home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / tools / cd / indexcd / bin / sources.lha / sources / Find.c < prev    next >
C/C++ Source or Header  |  1997-02-11  |  3KB  |  146 lines

  1. /* dcc HD1:IndexCD/Find.c */
  2.  
  3. char *Titolo = "$VER: Cerca v1.0 (11-02-1996) © by Claudio Buraglio";
  4.  
  5. #include    <stdio.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. char    work[255];
  10. char    line[255];
  11. char    buf[255];
  12. char    exe[255];
  13.  
  14. char    *lis1    =    "LIST ICD:Index/#?.index LFORMAT \"ICD:Bin/IndexAG >NIL: %p%s";
  15. char    *lis2    =    "-A\" TO T:Index.temp";
  16.  
  17. char    *AGline1 = "@database Aminet\n";
  18. char    *AGline2 = "@node main \"Find... '";
  19.  
  20. char    *AGline3 = "'\"\n\n@{\"Filename          \" LINK ICD:Bin/Help.guide/FILENAME} Directory  Size CD @{\"Description.\" LINK ICD:Bin/Help.guide/DESCRIPTION }\n";
  21. char    *AGline4 = "-----------------------------------------------------------\n";
  22.  
  23.  
  24. FILE    *fpr;        // Read
  25. FILE    *fpw;        // Write
  26. FILE    *fps;        // Source
  27. FILE    *fpc;        // Counter
  28.  
  29.  
  30. main(int arglen, char **argptr)
  31. {
  32.     printf("\n%s\n\n",Titolo+6);
  33.  
  34.     strcpy(buf, argptr[0]);
  35.     char *ptr = strrchr(buf, '/');
  36.     if(*ptr == '/')
  37.     {
  38.         *++ptr = 0;
  39.         sprintf(line, "c:Assign >NIL: ICD: \"%s\"\n", buf);
  40.         system(line);
  41.     }
  42.     else
  43.     {
  44.         system("c:Assign >NIL: ICD: \"\"");
  45.     }
  46.     Programma();
  47.     return(0);
  48. }
  49.  
  50. wbmain()
  51. {
  52.     system("c:Assign >NIL: ICD: \"\"");
  53.     Programma();
  54. }
  55.  
  56. Programma()
  57. {
  58.     time_t t = time(NULL);
  59.     struct tm *tp = localtime(&t);
  60.     char ora [20];    char idx [20];    char stf [20];
  61.     strftime(ora, sizeof(ora) - 1, "T:%H%M%S.guide",  tp);
  62.     strftime(idx, sizeof(ora) - 1, "T:%H%M%S.index", tp);
  63.     strftime(stf, sizeof(ora) - 1, "T:%H%M%S.string", tp);
  64.  
  65.     strcpy(exe, "ICD:Bin/GetString >NIL: ");
  66.     strcat(exe, stf);
  67.     system(exe);
  68.  
  69.     if (fpr = fopen(stf, "r"))
  70.     {
  71.         if (fgets(buf, sizeof(buf), fpr))
  72.         {
  73.             sprintf(exe,"%s %s %s %s\n", lis1, ora, buf, lis2);
  74.             system(exe);
  75.  
  76.             system("c:sort T:Index.temp T:Index.tmp");
  77.             remove("T:Index.temp");
  78.  
  79. // Copia l'header del file hhmmss.guide nella directory T:
  80.  
  81.             if (fpw = fopen(ora, "w"))
  82.             {
  83.                 fputs(AGline1 ,fpw);
  84.                 fputs(AGline2 ,fpw);
  85.                 fputs(buf ,fpw);
  86.                 fputs(AGline3 ,fpw);
  87.                 fputs(AGline4 ,fpw);
  88.                 fclose(fpw);
  89.             }
  90.  
  91.  
  92. // Esegue la ricerca su tutti gli archivi
  93.  
  94.             system("Execute T:Index.tmp");
  95.  
  96. // Crea il footer del file hhmmss.guide
  97.  
  98.             if (fpw = fopen(ora, "a"))
  99.             {
  100.                 if (fpc = fopen("T:Counter.temp", "r"))
  101.                 {
  102.                     int tot;
  103.                     fread(buf, 4, 1, fpc);
  104.                     int clc;
  105.                     tot = buf[0];    tot = tot & 0xff;    tot = tot << 24;
  106.                     clc = buf[1];    clc = clc & 0xff;    clc = clc << 16;
  107.                     tot = tot + clc;
  108.                     clc = buf[2];    clc = clc & 0xff;    clc = clc << 8;
  109.                     tot = tot + clc;
  110.                     clc = buf[3];    clc = clc & 0xff;
  111.                     tot = tot + clc;
  112.  
  113.                     fprintf(fpw, "\n%d files listed\n\n@ENDNODE\n", tot);
  114.                     fclose(fpc);
  115.                 }
  116.                 while(fgets(buf, sizeof(buf), fps) != NULL)
  117.                 {
  118.                     fputs(buf, fpw);
  119.                 }
  120.                 fclose(fpw);
  121.             }
  122.  
  123.             remove("T:Counter.temp");
  124. //            remove("T:Index.tmp");
  125.  
  126. // Visualizza il risultato
  127.  
  128.             strcpy(exe, "SYS:Utilities/AmigaGuide ");
  129.             strcat(exe, ora);
  130.             system(exe);
  131.             remove(ora);
  132.         }
  133.         else
  134.         {
  135.             puts("Nothing to find.");
  136.         }
  137.         fclose(fpr);
  138.     }
  139.     else
  140.     {
  141.         printf("Error! %s not found!\n", stf);
  142.     }
  143.     remove(stf);    // File che contiene la stringa
  144.     system("c:Delete >NIL: T:Command-#?");
  145. }
  146.