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

  1. /* dcc HD1:IndexCD/IndexCD.c */
  2.  
  3. char *Titolo = "$VER: IndexCD v1.0 (15-02-1997) © by Claudio Buraglio";
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <time.h>
  9.  
  10. char    buff[255];
  11. char    line[255];
  12. char    work[126];
  13. char    font[126];
  14. char    ora [20];
  15.  
  16. char    *TempList    ="T:List.temp";
  17. char    *ConfigFile    ="S:Aminet-Config";
  18.  
  19. char    *volume="         ";
  20. char    *anno="     ";
  21.  
  22. char    *AGhead ="@database Arc\n@node main \"IndexCD - Claudio Buraglio, ©1997.\"\n@font ";
  23. char    *AGfont ="\n\n\ @{\" Volume    Month      Year \" LINK ICD:bin/Help.guide/LABELNAME}\n\ ---------------------------\n";
  24. char    *AGfoot ="@ENDNODE\n";
  25.  
  26. char    *m00    =    "         ";
  27. char    *m01    =    "January  ";
  28. char    *m02    =    "February ";
  29. char    *m03    =    "March    ";
  30. char    *m04    =    "April    ";
  31. char    *m05    =    "May      ";
  32. char    *m06    =    "June     ";
  33. char    *m07    =    "July     ";
  34. char    *m08    =    "August   ";
  35. char    *m09    =    "September";
  36. char    *m10    =    "October  ";
  37. char    *m11    =    "November ";
  38. char    *m12    =    "December ";
  39.  
  40. FILE *fpr;
  41. FILE *fpw;
  42. char *ptr;
  43.  
  44. int XSize = 8*27;
  45. int Count;
  46. int Size;
  47.  
  48.  
  49. strpaste(char *d, char *s)
  50. {
  51.     while(*s != 0)
  52.         *d++ = *s++;
  53.     return(d);
  54. }
  55.  
  56. int main()
  57. {
  58.     printf("\n%s\n\n",Titolo+6);
  59.     puts("This command is usable only from Workbench.");
  60.     return(0);
  61. }
  62. int wbmain()
  63. {
  64.     Programma();
  65. }
  66.  
  67. Programma()
  68. {
  69.     system("c:Assign ICD: \"\"");
  70.  
  71.     LoadConfiguration();
  72.     ptr = strchr(font, ' ');
  73.     ptr++;
  74.     int Size = strtol(ptr,0,0);
  75.  
  76.     if (system("LIST ICD:Index/#?CD.#? ICD:Index/#?CD2.#? LFORMAT \"%p %s %d\" TO T:List.temp") == 0)
  77.     {
  78.        time_t t = time(NULL);
  79.        struct tm *tp = localtime(&t);
  80.        strftime(ora, sizeof(ora) - 1, "T:%H%M%S.guide",  tp);
  81.  
  82.         if (fpw = fopen(ora, "w"))
  83.         {
  84.             fputs(AGhead, fpw);
  85.             fputs(font,   fpw);
  86.             fputs(AGfont, fpw);
  87.  
  88.             system("LIST ICD:Index/#?.index LFORMAT \"%p %s %d\" TO T:List.tmp");
  89.             system("SORT T:List.tmp T:List.temp");
  90.             remove("T:List.tmp");
  91.  
  92.  
  93. // Scrive gli indici
  94.  
  95.             if (fpr = fopen(TempList, "r"))
  96.             {
  97.                while (fgets(buff, sizeof(buff), fpr))
  98.                 {
  99.                     CreaLinea();
  100.                     Count++;
  101.                 }
  102.             fclose(fpr);
  103.             }
  104.             fputs(AGfoot, fpw);
  105.             remove(TempList);
  106.             fclose(fpw);
  107.         }
  108.  
  109.         if (access("T:AmigaGuide_Workbench",0) != 0)
  110.             system("c:Copy ENV:AmigaGuide/Workbench T:AmigaGuide_Workbench");
  111.  
  112.         if (access("ENV:AmigaGuide/Workbench",0) == 0)
  113.         {
  114.             sprintf(buff, "ICD:Bin/SizeAG 0 0 %d %d", 238, ((Count+4)*(Size+2))+40);
  115.             system(buff);
  116.         }
  117.  
  118.         strcpy(line, "sys:Utilities/AmigaGuide >NIL: ");
  119.         strcat(line, ora);
  120.  
  121.         system(line);
  122.         remove(ora);
  123.  
  124.         if (access("T:AmigaGuide_Workbench",0) == 0)
  125.         {
  126.             remove("ENV:AmigaGuide/Workbench");
  127.             system("c:Copy T:AmigaGuide_Workbench ENV:AmigaGuide/Workbench");
  128.         }
  129.     }
  130.     else
  131.     {
  132.         system("C:RequestChoice \" IndexCD-ROM Problem \" \" 'c:LIST ICD:Index' is not executable \" OK");
  133.     }
  134. }
  135.  
  136.  
  137. CreaLinea()
  138. {
  139.     int i = 0;
  140.     char *mese = m00;
  141.     char *ptr = buff;
  142.     while (*ptr != ' ')        // cerca nome file
  143.         ptr++;
  144.     *ptr++;
  145.  
  146.     i = 0;
  147.     while (*ptr != '_')        // Copia Data
  148.         anno[i++] = *ptr++;
  149.     *ptr++;
  150.  
  151.     if(anno[i-2] == '0' && anno[i-1] == '1')    {mese = m01;}
  152.     if(anno[i-2] == '0' && anno[i-1] == '2')    {mese = m02;}
  153.     if(anno[i-2] == '0' && anno[i-1] == '3')    {mese = m03;}
  154.     if(anno[i-2] == '0' && anno[i-1] == '4')    {mese = m04;}
  155.     if(anno[i-2] == '0' && anno[i-1] == '5')    {mese = m05;}
  156.     if(anno[i-2] == '0' && anno[i-1] == '6')    {mese = m06;}
  157.     if(anno[i-2] == '0' && anno[i-1] == '7')    {mese = m07;}
  158.     if(anno[i-2] == '0' && anno[i-1] == '8')    {mese = m08;}
  159.     if(anno[i-2] == '0' && anno[i-1] == '9')    {mese = m09;}
  160.     if(anno[i-2] == '1' && anno[i-1] == '0')    {mese = m10;}
  161.     if(anno[i-2] == '1' && anno[i-1] == '1')    {mese = m11;}
  162.     if(anno[i-2] == '1' && anno[i-1] == '2')    {mese = m12;}
  163.     anno[i-2] = 0;
  164.  
  165.     i = 0;
  166.  
  167.     ptr = strchr(buff, '_');
  168.     ptr++;
  169.     while (*ptr != '.')                // Copia nome file
  170.         volume[i++] = *ptr++;
  171.     while(volume[i] != ' ')
  172.         volume[i++] = ' ';
  173.  
  174.     ptr = buff;
  175.     i = 0;
  176.     while (*ptr != ' ')            // Copia dir..
  177.         work[i++] = *ptr++;
  178.    *ptr++;
  179.  
  180.     while (*ptr != ' ')            // e nome archivio
  181.         work[i++] = *ptr++;
  182.     work[i] = 0;
  183.  
  184.     fprintf(fpw, "\ @{\" %s %s  %s \" SYSTEM \"c:run >NIL: ICD:Bin/IndexDirectory %s\"}\n", volume, mese, anno, work);
  185. }
  186.  
  187. LoadConfiguration()
  188. {
  189.     strcpy(font, "topaz.font 11");    // font per default
  190.  
  191.     FILE *fp;
  192.     if (fp = fopen(ConfigFile, "r"))
  193.     {
  194.        while (fgets(buff, sizeof(buff)-1, fp))
  195.         {
  196.             if ((ptr = strstr(buff, "font=")) != NULL)
  197.             {
  198.                 int len = strlen(buff);
  199.                 buff[len-1] = 0x0;
  200.  
  201.                 ptr = strchr(buff, '=') + 1;
  202.                 strcpy(font, ptr);
  203.  
  204.                 ptr = strchr(font, '/');
  205.                 strcpy(ptr, ".font ");
  206.  
  207.                 ptr = strchr(buff, '/') + 1;
  208.                 strcat(font, ptr);
  209.             }
  210.         }
  211.         fclose(fp);
  212.     }
  213. }
  214.