manpagez: man pages & more
info ffe
Home | html | info | man
[ << ] [ < ] [ 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|no

Controls 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|raw

All 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 string
rid position regexp

Identifies 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 %D in output definitions).

If * is given instead of the name, then the name will be the ordinal number of the field, or if the header option 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:

char

Printable character.

short

Short integer having current system length and byte order.

int

Integer having current system length and byte order.

long

Long integer having current system length and byte order.

llong

Long long integer having current system length and byte order.

ushort

Unsigned short integer having current system length and byte order.

uint

Unsigned integer having current system length and byte order.

ulong

Unsigned long integer having current system length and byte order.

ullong

Unsigned long long integer having current system length and byte order.

int8

8 bit integer.

int16_be

Big endian 16 bit integer.

int32_be

Big endian 32 bit integer.

int64_be

Big endian 64 bit integer.

int16_le

Little endian 16 bit integer.

int32_le

Little endian 32 bit integer.

int64_le

Little endian 64 bit integer.

uint8

Unsigned 8 bit integer.

uint16_be

Unsigned big endian 16 bit integer.

uint32_be

Unsigned big endian 32 bit integer.

uint64_be

Unsigned big endian 64 bit integer.

uint16_le

Unsigned little endian 16 bit integer.

uint32_le

Unsigned little endian 32 bit integer.

uint64_le

Unsigned little endian 64 bit integer.

float

Float having current system length and byte order.

float_be

Float having current system length and big endian byte order.

float_le

Float having current system length and little endian byte order.

double

Double having current system length and byte order.

double_be

Double having current system length and big endian byte order.

double_le

Double having current system length and little endian byte order.

bcd_be_len

Bcd number having length len and nybbles in big endian order.

bcd_le_len

Bcd number having length len and nybbles in little endian order.

hex_be_len

Hexadecimal data in big endian order having length len.

hex_le_len

Hexadecimal 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_len and bcd_le_len) is printed until len bytes are read or a nybble having hexadecimal value f is 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_len and hex_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 number

Same effect as having "field *" number times. This can be used in separated structure instead of writing sequential "field *" definitions. Several field-counts can be used in the same record and they can be mixed with field.

fields-from record

Fields in this record are the same as in record record. field and fields-from are mutually exclusive.

output name|no|raw

This 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|minimum
strict

Input 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.

minimum

Input 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:

%f

Name of the input file.

%s

Name of the current structure.

%r

Name of the current record.

%o

Input record number in current file.

%O

Input record number starting from the first file.

%i

Byte offset of the current record in the current file. Starts from zero.

%I

Byte offset of the current record starting from the first file. Starts from zero.

%n

Field name.

%t

Field contents, without leading and trailing whitespaces.

%d

Field 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.

%D

Field contents, right padded to the field length (requires length definition for the field).

%C

Field 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.

%x

Unsigned hexadecimal value of a binary integer. Other fields are printed as directive %d would be used.

%l

Lookup value which has been found using current field as a search key.

%L

Lookup value, right padded to the field length.

%p

Fields 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.

%h

Hexadecimal dump of a field. Byte values are printed as consecutive xnn values, where the nn is the hexadecimal value of a byte. Data is printed before any endian conversion.

%e

Does 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.

%g

Group name given by the keyword group_name in record definition.

%m

Element name given by the keyword element_name in record definition.

%%

Percent sign.

Output options:

file_header picture

picture is printed once before file contents.

file_trailer picture

picture is printed once after file contents.

header picture

If 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 %n directive.

data picture

Field contents is printed according picture.

lookup picture

If 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 from data.

separator string

All fields are terminated by string, except the last field of the record. Default is not to print separator.

record_header picture

picture is printed before the record content. Default is not to print the record header.

record_trailer picture

picture is printed after the record content. Default is newline.

justify left|right|char

The output from the data option is left or right justified. char justifies output according the first occurrence of char in the data picture. Default is left.

indent string

Record 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 level in 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|no

If field-list is given and and this is set as no and none of the fields in field-list does not belong to the current record, then the record_header and record_trailer are not printed. Default is yes.

field-empty-print yes|no

When 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 of record_trailer is also suppressed. Default is yes.

empty-chars string

string 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 file

Output 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 picture

If 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 %g and %n only.

group_trailer picture

If 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 picture

If a record has a level and a element name defined, picture is printed before the records contents.

element_trailer picture

If 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|no

Print 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 | longest

Search method for this table. Either exact or longest match is used when searching the table. Default is exact.

pair key value

Defines 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 %d printing 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 value

If 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_STRUCTURE

The name of the structure from ‘-s,--structure’.

FFE_OUTPUT

The name of the output file from ‘-o,--output’.

FFE_FORMAT

The name of the output format from ‘-p,--print’.

FFE_FIRST_FILE

The name of the first input file.

FFE_FILES

A 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.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.