Hpp

From ReactOS Wiki
Jump to: navigation, search

hpp - header preprocessor

Invocation

Usage: hpp.exe <sourcefile> <destfile>

  • <sourcefile> is a header template. The template file is basicly a header file + some preprocessing commands.
  • <destfile> is the header file that will be created.

Syntax of the prepreprocessor

  • $$ - Start of a comment that will not go into the destination file. Use "$$ // this is a comment".
  • $if(expression) - The following code, up to the closing $endif will be copied to the output file only if the expression evaluetes to true. Example: "$if (USE_THIS_STUFF)" "$if (CONSTANT1 && (!CONSTANT2 || CONSTANT3))"
  • $endif - closes a $if
  • $define(<name>) - defines a name for the prepreprocessor it will be evauated as 1
  • $include(<filename>) - <filename> will be included into this header file. loaction is relative to the header template's location.

examples

foo.ht:

/* This is an autogenerated header */
#ifndef _FOO_
#define _FOO_

$define(_FOO_) // This will make all foobar stuff go into this file
/* foo types */
$include(footypes.h)

/* foo fuctions */
$include(foofuncs.h)

#endif /* !_FOO_ */

foofuncs.h:

$if (0)
/*
 * This comment will not go into the destination file
 * PURPOSE: functions for foo
 */
$endif

$if(_FOO_) // This stuff goes into foo.h
VOID
FOOAPI
FooDoSomething(INT x);

INT
FOOAPI
FooDoNothing();
$endif

$if(_FOO_ || _BAR_)
INT
FooBarExecuteSomeInstructionsAndWaitForOtherStuffWithSecureHandle();
$endif

$if (0) // Here comes the private stuff
INT
FOOAPI
FooNotPublic();
$endif

Making a file a valid header

To make sure all this prepreprocessor commands don't affect the source header, you should define the following macros before including it:

  1. define $$
  2. define $if(x)
  3. define $endif
  4. define $define(x)
  5. define $include(x)

the function that includes foofuncs.h

#ifndef _FOOBAR_PRIV_
#define _FOOBAR_PRIV_

/* Make sure prepreprocessor commands don't do anything */
#define $$
#define $if(x)
#define $endif
#define $define(x)
#define $include(x)

#include <footypes.h>
#include <foofuncs.h>
#include <bartypes.h>
#include <barfuncs.h>

#endif /* !_FOOBAR_PRIV_ */

TODO

  • support different folders than the original one
  • implement $undef(<name>)
  • implemnt $define(<name>=<value>)
  • Get this page right