]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/tex2rtf.cpp
expose find window method
[wxWidgets.git] / utils / tex2rtf / src / tex2rtf.cpp
CommitLineData
9a29912f
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: tex2rtf.cpp
3// Purpose: Converts Latex to linear/WinHelp RTF, HTML, wxHelp.
4// Author: Julian Smart
b63b07a8
RL
5// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
6// Ron Lee
9a29912f
JS
7// Created: 7.9.93
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifdef __GNUG__
14#pragma implementation
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
ea172e69
MB
25 #ifndef NO_GUI
26 #include "wx/menu.h"
27 #include "wx/textctrl.h"
28 #include "wx/filedlg.h"
29 #include "wx/msgdlg.h"
30 #endif
9a29912f
JS
31#endif
32
33#ifndef NO_GUI
4538b3f1
GD
34#include "wx/help.h"
35#include "wx/timer.h"
9a29912f
JS
36#endif
37
9a29912f
JS
38#if wxUSE_IOSTREAMH
39#include <iostream.h>
40#include <fstream.h>
41#else
42#include <iostream>
43#include <fstream>
44#endif
9a29912f
JS
45
46#include <ctype.h>
47#include <stdlib.h>
48#include "tex2any.h"
49#include "tex2rtf.h"
50#include "rtfutils.h"
56d34922 51#include "symbols.h"
9a29912f 52
7658b9eb 53#if (defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)) && !defined(NO_GUI)
9a29912f
JS
54#include "tex2rtf.xpm"
55#endif
56
ea172e69
MB
57#if !WXWIN_COMPATIBILITY_2_4
58static inline wxChar* copystring(const wxChar* s)
59 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
60#endif
61
56d34922 62const float versionNo = TEX2RTF_VERSION_NUMBER;
9a29912f
JS
63
64TexChunk *currentMember = NULL;
b63b07a8 65bool startedSections = false;
6c155d33 66wxChar *contentsString = NULL;
b63b07a8
RL
67bool suppressNameDecoration = false;
68bool OkToClose = true;
9a29912f 69int passNumber = 1;
6a205442 70unsigned long errorCount = 0;
9a29912f
JS
71
72#ifndef NO_GUI
ffaaaacb 73
6c155d33
JS
74extern wxChar *BigBuffer;
75extern wxChar *TexFileRoot;
76extern wxChar *TexBibName; // Bibliography output file name
77extern wxChar *TexTmpBibName; // Temporary bibliography output file name
71599f0a
GT
78extern wxList ColourTable;
79extern TexChunk *TopLevel;
3924dd22
GT
80
81
71599f0a 82
ffaaaacb 83#if wxUSE_HELP
9a29912f 84wxHelpController *HelpInstance = NULL;
ffaaaacb 85#endif // wxUSE_HELP
9a29912f
JS
86
87#ifdef __WXMSW__
6c155d33
JS
88static wxChar *ipc_buffer = NULL;
89static wxChar Tex2RTFLastStatus[100];
9a29912f
JS
90Tex2RTFServer *TheTex2RTFServer = NULL;
91#endif
92#endif
93
6c155d33 94wxChar *bulletFile = NULL;
9a29912f
JS
95
96FILE *Contents = NULL; // Contents page
97FILE *Chapters = NULL; // Chapters (WinHelp RTF) or rest of file (linear RTF)
98FILE *Sections = NULL;
99FILE *Subsections = NULL;
100FILE *Subsubsections = NULL;
101FILE *Popups = NULL;
102FILE *WinHelpContentsFile = NULL;
103
6c155d33
JS
104wxChar *InputFile = NULL;
105wxChar *OutputFile = NULL;
106wxChar *MacroFile = copystring(_T("tex2rtf.ini"));
9a29912f 107
6c155d33
JS
108wxChar *FileRoot = NULL;
109wxChar *ContentsName = NULL; // Contents page from last time around
110wxChar *TmpContentsName = NULL; // Current contents page
111wxChar *TmpFrameContentsName = NULL; // Current frame contents page
112wxChar *WinHelpContentsFileName = NULL; // WinHelp .cnt file
113wxChar *RefFileName = NULL; // Reference file name
9a29912f 114
6c155d33 115wxChar *RTFCharset = copystring(_T("ansi"));
9a29912f
JS
116
117#ifdef __WXMSW__
118int BufSize = 100; // Size of buffer in K
119#else
120int BufSize = 500;
121#endif
122
123bool Go(void);
124void ShowOptions(void);
125
6c155d33 126wxChar wxTex2RTFBuffer[1500];
c4c794e1 127
aed3314d 128#ifdef NO_GUI
b63b07a8 129 IMPLEMENT_APP_CONSOLE(MyApp)
9a29912f 130#else
b63b07a8
RL
131 wxMenuBar *menuBar = NULL;
132 MyFrame *frame = NULL;
133 // DECLARE_APP(MyApp)
134 IMPLEMENT_APP(MyApp)
135#endif
9a29912f
JS
136
137// `Main program' equivalent, creating windows and returning main app frame
138bool MyApp::OnInit()
9a29912f
JS
139{
140 // Use default list of macros defined in tex2any.cc
141 DefineDefaultMacros();
6c155d33 142 AddMacroDef(ltHARDY, _T("hardy"), 0);
9a29912f 143
6c155d33
JS
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];
9a29912f 150
b63b07a8 151 ColourTable.DeleteContents(true);
71599f0a 152
9a29912f 153 int n = 1;
ffaaaacb 154
9a29912f
JS
155 // Read input/output files
156 if (argc > 1)
157 {
158 if (argv[1][0] != '-')
159 {
160 InputFile = argv[1];
161 n ++;
162
163 if (argc > 2)
164 {
165 if (argv[2][0] != '-')
166 {
167 OutputFile = argv[2];
168 n ++;
169 }
170 }
171 }
172 }
173
174#ifdef NO_GUI
175 if (!InputFile || !OutputFile)
176 {
219f4a6d 177 wxSTD cout << "Tex2RTF: input or output file is missing.\n";
9a29912f
JS
178 ShowOptions();
179 exit(1);
180 }
181#endif
b63b07a8 182
9a29912f
JS
183 if (InputFile)
184 {
185 TexPathList.EnsureFileAccessible(InputFile);
186 }
187 if (!InputFile || !OutputFile)
b63b07a8 188 isInteractive = true;
9a29912f 189
f6bcfd97
BP
190 int i;
191 for (i = n; i < argc;)
9a29912f 192 {
6c155d33 193 if (wxStrcmp(argv[i], _T("-winhelp")) == 0)
9a29912f
JS
194 {
195 i ++;
196 convertMode = TEX_RTF;
b63b07a8 197 winHelp = true;
9a29912f
JS
198 }
199#ifndef NO_GUI
6c155d33 200 else if (wxStrcmp(argv[i], _T("-interactive")) == 0)
9a29912f
JS
201 {
202 i ++;
b63b07a8 203 isInteractive = true;
9a29912f
JS
204 }
205#endif
6c155d33 206 else if (wxStrcmp(argv[i], _T("-sync")) == 0) // Don't yield
9a29912f
JS
207 {
208 i ++;
b63b07a8 209 isSync = true;
9a29912f 210 }
6c155d33 211 else if (wxStrcmp(argv[i], _T("-rtf")) == 0)
9a29912f
JS
212 {
213 i ++;
214 convertMode = TEX_RTF;
215 }
6c155d33 216 else if (wxStrcmp(argv[i], _T("-html")) == 0)
9a29912f
JS
217 {
218 i ++;
219 convertMode = TEX_HTML;
220 }
6c155d33 221 else if (wxStrcmp(argv[i], _T("-xlp")) == 0)
9a29912f
JS
222 {
223 i ++;
224 convertMode = TEX_XLP;
225 }
6c155d33 226 else if (wxStrcmp(argv[i], _T("-twice")) == 0)
9a29912f
JS
227 {
228 i ++;
b63b07a8 229 runTwice = true;
9a29912f 230 }
6c155d33 231 else if (wxStrcmp(argv[i], _T("-macros")) == 0)
9a29912f
JS
232 {
233 i ++;
234 if (i < argc)
235 {
236 MacroFile = copystring(argv[i]);
237 i ++;
238 }
239 }
6c155d33 240 else if (wxStrcmp(argv[i], _T("-bufsize")) == 0)
9a29912f
JS
241 {
242 i ++;
243 if (i < argc)
244 {
6c155d33 245 BufSize = wxAtoi(argv[i]);
9a29912f
JS
246 i ++;
247 }
248 }
6c155d33 249 else if (wxStrcmp(argv[i], _T("-charset")) == 0)
9a29912f
JS
250 {
251 i ++;
252 if (i < argc)
253 {
6c155d33 254 wxChar *s = argv[i];
9a29912f 255 i ++;
6c155d33
JS
256 if (wxStrcmp(s, _T("ansi")) == 0 || wxStrcmp(s, _T("pc")) == 0 || wxStrcmp(s, _T("mac")) == 0 ||
257 wxStrcmp(s, _T("pca")) == 0)
9a29912f
JS
258 RTFCharset = copystring(s);
259 else
260 {
6c155d33 261 OnError(_T("Incorrect argument for -charset"));
b63b07a8 262 return false;
9a29912f
JS
263 }
264 }
265 }
6c155d33 266 else if (wxStrcmp(argv[i], _T("-checkcurleybraces")) == 0)
fad535ee
GT
267 {
268 i ++;
b63b07a8 269 checkCurleyBraces = true;
fad535ee 270 }
6c155d33 271 else if (wxStrcmp(argv[i], _T("-checksyntax")) == 0)
fad535ee
GT
272 {
273 i ++;
b63b07a8 274 checkSyntax = true;
fad535ee 275 }
9a29912f
JS
276 else
277 {
63ad540d 278 wxString buf;
6c155d33
JS
279 buf.Printf(_T("Invalid switch %s.\n"), argv[i]);
280 OnError((wxChar *)buf.c_str());
9a29912f
JS
281#ifdef NO_GUI
282 ShowOptions();
283 exit(1);
284#endif
b63b07a8 285 return false;
9a29912f
JS
286 }
287 }
288
289#if defined(__WXMSW__) && !defined(NO_GUI)
290 wxDDEInitialize();
291 Tex2RTFLastStatus[0] = 0; // DDE connection return value
292 TheTex2RTFServer = new Tex2RTFServer;
6c155d33 293 TheTex2RTFServer->Create(_T("TEX2RTF"));
9a29912f
JS
294#endif
295
9a29912f
JS
296 TexInitialize(BufSize);
297 ResetContentsLevels(0);
298
299#ifndef NO_GUI
300
301 if (isInteractive)
302 {
6c155d33 303 wxChar buf[100];
9a29912f
JS
304
305 // Create the main frame window
b63b07a8 306 frame = new MyFrame(NULL, wxID_ANY, _T("Tex2RTF"), wxDefaultPosition, wxSize(400, 300));
9a29912f
JS
307 frame->CreateStatusBar(2);
308
309 // Give it an icon
310 // TODO: uncomment this when we have tex2rtf.xpm
311 frame->SetIcon(wxICON(tex2rtf));
312
313 if (InputFile)
314 {
b63b07a8 315 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), wxFileNameFromPath(InputFile));
9a29912f
JS
316 frame->SetTitle(buf);
317 }
318
319 // Make a menubar
320 wxMenu *file_menu = new wxMenu;
6c155d33
JS
321 file_menu->Append(TEX_GO, _T("&Go"), _T("Run converter"));
322 file_menu->Append(TEX_SET_INPUT, _T("Set &Input File"), _T("Set the LaTeX input file"));
323 file_menu->Append(TEX_SET_OUTPUT, _T("Set &Output File"), _T("Set the output file"));
9a29912f 324 file_menu->AppendSeparator();
6c155d33
JS
325 file_menu->Append(TEX_VIEW_LATEX, _T("View &LaTeX File"), _T("View the LaTeX input file"));
326 file_menu->Append(TEX_VIEW_OUTPUT, _T("View Output &File"), _T("View output file"));
327 file_menu->Append(TEX_SAVE_FILE, _T("&Save log file"), _T("Save displayed text into file"));
9a29912f 328 file_menu->AppendSeparator();
6c155d33 329 file_menu->Append(TEX_QUIT, _T("E&xit"), _T("Exit Tex2RTF"));
9a29912f
JS
330
331 wxMenu *macro_menu = new wxMenu;
332
6c155d33
JS
333 macro_menu->Append(TEX_LOAD_CUSTOM_MACROS, _T("&Load Custom Macros"), _T("Load custom LaTeX macro file"));
334 macro_menu->Append(TEX_VIEW_CUSTOM_MACROS, _T("View &Custom Macros"), _T("View custom LaTeX macros"));
9a29912f
JS
335
336 wxMenu *mode_menu = new wxMenu;
337
6c155d33
JS
338 mode_menu->Append(TEX_MODE_RTF, _T("Output linear &RTF"), _T("Wordprocessor-compatible RTF"));
339 mode_menu->Append(TEX_MODE_WINHELP, _T("Output &WinHelp RTF"), _T("WinHelp-compatible RTF"));
340 mode_menu->Append(TEX_MODE_HTML, _T("Output &HTML"), _T("HTML World Wide Web hypertext file"));
341 mode_menu->Append(TEX_MODE_XLP, _T("Output &XLP"), _T("wxHelp hypertext help file"));
9a29912f 342
fad535ee
GT
343 wxMenu *options_menu = new wxMenu;
344
b63b07a8
RL
345 options_menu->Append(TEX_OPTIONS_CURELY_BRACE, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true);
346 options_menu->Append(TEX_OPTIONS_SYNTAX_CHECKING, _T("Syntax checking"), _T("Syntax checking for common errors"),true);
fad535ee
GT
347
348 options_menu->Check(TEX_OPTIONS_CURELY_BRACE, checkCurleyBraces);
349 options_menu->Check(TEX_OPTIONS_SYNTAX_CHECKING, checkSyntax);
350
9a29912f
JS
351 wxMenu *help_menu = new wxMenu;
352
6c155d33
JS
353 help_menu->Append(TEX_HELP, _T("&Help"), _T("Tex2RTF Contents Page"));
354 help_menu->Append(TEX_ABOUT, _T("&About Tex2RTF"), _T("About Tex2RTF"));
9a29912f
JS
355
356 menuBar = new wxMenuBar;
6c155d33
JS
357 menuBar->Append(file_menu, _T("&File"));
358 menuBar->Append(macro_menu, _T("&Macros"));
359 menuBar->Append(mode_menu, _T("&Conversion Mode"));
360 menuBar->Append(options_menu, _T("&Options"));
361 menuBar->Append(help_menu, _T("&Help"));
9a29912f
JS
362
363 frame->SetMenuBar(menuBar);
b63b07a8 364 frame->textWindow = new wxTextCtrl(frame, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_MULTILINE);
9a29912f 365
6c155d33 366 (*frame->textWindow) << _T("Welcome to Tex2RTF.\n");
ffaaaacb 367// ShowOptions();
9a29912f 368
ffaaaacb 369#if wxUSE_HELP
9a29912f 370 HelpInstance = new wxHelpController();
6c155d33 371 HelpInstance->Initialize(_T("tex2rtf"));
ffaaaacb 372#endif // wxUSE_HELP
9a29912f
JS
373
374 /*
375 * Read macro/initialisation file
376 *
377 */
ffaaaacb 378
6c155d33
JS
379 wxString path = TexPathList.FindValidPath(MacroFile);
380 if (path != _T(""))
381 ReadCustomMacros((wxChar *)path.c_str());
9a29912f 382
6c155d33 383 wxStrcpy(buf, _T("In "));
9a29912f
JS
384
385 if (winHelp && (convertMode == TEX_RTF))
6c155d33 386 wxStrcat(buf, _T("WinHelp RTF"));
9a29912f 387 else if (!winHelp && (convertMode == TEX_RTF))
6c155d33
JS
388 wxStrcat(buf, _T("linear RTF"));
389 else if (convertMode == TEX_HTML) wxStrcat(buf, _T("HTML"));
390 else if (convertMode == TEX_XLP) wxStrcat(buf, _T("XLP"));
391 wxStrcat(buf, _T(" mode."));
9a29912f 392 frame->SetStatusText(buf, 1);
ffaaaacb 393
b63b07a8
RL
394 frame->Show(true);
395 return true;
9a29912f
JS
396 }
397 else
398#endif // NO_GUI
399 {
400 /*
401 * Read macro/initialisation file
402 *
403 */
ffaaaacb 404
6c155d33
JS
405 wxString path = TexPathList.FindValidPath(MacroFile);
406 if (path != _T(""))
407 ReadCustomMacros((wxChar*)path.c_str());
9a29912f
JS
408
409 Go();
3924dd22
GT
410 if (runTwice)
411 {
412 Go();
413 }
9a29912f 414#ifdef NO_GUI
b63b07a8 415 return true;
9a29912f 416#else
00827094 417 OnExit(); // Do cleanup since OnExit won't be called now
b63b07a8 418 return false;
9a29912f
JS
419#endif
420 }
9a29912f
JS
421}
422
c4c794e1 423#ifndef NO_GUI
9a29912f
JS
424int MyApp::OnExit()
425{
ddc4f3b5 426 wxNode *node = CustomMacroList.GetFirst();
9a29912f
JS
427 while (node)
428 {
ddc4f3b5 429 CustomMacro *macro = (CustomMacro *)node->GetData();
9a29912f
JS
430 delete macro;
431 delete node;
ddc4f3b5 432 node = CustomMacroList.GetFirst();
9a29912f
JS
433 }
434 MacroDefs.BeginFind();
435 node = MacroDefs.Next();
436 while (node)
437 {
ddc4f3b5 438 TexMacroDef* def = (TexMacroDef*) node->GetData();
9a29912f
JS
439 delete def;
440 node = MacroDefs.Next();
441 }
442 MacroDefs.Clear();
443#ifdef __WXMSW__
444 delete TheTex2RTFServer;
23016fdd 445 wxDDECleanUp();
9a29912f 446#endif
ffaaaacb
VZ
447
448#if wxUSE_HELP
9a29912f 449 delete HelpInstance;
ffaaaacb 450#endif // wxUSE_HELP
9a29912f 451
71599f0a
GT
452 if (BigBuffer)
453 {
454 delete BigBuffer;
455 BigBuffer = NULL;
456 }
457 if (currentArgData)
458 {
459 delete currentArgData;
460 currentArgData = NULL;
461 }
462 if (TexFileRoot)
463 {
464 delete TexFileRoot;
465 TexFileRoot = NULL;
466 }
467 if (TexBibName)
468 {
469 delete TexBibName;
470 TexBibName = NULL;
471 }
472 if (TexTmpBibName)
473 {
474 delete TexTmpBibName;
475 TexTmpBibName = NULL;
476 }
477 if (FileRoot)
478 {
479 delete FileRoot;
480 FileRoot = NULL;
481 }
482 if (ContentsName)
483 {
484 delete ContentsName;
485 ContentsName = NULL;
486 }
487 if (TmpContentsName)
488 {
489 delete TmpContentsName;
490 TmpContentsName = NULL;
491 }
492 if (TmpFrameContentsName)
493 {
494 delete TmpFrameContentsName;
495 TmpFrameContentsName = NULL;
496 }
497 if (WinHelpContentsFileName)
498 {
499 delete WinHelpContentsFileName;
500 WinHelpContentsFileName = NULL;
501 }
ad781c23 502 if (RefFileName)
71599f0a 503 {
ad781c23
GD
504 delete RefFileName;
505 RefFileName = NULL;
71599f0a
GT
506 }
507 if (TopLevel)
508 {
509 delete TopLevel;
510 TopLevel = NULL;
511 }
512 if (MacroFile)
513 {
514 delete MacroFile;
515 MacroFile = NULL;
516 }
517 if (RTFCharset)
518 {
519 delete RTFCharset;
520 RTFCharset = NULL;
521 }
522
3924dd22
GT
523 delete [] PageStyle;
524 delete [] BibliographyStyleString;
525 delete [] DocumentStyleString;
526 delete [] bitmapMethod;
527 delete [] backgroundColourString;
528 delete [] ContentsNameString;
529 delete [] AbstractNameString;
530 delete [] GlossaryNameString;
531 delete [] ReferencesNameString;
532 delete [] FiguresNameString;
533 delete [] TablesNameString;
534 delete [] FigureNameString;
535 delete [] TableNameString;
536 delete [] IndexNameString;
537 delete [] ChapterNameString;
538 delete [] SectionNameString;
539 delete [] SubsectionNameString;
540 delete [] SubsubsectionNameString;
541 delete [] UpNameString;
542 if (winHelpTitle)
543 delete[] winHelpTitle;
544
9a29912f
JS
545 // TODO: this simulates zero-memory leaks!
546 // Otherwise there are just too many...
12a44087 547#ifndef __WXGTK__
fad535ee 548#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
9a29912f 549 wxDebugContext::SetCheckpoint();
fad535ee 550#endif
12a44087 551#endif
9a29912f
JS
552
553 return 0;
554}
c4c794e1 555#endif
9a29912f
JS
556void ShowOptions(void)
557{
6c155d33 558 wxChar buf[100];
b63b07a8 559 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF version %.2f"), versionNo);
9a29912f 560 OnInform(buf);
6c155d33
JS
561 OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
562 OnInform(_T("where valid switches are"));
610c6ded 563#ifndef NO_GUI
6c155d33 564 OnInform(_T(" -interactive"));
610c6ded 565#endif
6c155d33
JS
566 OnInform(_T(" -bufsize <size in K>"));
567 OnInform(_T(" -charset <pc | pca | ansi | mac> (default ansi)"));
568 OnInform(_T(" -twice"));
569 OnInform(_T(" -sync"));
570 OnInform(_T(" -checkcurleybraces"));
571 OnInform(_T(" -checksyntax"));
572 OnInform(_T(" -macros <filename>"));
573 OnInform(_T(" -winhelp"));
574 OnInform(_T(" -rtf"));
575 OnInform(_T(" -html"));
576 OnInform(_T(" -xlp\n"));
9a29912f
JS
577}
578
579#ifndef NO_GUI
580
581BEGIN_EVENT_TABLE(MyFrame, wxFrame)
582 EVT_CLOSE(MyFrame::OnCloseWindow)
583 EVT_MENU(TEX_QUIT, MyFrame::OnExit)
584 EVT_MENU(TEX_GO, MyFrame::OnGo)
585 EVT_MENU(TEX_SET_INPUT, MyFrame::OnSetInput)
586 EVT_MENU(TEX_SET_OUTPUT, MyFrame::OnSetOutput)
587 EVT_MENU(TEX_SAVE_FILE, MyFrame::OnSaveFile)
588 EVT_MENU(TEX_VIEW_LATEX, MyFrame::OnViewLatex)
589 EVT_MENU(TEX_VIEW_OUTPUT, MyFrame::OnViewOutput)
590 EVT_MENU(TEX_VIEW_CUSTOM_MACROS, MyFrame::OnShowMacros)
591 EVT_MENU(TEX_LOAD_CUSTOM_MACROS, MyFrame::OnLoadMacros)
592 EVT_MENU(TEX_MODE_RTF, MyFrame::OnModeRTF)
593 EVT_MENU(TEX_MODE_WINHELP, MyFrame::OnModeWinHelp)
594 EVT_MENU(TEX_MODE_HTML, MyFrame::OnModeHTML)
595 EVT_MENU(TEX_MODE_XLP, MyFrame::OnModeXLP)
fad535ee
GT
596 EVT_MENU(TEX_OPTIONS_CURELY_BRACE, MyFrame::OnOptionsCurleyBrace)
597 EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING, MyFrame::OnOptionsSyntaxChecking)
9a29912f
JS
598 EVT_MENU(TEX_HELP, MyFrame::OnHelp)
599 EVT_MENU(TEX_ABOUT, MyFrame::OnAbout)
600END_EVENT_TABLE()
601
602// My frame constructor
603MyFrame::MyFrame(wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size):
604 wxFrame(frame, id, title, pos, size)
605{}
606
6c155d33 607void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
9a29912f
JS
608{
609 if (!stopRunning && !OkToClose)
610 {
b63b07a8
RL
611 stopRunning = true;
612 runTwice = false;
9a29912f
JS
613 return;
614 }
615 else if (OkToClose)
616 {
9a29912f
JS
617 this->Destroy();
618 }
619}
620
6c155d33 621void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
9a29912f 622{
71599f0a
GT
623 Close();
624// this->Destroy();
9a29912f
JS
625}
626
6c155d33 627void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event))
9a29912f 628{
f6bcfd97 629 passNumber = 1;
63ad540d 630 errorCount = 0;
b63b07a8
RL
631 menuBar->EnableTop(0, false);
632 menuBar->EnableTop(1, false);
633 menuBar->EnableTop(2, false);
634 menuBar->EnableTop(3, false);
9a29912f 635 textWindow->Clear();
b63b07a8 636 Tex2RTFYield(true);
9a29912f
JS
637 Go();
638
04b9c5bb
GT
639 if (stopRunning)
640 {
6c155d33 641 SetStatusText(_T("Build aborted!"));
04b9c5bb 642 wxString errBuf;
6c155d33
JS
643 errBuf.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount);
644 OnInform((wxChar *)errBuf.c_str());
04b9c5bb
GT
645 }
646
647
648 if (runTwice && !stopRunning)
9a29912f 649 {
b63b07a8 650 Tex2RTFYield(true);
9a29912f
JS
651 Go();
652 }
b63b07a8
RL
653 menuBar->EnableTop(0, true);
654 menuBar->EnableTop(1, true);
655 menuBar->EnableTop(2, true);
656 menuBar->EnableTop(3, true);
9a29912f
JS
657}
658
6c155d33 659void MyFrame::OnSetInput(wxCommandEvent& WXUNUSED(event))
9a29912f 660{
b63b07a8 661 ChooseInputFile(true);
9a29912f
JS
662}
663
6c155d33 664void MyFrame::OnSetOutput(wxCommandEvent& WXUNUSED(event))
9a29912f 665{
b63b07a8 666 ChooseOutputFile(true);
9a29912f
JS
667}
668
6c155d33 669void MyFrame::OnSaveFile(wxCommandEvent& WXUNUSED(event))
9a29912f 670{
6c155d33
JS
671 wxString s = wxFileSelector(_T("Save text to file"), _T(""), _T(""), _T("txt"), _T("*.txt"));
672 if (s != _T(""))
9a29912f
JS
673 {
674 textWindow->SaveFile(s);
6c155d33 675 wxChar buf[350];
b63b07a8 676 wxSnprintf(buf, sizeof(buf), _T("Saved text to %s"), (const wxChar*) s.c_str());
9a29912f
JS
677 frame->SetStatusText(buf, 0);
678 }
679}
680
6c155d33 681void MyFrame::OnViewOutput(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
682{
683 ChooseOutputFile();
684 if (OutputFile && wxFileExists(OutputFile))
685 {
686 textWindow->LoadFile(OutputFile);
6c155d33 687 wxChar buf[300];
9a29912f 688 wxString str(wxFileNameFromPath(OutputFile));
b63b07a8 689 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str());
9a29912f
JS
690 frame->SetTitle(buf);
691 }
692}
693
6c155d33 694void MyFrame::OnViewLatex(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
695{
696 ChooseInputFile();
697 if (InputFile && wxFileExists(InputFile))
698 {
699 textWindow->LoadFile(InputFile);
6c155d33 700 wxChar buf[300];
9a29912f 701 wxString str(wxFileNameFromPath(OutputFile));
b63b07a8 702 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str());
9a29912f
JS
703 frame->SetTitle(buf);
704 }
705}
706
6c155d33 707void MyFrame::OnLoadMacros(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
708{
709 textWindow->Clear();
6c155d33
JS
710 wxString s = wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile), wxFileNameFromPath(MacroFile), _T("ini"), _T("*.ini"));
711 if (s != _T("") && wxFileExists(s))
9a29912f
JS
712 {
713 MacroFile = copystring(s);
6c155d33 714 ReadCustomMacros((wxChar *)s.c_str());
9a29912f
JS
715 ShowCustomMacros();
716 }
717}
718
6c155d33 719void MyFrame::OnShowMacros(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
720{
721 textWindow->Clear();
b63b07a8 722 Tex2RTFYield(true);
9a29912f
JS
723 ShowCustomMacros();
724}
725
6c155d33 726void MyFrame::OnModeRTF(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
727{
728 convertMode = TEX_RTF;
b63b07a8 729 winHelp = false;
9a29912f
JS
730 InputFile = NULL;
731 OutputFile = NULL;
6c155d33 732 SetStatusText(_T("In linear RTF mode."), 1);
9a29912f
JS
733}
734
6c155d33 735void MyFrame::OnModeWinHelp(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
736{
737 convertMode = TEX_RTF;
b63b07a8 738 winHelp = true;
9a29912f
JS
739 InputFile = NULL;
740 OutputFile = NULL;
6c155d33 741 SetStatusText(_T("In WinHelp RTF mode."), 1);
9a29912f
JS
742}
743
6c155d33 744void MyFrame::OnModeHTML(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
745{
746 convertMode = TEX_HTML;
b63b07a8 747 winHelp = false;
9a29912f
JS
748 InputFile = NULL;
749 OutputFile = NULL;
6c155d33 750 SetStatusText(_T("In HTML mode."), 1);
9a29912f
JS
751}
752
6c155d33 753void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event))
9a29912f
JS
754{
755 convertMode = TEX_XLP;
756 InputFile = NULL;
757 OutputFile = NULL;
6c155d33 758 SetStatusText(_T("In XLP mode."), 1);
9a29912f
JS
759}
760
6c155d33 761void MyFrame::OnOptionsCurleyBrace(wxCommandEvent& WXUNUSED(event))
fad535ee
GT
762{
763 checkCurleyBraces = !checkCurleyBraces;
764 if (checkCurleyBraces)
765 {
6c155d33 766 SetStatusText(_T("Checking curley braces: YES"), 1);
fad535ee
GT
767 }
768 else
769 {
6c155d33 770 SetStatusText(_T("Checking curley braces: NO"), 1);
fad535ee
GT
771 }
772}
773
774
6c155d33 775void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& WXUNUSED(event))
fad535ee
GT
776{
777 checkSyntax = !checkSyntax;
778 if (checkSyntax)
779 {
6c155d33 780 SetStatusText(_T("Checking syntax: YES"), 1);
fad535ee
GT
781 }
782 else
783 {
6c155d33 784 SetStatusText(_T("Checking syntax: NO"), 1);
fad535ee
GT
785 }
786}
787
788
6c155d33 789void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
9a29912f 790{
ffaaaacb 791#if wxUSE_HELP
9a29912f
JS
792 HelpInstance->LoadFile();
793 HelpInstance->DisplayContents();
ffaaaacb 794#endif // wxUSE_HELP
9a29912f
JS
795}
796
6c155d33 797void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
9a29912f 798{
6c155d33 799 wxChar buf[300];
9a29912f 800#ifdef __WIN32__
6c155d33 801 wxChar *platform = _T(" (32-bit)");
9a29912f
JS
802#else
803#ifdef __WXMSW__
6c155d33 804 wxChar *platform = _T(" (16-bit)");
9a29912f 805#else
6c155d33 806 wxChar *platform = _T("");
9a29912f
JS
807#endif
808#endif
b63b07a8 809 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);
6c155d33 810 wxMessageBox(buf, _T("About Tex2RTF"));
9a29912f
JS
811}
812
813void ChooseInputFile(bool force)
814{
815 if (force || !InputFile)
816 {
6c155d33
JS
817 wxString s = wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile), wxFileNameFromPath(InputFile), _T("tex"), _T("*.tex"));
818 if (s != _T(""))
9a29912f
JS
819 {
820 // Different file, so clear index entries.
821 ClearKeyWordTable();
822 ResetContentsLevels(0);
823 passNumber = 1;
63ad540d
GT
824 errorCount = 0;
825
9a29912f
JS
826 InputFile = copystring(s);
827 wxString str = wxFileNameFromPath(InputFile);
63ad540d 828 wxString buf;
6c155d33
JS
829 buf.Printf(_T("Tex2RTF [%s]"), str.c_str());
830 frame->SetTitle((wxChar *)buf.c_str());
9a29912f
JS
831 OutputFile = NULL;
832 }
833 }
834}
835
836void ChooseOutputFile(bool force)
837{
6c155d33
JS
838 wxChar extensionBuf[10];
839 wxChar wildBuf[10];
840 wxStrcpy(wildBuf, _T("*."));
aed0ed3c 841 wxString path;
9a29912f
JS
842 if (OutputFile)
843 path = wxPathOnly(OutputFile);
844 else if (InputFile)
845 path = wxPathOnly(InputFile);
ffaaaacb 846
9a29912f
JS
847 switch (convertMode)
848 {
849 case TEX_RTF:
850 {
6c155d33
JS
851 wxStrcpy(extensionBuf, _T("rtf"));
852 wxStrcat(wildBuf, _T("rtf"));
9a29912f
JS
853 break;
854 }
855 case TEX_XLP:
856 {
6c155d33
JS
857 wxStrcpy(extensionBuf, _T("xlp"));
858 wxStrcat(wildBuf, _T("xlp"));
9a29912f
JS
859 break;
860 }
861 case TEX_HTML:
862 {
6c155d33
JS
863 wxStrcpy(extensionBuf, _T("html"));
864 wxStrcat(wildBuf, _T("html"));
9a29912f
JS
865 break;
866 }
867 }
868 if (force || !OutputFile)
869 {
6c155d33 870 wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile),
9a29912f 871 extensionBuf, wildBuf);
6c155d33 872 if (s != _T(""))
9a29912f
JS
873 OutputFile = copystring(s);
874 }
875}
876#endif
877
878bool Go(void)
879{
880#ifndef NO_GUI
881 ChooseInputFile();
882 ChooseOutputFile();
883#endif
884
04b9c5bb 885 if (!InputFile || !OutputFile || stopRunning)
b63b07a8 886 return false;
9a29912f
JS
887
888#ifndef NO_GUI
889 if (isInteractive)
890 {
6c155d33 891 wxChar buf[300];
9a29912f
JS
892 wxString str = wxFileNameFromPath(InputFile);
893
b63b07a8 894 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str);
9a29912f
JS
895 frame->SetTitle(buf);
896 }
897
898 wxStartTimer();
899#endif
900
901 // Find extension-less filename
6c155d33 902 wxStrcpy(FileRoot, OutputFile);
9a29912f
JS
903 StripExtension(FileRoot);
904
905 if (truncateFilenames && convertMode == TEX_HTML)
906 {
907 // Truncate to five characters. This ensures that
908 // we can generate DOS filenames such as thing999. But 1000 files
909 // may not be enough, of course...
6c155d33 910 wxChar* sName = wxFileNameFromPath( FileRoot); // this Julian's method is non-destructive reference
9a29912f
JS
911
912 if(sName)
6c155d33 913 if(wxStrlen( sName) > 5)
9a29912f
JS
914 sName[5] = '\0'; // that should do!
915 }
ffaaaacb 916
b63b07a8
RL
917 wxSnprintf(ContentsName, 300, _T("%s.con"), FileRoot);
918 wxSnprintf(TmpContentsName, 300, _T("%s.cn1"), FileRoot);
919 wxSnprintf(TmpFrameContentsName, 300, _T("%s.frc"), FileRoot);
920 wxSnprintf(WinHelpContentsFileName, 300, _T("%s.cnt"), FileRoot);
921 wxSnprintf(RefFileName, 300, _T("%s.ref"), FileRoot);
9a29912f
JS
922
923 TexPathList.EnsureFileAccessible(InputFile);
924 if (!bulletFile)
925 {
6c155d33
JS
926 wxString s = TexPathList.FindValidPath(_T("bullet.bmp"));
927 if (s != _T(""))
9a29912f
JS
928 {
929 wxString str = wxFileNameFromPath(s);
930 bulletFile = copystring(str);
931 }
932 }
933
ad781c23
GD
934 if (wxFileExists(RefFileName))
935 ReadTexReferences(RefFileName);
ffaaaacb 936
b63b07a8 937 bool success = false;
9a29912f
JS
938
939 if (InputFile && OutputFile)
940 {
2b5f62a0 941 if (!wxFileExists(InputFile))
9a29912f 942 {
6c155d33 943 OnError(_T("Cannot open input file!"));
9a29912f 944 TexCleanUp();
b63b07a8 945 return false;
9a29912f
JS
946 }
947#ifndef NO_GUI
948 if (isInteractive)
949 {
63ad540d 950 wxString buf;
6c155d33
JS
951 buf.Printf(_T("Working, pass %d...Click CLOSE to abort"), passNumber);
952 frame->SetStatusText((wxChar *)buf.c_str());
9a29912f
JS
953 }
954#endif
b63b07a8 955 OkToClose = false;
6c155d33 956 OnInform(_T("Reading LaTeX file..."));
9a29912f
JS
957 TexLoadFile(InputFile);
958
04b9c5bb 959 if (stopRunning)
e4941e3d 960 {
b63b07a8
RL
961 OkToClose = true;
962 return false;
e4941e3d 963 }
04b9c5bb 964
9a29912f
JS
965 switch (convertMode)
966 {
967 case TEX_RTF:
968 {
969 success = RTFGo();
970 break;
971 }
972 case TEX_XLP:
973 {
974 success = XLPGo();
975 break;
976 }
977 case TEX_HTML:
978 {
979 success = HTMLGo();
980 break;
981 }
982 }
983 }
984 if (stopRunning)
985 {
6c155d33 986 OnInform(_T("*** Aborted by user."));
b63b07a8
RL
987 success = false;
988 stopRunning = false;
989 OkToClose = true;
9a29912f
JS
990 }
991
992 if (success)
993 {
ad781c23 994 WriteTexReferences(RefFileName);
9a29912f 995 TexCleanUp();
b63b07a8 996 startedSections = false;
9a29912f 997
63ad540d 998 wxString buf;
9a29912f
JS
999#ifndef NO_GUI
1000 long tim = wxGetElapsedTime();
6c155d33
JS
1001 buf.Printf(_T("Finished PASS #%d in %ld seconds.\n"), passNumber, (long)(tim/1000.0));
1002 OnInform((wxChar *)buf.c_str());
63ad540d
GT
1003
1004 if (errorCount)
1005 {
6c155d33
JS
1006 buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
1007 OnInform((wxChar *)buf.c_str());
63ad540d
GT
1008 }
1009
9a29912f
JS
1010 if (isInteractive)
1011 {
6c155d33
JS
1012 buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
1013 frame->SetStatusText((wxChar *)buf.c_str());
9a29912f
JS
1014 }
1015#else
6c155d33
JS
1016 buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass"));
1017 OnInform((wxChar *)buf.c_str());
63ad540d
GT
1018 if (errorCount)
1019 {
6c155d33
JS
1020 buf.Printf(_T("Errors encountered during this pass: %lu\n"), errorCount);
1021 OnInform((wxChar *)buf.c_str());
63ad540d 1022 }
9a29912f
JS
1023#endif
1024 passNumber ++;
63ad540d 1025 errorCount = 0;
b63b07a8
RL
1026 OkToClose = true;
1027 return true;
9a29912f
JS
1028 }
1029
1030 TexCleanUp();
b63b07a8 1031 startedSections = false;
9a29912f 1032
8efab359 1033#ifndef NO_GUI
6c155d33 1034 frame->SetStatusText(_T("Aborted by user."));
8efab359 1035#endif // GUI
fad535ee 1036
6c155d33 1037 OnInform(_T("Sorry, unsuccessful."));
b63b07a8
RL
1038 OkToClose = true;
1039 return false;
9a29912f
JS
1040}
1041
6c155d33 1042void OnError(const wxChar *msg)
9a29912f 1043{
b63b07a8 1044 wxString msg_string = msg;
63ad540d
GT
1045 errorCount++;
1046
9a29912f 1047#ifdef NO_GUI
b63b07a8 1048 wxSTD cerr << "Error: " << msg_string.mb_str() << "\n";
219f4a6d 1049 wxSTD cerr.flush();
9a29912f 1050#else
3f8e5072 1051 if (isInteractive && frame)
6c155d33 1052 (*frame->textWindow) << _T("Error: ") << msg << _T("\n");
9a29912f
JS
1053 else
1054#ifdef __UNIX__
1055 {
b63b07a8 1056 wxSTD cerr << "Error: " << msg_string.mb_str() << "\n";
219f4a6d 1057 wxSTD cerr.flush();
9a29912f
JS
1058 }
1059#endif
63ad540d 1060
9a29912f 1061#ifdef __WXMSW__
11611a62 1062 wxLogError(msg);
9a29912f 1063#endif
b63b07a8 1064 Tex2RTFYield(true);
9a29912f
JS
1065#endif // NO_GUI
1066}
1067
6c155d33 1068void OnInform(const wxChar *msg)
9a29912f 1069{
b63b07a8 1070 wxString msg_string = msg;
9a29912f 1071#ifdef NO_GUI
b63b07a8 1072 wxSTD cout << msg_string.mb_str() << "\n";
219f4a6d 1073 wxSTD cout.flush();
9a29912f 1074#else
3f8e5072 1075 if (isInteractive && frame)
6c155d33 1076 (*frame->textWindow) << msg << _T("\n");
fad535ee
GT
1077/* This whole block of code is just wrong I think. It would behave
1078 completely wrong under anything other than MSW due to the ELSE
1079 with no statement, and the cout calls would fail under MSW, as
1080 the code in this block is compiled if !NO_GUI This code has been
1081 here since v1.1 of this file too. - gt
9a29912f
JS
1082 else
1083#ifdef __WXMSW__
1084 {
b63b07a8 1085 wxSTD cout << msg_string.mb_str() << "\n";
219f4a6d 1086 wxSTD cout.flush();
9a29912f
JS
1087 }
1088#endif
1089#ifdef __WXMSW__
1090 {}
1091#endif
fad535ee 1092*/
9a29912f
JS
1093 if (isInteractive)
1094 {
b63b07a8 1095 Tex2RTFYield(true);
9a29912f
JS
1096 }
1097#endif // NO_GUI
1098}
1099
1100void OnMacro(int macroId, int no_args, bool start)
1101{
1102 switch (convertMode)
1103 {
1104 case TEX_RTF:
1105 {
1106 RTFOnMacro(macroId, no_args, start);
1107 break;
1108 }
1109 case TEX_XLP:
1110 {
1111 XLPOnMacro(macroId, no_args, start);
1112 break;
1113 }
1114 case TEX_HTML:
1115 {
1116 HTMLOnMacro(macroId, no_args, start);
1117 break;
1118 }
1119 }
1120}
1121
1122bool OnArgument(int macroId, int arg_no, bool start)
1123{
1124 switch (convertMode)
1125 {
1126 case TEX_RTF:
1127 {
1128 return RTFOnArgument(macroId, arg_no, start);
6c155d33 1129 // break;
9a29912f
JS
1130 }
1131 case TEX_XLP:
1132 {
1133 return XLPOnArgument(macroId, arg_no, start);
6c155d33 1134 // break;
9a29912f
JS
1135 }
1136 case TEX_HTML:
1137 {
1138 return HTMLOnArgument(macroId, arg_no, start);
6c155d33 1139 // break;
9a29912f
JS
1140 }
1141 }
b63b07a8 1142 return true;
9a29912f
JS
1143}
1144
1145/*
1146 * DDE Stuff
1147 */
1148#if defined(__WXMSW__) && !defined(NO_GUI)
1149
1150/*
1151 * Server
1152 */
1153
1154wxConnectionBase *Tex2RTFServer::OnAcceptConnection(const wxString& topic)
1155{
6c155d33 1156 if (topic == _T("TEX2RTF"))
9a29912f
JS
1157 {
1158 if (!ipc_buffer)
6c155d33 1159 ipc_buffer = new wxChar[1000];
ffaaaacb 1160
9a29912f
JS
1161 return new Tex2RTFConnection(ipc_buffer, 4000);
1162 }
1163 else
1164 return NULL;
1165}
1166
1167 /*
1168 * Connection
1169 */
ffaaaacb 1170
6c155d33 1171Tex2RTFConnection::Tex2RTFConnection(wxChar *buf, int size):wxDDEConnection(buf, size)
9a29912f
JS
1172{
1173}
1174
1175Tex2RTFConnection::~Tex2RTFConnection(void)
1176{
1177}
1178
6c155d33 1179bool SplitCommand(wxChar *data, wxChar *firstArg, wxChar *secondArg)
9a29912f
JS
1180{
1181 firstArg[0] = 0;
1182 secondArg[0] = 0;
1183 int i = 0;
b63b07a8 1184 bool stop = false;
9a29912f
JS
1185 // Find first argument (command name)
1186 while (!stop)
1187 {
1188 if (data[i] == ' ' || data[i] == 0)
b63b07a8 1189 stop = true;
9a29912f
JS
1190 else
1191 {
1192 firstArg[i] = data[i];
1193 i ++;
1194 }
1195 }
1196 firstArg[i] = 0;
1197 if (data[i] == ' ')
1198 {
1199 // Find second argument
1200 i ++;
1201 int j = 0;
1202 while (data[i] != 0)
1203 {
1204 secondArg[j] = data[i];
1205 i ++;
1206 j ++;
1207 }
1208 secondArg[j] = 0;
1209 }
b63b07a8 1210 return true;
9a29912f
JS
1211}
1212
6c155d33 1213bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, int WXUNUSED(size), wxIPCFormat WXUNUSED(format))
9a29912f 1214{
6c155d33 1215 wxStrcpy(Tex2RTFLastStatus, _T("OK"));
9a29912f 1216
6c155d33
JS
1217 wxChar firstArg[50];
1218 wxChar secondArg[300];
9a29912f
JS
1219 if (SplitCommand(data, firstArg, secondArg))
1220 {
6c155d33
JS
1221 bool hasArg = (wxStrlen(secondArg) > 0);
1222 if (wxStrcmp(firstArg, _T("INPUT")) == 0 && hasArg)
9a29912f
JS
1223 {
1224 if (InputFile) delete[] InputFile;
1225 InputFile = copystring(secondArg);
1226 if (frame)
1227 {
6c155d33 1228 wxChar buf[100];
9a29912f 1229 wxString str = wxFileNameFromPath(InputFile);
b63b07a8 1230 wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str);
9a29912f
JS
1231 frame->SetTitle(buf);
1232 }
1233 }
6c155d33 1234 else if (wxStrcmp(firstArg, _T("OUTPUT")) == 0 && hasArg)
9a29912f
JS
1235 {
1236 if (OutputFile) delete[] OutputFile;
1237 OutputFile = copystring(secondArg);
1238 }
6c155d33 1239 else if (wxStrcmp(firstArg, _T("GO")) == 0)
9a29912f 1240 {
6c155d33 1241 wxStrcpy(Tex2RTFLastStatus, _T("WORKING"));
9a29912f 1242 if (!Go())
6c155d33 1243 wxStrcpy(Tex2RTFLastStatus, _T("CONVERSION ERROR"));
9a29912f 1244 else
6c155d33 1245 wxStrcpy(Tex2RTFLastStatus, _T("OK"));
9a29912f 1246 }
6c155d33 1247 else if (wxStrcmp(firstArg, _T("EXIT")) == 0)
9a29912f 1248 {
e3065973 1249 if (frame) frame->Close();
9a29912f 1250 }
6c155d33 1251 else if (wxStrcmp(firstArg, _T("MINIMIZE")) == 0 || wxStrcmp(firstArg, _T("ICONIZE")) == 0)
9a29912f
JS
1252 {
1253 if (frame)
b63b07a8 1254 frame->Iconize(true);
9a29912f 1255 }
6c155d33 1256 else if (wxStrcmp(firstArg, _T("SHOW")) == 0 || wxStrcmp(firstArg, _T("RESTORE")) == 0)
9a29912f
JS
1257 {
1258 if (frame)
1259 {
b63b07a8
RL
1260 frame->Iconize(false);
1261 frame->Show(true);
9a29912f
JS
1262 }
1263 }
1264 else
1265 {
1266 // Try for a setting
b63b07a8 1267 wxStrcpy(Tex2RTFLastStatus, RegisterSetting(firstArg, secondArg, false));
9a29912f 1268#ifndef NO_GUI
6c155d33 1269 if (frame && wxStrcmp(firstArg, _T("conversionMode")) == 0)
9a29912f 1270 {
6c155d33
JS
1271 wxChar buf[100];
1272 wxStrcpy(buf, _T("In "));
9a29912f
JS
1273
1274 if (winHelp && (convertMode == TEX_RTF))
6c155d33 1275 wxStrcat(buf, _T("WinHelp RTF"));
9a29912f 1276 else if (!winHelp && (convertMode == TEX_RTF))
6c155d33
JS
1277 wxStrcat(buf, _T("linear RTF"));
1278 else if (convertMode == TEX_HTML) wxStrcat(buf, _T("HTML"));
1279 else if (convertMode == TEX_XLP) wxStrcat(buf, _T("XLP"));
1280 wxStrcat(buf, _T(" mode."));
9a29912f
JS
1281 frame->SetStatusText(buf, 1);
1282 }
1283#endif
1284 }
1285 }
b63b07a8 1286 return true;
9a29912f
JS
1287}
1288
6c155d33 1289wxChar *Tex2RTFConnection::OnRequest(const wxString& WXUNUSED(topic), const wxString& WXUNUSED(item), int *WXUNUSED(size), wxIPCFormat WXUNUSED(format))
9a29912f
JS
1290{
1291 return Tex2RTFLastStatus;
1292}
1293
1294#endif
1295
c4c794e1 1296#ifndef NO_GUI
17867d61 1297#ifndef __WXGTK__
dd107c50 1298//void wxObject::Dump(wxSTD ostream& str)
7cf496bf
RS
1299//{
1300// if (GetClassInfo() && GetClassInfo()->GetClassName())
1301// str << GetClassInfo()->GetClassName();
1302// else
1303// str << "unknown object class";
1304//}
1305#endif
17867d61 1306#endif