-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.pas
205 lines (169 loc) · 5.32 KB
/
command.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
45
46
47
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
{$I CrossrefPrefixCode.inc} // STD definitions
// Crossref - Pascal Cross reference
// Version 0.06
// January 9, 2021
// Copyright 2021 Paul Robinson
// Licensed under GPL v2
// Command.pas - Commans File Processor
unit Command;
{$mode ObjFPC}{$H+}
interface
uses Notice, Tables,SysUtils, Scan;
Var
Quit: Boolean = False;
WillExit: Boolean = False; //< Exit without acting
WillHold: Boolean = False; //< pause before exit
WillDryRun: Boolean = False; //< test w/o acting
WillDumpStats: Boolean = False; //< dump statistics
// handle -x or -x= commands
Procedure ProcessSingleArgument(const S:UnicodeString);
// handle --x or --x= commands
Procedure ProcessDoubleArgument(const S:UnicodeString);
// handle @command file
Procedure ProcessCommandFile(Const S: UnicodeString);
// handle source file
Procedure ProcessSourceFile(Const S: UnicodeString);
// Message if no args
Procedure Usage;
implementation
Procedure Usage;
begin
if ParamCount < 1 then
begin
Writeln;
Writeln(' Usage: ',PasPath,' <options> ');
Writeln;
WriteLn(' Examples:');
Writeln('Usage: ',Programname,' [/switch | -switch | --switch ] ',
'<file1>| <file2> etc]');
Writeln(' Optional switches must come before any file nams)');
Writeln(' <file1>|<file2> etc]');
writeln(' If you want to use a configuration file, ',
'prefix the name with @');
writeln(' @configurationfile, if used, must appear first, ',
'after any switch(es), if used');
Writeln(' Any source or template files must come after the ',
'configuration file, if used');
Writeln;
writeln(' File names containing spaces must be quoted, @',
QuoteChar,'like this',QuoteChar,' or -u=',QuoteChar,
'this way',QuoteChar);
Writeln;
Writeln(' If you want to include units not used by a main program ',
'or units that');
Writeln(' the main program uses, directly or indirectly, list ',
'them first.');
Writeln(' The main prograam (or primary/controlling unit ',
'if no main program');
Writeln(' is specified) should be the last file name on ',
' the command line.');
Writeln;
Writeln(' The configuration file will declare options for the ',
'program and any independent units.');
Writeln(' if the configuration file includes or invokes the main ',
'program (and any independent units),');
Writeln(' then the source file need not be specified ',
'on the command line.');
Writeln;
Writeln('For a list of switches, use the /sw -sw or --switches command.');
writeln('Switches are not case senitive.');
{$IFDEF test}
writeln;write('** Press Enter; '); Readln;
{$ENDIF}
exit;
// The following DEAD CODE is INTRNTIONALLY used to eliminate
// spurious compiler warning messages
Starttime.Year:=0;
EndTime.Year:=0;
Starttime.Year := EndTime.Year;
EndTime.Year := Starttime.Year ;
end
end;
// Temporary proc to test --dryrun
Procedure DryRun;
begin
Writeln('Run in dry (no action) mode');
WillDryRun := TRUE;
WillDumpStats := TRUE;
end;
// handle /x -x /x= -x= /sa /sa= -sa -sa=
Procedure ProcessSingleArgument(const S:UnicodeString);
Var
Len,
Eq: Integer;
Val,
Cmd,
UCArg:UnicodeString;
begin
UCArg := Uppercase(S);
Len := Length(S);
Eq := Pos('=',UCArg);
If Eq > 0 then
begin
Val := Copy(S,Eq+1,Len);
Cmd := Copy(UCArg,1,Eq-1);
end
else
begin
Val := '';
Cmd :=UCArg;
end;
CASE UCArg of
'H','HELP','INFO': begin usage; WillExit := TRUE; end;
'XYXXY': Writeln('Nothing happens.');
'HOLD', 'STOP': WillHold := TRUE;
'DRY','DRYRUN','DRY-RUN' : Dryrun;
else
Writeln('?Imvalid argument "',S,'" ignoted');
end
end;
// handle --xxx --xxx-x --xxx-x= or --xx=
Procedure ProcessDoubleArgument(const S:UnicodeString);
Var
Len, //< param (S) length
Eq: Integer; //< location of = in param
Val, //< if = in command, value after it
Cmd, //< command as given
UCArg:UnicodeString; //< command in UPPER CASE
begin
UCArg := Uppercase(S);
Len := Length(S);
Eq := Pos('=',UCArg);
If Eq > 0 then
begin
Val := Copy(S,Eq+1,Len);
Cmd := Copy(UCArg,1,Eq-1);
end
else
begin
Val := '';
Cmd :=UCArg;
end;
CASE UCArg of
'H','HELP','INFO': begin usage; WillExit := TRUE; end;
'XYXXY': Writeln('Nothing happens.');
'HOLD','STOP' : WillHold := TRUE;
'DRY','DRYRUN','DRY-RUN' : Dryrun;
else
Writeln('?Imvalid argument "',S,'" ignored');
end
end;
// handle @command file
Procedure ProcessCommandFile(Const S: UnicodeString);
var
Temp: InPtr;
begin
If Buffer = NIL then // if this is the first unit
New(Buffer)
else
begin // this is another file
New(Temp);
Temp^.Next := Buffer; // save the prior Buffer
Buffer := Temp;
end;
end;
// handle source file
Procedure ProcessSourceFile(Const S: UnicodeString);
begin
end;
END.