/usr/share/doc/cxref-doc/examples/var.c.src.html is in cxref-doc 1.6d-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- This HTML file generated by cxref (version 1.6d). -->
<!-- cxref program (c) Andrew M. Bishop 1995-2011. -->
<!--
Cxref: ./cxref -warn-xref -xref -O../doc/example -Ncxref -latex -html-src -rtf -sgml var.c
CPP : /build/buildd/cxref-1.6d/cpp/cxref-cpp -cxref-cpp-defines /build/buildd/cxref-1.6d/cpp/cxref-cpp.defines -lang-c -C -dD -dI
-->
<HTML>
<HEAD>
<TITLE>Source File var.c</TITLE>
<LINK rel="stylesheet" href="cxref.css" type="text/css">
</HEAD>
<BODY>
<pre>
<a name="line1">1 |</a> /***************************************
<a name="line2">2 |</a> $Header: /home/amb/CVS/cxref/src/var.c,v 1.14 2004-01-10 20:43:06 amb Exp $
<a name="line3">3 |</a>
<a name="line4">4 |</a> C Cross Referencing & Documentation tool. Version 1.5f.
<a name="line5">5 |</a>
<a name="line6">6 |</a> Collects the variable definition stuff.
<a name="line7">7 |</a> ******************/ /******************
<a name="line8">8 |</a> Written by Andrew M. Bishop
<a name="line9">9 |</a>
<a name="line10">10 |</a> This file Copyright 1995,96,97,99,2004 Andrew M. Bishop
<a name="line11">11 |</a> It may be distributed under the GNU Public License, version 2, or
<a name="line12">12 |</a> any higher version. See section COPYING of the GNU Public license
<a name="line13">13 |</a> for conditions under which this file may be redistributed.
<a name="line14">14 |</a> ***************************************/
<a name="line15">15 |</a>
<a name="line16">16 |</a> /*+ Control the output of debugging information from this file. +*/
<a name="line17">17 |</a> #define DEBUG 0
<a name="line18">18 |</a>
<a name="line19">19 |</a> #include <stdlib.h>
<a name="line20">20 |</a> #include <stdio.h>
<a name="line21">21 |</a> #include <string.h>
<a name="line22">22 |</a>
<a name="line23">23 |</a> #include "memory.h"
<a name="line24">24 |</a> #include "datatype.h"
<a name="line25">25 |</a> #include "parse-yy.h"
<a name="line26">26 |</a> #include "cxref.h"
<a name="line27">27 |</a>
<a name="line28">28 |</a> /*+ The file that is currently being documented. +*/
<a name="line29">29 |</a> extern File CurFile;
<a name="line30">30 |</a>
<a name="line31">31 |</a> /*+ When in a header file make a note of which one for the included variables. +*/
<a name="line32">32 |</a> extern int in_header;
<a name="line33">33 |</a>
<a name="line34">34 |</a> /*+ A list of the variables found at each level of the scope. +*/
<a name="line35">35 |</a> static StringList2 *variable;
<a name="line36">36 |</a>
<a name="line37">37 |</a> /*+ The number of levels of scope depth allocated. +*/
<a name="line38">38 |</a> static int max_scope=0;
<a name="line39">39 |</a>
<a name="line40">40 |</a> /*+ The current scope depth. +*/
<a name="line41">41 |</a> static int cur_scope=-1;
<a name="line42">42 |</a>
<a name="line43">43 |</a>
<a name="line44">44 |</a> static Variable NewVariableType(char *name,char *type);
<a name="line45">45 |</a>
<a name="line46">46 |</a>
<a name="line47">47 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line48">48 |</a> Function that is called when a variable definition is seen.
<a name="line49">49 |</a>
<a name="line50">50 |</a> char* name The name of the variable.
<a name="line51">51 |</a>
<a name="line52">52 |</a> char* type The type of the variable.
<a name="line53">53 |</a>
<a name="line54">54 |</a> int scope The scope of variable that has been seen.
<a name="line55">55 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line56">56 |</a>
<a name="line57">57 |</a> void SeenVariableDefinition(char* name,char* type,int scope)
<a name="line58">58 |</a> {
<a name="line59">59 |</a> Variable var;
<a name="line60">60 |</a> int seen=0;
<a name="line61">61 |</a>
<a name="line62">62 |</a> #if DEBUG
<a name="line63">63 |</a> printf("#Var.c# Variable definition for '%s'\n",name);
<a name="line64">64 |</a> #endif
<a name="line65">65 |</a>
<a name="line66">66 |</a> for(var=CurFile->variables;var;var=var->next)
<a name="line67">67 |</a> if(!strcmp(var->name,name))
<a name="line68">68 |</a> {
<a name="line69">69 |</a> var->scope|=scope;
<a name="line70">70 |</a> seen=1;
<a name="line71">71 |</a> if(!in_header && var->scope&EXTERN_H)
<a name="line72">72 |</a> {
<a name="line73">73 |</a> if(var->comment)
<a name="line74">74 |</a> Free(var->comment);
<a name="line75">75 |</a> var->comment=MallocString(GetCurrentComment());
<a name="line76">76 |</a> var->lineno=parse_line;
<a name="line77">77 |</a> }
<a name="line78">78 |</a> break;
<a name="line79">79 |</a> }
<a name="line80">80 |</a>
<a name="line81">81 |</a> if(!seen)
<a name="line82">82 |</a> {
<a name="line83">83 |</a> var=NewVariableType(name,type);
<a name="line84">84 |</a>
<a name="line85">85 |</a> var->comment=MallocString(GetCurrentComment());
<a name="line86">86 |</a> var->scope=scope;
<a name="line87">87 |</a>
<a name="line88">88 |</a> var->lineno=parse_line;
<a name="line89">89 |</a>
<a name="line90">90 |</a> if(in_header && !(scope&EXTERN_H))
<a name="line91">91 |</a> var->incfrom=MallocString(parse_file);
<a name="line92">92 |</a>
<a name="line93">93 |</a> AddToLinkedList(CurFile->variables,Variable,var);
<a name="line94">94 |</a> }
<a name="line95">95 |</a> }
<a name="line96">96 |</a>
<a name="line97">97 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line98">98 |</a> Called when a new scope is entered.
<a name="line99">99 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line100">100 |</a>
<a name="line101">101 |</a> void UpScope(void)
<a name="line102">102 |</a> {
<a name="line103">103 |</a> cur_scope++;
<a name="line104">104 |</a>
<a name="line105">105 |</a> #if DEBUG
<a name="line106">106 |</a> printf("#Var.c# Scope ++ (%2d)\n",cur_scope);
<a name="line107">107 |</a> #endif
<a name="line108">108 |</a>
<a name="line109">109 |</a> if(cur_scope>=max_scope)
<a name="line110">110 |</a> {
<a name="line111">111 |</a> if(max_scope==0)
<a name="line112">112 |</a> variable=Malloc(16*sizeof(StringList2));
<a name="line113">113 |</a> else
<a name="line114">114 |</a> variable=Realloc(variable,(max_scope+16)*sizeof(StringList2));
<a name="line115">115 |</a> max_scope+=16;
<a name="line116">116 |</a> }
<a name="line117">117 |</a>
<a name="line118">118 |</a> variable[cur_scope]=NewStringList2();
<a name="line119">119 |</a> }
<a name="line120">120 |</a>
<a name="line121">121 |</a>
<a name="line122">122 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line123">123 |</a> Called when an old scope is exited.
<a name="line124">124 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line125">125 |</a>
<a name="line126">126 |</a> void DownScope(void)
<a name="line127">127 |</a> {
<a name="line128">128 |</a> #if DEBUG
<a name="line129">129 |</a> printf("#Var.c# Scope -- (%2d)\n",cur_scope);
<a name="line130">130 |</a> #endif
<a name="line131">131 |</a>
<a name="line132">132 |</a> DeleteStringList2(variable[cur_scope]);
<a name="line133">133 |</a>
<a name="line134">134 |</a> cur_scope--;
<a name="line135">135 |</a> }
<a name="line136">136 |</a>
<a name="line137">137 |</a>
<a name="line138">138 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line139">139 |</a> Add a variable to the list of known variables.
<a name="line140">140 |</a>
<a name="line141">141 |</a> char* name The name of the variable.
<a name="line142">142 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line143">143 |</a>
<a name="line144">144 |</a> void SeenScopeVariable(char* name)
<a name="line145">145 |</a> {
<a name="line146">146 |</a> #if DEBUG
<a name="line147">147 |</a> printf("#Var.c# Scope Variable depth %2d '%s'\n",cur_scope,name);
<a name="line148">148 |</a> #endif
<a name="line149">149 |</a>
<a name="line150">150 |</a> AddToStringList2(variable[cur_scope],name,NULL,0,0);
<a name="line151">151 |</a> }
<a name="line152">152 |</a>
<a name="line153">153 |</a>
<a name="line154">154 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line155">155 |</a> Check through the scope variables to look for the named one.
<a name="line156">156 |</a>
<a name="line157">157 |</a> int IsAScopeVariable Returns 1 if the name does refer to a variable that is scoped.
<a name="line158">158 |</a>
<a name="line159">159 |</a> char* name The name of the variable to search for.
<a name="line160">160 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line161">161 |</a>
<a name="line162">162 |</a> int IsAScopeVariable(char* name)
<a name="line163">163 |</a> {
<a name="line164">164 |</a> int i,scope;
<a name="line165">165 |</a>
<a name="line166">166 |</a> #if DEBUG
<a name="line167">167 |</a> printf("#Var.c# Lookup variable '%s'\n",name);
<a name="line168">168 |</a> #endif
<a name="line169">169 |</a>
<a name="line170">170 |</a> for(scope=cur_scope;scope>=0;scope--)
<a name="line171">171 |</a> for(i=0;i<variable[scope]->n;i++)
<a name="line172">172 |</a> if(!strcmp(variable[scope]->s1[i],name))
<a name="line173">173 |</a> return(1);
<a name="line174">174 |</a>
<a name="line175">175 |</a> return(0);
<a name="line176">176 |</a> }
<a name="line177">177 |</a>
<a name="line178">178 |</a>
<a name="line179">179 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line180">180 |</a> Tidy up all of the local variables in case of a problem and abnormal parser termination.
<a name="line181">181 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line182">182 |</a>
<a name="line183">183 |</a> void ResetVariableAnalyser(void)
<a name="line184">184 |</a> {
<a name="line185">185 |</a> while(cur_scope>=0)
<a name="line186">186 |</a> {
<a name="line187">187 |</a> DeleteStringList2(variable[cur_scope]);
<a name="line188">188 |</a> cur_scope--;
<a name="line189">189 |</a> }
<a name="line190">190 |</a>
<a name="line191">191 |</a> if(variable) Free(variable);
<a name="line192">192 |</a> variable=NULL;
<a name="line193">193 |</a>
<a name="line194">194 |</a> max_scope=0;
<a name="line195">195 |</a> cur_scope=-1;
<a name="line196">196 |</a> }
<a name="line197">197 |</a>
<a name="line198">198 |</a>
<a name="line199">199 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line200">200 |</a> Create a new variable type.
<a name="line201">201 |</a>
<a name="line202">202 |</a> Variable NewVariableType Returns a new Variable type.
<a name="line203">203 |</a>
<a name="line204">204 |</a> char *name The name of the variable.
<a name="line205">205 |</a>
<a name="line206">206 |</a> char *type The type of the variable.
<a name="line207">207 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line208">208 |</a>
<a name="line209">209 |</a> static Variable NewVariableType(char *name,char *type)
<a name="line210">210 |</a> {
<a name="line211">211 |</a> Variable var=(Variable)Calloc(1,sizeof(struct _Variable)); /* clear unused pointers */
<a name="line212">212 |</a>
<a name="line213">213 |</a> var->name =MallocString(name);
<a name="line214">214 |</a> var->type =MallocString(type);
<a name="line215">215 |</a> var->visible=NewStringList2();
<a name="line216">216 |</a> var->used =NewStringList2();
<a name="line217">217 |</a>
<a name="line218">218 |</a> return(var);
<a name="line219">219 |</a> }
<a name="line220">220 |</a>
<a name="line221">221 |</a>
<a name="line222">222 |</a> /*++++++++++++++++++++++++++++++++++++++
<a name="line223">223 |</a> Delete the specified Variable type.
<a name="line224">224 |</a>
<a name="line225">225 |</a> Variable var The Variable type to be deleted.
<a name="line226">226 |</a> ++++++++++++++++++++++++++++++++++++++*/
<a name="line227">227 |</a>
<a name="line228">228 |</a> void DeleteVariableType(Variable var)
<a name="line229">229 |</a> {
<a name="line230">230 |</a> if(var->comment) Free(var->comment);
<a name="line231">231 |</a> if(var->name) Free(var->name);
<a name="line232">232 |</a> if(var->type) Free(var->type);
<a name="line233">233 |</a> if(var->defined) Free(var->defined);
<a name="line234">234 |</a> if(var->incfrom) Free(var->incfrom);
<a name="line235">235 |</a> if(var->visible) DeleteStringList2(var->visible);
<a name="line236">236 |</a> if(var->used) DeleteStringList2(var->used);
<a name="line237">237 |</a> Free(var);
<a name="line238">238 |</a> }
</pre>
</BODY>
</HTML>
|