![]() |
fuse_kafka
|
00001 #include "config.h" 00002 #include "trace.c" 00004 #define STR(s) #s 00005 00009 #define CONFIG_CURRENT_DO(expected, action) \ 00010 if(!strcmp(name, STR(expected))) { \ 00011 trace_debug("parsing config item " STR(expected)); \ 00012 current_size = &(conf->expected ## _n); \ 00013 conf->expected = argv + i + 1; \ 00014 action; \ 00015 } 00016 #define CONFIG_CURRENT(expected) CONFIG_CURRENT_DO(expected, 1) 00017 #include "util.c" 00018 void add_fields_and_tags(config* conf) 00019 { 00020 if(conf->fields_s != NULL) 00021 { 00022 free(conf->fields_s); 00023 conf->fields_s = NULL; 00024 } 00025 conf->fields_s = array_to_container_string( 00026 conf->fields, conf->fields_n, '{', '}', ':', ','); 00027 if(conf->tags_s != NULL) 00028 { 00029 free(conf->tags_s); 00030 conf->tags_s = NULL; 00031 } 00032 conf->tags_s = array_to_container_string( 00033 conf->tags, conf->tags_n, '[', ']', ',', ','); 00034 } 00035 void free_fields_and_tags(config* conf) 00036 { 00037 if(conf->fields_s != NULL) 00038 { 00039 free(conf->fields_s); 00040 conf->fields_s = NULL; 00041 } 00042 if(conf->tags_s != NULL) 00043 { 00044 free(conf->tags_s); 00045 conf->tags_s = NULL; 00046 } 00047 } 00048 int parse_arguments(int argc, char** argv, config* conf) 00049 { 00050 int i; 00051 size_t* current_size; 00052 char* name; 00053 trace_debug("parse_argument: parsing %d arguments", argc); 00054 for(i = 0; i < argc; i++) 00055 { 00056 trace_debug("parse_argument: parsing arg #%d", i); 00057 if(strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == '-') 00058 { 00059 name = argv[i] + 2; 00060 CONFIG_CURRENT(directories) 00061 else CONFIG_CURRENT(persist) 00062 else CONFIG_CURRENT(excluded_files) 00063 else CONFIG_CURRENT(substitutions) 00064 else CONFIG_CURRENT(zookeepers) 00065 else CONFIG_CURRENT(brokers) 00066 else CONFIG_CURRENT(topic) 00067 else CONFIG_CURRENT(fields) 00068 else CONFIG_CURRENT(tags) 00069 else CONFIG_CURRENT(quota) 00070 else CONFIG_CURRENT(input) 00071 else CONFIG_CURRENT(output) 00072 else CONFIG_CURRENT(encoder) 00073 else CONFIG_CURRENT(debug) 00074 else CONFIG_CURRENT(log) 00075 else if(!strcmp(name, "version")) 00076 { 00077 printf("fuse_kafka " VERSION ", commit " COMMIT "\n") ; 00078 return 0; 00079 } 00080 else 00081 { 00082 printf("unknown option %s\n", argv[i]); 00083 return 0; 00084 } 00085 *current_size = 0; 00086 } 00087 else 00088 { 00089 (*current_size)++; 00090 } 00091 } 00092 add_fields_and_tags(conf); 00093 return 1; 00094 }