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

Annotation 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.1 - (hide annotations) (download)
Fri Sep 20 19:47:31 2002 UTC (22 years, 9 months ago) by adcroft
Branch: MAIN
Branch point for: Import
File MIME type: text/plain
Initial revision

1 adcroft 1.1 /* $Id: dd.c,v 1.1 1997/03/22 20:02:35 cnh 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     if ( dd[ddCurrent].name == NULL ) return((ddRecord *)NULL);
57     dd[ddCurrent].id = ddKey+1;
58     dd[ddCurrent].key = strdup(ddkey(ddKey+1));
59     if ( rec->hrefEntry != NULL ){
60     dd[ddCurrent].hrefEntry = strdup(rec->hrefEntry);
61     if ( dd[ddCurrent].hrefEntry == NULL ) return((ddRecord *)NULL);
62     } else {
63     dd[ddCurrent].hrefEntry = NULL;
64     }
65    
66     if ( rec->textEntry != NULL ){
67     dd[ddCurrent].textEntry = strdup(rec->textEntry);
68     if ( dd[ddCurrent].textEntry == NULL ) return((ddRecord *)NULL);
69     } else {
70     dd[ddCurrent].textEntry = NULL;
71     }
72    
73     if ( rec->footNotesEntry != NULL ){
74     dd[ddCurrent].footNotesEntry = strdup(rec->footNotesEntry);
75     if ( dd[ddCurrent].footNotesEntry == NULL ) return((ddRecord *)NULL);
76     } else {
77     dd[ddCurrent].footNotesEntry = NULL;
78     }
79    
80     if ( rec->unitsEntry != NULL ){
81     dd[ddCurrent].unitsEntry = strdup(rec->unitsEntry);
82     if ( dd[ddCurrent].unitsEntry == NULL ) return((ddRecord *)NULL);
83     } else {
84     dd[ddCurrent].unitsEntry = NULL;
85     }
86    
87     dd[ddCurrent].active = rec->active;
88    
89     /* Set to not a namelist member by default */
90     dd[ddCurrent].isInNameList = 0;
91     /* Set to not an ifdef entry by default */
92     dd[ddCurrent].isInIfdef = 0;
93     /* Set to not a procedure name by default */
94     dd[ddCurrent].isProcName = 0;
95    
96     /* Move current record pointer forward */
97     if ( ddCurrent == ddNused ){
98     ++ddNused;
99     }
100     ++ddCurrent; ++ddKey;
101     return(dd+(ddCurrent-1));
102     }
103    
104     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
105     static int ddCompar( a, b )
106     /* DD entry comparison routine. Used by ddSort */
107     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
108     ddRecord *a;
109     ddRecord *b;
110     {
111     int rc;
112     rc = strcasecmp(a->name,b->name);
113     return(rc);
114     }
115    
116     int ddSort()
117     /* Sort the DD table */
118     {
119     int ddElSize;
120     /* Sort the table */
121     ddElSize = sizeof(*dd);
122     qsort(dd,ddNused,ddElSize,ddCompar);
123     ddCurrent=0;
124     }
125     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
126     int ddSetCurrent(n)
127     /* Set current DD record */
128     int n;
129     {
130     ddCurrent = n;
131     }
132     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
133    
134     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
135     int ddGetCurrent(rec)
136     /* Return current DD record */
137     ddRecord **rec;
138     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
139     {
140     /* Return if at or past end of table */
141     if ( ddCurrent == ddNused ) {
142     return(0);
143     }
144    
145     *rec = &dd[ddCurrent];
146     ++ddCurrent;
147     return(dd[ddCurrent-1].id);
148     }
149    
150     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
151     ddRecord *ddFind(rec)
152     /* Return current DD record */
153     /* Usage:
154     Routine can be called with ddRecord or with NULL. If record "rec"
155     is not NULL search starts from top. If record is NULL search
156     starts from where previous search finished.
157     */
158     ddRecord *rec;
159     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
160     {
161     static ddRecord *curRec = NULL;
162     static int curInd = 0;
163    
164     /* Conditions under which we know nothing can be found. */
165     if ( curRec == NULL && rec == NULL ) return((ddRecord *)NULL);
166     if ( rec != NULL && rec->name == NULL ) return((ddRecord *)NULL);
167     if ( rec == NULL && curInd >= ddNused-1 ) return((ddRecord *)NULL);
168    
169     /* It is worth looking */
170     /* Start new search */
171     if ( rec != NULL ) { curInd = 0; curRec = rec; }
172     /* Do search */
173     while ( curInd < ddNused ) {
174     if ( strcmp(curRec->name,(dd[curInd]).name) == 0 ) {
175     return(&(dd[curInd]));
176     }
177     ++curInd;
178     }
179     /* Nothing found */
180     return((ddRecord *)NULL);
181     }
182     char *ddkey(n)
183     int n;
184     {
185     return(base36(n));
186     }
187    
188     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
189     void ddPrint()
190     /* Prints DD table to standard out */
191     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
192     {
193     int curInd = 0;
194    
195     curInd = 0;
196     /* Do print */
197     while ( curInd < ddNused ) {
198     printf("DD Record No. %d == \"%s\"", curInd, (dd[curInd]).name);
199     printf(", NL = %d", (dd[curInd]).isInNameList);
200     printf(", IFDEF = %d", (dd[curInd]).isInIfdef);
201     printf(", PROC = %d", (dd[curInd]).isProcName);
202     printf("\n");
203     ++curInd;
204     }
205     /* Nothing found */
206     return;
207     }
208    
209     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
210     ddRecord *ddSetIsInNamelist( rec )
211     /* Tags dd entry used in NAMELIST */
212     ddRecord *rec;
213     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
214     {
215     rec->isInNameList=1;
216     }
217    
218     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
219     ddRecord *ddSetIsInIfdef( rec )
220     /* Tags dd entry used in ifdef */
221     ddRecord *rec;
222     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
223     {
224     rec->isInIfdef=1;
225     }
226    
227     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
228     ddRecord *ddSetIsProcName( rec )
229     /* Tags dd entry used in ifdef */
230     ddRecord *rec;
231     /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
232     {
233     rec->isProcName=1;
234     }

  ViewVC Help
Powered by ViewVC 1.1.22