1 #include "config.h" 2 3 #include <stdio.h> 4 #include <string.h> 5 6 #include "json.h" 7 #include "parse_flags.h" 8 9 #if !defined(HAVE_STRCASECMP) && defined(_MSC_VER) 10 #define strcasecmp _stricmp 11 #elif !defined(HAVE_STRCASECMP) 12 #error You do not have strcasecmp on your system. 13 #endif /* HAVE_STRNCASECMP */ 14 15 static struct 16 { 17 const char *arg; 18 int flag; 19 } format_args[] = { 20 {"plain", JSON_C_TO_STRING_PLAIN}, 21 {"spaced", JSON_C_TO_STRING_SPACED}, 22 {"pretty", JSON_C_TO_STRING_PRETTY}, 23 {"pretty_tab", JSON_C_TO_STRING_PRETTY_TAB}, 24 }; 25 26 #ifndef NELEM 27 #define NELEM(x) (sizeof(x) / sizeof(x[0])) 28 #endif 29 30 int parse_flags(int argc, char **argv) 31 { 32 int arg_idx; 33 int sflags = 0; 34 for (arg_idx = 1; arg_idx < argc; arg_idx++) 35 { 36 int jj; 37 for (jj = 0; jj < (int)NELEM(format_args); jj++) 38 { 39 if (strcasecmp(argv[arg_idx], format_args[jj].arg) == 0) 40 { 41 sflags |= format_args[jj].flag; 42 break; 43 } 44 } 45 if (jj == NELEM(format_args)) 46 { 47 printf("Unknown arg: %s\n", argv[arg_idx]); 48 exit(1); 49 } 50 } 51 return sflags; 52 } 53
This page was automatically generated by LXR 0.3.1. • OpenWrt