home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / bbs / rover / pcb2rov.c < prev   
C/C++ Source or Header  |  1992-10-27  |  3KB  |  159 lines

  1. /*
  2.  * from pcboard to roverboard
  3.  *
  4.  */
  5.  
  6. #if 0
  7. 1234567890123456789012345678901
  8. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  9.                                | modems.
  10. ---------->
  11. 01 4DOS40D.ZIP 11/17/91;00001;*;4DOS 4.0 - manual
  12. 01 4UTILS.ZIP 08/10/90;00002;*;Utils for 4DOS
  13. #endif
  14.  
  15. #define LINE_MAX        150
  16.  
  17. #include <ctype.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. struct data {
  23.     char filename[15];
  24.     long filesize;
  25.     int year;
  26.     int month;
  27.     int day;
  28.     char description[900];
  29. };
  30.  
  31. int pastheader = 0;
  32. struct data line;
  33.  
  34. #define CONTINUE_POS    sizeof("                               |") - 1
  35.  
  36. void
  37. readline(void) {
  38.     static char buf[1000];
  39.     static char datebuf[5] = "12";
  40.     char *r;
  41.  
  42.     if (0 == buf[0]) {
  43.         if (NULL == gets(buf))
  44.             exit(0);
  45.     }
  46.     
  47.     if (!buf[0] || isspace(buf[0]) || buf[0] == '*') {
  48.         /* a comment */
  49.         line.filename[0] = 0;
  50.         buf[0] = 0;
  51.         return;
  52.     }
  53.     
  54.     if (strlen(buf) < 31) {
  55.         fprintf(stderr, "warning: line too short:\n%s\n", buf);
  56.     }
  57.     
  58.     r = strtok(buf, " ");
  59.     if (! r) {
  60.         fprintf(stderr, "unknown line:\n%s\n", buf);
  61.         buf[0] = 0;
  62.         return;
  63.     }
  64.     strcpy(line.filename, r);
  65.     
  66.     r += strlen(r) + 1;        /* skip name */
  67.     while (isspace(*r))        /* skip white */
  68.         ++r;
  69.     
  70.     r = strtok(r, " ");
  71.     if (! r) {
  72.         fprintf(stderr, "unknown line:\n%s\n", buf);
  73.         buf[0] = 0;
  74.         return;
  75.     }
  76.     line.filesize = atol(r);
  77.     r += strlen(r) + 1;
  78.     
  79.     while (isspace(*r))        /* skip white */
  80.         ++r;
  81.     
  82.     datebuf[0] = *r;
  83.     ++r;
  84.     datebuf[1] = *r;
  85.     ++r;
  86.     line.month = atoi(datebuf);
  87.     ++r;                    /* - */
  88.     
  89.     datebuf[0] = *r;
  90.     ++r;
  91.     datebuf[1] = *r;
  92.     ++r;
  93.     line.day = atoi(datebuf);
  94.     ++r;
  95.     
  96.     datebuf[0] = *r;
  97.     ++r;
  98.     datebuf[1] = *r;
  99.     ++r;
  100.     line.year = atoi(datebuf);
  101.     
  102.     while (isspace(*r))        /* skip white */
  103.         ++r;
  104.     
  105.     /* now read in continue lines, appending to description */
  106.     if (*r) {
  107.         strcpy(line.description, r);
  108.     
  109.         while (1) {
  110.             if (NULL == gets(buf)) {
  111.                 buf[0] = 0;
  112.                 return;
  113.             }
  114.         
  115.             if (0 == strncmp(buf, "                               |",
  116.                                         CONTINUE_POS)) {
  117.                 /* continue line... */
  118.                 strcat(line.description, " ");
  119.                 strcat(line.description, buf + CONTINUE_POS + 1);
  120.             } else {
  121.                 /* forget it ... but keeping line in buf. */
  122.                 strcat(line.description, "\n");
  123.                 return;
  124.             }
  125.         }
  126.     }
  127. }
  128.  
  129. void
  130. writeline(void) {
  131.  
  132.     if (! line.filename[0])
  133.         return;
  134.  
  135. #if 0    
  136. 01 4DOS40D.ZIP 11/17/91;00001;*;4DOS 4.0 - manual
  137. #endif
  138.  
  139.     line.description[LINE_MAX] = '\r';            /* limit this line */
  140.     line.description[LINE_MAX + 1] = '\n';        /* limit this line */
  141.     line.description[LINE_MAX + 2] = 0;            /* limit this line */
  142.  
  143.     printf("00 %s %02d/%02d/%02d;00000;cdrom;%s",
  144.         line.filename,
  145.         line.month,
  146.         line.day,
  147.         line.year,
  148.         line.description);
  149. }
  150.  
  151. void _Cdecl
  152. main(void) {
  153.     
  154.     while (1) {
  155.         readline();
  156.         writeline();
  157.     }
  158. }
  159.