int help_query(const char *list, int def) { char s[256]; const char *a; int opt; int n = 1; a = list; while(strnotempty(a)) { const char *b = strchr(a, '|'); if (b) { char str[256]; str[0] = '\0'; // strncatbuff(str, a, (int) (b - a)); if (n == def) printf("(enter)\t%d\t%s\n", n++, str); else printf("\t%d\t%s\n", n++, str); a = b + 1; } else a = list + strlen(list); } printf("\t0\tQuit"); do { printf("\n: "); fflush(stdout); linput(stdin, s, 250); } while((strnotempty(s) != 0) && (sscanf(s, "%d", &opt) != 1)); if (strnotempty(s)) return opt; else return def; }
void MRFFT::calc(const float* input, float* output) { // temporary buffers std::vector<kiss_fft_scalar> linput(m_size), rinput(m_size); std::vector<kiss_fft_cpx> loutput(m_size), routput(m_size); for (size_t i=0;i<m_size;++i) { linput[i] = input[2*i]; rinput[i] = input[2*i+1]; } if (m_windowed) { hann(linput); hann(rinput); } // transform channels kiss_fftr(m_cfg, &linput[0], &loutput[0]); kiss_fftr(m_cfg, &rinput[0], &routput[0]); auto&& filter = [&](kiss_fft_cpx& data) { return sqrt(data.r*data.r+data.i*data.i) * 2.0/m_size * (m_windowed?sqrt(8.0/3.0):1.0); }; // interleave while taking magnitudes and normalizing for (size_t i=0;i<m_size/2;++i) { output[2*i] = filter(loutput[i]); output[2*i+1] = filter(routput[i]); } }
static const char* __cdecl htsshow_query2(t_hts_callbackarg *carg, httrackp *opt, const char* question) { static char s[12] = ""; /* ok */ printf("%s\nPress <Y><Enter> to confirm, <N><Enter> to abort\n", question); io_flush; linput(stdin, s, 4); return s; }
HTSEXT_API char* hts_getcategory(const char* filename) { String categ = STRING_EMPTY; if (fexist(filename)) { FILE* fp = fopen(filename, "rb"); if (fp != NULL) { int done=0; while(!feof(fp) && !done) { char BIGSTK line[1024]; int n = linput(fp, line, sizeof(line) - 2); if (n > 0) { if (strfield(line, "category=")) { unescapehttp(line+9, &categ); done=1; } } } fclose(fp); } } return StringBuffRW(categ); }
static const char *__cdecl htsshow_query3(t_hts_callbackarg * carg, httrackp * opt, const char *question) { static char line[256]; /* ok */ printf("\n" "A link, %s, is located beyond this mirror scope.\n" "What should I do? (type in the choice + enter)\n\n" "* Ignore all further links and do not ask any more questions\n" "0 Ignore this link (default if empty entry)\n" "1 Ignore directory and lower structures\n" "2 Ignore all domain\n" "\n" "4 Get only this page/link, but not links inside this page\n" "5 Mirror this link (useful)\n" "6 Mirror all links located on the same domain as this link\n" "\n", question); do { printf(">> "); io_flush; linput(stdin, line, 200); } while(!strnotempty(line)); printf("ok..\n"); return line; }
void help_wizard(httrackp * opt) { help_wizard_buffers *buffers = malloct(sizeof(help_wizard_buffers)); #undef urls #undef mainpath #undef projname #undef stropt #undef stropt2 #undef strwild #undef cmd #undef str #undef argv #define urls (buffers->urls) #define mainpath (buffers->mainpath) #define projname (buffers->projname) #define stropt (buffers->stropt) #define stropt2 (buffers->stropt2) #define strwild (buffers->strwild) #define cmd (buffers->cmd) #define str (buffers->str) #define argv (buffers->argv) //char *urls = (char *) malloct(HTS_URLMAXSIZE * 2); //char *mainpath = (char *) malloct(256); //char *projname = (char *) malloct(256); //char *stropt = (char *) malloct(2048); // options //char *stropt2 = (char *) malloct(2048); // options longues //char *strwild = (char *) malloct(2048); // wildcards //char *cmd = (char *) malloct(4096); //char *str = (char *) malloct(256); //char **argv = (char **) malloct(256 * sizeof(char *)); // char *a; // if (urls == NULL || mainpath == NULL || projname == NULL || stropt == NULL || stropt2 == NULL || strwild == NULL || cmd == NULL || str == NULL || argv == NULL) { fprintf(stderr, "* memory exhausted in %s, line %d\n", __FILE__, __LINE__); return; } urls[0] = mainpath[0] = projname[0] = stropt[0] = stropt2[0] = strwild[0] = cmd[0] = str[0] = '\0'; // strcpybuff(stropt, "-"); mainpath[0] = projname[0] = stropt2[0] = strwild[0] = '\0'; // printf("\n"); printf("Welcome to HTTrack Website Copier (Offline Browser) " HTTRACK_VERSION "%s\n", hts_get_version_info(opt)); printf("Copyright (C) 1998-2016 Xavier Roche and other contributors\n"); #ifdef _WIN32 printf("Note: You are running the commandline version,\n"); printf("run 'WinHTTrack.exe' to get the GUI version.\n"); #endif #ifdef HTTRACK_AFF_WARNING printf("NOTE: " HTTRACK_AFF_WARNING "\n"); #endif #ifdef HTS_PLATFORM_NAME #if USE_BEGINTHREAD printf("[compiled: " HTS_PLATFORM_NAME " - MT]\n"); #else printf("[compiled: " HTS_PLATFORM_NAME "]\n"); #endif #endif printf("To see the option list, enter a blank line or try httrack --help\n"); // // Project name while(strnotempty(projname) == 0) { printf("\n"); printf("Enter project name :"); fflush(stdout); linput(stdin, projname, 250); if (strnotempty(projname) == 0) help("httrack", 1); } // // Path if (strnotempty(hts_gethome())) printf("\nBase path (return=%s/websites/) :", hts_gethome()); else printf("\nBase path (return=current directory) :"); linput(stdin, str, 250); if (!strnotempty(str)) { strcatbuff(str, hts_gethome()); strcatbuff(str, "/websites/"); } if (strnotempty(str)) if ((str[strlen(str) - 1] != '/') && (str[strlen(str) - 1] != '\\')) strcatbuff(str, "/"); strcatbuff(stropt2, "-O \""); strcatbuff(stropt2, str); strcatbuff(stropt2, projname); strcatbuff(stropt2, "\" "); // Créer si ce n'est fait un index.html 1er niveau make_empty_index(str); // printf("\n"); printf("Enter URLs (separated by commas or blank spaces) :"); fflush(stdout); linput(stdin, urls, 250); if (strnotempty(urls)) { while((a = strchr(urls, ','))) *a = ' '; while((a = strchr(urls, '\t'))) *a = ' '; // Action printf("\nAction:\n"); switch (help_query ("Mirror Web Site(s)|Mirror Web Site(s) with Wizard|Just Get Files Indicated|Mirror ALL links in URLs (Multiple Mirror)|Test Links In URLs (Bookmark Test)|Update/Continue a Mirror", 1)) { case 1: break; case 2: strcatbuff(stropt, "W"); break; case 3: strcatbuff(stropt2, "--get "); break; case 4: strcatbuff(stropt2, "--mirrorlinks "); break; case 5: strcatbuff(stropt2, "--testlinks "); break; case 6: strcatbuff(stropt2, "--update "); break; case 0: return; break; } // Proxy printf("\nProxy (return=none) :"); linput(stdin, str, 250); if (strnotempty(str)) { while((a = strchr(str, ' '))) *a = ':'; // port if (!strchr(jump_identification_const(str), ':')) { char str2[256]; printf("\nProxy port (return=8080) :"); linput(stdin, str2, 250); strcatbuff(str, ":"); if (strnotempty(str2) == 0) strcatbuff(str, "8080"); else strcatbuff(str, str2); } strcatbuff(stropt2, "-P "); strcatbuff(stropt2, str); strcatbuff(stropt2, " "); } // Display strcatbuff(stropt2, " -%v "); // Wildcards printf ("\nYou can define wildcards, like: -*.gif +www.*.com/*.zip -*img_*.zip\n"); printf("Wildcards (return=none) :"); linput(stdin, strwild, 250); // Options do { printf ("\nYou can define additional options, such as recurse level (-r<number>), separated by blank spaces\n"); printf("To see the option list, type help\n"); printf("Additional options (return=none) :"); linput(stdin, str, 250); if (strfield2(str, "help")) { help("httrack", 2); } else if (strnotempty(str)) { strcatbuff(stropt2, str); strcatbuff(stropt2, " "); } } while(strfield2(str, "help")); { int argc = 1; int g = 0; int i = 0; // printf("\n"); if (strlen(stropt) == 1) stropt[0] = '\0'; // aucune sprintf(cmd, "%s %s %s %s", urls, stropt, stropt2, strwild); printf("---> Wizard command line: httrack %s\n\n", cmd); printf("Ready to launch the mirror? (Y/n) :"); fflush(stdout); linput(stdin, str, 250); if (strnotempty(str)) { if (!((str[0] == 'y') || (str[0] == 'Y'))) return; } printf("\n"); // couper en morceaux argv[0] = strdup("winhttrack"); argv[1] = cmd; argc++; while(cmd[i]) { if (cmd[i] == '\"') g = !g; if (cmd[i] == ' ') { if (!g) { cmd[i] = '\0'; argv[argc++] = cmd + i + 1; } } i++; } hts_main(argc, argv); } //} else { // help("httrack",1); } /* Free buffers */ free(buffers); #undef urls #undef mainpath #undef projname #undef stropt #undef stropt2 #undef strwild #undef cmd #undef str #undef argv }
HTSEXT_API char* hts_getcategories(char* path, int type) { String categ = STRING_EMPTY; String profiles = STRING_EMPTY; char* rpath = path; find_handle h; inthash hashCateg = NULL; if (rpath[0]) { if (rpath[strlen(rpath)-1]=='/') { rpath[strlen(rpath)-1]='\0'; /* note: patching stored (inhash) value */ } } h = hts_findfirst(rpath); if (h) { String iname = STRING_EMPTY; if (type == 1) { hashCateg = inthash_new(127); StringCat(categ, "Test category 1"); StringCat(categ, "\r\nTest category 2"); } do { if (hts_findisdir(h)) { char BIGSTK line2[1024]; StringCopy(iname,rpath); StringCat(iname,"/"); StringCat(iname,hts_findgetname(h)); StringCat(iname,"/hts-cache/winprofile.ini"); if (fexist(StringBuff(iname))) { if (type == 1) { FILE* fp = fopen(StringBuff(iname), "rb"); if (fp != NULL) { int done=0; while(!feof(fp) && !done) { int n = linput(fp, line2, sizeof(line2) - 2); if (n > 0) { if (strfield(line2, "category=")) { if (*(line2+9)) { if (!inthash_read(hashCateg, line2+9, NULL)) { inthash_write(hashCateg, line2+9, 0); if (StringLength(categ) > 0) { StringCat(categ, "\r\n"); } unescapehttp(line2+9, &categ); } } done=1; } } } line2[0] = '\0'; fclose(fp); } } else { if (StringLength(profiles) > 0) { StringCat(profiles, "\r\n"); } StringCat(profiles, hts_findgetname(h)); } } } } while(hts_findnext(h)); hts_findclose(h); StringFree(iname); } if (hashCateg) { inthash_delete(&hashCateg); hashCateg = NULL; } if (type == 1) return StringBuffRW(categ); else return StringBuffRW(profiles); }
// lire cookies.txt // lire également (Windows seulement) les *@*.txt (cookies IE copiés) // !=0 : erreur int cookie_load(t_cookie * cookie, const char *fpath, const char *name) { char catbuff[CATBUFF_SIZE]; char buffer[8192]; // cookie->data[0]='\0'; // Fusionner d'abord les éventuels cookies IE #ifdef _WIN32 { WIN32_FIND_DATAA find; HANDLE h; char pth[MAX_PATH + 32]; strcpybuff(pth, fpath); strcatbuff(pth, "*@*.txt"); h = FindFirstFileA((char *) pth, &find); if (h != INVALID_HANDLE_VALUE) { do { if (!(find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!(find.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)) { FILE *fp = fopen(fconcat(catbuff, fpath, find.cFileName), "rb"); if (fp) { char cook_name[256]; char cook_value[1000]; char domainpathpath[512]; char dummy[512]; // char domain[256]; // domaine cookie (.netscape.com) char path[256]; // chemin (/) int cookie_merged = 0; // // Read all cookies while(!feof(fp)) { cook_name[0] = cook_value[0] = domainpathpath[0] = dummy[0] = domain[0] = path[0] = '\0'; linput(fp, cook_name, 250); if (!feof(fp)) { linput(fp, cook_value, 250); if (!feof(fp)) { int i; linput(fp, domainpathpath, 500); /* Read 6 other useless values */ for(i = 0; !feof(fp) && i < 6; i++) { linput(fp, dummy, 500); } if (strnotempty(cook_name) && strnotempty(cook_value) && strnotempty(domainpathpath)) { if (ident_url_absolute(domainpathpath, domain, path) >= 0) { cookie_add(cookie, cook_name, cook_value, domain, path); cookie_merged = 1; } } } } } fclose(fp); if (cookie_merged) remove(fconcat(catbuff, fpath, find.cFileName)); } // if fp } } while(FindNextFileA(h, &find)); FindClose(h); } } #endif // Ensuite, cookies.txt { FILE *fp = fopen(fconcat(catbuff, fpath, name), "rb"); if (fp) { char BIGSTK line[8192]; while((!feof(fp)) && (((int) strlen(cookie->data)) < cookie->max_len)) { rawlinput(fp, line, 8100); if (strnotempty(line)) { if (strlen(line) < 8000) { if (line[0] != '#') { char domain[256]; // domaine cookie (.netscape.com) char path[256]; // chemin (/) char cook_name[1024]; // nom cookie (MYCOOK) char BIGSTK cook_value[8192]; // valeur (ID=toto,S=1234) strcpybuff(domain, cookie_get(buffer, line, 0)); // host strcpybuff(path, cookie_get(buffer, line, 2)); // path strcpybuff(cook_name, cookie_get(buffer, line, 5)); // name strcpybuff(cook_value, cookie_get(buffer, line, 6)); // value #if DEBUG_COOK printf("%s\n", line); #endif cookie_add(cookie, cook_name, cook_value, domain, path); } } } } fclose(fp); return 0; } } return -1; }
/* Indexing system A little bit dirty, (quick'n dirty, in fact) But should be okay on most cases Tags and javascript handled (ignored) */ int index_keyword(const char* html_data,LLint size,const char* mime,const char* filename,const char* indexpath) { #if HTS_MAKE_KEYWORD_INDEX char catbuff[CATBUFF_SIZE]; int intag=0,inscript=0,incomment=0; char keyword[KEYW_LEN+32]; int i=0; // int WordIndexSize=1024; inthash WordIndexHash=NULL; FILE *tmpfp=NULL; // // Check parameters if (!html_data) return 0; if (!size) return 0; if (!mime) return 0; if (!filename) return 0; // Init ? if (hts_index_init) { remove(concat(catbuff,indexpath,"index.txt")); remove(concat(catbuff,indexpath,"sindex.html")); hts_index_init=0; } // Check MIME type if (is_html_mime_type(mime)) { inscript=0; } // FIXME - temporary fix for image/svg+xml (svg) // "IN XML" (html like, in fact :) ) else if ( (strfield2(mime,"image/svg+xml")) || (strfield2(mime,"image/svg-xml")) #if HTS_USEMMS || strfield2(mime,"video/x-ms-asf") #endif ) { inscript=0; } else if ( (strfield2(mime,"application/x-javascript")) || (strfield2(mime,"text/css")) ) { inscript=1; //} else if (strfield2(mime, "text/vnd.wap.wml")) { // humm won't work in many cases // inscript=0; } else return 0; // Temporary file tmpfp = tmpfile(); if (!tmpfp) return 0; // Create hash structure // Hash tables rulez da world! WordIndexHash=inthash_new(WordIndexSize); if (!WordIndexHash) return 0; // Start indexing this page keyword[0]='\0'; while(i<size) { if (strfield(html_data + i , "<script")) { inscript=1; } else if (strfield(html_data + i , "<!--")) { incomment=1; } else if (strfield(html_data + i , "</script")) { if (!incomment) inscript=0; } else if (strfield(html_data + i , "-->")) { incomment=0; } else if (html_data[i]=='<') { if (!inscript) intag=1; } else if (html_data[i]=='>') { intag=0; } else { // Okay, parse keywords if ( (!inscript) && (!incomment) && (!intag) ) { char cchar=html_data[i]; int pos; int len = (int) strlen(keyword); // Replace (ignore case, and so on..) if ((pos=strcpos(KEYW_TRANSCODE_FROM,cchar))>=0) cchar=KEYW_TRANSCODE_TO[pos]; if (strchr(KEYW_ACCEPT,cchar)) { /* Ignore some characters at begining */ if ((len>0) || (!strchr(KEYW_IGNORE_BEG,cchar))) { keyword[len++]=cchar; keyword[len]='\0'; } } else if ( (strchr(KEYW_SPACE,cchar)) || (!cchar) ) { /* Avoid these words */ if (len>0) { if (strchr(KEYW_NOT_BEG,keyword[0])) { keyword[(len=0)]='\0'; } } /* Strip ending . and so */ { int ok=0; while((len = (int) strlen(keyword)) && (!ok)) { if (strchr(KEYW_STRIP_END,keyword[len-1])) { /* strip it */ keyword[len-1]='\0'; } else ok=1; } } /* Store it ? */ if (len >= KEYW_MIN_LEN ) { hts_primindex_words++; if (inthash_inc(WordIndexHash,keyword)) { /* added new */ fprintf(tmpfp,"%s\n",keyword); } } keyword[(len=0)]='\0'; } else /* Invalid */ keyword[(len=0)]='\0'; if (len>KEYW_LEN) { keyword[(len=0)]='\0'; } } } i++; } // Reset temp file fseek(tmpfp,0,SEEK_SET); // Process indexing for this page { //FILE* fp=NULL; //fp=fopen(concat(indexpath,"index.txt"),"ab"); if (fp_tmpproject) { while(!feof(tmpfp)) { char line[KEYW_LEN + 32]; linput(tmpfp,line,KEYW_LEN + 2); if (strnotempty(line)) { intptr_t e=0; if (inthash_read(WordIndexHash,line,&e)) { //if (e) { char BIGSTK savelst[HTS_URLMAXSIZE*2]; e++; /* 0 means "once" */ if (strncmp((const char*)fslash(catbuff,(char*)indexpath),filename,strlen(indexpath))==0) // couper strcpybuff(savelst,filename+strlen(indexpath)); else strcpybuff(savelst,filename); // Add entry for this file and word fprintf(fp_tmpproject,"%s %d %s\n",line,(int) (KEYW_SORT_MAXCOUNT - e),savelst); hts_primindex_size++; //} } } } //fclose(fp); } } // Delete temp file fclose(tmpfp); tmpfp=NULL; // Clear hash table inthash_delete(&WordIndexHash); #endif return 1; }
/* Note: NOT utf-8 */ int optinclude_file(const char *name, int *argc, char **argv, char *x_argvblk, int *x_ptr) { FILE *fp; fp = fopen(name, "rb"); if (fp) { char line[256]; int insert_after = 1; /* first, insert after program filename */ while(!feof(fp)) { char *a, *b; int result; /* read line */ linput(fp, line, 250); hts_lowcase(line); if (strnotempty(line)) { /* no comment line: # // ; */ if (strchr("#/;", line[0]) == NULL) { /* right trim */ a = line + strlen(line) - 1; while(is_realspace(*a)) *(a--) = '\0'; /* jump "set " and spaces */ a = line; while(is_realspace(*a)) a++; if (strncmp(a, "set", 3) == 0) { if (is_realspace(*(a + 3))) { a += 4; } } while(is_realspace(*a)) a++; /* delete = ("sockets=8") */ if ((b = strchr(a, '='))) *b = ' '; /* isolate option and parameter */ b = a; while((!is_realspace(*b)) && (*b)) b++; if (*b) { *b = '\0'; b++; } /* a is now the option, b the parameter */ { int return_argc; char return_error[256]; char _tmp_argv[4][HTS_CDLMAXSIZE]; char *tmp_argv[4]; tmp_argv[0] = _tmp_argv[0]; tmp_argv[1] = _tmp_argv[1]; tmp_argv[2] = _tmp_argv[2]; tmp_argv[3] = _tmp_argv[3]; strcpybuff(_tmp_argv[0], "--"); strcatbuff(_tmp_argv[0], a); strcpybuff(_tmp_argv[1], b); result = optalias_check(2, (const char *const *) tmp_argv, 0, &return_argc, (tmp_argv + 2), return_error); if (!result) { printf("%s\n", return_error); } else { int insert_after_argc; /* Insert parameters BUT so that they can be in the same order */ /* temporary argc: Number of parameters after minus insert_after_argc */ insert_after_argc = (*argc) - insert_after; cmdl_ins((tmp_argv[2]), insert_after_argc, (argv + insert_after), x_argvblk, (*x_ptr)); *argc = insert_after_argc + insert_after; insert_after++; /* Second one */ if (return_argc > 1) { insert_after_argc = (*argc) - insert_after; cmdl_ins((tmp_argv[3]), insert_after_argc, (argv + insert_after), x_argvblk, (*x_ptr)); *argc = insert_after_argc + insert_after; insert_after++; } /* increment to nbr of used parameters */ /* insert_after+=result; */ } } } } } fclose(fp); return 1; } return 0; }