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);
135 char wxTex2RTFBuffer
[1500];
139 int main(int argc
, char **argv
)
141 wxMenuBar
*menuBar
= NULL
;
142 MyFrame
*frame
= NULL
;
144 // DECLARE_APP(MyApp)
147 // `Main program' equivalent, creating windows and returning main app frame
151 // Use default list of macros defined in tex2any.cc
152 DefineDefaultMacros();
153 AddMacroDef(ltHARDY
, "hardy", 0);
155 FileRoot
= new char[300];
156 ContentsName
= new char[300];
157 TmpContentsName
= new char[300];
158 TmpFrameContentsName
= new char[300];
159 WinHelpContentsFileName
= new char[300];
160 RefFileName
= new char[300];
162 ColourTable
.DeleteContents(TRUE
);
166 // Read input/output files
169 if (argv
[1][0] != '-')
176 if (argv
[2][0] != '-')
178 OutputFile
= argv
[2];
186 if (!InputFile
|| !OutputFile
)
188 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
196 TexPathList
.EnsureFileAccessible(InputFile
);
198 if (!InputFile
|| !OutputFile
)
199 isInteractive
= TRUE
;
202 for (i
= n
; i
< argc
;)
204 if (strcmp(argv
[i
], "-winhelp") == 0)
207 convertMode
= TEX_RTF
;
211 else if (strcmp(argv
[i
], "-interactive") == 0)
214 isInteractive
= TRUE
;
217 else if (strcmp(argv
[i
], "-sync") == 0) // Don't yield
222 else if (strcmp(argv
[i
], "-rtf") == 0)
225 convertMode
= TEX_RTF
;
227 else if (strcmp(argv
[i
], "-html") == 0)
230 convertMode
= TEX_HTML
;
232 else if (strcmp(argv
[i
], "-xlp") == 0)
235 convertMode
= TEX_XLP
;
237 else if (strcmp(argv
[i
], "-twice") == 0)
242 else if (strcmp(argv
[i
], "-macros") == 0)
247 MacroFile
= copystring(argv
[i
]);
251 else if (strcmp(argv
[i
], "-bufsize") == 0)
256 BufSize
= atoi(argv
[i
]);
260 else if (strcmp(argv
[i
], "-charset") == 0)
267 if (strcmp(s
, "ansi") == 0 || strcmp(s
, "pc") == 0 || strcmp(s
, "mac") == 0 ||
268 strcmp(s
, "pca") == 0)
269 RTFCharset
= copystring(s
);
272 OnError("Incorrect argument for -charset");
277 else if (strcmp(argv
[i
], "-checkcurleybraces") == 0)
280 checkCurleyBraces
= TRUE
;
282 else if (strcmp(argv
[i
], "-checksyntax") == 0)
290 buf
.Printf("Invalid switch %s.\n", argv
[i
]);
291 OnError((char *)buf
.c_str());
301 #if defined(__WXMSW__) && !defined(NO_GUI)
303 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
304 TheTex2RTFServer
= new Tex2RTFServer
;
305 TheTex2RTFServer
->Create("TEX2RTF");
308 #if defined(__WXMSW__) && defined(__WIN16__)
309 // Limit to max Windows array size
310 if (BufSize
> 64) BufSize
= 64;
313 TexInitialize(BufSize
);
314 ResetContentsLevels(0);
322 // Create the main frame window
323 frame
= new MyFrame(NULL
, -1, "Tex2RTF", wxPoint(-1, -1), wxSize(400, 300));
324 frame
->CreateStatusBar(2);
327 // TODO: uncomment this when we have tex2rtf.xpm
328 frame
->SetIcon(wxICON(tex2rtf
));
332 sprintf(buf
, "Tex2RTF [%s]", FileNameFromPath(InputFile
));
333 frame
->SetTitle(buf
);
337 wxMenu
*file_menu
= new wxMenu
;
338 file_menu
->Append(TEX_GO
, "&Go", "Run converter");
339 file_menu
->Append(TEX_SET_INPUT
, "Set &Input File", "Set the LaTeX input file");
340 file_menu
->Append(TEX_SET_OUTPUT
, "Set &Output File", "Set the output file");
341 file_menu
->AppendSeparator();
342 file_menu
->Append(TEX_VIEW_LATEX
, "View &LaTeX File", "View the LaTeX input file");
343 file_menu
->Append(TEX_VIEW_OUTPUT
, "View Output &File", "View output file");
344 file_menu
->Append(TEX_SAVE_FILE
, "&Save log file", "Save displayed text into file");
345 file_menu
->AppendSeparator();
346 file_menu
->Append(TEX_QUIT
, "E&xit", "Exit Tex2RTF");
348 wxMenu
*macro_menu
= new wxMenu
;
350 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, "&Load Custom Macros", "Load custom LaTeX macro file");
351 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, "View &Custom Macros", "View custom LaTeX macros");
353 wxMenu
*mode_menu
= new wxMenu
;
355 mode_menu
->Append(TEX_MODE_RTF
, "Output linear &RTF", "Wordprocessor-compatible RTF");
356 mode_menu
->Append(TEX_MODE_WINHELP
, "Output &WinHelp RTF", "WinHelp-compatible RTF");
357 mode_menu
->Append(TEX_MODE_HTML
, "Output &HTML", "HTML World Wide Web hypertext file");
358 mode_menu
->Append(TEX_MODE_XLP
, "Output &XLP", "wxHelp hypertext help file");
360 wxMenu
*options_menu
= new wxMenu
;
362 options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, "Curley brace matching", "Checks for mismatched curley braces",TRUE
);
363 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, "Syntax checking", "Syntax checking for common errors",TRUE
);
365 options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
);
366 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
368 wxMenu
*help_menu
= new wxMenu
;
370 help_menu
->Append(TEX_HELP
, "&Help", "Tex2RTF Contents Page");
371 help_menu
->Append(TEX_ABOUT
, "&About Tex2RTF", "About Tex2RTF");
373 menuBar
= new wxMenuBar
;
374 menuBar
->Append(file_menu
, "&File");
375 menuBar
->Append(macro_menu
, "&Macros");
376 menuBar
->Append(mode_menu
, "&Conversion Mode");
377 menuBar
->Append(options_menu
, "&Options");
378 menuBar
->Append(help_menu
, "&Help");
380 frame
->SetMenuBar(menuBar
);
381 frame
->textWindow
= new wxTextCtrl(frame
, -1, "", wxPoint(-1, -1), wxSize(-1, -1), wxTE_READONLY
|wxTE_MULTILINE
);
383 (*frame
->textWindow
) << "Welcome to Julian Smart's LaTeX to RTF converter.\n";
387 HelpInstance
= new wxHelpController();
388 HelpInstance
->Initialize("tex2rtf");
392 * Read macro/initialisation file
397 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
398 ReadCustomMacros((char*) (const char*) path
);
402 if (winHelp
&& (convertMode
== TEX_RTF
))
403 strcat(buf
, "WinHelp RTF");
404 else if (!winHelp
&& (convertMode
== TEX_RTF
))
405 strcat(buf
, "linear RTF");
406 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
407 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
408 strcat(buf
, " mode.");
409 frame
->SetStatusText(buf
, 1);
418 * Read macro/initialisation file
423 if ((path
= TexPathList
.FindValidPath(MacroFile
)) != "")
424 ReadCustomMacros((char*) (const char*) path
);
439 // Return the main frame window
449 wxNode
*node
= CustomMacroList
.First();
452 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
455 node
= CustomMacroList
.First();
457 MacroDefs
.BeginFind();
458 node
= MacroDefs
.Next();
461 TexMacroDef
* def
= (TexMacroDef
*) node
->Data();
463 node
= MacroDefs
.Next();
467 delete TheTex2RTFServer
;
482 delete currentArgData
;
483 currentArgData
= NULL
;
497 delete TexTmpBibName
;
498 TexTmpBibName
= NULL
;
512 delete TmpContentsName
;
513 TmpContentsName
= NULL
;
515 if (TmpFrameContentsName
)
517 delete TmpFrameContentsName
;
518 TmpFrameContentsName
= NULL
;
520 if (WinHelpContentsFileName
)
522 delete WinHelpContentsFileName
;
523 WinHelpContentsFileName
= NULL
;
547 delete [] BibliographyStyleString
;
548 delete [] DocumentStyleString
;
549 delete [] bitmapMethod
;
550 delete [] backgroundColourString
;
551 delete [] ContentsNameString
;
552 delete [] AbstractNameString
;
553 delete [] GlossaryNameString
;
554 delete [] ReferencesNameString
;
555 delete [] FiguresNameString
;
556 delete [] TablesNameString
;
557 delete [] FigureNameString
;
558 delete [] TableNameString
;
559 delete [] IndexNameString
;
560 delete [] ChapterNameString
;
561 delete [] SectionNameString
;
562 delete [] SubsectionNameString
;
563 delete [] SubsubsectionNameString
;
564 delete [] UpNameString
;
566 delete[] winHelpTitle
;
568 // TODO: this simulates zero-memory leaks!
569 // Otherwise there are just too many...
571 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
572 wxDebugContext::SetCheckpoint();
579 void ShowOptions(void)
582 sprintf(buf
, "Tex2RTF version %.2f", versionNo
);
584 OnInform("Usage: tex2rtf [input] [output] [switches]\n");
585 OnInform("where valid switches are");
587 OnInform(" -interactive");
589 OnInform(" -bufsize <size in K>");
590 OnInform(" -charset <pc | pca | ansi | mac> (default ansi)");
593 OnInform(" -checkcurleybraces");
594 OnInform(" -checksyntax");
595 OnInform(" -macros <filename>");
596 OnInform(" -winhelp");
604 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
605 EVT_CLOSE(MyFrame::OnCloseWindow
)
606 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
607 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
608 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
609 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
610 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
611 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
612 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
613 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
614 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
615 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
616 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
617 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
618 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
619 EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
620 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
621 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
622 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
625 // My frame constructor
626 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
627 wxFrame(frame
, id
, title
, pos
, size
)
630 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
632 if (!stopRunning
&& !OkToClose
)
644 void MyFrame::OnExit(wxCommandEvent
& event
)
650 void MyFrame::OnGo(wxCommandEvent
& event
)
654 menuBar
->EnableTop(0, FALSE
);
655 menuBar
->EnableTop(1, FALSE
);
656 menuBar
->EnableTop(2, FALSE
);
657 menuBar
->EnableTop(3, FALSE
);
664 SetStatusText("Build aborted!");
666 errBuf
.Printf("\nErrors encountered during this pass: %lu\n", errorCount
);
667 OnInform((char *)errBuf
.c_str());
671 if (runTwice
&& !stopRunning
)
676 menuBar
->EnableTop(0, TRUE
);
677 menuBar
->EnableTop(1, TRUE
);
678 menuBar
->EnableTop(2, TRUE
);
679 menuBar
->EnableTop(3, TRUE
);
682 void MyFrame::OnSetInput(wxCommandEvent
& event
)
684 ChooseInputFile(TRUE
);
687 void MyFrame::OnSetOutput(wxCommandEvent
& event
)
689 ChooseOutputFile(TRUE
);
692 void MyFrame::OnSaveFile(wxCommandEvent
& event
)
694 wxString s
= wxFileSelector("Save text to file", "", "", "txt", "*.txt");
697 textWindow
->SaveFile(s
);
699 sprintf(buf
, "Saved text to %s", (const char*) s
);
700 frame
->SetStatusText(buf
, 0);
704 void MyFrame::OnViewOutput(wxCommandEvent
& event
)
707 if (OutputFile
&& wxFileExists(OutputFile
))
709 textWindow
->LoadFile(OutputFile
);
711 wxString
str(wxFileNameFromPath(OutputFile
));
712 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
713 frame
->SetTitle(buf
);
717 void MyFrame::OnViewLatex(wxCommandEvent
& event
)
720 if (InputFile
&& wxFileExists(InputFile
))
722 textWindow
->LoadFile(InputFile
);
724 wxString
str(wxFileNameFromPath(OutputFile
));
725 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
726 frame
->SetTitle(buf
);
730 void MyFrame::OnLoadMacros(wxCommandEvent
& event
)
733 wxString s
= wxFileSelector("Choose custom macro file", wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), "ini", "*.ini");
734 if (s
!= "" && wxFileExists(s
))
736 MacroFile
= copystring(s
);
737 ReadCustomMacros((char*) (const char*) s
);
742 void MyFrame::OnShowMacros(wxCommandEvent
& event
)
749 void MyFrame::OnModeRTF(wxCommandEvent
& event
)
751 convertMode
= TEX_RTF
;
755 SetStatusText("In linear RTF mode.", 1);
758 void MyFrame::OnModeWinHelp(wxCommandEvent
& event
)
760 convertMode
= TEX_RTF
;
764 SetStatusText("In WinHelp RTF mode.", 1);
767 void MyFrame::OnModeHTML(wxCommandEvent
& event
)
769 convertMode
= TEX_HTML
;
773 SetStatusText("In HTML mode.", 1);
776 void MyFrame::OnModeXLP(wxCommandEvent
& event
)
778 convertMode
= TEX_XLP
;
781 SetStatusText("In XLP mode.", 1);
784 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& event
)
786 checkCurleyBraces
= !checkCurleyBraces
;
787 if (checkCurleyBraces
)
789 SetStatusText("Checking curley braces: YES", 1);
793 SetStatusText("Checking curley braces: NO", 1);
798 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& event
)
800 checkSyntax
= !checkSyntax
;
803 SetStatusText("Checking syntax: YES", 1);
807 SetStatusText("Checking syntax: NO", 1);
812 void MyFrame::OnHelp(wxCommandEvent
& event
)
815 HelpInstance
->LoadFile();
816 HelpInstance
->DisplayContents();
820 void MyFrame::OnAbout(wxCommandEvent
& event
)
824 char *platform
= " (32-bit)";
827 char *platform
= " (16-bit)";
832 sprintf(buf
, "Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, HTML and wxHelp Conversion\n\n(c) Julian Smart 1999", versionNo
, platform
);
833 wxMessageBox(buf
, "About Tex2RTF");
836 void ChooseInputFile(bool force
)
838 if (force
|| !InputFile
)
840 wxString s
= wxFileSelector("Choose LaTeX input file", wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), "tex", "*.tex");
843 // Different file, so clear index entries.
845 ResetContentsLevels(0);
849 InputFile
= copystring(s
);
850 wxString str
= wxFileNameFromPath(InputFile
);
852 buf
.Printf("Tex2RTF [%s]", str
.c_str());
853 frame
->SetTitle((char *)buf
.c_str());
859 void ChooseOutputFile(bool force
)
861 char extensionBuf
[10];
863 strcpy(wildBuf
, "*.");
866 path
= wxPathOnly(OutputFile
);
868 path
= wxPathOnly(InputFile
);
874 strcpy(extensionBuf
, "rtf");
875 strcat(wildBuf
, "rtf");
880 strcpy(extensionBuf
, "xlp");
881 strcat(wildBuf
, "xlp");
886 #if defined(__WXMSW__) && defined(__WIN16__)
887 strcpy(extensionBuf
, "htm");
888 strcat(wildBuf
, "htm");
890 strcpy(extensionBuf
, "html");
891 strcat(wildBuf
, "html");
896 if (force
|| !OutputFile
)
898 wxString s
= wxFileSelector("Choose output file", path
, wxFileNameFromPath(OutputFile
),
899 extensionBuf
, wildBuf
);
901 OutputFile
= copystring(s
);
913 if (!InputFile
|| !OutputFile
|| stopRunning
)
920 wxString str
= wxFileNameFromPath(InputFile
);
922 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
923 frame
->SetTitle(buf
);
929 // Find extension-less filename
930 strcpy(FileRoot
, OutputFile
);
931 StripExtension(FileRoot
);
933 if (truncateFilenames
&& convertMode
== TEX_HTML
)
935 // Truncate to five characters. This ensures that
936 // we can generate DOS filenames such as thing999. But 1000 files
937 // may not be enough, of course...
938 char* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
941 if(strlen( sName
) > 5)
942 sName
[5] = '\0'; // that should do!
945 sprintf(ContentsName
, "%s.con", FileRoot
);
946 sprintf(TmpContentsName
, "%s.cn1", FileRoot
);
947 sprintf(TmpFrameContentsName
, "%s.frc", FileRoot
);
948 sprintf(WinHelpContentsFileName
, "%s.cnt", FileRoot
);
949 sprintf(RefFileName
, "%s.ref", FileRoot
);
951 TexPathList
.EnsureFileAccessible(InputFile
);
954 wxString s
= TexPathList
.FindValidPath("bullet.bmp");
957 wxString str
= wxFileNameFromPath(s
);
958 bulletFile
= copystring(str
);
962 if (wxFileExists(RefFileName
))
963 ReadTexReferences(RefFileName
);
965 bool success
= FALSE
;
967 if (InputFile
&& OutputFile
)
969 if (!FileExists(InputFile
))
971 OnError("Cannot open input file!");
979 buf
.Printf("Working, pass %d...Click CLOSE to abort", passNumber
);
980 frame
->SetStatusText((char *)buf
.c_str());
984 OnInform("Reading LaTeX file...");
985 TexLoadFile(InputFile
);
1014 OnInform("*** Aborted by user.");
1016 stopRunning
= FALSE
;
1022 WriteTexReferences(RefFileName
);
1024 startedSections
= FALSE
;
1028 long tim
= wxGetElapsedTime();
1029 buf
.Printf("Finished PASS #%d in %ld seconds.\n", passNumber
, (long)(tim
/1000.0));
1030 OnInform((char *)buf
.c_str());
1034 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1035 OnInform((char *)buf
.c_str());
1040 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1041 frame
->SetStatusText((char *)buf
.c_str());
1044 buf
.Printf("Done, %d %s.", passNumber
, (passNumber
> 1) ? "passes" : "pass");
1045 OnInform((char *)buf
.c_str());
1048 buf
.Printf("Errors encountered during this pass: %lu\n", errorCount
);
1049 OnInform((char *)buf
.c_str());
1059 startedSections
= FALSE
;
1062 frame
->SetStatusText("Aborted by user.");
1065 OnInform("Sorry, unsuccessful.");
1070 void OnError(const char *msg
)
1075 wxSTD cerr
<< "Error: " << msg
<< "\n";
1078 if (isInteractive
&& frame
)
1079 (*frame
->textWindow
) << "Error: " << msg
<< "\n";
1083 wxSTD cerr
<< "Error: " << msg
<< "\n";
1095 void OnInform(const char *msg
)
1098 wxSTD cout
<< msg
<< "\n";
1101 if (isInteractive
&& frame
)
1102 (*frame
->textWindow
) << msg
<< "\n";
1103 /* This whole block of code is just wrong I think. It would behave
1104 completely wrong under anything other than MSW due to the ELSE
1105 with no statement, and the cout calls would fail under MSW, as
1106 the code in this block is compiled if !NO_GUI This code has been
1107 here since v1.1 of this file too. - gt
1111 wxSTD cout << msg << "\n";
1126 void OnMacro(int macroId
, int no_args
, bool start
)
1128 switch (convertMode
)
1132 RTFOnMacro(macroId
, no_args
, start
);
1137 XLPOnMacro(macroId
, no_args
, start
);
1142 HTMLOnMacro(macroId
, no_args
, start
);
1148 bool OnArgument(int macroId
, int arg_no
, bool start
)
1150 switch (convertMode
)
1154 return RTFOnArgument(macroId
, arg_no
, start
);
1159 return XLPOnArgument(macroId
, arg_no
, start
);
1164 return HTMLOnArgument(macroId
, arg_no
, start
);
1174 #if defined(__WXMSW__) && !defined(NO_GUI)
1180 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1182 if (topic
== "TEX2RTF")
1185 ipc_buffer
= new char[1000];
1187 return new Tex2RTFConnection(ipc_buffer
, 4000);
1197 Tex2RTFConnection::Tex2RTFConnection(char *buf
, int size
):wxDDEConnection(buf
, size
)
1201 Tex2RTFConnection::~Tex2RTFConnection(void)
1205 bool SplitCommand(char *data
, char *firstArg
, char *secondArg
)
1210 int len
= strlen(data
);
1212 // Find first argument (command name)
1215 if (data
[i
] == ' ' || data
[i
] == 0)
1219 firstArg
[i
] = data
[i
];
1226 // Find second argument
1229 while (data
[i
] != 0)
1231 secondArg
[j
] = data
[i
];
1240 bool Tex2RTFConnection::OnExecute(const wxString
& topic
, char *data
, int size
, int format
)
1242 strcpy(Tex2RTFLastStatus
, "OK");
1245 char secondArg
[300];
1246 if (SplitCommand(data
, firstArg
, secondArg
))
1248 bool hasArg
= (strlen(secondArg
) > 0);
1249 if (strcmp(firstArg
, "INPUT") == 0 && hasArg
)
1251 if (InputFile
) delete[] InputFile
;
1252 InputFile
= copystring(secondArg
);
1256 wxString str
= wxFileNameFromPath(InputFile
);
1257 sprintf(buf
, "Tex2RTF [%s]", (const char*) str
);
1258 frame
->SetTitle(buf
);
1261 else if (strcmp(firstArg
, "OUTPUT") == 0 && hasArg
)
1263 if (OutputFile
) delete[] OutputFile
;
1264 OutputFile
= copystring(secondArg
);
1266 else if (strcmp(firstArg
, "GO") == 0)
1268 strcpy(Tex2RTFLastStatus
, "WORKING");
1270 strcpy(Tex2RTFLastStatus
, "CONVERSION ERROR");
1272 strcpy(Tex2RTFLastStatus
, "OK");
1274 else if (strcmp(firstArg
, "EXIT") == 0)
1276 if (frame
) frame
->Close();
1278 else if (strcmp(firstArg
, "MINIMIZE") == 0 || strcmp(firstArg
, "ICONIZE") == 0)
1281 frame
->Iconize(TRUE
);
1283 else if (strcmp(firstArg
, "SHOW") == 0 || strcmp(firstArg
, "RESTORE") == 0)
1287 frame
->Iconize(FALSE
);
1293 // Try for a setting
1294 strcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, FALSE
));
1296 if (frame
&& strcmp(firstArg
, "conversionMode") == 0)
1301 if (winHelp
&& (convertMode
== TEX_RTF
))
1302 strcat(buf
, "WinHelp RTF");
1303 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1304 strcat(buf
, "linear RTF");
1305 else if (convertMode
== TEX_HTML
) strcat(buf
, "HTML");
1306 else if (convertMode
== TEX_XLP
) strcat(buf
, "XLP");
1307 strcat(buf
, " mode.");
1308 frame
->SetStatusText(buf
, 1);
1316 char *Tex2RTFConnection::OnRequest(const wxString
& topic
, const wxString
& item
, int *size
, int format
)
1318 return Tex2RTFLastStatus
;
1325 //void wxObject::Dump(wxSTD ostream& str)
1327 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1328 // str << GetClassInfo()->GetClassName();
1330 // str << "unknown object class";