// enregistrement lien lpos dans les 3 tables hash1..3 void hash_write(hash_struct * hash, int lpos) { /* first entry: destination filename (lowercased) */ inthash_write(hash->sav, hash->liens[lpos]->sav, lpos); /* second entry: URL address and path */ inthash_write(hash->adrfil, (char*) hash->liens[lpos], lpos); /* third entry: URL address and path before redirect */ if (hash->liens[lpos]->former_adr) { // former_adr existe? inthash_write(hash->former_adrfil, (char*) hash->liens[lpos], lpos); } }
// Increment pos value, create one if necessary (=0) // (==1 : created) int inthash_inc(inthash hashtable, const char *name) { intptr_t value = 0; int r = 0; if (inthash_read(hashtable, name, &value)) { value++; } else { /* create new value */ value = 0; r = 1; } inthash_write(hashtable, name, value); return (r); }
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); }