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;
79 char *xpointer = "#xpointer(1/";
84 /***************************************************************/
85 /* 3. Regular definitions. */
86 /***************************************************************/
92 /***************************************************************/
94 /***************************************************************/
99 "<Variable"[^>]*">"(" "|\n)*"<body" {
100 position = INBODY; // Variables have both a body and a type
103 "</body>"(" "|\n)*"<type" {
104 position = INTYPE; // Variables have both a body and a type
113 if (position == INTYPE)
115 else if (position == MAINHYP)
122 if (position == INHYP)
125 if (no_open_source == 0)
132 else if (position == MAINHYP)
139 /* bug? first_child = HERE; */
154 if (((position == INTYPE) | (position == MAINHYP)) &&
155 (first_child == HERE))
157 if (position == INTYPE) /* REL on the spine */
160 search("Rel",first_child,position,spine_depth);
162 else search("Rel",first_child,position,depth);
167 "<SORT"(" "|\n)+"value=\""{value} {
168 if (((position == INTYPE) | (position == MAINHYP)) &&
169 (first_child == HERE))
171 tmp=(char *)malloc((sizeof('a')*200));
174 if (position == INTYPE) /* SORT on the spine */
177 search(tmp,first_child,position,spine_depth);
179 else search(tmp,first_child,position,depth);
190 if (position == INTYPE) /* CONST on the spine */
196 if (position == INTYPE) /* MUTIND on the spine */
202 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
204 where = MUTCONSTRUCT;
209 uri=(char *)malloc((sizeof('a')*200));
214 if (position == INCONCL)
215 search(uri,first_child,position,spine_depth);
216 else search(uri,first_child,position,depth);
224 "noType=\""{digits} {
225 if ((where == MUTIND) || (where == MUTCONSTRUCT))
226 { strsep(&yytext,&sep);
227 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
230 sprintf(tmp,"%d",tmp_n);
231 strcat(uri,"#xpointer(1/");
237 if (position == INCONCL)
238 search(uri,first_child,position,spine_depth);
239 else search(uri,first_child,position,depth);
243 first_child = AFTER;};
246 "noConstr=\""{digits} {
247 if (where == MUTCONSTRUCT)
248 { strsep(&yytext,&sep);
249 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
254 if (position == INCONCL)
255 search(uri,first_child,position,spine_depth);
256 else search(uri,first_child,position,depth);
260 first_child = AFTER;};
267 /***************************************************************/
268 /* 6. Auxiliary functions. */
269 /***************************************************************/
271 main(int argc, char *argv[])
288 fprintf(stderr, "Usage: meta <object_uri> <body_file> <type_file>\n");
293 * begin, by setting the parameters for a backend connection if the
294 * parameters are null, then the system will try to use reasonable
295 * defaults by looking up environment variables or, failing that,
296 * using hardwired constants
299 /* make a connection to the database */
300 conn = PQconnectdb("user=helm dbname=mowgli_test");
303 * check to see that the backend connection was successfully made
305 if (PQstatus(conn) == CONNECTION_BAD)
307 fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
308 fprintf(stderr, "%s", PQerrorMessage(conn));
312 /* debug = fopen("/tmp/trace.out","w"); */
313 /* PQtrace(conn, debug); */
315 /* initialize the symbol table */
318 // We process the body
319 if (!stat(argv[2],&buf))
321 yyin = fopen(argv[2], "r");
327 // We process the type
328 yyin = fopen(argv[3], "r");
336 print_all(argv[1],conn);
342 search(uri,first_child,position,depth)
347 if (position == MAINHYP)
349 if (first_child == HERE)
350 found = search_bucket(uri,MAINHYP,depth);
352 found = search_bucket(uri,INHYP,0);
354 else if (position == INCONCL)
356 if (first_child == HERE)
357 found = search_bucket(uri,MAINCONCL,depth);
359 found = search_bucket(uri,INCONCL,0);
363 found = search_bucket(uri,position,depth);
365 if (found == NOTFOUND)
366 fprintf(stderr,"here = %d, pos = %d, uri = %s\n", first_child,position, uri); */
369 (first_child == HERE)
371 if (position == MAINHYP)
372 found = search_bucket(uri,MAINHYP,depth);
373 else if (position == INCONCL)
374 found = search_bucket(uri,MAINCONCL,0);
375 else if (position == INHYP)
376 found = search_bucket(uri,INHYP,0);
377 if (found == NOTFOUND)
378 printf( "pos = %d, uri = %s\n", MAINCONCL, uri);
380 else if ((position == MAINHYP) && (first_child == AFTER))
381 found = search_bucket(uri,INHYP,0);
382 else found = search_bucket(uri,position,0);
383 if (found == NOTFOUND)
384 printf( "pos = %d, uri = %s\n", position, uri);