]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/metadata/create_V7_mowgli/METADATA/meta_lex_ind.l
* new version of metadata extraction
[helm.git] / helm / metadata / create_V7_mowgli / METADATA / meta_lex_ind.l
index acf86244658752e9388088e775fb963d18ee5e7e..ef0abac72c3ea09915f528d463835ec6aa56a4dd 100644 (file)
@@ -39,7 +39,8 @@
 #include                <string.h>
 #include                <stdlib.h>
 #include                <sys/stat.h>
-#include                "sthandler_ind.h"
+#include                <postgresql/libpq-fe.h>
+#include                "sthandler.h"
 %}
 
  /***************************************************************/
@@ -81,11 +82,9 @@ char                    sep = '"';
 char                    *xpointer = "#xpointer(1/";
 char                    *uri;
 char                    *tmp;
-char                    *filename;
-char                    *file_uri; 
-char                    *inductive_uri;
-char                    *filename_prefix;
-char                    *file_uri_prefix;
+char                    *source_uri; 
+char                    *source_uri_prefix;
+PGconn                  *conn;
 %}
 
  /***************************************************************/
@@ -117,17 +116,13 @@ value                   [^"]+
                    }
 
 "</arity>"         { tmp = (char *)malloc(sizeof('a')*128);
-                     strcpy(filename,filename_prefix);
-                     /* fprintf(stderr,"tre"); */
-                     strcpy(file_uri,file_uri_prefix);
-                     sprintf(tmp,",%d.xml", inductive_type);
-                     /* fprintf(stderr,"quattro"); */
-                     strcat(filename,tmp);
+                     strcpy(source_uri,source_uri_prefix);
                      sprintf(tmp,"#xpointer(1/%d)", inductive_type);
-                     strcat(file_uri,tmp);
+                     strcat(source_uri,tmp);
                      /* fprintf(stderr,"cinque"); */
                      free(tmp);
-                     print_file();
+                     print_all(source_uri,conn);
+                     /* print_file(); */
                    }
 
 "<Constructor"     { init_symbol_table();
@@ -135,25 +130,21 @@ value                   [^"]+
                      depth = 0;
                      spine_depth = 0;
                      constructor++;
-                     strcpy(inductive_uri,file_uri_prefix);
                      position = INTYPE;
                      first_child = HERE;
                    }
 
 "</Constructor>"   { tmp = (char *)malloc(sizeof('a')*128);
-                     strcpy(filename,filename_prefix);
-                     strcpy(file_uri,file_uri_prefix);
-                     strcpy(inductive_uri,file_uri_prefix);
-                     sprintf(tmp,",%d,%d.xml", inductive_type,constructor);
-                     strcat(filename,tmp);
+                     strcpy(source_uri,source_uri_prefix);
                      sprintf(tmp,"#xpointer(1/%d/%d)",inductive_type,constructor);
-                     strcat(file_uri,tmp);
+                     strcat(source_uri,tmp);
                      free(tmp);
-                     print_file();
+                     print_all(source_uri,conn);
+                     /* print_file(); */
                    }
 
 "<decl"            |
-"<def"             {
+"<def"            {
                     if (position == INTYPE)
                        position = MAINHYP;
                     else if (position == MAINHYP)
@@ -162,7 +153,7 @@ value                   [^"]+
                    }
 
 "</decl>"          |
-"</def           {
+"</def>"           {
                     if (position == INHYP)
                      {
                       no_open_source--;
@@ -178,8 +169,8 @@ value                   [^"]+
                        position = INTYPE;
                        spine_depth++;
                        depth = 0;
+                       first_child = HERE;
                       }
-                    first_child = HERE;
                    }
 
 
@@ -313,55 +304,46 @@ value                   [^"]+
 
 main(int argc, char *argv[])
 {
-                   filename = malloc((sizeof('a')*2000));
-                   file_uri = malloc((sizeof('a')*2000));
-                   inductive_uri = malloc((sizeof('a')*2000));
-                   filename_prefix=argv[1];
-                   file_uri_prefix=argv[2];
-                   /* fprintf(stderr,"qua"); */
-                   yyin = fopen("tmp/inductive_type.xml", "r");
-                   yylex();
-}
-
-print_file()
-{                  
-                   FILE *out, *outrel, *outsort;
-
-                   if (!(out = fopen(filename,"w"))) 
-                     {
-                     fprintf(stderr, "error in openinf file %s\n", filename);
-                      exit(-1);
-                     } 
-                   if (!(outrel = fopen("forward_rel.xml","a"))) 
-                     {
-                     fprintf(stderr, "error in openinf file forward_rel.xml\n");
-                      exit(-1);
-                     }
-                   if (!(outsort = fopen("forward_sort.xml","a"))) 
-                     {
-                     fprintf(stderr, "error in openinf file forward_rel.xml\n");
-                      exit(-1);
-                     }
-                 
-                   // We process the type
-
-                   fprintf(out,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
-fprintf(out,"<!DOCTYPE rdf:RDF [
-        <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
-        <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
-        <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>
-
-   ]>\n");
-                   fprintf(out,"<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"&rdfns;\" xmlns:h=\"&hns;\" xmlns:hth=\"&hthns;\">\n");
-                   fprintf(out,"\t<h:Object rdf:about=\"");
-                   fprintf(out,"%s",file_uri);
-                   fprintf(out,"\">\n");
-                   print_all(file_uri,out,outrel,outsort);
-                   fprintf(out,"\t</h:Object>\n");
-                   fprintf(out,"</rdf:RDF>\n");
-                   fclose(out);
-                   fclose(outrel);
-                   fclose(outsort);
+    struct stat buf;
+
+    char       *pghost,
+               *pgport,
+               *pgoptions,
+               *pgtty;
+    char       *dbName;
+
+    /* FILE *debug; */
+
+    PGresult   *res;
+
+    /*
+     * begin, by setting the parameters for a backend connection if the
+     * parameters are null, then the system will try to use reasonable
+     * defaults by looking up environment variables or, failing that,
+     * using hardwired constants
+     */
+
+    /* make a connection to the database */
+    conn = PQconnectdb("user=helm dbname=mowgli");
+
+    /*
+     * check to see that the backend connection was successfully made
+     */
+    if (PQstatus(conn) == CONNECTION_BAD)
+    {
+        fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
+        fprintf(stderr, "%s", PQerrorMessage(conn));
+        exit_nicely(conn);
+    }
+
+    /* debug = fopen("/tmp/trace.out","w"); */
+    /* PQtrace(conn, debug);  */
+
+    source_uri = malloc((sizeof('a')*2000));
+    source_uri_prefix=argv[1];
+    /* fprintf(stderr,"qua"); */
+    yyin = fopen("tmp/inductive_type.xml", "r");
+    yylex();
 }
 
 search(uri,first_child,position,depth)
@@ -386,8 +368,8 @@ int                position;
                         
                    else 
                       found = search_bucket(uri,position,depth);
-                   /* if (found == NOTFOUND)
-                         printf( "pos = %d, uri = %s\n", position, uri); */
+                   if (found == NOTFOUND)
+                         printf( "pos = %d, uri = %s\n", position, uri); 
 }