home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 July / Cica_July92.cdr / bbs / pcbtool / to_pcb.c < prev   
C/C++ Source or Header  |  1992-06-29  |  4KB  |  202 lines

  1. /*
  2.  * from simtel20 and CICA format to pcboard
  3.  */
  4.  
  5. #if 0
  6. 1234567890123456789012345678901 [Simtel]
  7. 4DOSANN.ZIP   B    6864  910819  4DOS runs on DOS 5.0 and Norton DOS info
  8. 1234567890123456789012345678901 [CICA]
  9. diskindx.txt    901031    Cumulative Index of the WRK Disks (below)
  10. diskroot.zip    920610    Windows Resource Kit 4/3/92
  11. ---------->
  12. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  13.                                | modems.
  14. #endif
  15.  
  16. #include <ctype.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <sys\stat.h>
  21.  
  22. #define CICA
  23.  
  24. struct data {
  25.     char filename[15];
  26.     long filesize;
  27.     int year;
  28.     int month;
  29.     int day;
  30.     char description[900];
  31. };
  32.  
  33. int pastheader = 0;
  34. struct data line;
  35. char path[128];
  36.  
  37. void
  38. readline(void) {
  39.     char buf[1000];
  40.     char workbuf[1000];
  41.     static char datebuf[5] = "12";
  42.     char *r;
  43.     
  44.     if (NULL == gets(buf))
  45.         exit(0);
  46.     
  47.     /* wait for header */
  48.     if (! pastheader) {
  49. #ifdef CICA        
  50.         if (0 == strlen(buf))
  51.             ++pastheader;
  52. #else        
  53.         if (strstr(buf, "================"))
  54.             ++pastheader;
  55. #endif
  56.         return;
  57.     }
  58.     
  59.     line.filename[0] = 0;
  60.         
  61.     if (strlen(buf) == 0) {
  62.         fprintf(stderr, "zero length line\n");
  63.         return;
  64.     }
  65.     
  66.     if (strlen(buf) < 31) {
  67.         fprintf(stderr, "warning: line too short:\n%s\n", buf);
  68.     }
  69.     
  70.     strcpy(workbuf, buf);
  71.     
  72.     r = strtok(buf, "\t ");
  73.     if (! r) {
  74.         fprintf(stderr, "unknown line:\n%s\n", buf);
  75.         return;
  76.     }
  77.     strcpy(line.filename, r);
  78.     
  79.     r += strlen(r) + 1;        /* skip name */
  80.     while (isspace(*r))        /* skip white */
  81.         ++r;
  82.  
  83. #ifndef CICA    
  84.     ++r;                    /* skip file type */
  85.     
  86.     while (isspace(*r))        /* skip white */
  87.         ++r;
  88.     
  89.     r = strtok(r, "\t ");
  90.     if (! r) {
  91.         fprintf(stderr, "unknown line:\n%s\n", buf);
  92.         line.filename[0] = 0;
  93.         return;
  94.     }
  95.     line.filesize = atol(r);
  96.     r += strlen(r) + 1;
  97.     
  98.     while (isspace(*r))        /* skip white */
  99.         ++r;
  100. #endif    
  101.     
  102.     datebuf[0] = *r;
  103.     ++r;
  104.     datebuf[1] = *r;
  105.     ++r;
  106.     line.year = atoi(datebuf);
  107.     
  108.     datebuf[0] = *r;
  109.     ++r;
  110.     datebuf[1] = *r;
  111.     ++r;
  112.     line.month = atoi(datebuf);
  113.     datebuf[0] = *r;
  114.     ++r;
  115.     datebuf[1] = *r;
  116.     ++r;
  117.     line.day = atoi(datebuf);
  118.     
  119.     while (isspace(*r))        /* skip white */
  120.         ++r;
  121.     
  122.     if (*r)    
  123.         strcpy(line.description, r);
  124.     else
  125.         line.description[0] = 0;
  126. }
  127.  
  128. void
  129. writeline(void) {
  130.     char *r;
  131.     char *p;
  132.     FILE *foo;
  133.     char buf[128];
  134.     struct stat stat_buf;
  135.  
  136.     if (! line.filename[0])
  137.         return;
  138.  
  139. #if 0    
  140. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  141.                                | modems.
  142. #endif
  143.  
  144. #ifdef CICA
  145.     sprintf(buf, "%s\\%s", path, line.filename);
  146.     if (NULL == (foo = fopen(buf, "r"))) {
  147.         fprintf(stderr, "failed opening '%s'\n", buf);
  148.         exit(1);
  149.     }
  150.  
  151.     stat(buf, &stat_buf);
  152.  
  153.     fclose(foo);
  154.         
  155.     line.filesize = stat_buf.st_size;
  156. #endif
  157.     
  158.     printf("%-13s%8ld  %02d-%02d-%02d  ",
  159.         line.filename,
  160.         line.filesize,
  161.         line.month,
  162.         line.day,
  163.         line.year);
  164.     
  165.     /* write wrapping description */
  166.  
  167.     r = line.description;
  168.     while (1) {
  169.         if (strlen(r) <= 45) {        
  170.             printf("%s\n", r);
  171.             return;
  172.         }
  173.  
  174.         p = r + 45;
  175.         while (! isspace(*p))
  176.             --p;
  177.         
  178. #if 0    
  179. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  180.                                | modems.
  181. #endif
  182.         *p = 0;
  183.         printf("%s\n%31s| ", r, " ");
  184.         r = p + 1;
  185.     }
  186. }
  187.  
  188. void _Cdecl
  189. main(int argc, char *argv[]) {
  190.     
  191. #ifdef CICA    
  192.     fprintf(stderr,
  193.         "usage: 2pcb <directory path> < 00_index.txt > files.bbs\n");
  194.     strcpy(path, argv[1]);
  195. #endif
  196.     
  197.     while (1) {
  198.         readline();
  199.         writeline();
  200.     }
  201. }
  202.