00001 #ifndef TEST_ARGPARSING_H
00002 #define TEST_ARGPARSING_H
00003
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <stdarg.h>
00007
00008 #ifndef SST
00009 # define CHECK_VERBOSE() verbose = (getenv("VERBOSE") != NULL)
00010 #else
00011 # define CHECK_VERBOSE()
00012 #endif
00013
00014 #define NUMARG(var,name) do { \
00015 char *str; \
00016 if ((str = getenv(name)) != NULL) { \
00017 char *stre = NULL; \
00018 size_t tmp = strtoul(str, &stre, 0); \
00019 if (stre == NULL || stre == str) { \
00020 fprintf(stderr, "unparsable "name" (%s)\n", str); \
00021 } else { \
00022 var = tmp; \
00023 } \
00024 } \
00025 iprintf(name" = %lu\n", (unsigned long)var); \
00026 } while (0)
00027
00028 #ifdef SST
00029 static int verbose = 1;
00030 #else
00031 static int verbose = 0;
00032 #endif
00033
00034 #ifdef __tile__
00035 #define iprintf printf
00036 #else
00037 static void iprintf(const char * restrict format, ...)
00038 {
00039 if (verbose != 0) {
00040 va_list ap;
00041
00042 va_start(ap, format);
00043 vprintf(format, ap);
00044 fflush(stdout);
00045 va_end(ap);
00046 }
00047 }
00048 #endif
00049
00050 #endif