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"
36 #include "wx/cshelp.h"
37 #include "wx/helphtml.h"
39 #include "wx/msw/helpchm.h"
41 #include "wx/html/helpctrl.h"
60 #if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
61 #include "tex2rtf.xpm"
64 #if !WXWIN_COMPATIBILITY_2_4
65 static inline wxChar
* copystring(const wxChar
* s
)
66 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
69 const float versionNo
= (float)TEX2RTF_VERSION_NUMBER
;
71 TexChunk
*currentMember
= NULL
;
72 bool startedSections
= false;
73 wxChar
*contentsString
= NULL
;
74 bool suppressNameDecoration
= false;
75 bool OkToClose
= true;
77 unsigned long errorCount
= 0;
81 extern wxChar
*BigBuffer
;
82 extern wxChar
*TexFileRoot
;
83 extern wxChar
*TexBibName
; // Bibliography output file name
84 extern wxChar
*TexTmpBibName
; // Temporary bibliography output file name
85 extern wxList ColourTable
;
86 extern TexChunk
*TopLevel
;
89 wxHelpControllerBase
*HelpInstance
= NULL
;
93 static wxChar
*ipc_buffer
= NULL
;
94 static wxChar Tex2RTFLastStatus
[100];
95 Tex2RTFServer
*TheTex2RTFServer
= NULL
;
100 wxChar
*bulletFile
= NULL
;
102 FILE *Contents
= NULL
; // Contents page
103 FILE *Chapters
= NULL
; // Chapters (WinHelp RTF) or rest of file (linear RTF)
104 FILE *Sections
= NULL
;
105 FILE *Subsections
= NULL
;
106 FILE *Subsubsections
= NULL
;
108 FILE *WinHelpContentsFile
= NULL
;
110 wxChar
*InputFile
= NULL
;
111 wxChar
*OutputFile
= NULL
;
112 wxChar
*MacroFile
= copystring(_T("tex2rtf.ini"));
114 wxChar
*FileRoot
= NULL
;
115 wxChar
*ContentsName
= NULL
; // Contents page from last time around
116 wxChar
*TmpContentsName
= NULL
; // Current contents page
117 wxChar
*TmpFrameContentsName
= NULL
; // Current frame contents page
118 wxChar
*WinHelpContentsFileName
= NULL
; // WinHelp .cnt file
119 wxChar
*RefFileName
= NULL
; // Reference file name
121 wxChar
*RTFCharset
= copystring(_T("ansi"));
124 int BufSize
= 100; // Size of buffer in K
130 void ShowOptions(void);
132 wxChar wxTex2RTFBuffer
[1500];
135 IMPLEMENT_APP_CONSOLE(MyApp
)
137 wxMenuBar
*menuBar
= NULL
;
138 MyFrame
*frame
= NULL
;
139 // DECLARE_APP(MyApp)
143 // `Main program' equivalent, creating windows and returning main app frame
146 // Use default list of macros defined in tex2any.cc
147 DefineDefaultMacros();
148 AddMacroDef(ltHARDY
, _T("hardy"), 0);
150 FileRoot
= new wxChar
[300];
151 ContentsName
= new wxChar
[300];
152 TmpContentsName
= new wxChar
[300];
153 TmpFrameContentsName
= new wxChar
[300];
154 WinHelpContentsFileName
= new wxChar
[300];
155 RefFileName
= new wxChar
[300];
157 WX_CLEAR_LIST(wxList
,ColourTable
);
161 // Read input/output files
164 if (argv
[1][0] != '-')
171 if (argv
[2][0] != '-')
173 OutputFile
= argv
[2];
181 if (!InputFile
|| !OutputFile
)
183 wxSTD cout
<< "Tex2RTF: input or output file is missing.\n";
191 TexPathList
.EnsureFileAccessible(InputFile
);
193 if (!InputFile
|| !OutputFile
)
194 isInteractive
= true;
197 for (i
= n
; i
< argc
;)
199 if (wxStrcmp(argv
[i
], _T("-winhelp")) == 0)
202 convertMode
= TEX_RTF
;
206 else if (wxStrcmp(argv
[i
], _T("-interactive")) == 0)
209 isInteractive
= true;
212 else if (wxStrcmp(argv
[i
], _T("-sync")) == 0) // Don't yield
217 else if (wxStrcmp(argv
[i
], _T("-rtf")) == 0)
220 convertMode
= TEX_RTF
;
222 else if (wxStrcmp(argv
[i
], _T("-html")) == 0)
225 convertMode
= TEX_HTML
;
227 else if (wxStrcmp(argv
[i
], _T("-xlp")) == 0)
230 convertMode
= TEX_XLP
;
232 else if (wxStrcmp(argv
[i
], _T("-twice")) == 0)
237 else if (wxStrcmp(argv
[i
], _T("-macros")) == 0)
242 MacroFile
= copystring(argv
[i
]);
246 else if (wxStrcmp(argv
[i
], _T("-bufsize")) == 0)
251 BufSize
= wxAtoi(argv
[i
]);
255 else if (wxStrcmp(argv
[i
], _T("-charset")) == 0)
262 if (wxStrcmp(s
, _T("ansi")) == 0 || wxStrcmp(s
, _T("pc")) == 0 || wxStrcmp(s
, _T("mac")) == 0 ||
263 wxStrcmp(s
, _T("pca")) == 0)
264 RTFCharset
= copystring(s
);
267 OnError(_T("Incorrect argument for -charset"));
272 else if (wxStrcmp(argv
[i
], _T("-checkcurleybraces")) == 0)
275 checkCurleyBraces
= true;
277 else if (wxStrcmp(argv
[i
], _T("-checksyntax")) == 0)
285 buf
.Printf(_T("Invalid switch %s.\n"), argv
[i
]);
286 OnError((wxChar
*)buf
.c_str());
296 #if defined(__WXMSW__) && !defined(NO_GUI)
298 Tex2RTFLastStatus
[0] = 0; // DDE connection return value
299 TheTex2RTFServer
= new Tex2RTFServer
;
300 TheTex2RTFServer
->Create(_T("TEX2RTF"));
303 TexInitialize(BufSize
);
304 ResetContentsLevels(0);
312 // Create the main frame window
313 frame
= new MyFrame(NULL
, wxID_ANY
, _T("Tex2RTF"), wxDefaultPosition
, wxSize(400, 300));
315 frame
->CreateStatusBar(2);
316 #endif // wxUSE_STATUSBAR
319 // TODO: uncomment this when we have tex2rtf.xpm
320 frame
->SetIcon(wxICON(tex2rtf
));
324 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile
));
325 frame
->SetTitle(buf
);
329 wxMenu
*file_menu
= new wxMenu
;
330 file_menu
->Append(TEX_GO
, _T("&Go"), _T("Run converter"));
331 file_menu
->Append(TEX_SET_INPUT
, _T("Set &Input File"), _T("Set the LaTeX input file"));
332 file_menu
->Append(TEX_SET_OUTPUT
, _T("Set &Output File"), _T("Set the output file"));
333 file_menu
->AppendSeparator();
334 file_menu
->Append(TEX_VIEW_LATEX
, _T("View &LaTeX File"), _T("View the LaTeX input file"));
335 file_menu
->Append(TEX_VIEW_OUTPUT
, _T("View Output &File"), _T("View output file"));
336 file_menu
->Append(TEX_SAVE_FILE
, _T("&Save log file"), _T("Save displayed text into file"));
337 file_menu
->AppendSeparator();
338 file_menu
->Append(TEX_QUIT
, _T("E&xit"), _T("Exit Tex2RTF"));
340 wxMenu
*macro_menu
= new wxMenu
;
342 macro_menu
->Append(TEX_LOAD_CUSTOM_MACROS
, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
343 macro_menu
->Append(TEX_VIEW_CUSTOM_MACROS
, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
345 wxMenu
*mode_menu
= new wxMenu
;
347 mode_menu
->Append(TEX_MODE_RTF
, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
348 mode_menu
->Append(TEX_MODE_WINHELP
, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
349 mode_menu
->Append(TEX_MODE_HTML
, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
350 mode_menu
->Append(TEX_MODE_XLP
, _T("Output &XLP"), _T("wxHelp hypertext help file"));
352 wxMenu
*options_menu
= new wxMenu
;
354 options_menu
->Append(TEX_OPTIONS_CURLEY_BRACE
, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true);
355 options_menu
->Append(TEX_OPTIONS_SYNTAX_CHECKING
, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
357 options_menu
->Check(TEX_OPTIONS_CURLEY_BRACE
, checkCurleyBraces
);
358 options_menu
->Check(TEX_OPTIONS_SYNTAX_CHECKING
, checkSyntax
);
360 wxMenu
*help_menu
= new wxMenu
;
362 help_menu
->Append(TEX_HELP
, _T("&Help"), _T("Tex2RTF Contents Page"));
363 help_menu
->Append(TEX_ABOUT
, _T("&About Tex2RTF"), _T("About Tex2RTF"));
365 menuBar
= new wxMenuBar
;
366 menuBar
->Append(file_menu
, _T("&File"));
367 menuBar
->Append(macro_menu
, _T("&Macros"));
368 menuBar
->Append(mode_menu
, _T("&Conversion Mode"));
369 menuBar
->Append(options_menu
, _T("&Options"));
370 menuBar
->Append(help_menu
, _T("&Help"));
372 frame
->SetMenuBar(menuBar
);
373 frame
->textWindow
= new wxTextCtrl(frame
, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, wxTE_READONLY
|wxTE_MULTILINE
);
375 (*frame
->textWindow
) << _T("Welcome to Tex2RTF.\n");
379 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
380 HelpInstance
= new wxCHMHelpController
;
382 HelpInstance
= new wxHtmlHelpController
;
384 HelpInstance
->Initialize(_T("tex2rtf"));
388 * Read macro/initialisation file
392 wxString path
= TexPathList
.FindValidPath(MacroFile
);
394 ReadCustomMacros((wxChar
*)path
.c_str());
397 wxStrcpy(buf
, _T("In "));
401 wxStrcat(buf
, (winHelp
) ? _T("WinHelp RTF") : _T("linear RTF"));
404 wxStrcat(buf
, _T("HTML"));
407 wxStrcat(buf
, _T("XLP"));
410 wxStrcat(buf
, _T("unknown"));
413 wxStrcat(buf
, _T(" mode."));
414 frame
->SetStatusText(buf
, 1);
415 #endif // wxUSE_STATUSBAR
424 * Read macro/initialisation file
428 wxString path
= TexPathList
.FindValidPath(MacroFile
);
430 ReadCustomMacros((wxChar
*)path
.c_str());
440 OnExit(); // Do cleanup since OnExit won't be called now
449 wxNode
*node
= CustomMacroList
.GetFirst();
452 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
455 node
= CustomMacroList
.GetFirst();
457 MacroDefs
.BeginFind();
458 wxHashTable::Node
* mNode
= MacroDefs
.Next();
461 TexMacroDef
* def
= (TexMacroDef
*) mNode
->GetData();
463 mNode
= 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 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF version %.2f"), versionNo
);
584 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
585 OnInform(_T("where valid switches are"));
587 OnInform(_T(" -interactive"));
589 OnInform(_T(" -bufsize <size in K>"));
590 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
591 OnInform(_T(" -twice"));
592 OnInform(_T(" -sync"));
593 OnInform(_T(" -checkcurleybraces"));
594 OnInform(_T(" -checksyntax"));
595 OnInform(_T(" -macros <filename>"));
596 OnInform(_T(" -winhelp"));
597 OnInform(_T(" -rtf"));
598 OnInform(_T(" -html"));
599 OnInform(_T(" -xlp\n"));
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_CURLEY_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
& WXUNUSED(event
))
632 if (!stopRunning
&& !OkToClose
)
644 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
650 void MyFrame::OnGo(wxCommandEvent
& WXUNUSED(event
))
654 menuBar
->EnableTop(0, false);
655 menuBar
->EnableTop(1, false);
656 menuBar
->EnableTop(2, false);
657 menuBar
->EnableTop(3, false);
665 SetStatusText(_T("Build aborted!"));
666 #endif // wxUSE_STATUSBAR
668 errBuf
.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount
);
669 OnInform((wxChar
*)errBuf
.c_str());
673 if (runTwice
&& !stopRunning
)
678 menuBar
->EnableTop(0, true);
679 menuBar
->EnableTop(1, true);
680 menuBar
->EnableTop(2, true);
681 menuBar
->EnableTop(3, true);
684 void MyFrame::OnSetInput(wxCommandEvent
& WXUNUSED(event
))
686 ChooseInputFile(true);
689 void MyFrame::OnSetOutput(wxCommandEvent
& WXUNUSED(event
))
691 ChooseOutputFile(true);
694 void MyFrame::OnSaveFile(wxCommandEvent
& WXUNUSED(event
))
696 wxString s
= wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
699 textWindow
->SaveFile(s
);
702 wxSnprintf(buf
, sizeof(buf
), _T("Saved text to %s"), (const wxChar
*) s
.c_str());
703 frame
->SetStatusText(buf
, 0);
704 #endif // wxUSE_STATUSBAR
708 void MyFrame::OnViewOutput(wxCommandEvent
& WXUNUSED(event
))
711 if (OutputFile
&& wxFileExists(OutputFile
))
713 textWindow
->LoadFile(OutputFile
);
715 wxString
str(wxFileNameFromPath(OutputFile
));
716 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
717 frame
->SetTitle(buf
);
721 void MyFrame::OnViewLatex(wxCommandEvent
& WXUNUSED(event
))
724 if (InputFile
&& wxFileExists(InputFile
))
726 textWindow
->LoadFile(InputFile
);
728 wxString
str(wxFileNameFromPath(OutputFile
));
729 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
.c_str());
730 frame
->SetTitle(buf
);
734 void MyFrame::OnLoadMacros(wxCommandEvent
& WXUNUSED(event
))
737 wxString s
= wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile
), wxFileNameFromPath(MacroFile
), _T("ini"), _T("*.ini"));
738 if (s
!= _T("") && wxFileExists(s
))
740 MacroFile
= copystring(s
);
741 ReadCustomMacros((wxChar
*)s
.c_str());
746 void MyFrame::OnShowMacros(wxCommandEvent
& WXUNUSED(event
))
753 void MyFrame::OnModeRTF(wxCommandEvent
& WXUNUSED(event
))
755 convertMode
= TEX_RTF
;
760 SetStatusText(_T("In linear RTF mode."), 1);
761 #endif // wxUSE_STATUSBAR
764 void MyFrame::OnModeWinHelp(wxCommandEvent
& WXUNUSED(event
))
766 convertMode
= TEX_RTF
;
771 SetStatusText(_T("In WinHelp RTF mode."), 1);
772 #endif // wxUSE_STATUSBAR
775 void MyFrame::OnModeHTML(wxCommandEvent
& WXUNUSED(event
))
777 convertMode
= TEX_HTML
;
782 SetStatusText(_T("In HTML mode."), 1);
783 #endif // wxUSE_STATUSBAR
786 void MyFrame::OnModeXLP(wxCommandEvent
& WXUNUSED(event
))
788 convertMode
= TEX_XLP
;
792 SetStatusText(_T("In XLP mode."), 1);
793 #endif // wxUSE_STATUSBAR
796 void MyFrame::OnOptionsCurleyBrace(wxCommandEvent
& WXUNUSED(event
))
798 checkCurleyBraces
= !checkCurleyBraces
;
800 if (checkCurleyBraces
)
802 SetStatusText(_T("Checking curley braces: YES"), 1);
806 SetStatusText(_T("Checking curley braces: NO"), 1);
808 #endif // wxUSE_STATUSBAR
812 void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent
& WXUNUSED(event
))
814 checkSyntax
= !checkSyntax
;
818 SetStatusText(_T("Checking syntax: YES"), 1);
822 SetStatusText(_T("Checking syntax: NO"), 1);
824 #endif // wxUSE_STATUSBAR
828 void MyFrame::OnHelp(wxCommandEvent
& WXUNUSED(event
))
831 HelpInstance
->LoadFile();
832 HelpInstance
->DisplayContents();
836 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
840 wxChar
*platform
= _T(" (32-bit)");
843 wxChar
*platform
= _T(" (16-bit)");
845 wxChar
*platform
= _T("");
848 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
);
849 wxMessageBox(buf
, _T("About Tex2RTF"));
852 void ChooseInputFile(bool force
)
854 if (force
|| !InputFile
)
856 wxString s
= wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile
), wxFileNameFromPath(InputFile
), _T("tex"), _T("*.tex"));
859 // Different file, so clear index entries.
861 ResetContentsLevels(0);
865 InputFile
= copystring(s
);
866 wxString str
= wxFileNameFromPath(InputFile
);
868 buf
.Printf(_T("Tex2RTF [%s]"), str
.c_str());
869 frame
->SetTitle((wxChar
*)buf
.c_str());
875 void ChooseOutputFile(bool force
)
877 wxChar extensionBuf
[10];
879 wxStrcpy(wildBuf
, _T("*."));
882 path
= wxPathOnly(OutputFile
);
884 path
= wxPathOnly(InputFile
);
890 wxStrcpy(extensionBuf
, _T("rtf"));
891 wxStrcat(wildBuf
, _T("rtf"));
896 wxStrcpy(extensionBuf
, _T("xlp"));
897 wxStrcat(wildBuf
, _T("xlp"));
902 wxStrcpy(extensionBuf
, _T("html"));
903 wxStrcat(wildBuf
, _T("html"));
907 if (force
|| !OutputFile
)
909 wxString s
= wxFileSelector(_T("Choose output file"), path
, wxFileNameFromPath(OutputFile
),
910 extensionBuf
, wildBuf
);
912 OutputFile
= copystring(s
);
924 if (!InputFile
|| !OutputFile
|| stopRunning
)
931 wxString str
= wxFileNameFromPath(InputFile
);
933 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
934 frame
->SetTitle(buf
);
940 // Find extension-less filename
941 wxStrcpy(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 wxChar
* sName
= wxFileNameFromPath( FileRoot
); // this Julian's method is non-destructive reference
952 if(wxStrlen( sName
) > 5)
953 sName
[5] = '\0'; // that should do!
956 wxSnprintf(ContentsName
, 300, _T("%s.con"), FileRoot
);
957 wxSnprintf(TmpContentsName
, 300, _T("%s.cn1"), FileRoot
);
958 wxSnprintf(TmpFrameContentsName
, 300, _T("%s.frc"), FileRoot
);
959 wxSnprintf(WinHelpContentsFileName
, 300, _T("%s.cnt"), FileRoot
);
960 wxSnprintf(RefFileName
, 300, _T("%s.ref"), FileRoot
);
962 TexPathList
.EnsureFileAccessible(InputFile
);
965 wxString s
= TexPathList
.FindValidPath(_T("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(_T("Cannot open input file!"));
986 #if !defined(NO_GUI) && wxUSE_STATUSBAR
990 buf
.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber
);
991 frame
->SetStatusText((wxChar
*)buf
.c_str());
995 OnInform(_T("Reading LaTeX file..."));
996 TexLoadFile(InputFile
);
1004 switch (convertMode
)
1025 OnInform(_T("*** Aborted by user."));
1027 stopRunning
= false;
1033 WriteTexReferences(RefFileName
);
1035 startedSections
= false;
1039 long tim
= wxGetElapsedTime();
1040 buf
.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber
, (long)(tim
/1000.0));
1041 OnInform((wxChar
*)buf
.c_str());
1045 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1046 OnInform((wxChar
*)buf
.c_str());
1052 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1053 frame
->SetStatusText((wxChar
*)buf
.c_str());
1055 #endif // wxUSE_STATUSBAR
1057 buf
.Printf(_T("Done, %d %s."), passNumber
, (passNumber
> 1) ? _T("passes") : _T("pass"));
1058 OnInform((wxChar
*)buf
.c_str());
1061 buf
.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount
);
1062 OnInform((wxChar
*)buf
.c_str());
1072 startedSections
= false;
1074 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1075 frame
->SetStatusText(_T("Aborted by user."));
1078 OnInform(_T("Sorry, unsuccessful."));
1083 void OnError(const wxChar
*msg
)
1085 wxString msg_string
= msg
;
1089 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1092 if (isInteractive
&& frame
)
1093 (*frame
->textWindow
) << _T("Error: ") << msg
<< _T("\n");
1097 wxSTD cerr
<< "Error: " << msg_string
.mb_str() << "\n";
1109 void OnInform(const wxChar
*msg
)
1111 wxString msg_string
= msg
;
1113 wxSTD cout
<< msg_string
.mb_str() << "\n";
1116 if (isInteractive
&& frame
)
1117 (*frame
->textWindow
) << msg
<< _T("\n");
1118 /* This whole block of code is just wrong I think. It would behave
1119 completely wrong under anything other than MSW due to the ELSE
1120 with no statement, and the cout calls would fail under MSW, as
1121 the code in this block is compiled if !NO_GUI This code has been
1122 here since v1.1 of this file too. - gt
1126 wxSTD cout << msg_string.mb_str() << "\n";
1141 void OnMacro(int macroId
, int no_args
, bool start
)
1143 switch (convertMode
)
1147 RTFOnMacro(macroId
, no_args
, start
);
1152 XLPOnMacro(macroId
, no_args
, start
);
1157 HTMLOnMacro(macroId
, no_args
, start
);
1163 bool OnArgument(int macroId
, int arg_no
, bool start
)
1165 switch (convertMode
)
1169 return RTFOnArgument(macroId
, arg_no
, start
);
1174 return XLPOnArgument(macroId
, arg_no
, start
);
1179 return HTMLOnArgument(macroId
, arg_no
, start
);
1189 #if defined(__WXMSW__) && !defined(NO_GUI)
1195 wxConnectionBase
*Tex2RTFServer::OnAcceptConnection(const wxString
& topic
)
1197 if (topic
== _T("TEX2RTF"))
1200 ipc_buffer
= new wxChar
[1000];
1202 return new Tex2RTFConnection(ipc_buffer
, 4000);
1212 Tex2RTFConnection::Tex2RTFConnection(wxChar
*buf
, int size
):wxDDEConnection(buf
, size
)
1216 Tex2RTFConnection::~Tex2RTFConnection(void)
1220 bool SplitCommand(wxChar
*data
, wxChar
*firstArg
, wxChar
*secondArg
)
1226 // Find first argument (command name)
1229 if (data
[i
] == ' ' || data
[i
] == 0)
1233 firstArg
[i
] = data
[i
];
1240 // Find second argument
1243 while (data
[i
] != 0)
1245 secondArg
[j
] = data
[i
];
1254 bool Tex2RTFConnection::OnExecute(const wxString
& WXUNUSED(topic
), wxChar
*data
, int WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1256 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1258 wxChar firstArg
[50];
1259 wxChar secondArg
[300];
1260 if (SplitCommand(data
, firstArg
, secondArg
))
1262 bool hasArg
= (wxStrlen(secondArg
) > 0);
1263 if (wxStrcmp(firstArg
, _T("INPUT")) == 0 && hasArg
)
1265 if (InputFile
) delete[] InputFile
;
1266 InputFile
= copystring(secondArg
);
1270 wxString str
= wxFileNameFromPath(InputFile
);
1271 wxSnprintf(buf
, sizeof(buf
), _T("Tex2RTF [%s]"), (const wxChar
*) str
);
1272 frame
->SetTitle(buf
);
1275 else if (wxStrcmp(firstArg
, _T("OUTPUT")) == 0 && hasArg
)
1277 if (OutputFile
) delete[] OutputFile
;
1278 OutputFile
= copystring(secondArg
);
1280 else if (wxStrcmp(firstArg
, _T("GO")) == 0)
1282 wxStrcpy(Tex2RTFLastStatus
, _T("WORKING"));
1284 wxStrcpy(Tex2RTFLastStatus
, _T("CONVERSION ERROR"));
1286 wxStrcpy(Tex2RTFLastStatus
, _T("OK"));
1288 else if (wxStrcmp(firstArg
, _T("EXIT")) == 0)
1290 if (frame
) frame
->Close();
1292 else if (wxStrcmp(firstArg
, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg
, _T("ICONIZE")) == 0)
1295 frame
->Iconize(true);
1297 else if (wxStrcmp(firstArg
, _T("SHOW")) == 0 || wxStrcmp(firstArg
, _T("RESTORE")) == 0)
1301 frame
->Iconize(false);
1307 // Try for a setting
1308 wxStrcpy(Tex2RTFLastStatus
, RegisterSetting(firstArg
, secondArg
, false));
1309 #if !defined(NO_GUI) && wxUSE_STATUSBAR
1310 if (frame
&& wxStrcmp(firstArg
, _T("conversionMode")) == 0)
1313 wxStrcpy(buf
, _T("In "));
1315 if (winHelp
&& (convertMode
== TEX_RTF
))
1316 wxStrcat(buf
, _T("WinHelp RTF"));
1317 else if (!winHelp
&& (convertMode
== TEX_RTF
))
1318 wxStrcat(buf
, _T("linear RTF"));
1319 else if (convertMode
== TEX_HTML
) wxStrcat(buf
, _T("HTML"));
1320 else if (convertMode
== TEX_XLP
) wxStrcat(buf
, _T("XLP"));
1321 wxStrcat(buf
, _T(" mode."));
1322 frame
->SetStatusText(buf
, 1);
1330 wxChar
*Tex2RTFConnection::OnRequest(const wxString
& WXUNUSED(topic
), const wxString
& WXUNUSED(item
), int *WXUNUSED(size
), wxIPCFormat
WXUNUSED(format
))
1332 return Tex2RTFLastStatus
;
1339 //void wxObject::Dump(wxSTD ostream& str)
1341 // if (GetClassInfo() && GetClassInfo()->GetClassName())
1342 // str << GetClassInfo()->GetClassName();
1344 // str << "unknown object class";