/[MITgcm]/mitgcm.org/devel/buildweb/code-browser/F90Mapper/dd.c
ViewVC logotype

Contents of /mitgcm.org/devel/buildweb/code-browser/F90Mapper/dd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Wed Jul 23 17:54:35 2003 UTC (22 years ago) by edhill
Branch: MAIN
Changes since 1.1: +8 -1 lines
File MIME type: text/plain
These are initial changes made so that the mitgcm.org web site, LaTeX
documentation, HTML code browser, etc. will build on a relatively stock
RH 9 system.

1 /* $Id: dd.c,v 1.1.1.1 2002/09/20 19:47:31 adcroft Exp $ */
2 #include <stdio.h>
3 #include <string.h>
4 #include "GLOBALS.h"
5 #include "DD.h"
6
7 /*====================================================================
8 Package of routines for managing a table of names and associated
9 parameters. Used as tool for manipulating the data dictionary
10 associated with a list of program variables.
11 Data dictionary contains symbol names, certain symbol attributes
12 and pointers to a definition for that name.
13 ======================================================================*/
14
15 #define ddBLOCK 100 /* Dictionary. Initial size ddBLOCK. Grown in */
16 ddRecord *dd=NULL; /* Initial dictionary pointer. */
17 ddRecord *ddTmp=NULL;
18 int ddSize = 0; /* Size of table. */
19 int ddNused = 0; /* No. slots used in table. */
20 int ddCurrent = 0; /* Current record. */
21 int ddKey = 0; /* Identifier key. */
22
23 char *ddkey();
24
25 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
26 ddRecord *ddAdd( rec )
27 /* Add record at end of dictionary */
28 ddRecord *rec;
29 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
30 {
31 /* On first call create one block dd */
32 /* use malloc so we can realloc later */
33 if ( dd == NULL ) {
34 dd = (ddRecord *)malloc(sizeof(ddRecord)*ddBLOCK);
35 if ( dd == NULL ) return((ddRecord *)NULL);
36 ddSize = ddBLOCK;
37 }
38
39 /* No name so we can't insert */
40 if ( rec->name == NULL ) return ((ddRecord *)NULL);
41
42 /* Allocate more storage - if it is needed. */
43 if ( ddCurrent == ddSize ) {
44 /* Allocate another block of dd space. */
45 ddTmp=dd;
46 dd = (ddRecord *)realloc(dd,sizeof(*dd)*ddBLOCK+sizeof(*dd)*ddSize);
47 if ( dd == NULL ) {
48 dd=ddTmp;
49 return((ddRecord *)NULL);
50 }
51 ddSize = ddSize+ddBLOCK;
52 }
53
54 /* Now set values that are not NULL */
55 dd[ddCurrent].name = strdup(rec->name);
56
57 /* CNH Debug starts */
58 printf("ddAdd name=\"%s\", rec. no. = %d\n",rec->name,ddKey+1);
59
60 /* CNH Debug ends */
61
62
63 if ( dd[ddCurrent].name == NULL ) return((ddRecord *)NULL);
64 dd[ddCurrent].id = ddKey+1;
65 dd[ddCurrent].key = strdup(ddkey(ddKey+1));
66 if ( rec->hrefEntry != NULL ){
67 dd[ddCurrent].hrefEntry = strdup(rec->hrefEntry);
68 if ( dd[ddCurrent].hrefEntry == NULL ) return((ddRecord *)NULL);
69 } else {
70 dd[ddCurrent].hrefEntry = NULL;
71 }
72
73 if ( rec->textEntry != NULL ){
74 dd[ddCurrent].textEntry = strdup(rec->textEntry);
75 if ( dd[ddCurrent].textEntry == NULL ) return((ddRecord *)NULL);
76 } else {
77 dd[ddCurrent].textEntry = NULL;
78 }
79
80 if ( rec->footNotesEntry != NULL ){
81 dd[ddCurrent].footNotesEntry = strdup(rec->footNotesEntry);
82 if ( dd[ddCurrent].footNotesEntry == NULL ) return((ddRecord *)NULL);
83 } else {
84 dd[ddCurrent].footNotesEntry = NULL;
85 }
86
87 if ( rec->unitsEntry != NULL ){
88 dd[ddCurrent].unitsEntry = strdup(rec->unitsEntry);
89 if ( dd[ddCurrent].unitsEntry == NULL ) return((ddRecord *)NULL);
90 } else {
91 dd[ddCurrent].unitsEntry = NULL;
92 }
93
94 dd[ddCurrent].active = rec->active;
95
96 /* Set to not a namelist member by default */
97 dd[ddCurrent].isInNameList = 0;
98 /* Set to not an ifdef entry by default */
99 dd[ddCurrent].isInIfdef = 0;
100 /* Set to not a procedure name by default */
101 dd[ddCurrent].isProcName = 0;
102
103 /* Move current record pointer forward */
104 if ( ddCurrent == ddNused ){
105 ++ddNused;
106 }
107 ++ddCurrent; ++ddKey;
108 return(dd+(ddCurrent-1));
109 }
110
111 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
112 static int ddCompar( a, b )
113 /* DD entry comparison routine. Used by ddSort */
114 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
115 ddRecord *a;
116 ddRecord *b;
117 {
118 int rc;
119 rc = strcasecmp(a->name,b->name);
120 return(rc);
121 }
122
123 int ddSort()
124 /* Sort the DD table */
125 {
126 int ddElSize;
127 /* Sort the table */
128 ddElSize = sizeof(*dd);
129 qsort(dd,ddNused,ddElSize,ddCompar);
130 ddCurrent=0;
131 }
132 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
133 int ddSetCurrent(n)
134 /* Set current DD record */
135 int n;
136 {
137 ddCurrent = n;
138 }
139 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
140
141 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
142 int ddGetCurrent(rec)
143 /* Return current DD record */
144 ddRecord **rec;
145 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
146 {
147 /* Return if at or past end of table */
148 if ( ddCurrent == ddNused ) {
149 return(0);
150 }
151
152 *rec = &dd[ddCurrent];
153 ++ddCurrent;
154 return(dd[ddCurrent-1].id);
155 }
156
157 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
158 ddRecord *ddFind(rec)
159 /* Return current DD record */
160 /* Usage:
161 Routine can be called with ddRecord or with NULL. If record "rec"
162 is not NULL search starts from top. If record is NULL search
163 starts from where previous search finished.
164 */
165 ddRecord *rec;
166 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
167 {
168 static ddRecord *curRec = NULL;
169 static int curInd = 0;
170
171 /* Conditions under which we know nothing can be found. */
172 if ( curRec == NULL && rec == NULL ) return((ddRecord *)NULL);
173 if ( rec != NULL && rec->name == NULL ) return((ddRecord *)NULL);
174 if ( rec == NULL && curInd >= ddNused-1 ) return((ddRecord *)NULL);
175
176 /* It is worth looking */
177 /* Start new search */
178 if ( rec != NULL ) { curInd = 0; curRec = rec; }
179 /* Do search */
180 while ( curInd < ddNused ) {
181 if ( strcmp(curRec->name,(dd[curInd]).name) == 0 ) {
182 return(&(dd[curInd]));
183 }
184 ++curInd;
185 }
186 /* Nothing found */
187 return((ddRecord *)NULL);
188 }
189 char *ddkey(n)
190 int n;
191 {
192 return(base36(n));
193 }
194
195 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
196 void ddPrint()
197 /* Prints DD table to standard out */
198 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
199 {
200 int curInd = 0;
201
202 curInd = 0;
203 /* Do print */
204 while ( curInd < ddNused ) {
205 printf("DD Record No. %d == \"%s\"", curInd, (dd[curInd]).name);
206 printf(", NL = %d", (dd[curInd]).isInNameList);
207 printf(", IFDEF = %d", (dd[curInd]).isInIfdef);
208 printf(", PROC = %d", (dd[curInd]).isProcName);
209 printf("\n");
210 ++curInd;
211 }
212 /* Nothing found */
213 return;
214 }
215
216 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
217 ddRecord *ddSetIsInNamelist( rec )
218 /* Tags dd entry used in NAMELIST */
219 ddRecord *rec;
220 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
221 {
222 rec->isInNameList=1;
223 }
224
225 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
226 ddRecord *ddSetIsInIfdef( rec )
227 /* Tags dd entry used in ifdef */
228 ddRecord *rec;
229 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
230 {
231 rec->isInIfdef=1;
232 }
233
234 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
235 ddRecord *ddSetIsProcName( rec )
236 /* Tags dd entry used in ifdef */
237 ddRecord *rec;
238 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
239 {
240 rec->isProcName=1;
241 }

  ViewVC Help
Powered by ViewVC 1.1.22