source: trunk/third/enscript/states/states.1.in @ 17620

Revision 17620, 11.0 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17619, which included commits to RCS files with non-trunk default branches.
Line 
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
26states \- 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
41machine extensions.  It is designed for program source code
42highlighting and to similar tasks where state information helps input
43processing.
44
45At a single point of time, \f3States\f1 is in one state, each quite
46similar to awk's work environment, they have regular expressions which
47are matched from the input and actions which are executed when a match
48is found.  From the action blocks, \f3states\f1 can perform state
49transitions; it can move to another state from which the processing is
50continued.  State transitions are recorded so \f3states\f1 can return
51to the calling state once the current state has finished.
52
53The biggest difference between \f3states\f1 and awk, besides state
54machine extensions, is that \f3states\f1 is not line-oriented.  It
55matches regular expression tokens from the input and once a match is
56processed, it continues processing from the current position, not from
57the 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
62Define variable \f2var\f1 to have string value \f2val\f1.  Command
63line definitions overwrite variable definitions found from the config
64file.
65.TP 8
66.B \-f \f2file\f3, \-\-file=\f2file\f3
67Read state definitions from file \f2file\f1.  As a default,
68\f3states\f1 tries to read state definitions from file \f3states.st\f1
69in the current working directory.
70.TP 8
71.B \-h, \-\-help
72Print short help message and exit.
73.TP 8
74.B \-o \f2file\f3, \-\-output=\f2file\f3
75Save output to file \f2file\f1 instead of printing it to
76\f3stdout\f1.
77.TP 8
78.B \-s \f2state\f3, \-\-state=\f2state\f3
79Start execution from state \f3state\f1.  This definition overwrites
80start state resolved from the \f3start\f1 block.
81.TP 8
82.B \-V, \-\-version
83Print \f3states\f1 version and exit.
84.TP 8
85.B \-W \f2level\f3, \-\-warning=\f2level\f3
86Set the warning level to \f2level\f1.  Possible values for \f2level\f1
87are:
88.RS 8
89.TP 8
90.B light
91light warnings (default)
92.TP 8
93.B all
94all 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
101state, \f2state\f1 definitions and \f2expressions\f1.
102
103The \f2start\f1 block is the main() of the \f3states\f1 program, it is
104executed on script startup for each input file and it can perform any
105initialization the script needs.  It normally also calls the
106\f3check_startrules()\f1 and \f3check_namerules()\f1 primitives which
107resolve the initial state from the input file name or the data found
108from the begining of the input file.  Here is a sample start block
109which initializes two variables and does the standard start state
110resolving:
111.PP
112.RS
113.nf
114start
115{
116  a = 1;
117  msg = "Hello, world!";
118  check_startrules ();
119  check_namerules ();
120}
121.fi
122.RE
123.PP
124Once the start block is processed, the input processing is continued
125from the initial state.
126
127The initial state is resolved by the information found from the
128\f2startrules\f1 and \f2namerules\f1 blocks.  Both blocks contain
129regular expression - symbol pairs, when the regular expression is
130matched from the name of from the beginning of the input file, the
131initial state is named by the corresponding symbol.  For example, the
132following start and name rules can distinguish C and Fortran files:
133.PP
134.RS
135.nf
136namerules
137{
138  /\.(c|h)$/    c;
139  /\.[fF]$/     fortran;
140}
141
142startrules
143{
144  /-\*- [cC] -\*-/      c;
145  /-\*- fortran -\*-/   fortran;
146}
147.fi
148.RE
149.PP
150If these rules are used with the previously shown start block,
151\f3states\f1 first check the beginning of input file.  If it has
152string \f3-*- c -*-\f1, the file is assumed to contain C code and the
153processing is started from state called \f3c\f1.  If the beginning of
154the 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
156input 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
160If both start and name rules failed to resolve the start state,
161\f3states\f1 just copies its input to output unmodified.
162
163The start state can also be specified from the command line with
164option \f3\-s\f1, \f3\-\-state\f1.
165
166State definitions have the following syntax:
167
168.B state { \f2expr\f1 {\f2statements\f1} ... }
169
170where \f2expr\f1 is: a regular expression, special expression or
171symbol and \f2statements\f1 is a list of statements.  When the
172expression \f2expr\f1 is matched from the input, the statement block
173is executed.  The statement block can call \f3states\f1' primitives,
174user-defined subroutines, call other states, etc.  Once the block is
175executed, the input processing is continued from the current intput
176position (which might have been changed if the statement block called
177other states).
178
179Special expressions \f3BEGIN\f1 and \f3END\f1 can be used in the place
180of \f2expr\f1.  Expression \f3BEGIN\f1 matches the beginning of the
181state, 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
185If \f2expr\f1 is a symbol, its value is looked up from the global
186environment and if it is a regular expression, it is matched to the
187input, otherwise that rule is ignored.
188
189The \f3states\f1 program file can also have top-level expressions,
190they are evaluated after the program file is parsed but before any
191input files are processed or the \f2start\f1 block is evaluated.
192
193.SH PRIMITIVE FUNCTIONS
194
195.TP 8
196.B call (\f2symbol\f3)
197Move to state \f2symbol\f1 and continue input file processing from
198that state.  Function returns whatever the \f3symbol\f1 state's
199terminating \f3return\f1 statement returned.
200.TP 8
201.B check_namerules ()
202Try to resolve start state from \f3namerules\f1 rules.  Function
203returns \f31\f1 if start state was resolved or \f30\f1 otherwise.
204.TP 8
205.B check_startrules ()
206Try to resolve start state from \f3startrules\f1 rules.  Function
207returns \f31\f1 if start state was resolved or \f30\f1 otherwise.
208.TP 8
209.B concat (\f2str\f3, ...)
210Concanate argument strings and return result as a new string.
211.TP 8
212.B float (\f2any\f3)
213Convert argument to a floating point number.
214.TP 8
215.B getenv (\f2str\f3)
216Get value of environment variable \f2str\f1.  Returns an empty string
217if variable \f2var\f1 is undefined.
218.TP 8
219.B int (\f2any\f3)
220Convert argument to an integer number.
221.TP 8
222.B length (\f2item\f3, ...)
223Count the length of argument strings or lists.
224.TP 8
225.B list (\f2any\f3, ...)
226Create a new list which contains items \f2any\f1, ...
227.TP 8
228.B panic (\f2any\f3, ...)
229Report a non-recoverable error and exit with status \f31\f1.  Function
230never returns.
231.TP 8
232.B print (\f2any\f3, ...)
233Convert arguments to strings and print them to the output.
234.TP 8
235.B range (\f2source\f3, \f2start\f3, \f2end\f3)
236Return a sub\-range of \f2source\f1 starting from position \f2start\f1
237(inclusively) to \f2end\f1 (exclusively).  Argument \f2source\f1 can
238be string or list.
239.TP 8
240.B regexp (\f2string\f3)
241Convert string \f2string\f1 to a new regular expression.
242.TP 8
243.B regexp_syntax (\f2char\f3, \f2syntax\f3)
244Modify regular expression character syntaxes by assigning new
245syntax \f2syntax\f1 for character \f2char\f1.  Possible values for
246\f2syntax\f1 are:
247.RS 8
248.TP 8
249.B 'w'
250character is a word constituent
251.TP 8
252.B ' '
253character isn't a word constituent
254.RE
255.TP 8
256.B regmatch (\f2string\f3, \f2regexp\f3)
257Check if string \f2string\f1 matches regular expression \f2regexp\f1.
258Functions returns a boolean success status and sets sub-expression
259registers \f3$\f2n\f1.
260.TP 8
261.B regsub (\f2string\f1, \f2regexp\f3, \f2subst\f3)
262Search regular expression \f2regexp\f1 from string \f2string\f1 and
263replace the matching substring with string \f2subst\f1.  Returns the
264resulting string.  The substitution string \f2subst\f1 can contain
265\f3$\f2n\f1 references to the \f2n\f1:th parenthesized
266sup-expression.
267.TP 8
268.B regsuball (\f2string\f1, \f2regexp\f3, \f2subst\f3)
269Like \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)
273Split string \f2string\f1 to list considering matches of regular
274rexpression \f2regexp\f1 as item separator.
275.TP 8
276.B sprintf (\f2fmt\f1, ...)
277Format arguments according to \f2fmt\f1 and return result as a
278string.
279.TP 8
280.B strcmp (\f2str1\f3, \f2str2\f3)
281Perform 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
286string \f2str1\f1 is less than \f2str2\f1
287.TP 8
288.B 0
289strings are equal
290.TP 8
291.B 1
292string \f2str1\f1 is greater than \f2str2\f1
293.RE
294.TP 8
295.B string (\f2any\f3)
296Convert argument to string.
297.TP 8
298.B strncmp (\f2str1\f3, \f2str2\f3, \f2num\f3)
299Perform 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)
303Return 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 $.
310current input line number
311.TP 8
312.B $\f2n\f3
313the \f2n\f1th parenthesized regular expression sub-expression from the
314latest state regular expression or from the \f3regmatch\f1 primitive
315.TP 8
316.B $`
317everything before the matched regular rexpression.  This is usable
318when used with the \f3regmatch\f1 primitive; the contents of this
319variable is undefined when used in action blocks to refer the data
320before the block's regular expression.
321.TP 8
322.B $B
323an alias for \f3$`\f1
324.TP 8
325.B argv
326list of input file names
327.TP 8
328.B filename
329name of the current input file
330.TP 8
331.B program
332name of the program (usually \f3states\f1)
333.TP 8
334.B version
335program 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
345awk(1), enscript(1)
346
347.SH AUTHOR
348Markku Rossi <mtr@iki.fi> <http://www.iki.fi/~mtr/>
349
350GNU Enscript WWW home page: <http://www.iki.fi/~mtr/genscript/>
Note: See TracBrowser for help on using the repository browser.