NAME

Slice -- Extract out pre-defined slices of an ASCII file

SYNOPSIS

slice [-v] [-o sliceterm:outputfile[@chmodcmd] ..] [inputfile]

DESCRIPTION

Input Principle

The slice program reads inputfile (or from stdin if inputfile is not specified or equal "-") and divide its prepaired ASCII contents into possibly overlapping slices. These slices are determined by enclosing blocks which are defined by begin and end delimiters which have to be already in the file. These block delimiters use the syntax

[NAME: ... :NAME]

or alternatively (if there is no mis-interpretation, i.e. no overlapping or stacked slices)

[NAME: ... :]

There can as many such slice definitions as you like and there can be more than one slice with the same name. The resulting slice is the union of all equal named slices. Actually use this to spread a big slice over disjunct peaces of the file.

Output Selection Scheme

The final output gets calculated by a slice term consisting of slice names, set theory operators and optional round brackets. The following syntax is recognized (in order of grammar parsing) for slice terms:

SLICE_TERM ::= !NAME | ~NAME

The complement of slice NAME (i.e. ALL\NAME).

SLICE_TERM ::= NAME1nNAME2 | NAME1*NAME2

The intersection of slices NAME1 and slices NAME2.

SLICE_TERM ::= NAME1xNAME2, NAME1^NAME2

The exclusive or relation between slices NAME1 and slices NAME2.

SLICE_TERM ::= NAME1uNAME2, NAME1+NAME2

The union of slices NAME1 and slices NAME2.

SLICE_TERM ::= NAME1\NAME2, NAME1-NAME2

The difference of slices NAME1 minus slices NAME2.

SLICE_TERM ::= ( SLICE_TERM )

A grouped slice term. Use this to force a different order of evaluation.

Advanced Selection: Slice Levels

Because slices can be overlapping or stacked, a definition level is assigned to each slice while the input is parsed. These levels range from 1 to the maximum encounted (the level 0 is the whole file). When a slice begins it is assigned the lowest free level, beginning with level 1. As long as one level is in use, it cannot be assigned again until the end delimter of the corresponding slice is seen.

An example:

   [A:[B::B]:A][C:[D:[E::C]:D][F::E]:F]

3                     E-----------E
2      B--B        D--------D 
1   A--------A  C--------C     F-----F
0 

Here slice A is assigned level 1. Then B is assigned level 2 because level 1 is still in use by A. Then the end of B is reached, level 2 is freed. Then the end of A is reached and level 1 is also free now, so C is assigned level 1 again. Now only level 1 is in use, so D is assigned level 2. Then E is assigned level 3. Then the end of C is seen and level 1 freed. Then the end of D is seen and level 2 is freed. Now F begins and because only level 3 is in use, it gets level 1 assigned. Then the end of E frees level 3 and the end of F frees level 1. Finally no levels are still in use. This indicates that the slicing is correct. If there are any used levels left at the end this indicates an error and slice will print an error.

This complicated level mechanism is needed for granular set operations where particular slices should be included or excluded only. To make life easier, a few pseudo-slices are automatically defined:

DEFn

The union of all user-defined slices at exactly level n (0 <= n <= maxlevel).

UNDEFn

The union of all not user-defined slices at exactly level n (0 <= n <= maxlevel). Actually this is just !DEFn.

DEF

The union of all user-defined slices at all levels, beginning at 1. Actually this is the union of all DEFn slices.

UNDEF

The union of all non-user-defined slices at all levels, beginning with 1. Actually this is just !DEF.

ALL

The whole file. This actually is just UNDEF0, because at level 0 there are no user defined slices, so all is undefined.

OPTIONS

[-o sliceterm:outputfile[@chmodcmd] ..]

This redirects the output to a file. Usually the whole file will be send to stdout (same as ALL:-). You can use this option more than once to output to more than one file while the corresponding sliceterm determines which contents will be included into each output file.

The optional chmodcmd string is intended for specifying options for the chmod command, which is applied to outputfile after writing. For instance use ``u+x'' to create a file with the execution bit set (usually used for SSI files on a webserver with the XBitHack option available).

-v

This sets verbose mode where some processing information will be given on the console for debugging purpose.

EXAMPLE

Assume the following simple multi-language article file article.src, written in HTML:

<html>
<head>
<title>[EN:Titlepage:][DE:Titelseite:]</title>
</head>
<body>

<center>
<h1>[EN:The Title itself:][DE:Der Titel selbst:]</h1>
</center>

<blockquote>
[EN:...English Abstract...:]
[DE:...Deutsche Zusammenfassung...:]
</blockquote>

[EN:...English Text...:]
[DE:...Deutscher Text...:]

</body>
</html>

Then the command

slice -o ENuUNDEF:article.html.en -o DEuUNDEF:article.html.de

creates the following to files:

article.html.en:
<html>
<head>
<title>Titlepage</title>
</head>
<body>

<center>
<h1>The Title itself</h1>
</center>

<blockquote>
...English Abstract...
</blockquote>

...English Text...
</body>
</html>
article.html.de:
<html>
<head>
<title>Titelseite</title>
</head>
<body>

<center>
<h1>Der Titel selbst</h1>
</center>

<blockquote>
...Deutsche Zusammenfassung...
</blockquote>

...Deutscher Text...
</body>
</html>

RESTRICTIONS

The program is written in Perl and not C, so it is not as fast as it could be. But usually its feature is not needed under any fast runtime situation. Usually slice is used for offline generation of data files. Actually it was developed to generate various HTML files from one source file.

AUTHOR

Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com