# HG changeset patch # User tuomov # Date 973368892 -3600 # Node ID 228f64ffb422c170dff58e8e7f8be259e94e332c # Parent ebc92fce5a3c5622fe3b508bc4c247a6bafc965d trunk: changeset 30 Added LIBTU_NO_ERRMSG so snprintf is not needed with programs that don't use the errmsg functions (pwm). diff -r ebc92fce5a3c -r 228f64ffb422 Makefile --- a/Makefile Fri Oct 27 15:41:36 2000 +0200 +++ b/Makefile Sat Nov 04 21:14:52 2000 +0100 @@ -12,11 +12,15 @@ OBJS= misc.o output.o util.o optparser.o parser.o tokenizer.o +ifdef LIBTU_NO_ERRMSG +CFLAGS += -DLIBTU_NO_ERRMSG +else ifndef HAS_SYSTEM_ASPRINTF OBJS += ../snprintf_2.2/snprintf.o else CFLAGS += -DHAS_SYSTEM_ASPRINTF endif +endif LIBDIR=$(PREFIX)/lib INCDIR=$(PREFIX)/include/libtu diff -r ebc92fce5a3c -r 228f64ffb422 output.c --- a/output.c Fri Oct 27 15:41:36 2000 +0200 +++ b/output.c Sat Nov 04 21:14:52 2000 +0100 @@ -15,7 +15,7 @@ #include #include -#ifndef HAS_SYSTEM_ASPRINTF +#if !defined(LIBTU_NO_ERRMSG) && !defined(HAS_SYSTEM_ASPRINTF) #include "../snprintf_2.2/snprintf.h" #endif @@ -75,9 +75,6 @@ } -/* warn - */ - void warn_progname_enable(bool enable) { progname_enable=enable; @@ -99,11 +96,12 @@ fprintf(stderr, "%s: ", (char*)progname); } +/* warn + */ #define CALL_V(NAME, ARGS) \ va_list args; va_start(args, p); NAME ARGS; va_end(args); -#define CALL_V_RET(NAME, ARGS) \ - char *ret; va_list args; va_start(args, p); ret=NAME ARGS; va_end(args); return ret; + void warn(const char *p, ...) { @@ -111,48 +109,24 @@ } -char* errmsg(const char *p, ...) -{ - CALL_V_RET(errmsg_v, (p, args)); -} - - void warn_obj(const char *obj, const char *p, ...) { CALL_V(warn_obj_v, (obj, p, args)); } -char *errmsg_obj(const char *obj, const char *p, ...) -{ - CALL_V_RET(errmsg_obj_v, (obj, p, args)); -} - - void warn_obj_line(const char *obj, int line, const char *p, ...) { CALL_V(warn_obj_line_v, (obj, line, p, args)); } -char *errmsg_obj_line(const char *obj, int line, const char *p, ...) -{ - CALL_V_RET(errmsg_obj_line_v, (obj, line, p, args)); -} - - void warn_obj_v(const char *obj, const char *p, va_list args) { warn_obj_line_v(obj, -1, p, args); } -char* errmsg_obj_v(const char *obj, const char *p, va_list args) -{ - return errmsg_obj_line_v(obj, -1, p, args); -} - - void warn_v(const char *p, va_list args) { put_prog_name(); @@ -161,14 +135,6 @@ } -char *errmsg_v(const char *p, va_list args) -{ - char *res; - vasprintf(&res, p, args); - return res; -} - - void warn_obj_line_v(const char *obj, int line, const char *p, va_list args) { put_prog_name(); @@ -186,6 +152,80 @@ } +void warn_err() +{ + put_prog_name(); + fprintf(stderr, "%s\n", strerror(errno)); +} + + +void warn_err_obj(const char *obj) +{ + put_prog_name(); + if(obj!=NULL) + fprintf(stderr, "%s: %s\n", obj, strerror(errno)); + else + fprintf(stderr, "%s\n", strerror(errno)); +} + +void warn_err_obj_line(const char *obj, int line) +{ + put_prog_name(); + if(obj!=NULL){ + if(line>0) + fprintf(stderr, TR("%s:%d: %s\n"), obj, line, strerror(errno)); + else + fprintf(stderr, "%s: %s\n", obj, strerror(errno)); + }else{ + if(line>0) + fprintf(stderr, TR("%d: %s\n"), line, strerror(errno)); + else + fprintf(stderr, TR("%s\n"), strerror(errno)); + } + +} + + +/* errmsg + */ +#ifndef LIBTU_NO_ERRMSG + +#define CALL_V_RET(NAME, ARGS) \ + char *ret; va_list args; va_start(args, p); ret=NAME ARGS; va_end(args); return ret; + + +char* errmsg(const char *p, ...) +{ + CALL_V_RET(errmsg_v, (p, args)); +} + + +char *errmsg_obj(const char *obj, const char *p, ...) +{ + CALL_V_RET(errmsg_obj_v, (obj, p, args)); +} + + +char *errmsg_obj_line(const char *obj, int line, const char *p, ...) +{ + CALL_V_RET(errmsg_obj_line_v, (obj, line, p, args)); +} + + +char* errmsg_obj_v(const char *obj, const char *p, va_list args) +{ + return errmsg_obj_line_v(obj, -1, p, args); +} + + +char *errmsg_v(const char *p, va_list args) +{ + char *res; + vasprintf(&res, p, args); + return res; +} + + char *errmsg_obj_line_v(const char *obj, int line, const char *p, va_list args) { char *res1=NULL, *res2, *res3; @@ -211,13 +251,6 @@ } -void warn_err() -{ - put_prog_name(); - fprintf(stderr, "%s\n", strerror(errno)); -} - - char *errmsg_err() { char *res; @@ -226,16 +259,6 @@ } -void warn_err_obj(const char *obj) -{ - put_prog_name(); - if(obj!=NULL) - fprintf(stderr, "%s: %s\n", obj, strerror(errno)); - else - fprintf(stderr, "%s\n", strerror(errno)); -} - - char *errmsg_err_obj(const char *obj) { char *res; @@ -247,24 +270,6 @@ } -void warn_err_obj_line(const char *obj, int line) -{ - put_prog_name(); - if(obj!=NULL){ - if(line>0) - fprintf(stderr, TR("%s:%d: %s\n"), obj, line, strerror(errno)); - else - fprintf(stderr, "%s: %s\n", obj, strerror(errno)); - }else{ - if(line>0) - fprintf(stderr, TR("%d: %s\n"), line, strerror(errno)); - else - fprintf(stderr, TR("%s\n"), strerror(errno)); - } - -} - - char *errmsg_err_obj_line(const char *obj, int line) { char *res; @@ -281,6 +286,7 @@ } return res; } +#endif /* LIBTU_NO_ERRMSG */ /* die