home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / TEXI2IPF / TEXI2IPF.C < prev    next >
Text File  |  1993-03-17  |  3KB  |  116 lines

  1. /*
  2.  * texi2ipf.c - texi2ipf mainline
  3.  *
  4.  * texi2roff history:
  5.  *             Release 1.0a    August 1988
  6.  *             Release 2.0     January 1990
  7.  *
  8.  * Copyright 1988, 1989, 1990  Beverly A.Erlebacher
  9.  * erlebach@cs.toronto.edu    ...uunet!utai!erlebach
  10.  *
  11.  * texi2ipf history:
  12.  *             Release 1.0     February 1993
  13.  *
  14.  * Modified by Marcus Gröber, Fido 2:2402/61.1
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>
  19. #ifndef __TURBOC__
  20. #include <sys/types.h>
  21. #endif
  22. #include <sys/stat.h>
  23. #include "texi2ipf.h"
  24.  
  25. char *progname;
  26.  
  27. /*
  28.  * main - parse arguments, handle options
  29.  *     - initialize tables and other strings
  30.  *     - open files and pass them to process().
  31.  */
  32. int main(argc, argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.     int errflg = 0;
  37.     FILE *in;
  38.     char *inname;
  39.     int optind = 1;    /* to keep structure without using getopt() */
  40.  
  41.     extern int process();
  42.     extern void initialize();
  43.  
  44.     progname = argv[0];
  45.  
  46.     if (errflg || argc < 2) {
  47.        (void) fprintf(stderr,
  48.            "\ntexi2ipf -=- Convert GNU texinfo files to OS/2 IPFC source code\n"
  49.            "Based on texi2roff by Beverly A.Erlebacher (1990)\n"
  50.            "Modified by Marcus Groeber 1993\n\n"
  51.            "Usage: %s texi_file(s) [>ipfc_file]\n", progname);
  52.        exit(1);
  53.     }
  54.  
  55.     (void) initialize();
  56.  
  57.     if (optind >= argc) {
  58.        errflg += process(stdin, "stdin");
  59.        }
  60.     else
  61.        for (; optind < argc; optind++) {
  62.            if (STREQ(argv[optind], "-")) {
  63.                inname = "stdin";
  64.                in = stdin;
  65.                }
  66.            else {
  67.                if (( in = fopen(argv[optind], "rt")) == NULL) {
  68.                    (void) fprintf(stderr,"%s : can't open file %s\n",
  69.                            progname, argv[optind]);
  70.                    continue;
  71.                }
  72.                inname = argv[optind];
  73.            }
  74.            errflg += process(in, inname);
  75.            if (in != stdin)
  76.                (void) fclose(in);
  77.        }
  78.     if(!errflg)
  79.       puts(cmds->exit);
  80.     exit(errflg);
  81. }
  82.  
  83. /*
  84.  * process -  check opened files and pass them to translate().
  85.  *        -  report on disastrous translation failures
  86.  */
  87. int
  88. process(fp, filename)
  89.     FILE *fp;
  90.     char *filename;
  91. {
  92.     struct stat statbuf;
  93.     extern int translate(/* FILE *, char * */);
  94.  
  95.     if (fstat(fileno(fp), &statbuf) != 0){
  96.        (void) fprintf(stderr,"%s : can't fstat file %s\n", progname,
  97.                                                                filename);
  98.        return 1;
  99.     }
  100.     if ((statbuf.st_mode & S_IFMT)==S_IFDIR) {
  101.        (void) fprintf(stderr, "%s : %s is a directory\n", progname,
  102.                                                                filename);
  103.        return 1;
  104.     }
  105.     /* translate returns 0 (ok) or -1 (disaster). it isn't worthwhile
  106.      * to try to recover from a disaster.
  107.      */
  108.     if (translate(fp, filename) < 0) {
  109.        (void) fprintf(stderr,
  110.                "%s: error while processing file %s, translation aborted\n",
  111.                progname, filename);
  112.        exit(1);
  113.     }
  114.     return 0;
  115. }
  116.