PluginManager::PluginManager(int argc, const char** argv) { const bool help = containsString(argc, argv, "--help"); for (int i = 0; i < argc; ++i) { if (std::strcmp(argv[i], "--plugin") != 0) continue; if (++i == argc || argv[i][0] == '\0' || argv[i][0] == '-') { // Do not print anything here, errors will be reported later // during option parsing continue; } std::string str(argv[i]); boost::trim(str); std::vector<std::string> words; boost::split(words, str, boost::is_any_of(" "), boost::token_compress_on); if (help) words.push_back("--help"); const char* name = words.front().c_str(); std::vector<const char*> args; for (const auto& w : words) args.push_back(w.c_str()); _loadPlugin(name, args.size(), args.data()); } }
int main(int argc, char *argv[]) { if(1 >= argc) return 1; struct PrefixTree *tree = loadTree(argv[1]); char str[BUF_SIZE]; while(1) { printf("Input string: "); scanf("%s", str); if(strcmp(str, "exit") == 0) break; if(1 == containsString(tree, str, strlen(str))) printf("YES\r\n"); else printf("NO\r\n"); } deletePrefixTree(tree); return 0; }
void* doSomeThing(void *arg) { pthread_t id = pthread_self(); int idno; for(idno = 0; idno < thread_number; idno++){ if(pthread_equal(id,tid[idno])){ break; } } // printf("Thread %i processing\n", idno); int endOfFile = 0; while((endOfFile == 0)&&(isFound==0)){ struct record theRecord[record_number]; int i; if(fread(&theRecord, 1024*record_number, 1, target)==0){ endOfFile = 1; } for(i = 0; i < record_number; i++){ // if(fread(&theRecord[i], 1024, 1, target) == 0){ // endOfFile = 1; // } if(containsString(theRecord[i].text, text)){ printf("Found! TID: %i, Record ID: %i\n", idno, theRecord[i].id); isFound = 1; break; } } } return NULL; }
void prefixTreeSample() { struct PrefixTree *prefixTree = createPrefixTree(32, 127); insertString(prefixTree, "abcd", 4); insertString(prefixTree, "sadr", 4); insertString(prefixTree, "fved", 4); insertString(prefixTree, "vcefd", 5); if(1 == containsString(prefixTree, "abcd", 4)) printf("Contain 'abcd'\r\n"); else printf("NO 'abcd'\r\n"); if(1 == containsString(prefixTree, "abc", 3)) printf("Contain 'abc'\r\n"); else printf("NO 'abc'\r\n"); deletePrefixTree(prefixTree); }
int main (int argc, const char * argv []) { char ch; String string = initString(SIZE); String substring = initString(SIZE); do { printf("\n\tEnter the string: "); scanf(" %s", string); printf("\tEnter the substring: "); scanf(" %s", substring); if (containsString(string, substring)) printf("\n\t'%s' is contained in '%s'.", substring, string); else printf("\n\t'%s' is not present in '%s'.", substring, string); printf("\n\tContinue (y/n): "); scanf(" %c", &ch); } while (ch == 'y'); printf("\n\n"); }
int docmd(Client *C, char *cmd) { int rc = 1; Proto_Client *client = (Proto_Client *) C->ph; // If this is a connect attempt char input[50]; strcpy(input, cmd); int connectAttempt = check_if_connect(input); if (connectAttempt==1) { // Ok startup our connection to the server if (startConnection(C, globals.host, globals.port, update_event_handler)<0) { fprintf(stderr, "ERROR: startConnection failed\n"); return -1; } else { fprintf(stderr, "Successfully connected to <%s:%d>\n", globals.host, globals.port); proto_client_hello(C->ph); doRPCCmd(C, 'q'); //query for the map return 1; } return 1; } strcpy(input,cmd); if (strcmp(cmd, "disconnect\n")==0) { doRPCCmd(C, 'g'); rc=-1; } else if (strcmp(cmd, "where\n")==0) where(); else if (strcmp(cmd, "numhome 1\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome1!=0) fprintf(stderr, "%d\n", client->game.map.numHome1); } else if (strcmp(cmd, "numhome 2\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome2!=0) fprintf(stderr, "%d\n", client->game.map.numHome2); } else if (strcmp(cmd, "numjail 1\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numJail1!=0) fprintf(stderr, "%d\n", client->game.map.numJail1); } else if (strcmp(cmd, "numjail 2\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numHome2!=0) fprintf(stderr, "%d\n", client->game.map.numJail2); } else if (strcmp(cmd, "numwall\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numFixedWall!=0 && client->game.map.numNonfixedWall!=0) fprintf(stderr, "%d\n", client->game.map.numFixedWall + client->game.map.numNonfixedWall); } else if (strcmp(cmd, "numfloor\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.numFloor1!=0 && client->game.map.numFloor2!=0) fprintf(stderr, "%d\n", client->game.map.numFloor1+client->game.map.numFloor2); } else if (strcmp(cmd, "dim\n")==0) { doRPCCmd(C, 'q'); // query map if (client->game.map.dimension.x!=0 && client->game.map.dimension.y!=0) fprintf(stderr, "%dx%d\n", client->game.map.dimension.x, client->game.map.dimension.y); } else if (strcmp(cmd, "dump\n")==0) { doRPCCmd(C, 'q'); // query map printMap(&client->game.map); if (DISPLAYUI==1) ui_update(ui); } else if (containsString(input, "cinfo")>0) { doRPCCmd(C, 'q'); // query map cinfo(cmd, C); } else if (strcmp(cmd, "start\n")==0) { doRPCCmd(C, 's'); // query map } else if (strcmp(cmd, "test\n")==0) { if (STRESS_TEST == 1) { pid_t myChild; myChild = fork(); if (myChild == 0) { Wander(C, 0); } else{} } } // MOVEMENT else if (strcmp(cmd, "w\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = UP; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "a\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = LEFT; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "d\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = RIGHT; doRPCCmd(C, 'm'); // query map } else if (strcmp(cmd, "s\n")==0) { Proto_Client *client = C->ph; client->rpc_session.shdr.returnCode = DOWN; doRPCCmd(C, 'm'); // query map } // END OF MOVEMENT //PICKUP else if (strcmp(cmd, "f\n")==0){ Proto_Client *client = C->ph; doRPCCmd(C, 'f'); } //END PICKUP else if (strcmp(cmd, "O\n")==0) proto_debug_on(); else if (strcmp(cmd, "o\n")==0) proto_debug_off(); else if (strcmp(cmd, "rh\n")==0) rc = proto_client_hello(C->ph); else if (strcmp(cmd, "q\n")==0) { fprintf(stderr, "Game Over: You Quit\n"); doRPCCmd(C, 'g'); rc=-1; } else if (strcmp(cmd, "quit\n")==0) { doRPCCmd(C, 'g'); fprintf(stderr, "Game Over: You Quit\n"); rc=-1; } else if (strcmp(cmd, "\n")==0) { rc = proto_client_update(C->ph); rc=1; } else { fprintf(stderr, "Unknown command\n"); } return rc; }