X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmetadata%2Fcreate_V7_mowgli%2FMETADATA%2Fsthandler.c;h=94b87c0c4708d7c24bba4c0fbce509347e65f488;hb=cdb45d73b98f6abaf670229b48a8442e1db902fc;hp=0f32e07c179c6a0cf25a86b66bd79e19eb10455d;hpb=6dc6f6e97cb85d5b51fbf5d14a9f87b24b2964cd;p=helm.git diff --git a/helm/metadata/create_V7_mowgli/METADATA/sthandler.c b/helm/metadata/create_V7_mowgli/METADATA/sthandler.c index 0f32e07c1..94b87c0c4 100644 --- a/helm/metadata/create_V7_mowgli/METADATA/sthandler.c +++ b/helm/metadata/create_V7_mowgli/METADATA/sthandler.c @@ -42,6 +42,7 @@ /****************************************************************/ #include +#include #include /****************************************************************/ @@ -173,17 +174,15 @@ search_bucket(id, where, depth) /* the identifier is not in the first position */ { prev->next_st_bucket = curr->next_st_bucket; - move_bucket(curr, - dict_index); + move_bucket(curr,dict_index); }; return where; } } -print_all(about,outrel,outsort) +print_all(about,conn) char *about; - FILE *outrel, - *outsort; + PGconn *conn; { int i; @@ -195,11 +194,11 @@ print_all(about,outrel,outsort) if ((curr->pos[i]) == 1) { if (i == MAINHYP) - print_mainhyp(about,outrel,outsort,curr->id,curr->depths); + print_mainhyp(about,conn,curr->id,curr->depths); else if (i == MAINCONCL) - print_mainconcl(about,outrel,outsort,curr->id,curr->main_depth); + print_mainconcl(about,conn,curr->id,curr->main_depth); else - print_one(curr->id,i); + print_one(conn,about,curr->id,i); } curr = curr->all_next; } @@ -210,6 +209,12 @@ print_all(about,outrel,outsort) /* 5. Definitions of functions local to the module. */ /****************************************************************/ +void exit_nicely(PGconn *conn) +{ + PQfinish(conn); + exit(1); +} + struct int_list *add(l,m) struct int_list *l; int m; @@ -232,13 +237,14 @@ struct int_list *add(l,m) } -print_mainhyp(about,outrel,outsort,uri,l) +print_mainhyp(about,conn,uri,l) char *about; - FILE *outrel, - *outsort; + PGconn *conn; char *uri; struct int_list *l; { + PGresult *res; + char *command = (char *)malloc((sizeof('a')*200)); struct int_list *curr; curr = l; if (!strcmp(uri,"Rel")) @@ -246,14 +252,18 @@ print_mainhyp(about,outrel,outsort,uri,l) /* scan the list */ while (curr != NULL) { - fprintf(outrel,"\t\n"); - fprintf(outrel,"\t\t"); - fprintf(outrel,"\n\t\t\t\t"); - fprintf(outrel,"\n\t\t\t\t%d",curr->val); - fprintf(outrel,"\n\t\t\n"); - fprintf(outrel,"\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + PQescapeString(qabout,about,len); + sprintf(command,"INSERT INTO refRel values ('%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#MainHypothesis', %d)",qabout,curr->val); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "BEGIN command failed\n"); + PQclear(res); + exit_nicely(conn); + } curr = curr->next; } } @@ -263,15 +273,18 @@ print_mainhyp(about,outrel,outsort,uri,l) /* scan the list */ while (curr != NULL) { - fprintf(outsort,"\t\n"); - fprintf(outsort,"\t\t"); - fprintf(outsort,"\n\t\t\t\t"); - fprintf(outsort,"\n\t\t\t\t",uri); - fprintf(outsort,"\n\t\t\t\t%d",curr->val); - fprintf(outsort,"\n\t\t\n"); - fprintf(outsort,"\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + PQescapeString(qabout,about,len); + sprintf(command,"INSERT INTO refSort values ('%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#MainHypothesis', %d, '%s')",qabout,curr->val,uri); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "BEGIN command failed\n"); + PQclear(res); + exit_nicely(conn); + } curr = curr->next; } } @@ -280,76 +293,114 @@ print_mainhyp(about,outrel,outsort,uri,l) /* scan the list */ while (curr != NULL) { - printf("\t\t"); - printf("\n\t\t\t\t"); - printf("\n\t\t\t\t%d",curr->val); - printf("\n\t\t\t\t",uri); - printf("\n\t\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + char *quri; + PQescapeString(qabout,about,len); + len = strlen(uri) + 1; + quri = malloc (sizeof(char) * len * 2); + PQescapeString(quri,uri,len); + sprintf(command,"INSERT INTO refObj values ('%s', '%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#MainHypothesis', %d)",qabout,quri,curr->val); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "BEGIN command failed\n"); + PQclear(res); + exit_nicely(conn); + } curr = curr->next; } } } -print_mainconcl(about,outrel,outsort,uri,depth) +print_mainconcl(about,conn,uri,depth) char *about; - FILE *outrel, - *outsort; + PGconn *conn; char *uri; int depth; { + PGresult *res; + char *command = (char *)malloc((sizeof('a')*200)); + /* fprintf(stderr,"about = %s\n",about); */ if (!strcmp(uri,"Rel")) { - fprintf(outrel,"\t\n"); - fprintf(outrel,"\t\t"); - fprintf(outrel,"\n\t\t\t\t"); - fprintf(outrel,"\n\t\t\t\t%d",depth); - fprintf(outrel,"\n\t\t\n"); - fprintf(outrel,"\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + PQescapeString(qabout,about,len); + sprintf(command,"INSERT INTO refRel values ('%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion', %d)",qabout,depth); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); } else if ((!strcmp(uri,"Prop")) || (!strcmp(uri,"Type")) || (!strcmp(uri,"Set"))) { - fprintf(outsort,"\t\n"); - fprintf(outsort,"\t\t"); - fprintf(outsort,"\n\t\t\t\t"); - fprintf(outsort,"\n\t\t\t\t",uri); - fprintf(outsort,"\n\t\t\t\t%d",depth); - fprintf(outsort,"\n\t\t\n"); - fprintf(outsort,"\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + PQescapeString(qabout,about,len); + sprintf(command,"INSERT INTO refSort values ('%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion', %d, '%s')",qabout,depth,uri); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); } else { - printf("\t\t"); - printf("\n\t\t\t\t"); - printf("\n\t\t\t\t%d",depth); - printf("\n\t\t\t\t",uri); - printf("\n\t\t\n"); + size_t len = strlen(about) + 1; + char *qabout = malloc (sizeof(char) * len * 2); + char *quri; + PQescapeString(qabout,about,len); + len = strlen(uri) + 1; + quri = malloc (sizeof(char) * len * 2); + PQescapeString(quri,uri,len); + sprintf(command,"INSERT INTO refObj values ('%s', '%s','http://www.cs.unibo.it/helm/schemas/schema-helm#MainConclusion', %d)",qabout,quri,depth); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); + } + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "BEGIN command failed\n"); + PQclear(res); + exit_nicely(conn); } + /* fprintf(stderr,"FINITO\n"); */ } // dome: cambiata per usare il modello con position -print_one(uri,pos) - char *uri; +print_one(conn,about,uri,pos) + PGconn *conn; + char *about, + *uri; int pos; { - printf("\t\t"); - printf("\n\t\t\t\t\n\t\t\t\t\n\t\t\n", uri); + position="MainConclusion"; /* This should never happen */ + sprintf(command,"INSERT INTO refObj values ('%s', '%s', 'http://www.cs.unibo.it/helm/schemas/schema-helm#%s')",qabout,quri,position); + /* fprintf(stderr, "%s\n", command); */ + res = PQexec(conn, command); + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, "BEGIN command failed\n"); + PQclear(res); + exit_nicely(conn); + } } /* The following function allocates a bucket for an identifier. */