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_ind.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/";
87 char *filename_prefix;
88 char *file_uri_prefix;
91 /***************************************************************/
92 /* 3. Regular definitions. */
93 /***************************************************************/
99 /***************************************************************/
101 /***************************************************************/
107 /* fprintf(stderr,"uno"); */
112 /* fprintf(stderr,"due"); */
119 "</arity>" { tmp = (char *)malloc(sizeof('a')*128);
120 strcpy(filename,filename_prefix);
121 /* fprintf(stderr,"tre"); */
122 strcpy(file_uri,file_uri_prefix);
123 sprintf(tmp,",%d.xml", inductive_type);
124 /* fprintf(stderr,"quattro"); */
125 strcat(filename,tmp);
126 sprintf(tmp,"#xpointer(1/%d)", inductive_type);
127 strcat(file_uri,tmp);
128 /* fprintf(stderr,"cinque"); */
133 "<Constructor" { init_symbol_table();
138 strcpy(inductive_uri,file_uri_prefix);
143 "</Constructor>" { tmp = (char *)malloc(sizeof('a')*128);
144 strcpy(filename,filename_prefix);
145 strcpy(file_uri,file_uri_prefix);
146 strcpy(inductive_uri,file_uri_prefix);
147 sprintf(tmp,",%d,%d.xml", inductive_type,constructor);
148 strcat(filename,tmp);
149 sprintf(tmp,"#xpointer(1/%d/%d)",inductive_type,constructor);
150 strcat(file_uri,tmp);
157 if (position == INTYPE)
159 else if (position == MAINHYP)
166 if (position == INHYP)
169 if (no_open_source == 0)
176 else if (position == MAINHYP)
197 if (((position == INTYPE) | (position == MAINHYP)) &&
198 (first_child == HERE))
200 if (position == INTYPE) /* REL on the spine */
203 search("Rel",first_child,position,spine_depth);
205 else search("Rel",first_child,position,depth);
210 "<SORT"(" "|\n)+"value=\""{value} {
211 if (((position == INTYPE) | (position == MAINHYP)) &&
212 (first_child == HERE))
214 tmp=(char *)malloc((sizeof('a')*200));
217 if (position == INTYPE) /* SORT on the spine */
220 search(tmp,first_child,position,spine_depth);
222 else search(tmp,first_child,position,depth);
233 if (position == INTYPE) /* CONST on the spine */
239 if (position == INTYPE) /* MUTIND on the spine */
245 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
247 where = MUTCONSTRUCT;
252 uri=(char *)malloc((sizeof('a')*200));
257 if (position == INCONCL)
258 search(uri,first_child,position,spine_depth);
259 else search(uri,first_child,position,depth);
267 "noType=\""{digits} {
268 if ((where == MUTIND) || (where == MUTCONSTRUCT))
269 { strsep(&yytext,&sep);
270 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
273 sprintf(tmp,"%d",tmp_n);
274 strcat(uri,"#xpointer(1/");
280 if (position == INCONCL)
281 search(uri,first_child,position,spine_depth);
282 else search(uri,first_child,position,depth);
286 first_child = AFTER;};
289 "noConstr=\""{digits} {
290 if (where == MUTCONSTRUCT)
291 { strsep(&yytext,&sep);
292 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
297 if (position == INCONCL)
298 search(uri,first_child,position,spine_depth);
299 else search(uri,first_child,position,depth);
303 first_child = AFTER;};
310 /***************************************************************/
311 /* 6. Auxiliary functions. */
312 /***************************************************************/
314 main(int argc, char *argv[])
316 filename = malloc((sizeof('a')*2000));
317 file_uri = malloc((sizeof('a')*2000));
318 inductive_uri = malloc((sizeof('a')*2000));
319 filename_prefix=argv[1];
320 file_uri_prefix=argv[2];
321 /* fprintf(stderr,"qua"); */
322 yyin = fopen("tmp/inductive_type.xml", "r");
328 FILE *out, *outrel, *outsort;
330 if (!(out = fopen(filename,"w")))
332 fprintf(stderr, "error in openinf file %s\n", filename);
335 if (!(outrel = fopen("forward_rel.xml","a")))
337 fprintf(stderr, "error in openinf file forward_rel.xml\n");
340 if (!(outsort = fopen("forward_sort.xml","a")))
342 fprintf(stderr, "error in openinf file forward_rel.xml\n");
346 // We process the type
348 fprintf(out,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
349 fprintf(out,"<!DOCTYPE rdf:RDF [
350 <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
351 <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
352 <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>
355 fprintf(out,"<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"&rdfns;\" xmlns:h=\"&hns;\" xmlns:hth=\"&hthns;\">\n");
356 fprintf(out,"\t<h:Object rdf:about=\"");
357 fprintf(out,"%s",file_uri);
358 fprintf(out,"\">\n");
359 print_all(file_uri,out,outrel,outsort);
360 fprintf(out,"\t</h:Object>\n");
361 fprintf(out,"</rdf:RDF>\n");
367 search(uri,first_child,position,depth)
372 if (position == MAINHYP)
374 if (first_child == HERE)
375 found = search_bucket(uri,MAINHYP,depth);
377 found = search_bucket(uri,INHYP,0);
379 else if (position == INCONCL)
381 if (first_child == HERE)
382 found = search_bucket(uri,MAINCONCL,depth);
384 found = search_bucket(uri,INCONCL,0);
388 found = search_bucket(uri,position,depth);
389 /* if (found == NOTFOUND)
390 printf( "pos = %d, uri = %s\n", position, uri); */