home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 364_02 / tdef_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  5KB  |  221 lines

  1.  /*
  2. HEADER:         ;
  3. TITLE:          C-ACROSS;
  4. VERSION         1.02
  5.  
  6. DESCRIPTION:   "Utility for multiple module programs. Produces
  7.       Six indexes of functions, prototypes, and globals that
  8.       enable user to 'see across' modules for use in checking
  9.       and comparison.  One of these is type of hierarchical
  10.       functions list, a listing by module of functions
  11.       and calls made FROM them; another is alphabetical list
  12.       of functions and calls made TO them. Globals listed
  13.       in schematic descriptors which record all modifiers
  14.       and qualifiers and enable checking of declarators
  15.       across modules. Creates, on request, header file
  16.       consisting of prototypes constructed from function
  17.       definitions. Can list user types #defined and some
  18.       preprocessor #defines. Full documentation in README.CA";
  19.  
  20. KEYWORDS:       Utility, Cross Reference, Deubgging;
  21. SYSTEM:         MS-DOS;
  22. FILENAME:       TDEF_CA.C;
  23.  
  24. WARNINGS:      "1. Assumes function definitions conform with
  25.         ANSI standards and have prototype form. See
  26.         also "Caveats and Restrictions" in README.CA.
  27.         2. Assumes syntactically correct source files.
  28.         3. Written and tested using Microsoft QuickC.
  29.         4. Copyright retained.  See Copyright
  30.         information in README.CA.";
  31.  
  32. SEE-ALSO:      EXIT_CA.C, FUNC_CA.C, FUNC_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            LINKL_CA.C, PARSE_CA.C, TYPES_CA, UTIL_CA.C,
  34.            UTLG_CA.C, XRF_CA.C, README.CA,
  35.            CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
  36. AUTHORS:       Myron Turner;
  37. COMPILERS:     Microsoft C;
  38.  
  39. */
  40.  
  41. /***************************  C-ACROSS  ***************************
  42.                 V. 1.02
  43.                Copyright (C) Myron Turner
  44.  
  45.               333 Bartlet Ave.
  46.               Winnipeg, Manitoba
  47.               Canada R3L 0Z9
  48.               (204) 284-8387
  49.  
  50. *********************************************************************/
  51.  
  52.  
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <ctype.h>
  56.  
  57. #define TYPEDEF_DEFINE
  58. #define TDEF_CA
  59. #include "ca.h"
  60. #include "ca_decl.h"
  61.  
  62. int get_typedef(char *test)
  63. {
  64.    char *open_brace = NULL;
  65.    char *token;
  66.    static int tdef_open = 0;
  67.  
  68.  
  69.    if (!tdef_open)
  70.       if ( !(open_brace =  strchr(test, '{')) )
  71.         tdef_open = tdeftest(test, tdef_open);
  72.         else tdef_open = 1;
  73.  
  74.     if (open_brace || tdef_open)
  75.        if ( strchr(test, '}') )
  76.            tdef_open = tdeftest(test, tdef_open);
  77.  
  78.  
  79.    return(tdef_open);
  80. }
  81.  
  82.  
  83. int tdeftest(char *test, int tdef_open)
  84. {
  85.    char *semi_colon = NULL, hold_char = '\0';
  86.    char *token, *comma = NULL;
  87.    int i, str_pos, complex = 0;
  88.    char *paren = NULL;
  89.    char *temp = test;
  90.  
  91.       if ( (semi_colon = strchr(test, ';')) ) {
  92.       if (!tdef_open) {
  93.         test += 7;    /* skip over 'typedef' key word */
  94.         while(iswhite(*test)) test++;
  95.         test += data_type_ (test, &i);
  96.  
  97.  
  98.         do
  99.           {
  100.            while(iswhite(*test) || *test == '*' || *test == '(' ) {
  101.              if (*test == '(' ) if (!paren) paren = test;
  102.              test++;
  103.              }
  104.            str_pos = _modifier(test, 0);
  105.            test += str_pos;
  106.           }
  107.           while (str_pos);
  108.         }
  109.       do
  110.       {
  111.        complex = NO_COMPLEX;
  112.        if (paren)
  113.          complex   =  complex_value(paren);
  114.        while(!isalpha(*test) && *test != '_') test++;
  115.        token = test;
  116.        while(isalnum(*test) || *test == '_') test++;
  117.        hold_char = *test;
  118.        *test = '\0';
  119.        if ( (i =insert_type(token)) != -1 )
  120.         __typ_mod[i] = _TYPE_ | complex;
  121.         *test = hold_char;
  122.         if(comma = strchr(test, ',') ) {
  123.            test = comma + 1;
  124.            paren = strchr(test, '(');
  125.            }
  126.            else break;
  127.        }
  128.        while(test != semi_colon);
  129.        return(0);
  130.        }
  131.  
  132.     return(1);
  133.  }
  134.  
  135.  
  136. int check_types(char *token_ptr, int *typenum)
  137. {
  138.   int i, str_pos = 0;
  139.  
  140.        if(!*token_ptr) return(0);
  141.  
  142.        for  (i = 0; i < __typedef_count; i++){
  143.      if(*token_ptr == __type_def[i][0])
  144.       if ((str_pos = test_token(token_ptr, __type_def[i]))) {
  145.         *typenum = i;
  146.         return(str_pos);
  147.         }
  148.         }
  149.  
  150.    return(0);
  151.  }
  152.  
  153.  
  154. int intypeslist(char *token)
  155. {
  156.   int i = 0;
  157.  
  158.   if(!*token) return(1);
  159.   for (; i < __typedef_count; i++)
  160.      if ( __type_def[i][0] == *token )
  161.        if (!strcmp(__type_def[i], token)) return (1);
  162.  
  163.   return(0);
  164. }
  165.  
  166.  
  167. int get_defines(char *test)
  168. {
  169.    char token[32], *end_token, *p ;
  170.    size_t strL;
  171.    int __type;
  172.    int i;
  173.  
  174.    p = token;
  175.  
  176.    strL = strlen(test);
  177.   *(test + strL -1)  = '\0';
  178.    while( iswhite( *test) ) test++;
  179.    strncpy(token, test, 31);
  180.    end_token = token;
  181.  
  182.    while( !(iswhite( *test)) && *test != '\n' && *test ) {
  183.      test++; end_token++;
  184.      }
  185.  
  186.    if (!*test || *test == '\n') return(0);
  187.  
  188.    *(end_token) = '\0';
  189.    while( iswhite( *test) || *test == '*' )             {
  190.             test++;
  191.             }
  192.  
  193.    if (data_type_(test, &__type)) {
  194.      if ( (i =insert_type(token)) != -1 ) {
  195.          __typ_mod[i] = _TYPE_;
  196.       return(i);
  197.       }
  198.      }
  199.  
  200.    if(_modifier (test, 0)) {
  201.     if ( (i =insert_type(token)) != -1 ) {
  202.       __typ_mod[i] = _MOD_;
  203.       return(i);
  204.       }
  205.       }
  206.  
  207.    return(0);
  208. }
  209.  
  210. int insert_type(char *token)
  211. {
  212.      if (token && __typedef_count < __TYPEDEFS) {
  213.     if(!intypeslist(token)) {
  214.        strncpy(__type_def[__typedef_count], token, 31);
  215.       return(__typedef_count++);
  216.      }
  217.      }   else printf ("\aOut of typedef space: %s\n", token);
  218.  
  219.   return(-1);
  220. }
  221.