STATES(1)
π states β the awk-alike text processing tool, but make it a state machine π¦
okay bestie, sit down, hydrate, because we're about to talk about states β a manual page from the STATES(1) section, and honestly? she's giving β¨ underrated icon β¨.
πΈ NAME πΈ
states β an awk-alike text processing tool π
β¨ SYNOPSIS β¨
states [-hvV] [-D var=val] [-f file] [-o outputfile] [-p path] [-s
startstate] [-W level] [filename ...]
π DESCRIPTION π
okay so States is an awk-alike text processing tool, but with some state machine extensions sprinkled on top like glitter π§. She was literally designed for program source code highlighting and similar tasks where having state info actually helps you process your input. periodt.
At any single point of time, States is in one state, and every state is quite similar to awk's work environment β they've got regular expressions that get matched from the input, and actions that get executed when a match is found. From the action blocks, states can do state transitions; it can move to another state and continue processing from there. And the way state transitions are recorded? so states can return to the calling state once the current state has finished π«Ά. it's giving recursion but make it fashion.
The biggest difference between states and awk (besides the state machine extensions, obviously) is that states is not line-oriented. She matches regular expression tokens from the input, and once a match is processed, she keeps going from the current position β NOT from the beginning of the next input line. no cap. π
π OPTIONS π
-D var=val,--define=var=valβ define variable var to have string value val. and bestie, command line definitions overwrite variable definitions found from the config file. so they win. period.-f file,--file=fileβ read state definitions from file file. As a default, states tries to read state definitions from filestates.stin the current working directory π.-h,--helpβ print short help message and exit. short and sweet, we love her.-o file,--output=fileβ save output to file file instead of printing it tostdoutπ .-p path,--path=pathβ set the load path to path. The load path defaults to the directory, from which the state definitions file is loaded.-s state,--state=stateβ start execution from state state. This definition overwrites start state resolved from thestartblock π₯.-v,--verboseβ increase the program verbosity. she's chatty now.-V,--versionβ print states version and exit.-W level,--warning=levelβ set the warning level to level. Possible values for level are:lightβ light warnings (default)allβ all warnings
π STATES PROGRAM FILES π
States program files can contain on start block, startrules and namerules blocks to specify the initial state, state definitions and expressions.
The start block is the main() of the states program β she's executed on script startup for each input file and she can perform any initialization the script needs. She normally also calls the check_startrules() and check_namerules() primitives which resolve the initial state from the input file name or the data found from the beginning of the input file. Here's a sample start block which initializes two variables and does the standard start state resolving:
start
{
a = 1;
msg = "Hello, world!";
check_startrules ();
check_namerules ();
}
Once the start block is processed, the input processing is continued from the initial state β¨.
The initial state is resolved by the information found from the startrules and namerules blocks. Both blocks contain regular expression - symbol pairs; when the regular expression is matched from the name of from the beginning of the input file, the initial state is named by the corresponding symbol. For example, the following start and name rules can distinguish C and Fortran files:
namerules
{
/\.(c|h)$/ c;
/\.[fF]$/ fortran;
}
startrules
{
/-\*- [cC] -\*-/ c;
/-\*- fortran -\*-/ fortran;
}
If these rules are used with the previously shown start block, states first checks the beginning of input file. If it has string -*- c -*-, the file is assumed to contain C code and the processing is started from state called c. If the beginning of the input file has string -*- fortran -*-, the initial state is fortran. If none of the start rules matched, the name of the input file is matched with the namerules. If the name ends to suffix c or C, we go to state c. If the suffix is f or F, the initial state is fortran.
If both start and name rules failed to resolve the start state, states just copies its input to output unmodified. no thoughts, head empty, just vibes π¦.
The start state can also be specified from the command line with option -s, --state.
State definitions have the following syntax:
state { expr {statements} ... }
where expr is: a regular expression, special expression or symbol and statements is a list of statements. When the expression expr is matched from the input, the statement block is executed. The statement block can call states' primitives, user-defined subroutines, call other states, etc. Once the block is executed, the input processing is continued from the current intput position (which might have been changed if the statement block called other states).
Special expressions BEGIN and END can be used in the place of expr. Expression BEGIN matches the beginning of the state β its block is called when the state is entered π. Expression END matches the end of the state β its block is executed when states leaves the state π.
If expr is a symbol, its value is looked up from the global environment and if it is a regular expression, it is matched to the input, otherwise that rule is ignored.
The states program file can also have top-level expressions β they are evaluated after the program file is parsed but before any input files are processed or the start block is evaluated. main character energy fr fr.
π§ PRIMITIVE FUNCTIONS π§
call (symbol)β move to state symbol and continue input file processing from that state. Function returns whatever the symbol state's terminatingreturnstatement returned.calln (name)β likecallbut the argument name is evaluated and its value must be string. For example, this function can be used to call a state which name is stored to a variable.check_namerules ()β try to resolve start state fromnamerulesrules. Function returns1if start state was resolved or0otherwise.check_startrules ()β try to resolve start state fromstartrulesrules. Function returns1if start state was resolved or0otherwise.concat (str, ...)β concanate argument strings and return result as a new string.float (any)β convert argument to a floating point number.getenv (str)β get value of environment variable str. Returns an empty string if variable var is undefined.int (any)β convert argument to an integer number.length (item, ...)β count the length of argument strings or lists.list (any, ...)β create a new list which contains items any, ...panic (any, ...)β report a non-recoverable error and exit with status1. Function never returns π.print (any, ...)β convert arguments to strings and print them to the output.range (source, start, end)β return a sub-range of source starting from position start (inclusively) to end (exclusively). Argument source can be string or list.regexp (string)β convert string string to a new regular expression.regexp_syntax (char, syntax)β modify regular expression character syntaxes by assigning new syntax syntax for character char. Possible values for syntax are:'w'β character is a word constituent' 'β character isn't a word constituent
regmatch (string, regexp)β check if string string matches regular expression regexp. Functions returns a boolean success status and sets sub-expression registers$n.regsub (string, regexp, subst)β search regular expression regexp from string string and replace the matching substring with string subst. Returns the resulting string. The substitution string subst can contain$nreferences to the n:th parenthesized sup-expression.regsuball (string, regexp, subst)β likeregsubbut replace all matches of regular expression regexp from string string with string subst. she does the whole sweep, obsessed.require_state (symbol)β check that the state symbol is defined. If the required state is undefined, the function tries to autoload it. If the loading fails, the program will terminate with an error message π.split (regexp, string)β split string string to list considering matches of regular rexpression regexp as item separator.sprintf (fmt, ...)β format arguments according to fmt and return result as a string.strcmp (str1, str2)β perform a case-sensitive comparision for strings str1 and str2. Function returns a value that is:-1β string str1 is less than str20β strings are equal1β string str1 is greater than str2
string (any)β convert argument to string.strncmp (str1, str2, num)β perform a case-sensitive comparision for strings str1 and str2 comparing at maximum num characters.substring (str, start, end)β return a substring of string str starting from position start (inclusively) to end (exclusively).
π BUILTIN VARIABLES π
$.β current input line number$nβ the n:th parenthesized regular expression sub-expression from the latest state regular expression or from theregmatchprimitive$`β everything before the matched regular rexpression. This is usable when used with theregmatchprimitive; the contents of this variable is undefined when used in action blocks to refer the data before the block's regular expression.$Bβ an alias for$`argvβ list of input file namesfilenameβ name of the current input fileprogramβ name of the program (usuallystates)versionβ program version string
π FILES π
/usr/share/enscript/hl/*.st enscript's states definitions
π₯ SEE ALSO π₯
π«Ά AUTHOR π«Ά
Markku Rossi <mtr@iki.fi> <http://www.iki.fi/~mtr/>
GNU Enscript WWW home page: <http://www.iki.fi/~mtr/genscript/>
okay that's the whole page bestie, no notes π
. this is from the STATES(1) manual, STATES section, dated Oct 23, 1998 β yes she's a vintage icon and she still ate π. love that for her. bye pookie πΈβ¨
π¦ where this page comes from
- alpine 3.24: enscript-doc 1.6.6-r7 Β· GPL-3.0-only
- arch rolling: enscript 1.6.6-6 Β· GPL3
- centos-stream 10: enscript 1.6.6-36.el10 Β· LGPL-2.0-or-later AND GPL-3.0-or-later AND GPL-2.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2 AND LGPL-2.1-or-later
- centos-stream 9: enscript 1.6.6-28.el9 Β· GPLv3+ and LGPLv2+ and GPLv2+
- debian bookworm: enscript 1.6.5.90-3+b1
- debian trixie: enscript 1.6.5.90-3.1+b1
- fedora 43: enscript 1.6.6-37.fc43 Β· LGPL-2.0-or-later AND GPL-3.0-or-later AND GPL-2.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2 AND LGPL-2.1-or-later
- fedora 44: enscript 1.6.6-38.fc44 Β· LGPL-2.0-or-later AND GPL-3.0-or-later AND GPL-2.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2 AND LGPL-2.1-or-later
- opensuse-leap 16.0: enscript 1.6.6-bp160.1.12 Β· GPL-3.0-or-later
- opensuse-leap 16.0: enscript 1.6.6-bp160.1.12 Β· GPL-3.0-or-later
- opensuse-leap 16.0: enscript 1.6.6-bp160.1.12 Β· GPL-3.0-or-later
- opensuse-leap 16.0: enscript 1.6.6-bp160.1.12 Β· GPL-3.0-or-later
- ubuntu jammy: enscript 1.6.5.90-3
- ubuntu noble: enscript 1.6.5.90-3.1
- ubuntu questing: enscript 1.6.5.90-3.2
- ubuntu resolute: enscript 1.6.5.90-3.2build1
- ubuntu stonking: enscript 1.6.5.90-3.2build1
- Copyright (c) 1997-1998 Markku Rossi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms