The following code is compiled like so on red hat 8.0 to create cgi for this form
http://www.library.drexel.edu/er/searchform_sfx.htmlcompiled like so
gcc -l new.c -o search2.cgi:
void per_hit_issn(char* name, char* keys) {
FILE* f = fopen(name, "r");
char* line = (char*) malloc(SIZE*sizeof(char));
char* temp = (char*) malloc(SIZE*sizeof(char));
char* one = (char*) malloc(SIZE*sizeof(char));
char* two = (char*) malloc(SIZE*sizeof(char));
char* three = (char*) malloc(SIZE*sizeof(char));
char* issn = (char*) malloc(SIZE*sizeof(char));
char* cloc = (char*) malloc(25*sizeof(char));
char* k = (char*) malloc(SIZE*sizeof(char));
char* isn = (char*) malloc(SMALL*sizeof(char))
;
char * start;
char* tmpfile = "XXXXXX";
char* t;
char *t2;
char* name2;
int len;
int count = 0;
int flag;
while(!feof(f)) {
fgets(line, SIZE, f);
if (feof(f)) break;
if (strstr(line, "<eee>yes</eee>")) flag = 0;
else flag = 1;
if (count > 0) printf("<hr>");
else printf("<br>");
printf("<br><strong>%d</st
rong><br>"
, ++count);
start = (strstr(line, "<JOURNAL>") + 9);
len = strstr(line, "</JOURNAL>") - start;
strcopy(temp, start, len);
printf("<strong><font size=-1>%s</font></strong>
<br>\n", temp);
if (!strstr(line, "<eee>yes")) {
start = (strstr(line, "<CLOC>") + 6);
len = strstr(line, "</CLOC>") - start;;
strcopy(cloc, start, len);
}
strncopy2(k, keys);
if (!strstr(line, "<eee>yes")) {
start = (strstr(line, "<ISBN/ISSN>") + 11);
len = strstr(line, "</ISBN/ISSN>") - start;
strcopy(issn, start, len);
if (strcmp("AAAAAAAA", issn) != 0) {
print_issn(issn, k, isn);
printf("<strong>ISSN: %s </strong><br><br>\n", isn);
}
else printf("<br>\n");
} else {
start = (strstr(line, "<issn>") + 6);
len = strstr(line, "</issn>") - start;
strcopy(issn, start, len);
if (strcmp("AAAAAAAA", issn) != 0) {
print_issn(issn, k, isn);
//printf("isn = %s, length = %d\n", isn, strlen(isn));
printf("<strong>ISSN: %s </strong><br><br>\n", isn);
}
else printf("<br>");
}
if (strcmp("AAAAAAAA", issn) != 0)
print_at(line, NULL, -1);
if (strstr(line, "<url>")) {
start = (strstr(line, "<url>") + 5);
len = strstr(line, "</url>") - start;;
strcopy(temp, start, len);
sfx_button(temp);
while (1) {
if (!strstr(line, "<via>")) break;
start = (strstr(line, "<via>") + 5);
len = strstr(line, "</via>") - start;;
strcopy(temp, start, len);
printf("<strong> &nbs
p; &n
bsp;
%s </strong><br> \n", temp);
start = (strstr(line, "<av>") + 4);
len = strstr(line, "</av>") - start;;
strcopy(temp, start, len);
printf("
&nbs
p;%s <br>\n\n", temp);
strncopy(line, strstr(line, "</av>") + 5);
}
if (flag) printf("<br>");
}
if (flag) {
start = (strstr(line, "<OCLC #>") + 8);
len = strstr(line, "</OCLC #>") - start;;
strcopy(temp, start, len);
printf("<a href=\"
http://innopac.library.drexel.edu/search/o?SEARCH=%s\">View
Print Journal Records</a><b
r>\n\n", temp);
while (1) {
if (!strstr(line, "<resource>")) break;
start = (strstr(line, "<resource>") + 10);
len = strstr(line, "</resource>") - start;;
strcopy(temp, start, len);
t = strtok(temp, "\" ");
t2 = strtok(NULL, "\" ");
printf("
&nbs
p;<strong>
%s</strong
>: %s<br>", t, t2);
strncopy(line, strstr(line, "</resource>") + 10);
}
printf("<br>");
} else {
printf("<br>");
}
}
fclose(f);
free(line);
free(temp);
free(cloc);
free(one);
free(two);
free(three);
free(k);
free(issn);
free(isn);
}
int main(int argc, char** argv) {
FILE* f;
int i = 0;
int j = 0;
int k = 0;
int type = 0;
int ejournal = 0;
char* input = (char*) malloc(SIZE*sizeof(char));
char* search = (char*) malloc(SIZE*sizeof(char));
char* line = (char*) malloc(SIZE*sizeof(char));
char* line2 = (char*) malloc(SIZE*sizeof(char));
char* temp3 = (char*) malloc(SIZE*sizeof(char));
char* issn;
char* issn2 = (char*) malloc(64*sizeof(char));
char* name;
char* temp;
char* temp2; char* start; char* end;
int f1, f2, f3;
char* tmpfile = "XXXXXX";
printf("Content-type: text/html\r\n\r\n");
for (i = 1; i < argc; i++) {
temp = argv[i];
while (temp[k] != '\0') {
input[j] = temp[k];
j++;
k++;
}
input[j] = ' ';
j++;
k = 0;
}
input[j-1] = '\0';
k = 0;
j = 0;
i = 0;
start = strstr(input, "search_input=") + 13;
end = strstr(input, "\\&submit=");
if (start == NULL) {
printf("start == NULL\n");
return;
}
if (end == NULL) {
printf("end == NULL\n");
return;
}
for (i = 0; strlen((char*) start+i) != strlen((char*) end); i++) {
if (start[i] == '\\') continue;
if (strstr(input, "search_type=issn") != NULL) {
if (start[i] != '-') {
search[j] = start[i];
j++;
}
}
else {
search[j] = start[i];
j++;
}
}
j = 0;
search[i]='\0';
// printf("%s\n", input);
// return;
if (strstr(input, "search_type=title") != NULL) type = 1;
if (strstr(input, "search_type=keywords") != NULL) type = 2;
if (strstr(input, "search_type=issn") != NULL) type = 3;
if (strstr(input, "ejournals=yes") != NULL) ejournal = 1;
//printf("search = %s\n", search);
// printf("input = %s\n", input);
if (ejournal == 1) { //ejournals only
if (type == ISSN) { //issn search
//name = tmpnam(NULL);
f1 = mkstemp(tmpfile);
get_issn(issn2, search);
issn_grep(data_file2, f1, issn2);
f = fdopen(f1, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f) || ferror(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
ejournal_hit_issn(name, search);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
return 0;
}
} else if (type == KEYWORDS) { //keywords search
sprintf(temp3, "%s", search);
sprintf(line2, "%s", search);
//printf("%s\n", search);
f1 = mkstemp(tmpfile);
//f2 = mkstemp(tmpfile);
//f3 = mkstemp(tmpfile);
//strcopy(search, f3, strlen(temp2));
//strcopy(input, f2, strlen(temp));
//search[strlen(temp2)] = '1';
//search[strlen(temp2)+1] = '\0';
//input[strlen(temp)] = '2';
//input[strlen(temp)+1] = '\0';
//keywords_grep(data_file2
, name, search, input, temp3);
title_grep_2(data_file2, f1, temp3);
f = fopen(name, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f) || ferror(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
free(line2);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
ejournal_hit_title(f1, line2, type);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
free(line2);
return 0;
}
} else if (type == TITLE) { //title search
concat(input, search);
sprintf(temp3, "%s", input);
sprintf(line2, "%s", input);
//name = tmpnam(NULL);
f1 = mkstemp(tmpfile);
title_grep(data_file2, f1, temp3);
f = fopen(name, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
free(line2);
free(name);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
ejournal_hit_title(f1, line2, type);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
free(line2);
return 0;
}
}
} else { //not only ejournals
if (type == ISSN) { //issn search
f2 = mkstemp(tmpfile);
//name = tmpnam(NULL);
get_issn(issn2, search);
issn_grep(data_file, f2, issn2);
f = fdopen(f2, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f) || ferror(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
free(line2);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
per_hit_issn(name, search);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
free(line2);
return 0;
}
} else if (type == KEYWORDS) { //keywords
sprintf(temp3, "%s", search);
sprintf(line2, "%s", search);
//printf("%s\n", search);
//name = tmpnam(NULL);
f1 = mkstemp(tmpfile);
//temp = tmpnam(NULL);
//temp2 = tmpnam(NULL);
//strcopy(search, temp2, strlen(temp2));
//strcopy(input, temp, strlen(temp));
//search[strlen(temp2)] = '1';
//search[strlen(temp2)+1] = '\0';
//input[strlen(temp)] = '2';
//input[strlen(temp)+1] = '\0';
// combined_keywords_grep(dat
a_file, name, search, input, temp3);
combined_title_grep_2(data
_file, f1, temp3);
//printf("here\n");
f = fdopen(f1, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f) || ferror(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
free(line2);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
per_hit_title(f1, line2, type);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
free(line2);
return 0;
}
} else if (type == TITLE) { //title
concat(input, search);
sprintf(temp3, "%s", input);
sprintf(line2, "%s", input);
//name = tmpnam(NULL);
f1 = mkstemp(tmpfile);
combined_title_grep(data_f
ile, f1, temp3);
f = fopen(name, "r");
if (!ferror(f) && !feof(f)) fgets(line, SIZE, f);
if (feof(f) || ferror(f)) { //miss
fclose(f);
nothing();
free(temp3);
free(search);
free(input);
free(line);
free(line2);
return 0;
} else { //hits
fclose(f);
header();
js();
printf("<center><b>Click SFX button for full-text options.</b></center><br>\
n");
printf("<font size=-1>");
new_search();
per_hit_title(f1, line2, type);
new_search();
printf("</font>");
footer();
free(search);
free(input);
free(line);
free(temp3);
free(line2);
return 0;
}
}
}
}
1) need to get this to compile and work with sun solaris 7 operating system
2) if (type == ISSN) { //issn search meaning if the the search type selected is issn only it needs to work with lowercase letters as well as uppercase. example someone puts in
0193-953x they do not get a return however is they put in
0193-953X they get a return.
thanks
Tutbro 22
Start Free Trial