Changeset 22768 for titan/titan/debug.h


Ignore:
Timestamp:
Aug 11, 2013, 10:00:13 AM (7 years ago)
Author:
nit
Message:

[titan] optimize titan size (7%-8%)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • titan/titan/debug.h

    r19177 r22768  
    1414// panel debug_level = 60;
    1515
     16//debug
    1617//first line shows greater/same debuglevel
    1718//second line shows only same debuglevel
    1819//#define debug(level, fmt, args...) if(debug_level >= level) { do { printf("[%s] " fmt, PROGNAME, ##args); } while (0); printf(", file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
    19 #define debug(level, fmt, args...) if(debug_level == level) { do { printf("[%s] " fmt, PROGNAME, ##args); } while (0); printf(", file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     20//#define debug(level, fmt, args...) if(debug_level == level) { do { printf("[%s] " fmt, PROGNAME, ##args); } while (0); printf(", file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     21void debugfunc(int level, char* file, const char* function, int line, char* msg, ...)
     22{
     23        if(debug_level == level)
     24        {
     25                va_list ap;
     26                va_start(ap, msg);
     27                printf("[%s] ", PROGNAME);
     28                vfprintf(stdout, msg, ap);
     29                va_end(ap);
     30                printf(", file=%s, func=%s, line=%d\n", file, function, line);
     31        }
     32}
     33#define debug(level, msg...) debugfunc(level, __FILE__, __FUNCTION__, __LINE__, msg);
    2034
    21 #define err(fmt, args...) { do { fprintf(stderr, "[%s] error: " fmt, PROGNAME, ##args); } while (0); fprintf(stderr, ", file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     35//err
     36//#define err(fmt, args...) { do { fprintf(stderr, "[%s] error: " fmt, PROGNAME, ##args); } while (0); fprintf(stderr, ", file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     37void errfunc(char* file, const char* function, int line, char* msg, ...)
     38{
     39        va_list ap;
     40        va_start(ap, msg);
     41        fprintf(stderr, "[%s] error: ", PROGNAME);
     42        vfprintf(stderr, msg, ap);
     43        va_end(ap);
     44        fprintf(stderr, ", file=%s, func=%s, line=%d\n", file, function, line);
     45}
     46#define err(msg...) errfunc(__FILE__, __FUNCTION__, __LINE__, msg);
    2247
    23 #define perr(fmt, args...) { do { fprintf(stderr, "[%s] error: " fmt, PROGNAME, ##args); } while (0); fprintf(stderr, ", err=%m, file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     48//perr
     49//#define perr(fmt, args...) { do { fprintf(stderr, "[%s] error: " fmt, PROGNAME, ##args); } while (0); fprintf(stderr, ", err=%m, file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__); }
     50void perrfunc(char* file, const char* function, int line, char* msg, ...)
     51{
     52        va_list ap;
     53        va_start(ap, msg);
     54        fprintf(stderr, "[%s] error: ", PROGNAME);
     55        vfprintf(stderr, msg, ap);
     56        va_end(ap);
     57        fprintf(stderr, ", err=%m, file=%s, func=%s, line=%d\n", file, function, line);
     58}
     59#define perr(msg...) perrfunc(__FILE__, __FUNCTION__, __LINE__, msg);
    2460
    25 #define filedebug(file, fmt, args...) { FILE* fd = fopen(file, "a"); if(fd != NULL) { do { fprintf(fd, "" fmt, ##args); } while (0); fprintf(fd, "\n"); fclose(fd); }}
     61//filedebug
     62//#define filedebug(file, fmt, args...) { FILE* fd = fopen(file, "a"); if(fd != NULL) { do { fprintf(fd, "" fmt, ##args); } while (0); fprintf(fd, "\n"); }}
     63void filedebugfunc(char* file, char* msg, ...)
     64{
     65        FILE* fd = fopen(file, "a");
     66        if(fd != NULL)
     67        {
     68                va_list ap;
     69                va_start(ap, msg);
     70                vfprintf(fd, msg, ap);
     71                va_end(ap);
     72                fprintf(fd, "\n");
     73                fclose(fd);
     74        }
     75}
     76#define filedebug(file, msg...) filedebugfunc(file, msg);
    2677
    2778#endif
Note: See TracChangeset for help on using the changeset viewer.