home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / TXI2IPF1 / SOURCE.ZIP / main.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-11  |  3.3 KB  |  145 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // $Id: main.cc,v 1.6 1993/02/10 20:58:21 ak Exp $
  3. ///////////////////////////////////////////////////////////////////////////////
  4. // $Log: main.cc,v $
  5. // Revision 1.6  1993/02/10  20:58:21  ak
  6. // Pass menues.
  7. //
  8. // Revision 1.5  1993/02/06  00:09:56  ak
  9. // *** empty log message ***
  10. //
  11. // Revision 1.4  1993/02/05  23:44:09  ak
  12. // Bugfixes and cosmetic changes.
  13. //
  14. // Revision 1.3  1993/02/05  08:44:21  ak
  15. // Statt -c besser Typ vom Output-File.
  16. //
  17. // Revision 1.2  1993/02/04  17:51:20  ak
  18. // *** empty log message ***
  19. //
  20. // Revision 1.1.1.1  1993/02/04  15:21:36  ak
  21. // Texinfo -> OS/2 IPF/INF converter.
  22. //
  23. // Revision 1.1  1993/02/04  15:21:33  ak
  24. // Initial revision
  25. //
  26. ///////////////////////////////////////////////////////////////////////////////
  27.  
  28. static char *rcsid = "$Id: main.cc,v 1.6 1993/02/10 20:58:21 ak Exp $";
  29.  
  30. #define EXTERN
  31. #define INIT(x) = x
  32. #include "info.h"
  33. #include <fstream.h>
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include <getopt.h>
  37. #include <process.h>
  38.  
  39. void
  40. usage()
  41. {
  42.     cout <<"texi2ipf [options {in [out]]" << endl
  43.          <<" -Dflag    set Texinfo flag" << endl
  44.          <<" -Uflag    clear Texinfo flag" << endl
  45.          <<" -n    use @node to split into panels, not @chapter" << endl
  46.          <<" -d    debugging aid" << endl
  47.          <<" -f    flex scanner trace" << endl
  48.          <<" in    texinfo file, default=stdin" << endl
  49.          <<" out    inf file (*.inf) or ipf source (else)" << endl;
  50. }
  51.  
  52. main(int argc, char **argv)
  53. {
  54.     int compile = 0;
  55.     ofstream *outf = 0;
  56.  
  57.     extern int yy_flex_debug;
  58.     yy_flex_debug = 0;
  59.  
  60.     GetOpt getopt(argc, argv, "dD:fnU:");
  61.     for (int c; (c = getopt()) != EOF; )
  62.         switch (c) {
  63.         case 'd':
  64.             ++debug;
  65.             break;
  66.         case 'D':
  67.             flags[getopt.optarg] = 1;
  68.             break;
  69.         case 'f':
  70.             ++yy_flex_debug;
  71.             break;
  72.         case 'n':
  73.             ++f_node;
  74.             break;
  75.         case 'U':
  76.             flags[getopt.optarg] = 0;
  77.             break;
  78.         default:
  79.             usage();
  80.             exit(2);
  81.         }
  82.     if (getopt.optind < argc) {
  83.         char *fn = argv[getopt.optind];
  84.         if (freopen(fn, "r", stdin) == NULL) {
  85.             perror(fn);
  86.             exit(1);
  87.         }
  88.     }
  89.     String ipfname, basename;
  90.     if (++getopt.optind < argc) {
  91.         ipfname = argv[getopt.optind];
  92.         int ext = ipfname.index('.', -1);
  93.         if (ext >= 0) {
  94.             basename = ipfname.before(ext);
  95.             if (fcompare(ipfname.from(ext), ".inf") == 0) {
  96.                 compile = 1;
  97.                 ipfname.from(ext) = ".ipf";
  98.             }
  99.         }
  100.         out = outf = new ofstream(ipfname);
  101.         if (!outf->good()) {
  102.             perror(ipfname);
  103.             exit(1);
  104.         }
  105.     }
  106.  
  107.     *out << ":userdoc." << endl
  108.          << ":docprof toc=123456." << endl;
  109.  
  110.     while ((c = yylex()) > 0)
  111.         if (c == '\n')
  112.             newline();
  113.         else
  114.             PUTS(c);
  115.  
  116.     *out << ":euserdoc." << endl;
  117.  
  118.     if (outf) {
  119.         outf->close();
  120.  
  121.         if (compile) {
  122.             Regex rpath ("[:\\\\/]");
  123.             int split = basename.index(rpath, -1);
  124.             if (split >= 0) {
  125.                 String path (basename.through(split));
  126.                 _chdrive(toupper(path[0])); // EMX library bug
  127.                 _chdir2(path);
  128.                 basename.del(0, split + 1);
  129.             }
  130.             int r = spawnlp(0, "ipfc", "ipfc",
  131.                 "/w1", "/codepage=850", "/inf",
  132.                 basename.chars(), NULL);
  133.             if (r < 0) {
  134.                 perror("starting ipfc");
  135.                 exit(1);
  136.             } else if (r == 0) {
  137.                 basename += ".ipf";
  138.                 remove(basename);
  139.             }
  140.         }
  141.     }
  142.             
  143.     return c ? 1 : 0;
  144. }
  145.