1 /******************************************************************/
2 /* Copyright (C) 2000, HELM Team */
4 /* This file is part of HELM, an Hypertextual, Electronic */
5 /* Library of Mathematics, developed at the Computer Science */
6 /* Department, University of Bologna, Italy. */
8 /* HELM is free software; you can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation; either version */
11 /* 2 of the License, or (at your option) any later version. */
13 /* HELM is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
18 /* You should have received a copy of the GNU General Public */
19 /* License along with HELM; if not, write to the Free Software */
20 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, */
21 /* MA 02111-1307, USA. */
23 /* For details, see the HELM World-Wide-Web page, */
24 /* http://cs.unibo.it/helm/. */
25 /******************************************************************/
27 /***************************************************************/
29 /* Automatic Metadata Extractor */
30 /* First draft 11/12/2001, by Andrea Asperti */
31 /* more bugs added by domenico lordi on mon 12/17/2001 */
32 /***************************************************************/
34 /***************************************************************/
35 /* 1. Inclusion of header files. */
36 /***************************************************************/
42 #include "sthandler.h"
45 /***************************************************************/
46 /* 2. Constants and Variables Definitions */
47 /***************************************************************/
53 #define MUTCONSTRUCT 3
70 int position = INBODY;
71 int first_child = HERE;
72 int skip = 0; // boolean to skip the insertion of a URI
73 int no_open_source = 0;
78 char *xpointer = "#xpointer(1/";
82 void search(char *uri, int first_child, int position, int depth);
85 /***************************************************************/
86 /* 3. Regular definitions. */
87 /***************************************************************/
93 /***************************************************************/
95 /***************************************************************/
100 "<Variable"[^>]*">"(" "|\n)*"<body" {
101 position = INBODY; // Variables have both a body and a type
104 "</body>"(" "|\n)*"<type" {
105 position = INTYPE; // Variables have both a body and a type
114 if (position == INTYPE)
116 else if (position == MAINHYP)
119 else if (position == INHYP) no_open_source++;
124 if (position == INHYP)
127 if (no_open_source == 0)
134 else if (position == MAINHYP)
141 /* bug? first_child = HERE; */
156 if (((position == INTYPE) | (position == MAINHYP)) &&
157 (first_child == HERE))
159 if (position == INTYPE) /* REL on the spine */
162 search("Rel",first_child,position,spine_depth);
164 else search("Rel",first_child,position,depth);
169 "<SORT"(" "|\n)+"value=\""{value} {
170 if (((position == INTYPE) | (position == MAINHYP)) &&
171 (first_child == HERE))
173 tmp=(char *)malloc((sizeof('a')*200));
176 if (position == INTYPE) /* SORT on the spine */
179 search(tmp,first_child,position,spine_depth);
181 else search(tmp,first_child,position,depth);
192 if (position == INTYPE) /* CONST on the spine */
198 if (position == INTYPE) /* MUTIND on the spine */
204 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
206 where = MUTCONSTRUCT;
211 uri=(char *)malloc((sizeof('a')*200));
216 if (position == INCONCL)
217 search(uri,first_child,position,spine_depth);
218 else search(uri,first_child,position,depth);
226 "noType=\""{digits} {
227 if ((where == MUTIND) || (where == MUTCONSTRUCT))
228 { strsep(&yytext,&sep);
229 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
232 sprintf(tmp,"%d",tmp_n);
233 strcat(uri,"#xpointer(1/");
239 if (position == INCONCL)
240 search(uri,first_child,position,spine_depth);
241 else search(uri,first_child,position,depth);
245 first_child = AFTER;};
248 "noConstr=\""{digits} {
249 if (where == MUTCONSTRUCT)
250 { strsep(&yytext,&sep);
251 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
256 if (position == INCONCL)
257 search(uri,first_child,position,spine_depth);
258 else search(uri,first_child,position,depth);
262 first_child = AFTER;};
269 /***************************************************************/
270 /* 6. Auxiliary functions. */
271 /***************************************************************/
273 int main(int argc, char *argv[])
284 fprintf(stderr, "Usage: meta <object_uri> <body_file> <type_file>\n");
289 /* initialize the symbol table */
292 // We process the body
293 if (!stat(argv[2],&buf))
295 yyin = fopen(argv[2], "r");
301 // We process the type
302 yyin = fopen(argv[3], "r");
311 poss = rindex(argv[1],'/');
312 posd = rindex(argv[1],'.');
313 name = (char *)malloc((posd - poss) * sizeof(char));
314 strncpy(name, poss + 1, posd - poss - 1);
315 name[posd - poss - 1] = '\0';
316 print_name(name,argv[1]);
323 void search(uri,first_child,position,depth)
328 if (position == MAINHYP)
330 if (first_child == HERE)
331 found = search_bucket(uri,MAINHYP,depth);
333 found = search_bucket(uri,INHYP,0);
335 else if (position == INCONCL)
337 if (first_child == HERE)
338 found = search_bucket(uri,MAINCONCL,depth);
340 found = search_bucket(uri,INCONCL,0);
344 found = search_bucket(uri,position,depth);
346 if (found == NOTFOUND)
347 fprintf(stderr,"here = %d, pos = %d, uri = %s\n", first_child,position, uri); */
350 (first_child == HERE)
352 if (position == MAINHYP)
353 found = search_bucket(uri,MAINHYP,depth);
354 else if (position == INCONCL)
355 found = search_bucket(uri,MAINCONCL,0);
356 else if (position == INHYP)
357 found = search_bucket(uri,INHYP,0);
358 if (found == NOTFOUND)
359 printf( "pos = %d, uri = %s\n", MAINCONCL, uri);
361 else if ((position == MAINHYP) && (first_child == AFTER))
362 found = search_bucket(uri,INHYP,0);
363 else found = search_bucket(uri,position,0);
364 if (found == NOTFOUND)
365 printf( "pos = %d, uri = %s\n", position, uri);