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;
86 int waiting_for_name = 0;
88 void search(char *uri, int first_child, int position, int depth);
91 /***************************************************************/
92 /* 3. Regular definitions. */
93 /***************************************************************/
98 id [a-zA-Z]([-_'a-zA-Z0-9])*
100 /***************************************************************/
102 /***************************************************************/
108 /* fprintf(stderr,"uno"); */
113 /* fprintf(stderr,"due"); */
118 waiting_for_name = 1;
120 tmp = (char *)malloc(sizeof('a')*128);
121 strcpy(source_uri,source_uri_prefix);
122 sprintf(tmp,"#xpointer(1/%d)", inductive_type);
123 strcat(source_uri,tmp);
124 /* fprintf(stderr,"cinque"); */
129 print_all(source_uri);
133 "<Constructor" { init_symbol_table();
140 waiting_for_name = 1;
142 tmp = (char *)malloc(sizeof('a')*128);
143 strcpy(source_uri,source_uri_prefix);
144 sprintf(tmp,"#xpointer(1/%d/%d)",inductive_type,constructor);
145 strcat(source_uri,tmp);
149 "</Constructor>" { print_all(source_uri);
155 if (position == INTYPE)
157 else if (position == MAINHYP)
164 if (position == INHYP)
167 if (no_open_source == 0)
174 else if (position == MAINHYP)
195 if (((position == INTYPE) | (position == MAINHYP)) &&
196 (first_child == HERE))
198 if (position == INTYPE) /* REL on the spine */
201 search("Rel",first_child,position,spine_depth);
203 else search("Rel",first_child,position,depth);
208 "<SORT"(" "|\n)+"value=\""{value} {
209 if (((position == INTYPE) | (position == MAINHYP)) &&
210 (first_child == HERE))
212 tmp=(char *)malloc((sizeof('a')*200));
215 if (position == INTYPE) /* SORT on the spine */
218 search(tmp,first_child,position,spine_depth);
220 else search(tmp,first_child,position,depth);
231 if (position == INTYPE) /* CONST on the spine */
237 if (position == INTYPE) /* MUTIND on the spine */
243 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
245 where = MUTCONSTRUCT;
250 uri=(char *)malloc((sizeof('a')*200));
255 if (position == INCONCL)
256 search(uri,first_child,position,spine_depth);
257 else search(uri,first_child,position,depth);
265 "noType=\""{digits} {
266 if ((where == MUTIND) || (where == MUTCONSTRUCT))
267 { strsep(&yytext,&sep);
268 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
271 sprintf(tmp,"%d",tmp_n);
272 strcat(uri,"#xpointer(1/");
278 if (position == INCONCL)
279 search(uri,first_child,position,spine_depth);
280 else search(uri,first_child,position,depth);
284 first_child = AFTER;};
287 "noConstr=\""{digits} {
288 if (where == MUTCONSTRUCT)
289 { strsep(&yytext,&sep);
290 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
295 if (position == INCONCL)
296 search(uri,first_child,position,spine_depth);
297 else search(uri,first_child,position,depth);
301 first_child = AFTER;};
305 if (waiting_for_name == 1) {
306 waiting_for_name = 0;
307 strsep(&yytext,&sep);
308 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
310 print_name(tmp,source_uri);
318 /***************************************************************/
319 /* 6. Auxiliary functions. */
320 /***************************************************************/
322 int main(int argc, char *argv[])
328 fprintf(stderr, "Usage: meta_ind <object_uri> <inductive_type_file>\n");
332 source_uri = malloc((sizeof('a')*2000));
333 source_uri_prefix=argv[1];
334 /* fprintf(stderr,"qua"); */
335 yyin = fopen(argv[2], "r");
341 void search(uri,first_child,position,depth)
346 if (position == MAINHYP)
348 if (first_child == HERE)
349 found = search_bucket(uri,MAINHYP,depth);
351 found = search_bucket(uri,INHYP,0);
353 else if (position == INCONCL)
355 if (first_child == HERE)
356 found = search_bucket(uri,MAINCONCL,depth);
358 found = search_bucket(uri,INCONCL,0);
362 found = search_bucket(uri,position,depth);
363 /* if (found == NOTFOUND)
364 printf( "pos = %d, uri = %s\n", position, uri); */