home *** CD-ROM | disk | FTP | other *** search
/ Tutto per Internet / Internet.iso / soft95 / Varie / server / SRCHX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-15  |  3.9 KB  |  186 lines

  1. #include <windows.h>
  2. #include <iostream.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #include "httpext.h"
  7. #include "Srch.h"
  8.                        
  9. // This opens each file and looks for the search info
  10. void CSrch::PrintFindData(WIN32_FIND_DATA *findData, char *findmask)
  11. {
  12.        char *pszFilename;
  13.        char cFullname[256];
  14.  
  15.     GetFullPathName(findData->cFileName, 256, cFullname, &pszFilename);
  16.  
  17.     FILE *hFile;
  18.     char* pszFileInput = (char*)malloc(256);
  19.     BOOL bTrigger1 = FALSE;
  20.  
  21.        if( (hFile = fopen( cFullname, "r" )) != NULL )
  22.            {                
  23.         while ( fgets( pszFileInput, 256, hFile ) != NULL)
  24.             {
  25.             _strupr(pszFileInput);    
  26.             if (strstr(pszFileInput, findmask) != NULL)
  27.                 {
  28.                 if (!bTrigger1) 
  29.                     {
  30.                     sHitCount++;
  31.                     sHitStruct[sHitCount].sHits = 0;
  32.                     sHitStruct[sHitCount].cHREF = (char*)VirtualAlloc(NULL, 
  33.                             256, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);    
  34.  
  35.                     strcpy(sHitStruct[sHitCount].cHREF, pszAlias);
  36.                     
  37.                     strcat(sHitStruct[sHitCount].cHREF,
  38.                          Substituteb(cFullname + strlen(cStartDir)));
  39.  
  40.                     bTrigger1 = TRUE;
  41.                     }
  42.  
  43.                 sHitStruct[sHitCount].sHits++; 
  44.                           
  45.                 bHitSomething = TRUE; 
  46.                 sCounter++;
  47.                 if (sCounter > 255)
  48.                     {
  49.                     bOverflow = TRUE;
  50.                     break;
  51.                     }
  52.                 }     
  53.             }           
  54.           fclose( hFile );
  55.            }
  56.     
  57.     free(pszFileInput);
  58.     
  59.  
  60. }
  61.  
  62. // This fn will change a UNC path into a WWW path
  63. const char* CSrch::Substituteb(LPSTR lpSubstIn)
  64. {
  65.     char* cTemp;
  66.     cTemp = lpSubstIn;
  67.  
  68.     while(*cTemp)
  69.         {
  70.         if (*cTemp == '\\') *cTemp = '/';
  71.         cTemp++;
  72.         }
  73.  
  74.     return lpSubstIn;
  75.  
  76. }
  77.  
  78.  
  79. // recursive directory scanner. 
  80. void CSrch::ListDirectoryContents( char *dirname, char *filemask, char *findmask)
  81. {
  82.     if(bOverflow) return;
  83.  
  84.     char *pszFilename;
  85.     char cCurdir[256];
  86.     char cFullname[256];
  87.     HANDLE hFile;
  88.     WIN32_FIND_DATA findData;
  89.     
  90.     if (!GetCurrentDirectory(256, cCurdir)) return;
  91.  
  92.     if (strcmp(dirname, ".") && strcmp (dirname, ".."))
  93.             {
  94.             if (!SetCurrentDirectory(dirname)) return;
  95.             }
  96.  
  97.     else return;
  98.  
  99.     if (!GetFullPathName(filemask, 256, cFullname, &pszFilename)) return;
  100.   
  101.     if (sCounter > 255) 
  102.         {
  103.         bOverflow = TRUE;
  104.         return;
  105.         
  106.         }
  107.  
  108.     hFile = FindFirstFile( filemask, &findData);
  109.     while (hFile != INVALID_HANDLE_VALUE)
  110.             {
  111.             PrintFindData(&findData, findmask);
  112.             
  113.             if (!FindNextFile(hFile, &findData) ) break;
  114.             }
  115.  
  116.     FindClose(hFile);
  117.     
  118.     hFile = FindFirstFile( "*.*", &findData);
  119.     while (hFile != INVALID_HANDLE_VALUE)
  120.             {
  121.             if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  122.                     {
  123.                     ListDirectoryContents(findData.cFileName, filemask, findmask);
  124.                     }
  125.  
  126.             if (!FindNextFile(hFile, &findData) ) break;
  127.             }
  128.  
  129.     SetCurrentDirectory(cCurdir);
  130. }
  131.  
  132.  
  133. // converts a two digit hex value into an int.
  134. int CSrch::Hex2Int(char *pC) 
  135. {
  136.     int Hi;
  137.     int Lo;
  138.     int Result;
  139.  
  140.     Hi = pC[0];
  141.     if ('0'<=Hi && Hi<='9')         Hi -= '0';
  142.  
  143.     else if ('a'<=Hi && Hi<='f')     Hi -= ('a'-10);
  144.         
  145.     else if ('A'<=Hi && Hi<='F')     Hi -= ('A'-10);
  146.         
  147.     Lo = pC[1];
  148.     if ('0'<=Lo && Lo<='9')         Lo -= '0';
  149.  
  150.     else if ('a'<=Lo && Lo<='f')    Lo -= ('a'-10);
  151.         
  152.     else if ('A'<=Lo && Lo<='F')    Lo -= ('A'-10);
  153.         
  154.     Result = Lo + 16*Hi;
  155.     return Result;
  156. }
  157.  
  158. // prepares a hex value from an HTML doc to be converted into an int.
  159. void CSrch::DecodeHex(char *p) 
  160. {
  161.     char *pD;
  162.  
  163.     pD = p;
  164.     while (*p) 
  165.         {
  166.         if (*p=='%') 
  167.             {
  168.             p++;
  169.             if (isxdigit(p[0]) && isxdigit(p[1])) 
  170.                 {
  171.                 *pD++ = (char) Hex2Int(p);
  172.                 p += 2;
  173.  
  174.                 }
  175.             }
  176.          else *pD++ = *p++;
  177.         
  178.         }
  179.  
  180.     *pD = '\0';
  181. }
  182.  
  183.              
  184.  
  185.                                   
  186.