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

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