groffstudio

Check-in [edf9412b43]
Login

Check-in [edf9412b43]

Overview
Comment:[Feature] The installed Ghostscript version is now displayed in the settings. ... and code formatting
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: edf9412b4352dd4a0fe09564ccd839785876a89f580aaab1223a93234fa5bbcd
User & Date: Cthulhux on 2024-04-30 12:29:10
Other Links: manifest | tags
Context
2024-04-30
12:37
.. check-in: 726dbe99cb user: Cthulhux tags: trunk
12:29
[Feature] The installed Ghostscript version is now displayed in the settings. ... and code formatting check-in: edf9412b43 user: Cthulhux tags: trunk
12:10
[Feature] There is an option to keep both the .ps and the .pdf file now. [Feature] Non-Windows users can choose to use Ghostscript (if installed) or pdfroff. check-in: 80a9157eaf user: Cthulhux tags: trunk
Changes

Modified CHANGES.txt from [5125c42e0a] to [c13e25c21d].

1
2
3
4
5
6

7
8
9
10
11
12
13
Version [next]

[Feature] On Windows, Ghostscript replaced pdfroff (thanks @wysardry).
[Bugfix] The groff detection logic was not as logical as it should have been.
[Feature] There is an option to keep both the .ps and the .pdf file now.
[Feature] Non-Windows users can choose to use Ghostscript (if installed) or pdfroff.


-------------------------------

Version 0.13.2
2024-04-30

[Improved] Multi-threading is more standards-compliant now (thanks @Th69).






>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
Version [next]

[Feature] On Windows, Ghostscript replaced pdfroff (thanks @wysardry).
[Bugfix] The groff detection logic was not as logical as it should have been.
[Feature] There is an option to keep both the .ps and the .pdf file now.
[Feature] Non-Windows users can choose to use Ghostscript (if installed) or pdfroff.
[Feature] The installed Ghostscript version is now displayed in the settings.

-------------------------------

Version 0.13.2
2024-04-30

[Improved] Multi-threading is more standards-compliant now (thanks @Th69).

Modified src/buildoutputwindow.pas from [b2dc02ad8c] to [a65bb3f811].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  { TBuildStatusWindow }

  TBuildStatusWindow = class(TForm)
    Label1: TLabel;
  private

  public
    function BuildDocument(CommandLine: String; LogFile: String): Boolean;

  end;

var
  OutputText: String;

implementation

{$R *.lfm}

function TBuildStatusWindow.BuildDocument(CommandLine: String; LogFile: String): Boolean;
var
  str: String;
  lh: TextFile;
  ret: Boolean;
begin
{$IFDEF WINDOWS}
  ret := RunCommand('cmd', ['/c', CommandLine], str, [], swoHIDE);
{$ELSE}
  ret := RunCommand('sh', ['-c', CommandLine], str, [], swoHIDE);
{$ENDIF}

  if Length(str) = 0 then str := 'No problems have occurred. :-)';

  if LogFile <> '' then
  begin
    AssignFile(lh, LogFile);
    try







|




|





|

|

|

|



|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  { TBuildStatusWindow }

  TBuildStatusWindow = class(TForm)
    Label1: TLabel;
  private

  public
    function BuildDocument(CommandLine: string; LogFile: string): boolean;

  end;

var
  OutputText: string;

implementation

{$R *.lfm}

function TBuildStatusWindow.BuildDocument(CommandLine: string; LogFile: string): boolean;
var
  str: string;
  lh: TextFile;
  ret: boolean;
begin
  {$IFDEF WINDOWS}
  ret := RunCommand('cmd', ['/c', CommandLine], str, [], swoHIDE);
{$ELSE}
  ret := RunCommand('sh', ['-c', CommandLine], str, [], swoHIDE);
  {$ENDIF}

  if Length(str) = 0 then str := 'No problems have occurred. :-)';

  if LogFile <> '' then
  begin
    AssignFile(lh, LogFile);
    try
70
71
72
73
74
75
76
77
  { Close the status window: }
  Close;

  Result := ret;
end;

end.








<
70
71
72
73
74
75
76

  { Close the status window: }
  Close;

  Result := ret;
end;

end.

Modified src/groffstudio.lpi from [aad3a914ec] to [cfbaa470c1].

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        <Resource_0 FileName="..\LICENSE" Type="RCDATA" ResourceName="LICENSE"/>
      </Resources>
    </General>
    <VersionInfo>
      <UseVersionInfo Value="True"/>
      <AutoIncrementBuild Value="True"/>
      <MinorVersionNr Value="14"/>
      <BuildNr Value="7"/>
      <StringTable ProductName="groffstudio"/>
    </VersionInfo>
    <BuildModes>
      <Item Name="Default" Default="True"/>
    </BuildModes>
    <PublishOptions>
      <Version Value="2"/>







|







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        <Resource_0 FileName="..\LICENSE" Type="RCDATA" ResourceName="LICENSE"/>
      </Resources>
    </General>
    <VersionInfo>
      <UseVersionInfo Value="True"/>
      <AutoIncrementBuild Value="True"/>
      <MinorVersionNr Value="14"/>
      <BuildNr Value="9"/>
      <StringTable ProductName="groffstudio"/>
    </VersionInfo>
    <BuildModes>
      <Item Name="Default" Default="True"/>
    </BuildModes>
    <PublishOptions>
      <Version Value="2"/>

Modified src/groffstudio.lpr from [85befef33a] to [326a826cd4].

16
17
18
19
20
21
22
23
24
25
26
27




28
29
30
31
32
33
34
35
36
37
38
39
40
41
}

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  {$IFDEF HASAMIGA}
  athreads,
  {$ENDIF}
  Interfaces,




  Forms, lazcontrols, Unit1, Helpers, BuildOutputWindow;

{$R *.res}

begin
  RequireDerivedFormResource:=True;
  Application.Scaled:=True;
  Application.Initialize;
  
  Application.CreateForm(TMainForm, MainForm);

  Application.Run;
end.








|


|

>
>
>
>
|

|


|
|

|




<
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

}

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads,
{$ENDIF}
  {$IFDEF HASAMIGA}
  athreads,
{$ENDIF}
  Interfaces,
  Forms,
  lazcontrols,
  Unit1,
  Helpers,
  BuildOutputWindow;

  {$R *.res}

begin
  RequireDerivedFormResource := True;
  Application.Scaled := True;
  Application.Initialize;

  Application.CreateForm(TMainForm, MainForm);

  Application.Run;
end.

Modified src/helpers.pas from [7fc6e4646d] to [b64febe3f4].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63

uses
  Classes, SysUtils;

type
  TGroffHelpers = class
  public
    procedure VerStrCompare(newVersion, oldVersion: String; out comp: Integer);
end;

implementation

procedure TGroffHelpers.VerStrCompare(newVersion, oldVersion: String; out comp: Integer);
var
  nE1, nE2, nV1, nV2: Integer;

begin
 if (Length(newVersion) > 0) or (Length(oldVersion) > 0) then begin

  nE1 := Pos('.', newVersion + '.');
  nE2 := Pos('.', oldVersion + '.');
  if nE1 > 1 then
    nV1 := StrToInt(Copy(newVersion,1,(nE1-1)))
  else
    nV1 := 0;

  if nE2 > 1 then
    nV2 := StrToInt(Copy(oldVersion,1,(nE2-1)))
  else
    nV2 := 0;

  if nV1 = nV2 then
    VerStrCompare(Copy(newVersion, nE1 + 1, Length(newVersion)), Copy(oldVersion, nE2 + 1, Length(oldVersion)), comp)

  else if nV1 > nV2 then
    comp := 1
  else if nV1 < nV2 then
    comp := -1;
 end
 else
   comp := 0;
end;

end.








|
|



|

|
<

|
>
|
|
|
|
|
|

|
|
|
|

|
|
>
|
|
|
|
|
|
|



<
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63


uses
  Classes, SysUtils;

type
  TGroffHelpers = class
  public
    procedure VerStrCompare(newVersion, oldVersion: string; out comp: integer);
  end;

implementation

procedure TGroffHelpers.VerStrCompare(newVersion, oldVersion: string; out comp: integer);
var
  nE1, nE2, nV1, nV2: integer;

begin
  if (Length(newVersion) > 0) or (Length(oldVersion) > 0) then
  begin
    nE1 := Pos('.', newVersion + '.');
    nE2 := Pos('.', oldVersion + '.');
    if nE1 > 1 then
      nV1 := StrToInt(Copy(newVersion, 1, (nE1 - 1)))
    else
      nV1 := 0;

    if nE2 > 1 then
      nV2 := StrToInt(Copy(oldVersion, 1, (nE2 - 1)))
    else
      nV2 := 0;

    if nV1 = nV2 then
      VerStrCompare(Copy(newVersion, nE1 + 1, Length(newVersion)),
        Copy(oldVersion, nE2 + 1, Length(oldVersion)), comp)
    else if nV1 > nV2 then
      comp := 1
    else if nV1 < nV2 then
      comp := -1;
  end
  else
    comp := 0;
end;

end.

Modified src/unit1.lfm from [1278594516] to [5721aed32c].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
object MainForm: TMainForm
  Left = 1073
  Height = 692
  Top = 99
  Width = 847
  Caption = 'groffstudio'
  ClientHeight = 692
  ClientWidth = 847
  DefaultMonitor = dmPrimary
  Position = poScreenCenter
  LCLVersion = '3.99.0.0'
  OnClose = FormClose
  OnCreate = FormCreate
  object MainStatusBar: TStatusBar
    Left = 0
    Height = 23
    Top = 669
    Width = 847










<







1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
object MainForm: TMainForm
  Left = 1073
  Height = 692
  Top = 99
  Width = 847
  Caption = 'groffstudio'
  ClientHeight = 692
  ClientWidth = 847
  DefaultMonitor = dmPrimary
  Position = poScreenCenter

  OnClose = FormClose
  OnCreate = FormCreate
  object MainStatusBar: TStatusBar
    Left = 0
    Height = 23
    Top = 669
    Width = 847
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    SimplePanel = False
  end
  object ExtendedNotebook1: TExtendedNotebook
    Left = 8
    Height = 662
    Top = 8
    Width = 827
    ActivePage = tsSettings
    Anchors = [akTop, akLeft, akRight, akBottom]
    Style = tsFlatButtons
    TabIndex = 1
    TabOrder = 1
    object tsEdit: TTabSheet
      Caption = 'edit a groff document'
      ClientHeight = 631
      ClientWidth = 819
      ParentFont = False
      object GroupBox1: TGroupBox







|


|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    SimplePanel = False
  end
  object ExtendedNotebook1: TExtendedNotebook
    Left = 8
    Height = 662
    Top = 8
    Width = 827
    ActivePage = tsEdit
    Anchors = [akTop, akLeft, akRight, akBottom]
    Style = tsFlatButtons
    TabIndex = 0
    TabOrder = 1
    object tsEdit: TTabSheet
      Caption = 'edit a groff document'
      ClientHeight = 631
      ClientWidth = 819
      ParentFont = False
      object GroupBox1: TGroupBox
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
        BorderStyle = bsNone
        Enabled = False
        TabOrder = 1
      end
      object lblTroffCommandNotFound: TLabel
        Left = 8
        Height = 45
        Top = 112
        Width = 806
        Anchors = [akTop, akLeft, akRight]
        Caption = 'groff was not found. in order to use groffstudio, you absolutely need groff in your PATH variable. on unix and unix-like systems, you''ll need to edit the $PATH variable. on windows, i warmly recommend the Rapid Environment Editor for that.'#13#10'please exit groffstudio at your nearest convenience and adjust your PATH variables. then try again.'
        Font.Color = clRed
        ParentColor = False
        ParentFont = False
        Visible = False







|







876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
        BorderStyle = bsNone
        Enabled = False
        TabOrder = 1
      end
      object lblTroffCommandNotFound: TLabel
        Left = 8
        Height = 45
        Top = 130
        Width = 806
        Anchors = [akTop, akLeft, akRight]
        Caption = 'groff was not found. in order to use groffstudio, you absolutely need groff in your PATH variable. on unix and unix-like systems, you''ll need to edit the $PATH variable. on windows, i warmly recommend the Rapid Environment Editor for that.'#13#10'please exit groffstudio at your nearest convenience and adjust your PATH variables. then try again.'
        Font.Color = clRed
        ParentColor = False
        ParentFont = False
        Visible = False
904
905
906
907
908
909
910

















911
912
913
914
915
916
917
      object Label10: TLabel
        Left = 8
        Height = 15
        Top = 77
        Width = 103
        Caption = 'groffstudio version:'
        ParentColor = False

















      end
    end
    object tsAbout: TTabSheet
      Caption = 'about groffstudio'
      ClientHeight = 631
      ClientWidth = 819
      object lblAboutProductName: TLabel







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
      object Label10: TLabel
        Left = 8
        Height = 15
        Top = 77
        Width = 103
        Caption = 'groffstudio version:'
        ParentColor = False
      end
      object Label15: TLabel
        Left = 8
        Height = 15
        Top = 98
        Width = 103
        Caption = 'ghostscript version:'
      end
      object edtGhostscriptInstalledVersion: TEdit
        Left = 144
        Height = 15
        Top = 98
        Width = 671
        Anchors = [akTop, akLeft, akRight]
        BorderStyle = bsNone
        Enabled = False
        TabOrder = 3
      end
    end
    object tsAbout: TTabSheet
      Caption = 'about groffstudio'
      ClientHeight = 631
      ClientWidth = 819
      object lblAboutProductName: TLabel

Modified src/unit1.pas from [a3a810c1b6] to [2e85f0db1a].

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)
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
    chkBoxPreprocessors: TCheckComboBox;
    chkUpdateCheckOnStart: TCheckBox;
    chkLogFile: TCheckBox;
    chkAutoSaveBuildSettings: TCheckBox;
    cmbMacro: TComboBox;
    edtGroffInstalledVersion: TEdit;
    edtGroffstudioInstalledVersion: TEdit;

    edtOnlineGroffVersionWindows: TEdit;
    ExtendedNotebook1: TExtendedNotebook;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    iniStorage: TIniPropStorage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;

    lblGithubRepo: TLabel;
    lblFossilRepo: TLabel;
    lblWebsite: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;







>












>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    chkBoxPreprocessors: TCheckComboBox;
    chkUpdateCheckOnStart: TCheckBox;
    chkLogFile: TCheckBox;
    chkAutoSaveBuildSettings: TCheckBox;
    cmbMacro: TComboBox;
    edtGroffInstalledVersion: TEdit;
    edtGroffstudioInstalledVersion: TEdit;
    edtGhostscriptInstalledVersion: TEdit;
    edtOnlineGroffVersionWindows: TEdit;
    ExtendedNotebook1: TExtendedNotebook;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    iniStorage: TIniPropStorage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    lblGithubRepo: TLabel;
    lblFossilRepo: TLabel;
    lblWebsite: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
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
    procedure chkUseGhostscriptChange(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}
    procedure GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
    {$ENDIF}
  private
  var
    currentGroffFilePath: string;
    currentGroffFileName: string;
    unsavedChanges: boolean;
    {$IFDEF WINDOWS}
    latestGroffWindowsUrl: String;
    {$ENDIF}
    // Settings:
    storeBuildSettings: boolean;
    updateCheck: boolean;
  public

  end;








|

|





|

|







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
    procedure chkUseGhostscriptChange(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}
    procedure GetSocketHandler(Sender: TObject; const UseSSL: Boolean; out AHandler: TSocketHandler);
{$ENDIF}
  private
  var
    currentGroffFilePath: string;
    currentGroffFileName: string;
    unsavedChanges: boolean;
{$IFDEF WINDOWS}
    latestGroffWindowsUrl: String;
{$ENDIF}
    // Settings:
    storeBuildSettings: boolean;
    updateCheck: boolean;
  public

  end;

128
129
130
131
132
133
134

135
136
137
138
139
140
141
var
  MainForm: TMainForm;
  BuildWindow: TBuildStatusWindow;
  hasGroff: boolean;
  hasGhostscript: boolean;
  GroffOutputVersion: string;
  ps2pdfOutput: string;


implementation

{$R *.lfm}

procedure TDetectGroffThread.UpdateUI;
begin







>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var
  MainForm: TMainForm;
  BuildWindow: TBuildStatusWindow;
  hasGroff: boolean;
  hasGhostscript: boolean;
  GroffOutputVersion: string;
  ps2pdfOutput: string;
  GhostscriptOutputVersion: string;

implementation

{$R *.lfm}

procedure TDetectGroffThread.UpdateUI;
begin
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);
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
    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');

      // 1. groff update check
      reGroffVersion := TRegExpr.Create('groff-win ([\d\.]+) (.*)$');
      reGroffVersion.ModifierM := True;







|







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    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');

      // 1. groff update check
      reGroffVersion := TRegExpr.Create('groff-win ([\d\.]+) (.*)$');
      reGroffVersion.ModifierM := True;
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
        if HasVersionUpdate > 0 then
          MainStatusBar.Panels[2].Text := 'update ' + reGroffStudioVersion.Match[1] + ' available';
      end;
    end else begin
        edtOnlineGroffVersionWindows.Text := 'n/a';
        btnDownloadGroffWindows.Enabled := False;
    end;
    {$ELSE}
    // Non-Windows platforms won't need some of that.
    {$IFDEF DARWIN}
    // What's the latest available version?
    try
      if updateCheck then
      begin
        HTTPClient := TFPHTTPClient.Create(Nil);







|







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
        if HasVersionUpdate > 0 then
          MainStatusBar.Panels[2].Text := 'update ' + reGroffStudioVersion.Match[1] + ' available';
      end;
    end else begin
        edtOnlineGroffVersionWindows.Text := 'n/a';
        btnDownloadGroffWindows.Enabled := False;
    end;
{$ELSE}
    // Non-Windows platforms won't need some of that.
    {$IFDEF DARWIN}
    // What's the latest available version?
    try
      if updateCheck then
      begin
        HTTPClient := TFPHTTPClient.Create(Nil);
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
      end;
    finally
      if updateCheck then HTTPClient.Free;
    end;
    {$ENDIF}
    edtOnlineGroffVersionWindows.Text := 'n/a';
    btnDownloadGroffWindows.Enabled := False;
    {$ENDIF}
  finally
    FileVerInfo.Free;
  end;

  // Loaded file display
  MainStatusBar.Panels[0].Text := '';








|







347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
      end;
    finally
      if updateCheck then HTTPClient.Free;
    end;
    {$ENDIF}
    edtOnlineGroffVersionWindows.Text := 'n/a';
    btnDownloadGroffWindows.Enabled := False;
{$ENDIF}
  finally
    FileVerInfo.Free;
  end;

  // Loaded file display
  MainStatusBar.Panels[0].Text := '';

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
  // Set the "Changed" mark:
  MainStatusBar.Panels[0].Text := '* ' + currentGroffFileName;
  unsavedChanges := True;
end;

procedure TMainForm.btnDownloadGroffWindowsClick(Sender: TObject);
begin
  {$IFDEF WINDOWS}
   // On other systems, the button is disabled anyway.
   OpenURL(latestGroffWindowsUrl);
  {$ENDIF}
end;

procedure TMainForm.btnBuildClick(Sender: TObject);
var
  buildSuccess: boolean;
  buildOpts: string;
  logFileName: string = '';







|


|







383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
  // Set the "Changed" mark:
  MainStatusBar.Panels[0].Text := '* ' + currentGroffFileName;
  unsavedChanges := True;
end;

procedure TMainForm.btnDownloadGroffWindowsClick(Sender: TObject);
begin
{$IFDEF WINDOWS}
   // On other systems, the button is disabled anyway.
   OpenURL(latestGroffWindowsUrl);
{$ENDIF}
end;

procedure TMainForm.btnBuildClick(Sender: TObject);
var
  buildSuccess: boolean;
  buildOpts: string;
  logFileName: string = '';
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';