static void empty_option_fail(void **state) { args *args = *state; option *opt = option_new("", "", ""); assert_int_equal( ARGPARSE_EMPTY_OPTION, args_add_option(args, opt) ); option_free(opt); }
/** @brief Parse modules. * * @param cur Pointer to the \<modules\> node. */ static void parser_modules(xmlNodePtr cur) { xmlChar *name, *weight, *mandatory; moduleoption *opt; module *dest; while(cur!=NULL) { if (!xmlStrcmp(cur->name, XMLCHAR "module")) { name=parser_getprop_str(cur, XMLCHAR "name"); weight=parser_getprop_str(cur, XMLCHAR "weight"); mandatory=parser_getprop_str(cur, XMLCHAR "mandatory"); opt=option_new(NULL, "weight", CHAR weight); if(!xmlStrcmp(mandatory, XMLCHAR "yes")) { opt=option_new(opt, "mandatory", "1"); } else if(!xmlStrcmp(mandatory, XMLCHAR "no")) { opt=option_new(opt, "mandatory", "0"); } else { FAIL("Property 'mandatory' should be 'yes'" "or 'no'", cur); } opt=parser_options(cur->children, opt); dest=module_load(CHAR name, opt); if(dest==NULL) { fatal(_("Module %s failed to load"), name); } xmlFree(name); xmlFree(weight); xmlFree(mandatory); option_free(opt); } cur=cur->next; } }
/** @brief Parse module options. * * @param cur Pointer to the \<module\> node. * @param opt Pointer to the linked list of module options. */ static moduleoption *parser_options(xmlNodePtr cur, moduleoption *opt) { xmlChar *content, *name; moduleoption *result; result=opt; while (cur!=NULL) { if (!xmlStrcmp(cur->name, XMLCHAR "option")) { name=parser_getprop_str(cur, XMLCHAR "name"); content=xmlNodeGetContent(cur); result=option_new(result, CHAR name, CHAR content); xmlFree(name); xmlFree(content); } cur=cur->next; } return(result); }
/* * main code * */ int main(int argc, char *argv[]) { Option *option; FILE *fp; char buffer[BUFSIZ]; HashTable *hash_table = NULL; YoutubeID youtube_id; int num_record_readed = 0, num_record_added = 0; /* parse option */ option = option_new(argc, argv); if (strcmp(option->id_list_path, "") == 0|| option->size_hash_table == 0) { printf_help_info(); exit(0); } /* open id list file */ fp = fopen(option->id_list_path, "a+"); if (fp == NULL) { printf("open id list file '%s' fail\n", option->id_list_path); exit(0); } /* create hash table */ hash_table = hash_table_new(option->size_hash_table); fseek(fp, 0, SEEK_SET); while (fgets(buffer, BUFSIZ, fp) != NULL) { buffer[strlen(buffer) - 1] = '\0'; // delete '\n' hash_table_insert(hash_table, (YoutubeID*) buffer); } fseek(fp, 0, SEEK_END); fprintf(stderr, "INFO: hash_table->size = %zd\n", hash_table->size); fprintf(stderr, "INFO: hash_table->count = %zd\n", hash_table->count); /* filte input */ while (fgets(buffer, BUFSIZ, stdin) != NULL) { if (extract_video_id(buffer, (char*) &youtube_id)) { if (!hash_table_find(hash_table, &youtube_id)) { fputs(buffer, stdout); hash_table_insert(hash_table, &youtube_id); fprintf(fp, "%s\n", youtube_id.id); num_record_added++; if (hash_table_is_fulled(hash_table)) { fprintf(stderr, "ERROR: the hash table is full!\n"); fprintf(stderr, "hash table size: %zd\n", hash_table->size); exit(0); } } } num_record_readed++; } fprintf(stderr, "INFO: num_record_readed = %d\n", num_record_readed); fprintf(stderr, "INFO: num_record_added = %d\n", num_record_added); fclose(fp); hash_table_free(hash_table); return 0; }