source: branches/stable/monitas/tst.c @ 353

Last change on this file since 353 was 353, checked in by bcornec, 13 years ago

monitas latest version

File size: 1.7 KB
Line 
1#include <time.h>
2#include <string.h>
3
4#define _XSTR(x) #x
5#define __XSTR(x) _XSTR(x)
6#define SUBFUNCTION() subfunct(__FUNCTION__, __FILE__, __XSTR(__LINE__))
7#define _SUBFUNCTION(a,b,c) subfunct(a, b, #c)
8
9
10
11
12void subfunct(char *func, char *file, char *line)
13{
14    char *descr;
15    /*              "file.c"   ":"  "122"      ", "  "main"      "():\n\0"  */
16    descr = alloca(strlen(file)+1 +strlen(line)+ 2  +strlen(func)+5);
17    sprintf(descr, "%s:%s, %s():\n", file, line, func);
18    printf("'%s'", descr);
19}
20
21int main(int argc, char *argv [])
22{
23    time_t clock;
24    struct tm tm;
25
26    char buf[100];
27    int x;
28
29    printf("\\t=%u \\n=%u \\r=%u \\c=%u  \n", (unsigned) '\t',(unsigned) '\n',(unsigned) '\r',(unsigned) '\c' );
30
31    time(&clock);
32/*
33    ctime_r(&clock, buf);
34    printf("'%s' strlen()=%d\n", buf, strlen(buf));
35
36    buf[strlen(buf)-6] = '*';
37    buf[10] = '>';
38
39    printf("'%s' strlen()=%d\n", buf, strlen(buf));
40*/
41    localtime_r(&clock, &tm);
42
43    printf("%d.%d.%d %02d:%02d:%02d\n", tm.tm_mday, tm.tm_mon, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
44    usleep(500000);
45
46    clock = time(NULL);
47    localtime_r(&clock, &tm);
48//    localtime_r(NULL, &tm);
49    printf("%d.%d.%d %02d:%02d:%02d\n", tm.tm_mday, tm.tm_mon, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
50
51    printf("func: %s, file: %s, line: %d\n", __FUNCTION__, __FILE__, __LINE__);
52
53    SUBFUNCTION();
54
55    printf("basename: %s\n", strrchr(argv[0], '/'));
56#define BASENAME(a) printf("basename of \""a"\" is \"%s\"\n", strrchr(a, '/'))
57
58    BASENAME("name");
59    BASENAME("/name");
60    BASENAME("path/name");
61    BASENAME("/path/name");
62    BASENAME("path/");
63    BASENAME("/path/");
64    return 0;
65}
Note: See TracBrowser for help on using the repository browser.