1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to linear/WinHelp RTF, HTML, wxHelp.
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/textctrl.h"
28 #include "wx/filedlg.h"
29 #include "wx/msgdlg.h"
53 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
54 #include "tex2rtf.xpm"
57 #if !WXWIN_COMPATIBILITY_2_4
58 static inline wxChar
* copystring(const wxChar
* s
)
59 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
62 const float versionNo
= TEX2RTF_VERSION_NUMBER
;
64 TexChunk
*currentMember
= NULL
;
65 bool startedSections
= false;
66 wxChar
*contentsString
= NULL
;
67 bool suppressNameDecoration
= false;
68 bool OkToClose
= true;
70 unsigned long errorCount
= 0;
74 extern wxChar
*BigBuffer
;
75 extern wxChar
*TexFileRoot
;
76 extern wxChar
*TexBibName
; // Bibliography output file name
77 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
78 extern wxList ColourTable
;
79 extern TexChunk
*TopLevel
;
84 wxHelpController
*HelpInstance
= NULL
;
88 static wxChar
*ipc_buffer
= NULL
;
89 static wxChar Tex2RTFLastStatus
[100];
90 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
94 wxChar
*bulletFile
= NULL
;
96 FILE *Contents
= NULL
; // Contents page
97 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
98 FILE *Sections
= NULL
;
99 FILE *Subsections
= NULL
;
100 FILE *Subsubsections
= NULL
;
102 FILE *WinHelpContentsFile
= NULL
;
104 wxChar
*InputFile
= NULL
;
105 wxChar
*OutputFile
= NULL
;
106 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
108 wxChar
*FileRoot
= NULL
;
109 wxChar
*ContentsName
= NULL
; // Contents page from last time around
110 wxChar
*TmpContentsName
= NULL
; // Current contents page
111 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
112 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
113 wxChar
*RefFileName
= NULL
; // Reference file name
115 wxChar
*RTFCharset
= copystring(_T("ansi"));
118 int BufSize
= 100; // Size of buffer in K
124 void ShowOptions(void);
126 wxChar wxTex2RTFBuffer
[1500];
129 IMPLEMENT_APP_CONSOLE(MyApp
)
131 wxMenuBar
*menuBar
= NULL
;
132 MyFrame
*frame
= NULL
;
133 // DECLARE_APP(MyApp)
137 // `Main program' equivalent, creating windows and returning main app frame
140 // Use default list of macros defined in tex2any.cc
141 DefineDefaultMacros();
142 AddMacroDef(ltHARDY
, _T("hardy"), 0);
144 FileRoot
= new wxChar
[300];
145 ContentsName
= new wxChar
[300];
146 TmpContentsName
= new wxChar
[300];
147 TmpFrameContentsName
= new wxChar
[300];
148 WinHelpContentsFileName
= new wxChar
[300];
149 RefFileName
= new wxChar
[300];
151 ColourTable
.DeleteContents(true);
155 // Read input/output files
158 if (argv
[1][0] != '-')
165 if (argv
[2][0] != '-')
167 OutputFile
= argv
[2];
175 if (!InputFile
|| !OutputFile
)
177 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
185 TexPathList
.EnsureFileAccessible(InputFile
);
187 if (!InputFile
|| !OutputFile
)
188 isInteractive
= true;
191 for (i
= n
; i
< argc
;)
193 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
196 convertMode
= TEX_RTF
;
200 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
203 isInteractive
= true;
206 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
211 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
214 convertMode
= TEX_RTF
;
216 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
219 convertMode
= TEX_HTML
;
221 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
224 convertMode
= TEX_XLP
;
226 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
231 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
236 MacroFile
= copystring(argv
[i
]);
240 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
245 BufSize
= wxAtoi(argv
[i
]);
249 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
256 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
257 wxStrcmp(s
, _T("pca")) == 0)
258 RTFCharset
= copystring(s
);
261 OnError(_T("Incorrect argument for -charset"));
266 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
269 checkCurleyBraces
= true;
271 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
279 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
280 OnError((wxChar
*)buf
.c_str());
289 #if defined(__WXMSW__) && !defined(NO_GUI)
291 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
292 TheTex2RTFServer
= new Tex2RTFServer
;
293 TheTex2RTFServer
->Create(_T("TEX2RTF"));
296 #if defined(__WXMSW__) && defined(__WIN16__)
297 // Limit to max Windows array size
298 if (BufSize
> 64) BufSize
= 64;
301 TexInitialize(BufSize
);
302 ResetContentsLevels(0);
310 // Create the main frame window
311 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
312 frame
->CreateStatusBar(2);
315 // TODO: uncomment this when we have tex2rtf.xpm
316 frame
->SetIcon(wxICON(tex2rtf
));
320 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
321 frame
->SetTitle(buf
);
325 wxMenu
*file_menu
= new wxMenu
;
326 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
327 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
328 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
329 file_menu
->AppendSeparator();
330 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
331 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
332 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
333 file_menu
->AppendSeparator();
334 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
336 wxMenu
*macro_menu
= new wxMenu
;
338 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
339 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
341 wxMenu
*mode_menu
= new wxMenu
;
343 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
344 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
345 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
346 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
348 wxMenu
*options_menu
= new wxMenu
;
350 options_menu
->Append(TEX_OPTIONS_CURELY_BRACE
, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true);
351 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
353 options_menu
->Check(TEX_OPTIONS_CURELY_BRACE
, checkCurleyBraces
);
354 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
356 wxMenu
*help_menu
= new wxMenu
;
358 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
359 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
361 menuBar
= new wxMenuBar
;
362 menuBar
->Append(file_menu
, _T("&File"));
363 menuBar
->Append(macro_menu
, _T("&Macros"));
364 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
365 menuBar
->Append(options_menu
, _T("&Options"));
366 menuBar
->Append(help_menu
, _T("&Help"));
368 frame
->SetMenuBar(menuBar
);
369 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
371 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
375 HelpInstance
= new wxHelpController();
376 HelpInstance
->Initialize(_T("tex2rtf"));
380 * Read macro/initialisation file
384 wxString path
= TexPathList
.FindValidPath(MacroFile
);
386 ReadCustomMacros((wxChar
*)path
.c_str());
388 wxStrcpy(buf
, _T("In "));
390 if (winHelp
&& (convertMode
== TEX_RTF
))
391 wxStrcat(buf
, _T("WinHelp RTF"));
392 else if (!winHelp
&& (convertMode
== TEX_RTF
))
393 wxStrcat(buf
, _T("linear RTF"));
394 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
395 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
396 wxStrcat(buf
, _T(" mode."));
397 frame
->SetStatusText(buf
, 1);
406 * Read macro/initialisation file
410 wxString path
= TexPathList
.FindValidPath(MacroFile
);
412 ReadCustomMacros((wxChar
*)path
.c_str());
422 OnExit(); // Do cleanup since OnExit won't be called now
431 wxNode
*node
= CustomMacroList
.GetFirst();
434 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
437 node
= CustomMacroList
.GetFirst();
439 MacroDefs
.BeginFind();
440 node
= MacroDefs
.Next();
443 TexMacroDef
* def
= (TexMacroDef
*) node
->GetData();
445 node
= MacroDefs
.Next();
449 delete TheTex2RTFServer
;
464 delete currentArgData
;
465 currentArgData
= NULL
;
479 delete TexTmpBibName
;
480 TexTmpBibName
= NULL
;
494 delete TmpContentsName
;
495 TmpContentsName
= NULL
;
497 if (TmpFrameContentsName
)
499 delete TmpFrameContentsName
;
500 TmpFrameContentsName
= NULL
;
502 if (WinHelpContentsFileName
)
504 delete WinHelpContentsFileName
;
505 WinHelpContentsFileName
= NULL
;
529 delete [] BibliographyStyleString
;
530 delete [] DocumentStyleString
;
531 delete [] bitmapMethod
;
532 delete [] backgroundColourString
;
533 delete [] ContentsNameString
;
534 delete [] AbstractNameString
;
535 delete [] GlossaryNameString
;
536 delete [] ReferencesNameString
;
537 delete [] FiguresNameString
;
538 delete [] TablesNameString
;
539 delete [] FigureNameString
;
540 delete [] TableNameString
;
541 delete [] IndexNameString
;
542 delete [] ChapterNameString
;
543 delete [] SectionNameString
;
544 delete [] SubsectionNameString
;
545 delete [] SubsubsectionNameString
;
546 delete [] UpNameString
;
548 delete[] winHelpTitle
;
550 // TODO: this simulates zero-memory leaks!
551 // Otherwise there are just too many...
553 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
554 wxDebugContext::SetCheckpoint();
561 void ShowOptions(void)
564 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
566 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
567 OnInform(_T("where valid switches are"));
569 OnInform(_T(" -interactive"));
571 OnInform(_T(" -bufsize <size in K>"));
572 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
573 OnInform(_T(" -twice"));
574 OnInform(_T(" -sync"));
575 OnInform(_T(" -checkcurleybraces"));
576 OnInform(_T(" -checksyntax"));
577 OnInform(_T(" -macros <filename>"));
578 OnInform(_T(" -winhelp"));
579 OnInform(_T(" -rtf"));
580 OnInform(_T(" -html"));
581 OnInform(_T(" -xlp\n"));
586 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
587 EVT_CLOSE(MyFrame::OnCloseWindow
)
588 EVT_MENU(TEX_QUIT
, MyFrame::OnExit
)
589 EVT_MENU(TEX_GO
, MyFrame::OnGo
)
590 EVT_MENU(TEX_SET_INPUT
, MyFrame::OnSetInput
)
591 EVT_MENU(TEX_SET_OUTPUT
, MyFrame::OnSetOutput
)
592 EVT_MENU(TEX_SAVE_FILE
, MyFrame::OnSaveFile
)
593 EVT_MENU(TEX_VIEW_LATEX
, MyFrame::OnViewLatex
)
594 EVT_MENU(TEX_VIEW_OUTPUT
, MyFrame::OnViewOutput
)
595 EVT_MENU(TEX_VIEW_CUSTOM_MACROS
, MyFrame::OnShowMacros
)
596 EVT_MENU(TEX_LOAD_CUSTOM_MACROS
, MyFrame::OnLoadMacros
)
597 EVT_MENU(TEX_MODE_RTF
, MyFrame::OnModeRTF
)
598 EVT_MENU(TEX_MODE_WINHELP
, MyFrame::OnModeWinHelp
)
599 EVT_MENU(TEX_MODE_HTML
, MyFrame::OnModeHTML
)
600 EVT_MENU(TEX_MODE_XLP
, MyFrame::OnModeXLP
)
601 EVT_MENU(TEX_OPTIONS_CURELY_BRACE
, MyFrame::OnOptionsCurleyBrace
)
602 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING
, MyFrame::OnOptionsSyntaxChecking
)
603 EVT_MENU(TEX_HELP
, MyFrame::OnHelp
)
604 EVT_MENU(TEX_ABOUT
, MyFrame::OnAbout
)
607 // My frame constructor
608 MyFrame::MyFrame(wxFrame
*frame
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
):
609 wxFrame(frame
, id
, title
, pos
, size
)
612 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
614 if (!stopRunning
&& !OkToClose
)
626 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
632 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
636 menuBar
->EnableTop(0, false);
637 menuBar
->EnableTop(1, false);
638 menuBar
->EnableTop(2, false);
639 menuBar
->EnableTop(3, false);
646 SetStatusText(_T("Build aborted!"));
648 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
649 OnInform((wxChar
*)errBuf
.c_str());
653 if (runTwice
&& !stopRunning
)
658 menuBar
->EnableTop(0, true);
659 menuBar
->EnableTop(1, true);
660 menuBar
->EnableTop(2, true);
661 menuBar
->EnableTop(3, true);
664 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
666 ChooseInputFile(true);
669 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
671 ChooseOutputFile(true);
674 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
676 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
679 textWindow
->SaveFile(s
);
681 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
682 frame
->SetStatusText(buf
, 0);
686 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
689 if (OutputFile
&& wxFileExists(OutputFile
))
691 textWindow
->LoadFile(OutputFile
);
693 wxString
str(wxFileNameFromPath(OutputFile
));
694 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
695 frame
->SetTitle(buf
);
699 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
702 if (InputFile
&& wxFileExists(InputFile
))
704 textWindow
->LoadFile(InputFile
);
706 wxString
str(wxFileNameFromPath(OutputFile
));
707 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
708 frame
->SetTitle(buf
);
712 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
715 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
716 if (s
!= _T("") && wxFileExists(s
))
718 MacroFile
= copystring(s
);
719 ReadCustomMacros((wxChar
*)s
.c_str());
724 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
731 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
733 convertMode
= TEX_RTF
;
737 SetStatusText(_T("In linear RTF mode."), 1);
740 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
742 convertMode
= TEX_RTF
;
746 SetStatusText(_T("In WinHelp RTF mode."), 1);
749 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
751 convertMode
= TEX_HTML
;
755 SetStatusText(_T("In HTML mode."), 1);
758 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
760 convertMode
= TEX_XLP
;
763 SetStatusText(_T("In XLP mode."), 1);
766 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& WXUNUSED(event
))
768 checkCurleyBraces
= !checkCurleyBraces
;
769 if (checkCurleyBraces
)
771 SetStatusText(_T("Checking curley braces: YES"), 1);
775 SetStatusText(_T("Checking curley braces: NO"), 1);
780 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
782 checkSyntax
= !checkSyntax
;
785 SetStatusText(_T("Checking syntax: YES"), 1);
789 SetStatusText(_T("Checking syntax: NO"), 1);
794 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
797 HelpInstance
->LoadFile();
798 HelpInstance
->DisplayContents();
802 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
806 wxChar
*platform
= _T(" (32-bit)");
809 wxChar
*platform
= _T(" (16-bit)");
811 wxChar
*platform
= _T("");
814 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF Version %.2f%s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2002"), versionNo
, platform
);
815 wxMessageBox(buf
, _T("About Tex2RTF"));
818 void ChooseInputFile(bool force
)
820 if (force
|| !InputFile
)
822 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
825 // Different file, so clear index entries.
827 ResetContentsLevels(0);
831 InputFile
= copystring(s
);
832 wxString str
= wxFileNameFromPath(InputFile
);
834 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
835 frame
->SetTitle((wxChar
*)buf
.c_str());
841 void ChooseOutputFile(bool force
)
843 wxChar extensionBuf
[10];
845 wxStrcpy(wildBuf
, _T("*."));
848 path
= wxPathOnly(OutputFile
);
850 path
= wxPathOnly(InputFile
);
856 wxStrcpy(extensionBuf
, _T("rtf"));
857 wxStrcat(wildBuf
, _T("rtf"));
862 wxStrcpy(extensionBuf
, _T("xlp"));
863 wxStrcat(wildBuf
, _T("xlp"));
868 #if defined(__WXMSW__) && defined(__WIN16__)
869 wxStrcpy(extensionBuf
, _T("htm"));
870 wxStrcat(wildBuf
, _T("htm"));
872 wxStrcpy(extensionBuf
, _T("html"));
873 wxStrcat(wildBuf
, _T("html"));
878 if (force
|| !OutputFile
)
880 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
881 extensionBuf
, wildBuf
);
883 OutputFile
= copystring(s
);
895 if (!InputFile
|| !OutputFile
|| stopRunning
)
902 wxString str
= wxFileNameFromPath(InputFile
);
904 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
905 frame
->SetTitle(buf
);
911 // Find extension-less filename
912 wxStrcpy(FileRoot
, OutputFile
);
913 StripExtension(FileRoot
);
915 if (truncateFilenames
&& convertMode
== TEX_HTML
)
917 // Truncate to five characters. This ensures that
918 // we can generate DOS filenames such as thing999. But 1000 files
919 // may not be enough, of course...
920 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
923 if(wxStrlen( sName
) > 5)
924 sName
[5] = '\0'; // that should do!
927 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
928 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
929 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
930 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
931 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
933 TexPathList
.EnsureFileAccessible(InputFile
);
936 wxString s
= TexPathList
.FindValidPath(_T("bullet.bmp"));
939 wxString str
= wxFileNameFromPath(s
);
940 bulletFile
= copystring(str
);
944 if (wxFileExists(RefFileName
))
945 ReadTexReferences(RefFileName
);
947 bool success
= false;
949 if (InputFile
&& OutputFile
)
951 if (!wxFileExists(InputFile
))
953 OnError(_T("Cannot open input file!"));
961 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
962 frame
->SetStatusText((wxChar
*)buf
.c_str());
966 OnInform(_T("Reading LaTeX file..."));
967 TexLoadFile(InputFile
);
996 OnInform(_T("*** Aborted by user."));
1004 WriteTexReferences(RefFileName
);
1006 startedSections
= false;
1010 long tim
= wxGetElapsedTime();
1011 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1012 OnInform((wxChar
*)buf
.c_str());
1016 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1017 OnInform((wxChar
*)buf
.c_str());
1022 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1023 frame
->SetStatusText((wxChar
*)buf
.c_str());
1026 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1027 OnInform((wxChar
*)buf
.c_str());
1030 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1031 OnInform((wxChar
*)buf
.c_str());
1041 startedSections
= false;
1044 frame
->SetStatusText(_T("Aborted by user."));
1047 OnInform(_T("Sorry, unsuccessful."));
1052 void OnError(const wxChar
*msg
)
1054 wxString msg_string
= msg
;
1058 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1061 if (isInteractive
&& frame
)
1062 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1066 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1078 void OnInform(const wxChar
*msg
)
1080 wxString msg_string
= msg
;
1082 wxSTD cout
<< msg_string
.mb_str() << "\n";
1085 if (isInteractive
&& frame
)
1086 (*frame
->textWindow
) << msg
<< _T("\n");
1087 /* This whole block of code is just wrong I think. It would behave
1088 completely wrong under anything other than MSW due to the ELSE
1089 with no statement, and the cout calls would fail under MSW, as
1090 the code in this block is compiled if !NO_GUI This code has been
1091 here since v1.1 of this file too. - gt
1095 wxSTD cout << msg_string.mb_str() << "\n";
1110 void OnMacro(int macroId
, int no_args
, bool start
)
1112 switch (convertMode
)
1116 RTFOnMacro(macroId
, no_args
, start
);
1121 XLPOnMacro(macroId
, no_args
, start
);
1126 HTMLOnMacro(macroId
, no_args
, start
);
1132 bool OnArgument(int macroId
, int arg_no
, bool start
)
1134 switch (convertMode
)
1138 return RTFOnArgument(macroId
, arg_no
, start
);
1143 return XLPOnArgument(macroId
, arg_no
, start
);
1148 return HTMLOnArgument(macroId
, arg_no
, start
);
1158 #if defined(__WXMSW__) && !defined(NO_GUI)
1164 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1166 if (topic
== _T("TEX2RTF"))
1169 ipc_buffer
= new wxChar
[1000];
1171 return new Tex2RTFConnection(ipc_buffer
, 4000);
1181 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1185 Tex2RTFConnection::~Tex2RTFConnection(void)
1189 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1195 // Find first argument (command name)
1198 if (data
[i
] == ' ' || data
[i
] == 0)
1202 firstArg
[i
] = data
[i
];
1209 // Find second argument
1212 while (data
[i
] != 0)
1214 secondArg
[j
] = data
[i
];
1223 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1225 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1227 wxChar firstArg
[50];
1228 wxChar secondArg
[300];
1229 if (SplitCommand(data
, firstArg
, secondArg
))
1231 bool hasArg
= (wxStrlen(secondArg
) > 0);
1232 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1234 if (InputFile
) delete[] InputFile
;
1235 InputFile
= copystring(secondArg
);
1239 wxString str
= wxFileNameFromPath(InputFile
);
1240 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1241 frame
->SetTitle(buf
);
1244 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1246 if (OutputFile
) delete[] OutputFile
;
1247 OutputFile
= copystring(secondArg
);
1249 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1251 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1253 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1255 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1257 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1259 if (frame
) frame
->Close();
1261 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1264 frame
->Iconize(true);
1266 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1270 frame
->Iconize(false);
1276 // Try for a setting
1277 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1279 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1282 wxStrcpy(buf
, _T("In "));
1284 if (winHelp
&& (convertMode
== TEX_RTF
))
1285 wxStrcat(buf
, _T("WinHelp RTF"));
1286 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1287 wxStrcat(buf
, _T("linear RTF"));
1288 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1289 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1290 wxStrcat(buf
, _T(" mode."));
1291 frame
->SetStatusText(buf
, 1);
1299 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1301 return Tex2RTFLastStatus
;
1308 //void wxObject::Dump(wxSTD ostream& str)
1310 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1311 // str << GetClassInfo()->GetClassName();
1313 // str << "unknown object class";