home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / bbs / pcbtool / to_pcb.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-15  |  5.7 KB  |  320 lines

  1. /*
  2.  * from SIMTEL20, CICA, ulowel:/games format to:
  3.  * pcboard
  4.  */
  5.  
  6. #if 0
  7. 1234567890123456789012345678901 [Simtel]
  8. 4DOSANN.ZIP   B    6864  910819  4DOS runs on DOS 5.0 and Norton DOS info
  9. 1234567890123456789012345678901 [CICA]
  10. diskindx.txt    901031    Cumulative Index of the WRK Disks (below)
  11. diskroot.zip    920610    Windows Resource Kit 4/3/92
  12. ---------->
  13. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  14.                                | modems.
  15. #endif
  16.  
  17. #include <ctype.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <sys\stat.h>
  22. #include <time.h>
  23.  
  24. #define SIMTEL    1
  25. #define CICA    2
  26. #define ULOWEL    3
  27.  
  28. struct data {
  29.     char filename[15];
  30.     long filesize;
  31.     int year;
  32.     int month;
  33.     int day;
  34.     char description[900];
  35. };
  36.  
  37. int pastheader = 0;
  38. int in_type;
  39. struct data line;
  40. char path[128];
  41.  
  42. int
  43. readline(void) {
  44.     static char buf[1000];
  45.     char workbuf[1000];
  46.     static char datebuf[5] = "12";
  47.     char *r;
  48.     int first = 1;
  49.     
  50.     if (buf[0] == 0)
  51.         if (NULL == gets(buf))
  52.             exit(0);
  53.     
  54.     line.filename[0] = 0;
  55.     line.description[0] = 0;
  56.         
  57.     if (in_type == ULOWEL) {
  58.         if (0 != strnicmp(buf, "file:", 5)) {
  59.             buf[0] = 0;
  60.             return(0);
  61.         }
  62.         
  63.         r = strtok(buf, "\r\n\t ");
  64.         if (! r) {
  65.             fprintf(stderr, "unknown line:\n%s\n", buf);
  66.             exit(1);
  67.             buf[0] = 0;
  68.             return(0);
  69.         }
  70.         
  71.         r += strlen(r) + 1;        /* skip 'file:' */
  72.         while (isspace(*r))        /* skip white */
  73.             ++r;
  74.         
  75.         r = strtok(r, "\r\n\t ");
  76.         if (! r) {
  77.             fprintf(stderr, "unknown line:\n%s\n", buf);
  78.             exit(1);
  79.             buf[0] = 0;
  80.             return(0);
  81.         }
  82.         
  83.         strcpy(line.filename, r);
  84.  
  85.         while (1) {
  86.             if (NULL == gets(buf))
  87.                 return(1);
  88.             if (buf[0] == '\r')
  89.                 continue;
  90.             if (! buf[0])
  91.                 continue;
  92.             if (isspace(buf[0])) {
  93.                 if (first)
  94.                     first = 0;
  95.                 else {
  96.                     strcat(line.description, " ");
  97.                 }
  98.                 strcat(line.description, &buf[1]);
  99.             } else
  100.                 return(0);
  101.         }
  102.     } else {
  103.  
  104.         /* wait for header */
  105.         if (! pastheader) {
  106.             if (in_type == CICA) {
  107.                 if (0 == strlen(buf))
  108.                     ++pastheader;
  109.             } else {
  110.                 if (strstr(buf, "================"))
  111.                     ++pastheader;
  112.             }
  113.             buf[0] = 0;
  114.             return(0);
  115.         }
  116.     
  117.         if (strlen(buf) == 0) {
  118.             fprintf(stderr, "zero length line\n");
  119.             exit(1);
  120.             buf[0] = 0;
  121.             return(0);
  122.         }
  123.  
  124.         if (strlen(buf) < 20) {
  125.             fprintf(stderr, "warning: line too short:\n%s\n", buf);
  126.             exit(1);
  127.         }
  128.     
  129.         strcpy(workbuf, buf);
  130.     
  131.         r = strtok(buf, "\r\n\t ");
  132.         if (! r) {
  133.             fprintf(stderr, "unknown line:\n%s\n", buf);
  134.             exit(1);
  135.             buf[0] = 0;
  136.             return(0);
  137.         }
  138.     
  139.         strcpy(line.filename, r);
  140.     
  141.         r += strlen(r) + 1;        /* skip name */
  142.         while (isspace(*r))        /* skip white */
  143.             ++r;
  144.  
  145.         if (in_type == SIMTEL) {
  146.             ++r;                    /* skip file type */
  147.     
  148.             while (isspace(*r))        /* skip white */
  149.                 ++r;
  150.     
  151.             r = strtok(r, "\r\n\t ");
  152.             if (! r) {
  153.                 fprintf(stderr, "unknown line:\n%s\n", buf);
  154.                 exit(1);
  155.                 line.filename[0] = 0;
  156.                 buf[0] = 0;
  157.                 return(0);
  158.             }
  159.             
  160.             line.filesize = atol(r);
  161.             r += strlen(r) + 1;
  162.     
  163.             while (isspace(*r))        /* skip white */
  164.                 ++r;
  165.         }
  166.     
  167.         datebuf[0] = *r;
  168.         ++r;
  169.         datebuf[1] = *r;
  170.         ++r;
  171.         line.year = atoi(datebuf);
  172.     
  173.         datebuf[0] = *r;
  174.         ++r;
  175.         datebuf[1] = *r;
  176.         ++r;
  177.         line.month = atoi(datebuf);
  178.         datebuf[0] = *r;
  179.         ++r;
  180.         datebuf[1] = *r;
  181.         ++r;
  182.         line.day = atoi(datebuf);
  183.     
  184.         while (isspace(*r))        /* skip white */
  185.             ++r;
  186.     
  187.         if (*r)    
  188.             strcpy(line.description, r);
  189.         buf[0] = 0;
  190.         return(0);
  191.     }
  192. }
  193.  
  194.  
  195. void
  196. writeline(void) {
  197.     char *r;
  198.     char *p;
  199.     FILE *foo;
  200.     char buf[128];
  201.     struct stat stat_buf;
  202.     struct tm *tm;
  203.     time_t t;
  204.  
  205.     if (! line.filename[0])
  206.         return;
  207.  
  208. #if 0    
  209. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  210.                                | modems.
  211. #endif
  212.  
  213.     if (in_type == CICA || in_type == ULOWEL) {
  214.         sprintf(buf, "%s\\%s", path, line.filename);
  215.         if (NULL == (foo = fopen(buf, "r"))) {
  216.             fprintf(stderr, "failed opening '%s'\n", buf);
  217.             exit(1);
  218.             exit(1);
  219.         }
  220.  
  221.         stat(buf, &stat_buf);
  222.  
  223.         fclose(foo);
  224.         
  225.         line.filesize = stat_buf.st_size;
  226.     }
  227.  
  228.     if (in_type == ULOWEL) {
  229.         t = stat_buf.st_ctime;
  230.         tm = localtime(&t);
  231.         line.month = tm->tm_mon;
  232.         line.day = tm->tm_mday;
  233.         line.year = tm->tm_year;
  234.     }
  235.     
  236.     printf("%-13s%8ld  %02d-%02d-%02d  ",
  237.         line.filename,
  238.         line.filesize,
  239.         line.month,
  240.         line.day,
  241.         line.year);
  242.     
  243.     /* write wrapping description */
  244.  
  245.     r = line.description;
  246.     while (1) {
  247.         if (strlen(r) <= 45) {        
  248.             printf("%s\n", r);
  249.             return;
  250.         }
  251.  
  252.         p = r + 45;
  253.         while (! isspace(*p))
  254.             --p;
  255.         
  256. #if 0    
  257. 9600TEXT.ZIP    16576  09-26-91  A pair of US Robotics text files about HST
  258.                                | modems.
  259. #endif
  260.         *p = 0;
  261.         printf("%s\n%31s| ", r, " ");
  262.         r = p + 1;
  263.     }
  264. }
  265.  
  266. void
  267. help(void) {
  268.  
  269.     switch (in_type) {
  270.         case SIMTEL:
  271.             fprintf(stderr,
  272.                 "usage: to_rbbs simtel < in > out\n");
  273.             break;
  274.         case ULOWEL:
  275.             fprintf(stderr,
  276.                 "usage: to_rbbs ulowel [directory path] < in > out\n");
  277.             break;
  278.         case CICA:
  279.             fprintf(stderr,
  280.                 "usage: to_rbbs cica [directory path] < in > out\n");
  281.             break;
  282.         default:
  283.             fprintf(stderr,
  284.     "usage: to_max {simtel | cica | ulowel} [directory path] < in > out\n");
  285.             fprintf(stderr,
  286.     "               pick a input format\n");
  287.             break;
  288.     }
  289.     exit(1);
  290. }
  291.  
  292.  
  293. void _Cdecl
  294. main(int argc, char *argv[]) {
  295.     int rv;
  296.     
  297.     if (argc == 1)
  298.         help();
  299.  
  300.     if (0 == stricmp("simtel", argv[1])) {
  301.         in_type = SIMTEL;
  302.     } else if (0 == stricmp("cica", argv[1])) {
  303.         in_type = CICA;
  304.     } else if (0 == stricmp("ulowel", argv[1])) {
  305.         in_type = ULOWEL;
  306.     } else
  307.         help();
  308.     
  309.     if (in_type == ULOWEL || in_type == CICA) {
  310.         strcpy(path, argv[2]);
  311.     }
  312.     
  313.     while (1) {
  314.         rv = readline();
  315.         writeline();
  316.         if (rv)
  317.             exit(0);
  318.     }
  319. }
  320.