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;
77 int inductive_type = 0;
81 char *xpointer = "#xpointer(1/";
85 char *source_uri_prefix;
87 void search(char *uri, int first_child, int position, int depth);
90 /***************************************************************/
91 /* 3. Regular definitions. */
92 /***************************************************************/
98 /***************************************************************/
100 /***************************************************************/
106 /* fprintf(stderr,"uno"); */
111 /* fprintf(stderr,"due"); */
118 "</arity>" { tmp = (char *)malloc(sizeof('a')*128);
119 strcpy(source_uri,source_uri_prefix);
120 sprintf(tmp,"#xpointer(1/%d)", inductive_type);
121 strcat(source_uri,tmp);
122 /* fprintf(stderr,"cinque"); */
124 print_all(source_uri);
128 "<Constructor" { init_symbol_table();
137 "</Constructor>" { tmp = (char *)malloc(sizeof('a')*128);
138 strcpy(source_uri,source_uri_prefix);
139 sprintf(tmp,"#xpointer(1/%d/%d)",inductive_type,constructor);
140 strcat(source_uri,tmp);
142 print_all(source_uri);
148 if (position == INTYPE)
150 else if (position == MAINHYP)
157 if (position == INHYP)
160 if (no_open_source == 0)
167 else if (position == MAINHYP)
188 if (((position == INTYPE) | (position == MAINHYP)) &&
189 (first_child == HERE))
191 if (position == INTYPE) /* REL on the spine */
194 search("Rel",first_child,position,spine_depth);
196 else search("Rel",first_child,position,depth);
201 "<SORT"(" "|\n)+"value=\""{value} {
202 if (((position == INTYPE) | (position == MAINHYP)) &&
203 (first_child == HERE))
205 tmp=(char *)malloc((sizeof('a')*200));
208 if (position == INTYPE) /* SORT on the spine */
211 search(tmp,first_child,position,spine_depth);
213 else search(tmp,first_child,position,depth);
224 if (position == INTYPE) /* CONST on the spine */
230 if (position == INTYPE) /* MUTIND on the spine */
236 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
238 where = MUTCONSTRUCT;
243 uri=(char *)malloc((sizeof('a')*200));
248 if (position == INCONCL)
249 search(uri,first_child,position,spine_depth);
250 else search(uri,first_child,position,depth);
258 "noType=\""{digits} {
259 if ((where == MUTIND) || (where == MUTCONSTRUCT))
260 { strsep(&yytext,&sep);
261 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
264 sprintf(tmp,"%d",tmp_n);
265 strcat(uri,"#xpointer(1/");
271 if (position == INCONCL)
272 search(uri,first_child,position,spine_depth);
273 else search(uri,first_child,position,depth);
277 first_child = AFTER;};
280 "noConstr=\""{digits} {
281 if (where == MUTCONSTRUCT)
282 { strsep(&yytext,&sep);
283 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
288 if (position == INCONCL)
289 search(uri,first_child,position,spine_depth);
290 else search(uri,first_child,position,depth);
294 first_child = AFTER;};
301 /***************************************************************/
302 /* 6. Auxiliary functions. */
303 /***************************************************************/
305 int main(int argc, char *argv[])
311 fprintf(stderr, "Usage: meta_ind <object_uri> <inductive_type_file>\n");
315 source_uri = malloc((sizeof('a')*2000));
316 source_uri_prefix=argv[1];
317 /* fprintf(stderr,"qua"); */
318 yyin = fopen(argv[2], "r");
324 void search(uri,first_child,position,depth)
329 if (position == MAINHYP)
331 if (first_child == HERE)
332 found = search_bucket(uri,MAINHYP,depth);
334 found = search_bucket(uri,INHYP,0);
336 else if (position == INCONCL)
338 if (first_child == HERE)
339 found = search_bucket(uri,MAINCONCL,depth);
341 found = search_bucket(uri,INCONCL,0);
345 found = search_bucket(uri,position,depth);
346 /* if (found == NOTFOUND)
347 printf( "pos = %d, uri = %s\n", position, uri); */