#include "apasrch_sm.h" extern int APAsrch_sm(char *query); main() { FILE *fp; /* file pointer to get HTML source */ char query[128]; /* user query */ getentry entries[16]; /* arguments from the user via http */ int dn; /* number of items in a web page */ int start; /* start point of the items */ short dspPreview; /* Display preview or not. YES or NO */ int i, x; /* for general use */ char line[256]; /* for general use */ strcpy(query, "\0"); /* initialize user query as NULL */ start = 0; /* start point, default as 0 */ dn = 5; /* display num's default as 5 */ dspPreview = YES; /* as default display preview image */ printf("content-type: text/html\n\n"); /* HTML Header */ #ifdef FILEOUT printf("Debugging Mode\n"); i = 2; strcpy(entries[0].name, "qt"); strcpy(entries[0].val, "lion"); strcpy(entries[1].name, "dspNum"); strcpy(entries[1].val, "5"); strcpy(entries[2].name, "dspPreview"); strcpy(entries[2].val, "YES"); #else i = ProcessGetMethod( entries ); #endif /* extract user's requirements */ for (x=0; x<=i; x++) { if (!strcasecmp(entries[x].name, "qt")) { strcpy(query, entries[x].val); trim(query); continue; } if (!strcasecmp(entries[x].name, "start")) { start = atoi(entries[x].val); if (start <= 0) start = 0; continue; } if (!strcasecmp(entries[x].name, "dspNum")) { dn = atoi(entries[x].val); if (dn <= 0) dn = 5; continue; } if (!strcasecmp(entries[x].name, "dspPreview")) { if (!strcasecmp(entries[x].val, "YES")) dspPreview = YES; else dspPreview = NO; continue; } } #ifdef FILEOUT printf("query [%s] dspNum : [%d] dspPreview : [%d]
\n", query, dn, dspPreview); fflush(stdout); #endif if (strlen(query) <= 0) strcpy(query, "unidentified"); if (strlen(query) > 0 && start == 0) { i = APAsrch_sm(query); if (i == 0) /* if there is no matching records */ { if ((fp=fopen(HTMLNORESULT, "r")) == NULL) fatal("HTML no result source file open failed"); while (fgets(line, 256, fp)) { if (strstr(line, "__QUERY__")) printf("%s\n", query); else printf("%s\n", line); } fclose(fp); exit(0); } } /* print the result */ printResult(start, dn, query, YES); exit(0); }