home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / bbs / opus / to_max.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-13  |  4.0 KB  |  224 lines

  1. /*
  2.  * from SIMTEL20, CICA, ulowel:/games format to:
  3.  * Remote Access / Maximus / TubFile / Opus / QuickBbs / SuperBbs
  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. AD-FEBBS.ZIP Great Demo for Febbs made by OUNO-Soft.
  14. #endif
  15.  
  16. #include <ctype.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #define SIMTEL    1
  22. #define CICA    2
  23. #define ULOWEL    3
  24.  
  25. struct data {
  26.     char filename[15];
  27.     long filesize;
  28.     int year;
  29.     int month;
  30.     int day;
  31.     char description[900];
  32. };
  33.  
  34. int pastheader = 0;
  35. int in_type;
  36. struct data line;
  37.  
  38. int
  39. readline(void) {
  40.     static char buf[1000] = "";
  41.     char workbuf[1000];
  42.     static char datebuf[5] = "12";
  43.     char *r;
  44.     
  45.     if (buf[0] == 0)
  46.         if (NULL == gets(buf))
  47.             return(1);
  48.     
  49.     line.filename[0] = 0;
  50.     line.description[0] = 0;
  51.     
  52.     if (in_type == ULOWEL) {
  53.         if (0 != strnicmp(buf, "file:", 5)) {
  54.             buf[0] = 0;
  55.             return(0);
  56.         }
  57.         
  58.         r = strtok(buf, "\r\n\t ");
  59.         if (! r) {
  60.             fprintf(stderr, "unknown line:\n%s\n", buf);
  61.             buf[0] = 0;
  62.             return(0);
  63.         }
  64.         
  65.         r += strlen(r) + 1;        /* skip 'file:' */
  66.         while (isspace(*r))        /* skip white */
  67.             ++r;
  68.         
  69.         r = strtok(r, "\r\n\t ");
  70.         if (! r) {
  71.             fprintf(stderr, "unknown line:\n%s\n", buf);
  72.             buf[0] = 0;
  73.             return(0);
  74.         }
  75.         
  76.         strcpy(line.filename, r);
  77.  
  78.         while (1) {
  79.             if (NULL == gets(buf))
  80.                 return(1);
  81.             if (buf[0] == '\r')
  82.                 continue;
  83.             if (! buf[0])
  84.                 continue;
  85.             if (isspace(buf[0])) {
  86.                 strcat(line.description, " ");
  87.                 strcat(line.description, &buf[1]);
  88.             } else
  89.                 return(0);
  90.         }
  91.     } else {
  92.  
  93.         /* wait for header */
  94.         if (! pastheader) {
  95.             if (in_type == CICA) {
  96.                 if (0 == strlen(buf))
  97.                     ++pastheader;
  98.             } else {
  99.                 if (strstr(buf, "================"))
  100.                     ++pastheader;
  101.             }
  102.             buf[0] = 0;
  103.             return(0);
  104.         }
  105.     
  106.         if (strlen(buf) == 0) {
  107.             fprintf(stderr, "zero length line\n");
  108.             buf[0] = 0;
  109.             return(0);
  110.         }
  111.  
  112.         if (strlen(buf) < 20) {
  113.             fprintf(stderr, "warning: line too short:\n%s\n", buf);
  114.         }
  115.     
  116.         strcpy(workbuf, buf);
  117.     
  118.         r = strtok(buf, "\r\n\t ");
  119.         if (! r) {
  120.             fprintf(stderr, "unknown line:\n%s\n", buf);
  121.             buf[0] = 0;
  122.             return(0);
  123.         }
  124.     
  125.         strcpy(line.filename, r);
  126.     
  127.         r += strlen(r) + 1;        /* skip name */
  128.         while (isspace(*r))        /* skip white */
  129.             ++r;
  130.  
  131.         if (in_type == SIMTEL) {
  132.             ++r;                    /* skip file type */
  133.     
  134.             while (isspace(*r))        /* skip white */
  135.                 ++r;
  136.     
  137.             r = strtok(r, "\r\n\t ");
  138.             if (! r) {
  139.                 fprintf(stderr, "unknown line:\n%s\n", buf);
  140.                 line.filename[0] = 0;
  141.                 buf[0] = 0;
  142.                 return(0);
  143.             }
  144.             
  145.             line.filesize = atol(r);
  146.             r += strlen(r) + 1;
  147.     
  148.             while (isspace(*r))        /* skip white */
  149.                 ++r;
  150.         }
  151.     
  152.         datebuf[0] = *r;
  153.         ++r;
  154.         datebuf[1] = *r;
  155.         ++r;
  156.         line.year = atoi(datebuf);
  157.     
  158.         datebuf[0] = *r;
  159.         ++r;
  160.         datebuf[1] = *r;
  161.         ++r;
  162.         line.month = atoi(datebuf);
  163.         datebuf[0] = *r;
  164.         ++r;
  165.         datebuf[1] = *r;
  166.         ++r;
  167.         line.day = atoi(datebuf);
  168.     
  169.         while (isspace(*r))        /* skip white */
  170.             ++r;
  171.     
  172.         if (*r)    
  173.             strcpy(line.description, r);
  174.         buf[0] = 0;
  175.         return(0);
  176.     }
  177. }
  178.  
  179. void
  180. writeline(void) {
  181.  
  182.     if (! line.filename[0])
  183.         return;
  184.  
  185. #if 0    
  186. 9600TEXT.ZIP  A pair of US Robotics text files about HST modems.
  187. #endif
  188.  
  189.     printf("%s %s\n", line.filename, line.description);
  190. }
  191.  
  192. void
  193. help(void) {
  194.     
  195.     fprintf(stderr,    "usage: to_max {simtel | cica | ulowel} < in > out\n");
  196.     fprintf(stderr, "               pick a input format\n");
  197.     exit(1);
  198. }
  199.     
  200.  
  201. void _Cdecl
  202. main(int argc, char *argv[]) {
  203.     int rv;
  204.     
  205.     if (argc != 2)
  206.         help();
  207.  
  208.     if (0 == stricmp("simtel", argv[1])) {
  209.         in_type = SIMTEL;
  210.     } else if (0 == stricmp("cica", argv[1])) {
  211.         in_type = CICA;
  212.     } else if (0 == stricmp("ulowel", argv[1])) {
  213.         in_type = ULOWEL;
  214.     } else
  215.         help();
  216.     
  217.     while (1) {
  218.         rv = readline();
  219.         writeline();
  220.         if (rv)
  221.             exit(0);
  222.     }
  223. }
  224.