home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / bbs / pcbtool / to_pcb.c < prev   
Encoding:
C/C++ Source or Header  |  1992-05-03  |  2.6 KB  |  156 lines

  1. /*
  2.  * from simtel20 format to pcboard
  3.  *
  4.  */
  5.  
  6. #if 0
  7. 1234567890123456789012345678901
  8. 4DOSANN.ZIP   B    6864  910819  4DOS runs on DOS 5.0 and Norton DOS info
  9. ---------->
  10. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  11.                                | modems.
  12. #endif
  13.  
  14. #include <ctype.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. struct data {
  20.     char filename[15];
  21.     long filesize;
  22.     int year;
  23.     int month;
  24.     int day;
  25.     char description[900];
  26. };
  27.  
  28. int pastheader = 0;
  29. struct data line;
  30.  
  31. void
  32. readline(void) {
  33.     char buf[1000];
  34.     char workbuf[1000];
  35.     static char datebuf[5] = "12";
  36.     char *r;
  37.     
  38.     if (NULL == gets(buf))
  39.         exit(0);
  40.     
  41.     /* wait for header */
  42.     if (! pastheader) {
  43.         if (strstr(buf, "================"))
  44.             ++pastheader;
  45.             return;
  46.     }
  47.     
  48.     if (strlen(buf) < 31) {
  49.         fprintf(stderr, "warning: line too short:\n%s\n", buf);
  50.     }
  51.     
  52.     strcpy(workbuf, buf);
  53.     
  54.     r = strtok(buf, " ");
  55.     if (! r) {
  56.         fprintf(stderr, "unknown line:\n%s\n", buf);
  57.         return;
  58.     }
  59.     strcpy(line.filename, r);
  60.     
  61.     r += strlen(r) + 1;        /* skip name */
  62.     while (isspace(*r))        /* skip white */
  63.         ++r;
  64.     
  65.     ++r;                    /* skip file type */
  66.     
  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.         return;
  74.     }
  75.     line.filesize = atol(r);
  76.     r += strlen(r) + 1;
  77.     
  78.     while (isspace(*r))        /* skip white */
  79.         ++r;
  80.     
  81.     datebuf[0] = *r;
  82.     ++r;
  83.     datebuf[1] = *r;
  84.     ++r;
  85.     line.year = atoi(datebuf);
  86.     
  87.     datebuf[0] = *r;
  88.     ++r;
  89.     datebuf[1] = *r;
  90.     ++r;
  91.     line.month = atoi(datebuf);
  92.     datebuf[0] = *r;
  93.     ++r;
  94.     datebuf[1] = *r;
  95.     ++r;
  96.     line.day = atoi(datebuf);
  97.     
  98.     while (isspace(*r))        /* skip white */
  99.         ++r;
  100.     
  101.     if (*r)    
  102.         strcpy(line.description, r);
  103. }
  104.  
  105. void
  106. writeline(void) {
  107.     char *r;
  108.     char *p;
  109.  
  110.     if (! line.filename[0])
  111.         return;
  112.  
  113. #if 0    
  114. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  115.                                | modems.
  116. #endif
  117.  
  118.     printf("%-13s%8ld  %02d-%02d-%02d  ",
  119.         line.filename,
  120.         line.filesize,
  121.         line.month,
  122.         line.day,
  123.         line.year);
  124.     
  125.     /* write wrapping description */
  126.  
  127.     r = line.description;
  128.     while (1) {
  129.         if (strlen(r) <= 45) {        
  130.             printf("%s\n", r);
  131.             return;
  132.         }
  133.  
  134.         p = r + 45;
  135.         while (! isspace(*p))
  136.             --p;
  137.         
  138. #if 0    
  139. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  140.                                | modems.
  141. #endif
  142.         *p = 0;
  143.         printf("%s\n%31s| ", r, " ");
  144.         r = p + 1;
  145.     }
  146. }
  147.  
  148. void _Cdecl
  149. main(void) {
  150.     
  151.     while (1) {
  152.         readline();
  153.         writeline();
  154.     }
  155. }
  156.