1 | .\" |
---|
2 | .\" States manual page. |
---|
3 | .\" Copyright (c) 1997 Markku Rossi. |
---|
4 | .\" Author: Markku Rossi <mtr@iki.fi> |
---|
5 | .\" |
---|
6 | .\" This file is part of GNU enscript. |
---|
7 | .\" |
---|
8 | .\" This program is free software; you can redistribute it and/or modify |
---|
9 | .\" it under the terms of the GNU General Public License as published by |
---|
10 | .\" the Free Software Foundation; either version 2, or (at your option) |
---|
11 | .\" any later version. |
---|
12 | .\" |
---|
13 | .\" This program is distributed in the hope that it will be useful, |
---|
14 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | .\" GNU General Public License for more details. |
---|
17 | .\" |
---|
18 | .\" You should have received a copy of the GNU General Public License |
---|
19 | .\" along with this program; see the file COPYING. If not, write to |
---|
20 | .\" the Free Software Foundation, 59 Temple Place - Suite 330, |
---|
21 | .\" Boston, MA 02111-1307, USA. |
---|
22 | .\" |
---|
23 | .TH STATES 1 "Jun 6, 1997" "STATES" "STATES" |
---|
24 | |
---|
25 | .SH NAME |
---|
26 | states \- awk alike text processing tool |
---|
27 | |
---|
28 | .SH SYNOPSIS |
---|
29 | .B states |
---|
30 | [\f3\-hV\f1] |
---|
31 | [\f3\-D \f2var\f3=\f2val\f1] |
---|
32 | [\f3\-f \f2file\f1] |
---|
33 | [\f3\-o \f2outputfile\f1] |
---|
34 | [\f3\-s \f2startstate\f1] |
---|
35 | [\f3\-W \f2level\f1] |
---|
36 | [\f2filename\f1 ...] |
---|
37 | |
---|
38 | .SH DESCRIPTION |
---|
39 | |
---|
40 | \f3States\f1 is an awk-alike text processing tool with some state |
---|
41 | machine extensions. It is designed for program source code |
---|
42 | highlighting and to similar tasks where state information helps input |
---|
43 | processing. |
---|
44 | |
---|
45 | At a single point of time, \f3States\f1 is in one state, each quite |
---|
46 | similar to awk's work environment, they have regular expressions which |
---|
47 | are matched from the input and actions which are executed when a match |
---|
48 | is found. From the action blocks, \f3states\f1 can perform state |
---|
49 | transitions; it can move to another state from which the processing is |
---|
50 | continued. State transitions are recorded so \f3states\f1 can return |
---|
51 | to the calling state once the current state has finished. |
---|
52 | |
---|
53 | The biggest difference between \f3states\f1 and awk, besides state |
---|
54 | machine extensions, is that \f3states\f1 is not line-oriented. It |
---|
55 | matches regular expression tokens from the input and once a match is |
---|
56 | processed, it continues processing from the current position, not from |
---|
57 | the beginning of the next input line. |
---|
58 | |
---|
59 | .SH OPTIONS |
---|
60 | .TP 8 |
---|
61 | .B \-D \f2var\f3=\f2val\f3, \-\-define=\f2var\f3=\f2val\f3 |
---|
62 | Define variable \f2var\f1 to have string value \f2val\f1. Command |
---|
63 | line definitions overwrite variable definitions found from the config |
---|
64 | file. |
---|
65 | .TP 8 |
---|
66 | .B \-f \f2file\f3, \-\-file=\f2file\f3 |
---|
67 | Read state definitions from file \f2file\f1. As a default, |
---|
68 | \f3states\f1 tries to read state definitions from file \f3states.st\f1 |
---|
69 | in the current working directory. |
---|
70 | .TP 8 |
---|
71 | .B \-h, \-\-help |
---|
72 | Print short help message and exit. |
---|
73 | .TP 8 |
---|
74 | .B \-o \f2file\f3, \-\-output=\f2file\f3 |
---|
75 | Save output to file \f2file\f1 instead of printing it to |
---|
76 | \f3stdout\f1. |
---|
77 | .TP 8 |
---|
78 | .B \-s \f2state\f3, \-\-state=\f2state\f3 |
---|
79 | Start execution from state \f3state\f1. This definition overwrites |
---|
80 | start state resolved from the \f3start\f1 block. |
---|
81 | .TP 8 |
---|
82 | .B \-V, \-\-version |
---|
83 | Print \f3states\f1 version and exit. |
---|
84 | .TP 8 |
---|
85 | .B \-W \f2level\f3, \-\-warning=\f2level\f3 |
---|
86 | Set the warning level to \f2level\f1. Possible values for \f2level\f1 |
---|
87 | are: |
---|
88 | .RS 8 |
---|
89 | .TP 8 |
---|
90 | .B light |
---|
91 | light warnings (default) |
---|
92 | .TP 8 |
---|
93 | .B all |
---|
94 | all warnings |
---|
95 | .RE |
---|
96 | |
---|
97 | .SH STATES PROGRAM FILES |
---|
98 | |
---|
99 | \f3States\f1 program files can contain on \f2start\f1 block, |
---|
100 | \f2startrules\f1 and \f2namerules\f1 blocks to specify the initial |
---|
101 | state, \f2state\f1 definitions and \f2expressions\f1. |
---|
102 | |
---|
103 | The \f2start\f1 block is the main() of the \f3states\f1 program, it is |
---|
104 | executed on script startup for each input file and it can perform any |
---|
105 | initialization the script needs. It normally also calls the |
---|
106 | \f3check_startrules()\f1 and \f3check_namerules()\f1 primitives which |
---|
107 | resolve the initial state from the input file name or the data found |
---|
108 | from the begining of the input file. Here is a sample start block |
---|
109 | which initializes two variables and does the standard start state |
---|
110 | resolving: |
---|
111 | .PP |
---|
112 | .RS |
---|
113 | .nf |
---|
114 | start |
---|
115 | { |
---|
116 | a = 1; |
---|
117 | msg = "Hello, world!"; |
---|
118 | check_startrules (); |
---|
119 | check_namerules (); |
---|
120 | } |
---|
121 | .fi |
---|
122 | .RE |
---|
123 | .PP |
---|
124 | Once the start block is processed, the input processing is continued |
---|
125 | from the initial state. |
---|
126 | |
---|
127 | The initial state is resolved by the information found from the |
---|
128 | \f2startrules\f1 and \f2namerules\f1 blocks. Both blocks contain |
---|
129 | regular expression - symbol pairs, when the regular expression is |
---|
130 | matched from the name of from the beginning of the input file, the |
---|
131 | initial state is named by the corresponding symbol. For example, the |
---|
132 | following start and name rules can distinguish C and Fortran files: |
---|
133 | .PP |
---|
134 | .RS |
---|
135 | .nf |
---|
136 | namerules |
---|
137 | { |
---|
138 | /\.(c|h)$/ c; |
---|
139 | /\.[fF]$/ fortran; |
---|
140 | } |
---|
141 | |
---|
142 | startrules |
---|
143 | { |
---|
144 | /-\*- [cC] -\*-/ c; |
---|
145 | /-\*- fortran -\*-/ fortran; |
---|
146 | } |
---|
147 | .fi |
---|
148 | .RE |
---|
149 | .PP |
---|
150 | If these rules are used with the previously shown start block, |
---|
151 | \f3states\f1 first check the beginning of input file. If it has |
---|
152 | string \f3-*- c -*-\f1, the file is assumed to contain C code and the |
---|
153 | processing is started from state called \f3c\f1. If the beginning of |
---|
154 | the input file has string \f3-*- fortran -*-\f1, the initial state is |
---|
155 | \f3fortran\f1. If none of the start rules matched, the name of the |
---|
156 | input file is matched with the namerules. If the name ends to suffix |
---|
157 | \f3c\f1 or \f3C\f1, we go to state \f3c\f1. If the suffix is |
---|
158 | \f3f\f1 or \f3F\f1, the initial state is fortran. |
---|
159 | |
---|
160 | If both start and name rules failed to resolve the start state, |
---|
161 | \f3states\f1 just copies its input to output unmodified. |
---|
162 | |
---|
163 | The start state can also be specified from the command line with |
---|
164 | option \f3\-s\f1, \f3\-\-state\f1. |
---|
165 | |
---|
166 | State definitions have the following syntax: |
---|
167 | |
---|
168 | .B state { \f2expr\f1 {\f2statements\f1} ... } |
---|
169 | |
---|
170 | where \f2expr\f1 is: a regular expression, special expression or |
---|
171 | symbol and \f2statements\f1 is a list of statements. When the |
---|
172 | expression \f2expr\f1 is matched from the input, the statement block |
---|
173 | is executed. The statement block can call \f3states\f1' primitives, |
---|
174 | user-defined subroutines, call other states, etc. Once the block is |
---|
175 | executed, the input processing is continued from the current intput |
---|
176 | position (which might have been changed if the statement block called |
---|
177 | other states). |
---|
178 | |
---|
179 | Special expressions \f3BEGIN\f1 and \f3END\f1 can be used in the place |
---|
180 | of \f2expr\f1. Expression \f3BEGIN\f1 matches the beginning of the |
---|
181 | state, its block is called when the state is entered. Expression |
---|
182 | \f3END\f1 matches the end of the state, its block is executed when |
---|
183 | \f3states\f1 leaves the state. |
---|
184 | |
---|
185 | If \f2expr\f1 is a symbol, its value is looked up from the global |
---|
186 | environment and if it is a regular expression, it is matched to the |
---|
187 | input, otherwise that rule is ignored. |
---|
188 | |
---|
189 | The \f3states\f1 program file can also have top-level expressions, |
---|
190 | they are evaluated after the program file is parsed but before any |
---|
191 | input files are processed or the \f2start\f1 block is evaluated. |
---|
192 | |
---|
193 | .SH PRIMITIVE FUNCTIONS |
---|
194 | |
---|
195 | .TP 8 |
---|
196 | .B call (\f2symbol\f3) |
---|
197 | Move to state \f2symbol\f1 and continue input file processing from |
---|
198 | that state. Function returns whatever the \f3symbol\f1 state's |
---|
199 | terminating \f3return\f1 statement returned. |
---|
200 | .TP 8 |
---|
201 | .B check_namerules () |
---|
202 | Try to resolve start state from \f3namerules\f1 rules. Function |
---|
203 | returns \f31\f1 if start state was resolved or \f30\f1 otherwise. |
---|
204 | .TP 8 |
---|
205 | .B check_startrules () |
---|
206 | Try to resolve start state from \f3startrules\f1 rules. Function |
---|
207 | returns \f31\f1 if start state was resolved or \f30\f1 otherwise. |
---|
208 | .TP 8 |
---|
209 | .B concat (\f2str\f3, ...) |
---|
210 | Concanate argument strings and return result as a new string. |
---|
211 | .TP 8 |
---|
212 | .B float (\f2any\f3) |
---|
213 | Convert argument to a floating point number. |
---|
214 | .TP 8 |
---|
215 | .B getenv (\f2str\f3) |
---|
216 | Get value of environment variable \f2str\f1. Returns an empty string |
---|
217 | if variable \f2var\f1 is undefined. |
---|
218 | .TP 8 |
---|
219 | .B int (\f2any\f3) |
---|
220 | Convert argument to an integer number. |
---|
221 | .TP 8 |
---|
222 | .B length (\f2item\f3, ...) |
---|
223 | Count the length of argument strings or lists. |
---|
224 | .TP 8 |
---|
225 | .B list (\f2any\f3, ...) |
---|
226 | Create a new list which contains items \f2any\f1, ... |
---|
227 | .TP 8 |
---|
228 | .B panic (\f2any\f3, ...) |
---|
229 | Report a non-recoverable error and exit with status \f31\f1. Function |
---|
230 | never returns. |
---|
231 | .TP 8 |
---|
232 | .B print (\f2any\f3, ...) |
---|
233 | Convert arguments to strings and print them to the output. |
---|
234 | .TP 8 |
---|
235 | .B range (\f2source\f3, \f2start\f3, \f2end\f3) |
---|
236 | Return a sub\-range of \f2source\f1 starting from position \f2start\f1 |
---|
237 | (inclusively) to \f2end\f1 (exclusively). Argument \f2source\f1 can |
---|
238 | be string or list. |
---|
239 | .TP 8 |
---|
240 | .B regexp (\f2string\f3) |
---|
241 | Convert string \f2string\f1 to a new regular expression. |
---|
242 | .TP 8 |
---|
243 | .B regexp_syntax (\f2char\f3, \f2syntax\f3) |
---|
244 | Modify regular expression character syntaxes by assigning new |
---|
245 | syntax \f2syntax\f1 for character \f2char\f1. Possible values for |
---|
246 | \f2syntax\f1 are: |
---|
247 | .RS 8 |
---|
248 | .TP 8 |
---|
249 | .B 'w' |
---|
250 | character is a word constituent |
---|
251 | .TP 8 |
---|
252 | .B ' ' |
---|
253 | character isn't a word constituent |
---|
254 | .RE |
---|
255 | .TP 8 |
---|
256 | .B regmatch (\f2string\f3, \f2regexp\f3) |
---|
257 | Check if string \f2string\f1 matches regular expression \f2regexp\f1. |
---|
258 | Functions returns a boolean success status and sets sub-expression |
---|
259 | registers \f3$\f2n\f1. |
---|
260 | .TP 8 |
---|
261 | .B regsub (\f2string\f1, \f2regexp\f3, \f2subst\f3) |
---|
262 | Search regular expression \f2regexp\f1 from string \f2string\f1 and |
---|
263 | replace the matching substring with string \f2subst\f1. Returns the |
---|
264 | resulting string. The substitution string \f2subst\f1 can contain |
---|
265 | \f3$\f2n\f1 references to the \f2n\f1:th parenthesized |
---|
266 | sup-expression. |
---|
267 | .TP 8 |
---|
268 | .B regsuball (\f2string\f1, \f2regexp\f3, \f2subst\f3) |
---|
269 | Like \f3regsub\f1 but replace all matches of regular expression |
---|
270 | \f2regexp\f1 from string \f2string\f1 with string \f2subst\f1. |
---|
271 | .TP 8 |
---|
272 | .B split (\f2regexp\f3, \f2string\f3) |
---|
273 | Split string \f2string\f1 to list considering matches of regular |
---|
274 | rexpression \f2regexp\f1 as item separator. |
---|
275 | .TP 8 |
---|
276 | .B sprintf (\f2fmt\f1, ...) |
---|
277 | Format arguments according to \f2fmt\f1 and return result as a |
---|
278 | string. |
---|
279 | .TP 8 |
---|
280 | .B strcmp (\f2str1\f3, \f2str2\f3) |
---|
281 | Perform a case\-sensitive comparision for strings \f2str1\f1 and |
---|
282 | \f2str2\f1. Function returns a value that is: |
---|
283 | .RS 8 |
---|
284 | .TP 8 |
---|
285 | .B -1 |
---|
286 | string \f2str1\f1 is less than \f2str2\f1 |
---|
287 | .TP 8 |
---|
288 | .B 0 |
---|
289 | strings are equal |
---|
290 | .TP 8 |
---|
291 | .B 1 |
---|
292 | string \f2str1\f1 is greater than \f2str2\f1 |
---|
293 | .RE |
---|
294 | .TP 8 |
---|
295 | .B string (\f2any\f3) |
---|
296 | Convert argument to string. |
---|
297 | .TP 8 |
---|
298 | .B strncmp (\f2str1\f3, \f2str2\f3, \f2num\f3) |
---|
299 | Perform a case\-sensitive comparision for strings \f2str1\f1 and |
---|
300 | \f2str2\f1 comparing at maximum \f2num\f3 characters. |
---|
301 | .TP 8 |
---|
302 | .B substring (\f2str\f3, \f2start\f3, \f2end\f3) |
---|
303 | Return a substring of string \f2str\f1 starting from position |
---|
304 | \f2start\f1 (inclusively) to \f2end\f1 (exclusively). |
---|
305 | .RE |
---|
306 | |
---|
307 | .SH BUILTIN VARIABLES |
---|
308 | .TP 8 |
---|
309 | .B $. |
---|
310 | current input line number |
---|
311 | .TP 8 |
---|
312 | .B $\f2n\f3 |
---|
313 | the \f2n\f1th parenthesized regular expression sub-expression from the |
---|
314 | latest state regular expression or from the \f3regmatch\f1 primitive |
---|
315 | .TP 8 |
---|
316 | .B $` |
---|
317 | everything before the matched regular rexpression. This is usable |
---|
318 | when used with the \f3regmatch\f1 primitive; the contents of this |
---|
319 | variable is undefined when used in action blocks to refer the data |
---|
320 | before the block's regular expression. |
---|
321 | .TP 8 |
---|
322 | .B $B |
---|
323 | an alias for \f3$`\f1 |
---|
324 | .TP 8 |
---|
325 | .B argv |
---|
326 | list of input file names |
---|
327 | .TP 8 |
---|
328 | .B filename |
---|
329 | name of the current input file |
---|
330 | .TP 8 |
---|
331 | .B program |
---|
332 | name of the program (usually \f3states\f1) |
---|
333 | .TP 8 |
---|
334 | .B version |
---|
335 | program version string |
---|
336 | .RE |
---|
337 | |
---|
338 | .SH FILES |
---|
339 | .nf |
---|
340 | .ta 4i |
---|
341 | @prefix@/share/enscript/enscript.st enscript's states definitions |
---|
342 | .fi |
---|
343 | |
---|
344 | .SH SEE ALSO |
---|
345 | awk(1), enscript(1) |
---|
346 | |
---|
347 | .SH AUTHOR |
---|
348 | Markku Rossi <mtr@iki.fi> <http://www.iki.fi/~mtr/> |
---|
349 | |
---|
350 | GNU Enscript WWW home page: <http://www.iki.fi/~mtr/genscript/> |
---|