| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
3.2 Configuration
ffe uses configuration file in order to read the input file and print the output.
Configuration file for ffe is a text file. The file may contain empty lines.
Commands are case sensitive. Comments begin with the #-character and end at the end of the line.
The string definitions can be enclosed in double quotation " characters.
char is a single character. string and char can contain following escape codes:
\a, \b, \t, \n, \v, \f, \r, \" and \#.
A backslash can be escaped as \\.
Configuration has two main parts: the structure, which specifies the input file structure and the output, which specifies how the input data is formatted for output.
Common syntax
Common syntax for configuration file is:
#comment
`command`
const name value
…
structure name {
option value …
…
record name {
option value …
…
}
record name {
option value …
…
}
…
}
structure name {
…
}
…
output name {
option value …
…
}
output name {
…
}
…
lookup name {
option value …
…
}
lookup name {
…
}
…
Structure
Keyword structure is used to specify the input file content. An input file can contain several
types of records (lines or binary blocks). E.g. file can have a header, data and trailer record types. Records
must be distinguishable from each other, this can be achieved defining different ’keys’
(id in record definition) or having different line lengths (for fixed length) or different count
of fields (for separated structure) for different records.
If binary structure has several records, then all records must have at least one key (id), because binary blocks can
be distinguished only by using keys.
The structure notation:
structure name {
option value …
…
}
A structure can contain following options:
type fixed|binary|separated [char] [*]The fields in the input are fixed length fields (text or binary) or text fields separated by char. If * is given, multiple sequential separators are considered as one. Default separator is comma.
quoted [char]Fields may be quoted with char, default quotation mark is the double quotation mark ’"’. A quotation mark is assumed to be escaped as \char or doubling the mark as charchar in input. Non escaped quotation marks are not preserved in output.
header first|all|noControls the occurrence of the header line. Default is no. If set as first or all, the first line of the first input file is considered as header line containing the names of the fields. first means that only the first file has a header, all means means that all files have a header, although the names are still taken from the header of the first file. Header line is handled according the record definition, meaning that the name positions, separators etc. are the same as for the fields. Binary files cannot have a header.
output name|no|rawAll records belonging to this structure are printed according output format name. Default is to use output named as ‘default’. ‘no’ prints nothing and ‘raw’ prints only the original data.
record name {options …}Specifies one record for a structure. A structure can contain several record types.
Record
A record specifies one type of input line or binary block in a file. Different records can be distinguished using
the id option or different line lengths or field counts. In multi-record binary structure every record must have at least one id because binary records do not have a special end of record marker as text lines have.
The record notation:
record name {
option value …
…
}
A record can contain following options:
id position stringrid position regexpIdentifies a record in the input file. Records are identified by the string or by the regular expression regexp in input record position position. For fixed length and binary input the position is the byte position of input record and for separated input the position is the position’th field of the input record. Positions starts always from one.
A record definition can contain several id’s, then all id’s must match the input line (
id’s are and-ed).Non printable characters can be escaped as ‘\xnn’, where ‘nn’ is characters hexadecimal value.
field name|FILLER|* [length]|* [lookup]|* [output]Defines one field in a text input structure. length is mandatory for fixed length input structure.
The last field of a fixed length input structure can have a * in place of length. That means that the last field has no exact length specified and it gets the remainder of the input line after all other fields. This allows a fixed record to have arbitrary long last field.
Length is also used for printing the fields in fixed length format (directive
%Din output definitions).If * is given instead of the name, then the name will be the ordinal number of the field, or if the
headeroption has value first or all, then the name of the field will be taken from the header line (first line of the input).If lookup is given then the fields contents is used to make a lookup in lookup table lookup. If length is not needed (separated format) but lookup is needed, use asterisk (*) in place of length definition.
If output is given the field will be printed using output definition output. If length and/or lookup are not needed use asterisk in place of them.
If field is named as
FILLER, the field will not appear in output.The order of fields in configuration file is essential, it specifies the field order in a record.
field name|FILLER|* length|type [lookup]|* [output]Defines one field in a binary structure. All other features are same as for text structure fields except the type parameter.
type specifies the field length and type and can have the following values:
charPrintable character.
shortShort integer having current system length and byte order.
intInteger having current system length and byte order.
longLong integer having current system length and byte order.
llongLong long integer having current system length and byte order.
ushortUnsigned short integer having current system length and byte order.
uintUnsigned integer having current system length and byte order.
ulongUnsigned long integer having current system length and byte order.
ullongUnsigned long long integer having current system length and byte order.
int88 bit integer.
int16_beBig endian 16 bit integer.
int32_beBig endian 32 bit integer.
int64_beBig endian 64 bit integer.
int16_leLittle endian 16 bit integer.
int32_leLittle endian 32 bit integer.
int64_leLittle endian 64 bit integer.
uint8Unsigned 8 bit integer.
uint16_beUnsigned big endian 16 bit integer.
uint32_beUnsigned big endian 32 bit integer.
uint64_beUnsigned big endian 64 bit integer.
uint16_leUnsigned little endian 16 bit integer.
uint32_leUnsigned little endian 32 bit integer.
uint64_leUnsigned little endian 64 bit integer.
floatFloat having current system length and byte order.
float_beFloat having current system length and big endian byte order.
float_leFloat having current system length and little endian byte order.
doubleDouble having current system length and byte order.
double_beDouble having current system length and big endian byte order.
double_leDouble having current system length and little endian byte order.
bcd_be_lenBcd number having length len and nybbles in big endian order.
bcd_le_lenBcd number having length len and nybbles in little endian order.
hex_be_lenHexadecimal data in big endian order having length len.
hex_le_lenHexadecimal data in little endian order having length len.
If length is given instead of the type, then the field is assumed to be a printable string having length length. String is printed until length characters are printed or NULL character is found.
Bcd number (
bcd_be_lenandbcd_le_len) is printed until len bytes are read or a nybble having hexadecimal valuefis found. Bcd number having big endian order is printed in order: most significant nybble first and least significant nybble second and bcd number having little endian order is printed in order: least significant nybble first and most significant nybble second. Bytes are always read in big endian order.Hexadecimal data (
hex_be_lenandhex_le_len) is printed as hexadecimal values. Big endian data is printed starting from lower address and little endian data starting from upper address.field-count numberSame effect as having "
field *" number times. This can be used in separated structure instead of writing sequential "field *" definitions. Severalfield-counts can be used in the same record and they can be mixed withfield.fields-from recordFields in this record are the same as in record record.
fieldandfields-fromare mutually exclusive.output name|no|rawThis record is printed according to output format name. Default is to use output format specified in structure.
level number [element_name|*] [group_name]Levels can be used to print the file in hierarchical multi-level nested form document. number is the level of the record, starting from number one (highest level), element_name is the name for the record, group_name is used to group records in the same and lower levels. Only number is mandatory. Use * instead of the element name if group name is needed.
record-length strict|minimumstrictInput record length (fixed format) or field count (separated format) must match the record definition in order to get it processed. This is the default value.
minimumInput record length or field count can be the same or longer as defined for the record. The rest of the input line is ignored.
Output
Keyword output specifies a output format for formatting the input data for output. Formatting
is controlled using options and printf style directives. An output definition is independent
from structur, so one output format can be used with different input file formats.
The output notation:
output name {
option value …
…
}
Actual formatting and printing is controlled using pictures in output options. Pictures can contain following printf style directives:
%fName of the input file.
%sName of the current structure.
%rName of the current record.
%oInput record number in current file.
%OInput record number starting from the first file.
%iByte offset of the current record in the current file. Starts from zero.
%IByte offset of the current record starting from the first file. Starts from zero.
%nField name.
%tField contents, without leading and trailing whitespaces.
%dField contents. Binary integer is printed as a decimal value. Floating point number is printed in the style
[-]ddd.ddd, where the number of digits after the decimal-point character is 6. Bcd number is printed as a decimal number and hexadecimal data as consecutive hexadecimal values.%DField contents, right padded to the field length (requires length definition for the field).
%CField contents, right padded to the field length (requires length definition for the field). Contents is cutted if the input field is longer than output length.
%xUnsigned hexadecimal value of a binary integer. Other fields are printed as directive
%dwould be used.%lLookup value which has been found using current field as a search key.
%LLookup value, right padded to the field length.
%pFields start position in a record. For fixed and binary structure this is field’s byte position in the input line and for separated structure this is the ordinal number of the field. Starts from one.
%hHexadecimal dump of a field. Byte values are printed as consecutive
xnnvalues, where thennis the hexadecimal value of a byte. Data is printed before any endian conversion.%eDoes not print anything, causes still the "field empty" check to be performed. Can be used when only the names of non-empty fields should be printed.
%gGroup name given by the keyword
group_namein record definition.%mElement name given by the keyword
element_namein record definition.%%Percent sign.
Output options:
file_header picturepicture is printed once before file contents.
file_trailer picturepicture is printed once after file contents.
header pictureIf given, then the header line describing the field names is printed before records. Every field name is printed according the picture using the same separator and field length as given for the fields. Picture can contain only
%ndirective.data pictureField contents is printed according picture.
lookup pictureIf current field is related to lookup table, then this picture is used instead of picture from
data. This makes possible to use different picture when the field is related to a lookup table. Default is to use the picture fromdata.separator stringAll fields are terminated by string, except the last field of the record. Default is not to print separator.
record_header picturepicture is printed before the record content. Default is not to print the record header.
record_trailer picturepicture is printed after the record content. Default is newline.
justify left|right|charThe output from the
dataoption is left or right justified. char justifies output according the first occurrence of char in the data picture. Default is left.indent stringRecord contents is intended by string. Field contents is intended by two times the string. Default is not to indent. If file contents is printed in hierarchial form (keyword
levelin record definition) then contents is indented according the level of a record.field-list name1,name2,…Only fields and constants named as name1,name2,… are printed, same effect as has option ‘-f’. Default is print all fields and no constants. Fields and constants are also printed in the same order as they are listed.
no-data-print yes|noIf
field-listis given and and this is set as no and none of the fields infield-listdoes not belong to the current record, then therecord_headerandrecord_trailerare not printed. Default is yes.field-empty-print yes|noWhen set as no, nothing is printed for the fields which consist entirely of characters from
empty-chars. If none of the fields of a record are printed, then the printing ofrecord_traileris also suppressed. Default is yes.empty-chars stringstring specifies a set of characters which consist an "empty" field. Default is " \f\n\r\t\v" (space, form-feed, newline, carriage return, horizontal tab and vertical tab).
output-file fileOutput is written to file instead of the default output (standard output or given by ‘-o, --output’). If - is given the output is written to standard output.
group_header pictureIf a record has a level and a group name defined, picture is printed before the first record in a group or if the group name has changed in the same level. Note: Level related pictures can contain printing directives
%gand%nonly.group_trailer pictureIf a record has a level and a group name defined, picture is printed after the records in lower levels are printed or if the group name has changed in the same level or if a higher level record is found.
element_header pictureIf a record has a level and a element name defined, picture is printed before the records contents.
element_trailer pictureIf a record has a level and a element name defined, picture is printed after the records contents or after the following lower level records.
hex-caps yes|noPrint hexadecimal numbers in capital letters. Default is no.
Lookup
Keyword lookup specifies a lookup table which can be searched using field contents. Found values can
be printed using output directives %l and %L.
The lookup table notation:
lookup name {
option value …
…
}
Lookup options:
search exact | longestSearch method for this table. Either exact or longest match is used when searching the table. Default is
exact.pair key valueDefines one key/value pair for the lookup table. In case of binary file key must have the same representation as can be shown using the
%dprinting directive.file name [separator]Data for the lookup table is read from file name. Each line in file name is considered as a key/value pair separated by a single character separator. Default separator is semicolon. Lines without separator are silently omitted. Note: The file size is limited by available memory because the file contents is loaded to memory.
default-value valueIf searching the lookup table is unsuccessful then value is used in printing. Default is empty string.
Constants
Keyword const specifies one name/value pair which can be used as an additional output field.
Constants can be used only in field lists (option ‘-f,--field-list’, or output option field-list).
Constants can be used to add fields to output which do not appear in input. E.g. new fields for separated output or adding spaces after a fixed length field (changing the field length).
Note that value is printed as it is for every record. It cannot be changed record by record.
If a constant has the same name as one of the input fields, the value value is printed instead of the input field contents.
The constant notation:
const name value
When name appears in field list it is treated as one of the input fields having contents value.
Command Substitution
Command Substitution allows the output of a command to replace parts of the configuration file. Syntax for
command substitution is:
‘command‘
The command is executed and the ‘command‘ is substituted with the standard output of
the command, with any trailing newlines deleted. Command substitutions may not be nested.
Before executing the command ffe sets following environment variables:
FFE_STRUCTUREThe name of the structure from ‘-s,--structure’.
FFE_OUTPUTThe name of the output file from ‘-o,--output’.
FFE_FORMATThe name of the output format from ‘-p,--print’.
FFE_FIRST_FILEThe name of the first input file.
FFE_FILESA space-separated list of all input files.
If variable is already set it will not be replaced.
Input Preprocessor
It is possible to define an input preprosessor for ffe. An input preprocessor is simply an executable program
which writes the contents of the input file to standard output which will be read by ffe. If the input preprosessor
does not write any characters on its standard output, then ffe uses the original file.
To set up an input preprocessor, set the FFEOPEN environment variable to a command line which will invoke your input preprocessor.
This command line should include one occurrence of the string %s,
which will be replaced by the input filename when the input preprocessor command is invoked.
The input preprocessor is not used if ffe is reading standard input.
Convenient way is to use lesspipe (or lesspipe.sh), which is availabe in many UNIX-systems, for example
export FFEOPEN="/usr/bin/lesspipe %s"
Using the example above is it possible to give a zipped input file to ffe, then the input processor will unzip the
file before it is processed by ffe.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 30, 2014 using texi2html 5.0.
