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

  1. /* dcc HD1:IndexCD/Bin/IndexDirectory.c */
  2.  
  3. char *Titolo = "$VER: IndexDirectory v1.0 (15-02-1997) © by Claudio Buraglio";
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <time.h>
  8.  
  9. char    buff[255];
  10. char    line[255];
  11. char    work[126];
  12. char    ora [20];
  13. char    font[126];
  14.  
  15. char    LastLine[126];
  16.  
  17. char    *ConfigFile    ="S:Aminet-Config";
  18.  
  19. char    *TempList="T:List.temp";
  20. char    *IndexAG ="T:IndiceEARSAN.guide";
  21. char  *AGHead1 ="@database Directory\n@node main \"";
  22. char    *AGHeadB ="          \"\n@font ";
  23. char    *AGHead2 ="           ";
  24. char    *AGHead3 ="\n\n";
  25. char  *AGHead4 ="           \n";
  26.  
  27. char    *AGfoot  ="\n@ENDNODE\n";
  28.  
  29. FILE *fpr;
  30. FILE *fpw;
  31. char *ptr;
  32.  
  33. int Count;
  34. int Size;
  35.  
  36. strpaste(char *d, char *s)
  37. {
  38.     while(*s != 0)
  39.         *d++ = *s++;
  40.     return(d);
  41. }
  42.  
  43.  
  44. int main(int arglen, char **argptr)    // L'argomento e' AMINETxx.indice
  45. {
  46.     printf("\n%s\n\n",Titolo+6);
  47.  
  48.     LoadConfiguration();
  49.     ptr = strchr(font, ' ');
  50.     ptr++;
  51.     int Size = strtol(ptr,0,0);
  52.  
  53.     unsigned char *ptr = strchr(argptr[1], '_');
  54.     ptr++;
  55.     int i = 0;
  56.     while    (*ptr != '.')
  57.     {
  58. //         AGHeadB[i] = *ptr;
  59.          AGHeadB[i++] = *ptr++;
  60.     }
  61.  
  62.     if (arglen != 2)
  63.     {
  64.         printf("Missing argument.\n\n");
  65.     }
  66.  
  67.     else
  68.     {
  69.        time_t t = time(NULL);                    // in 'ora' l'ora
  70.        struct tm *tp = localtime(&t);
  71.        strftime(ora, sizeof(ora) - 1, "T:%H%M%S.guide",  tp);
  72.  
  73.         if (fpr = fopen(argptr[1], "r"))        // Apre l'indice
  74.         {
  75.             if (fpw = fopen(ora, "w"))            // Apre il file T:ora.guide
  76.             {
  77.                 fputs(AGHead1, fpw);                // Scrive l'header di Amigaguide
  78.                 fputs(AGHeadB, fpw);                // e le prime righe
  79.                 fputs(AGHead2, fpw);                // e le prime righe
  80.                 fputs(font,    fpw);
  81.                 fputs(AGHead3, fpw);
  82. //                fputs(AGHead4, fpw);
  83.  
  84.                while (fgets(buff, sizeof(buff), fpr))
  85.                 {
  86.                     char *ptr = strchr(buff, '~');    // cerca il nome della dir
  87.                     *ptr++;                                    // ptr = inizio nome dir
  88.  
  89.                      if ((*ptr > 'a'-1) && (*ptr < 'z'+1))
  90.                         *ptr = (*ptr & 0xdf);            // Prima lettera Maiuscola
  91.  
  92.                     char *end = ptr;
  93.                     while (*end != '~') { *end++;}    // cerca fine nome dir
  94.                     *end = 0;                                // e termina con 0
  95.  
  96.                     if (strcmp(LastLine, ptr) != 0 ) // se diverso dalla dir vista prima
  97.                     {
  98.                         strcpy(LastLine, ptr);            // string in Lastline
  99.  
  100.                         fprintf(fpw, "  @{\" %s",ptr);
  101.                         int y = 0; while((strlen(ptr)+y)<12) {fprintf(fpw," "); y++;}
  102.                         fprintf(fpw, "\" SYSTEM \"c:Run >NIL: ICD:Bin/IndexFiles %s %s\"}\n",argptr[1], LastLine);
  103.                         Count++;
  104.                     }
  105.                 }
  106.                 fprintf(fpw, AGfoot);
  107.                 fclose(fpw);
  108.             }
  109.             fclose(fpr);
  110.  
  111.             if (access("T:AmigaGuide_Workbench",0) != 0)
  112.             {
  113.                 system("c:Copy ENV:AmigaGuide/Workbench T:AmigaGuide_Workbench");
  114.             }
  115.             if (access("ENV:AmigaGuide/Workbench",0) == 0)
  116.             {
  117.                 remove("ENV:AmigaGuide/Workbench");
  118.                 system("c:Copy T:AmigaGuide_Workbench ENV:AmigaGuide/Workbench");
  119.                 if (Count > 28) {    Count = 28; }
  120.  
  121.                 sprintf(buff, "ICD:Bin/SizeAG 300 0 144 %d", (Count+4)*(Size+2)+40 );
  122.                 system(buff);
  123.             }
  124.  
  125.             strcpy(line, "sys:Utilities/AmigaGuide >NIL: ");
  126.             strcat(line, ora);
  127.             system(line);
  128.             remove(ora);
  129.  
  130.             if (access("T:AmigaGuide_Workbench",0) == 0)
  131.             {
  132.                 remove("ENV:AmigaGuide/Workbench");
  133.                 system("c:Copy T:AmigaGuide_Workbench ENV:AmigaGuide/Workbench");
  134.             }
  135.         }
  136.         else
  137.         {
  138.             Printf("Can't open file %s.\n\n", argptr[1]);
  139.         }
  140.     }
  141. }
  142.  
  143. LoadConfiguration()
  144. {
  145.     strcpy(font, "topaz.font 11");    // font di default
  146.  
  147.     FILE *fp;
  148.     if (fp = fopen(ConfigFile, "r"))
  149.     {
  150.        while (fgets(buff, sizeof(buff)-1, fp))
  151.         {
  152.             if ((ptr = strstr(buff, "font=")) != NULL)
  153.             {
  154.                 int len = strlen(buff);
  155.                 buff[len-1] = 0x0;
  156.  
  157.                 ptr = strchr(buff, '=') + 1;
  158.                 strcpy(font, ptr);
  159.  
  160.                 ptr = strchr(font, '/');
  161.                 strcpy(ptr, ".font ");
  162.  
  163.                 ptr = strchr(buff, '/') + 1;
  164.                 strcat(font, ptr);
  165.             }
  166.         }
  167.         fclose(fp);
  168.     }
  169. }
  170.