Content-type: text/html Manpage of FILEPP

FILEPP

Section: User Commands (1)
Updated: Mar 25 2001
Index Return to Main Contents
 

NAME

filepp - A generic file preprocessor  

SYNOPSIS

filepp [options] filename(s)  

DESCRIPTION

filepp is a generic file preprocessor designed to allow the functionality provided by the C preprocessor cpp(1) to be used with any file type. filepp is designed to be easily customised and extended.  

OPTIONS

filepp accepts the following command line options:
-c
Read input from STDIN instead of a file.
-Dmacro
Predefine macro to have a definition of `1'.
-Dmacro=defn
Predefine macro to have a definition of defn.
-d
Output debugging information.
-dd
Output verbose debugging information. This option shows all normal debugging information, plus full list of defined macros every time list changes.
-h
Show summary of options.
-Idir
Append directory dir to the list of directories searched for include files.
-k
Turn off parsing of all keywords. This is useful if you just want to use the macro expansion facilities of filepp. With this option all keywords found will be ignored, filepp will just replace any macros specified with the -Dmacro=defn option.
-kc char
Set keyword prefix character to char (can also be a string). All filepp keywords are prefixed with the character # by default. This option allows the prefix to be changed to something else.
-lc char
Set line continuation character to char (can also be a string). When the line continuation character is found with a newline following it, it and the newline are replaced by the line continuation replacement character. Default is \ (cpp(1) style).
-lr char
Set line continuation replacement character to char (can also be a string). Default is a null string (cpp(1) style).
-lrn
Set line continuation replacement character to be a newline.
-m module.pm
Load module module.pm. module.pm is a perl(1) module which can be used to extend or modify the behaviour of filepp. See section FILEPP MODULES for more details.
-o name
Write output to name instead of STDOUT. If there is only one input file and it has the same name as the output file, the original input file will be backed-up as name~.
-s
Run filepp in safe mode. This turns off the pragma keyword.
-u
Undefine all currently defined macros, including predefined ones.
-v
Show version of program.
-w
Turn on word boundaries when replacing macros. When word boundaries are on, macros will only be replaced if the macro appears in the text as a word. For example, by default macro would be replaced in both cases of the following text:

macro as word, macroNOTaword

but only the first occurence would be replaced with the -w option.

With this option enabled filepp will only replace macros which contain alphanumeric characters. International (non-ASCII) character sets can be supported using Perl's locale handling.

 

KEYWORDS

filepp supports the following keywords:
#include <FILE>
Include a file in the file being processed. This variant is used for "system" include files. It searches for a file named FILE in a list of directories specified by you. Directories are specified with the command option `-I'. filepp does not predefine any system directories in which to search for files.
#include FILE
Include a file in the file being processed. This variant is used for include files of your own project. It searches for a file named FILE first in the current directory, then in the list of directories specified with the command option `-I'. The current directory is the directory the base input file is in.
#define macro
Define the macro macro to have a definition of `1'. macro can then be used with the keywords #ifdef and #ifndef.
#define macro defn
Define the macro macro to have the value defn. macro can then be used with the keywords #ifdef and #ifndef. Also, all instances of macro following the #define statement will be replaced with the string defn. The string defn is taken to be all the characters on the line following macro.
#define macro(arg1, arg2, ...) defn
Define the macro macro to have the value defn with arguments (arg1, arg2, ...). macro can be used as follows:

#define macro(foo) defn with foo in

Now when replacing occurs:

macro(bar)

will become:

defn with bar in

Macros can have any number of comma separated arguments.

#if expr
A conditional statement, expr will be evaluated to true (1) or false (0). If expr evaluates to true, the text between the #if and the next #else or #endif will be included. If expr evaluates to false, the text between the #if and the next #else or #endif will be ignored. expr can use all the usual cpp style comparisons (==, !=, <, >, etc.). Multiple comparisons can be combined with and (&&) and or (||). The defined keyword can also be used to check if macros are defined. For example:

#if defined macro && macro == defn

(Note to filepp experts: #if works by first parsing expr for the defined keyword and checking if the macro it refers to is defined, replacing it with 1 if it is and 0 if it isn't. It then checks expr for any other macros and replaces them with their definition. Finally it passes expr through Perl's eval function, which returns true or false.)

#elif expr
#elif stands for "else if". Like #else, it goes in the middle of a #if[n][def]-#endif pair and subdivides it; it does not require a matching #endif of its own. Like #if, the #elif directive includes an expression to be tested.
#ifdef macro
A conditional statement, if macro has been defined the text between the #ifdef and the next #else or #endif will be included. If macro has not been defined the text between the #ifdef and the next #else or #endif will be ignored.
#ifndef macro
The reverse case of the #ifdef conditional.
#else
The #else directive can be added to a conditional to provide alternative text to be used if the condition is false.
#endif
Used to terminate a conditional statement. Normal processing resumes following the #endif.
#undef macro
Undefine a previously defined macro.
#error mesg
Causes filepp to exit with the error message mesg.
#warning mesg
Causes filepp to issue the warning message mesg.
#comment mesg
As filepp is supposed to be a generic file preprocessor, it cannot support any known comment styles, therefore it defines its own with this keyword. All lines starting with #comment are treated as comments and removed by filepp.
#pragma filepp function arg1, arg2, ...
The #pragma keyword immediately followed by the word filepp allows the user to execute a Perl function during parsing. The word immediately following filepp is taken as the name of the function and the remainder of the line is taken to be a comma separated list of arguments to the function. Any of the filepp internal functions (see section FILEPP MODULES) can be called with the #pragma keyword.

Warning: There are obvious security risks with allowing arbitrary functions to be run, so the -s (safe mode) command line option has been added which turns the #pragma keyword off.

 

PREDEFINED MACROS

filepp supports a set of predefined macros. All the predefined macros are of the form __MACRO__, where MACRO is:
FILE
This macro expands to the name of the current input file.
LINE
This macro expands to the current input line number.
DATE
This macro expands to a string that describes the date on which the preprocessor is being run. The string contains eleven characters and looks like "Mar 25 2001".
ISO_DATE
This macro expands to a string that describes the date on which the preprocessor is being run. The string is in the format specified by ISO 8601 (YYYY-MM-DD) and looks like "2001-3-25".
TIME
This macro expands to a string that describes the time at which the preprocessor is being run. The string contains eight characters and looks like "18:15:37".
BASE_FILE
This macro expands to the name of the main input file.
INCLUDE_LEVEL
This macro expands to a decimal integer constant that represents the depth of nesting in include files. The value of this macro is incremented on every #include directive and decremented at every end of file.
NEWLINE
This macro expands to a newline.
NULL
This macro expands to nothing. It is useful if you want to define something to be nothing.
VERSION
This macro expands to a string constant which describes the version number of filepp. The string is a sequence of decimal numbers separated by periods and looks like "1.2.2".
FILEPP_INPUT
This macro expands to a string constant which says the file was generated automatically from the current BASE_FILE and looks like "Generated automatically from filepp.1.in by filepp".
 

FILEPP MODULES

The behaviour of filepp can be modified or extended through the use of modules. filepp modules are in fact perl(1) modules, and the rest of this section assumes the reader has a knowledge of Perl.

filepp modules are perl(1) modules which extend or modify filepp's behaviour by either calling or replacing filepp's internal functions. filepp has the Perl package name Filepp so its internal functions can be called within modules either as Filepp::function() or just function(). Any of filepp's internal functions can be called or replaced from within a filepp module, the most useful ones are:

Debug($string)
Print $string as debugging information if debugging is enabled.
AddKeyword($string,$function)
Add the keyword named $string. When the keyword is found in text processing the function named $function will be run with everything following the keyword passed as a single argument.
RemoveKeyword($string)
Removes the keyword named $string.
RemoveAllKeywords()
Removes all the keywords currently defined for filepp (used for the -k command line option).
AddIfword($string)
Adds keyword named $string to Ifword list. An Ifword takes in the string following the keyword and optionally parses it, returning a 1 if the string parses to true and 0 for false. The default Ifwords are if, ifdef and ifndef.
RemoveIfword($string)
Removes keyword named $string from Ifword list (note: this does NOT remove the keyword, use RemoveKeyword for that).
AddElseword($string)
Adds keyword named $string to Elseword list. An Elseword takes in the string following the keyword and optionally parses it, returning a 1 if the string parses to true and 0 for false. The default Elsewords are else and elif.
RemoveElseword($string)
Removes keyword named $string from Elseword list.
AddEndifword($string)
Adds keyword named $string to Endifword list. An Endifword has no input or output. The default Endifword is endif.
RemoveEndifword($string)
Removes keyword named $string from Endifword list.
SetKeywordchar($string)
Set the initial keyword char to $string (used for the -kc command line option).
SetContchar($string)
Set the line continuation char to $string (used for the -lc command line option).
SetContrepchar($string)
Set the line continuation replacement char to $string (used for the -lr command line option).
SetOutput(1/0)
Turns writing of parsed input file to output file on/off. This takes either 1 (output on) or 0 (output off) as input. When the output is turned off, the only output produced from filepp will be that generated by the module.
ToggleWordBoundaries()
Turns on word boundary checking when replacing macros, or turns it off if it is on (used for the -w command line option).
UndefAll()
Undefines all currently defined macros, including predefined ones (used for the -u command line option).
UseModule($string)
Loads a perl(1) module named $string using the Perl command require (used for the -m command line option).
$string=GetNextLine()
Returns the next line (after line continuation has been dealt with) of the input file currently being processed. Returns NULL for end of file.
Write($string)
Writes $string to the current output file.

In addition all the standard filepp keywords have equivalent functions which optionally take a single argument. The functions have the same name as the keyword, only with a capital first letter (eg: #define string calls the function Define(string)).

The main function in filepp is Parse($filename), which opens the input file $filename and parses it. A full description of the Parse function and all the other filepp internal functions is beyond the scope of this man page. The filepp script is well commented and hopefully readable by a Perl programmer, so use the source Luke!

 

BUGS

filepp has no known bugs, only "features". If you find any "features", please report them to the author.  

COPYING

Copyright (C) 2000-2001 Darren Miller

filepp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  

SEE ALSO

cpp(1), perl(1)  

AUTHOR

Darren Miller <darren@cabaret.demon.co.uk>.


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
KEYWORDS
PREDEFINED MACROS
FILEPP MODULES
BUGS
COPYING
SEE ALSO
AUTHOR

This document was created by man2html, using the manual pages.
Time: 17:15:37 GMT, March 25, 2001