示例#1
0
void* getFunctionPtr(void* handle, const char* fncname_) {
  if (handle) {
    void* userfunction = NULL;
    char *fncname = strdupt(fncname_);

    /* Strip optional comma */
    char *comma;
    if ((comma = strchr(fncname, ',')) != NULL) {   /* empty arg */
      *comma++ = '\0';
    }
    
    /* the function itself */
    userfunction = (void*) DynamicGet(handle, (char*)fncname);

    freet(fncname);

    return userfunction;
  }
  return NULL;
}
示例#2
0
HTSEXT_API int hts_buildtopindex(httrackp* opt,const char* path,const char* binpath) {
  FILE* fpo;
  int retval=0;
  char BIGSTK rpath[1024*2];
  char *toptemplate_header=NULL,*toptemplate_body=NULL,*toptemplate_footer=NULL,*toptemplate_bodycat=NULL;
 	char catbuff[CATBUFF_SIZE];

  // et templates html
  toptemplate_header=readfile_or(fconcat(catbuff, binpath,"templates/topindex-header.html"),HTS_INDEX_HEADER);
  toptemplate_body=readfile_or(fconcat(catbuff, binpath,"templates/topindex-body.html"),HTS_INDEX_BODY);
  toptemplate_bodycat=readfile_or(fconcat(catbuff, binpath,"templates/topindex-bodycat.html"),HTS_INDEX_BODYCAT);
  toptemplate_footer=readfile_or(fconcat(catbuff, binpath,"templates/topindex-footer.html"),HTS_INDEX_FOOTER);
  
  if (toptemplate_header && toptemplate_body && toptemplate_footer && toptemplate_bodycat) {
    
    strcpybuff(rpath,path);
    if (rpath[0]) {
      if (rpath[strlen(rpath)-1]=='/')
        rpath[strlen(rpath)-1]='\0';
    }
    
    fpo=fopen(fconcat(catbuff, rpath,"/index.html"),"wb");
    if (fpo) {
      find_handle h;
      verif_backblue(opt,concat(catbuff, rpath,"/"));    // générer gif
      // Header
      fprintf(fpo,toptemplate_header,
        "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
        );
      
      /* Find valid project names */
      h = hts_findfirst(rpath);
      if (h) {
        struct topindex_chain * chain=NULL;
        struct topindex_chain * startchain=NULL;
        String iname = STRING_EMPTY;
        int chainSize = 0;
        do {
          if (hts_findisdir(h)) {
            StringCopy(iname,rpath);
            StringCat(iname,"/");
            StringCat(iname,hts_findgetname(h));
            StringCat(iname,"/index.html");
            if (fexist(StringBuff(iname))) {
              int level = 0;
              char* category = NULL;
              struct topindex_chain * oldchain=chain;
              
              /* Check for an existing category */
              StringCopy(iname,rpath);
              StringCat(iname,"/");
              StringCat(iname,hts_findgetname(h));
              StringCat(iname,"/hts-cache/winprofile.ini");
              if (fexist(StringBuff(iname))) {
                category = hts_getcategory(StringBuff(iname));
                if (category != NULL) {
                  if (*category == '\0') {
                    freet(category);
                    category = NULL;
                  }
                }
              }
              if (category == NULL) {
                category = strdupt("No categories");
                level = 1;
              }

              chain=calloc(sizeof(struct topindex_chain), 1);
              chainSize++;
              if (!startchain) {
                startchain=chain;
              }
              if (chain) {
                if (oldchain) {
                  oldchain->next=chain;
                }
                chain->next=NULL;
                strcpybuff(chain->name, hts_findgetname(h));
                chain->category = category;
                chain->level = level;
              }
            }
            
          }
        } while(hts_findnext(h));
        hts_findclose(h);
        StringFree(iname);
        
        /* Sort chain */
        {
          struct topindex_chain** sortedElts = (struct topindex_chain**) calloct(sizeof(topindex_chain*), chainSize);
          assertf(sortedElts != NULL);
          if (sortedElts != NULL) {
            int i;
            char* category = "";
            
            /* Build array */
            struct topindex_chain * chain = startchain;
            for(i = 0 ; i < chainSize ; i++) {
              assertf(chain != NULL);
              sortedElts[i] = chain;
              chain = chain->next;
            }
            qsort(sortedElts, chainSize, sizeof(topindex_chain*), sortTopIndexFnc);
            
            /* Build sorted index */
            for(i = 0 ; i < chainSize ; i++) {
              char BIGSTK hname[HTS_URLMAXSIZE*2];
              strcpybuff(hname,sortedElts[i]->name);
              escape_check_url(hname);

              /* Changed category */
              if (strcmp(category, sortedElts[i]->category) != 0) {
                category = sortedElts[i]->category;
                fprintf(fpo,toptemplate_bodycat, category);
              }
              fprintf(fpo,toptemplate_body,
                hname,
                sortedElts[i]->name
                );
            }
            
            /* Wipe elements */
            for(i = 0 ; i < chainSize ; i++) {
              freet(sortedElts[i]->category);
              freet(sortedElts[i]);
              sortedElts[i] = NULL;
            }
            freet(sortedElts);
            
            /* Return value */
            retval=1;
          }
        }
        
      }
      
      // Footer
      fprintf(fpo,toptemplate_footer,
        "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
        );
      
      fclose(fpo);
      
    }
    
  }

  if (toptemplate_header)
    freet(toptemplate_header);
  if (toptemplate_body)
    freet(toptemplate_body);
  if (toptemplate_footer)
    freet(toptemplate_footer);
  if (toptemplate_body)
    freet(toptemplate_body);
  
  return retval;
}