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 <postgresql/libpq-fe.h>
43 #include "sthandler.h"
46 /***************************************************************/
47 /* 2. Constants and Variables Definitions */
48 /***************************************************************/
54 #define MUTCONSTRUCT 3
71 int position = INBODY;
72 int first_child = HERE;
73 int skip = 0; // boolean to skip the insertion of a URI
74 int no_open_source =0;
78 int inductive_type = 0;
82 char *xpointer = "#xpointer(1/";
86 char *source_uri_prefix;
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,conn);
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,conn);
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 main(int argc, char *argv[])
320 * begin, by setting the parameters for a backend connection if the
321 * parameters are null, then the system will try to use reasonable
322 * defaults by looking up environment variables or, failing that,
323 * using hardwired constants
326 /* make a connection to the database */
327 conn = PQconnectdb("user=helm dbname=mowgli");
330 * check to see that the backend connection was successfully made
332 if (PQstatus(conn) == CONNECTION_BAD)
334 fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
335 fprintf(stderr, "%s", PQerrorMessage(conn));
339 /* debug = fopen("/tmp/trace.out","w"); */
340 /* PQtrace(conn, debug); */
342 source_uri = malloc((sizeof('a')*2000));
343 source_uri_prefix=argv[1];
344 /* fprintf(stderr,"qua"); */
345 yyin = fopen("tmp/inductive_type.xml", "r");
349 search(uri,first_child,position,depth)
354 if (position == MAINHYP)
356 if (first_child == HERE)
357 found = search_bucket(uri,MAINHYP,depth);
359 found = search_bucket(uri,INHYP,0);
361 else if (position == INCONCL)
363 if (first_child == HERE)
364 found = search_bucket(uri,MAINCONCL,depth);
366 found = search_bucket(uri,INCONCL,0);
370 found = search_bucket(uri,position,depth);
371 if (found == NOTFOUND)
372 printf( "pos = %d, uri = %s\n", position, uri);