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__)
49 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)) && !defined(NO_GUI)
50 #include "tex2rtf.xpm"
53 const float versionNo
= TEX2RTF_VERSION_NUMBER
;
55 TexChunk
*currentMember
= NULL
;
56 bool startedSections
= FALSE
;
57 char *contentsString
= NULL
;
58 bool suppressNameDecoration
= FALSE
;
59 bool OkToClose
= TRUE
;
65 extern char *BigBuffer
;
66 extern char *TexFileRoot
;
67 extern char *TexBibName
; // Bibliography output file name
68 extern char *TexTmpBibName
; // Temporary bibliography output file name
69 extern wxList ColourTable
;
70 extern TexChunk
*TopLevel
;
71 extern char *PageStyle
;
72 extern char *BibliographyStyleString
;
73 extern char *DocumentStyleString
;
74 extern char *bitmapMethod
;
75 extern char *backgroundColourString
;
76 extern char *ContentsNameString
;
77 extern char *AbstractNameString
;
78 extern char *GlossaryNameString
;
79 extern char *ReferencesNameString
;
80 extern char *FiguresNameString
;
81 extern char *TablesNameString
;
82 extern char *FigureNameString
;
83 extern char *TableNameString
;
84 extern char *IndexNameString
;
85 extern char *ChapterNameString
;
86 extern char *SectionNameString
;
87 extern char *SubsectionNameString
;
88 extern char *SubsubsectionNameString
;
89 extern char *UpNameString
;
94 wxHelpController
*HelpInstance
= NULL
;
98 static char *ipc_buffer
= NULL
;
99 static char Tex2RTFLastStatus
[100];
100 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
104 char *bulletFile
= NULL
;
106 FILE *Contents
= NULL
; // Contents page
107 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
108 FILE *Sections
= NULL
;
109 FILE *Subsections
= NULL
;
110 FILE *Subsubsections
= NULL
;
112 FILE *WinHelpContentsFile
= NULL
;
114 char *InputFile
= NULL
;
115 char *OutputFile
= NULL
;
116 char *MacroFile
= copystring("tex2rtf.ini");
118 char *FileRoot
= NULL
;
119 char *ContentsName
= NULL
; // Contents page from last time around
120 char *TmpContentsName
= NULL
; // Current contents page
121 char *TmpFrameContentsName
= NULL
; // Current frame contents page
122 char *WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
123 char *RefFileName
= NULL
; // Reference file name
125 char *RTFCharset
= copystring("ansi");
128 int BufSize
= 100; // Size of buffer in K
134 void ShowOptions(void);
136 char wxTex2RTFBuffer
[1500];
140 int main(int argc
, char **argv
)
142 wxMenuBar
*menuBar
= NULL
;
143 MyFrame
*frame
= NULL
;
145 // DECLARE_APP(MyApp)
148 // `Main program' equivalent, creating windows and returning main app frame
152 // Use default list of macros defined in tex2any.cc
153 DefineDefaultMacros();
154 AddMacroDef(ltHARDY
, "hardy", 0);
156 FileRoot
= new char[300];
157 ContentsName
= new char[300];
158 TmpContentsName
= new char[300];
159 TmpFrameContentsName
= new char[300];
160 WinHelpContentsFileName
= new char[300];
161 RefFileName
= new char[300];
163 ColourTable
.DeleteContents(TRUE
);
167 // Read input/output files
170 if (argv
[1][0] != '-')
177 if (argv
[2][0] != '-')
179 OutputFile
= argv
[2];
187 if (!InputFile
|| !OutputFile
)
189 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
197 TexPathList
.EnsureFileAccessible(InputFile
);
199 if (!InputFile
|| !OutputFile
)
200 isInteractive
= TRUE
;
203 for (i
= n
; i
< argc
;)
205 if (strcmp(argv
[i
], "-winhelp") == 0)
208 convertMode
= TEX_RTF
;
212 else if (strcmp(argv
[i
], "-interactive") == 0)
215 isInteractive
= TRUE
;
218 else if (strcmp(argv
[i
], "-sync") == 0) // Don't yield
223 else if (strcmp(argv
[i
], "-rtf") == 0)
226 convertMode
= TEX_RTF
;
228 else if (strcmp(argv
[i
], "-html") == 0)
231 convertMode
= TEX_HTML
;
233 else if (strcmp(argv
[i
], "-xlp") == 0)
236 convertMode
= TEX_XLP
;
238 else if (strcmp(argv
[i
], "-twice") == 0)
243 else if (strcmp(argv
[i
], "-macros") == 0)
248 MacroFile
= copystring(argv
[i
]);
252 else if (strcmp(argv
[i
], "-bufsize") == 0)
257 BufSize
= atoi(argv
[i
]);
261 else if (strcmp(argv
[i
], "-charset") == 0)
268 if (strcmp(s
, "ansi") == 0 || strcmp(s
, "pc") == 0 || strcmp(s
, "mac") == 0 ||
269 strcmp(s
, "pca") == 0)
270 RTFCharset
= copystring(s
);
273 OnError("Incorrect argument for -charset");
278 else if (strcmp(argv
[i
], "-checkcurleybraces") == 0)
281 checkCurleyBraces
= TRUE
;
283 else if (strcmp(argv
[i
], "-checksyntax") == 0)
291 buf
.Printf("Invalid switch %s.\n", argv
[i
]);
292 OnError((char *)buf
.c_str());
302 #if defined(__WXMSW__) && !defined(NO_GUI)
304 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
305 TheTex2RTFServer
= new Tex2RTFServer
;
306 TheTex2RTFServer
->Create("TEX2RTF");
309 #if defined(__WXMSW__) && defined(__WIN16__)
310 // Limit to max Windows array size
311 if (BufSize
> 64) BufSize
= 64;
314 TexInitialize(BufSize
);
315 ResetContentsLevels(0);
323 // Create the main frame window
324 frame
= new MyFrame(NULL
, -1, "Tex2RTF", wxPoint(-1, -1), wxSize(400, 300));
325 frame
->CreateStatusBar(2);
328 // TODO: uncomment this when we have tex2rtf.xpm
329 frame
->SetIcon(wxICON(tex2rtf
));
333 sprintf(buf
, "Tex2RTF [%s]", wxFileNameFromPath(InputFile
));
334 frame
->SetTitle(buf
);
338 wxMenu
*file_menu
= new wxMenu
;
339 file_menu
->Append(TEX_GO
, "&Go", "Run converter");
340 file_menu
->Append(TEX_SET_INPUT
, "Set &Input File", "Set the LaTeX input file");
341 file_menu
->Append(TEX_SET_OUTPUT
, "Set &Output File", "Set the output file");
342 file_menu
->AppendSeparator();
343 file_menu
->Append(TEX_VIEW_LATEX
, "View &LaTeX File", "View the LaTeX input file");
344 file_menu
->Append(TEX_VIEW_OUTPUT
, "View Output &File", "View output file");
345 file_menu
->Append(TEX_SAVE_FILE
, "&Save log file", "Save displayed text into file");
346 file_menu
->AppendSeparator();
347 file_menu
->Append(TEX_QUIT
, "E&xit", "Exit Tex2RTF");
349 wxMenu
*macro_menu
= new wxMenu
;
351 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, "&Load Custom Macros", "Load custom LaTeX macro file");
352 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, "View &Custom Macros", "View custom LaTeX macros");
354 wxMenu
*mode_menu
= new wxMenu
;
356 mode_menu
->Append(TEX_MODE_RTF
, "Output linear &RTF", "Wordprocessor-compatible RTF");
357 mode_menu
->Append(TEX_MODE_WINHELP
, "Output &WinHelp RTF", "WinHelp-compatible RTF");
358 mode_menu
->Append(TEX_MODE_HTML
, "Output &HTML", "HTML World Wide Web hypertext file");
359 mode_menu
->Append(TEX_MODE_XLP
, "Output &XLP", "wxHelp hypertext help file");
361 wxMenu
*options_menu
= new wxMenu
;
363 options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, "Curley brace matching", "Checks for mismatched curley braces",TRUE
);
364 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, "Syntax checking", "Syntax checking for common errors",TRUE
);
366 options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
);
367 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
369 wxMenu
*help_menu
= new wxMenu
;
371 help_menu
->Append(TEX_HELP
, "&Help", "Tex2RTF Contents Page");
372 help_menu
->Append(TEX_ABOUT
, "&About Tex2RTF", "About Tex2RTF");
374 menuBar
= new wxMenuBar
;
375 menuBar
->Append(file_menu
, "&File");
376 menuBar
->Append(macro_menu
, "&Macros");
377 menuBar
->Append(mode_menu
, "&Conversion Mode");
378 menuBar
->Append(options_menu
, "&Options");
379 menuBar
->Append(help_menu
, "&Help");
381 frame
->SetMenuBar(menuBar
);
382 frame
->textWindow
= new wxTextCtrl(frame
, -1, "", wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY
|wxTE_MULTILINE
);
384 (*frame
->textWindow
) << "Welcome to Tex2RTF.\n";
388 HelpInstance
= new wxHelpController();
389 HelpInstance
->Initialize("tex2rtf");
393 * Read macro/initialisation file
398 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
399 ReadCustomMacros((char*) (const char*) path
);
403 if (winHelp
&& (convertMode
== TEX_RTF
))
404 strcat(buf
, "WinHelp RTF");
405 else if (!winHelp
&& (convertMode
== TEX_RTF
))
406 strcat(buf
, "linear RTF");
407 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
408 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
409 strcat(buf
, " mode.");
410 frame
->SetStatusText(buf
, 1);
419 * Read macro/initialisation file
424 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
425 ReadCustomMacros((char*) (const char*) path
);
440 // Return the main frame window
450 wxNode
*node
= CustomMacroList
.First();
453 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
456 node
= CustomMacroList
.First();
458 MacroDefs
.BeginFind();
459 node
= MacroDefs
.Next();
462 TexMacroDef
* def
= (TexMacroDef
*) node
->Data();
464 node
= MacroDefs
.Next();
468 delete TheTex2RTFServer
;
483 delete currentArgData
;
484 currentArgData
= NULL
;
498 delete TexTmpBibName
;
499 TexTmpBibName
= NULL
;
513 delete TmpContentsName
;
514 TmpContentsName
= NULL
;
516 if (TmpFrameContentsName
)
518 delete TmpFrameContentsName
;
519 TmpFrameContentsName
= NULL
;
521 if (WinHelpContentsFileName
)
523 delete WinHelpContentsFileName
;
524 WinHelpContentsFileName
= NULL
;
548 delete [] BibliographyStyleString
;
549 delete [] DocumentStyleString
;
550 delete [] bitmapMethod
;
551 delete [] backgroundColourString
;
552 delete [] ContentsNameString
;
553 delete [] AbstractNameString
;
554 delete [] GlossaryNameString
;
555 delete [] ReferencesNameString
;
556 delete [] FiguresNameString
;
557 delete [] TablesNameString
;
558 delete [] FigureNameString
;
559 delete [] TableNameString
;
560 delete [] IndexNameString
;
561 delete [] ChapterNameString
;
562 delete [] SectionNameString
;
563 delete [] SubsectionNameString
;
564 delete [] SubsubsectionNameString
;
565 delete [] UpNameString
;
567 delete[] winHelpTitle
;
569 // TODO: this simulates zero-memory leaks!
570 // Otherwise there are just too many...
572 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
573 wxDebugContext::SetCheckpoint();
580 void ShowOptions(void)
583 sprintf(buf
, "Tex2RTF version %.2f", versionNo
);
585 OnInform("Usage: tex2rtf [input] [output] [switches]\n");
586 OnInform("where valid switches are");
588 OnInform(" -interactive");
590 OnInform(" -bufsize <size in K>");
591 OnInform(" -charset <pc | pca | ansi | mac> (default ansi)");
594 OnInform(" -checkcurleybraces");
595 OnInform(" -checksyntax");
596 OnInform(" -macros <filename>");
597 OnInform(" -winhelp");
605 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
606 EVT_CLOSE(MyFrame::OnCloseWindow
)
607 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
608 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
609 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
610 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
611 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
612 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
613 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
614 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
615 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
616 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
617 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
618 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
619 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
620 EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
621 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
622 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
623 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
626 // My frame constructor
627 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
628 wxFrame(frame
, id
, title
, pos
, size
)
631 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
633 if (!stopRunning
&& !OkToClose
)
645 void MyFrame::OnExit(wxCommandEvent
& event
)
651 void MyFrame::OnGo(wxCommandEvent
& event
)
655 menuBar
->EnableTop(0, FALSE
);
656 menuBar
->EnableTop(1, FALSE
);
657 menuBar
->EnableTop(2, FALSE
);
658 menuBar
->EnableTop(3, FALSE
);
665 SetStatusText("Build aborted!");
667 errBuf
.Printf("\nErrors encountered during this pass: %lu\n", errorCount
);
668 OnInform((char *)errBuf
.c_str());
672 if (runTwice
&& !stopRunning
)
677 menuBar
->EnableTop(0, TRUE
);
678 menuBar
->EnableTop(1, TRUE
);
679 menuBar
->EnableTop(2, TRUE
);
680 menuBar
->EnableTop(3, TRUE
);
683 void MyFrame::OnSetInput(wxCommandEvent
& event
)
685 ChooseInputFile(TRUE
);
688 void MyFrame::OnSetOutput(wxCommandEvent
& event
)
690 ChooseOutputFile(TRUE
);
693 void MyFrame::OnSaveFile(wxCommandEvent
& event
)
695 wxString s
= wxFileSelector("Save text to file", "", "", "txt", "*.txt");
698 textWindow
->SaveFile(s
);
700 sprintf(buf
, "Saved text to %s", (const char*) s
);
701 frame
->SetStatusText(buf
, 0);
705 void MyFrame::OnViewOutput(wxCommandEvent
& event
)
708 if (OutputFile
&& wxFileExists(OutputFile
))
710 textWindow
->LoadFile(OutputFile
);
712 wxString
str(wxFileNameFromPath(OutputFile
));
713 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
714 frame
->SetTitle(buf
);
718 void MyFrame::OnViewLatex(wxCommandEvent
& event
)
721 if (InputFile
&& wxFileExists(InputFile
))
723 textWindow
->LoadFile(InputFile
);
725 wxString
str(wxFileNameFromPath(OutputFile
));
726 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
727 frame
->SetTitle(buf
);
731 void MyFrame::OnLoadMacros(wxCommandEvent
& event
)
734 wxString s
= wxFileSelector("Choose custom macro file", wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), "ini", "*.ini");
735 if (s
!= "" && wxFileExists(s
))
737 MacroFile
= copystring(s
);
738 ReadCustomMacros((char*) (const char*) s
);
743 void MyFrame::OnShowMacros(wxCommandEvent
& event
)
750 void MyFrame::OnModeRTF(wxCommandEvent
& event
)
752 convertMode
= TEX_RTF
;
756 SetStatusText("In linear RTF mode.", 1);
759 void MyFrame::OnModeWinHelp(wxCommandEvent
& event
)
761 convertMode
= TEX_RTF
;
765 SetStatusText("In WinHelp RTF mode.", 1);
768 void MyFrame::OnModeHTML(wxCommandEvent
& event
)
770 convertMode
= TEX_HTML
;
774 SetStatusText("In HTML mode.", 1);
777 void MyFrame::OnModeXLP(wxCommandEvent
& event
)
779 convertMode
= TEX_XLP
;
782 SetStatusText("In XLP mode.", 1);
785 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& event
)
787 checkCurleyBraces
= !checkCurleyBraces
;
788 if (checkCurleyBraces
)
790 SetStatusText("Checking curley braces: YES", 1);
794 SetStatusText("Checking curley braces: NO", 1);
799 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& event
)
801 checkSyntax
= !checkSyntax
;
804 SetStatusText("Checking syntax: YES", 1);
808 SetStatusText("Checking syntax: NO", 1);
813 void MyFrame::OnHelp(wxCommandEvent
& event
)
816 HelpInstance
->LoadFile();
817 HelpInstance
->DisplayContents();
821 void MyFrame::OnAbout(wxCommandEvent
& event
)
825 char *platform
= " (32-bit)";
828 char *platform
= " (16-bit)";
833 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
);
834 wxMessageBox(buf
, "About Tex2RTF");
837 void ChooseInputFile(bool force
)
839 if (force
|| !InputFile
)
841 wxString s
= wxFileSelector("Choose LaTeX input file", wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), "tex", "*.tex");
844 // Different file, so clear index entries.
846 ResetContentsLevels(0);
850 InputFile
= copystring(s
);
851 wxString str
= wxFileNameFromPath(InputFile
);
853 buf
.Printf("Tex2RTF [%s]", str
.c_str());
854 frame
->SetTitle((char *)buf
.c_str());
860 void ChooseOutputFile(bool force
)
862 char extensionBuf
[10];
864 strcpy(wildBuf
, "*.");
867 path
= wxPathOnly(OutputFile
);
869 path
= wxPathOnly(InputFile
);
875 strcpy(extensionBuf
, "rtf");
876 strcat(wildBuf
, "rtf");
881 strcpy(extensionBuf
, "xlp");
882 strcat(wildBuf
, "xlp");
887 #if defined(__WXMSW__) && defined(__WIN16__)
888 strcpy(extensionBuf
, "htm");
889 strcat(wildBuf
, "htm");
891 strcpy(extensionBuf
, "html");
892 strcat(wildBuf
, "html");
897 if (force
|| !OutputFile
)
899 wxString s
= wxFileSelector("Choose output file", path
, wxFileNameFromPath(OutputFile
),
900 extensionBuf
, wildBuf
);
902 OutputFile
= copystring(s
);
914 if (!InputFile
|| !OutputFile
|| stopRunning
)
921 wxString str
= wxFileNameFromPath(InputFile
);
923 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
924 frame
->SetTitle(buf
);
930 // Find extension-less filename
931 strcpy(FileRoot
, OutputFile
);
932 StripExtension(FileRoot
);
934 if (truncateFilenames
&& convertMode
== TEX_HTML
)
936 // Truncate to five characters. This ensures that
937 // we can generate DOS filenames such as thing999. But 1000 files
938 // may not be enough, of course...
939 char* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
942 if(strlen( sName
) > 5)
943 sName
[5] = '\0'; // that should do!
946 sprintf(ContentsName
, "%s.con", FileRoot
);
947 sprintf(TmpContentsName
, "%s.cn1", FileRoot
);
948 sprintf(TmpFrameContentsName
, "%s.frc", FileRoot
);
949 sprintf(WinHelpContentsFileName
, "%s.cnt", FileRoot
);
950 sprintf(RefFileName
, "%s.ref", FileRoot
);
952 TexPathList
.EnsureFileAccessible(InputFile
);
955 wxString s
= TexPathList
.FindValidPath("bullet.bmp");
958 wxString str
= wxFileNameFromPath(s
);
959 bulletFile
= copystring(str
);
963 if (wxFileExists(RefFileName
))
964 ReadTexReferences(RefFileName
);
966 bool success
= FALSE
;
968 if (InputFile
&& OutputFile
)
970 if (!wxFileExists(InputFile
))
972 OnError("Cannot open input file!");
980 buf
.Printf("Working, pass %d...Click CLOSE to abort", passNumber
);
981 frame
->SetStatusText((char *)buf
.c_str());
985 OnInform("Reading LaTeX file...");
986 TexLoadFile(InputFile
);
1015 OnInform("*** Aborted by user.");
1017 stopRunning
= FALSE
;
1023 WriteTexReferences(RefFileName
);
1025 startedSections
= FALSE
;
1029 long tim
= wxGetElapsedTime();
1030 buf
.Printf("Finished PASS #%d in %ld seconds.\n", passNumber
, (long)(tim
/1000.0));
1031 OnInform((char *)buf
.c_str());
1035 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1036 OnInform((char *)buf
.c_str());
1041 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1042 frame
->SetStatusText((char *)buf
.c_str());
1045 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1046 OnInform((char *)buf
.c_str());
1049 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1050 OnInform((char *)buf
.c_str());
1060 startedSections
= FALSE
;
1063 frame
->SetStatusText("Aborted by user.");
1066 OnInform("Sorry, unsuccessful.");
1071 void OnError(const char *msg
)
1076 wxSTD cerr
<< "Error: " << msg
<< "\n";
1079 if (isInteractive
&& frame
)
1080 (*frame
->textWindow
) << "Error: " << msg
<< "\n";
1084 wxSTD cerr
<< "Error: " << msg
<< "\n";
1096 void OnInform(const char *msg
)
1099 wxSTD cout
<< msg
<< "\n";
1102 if (isInteractive
&& frame
)
1103 (*frame
->textWindow
) << msg
<< "\n";
1104 /* This whole block of code is just wrong I think. It would behave
1105 completely wrong under anything other than MSW due to the ELSE
1106 with no statement, and the cout calls would fail under MSW, as
1107 the code in this block is compiled if !NO_GUI This code has been
1108 here since v1.1 of this file too. - gt
1112 wxSTD cout << msg << "\n";
1127 void OnMacro(int macroId
, int no_args
, bool start
)
1129 switch (convertMode
)
1133 RTFOnMacro(macroId
, no_args
, start
);
1138 XLPOnMacro(macroId
, no_args
, start
);
1143 HTMLOnMacro(macroId
, no_args
, start
);
1149 bool OnArgument(int macroId
, int arg_no
, bool start
)
1151 switch (convertMode
)
1155 return RTFOnArgument(macroId
, arg_no
, start
);
1160 return XLPOnArgument(macroId
, arg_no
, start
);
1165 return HTMLOnArgument(macroId
, arg_no
, start
);
1175 #if defined(__WXMSW__) && !defined(NO_GUI)
1181 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1183 if (topic
== "TEX2RTF")
1186 ipc_buffer
= new char[1000];
1188 return new Tex2RTFConnection(ipc_buffer
, 4000);
1198 Tex2RTFConnection::Tex2RTFConnection(char *buf
, int size
):wxDDEConnection(buf
, size
)
1202 Tex2RTFConnection::~Tex2RTFConnection(void)
1206 bool SplitCommand(char *data
, char *firstArg
, char *secondArg
)
1211 int len
= strlen(data
);
1213 // Find first argument (command name)
1216 if (data
[i
] == ' ' || data
[i
] == 0)
1220 firstArg
[i
] = data
[i
];
1227 // Find second argument
1230 while (data
[i
] != 0)
1232 secondArg
[j
] = data
[i
];
1241 bool Tex2RTFConnection::OnExecute(const wxString
& topic
, char *data
, int size
, int format
)
1243 strcpy(Tex2RTFLastStatus
, "OK");
1246 char secondArg
[300];
1247 if (SplitCommand(data
, firstArg
, secondArg
))
1249 bool hasArg
= (strlen(secondArg
) > 0);
1250 if (strcmp(firstArg
, "INPUT") == 0 && hasArg
)
1252 if (InputFile
) delete[] InputFile
;
1253 InputFile
= copystring(secondArg
);
1257 wxString str
= wxFileNameFromPath(InputFile
);
1258 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
1259 frame
->SetTitle(buf
);
1262 else if (strcmp(firstArg
, "OUTPUT") == 0 && hasArg
)
1264 if (OutputFile
) delete[] OutputFile
;
1265 OutputFile
= copystring(secondArg
);
1267 else if (strcmp(firstArg
, "GO") == 0)
1269 strcpy(Tex2RTFLastStatus
, "WORKING");
1271 strcpy(Tex2RTFLastStatus
, "CONVERSION ERROR");
1273 strcpy(Tex2RTFLastStatus
, "OK");
1275 else if (strcmp(firstArg
, "EXIT") == 0)
1277 if (frame
) frame
->Close();
1279 else if (strcmp(firstArg
, "MINIMIZE") == 0 || strcmp(firstArg
, "ICONIZE") == 0)
1282 frame
->Iconize(TRUE
);
1284 else if (strcmp(firstArg
, "SHOW") == 0 || strcmp(firstArg
, "RESTORE") == 0)
1288 frame
->Iconize(FALSE
);
1294 // Try for a setting
1295 strcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, FALSE
));
1297 if (frame
&& strcmp(firstArg
, "conversionMode") == 0)
1302 if (winHelp
&& (convertMode
== TEX_RTF
))
1303 strcat(buf
, "WinHelp RTF");
1304 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1305 strcat(buf
, "linear RTF");
1306 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
1307 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
1308 strcat(buf
, " mode.");
1309 frame
->SetStatusText(buf
, 1);
1317 char *Tex2RTFConnection::OnRequest(const wxString
& topic
, const wxString
& item
, int *size
, int format
)
1319 return Tex2RTFLastStatus
;
1326 //void wxObject::Dump(wxSTD ostream& str)
1328 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1329 // str << GetClassInfo()->GetClassName();
1331 // str << "unknown object class";