#include #include #include #include "y.tab.h" #include "data.h" TAO gloTao; int yyline = 1; int yycolumn = 0; char *yystr = NULL; FILE *yyin ; FILE *fpout = {stdout}; void sorry(char *); void src_txt(char *); void src_img(char *); void struct_link(char *); void template_parse(TAO); void tao_parse(char *); LINK *search_link(LINK *, char *); void insert_ic_input(IC*, char*, char*); interpreter(tao) char *tao; { tao_parse(tao); } void tao_parse(tao_name) char *tao_name; { char name[50]; #ifdef TRANSLATE char *ptr; FILE *fp,ftmp; char template[40]="tmp_dir/CHNXXXXXX"; char *filter_name; filter_name = mktemp(template); if( filter_name == NULL) { printf("can not make temp file\n"); return; } fp = fopen(filter_name,"wt"); if(fp == NULL) { printf("Can not open tmp file! %s\n",filter_name); fflush(stdout); return; } ftmp = *(stdout); /* save stdout temprorily */ *(stdout) = *fp; #endif sprintf(name, "%s/%s", "TAOML", tao_name); /* add path */ /* strcpy(name, tao_name); */ if (!strstr(name, ".taoml")) strcat(name, ".taoml"); yyin = fopen(name, "r"); if (!yyin) { printf("The file %s doesn't exist.\n", name); exit(0); } gloTao.TName = NULL; gloTao.TType = 0; gloTao.TTpl = NULL; gloTao.TTpl_in = NULL; gloTao.TLink = NULL; gloTao.TIC = NULL; gloTao.DB_access = strdup(""); gloTao.TSens = 0; yyline = 0; yycolumn = 1; yyparse(); fclose(yyin); if (!gloTao.TName) { printf("You should define TAO name.\n"); exit(0); } if (gloTao.TTpl && gloTao.TType) /* if tao type and template are specified */ switch (gloTao.TType) { case MIXED_TYPE: template_parse(gloTao); break; case IMAGE_TYPE: src_img(gloTao.TTpl); break; case TEXT_TYPE: src_txt(gloTao.TTpl); break; default: sorry("Types except image & text"); } else if (gloTao.TIC && gloTao.TName) { printf("\n"); insert_ic_input(gloTao.TIC, gloTao.TName, gloTao.DB_access); printf("\n"); } #ifdef TRANSLATE fflush(stdout); fclose(fp); /* this save the required text to file */ *(stdout) = ftmp; /* restore stdout */ if((ptr=get_cookie())==NULL) { print_file(filter_name); } else { if(strcmp(ptr,"hz_display=\"code_display\"")==0) convert_main(filter_name,FALSE); else if(strcmp(ptr,"hz_display=\"gif_display\"")==0) convert_main(filter_name,TRUE); else print_file(filter_name); } unlink(filter_name); printf("
\n"); printf("\n"); printf("Enable English Display
\n"); printf("\n"); printf("Enable Chinese BIG-5 Display
\n"); printf("\n"); printf("Enable Chinese GIF Display
\n"); fflush(stdout); #endif } /* Note: Use a structure TAO as the parameter */ void template_parse(locTao) TAO locTao; { int token; int ic_input_flag = 0, rel_flag = 0; LINK *ptrLink; char *name; char *name2; FILE *yyin2; FILE *par_fp; IC TIC; char *tao_name; char *db_access; char val[20]; int tic_flag; /* it is supposed that the file is located at subdirectory TAOML of the directory where secm.cgi located */ name = (char *) malloc(sizeof(char)*(strlen(locTao.TTpl)+10)); sprintf(name, "%s/%s", "TAOML", locTao.TTpl); if (!strstr(name, ".tpl")) strcat(name, ".tpl"); yyin = fopen(name, "r"); if (!yyin) { printf("The file %s doesn't exist.\n", name); exit(0); } name2 = (char *) malloc(sizeof(char)*(strlen(locTao.TTpl)+10)); sprintf(name2, "%s/%s", "TAOML", locTao.TTpl_in); if (!strstr(name2, ".par")) strcat(name2, ".par"); par_fp = fopen(name2, "r"); /* if not exist, par_fp is NULL */ /* Copy locTao.TIC to another space TIC */ /* if not, may get core dumpped. Do not know why. */ if (locTao.TIC) { TIC.Flag = locTao.TIC->Flag; TIC.flag = locTao.TIC->flag; TIC.IC_type = locTao.TIC->IC_type; TIC.ID_list = locTao.TIC->ID_list; TIC.Msg_type = locTao.TIC->Msg_type; TIC.Content = locTao.TIC->Content; TIC.cgi = locTao.TIC->cgi; tic_flag = 1; } else tic_flag = 0; tao_name = locTao.TName; /* keep the tao name */ db_access = locTao.DB_access; /* keep the db access */ yyline = 0; yycolumn = 1; while (!feof(yyin)&& (token = yylex())) { switch (token) { case NORMAL: printf("%s", yystr); break; case BTREL: if (!rel_flag) rel_flag = 1; else yyerror("TAO_REL"); break; case ETREL: if (rel_flag) rel_flag = 0; else yyerror("/TAO_REL"); break; case ICINPUT: if (!ic_input_flag) { ic_input_flag = 1; if (tic_flag && tao_name) insert_ic_input(&TIC, tao_name, db_access); } else printf("Warning: Tag used twice!\n"); break; case DBHERE: printf("\n\n", db_access); break; case INPBOXPAR: if (par_fp) { fgets(val, 20, par_fp); val[strlen(val)-1] = '\0'; if (atof(val) != -1) printf("%s", val); } break; case RADIOPAR: if (par_fp) { fgets(val, 20, par_fp); if (atof(val) == 1) printf("CHECKED"); } break; case CHKBOXPAR: if (par_fp) { fgets(val, 20, par_fp); if (atof(val) == 1) printf("CHECKED"); } break; case SKIPPAR: if (par_fp) fgets(val, 20, par_fp); /* display nothing */ break; case STRING: if (rel_flag) { ptrLink = search_link(locTao.TLink, yystr); while (ptrLink != NULL) { switch (ptrLink->LType) { case SPATIAL_LINK: yyin2 = yyin; tao_parse(ptrLink->LObj); yyin = yyin2; break; case TEMPORAL_LINK: sorry("Temporal Link"); break; case STRUCTURAL_LINK: struct_link(ptrLink->LObj); break; } ptrLink = ptrLink->next; } } else yyerror("error position for TAO REL name"); break; default: printf("%s: %d: Invalid syntax in template.\n", name, token); } } /* end of while */ printf("\n"); if (!ic_input_flag) /* if not specified in template */ { if (tic_flag && tao_name) { printf("\n"); insert_ic_input(&TIC, tao_name, db_access); printf("\n"); } } fclose(yyin); if (par_fp != NULL) { fclose(par_fp); unlink(name2); } } void insert_ic_input(IC* ic, char* tao_name, char* db_access) { if ((!ic->cgi) || (ic->cgi[0] == '?')) { printf("\n\nYou should define the cgi for this TAO.\n"); exit(0); } printf("\n\n"); printf("
\n
\n"); printf("
\n"); printf("

Input this Form to send a Message to Trigger an Index Cell

\n"); printf("
\n", ic->cgi); printf("\n"); if (ic->Flag == EMPTY_FLAG) { printf("\n"); printf("\n"); } else if (ic->Flag == OLD_FLAG) printf("\n"); else if (ic->Flag == NEW_FLAG) printf("\n"); else printf("*** Unexpected flag value = %d\n", ic->Flag); if (ic->IC_type == NULL) { printf("\n"); printf("\n"); } else if (ic->IC_type[0] == '?') { printf("\n"); printf("\n"); } else printf("\n", ic->IC_type); if (ic->ID_list == NULL) { printf("\n"); printf("\n"); } else if (ic->ID_list[0] == '?') { printf("\n"); printf("\n"); } else printf("\n", ic->ID_list); if (ic->Msg_type == NULL) { printf("\n"); printf("\n"); } else if (ic->Msg_type[0] == '?') { printf("\n"); printf("\n"); } else printf("\n",ic->Msg_type); if (ic->Content == NULL) { printf("\n"); printf("\n"); } else if (ic->Content[0] == '?') { printf("\n"); printf("\n"); } else printf("\n",ic->Content); printf("
flag\n"); if (ic->flag != NULL) printf("%s
\n", &(ic->flag[1])); printf("Existing IC (Do Not need to fill ic_type)
\n"); printf("New IC (Do Not need to fill ic_id_list)
\n"); printf("
ic_type
ic_type%s
\n", &(ic->IC_type[1])); printf("
ic_id_list
ic_id_list%s
\n", &(ic->ID_list[1])); printf("
message_type
message_type%s
\n", &(ic->Msg_type[1])); printf("
content
content%s
\n", &(ic->Content[1])); printf("
\n"); printf("\n", tao_name); printf("\n", db_access); if ((ic->IC_type == NULL) || (ic->IC_type[0] == '?')) printf("

\n"); else printf("
\">
\n", ic->IC_type); printf("
\n"); printf("
\n"); printf("
\n
\n"); } void struct_link(objname) char *objname; { char str[50], *dot; char* name; strcpy(str, objname); if ((dot = strchr(str, '.'))) dot[0] = '\0'; if (strstr(objname, ".taoml") != NULL) { printf("\n link to %s

\n", objname, str); } else if (strstr(objname, ".gif")) { /* it is supposed that the file is located at subdirectory TAOML of the directory where secm.cgi located */ name = (char *) malloc(sizeof(char)*(strlen(objname)+10)); sprintf(name, "%s/%s", "S-Event_Data/Images", objname); printf("\n the picture of %s

\n", name, str); } } void src_img(src_name) char *src_name; { char *name; name = (char *) malloc(sizeof(char)*(strlen(src_name)+10)); sprintf(name, "%s/%s", "S-Event_Data/Images", src_name); printf("

\n", name); } void src_txt(src_name) char *src_name; { FILE *fp; char str[120]; char *name; name = (char *) malloc(sizeof(char)*(strlen(src_name)+10)); sprintf(name, "%s/%s", "TAOML", src_name); /* add path */ fp = fopen(name, "r"); if (!fp) { printf("The file %s doesn't exist.\n", src_name); exit(0); } while (!feof(fp)) { if (fgets(str, 119, fp)) printf("%s", str); } fclose(fp); } void sorry(str) char *str; { printf("Sorry! %s is not implemented yet.\n

", str); } LINK *search_link(link_head, name) LINK *link_head; char *name; { LINK *ptr, *ptrHead, *tmp; ptrHead = (LINK *)malloc(sizeof(LINK)); ptrHead->next = NULL; tmp = ptrHead; ptr = link_head; while (ptr != NULL) { if (strcmp(ptr->LName, name) == 0) { tmp->next = (LINK *)malloc(sizeof(LINK)); tmp = tmp->next; tmp->LName = ptr->LName; tmp->LType = ptr->LType; tmp->LObj = ptr->LObj; tmp->next = NULL; } ptr = ptr->next; } return(ptrHead->next); }