home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / utils / wxhelp / src / tex2help.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  8.4 KB  |  330 lines

  1. /*
  2.  * File:     tex2help.cc
  3.  * Purpose:  Converts classes.tex to xlp format
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                        Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #include <windows.h> // Included only for benefit of MSC7 precompiled headers
  30. #include "tex2any.h"
  31.  
  32. FILE *Library = NULL;
  33. FILE *Classes = NULL;
  34. FILE *Members = NULL;
  35. FILE *Index = NULL;
  36.  
  37. void Go(void)
  38. {
  39.   char *file = wxFileSelector("Choose LaTeX input file", NULL, NULL, "tex", "*.tex");
  40.   if (file)
  41.   {
  42.     TexLoadFile(file);
  43.  
  44.     Library = fopen("library.xlp", "w");
  45.     Classes = fopen("classes.xlp", "w");
  46.     Members = fopen("members.xlp", "w");
  47.     Index = fopen("index.xlp", "w");
  48.  
  49.     SetCurrentOutput(Library);
  50.  
  51.     long id = NewId();
  52.     fprintf(Library, "\\hy-%d{%ld}{wxWindows Classes}\n",
  53.              BLOCK_LARGE_SECTION, id);
  54.     fprintf(Index, "\n\\hyindex{\n\"wxWindows Help\"\n");
  55.     TraverseDocument();
  56.     fprintf(Index, "}\n");
  57.  
  58.     fclose(Library);
  59.     fclose(Classes);
  60.     fclose(Members);
  61.     fclose(Index);
  62.  
  63.     wxConcatFiles("library.xlp", "classes.xlp", "tmp1.xlp");
  64.     wxConcatFiles("tmp1.xlp", "members.xlp", "tmp2.xlp");
  65.     wxConcatFiles("tmp2.xlp", "index.xlp", "wx.xlp");
  66.     wxRemoveFile("tmp1.xlp");
  67.     wxRemoveFile("tmp2.xlp");
  68.  
  69.     wxRemoveFile("library.xlp");
  70.     wxRemoveFile("classes.xlp");
  71.     wxRemoveFile("members.xlp");
  72.     wxRemoveFile("index.xlp");
  73.   }
  74. }
  75.  
  76. // Define a new application type
  77. class MyApp: public wxApp
  78. { public:
  79.     wxFrame *OnInit(void);
  80. };
  81.  
  82. // Define a new frame type
  83. class MyFrame: public wxFrame
  84. { public:
  85.     MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
  86.     void OnMenuCommand(int id);
  87. };
  88.  
  89. // ID for the menu quit command
  90. #define TEX_QUIT 1
  91. #define TEX_GO   2
  92.  
  93. // This statement initializes the whole application and calls OnInit
  94. MyApp myApp;
  95.  
  96. // `Main program' equivalent, creating windows and returning main app frame
  97. wxFrame *MyApp::OnInit(void)
  98. {
  99.   // Create the main frame window
  100.   MyFrame *frame = new MyFrame(NULL, "tex2help", 0, 0, 400, 300);
  101.  
  102.   // Put names which subsume other names at the TOP
  103.   // so they get recognized first
  104.   AddMacroDef("verbatim", 1);
  105.   AddMacroDef("comment", 1, TRUE);
  106.   AddMacroDef("helpignore", 1, TRUE);
  107.   AddMacroDef("itemize", 1);
  108.   AddMacroDef("enumerate", 1);
  109.   AddMacroDef("item", 0);
  110.   AddMacroDef("chapter", 1);
  111.   AddMacroDef("section", 1);
  112.   AddMacroDef("subsection", 1);
  113.   AddMacroDef("newpage", 0, TRUE);
  114.   AddMacroDef("special", 1, TRUE);
  115.   AddMacroDef("caption", 1, TRUE);
  116.   AddMacroDef("figure", 1, TRUE);
  117.   AddMacroDef("centerline", 1, TRUE);
  118.   AddMacroDef("psboxto", 0, TRUE);
  119.   AddMacroDef("psbox", 0, TRUE);
  120.   AddMacroDef("vskip", 0, TRUE);
  121.   AddMacroDef("hskip", 0, TRUE);
  122.   AddMacroDef("class", 1);
  123.   AddMacroDef("membersection", 1);
  124.   AddMacroDef("member", 2);
  125.   AddMacroDef("func", 3);
  126.   AddMacroDef("pfunc", 3);
  127.   AddMacroDef("param", 2);
  128.   AddMacroDef("destruct", 1);
  129.   AddMacroDef("void", 0);
  130.   AddMacroDef("cinsert", 0);
  131.   AddMacroDef("cextract", 0);
  132.   AddMacroDef("label", 1, TRUE);
  133.   AddMacroDef("ref", 1);
  134.   AddMacroDef("helpref", 1);
  135.   AddMacroDef("it", 1, FALSE, TRUE);
  136.   AddMacroDef("bf", 1, FALSE, TRUE);
  137.   AddMacroDef("tt", 1, FALSE, TRUE);
  138.   AddMacroDef("\\", 0);
  139.   AddMacroDef("/", 0);
  140.   AddMacroDef("_", 0);
  141.   AddMacroDef("&", 0);
  142.  
  143.   TexInitialize();
  144.  
  145.   // Make a menubar
  146.   wxMenu *file_menu = new wxMenu;
  147.   file_menu->Append(TEX_GO, "Go");
  148.   file_menu->Append(TEX_QUIT, "Quit");
  149.   wxMenuBar *menu_bar = new wxMenuBar;
  150.   menu_bar->Append(file_menu, "File");
  151.   frame->SetMenuBar(menu_bar);
  152.  
  153.   frame->Show(TRUE);
  154.  
  155.   // Return the main frame window
  156.   return frame;
  157. }
  158.  
  159. // My frame constructor
  160. MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
  161.   wxFrame(frame, title, x, y, w, h)
  162. {}
  163.  
  164. // Intercept menu commands
  165. void MyFrame::OnMenuCommand(int id)
  166. {
  167.   switch (id) {
  168.     case TEX_QUIT:
  169.       delete this;
  170.       break;
  171.     case TEX_GO:
  172.       Go();
  173.       break;
  174.     break;
  175.   }
  176. }
  177.  
  178. // Called on start/end of macro examination
  179. void OnMacro(char *name, int no_args, Bool start)
  180. {
  181.   if (strcmp(name, "section") == 0)
  182.   {
  183.     if (start)
  184.     {
  185.       SetCurrentOutputs(Library, Classes);
  186.       long id1 = NewId();
  187.       long id2 = NewId();
  188.       fprintf(Library, "  \\hy-%d{%ld}{", BLOCK_RED, id1);
  189.       fprintf(Classes, "\n\\hy-%d{%ld}{", BLOCK_LARGE_SECTION, id2);
  190.       fprintf(Index, "%ld %ld\n", id1, id2);
  191.     }
  192.     else
  193.     {
  194.       fprintf(Library, "}\n\n");
  195.       fprintf(Classes, "}");
  196.       SetCurrentOutput(Classes);
  197.     }
  198.   }
  199.   else if (strcmp(name, "membersection") == 0)
  200.   {
  201.     if (start)
  202.     {
  203.       SetCurrentOutputs(Classes, Members);
  204.       long id1 = NewId();
  205.       long id2 = NewId();
  206.       fprintf(Classes, "\\hy-%d{%ld}{", BLOCK_RED, id1);
  207.       fprintf(Members, "\\hy-%d{%ld}{", BLOCK_LARGE_SECTION, id2);
  208.       fprintf(Index, "%ld %ld\n", id1, id2);
  209.     }
  210.     else
  211.     {
  212.       fprintf(Classes, "}\n\n");
  213.       fprintf(Members, "}");
  214.       SetCurrentOutput(Members);
  215.     }
  216.   }
  217.   else if ((strcmp(name, "func") == 0) || (strcmp(name, "pfunc") == 0))
  218.   {
  219.     SetCurrentOutput(Members);
  220.     if (start)
  221.     {
  222.       long id = NewId();
  223.       fprintf(Members, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  224.     }
  225.     else
  226.       fprintf(Members, "}");
  227.   }
  228.   else if (strcmp(name, "member") == 0)
  229.   {
  230.     SetCurrentOutput(Members);
  231.     if (start)
  232.     {
  233.       long id = NewId();
  234.       fprintf(Members, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  235.     }
  236.     else
  237.       fprintf(Members, "}");
  238.   }
  239.   else if ((strcmp(name, "void") == 0) && start)
  240.     TexOutput("void");
  241.   else if ((strcmp(name, "cinsert") == 0) && start)
  242.     TexOutput("<<");
  243.   else if ((strcmp(name, "cextract") == 0) && start)
  244.     TexOutput(">>");
  245.   else if ((strcmp(name, "destruct") == 0) && start)
  246.     TexOutput("~");
  247.   else if ((strcmp(name, "_") == 0) && start)
  248.     TexOutput("_");
  249.   else if ((strcmp(name, "&") == 0) && start)
  250.     TexOutput("&");
  251.   else if (strcmp(name, "verbatim") == 0)
  252.   {
  253.     if (start)
  254.     {
  255.       char buf[100];
  256.       long id = NewId();
  257.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_TELETYPE, id);
  258.       TexOutput(buf);
  259.     }
  260.     else TexOutput("}");
  261.   }
  262.   else if ((strcmp(name, "subsection") == 0) || (strcmp(name, "bf") == 0) || (strcmp(name, "helpref") == 0))
  263.   {
  264.     if (start)
  265.     {
  266.       char buf[100];
  267.       long id = NewId();
  268.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  269.       TexOutput(buf);
  270.     }
  271.     else TexOutput("}");
  272.   }
  273.   else if (strcmp(name, "it") == 0)
  274.   {
  275.     if (start)
  276.     {
  277.       char buf[100];
  278.       long id = NewId();
  279.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_ITALIC, id);
  280.       TexOutput(buf);
  281.     }
  282.     else TexOutput("}");
  283.   }
  284.   else if (strcmp(name, "item") == 0)
  285.   {
  286.     if (start)
  287.     {
  288.       TexOutput(" -- ");
  289.     }
  290.   }
  291.   else
  292.   {
  293.   }
  294. }
  295.  
  296. // Called on start/end of argument examination
  297. void OnArgument(char *macro_name, int arg_no, Bool start)
  298. {
  299.   if (strcmp(macro_name, "func") == 0)
  300.   {
  301.     if (!start && (arg_no == 1))
  302.       TexOutput(" ");
  303.     if (start && (arg_no == 3))
  304.       TexOutput("(");
  305.     if (!start && (arg_no == 3))
  306.      TexOutput(")");
  307.   }
  308.   else if (strcmp(macro_name, "pfunc") == 0)
  309.   {
  310.     if (!start && (arg_no == 1))
  311.       TexOutput(" ");
  312.  
  313.     if (start && (arg_no == 2))
  314.       TexOutput("(*");
  315.     if (!start && (arg_no == 2))
  316.       TexOutput(")");
  317.  
  318.     if (start && (arg_no == 3))
  319.       TexOutput("(");
  320.     if (!start && (arg_no == 3))
  321.       TexOutput(")");
  322.   }
  323.   else if (strcmp(macro_name, "member") == 0)
  324.   {
  325.     if (!start && (arg_no == 1))
  326.       TexOutput(" ");
  327.   }
  328. }
  329.  
  330.