home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTdoc.lha / docs / doc2hlp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-22  |  2.3 KB  |  115 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: doc2hlp.c,v 1.9 1995/11/29 17:54:48 drd Exp $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * doc2hlp.c  -- program to convert Gnuplot .DOC format to 
  8.  * VMS help (.HLP) format.
  9.  *
  10.  * This involves stripping all lines with a leading ?,
  11.  * @, #, or %.
  12.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  13.  *
  14.  * usage:  doc2hlp [file.doc [file.hlp]]
  15.  *
  16.  * Original version by David Kotz used the following one line script!
  17.  * sed '/^[?@#%]/d' file.doc > file.hlp
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <ctype.h>
  23.  
  24. #include "ansichek.h"
  25.  
  26. #define MAX_LINE_LEN    256
  27. #define TRUE 1
  28. #define FALSE 0
  29.  
  30. int main __P(( int argc, char **argv ));
  31. void convert __P(( FILE *a, FILE *b ));
  32. void process_line __P(( char *line, FILE *b ));
  33.  
  34. #include "termdoc.c"
  35.  
  36. int main(argc,argv)
  37. int argc;
  38. char **argv;
  39. {
  40. FILE * infile;
  41. FILE * outfile;
  42.     infile = stdin;
  43.     outfile = stdout;
  44.     if (argc > 3) {
  45.         fprintf(stderr,"Usage: %s [infile [outfile]]\n", argv[0]);
  46.         exit(1);
  47.     }
  48.     if (argc >= 2) 
  49.         if ( (infile = fopen(argv[1],"r")) == (FILE *)NULL) {
  50.             fprintf(stderr,"%s: Can't open %s for reading\n",
  51.                 argv[0], argv[1]);
  52.             exit(1);
  53.         }
  54.     if (argc == 3)
  55.         if ( (outfile = fopen(argv[2],"w")) == (FILE *)NULL) {
  56.             fprintf(stderr,"%s: Can't open %s for writing\n",
  57.                 argv[0], argv[2]);
  58.         }
  59.     
  60.     convert(infile,outfile);
  61.     exit(0);
  62.     return 0;
  63. }
  64.  
  65.  
  66. void convert(a,b)
  67.     FILE *a,*b;
  68. {
  69.     static char line[MAX_LINE_LEN];
  70.  
  71.     while (fgets(line,MAX_LINE_LEN,a)) {
  72.        process_line(line, b);
  73.     }
  74. }
  75.  
  76. void process_line(line, b)
  77.     char *line;
  78.     FILE *b;
  79. {
  80.     static int line_count = 0;
  81.  
  82.     line_count++;
  83.  
  84.     switch(line[0]) {        /* control character */
  85.        case '?': {            /* interactive help entry */
  86.           break;            /* ignore */
  87.        }
  88.        case '@': {            /* start/end table */
  89.           break;            /* ignore */
  90.        }
  91.        case '#': {            /* latex table entry */
  92.           break;            /* ignore */
  93.        }
  94.        case '%': {            /* troff table entry */
  95.           break;            /* ignore */
  96.        }
  97.        case '^': {            /* html entry */
  98.           break;            /* ignore */
  99.        }
  100.        case '\n':            /* empty text line */
  101.        case ' ': {            /* normal text line */
  102.           (void) fputs(line,b); 
  103.           break;
  104.        }
  105.        default: {
  106.           if (isdigit(line[0])) { /* start of section */
  107.             (void) fputs(line,b); 
  108.           } else
  109.             fprintf(stderr, "unknown control code '%c' in column 1, line %d\n", 
  110.                   line[0], line_count);
  111.           break;
  112.        }
  113.     }
  114. }
  115.