home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devtools / cpp / cpp.c next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  9.5 KB  |  259 lines

  1. RCS_ID_C="$Id: cpp.c,v 1.2 1994/03/07 23:52:39 jraja Exp $";
  2. /*
  3.  * cpp -- a C PreProcessor suitable to be used with rpcgen
  4.  */
  5.  
  6. #include "cpp_rev.h"
  7.  
  8. const char version[] = VERSTAG;
  9.  
  10. /****** devtools.doc/cpp ****************************************************
  11.  
  12.     NAME
  13.         cpp - C Pre-Processor
  14.  
  15.     SYNOPSIS
  16.         cpp [-options] [infile [outfile]]
  17.  
  18.     DESCRIPTION
  19.         CPP reads a C source file, expands macros and include files, and
  20.         writes an input file for the C compiler.  If no file arguments are
  21.         given, CPP reads from stdin and writes to stdout.  If one file
  22.         argument is given, it will define the input file, while two file
  23.         arguments define both input and output files.  The file name "-" is
  24.         a synonym for stdin or stdout as appropriate.
  25.  
  26.         The following options are supported.  Options may be given in either
  27.         case.
  28.  
  29.         -C             If set, source-file comments are written to the
  30.                        output file.  This allows the output of CPP to be
  31.                        used as the input to a program, such as lint, that
  32.                        expects commands embedded in specially-formatted
  33.                        comments.
  34.  
  35.         -Dname=value   Define the name as if the programmer wrote
  36.  
  37.                            #define name value
  38.  
  39.                        at the start of the first file.  If "=value" is not
  40.                        given, a value of "1" will be used.
  41.  
  42.                        On non-unix systems, all alphabetic text will be
  43.                        forced to upper-case.
  44.  
  45.         -E             Always return "success" to the operating system, even
  46.                        if errors were detected.  Note that some fatal
  47.                        errors, such as a missing #include file, will
  48.                        terminate CPP, returning "failure" even if the -E
  49.                        option is given.
  50.  
  51.         -Idirectory    Add this directory to the list of directories
  52.                        searched for #include "..."  and #include <...>
  53.                        commands.  Note that there is no space between the
  54.                        "-I" and the directory string.  More than one -I
  55.                        command is permitted.  On non-Unix systems
  56.                        "directory" is forced to upper-case.
  57.  
  58.         -N             CPP normally predefines some symbols defining the
  59.                        target computer and operating system.  If -N is
  60.                        specified, no symbols will be predefined.  If -N -N
  61.                        is specified, the "always present" symbols, __LINE__,
  62.                        __FILE__, and __DATE__ are not defined.
  63.  
  64.         -P             Do not output #line directives.
  65.  
  66.         -Stext         CPP normally assumes that the size of the target
  67.                        computer's basic variable types is the same as the
  68.                        size of these types of the host computer.  (This can
  69.                        be overridden when CPP is compiled, however.)  The -S
  70.                        option allows dynamic respecification of these
  71.                        values.  "text" is a string of numbers, separated by
  72.                        commas, that specifies correct sizes.  The sizes must
  73.                        be specified in the exact order:
  74.  
  75.                            char short int long float double
  76.  
  77.                        If you specify the option as "-S*text", pointers to
  78.                        these types will be specified.  -S* takes one
  79.                        additional argument for pointer to function (e.g.
  80.                        int (*)())
  81.  
  82.                        For example, to specify sizes appropriate for a
  83.                        PDP-11, you would write:
  84.  
  85.                               c s i l f d func
  86.                             -S1,2,2,2,4,8,
  87.                            -S*2,2,2,2,2,2,2
  88.  
  89.                        Note that all values must be specified.
  90.  
  91.         -Uname         Undefine the name as if
  92.  
  93.                            #undef name
  94.  
  95.                        were given.  On non-Unix systems, "name" will be
  96.                        forced to upper-case.
  97.  
  98.         -Xnumber       Enable debugging code.  If no value is given, a value
  99.                        of 1 will be used.  (For maintenence of CPP only.)
  100.  
  101.  
  102.     PRE-DEFINED VARIABLES 
  103.         When CPP begins processing, the following variables will have been
  104.         defined (unless the -N option is specified):
  105.  
  106.         Target computer (as appropriate):
  107.  
  108.             pdp11, vax, M68000 m68000 m68k
  109.  
  110.         Target operating system (as appropriate):
  111.  
  112.             rsx, rt11, vms, unix
  113.  
  114.         Target compiler (as appropriate):
  115.  
  116.             decus, vax11c
  117.  
  118.         The implementor may add definitions to this list.  The default
  119.         definitions match the definition of the host computer, operating
  120.         system, and C compiler.
  121.  
  122.         The following are always available unless undefined (or -N was
  123.         specified twice):
  124.  
  125.             __FILE__    The input (or #include) file being compiled (as a
  126.                         quoted string).
  127.  
  128.             __LINE__    The line number being compiled.
  129.  
  130.             __DATE__    The date and time of compilation as a Unix ctime
  131.                         quoted string (the trailing newline is removed).
  132.                         Thus,
  133.  
  134.                             printf("Bug at line %s,", __LINE__);
  135.                             printf(" source file %s", __FILE__);
  136.                             printf(" compiled on %s", __DATE__);
  137.  
  138.  
  139.     DRAFT PROPOSED ANSI STANDARD CONSIDERATIONS
  140.         The current version of the Draft Proposed Standard explicitly states
  141.         that "readers are requested not to specify or claim conformance to
  142.         this draft." Readers and users of Decus CPP should not assume that
  143.         Decus CPP conforms to the standard, or that it will conform to the
  144.         actual C Language Standard.
  145.  
  146.         When CPP is itself compiled, many features of the Draft Proposed
  147.         Standard that are incompatible with existing preprocessors may be
  148.         disabled.  See the comments in CPP's source for details.
  149.  
  150.         The latest version of the Draft Proposed Standard (as reflected in
  151.         Decus CPP) is dated November 12, 1984.
  152.  
  153.         Comments are removed from the input text.  The comment is replaced
  154.         by a single space character.  The -C option preserves comments,
  155.         writing them to the output file.
  156.  
  157.         The '$' character is considered to be a letter.  This is a permitted
  158.         extension.
  159.  
  160.         The following new features of C are processed by CPP:
  161.  
  162.             #elif expression (#else #if)
  163.             '\xNNN' (Hexadecimal constant)
  164.             '\a' (Ascii BELL)
  165.             '\v' (Ascii Vertical Tab)
  166.             #if defined NAME 1 if defined, 0 if not
  167.             #if defined (NAME) 1 if defined, 0 if not
  168.             #if sizeof (basic type)
  169.             unary +
  170.             123U, 123LU Unsigned ints and longs.
  171.             12.3L Long double numbers
  172.             token#token Token concatenation
  173.             #include token Expands to filename
  174.  
  175.         The Draft Proposed Standard has extended C, adding a constant string
  176.         concatenation operator, where
  177.  
  178.             "foo" "bar"
  179.  
  180.         is regarded as the single string "foobar".  (This does not affect
  181.         CPP's processing but does permit a limited form of macro argument
  182.         substitution into strings as will be discussed.)
  183.  
  184.         The Standard Committee plans to add token concatenation to #define
  185.         command lines.  One suggested implementation is as follows: the
  186.         sequence "Token1#Token2" is treated as if the programmer wrote
  187.         "Token1Token2".  This could be used as follows:
  188.  
  189.             #line 123
  190.             #define ATLINE foo#__LINE__
  191.  
  192.         ATLINE would be defined as foo123.
  193.  
  194.         Note that "Token2" must either have the format of an identifier or
  195.         be a string of digits.  Thus, the string
  196.  
  197.             #define ATLINE foo#1x3
  198.  
  199.         generates two tokens:  "foo1" and "x3".
  200.  
  201.         If the tokens T1 and T2 are concatenated into T3, this
  202.         implementation operates as follows:
  203.  
  204.           1. Expand T1 if it is a macro.
  205.           2. Expand T2 if it is a macro.
  206.           3. Join the tokens, forming T3.
  207.           4. Expand T3 if it is a macro.
  208.  
  209.         A macro formal parameter will be substituted into a string or
  210.         character constant if it is the only component of that constant:
  211.  
  212.             #define VECSIZE 123
  213.             #define vprint(name, size) \
  214.               printf("name" "[" "size" "] = {\n")
  215.               ... vprint(vector, VECSIZE);
  216.  
  217.         expands (effectively) to
  218.  
  219.               vprint("vector[123] = {\n");
  220.  
  221.         Note that this will be useful if your C compiler supports the new
  222.         string concatenation operation noted above.  As implemented here, if
  223.         you write
  224.  
  225.             #define string(arg) "arg"
  226.               ... string("foo") ...
  227.  
  228.         This implementation generates "foo", rather than the strictly
  229.         correct ""foo"" (which will probably generate an error message).
  230.         This is, strictly speaking, an error in CPP and may be removed from
  231.         future releases.
  232.  
  233.     ERROR MESSAGES
  234.         Many.  CPP prints warning or error messages if you try to use
  235.         multiple-byte character constants (non-transportable) if you #undef
  236.         a symbol that was not defined, or if your program has potentially
  237.         nested comments.
  238.  
  239.     AUTHOR
  240.         Martin Minow
  241.  
  242.     BUGS
  243.         The #if expression processor uses signed integers only.  I.e,
  244.         #if 0xFFFFu < 0 may be TRUE.
  245.  
  246. *****************************************************************************
  247. */
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.