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

  1. /* dcc dh1:IndexCD/IndexCreator.c */
  2.  
  3. char *Titolo = "$VER: IndexCreator v1.0 (16-04-1997) © by Claudio Buraglio";
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <time.h>
  8. #include "libraries/dosextens.h"
  9.  
  10. extern struct FileHandle *Open();
  11. struct FileHandle *dos_fh;
  12.  
  13. unsigned char *ReqTemp="T:ReqCreaEarInd.temp";
  14. unsigned char *InfTemp="T:Info.temp";
  15.  
  16. unsigned char *ptr;
  17.  
  18. unsigned char buff[255];
  19. unsigned char LabelCD[80];
  20. unsigned char now[10];
  21. unsigned char final[255];
  22. unsigned char comm[255];
  23. unsigned char dest[255];
  24. unsigned char *path[80];
  25. unsigned char *file[80];
  26. unsigned char *coda[125];
  27.  
  28. FILE *fp;
  29. FILE *fpr;
  30. FILE *fpw;
  31.  
  32. strtoupper(char *p)
  33. {
  34.     while (*p != 0)
  35.     {
  36.      if ((*p > 'a'-1) && (*p < 'z'+1))
  37.         *p = (*p & 0xdf);
  38.     p++;
  39.     }
  40. }
  41.  
  42.  
  43. FormatLine()
  44. {
  45.     int s = 0;
  46.     int d = 0;
  47.  
  48.     if (buff[s] != '|')
  49.     {
  50.         while (buff[s] != 0)
  51.         {
  52.             if(buff[s] == 0x22)
  53.                 buff[s]  = 0x27;
  54.             if(buff[s] == '~')
  55.                 buff[s]  = '-';
  56.             s++;
  57.         }
  58.         s = 0;
  59.  
  60.         while (buff[s] != ' ')    // trova fine filename
  61.             s++;
  62.         d = s++;
  63.         buff[d++] = '~';
  64.  
  65.         while (buff[s] == ' ')    // trova inizio dir
  66.             s++;
  67.         while (buff[s] != ' ')    // copia dir
  68.             buff[d++] = buff[s++];
  69.         buff[d++] = '~';
  70.         s++;
  71.  
  72.         while (buff[s] == ' ')    // trova inizio size
  73.             s++;
  74.         while (buff[s] != ' ')    // copia Size
  75.             buff[d++] = buff[s++];
  76.         buff[d++] = '~';
  77.  
  78.         s = s + 5;
  79.         while (buff[s] != 0)    // copia Size
  80.             buff[d++] = buff[s++];
  81.         buff[d++] = 0;
  82.     }
  83.     else
  84.         buff[s] = 0;
  85. }
  86.  
  87.  
  88. CheckName(char *f, char *p, char *c, char *s)
  89. {
  90.     if (buff[0] != 0)
  91.     {
  92.  
  93.         while ((*s != '~') && (*s != 0))
  94.         {
  95.             *f++ = *s++;
  96.         }
  97.         *f = 0x0;
  98.         s++;
  99.  
  100.         while ((*s != '~') && (*s != 0))
  101.         {
  102.             *p++ = *s++;
  103.         }
  104.         *p = 0x0;
  105.         s++;
  106.  
  107.         while ((*s != 0))
  108.         {
  109.             *c++ = *s++;
  110.         }
  111.         *c = 0x0;
  112.  
  113.         sprintf(comm,"%saminet/%s/%s", LabelCD, path, file);
  114.         if (access(comm) != 0)
  115.         {
  116.             unsigned char linea[128];
  117.             sprintf(linea, "\n\n%s\t...Not found\n\nFound...\n ", comm);
  118.             Write(dos_fh, linea, strlen(linea));
  119.  
  120.             strcpy(linea, "c:List >t:list.tmp LFORMAT %F%N ");
  121.             strcat(linea, comm);
  122.             strcat(linea, "*");
  123.             system(linea);
  124.  
  125.             FILE *fpt;
  126.             if (fpt = fopen("t:list.tmp", "r"))
  127.             {
  128.                 buff[0] = 0;
  129.                 fgets(buff, sizeof(buff), fpt);
  130.  
  131.                 if((strstr(buff, ".lha") != 0) ||
  132.                     (strstr(buff, ".lzh") != 0) ||
  133.                     (strstr(buff, ".dms") != 0) ||
  134.                     (strstr(buff, ".jpg") != 0) ||
  135.                     (strstr(buff, ".exe") != 0) ||
  136.                     (strstr(buff, ".txt") != 0) ||
  137.                     (strstr(buff, ".anim")!= 0))
  138.                 {
  139.                     char *cptr;
  140.                     cptr = strchr(buff, 0xa);
  141.                     *cptr = 0;
  142.                     cptr = strrchr(buff, '/');
  143.                     cptr++;
  144.                     strcpy(file, cptr);
  145.                     sprintf(buff, "%s~%s~%s", file, path, coda);
  146.                     Write(dos_fh, buff, strlen(buff));
  147.                 }
  148.                 else
  149.                 {                    sprintf(linea," nothing\n");
  150.                     Write(dos_fh, linea, strlen(linea));
  151.  
  152.                 }
  153.                 fclose(fpt);
  154.             }
  155.         }
  156.     }
  157. }
  158.  
  159.  
  160.  
  161. int wbmain()
  162. {
  163.     getcwd(buff, sizeof(buff));
  164.  
  165.     ptr = strchr(buff, ':');
  166.     ptr[0] = 0;
  167.  
  168.     strtoupper(buff);
  169.     strcpy(LabelCD, buff);
  170.  
  171.     sprintf(final, "c:Info >%s %s:\n", InfTemp, LabelCD);
  172.     system(final);
  173.  
  174.     int r = 0;
  175.     if (fpr = fopen(InfTemp, "r"))
  176.     {
  177.         while (fgets(buff, sizeof(buff)-1, fpr))
  178.         {
  179.             strtoupper(buff);
  180.             if (strstr(buff, LabelCD) != NULL)
  181.             {
  182.                 if (strstr(buff, "READ/WRITE") != NULL)    {    r = 0;    }
  183.                 if (strstr(buff, "READ ONLY")  != NULL)    {    r = 1;    }
  184.             }
  185.         }
  186.         fclose(fpr);
  187.         remove(InfTemp);
  188.     }
  189.  
  190.     if (r == 1)
  191.     {
  192.     sprintf(final,"c:RequestChoice >NIL: CreatoreIndice \"Index not created! The Unit %s: is Read only.\" Exit\n", LabelCD);
  193.     system(final);
  194.     }
  195.     else
  196.     {
  197.         system("c:Assign ICD: \"\"");
  198.  
  199.         system("c:assign >t:assign.temp VOLS");
  200.  
  201.         int scelta = 0;
  202.         if (fp = fopen("t:assign.temp", "r"))
  203.         {
  204.            while (fgets(buff, sizeof(buff)-1, fp) && scelta == 0)
  205.             {
  206.                 strtoupper(buff);
  207.                 if((strstr(buff, "AMINET") != 0) || (strstr(buff, "SET") != 0))
  208.                 {
  209.                     int i = 0;
  210.                     while(buff[i] != 0x20)    {    i++;    }    buff[i] = 0;
  211.                     strcpy(final, buff);
  212.                     strcpy(LabelCD, buff);
  213.  
  214.                     sprintf(comm, "C:RequestChoice >%s IndexCreator \"I have found %s \" \"Make Index\" \"Find Other Label\"", ReqTemp, buff);
  215.                     system(comm);
  216.  
  217.                     if (fpr = fopen(ReqTemp, "r"))
  218.                     {
  219.                         fgets(buff, sizeof(buff)-1, fpr);
  220.                         if ( strchr(buff, '0') != NULL)
  221.                             scelta = 0;
  222.                         else
  223.                             scelta = 1;
  224.                         fclose(fpr);
  225.                         remove(ReqTemp);
  226.                     }
  227.                 }
  228.             }
  229.             fclose(fp);
  230.             remove("T:Assign.temp");
  231.  
  232.             if (scelta != 0)
  233.             {
  234.                 int i = 0;
  235.                 while(final[i] != 0x20)    {    i++;    }    final[i] = 0;
  236.  
  237.                 if            (strcmp(LabelCD, "SET1A"   ) == 0) strcpy(now, "199501_");
  238.                 else if    (strcmp(LabelCD, "SET1B"   ) == 0) strcpy(now, "199501_");
  239.                 else if    (strcmp(LabelCD, "SET1C"   ) == 0) strcpy(now, "199501_");
  240.                 else if    (strcmp(LabelCD, "SET1D"   ) == 0) strcpy(now, "199501_");
  241.                 else if    (strcmp(LabelCD, "SET2A"   ) == 0) strcpy(now, "199511_");
  242.                 else if    (strcmp(LabelCD, "SET2B"   ) == 0) strcpy(now, "199511_");
  243.                 else if    (strcmp(LabelCD, "SET2C"   ) == 0) strcpy(now, "199511_");
  244.                 else if    (strcmp(LabelCD, "SET2D"   ) == 0) strcpy(now, "199511_");
  245.                 else if    (strcmp(LabelCD, "SET3A"   ) == 0) strcpy(now, "199607_");
  246.                 else if    (strcmp(LabelCD, "SET3B"   ) == 0) strcpy(now, "199607_");
  247.                 else if    (strcmp(LabelCD, "SET3C"   ) == 0) strcpy(now, "199607_");
  248.                 else if    (strcmp(LabelCD, "SET3D"   ) == 0) strcpy(now, "199607_");
  249.                 else if    (strcmp(LabelCD, "SET3A"   ) == 0) strcpy(now, "199701_");
  250.                 else if    (strcmp(LabelCD, "SET3B"   ) == 0) strcpy(now, "199701_");
  251.                 else if    (strcmp(LabelCD, "SET3C"   ) == 0) strcpy(now, "199701_");
  252.                 else if    (strcmp(LabelCD, "SET3D"   ) == 0) strcpy(now, "199701_");
  253.                 else if    (strcmp(LabelCD, "AMINET1" ) == 0) strcpy(now, "199307_");
  254.                 else if    (strcmp(LabelCD, "AMINET2" ) == 0) strcpy(now, "199402_");
  255.                 else if    (strcmp(LabelCD, "AMINET3" ) == 0) strcpy(now, "199406_");
  256.                 else if    (strcmp(LabelCD, "AMINET4" ) == 0) strcpy(now, "199502_");
  257.                 else if    (strcmp(LabelCD, "AMINET5" ) == 0) strcpy(now, "199503_");
  258.                 else if    (strcmp(LabelCD, "AMINET6" ) == 0) strcpy(now, "199506_");
  259.                 else if    (strcmp(LabelCD, "AMINET7" ) == 0) strcpy(now, "199508_");
  260.                 else if    (strcmp(LabelCD, "AMINET8" ) == 0) strcpy(now, "199510_");
  261.                 else if    (strcmp(LabelCD, "AMINET9" ) == 0) strcpy(now, "199512_");
  262.                 else if    (strcmp(LabelCD, "AMINET10") == 0) strcpy(now, "199602_");
  263.                 else if    (strcmp(LabelCD, "AMINET11") == 0) strcpy(now, "199604_");
  264.                 else if    (strcmp(LabelCD, "AMINET12") == 0) strcpy(now, "199606_");
  265.                 else if    (strcmp(LabelCD, "AMINET13") == 0) strcpy(now, "199608_");
  266.                 else if    (strcmp(LabelCD, "AMINET14") == 0) strcpy(now, "199610_");
  267.                 else if    (strcmp(LabelCD, "AMINET15") == 0) strcpy(now, "199611_");
  268.                 else if    (strcmp(LabelCD, "AMINET16") == 0) strcpy(now, "199612_");
  269.                 else if    (strcmp(LabelCD, "AMINET17") == 0) strcpy(now, "199702_");
  270.                 else if    (strcmp(LabelCD, "AMINET18") == 0) strcpy(now, "199704_");
  271.                 else
  272.                 {
  273.                    time_t t = time(NULL);
  274.                    struct tm *tp = localtime(&t);
  275.                    strftime(now, sizeof(now)-1, "%Y",  tp);
  276.  
  277.                     int anno = 1997;
  278.                     sprintf(comm,"c:RequestChoice >t:year.tmp IndexCD \"Year of the CD-ROM %s\" ", LabelCD);
  279.                     while (strstr(buff, now) == 0)
  280.                     {
  281.                         sprintf(buff, "%d ", anno);
  282.                         strcat(comm, buff);
  283.                         anno++;
  284.                     }
  285.                     system(comm);
  286.  
  287.                     if (fpr = fopen("t:year.tmp", "r"))
  288.                     {
  289.                         fgets(buff, sizeof(buff)-1, fpr);
  290.                         if (strlen(buff) == 2)
  291.                         {
  292.                             if      (strchr(buff, '1') != NULL)
  293.                                 strcpy(now,"1997");
  294.                             else if (strchr(buff, '2') != NULL)
  295.                                 strcpy(now,"1998");
  296.                             else if (strchr(buff, '3') != NULL)
  297.                                 strcpy(now,"1999");
  298.                             else if (strchr(buff, '4') != NULL)
  299.                                 strcpy(now,"2000");
  300.                             else if (strchr(buff, '5') != NULL)
  301.                                 strcpy(now,"2001");
  302.                             else if (strchr(buff, '6') != NULL)
  303.                                 strcpy(now,"2002");
  304.                             else if (strchr(buff, '7') != NULL)
  305.                                 strcpy(now,"2003");
  306.                             else if (strchr(buff, '8') != NULL)
  307.                                 strcpy(now,"2004");
  308.                             else if (strchr(buff, '9') != NULL)
  309.                                 strcpy(now,"2005");
  310.                         }
  311.                         fclose(fpr);
  312.                     }
  313.                     remove("t:year.tmp");
  314.  
  315.                     sprintf(comm, "c:RequestChoice >t:month.tmp IndexCD \"Month of the CD-ROM %s\" 1 2 3 4 5 6 7 8 9 10 11 12", LabelCD);
  316.                     system(comm);
  317.                     if (fpr = fopen("t:month.tmp", "r"))
  318.                     {
  319.                         fgets(buff, sizeof(buff)-1, fpr);
  320.  
  321.                         if (strlen(buff) == 2)
  322.                         {
  323.                             if (strchr(buff, '0') != NULL)
  324.                                 strcat(now,"12_");
  325.                             else if (strchr(buff, '1') != NULL)
  326.                                 strcat(now,"01_");
  327.                             else if (strchr(buff, '2') != NULL)
  328.                                 strcat(now,"02_");
  329.                             else if (strchr(buff, '3') != NULL)
  330.                                 strcat(now,"03_");
  331.                             else if (strchr(buff, '4') != NULL)
  332.                                 strcat(now,"04_");
  333.                             else if (strchr(buff, '5') != NULL)
  334.                                 strcat(now,"05_");
  335.                             else if (strchr(buff, '6') != NULL)
  336.                                 strcat(now,"06_");
  337.                             else if (strchr(buff, '7') != NULL)
  338.                                 strcat(now,"07_");
  339.                             else if (strchr(buff, '8') != NULL)
  340.                                 strcat(now,"08_");
  341.                             else if (strchr(buff, '9') != NULL)
  342.                                 strcat(now,"09_");
  343.                         }
  344.                         else
  345.                         {
  346.                             if (strstr(buff, "10") != NULL)
  347.                                 strcat(now,"10_");
  348.                             else if (strstr(buff, "11") != NULL)
  349.                                 strcat(now,"11_");
  350.                         }
  351.                         fclose(fpr);
  352.                     }
  353.                     remove("t:month.tmp");
  354.                 }
  355.  
  356.                 chdir("ICD:Index/");
  357.                 sprintf( dest, "ICD:Index/%s%s.index", now, final);
  358.  
  359.                 int r = access(dest, 0);
  360.                 if (r == 0)
  361.                 {
  362.                     sprintf(comm, "C:RequestChoice >%s IndexCreator \"WARNING! - The File %s.index already exists.\" Overwrite Exit", ReqTemp, final);
  363.                     system(comm);
  364.  
  365.                     if (fpr = fopen(ReqTemp, "r"))
  366.                     {
  367.                         fgets(buff, sizeof(buff)-1, fpr);
  368.                         if ( strchr(buff, '0') == NULL)
  369.                         {
  370.                             remove(dest);
  371.                             sprintf(LabelCD,"%s:", final);
  372.                             Programma();
  373.                         }
  374.                         fclose(fpr);
  375.                     }
  376.                     remove(ReqTemp);
  377.                 }
  378.                 else
  379.                 {
  380.                     sprintf(LabelCD,"%s:", final);
  381.                     Programma();
  382.                 }
  383.             }
  384.             else
  385.             {
  386.                 strcpy(comm, "C:RequestChoice >NIL: IndexCreator \"Nothing found.\" Exit");
  387.                 system(comm);
  388.             }
  389.         }
  390.     }
  391. }
  392.  
  393. int main(int arglen, char **argptr)
  394. {
  395.  
  396.  
  397. }
  398.  
  399. Programma()
  400. {
  401.     dos_fh = Open("CON:////IndexCreator by Claudio Buraglio", MODE_NEWFILE);
  402.  
  403.     sprintf(comm, "Scanning files on %s\n", LabelCD);
  404.     Write(dos_fh, comm, strlen(comm));
  405.  
  406.     if (strstr(LabelCD, "AMINET"))
  407.         sprintf(comm, "%sLists/Index_Dir.doc", LabelCD);
  408.     else
  409.         sprintf(comm, "%sLocal/Index_Dir.doc", LabelCD);
  410.  
  411.     if (fpr = fopen(comm, "r"))
  412.     {
  413.         if (fpw = fopen( dest, "w"))
  414.         {
  415.             while (fgets(buff, sizeof(buff)-1, fpr))
  416.             {
  417.                 FormatLine();
  418.                 CheckName(file, path, coda, buff);
  419.                 fprintf(fpw, buff);
  420.             }
  421.             fclose(fpw);
  422. //            sprintf(final, "\n");
  423. //            Write(dos_fh, final, strlen(final));
  424.         }
  425.         fclose(fpr);
  426.     }
  427.  
  428.     sprintf(comm, "C:RequestChoice IndexCreator \"Index of %s done.\" OK", LabelCD);
  429.     system(comm);
  430.  
  431.     Close(dos_fh);        // Chiude la window
  432. }
  433.  
  434.