1 | /***************************************
2 | $Header: /home/amb/cxref/RCS/file.c 1.10 1997/05/17 15:06:01 amb Exp $
3 |
4 | C Cross Referencing & Documentation tool. Version 1.4.
5 |
6 | Sets up the top level File structure.
7 | ******************/ /******************
8 | Written by Andrew M. Bishop
9 |
10 | This file Copyright 1995,96,97 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 | ***************************************/
15 |
16 | /*+ To control the debugging in this file. +*/
17 | #define DEBUG 0
18 |
19 | #include <stdlib.h>
20 | #include <stdio.h>
21 | #include <string.h>
22 |
23 | #include "memory.h"
24 | #include "datatype.h"
25 | #include "cxref.h"
26 |
27 | /*+ This contains the File that is currently being documented to allow the other functions access to it. +*/
28 | extern File CurFile;
29 |
30 | /*++++++++++++++++++++++++++++++++++++++
31 | Creates a new File structure.
32 |
33 | File NewFile Returns the new file structure.
34 |
35 | char* name The name of the file.
36 | ++++++++++++++++++++++++++++++++++++++*/
37 |
38 | File NewFile(char* name)
39 | {
40 | File file=(File)Calloc(1,sizeof(struct _File));
41 |
42 | file->name=MallocString(name);
43 | file->inc_in=NewStringList();
44 | file->f_refs=NewStringList2();
45 | file->v_refs=NewStringList2();
46 |
47 | return(file);
48 | }
49 |
50 |
51 | /*++++++++++++++++++++++++++++++++++++++
52 | Called when a file comment has been seen. Only the first of multiple comments in a file are used.
53 |
54 | char* comment The comment for the file.
55 | ++++++++++++++++++++++++++++++++++++++*/
56 |
57 | void SeenFileComment(char* comment)
58 | {
59 | if(!CurFile->comment)
60 | CurFile->comment=MallocString(comment);
61 | }
62 |
63 |
64 | /*++++++++++++++++++++++++++++++++++++++
65 | Deletes a file structure.
66 |
67 | File file The file structure to be deleted.
68 |
69 | This is required to go through each of the elements in the File structure and delete each of them in turn.
70 | ++++++++++++++++++++++++++++++++++++++*/
71 |
72 | void DeleteFile(File file)
73 | {
74 | if(file->comment) Free(file->comment);
75 | if(file->name) Free(file->name);
76 |
77 | if(file->inc_in) DeleteStringList(file->inc_in);
78 | if(file->f_refs) DeleteStringList2(file->f_refs);
79 | if(file->v_refs) DeleteStringList2(file->v_refs);
80 |
81 | if(file->includes)
82 | {
83 | Include p=file->includes;
84 | do{
85 | Include n=p->next;
86 | DeleteIncludeType(p);
87 | p=n;
88 | }
89 | while(p);
90 | }
91 |
92 | if(file->defines)
93 | {
94 | Define p=file->defines;
95 | do{
96 | Define n=p->next;
97 | DeleteDefineType(p);
98 | p=n;
99 | }
100 | while(p);
101 | }
102 |
103 | if(file->typedefs)
104 | {
105 | Typedef p=file->typedefs;
106 | do{
107 | Typedef n=p->next;
108 | DeleteTypedefType(p);
109 | p=n;
110 | }
111 | while(p);
112 | }
113 |
114 | if(file->variables)
115 | {
116 | Variable p=file->variables;
117 | do{
118 | Variable n=p->next;
119 | DeleteVariableType(p);
120 | p=n;
121 | }
122 | while(p);
123 | }
124 |
125 | if(file->functions)
126 | {
127 | Function p=file->functions;
128 | do{
129 | Function n=p->next;
130 | DeleteFunctionType(p);
131 | p=n;
132 | }
133 | while(p);
134 | }
135 |
136 | Free(file);
137 | }