home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tags18.zip / CTAG.E < prev    next >
Text File  |  1992-05-04  |  74KB  |  2,140 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: ctag.c
  5.    Author: J. Kercheval
  6.    Created: Sun, 07/14/1991  17:24:44
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sat, 07/27/1991  22:08:04  creation
  12.    J. Kercheval  Sun, 08/18/1991  20:58:13  completion of C_get_token()
  13.    J. Kercheval  Wed, 08/21/1991  22:34:49  place function recognition
  14.    J. Kercheval  Wed, 08/21/1991  23:11:17  add defines and macros
  15.    J. Kercheval  Wed, 08/21/1991  23:54:33  add typedef and class parsing
  16.    J. Kercheval  Thu, 08/22/1991  23:53:51  add global variables
  17.    J. Kercheval  Thu, 08/22/1991  23:54:05  add enum, struct, union
  18.    J. Kercheval  Thu, 08/22/1991  23:54:28  add globals via typedefs
  19.    J. Kercheval  Sun, 08/25/1991  23:09:28  complete semantic parser
  20.    J. Kercheval  Tue, 08/27/1991  23:28:34  fix bug in typedef, struct, enum and union declarations
  21.    J. Kercheval  Sat, 08/31/1991  23:58:03  add prototype parsing
  22.    J. Kercheval  Tue, 09/03/1991  22:28:55  move many macros to functions
  23.    J. Kercheval  Tue, 09/03/1991  23:05:34  clean code and consolidate to functions
  24.    J. Kercheval  Sun, 09/08/1991  13:24:53  minor bug fix in function and global variable parser
  25.    J. Kercheval  Sun, 09/08/1991  21:31:06  fix bug in lexical parser
  26.    J. Kercheval  Sun, 09/08/1991  23:44:46  \v is not a valid literal in Epsilon, remove it
  27.    J. Kercheval  Mon, 09/09/1991  21:49:00  fix bug in function parser
  28.    J. Kercheval  Mon, 09/09/1991  22:44:46  fix bug in define parser
  29.    J. Kercheval  Tue, 09/10/1991  22:06:09  fix typedef parser
  30.    J. Kercheval  Wed, 09/11/1991  02:04:48  add extern symbol recognition
  31.    J. Kercheval  Wed, 09/11/1991  19:49:11  fix bug in function pointer variable declaration
  32.    J. Kercheval  Wed, 09/11/1991  20:38:13  add support for function pointer variable declarations after first declaration
  33.    J. Kercheval  Wed, 09/11/1991  21:51:37  move #directive parsing between semantic and lexical parser
  34.    J. Kercheval  Thu, 09/12/1991  22:44:43  add support for #ifdef blocks to avoid unmatched parens in ToLevelZero parsing
  35.    J. Kercheval  Fri, 09/13/1991  01:17:05  add when_loading() to remap def_srch_case_map[]
  36.    J. Kercheval  Wed, 09/18/1991  22:05:02  fix bug in GetToken and DiscardLine
  37.    J. Kercheval  Thu, 09/19/1991  22:26:09  fix bug in lexical parser when parsing non C syntax files
  38.    J. Kercheval  Thu, 10/03/1991  12:47:53  add .cc and .cpp extensions
  39.    J. Kercheval  Thu, 10/03/1991  18:15:10  add support for Static declarations
  40.    J. Kercheval  Fri, 10/04/1991  11:13:23  add support for tagging enumeration constants
  41.    J. Kercheval  Mon, 10/07/1991  09:36:07  create CParseEnumerationConstants()
  42.    J. Kercheval  Tue, 11/12/1991  22:46:16  add junk filter for tag output
  43.    J. Kercheval  Sat, 03/28/1992  13:50:06  fix a few bugs and add extern "C" parsing
  44.    J. Kercheval  Mon, 05/04/1992  00:50:27  fix preprocessor parsing for line_offset and line continuation in defines
  45. */
  46.  
  47. /*
  48.  * This file implements tagging for .C, .H and .E files which contain
  49.  * standard C and C++ syntax.  This file defines no new commands and is
  50.  * intended to work with the tags package included with V5.0 of Epsilon.
  51.  * There is no problem using modified tags packages providing calls are made
  52.  * to tags_suffix_???() routines in the same way Epsilon does this and that
  53.  * an output routine add_tag() is used.  All that should be required is to
  54.  * compile and load this file and this module will be used transparently to
  55.  * you.  If you wish to costumize the types of tags output modify the global
  56.  * variables CTagWant?????? which when TRUE allow the output of that type of
  57.  * tag and when FALSE prohibit that type of tag.
  58.  *
  59.  * This module implements tagging for union, struct, enum, typedef, #define,
  60.  * global variables, classes, prototypes and functions (all of which may be
  61.  * specifically turned on and off.  The performance cost for this level of
  62.  * accuracyis not trivial.  This parser knows a lot about the syntax of C and
  63.  * takes a fair amount of time.  You should expect to see a file complete
  64.  * somewhere in the range of 125%-150% of the time as Lugaru's tagger for C.
  65.  * This is not only because of the detail of the tags but also the larger
  66.  * number of them.  This tagger is not intended to do all of your work for
  67.  * you but is designed to be used in conjunction with the tags generator I
  68.  * have developed and is now available.  This file implements the same
  69.  * lexical and semantic parser as is found in that executable.  Use the
  70.  * executable in your make file for very fast and updated tags.  If you have
  71.  * problems finding it, contact me and I can point the way...
  72.  *
  73.  * There is defined at the end of this module a when_loading() function which
  74.  * alters the default search case map to allow *correct* (or at least
  75.  * consistent sorting with sort routines external to Epsilon.  In particular,
  76.  * to produce the same sort order as any UNIX, VMS or HP style sort or with
  77.  * the tags generator this module is supposed to coexist with this mapping
  78.  * must be done.  You should see no difference in the location of sorted
  79.  * buffers except for lines starting with ^, [, \, ] and _.
  80.  *
  81.  * This code is dedicated to the public domain with the caveat that Lugaru is
  82.  * welcome to use this within their distribution source code which is
  83.  * supplied with Epsilon.
  84.  *
  85.  * Good Tagging,
  86.  *
  87.  *      jbk@wrq.com
  88.  *
  89.  *      John Kercheval
  90.  *      127 NW Bowdoin Pl #105
  91.  *      Seattle, WA  98107-4960
  92.  *      September 8, 1991
  93.  */
  94.  
  95. #include <eel.h>
  96.  
  97. #define BOOLEAN int
  98. #define TRUE 1
  99. #define FALSE 0
  100.  
  101. #define CBUFSIZE 4096
  102. #define MAX_TOKEN_LENGTH 4096
  103.  
  104.  
  105. /* the following variable determine the behavior of the parser with respect
  106.  * to the token types which are output as a tag.  Note that use of the
  107.  * CTagWantExtern variable is a modifier and will only be effective when
  108.  * other options are used (ie. CTagWantProtoType must be specified to obtain
  109.  * extern prototypes, CTagWantExtern alone yields nothing).  Note also that
  110.  * the CTagWantExtern modifier has no effect for function, define and macro
  111.  * tags which are tagged only according only to the CTagWantFunction,
  112.  * CTagWantDefine and CTagWantMacro variables respectively.  CTagWantStatic
  113.  * is also a modifier and will allow tags of internal statically defined
  114.  * variables and other declarations.  CTagWantStatic also has no effect on
  115.  * Define and Macro tags.
  116.  */
  117. BOOLEAN CTagWantFunction = TRUE;
  118. BOOLEAN CTagWantProtoType = FALSE;
  119. BOOLEAN CTagWantStructure = TRUE;
  120. BOOLEAN CTagWantTypeDefinition = TRUE;
  121. BOOLEAN CTagWantMacro = TRUE;
  122. BOOLEAN CTagWantEnumeration = TRUE;
  123. BOOLEAN CTagWantEnumerationConstant = TRUE;
  124. BOOLEAN CTagWantUnion = TRUE;
  125. BOOLEAN CTagWantGlobalVariable = TRUE;
  126. BOOLEAN CTagWantClass = TRUE;
  127. BOOLEAN CTagWantDefine = TRUE;
  128. BOOLEAN CTagWantExtern = FALSE;
  129. BOOLEAN CTagWantStatic = TRUE;
  130.  
  131.  
  132. /* function for determining if character is whitespace */
  133. #define IsWhite(c) ( _C_white_table[c] )
  134.  
  135. /* the indexed table for white space character lookup */
  136. BOOLEAN _C_white_table[256];
  137.  
  138. /* list of whitespace characters */
  139. char C_white[] = " \f\t\n\r";
  140.  
  141.  
  142. /* function for determining if character is a delimiter */
  143. #define IsDelim(c) ( _C_delim_table[c] )
  144.  
  145. /* the indexed table for token delimiter lookup */
  146. BOOLEAN _C_delim_table[256];
  147.  
  148. /* list of token delimiters */
  149. char C_delim[] = " \f\t\n\r\"[](){}#;:,.'=-+*/%&|^~!<>?";
  150.  
  151.  
  152. /* function for determining if character is a puncuator */
  153. #define IsPunctuator(c) ( _C_punctuator_table[c] )
  154.  
  155. /* the indexed table for punctuator character lookup */
  156. BOOLEAN _C_punctuator_table[256];
  157.  
  158. /* list of punctuators */
  159. char C_punctuator[] = "[](){},;=";
  160.  
  161.  
  162. char C_open_brace[] = "{[(";    /* open brace set */
  163. char C_close_brace[] = ")]}";   /* close brace set */
  164.  
  165.  
  166. /*
  167.  * These defines are used to denote the type of the current tag
  168.  */
  169. #define NOP 0
  170. #define Function 1
  171. #define ProtoType 2
  172. #define Structure 3
  173. #define TypeDefinition 4
  174. #define Macro 5
  175. #define Enumeration 6
  176. #define EnumerationConstant 7
  177. #define Union 8
  178. #define GlobalVariable 9
  179. #define Class 10
  180. #define Define 11
  181. #define Extern 12
  182. #define Static 13
  183.  
  184. /* convenient definition */
  185. typedef int SymbolType;
  186.  
  187.  
  188. /* the current file buffer state */
  189. typedef struct BufferStruct {
  190.     int token_line_location;    /* current token line in buffer */
  191.     char *inbuf;                /* the buffer currently being parsed */
  192. } Buffer;
  193.  
  194.  
  195. /* the current input token state */
  196. typedef struct TokenStruct {
  197.     char sbuf1[MAX_TOKEN_LENGTH];       /* the first token buffer */
  198.     int charloc1;               /* the char location of sbuf1 */
  199.     int tokenline1;             /* the line number of sbuf1 */
  200.  
  201.     char sbuf2[MAX_TOKEN_LENGTH];       /* the second token buffer */
  202.     int charloc2;               /* the char location of sbuf2 */
  203.     int tokenline2;             /* the line number of sbuf2 */
  204.  
  205.     char *cur_token;            /* pointer to the current token buffer */
  206.     int *cur_char_location;     /* the location of current token */
  207.     int *cur_token_line;        /* the line of the current token */
  208.  
  209.     char *prev_token;           /* pointer to the last token buffer */
  210.     int *prev_char_location;    /* the location of previous token */
  211.     int *prev_token_line;       /* the line of the previous token */
  212.  
  213.     int token_count;            /* temporary variable, used by ToPunctuator */
  214.     int else_nesting_level;     /* the current nesting level */
  215.  
  216.     BOOLEAN extern_active;      /* minor state for this statement */
  217.     BOOLEAN CPP_extern_active;  /* minor state for this statement */
  218.     BOOLEAN static_active;      /* minor state for this statement */
  219. } Token;
  220.  
  221.  
  222. #define SYMBOL_SIZE 20
  223.  
  224. /* a list of known C tokens and keywords */
  225. char C_token_list[][SYMBOL_SIZE] =
  226. {
  227.     "*ivclsdfuaretp_hn\"",      /* list of starting characters of symbols
  228.                                  * below */
  229.     "*",                        /* pointer */
  230.     "\"C\"",                    /* C++ extern for C code */
  231.     "int",                      /* integer declaration */
  232.     "void",                     /* void type */
  233.     "char",                     /* character */
  234.     "long",                     /* long integer */
  235.     "short",                    /* short integer */
  236.     "double",                   /* double floating point */
  237.     "float",                    /* floating point */
  238.     "signed",                   /* signed integer */
  239.     "unsigned",                 /* unsigned integer */
  240.     "auto",                     /* auto variable (local duration) */
  241.     "register",                 /* register variable */
  242.     "static",                   /* static variable */
  243.     "struct",                   /* structure define */
  244.     "union",                    /* union define */
  245.     "enum",                     /* enum defined */
  246.     "typedef",                  /* type definition */
  247.     "const",                    /* constant variable */
  248.     "extern",                   /* external declaration */
  249.     "class",                    /* class declaration */
  250.     "friend",                   /* class modifier */
  251.     "private",                  /* class modifier */
  252.     "protected",                /* class modifier */
  253.     "public",                   /* class modifier */
  254.     "volatile",                 /* Compiler warning */
  255.     "_based",                   /* pointer type */
  256.     "_cdecl",                   /* parameter calling sequence, C style */
  257.     "cdecl",                    /* parameter calling sequence, C style */
  258.     "_far",                     /* pointer type */
  259.     "far",                      /* pointer type */
  260.     "_huge",                    /* pointer type */
  261.     "huge",                     /* pointer type */
  262.     "_near",                    /* pointer type */
  263.     "near",                     /* pointer type */
  264.     "_pascal",                  /* parameter calling sequence, PASCAL style */
  265.     "pascal",                   /* parameter calling sequence, PASCAL style */
  266.     "_fortran",                 /* parameter calling sequence, FORTRAN style */
  267.     "_fastcall",                /* parameter calling sequence, via registers */
  268.     "\0"
  269. };
  270.  
  271.  
  272. /*----------------------------------------------------------------------------
  273.  *
  274.  * CParserInit() initializes the tables required by the parser. The tables
  275.  * used are a simple boolean index which are true if the character
  276.  * corresponding to the index is a member of the associated table.
  277.  *
  278.  ---------------------------------------------------------------------------*/
  279.  
  280. CParserInit()
  281. {
  282.     char *s;
  283.     int i;
  284.  
  285.     /* init the entire block to FALSE */
  286.     for (i = 0; i < 256; i++) {
  287.         _C_delim_table[i] = FALSE;
  288.         _C_white_table[i] = FALSE;
  289.         _C_punctuator_table[i] = FALSE;
  290.     }
  291.  
  292.     /* set the characters in the delim set to TRUE */
  293.     for (s = C_delim; *s; s++) {
  294.         _C_delim_table[*s] = TRUE;
  295.     }
  296.  
  297.     /* set the characters in the white set to TRUE */
  298.     for (s = C_white; *s; s++) {
  299.         _C_white_table[*s] = TRUE;
  300.     }
  301.  
  302.     /* set the characters in the punctuator set to TRUE */
  303.     for (s = C_punctuator; *s; s++) {
  304.         _C_punctuator_table[*s] = TRUE;
  305.     }
  306. }
  307.  
  308.  
  309. /*----------------------------------------------------------------------------
  310.  *
  311.  * strchr() is the standard string library function strchr()
  312.  *
  313.  ---------------------------------------------------------------------------*/
  314.  
  315. char *strchr(s, c)
  316.     char *s;
  317.     char c;
  318. {
  319.     char *ret = s;
  320.  
  321.     while (*ret) {
  322.         if (*ret == c)
  323.             return ret;
  324.         ret++;
  325.     }
  326.  
  327.     if (*ret == c)
  328.         return ret;
  329.  
  330.     return NULL;
  331. }
  332.  
  333.  
  334. /*----------------------------------------------------------------------------
  335.  *
  336.  * CSymbolWanted() returns true if flags are true for the symbol type passed
  337.  * and false otherwise.
  338.  *
  339.  ---------------------------------------------------------------------------*/
  340.  
  341. BOOLEAN CSymbolWanted(type)
  342.     SymbolType type;
  343. {
  344.     switch (type) {
  345.         case Function:
  346.             return CTagWantFunction;
  347.             break;
  348.         case ProtoType:
  349.             return CTagWantProtoType;
  350.             break;
  351.         case GlobalVariable:
  352.             return CTagWantGlobalVariable;
  353.             break;
  354.         case Define:
  355.             return CTagWantDefine;
  356.             break;
  357.         case Macro:
  358.             return CTagWantMacro;
  359.             break;
  360.         case Structure:
  361.             return CTagWantStructure;
  362.             break;
  363.         case TypeDefinition:
  364.             return CTagWantTypeDefinition;
  365.             break;
  366.         case Enumeration:
  367.             return CTagWantEnumeration;
  368.             break;
  369.         case EnumerationConstant:
  370.             return CTagWantEnumerationConstant;
  371.             break;
  372.         case Union:
  373.             return CTagWantUnion;
  374.             break;
  375.         case Class:
  376.             return CTagWantClass;
  377.             break;
  378.         default:
  379.             return FALSE;
  380.             break;
  381.     }
  382. }
  383.  
  384.  
  385. /*----------------------------------------------------------------------------
  386.  *
  387.  * CTokenType() takes the token passed and determines if the token is a
  388.  * special token.  Special tokens require specialized handling in the parser.
  389.  * The function returns the type of token according to the SymbolTypeEnum
  390.  * enumeration.  This routine can only tell so much from one symbol but will
  391.  * return some type for all the *interesting* tokens.  Anything that is
  392.  * loosely defined is given back with the closest type available and the
  393.  * parser must give it contextual meaning
  394.  *
  395.  ---------------------------------------------------------------------------*/
  396.  
  397. SymbolType CTokenType(token)
  398.     char *token;
  399. {
  400.     /* look for dirty rejection */
  401.     if (!strchr("cestu#", token[0]))
  402.         return NOP;
  403.  
  404.     /* macro and non macro defines */
  405.     if (!strcmp(token, "#"))
  406.         return Define;
  407.  
  408.     /* structure declarations */
  409.     if (!strcmp(token, "struct"))
  410.         return Structure;
  411.  
  412.     /* type declaration */
  413.     if (!strcmp(token, "typedef"))
  414.         return TypeDefinition;
  415.  
  416.     /* enumeration declaration */
  417.     if (!strcmp(token, "enum"))
  418.         return Enumeration;
  419.  
  420.     /* union declaration */
  421.     if (!strcmp(token, "union"))
  422.         return Union;
  423.  
  424.     /* class declaration */
  425.     if (!strcmp(token, "class"))
  426.         return Class;
  427.  
  428.     /* external declaration */
  429.     if (!strcmp(token, "extern"))
  430.         return Extern;
  431.  
  432.     /* static declaration */
  433.     if (!strcmp(token, "static"))
  434.         return Static;
  435.  
  436.     /* do not recognize it as anything special */
  437.     return NOP;
  438. }
  439.  
  440.  
  441. /*----------------------------------------------------------------------------
  442.  *
  443.  * CIsDeclarationToken() takes the token passed and determines if the token
  444.  * is a declaration keyword used in C.  The user may define new declaration
  445.  * keywords via use of the typedef keyword.  This alters the syntax of C.  If
  446.  * the syntax is changed in this way it is probable that this routine would
  447.  * not return the correct value.  For the standard uses of this routine that
  448.  * information should not hinder performance for the vast majority of the
  449.  * cases.
  450.  *
  451.  ---------------------------------------------------------------------------*/
  452.  
  453. BOOLEAN CIsDeclarationToken(token)
  454.     char *token;
  455. {
  456.     int index;
  457.  
  458.     /* look for dirty rejection */
  459.     if (!strchr(C_token_list[0], token[0]))
  460.         return FALSE;
  461.  
  462.     /* march through array until membership is determined */
  463.     for (index = 1; *C_token_list[index]; (index)++) {
  464.  
  465.         /* return true if token found */
  466.         if (!strcmp(token, C_token_list[index])) {
  467.             return TRUE;
  468.         }
  469.     }
  470.  
  471.     /* did not find it */
  472.     return FALSE;
  473. }
  474.  
  475.  
  476. /*----------------------------------------------------------------------------
  477.  *
  478.  * COutputToken() will output a token of a given type.  The token is output
  479.  * if the passed token type is requested from the command line.
  480.  *
  481.  ---------------------------------------------------------------------------*/
  482.  
  483. COutputToken(token, token_buffer, token_type, infname, outbuf)
  484.     Token *token;
  485.     Buffer *token_buffer;
  486.     SymbolType token_type;
  487.     char *infname;
  488.     char *outbuf;
  489. {
  490.     /* filter junk symbols */
  491.     if (!IsDelim(token->prev_token[0])) {
  492.  
  493.         /* check that the symbol is wanted and output it if so */
  494.         if (CSymbolWanted(token_type)) {
  495.  
  496.             if (token->extern_active) {
  497.                 if (!CTagWantExtern) {
  498.                     if (token_type != Function &&
  499.                         token_type != Define &&
  500.                         token_type != Macro) {
  501.                         return;
  502.                     }
  503.                 }
  504.             }
  505.             /* return if statics are not wanted */
  506.             if (token->static_active) {
  507.                 if (!CTagWantStatic) {
  508.                     if (token_type != Define &&
  509.                         token_type != Macro) {
  510.                         return;
  511.                     }
  512.                 }
  513.             }
  514.             add_tag(token->prev_token,
  515.                     *(token->prev_char_location) -
  516.                     strlen(token->prev_token));
  517.         }
  518.     }
  519. }
  520.  
  521.  
  522. /*----------------------------------------------------------------------------
  523.  *
  524.  * CGetToken() will obtain the next token in the line pointed to by lptr and
  525.  * in addition will return FALSE if EOL is reached.  This routine is passed
  526.  * an inbut buffer (Cbuf) and a current pointer into the buffer.  It is the
  527.  * responsibility of this routine to refill the buffer if required.  Quoted
  528.  * strings and single quoted characters are returned as a single token.
  529.  * Comments are completely ignored by this parser.  The token will not exceed
  530.  * max_token_length - 1 in length (not including the end of line delimiter)
  531.  *
  532.  ---------------------------------------------------------------------------*/
  533.  
  534. BOOLEAN CGetToken(inbuf, token, max_token_length, line_number)
  535.     char *inbuf;
  536.     char *token;
  537.     int max_token_length;
  538.     int *line_number;
  539. {
  540.     /* a state of the lexical parser */
  541. #define Parse 0
  542. #define BeginCommentMaybe 1
  543. #define InComment 2
  544. #define InCommentEndMaybe 3
  545. #define InCPPComment 4
  546. #define InQuoteNormal 5
  547. #define InQuoteLiteral 6
  548. #define InSingleQuoteNormal 7
  549. #define InSingleQuoteLiteral 8
  550. #define EndSingleQuote 9
  551. #define WhiteSpace 10
  552. #define Exit 11
  553.  
  554.     typedef int State;
  555.  
  556.     State current_state;        /* the current state of the parser */
  557.  
  558.     char c;                     /* the current character being examined */
  559.     char *t;                    /* pointer into token */
  560.  
  561.     int token_length;           /* the current token_length cannot exceed
  562.                                  * max token length */
  563.  
  564.     /* init */
  565.     current_state = WhiteSpace;
  566.     t = token;
  567.     *t = '\0';
  568.     token_length = 0;
  569.  
  570.     /* parse the file for the next token */
  571.     while (TRUE) {
  572.  
  573.         /* if the buffer has been completely used, return FALSE */
  574.         if (point == size())
  575.             return FALSE;
  576.  
  577.         c = curchar();
  578.         point++;
  579.  
  580.         /* react on the state machine */
  581.         switch (current_state) {
  582.  
  583.             case Parse:
  584.                 switch (c) {
  585.  
  586.                     case '/':
  587.  
  588.                         /* return if we already have a token */
  589.                         if (t != token) {
  590.                             point--;
  591.                             current_state = Exit;
  592.                         }
  593.                         else {
  594.                             /* this may be the begin if a comment or the
  595.                              * division symbol, read the next character after
  596.                              * verifying it the buffer doesn't need refilling */
  597.                             current_state = BeginCommentMaybe;
  598.                             *t = c;
  599.                         }
  600.                         break;
  601.  
  602.                     case '\"':
  603.  
  604.                         /* return if we already have a token */
  605.                         if (t != token) {
  606.                             point--;
  607.                             current_state = Exit;
  608.                         }
  609.                         else {
  610.                             current_state = InQuoteNormal;
  611.                             *t++ = c;
  612.                             token_length++;
  613.                         }
  614.                         break;
  615.  
  616.                     case '\'':
  617.  
  618.                         /* return if we already have a token */
  619.                         if (t != token) {
  620.                             point--;
  621.                             current_state = Exit;
  622.                         }
  623.                         else {
  624.                             current_state = InSingleQuoteNormal;
  625.                             *t++ = c;
  626.                             token_length++;
  627.                         }
  628.                         break;
  629.  
  630.                     default:
  631.  
  632.                         /* if it is a delimiter than stop processing */
  633.                         if (IsDelim(c)) {
  634.  
  635.                             /* if a token exists then back up in buffer */
  636.                             if (t != token) {
  637.                                 point--;
  638.                             }
  639.                             else {
  640.                                 *t++ = c;
  641.                                 token_length++;
  642.                             }
  643.                             current_state = Exit;
  644.                         }
  645.                         else {
  646.  
  647.                             /* normal character, store it in the token */
  648.                             *t++ = c;
  649.                             token_length++;
  650.                         }
  651.                         break;
  652.                 }
  653.                 break;
  654.  
  655.             case WhiteSpace:
  656.  
  657.                 /* pass over whitespace, backup one char if no longer in
  658.                  * white space region */
  659.                 if (!IsWhite(c)) {
  660.                     current_state = Parse;
  661.                     point--;
  662.                 }
  663.                 else {
  664.  
  665.                     /* check for newline */
  666.                     if (c == '\n') {
  667.                         (*line_number)++;
  668.                     }
  669.                 }
  670.                 break;
  671.  
  672.             case BeginCommentMaybe:
  673.                 switch (c) {
  674.  
  675.                     case '/':
  676.                         current_state = InCPPComment;
  677.                         break;
  678.  
  679.                     case '*':
  680.                         current_state = InComment;
  681.                         break;
  682.  
  683.                     default:
  684.                         t++;
  685.                         token_length++;
  686.                         point--;
  687.                         current_state = Exit;
  688.                         break;
  689.                 }
  690.                 break;
  691.  
  692.             case InComment:
  693.                 switch (c) {
  694.  
  695.                     case '*':
  696.                         /* this is potentially the end of the comment */
  697.                         current_state = InCommentEndMaybe;
  698.                         break;
  699.  
  700.                     case '\n':
  701.                         /* new line just increment state variables */
  702.                         (*line_number)++;
  703.                         break;
  704.  
  705.                     default:
  706.                         break;
  707.                 }
  708.                 break;
  709.  
  710.             case InCommentEndMaybe:
  711.                 switch (c) {
  712.  
  713.                     case '/':
  714.                         /* this is indeed the end of the comment */
  715.                         current_state = WhiteSpace;
  716.                         break;
  717.  
  718.                     case '*':
  719.                         /* this is also perhaps the end of comment */
  720.                         break;
  721.  
  722.                     case '\n':
  723.                         /* new line just increment state variables */
  724.                         (*line_number)++;
  725.  
  726.                     default:
  727.                         /* still part of the current comment */
  728.                         current_state = InComment;
  729.                         break;
  730.                 }
  731.                 break;
  732.  
  733.             case InCPPComment:
  734.                 if (c == '\n') {
  735.                     current_state = WhiteSpace;
  736.                     (*line_number)++;
  737.                 }
  738.                 break;
  739.  
  740.             case InQuoteNormal:
  741.                 switch (c) {
  742.  
  743.                     case '\"':
  744.                         /* end of InQuoteNormal state */
  745.                         current_state = Exit;
  746.                         break;
  747.  
  748.                     case '\\':
  749.                         /* InQuoteLiteral state */
  750.                         current_state = InQuoteLiteral;
  751.                         break;
  752.  
  753.                     default:
  754.                         /* normal dull behavior */
  755.                         break;
  756.                 }
  757.                 *t++ = c;
  758.                 token_length++;
  759.                 break;
  760.  
  761.             case InQuoteLiteral:
  762.                 /* this char is simply copied */
  763.                 current_state = InQuoteNormal;
  764.                 *t++ = c;
  765.                 token_length++;
  766.                 break;
  767.  
  768.             case InSingleQuoteNormal:
  769.                 switch (c) {
  770.  
  771.                     case '\\':
  772.                         /* InQuoteLiteral state */
  773.                         current_state = InSingleQuoteLiteral;
  774.                         break;
  775.  
  776.                     default:
  777.                         /* Just copy the character and move to close quote */
  778.                         current_state = EndSingleQuote;
  779.                         break;
  780.                 }
  781.                 *t++ = c;
  782.                 token_length++;
  783.                 break;
  784.  
  785.             case InSingleQuoteLiteral:
  786.                 /* this char is simply copied */
  787.                 current_state = EndSingleQuote;
  788.                 *t++ = c;
  789.                 token_length++;
  790.                 break;
  791.  
  792.             case EndSingleQuote:
  793.  
  794.                 /* end of InSingleQuote states */
  795.                 current_state = Exit;
  796.                 *t++ = c;
  797.                 token_length++;
  798.                 break;
  799.  
  800.             case Exit:
  801.                 *t = '\0';
  802.                 point--;
  803.                 return TRUE;
  804.                 break;
  805.  
  806.             default:            /* not reached */
  807.                 break;
  808.         }
  809.  
  810.         /* if the token_length has gotten too large then return */
  811.         if (token_length == max_token_length - 1) {
  812.             *t = '\0';
  813.             point--;
  814.             return TRUE;
  815.         }
  816.     }
  817. }
  818.  
  819.  
  820. /*----------------------------------------------------------------------------
  821.  *
  822.  * CFillToken() will obtain the next lexical parser from the buffer and move
  823.  * the token into the Token structure.  TRUE is returned if the lexical
  824.  * parser returns TRUE, otherwise FALSE is returned.
  825.  *
  826.  ---------------------------------------------------------------------------*/
  827.  
  828. BOOLEAN CFillToken(token, token_buffer)
  829.     Token *token;
  830.     Buffer *token_buffer;
  831. {
  832.     BOOLEAN token_found;
  833.  
  834.     /* obtain the next token */
  835.     token_found = CGetToken(token_buffer->inbuf,
  836.                             token->cur_token,
  837.                             MAX_TOKEN_LENGTH,
  838.                             &(token_buffer->token_line_location));
  839.  
  840.     /* if one is around then update the state for that token */
  841.     if (token_found) {
  842.         /* update location variables */
  843.         *(token->cur_char_location) = point;
  844.         *(token->cur_token_line) = token_buffer->token_line_location;
  845.     }
  846.  
  847.     return token_found;
  848. }
  849.  
  850.  
  851. /*----------------------------------------------------------------------------
  852.  *
  853.  * CTokenSwap() will swap the token variables and set the prev_ variables
  854.  * correctly
  855.  *
  856.  ---------------------------------------------------------------------------*/
  857.  
  858. CTokenSwap(token)
  859.     Token *token;
  860. {
  861.     char *charswap;             /* temporary swap variable */
  862.     int *longintswap;           /* temporary swap variable */
  863.  
  864.     /* swap the active token string */
  865.     charswap = token->cur_token;
  866.     token->cur_token = token->prev_token;
  867.     token->prev_token = charswap;
  868.  
  869.     /* swap the active character location */
  870.     longintswap = token->cur_char_location;
  871.     token->cur_char_location = token->prev_char_location;
  872.     token->prev_char_location = longintswap;
  873.  
  874.     /* swap the active line */
  875.     longintswap = token->cur_token_line;
  876.     token->cur_token_line = token->prev_token_line;
  877.     token->prev_token_line = longintswap;
  878. }
  879.  
  880.  
  881. /*----------------------------------------------------------------------------
  882.  *
  883.  * CDiscardLine() will move past all the characters up to the next EOL that
  884.  * is not preceded by a line continuation character.  This routine will
  885.  * return TRUE if there was a '(' character as the first character.  This
  886.  * return value is useful for determining if #defines are macros or simple
  887.  * defines.
  888.  *
  889.  ---------------------------------------------------------------------------*/
  890.  
  891. BOOLEAN CDiscardLine(inbuf, line_number)
  892.     char *inbuf;
  893.     int *line_number;
  894. {
  895.     char c;                     /* the current character being examined */
  896.  
  897.     BOOLEAN line_continue;      /* TRUE if line continuation true */
  898.     BOOLEAN is_macro;           /* TRUE if the first delimiter char is '(' */
  899.     BOOLEAN first_char;         /* TRUE when first character is active */
  900.  
  901.     /* init */
  902.     c = '\0';
  903.     line_continue = FALSE;
  904.     is_macro = FALSE;
  905.     first_char = TRUE;
  906.  
  907.     /* if the end of buffer is reached then return */
  908.     if (point == size())
  909.         return is_macro;
  910.  
  911.     /* loop until non continued EOL encountered */
  912.     do {
  913.  
  914.         /* determine if the first character is a '(' */
  915.         if (first_char) {
  916.             if (c == '(')
  917.                 is_macro = TRUE;
  918.             first_char = FALSE;
  919.         }
  920.  
  921.         /* handle the newline */
  922.         if (c == '\n') {
  923.             line_continue = FALSE;
  924.             (*line_number)++;
  925.         }
  926.  
  927.         c = curchar();
  928.         point++;
  929.  
  930.         if (!IsWhite(c))
  931.             line_continue = FALSE;
  932.         
  933.         if (c == '\\')
  934.             line_continue = TRUE;
  935.  
  936.     } while (c != '\n' || line_continue);
  937.  
  938.     (*line_number)++;
  939.     return is_macro;
  940. }
  941.  
  942.  
  943. /*----------------------------------------------------------------------------
  944.  *
  945.  * CParseDefine() will parse macros and defines in standard C syntax
  946.  * distinguish between a macro and a define, if there is a punctuator '(',
  947.  * then it is a macro.  Take the token just before the first space or
  948.  * punctuator
  949.  *
  950.  ---------------------------------------------------------------------------*/
  951.  
  952. CParseDefine(token, token_buffer, infname, outbuf)
  953.     Token *token;
  954.     Buffer *token_buffer;
  955.     char *infname;
  956.     char *outbuf;
  957. {
  958.     SymbolType tmptype;         /* a temporay type variable */
  959.  
  960.     BOOLEAN token_found;
  961.     BOOLEAN is_macro;
  962.  
  963.     token_found = CFillToken(token, token_buffer);
  964.     if (token_found) {
  965.  
  966.         /* save the previous values */
  967.         CTokenSwap(token);
  968.  
  969.  
  970.         /* get rid of the rest of the line and return the define type */
  971.         is_macro =
  972.             CDiscardLine(token_buffer->inbuf,
  973.                          &(token_buffer->token_line_location));
  974.  
  975.         /* react on the token */
  976.         if (is_macro) {
  977.             tmptype = Macro;
  978.         }
  979.         else {
  980.             tmptype = Define;
  981.         }
  982.  
  983.         /* output the token */
  984.         COutputToken(token, token_buffer, tmptype,
  985.                      infname, outbuf);
  986.     }
  987. }
  988.  
  989.  
  990. /*----------------------------------------------------------------------------
  991.  *
  992.  * CParsePreprocessorDirective() will parse preprocessor directives in
  993.  * standard C syntax
  994.  *
  995.  ---------------------------------------------------------------------------*/
  996.  
  997. CParsePreprocessorDirective(token, token_buffer, infname, outbuf)
  998.     Token *token;
  999.     Buffer *token_buffer;
  1000.     char *infname;
  1001.     char *outbuf;
  1002. {
  1003.     BOOLEAN token_found;
  1004.  
  1005.     token_found = CFillToken(token, token_buffer);
  1006.     if (token_found) {
  1007.  
  1008.         /* deal with a define directive */
  1009.         if (!strcmp(token->cur_token, "define")) {
  1010.             CParseDefine(token, token_buffer, infname, outbuf);
  1011.         }
  1012.         else {
  1013.  
  1014.             /* increment the else block level pointer */
  1015.             if (!strcmp(token->cur_token, "else")) {
  1016.                 token->else_nesting_level++;
  1017.             }
  1018.             else {
  1019.  
  1020.                 /* decrement the else block level pointer */
  1021.                 if (!strcmp(token->cur_token, "endif")) {
  1022.                     if (token->else_nesting_level)
  1023.                         token->else_nesting_level--;
  1024.                 }
  1025.                 else {
  1026.  
  1027.                     /* if an else has not already been seen then increment
  1028.                      * the level */
  1029.                     if (!strcmp(token->cur_token, "elif")) {
  1030.                         token->else_nesting_level++;
  1031.                     }
  1032.                 }
  1033.             }
  1034.  
  1035.             /* remove the rest of the directive line including line
  1036.              * continuation characters */
  1037.             CDiscardLine(token_buffer->inbuf,
  1038.                          &(token_buffer->token_line_location));
  1039.         }
  1040.     }
  1041. }
  1042.  
  1043.  
  1044. /*----------------------------------------------------------------------------
  1045.  *
  1046.  * CNextToken() will obtain the next token in the buffer and update the
  1047.  * appropriate variables.
  1048.  *
  1049.  ---------------------------------------------------------------------------*/
  1050.  
  1051. BOOLEAN CNextToken(token, token_buffer, infname, outbuf)
  1052.     Token *token;
  1053.     Buffer *token_buffer;
  1054.     char *infname;
  1055.     char *outbuf;
  1056. {
  1057.     BOOLEAN token_found;
  1058.     BOOLEAN cycle;
  1059.  
  1060.     do {
  1061.         /* obtain the next token */
  1062.         token_found = CFillToken(token, token_buffer);
  1063.  
  1064.         /* check for preprocessing directives and parse them if found */
  1065.         if (token->cur_token[0] == '#' && token_found) {
  1066.  
  1067.             /* parse the directive and loop back to get another token */
  1068.             CParsePreprocessorDirective(token, token_buffer, infname, outbuf);
  1069.             cycle = TRUE;
  1070.         }
  1071.         else {
  1072.  
  1073.             /* we found a token to pass to the semantic parser */
  1074.             cycle = FALSE;
  1075.         }
  1076.     } while (cycle);
  1077.  
  1078.     /* return it */
  1079.     return token_found;
  1080. }
  1081.  
  1082.  
  1083. /*----------------------------------------------------------------------------
  1084.  *
  1085.  * CToLevelZero() will increment the nesting level and then parse tokens
  1086.  * until level zero has been reached again.  If tokens are no longer
  1087.  * available this loop will stop.
  1088.  *
  1089.  ---------------------------------------------------------------------------*/
  1090.  
  1091. CToLevelZero(token, token_buffer, infname, outbuf)
  1092.     Token *token;
  1093.     Buffer *token_buffer;
  1094.     char *infname;
  1095.     char *outbuf;
  1096. {
  1097.     int nesting_level = 1;
  1098.  
  1099.     token->else_nesting_level = 0;
  1100.  
  1101.     while (nesting_level) {
  1102.         if (CGetToken(token_buffer->inbuf, token->cur_token,
  1103.                       MAX_TOKEN_LENGTH,
  1104.                       &(token_buffer->token_line_location))) {
  1105.             if (token->cur_token[0] == '#') {
  1106.                 CParsePreprocessorDirective(token, token_buffer,
  1107.                                             infname, outbuf);
  1108.             }
  1109.             else {
  1110.  
  1111.                 /* only count open brace, parens and brackets within blocks
  1112.                  * of one element of an ifdef code block */
  1113.                 if (!token->else_nesting_level) {
  1114.                     if (strchr(C_open_brace, token->cur_token[0]))
  1115.                         nesting_level++;
  1116.                     else
  1117.                         if (strchr(C_close_brace, token->cur_token[0]))
  1118.                             nesting_level--;
  1119.                 }
  1120.             }
  1121.         }
  1122.         else
  1123.             nesting_level = 0;
  1124.     }
  1125. }
  1126.  
  1127.  
  1128. /*----------------------------------------------------------------------------
  1129.  *
  1130.  * CToPunctuator() will parse tokens until the next punctuator has been
  1131.  * reached.  If tokens are no longer available this loop will stop.  If this
  1132.  * loop is successful the found flag declared in the host routine will be
  1133.  * set.
  1134.  *
  1135.  ---------------------------------------------------------------------------*/
  1136.  
  1137. BOOLEAN CToPunctuator(token, token_buffer, infname, outbuf)
  1138.     Token *token;
  1139.     Buffer *token_buffer;
  1140.     char *infname;
  1141.     char *outbuf;
  1142. {
  1143.     BOOLEAN punctuator_found;
  1144.  
  1145.     /* init and parse through until the first punctuator is found */
  1146.     token->token_count = 0;
  1147.     punctuator_found = FALSE;
  1148.     while (!punctuator_found) {
  1149.         token->token_count++;
  1150.         CTokenSwap(token);
  1151.         if (!CNextToken(token, token_buffer, infname, outbuf)) {
  1152.             break;
  1153.         }
  1154.         else {
  1155.             if (IsPunctuator(token->cur_token[0]))
  1156.                 punctuator_found = TRUE;
  1157.         }
  1158.     }
  1159.  
  1160.     /* return value */
  1161.     return punctuator_found;
  1162. }
  1163.  
  1164.  
  1165. /*----------------------------------------------------------------------------
  1166.  *
  1167.  * CParseParens() will move through a declaration in parentheses and place
  1168.  * the correct valid token as prev_token.  This return TRUE if a '[' was seen
  1169.  * within the parens and false otherwise.
  1170.  *
  1171.  ---------------------------------------------------------------------------*/
  1172.  
  1173. BOOLEAN CParseParens(token, token_buffer, infname, outbuf)
  1174.     Token *token;
  1175.     Buffer *token_buffer;
  1176.     char *infname;
  1177.     char *outbuf;
  1178. {
  1179.     BOOLEAN token_found;
  1180.     BOOLEAN variable_seen;
  1181.     int brace_ignore = 1;
  1182.  
  1183.     token->else_nesting_level = 0;
  1184.  
  1185.     token_found = TRUE;
  1186.     variable_seen = FALSE;
  1187.     while (brace_ignore &&
  1188.            token_found) {
  1189.  
  1190.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1191.  
  1192.         if (token_found &&
  1193.             !token->else_nesting_level) {
  1194.             switch (token->cur_token[0]) {
  1195.  
  1196.                 case '(':
  1197.  
  1198.                     /* increment brace_ignore and continue */
  1199.                     brace_ignore++;
  1200.                     break;
  1201.  
  1202.                 case ')':
  1203.  
  1204.                     /* just decrement brace_ignore if it is positive. If
  1205.                      * brace ignore is not positive at this point then we
  1206.                      * certainly have a syntax error.  Ignore this fact if
  1207.                      * so. */
  1208.                     if (brace_ignore) {
  1209.                         brace_ignore--;
  1210.                     }
  1211.                     break;
  1212.  
  1213.                 case '[':
  1214.  
  1215.                     /* move to end of array bounds */
  1216.                     variable_seen = TRUE;
  1217.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1218.                     break;
  1219.  
  1220.                 default:
  1221.                     CTokenSwap(token);
  1222.                     break;
  1223.             }
  1224.         }
  1225.     }
  1226.  
  1227.     return variable_seen;
  1228. }
  1229.  
  1230.  
  1231. /*----------------------------------------------------------------------------
  1232.  *
  1233.  * COutputCommaDelimitedToken() will output a token and then parse the
  1234.  * statement until ';' or ',' is reached.  The token is output if the passed
  1235.  * token type is requested from the command line.
  1236.  *
  1237.  ---------------------------------------------------------------------------*/
  1238.  
  1239. COutputCommaDelimitedToken(token, token_buffer, token_type, infname, outbuf)
  1240.     Token *token;
  1241.     Buffer *token_buffer;
  1242.     SymbolType token_type;
  1243.     char *infname;
  1244.     char *outbuf;
  1245. {
  1246.     BOOLEAN punctuator_found;
  1247.  
  1248.     /* output the token */
  1249.     COutputToken(token, token_buffer, token_type, infname, outbuf);
  1250.  
  1251.     /* go to the next list punctuator (',' or ';') */
  1252.     punctuator_found = TRUE;
  1253.     while (token->cur_token[0] != ',' &&
  1254.            token->cur_token[0] != ';' &&
  1255.            punctuator_found) {
  1256.         if (strchr(C_open_brace, token->cur_token[0])) {
  1257.             CToLevelZero(token, token_buffer, infname, outbuf);
  1258.         }
  1259.         punctuator_found = CToPunctuator(token, token_buffer,
  1260.                                          infname, outbuf);
  1261.     }
  1262. }
  1263.  
  1264.  
  1265. /*----------------------------------------------------------------------------
  1266.  *
  1267.  * CParseCommaDelimitedList() will parse a token list seperated by commas
  1268.  * until a ';' is found.  The tokens are output if the passed type is
  1269.  * requested from the command line.
  1270.  *
  1271.  ---------------------------------------------------------------------------*/
  1272.  
  1273. CParseCommaDelimitedList(token, token_buffer, token_type, infname, outbuf)
  1274.     Token *token;
  1275.     Buffer *token_buffer;
  1276.     SymbolType token_type;
  1277.     char *infname;
  1278.     char *outbuf;
  1279. {
  1280.     BOOLEAN punctuator_found;
  1281.  
  1282.     /* parse through the list */
  1283.     punctuator_found = TRUE;
  1284.     while (token->cur_token[0] != ';' &&
  1285.            punctuator_found) {
  1286.         punctuator_found = CToPunctuator(token, token_buffer,
  1287.                                          infname, outbuf);
  1288.         if (punctuator_found) {
  1289.             switch (token->cur_token[0]) {
  1290.  
  1291.                 case '(':
  1292.                     /* this is an embedded variable declaration, either a
  1293.                      * complex variable pointer or function pointer, fall
  1294.                      * through after picking out the internal token */
  1295.                     CParseParens(token, token_buffer, infname, outbuf);
  1296.  
  1297.                 case '[':
  1298.                 case ',':
  1299.                 case ';':
  1300.                 case '=':
  1301.  
  1302.                     /* this is one of the proper ending tokens for this type
  1303.                      * of declaration list, so output it and parse to the
  1304.                      * next correct punctuator */
  1305.                     COutputToken(token, token_buffer, token_type,
  1306.                                  infname, outbuf);
  1307.                     while (token->cur_token[0] != ',' &&
  1308.                            token->cur_token[0] != ';' &&
  1309.                            punctuator_found) {
  1310.                         if (strchr(C_open_brace, token->cur_token[0])) {
  1311.                             CToLevelZero(token, token_buffer,
  1312.                                          infname, outbuf);
  1313.                         }
  1314.                         punctuator_found = CToPunctuator(token, token_buffer,
  1315.                                                          infname, outbuf);
  1316.                     }
  1317.                     break;
  1318.                 default:
  1319.                     break;
  1320.             }
  1321.         }
  1322.     }
  1323. }
  1324.  
  1325.  
  1326. /*----------------------------------------------------------------------------
  1327.  *
  1328.  * CParseFunctionOrGlobalVariable() will parse a function, prototype or
  1329.  * global variable syntax.
  1330.  *
  1331.  ---------------------------------------------------------------------------*/
  1332.  
  1333. CParseFunctionOrGlobalVariable(token, token_buffer, infname, outbuf)
  1334.     Token *token;
  1335.     Buffer *token_buffer;
  1336.     char *infname;
  1337.     char *outbuf;
  1338. {
  1339.     char *line_buf;             /* the first token buffer */
  1340.     int charloc;                /* the char location of sbuf1 */
  1341.     int tokenline;              /* the line number of sbuf1 */
  1342.  
  1343.     BOOLEAN token_found;
  1344.     BOOLEAN punctuator_found;
  1345.     BOOLEAN last_token_known;
  1346.     BOOLEAN variable_seen;
  1347.  
  1348.     /* init */
  1349.     charloc = 0;
  1350.     tokenline = 1;
  1351.     line_buf = malloc(MAX_TOKEN_LENGTH);
  1352.     line_buf[0] = '\0';
  1353.  
  1354.     /* save the previous token */
  1355.     last_token_known = CIsDeclarationToken(token->prev_token);
  1356.     if (!last_token_known) {
  1357.  
  1358.         /* If this is not a known token then it may be a function name. Save
  1359.          * it then look further at the syntax.  This also may be a symbol
  1360.          * previously defined via a typedef which alters the syntax of C/C++ */
  1361.         strcpy(line_buf, token->prev_token);
  1362.         charloc = *(token->prev_char_location);
  1363.         tokenline = *(token->prev_token_line);
  1364.     }
  1365.  
  1366.     /* This is a function or prototype or global variable go to brace_ignore
  1367.      * level zero again. */
  1368.     variable_seen = CParseParens(token, token_buffer, infname, outbuf);
  1369.  
  1370.     /* Check to see if this is a function, prototype, or global variable. If
  1371.      * the token is a ';' and last_token_known is false then we assume a
  1372.      * function.  Strange variable declarations may fool this, but not
  1373.      * likely. If the character is a '(' then it is certainly a function or
  1374.      * prototype unless variable_seen is TRUE, then it is a variable. If the
  1375.      * character is a '[', ',' then it is certainly a variable declaration.
  1376.      * If the character is a ';' and last_token_known is true then it is a
  1377.      * variable declaration.  If the token is anything else then it is a
  1378.      * function. */
  1379.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1380.     if (token_found) {
  1381.         switch (token->cur_token[0]) {
  1382.  
  1383.             case ';':
  1384.  
  1385.                 /* determine if a prototype or a variable declaration. if the
  1386.                  * last_token_known is true then it is a global variable.  If
  1387.                  * the token was a symbol defined by a typedef then this
  1388.                  * distinction is incorrect since typedef actually alters
  1389.                  * syntax.  This is correct for the large majority of cases
  1390.                  * since most do not enclose simple variable declarations in
  1391.                  * parens. */
  1392.                 if (last_token_known) {
  1393.  
  1394.                     /* this is a global variable */
  1395.                     COutputToken(token, token_buffer, GlobalVariable,
  1396.                                  infname, outbuf);
  1397.                 }
  1398.                 else {
  1399.  
  1400.                     /* this is a prototype, copy saved token back to
  1401.                      * prev_token, output and continue */
  1402.                     strcpy(token->prev_token, line_buf);
  1403.                     *(token->prev_char_location) = charloc;
  1404.                     *(token->prev_token_line) = tokenline;
  1405.                     COutputToken(token, token_buffer, ProtoType,
  1406.                                  infname, outbuf);
  1407.                 }
  1408.                 break;
  1409.  
  1410.             case '(':
  1411.  
  1412.                 if (variable_seen) {
  1413.  
  1414.                     /* this is a variable declaration */
  1415.                     COutputCommaDelimitedToken(token, token_buffer,
  1416.                                                GlobalVariable,
  1417.                                                infname, outbuf);
  1418.                     CParseCommaDelimitedList(token, token_buffer,
  1419.                                              GlobalVariable,
  1420.                                              infname, outbuf);
  1421.                 }
  1422.                 else {
  1423.  
  1424.                     /* move to level zero again */
  1425.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1426.  
  1427.                     /* obtain the next token */
  1428.                     token_found = CNextToken(token, token_buffer,
  1429.                                              infname, outbuf);
  1430.  
  1431.                     if (token_found) {
  1432.  
  1433.                         /* check if prototype, function or function pointer
  1434.                          * variable declaration */
  1435.                         switch (token->cur_token[0]) {
  1436.  
  1437.                             case '=':
  1438.  
  1439.                                 /* this is a function pointer variable
  1440.                                  * declaration */
  1441.                                 COutputCommaDelimitedToken(token,
  1442.                                                            token_buffer,
  1443.                                                            GlobalVariable,
  1444.                                                            infname, outbuf);
  1445.                                 CParseCommaDelimitedList(token, token_buffer,
  1446.                                                          GlobalVariable,
  1447.                                                          infname, outbuf);
  1448.                                 break;
  1449.  
  1450.                             case ';':
  1451.  
  1452.                                 /* this is a prototype, output it */
  1453.                                 COutputToken(token, token_buffer,
  1454.                                              ProtoType, infname, outbuf);
  1455.                                 break;
  1456.  
  1457.                             default:
  1458.  
  1459.                                 /* this is a function */
  1460.                                 COutputToken(token, token_buffer,
  1461.                                              Function, infname, outbuf);
  1462.  
  1463.                                 /* parse through function */
  1464.                                 punctuator_found = TRUE;
  1465.                                 while (token->cur_token[0] != '{' &&
  1466.                                        punctuator_found) {
  1467.                                     punctuator_found =
  1468.                                         CToPunctuator(token, token_buffer,
  1469.                                                       infname, outbuf);
  1470.                                 }
  1471.                                 if (punctuator_found) {
  1472.                                     CToLevelZero(token, token_buffer,
  1473.                                                  infname, outbuf);
  1474.                                 }
  1475.                                 break;
  1476.                         }
  1477.                     }
  1478.                 }
  1479.                 break;
  1480.  
  1481.             case '[':
  1482.             case '=':
  1483.             case ',':
  1484.  
  1485.                 /* global variables */
  1486.                 COutputCommaDelimitedToken(token, token_buffer,
  1487.                                            GlobalVariable,
  1488.                                            infname, outbuf);
  1489.                 CParseCommaDelimitedList(token, token_buffer,
  1490.                                          GlobalVariable,
  1491.                                          infname, outbuf);
  1492.                 break;
  1493.  
  1494.             default:
  1495.  
  1496.                 /* this is a function, copy saved token back to prev_token,
  1497.                  * output and continue */
  1498.                 strcpy(token->prev_token, line_buf);
  1499.                 *(token->prev_char_location) = charloc;
  1500.                 *(token->prev_token_line) = tokenline;
  1501.                 COutputToken(token, token_buffer,
  1502.                              Function, infname, outbuf);
  1503.  
  1504.                 /* parse through function */
  1505.                 punctuator_found = TRUE;
  1506.                 while (token->cur_token[0] != '{' &&
  1507.                        punctuator_found) {
  1508.                     punctuator_found =
  1509.                         CToPunctuator(token, token_buffer, infname, outbuf);
  1510.                 }
  1511.                 if (punctuator_found) {
  1512.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1513.                 }
  1514.                 break;
  1515.         }
  1516.     }
  1517.     free(line_buf);
  1518. }
  1519.  
  1520.  
  1521. /*----------------------------------------------------------------------------
  1522.  *
  1523.  * CParseNOP() will parse an as of yet unrecognized statement.  If I run into
  1524.  * a punctuator at this time then I have found either a structure declaration
  1525.  * (C++ 2.0), or a global variable declaration.  If the punctuator is '[',
  1526.  * ',', '=', or ';' then it is a global variable declaration.  If the
  1527.  * punctuator is a '{' then we have a structure declaration at this time we
  1528.  * should not run into any closing punctuators or syntax is in a bad way
  1529.  *
  1530.  ---------------------------------------------------------------------------*/
  1531.  
  1532. CParseNOP(token, token_buffer, infname, outbuf)
  1533.     Token *token;
  1534.     Buffer *token_buffer;
  1535.     char *infname;
  1536.     char *outbuf;
  1537. {
  1538.     BOOLEAN token_found;
  1539.  
  1540.     switch (token->cur_token[0]) {
  1541.         case ';':
  1542.         case '=':
  1543.         case ',':
  1544.         case '[':
  1545.  
  1546.             /* global variables are here */
  1547.             COutputCommaDelimitedToken(token, token_buffer,
  1548.                                        GlobalVariable,
  1549.                                        infname, outbuf);
  1550.             CParseCommaDelimitedList(token, token_buffer,
  1551.                                      GlobalVariable,
  1552.                                      infname, outbuf);
  1553.             token->extern_active = FALSE;
  1554.             token->CPP_extern_active = FALSE;
  1555.             token->static_active = FALSE;
  1556.             break;
  1557.  
  1558.         case '{':
  1559.  
  1560.             /* validate we are not in a C++ extern for C statements */
  1561.              if (!token->CPP_extern_active) {
  1562.                  
  1563.                 /* this is a structure (C++ syntax) */
  1564.                  /* output it */
  1565.                  COutputToken(token, token_buffer, Structure,
  1566.                               infname, outbuf);
  1567.  
  1568.                  /* move through declaration */
  1569.                  CToLevelZero(token, token_buffer, infname, outbuf);
  1570.  
  1571.                  /* get the next token */
  1572.                  token_found = CNextToken(token, token_buffer,
  1573.                                           infname, outbuf);
  1574.  
  1575.                  /* if a token is available then output the list */
  1576.                  if (token_found) {
  1577.                      CParseCommaDelimitedList(token, token_buffer,
  1578.                                               GlobalVariable,
  1579.                                               infname, outbuf);
  1580.                  }                                                      
  1581.                  token->extern_active = FALSE;
  1582.                  token->static_active = FALSE;
  1583.              }
  1584.             break;
  1585.  
  1586.         case '(':
  1587.  
  1588.             CParseFunctionOrGlobalVariable(token, token_buffer,
  1589.                                            infname, outbuf);
  1590.             token->extern_active = FALSE;
  1591.             token->CPP_extern_active = FALSE;
  1592.             token->static_active = FALSE;
  1593.             break;
  1594.  
  1595.          case '"':
  1596.                                              
  1597.              if (!strcmp("\"C\"",token->cur_token))
  1598.                  token->CPP_extern_active = TRUE;
  1599.              break;
  1600.              
  1601.         default:
  1602.  
  1603.             /* true NOP */
  1604.             break;
  1605.     }
  1606. }
  1607.  
  1608.  
  1609. /*----------------------------------------------------------------------------
  1610.  *
  1611.  * CParseEnumerationConstants() will parse constants within an enumeration
  1612.  * declaration
  1613.  *
  1614.  ---------------------------------------------------------------------------*/
  1615.  
  1616. CParseEnumerationConstants(token, token_buffer, infname, outbuf)
  1617.     Token *token;
  1618.     Buffer *token_buffer;
  1619.     char *infname;
  1620.     char *outbuf;
  1621. {
  1622.     BOOLEAN punctuator_found;
  1623.  
  1624.     char *open_brace = "({[";
  1625.  
  1626.     /* obtain the enumeration constants */
  1627.     punctuator_found = TRUE;
  1628.  
  1629.     while (token->cur_token[0] != '}' &&
  1630.            punctuator_found) {
  1631.         punctuator_found = CToPunctuator(token, token_buffer,
  1632.                                          infname, outbuf);
  1633.         if (punctuator_found) {
  1634.             switch (token->cur_token[0]) {
  1635.  
  1636.                 case ',':
  1637.                 case '=':
  1638.  
  1639.                     /* this is one of the proper ending tokens for this type
  1640.                      * of declaration list, so output it and parse to the
  1641.                      * next correct punctuator */
  1642.                     COutputToken(token, token_buffer, EnumerationConstant,
  1643.                                  infname, outbuf);
  1644.                     while (token->cur_token[0] != ',' &&
  1645.                            token->cur_token[0] != '}' &&
  1646.                            punctuator_found) {
  1647.                         if (strchr(open_brace, token->cur_token[0])) {
  1648.                             CToLevelZero(token, token_buffer,
  1649.                                          infname, outbuf);
  1650.                         }
  1651.                         punctuator_found = CToPunctuator(token, token_buffer,
  1652.                                                          infname, outbuf);
  1653.                     }
  1654.                     break;
  1655.  
  1656.                 default:
  1657.                     break;
  1658.             }
  1659.         }
  1660.     }
  1661. }
  1662.  
  1663.  
  1664. /*----------------------------------------------------------------------------
  1665.  *
  1666.  * CParseDeclarationStatement() will parse struct, enum and union
  1667.  * declarations.  take the token just before the first punctuator, run
  1668.  * through the top level braces and parse for variables if the first
  1669.  * punctuator is a ';' then this is a global variable declaration, if the
  1670.  * first token[0] is a '{' then this is a global variable declaration.
  1671.  *
  1672.  ---------------------------------------------------------------------------*/
  1673.  
  1674. CParseDeclarationStatement(token, token_buffer, type, infname, outbuf)
  1675.     Token *token;
  1676.     Buffer *token_buffer;
  1677.     SymbolType type;
  1678.     char *infname;
  1679.     char *outbuf;
  1680. {
  1681.     BOOLEAN token_found;
  1682.     BOOLEAN punctuator_found;
  1683.     BOOLEAN primary_parse;
  1684.  
  1685.     punctuator_found = CToPunctuator(token, token_buffer, infname, outbuf);
  1686.     if (punctuator_found) {
  1687.  
  1688.         /* init */
  1689.         primary_parse = TRUE;
  1690.  
  1691.         /* switch on current token */
  1692.         switch (token->cur_token[0]) {
  1693.  
  1694.                 /* this is truly an object declaration */
  1695.             case '{':
  1696.  
  1697.                 /* output only if this is not a variable declaration */
  1698.                 if (token->token_count != 1) {
  1699.  
  1700.                     /* output it */
  1701.                     COutputToken(token, token_buffer, type, infname, outbuf);
  1702.                 }
  1703.  
  1704.                 /* check if enumeration */
  1705.                 if (type == Enumeration) {
  1706.  
  1707.                     /* obtain the enumeration constants */
  1708.                     CParseEnumerationConstants(token, token_buffer,
  1709.                                                infname, outbuf);
  1710.                 }
  1711.                 else {
  1712.  
  1713.                     /* move through declaration and fall through */
  1714.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1715.                 }
  1716.  
  1717.                 /* get the next token, if one not available then break out of
  1718.                  * case */
  1719.                 token_found = CNextToken(token, token_buffer,
  1720.                                          infname, outbuf);
  1721.                 if (!token_found)
  1722.                     break;
  1723.  
  1724.                 /* fall through to take care of variable declarations after
  1725.                  * setting pre-parse flag */
  1726.                 primary_parse = FALSE;
  1727.  
  1728.             case ';':
  1729.             case '=':
  1730.             case ',':
  1731.             case '[':
  1732.  
  1733.                 /* if this is the first seen then output it */
  1734.                 if (primary_parse) {
  1735.                     COutputCommaDelimitedToken(token, token_buffer,
  1736.                                                GlobalVariable,
  1737.                                                infname, outbuf);
  1738.                 }
  1739.  
  1740.                 CParseCommaDelimitedList(token, token_buffer,
  1741.                                          GlobalVariable,
  1742.                                          infname, outbuf);
  1743.                 break;
  1744.  
  1745.             case '(':
  1746.  
  1747.                 CParseFunctionOrGlobalVariable(token, token_buffer,
  1748.                                                infname, outbuf);
  1749.                 break;
  1750.  
  1751.             default:
  1752.  
  1753.                 /* not reached */
  1754.                 break;
  1755.         }
  1756.     }
  1757. }
  1758.  
  1759.  
  1760. /*----------------------------------------------------------------------------
  1761.  *
  1762.  * CParseTypeDefinition() parses the typedef statement.  take the token just
  1763.  * before the first *correct* punctuator, the ';', ',' or the '['.  Tag any
  1764.  * declarations being done here, get the next token
  1765.  *
  1766.  ---------------------------------------------------------------------------*/
  1767.  
  1768. CParseTypeDefinition(token, token_buffer, infname, outbuf)
  1769.     Token *token;
  1770.     Buffer *token_buffer;
  1771.     char *infname;
  1772.     char *outbuf;
  1773. {
  1774.     BOOLEAN token_found;
  1775.     BOOLEAN parens_found;
  1776.     BOOLEAN special_found;
  1777.  
  1778.     int token_count;
  1779.     SymbolType tmptype;
  1780.  
  1781.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1782.  
  1783.     if (token_found) {
  1784.  
  1785.         /* check the type of the token for future use */
  1786.         tmptype = CTokenType(token->cur_token);
  1787.  
  1788.         /* parse the typedef */
  1789.         parens_found = FALSE;
  1790.         special_found = FALSE;
  1791.         token_count = 0;
  1792.         while (token->cur_token[0] != ';' &&
  1793.                token->cur_token[0] != ',' &&
  1794.                token->cur_token[0] != '[' &&
  1795.                token_found &&
  1796.                !special_found) {
  1797.  
  1798.             /* parse for defines */
  1799.             if (token_found) {
  1800.  
  1801.                 /* handle the punctuator */
  1802.                 switch (token->cur_token[0]) {
  1803.  
  1804.                     case '{':
  1805.  
  1806.                         /* pass through any defines going on here */
  1807.                         if (token->cur_token[0] == '{') {
  1808.  
  1809.                             /* if the token count is > 1 here then we have a
  1810.                              * named declaration and need to output the
  1811.                              * token, output only if the token type is enum,
  1812.                              * struct, or union */
  1813.                             if (token_count > 1 &&
  1814.                                 (tmptype == Structure ||
  1815.                                  tmptype == Enumeration ||
  1816.                                  tmptype == Union)) {
  1817.                                 COutputToken(token, token_buffer,
  1818.                                              tmptype, infname, outbuf);
  1819.                             }
  1820.  
  1821.                             /* check if enumeration */
  1822.                             if (tmptype == Enumeration) {
  1823.  
  1824.                                 /* obtain the enumeration constants */
  1825.                                 CParseEnumerationConstants(token,
  1826.                                                            token_buffer,
  1827.                                                            infname, outbuf);
  1828.                             }
  1829.                             else {
  1830.  
  1831.                                 /* go back to level 0 */
  1832.                                 CToLevelZero(token, token_buffer,
  1833.                                              infname, outbuf);
  1834.                             }
  1835.                         }
  1836.                         break;
  1837.  
  1838.                     case '(':
  1839.  
  1840.                         /* if this is the top level and we have already been
  1841.                          * through a set of parens then we know this to be a
  1842.                          * function typedef so we ouput the previous token,
  1843.                          * otherwise check the previous token and if it is a
  1844.                          * known keyword then just eat the token and continue */
  1845.                         if (parens_found) {
  1846.                             COutputToken(token, token_buffer,
  1847.                                          TypeDefinition, infname, outbuf);
  1848.                             CToLevelZero(token, token_buffer,
  1849.                                          infname, outbuf);
  1850.                             special_found = TRUE;
  1851.                         }
  1852.                         else {
  1853.  
  1854.                             /* Move back to the top level */
  1855.                             CParseParens(token, token_buffer,
  1856.                                          infname, outbuf);
  1857.  
  1858.                             /* next paren we find we know we have a token */
  1859.                             parens_found = TRUE;
  1860.  
  1861.                             /* swap to prevent loss of token */
  1862.                             CTokenSwap(token);
  1863.                         }
  1864.                         break;
  1865.  
  1866.                     default:
  1867.  
  1868.                         /* if we have another token after a paren parse then
  1869.                          * we know the token in the parens was nothing
  1870.                          * special */
  1871.                         parens_found = FALSE;
  1872.                         break;
  1873.                 }
  1874.             }
  1875.  
  1876.             /* get another token */
  1877.             CTokenSwap(token);
  1878.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1879.             token_count++;
  1880.         }
  1881.  
  1882.         /* output the typedef names if appropriate */
  1883.         if (token->prev_token[0] != '}' &&
  1884.             token_found) {
  1885.  
  1886.             /* don't output the first token if already done */
  1887.             if (!special_found) {
  1888.                 COutputCommaDelimitedToken(token, token_buffer,
  1889.                                            TypeDefinition,
  1890.                                            infname, outbuf);
  1891.             }
  1892.  
  1893.             /* parse through the rest of the typedef names */
  1894.             CParseCommaDelimitedList(token, token_buffer,
  1895.                                      TypeDefinition,
  1896.                                      infname, outbuf);
  1897.         }
  1898.     }
  1899. }
  1900.  
  1901.  
  1902. /*----------------------------------------------------------------------------
  1903.  *
  1904.  * CParseClass() will parse the C++ class syntax.  take the token just before
  1905.  * the first '{', ',' or ':' and run through the top level braces if there
  1906.  *
  1907.  ---------------------------------------------------------------------------*/
  1908.  
  1909. CParseClass(token, token_buffer, infname, outbuf)
  1910.     Token *token;
  1911.     Buffer *token_buffer;
  1912.     char *infname;
  1913.     char *outbuf;
  1914. {
  1915.     BOOLEAN token_found;
  1916.  
  1917.     token_found = TRUE;
  1918.     while (token->cur_token[0] != '{' &&
  1919.            token->cur_token[0] != ':' &&
  1920.            token->cur_token[0] != ';' &&
  1921.            token_found) {
  1922.  
  1923.         /* save the current token */
  1924.         CTokenSwap(token);
  1925.  
  1926.         /* get the next token */
  1927.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1928.     }
  1929.  
  1930.     /* output the class name */
  1931.     if (token_found) {
  1932.         COutputToken(token, token_buffer, Class, infname, outbuf);
  1933.  
  1934.         /* parse through the remainder of the statement */
  1935.         while (token->cur_token[0] != ';' &&
  1936.                token_found) {
  1937.             if (token->cur_token[0] == '{') {
  1938.  
  1939.                 /* move back to the zero level */
  1940.                 CToLevelZero(token, token_buffer, infname, outbuf);
  1941.             }
  1942.  
  1943.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1944.         }
  1945.     }
  1946. }
  1947.  
  1948.  
  1949. /*----------------------------------------------------------------------------
  1950.  *
  1951.  * CTags() tags an input stream assuming standard ANSI 2.0 C/C++ syntax.
  1952.  * Long tokens are allowed, ANSI requires only 31 significant, note that if
  1953.  * token length exceeds MAX_TOKEN_LENGTH this parser will die a horrible
  1954.  * death (or at the very least do ugly things to someone else's memory),
  1955.  * with the large size of MAX_TOKEN_LENGTH, anyone caught on this hook
  1956.  * deserves what they get...
  1957.  *
  1958.  ---------------------------------------------------------------------------*/
  1959.  
  1960. CTags(inbuf, infname, outbuf)
  1961.     char *inbuf;
  1962.     char *infname;
  1963.     char *outbuf;
  1964. {
  1965.     SymbolType type;            /* the type of the current token */
  1966.  
  1967.     Token *token;               /* current state variable */
  1968.     Buffer *token_buffer;       /* input buffer */
  1969.  
  1970.     BOOLEAN token_found;        /* set by CNextToken() */
  1971.  
  1972.     /* allocate the Buffer and Token memory */
  1973.     token = (Token *) malloc(sizeof(Token));
  1974.     token_buffer = (Buffer *) malloc(sizeof(Token));
  1975.  
  1976.     /* init the parser engine */
  1977.     point = 0;
  1978.     CParserInit();
  1979.     token->token_count = 0;
  1980.  
  1981.     /* init the current token buffers */
  1982.     token->cur_token = token->sbuf1;
  1983.     token->cur_char_location = &(token->charloc1);
  1984.     token->cur_token_line = &(token->tokenline1);
  1985.     token->cur_token[0] = '\0';
  1986.     *(token->cur_char_location) = 0;
  1987.     *(token->cur_token_line) = 1;
  1988.  
  1989.     /* init the previous token buffers */
  1990.     token->prev_token = token->sbuf2;
  1991.     token->prev_char_location = &(token->charloc2);
  1992.     token->prev_token_line = &(token->tokenline2);
  1993.     token->prev_token[0] = '\0';
  1994.     *(token->prev_char_location) = 0;
  1995.     *(token->prev_token_line) = 1;
  1996.  
  1997.     /* init the input buffers */
  1998.     token_buffer->token_line_location = 1;
  1999.     token_buffer->inbuf = inbuf;
  2000.  
  2001.     /* init Extern and Static state */
  2002.     token->extern_active = FALSE;
  2003.     token->CPP_extern_active = FALSE;
  2004.     token->static_active = FALSE;
  2005.  
  2006.     /* get the first token */
  2007.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  2008.  
  2009.     /* loop through the file */
  2010.     while (token_found) {
  2011.  
  2012.         /* obtain the token type */
  2013.         type = CTokenType(token->cur_token);
  2014.  
  2015.         /* react on the token type */
  2016.         switch (type) {
  2017.  
  2018.             case NOP:
  2019.                 CParseNOP(token, token_buffer, infname, outbuf);
  2020.                 break;
  2021.  
  2022.             case Structure:
  2023.             case Enumeration:
  2024.             case Union:
  2025.                 CParseDeclarationStatement(token, token_buffer,
  2026.                                            type, infname, outbuf);
  2027.                 break;
  2028.  
  2029.             case TypeDefinition:
  2030.                 CParseTypeDefinition(token, token_buffer, infname, outbuf);
  2031.                 break;
  2032.  
  2033.             case Class:
  2034.                 CParseClass(token, token_buffer, infname, outbuf);
  2035.                 break;
  2036.  
  2037.             case Extern:
  2038.                 token->extern_active = TRUE;
  2039.                 break;
  2040.  
  2041.             case Static:
  2042.                 token->static_active = TRUE;
  2043.                 break;
  2044.  
  2045.             default:
  2046.                 /* not reached */
  2047.                 break;
  2048.         }
  2049.  
  2050.         if (type != Extern &&
  2051.             type != Static &&
  2052.             type != NOP) {
  2053.  
  2054.             /* turn off the extern flag */
  2055.             token->extern_active = FALSE;
  2056.             token->CPP_extern_active = FALSE;
  2057.             token->static_active = FALSE;
  2058.         }
  2059.  
  2060.         /* swap state variables and get the next token */
  2061.         CTokenSwap(token);
  2062.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  2063.     }
  2064.  
  2065.     free(token);
  2066.     free(token_buffer);
  2067. }
  2068.  
  2069.  
  2070. /*----------------------------------------------------------------------------
  2071.  *
  2072.  * tag_suffix_c(), tag_suffix_h() and tag_suffix_e() are recognized procedure
  2073.  * names to the tags package in Epsilon and will be called automatically when
  2074.  * tagging needs to happen for these extensions.  These are replacement names
  2075.  * for the routines of the same name defined in tags.e.
  2076.  *
  2077.  ---------------------------------------------------------------------------*/
  2078.  
  2079. tag_suffix_c()
  2080. {
  2081.     /* the third parameter, the output buffer name is not actually used by
  2082.      * anyone but is left here for a time when this information may be
  2083.      * needed.  The current algorithm is to let the funtion add_tag() decide
  2084.      * the buffer name to send the output to.  As a little more than
  2085.      * coincedence, the name used here is the same used in add_tag() defined
  2086.      * in tags.e */
  2087.     CTags(bufname, filename, "-tags");
  2088. }
  2089.  
  2090. tag_suffix_h()
  2091. {
  2092.     tag_suffix_c();
  2093. }
  2094.  
  2095. tag_suffix_e()
  2096. {
  2097.     tag_suffix_c();
  2098. }
  2099.  
  2100. tag_suffix_cc()
  2101. {
  2102.     tag_suffix_c();
  2103. }
  2104.  
  2105. tag_suffix_cpp()
  2106. {
  2107.     tag_suffix_c();
  2108. }
  2109.  
  2110. #ifdef foo
  2111. /* rebuild the default character maps */
  2112. when_loading()
  2113. {
  2114. #define UCLC(up, low)   _def_char_class[low] = C_LOWER, \
  2115.                         _def_char_class[up] = C_UPPER, \
  2116.                         _def_srch_case_map[up] = low, \
  2117.                         _def_case_map[low] = up, \
  2118.                         _def_case_map[up] = low
  2119.  
  2120.     int i, j;
  2121.  
  2122.     for (i = 0; i < 256; i++)
  2123.         _def_case_map[i] = _def_srch_case_map[i] = i;
  2124.     for (i = 'A', j = 'a'; i <= 'Z'; i++, j++)
  2125.         UCLC(i, j);
  2126.     for (i = 131; i < 154; i++)
  2127.         _def_char_class[i] = C_LOWER;
  2128.     for (i = 160; i < 164; i++)
  2129.         _def_char_class[i] = C_LOWER;
  2130.     UCLC('Ç', 'ç');
  2131.     UCLC('Ä', 'ä');
  2132.     UCLC('Å', 'å');
  2133.     UCLC('É', 'é');
  2134.     UCLC('Æ', 'æ');
  2135.     UCLC('Ö', 'ö');
  2136.     UCLC('Ü', 'ü');
  2137.     UCLC('Ñ', 'ñ');
  2138. }
  2139. #endif
  2140.