⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doxysearch.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        int rank=(int)(d->rank*100+0.5);        if (rank==0) rank++;        printf("        <tr><td align=\"right\"><b><font color=#%2x00%2x>%d</font></b>"               "</td><td><a href=\"%s/%s\">%s</a></td></tr>\n",               rank*2+55, 255-rank*2, rank,                d->fileInfo->url, htmlName, linkName);        pageEntries--;        if (d->fileInfo->f != 0)        {          fclose(d->fileInfo->f);          d->fileInfo->f = 0;        }      }      else       {        skipEntries--;      }    }    printf("      </table>\n"           "    </td>\n"           "  </tr>\n"           "  <tr><td colspan=2 bgcolor=\"#4040c0\"><center>&nbsp;");        if (page>0)    {      printf("<a href=\"%s?page=%d&which=%s&what=%s&query=%s\">"             "<font color=\"ffffff\">prev</font></a>&nbsp;",              cgiBin, page-1,               wordOnly?"word":"doc",               nameOnly?"name":"string",              encQueryInput);    }    int startPage = page-5 < 0 ? 0 : page-5;    int endPage   = page+6 > numPages ? numPages : page+5;    if (endPage-startPage>1)    {      for (i=startPage;i<endPage;i++)      {        if (i!=page)        {          printf("<a href=\"%s?page=%d&which=%s&what=%s&query=%s\">"              "<font color=\"ffffff\">%d</font></a>&nbsp;",              cgiBin, i,               wordOnly?"word":"doc",               nameOnly?"name":"string",               encQueryInput, i+1);        }        else        {          printf("<b><font color=\"ffffff\">%d</font></b></a>&nbsp;",i+1);        }      }    }    if (page<numPages-1)    {      printf("<a href=\"%s?page=%d&which=%s&what=%s&query=%s\">"             "<font color=\"ffffff\">next</font></a>",              cgiBin, page+1,               wordOnly?"word":"doc",               nameOnly?"name":"string",              encQueryInput);    }    printf("  &nbsp;</center></td></tr>\n"           "  <tr bgcolor=#ffffff>\n"           "    <td colspan=2><p>\n"           "       Occurrence count: ");    WordInfo *wi=wordList.first;    while (wi)    {      printf("<b><font color=#ff0000>%s</font></b> ",wi->word);      if (wi->freq>0) printf("(%d)",wi->freq); else printf("(ignored)");      wi=wi->next;      if (wi)       {        if (wi->next) printf(", "); else printf(" and ");      }    }    printf("\n"           "    </td>\n"           "  </tr>\n");  }  printf("</table>\n</center>\n</form>\n");  printFooter();  free(docPtrArray);}//----------------------------------------------------------------------------void generateHelpPage(){  printHeader();  printf("<h3>Doxysearch help page</h3>\n"         "<b>Basic search instructions</b>\n"         "<ul>\n"         "Just type in one or more words or fragments of words and press the "         "search button. Doxysearch will return a list of functions and class names, "         "whose documentation or name matches one or more of the words. "         "Documents containing more matches will appear earlier in the list. "         "\n"         "</ul>\n"         "<b>Search modes</b>\n"         "<ul>\n"         "Doxysearch has four search modes. From least restrictive to most "         "restrictive they are:\n"         "  <ul><p>\n"         "    <li><em>Search for strings in the documentation:</em>\n"         "      The words you type will be searched in the documentation as substrings."          "      Typing the word &quot;<b>the</b>&quot; for example, will find "         "      documents containing the words &quot;<b>the</b>&quot;, "         "      &quot;<b>the</b>re&quot;, and &quot;fea<b>the</b>r&quot;.<p>\n"         "    <li><em>Search for words in the documentation:</em>\n"         "      The words you type will be searched in the documentation as words."         "      Typing the word &quot;<b>the</b>&quot; for example, will look "         "      for documents containing the word &quot;<b>the</b>&quot; and not for"         "      documents containing the word &quot;<b>the</b>re&quot;.<p>\n"         "    <li><em>Search for strings in the function and class names:</em>\n"         "      The words you type will be searched in the function and class names "         "      as substrings. Typing the word &quot;<b>set</b>&quot; for example, will "         "      result in a list of links to the documentation of all functions and classes "         "      that contain the word &quot;<b>set</b>&quot; in the name, such as the function "         "      <code><b>set</b>Cursor</code>.<p>\n"         "    <li><em>Search for words in the function and class names:</em>\n"         "      The words you type will be matched against the function and class names."         "      The result will be a list of links to the documentation of all function "         "      and class names that are equal to one of the words.\n"         "  </ul>\n"         "</ul>\n"         "<b>Requiring/Excluding words</b>\n"         "<ul>\n"         "  Often you will know a word that will be guaranteed to appear in a document "         "  for which you are searching. If this is the case, require that the word appears "         "  in all of the results by attaching a &quot;<b>+</b>&quot; to the beginning of "         "  the word. You can quickly reject results by adding a word that appears only "         "  in unwanted documents with a &quot;<b>-</b>&quot; before it."         "</ul>\n"        );           printFooter();}//----------------------------------------------------------------------------void mergeSearchResults(SearchResults *totalResults,                        SearchResults *sr,int mode){  SearchDoc *otd = 0,            *td  = totalResults->docList,             *d   = sr->docList;  totalResults->totalFreq += sr->totalFreq;  if (!d) return; // nothing to add  while (td && d)  {    int otdih = otd ? otd->fileInfo->index : -1,        otdil = otd ? otd->index : -1,         tdih  = td->fileInfo->index,        tdil  = td->index,         dih   = d->fileInfo->index,        dil   = d->index;    if (tdih==dih && tdil==dil) // combine results    {      if (mode != EXCLUDE)      {        td->rank += d->rank;        td->rank *= 2;          // put extra emphasis on multiple word matches        td->freq += d->freq;        d = d->next;        otd = td; td = td->next;      }      else // mode == EXCLUDE => remove entry from results      {        SearchDoc *tmp=td;        td=td->next;        if (otd) otd->next=td; else totalResults->docList = td;        delete tmp;      }    }    else if ((otdih<dih || (otdih==dih && otdil<dil)) &&             (tdih>dih  || (tdih==dih && tdil>dil))) // insert    {      if (mode == NORMAL)      {        SearchDoc *nd = new SearchDoc(*d);        if (otd) otd->next = nd; else totalResults->docList = nd;        nd->next = td;        td = nd;      }      d = d->next;    }    else if (tdih<dih || (tdih==dih && tdil<dil)) // remove or skip    {      if (mode == INCLUDE)      {        SearchDoc *tmp=td;        td=td->next;        if (otd) otd->next=td; else totalResults->docList = td;        delete tmp;      }      else // mode == EXCLUDE or mode == NORMAL      {        otd = td; td = td->next;      }    }  }  if (td==0 && d && mode==NORMAL) // append rest of sr to totalResults  {    while (d)    {      SearchDoc *nd = new SearchDoc(*d);      if (otd) otd->next = nd; else totalResults->docList = nd;      nd->next = 0;      d = d->next;      otd = nd;    }   }  if (td && d==0 && mode==INCLUDE) // delete the rest of the results  {    while (td)    {      SearchDoc *tmp=td;      td=td->next;      if (otd) otd->next = td; else totalResults->docList = td;      delete tmp;    }  }}//----------------------------------------------------------------------------int asciiToHex(char c){  char l=tolower(c);  if (l>='0' && l<='9')     return l-'0';  else if (l>='a' && l<='f')    return l+10-'a';  else // invalid hex char    return 0;}//----------------------------------------------------------------------------void fileToBuf(const char *name, char **buf){  FILE *f;  struct stat file_stats;  if ((f=fopen(name,"rb"))==NULL) return;  if (stat(name,&file_stats)==-1)  {    message("Error: could not fstat file %s\n",name);    exit(1);  }  unsigned int len=file_stats.st_size;  if ((*buf=(char *)malloc(len+1))==NULL)   {    message("Error: out of memory\n");    exit(1);  }  if (fread(*buf,1,len,f)!=len)  {    message("Error: could not read file %s\n",name);    exit(1);  }  (*buf)[len]='\0';  fclose(f);}//----------------------------------------------------------------------------void getConfig(const char *s){  int l;  char configFile[MAXSTRLEN];  strcpy(configFile,s);  strcat(configFile,"/search.cfg");  FILE *f;  if ((f=fopen(configFile,"r"))==NULL)  {    message("Error: could not open config file %s\n",configFile);    exit(1);  }      // get the URL to the documentation  fgets(firstDocUrl,MAXSTRLEN,f);  l=strlen(firstDocUrl)-1;  if (firstDocUrl[l]=='\n') firstDocUrl[l]='\0';  l=strlen(firstDocUrl);  if (firstDocUrl[l]=='/') firstDocUrl[l]='\0';    // get the URL to the cgi script  fgets(cgiBin,MAXSTRLEN,f);  l=strlen(cgiBin)-1;  if (cgiBin[l]=='\n') cgiBin[l]='\0';    fclose(f);    char headerFile[MAXSTRLEN];  strcpy(headerFile,s);#if defined(_WIN32)  strcat(headerFile,"\\header.html");#else  strcat(headerFile,"/header.html");#endif  fileToBuf(headerFile,&headerBuf);    char footerFile[MAXSTRLEN];  strcpy(footerFile,s);#if defined(_WIN32)  strcat(footerFile,"\\footer.html");#else  strcat(footerFile,"/footer.html");#endif  fileToBuf(footerFile,&footerBuf);  }//----------------------------------------------------------------------------// copy and convert string to lower casevoid strlowercpy(char *d,const char *s){  while (*s!='\0') *d++=tolower(*s++); *d='\0';}//----------------------------------------------------------------------------int main(int argc,char **argv){#ifdef PROFILING  struct timeval tv_start,tv_end;  gettimeofday(&tv_start,0);#endif  char *argString=getenv("QUERY_STRING");  if (argc==1)  {    message("Error: invalid number of arguments. "            "Usage: %s doc_path [doc_path ...]",argv[0]);    exit(1);  }  // read the configuration file for this instance of the search engine  getConfig(argv[1]);  if (!argString)   {    printHeader();    printSearchPage();    printFooter();    exit(1);  }    SearchResults tsr;  // parse cgi arguments  char *arg=strtok(argString,"&");  char *query = 0;  char *what  = 0;  char *which = 0;  char *help  = 0;  page = 0;  while (arg)  {    int namelen=strcspn(arg,"=");    if      (!strncmp(arg,"query", namelen)) query = &arg[namelen+1];    else if (!strncmp(arg,"what",  namelen)) what  = &arg[namelen+1];    else if (!strncmp(arg,"which", namelen)) which = &arg[namelen+1];    else if (!strncmp(arg,"help",  namelen)) help  = &arg[namelen+1];    else if (!strncmp(arg,"page",  namelen)) page  = atoi(&arg[namelen+1]);    arg=strtok(0,"&");  }  wordOnly=which ? strcmp(which,"word")==0 : FALSE;  nameOnly=what  ? strcmp(what, "name")==0 : FALSE;  helpOnly=help  ? strcmp(help, "on"  )==0 : FALSE;    // store encoded query string  if (query) strcpy(encQueryInput,query); else encQueryInput[0]='\0';  // convert query string to original input  char *s=query,*d=queryInput;  if (s)  {    while (*s!='\0')    {      char c=*s++;      if (c=='+')         *d++=' ';      else if (c=='%')      {        *d=asciiToHex(*s++)*16;        *d+=asciiToHex(*s++);        d++;      }      else        *d++=c;    }  }  *d='\0';  if (helpOnly)   {    generateHelpPage();    exit(1);  }  // read search index files  int argIndex=0;  for (argIndex=1;argIndex<argc;argIndex++)  {    char configFile[MAXSTRLEN];    strcpy(configFile,argv[argIndex]);#if defined(_WIN32)    strcat(configFile,"\\search.cfg");#else    strcat(configFile,"/search.cfg");#endif    char indexFile[MAXSTRLEN];    strcpy(indexFile,argv[argIndex]);#if defined(_WIN32)    strcat(indexFile,"\\search.idx");#else    strcat(indexFile,"/search.idx");#endif    FileInfo *fi=fileList.add();    FILE *g;        strcpy(fi->name,indexFile);    if ((fi->f=fopen(indexFile,"rb"))==NULL)    {      message("Error: could not open index file %s\n",indexFile);      exit(1);    }     if ((g=fopen(configFile,"r"))==NULL)    {      message("Error: could not open config file %s\n",configFile);      exit(1);    }        // get URL to the documentation    char tmp[MAXSTRLEN];    fgets(tmp,MAXSTRLEN,g);    if (tmp[strlen(tmp)-1]=='\n') tmp[strlen(tmp)-1]='\0';    if (tmp[strlen(tmp)-1]=='/')  tmp[strlen(tmp)-1]='\0';    fi->url = new char[strlen(tmp)+1];    strcpy(fi->url,tmp);    fclose(g);        // read & check the format of the search index file    fseek(fi->f,0,SEEK_SET);    char header[5];    if (fread(header,1,4,fi->f)!=4)     {      message("Error: Couldn't read header of the index file %s\n",indexFile);      exit(1);    }    header[4]='\0';    if (strcmp(header,"DOXI"))    {      message("Error: Index file %s has an unknown format\n",indexFile);      exit(1);    }    // read and store the offset to the link index    fi->refOffset=readInt(fi->f);    fclose(fi->f);    fi->f = 0;  }  char *word;  char wordString[MAXSTRLEN];  // search for included words  strlowercpy(wordString,queryInput);  word=strtok(wordString," ");   bool first=TRUE;  while (word)  {    if (word[0]=='+') // + character => include    {      SearchResults sr;      searchIndex(&word[1],&sr);      if (first)        mergeSearchResults(&tsr,&sr,NORMAL);      else        mergeSearchResults(&tsr,&sr,INCLUDE);      first=FALSE;    }    word=strtok(0," ");  }  // search for normal words  strlowercpy(wordString,queryInput);  word=strtok(wordString," ");   while (word)  {    if (word[0]!='-' && word[0]!='+') // normal word    {      SearchResults sr;      searchIndex(word,&sr);      mergeSearchResults(&tsr,&sr,NORMAL);    }    word=strtok(0," ");  }  // search for excluded words  strlowercpy(wordString,queryInput);  word=strtok(wordString," ");   while (word)  {    if (word[0]=='-') // - character => exclude    {      SearchResults sr;      searchIndex(&word[1],&sr);      mergeSearchResults(&tsr,&sr,EXCLUDE);    }    word=strtok(0," ");  }  // write results to HTML page  generateResults(&tsr);  free(headerBuf);  free(footerBuf);#ifdef PROFILING  gettimeofday(&tv_end,0);  printf("processing time %3.3f msec\n",      ((tv_end.tv_sec-tv_start.tv_sec)*1000000+        tv_end.tv_usec-tv_start.tv_usec)/1000.0        );#endif  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -