Advertisement

04.12.2004 at 07:44AM PDT, ID: 20951011
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

C cgi program

Asked by turbo22 in CGI Scripting

Tags: , ,

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.html

compiled 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</strong><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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s </strong><br> \n", temp);
        start = (strstr(line, "<av>") + 4);
        len = strstr(line, "</av>") - start;;
        strcopy(temp, start, len);
        printf("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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(data_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_file, 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
[+][-]04.13.2004 at 02:47PM PDT, ID: 10817909

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: CGI Scripting
Tags: c, cgi, programming
Sign Up Now!
Solution Provided By: ShawnCurry
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.15.2004 at 11:22AM PDT, ID: 10835676

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.03.2004 at 04:45AM PDT, ID: 11971682

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.07.2004 at 07:44PM PDT, ID: 12002830

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44