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"
26 #include "wx/textctrl.h"
27 #include "wx/filedlg.h"
28 #include "wx/msgdlg.h"
37 #if defined(NO_GUI) || defined(__UNIX__)
54 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
55 #include "tex2rtf.xpm"
58 #if !WXWIN_COMPATIBILITY_2_4
59 static inline wxChar
* copystring(const wxChar
* s
)
60 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
63 const float versionNo
= TEX2RTF_VERSION_NUMBER
;
65 TexChunk
*currentMember
= NULL
;
66 bool startedSections
= FALSE
;
67 char *contentsString
= NULL
;
68 bool suppressNameDecoration
= FALSE
;
69 bool OkToClose
= TRUE
;
75 extern char *BigBuffer
;
76 extern char *TexFileRoot
;
77 extern char *TexBibName
; // Bibliography output file name
78 extern char *TexTmpBibName
; // Temporary bibliography output file name
79 extern wxList ColourTable
;
80 extern TexChunk
*TopLevel
;
81 extern char *PageStyle
;
82 extern char *BibliographyStyleString
;
83 extern char *DocumentStyleString
;
84 extern char *bitmapMethod
;
85 extern char *backgroundColourString
;
86 extern char *ContentsNameString
;
87 extern char *AbstractNameString
;
88 extern char *GlossaryNameString
;
89 extern char *ReferencesNameString
;
90 extern char *FiguresNameString
;
91 extern char *TablesNameString
;
92 extern char *FigureNameString
;
93 extern char *TableNameString
;
94 extern char *IndexNameString
;
95 extern char *ChapterNameString
;
96 extern char *SectionNameString
;
97 extern char *SubsectionNameString
;
98 extern char *SubsubsectionNameString
;
99 extern char *UpNameString
;
104 wxHelpController
*HelpInstance
= NULL
;
108 static char *ipc_buffer
= NULL
;
109 static char Tex2RTFLastStatus
[100];
110 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
114 char *bulletFile
= NULL
;
116 FILE *Contents
= NULL
; // Contents page
117 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
118 FILE *Sections
= NULL
;
119 FILE *Subsections
= NULL
;
120 FILE *Subsubsections
= NULL
;
122 FILE *WinHelpContentsFile
= NULL
;
124 char *InputFile
= NULL
;
125 char *OutputFile
= NULL
;
126 char *MacroFile
= copystring("tex2rtf.ini");
128 char *FileRoot
= NULL
;
129 char *ContentsName
= NULL
; // Contents page from last time around
130 char *TmpContentsName
= NULL
; // Current contents page
131 char *TmpFrameContentsName
= NULL
; // Current frame contents page
132 char *WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
133 char *RefFileName
= NULL
; // Reference file name
135 char *RTFCharset
= copystring("ansi");
138 int BufSize
= 100; // Size of buffer in K
144 void ShowOptions(void);
146 char wxTex2RTFBuffer
[1500];
150 int main(int argc
, char **argv
)
152 wxMenuBar
*menuBar
= NULL
;
153 MyFrame
*frame
= NULL
;
155 // DECLARE_APP(MyApp)
158 // `Main program' equivalent, creating windows and returning main app frame
162 // Use default list of macros defined in tex2any.cc
163 DefineDefaultMacros();
164 AddMacroDef(ltHARDY
, "hardy", 0);
166 FileRoot
= new char[300];
167 ContentsName
= new char[300];
168 TmpContentsName
= new char[300];
169 TmpFrameContentsName
= new char[300];
170 WinHelpContentsFileName
= new char[300];
171 RefFileName
= new char[300];
173 ColourTable
.DeleteContents(TRUE
);
177 // Read input/output files
180 if (argv
[1][0] != '-')
187 if (argv
[2][0] != '-')
189 OutputFile
= argv
[2];
197 if (!InputFile
|| !OutputFile
)
199 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
207 TexPathList
.EnsureFileAccessible(InputFile
);
209 if (!InputFile
|| !OutputFile
)
210 isInteractive
= TRUE
;
213 for (i
= n
; i
< argc
;)
215 if (strcmp(argv
[i
], "-winhelp") == 0)
218 convertMode
= TEX_RTF
;
222 else if (strcmp(argv
[i
], "-interactive") == 0)
225 isInteractive
= TRUE
;
228 else if (strcmp(argv
[i
], "-sync") == 0) // Don't yield
233 else if (strcmp(argv
[i
], "-rtf") == 0)
236 convertMode
= TEX_RTF
;
238 else if (strcmp(argv
[i
], "-html") == 0)
241 convertMode
= TEX_HTML
;
243 else if (strcmp(argv
[i
], "-xlp") == 0)
246 convertMode
= TEX_XLP
;
248 else if (strcmp(argv
[i
], "-twice") == 0)
253 else if (strcmp(argv
[i
], "-macros") == 0)
258 MacroFile
= copystring(argv
[i
]);
262 else if (strcmp(argv
[i
], "-bufsize") == 0)
267 BufSize
= atoi(argv
[i
]);
271 else if (strcmp(argv
[i
], "-charset") == 0)
278 if (strcmp(s
, "ansi") == 0 || strcmp(s
, "pc") == 0 || strcmp(s
, "mac") == 0 ||
279 strcmp(s
, "pca") == 0)
280 RTFCharset
= copystring(s
);
283 OnError("Incorrect argument for -charset");
288 else if (strcmp(argv
[i
], "-checkcurleybraces") == 0)
291 checkCurleyBraces
= TRUE
;
293 else if (strcmp(argv
[i
], "-checksyntax") == 0)
301 buf
.Printf("Invalid switch %s.\n", argv
[i
]);
302 OnError((char *)buf
.c_str());
312 #if defined(__WXMSW__) && !defined(NO_GUI)
314 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
315 TheTex2RTFServer
= new Tex2RTFServer
;
316 TheTex2RTFServer
->Create("TEX2RTF");
319 #if defined(__WXMSW__) && defined(__WIN16__)
320 // Limit to max Windows array size
321 if (BufSize
> 64) BufSize
= 64;
324 TexInitialize(BufSize
);
325 ResetContentsLevels(0);
333 // Create the main frame window
334 frame
= new MyFrame(NULL
, -1, "Tex2RTF", wxPoint(-1, -1), wxSize(400, 300));
335 frame
->CreateStatusBar(2);
338 // TODO: uncomment this when we have tex2rtf.xpm
339 frame
->SetIcon(wxICON(tex2rtf
));
343 sprintf(buf
, "Tex2RTF [%s]", wxFileNameFromPath(InputFile
));
344 frame
->SetTitle(buf
);
348 wxMenu
*file_menu
= new wxMenu
;
349 file_menu
->Append(TEX_GO
, "&Go", "Run converter");
350 file_menu
->Append(TEX_SET_INPUT
, "Set &Input File", "Set the LaTeX input file");
351 file_menu
->Append(TEX_SET_OUTPUT
, "Set &Output File", "Set the output file");
352 file_menu
->AppendSeparator();
353 file_menu
->Append(TEX_VIEW_LATEX
, "View &LaTeX File", "View the LaTeX input file");
354 file_menu
->Append(TEX_VIEW_OUTPUT
, "View Output &File", "View output file");
355 file_menu
->Append(TEX_SAVE_FILE
, "&Save log file", "Save displayed text into file");
356 file_menu
->AppendSeparator();
357 file_menu
->Append(TEX_QUIT
, "E&xit", "Exit Tex2RTF");
359 wxMenu
*macro_menu
= new wxMenu
;
361 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, "&Load Custom Macros", "Load custom LaTeX macro file");
362 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, "View &Custom Macros", "View custom LaTeX macros");
364 wxMenu
*mode_menu
= new wxMenu
;
366 mode_menu
->Append(TEX_MODE_RTF
, "Output linear &RTF", "Wordprocessor-compatible RTF");
367 mode_menu
->Append(TEX_MODE_WINHELP
, "Output &WinHelp RTF", "WinHelp-compatible RTF");
368 mode_menu
->Append(TEX_MODE_HTML
, "Output &HTML", "HTML World Wide Web hypertext file");
369 mode_menu
->Append(TEX_MODE_XLP
, "Output &XLP", "wxHelp hypertext help file");
371 wxMenu
*options_menu
= new wxMenu
;
373 options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, "Curley brace matching", "Checks for mismatched curley braces",TRUE
);
374 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, "Syntax checking", "Syntax checking for common errors",TRUE
);
376 options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
);
377 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
379 wxMenu
*help_menu
= new wxMenu
;
381 help_menu
->Append(TEX_HELP
, "&Help", "Tex2RTF Contents Page");
382 help_menu
->Append(TEX_ABOUT
, "&About Tex2RTF", "About Tex2RTF");
384 menuBar
= new wxMenuBar
;
385 menuBar
->Append(file_menu
, "&File");
386 menuBar
->Append(macro_menu
, "&Macros");
387 menuBar
->Append(mode_menu
, "&Conversion Mode");
388 menuBar
->Append(options_menu
, "&Options");
389 menuBar
->Append(help_menu
, "&Help");
391 frame
->SetMenuBar(menuBar
);
392 frame
->textWindow
= new wxTextCtrl(frame
, -1, "", wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY
|wxTE_MULTILINE
);
394 (*frame
->textWindow
) << "Welcome to Tex2RTF.\n";
398 HelpInstance
= new wxHelpController();
399 HelpInstance
->Initialize("tex2rtf");
403 * Read macro/initialisation file
408 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
409 ReadCustomMacros((char*) (const char*) path
);
413 if (winHelp
&& (convertMode
== TEX_RTF
))
414 strcat(buf
, "WinHelp RTF");
415 else if (!winHelp
&& (convertMode
== TEX_RTF
))
416 strcat(buf
, "linear RTF");
417 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
418 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
419 strcat(buf
, " mode.");
420 frame
->SetStatusText(buf
, 1);
429 * Read macro/initialisation file
434 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
435 ReadCustomMacros((char*) (const char*) path
);
450 // Return the main frame window
460 wxNode
*node
= CustomMacroList
.First();
463 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
466 node
= CustomMacroList
.First();
468 MacroDefs
.BeginFind();
469 node
= MacroDefs
.Next();
472 TexMacroDef
* def
= (TexMacroDef
*) node
->Data();
474 node
= MacroDefs
.Next();
478 delete TheTex2RTFServer
;
493 delete currentArgData
;
494 currentArgData
= NULL
;
508 delete TexTmpBibName
;
509 TexTmpBibName
= NULL
;
523 delete TmpContentsName
;
524 TmpContentsName
= NULL
;
526 if (TmpFrameContentsName
)
528 delete TmpFrameContentsName
;
529 TmpFrameContentsName
= NULL
;
531 if (WinHelpContentsFileName
)
533 delete WinHelpContentsFileName
;
534 WinHelpContentsFileName
= NULL
;
558 delete [] BibliographyStyleString
;
559 delete [] DocumentStyleString
;
560 delete [] bitmapMethod
;
561 delete [] backgroundColourString
;
562 delete [] ContentsNameString
;
563 delete [] AbstractNameString
;
564 delete [] GlossaryNameString
;
565 delete [] ReferencesNameString
;
566 delete [] FiguresNameString
;
567 delete [] TablesNameString
;
568 delete [] FigureNameString
;
569 delete [] TableNameString
;
570 delete [] IndexNameString
;
571 delete [] ChapterNameString
;
572 delete [] SectionNameString
;
573 delete [] SubsectionNameString
;
574 delete [] SubsubsectionNameString
;
575 delete [] UpNameString
;
577 delete[] winHelpTitle
;
579 // TODO: this simulates zero-memory leaks!
580 // Otherwise there are just too many...
582 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
583 wxDebugContext::SetCheckpoint();
590 void ShowOptions(void)
593 sprintf(buf
, "Tex2RTF version %.2f", versionNo
);
595 OnInform("Usage: tex2rtf [input] [output] [switches]\n");
596 OnInform("where valid switches are");
598 OnInform(" -interactive");
600 OnInform(" -bufsize <size in K>");
601 OnInform(" -charset <pc | pca | ansi | mac> (default ansi)");
604 OnInform(" -checkcurleybraces");
605 OnInform(" -checksyntax");
606 OnInform(" -macros <filename>");
607 OnInform(" -winhelp");
615 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
616 EVT_CLOSE(MyFrame::OnCloseWindow
)
617 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
618 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
619 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
620 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
621 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
622 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
623 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
624 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
625 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
626 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
627 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
628 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
629 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
630 EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
631 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
632 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
633 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
636 // My frame constructor
637 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
638 wxFrame(frame
, id
, title
, pos
, size
)
641 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
643 if (!stopRunning
&& !OkToClose
)
655 void MyFrame::OnExit(wxCommandEvent
& event
)
661 void MyFrame::OnGo(wxCommandEvent
& event
)
665 menuBar
->EnableTop(0, FALSE
);
666 menuBar
->EnableTop(1, FALSE
);
667 menuBar
->EnableTop(2, FALSE
);
668 menuBar
->EnableTop(3, FALSE
);
675 SetStatusText("Build aborted!");
677 errBuf
.Printf("\nErrors encountered during this pass: %lu\n", errorCount
);
678 OnInform((char *)errBuf
.c_str());
682 if (runTwice
&& !stopRunning
)
687 menuBar
->EnableTop(0, TRUE
);
688 menuBar
->EnableTop(1, TRUE
);
689 menuBar
->EnableTop(2, TRUE
);
690 menuBar
->EnableTop(3, TRUE
);
693 void MyFrame::OnSetInput(wxCommandEvent
& event
)
695 ChooseInputFile(TRUE
);
698 void MyFrame::OnSetOutput(wxCommandEvent
& event
)
700 ChooseOutputFile(TRUE
);
703 void MyFrame::OnSaveFile(wxCommandEvent
& event
)
705 wxString s
= wxFileSelector("Save text to file", "", "", "txt", "*.txt");
708 textWindow
->SaveFile(s
);
710 sprintf(buf
, "Saved text to %s", (const char*) s
);
711 frame
->SetStatusText(buf
, 0);
715 void MyFrame::OnViewOutput(wxCommandEvent
& event
)
718 if (OutputFile
&& wxFileExists(OutputFile
))
720 textWindow
->LoadFile(OutputFile
);
722 wxString
str(wxFileNameFromPath(OutputFile
));
723 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
724 frame
->SetTitle(buf
);
728 void MyFrame::OnViewLatex(wxCommandEvent
& event
)
731 if (InputFile
&& wxFileExists(InputFile
))
733 textWindow
->LoadFile(InputFile
);
735 wxString
str(wxFileNameFromPath(OutputFile
));
736 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
737 frame
->SetTitle(buf
);
741 void MyFrame::OnLoadMacros(wxCommandEvent
& event
)
744 wxString s
= wxFileSelector("Choose custom macro file", wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), "ini", "*.ini");
745 if (s
!= "" && wxFileExists(s
))
747 MacroFile
= copystring(s
);
748 ReadCustomMacros((char*) (const char*) s
);
753 void MyFrame::OnShowMacros(wxCommandEvent
& event
)
760 void MyFrame::OnModeRTF(wxCommandEvent
& event
)
762 convertMode
= TEX_RTF
;
766 SetStatusText("In linear RTF mode.", 1);
769 void MyFrame::OnModeWinHelp(wxCommandEvent
& event
)
771 convertMode
= TEX_RTF
;
775 SetStatusText("In WinHelp RTF mode.", 1);
778 void MyFrame::OnModeHTML(wxCommandEvent
& event
)
780 convertMode
= TEX_HTML
;
784 SetStatusText("In HTML mode.", 1);
787 void MyFrame::OnModeXLP(wxCommandEvent
& event
)
789 convertMode
= TEX_XLP
;
792 SetStatusText("In XLP mode.", 1);
795 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& event
)
797 checkCurleyBraces
= !checkCurleyBraces
;
798 if (checkCurleyBraces
)
800 SetStatusText("Checking curley braces: YES", 1);
804 SetStatusText("Checking curley braces: NO", 1);
809 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& event
)
811 checkSyntax
= !checkSyntax
;
814 SetStatusText("Checking syntax: YES", 1);
818 SetStatusText("Checking syntax: NO", 1);
823 void MyFrame::OnHelp(wxCommandEvent
& event
)
826 HelpInstance
->LoadFile();
827 HelpInstance
->DisplayContents();
831 void MyFrame::OnAbout(wxCommandEvent
& event
)
835 char *platform
= " (32-bit)";
838 char *platform
= " (16-bit)";
843 sprintf(buf
, "Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2002", versionNo
, platform
);
844 wxMessageBox(buf
, "About Tex2RTF");
847 void ChooseInputFile(bool force
)
849 if (force
|| !InputFile
)
851 wxString s
= wxFileSelector("Choose LaTeX input file", wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), "tex", "*.tex");
854 // Different file, so clear index entries.
856 ResetContentsLevels(0);
860 InputFile
= copystring(s
);
861 wxString str
= wxFileNameFromPath(InputFile
);
863 buf
.Printf("Tex2RTF [%s]", str
.c_str());
864 frame
->SetTitle((char *)buf
.c_str());
870 void ChooseOutputFile(bool force
)
872 char extensionBuf
[10];
874 strcpy(wildBuf
, "*.");
877 path
= wxPathOnly(OutputFile
);
879 path
= wxPathOnly(InputFile
);
885 strcpy(extensionBuf
, "rtf");
886 strcat(wildBuf
, "rtf");
891 strcpy(extensionBuf
, "xlp");
892 strcat(wildBuf
, "xlp");
897 #if defined(__WXMSW__) && defined(__WIN16__)
898 strcpy(extensionBuf
, "htm");
899 strcat(wildBuf
, "htm");
901 strcpy(extensionBuf
, "html");
902 strcat(wildBuf
, "html");
907 if (force
|| !OutputFile
)
909 wxString s
= wxFileSelector("Choose output file", path
, wxFileNameFromPath(OutputFile
),
910 extensionBuf
, wildBuf
);
912 OutputFile
= copystring(s
);
924 if (!InputFile
|| !OutputFile
|| stopRunning
)
931 wxString str
= wxFileNameFromPath(InputFile
);
933 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
934 frame
->SetTitle(buf
);
940 // Find extension-less filename
941 strcpy(FileRoot
, OutputFile
);
942 StripExtension(FileRoot
);
944 if (truncateFilenames
&& convertMode
== TEX_HTML
)
946 // Truncate to five characters. This ensures that
947 // we can generate DOS filenames such as thing999. But 1000 files
948 // may not be enough, of course...
949 char* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
952 if(strlen( sName
) > 5)
953 sName
[5] = '\0'; // that should do!
956 sprintf(ContentsName
, "%s.con", FileRoot
);
957 sprintf(TmpContentsName
, "%s.cn1", FileRoot
);
958 sprintf(TmpFrameContentsName
, "%s.frc", FileRoot
);
959 sprintf(WinHelpContentsFileName
, "%s.cnt", FileRoot
);
960 sprintf(RefFileName
, "%s.ref", FileRoot
);
962 TexPathList
.EnsureFileAccessible(InputFile
);
965 wxString s
= TexPathList
.FindValidPath("bullet.bmp");
968 wxString str
= wxFileNameFromPath(s
);
969 bulletFile
= copystring(str
);
973 if (wxFileExists(RefFileName
))
974 ReadTexReferences(RefFileName
);
976 bool success
= FALSE
;
978 if (InputFile
&& OutputFile
)
980 if (!wxFileExists(InputFile
))
982 OnError("Cannot open input file!");
990 buf
.Printf("Working, pass %d...Click CLOSE to abort", passNumber
);
991 frame
->SetStatusText((char *)buf
.c_str());
995 OnInform("Reading LaTeX file...");
996 TexLoadFile(InputFile
);
1004 switch (convertMode
)
1025 OnInform("*** Aborted by user.");
1027 stopRunning
= FALSE
;
1033 WriteTexReferences(RefFileName
);
1035 startedSections
= FALSE
;
1039 long tim
= wxGetElapsedTime();
1040 buf
.Printf("Finished PASS #%d in %ld seconds.\n", passNumber
, (long)(tim
/1000.0));
1041 OnInform((char *)buf
.c_str());
1045 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1046 OnInform((char *)buf
.c_str());
1051 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1052 frame
->SetStatusText((char *)buf
.c_str());
1055 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1056 OnInform((char *)buf
.c_str());
1059 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1060 OnInform((char *)buf
.c_str());
1070 startedSections
= FALSE
;
1073 frame
->SetStatusText("Aborted by user.");
1076 OnInform("Sorry, unsuccessful.");
1081 void OnError(const char *msg
)
1086 wxSTD cerr
<< "Error: " << msg
<< "\n";
1089 if (isInteractive
&& frame
)
1090 (*frame
->textWindow
) << "Error: " << msg
<< "\n";
1094 wxSTD cerr
<< "Error: " << msg
<< "\n";
1106 void OnInform(const char *msg
)
1109 wxSTD cout
<< msg
<< "\n";
1112 if (isInteractive
&& frame
)
1113 (*frame
->textWindow
) << msg
<< "\n";
1114 /* This whole block of code is just wrong I think. It would behave
1115 completely wrong under anything other than MSW due to the ELSE
1116 with no statement, and the cout calls would fail under MSW, as
1117 the code in this block is compiled if !NO_GUI This code has been
1118 here since v1.1 of this file too. - gt
1122 wxSTD cout << msg << "\n";
1137 void OnMacro(int macroId
, int no_args
, bool start
)
1139 switch (convertMode
)
1143 RTFOnMacro(macroId
, no_args
, start
);
1148 XLPOnMacro(macroId
, no_args
, start
);
1153 HTMLOnMacro(macroId
, no_args
, start
);
1159 bool OnArgument(int macroId
, int arg_no
, bool start
)
1161 switch (convertMode
)
1165 return RTFOnArgument(macroId
, arg_no
, start
);
1170 return XLPOnArgument(macroId
, arg_no
, start
);
1175 return HTMLOnArgument(macroId
, arg_no
, start
);
1185 #if defined(__WXMSW__) && !defined(NO_GUI)
1191 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1193 if (topic
== "TEX2RTF")
1196 ipc_buffer
= new char[1000];
1198 return new Tex2RTFConnection(ipc_buffer
, 4000);
1208 Tex2RTFConnection::Tex2RTFConnection(char *buf
, int size
):wxDDEConnection(buf
, size
)
1212 Tex2RTFConnection::~Tex2RTFConnection(void)
1216 bool SplitCommand(char *data
, char *firstArg
, char *secondArg
)
1221 int len
= strlen(data
);
1223 // Find first argument (command name)
1226 if (data
[i
] == ' ' || data
[i
] == 0)
1230 firstArg
[i
] = data
[i
];
1237 // Find second argument
1240 while (data
[i
] != 0)
1242 secondArg
[j
] = data
[i
];
1251 bool Tex2RTFConnection::OnExecute(const wxString
& topic
, char *data
, int size
, int format
)
1253 strcpy(Tex2RTFLastStatus
, "OK");
1256 char secondArg
[300];
1257 if (SplitCommand(data
, firstArg
, secondArg
))
1259 bool hasArg
= (strlen(secondArg
) > 0);
1260 if (strcmp(firstArg
, "INPUT") == 0 && hasArg
)
1262 if (InputFile
) delete[] InputFile
;
1263 InputFile
= copystring(secondArg
);
1267 wxString str
= wxFileNameFromPath(InputFile
);
1268 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
1269 frame
->SetTitle(buf
);
1272 else if (strcmp(firstArg
, "OUTPUT") == 0 && hasArg
)
1274 if (OutputFile
) delete[] OutputFile
;
1275 OutputFile
= copystring(secondArg
);
1277 else if (strcmp(firstArg
, "GO") == 0)
1279 strcpy(Tex2RTFLastStatus
, "WORKING");
1281 strcpy(Tex2RTFLastStatus
, "CONVERSION ERROR");
1283 strcpy(Tex2RTFLastStatus
, "OK");
1285 else if (strcmp(firstArg
, "EXIT") == 0)
1287 if (frame
) frame
->Close();
1289 else if (strcmp(firstArg
, "MINIMIZE") == 0 || strcmp(firstArg
, "ICONIZE") == 0)
1292 frame
->Iconize(TRUE
);
1294 else if (strcmp(firstArg
, "SHOW") == 0 || strcmp(firstArg
, "RESTORE") == 0)
1298 frame
->Iconize(FALSE
);
1304 // Try for a setting
1305 strcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, FALSE
));
1307 if (frame
&& strcmp(firstArg
, "conversionMode") == 0)
1312 if (winHelp
&& (convertMode
== TEX_RTF
))
1313 strcat(buf
, "WinHelp RTF");
1314 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1315 strcat(buf
, "linear RTF");
1316 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
1317 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
1318 strcat(buf
, " mode.");
1319 frame
->SetStatusText(buf
, 1);
1327 char *Tex2RTFConnection::OnRequest(const wxString
& topic
, const wxString
& item
, int *size
, int format
)
1329 return Tex2RTFLastStatus
;
1336 //void wxObject::Dump(wxSTD ostream& str)
1338 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1339 // str << GetClassInfo()->GetClassName();
1341 // str << "unknown object class";