1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     Converts Latex to linear/WinHelp RTF, HTML, wxHelp. 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  32 #if defined(NO_GUI) || defined(__UNIX__) 
  48 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)) && !defined(NO_GUI) 
  49 #include "tex2rtf.xpm" 
  52 const float versionNo 
= 2.0; 
  54 TexChunk 
*currentMember 
= NULL
; 
  55 bool startedSections 
= FALSE
; 
  56 char *contentsString 
= NULL
; 
  57 bool suppressNameDecoration 
= FALSE
; 
  58 bool OkToClose 
= TRUE
; 
  64 extern char *BigBuffer
; 
  65 extern char *TexFileRoot
; 
  66 extern char *TexBibName
;         // Bibliography output file name 
  67 extern char *TexTmpBibName
;      // Temporary bibliography output file name 
  68 extern wxList ColourTable
; 
  69 extern TexChunk 
*TopLevel
; 
  70 extern char *PageStyle
; 
  71 extern char *BibliographyStyleString
; 
  72 extern char *DocumentStyleString
; 
  73 extern char *bitmapMethod
; 
  74 extern char *backgroundColourString
; 
  75 extern char *ContentsNameString
; 
  76 extern char *AbstractNameString
; 
  77 extern char *GlossaryNameString
; 
  78 extern char *ReferencesNameString
; 
  79 extern char *FiguresNameString
; 
  80 extern char *TablesNameString
; 
  81 extern char *FigureNameString
; 
  82 extern char *TableNameString
; 
  83 extern char *IndexNameString
; 
  84 extern char *ChapterNameString
; 
  85 extern char *SectionNameString
; 
  86 extern char *SubsectionNameString
; 
  87 extern char *SubsubsectionNameString
; 
  88 extern char *UpNameString
; 
  93 wxHelpController 
*HelpInstance 
= NULL
; 
  97 static char *ipc_buffer 
= NULL
; 
  98 static char Tex2RTFLastStatus
[100]; 
  99 Tex2RTFServer 
*TheTex2RTFServer 
= NULL
; 
 103 char *bulletFile 
= NULL
; 
 105 FILE *Contents 
= NULL
;   // Contents page 
 106 FILE *Chapters 
= NULL
;   // Chapters (WinHelp RTF) or rest of file (linear RTF) 
 107 FILE *Sections 
= NULL
; 
 108 FILE *Subsections 
= NULL
; 
 109 FILE *Subsubsections 
= NULL
; 
 111 FILE *WinHelpContentsFile 
= NULL
; 
 113 char *InputFile 
= NULL
; 
 114 char *OutputFile 
= NULL
; 
 115 char *MacroFile 
= copystring("tex2rtf.ini"); 
 117 char *FileRoot 
= NULL
; 
 118 char *ContentsName 
= NULL
;    // Contents page from last time around 
 119 char *TmpContentsName 
= NULL
; // Current contents page 
 120 char *TmpFrameContentsName 
= NULL
; // Current frame contents page 
 121 char *WinHelpContentsFileName 
= NULL
; // WinHelp .cnt file 
 122 char *RefFileName 
= NULL
;         // Reference file name 
 124 char *RTFCharset 
= copystring("ansi"); 
 127 int BufSize 
= 100;             // Size of buffer in K 
 133 void ShowOptions(void); 
 137 #if wxUSE_GUI || !defined(__UNIX__) 
 138 // wxBase for Unix does not have wxBuffer 
 141 char *wxBuffer
; // we must init it, otherwise tex2rtf will crash 
 143 int main(int argc
, char **argv
) 
 145 wxMenuBar 
*menuBar 
= NULL
; 
 146 MyFrame 
*frame 
= NULL
; 
 148 // DECLARE_APP(MyApp) 
 151 // `Main program' equivalent, creating windows and returning main app frame 
 155   // Use default list of macros defined in tex2any.cc 
 156   DefineDefaultMacros(); 
 157   AddMacroDef(ltHARDY
, "hardy", 0); 
 159   FileRoot 
= new char[300]; 
 160   ContentsName 
= new char[300]; 
 161   TmpContentsName 
= new char[300]; 
 162   TmpFrameContentsName 
= new char[300]; 
 163   WinHelpContentsFileName 
= new char[300]; 
 164   RefFileName 
= new char[300]; 
 166   ColourTable
.DeleteContents(TRUE
); 
 170   // Read input/output files 
 173     if (argv
[1][0] != '-') 
 180         if (argv
[2][0] != '-') 
 182           OutputFile 
= argv
[2]; 
 190   wxBuffer 
= new char[1500]; 
 191   // this is done in wxApp, but NO_GUI version doesn't call it :-( 
 193   if (!InputFile 
|| !OutputFile
) 
 195     cout 
<< "Tex2RTF: input or output file is missing.\n"; 
 203     TexPathList
.EnsureFileAccessible(InputFile
); 
 205   if (!InputFile 
|| !OutputFile
) 
 206     isInteractive 
= TRUE
; 
 209   for (i 
= n
; i 
< argc
;) 
 211     if (strcmp(argv
[i
], "-winhelp") == 0) 
 214       convertMode 
= TEX_RTF
; 
 218     else if (strcmp(argv
[i
], "-interactive") == 0) 
 221       isInteractive 
= TRUE
; 
 224     else if (strcmp(argv
[i
], "-sync") == 0)  // Don't yield 
 229     else if (strcmp(argv
[i
], "-rtf") == 0) 
 232       convertMode 
= TEX_RTF
; 
 234     else if (strcmp(argv
[i
], "-html") == 0) 
 237       convertMode 
= TEX_HTML
; 
 239     else if (strcmp(argv
[i
], "-xlp") == 0) 
 242       convertMode 
= TEX_XLP
; 
 244     else if (strcmp(argv
[i
], "-twice") == 0) 
 249     else if (strcmp(argv
[i
], "-macros") == 0) 
 254         MacroFile 
= copystring(argv
[i
]); 
 258     else if (strcmp(argv
[i
], "-bufsize") == 0) 
 263         BufSize 
= atoi(argv
[i
]); 
 267     else if (strcmp(argv
[i
], "-charset") == 0) 
 274         if (strcmp(s
, "ansi") == 0 || strcmp(s
, "pc") == 0 || strcmp(s
, "mac") == 0 || 
 275             strcmp(s
, "pca") == 0) 
 276           RTFCharset 
= copystring(s
); 
 279           OnError("Incorrect argument for -charset"); 
 284     else if (strcmp(argv
[i
], "-checkcurleybraces") == 0) 
 287       checkCurleyBraces 
= TRUE
; 
 289     else if (strcmp(argv
[i
], "-checksyntax") == 0) 
 297       buf
.Printf("Invalid switch %s.\n", argv
[i
]); 
 298       OnError((char *)buf
.c_str()); 
 308 #if defined(__WXMSW__) && !defined(NO_GUI) 
 310   Tex2RTFLastStatus
[0] = 0; // DDE connection return value 
 311   TheTex2RTFServer 
= new Tex2RTFServer
; 
 312   TheTex2RTFServer
->Create("TEX2RTF"); 
 315 #if defined(__WXMSW__) && defined(__WIN16__) 
 316   // Limit to max Windows array size 
 317   if (BufSize 
> 64) BufSize 
= 64; 
 320   TexInitialize(BufSize
); 
 321   ResetContentsLevels(0); 
 329     // Create the main frame window 
 330     frame 
= new MyFrame(NULL
, -1, "Tex2RTF", wxPoint(-1, -1), wxSize(400, 300)); 
 331     frame
->CreateStatusBar(2); 
 334     // TODO: uncomment this when we have tex2rtf.xpm 
 335     frame
->SetIcon(wxICON(tex2rtf
)); 
 339       sprintf(buf
, "Tex2RTF [%s]", FileNameFromPath(InputFile
)); 
 340       frame
->SetTitle(buf
); 
 344     wxMenu 
*file_menu 
= new wxMenu
; 
 345     file_menu
->Append(TEX_GO
, "&Go",                        "Run converter"); 
 346     file_menu
->Append(TEX_SET_INPUT
, "Set &Input File",     "Set the LaTeX input file"); 
 347     file_menu
->Append(TEX_SET_OUTPUT
, "Set &Output File",   "Set the output file"); 
 348     file_menu
->AppendSeparator(); 
 349     file_menu
->Append(TEX_VIEW_LATEX
, "View &LaTeX File",   "View the LaTeX input file"); 
 350     file_menu
->Append(TEX_VIEW_OUTPUT
, "View Output &File", "View output file"); 
 351     file_menu
->Append(TEX_SAVE_FILE
, "&Save log file", "Save displayed text into file"); 
 352     file_menu
->AppendSeparator(); 
 353     file_menu
->Append(TEX_QUIT
, "E&xit",                    "Exit Tex2RTF"); 
 355     wxMenu 
*macro_menu 
= new wxMenu
; 
 357     macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, "&Load Custom Macros", "Load custom LaTeX macro file"); 
 358     macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, "View &Custom Macros", "View custom LaTeX macros"); 
 360     wxMenu 
*mode_menu 
= new wxMenu
; 
 362     mode_menu
->Append(TEX_MODE_RTF
, "Output linear &RTF",   "Wordprocessor-compatible RTF"); 
 363     mode_menu
->Append(TEX_MODE_WINHELP
, "Output &WinHelp RTF", "WinHelp-compatible RTF"); 
 364     mode_menu
->Append(TEX_MODE_HTML
, "Output &HTML",        "HTML World Wide Web hypertext file"); 
 365     mode_menu
->Append(TEX_MODE_XLP
, "Output &XLP",          "wxHelp hypertext help file"); 
 367     wxMenu 
*options_menu 
= new wxMenu
; 
 369     options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, "Curley brace matching",   "Checks for mismatched curley braces",TRUE
); 
 370     options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, "Syntax checking", "Syntax checking for common errors",TRUE
); 
 372     options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
); 
 373     options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
); 
 375     wxMenu 
*help_menu 
= new wxMenu
; 
 377     help_menu
->Append(TEX_HELP
, "&Help", "Tex2RTF Contents Page"); 
 378     help_menu
->Append(TEX_ABOUT
, "&About Tex2RTF", "About Tex2RTF"); 
 380     menuBar 
= new wxMenuBar
; 
 381     menuBar
->Append(file_menu
, "&File"); 
 382     menuBar
->Append(macro_menu
, "&Macros"); 
 383     menuBar
->Append(mode_menu
, "&Conversion Mode"); 
 384     menuBar
->Append(options_menu
, "&Options"); 
 385     menuBar
->Append(help_menu
, "&Help"); 
 387     frame
->SetMenuBar(menuBar
); 
 388     frame
->textWindow 
= new wxTextCtrl(frame
, -1, "", wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY
|wxTE_MULTILINE
); 
 390     (*frame
->textWindow
) << "Welcome to Julian Smart's LaTeX to RTF converter.\n"; 
 394     HelpInstance 
= new wxHelpController(); 
 395     HelpInstance
->Initialize("tex2rtf"); 
 399      * Read macro/initialisation file 
 404     if ((path 
= TexPathList
.FindValidPath(MacroFile
)) != "") 
 405       ReadCustomMacros((char*) (const char*) path
); 
 409     if (winHelp 
&& (convertMode 
== TEX_RTF
)) 
 410       strcat(buf
, "WinHelp RTF"); 
 411     else if (!winHelp 
&& (convertMode 
== TEX_RTF
)) 
 412       strcat(buf
, "linear RTF"); 
 413     else if (convertMode 
== TEX_HTML
) strcat(buf
, "HTML"); 
 414     else if (convertMode 
== TEX_XLP
) strcat(buf
, "XLP"); 
 415       strcat(buf
, " mode."); 
 416     frame
->SetStatusText(buf
, 1); 
 425      * Read macro/initialisation file 
 430     if ((path 
= TexPathList
.FindValidPath(MacroFile
)) != "") 
 431       ReadCustomMacros((char*) (const char*) path
); 
 446   // Return the main frame window 
 457   wxNode 
*node 
= CustomMacroList
.First(); 
 460     CustomMacro 
*macro 
= (CustomMacro 
*)node
->Data(); 
 463     node 
= CustomMacroList
.First(); 
 465   MacroDefs
.BeginFind(); 
 466   node 
= MacroDefs
.Next(); 
 469     TexMacroDef
* def 
= (TexMacroDef
*) node
->Data(); 
 471     node 
= MacroDefs
.Next(); 
 475   delete TheTex2RTFServer
; 
 490       delete currentArgData
; 
 491       currentArgData 
= NULL
; 
 505       delete TexTmpBibName
; 
 506       TexTmpBibName 
= NULL
; 
 520       delete TmpContentsName
; 
 521       TmpContentsName 
= NULL
; 
 523     if (TmpFrameContentsName
) 
 525       delete TmpFrameContentsName
; 
 526       TmpFrameContentsName 
= NULL
; 
 528     if (WinHelpContentsFileName
) 
 530       delete WinHelpContentsFileName
; 
 531       WinHelpContentsFileName 
= NULL
; 
 555     delete [] BibliographyStyleString
; 
 556     delete [] DocumentStyleString
; 
 557     delete [] bitmapMethod
; 
 558     delete [] backgroundColourString
; 
 559     delete [] ContentsNameString
; 
 560     delete [] AbstractNameString
; 
 561     delete [] GlossaryNameString
; 
 562     delete [] ReferencesNameString
; 
 563     delete [] FiguresNameString
; 
 564     delete [] TablesNameString
; 
 565     delete [] FigureNameString
; 
 566     delete [] TableNameString
; 
 567     delete [] IndexNameString
; 
 568     delete [] ChapterNameString
; 
 569     delete [] SectionNameString
; 
 570     delete [] SubsectionNameString
; 
 571     delete [] SubsubsectionNameString
; 
 572     delete [] UpNameString
; 
 574       delete[] winHelpTitle
; 
 576   // TODO: this simulates zero-memory leaks! 
 577   // Otherwise there are just too many... 
 579 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT 
 580   wxDebugContext::SetCheckpoint(); 
 587 void ShowOptions(void) 
 590     sprintf(buf
, "Tex2RTF version %.2f", versionNo
); 
 592     OnInform("Usage: tex2rtf [input] [output] [switches]\n"); 
 593     OnInform("where valid switches are"); 
 595     OnInform("    -interactive"); 
 597     OnInform("    -bufsize <size in K>"); 
 598     OnInform("    -charset <pc | pca | ansi | mac> (default ansi)"); 
 601     OnInform("    -checkcurleybraces"); 
 602     OnInform("    -checksyntax"); 
 603     OnInform("    -macros <filename>"); 
 604     OnInform("    -winhelp"); 
 612 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
) 
 613     EVT_CLOSE(MyFrame::OnCloseWindow
) 
 614     EVT_MENU(TEX_QUIT
, MyFrame::OnExit
) 
 615     EVT_MENU(TEX_GO
, MyFrame::OnGo
) 
 616     EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
) 
 617     EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
) 
 618     EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
) 
 619     EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
) 
 620     EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
) 
 621     EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
) 
 622     EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
) 
 623     EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
) 
 624     EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
) 
 625     EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
) 
 626     EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
) 
 627     EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
) 
 628     EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
) 
 629     EVT_MENU(TEX_HELP
, MyFrame::OnHelp
) 
 630     EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
) 
 633 // My frame constructor 
 634 MyFrame::MyFrame(wxFrame 
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
): 
 635   wxFrame(frame
, id
, title
, pos
, size
) 
 638 void MyFrame::OnCloseWindow(wxCloseEvent
& event
) 
 640   if (!stopRunning 
&& !OkToClose
) 
 652 void MyFrame::OnExit(wxCommandEvent
& event
) 
 658 void MyFrame::OnGo(wxCommandEvent
& event
) 
 662       menuBar
->EnableTop(0, FALSE
); 
 663       menuBar
->EnableTop(1, FALSE
); 
 664       menuBar
->EnableTop(2, FALSE
); 
 665       menuBar
->EnableTop(3, FALSE
); 
 672         SetStatusText("Build aborted!"); 
 674         errBuf
.Printf("\nErrors encountered during this pass: %lu\n", errorCount
); 
 675         OnInform((char *)errBuf
.c_str()); 
 679       if (runTwice 
&& !stopRunning
) 
 684       menuBar
->EnableTop(0, TRUE
); 
 685       menuBar
->EnableTop(1, TRUE
); 
 686       menuBar
->EnableTop(2, TRUE
); 
 687       menuBar
->EnableTop(3, TRUE
); 
 690 void MyFrame::OnSetInput(wxCommandEvent
& event
) 
 692       ChooseInputFile(TRUE
); 
 695 void MyFrame::OnSetOutput(wxCommandEvent
& event
) 
 697       ChooseOutputFile(TRUE
); 
 700 void MyFrame::OnSaveFile(wxCommandEvent
& event
) 
 702       wxString s 
= wxFileSelector("Save text to file", "", "", "txt", "*.txt"); 
 705         textWindow
->SaveFile(s
); 
 707         sprintf(buf
, "Saved text to %s", (const char*) s
); 
 708         frame
->SetStatusText(buf
, 0); 
 712 void MyFrame::OnViewOutput(wxCommandEvent
& event
) 
 715       if (OutputFile 
&& wxFileExists(OutputFile
)) 
 717         textWindow
->LoadFile(OutputFile
); 
 719         wxString 
str(wxFileNameFromPath(OutputFile
)); 
 720         sprintf(buf
, "Tex2RTF [%s]", (const char*) str
); 
 721         frame
->SetTitle(buf
); 
 725 void MyFrame::OnViewLatex(wxCommandEvent
& event
) 
 728       if (InputFile 
&& wxFileExists(InputFile
)) 
 730         textWindow
->LoadFile(InputFile
); 
 732         wxString 
str(wxFileNameFromPath(OutputFile
)); 
 733         sprintf(buf
, "Tex2RTF [%s]", (const char*) str
); 
 734         frame
->SetTitle(buf
); 
 738 void MyFrame::OnLoadMacros(wxCommandEvent
& event
) 
 741       wxString s 
= wxFileSelector("Choose custom macro file", wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), "ini", "*.ini"); 
 742       if (s 
!= "" && wxFileExists(s
)) 
 744         MacroFile 
= copystring(s
); 
 745         ReadCustomMacros((char*) (const char*) s
); 
 750 void MyFrame::OnShowMacros(wxCommandEvent
& event
) 
 757 void MyFrame::OnModeRTF(wxCommandEvent
& event
) 
 759       convertMode 
= TEX_RTF
; 
 763       SetStatusText("In linear RTF mode.", 1); 
 766 void MyFrame::OnModeWinHelp(wxCommandEvent
& event
) 
 768       convertMode 
= TEX_RTF
; 
 772       SetStatusText("In WinHelp RTF mode.", 1); 
 775 void MyFrame::OnModeHTML(wxCommandEvent
& event
) 
 777       convertMode 
= TEX_HTML
; 
 781       SetStatusText("In HTML mode.", 1); 
 784 void MyFrame::OnModeXLP(wxCommandEvent
& event
) 
 786       convertMode 
= TEX_XLP
; 
 789       SetStatusText("In XLP mode.", 1); 
 792 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& event
) 
 794     checkCurleyBraces 
= !checkCurleyBraces
; 
 795     if (checkCurleyBraces
) 
 797         SetStatusText("Checking curley braces: YES", 1); 
 801         SetStatusText("Checking curley braces: NO", 1); 
 806 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& event
) 
 808     checkSyntax 
= !checkSyntax
; 
 811         SetStatusText("Checking syntax: YES", 1); 
 815         SetStatusText("Checking syntax: NO", 1); 
 820 void MyFrame::OnHelp(wxCommandEvent
& event
) 
 823       HelpInstance
->LoadFile(); 
 824       HelpInstance
->DisplayContents(); 
 828 void MyFrame::OnAbout(wxCommandEvent
& event
) 
 832       char *platform 
= " (32-bit)"; 
 835       char *platform 
= " (16-bit)"; 
 840       sprintf(buf
, "Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, HTML and wxHelp Conversion\n\n(c) Julian Smart 1999", versionNo
, platform
); 
 841       wxMessageBox(buf
, "About Tex2RTF"); 
 844 void ChooseInputFile(bool force
) 
 846   if (force 
|| !InputFile
) 
 848     wxString s 
= wxFileSelector("Choose LaTeX input file", wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), "tex", "*.tex"); 
 851       // Different file, so clear index entries. 
 853       ResetContentsLevels(0); 
 857       InputFile 
= copystring(s
); 
 858       wxString str 
= wxFileNameFromPath(InputFile
); 
 860       buf
.Printf("Tex2RTF [%s]", str
.c_str()); 
 861       frame
->SetTitle((char *)buf
.c_str()); 
 867 void ChooseOutputFile(bool force
) 
 869   char extensionBuf
[10]; 
 871   strcpy(wildBuf
, "*."); 
 874     path 
= wxPathOnly(OutputFile
); 
 876     path 
= wxPathOnly(InputFile
); 
 882       strcpy(extensionBuf
, "rtf"); 
 883       strcat(wildBuf
, "rtf"); 
 888       strcpy(extensionBuf
, "xlp"); 
 889       strcat(wildBuf
, "xlp"); 
 894 #if defined(__WXMSW__) && defined(__WIN16__) 
 895       strcpy(extensionBuf
, "htm"); 
 896       strcat(wildBuf
, "htm"); 
 898       strcpy(extensionBuf
, "html"); 
 899       strcat(wildBuf
, "html"); 
 904   if (force 
|| !OutputFile
) 
 906     wxString s 
= wxFileSelector("Choose output file", path
, wxFileNameFromPath(OutputFile
), 
 907                    extensionBuf
, wildBuf
); 
 909       OutputFile 
= copystring(s
); 
 921   if (!InputFile 
|| !OutputFile 
|| stopRunning
) 
 928     wxString str 
= wxFileNameFromPath(InputFile
); 
 930     sprintf(buf
, "Tex2RTF [%s]", (const char*) str
); 
 931     frame
->SetTitle(buf
); 
 937   // Find extension-less filename 
 938   strcpy(FileRoot
, OutputFile
); 
 939   StripExtension(FileRoot
); 
 941   if (truncateFilenames 
&& convertMode 
== TEX_HTML
) 
 943     // Truncate to five characters. This ensures that 
 944     // we can generate DOS filenames such as thing999. But 1000 files 
 945     // may not be enough, of course... 
 946     char* sName 
= wxFileNameFromPath( FileRoot
);  // this Julian's method is non-destructive reference 
 949       if(strlen( sName
) > 5) 
 950         sName
[5] = '\0';  // that should do! 
 953   sprintf(ContentsName
, "%s.con", FileRoot
); 
 954   sprintf(TmpContentsName
, "%s.cn1", FileRoot
); 
 955   sprintf(TmpFrameContentsName
, "%s.frc", FileRoot
); 
 956   sprintf(WinHelpContentsFileName
, "%s.cnt", FileRoot
); 
 957   sprintf(RefFileName
, "%s.ref", FileRoot
); 
 959   TexPathList
.EnsureFileAccessible(InputFile
); 
 962     wxString s 
= TexPathList
.FindValidPath("bullet.bmp"); 
 965       wxString str 
= wxFileNameFromPath(s
); 
 966       bulletFile 
= copystring(str
); 
 970   if (wxFileExists(RefFileName
)) 
 971     ReadTexReferences(RefFileName
); 
 973   bool success 
= FALSE
; 
 975   if (InputFile 
&& OutputFile
) 
 977     if (!FileExists(InputFile
)) 
 979       OnError("Cannot open input file!"); 
 987       buf
.Printf("Working, pass %d...Click CLOSE to abort", passNumber
); 
 988       frame
->SetStatusText((char *)buf
.c_str()); 
 992     OnInform("Reading LaTeX file..."); 
 993     TexLoadFile(InputFile
); 
1001     switch (convertMode
) 
1022     OnInform("*** Aborted by user."); 
1024     stopRunning 
= FALSE
; 
1030     WriteTexReferences(RefFileName
); 
1032     startedSections 
= FALSE
; 
1036     long tim 
= wxGetElapsedTime(); 
1037     buf
.Printf("Finished PASS #%d in %ld seconds.\n", passNumber
, (long)(tim
/1000.0)); 
1038     OnInform((char *)buf
.c_str()); 
1042         buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
); 
1043         OnInform((char *)buf
.c_str()); 
1048       buf
.Printf("Done, %d %s.", passNumber
, (passNumber 
> 1) ? "passes" : "pass"); 
1049       frame
->SetStatusText((char *)buf
.c_str()); 
1052     buf
.Printf("Done, %d %s.", passNumber
, (passNumber 
> 1) ? "passes" : "pass"); 
1053     OnInform((char *)buf
.c_str()); 
1056         buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
); 
1057         OnInform((char *)buf
.c_str()); 
1067   startedSections 
= FALSE
; 
1070   frame
->SetStatusText("Aborted by user."); 
1073   OnInform("Sorry, unsuccessful."); 
1078 void OnError(char *msg
) 
1083   cerr 
<< "Error: " << msg 
<< "\n"; 
1086   if (isInteractive 
&& frame
) 
1087     (*frame
->textWindow
) << "Error: " << msg 
<< "\n"; 
1091     cerr 
<< "Error: " << msg 
<< "\n"; 
1103 void OnInform(char *msg
) 
1106   cout 
<< msg 
<< "\n"; 
1109   if (isInteractive 
&& frame
) 
1110     (*frame
->textWindow
) << msg 
<< "\n"; 
1111 /* This whole block of code is just wrong I think.  It would behave 
1112    completely wrong under anything other than MSW due to the ELSE 
1113         with no statement, and the cout calls would fail under MSW, as 
1114         the code in this block is compiled if !NO_GUI This code has been  
1115         here since v1.1 of this file too. - gt 
1119     cout << msg << "\n"; 
1134 void OnMacro(int macroId
, int no_args
, bool start
) 
1136   switch (convertMode
) 
1140       RTFOnMacro(macroId
, no_args
, start
); 
1145       XLPOnMacro(macroId
, no_args
, start
); 
1150       HTMLOnMacro(macroId
, no_args
, start
); 
1156 bool OnArgument(int macroId
, int arg_no
, bool start
) 
1158   switch (convertMode
) 
1162       return RTFOnArgument(macroId
, arg_no
, start
); 
1167       return XLPOnArgument(macroId
, arg_no
, start
); 
1172       return HTMLOnArgument(macroId
, arg_no
, start
); 
1182 #if defined(__WXMSW__) && !defined(NO_GUI) 
1188 wxConnectionBase 
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
) 
1190   if (topic 
== "TEX2RTF") 
1193       ipc_buffer 
= new char[1000]; 
1195     return new Tex2RTFConnection(ipc_buffer
, 4000); 
1205 Tex2RTFConnection::Tex2RTFConnection(char *buf
, int size
):wxDDEConnection(buf
, size
) 
1209 Tex2RTFConnection::~Tex2RTFConnection(void) 
1213 bool SplitCommand(char *data
, char *firstArg
, char *secondArg
) 
1218   int len 
= strlen(data
); 
1220   // Find first argument (command name) 
1223     if (data
[i
] == ' ' || data
[i
] == 0) 
1227       firstArg
[i
] = data
[i
]; 
1234     // Find second argument 
1237     while (data
[i
] != 0) 
1239       secondArg
[j
] = data
[i
]; 
1248 bool Tex2RTFConnection::OnExecute(const wxString
& topic
, char *data
, int size
, int format
) 
1250   strcpy(Tex2RTFLastStatus
, "OK"); 
1253   char secondArg
[300]; 
1254   if (SplitCommand(data
, firstArg
, secondArg
)) 
1256     bool hasArg 
= (strlen(secondArg
) > 0); 
1257     if (strcmp(firstArg
, "INPUT") == 0 && hasArg
) 
1259       if (InputFile
) delete[] InputFile
; 
1260       InputFile 
= copystring(secondArg
); 
1264         wxString str 
= wxFileNameFromPath(InputFile
); 
1265         sprintf(buf
, "Tex2RTF [%s]", (const char*) str
); 
1266         frame
->SetTitle(buf
); 
1269     else if (strcmp(firstArg
, "OUTPUT") == 0 && hasArg
) 
1271       if (OutputFile
) delete[] OutputFile
; 
1272       OutputFile 
= copystring(secondArg
); 
1274     else if (strcmp(firstArg
, "GO") == 0) 
1276       strcpy(Tex2RTFLastStatus
, "WORKING"); 
1278         strcpy(Tex2RTFLastStatus
, "CONVERSION ERROR"); 
1280         strcpy(Tex2RTFLastStatus
, "OK"); 
1282     else if (strcmp(firstArg
, "EXIT") == 0) 
1284       if (frame
) frame
->Close(); 
1286     else if (strcmp(firstArg
, "MINIMIZE") == 0 || strcmp(firstArg
, "ICONIZE") == 0) 
1289         frame
->Iconize(TRUE
); 
1291     else if (strcmp(firstArg
, "SHOW") == 0 || strcmp(firstArg
, "RESTORE") == 0) 
1295         frame
->Iconize(FALSE
); 
1301       // Try for a setting 
1302       strcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, FALSE
)); 
1304       if (frame 
&& strcmp(firstArg
, "conversionMode") == 0) 
1309         if (winHelp 
&& (convertMode 
== TEX_RTF
)) 
1310           strcat(buf
, "WinHelp RTF"); 
1311         else if (!winHelp 
&& (convertMode 
== TEX_RTF
)) 
1312           strcat(buf
, "linear RTF"); 
1313         else if (convertMode 
== TEX_HTML
) strcat(buf
, "HTML"); 
1314         else if (convertMode 
== TEX_XLP
) strcat(buf
, "XLP"); 
1315           strcat(buf
, " mode."); 
1316         frame
->SetStatusText(buf
, 1); 
1324 char *Tex2RTFConnection::OnRequest(const wxString
& topic
, const wxString
& item
, int *size
, int format
) 
1326   return Tex2RTFLastStatus
; 
1333 //void wxObject::Dump(wxSTD ostream& str) 
1335 //  if (GetClassInfo() && GetClassInfo()->GetClassName()) 
1336 //    str << GetClassInfo()->GetClassName(); 
1338 //    str << "unknown object class";