#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
-#include "sthandler_ind.h"
+#include <postgresql/libpq-fe.h>
+#include "sthandler.h"
%}
/***************************************************************/
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;
%}
/***************************************************************/
}
"</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();
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)
}
"</decl>" |
-"</def" {
+"</def>" {
if (position == INHYP)
{
no_open_source--;
position = INTYPE;
spine_depth++;
depth = 0;
+ first_child = HERE;
}
- first_child = HERE;
}
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;
+
+ if (argc != 3)
+ {
+ fprintf(stderr, "Usage: meta_ind <object_uri> <inductive_type_file>\n");
+ exit(1);
+ }
+
+ /*
+ * 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(argv[2], "r");
+ yylex();
+
+ return 0;
}
search(uri,first_child,position,depth)
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);
}