home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / txict100.zip / texicvt1.00 / source / mainrtf.cc < prev    next >
C/C++ Source or Header  |  1997-03-31  |  9KB  |  266 lines

  1. /*
  2. ================================================================================
  3.                         Texinfo converting Tools
  4.                          Release 1.00 28.03.97
  5.                        (c) 1996 by Andreas Kaiser
  6.                     (c) 1997 by Karl Heinz Marbaise
  7. ================================================================================
  8.  
  9. Discription:
  10.     Mainprogramm for Texinfo to RTF converter
  11.  
  12. Authors:
  13.    Andreas Kaiser
  14.    Karl Heinz Marbaise
  15.  
  16. e-mail:
  17.    Internet: KHMarbaise@p69.ks.fido.de
  18.    Fido-net: 2:2452/117.69
  19.  
  20. Bugs, question:
  21.    to above e-mail adress.
  22.  
  23. Register:
  24.    Please send a e-mail to above adress to register.
  25.    (include the release you want to register)
  26.    This registration should be done to let me
  27.    know how many people using these tools and
  28.    if it is worth to invest more time in continuing
  29.    development these tools or let the first release
  30.    of them be the last.
  31.    That is the only reason to make a registration.
  32.    I think a e-mail is not to much, isn't it?
  33.  
  34. License:
  35.    The "Texinfo converting tools" are free software;
  36.    you can redistribute it and/or modify it under the terms of
  37.    the GNU General Public License as published by the Free
  38.    Software Foundation; either version 2, or (at your option)
  39.    any later version.
  40.  
  41.    The "Texinfo converting tools" are distributed in the hope that
  42.    they will be useful, but WITHOUT ANY WARRANTY; without even the
  43.    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  44.    PURPOSE.  See the GNU General Public License for more details.
  45.  
  46.    You should have received a copy of the GNU General Public License
  47.    along with the "Texinfo converting tools" ; see the file COPYING.
  48.    If not, write to the:
  49.    Free Software Foundation,
  50.    59 Temple Place - Suite 330,
  51.    Boston, MA 02111-1307, USA.
  52.  
  53.    See \texicvt1.00\COPYING for details.
  54.  
  55. ================================================================================
  56. */
  57.  
  58.  
  59. /*
  60. ------------------------------------------------------------------------------
  61.                       (R)evision (C)ontrol (S)ystem
  62. ------------------------------------------------------------------------------
  63. */
  64.  
  65. #ifdef __RCS__
  66. static const char *mainrtf_cc = "$Id: MAINRTF.CC 1.5 1997/03/30 15:08:20 KHM Exp $";
  67. #endif
  68.  
  69. /*--------------------------------------------------------------------------*/
  70. /*                             Include Files                                */
  71. /*--------------------------------------------------------------------------*/
  72.  
  73. #define EXTERN
  74. #define INIT(x) = x
  75. #include "info.h"
  76. #include <fstream.h>
  77. #include <stdio.h>
  78. #include <ctype.h>
  79. #if defined (__EMX__)
  80. #include <getopt.h>
  81. #else
  82. #include <GetOpt.h>
  83. #endif
  84.  
  85. #include "version.h"
  86.  
  87. void
  88. usage()
  89. {
  90.     cout <<"texi2rtf [options {in [out]]" << endl
  91.          <<" -Dflag    set Texinfo flag" << endl
  92.          <<" -Uflag    clear Texinfo flag" << endl
  93.          <<" -i    create IPF index" << endl
  94.          <<" -n    use @node to split into panels, not @chapter" << endl
  95.          <<" -d    debugging aid" << endl
  96.          <<" -f    flex scanner trace" << endl
  97.          <<" -v    print out version, copyright and" << endl
  98.              <<"        copying conditions." << endl
  99.          <<" in    texinfo file, default=stdin" << endl
  100.          <<" out    inf file (*.inf) or ipf source (else)" << endl;
  101. }
  102.  
  103. main(int argc, char **argv)
  104. {
  105.         int c;
  106.     int compile = 0;
  107.         int direct = 0;
  108.         char *fn = (char *)NULL;
  109. #if defined (__EMX__)
  110.         char s[_MAX_PATH];
  111.         char drive[_MAX_DRIVE];
  112.         char dir[_MAX_DIR];
  113.         char file[_MAX_FNAME];
  114.         char ext[_MAX_EXT];
  115. #endif
  116.     ofstream *outf = 0;
  117.  
  118.     extern int yy_flex_debug;
  119.     yy_flex_debug = 0;
  120.  
  121.         f_node = 0; /* use chapter */
  122.         f_index = 0; /* don't create index */
  123.  
  124.         IncludeFile = 0;
  125. #if defined (__EMX__)
  126.         GetOpt getopt(argc, argv, "?hdD:finU:ov");
  127. #else
  128.         GetOpt getopt(argc, argv, "?hdD:finU:v");
  129. #endif
  130.     for (c = 0; (c = getopt()) != EOF; )
  131.         switch (c) {
  132.                 case 'o':
  133.                         direct = 1;
  134.                         break;
  135.         case 'd':
  136.             ++debug;
  137.             break;
  138.         case 'D':
  139.             flags[getopt.optarg] = 1;
  140.             break;
  141.         case 'f':
  142.             ++yy_flex_debug;
  143.             break;
  144.         case 'i':
  145.             ++f_index;
  146.             break;
  147.         case 'n':
  148.             ++f_node;
  149.             break;
  150.         case 'U':
  151.             flags[getopt.optarg] = (const char *)0;
  152.             break;
  153.                 case 'v':
  154.                         PrintCopyright ();
  155.                 case '?':
  156.                 case 'h':
  157.         default:
  158.             usage();
  159.             exit(2);
  160.         }
  161.     if (getopt.optind < argc) {
  162.                 fn = argv[getopt.optind];
  163.         if (freopen(fn, "r", stdin) == NULL) {
  164.             perror(fn);
  165.             exit(1);
  166.         }
  167.     }
  168.     String ipfname, basename;
  169.  
  170. #if defined (__EMX__)
  171.         if (direct)
  172.         {
  173.             sprintf (s, fn);
  174.             _splitpath(s,drive,dir,file,ext);
  175.             _makepath (s,drive,dir,file,".rtf");
  176.             fprintf (stderr, "converting %s to %s\n", fn, s);
  177.         out = outf = new ofstream(s);
  178.         if (!outf->good()) {
  179.             perror(s);
  180.             exit(1);
  181.         }
  182.         }
  183. #endif
  184.     if (++getopt.optind < argc) {
  185.         ipfname = argv[getopt.optind];
  186.         int ext = ipfname.index('.', -1);
  187.         if (ext >= 0) {
  188.             basename = ipfname.before(ext);
  189.             if (fcompare(ipfname.from(ext), ".inf") == 0) {
  190.                 compile = 1;
  191.                 ipfname.from(ext) = ".ipf";
  192.             }
  193.         }
  194.         out = outf = new ofstream(ipfname);
  195.         if (!outf->good()) {
  196.             perror(ipfname);
  197.             exit(1);
  198.         }
  199.     }
  200.  
  201. *out << "{\\rtf1\\ansi \\deff4\\deflang1033{\\fonttbl" << endl;
  202. *out << "{\\f4\\froman\\fcharset0\\fprq2 Times New Roman;}}" << endl;
  203. *out << "{\\colortbl;\\red0\\green0\\blue0;" << endl;
  204. *out << "\\red0\\green0\\blue255;" << endl;
  205. *out << "\\red0\\green255\\blue255;" << endl;
  206. *out << "\\red0\\green255\\blue0;" << endl;
  207. *out << "\\red255\\green0\\blue255;" << endl;
  208. *out << "\\red255\\green0\\blue0;" << endl;
  209. *out << "\\red255\\green255\\blue0;" << endl;
  210. *out << "\\red255\\green255\\blue255;" << endl;
  211. *out << "\\red0\\green0\\blue128;" << endl;
  212. *out << "\\red0\\green128\\blue128;" << endl;
  213. *out << "\\red0\\green128\\blue0;" << endl;
  214. *out << "\\red128\\green0\\blue128;" << endl;
  215. *out << "\\red128\\green0\\blue0;" << endl;
  216. *out << "\\red128\\green128\\blue0;" << endl;
  217. *out << "\\red128\\green128\\blue128;" << endl;
  218. *out << "\\red192\\green192\\blue192;}" << endl;
  219. *out << "{\\stylesheet{\\f4\\fs20\\lang1031 \\snext0 Normal;}" << endl;
  220. *out << "{\\*\\cs10 \\additive Default Paragraph Font;}" << endl;
  221. *out << "{\\s15 \\f4\\fs20\\lang1031 \\sbasedon0\\snext15 footnote text;}" << endl;
  222. *out << "{\\*\\cs16 \\additive\\super \\sbasedon10 footnote reference;}}" << endl;
  223. *out << "{\\info{\\author Marbaise Karl Heinz}" << endl;
  224. *out << "{\\creatim\\yr1997\\mo3\\dy2\\hr22\\min31}" << endl;
  225. *out << "{\\version1}{\\edmins0}" << endl;
  226. *out << "{\\nofpages0}" << endl;
  227. *out << "{\\nofwords0}" << endl;
  228. *out << "{\\nofchars0}" << endl;
  229. *out << "{\\vern49205}}" << endl;
  230. *out << "\\paperw11906\\paperh16838\\margl1417\\margr1417\\margt1417\\margb1134" << endl;
  231. *out << "\\deftab708\\widowctrl\\ftnbj\\aenddoc\\hyphhotz425\\hyphcaps0\\formshade" << endl;
  232. *out << "\\fet0\\sectd" << endl;
  233. *out << "\\linex0\\headery709\\footery709\\colsx709\\endnhere" << endl;
  234. *out << "{\\*\\pnseclvl1\\pnucrm\\pnstart1\\pnindent720\\pnhang{\\pntxta .}}" << endl;
  235. *out << "{\\*\\pnseclvl2\\pnucltr\\pnstart1\\pnindent720\\pnhang{\\pntxta .}}" << endl;
  236. *out << "{\\*\\pnseclvl3\\pndec\\pnstart1\\pnindent720\\pnhang{\\pntxta .}}" << endl;
  237. *out << "{\\*\\pnseclvl4\\pnlcltr\\pnstart1\\pnindent720\\pnhang{\\pntxta )}}" << endl;
  238. *out << "{\\*\\pnseclvl5\\pndec\\pnstart1\\pnindent720\\pnhang{\\pntxtb (}{\\pntxta )}}" << endl;
  239. *out << "{\\*\\pnseclvl6\\pnlcltr\\pnstart1\\pnindent720\\pnhang{\\pntxtb (}{\\pntxta )}}" << endl;
  240. *out << "{\\*\\pnseclvl7\\pnlcrm\\pnstart1\\pnindent720\\pnhang{\\pntxtb (}{\\pntxta )}}" << endl;
  241. *out << "{\\*\\pnseclvl8\\pnlcltr\\pnstart1\\pnindent720\\pnhang{\\pntxtb (}{\\pntxta )}}" << endl;
  242. *out << "{\\*\\pnseclvl9\\pnlcrm\\pnstart1\\pnindent720\\pnhang{\\pntxtb (}{\\pntxta )}}" << endl;
  243. *out << "{\\comment " << RELEASENAME << " }" <<  endl;
  244. *out << "{\\comment " << COPYRIGHT << " }" << endl;
  245. *out << "\\pard\\plain" << endl;
  246.  
  247.     while ((c = yylex()) > 0)
  248.         {
  249.         if (c == '\n')
  250.                      /* *out << endl << "\\par "; */
  251.             newline (); /**out << endl;*/
  252.                 else
  253.                     PUTS ((char)c); /* *out << (char)c; */
  254.         }
  255.  
  256.         *out << "\\par }" << endl;
  257.  
  258.         if (outf)
  259.             outf->close();
  260.  
  261.         if (IncludeFile)
  262.             cerr << endl;
  263.  
  264.     return c ? 1 : 0;
  265. }
  266.