void handle_line(char *s) { char *result, *tempstr; /* Apply alternative */ results = 0; if (apply_alternates == 1) { for (chain_pos = chain_head, tempstr = s; ; chain_pos = chain_pos->next) { result = applyer(chain_pos->ah, tempstr); if (result != NULL) { results++; if (results == 1) { fprintf(stdout, "\"<%s>\"\n",line); } app_print(result); while ((result = applyer(chain_pos->ah, NULL)) != NULL) { results++; app_print(result); } break; } if (chain_pos == chain_tail) { break; } } } else { /* Get result from chain */ for (chain_pos = chain_head, tempstr = s; ; chain_pos = chain_pos->next) { result = applyer(chain_pos->ah, tempstr); if (result != NULL && chain_pos != chain_tail) { tempstr = result; continue; } if (result != NULL && chain_pos == chain_tail) { do { results++; if (results == 1) { fprintf(stdout, "\"<%s>\"\n",line); } app_print(result); } while ((result = applyer(chain_pos->ah, NULL)) != NULL); } if (result == NULL) { /* Move up */ for (chain_pos = chain_pos->prev; chain_pos != NULL; chain_pos = chain_pos->prev) { result = applyer(chain_pos->ah, NULL); if (result != NULL) { tempstr = result; break; } } } if (chain_pos == NULL) { break; } } } }
int main (int argc, char * const argv[]) { _run_none_test = false; app_print("start app...", true); app_print(""); test_basics_structures(true, "* Teste - Estruturas Basicas...\n"); system("pause"); return 0; }
int main(int argc, const char *argv[]) { #if 0 *((unsigned char *)(0xb8000+160*22+0)) = 'e'; *((unsigned char *)(0xb8000+160*22+1)) = 0x14; *((unsigned char *)(0xb8000+160*22+2)) = 'c'; *((unsigned char *)(0xb8000+160*22+3)) = 0x94; *((unsigned char *)(0xb8000+160*22+4)) = 'h'; *((unsigned char *)(0xb8000+160*22+5)) = 0x0f; *((unsigned char *)(0xb8000+160*22+6)) = 'o'; *((unsigned char *)(0xb8000+160*22+7)) = 0x0c; #endif //s32_printf("I am app\r\n"); app_print("I am echo app"); #if 1 for (int i=0 ; i < 10000 ; ++i) for (int j=0 ; j < 10000 ; ++j) ; #endif return 678; }
void test_basics_structures (bool run, string _test_name="") { if (run && !_run_none_test) { app_print(_test_name); app_print("test - GenericData class..."); app_print(""); GenericData * db = new GenericData(1, "Leonardo Costa"); int id_from_db = db->getId(); app_print(id_from_db, false); app_print(db->getName()); app_print(""); app_print("test - TreeNode class..."); app_print("maker - root node"); GenericData * left__generic_data = new GenericData(1, "nome 1"); GenericData * root__generic_data = new GenericData(2, "nome 2"); GenericData * right_generic_data = new GenericData(3, "nome 3"); // tree = new TreeNode(elem, NULL, NULL) // TreeNode(GenericData * elem, TreeNode* left, TreeNode* right) /* TreeNode * left__node = new TreeNode(left__generic_data, NULL, NULL); TreeNode * root__node = new TreeNode(root__generic_data, NULL, NULL); TreeNode * right_node = new TreeNode(right_generic_data, NULL, NULL); */ app_print("maker - tree"); //-----------------------------------------client tree--------------------- Tree * b_tree = new Tree(); b_tree->add(left__generic_data); b_tree->add(root__generic_data); b_tree->add(right_generic_data); b_tree->add(new GenericData(4, "new")); Client * client1 = new Client(1000, "leo", 22); b_tree->add(client1); b_tree->print(std::cout); app_print("\n------------------------------------------maker - tree_client"); TreeClient * b_tree_client_db = new TreeClient(); b_tree_client_db->add(new Client(1, "client 1", 10)); b_tree_client_db->add(new Client(2, "client 2", 20)); b_tree_client_db->add(new Client(3, "client 3", 30)); GenericData * get_client1 = b_tree_client_db->get(2); if (typeid(*get_client1) == typeid(Client)) { app_print("get id, name and age from client..."); Client * current_client = ((Client*)get_client1);// cast para aceder aos atributos q nao são generic data int id_client = current_client->getId(); app_print(id_client); string name_client = current_client->getName(); app_print(name_client); int age = current_client->getAge(); app_print(age); } //b_tree_client_db->add(right_generic_data); b_tree_client_db->print(std::cout); //-----------------------------------------shop tree--------------------- app_print("\n-------------------------------------------maker - shop tree"); Tree * shop_tree = new Tree(); Shop * shop1 = new Shop(3, 10, 11, "viagra", 100, true, 33);//(id,idPhar,idDrug,name,quantity, compart, totalValue) shop_tree->add(shop1); Shop * shop2 = new Shop(2, 20, 12, "arldite", 100, true, 34); shop_tree->add(shop2); shop_tree->add(new Shop(1, 30, 13, "cosmite", 100, true, 35)); shop_tree->add(new Shop(4, 40, 14, "afrdite", 100, true, 36)); shop_tree->add(new Shop(5, 50, 15, "tttdite", 100, true, 37)); GenericData * get_shop = shop_tree->get(1); //poly. get element with id 1 if (typeid(* get_shop) == typeid(Shop)) { app_print("get id, name and totalValue from Shop..."); Shop * current_shop = ((Shop*)get_shop); // cast para aceder aos atributos q nao são generic data int id_shop = current_shop->getId(); string name_shop = current_shop->getName(); int totalVal = current_shop->getTotalValue(); app_print(id_shop); app_print(name_shop); app_print(totalVal); shop_tree->print(std::cout);//print tree [[]] } //-----------------------------------------pharmacy tree--------------------- app_print("\n-------------------------------------------maker - Pharmacy tree"); Tree * pharm_tree = new Tree(); pharm_tree->add(new Pharmacy(1, "Farmacia Brito")); pharm_tree->add(new Pharmacy(2, "Farmacia Cristal")); pharm_tree->add(new Pharmacy(3, "Farmacia Charopinho")); GenericData * get_pharm = pharm_tree->get(1); //poly. get element with id 1 if (typeid(* get_pharm) == typeid(Pharmacy)) { app_print("get id, name"); Pharmacy * current_pharm = ((Pharmacy*)get_pharm); // cast para aceder aos atributos q nao são generic data int id_pharm = current_pharm->getId(); string name_pharm = current_pharm->getName(); app_print(id_pharm); app_print(name_pharm); pharm_tree->print(std::cout);//print tree [[]] //------------------------------------------------------------------------ app_print(""); app_print(""); app_print(""); } } }
int main(int argc, char *argv[]) { int opt, sortarcs = 1; char *infilename; struct fsm *net; setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); while ((opt = getopt(argc, argv, "abhHiI:qs:uw:vx")) != -1) { switch(opt) { case 'a': apply_alternates = 1; break; case 'b': buffered_output = 0; break; case 'h': printf("%s%s\n", usagestring,helpstring); exit(0); case 'i': direction = DIR_DOWN; applyer = &apply_down; break; case 'q': sortarcs = 0; break; case 'I': if (strcmp(optarg, "f") == 0) { index_flag_states = 1; index_arcs = 1; } else if (strstr(optarg, "k") != NULL && strstr(optarg,"K") != NULL) { /* k limit */ index_mem_limit = 1024*atoi(optarg); index_arcs = 1; } else if (strstr(optarg, "m") != NULL && strstr(optarg,"M") != NULL) { /* m limit */ index_mem_limit = 1024*1024*atoi(optarg); index_arcs = 1; } else if (isdigit(*optarg)) { index_arcs = 1; index_cutoff = atoi(optarg); } break; case 's': separator = strdup(optarg); break; case 'u': mark_uppercase = 1; if (!setlocale(LC_CTYPE, "")) { fprintf(stderr, "Check uppercase flag is on, but can't set locale!\n"); } break; case 'w': wordseparator = strdup(optarg); break; case 'v': printf("cgflookup 1.03 (foma library version %s)\n", fsm_get_library_version_string()); exit(0); default: fprintf(stderr, "%s", usagestring); exit(EXIT_FAILURE); } } if (optind == argc) { fprintf(stderr, "%s", usagestring); exit(EXIT_FAILURE); } infilename = argv[optind]; if ((fsrh = fsm_read_binary_file_multiple_init(infilename)) == NULL) { perror("File error"); exit(EXIT_FAILURE); } chain_head = chain_tail = NULL; while ((net = fsm_read_binary_file_multiple(fsrh)) != NULL) { numnets++; chain_new = xxmalloc(sizeof(struct lookup_chain)); if (direction == DIR_DOWN && net->arcs_sorted_in != 1 && sortarcs) { fsm_sort_arcs(net, 1); } if (direction == DIR_UP && net->arcs_sorted_out != 1 && sortarcs) { fsm_sort_arcs(net, 2); } chain_new->net = net; chain_new->ah = apply_init(net); if (direction == DIR_DOWN && index_arcs) { apply_index(chain_new->ah, APPLY_INDEX_INPUT, index_cutoff, index_mem_limit, index_flag_states); } if (direction == DIR_UP && index_arcs) { apply_index(chain_new->ah, APPLY_INDEX_OUTPUT, index_cutoff, index_mem_limit, index_flag_states); } chain_new->next = NULL; chain_new->prev = NULL; if (chain_tail == NULL) { chain_tail = chain_head = chain_new; } else if (direction == DIR_DOWN || apply_alternates == 1) { chain_tail->next = chain_new; chain_new->prev = chain_tail; chain_tail = chain_new; } else { chain_new->next = chain_head; chain_head->prev = chain_new; chain_head = chain_new; } } if (numnets < 1) { fprintf(stderr, "%s: %s\n", "File error", infilename); exit(EXIT_FAILURE); } /* Standard read from stdin */ line = xxcalloc(LINE_LIMIT, sizeof(char)); INFILE = stdin; while (get_next_line() != NULL) { results = 0; handle_line(line); if (results == 0) { app_print(NULL); } fprintf(stdout, "%s", wordseparator); if (!buffered_output) { fflush(stdout); } } /* Cleanup */ for (chain_pos = chain_head; chain_pos != NULL; chain_pos = chain_head) { chain_head = chain_pos->next; if (chain_pos->ah != NULL) { apply_clear(chain_pos->ah); } if (chain_pos->net != NULL) { fsm_destroy(chain_pos->net); } xxfree(chain_pos); } if (line != NULL) xxfree(line); exit(0); }
int main(int argc, char *argv[]) { int opt, sortarcs = 1; char *infilename; struct fsm *net; setvbuf(stdout, buffer, _IOFBF, sizeof(buffer)); while ((opt = getopt(argc, argv, "abhHiI:qs:SA:P:w:vx")) != -1) { switch(opt) { case 'a': apply_alternates = 1; break; case 'b': buffered_output = 0; break; case 'h': printf("%s%s\n", usagestring,helpstring); exit(0); case 'i': direction = DIR_DOWN; applyer = &apply_down; break; case 'q': sortarcs = 0; break; case 'I': if (strcmp(optarg, "f") == 0) { index_flag_states = 1; index_arcs = 1; } else if (strcasestr(optarg, "k") != NULL) { /* k limit */ index_mem_limit = 1024*atoi(optarg); index_arcs = 1; } else if (strcasestr(optarg, "m") != NULL) { /* m limit */ index_mem_limit = 1024*1024*atoi(optarg); index_arcs = 1; } else if (isdigit(*optarg)) { index_arcs = 1; index_cutoff = atoi(optarg); } break; case 's': separator = strdup(optarg); break; case 'S': mode_server = 1; break; case 'A': server_address = strdup(optarg); break; case 'P': port_number = atoi(optarg); break; case 'w': wordseparator = strdup(optarg); break; case 'v': printf("flookup 1.02 (foma library version %s)\n", fsm_get_library_version_string()); exit(0); case 'x': echo = 0; break; default: fprintf(stderr, "%s", usagestring); exit(EXIT_FAILURE); } } if (optind == argc) { fprintf(stderr, "%s", usagestring); exit(EXIT_FAILURE); } infilename = argv[optind]; if ((fsrh = fsm_read_binary_file_multiple_init(infilename)) == NULL) { perror("File error"); exit(EXIT_FAILURE); } chain_head = chain_tail = NULL; while ((net = fsm_read_binary_file_multiple(fsrh)) != NULL) { numnets++; chain_new = xxmalloc(sizeof(struct lookup_chain)); if (direction == DIR_DOWN && net->arcs_sorted_in != 1 && sortarcs) { fsm_sort_arcs(net, 1); } if (direction == DIR_UP && net->arcs_sorted_out != 1 && sortarcs) { fsm_sort_arcs(net, 2); } chain_new->net = net; chain_new->ah = apply_init(net); if (direction == DIR_DOWN && index_arcs) { apply_index(chain_new->ah, APPLY_INDEX_INPUT, index_cutoff, index_mem_limit, index_flag_states); } if (direction == DIR_UP && index_arcs) { apply_index(chain_new->ah, APPLY_INDEX_OUTPUT, index_cutoff, index_mem_limit, index_flag_states); } chain_new->next = NULL; chain_new->prev = NULL; if (chain_tail == NULL) { chain_tail = chain_head = chain_new; } else if (direction == DIR_DOWN || apply_alternates == 1) { chain_tail->next = chain_new; chain_new->prev = chain_tail; chain_tail = chain_new; } else { chain_new->next = chain_head; chain_head->prev = chain_new; chain_head = chain_new; } } if (numnets < 1) { fprintf(stderr, "%s: %s\n", "File error", infilename); exit(EXIT_FAILURE); } if (mode_server) { server_init(); serverstring = xxcalloc(UDP_MAX+1, sizeof(char)); line = xxcalloc(UDP_MAX+1, sizeof(char)); addrlen = sizeof(clientaddr); for (;;) { numbytes = recvfrom(listen_sd, line, UDP_MAX, 0,(struct sockaddr *)&clientaddr, &addrlen); if (numbytes == -1) { perror("recvfrom() failed, aborting"); break; } line[numbytes] = '\0'; line[strcspn(line, "\n\r")] = '\0'; fflush(stdout); results = 0; udpsize = 0; serverstring[0] = '\0'; handle_line(line); if (results == 0) { app_print(NULL); } if (serverstring[0] != '\0') { numbytes = sendto(listen_sd, serverstring, strlen(serverstring), 0, (struct sockaddr *)&clientaddr, addrlen); if (numbytes < 0) { perror("sendto() failed"); fflush(stdout); } } } } else { /* Standard read from stdin */ line = xxcalloc(LINE_LIMIT, sizeof(char)); INFILE = stdin; while (get_next_line() != NULL) { results = 0; handle_line(line); if (results == 0) { app_print(NULL); } fprintf(stdout, "%s", wordseparator); if (!buffered_output) { fflush(stdout); } } } /* Cleanup */ for (chain_pos = chain_head; chain_pos != NULL; chain_pos = chain_head) { chain_head = chain_pos->next; if (chain_pos->ah != NULL) { apply_clear(chain_pos->ah); } if (chain_pos->net != NULL) { fsm_destroy(chain_pos->net); } xxfree(chain_pos); } if (serverstring != NULL) xxfree(serverstring); if (line != NULL) xxfree(line); exit(0); }