File: sxpdbf.c

package info (click to toggle)
pact 980714-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 13,096 kB
  • ctags: 26,034
  • sloc: ansic: 109,076; lisp: 9,645; csh: 7,147; fortran: 1,050; makefile: 136; lex: 95; sh: 32
file content (175 lines) | stat: -rw-r--r-- 5,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * SXPDBF.C - PDB find functionality in SX
 *
 * Source Version: 3.0
 * Software Release #92-0043
 *
 */

#include "cpyright.h"
 
#include "sx.h"

static char
 TYPE[10];

void
 SC_DECLARE(_SX_find_data,
         (HASHTAB *type_table, PDBfile *file, byte *vr, 
          long nitems, char *type)), 
 SC_DECLARE(_SX_find_indirection,
         (HASHTAB *type_table, PDBfile *file, char **vr, 
          long nitems, char *type)), 
 SC_DECLARE(_SX_find_leaf,
         (HASHTAB *type_table, PDBfile *file, char *vr, 
          long nitems, char *type));

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* SX_FIND_TYPES - find all types used by this variable */

object *SX_find_types(arg)
   object *arg;
   {char *type;
    long nitems;
    byte *vr;
    HASHTAB *type_table;
    object *args, *obj;
    PDBfile *file;
    syment *ep;

    if (!SX_PDBDATAP(arg))
       SS_error("MUST BE PDBDATA - SX_FIND_TYPES", arg);

    file   = PDBDATA_FILE(arg);
    ep     = PDBDATA_EP(arg);
    vr     = PDBDATA_DATA(arg);
    type   = PD_entry_type(ep);
    nitems = PD_entry_number(ep);

/* create a hash table to put all of these types in */
    type_table = SC_make_hash_table(HSZSMALL, NODOC);
    strcpy(TYPE, "type");

/* fill the hash table with the types */
    _SX_find_data(type_table, file, vr, nitems, type);

/* convert table to list */
    args = SS_mk_cons(SS_mk_hash_table(type_table), 
                      SS_null);
    obj = SS_hash_dump(args);

/* delete hash table */
    SC_hash_clr(type_table);

    return(obj);}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* _SX_FIND_DATA - locate part of a data element */

void _SX_find_data(type_table, file, vr, nitems, type)
   HASHTAB *type_table;
   PDBfile *file;
   byte *vr;
   long nitems;
   char *type;
   {

/* if the type is an indirection, follow the pointer */
    if (_PD_indirection(type))
       _SX_find_indirection(type_table, file, (char **) vr, nitems, type);
    else
       _SX_find_leaf(type_table, file,  vr, nitems, type);

    return;}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* _SX_FIND_INDIRECTION - locate part of a data element thru indirection */

void _SX_find_indirection(type_table, file, vr, nitems, type)
   HASHTAB *type_table;
   PDBfile *file;
   char **vr;
   long nitems;
   char *type;
   {long i, ditems;
    char *dtype, bf[MAXLINE];

    dtype = PD_dereference(SC_strsavef(type,
                           "char*:_SX_FIND_INDIRECTION:dtype"));

    for (i = 0L; i < nitems; i++, vr++)
        {ditems = _PD_number_refd(DEREF(vr), dtype, file->host_chart);

         if (ditems == -1L)
            {sprintf(bf, 
                     "CAN'T GET POINTER LENGTH ON %s - _SX_FIND_INDIRECTION", 
                     dtype);
             SS_error(bf, SS_null);};

         if (ditems == -2L)
            {sprintf(bf, 
                     "UNKNOW TYPE %s - _SX_FIND_INDIRECTION", 
                     dtype);
             SS_error(bf, SS_null);};

/* if the type is an indirection, follow the pointer */
         if (_PD_indirection(dtype))
            _SX_find_indirection(type_table, file, (char **) DEREF(vr), 
                                 ditems, dtype);
         else
            _SX_find_leaf(type_table, file, DEREF(vr), ditems, dtype);};

    SFREE(dtype);

    return;}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* _SX_FIND_LEAF - if 'type' is a primitive type, display the data, 
 *               - otherwise, lookup the type, and display each member.
 */

void _SX_find_leaf(type_table, file, vr, nitems, type)
   HASHTAB *type_table;
   PDBfile *file;
   char *vr;
   long nitems;
   char *type;
   {long i, sz;
    char *svr;
    defstr *defp;
    HASHTAB *tab;
    memdes *desc, *mem_lst;

    tab = file->host_chart;

/* print out the type */
    defp = PD_inquire_table_type(tab, type);
    if (defp == NULL)
       SS_error("VARIABLE NOT IN STRUCTURE CHART - _SX_FIND_LEAF", SS_null);

    mem_lst = defp->members;
    if (mem_lst != NULL)
       {SC_install(type, TYPE, TYPE, type_table);
	sz  = defp->size;
	svr = vr;
        for (i = 0L; i < nitems; i++, svr += sz)
            {if (pdb_wr_hook != NULL)
                mem_lst = (*pdb_wr_hook)(file, svr, defp);

             for (desc = mem_lst; desc != NULL; desc = desc->next)
                 {_SX_find_data(type_table, file,
				(char *) (svr + desc->member_offs), 
                                desc->number, desc->type);};};};

    return;}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/