home *** CD-ROM | disk | FTP | other *** search
- USER MANUAL FOR SPPLIB
- =======================
-
- Version 0.1
- G.C.Wraith, August 1997
-
- SPPLIB is a Simple PreProcessor C Library. Preprocessors work
- line by line, which makes it feasible to have an input function,
- spp_fgets, which performs the same function as fgets in stdio.h,
- but which, in addition, preprocesses the input. This preprocessor
- is simpler, and more general, than the usual C preprocessor. Its
- directives are described below.
-
- SPPLIB consists of this text file, a header file h.spp, and an Acorn
- Library Format (ALF) file o.spp, and a simple example of a C program
- Example.c.test. This shows how to use the functions spp_init and spp_fgets
- to write a minimal preprocessor using SPPLIB.
-
- These files are not in the public domain; they belong to me. They are
- freeware in the sense that you may distribute and use them freely, and
- need not pay for them. You may not, however, (1) distribute modified
- copies, or (2) make money from the programs or documentation in
- any way. You may, of course, modify your own copy; but you must
- not then distribute it. If you have modifications that you think are
- improvements, please get in touch with me at the address below and tell
- me more. It is quite likely that there are features and bugs which I have
- not yet discovered. The code is StrongArm compatible.
-
- SPPLIB provides three functions:
-
- extern void spp_init(char *fname); /* initialise - use before the others. Do
- not use again until spp_fgets returns
- 0 or spp_fclose is called.*/
- extern int spp_fgets(char *buf); /* read a line of preprocessed
- input into buf - returns 0 when no more */
- extern int spp_fclose(void); /* shut-down - only needed for error
- handling as spp_fgets will have closed all
- the files by the time it returns 0 */
-
- SPP
- ===
- SPP is not aimed specifically at C, which may make some of its behaviour
- appear odd to those who are familiar with the C preprocessor. The aim
- is for it to be useful for language writers. However, some syntactic choices
- have to be made.
-
- Comments
- --------------
- SPP removes comments, which have the same syntax as comments
- C++; that is:
-
- 1) single line comments, introduced by // and terminated by the end of
- the line or the end of the file.
-
- 2) multiline comments, introduced by /* and terminated by */. Multiline
- comments are not nestable.
-
- Strings
- ---------
- SPP will complain if double-quotes (") do not occur in pairs. However, strings
- are not recognised as single tokens, so that double-quotes will not hide comment
- initiators and terminators.
-
- Directives
- -------------
- SPP directives must be placed at the beginning of the line, with no preceding
- whitespace. If they take an argument they must be separated from it by whitespace.
- They are:
-
- #include <filename>
-
- Include the file specified by <filename>. Note that <filename>
- can be any valid file descriptor in Risc OS, e.g
-
- #include MyVar:mydir.myfile
-
- #includes can be nested up to 8 deep.
-
- #define <macroname> <macrobody>
-
- The syntax for macros follows that of Risc OS. <macroname> must
- not contain whitespace, but <macrobody> can. Formal parameters
- occur in <macrobody> as %0, %1, ... %9 just as in Obey files. %*n
- stands for all the arguments from the n-th one onwards. Macro
- substitution converts %% to %. When macro substitution takes place
- the argument list is a string of space-separated items following the
- macro's name. Beware of invisible, but significant, whitespace at the
- end of macro bodies.
-
- Example:
-
- #define abs (%0)?(%0):(-%0)
-
- y = abs x ;
-
- Note the necessary space between x and ;.
- Macro substitution does not take place within SPP directives.
-
- #undef <macroname>
-
- Undefine the macro called <macroname>.
-
- #ifdef <macroname>
- #ifndef <macroname>
- #else
- #endif
-
- Conditional inclusion or exclusion of text.
- The #if(n)def/#endif constructs may be nested up to 8 deep.
-
- Errors
- --------
- SPP will produce error messages indicating the file and line on which the
- error occurred.
- ----------------------------------------------------------------------------------------------
- Gavin Wraith
- mailto: gavin@wraith.u-net.com
- http://www.wraith.u-net.com/
-