alsa.audio: move handling of XRUN when writting to the slave task
[AROS.git] / tools / cxref / var.c
blob980c07e8e75ccd56f071e3c913f10f1c5bb60854
1 /***************************************
2 $Header$
4 C Cross Referencing & Documentation tool. Version 1.5f.
6 Collects the variable definition stuff.
7 ******************/ /******************
8 Written by Andrew M. Bishop
10 This file Copyright 1995,96,97,99,2004 Andrew M. Bishop
11 It may be distributed under the GNU Public License, version 2, or
12 any higher version. See section COPYING of the GNU Public license
13 for conditions under which this file may be redistributed.
14 ***************************************/
16 /*+ Control the output of debugging information from this file. +*/
17 #define DEBUG 0
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
23 #include "memory.h"
24 #include "datatype.h"
25 #include "parse-yy.h"
26 #include "cxref.h"
28 /*+ The file that is currently being documented. +*/
29 extern File CurFile;
31 /*+ When in a header file make a note of which one for the included variables. +*/
32 extern int in_header;
34 /*+ A list of the variables found at each level of the scope. +*/
35 static StringList2 *variable;
37 /*+ The number of levels of scope depth allocated. +*/
38 static int max_scope=0;
40 /*+ The current scope depth. +*/
41 static int cur_scope=-1;
44 static Variable NewVariableType(char *name,char *type);
47 /*++++++++++++++++++++++++++++++++++++++
48 Function that is called when a variable definition is seen.
50 char* name The name of the variable.
52 char* type The type of the variable.
54 int scope The scope of variable that has been seen.
55 ++++++++++++++++++++++++++++++++++++++*/
57 void SeenVariableDefinition(char* name,char* type,int scope)
59 Variable var;
60 int seen=0;
62 #if DEBUG
63 printf("#Var.c# Variable definition for '%s'\n",name);
64 #endif
66 for(var=CurFile->variables;var;var=var->next)
67 if(!strcmp(var->name,name))
69 var->scope|=scope;
70 seen=1;
71 if(!in_header && var->scope&EXTERN_H)
73 if(var->comment)
74 Free(var->comment);
75 var->comment=MallocString(GetCurrentComment());
76 var->lineno=parse_line;
78 break;
81 if(!seen)
83 var=NewVariableType(name,type);
85 var->comment=MallocString(GetCurrentComment());
86 var->scope=scope;
88 var->lineno=parse_line;
90 if(in_header && !(scope&EXTERN_H))
91 var->incfrom=MallocString(parse_file);
93 AddToLinkedList(CurFile->variables,Variable,var);
97 /*++++++++++++++++++++++++++++++++++++++
98 Called when a new scope is entered.
99 ++++++++++++++++++++++++++++++++++++++*/
101 void UpScope(void)
103 cur_scope++;
105 #if DEBUG
106 printf("#Var.c# Scope ++ (%2d)\n",cur_scope);
107 #endif
109 if(cur_scope>=max_scope)
111 if(max_scope==0)
112 variable=Malloc(16*sizeof(StringList2));
113 else
114 variable=Realloc(variable,(max_scope+16)*sizeof(StringList2));
115 max_scope+=16;
118 variable[cur_scope]=NewStringList2();
122 /*++++++++++++++++++++++++++++++++++++++
123 Called when an old scope is exited.
124 ++++++++++++++++++++++++++++++++++++++*/
126 void DownScope(void)
128 #if DEBUG
129 printf("#Var.c# Scope -- (%2d)\n",cur_scope);
130 #endif
132 DeleteStringList2(variable[cur_scope]);
134 cur_scope--;
138 /*++++++++++++++++++++++++++++++++++++++
139 Add a variable to the list of known variables.
141 char* name The name of the variable.
142 ++++++++++++++++++++++++++++++++++++++*/
144 void SeenScopeVariable(char* name)
146 #if DEBUG
147 printf("#Var.c# Scope Variable depth %2d '%s'\n",cur_scope,name);
148 #endif
150 AddToStringList2(variable[cur_scope],name,NULL,0,0);
154 /*++++++++++++++++++++++++++++++++++++++
155 Check through the scope variables to look for the named one.
157 int IsAScopeVariable Returns 1 if the name does refer to a variable that is scoped.
159 char* name The name of the variable to search for.
160 ++++++++++++++++++++++++++++++++++++++*/
162 int IsAScopeVariable(char* name)
164 int i,scope;
166 #if DEBUG
167 printf("#Var.c# Lookup variable '%s'\n",name);
168 #endif
170 for(scope=cur_scope;scope>=0;scope--)
171 for(i=0;i<variable[scope]->n;i++)
172 if(!strcmp(variable[scope]->s1[i],name))
173 return(1);
175 return(0);
179 /*++++++++++++++++++++++++++++++++++++++
180 Tidy up all of the local variables in case of a problem and abnormal parser termination.
181 ++++++++++++++++++++++++++++++++++++++*/
183 void ResetVariableAnalyser(void)
185 while(cur_scope>=0)
187 DeleteStringList2(variable[cur_scope]);
188 cur_scope--;
191 if(variable) Free(variable);
192 variable=NULL;
194 max_scope=0;
195 cur_scope=-1;
199 /*++++++++++++++++++++++++++++++++++++++
200 Create a new variable type.
202 Variable NewVariableType Returns a new Variable type.
204 char *name The name of the variable.
206 char *type The type of the variable.
207 ++++++++++++++++++++++++++++++++++++++*/
209 static Variable NewVariableType(char *name,char *type)
211 Variable var=(Variable)Calloc(1,sizeof(struct _Variable)); /* clear unused pointers */
213 var->name =MallocString(name);
214 var->type =MallocString(type);
215 var->visible=NewStringList2();
216 var->used =NewStringList2();
218 return(var);
222 /*++++++++++++++++++++++++++++++++++++++
223 Delete the specified Variable type.
225 Variable var The Variable type to be deleted.
226 ++++++++++++++++++++++++++++++++++++++*/
228 void DeleteVariableType(Variable var)
230 if(var->comment) Free(var->comment);
231 if(var->name) Free(var->name);
232 if(var->type) Free(var->type);
233 if(var->defined) Free(var->defined);
234 if(var->incfrom) Free(var->incfrom);
235 if(var->visible) DeleteStringList2(var->visible);
236 if(var->used) DeleteStringList2(var->used);
237 Free(var);