int main(int argc,char *argv[]) { char *s=NULL; replaceSubstr(argv[1],&s,argv[2],argv[3]); printf("%s\n",s); return 0; }
static bool replaceURL (tr_benc * metainfo, const char * in, const char * out) { const char * str; tr_benc * announce_list; bool changed = false; if (tr_bencDictFindStr (metainfo, "announce", &str) && strstr (str, in)) { char * newstr = replaceSubstr (str, in, out); printf ("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr); tr_bencDictAddStr (metainfo, "announce", newstr); tr_free (newstr); changed = true; } if (tr_bencDictFindList (metainfo, "announce-list", &announce_list)) { tr_benc * tier; int tierCount = 0; while ((tier = tr_bencListChild (announce_list, tierCount++))) { tr_benc * node; int nodeCount = 0; while ((node = tr_bencListChild (tier, nodeCount++))) { if (tr_bencGetStr (node, &str) && strstr (str, in)) { char * newstr = replaceSubstr (str, in, out); printf ("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount, str, newstr); tr_bencFree (node); tr_bencInitStr (node, newstr, -1); tr_free (newstr); changed = true; } } } } return changed; }
static bool replaceURL (tr_variant * metainfo, const char * in, const char * out) { const char * str; tr_variant * announce_list; bool changed = false; if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && strstr (str, in)) { char * newstr = replaceSubstr (str, in, out); printf ("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr); tr_variantDictAddStr (metainfo, TR_KEY_announce, newstr); tr_free (newstr); changed = true; } if (tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list)) { tr_variant * tier; int tierCount = 0; while ((tier = tr_variantListChild (announce_list, tierCount++))) { tr_variant * node; int nodeCount = 0; while ((node = tr_variantListChild (tier, nodeCount++))) { if (tr_variantGetStr (node, &str, NULL) && strstr (str, in)) { char * newstr = replaceSubstr (str, in, out); printf ("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount, str, newstr); tr_variantFree (node); tr_variantInitStr (node, newstr, TR_BAD_SIZE); tr_free (newstr); changed = true; } } } } return changed; }
void exeRunQuery (void *code) { List *res; int i = 0; char *adaptedQuery; // remove semicolon adaptedQuery = replaceSubstr(code, ";", ""); //TODO not safe if ; in strings // execute query INFO_LOG("run query:\n%s", (char *) adaptedQuery); res = executeQuery((char *) adaptedQuery); // output results FOREACH(List,t,res) { FOREACH(char,a,t) printf("%s|", a); printf("\n"); if ((i++ % 1000) == 0) fflush(stdout); }