/* #include #include #include #include #include */ #include "tmxtm.h" #include "tmassert.h" #include "tmtrace.h" #include "tmsubject.h" #include "tmtopicmap.h" /* #include #include #include */ #include "tmvtasidp.h" static char q1[] = "\ SELECT * \ WHERE http://purl.org/tm/amod/a-sidp == null \ AND http://purl.org/tm/sam/IndicatorData == null"; static char q2[] = "\ SELECT * \ WHERE http://purl.org/tm/amod/a-sidp != null"; static void my_print_topic(char **bufp, int *sizep,TMSubject sbj, TMTopic t); static void my_print_assoc(char **bufp, int *sizep,TMSubject sbj, TMTopic t); static char preamble[] = "\n\ \n\ \n\ \n\ \n\n"; TMError make_xtm(TMTopicMap topicmap,void chunk(const char *chunk, void *cl), void *cl, int chunk_size) { TMResult result = NULL; char *buf; int size = 4096; int i /*,j*/; TM_ENTER; tm_topicmap_start_transaction(topicmap,"query"); buf = (char*)TM_ALLOC( tm_topicmap_get_current_transaction_pool(topicmap), 4096); if( tm_topicmap_query(topicmap,q1,&result) != TM_OK) { fprintf(stderr,"could not execute query '%s', %s\n", q1, tm_get_error(tm_topicmap_get_tm(topicmap)) ); assert(0); } assert(result); assert(result->type == TM_RESULT_SUBJECTS); snprintf(buf,size,"%s",preamble); chunk(buf,cl); *buf = 0; for(i=0;insubjects;i++) { my_print_topic(&buf,&size,&(result->subjects[i]),result->topics[i]); chunk(buf,cl); *buf = 0; } tm_result_delete(&result); if( tm_topicmap_query(topicmap,q2,&result) != TM_OK) { fprintf(stderr,"could not execute query '%s', %s\n", q1, tm_get_error(tm_topicmap_get_tm(topicmap)) ); assert(0); } assert(result); assert(result->type == TM_RESULT_SUBJECTS); for(i=0;insubjects;i++) { my_print_assoc(&buf,&size,&(result->subjects[i]),result->topics[i]); chunk(buf,cl); *buf = 0; } snprintf(buf,size,"\n"); chunk(buf,cl); *buf = 0; TM_FREE(tm_topicmap_get_current_transaction_pool(topicmap),buf); tm_topicmap_end_transaction(topicmap); TM_RETURN(TM_OK); } void my_print_topic(char **bufp, int *sizep,TMSubject sbj, TMTopic t) { TMList sirs,names; int j; char b[1024]; TM_ENTER; snprintf(*bufp,*sizep,"\n" , t); if( tm_subject_get_value(sbj,"http://purl.org/tm/sam/SubjectIndicators",NULL) || tm_subject_get_value(sbj,"http://purl.org/tm/sam/SubjectAddress",NULL)) { strcat(*bufp," \n"); if( tm_subject_get_value(sbj,"http://purl.org/tm/sam/SubjectIndicators", (void**)&sirs )) { for( ; sirs; sirs=sirs->next) { sprintf(b," \n" , (char*)sirs->content ); strcat(*bufp,b); } } strcat(*bufp," \n"); } if( tm_subject_get_value(sbj,"http://purl.org/tm/sam/BaseNames",(void**)&names )) { for( ; names; names=names->next) { strcat(*bufp," \n"); sprintf(b," %s\n" , (char*)names->content ); strcat(*bufp,b); strcat(*bufp," \n"); } } for(j=0;jN;j++) { char buf[1024]; if(strcmp(sbj->props[j].prop->fullname, "http://purl.org/tm/sam/BaseNames") == 0) continue; if(strcmp(sbj->props[j].prop->fullname, "http://purl.org/tm/sam/SubjectIndicators") == 0) continue; if(strcmp(sbj->props[j].prop->fullname, "http://purl.org/tm/sam/SubjectAddress") == 0) continue; if(strcmp(sbj->props[j].prop->fullname, "http://purl.org/tm/sam/SourceLocators") == 0) continue; tm_value_to_string( sbj->props[j].prop->value_type, sbj->props[j].value, buf,1024); strcat(*bufp," \n"); strcat(*bufp," \n"); sprintf(b," \n", sbj->props[j].prop->fullname); strcat(*bufp,b); strcat(*bufp," \n"); sprintf(b," %s\n",buf); strcat(*bufp,b); strcat(*bufp," \n"); } strcat(*bufp,"\n"); TM_EXIT; } void my_print_assoc(char **bufp, int *sizep,TMSubject sbj, TMTopic t) { struct asidp_value *Vasidp; TMList mp; char b[1024]; int j; TM_ENTER; tm_subject_get_value(sbj,"http://purl.org/tm/amod/a-sidp",&Vasidp); sprintf(b,"\n" , t); strcat(*bufp,b); strcat(*bufp," \n"); sprintf(b," \n", Vasidp->type.topic); strcat(*bufp,b); strcat(*bufp," \n"); for(mp=Vasidp->memberships;mp;mp=mp->next) { struct a_membership *m; m = (struct a_membership *)mp->content; strcat(*bufp," \n"); sprintf(b," \n", m->role.topic); strcat(*bufp,b); strcat(*bufp," \n"); sprintf(b," \n", m->player.topic); strcat(*bufp,b); } strcat(*bufp,"\n"); TM_EXIT; } #if 0 TMProperty p = result->prop_heading[j]; printf("| %-30s\t",p->name); } printf("%s\n\n","|"); for(i=0;inrows;i++) { void **row; row = result->vtable[i]; for(j=0;jncols;j++) { TMProperty p = result->prop_heading[j]; printf("| %-30s\t", tm_value_as_string(p->value_type,row[j],NULL,0) ); } printf("%s\n","|"); } break; default: } /* end switch */ tm_topicmap_end_transaction(topicmap); } #endif