=head1 btred

btred - non-interactive scriptable version of the tree editor TrEd

=head1 SYNOPSIS

  btred [-c config-file]
        [-t context] [-m|-I macro-file] [-e code] [-i init-code]
        [-N|-H] [-T] [-S | --no-save] [--knit] [-P] [-F]
        [-s strip-sfx] [-a append-sfx] [-p strip-prefix] [-r add-prefix]
        [-f out-fmt] [-n file-encoding] [-d terminal-encoding]
        [-W] [-q|-Q] [-D] [-V] [-L port] [-b hub]
        [-x extra_attribs] [-X gov,ord?,hide?] [-R]
        [-o script options -- ] [-l file-list] files...
or
  btred -u          for usage
  btred -h          for help
  btred --man       for the manual page

=head1 DESCRIPTION

btred is an off-line TrEd macro processor which applies macros on given files

=head1 OPTIONS

=head2 Filename arguments

Each filename on the command-line or in a file list may be optionally
followed by a suffix which identifies a node to be selected when the
file is opened (this means that C<$this> will point the the selected
node and C<$root> will point to the root of that tree). The suffix can
be of one of the following following forms:

#ID     where ID is an identifier of a node (for file formats that have
        identifiers, e.g. PML).

##N     where N is a number. This selects the root of the N-th tree

##N.M   where N and M are numbers. This selects the M-th node in
        the depth-first order in the N-th tree.

=over 8

=item B<--macro-file|-m> filename

File with macro definitions to load instead of the standard macro file
(by default C<tred.mac>).

WARNING: since extensions may require the standard macro file, using
this option automatically disables all extensions. One may use
C<--enable-extensions extension-list...> to selectively enable
required extensions.

=item B<--include-macro-file|-I> filename

A file containing additional set of macros to load. This option is
typically used instead of C<--macro-file> to allow loading macros
B<both> from C<filename> B<and> the default macro set (C<tred.mac>).
C<--macro-file> can still be used in combination with
B<--include-macro-file> to supply a replacement for C<tred.mac>.

=item B<--execute|-e> perl-code

Macro code to apply to given files. If no code is specified, btred
expects a function called `autostart' to be defined in the used
context and defaults to `autostart()' as the macro code.

The macro code may use all functions defined in a given macro file,
the default macro file tred.def, plus all functions and methods from
Treex::PML (see Treex::PML documentation).

Note, that a lot of information on the current node, file etc. can be
obtained using some pre-defined macro from `tred.def'. The
documentation for `tred.def' is a highly recommended reading for btred
macro coder and macros defined there in should be prefered in all
applicable situations.

As in TrEd, the following variables can be used in macros:

$this - the current node (the root of the first tree in a file at the
beginning)

$root - the root node of the current tree

Among many other, the following functions are defined (see 'tred.def' for a full list):

CurrentFile() - current FSFile object (see section on FSFile in Treex::PML
documentation)

CurrentTreeNumber() - current tree number

CurrentContext() - current macro context

ChangingFile() - - macro may call this function to indicate that the
file should be saved at the end of the pocessing.

=item B<--initial-code|-i> code

Code to be evaluated before any file is open.

=item B<--context|-t>

Start in a given macro context (Perl package).
The default context is `TredMacro'.

=item B<--preload-module|-M> module-name

Preload a given Perl module at btred startup so as it is available to
all macros (even if running in a safe compartment).  This option may
be specified more than once with different modules.

=item B<--filelist|-l> file-list

Read a list of filenames to process from a given file (one filename
per line). Files specified in a file-list are processed prior to files
specified on the command-line. If file-list is a file with .fl
extension, then the first line may contain a file-list name (as in
TrEd). Moreover, unlike in other file-lists, filenames in .fl
file-lists are asssumed to be relative to the file-list file location.

=item B<--glob|-g>

Apply Perl C<glob> function on the filename patterns given on the
command-line.  This expands possible wild-card patterns on each of the
filename command-line argument as the standard Unix shell /bin/csh
would do. This can not only help in a situation where the shell used
does not support wildcard expansion, but can also be used to reduce the
number of the command-line arguments passed to the process in cases
where the argument list would after the shell-expansion exceed a
system limit. By default, this flag is 'on' for the Windows platform
and 'off' on all other systems.

=item B<--strip-prefix|-p> regexp

Remove strings matching a given regexp from the beginning of filenames
before saving.

=item B<--add-prefix|-r> prefix

Prepend output filenames with a given prefix.

=item B<--strip-suffix|-s> regexp

Strip strings matching a given regexp from the end of filenames.

=item B<--add-suffix|-a> suffix

Append a given suffix to the filenames.

=item B<--output-format|-f> [fs|csts|trxml|tei|storable]

Format to use for files being saved.

=item B<--config-file|-c> filename

TrEd configuration file (overrides ~/.tredrc).

=item B<--option|-O> name=value

Override configuration option from the config file with a given
value. This flag can be used several times for different options.

Special syntax of the name part allows some modifications of existing
option values for options that are delimited lists (this cannot be
used to modify default or implicit values):

=over 8

=item nameX=value

Treat the option as a list delimited by the delimiter X and
prepend the value to the list.

=item  nameX+=value

Treat the option as a list delimited by the delimiter X and append the
value to the list.

=item  nameX-=value

Treat the option as a list delimited by the delimiter X and remove the
value from the list (if exists).

=back

Only the following characters can be used as a delimiter:

      ; : , & | / + - \s \t SPACE

where SPACE is a space character, \s matches arbitrary white-space,
and \t matches TAB character.

The options can be combined; for example

  -O "extensionRepos\\s"-=http://foo/bar -O "extensionRepos\\s"+=http://foo/bar

first removes any occurrence of the URL http://foo/bar from the
white-space separated list of extensionRepos and then appends the URL
to the end of the list.

=item B<--resource-dir|-Z> dirname

Specifies resource path. This option can be repeated and overrides
ResoucePath setting in the TrEd configuration file.

Individual paths can also be separated by colon (POSIX/Unix) or
semi-colon (Windows) separator. If there is a lone leading or trailing
separator, the default resource path is prepended or appended,
respectively.

=item B<--all-trees|-T>

Apply the macro code to all trees (wrapping the code into a
C<if ($root) { do {{ CODE }} while TredMacro::NextTree() }> loop).

=item B<--all-nodes|-N>

Apply the macro code tn all nodes (you still must use --all-trees or
-T to aplly to all trees in a file) (wrapping the code into a C<while
($this) { CODE ; $this=$this-E<gt>following };> loop).

=item B<--all-nonhidden-nodes|-H>

Apply the macro code to all nodes except the hidden ones (you still
must use --all-trees or -T to process all trees in a file). This
option wraps the code into a C<while ($this) { CODE ;
$this=$this-E<gt>following_visible(FS()) };> loop).

=item B<--file-encoding|-n> encoding

Allows to specify character encoding of input files (does not apply to
XML files).

=item B<--terminal-encoding|-d> encoding

Automatically apllies a given character encoding to all stdout and
stderr output operations. Works only with Perl >= 5.8.

=item B<--save|-S>

Unconditionally save files after macro code was applied.  By default,
files are saved only if the C<$FileChanged> variable has been set to 1
within the macro code.

=item B<--knit|-K> ALL|NONE|name1,name2,...

If a file is saved, save/update also listed types of reffiles the file
pulled data from. For the moment, this only makes sense with the
C<PML> backend which supports so called B<knitting>, i.e. a method to
pull certain data from external resources and push it back (with all
changes) to the original position in the resource when saving the
file. This option allows to list the types of resources (in PML the
types are the reference names listed in the PML schema) which should
be saved. Default is C<NONE>. This type of resources does not include
so called secondary files.

=item B<--no-save>

Never ever save any files (this way you may protect your files from
being saved even if applying a macro that modifies them and sets
C<$TredMacro::FileChanged> to 1).

=item B<--allow-no-trees|-0>

Allow files with no trees (normaly such files are considered broken).
Note: the short flag is -zero.

=item B<--allow-switch-context>

By default, SwitchContext() macro in btred is a no-op.

If this flag is used, SwitchContext() operates as in TrEd, i.e.  it
changes the macro context and calls allow_switch_context_hook,
pre_switch_context_hook, and switch_context_hook appropriately.

=item B<--safe-mode|-F>

Run macro code in a safe compartment restricting some operations that
could be used by a malicious code writer to explore and compromise the
user's environment and potentially the entire system. Most notably,
this blocks most IO operations. NO WARRANTY! If unsure, do not run the
macro code at all.

=item B<--obey-locks>

If used, btred will refuse to open or overwrite a file that is locked
by TrEd.

=item B<--csts-tree-attributes|-X> gov,ord?,hide?

CSTS format is "many in one"; there may be more tree structures in one
file.  This option can be used to specify which tree structure should
be used.  Provide a comma separated list consisting of names of node
atributes corresponding to CSTS elements that contain the necessary
information to build a tree out of a CSTS file. The first attribute
should be an attribute containing the index of the governing node; the
second one is optional and specifies the ordering attribute; the third
one is also optional and if specified, it should be the attribute used
to mark hidden nodes with the string 'hide'. If the third argument is
specified as empty (i.e. there is a trailing comma), default to
'X_hide' with preset-value 'hide'.

Examples:
  -X govTR,dord  - corresponds to elements <TRg> and <tfr>
                   in CSTS

  -X govMD_c,ord,x_MD_c_hide
                 - corresponds to <MDg src="c">, <r>,
                   and <x name="MD_c_hide">).

=item B<--tectogrammatical-trees|-R>

Build tectogrammatic trees from CSTS files.

=item B<--fs2csts-attributes|-x> list

Comma separated list of FS attribute names that
should be preserved as <x> elements when saving to CSTS.

=item B<--confing-file|-c> filename

Use a given TrEd configuration file.

=item B<--preload-files|-P>

Preload all given files into memory before applying the macros (DOES
NOT WORK WITH RESTRICTED MODE).

=item B<--warn-only|-W>

Do not stop (die) on errors, just warn.

=item B<--validate-fs|-V>

Force Treex::PML to test validity of values assigned to @L (list)
attributes in FS files.

=item B<--quiet|-q>

Print only general processing information on stderr.

=item B<--very-quiet|-Q>

Do not print anything to stderr at all (except for fatal errors).

=item B<--debugging|-D>

Print a lot of debugging information on the stderr.

=item B<--carp>

Replace 'die' with 'Carp::confess', so that a complete stack trace is
printed upon error. Useful for debugging.

=item B<--dump-macros>

Dump all macros currently being loaded to STDOUT and exit. Useful for debugging.

=item B<--server-port|-L> port

Start btred server, listening on a given port; implies -P. Use a
suitable client such as B<ntred> to apply a macro code on the files
possesed by the server.

=item B<--allow-host|-b> hostname

Accept only connections from a given host when operating in the
server-mode.

=item B<--extra-backends|-B> backends

Comma separated list of user-defined IO-backend modules to load.

=item B<--define-symbol|-y> symbol

Symbol name or a name=value pair to be used by macro-preprocessor
(equivalent to a C<#define> instruction at the beginning of the macro
file). Multiple definitions symbols may be separated by a comma and
the option may be repeated.

=item B<--no-secondary-files|-Y>

Neither load or save "secondary" files. Normally, secondary files (if
loaded) are saved along with their primary files (the exactly same
file-name prefix/suffix processing and format apply to both the
primary and secondary files). A secondary file is a file required by a
(normal - primary) file to be loaded along with it; this is typical
for files containing some form of a stand-off annotation where one
tree is built upon another. Note however, that this does not include so
called knitting - an operation where the stand-off annotation is
handled by a IO backend and the resulting knitted file appears to
btred as a single unit.

=item B<--enable-extensions|-j> list

Give a comma-separated list of installed TrEd extension names to
temporarily enable if disabled in the extension configuration.
Use '*' to enable all currently enabled extensions.

=item B<--disable-extensions|-J> list

Give a comma-separated list of installed TrEd extension names to
temporarily disable if enabled in the extension configuration.
Use '*' to disable all currently enabled extensions.

=item B<--list-extensions>

Print out a list of available extensions and exit. Each extension name
is given on a separate line and disabled extensions are preceded by
'!'. This command takes into account options of
B<--disable-extensions> and B<--enable-extensions>, so it can be used
to test their interaction.

=item B<--lib>

Prints path to module directory containing Treex::PML and other TrEd specific
libraries and exit.


=item B<--usage|-u>

Print a brief help message on usage and exits.

=item B<--help|-h>

Prints the help page and exits.

=item B<--man>

Displays the help as manual page.

=back

=head1 LICENSE

This software is distributed under GPL - The General Public Licence.
Full text of the GPL can be found in the LICENSE file distributed with
this program and also on-line at http://www.gnu.org/copyleft/gpl.html.

=head1 AUTHOR

Petr Pajas <pajas@matfyz.cz>

Copyright 2000-2008 Petr Pajas, All rights reserved.

