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)
123 if (position == INHYP)
126 if (no_open_source == 0)
133 else if (position == MAINHYP)
140 /* bug? first_child = HERE; */
155 if (((position == INTYPE) | (position == MAINHYP)) &&
156 (first_child == HERE))
158 if (position == INTYPE) /* REL on the spine */
161 search("Rel",first_child,position,spine_depth);
163 else search("Rel",first_child,position,depth);
168 "<SORT"(" "|\n)+"value=\""{value} {
169 if (((position == INTYPE) | (position == MAINHYP)) &&
170 (first_child == HERE))
172 tmp=(char *)malloc((sizeof('a')*200));
175 if (position == INTYPE) /* SORT on the spine */
178 search(tmp,first_child,position,spine_depth);
180 else search(tmp,first_child,position,depth);
191 if (position == INTYPE) /* CONST on the spine */
197 if (position == INTYPE) /* MUTIND on the spine */
203 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
205 where = MUTCONSTRUCT;
210 uri=(char *)malloc((sizeof('a')*200));
215 if (position == INCONCL)
216 search(uri,first_child,position,spine_depth);
217 else search(uri,first_child,position,depth);
225 "noType=\""{digits} {
226 if ((where == MUTIND) || (where == MUTCONSTRUCT))
227 { strsep(&yytext,&sep);
228 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
231 sprintf(tmp,"%d",tmp_n);
232 strcat(uri,"#xpointer(1/");
238 if (position == INCONCL)
239 search(uri,first_child,position,spine_depth);
240 else search(uri,first_child,position,depth);
244 first_child = AFTER;};
247 "noConstr=\""{digits} {
248 if (where == MUTCONSTRUCT)
249 { strsep(&yytext,&sep);
250 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
255 if (position == INCONCL)
256 search(uri,first_child,position,spine_depth);
257 else search(uri,first_child,position,depth);
261 first_child = AFTER;};
268 /***************************************************************/
269 /* 6. Auxiliary functions. */
270 /***************************************************************/
272 int main(int argc, char *argv[])
283 fprintf(stderr, "Usage: meta <object_uri> <body_file> <type_file>\n");
288 /* initialize the symbol table */
291 // We process the body
292 if (!stat(argv[2],&buf))
294 yyin = fopen(argv[2], "r");
300 // We process the type
301 yyin = fopen(argv[3], "r");
310 poss = rindex(argv[1],'/');
311 posd = rindex(argv[1],'.');
312 name = (char *)malloc((posd - poss) * sizeof(char));
313 strncpy(name, poss + 1, posd - poss - 1);
314 name[posd - poss - 1] = '\0';
315 print_name(name,argv[1]);
322 void search(uri,first_child,position,depth)
327 if (position == MAINHYP)
329 if (first_child == HERE)
330 found = search_bucket(uri,MAINHYP,depth);
332 found = search_bucket(uri,INHYP,0);
334 else if (position == INCONCL)
336 if (first_child == HERE)
337 found = search_bucket(uri,MAINCONCL,depth);
339 found = search_bucket(uri,INCONCL,0);
343 found = search_bucket(uri,position,depth);
345 if (found == NOTFOUND)
346 fprintf(stderr,"here = %d, pos = %d, uri = %s\n", first_child,position, uri); */
349 (first_child == HERE)
351 if (position == MAINHYP)
352 found = search_bucket(uri,MAINHYP,depth);
353 else if (position == INCONCL)
354 found = search_bucket(uri,MAINCONCL,0);
355 else if (position == INHYP)
356 found = search_bucket(uri,INHYP,0);
357 if (found == NOTFOUND)
358 printf( "pos = %d, uri = %s\n", MAINCONCL, uri);
360 else if ((position == MAINHYP) && (first_child == AFTER))
361 found = search_bucket(uri,INHYP,0);
362 else found = search_bucket(uri,position,0);
363 if (found == NOTFOUND)
364 printf( "pos = %d, uri = %s\n", position, uri);