19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
ExtCtrls, Buttons, ExtendedNotebook, SynEdit, fphttpclient, RegExpr, LCLIntf,
LCLType, IniPropStorage, ComboEx, Process, Helpers, fileinfo,
{$IF DEFINED(WINDOWS)}
winpeimagereader, opensslsockets,
{$ELSEIF DEFINED(DARWIN)}
machoreader, ssockets, sslsockets, sslbase, opensslsockets,
{$ELSEIF DEFINED(LINUX)}
elfreader,
{$ENDIF}
BuildOutputWindow;
type
{ TMainForm }
TMainForm = class(TForm)
|
|
|
|
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,
ExtCtrls, Buttons, ExtendedNotebook, SynEdit, fphttpclient, RegExpr, LCLIntf,
LCLType, IniPropStorage, ComboEx, Process, Helpers, fileinfo,
{$IF DEFINED(WINDOWS)}
winpeimagereader, opensslsockets,
{$ELSEIF DEFINED(DARWIN)}
machoreader, ssockets, sslsockets, sslbase, opensslsockets,
{$ELSEIF DEFINED(LINUX)}
elfreader,
{$ENDIF}
BuildOutputWindow;
type
{ TMainForm }
TMainForm = class(TForm)
|
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
hasGroff := True;
MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
end;
// Try to find ps2pdf:
if pos('ps2pdf', ps2pdfOutput) = 0 then
begin
{$IFDEF WINDOWS}
// ps2pdf is mandatory on Windows.
ShowMessage('On Windows, for creating PDF files, you need Ghostscript installed.'
+ LineEnding + 'Sadly, groffstudio could not find ps2pdf.bat in your %PATH%, so '
+ 'writing PDF files will not be supported. Please install Ghostscript and make sure '
+ 'that the folder that contains ps2pdf.bat is in your %PATH%.');
MainForm.rdPdf.Enabled := False;
{$ENDIF}
hasGhostscript := False;
MainForm.chkUseGhostscript.Checked := False;
MainForm.chkUseGhostscript.Enabled := False;
end else begin
hasGhostscript := True;
{$IFDEF WINDOWS}
MainForm.rdPdf.Enabled := True;
MainForm.chkUseGhostscript.Checked := True;
{$ENDIF}
MainForm.chkUseGhostscript.Enabled := True;
end;
end;
procedure TDetectGroffThread.Execute;
begin
FreeOnTerminate := True;
{$IFDEF WINDOWS}
RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE);
RunCommand('cmd', ['/c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ELSE}
RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
[], swoHIDE);
RunCommand('/bin/sh', ['-c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ENDIF}
Synchronize(@UpdateUI);
end;
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
var
OnlineVersionsFile: string;
{$IFDEF WINDOWS}
reGroffVersion: TRegExpr;
{$ENDIF}
reGroffStudioVersion: TRegExpr;
FileVerInfo: TFileVersionInfo;
HasVersionUpdate: integer;
GroffHelpers: TGroffHelpers;
ResStream: TResourceStream;
{$IFDEF DARWIN}
HTTPClient: TFPHttpClient;
{$ENDIF}
begin
// What's the current running groff version?
TDetectGroffThread.Create(False);
// Default file name
currentGroffFileName := '[unsaved file]';
// Embed the license
ResStream := TResourceStream.Create(HInstance, 'LICENSE', RT_RCDATA);
try
mLicense.Lines.LoadFromStream(ResStream);
finally
ResStream.Free;
end;
{$IFNDEF WINDOWS}
// Ghostscript is not optional on Windows.
// On other platforms, let's use the stored setting.
chkUseGhostscript.Checked := iniStorage.ReadBoolean('UseGhostscript', False);
{$ENDIF}
// Restore the settings
iniStorage.Restore;
storeBuildSettings := iniStorage.ReadBoolean('AutoSaveBuildSettings', False);
chkAutoSaveBuildSettings.Checked := storeBuildSettings;
{$IF DEFINED(LINUX) OR DEFINED(BSD)}
// On platforms which probably use a package manager (currently, Linux and
// BSDs), the "update check" checkbox is disabled.
chkUpdateCheckOnStart.Enabled := False;
{$ELSE}
updateCheck := iniStorage.ReadBoolean('UpdateCheckOnStart', False);
chkUpdateCheckOnStart.Checked := updateCheck;
{$ENDIF}
if storeBuildSettings then
begin
chkLogFile.Checked := iniStorage.ReadBoolean('BuildLogFile', False);
cmbMacro.Text := iniStorage.ReadString('BuildChosenMacro', '[ select ]');
chkBoxPreprocessors.Checked[0] := iniStorage.ReadBoolean('BuildUseChem', False);
chkBoxPreprocessors.Checked[1] := iniStorage.ReadBoolean('BuildUseEqn', False);
|
|
|
>
>
|
|
|
>
>
>
>
>
>
|
>
|
>
>
|
|
|
|
|
|
|
|
|
|
|
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
hasGroff := True;
MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
end;
// Try to find ps2pdf:
if pos('ps2pdf', ps2pdfOutput) = 0 then
begin
{$IFDEF WINDOWS}
// ps2pdf is mandatory on Windows.
ShowMessage('On Windows, for creating PDF files, you need Ghostscript installed.'
+ LineEnding + 'Sadly, groffstudio could not find ps2pdf.bat in your %PATH%, so '
+ 'writing PDF files will not be supported. Please install Ghostscript and make sure '
+ 'that the folder that contains ps2pdf.bat is in your %PATH%.');
MainForm.rdPdf.Enabled := False;
{$ENDIF}
hasGhostscript := False;
MainForm.chkUseGhostscript.Checked := False;
MainForm.chkUseGhostscript.Enabled := False;
end
else
begin
hasGhostscript := True;
{$IFDEF WINDOWS}
MainForm.rdPdf.Enabled := True;
MainForm.chkUseGhostscript.Checked := True;
{$ENDIF}
MainForm.chkUseGhostscript.Enabled := True;
end;
// Try to find Ghostscript, just for displaying the version:
if hasGhostscript then
MainForm.edtGhostscriptInstalledVersion.Text := GhostscriptOutputVersion
else
MainForm.edtGhostscriptInstalledVersion.Text := 'n/a';
end;
procedure TDetectGroffThread.Execute;
begin
FreeOnTerminate := True;
{$IFDEF WINDOWS}
RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE);
RunCommand('cmd', ['/c', 'gs --version'], GhostscriptOutputVersion, [], swoHIDE);
RunCommand('cmd', ['/c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ELSE}
RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
[], swoHIDE);
RunCommand('/bin/sh', ['-c', 'gs --version'], GhostscriptOutputVersion,
[], swoHIDE);
RunCommand('/bin/sh', ['-c', 'ps2pdf'], ps2pdfOutput, [], swoHIDE);
{$ENDIF}
Synchronize(@UpdateUI);
end;
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
var
OnlineVersionsFile: string;
{$IFDEF WINDOWS}
reGroffVersion: TRegExpr;
{$ENDIF}
reGroffStudioVersion: TRegExpr;
FileVerInfo: TFileVersionInfo;
HasVersionUpdate: integer;
GroffHelpers: TGroffHelpers;
ResStream: TResourceStream;
{$IFDEF DARWIN}
HTTPClient: TFPHttpClient;
{$ENDIF}
begin
// What's the current running groff version?
TDetectGroffThread.Create(False);
// Default file name
currentGroffFileName := '[unsaved file]';
// Embed the license
ResStream := TResourceStream.Create(HInstance, 'LICENSE', RT_RCDATA);
try
mLicense.Lines.LoadFromStream(ResStream);
finally
ResStream.Free;
end;
{$IFNDEF WINDOWS}
// Ghostscript is not optional on Windows.
// On other platforms, let's use the stored setting.
chkUseGhostscript.Checked := iniStorage.ReadBoolean('UseGhostscript', False);
{$ENDIF}
// Restore the settings
iniStorage.Restore;
storeBuildSettings := iniStorage.ReadBoolean('AutoSaveBuildSettings', False);
chkAutoSaveBuildSettings.Checked := storeBuildSettings;
{$IF DEFINED(LINUX) OR DEFINED(BSD)}
// On platforms which probably use a package manager (currently, Linux and
// BSDs), the "update check" checkbox is disabled.
chkUpdateCheckOnStart.Enabled := False;
{$ELSE}
updateCheck := iniStorage.ReadBoolean('UpdateCheckOnStart', False);
chkUpdateCheckOnStart.Checked := updateCheck;
{$ENDIF}
if storeBuildSettings then
begin
chkLogFile.Checked := iniStorage.ReadBoolean('BuildLogFile', False);
cmbMacro.Text := iniStorage.ReadString('BuildChosenMacro', '[ select ]');
chkBoxPreprocessors.Checked[0] := iniStorage.ReadBoolean('BuildUseChem', False);
chkBoxPreprocessors.Checked[1] := iniStorage.ReadBoolean('BuildUseEqn', False);
|
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
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 and not chkUseGhostscript.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);
{$IFDEF WINDOWS}
if buildSuccess and hasGhostscript and rdPdf.Checked then
{$ELSE}
// On non-Windows systems, Ghostscript is entirely optional.
if buildSuccess and hasGhostscript and chkUseGhostscript.Checked and rdPdf.Checked then
{$ENDIF}
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 and not chkKeepPostscriptFile.Checked then;
DeleteFile(outputFileName); // get rid of the .ps fil
end;
if buildSuccess then
MainStatusBar.Panels[1].Text := 'build successful'
else
MainStatusBar.Panels[1].Text := 'build problem';
|
|
|
|
|
|
|
|
|
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
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 and not chkUseGhostscript.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);
{$IFDEF WINDOWS}
if buildSuccess and hasGhostscript and rdPdf.Checked then
{$ELSE}
// On non-Windows systems, Ghostscript is entirely optional.
if buildSuccess and hasGhostscript and chkUseGhostscript.Checked and rdPdf.Checked then
{$ENDIF}
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 and not chkKeepPostscriptFile.Checked then
DeleteFile(outputFileName); // get rid of the .ps file
end;
if buildSuccess then
MainStatusBar.Panels[1].Text := 'build successful'
else
MainStatusBar.Panels[1].Text := 'build problem';
|