Debian Codegraph @

w4/metadata.c

raw
1 /* File: metadata.c
2 * Author: Danielle et Jean Thierry-Mieg ([email protected])
3 * Copyright (C) J Thierry-Mieg and R Durbin, 1993
4 * -------------------------------------------------------------------
5 * Acedb is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
19 * -------------------------------------------------------------------
20 * This file is part of the ACEDB genome database package, written by
21 * Richard Durbin (MRC LMB, UK) [email protected], and
22 * Jean Thierry-Mieg (CRBM du CNRS, France) [email protected]
23 *
24 * Description:
25 First run the script wtools/parsecode
26 Then read the file generated that way called code.ace
27 Then run this program
28 This results in cross referencing the includes, tags and
29 classes used in the code
30 * Exported functions:
31 void metaCheckCode(void)
32 * HISTORY:
33 * Last edited: Jul 9 11:48 2003 (rnc)
34 * Created: Wed Apr 21 20:22:39 1993 (mieg)
35 *-------------------------------------------------------------------
36 */
37
38 /* $Id: metadata.c,v 1.14 2003/07/09 13:20:25 rnc Exp $ */
39
40 #include "acedb.h"
41
42 #include "lex.h"
43 #include "a.h"
44 #include "bs.h"
45 #include "session.h"
46 #include "pick.h"
47 #include "utils.h" /* for lexstrcmp */
48
49 #include "whooks/sysclass.h"
50 #include "whooks/systags.h"
51
52 static int _VInclude, _VSourceCode, _VTag ; /* metadata class, not used by the kernel */
53
54 /********************************************************/
55
56 static void metaCheckTagConsistency(void)
57 { KEY tag = 0 , metaTag = KEYMAKE(_VTag,0) ;
58 int n ;
59 OBJ obj ; char *cp ;
60
61 if (iskey(KEYMAKE(_VTag,0)) != 2)
62 return ; /* i.e. the Tag model does not yet exists */
63
64 /* tag to metatag injection */
65 while (lexNext(_VSystem, &tag))
66 { lexaddkey(name(tag), &metaTag, _VTag) ;
67 obj = bsUpdate(metaTag) ;
68 if (bsGetData(obj, _Parent_tag, _Text, &cp))
69 { if (lexstrcmp(cp, name(tag)))
70 messerror ("Tag %s has somehow been renamed as %s",
71 cp, name(tag)) ;
72 if (bsGetData(obj, _bsRight, _Int, &n) && n!= 458 && n!= 478)
73 { if ( n != tag )
74 messerror ("Tag %s has been renumbered, old value %d, new %d",
75 name(tag), n, tag);
76 }
77 }
78 bsAddData(obj, _Parent_tag, _Text, name(tag)) ;
79 n = tag ; /* to cast to int */
80 bsAddData(obj, _bsRight, _Int, &n) ;
81 bsSave (obj) ; /* Those operation are often null, hence quick and harmless */
82 }
83
84 /* is it a surjection */
85
86 metaTag = 0 ;
87 while (lexNext(_VTag, &metaTag))
88 if ((obj = bsCreate(metaTag)))
89 {
90 if (bsGetData(obj, _Parent_tag, _Text, &cp) &&
91 bsGetData(obj, _bsRight, _Int, &n) &&
92 strncmp(cp,"__sys", 5) &&
93 n != 458 && n != 478 ) /* A fix, Because 458 is Semi_dominant, was demi-dominant */
94 { if (!lexword2key(cp, &tag, _VSystem))
95 messerror ("Tag %s %d has somehow disappeared from wspec",
96 cp, n) ;
97 if (lexstrcmp(cp, name(tag)))
98 messerror ("Tag %d has been renamed, old name %s, new name %s",
99 n, cp, name(tag)) ;
100 if (n != tag )
101 messerror ("Tag %s has been renumbered, old value %d, new %d",
102 name(metaTag), n, tag);
103 }
104 bsDestroy (obj) ; /* Those operation are often null, hence quick and harmless */
105 }
106 }
107
108 /************************************************************/
109
110 void metaCheckCode(void)
111 {
112 KEY key, codeText, code , metaTag , metaClass, incl ;
113 char *cp, *cq , cutter;
114 Stack s ;
115 int level , nt = 0, nc= 0, ni = 0 ;
116 OBJ Code ;
117
118
119 if (!sessionGainWriteAccess())
120 {
121 messout("Sorry, you cannot gain write access") ;
122 return ;
123 }
124
125 lexaddkey ("Include", &key, _VMainClasses) ; _VInclude = KEYKEY (key) ;
126 lexaddkey ("SourceCode", &key, _VMainClasses) ; _VSourceCode = KEYKEY (key) ;
127 lexaddkey ("Tag", &key, _VMainClasses) ; _VTag = KEYKEY (key) ;
128
129 metaCheckTagConsistency() ;
130 code = 0 ;
131
132 while (lexNext(_VSourceCode, &code))
133 {
134 if((Code = bsUpdate(code)))
135 {
136 if(bsFindTag(Code, _Includes))
137 bsRemove(Code) ;
138 if(bsFindTag(Code, _Uses_tags))
139 bsRemove(Code) ;
140 if(bsFindTag(Code, _Uses_class))
141 bsRemove(Code) ;
142
143 if (bsGetKey(Code, _SourceFile, &codeText) &&
144 (s = stackGet(codeText) ))
145 { stackCursor(s, 0) ;
146 while ((cp = stackNextText(s)))
147 { level = freesettext(cp, "") ;
148 while (freecard(level))
149 if ((cq = freeword()) && !strcmp(cq, "#include"))
150 {
151 freenext() ;
152 cq = freeword() ;
153 if (lexword2key(cq, &incl, _VInclude))
154 { ni++ ;
155 bsAddKey(Code, _Includes, incl) ;
156 }
157 else
158 printf("Unrecognised include: %s in %s \n", cp, name(code)) ;
159 }
160 else while ( freenext(),
161 (cq = freewordcut(" {}()[],.;:=!#>?\"", &cutter), cq || cutter))
162 if (cq && *cq == '_' && *(cq+1) == 'V')
163 { if (lexword2key(cq+2, &metaClass, _VClass))
164 { nc++ ; bsAddKey(Code, _Uses_class, metaClass) ; }
165 else
166 fprintf(stderr, "Unrecognised class %s in %s \n", cq ? cq : "Null", name(code)) ;
167 }
168 else if (cq && *cq == '_')
169 { if (lexword2key(cq+1, &metaTag, _VTag))
170 { nt++; bsAddKey(Code, _Uses_tags, metaTag) ; }
171 else
172 fprintf(stderr, "Unrecognised tag %s in %s \n", cq ? cq : "Null", name(code)) ;
173 }
174 }
175 stackDestroy(s) ;
176 }
177 bsSave(Code) ;
178
179 }
180 }
181
182 printf ("#*#*#*# Found %d tags, %d classes %d inclusions \n\n", nt, nc, ni) ;
183 }
184
185 /***********************************/
186
187 int main (int argc, char **argv)
188 {
189 if (argc >= 2)
190 aceInit(argv[1]);
191
192 metaCheckCode ();
193
194 return 0;
195 }
196
197 /***********************************/
198