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

  1. /*
  2.  * File:     c2help.cc
  3.  * Purpose:  CLIPS function documentation --> XLP
  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 *Members = NULL;
  34. FILE *Index = NULL;
  35.  
  36. void Go(void)
  37. {
  38.   char *file = wxFileSelector("Choose LaTeX input file", NULL, NULL, "tex", "*.tex");
  39.   if (file)
  40.   {
  41.     TexLoadFile(file);
  42.  
  43.     Library = fopen("library.xlp", "w");
  44.     Members = fopen("functions.xlp", "w");
  45.     Index = fopen("index.xlp", "w");
  46.  
  47.     SetCurrentOutput(Library);
  48.  
  49.     long id = NewId();
  50.     fprintf(Library, "\\hy-%d{%ld}{CLIPS for HARDY functions}\n",
  51.              BLOCK_LARGE_SECTION, id);
  52.     fprintf(Index, "\n\\hyindex{\n\"CLIPS for HARDY Help\"\n");
  53.     TraverseDocument();
  54.     fprintf(Index, "}\n");
  55.  
  56.     fclose(Library);
  57.     fclose(Members);
  58.     fclose(Index);
  59.  
  60.     wxConcatFiles("library.xlp", "functions.xlp", "tmp1.xlp");
  61.     wxConcatFiles("tmp1.xlp", "index.xlp", "clips.xlp");
  62.     wxRemoveFile("tmp1.xlp");
  63.  
  64.     wxRemoveFile("library.xlp");
  65.     wxRemoveFile("functions.xlp");
  66.     wxRemoveFile("index.xlp");
  67.   }
  68. }
  69.  
  70. // Define a new application type
  71. class MyApp: public wxApp
  72. { public:
  73.     wxFrame *OnInit(void);
  74. };
  75.  
  76. // Define a new frame type
  77. class MyFrame: public wxFrame
  78. { public:
  79.     MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h);
  80.     void OnMenuCommand(int id);
  81. };
  82.  
  83. // ID for the menu quit command
  84. #define TEX_QUIT 1
  85. #define TEX_GO   2
  86.  
  87. // This statement initializes the whole application and calls OnInit
  88. MyApp myApp;
  89.  
  90. // `Main program' equivalent, creating windows and returning main app frame
  91. wxFrame *MyApp::OnInit(void)
  92. {
  93.   // Create the main frame window
  94.   MyFrame *frame = new MyFrame(NULL, "c2help", 0, 0, 400, 300);
  95.  
  96.   // Put names which subsume other names at the TOP
  97.   // so they get recognized first
  98.   AddMacroDef("verbatim", 1);
  99.   AddMacroDef("comment", 1, TRUE);
  100.   AddMacroDef("helpignore", 1, TRUE);
  101.   AddMacroDef("itemize", 1);
  102.   AddMacroDef("enumerate", 1);
  103.   AddMacroDef("item", 0);
  104.   AddMacroDef("chapter", 1);
  105.   AddMacroDef("section", 1);
  106.   AddMacroDef("subsection", 1);
  107.   AddMacroDef("newpage", 0, TRUE);
  108.   AddMacroDef("special", 1, TRUE);
  109.   AddMacroDef("caption", 1, TRUE);
  110.   AddMacroDef("figure", 1, TRUE);
  111.   AddMacroDef("class", 1);
  112.   AddMacroDef("functionsection", 1);
  113.   AddMacroDef("member", 2);
  114.   AddMacroDef("hardy", 0);
  115.   AddMacroDef("func", 3);
  116.   AddMacroDef("pfunc", 3);
  117.   AddMacroDef("param", 2);
  118.   AddMacroDef("destruct", 1);
  119.   AddMacroDef("void", 0);
  120.   AddMacroDef("cinsert", 0);
  121.   AddMacroDef("cextract", 0);
  122.   AddMacroDef("label", 1, TRUE);
  123.   AddMacroDef("ref", 1);
  124.   AddMacroDef("helpref", 1);
  125.   AddMacroDef("it", 1);
  126.   AddMacroDef("bf", 1);
  127.   AddMacroDef("tt", 1);
  128.   AddMacroDef(" ", 0);
  129.   AddMacroDef("\\", 0);
  130.   AddMacroDef("/", 0);
  131.   AddMacroDef("_", 0);
  132.   AddMacroDef("&", 0);
  133.  
  134.  
  135.   TexInitialize();
  136.  
  137.   // Make a menubar
  138.   wxMenu *file_menu = new wxMenu;
  139.   file_menu->Append(TEX_GO, "Go");
  140.   file_menu->Append(TEX_QUIT, "Quit");
  141.   wxMenuBar *menu_bar = new wxMenuBar;
  142.   menu_bar->Append(file_menu, "File");
  143.   frame->SetMenuBar(menu_bar);
  144.  
  145.   frame->Show(TRUE);
  146.  
  147.   // Return the main frame window
  148.   return frame;
  149. }
  150.  
  151. // My frame constructor
  152. MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h):
  153.   wxFrame(frame, title, x, y, w, h)
  154. {}
  155.  
  156. // Intercept menu commands
  157. void MyFrame::OnMenuCommand(int id)
  158. {
  159.   switch (id) {
  160.     case TEX_QUIT:
  161.       delete this;
  162.       break;
  163.     case TEX_GO:
  164.       Go();
  165.       break;
  166.     break;
  167.   }
  168. }
  169.  
  170. // Called on start/end of macro examination
  171. void OnMacro(char *name, int no_args, Bool start)
  172. {
  173.   char buf[100];
  174.  
  175.   if (strcmp(name, "section") == 0)
  176.   {
  177.     if (start)
  178.     {
  179.       SetCurrentOutputs(Library, Members);
  180.       long id1 = NewId();
  181.       long id2 = NewId();
  182.       fprintf(Library, "  \\hy-%d{%ld}{", BLOCK_RED, id1);
  183.       fprintf(Members, "\n\\hy-%d{%ld}{", BLOCK_LARGE_SECTION, id2);
  184.       fprintf(Index, "%ld %ld\n", id1, id2);
  185.     }
  186.     else
  187.     {
  188.       fprintf(Library, "}\n\n");
  189.       fprintf(Members, "}");
  190.       SetCurrentOutput(Members);
  191.     }
  192.   }
  193.   else if (strcmp(name, "functionsection") == 0)
  194.   {
  195.     if (start)
  196.     {
  197.       SetCurrentOutputs(Library, Members);
  198.       long id1 = NewId();
  199.       long id2 = NewId();
  200.       fprintf(Library, "\\hy-%d{%ld}{", BLOCK_RED, id1);
  201.       fprintf(Members, "\\hy-%d{%ld}{", BLOCK_LARGE_SECTION, id2);
  202.       fprintf(Index, "%ld %ld\n", id1, id2);
  203.     }
  204.     else
  205.     {
  206.       fprintf(Library, "}\n\n");
  207.       fprintf(Members, "}");
  208.       SetCurrentOutput(Members);
  209.     }
  210.   }
  211. /*
  212.   else if (strcmp(name, "func") == 0)
  213.   {
  214.     SetCurrentOutput(Members);
  215.     if (start)
  216.     {
  217.       long id = NewId();
  218.       fprintf(Members, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  219.     }
  220.     else
  221.       fprintf(Members, "}");
  222.   }
  223. */
  224.   else if ((strcmp(name, "void") == 0) && start)
  225.     TexOutput("void");
  226.   else if ((strcmp(name, "hardy") == 0) && start)
  227.     TexOutput("HARDY");
  228.   else if ((strcmp(name, "cinsert") == 0) && start)
  229.     TexOutput("<<");
  230.   else if ((strcmp(name, "cextract") == 0) && start)
  231.     TexOutput(">>");
  232.   else if ((strcmp(name, "destruct") == 0) && start)
  233.     TexOutput("~");
  234.   else if ((strcmp(name, "_") == 0) && start)
  235.     TexOutput("_");
  236.   else if ((strcmp(name, "&") == 0) && start)
  237.     TexOutput("&");
  238.   else if (strcmp(name, "verbatim") == 0)
  239.   {
  240.     if (start)
  241.     {
  242.       long id = NewId();
  243.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_TELETYPE, id);
  244.       TexOutput(buf);
  245.     }
  246.     else TexOutput("}");
  247.   }
  248.   else if ((strcmp(name, "subsection") == 0) || (strcmp(name, "bf") == 0) || (strcmp(name, "helpref") == 0))
  249.   {
  250.     if (start)
  251.     {
  252.       long id = NewId();
  253.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  254.       TexOutput(buf);
  255.     }
  256.     else TexOutput("}");
  257.   }
  258.   else if (strcmp(name, "it") == 0)
  259.   {
  260.     if (start)
  261.     {
  262.       long id = NewId();
  263.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_ITALIC, id);
  264.       TexOutput(buf);
  265.     }
  266.     else TexOutput("}");
  267.   }
  268.   else if (strcmp(name, "item") == 0)
  269.   {
  270.     if (start)
  271.     {
  272.       TexOutput(" -- ");
  273.     }
  274.   }
  275.   else
  276.   {
  277.   }
  278. }
  279.  
  280. // Called on start/end of argument examination
  281. void OnArgument(char *macro_name, int arg_no, Bool start)
  282. {
  283.   char buf[100];
  284.   if (strcmp(macro_name, "func") == 0)
  285.   {
  286.     if (!start && (arg_no == 1))
  287.       TexOutput(" ");
  288.     if (start && (arg_no == 2))
  289.     {
  290.       TexOutput("(");
  291.       long id = NewId();
  292.       sprintf(buf, "\\hy-%d{%ld}{", BLOCK_BOLD, id);
  293.       TexOutput(buf);
  294.     }
  295.     if (!start && (arg_no == 2))
  296.     {
  297.       TexOutput("}");
  298.     }
  299.     if (!start && (arg_no == 3))
  300.      TexOutput(")");
  301.   }
  302.   if (strcmp(macro_name, "param") == 0)
  303.   {
  304.     if (start && (arg_no == 2))
  305.     {
  306.       long id = NewId();
  307.       sprintf(buf, " \\hy-%d{%ld}{", BLOCK_BOLD, id);
  308.       TexOutput(buf);
  309.     }
  310.     if (!start && (arg_no == 2))
  311.     {
  312.       TexOutput("}");
  313.     }
  314.   }
  315. }
  316.  
  317.