1 /***************************************
4 C Cross Referencing & Documentation tool. Version 1.4.
5 ******************/ /******************
6 Written by Andrew M. Bishop
8 This file Copyright 1995,96,97 Andrew M. Bishop
9 It may be distributed under the GNU Public License, version 2, or
10 any higher version. See section COPYING of the GNU Public license
11 for conditions under which this file may be redistributed.
12 ***************************************/
18 #include "../memory.h"
19 #include "../datatype.h"
24 /*+ The command line switch that sets the amount of cross referencing to do. +*/
25 extern int option_xref
;
27 extern File
*files
; /*+ The files that are queried. +*/
28 extern int n_files
; /*+ The number of files referenced. +*/
30 extern Function
*functions
; /*+ The functions that are queried. +*/
31 extern int n_functions
; /*+ The number of functions referenced. +*/
33 extern Variable
*variables
; /*+ The variables that are queried. +*/
34 extern int n_variables
; /*+ The number of variables referenced. +*/
36 extern Typedef
*typedefs
; /*+ The type definitions that are queried. +*/
37 extern int n_typedefs
; /*+ The number of typedefs referenced. +*/
41 static void OutputFile(File file
);
42 static void OutputInclude(Include incl
,int depth
);
43 static void OutputFunction(Function func
);
44 static void OutputVariable(Variable var
);
45 static void OutputTypedef(Typedef type
);
48 /*++++++++++++++++++++++++++++++++++++++
49 Ouput the cross references for the named thing.
51 char* name The name of the object to ouput the cross references for.
52 ++++++++++++++++++++++++++++++++++++++*/
54 void OutputCrossRef(char* name
)
58 for(i
=0;i
<n_files
;i
++)
59 if(!strcmp(name
,files
[i
]->name
))
60 {OutputFile(files
[i
]);any
++;}
62 for(i
=0;i
<n_typedefs
;i
++)
63 if(!strcmp(name
,typedefs
[i
]->name
))
64 {OutputTypedef(typedefs
[i
]);any
++;}
66 for(i
=0;i
<n_variables
;i
++)
67 if(!strcmp(name
,variables
[i
]->name
))
68 {OutputVariable(variables
[i
]);any
++;}
70 for(i
=0;i
<n_functions
;i
++)
71 if(!strcmp(name
,functions
[i
]->name
))
72 {OutputFunction(functions
[i
]);any
++;}
75 printf("cxref-query: No match for '%s'.\n",name
);
78 /*++++++++++++++++++++++++++++++++++++++
79 Print out the information for a file.
81 File file The file to output the information for.
82 ++++++++++++++++++++++++++++++++++++++*/
84 static void OutputFile(File file
)
92 printf("File: %s\n\n",file
->name
);
94 for(inc
=file
->includes
,i
=0;inc
;inc
=inc
->next
,i
++)
96 printf(" %s %c%s%c\n",i
?" ":"Includes: ",inc
->scope
==GLOBAL
?'<':'"',inc
->name
,inc
->scope
==GLOBAL
?'>':'"');
102 for(func
=file
->functions
,i
=0;func
;func
=func
->next
,i
++)
103 printf(" %s %s\n",i
?" ":"Functions:",func
->name
);
107 for(var
=file
->variables
,i
=0;var
;var
=var
->next
,i
++)
108 printf(" %s %s\n",i
?" ":"Variables:",var
->name
);
112 for(type
=file
->typedefs
,i
=0;type
;type
=type
->next
,i
++)
113 printf(" %s %s\n",i
?" ":"Types: ",type
->name
);
117 if(option_xref
&XREF_FILE
)
119 for(i
=0;i
<file
->inc_in
->n
;i
++)
120 printf(" %s %s\n",i
?" ":"Included in:",file
->inc_in
->s
[i
]);
125 if(option_xref
&XREF_FUNC
)
127 for(i
=0;i
<file
->f_refs
->n
;i
++)
128 printf(" %s %s : %s\n",i
?" ":"Refs func: ",file
->f_refs
->s1
[i
],file
->f_refs
->s2
[i
]);
133 if(option_xref
&XREF_VAR
)
135 for(i
=0;i
<file
->v_refs
->n
;i
++)
136 printf(" %s %s : %s\n",i
?" ":"Refs var: ",file
->v_refs
->s1
[i
],file
->v_refs
->s2
[i
]);
143 /*++++++++++++++++++++++++++++++++++++++
144 Print out the information for an include file.
146 Include incl The include file to output the information for.
148 int depth The depth of the includes.
149 ++++++++++++++++++++++++++++++++++++++*/
151 static void OutputInclude(Include incl
,int depth
)
156 for(inc
=incl
->includes
,c
=0;inc
;inc
=inc
->next
,c
++)
158 for(i
=0;i
<depth
;i
++) fputs(" ",stdout
);
159 printf(" %c%s%c\n",inc
->scope
==GLOBAL
?'<':'"',inc
->name
,inc
->scope
==GLOBAL
?'>':'"');
160 OutputInclude(inc
,depth
+1);
165 /*++++++++++++++++++++++++++++++++++++++
166 Print out the information for a typedef.
168 Typedef type The typedef to output the information for.
169 ++++++++++++++++++++++++++++++++++++++*/
171 static void OutputTypedef(Typedef type
)
173 printf("In file: %s\n",type
->comment
);
176 printf("Typedef: %s = %s\n",type
->name
,type
->type
);
178 printf("Type: %s\n",type
->name
);
184 /*++++++++++++++++++++++++++++++++++++++
185 Print out the information for a variable.
187 Variable var The variable to output the information for.
188 ++++++++++++++++++++++++++++++++++++++*/
190 static void OutputVariable(Variable var
)
194 printf("In file: %s\n",var
->comment
);
196 printf("Variable: %s [",var
->name
);
197 if(var
->scope
&LOCAL
) done
=printf("Local");
198 if(var
->scope
&GLOBAL
) done
=printf("%sGlobal definition",done
?" and ":"");
199 if(var
->scope
&EXTERNAL
) done
=printf("%sExternal",done
?" and ":"");
200 if(var
->scope
&EXTERN_H
) done
=printf("%sExternal from header file",done
?" and ":"");
201 if(var
->scope
&EXTERN_F
) done
=printf("%sExternal within function",done
?" and ":"");
204 if(option_xref
&XREF_VAR
)
206 if(var
->scope
&(GLOBAL
|LOCAL
))
207 for(i
=0;i
<var
->visible
->n
;i
++)
208 printf(" %s %s : %s\n",i
?" ":"Visible in: ",var
->visible
->s1
[i
],var
->visible
->s2
[i
]);
210 for(i
=0;i
<var
->used
->n
;i
++)
211 if(var
->used
->s1
[i
][0]=='$')
212 printf(" %s %s\n",i
?" ":"Used in: ",var
->used
->s2
[i
]);
214 printf(" %s %s : %s\n",i
?" ":"Used in: ",var
->used
->s1
[i
],var
->used
->s2
[i
]);
221 /*++++++++++++++++++++++++++++++++++++++
222 Print out the information for a function.
224 Function func The function to output the information for.
225 ++++++++++++++++++++++++++++++++++++++*/
227 static void OutputFunction(Function func
)
231 printf("In file: %s\n",func
->comment
);
233 printf("Function: %s ",func
->name
);
237 case LOCAL
: printf("[Local]\n"); break;
238 case GLOBAL
: printf("[Global]\n"); break;
239 case LOCAL
+INLINED
: printf("[Local inline]\n"); break;
240 case INLINED
: printf("[inline]\n"); break;
244 if(option_xref
&XREF_FUNC
)
246 for(i
=0;i
<func
->calls
->n
;i
++)
247 printf(" %s %s : %s\n",i
?" ":"Calls: ",func
->calls
->s1
[i
],func
->calls
->s2
[i
]?func
->calls
->s2
[i
]:"?unknown?");
249 for(i
=0;i
<func
->called
->n
;i
++)
250 printf(" %s %s : %s\n",i
?" ":"Called from:",func
->called
->s1
[i
],func
->called
->s2
[i
]);
252 for(i
=0;i
<func
->used
->n
;i
++)
254 if(func
->used
->s1
[i
][0]=='$')
255 printf(" %s %s\n",i
?" ":"Used in: ",func
->used
->s2
[i
]);
257 printf(" %s %s : %s\n",i
?" ":"Used in: ",func
->used
->s1
[i
],func
->used
->s2
[i
]);
260 for(i
=0;i
<func
->f_refs
->n
;i
++)
261 printf(" %s %s : %s\n",i
?" ":"Refs func: ",func
->f_refs
->s1
[i
],func
->f_refs
->s2
[i
]?func
->f_refs
->s2
[i
]:"?unknown?");
264 if(option_xref
&XREF_VAR
)
265 for(i
=0;i
<func
->v_refs
->n
;i
++)
266 printf(" %s %s : %s\n",i
?" ":"Refs var: ",func
->v_refs
->s1
[i
],func
->v_refs
->s2
[i
]?func
->v_refs
->s2
[i
]:"?unknown?");