scconfig - generator (templating)
scconfig lets the user generate all output files from hook.c. The
user may use a series of fprintf() calls to generate the new file or could
get sed/awk detected and run scripts. However, it is very common that there
is a template for the file to be generated with a few parts which should
be conditional or replaced by autodetected or calculated values or pasted
repeatedly. To ease generating these common files, scconfig offers an
optional module called generator which is a very simple templating
system.
Syntax
With generator, a plain text file is read and another plain text file
is written. Normally the input file is copied byte by byte to the
output file. The only exception is when a generator command is detected.
Generator commands are sorrunded by ### marks and they can not be nested.
###put path value###
Write the database. Equivalent of C call put(path, value).
If node exists on path, it's overwritten, else it is created.
###append path value###
Write the database. Equivalent of C call append(path, value).
If node exists on path, value is appended at the end of the original
value, else it is created.
###nput dstpath srcpath###
Same as put, but second argument is a node: value of srcpath is copied
to node dstpath.
###nappend dstpath srcpath###
Same as append, but second argument is a node: value of srcpath is appended
to node dstpath.
###neval node###
Evaluate value of node and print result.
###nsplit strnode dirname regex###
Split value of strnode by regex into words and store
each word in new node dirname/N.
###include filename###
Include filename (same as #include in C).
###report text###
Print text in the log and on stdout to the user.
###abort###
Call abort().
###if path op refval###, ###else###, ###endif###
Fetches the value of variable path from the database and compares
it to refval. Valid operators for the op field are:
- ==
- > (for numerics only)
- < (for numerics only)
- ~ (regex match)
- @ (true if node value is empty; refval is ignored)
Example:
###if /host/libs/math/minpack/present == true###
Minpack found.
###else###
Minpack not found.
###endif###
###if /target/sys/uname ~ mips###
Compiling for mips.
###endif###
###[ng]sub path pattern substitute###
Read the value of node at path and do regex substitution of pattern with
substitute and emit the resulting string. Different sub
commands with 'n' and/or 'g' prefixes will do slightly different
modification on the input:
command
| global
| node value
|
sub
| no
| no
|
gsub
| yes
| no
|
nsub
| no
| yes
|
ngsub
| yes
| yes
|
Global substitution means all matches are substituted (as opposed to
the normal behavior when only the longest is substituted). Those
commands operating with node value take substitute as a node
path and use the value of that node as a substitution string.
Examples (with equivalent sed scripts):
###put /local/str This is a test string.###
###put /local/new A###
With string literals substitutions:
"s/i/II/" is ###sub /local/str i II###
"s/i/II/g" is ###gsub /local/str i II###
With node value substitutions:
"s/i/A/" is ###nsub /host/str i /host/new###
"s/i/A/g" is ###ngsub /host/str i /host/new###
###foreach lvar invar###, ###done###
invar is variable holding a space separated list of words. The body of the loop
is interpreted for each word and the value of lvar is set to the word
prior to each run. Example:
###foreach /local/n /local/source_files###
###/local/n###.o: ###/local/n###.c ###/local/n###.h common.h
$(CC) -c $(CFLAGS) -o ###/local/n###.o ###/local/n###.c
###done
###redir filename###
Redirect output to filename. If filename is empty, close
current redirection. Thus, redir comes in pairs and may be nested. Example:
###call func args###
When GENCALL is defined (-DGENCALL should be added in USER_CFLAGS), genertor
implements this command as a generic callback to hooks.c, where function called
generator_callback(char *func, char *args) will be executed upon
###call### commands. args is an optional multiword payload.
local/a
###redir file1###
out1/a
###redir file2###
out2
###redir###
out1/b
###redir###
local/b
The first ###redir### will stop writing file2 returning to file1 (where
out1/b will land) and the second ###redir### will stop writing file1 returning
to the original output file.
###sep###
Print separator (###) on output. Useful when generating input for subsequent
generator operations.
get
Every other word sorrunded by ### marks are interpreted as node names
and substituted with their corresponding value (or empty string if
node does not exist). Example:
LDFLAGS_PTHREAD = ###/target/libs/lpthread###
###uniq separators node1 node2 node3 ... nodeN ###
Split nodes using separators into records, build an ordered list of all records
and make sure only one instance of each record is on the list. Order of record
is as they appear in node values (the list will keep the first occurance
of each record). One or more node names can be specified. \n substitution is
automatically done on node values.
Separators is a single word list of separator characters. The following
escape sequences are interpreted: \n, \t, \s (for space) and \\ (for backslsash).
The output will be separated by the first character of this list.