home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 July / Cica_July92.cdr / bbs / rbbstool / to_rbbs.c < prev   
C/C++ Source or Header  |  1992-06-29  |  3KB  |  177 lines

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