home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / TICKFBS / TICKFB.C next >
C/C++ Source or Header  |  1991-12-21  |  4KB  |  205 lines

  1. #include <stdio.h>
  2. #include <dir.h>
  3. #include <dos.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define MAX_AREAS 1296
  10. #define MAX_TICKS 200
  11.  
  12. int x, y, z, num_areas, c = 0;
  13.  
  14. typedef struct {
  15.    char marea[9];
  16.    char tarea[9];
  17. } AREAS;
  18.  
  19. typedef struct {
  20.    char area[9];
  21. } TICKS;
  22.  
  23. TICKS *info[MAX_TICKS];
  24. AREAS *ctl[MAX_AREAS];
  25.  
  26. FILE *in, *out, *ctnl;
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30.    char filename[80];
  31.    struct ffblk fileinfo;
  32.  
  33.    if(argc < 3)
  34.    {
  35.       printf("\nUsage:\n\t");
  36.       printf("TICKFB out_file area_dat [ctl_file]\n\nExample:\n\t");
  37.       printf("TICKFB D:\\MAX\\FBRUN.BAT AREA.DAT [D:\\MAX\\TICKFB.CTL]\n");
  38.       exit(255);
  39.    }
  40.    printf("\nTICKFB        By Erik VanRiper     (1:107/230@fidonet.org)\n\n" \
  41.               "This program is free for non-commercial use.\n");
  42.  
  43.    if(argv[3] != NULL) c = 3;
  44.  
  45.    if(c == 3)
  46.    {
  47.       if((ctnl = fopen(argv[3],"r")) == NULL)
  48.       {
  49.          printf("Unable to open! %s\n",argv[3]);
  50.          exit(255);
  51.       }
  52.    }
  53.  
  54.    for(x = 0; x < MAX_TICKS; x++)
  55.    {
  56.       if((info[x] = malloc(sizeof(TICKS))) == NULL)
  57.       {
  58.          printf("\nOut of memory!\n");
  59.          exit(255);
  60.       }
  61.    }
  62.  
  63.    for(x = 0; x < MAX_AREAS; x++)
  64.    {
  65.       if((ctl[x] = malloc(sizeof(AREAS))) == NULL)
  66.       {
  67.          printf("\nOut of memory!\n");
  68.          exit(255);
  69.       }
  70.    }
  71.  
  72.    if(c == 3) parsectl();
  73.    fclose(ctnl);
  74.  
  75.    x = y = z = 0;
  76.    if(findfirst("*.TIC", &fileinfo, 0) == 0)
  77.       tickfb(fileinfo.ff_name);
  78.  
  79.    else
  80.    {
  81.       printf("\nNo files found.");
  82.       fclose(out);
  83.       for(x = 0; x < MAX_AREAS; x++) free(ctl[x]);
  84.       for(x = 0; x < MAX_TICKS; x++) free(info[x]);
  85.       exit(0);
  86.    }
  87.  
  88.    while(findnext(&fileinfo) == 0)
  89.       tickfb(fileinfo.ff_name);
  90.  
  91.  
  92.    if(z)
  93.    {
  94.       if((out = fopen(argv[1],"wt")) == NULL)
  95.       {
  96.          printf("\a\aError, unable to open %s\n",argv[1]);
  97.          exit(255);
  98.       }
  99.       fprintf(out,"@echo off\nFB %s ",argv[2]);
  100.       for(y = 0; y < z; y++)
  101.       {
  102.          fprintf(out,"%s ",info[y]->area);
  103.       }
  104.       fprintf(out,"\n");
  105.       fclose(out);
  106.    }
  107.  
  108.    for(x = 0; x < MAX_AREAS; x++) free(ctl[x]);
  109.    for(x = 0; x < MAX_TICKS; x++) free(info[x]);
  110.  
  111.    if(z) return(1);
  112.    return(0);
  113. }
  114.  
  115. parsectl()
  116. {
  117.    char line[20], *token;
  118.  
  119.    num_areas = 0;
  120.  
  121.    while(fgets(line,19,ctnl) != NULL)
  122.    {
  123.       token = strtok(line," ");
  124.       if(token == NULL)
  125.       {
  126.          if(num_areas) return(1);
  127.          printf("\nError no. 1 in CTL file.  line = %s \n",line);
  128.          exit(255);
  129.       }
  130.       strcpy(ctl[num_areas]->tarea,token);
  131.  
  132.       token = strtok(NULL," \r\n");
  133.       if(token == NULL)
  134.       {
  135.          if(num_areas) return(1);
  136.          printf("\nError no. 2 in CTL file.  line = %s\n",line);
  137.          exit(255);
  138.       }
  139.       strcpy(ctl[num_areas]->marea,token);
  140.       
  141.       num_areas++;
  142.    }
  143.    return(1);
  144. }
  145.  
  146. int tickfb(char *file)
  147. {
  148.    char line[20], *token;
  149.  
  150.    if((in = fopen(file,"rb")) == NULL)
  151.    {
  152.       printf("\rError, unable to open %s",file);
  153.       return(0);
  154.    }
  155.  
  156.    memset(line,'\0',20);
  157.  
  158.    fgets(line,19,in);
  159.  
  160.    fclose(in);
  161.  
  162.    token = strtok(line," ");
  163.    token = strtok(NULL,"\r\n ");
  164.  
  165.    if(token != NULL)
  166.    {
  167.       y = 0;
  168.       if(c == 3)
  169.       {
  170.          for(x = 0; x < num_areas; x++)
  171.          {
  172.             if(strcmp(ctl[x]->tarea,token) == 0)
  173.             {
  174.                for(y = 0; y < z; y++)
  175.                {
  176.                   if(strcmp(info[y]->area,ctl[x]->marea) == 0)
  177.                   {
  178.                      return(1);
  179.                   }
  180.                }
  181.                strcpy(info[z]->area,ctl[x]->marea);
  182.                y = 1;
  183.                break;
  184.             }
  185.          }
  186.       }
  187.       if(y == 0)
  188.       {
  189.          for(y = 0; y < z; y++)
  190.          {
  191.             if(strcmp(info[y]->area,token) == 0)
  192.             {
  193.                return(1);
  194.             }
  195.          }
  196.          strcpy(info[z]->area,token);
  197.       }
  198.  
  199.       printf("\n%-8s -=> %s",token,info[z]->area);
  200.       z++;
  201.    }
  202.    else printf("Err.");
  203.    return(1);
  204. }
  205.