home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / texipf22.zip / texi2ipf / texi2ipf.c < prev    next >
C/C++ Source or Header  |  1997-07-17  |  5KB  |  177 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.  * Modified by Martin "Herbert" Dietze, Email herbert@wiloyee.shnet.org
  17.  *
  18.  */
  19.  
  20. /*
  21.  * History:
  22.  *
  23.  * $Log: texi2ipf.c,v $
  24.  * Revision 1.1.1.1  1997/07/17 13:49:26  HERBERT
  25.  * Texi2IPF 2.2 new import
  26.  *
  27.  * Revision 1.6  1997/02/06 12:45:17  herbert
  28.  * - Added documentation in Texinfo format.
  29.  * - Minor bug fixes.
  30.  *
  31.  * Revision 1.5  1997/02/04 13:05:43  herbert
  32.  * Menu descriptions of more than one lines are now converted correctly if they
  33.  * are indented by more than 25 whitespaces (1 tab == 8 spaces).
  34.  *
  35.  * Revision 1.4  1997/01/10 14:56:44  herbert
  36.  * Fixed a weird error under OS/2 caused by too few stack.
  37.  *
  38.  * Revision 1.3  1996/12/17 15:14:22  herbert
  39.  * Only some cosmetic changes. The code looks still rather ugly to me :-)
  40.  *
  41.  * Revision 1.2  1996/12/17 14:10:01  herbert
  42.  * Added support for pseudo-Texinfo-commands: @ifhtml (ignored) and @ipfline{}
  43.  * (my invention) for putting IPF code into the Texinfo source.
  44.  * Added @macro command to table.h, will be ignored.
  45.  *
  46.  * Revision 1.1.1.1  1996/12/02 12:10:01  herbert
  47.  * Texi2IPF 1.0
  48.  *
  49.  */
  50.  
  51. #include "texi2ipf.h"
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #ifndef __TURBOC__
  55. #include <sys/types.h>
  56. #endif
  57. #include <sys/stat.h>
  58. #include <string.h>
  59. #include <setjmp.h>
  60.  
  61. static char * id =
  62. "@(#)$Id: texi2ipf.c,v 1.1.1.1 1997/07/17 13:49:26 HERBERT Exp $";
  63.  
  64. /*
  65.  * I start by version 2.0 since it is the first version touched by me...
  66.  * (herbert)
  67.  */
  68. static char * version = "2.2";
  69.  
  70. char *progname;
  71. jmp_buf cleanup_point;  /* needed to reach the end-of-file processing
  72.                          * via longjmp() after encountering @bye */    
  73.  
  74. /*
  75.  * main - parse arguments, handle options
  76.  *     - initialize tables and other strings
  77.  *     - open files and pass them to process().
  78.  */
  79. int main( int argc, char * argv[])
  80. {
  81.     int errflg = 0;
  82.     FILE *in;
  83.     char *inname;
  84.     int h_optind = 1;   /* to keep structure without using getopt() */
  85.  
  86.     int process( FILE*, char*);
  87.     void initialize( void);
  88.  
  89.     progname = argv[0];
  90.  
  91.     if ( errflg || argc < 2 ) {
  92.         (void) fprintf( stderr,
  93.                        "\ntexi2ipf -=- Convert GNU texinfo files to "
  94.                        "OS/2 IPFC source code, version %s\n"
  95.                        "Based on texi2roff by Beverly A.Erlebacher (1990)\n"
  96.                        "Modified by Marcus Groeber (1993)\n"
  97.                        "Modified by Martin \"Herbert\" Dietze (1997)\n\n"
  98.                        "Usage: %s texi_file(s) [>ipfc_file]\n", 
  99.                         version, progname);
  100.         exit(1);
  101.     }
  102.  
  103.     initialize();
  104.  
  105.     if ( !setjmp( cleanup_point) ) /* Store address for longjmp() after @bye
  106.                                     * in Texinfo file... */
  107.         if ( h_optind >= argc ) {
  108.             errflg += process( stdin, "stdin");
  109.         } else
  110.             for (; h_optind < argc; h_optind++) {
  111.                 if ( STREQ(argv[h_optind], "-") ) {
  112.                     inname = "stdin";
  113.                     in = stdin;
  114.                 } else {
  115.     #ifdef __IBMC__
  116.     #  define OM_ "r"
  117.     #else
  118.     #  define OM_ "rt"
  119.     #endif
  120.                     if ( ( in = fopen(argv[h_optind], OM_)) == NULL ) {
  121.                         (void) fprintf( stderr, "%s : can't open file %s\n",
  122.                                         progname, argv[h_optind]);
  123.                         continue;
  124.                     }/* if */
  125.                     inname = argv[h_optind];
  126.                 }/* if */
  127.                 errflg += process( in, inname);
  128.                 if ( in != stdin )
  129.                     (void) fclose( in);
  130.                 /* endif */
  131.             }/* for */
  132.         /* endif */
  133.     else
  134.         if( !errflg )     /* we don't close files here as we exit the program anyway... */
  135.             puts( cmds->exit);
  136.         /* endif */
  137.     /* endif */
  138.     exit( errflg);
  139.     return 0; /* keep the compiler happy... */
  140. }
  141.  
  142. /*
  143.  * process -  check opened files and pass them to translate().
  144.  *        -  report on disastrous translation failures
  145.  */
  146. int process( FILE *fp, char *filename)
  147. {
  148.     struct stat statbuf;
  149.     int translate( FILE *, char *);
  150.  
  151.     if ( fstat(fileno(fp), &statbuf) != 0 ){
  152.         (void) fprintf( stderr, "%s : can't fstat file %s\n", progname,
  153.                         filename);
  154.         return 1;
  155.     }
  156. #ifdef __IBMC__
  157.     if (statbuf.st_mode & S_IFDIR) {
  158. #else
  159.     if ((statbuf.st_mode & S_IFMT)==S_IFDIR) {
  160. #endif
  161.         (void) fprintf( stderr, "%s : %s is a directory\n", progname,
  162.                         filename);
  163.         return 1;
  164.     }
  165.     /* translate returns 0 (ok) or -1 (disaster). it isn't worthwhile
  166.      * to try to recover from a disaster.
  167.      */
  168.     if ( translate( fp, filename) < 0 ) {
  169.         (void) fprintf( stderr,
  170.                         "%s: error while processing file %s,"
  171.                         " translation aborted\n",
  172.                         progname, filename);
  173.         exit( 1);
  174.     }
  175.     return 0;
  176. }
  177.