home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / CONVERTR / RTF2HTML / SRC / RTF2HTML.TAR / rtftohtml_src / Libs / h / makehdrs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-05  |  2.9 KB  |  110 lines

  1. /* Think C program to make header files for Macintosh.                                 */
  2. /* This program produces rtf.h and stdcharnames.h files for the DuBois RTF parser.    */
  3. /* The output files have been checked with the Compare Files command of BBEdit and    */
  4. /* are identical to those produced by awk and sed under UNIX.                        */
  5.  
  6. /* Input files "standard-names" and "rtf.h.dist" are expected to be in the            */
  7. /* the directory rtftohtml/Libs/h relative to where the program runs -CJH-        */
  8. /* Macintosh users may want to use a utility like FileTyper to set the output files    */
  9. /* creator to 'KAHL' for convenient Mac access.                                        */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. char *fnrtft = ":rtftohtml_src:Libs:h:rtf.h.dist";        /* input files */
  16. char *fnstct = ":rtftohtml_src:Libs:h:standard-names";
  17. char *fnrtf = ":rtftohtml_src:Libs:h:rtf.h";                /* output files */
  18. char *fnstc = ":rtftohtml_src:Libs:h:stdcharnames.h";
  19. FILE *fin;
  20. FILE *frout, *fsout;
  21.  
  22. int main(int argc, char **argv)
  23. {
  24.     char buf[256];
  25.     char *fstat;
  26.     int fostat;
  27.     int len;
  28.     int count = 0;
  29.     
  30.     /* start with rtf.h */
  31.     
  32.     fin = fopen(fnrtft, "r");
  33.     if (fin == NULL) {
  34.         fprintf(stderr, "Can't open %s!\n", fnrtft);
  35.         exit(1);
  36.     }
  37.     
  38.     _fcreator = 'KAHL';
  39.     frout = fopen(fnrtf, "w");
  40.     if (frout == NULL) {
  41.         fprintf(stderr, "Can't open %s for writing!\n", fnrtf);
  42.         exit(1);
  43.     }
  44.     
  45.     /* copy rtf.h.dist to rtf.h */
  46.     
  47.     while (feof(fin) == false) {
  48.         fstat = fgets(buf, 255, fin);
  49.         if (fstat != NULL) {
  50.             fostat = fputs(buf, frout);
  51.             if (fostat == EOF) {
  52.                 fprintf(stderr, "Error copying %s!\n", fnrtf);
  53.                 exit(1);
  54.             }
  55.         } else {
  56.             if (ferror(fin) != 0) {
  57.                 fprintf(stderr, "Error reading %s!\n", fnrtft);
  58.                 exit(1);
  59.             }
  60.         }
  61.     }
  62.     fclose(fin);
  63.     
  64.     fprintf(frout, "\n/* The following defines are automatically generated.  Do not edit. */\n\n");
  65.     fprintf(frout, "\n/* These must be sequential beginning from zero */\n\n");
  66.     
  67.     /* Now process the standard character names.    */
  68.     
  69.     fin = fopen(fnstct, "r");
  70.     if (fin == NULL) {
  71.         fprintf(stderr, "Can't open %s!\n", fnstct);
  72.         exit(1);
  73.     }
  74.     
  75.     fsout = fopen(fnstc, "w");
  76.     if (frout == NULL) {
  77.         fprintf(stderr, "Can't open %s for writing!\n", fnstc);
  78.         exit(1);
  79.     }
  80.     
  81.     while (feof(fin) == false) {
  82.         fstat = fgets(buf, 255, fin);
  83.         if (fstat != NULL) {
  84.             if (strlen(buf) == 1 && buf[0] == '\n') {    /* ignore empty line */
  85.                 continue;
  86.             } else if (buf[0] == '#') {                    /* ignore comment line */
  87.                 continue;
  88.             } else {
  89.                 len = strlen(buf);
  90.                 buf[len - 1] = '\0';    /* smash newline */
  91.                 fprintf(frout, "#define rtfSC_%s\t%d\n", buf, count);
  92.                 fprintf(fsout, "\"%s\",\n", buf);
  93.                 count++;
  94.             }
  95.         } else {
  96.             if (ferror(fin) != 0) {
  97.                 fprintf(stderr, "Error reading %s!\n", fnstct);
  98.                 exit(1);
  99.             }
  100.         }
  101.     }
  102.     
  103.     fclose(fin);
  104.     fclose(fsout);
  105.     fprintf(frout, "\n#define rtfSC_MaxChar\t%d\n", count);
  106.     fclose(frout);
  107.     
  108.     fprintf(stderr, "Finished processing %d standard characters.\n", count);
  109.     exit(0);
  110. }