cauxp is a tool for doing some additional preprocessing which compliments the C preprocesor. It shoudl be run before the C processor ( or more typically, before the compiler which will invoke the standard preprocessor automatically ).
The simplest way to show how cauxp works is to give examples.
Using the command directive sends the source data in the file to an external tool and outputs the results. The section to ends with a hash character on an empty line ( which is the way cauxp typically denotes the end of a section of input ).
#command ./toupper
this was all in lower case
and should be in upper case
in the output
#
In C it's common to create multiple constants with identical prefixes and postfixes. These are tedious to type and a pain if you have to change the prefix or postfix for any reason.
It's also common to create multiple flags for binary masks, again a tedious task for editing.
cauxp provides a few methods to handle these.
#constants SJG TEST
FIRST
SECOND
THIRD
FOURTH
FIFTH
#
This would create output like :
#define SJG_FIRST_TEST 0
#define SJG_SECOND_TEST SJG_FIRST_TEST + 1
#define SJG_THIRD_TEST SJG_FIRST_TEST + 2
#define SJG_FOURTH_TEST SJG_FIRST_TEST + 3
#define SJG_FIFTH_TEST SJG_FIRST_TEST + 4
To create flags or masks :
#flags SJG FLAG
ALPHA
BETA
GAMMA
OMEGA
DELTA
#
Which generates :
#define SJG_ALPHA_FLAG 0x01
#define SJG_BETA_FLAG 0x02
#define SJG_GAMMA_FLAG 0x04
#define SJG_OMEGA_FLAG 0x08
#define SJG_DELTA_FLAG 0x010
Explicit values for constants can be generated as well :
#constants-negative SJG NEG
FIRST
SECOND
THIRD
FOURTH
FIFTH
#
#constants-values SJG VALS
FIRST
SECOND
THIRD
FOURTH
FIFTH
#
There are a couple of additions to allow multiline defines to be created without using end of line continuation markers. THis is useful not only for avoiding potential issues due to missing markers, but because code coloring algorithms used in editors typically don't like multi-line macros with continuations. Using these macros allows you to use the your editor's coloring features fully, which can often help avoid tedious typos and bugs.
The first method simply adds end of line continuation markers to a section ( including any blank lines ).
#quote #define grey(a,b,c)
if( a > b )
{
b = a ;
}
else
{
a = b ;
}
if( b > c )
{
c = b ;
}
else
{
b = c ;
}
#
~~~~~~~~~~
#define grey(a,b,c) \
if( a > b ) \
{ \
b = a ; \
} \
else \
{ \
a = b ; \
} \
\
if( b > c ) \
{ \
c = b ; \
} \
else \
{ \
b = c ; \
}
~~~~~~~~~~~~~
Note this does no special work on anything inside the quoted block.
The second method is specific to multiline defines. It not only adds teh continuation markers to the end of lines, it also handles teh tedious business of parameter substitution brackets. References to the macro parameters will be bracketed automatically in the output, which is generally desireable in macros but tedious to code and maintain - indeed it is the source of many errors.
#def wibble( m, n, p )
{
int n1 = 2 ;
if( n > m )
m = n ;
else
n = m ;
if( n*m == m*p ) m = n + p ; else n = m + p ;
printf( "This is a single n on it's own\n" ) ;
printf( "This is an escaped quote \" followed by an n on it's own inside a quoted string\n" ) ;
if( p > n )
{
m = p ;
n = p ;
}
else
{
p = n ;
}
if( m > stuff )
m = stuff ;
if( n > n2 )
n = stuff ;
if( p > stuff )
p = stuff ;
}
#
This would output :
#define wibble( m, n, p ) \
{ \
int n1 = 2 ; \
\
if( (n) > (m) ) \
(m) = (n) ; \
else \
(n) = (m) ; \
\
if( (n)*(m) == (m)*(p) ) (m) = (n) + (p) ; else (n) = (m) + (p) ; \
\
printf( "This is a single n on it's own\n" ) ; \
\
printf( "This is an escaped quote \" followed by an n on it's own inside a quoted string\n" ) ; \
\
if( (p) > (n) ) \
{ \
(m) = (p) ; \
(n) = (p) ; \
} \
else \
{ \
(p) = (n) ; \
} \
\
if( (m) > stuff ) \
(m) = stuff ; \
if( (n) > n2 ) \
(n) = stuff ; \
if( (p) > stuff ) \
(p) = stuff ; \
}
The skipon and skipoff directives are useful.
#skipon
/* The source file had a skipon directive before this and it should
* not be in the output.
*/
/* The source file has a skipoff directive after this comment and it should
* not be in the output.
*/
#skipoff
To create neat comments use the comment directive.
#comment
The comment directive was made inside a skipon-skipoff section and
should still be in the output file. It should not have been processed.
#
This would generate :
/*
* The comment directive was made inside a skipon-skipoff section and
* should still be in the output file. It should not have been processed.
*/
As trivial as this may seem it can take the pain out of commenting code.
The wiki uses Markdown syntax.