home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / usagep24.lzh / CVTINC.C < prev    next >
C/C++ Source or Header  |  1992-11-10  |  4KB  |  159 lines

  1. /*
  2.  
  3. CVTINC -- Converts USAGE 2.1 and 2.2 /I files to USAGE 2.3 format
  4.  
  5. Version 1.1  (11/10/92)
  6.  
  7. Written by Bob Quinlan of Austin, Texas, USA
  8. Sysop of Red October at 512-834-2593 (1:382/111)
  9.  
  10. Copyright 1992 by Bob Quinlan
  11.  
  12.  
  13. CVTINC converts old USAGE /I files from the 2.1 or 2.2 formats to the
  14. 2.3 format.  It requires two command line parameters and accepts an
  15. optional third.  The first is the name of the old file to be converted.
  16. The second is the name of the 2.3 format file to create from it.  The
  17. third is the decimal of the old version number (1 for 2.1 or 2 for 2.2).
  18. If no version is specified 2.2 is assumed.
  19.  
  20.  
  21. CVTINC returns ERRORLEVEL 0 after a successful run.  ERRORLEVEL 1 is
  22. returned to indicate an error.
  23.  
  24. NOTICE:  You may use, copy, and distribute this program freely as long
  25. as you insure that both the executable and the documentation (.DOC)
  26. files are included in the distribution package.  The source code does
  27. not need to be included.  You may modify this program and document, so
  28. long as reasonable credit is given to the original author if a
  29. substantial portion of the original remains intact.  The author is not
  30. responsible for any losses which may occur either directly or indirectly
  31. as a result of using this program.
  32.  
  33. HISTORY:
  34. Version 1.1  (11/10/92) -- Modify to convert from 2.1 and 2.2 to 2.3.
  35. Version 1.0  (11/07/92) -- Original release.  Written in Borland C.
  36.  
  37. Large memory model
  38. */
  39.  
  40.  
  41. #include <dos.h>
  42. #include <fcntl.h>
  43. #include <io.h>
  44. #include <share.h>
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include <sys\stat.h>
  49. #include <sys\types.h>
  50.  
  51.  
  52. #define VERSION     "1.1"
  53. #define DATE        "11/10/92"
  54.  
  55. #define MAXLINE     (512)
  56. #define MAXSTAMP    (16)
  57.  
  58. #ifndef FALSE
  59.     #define FALSE 0
  60.     #define TRUE 1
  61. #endif
  62.  
  63.  
  64. typedef struct _increments
  65. {
  66.     long    lastpos;
  67.     char    last[MAXSTAMP];
  68.     int     online;
  69.     char    start[MAXSTAMP];
  70.     int     slen;
  71. } increments;
  72.  
  73.  
  74. int main(int argc, char *argv[])
  75. {
  76.     int     oldinc_fh;
  77.     int     newinc_fh;
  78.  
  79.     int     version = 2;
  80.  
  81.     increments      increment;
  82.  
  83.     char   line[MAXLINE];
  84.  
  85.  
  86. /************/
  87. /*  CVTINC  */
  88. /************/
  89.  
  90.     printf("CVTINC %s -- Copyright 1992 by Bob Quinlan (%s)\n\n", VERSION, DATE);
  91.  
  92.     if (argc < 3)
  93.     {
  94.         fprintf(stderr, "Usage:  CVTINC old.INC new.INC [1 | 2]\n\n");
  95.         exit(1);
  96.     }
  97.     if (argc > 3)
  98.     {
  99.         version = atoi(argv[3]);
  100.         if ((version < 1) || (version > 2))
  101.         {
  102.             fprintf(stderr, "CVTINC: Illegal version specification: %d\n",
  103.                 version);
  104.             exit(1);
  105.         }
  106.     }
  107.  
  108.     if ((oldinc_fh = sopen(argv[1], O_RDONLY | O_BINARY | O_DENYNONE,
  109.         SH_DENYNO, S_IREAD | S_IWRITE)) == -1)
  110.     {
  111.         fprintf(stderr, "CVTINC: Unable to open %s\n", argv[1]);
  112.         exit(1);
  113.     }
  114.  
  115.     /*  Fill in all fields  */
  116.     memset(&increment, 0, sizeof(increments));
  117.  
  118.     if ((newinc_fh = sopen(argv[2], O_WRONLY | O_CREAT | O_BINARY | O_DENYALL,
  119.         SH_DENYRW, S_IREAD | S_IWRITE)) == -1)
  120.     {
  121.         fprintf(stderr, "CVTINC: Unable to open %s\n", argv[2]);
  122.         exit(1);
  123.     }
  124.  
  125.     while (read(oldinc_fh, &increment.lastpos, sizeof(long)) >= sizeof(long))
  126.     {
  127.         if (version == 2)
  128.         {
  129.             if (read(oldinc_fh, &increment.online, sizeof(int)) < sizeof(int))
  130.             {
  131.                 break;
  132.             }
  133.             if (read(oldinc_fh, &increment.start, MAXSTAMP) < MAXSTAMP)
  134.             {
  135.                 break;
  136.             }
  137.         }
  138.         if (read(oldinc_fh, &increment.slen, sizeof(int)) < sizeof(int))
  139.         {
  140.             break;
  141.         }
  142.         if (read(oldinc_fh, line, increment.slen) < increment.slen)
  143.         {
  144.             break;
  145.         }
  146.  
  147.         /*  Write data in new format  */
  148.         write(newinc_fh, &increment, sizeof(increments));
  149.         write(newinc_fh, line, increment.slen);
  150.     }
  151.  
  152.     close(newinc_fh);
  153.     close(oldinc_fh);
  154.  
  155.     return 0;
  156. }
  157.  
  158.  
  159.