121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
+
+
-
-
+
+
-
-
+
-
|
end;
var
MainForm: TMainForm;
BuildWindow: TBuildStatusWindow;
hasGroff: boolean;
GroffOutputVersion: string;
{$IFDEF WINDOWS}
hasGhostscript: boolean;
ps2pdfOutput: string;
{$ENDIF}
implementation
{$R *.lfm}
procedure TDetectGroffThread.UpdateUI;
begin
// groff:
MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
if pos('GNU', GroffOutputVersion) = 0 then
begin
ShowMessage('groffstudio thinks that your installed version of troff is not GNU troff.'
+ LineEnding + 'If this is correct, you are advised to fix this before continuing.'
+ LineEnding +
'If it is an error, please tell me so I can improve this detection.');
hasGroff := True;
hasGroff := False;
MainForm.edtGroffInstalledVersion.Text := 'n/a';
MainForm.lblTroffCommandNotFound.Visible := True;
end
else
hasGroff := True;
// ps2pdf (Windows-only):
{$IFDEF WINDOWS}
if pos('ps2pdf', ps2pdfOutput) = 0 then
begin
ShowMessage('On Windows, for creating PDF files, you need Ghostscript installed.'
+ LineEnding + 'Sadly, groffstudio could not find ps2pdf.exe in your %PATH%, so '
+ 'writing PDF files will not be supported.');
MainForm.edtGroffInstalledVersion.Text := 'n/a';
hasGroff := False;
MainForm.lblTroffCommandNotFound.Visible := True;
hasGhostscript := False;
MainForm.rdPdf.Enabled := False;
end else begin
hasGhostscript := True;
MainForm.rdPdf.Enabled := True;
end;
{$ENDIF}
end;
procedure TDetectGroffThread.Execute;
begin
FreeOnTerminate := True;
{$IFDEF WINDOWS}
if RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE) then
RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE);
RunCommand('cmd', ['/c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ELSE}
if RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
[], swoHIDE) then
RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
[], swoHIDE);
{$ENDIF}
begin
Synchronize(@UpdateUI);
Synchronize(@UpdateUI);
end;
end;
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
var
OnlineVersionsFile: string;
|
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if chkBoxPreprocessors.Checked[3] then buildOpts := buildOpts + ' -pic';
if chkBoxPreprocessors.Checked[4] then buildOpts := buildOpts + ' -refer';
if chkBoxPreprocessors.Checked[5] then buildOpts := buildOpts + ' -tbl';
if chkBoxExtras.Checked[0] then buildOpts := buildOpts + ' -mhdtbl';
// - PDF-specifics:
{$IFNDEF WINDOWS}
// On Windows, we use a two-step program:
// 1) Output to PostScript,
// 2) ps2pdf to PDF.
// This is because there is no pdfroff.exe. Requires Ghostscript.
if rdPdf.Checked then
begin
buildOpts := buildOpts + ' -Tpdf';
if chkBoxExtras.Checked[1] then buildOpts := buildOpts + ' -mpdfmark';
outputFileName := currentGroffFilePath + '.pdf';
end
else
{$ENDIF}
outputFileName := currentGroffFilePath + '.ps';
// - Input file:
buildOpts := buildOpts + ' ' + currentGroffFilePath;
buildOpts := buildOpts + ' > ' + outputFileName;
// - Log file:
if chkLogFile.Checked then logFileName := currentGroffFilePath + '.log';
// Build:
buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);
if buildSuccess then
MainStatusBar.Panels[1].Text := 'build successful'
else
MainStatusBar.Panels[1].Text := 'build problem';
{$IFDEF WINDOWS}
if buildSuccess and hasGhostscript then
begin
// Invoke ps2pdf:
buildOpts := 'ps2pdf';
// outputFileName is still the .ps file. Just use it as the input name.
buildOpts := buildOpts + ' ' + outputFileName;
buildSuccess := BuildWindow.BuildDocument(buildOpts, logFileName);
if buildSuccess then
begin
MainStatusBar.Panels[1].Text := 'build successful';
DeleteFile(outputFileName); // get rid of the .ps file
end
else
MainStatusBar.Panels[1].Text := 'build problem';
end;
{$ENDIF}
FreeAndNil(BuildWindow);
end;
procedure TMainForm.btnLoadGroffClick(Sender: TObject);
var
Reply, BoxStyle: integer;
|