home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 364_02 / types_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  10KB  |  386 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:       TYPES_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, GLOB_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, 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. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <graph.h>
  56. #include <malloc.h>
  57. #include <ctype.h>
  58.  
  59. #define INCLUDEFILES_DEFINE
  60. #define TYPEDEF_DEFINE
  61. #define TDEF_EXTERNAL
  62. #define TDEF_NUM
  63. #define EXTERNAL
  64. #include "keywords.h"
  65. #include "ca.h"
  66. #include "ca_decl.h"
  67.  
  68. #define INPARENTHESES -1
  69.  
  70. /* externs */
  71. extern FILE *scrn_out;
  72. extern int __mods[_MAX_MODS];
  73. extern int declare_file ;    /* create a C declarations file: /UHF switch */
  74. extern int In_Parentheses ;
  75. extern int In_MainLoop ;
  76.  
  77. /******************     Begin Routines      ****************/
  78.  
  79. int data_type_ (char *test, int *__type)
  80. {
  81.   char *p, buffer[261], *token_ptr, structname[40], *end_token;
  82.   int str_pos = 0, i, holdpos = 0;
  83.   static typedef_open = 0;
  84.   FILE * holdfp;
  85.   size_t strL;
  86.  
  87.   *__type = NO_TYPE;
  88.   if (In_Parentheses) return(INPARENTHESES);
  89.   if(typedef_open) {
  90.       typedef_open = get_typedef(test);
  91.       return(0);
  92.       }
  93.  
  94.   strcpy (buffer, test);
  95.   p = buffer;
  96.   while(iswhite(*p) ) { p++; holdpos++; }
  97.   token_ptr = isolate_token(p, &end_token);
  98.   if(!token_ptr) return(0);
  99.  
  100.   switch (*token_ptr)
  101.   {
  102.  
  103.     case '#':
  104.  
  105.     if (!In_MainLoop) {
  106.       *__type = PREPROCESSOR;   return(0);
  107.     }
  108.  
  109.     token_ptr++;
  110.     if( !(*token_ptr) ) {
  111.       p = token_ptr + 1;
  112.       token_ptr = isolate_token(p, &end_token);
  113.       }
  114.  
  115.     if ( (str_pos = test_token(token_ptr, TYPES[DEFINE_])) )   {
  116.         get_defines(token_ptr+str_pos);
  117.         return(0);
  118.         }
  119.      if(is_include(token_ptr,holdfp)) return(0);
  120.       break;
  121.  
  122.     case 'c':
  123.     if ( (str_pos = test_token(token_ptr, TYPES[CHARACTER])) ) {
  124.          *__type = CHARACTER;
  125.          return (str_pos + holdpos);
  126.          }
  127.     break;
  128.  
  129.     case 'd':
  130.       if ( (str_pos = test_token(token_ptr, TYPES[DOUBLE])) ) {
  131.          *__type = DOUBLE;
  132.          return (str_pos + holdpos);
  133.          }
  134.       break;
  135.  
  136.      case 'e':
  137.       if ( (str_pos = test_token(token_ptr, TYPES[ENUM])) ) {
  138.          *__type =  ENUM;
  139.          return (str_pos);
  140.          }
  141.       break;
  142.  
  143.      case 'F':
  144.       if ( (str_pos = test_token(token_ptr, TYPES[file])) ) {
  145.          *__type =  file;
  146.          return (str_pos);
  147.          }
  148.       break;
  149.  
  150.  
  151.      case 'f':
  152.        if ( (str_pos = test_token(token_ptr, TYPES[FLOAT])) ) {
  153.          *__type = FLOAT;
  154.          return (str_pos);
  155.          }
  156.       break;
  157.  
  158.     case 'h':
  159.      if ( (str_pos = test_token(token_ptr, TYPES[HUGE])) ) {
  160.          *__type = HUGE;
  161.          return (str_pos);
  162.          }
  163.       break;
  164.  
  165.     case 'i':
  166.     if ( (str_pos = test_token(token_ptr, TYPES[INTEGER])) ) {
  167.          *__type = INTEGER;
  168.          return (str_pos + holdpos);
  169.          }
  170.       break;
  171.  
  172.      case 'l':
  173.       if ( (str_pos = test_token(token_ptr, TYPES[LONG])) ) {
  174.         str_pos += data_type_(p + str_pos, __type);
  175.         *__type = LONG;
  176.          return (str_pos);
  177.          }
  178.       break;
  179.  
  180.     case 's':
  181.     if ( (str_pos = test_token(token_ptr, TYPES[SIGNED])) ) {
  182.          str_pos += data_type_(p + str_pos, __type);
  183.          *__type = SIGNED;
  184.          return (str_pos);
  185.          }
  186.     if ( (str_pos = test_token(token_ptr, TYPES[SHORT])) ) {
  187.          *__type = SHORT;
  188.          return (str_pos);
  189.          }
  190.     if ( (str_pos = test_token(token_ptr, TYPES[STRUCTURE])) )
  191.          {
  192.          strL = strlen(p);
  193.          p += strL;
  194.          p++;
  195.          while (iswhite(*p) && *p) { p++; str_pos++; }
  196.          while (isalnum( (int) *p ) ) { p++; str_pos++; }
  197.          while (iswhite(*p) && *p)
  198.         { p++; str_pos++; }
  199.          while (isalnum( (int) *p) || *p == '_')
  200.         { p++; str_pos++; }
  201.          while(is_in(*p, " *") && *p)
  202.         {
  203.         p++;
  204.         str_pos++;
  205.         }
  206.          *__type = STRUCTURE;
  207.          return (str_pos);
  208.          }
  209.  
  210.     if ( (str_pos = test_token(token_ptr, TYPES[SEGMENT])) ) {
  211.          *__type = SEGMENT;
  212.          return (str_pos);
  213.          }
  214.  
  215.        break;
  216.  
  217.      case 't':
  218.        if ( (str_pos = test_token(token_ptr, TYPES[TYPEDEF])) ) {
  219.          typedef_open = get_typedef(test);
  220.          *__type = TYPEDEF + 100 + typedef_open;
  221.          return(0);
  222.          }
  223.       break;
  224.  
  225.     case 'u':
  226.     if ( (str_pos = test_token(token_ptr, TYPES[UNSIGNED])) ) {
  227.          str_pos += data_type_(p + str_pos, __type);
  228.          *__type = UNSIGNED;
  229.          return (str_pos);
  230.          }
  231.     if ( (str_pos = test_token(token_ptr, TYPES[UNION])) ) {
  232.          str_pos += data_type_(p += str_pos, __type);
  233.          *__type = UNION;
  234.          return (str_pos);
  235.          }
  236.  
  237.     break;
  238.  
  239.     case 'v':
  240.       if ( (str_pos = test_token(token_ptr, TYPES[VOID])) ) {
  241.          *__type = VOID;
  242.          return (str_pos);
  243.          }
  244.       break;
  245.  
  246.  
  247.      }
  248.  
  249.       if ( (str_pos = check_types(token_ptr, &__typenum))) {
  250.       if (( __typ_mod[__typenum] & 0xf) == _TYPE_) {
  251.          *__type = TYPEDEF;
  252.           return(str_pos);
  253.           }
  254.         }
  255.  
  256.      return(0);
  257. }
  258.  
  259.  
  260.  
  261.  
  262. int _modifier (char *test, int t_pos)
  263. {
  264.   char *p,  *token_ptr;
  265.   int str_pos = t_pos, post_ptr_strpos;
  266.   char _mod_buffer[261];
  267.   int ptr_count = 0, mod_type = NO_TYPE, underscore = 0;
  268.  
  269.   strcpy (_mod_buffer, test + t_pos);
  270.   p = _mod_buffer;
  271.  
  272.  
  273.   post_ptr_strpos = check_pointers(p, &ptr_count);
  274.   p += post_ptr_strpos;
  275.   if (*p == '/'  && !In_MainLoop) return(0);
  276.   str_pos += post_ptr_strpos;
  277.   t_pos = str_pos;
  278.  
  279.   if (*p == '_') {  p++; underscore = 1; }
  280.   token_ptr  = p;
  281.   while ( *p != '\x20' && *p != '\x9' && *p != '(' && *p != '\0') p++;
  282.   *p = '\0';      /* isolate first element in line  */
  283.  
  284.    switch (*token_ptr)
  285.    {
  286.     case 'b':
  287.       str_pos += test_token(token_ptr, MODIFIERS[BASED]);
  288.         if(str_pos > t_pos) mod_type = BASED;
  289.          break;
  290.  
  291.     case 'c':
  292.       str_pos += test_token(token_ptr, MODIFIERS[CDECL]);
  293.        if(str_pos > t_pos) {
  294.        mod_type = CDECL;
  295.        break;
  296.        }
  297.  
  298.       str_pos += test_token(token_ptr, MODIFIERS[CONSTANT]);
  299.        if(str_pos > t_pos)   mod_type = CONSTANT;
  300.          break;
  301.  
  302.     case 'e':
  303.       str_pos += test_token(token_ptr, MODIFIERS[EXTERN]);
  304.        if(str_pos > t_pos) mod_type = EXTERN;
  305.        break;
  306.  
  307.     case 'f':
  308.        str_pos += test_token(token_ptr, MODIFIERS[FAR]);
  309.        if(str_pos > t_pos)  mod_type = FAR;
  310.         break;
  311.        str_pos += test_token(token_ptr, MODIFIERS[FORTRAN]);
  312.        if(str_pos > t_pos)   mod_type = FORTRAN;
  313.          break;
  314.  
  315.     case 'i':
  316.       str_pos += test_token(token_ptr, MODIFIERS[INTERRUPT]);
  317.        if(str_pos > t_pos)   mod_type = INTERRUPT;
  318.          break;
  319.  
  320.     case 'l':
  321.       str_pos += test_token(token_ptr, MODIFIERS[LOADDS]);
  322.        if(str_pos > t_pos)   mod_type = LOADDS;
  323.          break;
  324.  
  325.     case 'n':
  326.       str_pos += test_token(token_ptr, MODIFIERS[NEAR]);
  327.        if(str_pos > t_pos)   mod_type = NEAR;
  328.          break;
  329.  
  330.     case 'p':
  331.       str_pos += test_token(token_ptr, MODIFIERS[PASCAL]);
  332.        if(str_pos > t_pos)   mod_type = PASCAL;
  333.          break;
  334.  
  335.     case 's':
  336.       str_pos += test_token(token_ptr, MODIFIERS[STATIC]);
  337.        if(str_pos > t_pos)   mod_type = STATIC;
  338.          break;
  339.       str_pos += test_token(token_ptr, MODIFIERS[SEGNAME]);
  340.        if(str_pos > t_pos)   mod_type = SEGNAME;
  341.          break;
  342.  
  343.     case 'v':
  344.       str_pos += test_token(token_ptr, MODIFIERS[VOLATILE]);
  345.        if(str_pos > t_pos)   mod_type = VOLATILE;
  346.          break;
  347.  
  348.    }
  349.  
  350.    if (__mods[0] && mod_type != NO_TYPE) {
  351.       if (__mods[0] < _MAX_MODS) {
  352.         ptr_count <<= 8;
  353.       __mods[__mods[0]++] =  mod_type | ptr_count;
  354.       }
  355.        }
  356.  
  357.   /* Check user defs if parsing functions; for globals this is */
  358.   /* done in get_modifiers() in UTLG_CA */
  359.   if (In_MainLoop) {
  360.       int temp = 0;
  361.       char *tp = token_ptr;
  362.       if (underscore)
  363.       --tp;
  364.       if ( (temp = check_types(tp, &__typenum))) {
  365.       if (__typ_mod[__typenum] == _MOD_)
  366.           str_pos += temp;
  367.       }
  368.        }
  369.  
  370.     /* check for additional modifiers */
  371.   if (str_pos != t_pos )
  372.      {
  373.      p++; str_pos++;
  374.      while (iswhite(*p) && *p) { p++; str_pos++; }
  375.  
  376.      if(!underscore) str_pos--;
  377.      str_pos = _modifier (test,  str_pos);
  378.      }
  379.  
  380.   if (ptr_count && mod_type == NO_TYPE)
  381.        str_pos -= post_ptr_strpos;
  382.   return(str_pos) ;
  383. }
  384.  
  385.  
  386.