92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
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
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
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
|
-
+
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
-
-
-
-
+
-
-
-
-
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
|
procedure btnSaveSettingsClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure lblFossilRepoClick(Sender: TObject);
procedure lblGithubRepoClick(Sender: TObject);
procedure lblWebsiteClick(Sender: TObject);
procedure SynEdit1Change(Sender: TObject);
{$IFDEF DARWIN}
{$IFDEF DARWIN}
procedure GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
{$ENDIF}
{$ENDIF}
private
var
var currentGroffFilePath: String;
var currentGroffFileName: String;
var unsavedChanges: Boolean;
{$IFDEF WINDOWS}
var latestGroffWindowsUrl: String;
{$ENDIF}
var storeBuildSettings: Boolean;
var updateCheck: Boolean;
currentGroffFilePath: string;
currentGroffFileName: string;
unsavedChanges: boolean;
{$IFDEF WINDOWS}
atestGroffWindowsUrl: String;
{$ENDIF}
storeBuildSettings: boolean;
updateCheck: boolean;
public
end;
TDetectGroffThread = class(TThread)
private
procedure UpdateUI;
protected
procedure Execute; Override;
procedure Execute; override;
end;
var
MainForm: TMainForm;
BuildWindow: TBuildStatusWindow;
hasGroff: Boolean;
hasGroff: boolean;
GroffOutputVersion: string;
implementation
{$R *.lfm}
procedure TDetectGroffThread.Execute;
procedure TDetectGroffThread.UpdateUI;
var
GroffOutputVersion: String;
begin
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;
end
else
begin
MainForm.edtGroffInstalledVersion.Text := 'n/a';
hasGroff := False;
MainForm.lblTroffCommandNotFound.Visible := True;
end;
end;
procedure TDetectGroffThread.Execute;
begin
FreeOnTerminate := True;
{$IFDEF WINDOWS}
if RunCommand('cmd', ['/c', 'troff --version'], GroffOutputVersion, [], swoHIDE) then
{$ELSE}
if RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion, [], swoHIDE) then
if RunCommand('/bin/sh', ['-c', 'troff --version'], GroffOutputVersion,
[], swoHIDE) then
{$ENDIF}
begin
MainForm.edtGroffInstalledVersion.Text := GroffOutputVersion;
if pos('GNU', GroffOutputVersion) = 0 then
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;
Synchronize(@UpdateUI);
end else begin
MainForm.edtGroffInstalledVersion.Text := 'n/a';
hasGroff := False;
MainForm.lblTroffCommandNotFound.Visible := True;
end;
end;
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
var
OnlineVersionsFile: String;
OnlineVersionsFile: string;
{$IFDEF WINDOWS}
reGroffVersion: TRegExpr;
{$ENDIF}
reGroffStudioVersion: TRegExpr;
FileVerInfo: TFileVersionInfo;
HasVersionUpdate: Integer;
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);
ResStream := TResourceStream.Create(HInstance, 'LICENSE', RT_RCDATA);
try
mLicense.Lines.LoadFromStream(ResStream);
finally
ResStream.Free;
end;
// Restore the settings
iniStorage.Restore;
storeBuildSettings := iniStorage.ReadBoolean('AutoSaveBuildSettings', False);
chkAutoSaveBuildSettings.Checked := storeBuildSettings;
{$IF DEFINED(LINUX) OR DEFINED(BSD)}
{$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}
{$ELSE}
updateCheck := iniStorage.ReadBoolean('UpdateCheckOnStart', False);
chkUpdateCheckOnStart.Checked := updateCheck;
{$ENDIF}
{$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);
chkBoxPreprocessors.Checked[2] := iniStorage.ReadBoolean('BuildUseGrn', False);
chkBoxPreprocessors.Checked[3] := iniStorage.ReadBoolean('BuildUsePic', False);
chkBoxPreprocessors.Checked[4] := iniStorage.ReadBoolean('BuildUseRefer', False);
chkBoxPreprocessors.Checked[5] := iniStorage.ReadBoolean('BuildUseTbl', False);
chkBoxExtras.Checked[0] := iniStorage.ReadBoolean('BuildUseHdtbl', False);
chkBoxExtras.Checked[1] := iniStorage.ReadBoolean('BuildUsePdfMark', False);
rdPs.Checked := iniStorage.ReadBoolean('BuildToPostscript', False);
rdPdf.Checked := iniStorage.ReadBoolean('BuildToPDF', False);
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);
chkBoxPreprocessors.Checked[2] := iniStorage.ReadBoolean('BuildUseGrn', False);
chkBoxPreprocessors.Checked[3] := iniStorage.ReadBoolean('BuildUsePic', False);
chkBoxPreprocessors.Checked[4] := iniStorage.ReadBoolean('BuildUseRefer', False);
chkBoxPreprocessors.Checked[5] := iniStorage.ReadBoolean('BuildUseTbl', False);
chkBoxExtras.Checked[0] := iniStorage.ReadBoolean('BuildUseHdtbl', False);
chkBoxExtras.Checked[1] := iniStorage.ReadBoolean('BuildUsePdfMark', False);
rdPs.Checked := iniStorage.ReadBoolean('BuildToPostscript', False);
rdPdf.Checked := iniStorage.ReadBoolean('BuildToPDF', False);
end;
// What's the latest available version?
FileVerInfo := TFileVersionInfo.Create(nil);
try
FileVerInfo.ReadFileInfo;
edtGroffStudioInstalledVersion.Text := FileVerInfo.VersionStrings.Values['FileVersion'];
lblAboutProductName.Caption := FileVerInfo.VersionStrings.Values['ProductName'] + ' ' + FileVerInfo.VersionStrings.Values['FileVersion'];
edtGroffStudioInstalledVersion.Text :=
FileVerInfo.VersionStrings.Values['FileVersion'];
lblAboutProductName.Caption :=
FileVerInfo.VersionStrings.Values['ProductName'] + ' ' +
FileVerInfo.VersionStrings.Values['FileVersion'];
MainStatusBar.Panels[2].Text := '';
{$IFDEF WINDOWS}
if updateCheck then
begin
OnlineVersionsFile := TFPCustomHTTPClient.SimpleGet('https://groff.tuxproject.de/updates/versions.txt');
|
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
-
+
-
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
|
// Set the "Changed" mark:
MainStatusBar.Panels[0].Text := '* ' + currentGroffFileName;
unsavedChanges := True;
end;
procedure TMainForm.btnDownloadGroffWindowsClick(Sender: TObject);
begin
{$IFDEF WINDOWS}
{$IFDEF WINDOWS}
// On other systems, the button is disabled anyway.
OpenURL(latestGroffWindowsUrl);
{$ENDIF}
{$ENDIF}
end;
procedure TMainForm.btnBuildClick(Sender: TObject);
var
buildSuccess: Boolean;
buildOpts: String;
logFileName: String = '';
outputFileName: String;
buildSuccess: boolean;
buildOpts: string;
logFileName: string = '';
outputFileName: string;
begin
// Reset status display:
MainStatusBar.Panels[1].Text := '';
BuildWindow := TBuildStatusWindow.Create(Application);
BuildWindow.Show;
// Build the parameters:
buildOpts := 'groff';
// - Macro:
if LeftStr(cmbMacro.Text, 1) = 'm' then buildOpts := buildOpts + ' -' + cmbMacro.Text;
// - Enforce UTF-8:
buildOpts := buildOpts + ' -Kutf8';
// - Preprocessors:
if chkBoxPreprocessors.Checked[0] then buildOpts := buildOpts + ' -chem';
if chkBoxPreprocessors.Checked[1] then buildOpts := buildOpts + ' -eqn';
if chkBoxPreprocessors.Checked[2] then buildOpts := buildOpts + ' -grn';
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 chkBoxPreprocessors.Checked[0] then buildOpts := buildOpts + ' -chem';
if chkBoxPreprocessors.Checked[1] then buildOpts := buildOpts + ' -eqn';
if chkBoxPreprocessors.Checked[2] then buildOpts := buildOpts + ' -grn';
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:
if rdPdf.Checked then begin
if rdPdf.Checked then
begin
buildOpts := buildOpts + ' -Tpdf';
if chkBoxExtras.Checked[1] then buildOpts := buildOpts + ' -mpdfmark';
outputFileName := currentGroffFilePath + '.pdf';
end
else
else outputFileName := currentGroffFilePath + '.ps';
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';
FreeAndNil(BuildWindow);
end;
procedure TMainForm.btnLoadGroffClick(Sender: TObject);
var
Reply, BoxStyle: Integer;
Reply, BoxStyle: integer;
begin
// If the current file has unsaved changes, ask first.
if unsavedChanges then with Application do begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := MessageBox('Do you want to save the document first?', 'UnsavedChanges', BoxStyle);
if Reply = IDYES then SynEdit1.Lines.SaveToFile(currentGroffFilePath);
unsavedChanges := False;
end;
if unsavedChanges then with Application do
begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := MessageBox('Do you want to save the document first?',
'UnsavedChanges', BoxStyle);
if Reply = idYes then SynEdit1.Lines.SaveToFile(currentGroffFilePath);
unsavedChanges := False;
end;
if odOpenGroffFile.Execute then
begin
if FileExists(odOpenGroffFile.FileName) then
begin
currentGroffFilePath := odOpenGroffFile.FileName;
currentGroffFileName := ExtractFileName(odOpenGroffFile.FileName);
|
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
-
+
-
-
-
-
-
+
+
+
+
+
+
+
-
|
iniStorage.WriteBoolean('AutoUpdateCheck', chkUpdateCheckOnStart.Checked);
iniStorage.Save;
end;
procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
Reply, BoxStyle: Integer;
Reply, BoxStyle: integer;
begin
// If the current file has unsaved changes, ask first.
if unsavedChanges then
with Application do begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := MessageBox('Do you want to save the document first?', 'UnsavedChanges', BoxStyle);
if Reply = IDYES then btnSaveGroffClick(Sender);
end;
with Application do
begin
BoxStyle := MB_ICONQUESTION + MB_YESNO;
Reply := MessageBox('Do you want to save the document first?',
'UnsavedChanges', BoxStyle);
if Reply = idYes then btnSaveGroffClick(Sender);
end;
end;
{$IFDEF DARWIN}
// Fix HTTPS on macOS:
procedure TMainForm.GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
begin
if UseSSL then begin
AHandler := TSSLSocketHandler.Create;
TSSLSocketHandler(AHandler).SSLType := stTLSv1_2;
end else AHandler := TSocketHandler.Create;
end;
{$ENDIF}
end.
|