main() { FILE *fp ; return_header("text/html") ; printf("<form name=theform>") ; printf("Select an herbarium:<br>\n") ; printf("<select name=herb>\n") ; fp = fopen("/herbaria/FLORA/tracy/mgdata/herb_list", "r") ; while (!feof(fp)) { char s[80] ; fgets(s, 80, fp) ; if (!feof(fp)) { *strrchr(s, '\n') = '\0' ; printf("<option>%s\n", s) ; } } fclose(fp) ; printf("</select><br>\n") ; printf("and enter an accession number: ") ; printf("<input type=text name=acc size=10><br>\n") ; printf("<input type=button value=\"Get specimen\" ") ; printf("onClick=\"top.get_single(theform.herb.value,theform.acc.value)\">") ; printf("</form>\n") ; }
main() { char *xy_str ; char *x_in ; char *y_in ; char *clicked_loc ; xy_str = getenv("QUERY_STRING") ; x_in = strtok(xy_str, ",") ; y_in = strtok(NULL, ",") ; clicked_loc = map_convert_xy_to_name(atoi(x_in), atoi(y_in), HSB_MAP_PATH, "tx", "ut_abbr") ; if (clicked_loc == NULL) return_nothing() ; else { return_header("text/html") ; printf("<script>") ; printf("top.toggle_loc('%s');\n", clicked_loc) ; printf("</script>") ; printf("<body onLoad=\"window.history.back();\"></body>") ; } }
void *process(void *a) { char **envp; const char *data; int res; FCGX_Request req; json_object *json; json_object *jarray; FCGX_InitRequest(&req, 0, 0); while(1) { res = FCGX_Accept_r(&req); if(res < 0) { break; } json = json_object_new_object(); jarray = json_object_new_array(); return_header(&req, 200, NULL, "application/json"); for(envp = req.envp; *envp != NULL; envp++) { //FIXME jsonurlencode... json_object_array_add(jarray, json_object_new_string(*envp)); } json_object_object_add(json, "env", jarray); data = json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY); FCGX_FPrintF(req.out, "%s\n", data); json_object_put(json); FCGX_Finish_r(&req); } return NULL; }
main() { int i ; char *regions, *name, *plainname, *s ; int rs[] = {255, 255, 176, 255, 0, 196, 0, 135, 0, 0} ; int gs[] = { 0, 165, 48, 255, 255, 196, 196, 206, 0, 0} ; int bs[] = { 0, 0, 96, 0, 0, 0, 0, 235, 255, 0} ; void *map_info ; return_header("text/html") ; printf("<body bgcolor=\"#ffffff\">") ; decode_query_string(2,"reg", ®ions, "name", &name) ; plainname = (char *)malloc(sizeof(char) *(strlen(name)+1)) ; strcpy(plainname, name) ; { int i, j ; i = 0 ; while (plainname[i] != '\0') { if (plainname[i] == '<') { j = i ; while (plainname[j] != '>' && plainname[j] != '\0') j++ ; if (plainname[j] == '>') { j++ ; strcpy(plainname+i, plainname+j) ; } else plainname[i] = '\0' ; } else i++ ; } } map_info = map_initialize("/herbaria/FLORA/cgi/maps", "vpt", ABSOLUTE) ; map_assign_absolute_colors(map_info, 10, rs, gs, bs) ; s = strtok(regions, ",") ; while (s != NULL) { map_set_region_color_by_num(map_info, atoi(s)-1, atoi(s)) ; s = strtok(NULL, ",") ; } printf("<title>Distribution of %s in Texas</title>\n", plainname) ; printf("<h1>Distribution of %s in Texas:</h1>\n", name) ; map_output_img(map_info, 0, NULL, "left", NULL) ; printf("<p>\n") ; for (i=0 ; i < 10 ; i++) { map_output_absolute_color_block(map_info, i+1) ; printf("<a href=\"/FLORA/tracy/%s%d.htm\"> %s</a><br>", i+1 == 10 ? "taesre" : "taesreg", i+1, names[i]) ; } }
main() { int i ; char *regions, *species, *genus, *infra, *inspec, *s ; char plainname[128], italname[128] ; int rs[] = {255, 255, 176, 255, 0, 196, 0, 135, 0, 0} ; int gs[] = { 0, 165, 48, 255, 255, 196, 196, 206, 0, 0} ; int bs[] = { 0, 0, 96, 0, 0, 0, 0, 235, 255, 0} ; void *map_info ; return_header("text/html") ; decode_query_string(1, "reg", ®ions, "spec", &species, "gen", &genus, "infra", &infra, "inspec", &inspec) ; if (nonempty(inspec)) { sprintf(plainname, "%s %s %s %s", genus, species, inspec, infra) ; sprintf(italname, "<i>%s %s</i> %s <i>%s</i>", genus, species, inspec, infra) ; } else { sprintf(plainname, "%s %s", genus, species) ; sprintf(italname, "<i>%s %s</i>", genus, species) ; } map_info = map_initialize("/herbaria/FLORA/cgi/maps", "vpt", ABSOLUTE) ; map_assign_absolute_colors(map_info, 10, rs, gs, bs) ; s = strtok(regions, ",") ; while (s != NULL) { map_set_region_color_by_num(map_info, atoi(s)-1, atoi(s)) ; s = strtok(NULL, ",") ; } printf("<title>Distribution of %s in Texas</title>\n", plainname) ; printf("<h1>Distribution of %s in Texas:</h1>\n", italname) ; map_output_img(map_info, 0, NULL, "left", NULL) ; printf("<p>\n") ; for (i=0 ; i < 10 ; i++) { map_output_absolute_color_block(map_info, i+1) ; printf("<a href=\"/FLORA/tracy/%s%d.htm\">%s</a><br>", i+1 == 10 ? "taesre" : "taesreg", i+1, names[i]) ; } }
main() { char *host, *query, *querytype, *return_format ; char *outfile ; char s[1024] ; char qstr[1024] ; FILE *fp ; int parnum ; return_header("text/html") ; decode_query_string(3,"query", &query, "type", &querytype, "rform", &return_format) ; sprintf(qstr, ".set query %s\n%s", querytype, query) ; do_mg_query(qstr, "/herbaria/FLORA/hatch_checklist/mgdata", "hatch_checklist", &outfile) ; fp = fopen(outfile, "r") ; if (!strcmp("full", return_format)) { while (!feof(fp)) { fgets(s, 1024, fp) ; if (!strncmp(s, "entrnum", 7)) printf("<hr>\n") ; else printf("%s<br>\n", s) ; } } else { printf("Entries matching your query: <br>\n") ; printf("<ul>\n") ; while (!feof(fp)) { fgets(s, 1024, fp) ; if (!strncmp(s, "entrnum", 7)) { sscanf(s, "entrnum %d\n", &parnum) ; printf("<li><a href=\"http://%s%s?rform=full&type=docnums&query=%d\">", getenv("SERVER_NAME"), getenv("SCRIPT_NAME"), parnum) ; fgets(s, 1024, fp) ; printf("%s</a>\n", s) ; } } printf("</ul>\n") ; } fclose(fp) ; unlink(outfile) ; }
main() { char *color_str ; FILE *fp ; int i, j ; int ra[1], ga[1], ba[1] ; return_header("image/gif") ; decode_query_string(1,"color", &color_str) ; ra[0] = 100*(color_str[0]-'0') + 10*(color_str[1]-'0') + color_str[2]-'0' ; ga[0] = 100*(color_str[3]-'0') + 10*(color_str[4]-'0') + color_str[5]-'0' ; ba[0] = 100*(color_str[6]-'0') + 10*(color_str[7]-'0') + color_str[8]-'0' ; rle22gif("./smallsquare.rle2", 1, 0, ra, ga, ba) ; }
int main(int argc, char *argv[]) { char *all_in, *group_in, *subclass_in, *order_in ; char *family_in, *genus_in, *species_in, *tri_in, *show_infras ; char *loc_in, *x_in, *y_in ; request_level_t request_level ; char name_html[128], *name_plain ; char qstr[512] ; void *qd ; taxon *root ; taxon *group_p, *subc_p, *ord_p, *fam_p, *gen_p, *spec_p, *tri_p, *quad_p ; int has_orders, has_subclasses ; int is_ext = !strcmp(argv[0], "b98_list_ext") ? 1 : 0 ; /* get CGI vars */ decode_query_string(11, "all", &all_in, "group", &group_in, "subclass", &subclass_in, "order", &order_in, "family", &family_in, "genus", &genus_in, "species", &species_in, "tri", &tri_in, "loc", &loc_in, "x", &x_in, "y", &y_in) ; /* process mouse click */ if (nonempty(x_in)) { loc_in = map_convert_xy_to_name(atoi(x_in), atoi(y_in), MAP_DIR, MAP_NAME, "abbr") ; if (!nonempty(loc_in)) return_nothing() ; } /* determine "request level" of request */ if (nonempty(all_in)) request_level = ALL ; else if (nonempty(group_in)) request_level = GROUP ; else if (nonempty(subclass_in)) request_level = SUBCLASS ; else if (nonempty(order_in)) request_level = ORDER ; else if (nonempty(family_in)) request_level = FAMILY ; else if (nonempty(genus_in)) { if (nonempty(species_in)) if (nonempty(tri_in)) request_level = TRI ; else request_level = SPECIES ; else request_level = GENUS ; } else request_level = ERROR ; /* build MG query string */ switch(request_level) { case ALL: sprintf(qstr, "qqall") ; break; case GROUP: sprintf(qstr, "qqgrp%s", group_in) ; break ; case SUBCLASS: sprintf(qstr, "qqsbc%s", subclass_in) ; break ; case ORDER: sprintf(qstr, "qqord%s", order_in) ; break ; case FAMILY: sprintf(qstr, "qqfam%s", family_in) ; break ; case GENUS: sprintf(qstr, "qqgen%s", genus_in) ; break ; case SPECIES: case TRI: /* eliminate dashes in species names */ { char *temp_s, *dash_loc ; temp_s = strdup(species_in) ; if ((dash_loc = strchr(temp_s, '-')) != NULL) strcpy(dash_loc, dash_loc+1) ; sprintf(qstr, "qqgen%s&qqspe%s", genus_in, temp_s) ; free(temp_s) ; if (request_level == TRI) { temp_s = strdup(tri_in) ; if ((dash_loc = strchr(temp_s, '-')) != NULL) strcpy(dash_loc, dash_loc+1) ; sprintf(qstr+strlen(qstr), "&qqtri%s", temp_s) ; free(temp_s) ; } } break ; } if (nonempty(loc_in)) sprintf(qstr+strlen(qstr), "&qqloc%s", loc_in) ; /* execute MG query */ mg_bool_query(qstr, MG_COLL_DIR, MG_COLL_NAME, &qd) ; /* process MG query results */ if (mg_get_num_returned(qd) == 0) return_nothing() ; root = NULL ; { char s[256] ; void *lp=NULL ; int docnum ; do { clear_name_vars() ; docnum = mg_get_doc_num(qd) ; mg_setup_doc_line_producer(qd, docnum, &lp) ; while (mg_dlp_more_lines(lp)) { if (!strncmp(s, "qqgrp", 5)) strcpy(group_out, s+5) ; else if (!strncmp(s, "qqsbc", 5)) strcpy(subclass_out, s+5) ; else if (!strncmp(s, "qqord", 5)) strcpy(order_out, s+5) ; else if (!strncmp(s, "qqfam", 5)) strcpy(family_out, s+5) ; else if (!strncmp(s, "qqgen", 5)) strcpy(genus_out, s+5) ; else if (!strncmp(s, "qqhyb", 5)) hybrid = (!strncmp(s+5, "yes", 3) ? 1 : 0) ; else if (!strncmp(s, "qqspr", 5)) strcpy(species_out, s+5) ; else if (!strncmp(s, "qqtrs", 5)) strcpy(trirank_out, s+5) ; else if (!strncmp(s, "qqtrr", 5)) strcpy(tri_out, s+5) ; else if (!strncmp(s, "qqqus", 5)) strcpy(quadrank_out, s+5) ; else if (!strncmp(s, "qqqur", 5)) strcpy(quad_out, s+5) ; mg_dlp_next_line(lp, s) ; } switch (group_out[0]) { case 'P': group_p = insert_taxon_item(&root, "1Pteridophytes", NULL, 1) ; break ; case 'G': group_p = insert_taxon_item(&root, "2Gymnosperms", NULL, 1) ; break ; case 'M': group_p = insert_taxon_item(&root, "3Monocots", NULL, 1) ; break ; case 'D': group_p = insert_taxon_item(&root, "4Dicots", NULL, 1) ; break ; } subc_p = insert_taxon_child(group_p, subclass_out, NULL, 1) ; ord_p = insert_taxon_child(subc_p, order_out, NULL, 1) ; fam_p = insert_taxon_child(ord_p, family_out, NULL, 1) ; gen_p = insert_taxon_child(fam_p, genus_out, NULL, 1) ; spec_p = insert_taxon_child(gen_p, species_out, new_int(hybrid), 1) ; if (nonempty(tri_out)) { tri_p = insert_taxon_child(spec_p, tri_out, new_int(!strcmp(trirank_out, "var") ? 1 : 0), 1) ; if (nonempty(quad_out)) { quad_p = insert_taxon_child(tri_p, quad_out, new_int(!strcmp(quadrank_out, "var") ? 1 : 0), 1) ; } } } while (mg_goto_next_doc(qd)) ; } /* generate HTML page */ /* HTTP header */ return_header("text/html") ; build_name(name_html, request_level, 0) ; name_plain = strip_tags(name_html) ; puts("<html>") ; puts("<head>") ; printf("<title>BONAP Distribution Data: ") ; if (request_level == SPECIES || request_level == TRI) printf("subspecies/varieties ") ; else printf("taxa ") ; printf("of %s", name_plain) ; if (nonempty(loc_in)) printf(" in %s", map_convert_region_name(MAP_DIR, MAP_NAME, "abbr", "name", loc_in)) ; else puts(" in the US") ; puts("</title>") ; puts("</head>") ; puts("<body bgcolor=\"#ffffff\">") ; if (is_ext) ext_header() ; printf("<h1>") ; if (request_level == SPECIES || request_level == TRI) printf("Subspecies/varieties ") ; else printf("Taxa ") ; printf("of %s", name_html) ; if (nonempty(loc_in)) printf(" in %s", map_convert_region_name(MAP_DIR, MAP_NAME, "abbr", "name", loc_in)) ; else puts(" in the US") ; printf("</h1>") ; if (request_level > GROUP) { if (request_level <= GENUS) name_html[0] = toupper(name_html[0]) ; printf("%s is a member of the %s group", name_html, (root->name)+1) ; if (request_level > SUBCLASS) if (strcmp(root->nextlevel->name, "none")) printf(", subclass %s", root->nextlevel->name) ; if (request_level > ORDER) if (strcmp(root->nextlevel->nextlevel->name, "none")) printf(", order %s", root->nextlevel->nextlevel->name) ; if (request_level > FAMILY) printf(", family %s", root->nextlevel->nextlevel->nextlevel->name) ; /* Don't really need to mention genus because it's obvious from the species name */ /* if (request_level > GENUS) printf(", genus <i>%s</i>", root->nextlevel->nextlevel->nextlevel->nextlevel->name) ; */ puts(".<p>") ; } if (request_level <= ALL) puts("<ul>") ; group_p = root ; while (group_p != NULL) { if (request_level <= ALL) printf("%s<br>\n", (group_p->name)+1) ; subc_p = group_p->nextlevel ; has_subclasses = (strcmp(subc_p->name, "none") != 0) ; if (request_level <= GROUP) if (has_subclasses) puts("<ul>") ; while (subc_p != NULL) { strcpy(subclass_out, subc_p->name) ; if (request_level <= GROUP && has_subclasses) { build_name(name_html, SUBCLASS, 1) ; printf("<b>%s</b>", name_html) ; puts("<br>") ; } ord_p = subc_p->nextlevel ; has_orders = (strcmp(ord_p->name, "none") != 0) ; if (request_level <= SUBCLASS) if (has_orders) puts("<ul>") ; while (ord_p != NULL) { strcpy(order_out, ord_p->name) ; if (request_level <= SUBCLASS && has_orders) { build_name(name_html, ORDER, 1) ; printf("<b>%s</b><br>\n", name_html) ; } fam_p = ord_p->nextlevel ; if (request_level <= ORDER) puts("<ul>") ; while (fam_p != NULL) { strcpy(family_out, fam_p->name) ; if (request_level <= ORDER) { build_name(name_html, FAMILY, 1) ; printf("<b>%s</b><br>\n", name_html) ; } gen_p = fam_p->nextlevel ; if (request_level <= FAMILY) puts("<ul>") ; while (gen_p != NULL) { strcpy(genus_out, gen_p->name) ; if (request_level <= FAMILY) { build_name(name_html, GENUS, 1) ; printf("<b>%s</b> ", name_html) ; printf("<a href=\"%s?colldir=%s&collname=%s&" "query=%s\">(checklist entries)</a>", RULED_HTML_QUERY_URL, CHECKLIST_COLL_DIR, CHECKLIST_COLL_NAME, gen_p->name) ; printf(" <a href=\"%s?genus=%s\">(map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out) ; puts("<br>") ; } spec_p = gen_p->nextlevel ; if (request_level <= GENUS) puts("<ul>") ; while (spec_p != NULL) { strcpy(species_out, spec_p->name) ; hybrid = *((int *)(spec_p->other_data)) ; if (request_level <= GENUS) { build_name(name_html, SPECIES, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?colldir=%s&collname=%s&" "query=%s%%26%s\">(checklist entry)</a>", RULED_HTML_QUERY_URL, CHECKLIST_COLL_DIR, CHECKLIST_COLL_NAME, gen_p->name, spec_p->name) ; printf(" <a href=\"%s?genus=%s&species=%s\">(species " "map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out) ; if (spec_p->nextlevel != NULL) printf(" <a href=\"%s?genus=%s&species=%s&show_infras=yes\">" "(infras map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out) ; printf("<br>\n") ; } if (spec_p->nextlevel != NULL) puts("<ul>") ; tri_p = spec_p->nextlevel ; while (tri_p != NULL) { strcpy(tri_out, tri_p->name) ; strcpy(trirank_out, *((int *)(tri_p->other_data)) ? "var" : "ssp") ; build_name(name_html, TRI, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?genus=%s&species=%s&tri=%s\">" "(infra map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out) ; if (tri_p->nextlevel != NULL) printf(" <a href=\"%s?genus=%s&species=%s&tri=%s" "&show_infras=yes\">(subinfras map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out) ; puts("<br>") ; if (tri_p->nextlevel != NULL) puts("<ul>") ; quad_p = tri_p->nextlevel ; while (quad_p != NULL) { strcpy(quad_out, quad_p->name) ; strcpy(quadrank_out, *((int *)(quad_p->other_data)) ? "var" : "ssp") ; build_name(name_html, QUAD, 1) ; printf("<b>%s</b>", name_html) ; printf(" <a href=\"%s?genus=%s&species=%s&tri=%s&quad=%s\">" "(subinfra map)</a>", is_ext ? B98_MAP_EXT_URL : B98_MAP_URL, genus_out, species_out, tri_out, quad_out) ; puts("<br>") ; step_taxon(quad_p) ; } if (tri_p->nextlevel != NULL) puts("</ul>") ; step_taxon(tri_p) ; } if (spec_p->nextlevel != NULL) puts("</ul>") ; step_taxon(spec_p) ; } if (request_level <= GENUS) puts("</ul>") ; step_taxon(gen_p) ; } if (request_level <= FAMILY) puts("</ul>") ; step_taxon(fam_p) ; } if (request_level <= ORDER) puts("</ul>") ; step_taxon(ord_p) ; } if (request_level <= SUBCLASS) if (has_orders) puts("</ul>") ; step_taxon(subc_p) ; } if (request_level <= GROUP) if (has_subclasses) puts("</ul>") ; step_taxon(group_p) ; } if (request_level <= ALL) puts("</ul>") ; puts("</body>" "</html>") ; }
main() { void *qd, *map_info ; char *all_in ; char *fam_in ; char *gen_in ; char *spec_in ; char *mode_in ; char *mode_str ; char *herb_in, *coll_in, *loc_in, *cult_in ; char query_str[1024] ; char fam_name_html[80] ; char genus_name_html[80] ; char spec_name_html[80] ; int i ; int num_hits ; int request_level ; int item_num ; int first ; char header_string[1024] ; char *title_string ; int redblue_colorsteps[] = {162, 54, 0, 0, 0} ; int green_colorsteps[] = {255, 255, 217, 140, 86} ; return_header("text/html") ; printf("<script>") ; printf("if (top.display_mode.substring(top.display_mode.length-4,top.display_mode.length) == 'icty')") ; printf("top.change_mode(top.display_mode);") ; printf("</script>") ; decode_query_string(9, "all", &all_in, "fam", &fam_in, "gen", &gen_in, "spec", &spec_in, "mode", &mode_in, "herb", &herb_in, "coll", &coll_in, "cult", &cult_in, "loc", &loc_in) ; if (nonempty(mode_in) && !strcmp(mode_in, "taxa")) mode_str = "qqtax" ; else mode_str = "qqspc" ; if (nonempty(all_in)) request_level = 0 ; else if (nonempty(fam_in)) { if (nonempty(gen_in)) { if (nonempty(spec_in)) { char *s ; while ((s = strchr(spec_in, '-')) != NULL) strcpy(s, s+1) ; request_level = 3 ; } else request_level = 2 ; } else request_level = 1 ; } if (nonempty(mode_str)) sprintf(query_str, "%s&", mode_str) ; else sprintf(query_str, "") ; switch(request_level) { case 3: sprintf(query_str+strlen(query_str), "qqfam%s&qqgen%s&qqspe%s&", fam_in, gen_in, spec_in) ; break ; case 2: sprintf(query_str+strlen(query_str), "qqfam%s&qqgen%s&", fam_in, gen_in) ; break ; case 1: sprintf(query_str+strlen(query_str), "qqfam%s&", fam_in) ; break ; case 0: /* don't need to do anything */ break ; } if (nonempty(cult_in)) sprintf(query_str+strlen(query_str), "qqcul%s&", cult_in) ; if (nonempty(loc_in)) { char *t ; sprintf(query_str+strlen(query_str), "(") ; t = loc_in ; while (*t != '\0') { sprintf(query_str+strlen(query_str), "qqloc%c%c%c", t[0],t[1],t[2]) ; t+=3 ; if (*t != '\0') sprintf(query_str+strlen(query_str), "|") ; } sprintf(query_str+strlen(query_str), ")&") ; } if (nonempty(herb_in)) { char *temp, *tok ; temp = strdup(herb_in) ; tok = strtok(temp, " ") ; sprintf(query_str+strlen(query_str), "(") ; do { sprintf(query_str+strlen(query_str), "qqhrb%s", tok) ; tok = strtok(NULL, " ") ; if (tok != NULL) sprintf(query_str+strlen(query_str), "|") ; } while (tok != NULL) ; sprintf(query_str+strlen(query_str), ")&") ; free(temp) ; } *strrchr(query_str, '&') = '\0' ; mg_bool_query(query_str, HSB_DATA_PATH, "tracyspecs_map", &qd) ; num_hits = mg_get_num_returned(qd) ; if (num_hits == 0) { printf("<h1>No specimens match criteria</h1>") ; printf("Sorry! The database does not contain any items ") ; printf("meeting the criteria you have selected.\n") ; } else { map_info = map_initialize(HSB_MAP_PATH, "tx", GRADED_VALUE); map_assign_graded_colors(map_info, 5, redblue_colorsteps, green_colorsteps, redblue_colorsteps) ; if (nonempty(loc_in)) { char loc[4], *t ; map_disable_all_regions(map_info) ; t = loc_in ; while (*t != '\0') { strncpy(loc, t, 3) ; loc[3] = '\0' ; map_enable_region_by_name(map_info, "ut_abbr", loc) ; t += 3 ; } } first = 1 ; do { item_num = mg_get_doc_num(qd) ; if (request_level > 0 && first) { /* grab one of the returned items to get all the names */ void *line_producer = NULL; mg_setup_doc_line_producer(qd, item_num, &line_producer) ; while (mg_dlp_more_lines(line_producer)) { char s[256] ; mg_dlp_next_line(line_producer, s) ; if (s[0] != '\0') { if (!strncmp(s, "qqfah", 5)) { strcpy(fam_name_html, s+6) ; } else if (!strncmp(s, "qqgeh", 5)) { strcpy(genus_name_html, s+6) ; } else if (!strncmp(s, "qqsph", 5)) { strcpy(spec_name_html, s+6) ; } } } first = 0 ; } add_to_county_bins(map_info, item_num) ; } while (mg_goto_next_doc(qd)) ; printf("<body bgcolor=\"#ffffff\">") ; printf("<h1>") ; if (!strcmp(mode_str, "qqtax")) printf("Species") ; else printf("Specimen") ; printf(" Distribution Map</h1>\n") ; printf("<b>Selection criteria:</b>:<br>") ; if (nonempty(cult_in)) printf("Mapping only items taken from %s material <br>\n", !strcmp(cult_in, "yes") ? "cultivated" : "non-cultivated") ; printf("Herbaria: <b>") ; if (nonempty(herb_in)) { printf("%s", herb_in) ; } else printf("all") ; printf("</b><br>\n") ; printf("Items: <b>") ; switch (request_level) { case 0: printf("all") ; break ; case 1: printf("family %s", fam_name_html) ; break ; case 2: printf("genus %s", genus_name_html) ; break ; case 3: printf("species %s", spec_name_html) ; break ; } printf("</b><p>\n") ; printf("<font size=+1>") ; printf("<b>Color Key (number of %s county) :<br>\n", !strcmp(mode_str, "qqtax") ? "species in" : "specimens from") ; map_output_graded_color_key(map_info) ; printf("</b>\n") ; printf("<form method=get action=\"%s/specsfrommap.html\">", HSB_MAIN_URL) ; map_output_form_elem(map_info, NULL, NULL, NULL) ; printf("</form>\n") ; printf("</font>") ; } }
main() { char *fam_in, *gen_in, *spec_in, *nkcode_in, *tkcode_in, *x_in, *y_in ; char *ncode_in, *tcode_in, *gcode_in, *fcode_in, *ntype_in ; char *all_in, *tri_in, *quad_in, *cutoff_in ; int need_name ; char name_html[128] ; int i, cutoff_level ; void *qd ; int num_hits ; char *loc_in=NULL, *county_in=NULL ; int request_level ; char qstr[256] ; if (!mg_db_available("/bwg/FLORA/tracy/mgdata","tracyspecs")) { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The database of specimens used to generate lists, which is ") ; puts("required to process ") ; puts("your query, is currently being rebuilt. Please try again ") ; puts("in a little while.") ; exit(0) ; } decode_query_string(14, "ncode", &ncode_in, /* bonap name code */ "tcode", &tcode_in, /* bonap taxon code */ "gcode", &gcode_in, /* ncode of genus */ "fcode", &fcode_in, /* ncode of family */ "ntype", &ntype_in, /* native/bonap_n/bonap_t */ "all", &all_in, "fam", &fam_in, "gen", &gen_in, "spec", &spec_in, "infra", &tri_in, "infra2", &quad_in, "cutoff", &cutoff_in, /* clip level of map */ "x", &x_in, "y", &y_in) ; if (nonempty(x_in)) { loc_in = map_convert_xy_to_name(atoi(x_in), atoi(y_in), "/herbaria/FLORA/cgi/maps","tx", "ut_abbr") ; if (loc_in == NULL) { return_nothing() ; exit() ; } county_in = map_convert_xy_to_name(atoi(x_in), atoi(y_in), "/herbaria/FLORA/cgi/maps","tx", "cname") ; } need_name = 0 ; if (nonempty(ncode_in) || nonempty(tcode_in) || nonempty(gcode_in) || nonempty(fcode_in)) { char *code, *prefix ; if (nonempty(ncode_in)) { code = ncode_in ; prefix = "qqbnn" ; } else if (nonempty(tcode_in)) { code = tcode_in ; prefix = "qqbtn" ; } else if (nonempty(gcode_in)){ code = gcode_in ; prefix = "qqgco" ; } else if (nonempty(fcode_in)) { code = fcode_in ; prefix = "qqfco" ; } get_bonap_info_by_code(code, name_html, &request_level) ; strcpy(qstr, prefix) ; for (i=0 ; code[i] != '\0' ; i++) sprintf(qstr+strlen(qstr), "%c", code[i]+'A'-'0') ; } else /* no bonap code, doing it by name */ { /* determine request level */ if (nonempty(all_in)) { request_level = 0 ; sprintf(qstr, "qqspc") ; } else if (nonempty(fam_in)) { request_level = 1 ; sprintf(qstr, "qqfam%s", fam_in) ; } else if (nonempty(gen_in)) { if (nonempty(spec_in)) { if (nonempty(tri_in)) { if (nonempty(quad_in)) { request_level = 5 ; sprintf(qstr, "qqgen%s&qqspe%s&qqtri%s&qqqua%s", fam_in, gen_in, tri_in, quad_in) ; } else { request_level = 4 ; sprintf(qstr, "qqgen%s&qqspe%s&qqtri%s", fam_in, gen_in, tri_in) ; } } else { request_level = 3 ; sprintf(qstr, "qqgen%s&qqspe%s", gen_in, spec_in) ; } } else { request_level = 2 ; sprintf(qstr, "qqgen%s", gen_in) ; } } else { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The URL you requested is malformed. When querying by name,") ; puts("you must provide one of the following:") ; puts("<ul>") ; puts("<li>A request for all specimens") ; puts("<li>A family") ; puts("<li>A genus") ; puts("<li>A genus and species") ; puts("<li>A genus, species, and tri-level infra") ; puts("<li>A genus, species, tri- and quad-level infras") ; puts("</ul>") ; puts("Please check the URL structure and try again.") ; exit(1) ; } if (request_level > 0) { if (nonempty(ntype_in) && strcmp(ntype_in, "native")) { char ncode[10], tcode[10], *prefix, *code ; get_bonap_info_by_qstr(qstr, name_html, ncode, tcode) ; prefix = !strcmp(ntype_in, "bonap_n") ? "qqbnn" : "qqbtn" ; code = !strcmp(ntype_in, "bonap_n") ? ncode : tcode ; switch(request_level) { case 1: sprintf(qstr, "qqfco%s", tcode) ; break ; case 2: sprintf(qstr, "qqgco%s", tcode) ; break ; case 3: sprintf(qstr, "(%s%s|qqsco%s", prefix, code, tcode) ; break ; case 4: sprintf(qstr, "(%s%s|qqtco%s", prefix, code, tcode) ; break ; case 5: sprintf(qstr, "%s%s", prefix, code) ; break ; } } else need_name = 1 ; } } /* after all this drill "name_html" should contain the html form of the thing being queried for or need_name != 0 */ if (nonempty(cutoff_in)) { if (!strcmp(cutoff_in, "fam") && request_level <= 1) { cutoff_level = 1 ; sprintf(qstr+strlen(qstr), "&qqfrp") ; } else if (!strcmp(cutoff_in, "gen") && request_level <= 2) { cutoff_level = 2 ; sprintf(qstr+strlen(qstr), "&qqgrp") ; } else if (!strcmp(cutoff_in, "spec") && request_level <= 3) { sprintf(qstr+strlen(qstr), "&qqtax") ; cutoff_level = 3 ; } else { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The URL you requested is malformed. When supplying a cutoff,") ; puts("the cutoff must be at a taxonomic level less than or equal to ") ; puts("the level of the query (for example, you cannot have a cutoff ") ; puts("of \"family\" when listing a genus). Please check the URL ") ; puts("and try again.") ; exit(1) ; } } else cutoff_level = 0 ; if (nonempty(loc_in)) sprintf(qstr+strlen(qstr), "&qqloc%s", loc_in) ; mg_bool_query(qstr,"/bwg/FLORA/tracy/mgdata", "tracyspecs", &qd) ; num_hits = mg_get_num_returned(qd) ; if (num_hits == 0) { if (nonempty(loc_in)) return_nothing() ; else { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("There are no items in the database which corresponded to your ") ; puts("query.") ; } } else { void *dlp=NULL ; char s[256] ; char stored_fam[80], stored_gen[80], stored_spec[80] ; char stored_tri[80], stored_quad[80] ; int new_fam, new_gen, new_spec ; int printing_genera, printing_species, printing_specimens ; if (need_name) { void *lp=NULL ; char tri_html[80], quad_html[80] ; mg_setup_doc_line_producer(qd, mg_get_doc_num(qd), &lp) ; while (mg_dlp_more_lines(lp)) { char s[256] ; mg_dlp_next_line(lp, s) ; if (request_level == 1) { if (!strncmp(s, "qqfah ", 6)) strcpy(name_html, s+6) ; } else if (request_level == 2) { if (!strncmp(s, "qqgeh ", 6)) strcpy(name_html, s+6) ; } else { if (!strncmp(s, "qqsph ", 6)) strcpy(name_html, s+6) ; else if (!strncmp(s, "qqiah ", 6)) strcpy(tri_html, s+6) ; else if (!strncmp(s, "qqibh ", 6)) strcpy(quad_html, s+6) ; } } if (request_level >= 4) sprintf(name_html+strlen(name_html), " %s", tri_html) ; if (request_level == 5) sprintf(name_html+strlen(name_html), " %s", quad_html) ; } if (cutoff_level != 0) { printing_specimens = 0 ; stored_fam[0] = stored_gen[0] = stored_spec[0] = '\0' ; printing_genera = (cutoff_level >= 2) ; printing_species = (cutoff_level == 3) ; } else { printing_specimens = 1 ; printing_genera=printing_species = 0 ; } /* header stuff */ return_header("text/html") ; printf("<body bgcolor=\"#ffffff\">\n") ; puts("<title>Flora of Texas Consortium - Texas Plant") ; puts("Distributions</title>") ; puts("<h1>Flora of Texas Consortium - Texas Plant Distributions</h1>") ; puts("<b>Currently listing: ") ; switch (request_level) { case 0: switch (cutoff_level) { case 0: puts("all specimens") ; break ; case 1: puts("all families") ; break ; case 2: puts("all genera") ; break ; case 3: puts("all species") ; break ; } break ; case 1: switch (cutoff_level) { case 0: puts("specimens of family") ; break ; case 2: puts("genera of family") ; break ; case 3: puts("species of family") ; break ; } break ; case 2: switch(cutoff_level) { case 0: puts("specimens of genus") ; break ; case 3: puts("species of genus") ; break ; } break ; default: puts("specimens of ") ; break ; } if (request_level > 0) puts(name_html) ; if (nonempty(county_in)) printf(" from %s County", county_in) ; puts("</b><p>") ; if (nonempty(ntype_in) && !strcmp(ntype_in, "bonap_t")) { puts("Items whose names are defined as synonymous to ") ; puts("the name requested are included in this list.<p>") ; } if (printing_genera) puts("<ul>") ; if (printing_species) puts("<ul>") ; do { char auth_name[80], herb_abbr[5], acc_num[16] ; char coll_name[80] ; char spec_loc[4] ; int cultivated ; auth_name[0] = '\0' ; coll_name[0] = '\0' ; stored_tri[0] = stored_quad[0] = '\0' ; mg_setup_doc_line_producer(qd, mg_get_doc_num(qd), &dlp) ; while (mg_dlp_more_lines(dlp)) { mg_dlp_next_line(dlp, s) ; if (!strncmp(s, "qqfah", 5)) { if (strcmp(s+6, stored_fam)) { new_fam=1 ; strcpy(stored_fam, s+6) ; } else new_fam = 0 ; } if (!strncmp(s, "qqgeh", 5)) { if (strcmp(s+6, stored_gen)) { new_gen=1 ; strcpy(stored_gen, s+6) ; } else new_gen = 0 ; } if (!strncmp(s, "qqsph", 5)) { if (strcmp(s+6, stored_spec)) { new_spec=1 ; strcpy(stored_spec, s+6) ; } else new_spec = 0 ; } if (!strncmp(s, "qqiah", 5)) strcpy(stored_tri, s+6) ; if (!strncmp(s, "qqibh", 5)) strcpy(stored_quad, s+6) ; if (printing_specimens) { if (!strncmp(s, "qqaut", 5)) strcpy(auth_name, s+6) ; else if (!strncmp(s, "qqhrb", 5)) strcpy(herb_abbr, s+5) ; else if (!strncmp(s, "qqacc", 5)) { strcpy(acc_num, s+5) ; for (i=0 ; acc_num[i] != '\0' ; i++) acc_num[i] += '0'-'A' ; } else if (!strncmp(s, "qqcnm", 5)) strcpy(coll_name, s+6) ; else if (!strncmp(s, "qqcul", 5)) cultivated = !strncmp(s+5, "yes", 3) ; else if (!nonempty(loc_in) && !strncmp(s, "qqloc", 5)) strcpy(spec_loc, s+5) ; } } if (printing_specimens) { printf("%s %s ", herb_abbr, acc_num, auth_name) ; if (nonempty(auth_name)) printf(" %s", auth_name) ; else { fputs(stored_spec, stdout) ; if (nonempty(stored_tri)) printf(" %s", stored_tri) ; if (nonempty(stored_quad)) printf(" %s", stored_quad) ; } printf(", collected by %s", coll_name) ; if (cultivated) printf(" from cultivated material") ; if (!nonempty(loc_in)) printf(", %s county ", map_convert_region_name("/bwg/FLORA/cgi/maps", "tx", "ut_abbr", "cname", spec_loc)) ; puts("<br>") ; } else { if (new_fam) { if (printing_specimens) puts("</ul>") ; if (printing_species) puts("</ul>") ; if (printing_genera) puts("</ul>") ; printf("Family %s<br>", stored_fam) ; } if (printing_genera && new_gen) { if (new_fam) puts("<ul>") ; else { if (printing_specimens) puts("</ul>") ; if (printing_species) puts("</ul>") ; } printf("Genus %s", stored_gen) ; puts("<br>") ; } if (printing_species && new_spec) { if (new_gen) printf("<ul>") ; else { if (printing_specimens) puts("</ul>") ; } printf("%s<br>", stored_spec) ; } } } while (mg_goto_next_doc(qd)) ; if (printing_specimens) puts("</ul>") ; if (printing_species) puts("</ul>") ; if (printing_genera) puts("</ul>") ; /* footer stuff */ puts("<hr>") ; puts("This page was constructed by a program written by ") ; puts("<a href=\"mailto:[email protected]\">") ; puts("Erich Schneider</a> of the ") ; puts("<a href=\"http://www.csdl.tamu.edu\">") ; puts("Center for the Study of Digital Libraries</a> ") ; puts("working for the ") ; puts("<a href=\"http://www.csdl.tamu.edu/FLORA/tamuherb.htm\">") ; puts("Texas A&M Bioinformatics Working Group</a>.") ; } }
main() { char *mode ; // char date[100]; int i ; char new_mode[20] ; char *final_mode ; // FILE* datein; // datein = fopen("updated","r"); // fgets(date,99,datein); // fclose(datein); decode_query_string(1,"mode", &mode) ; return_header("text/html") ; final_mode = mode + strlen(mode)-4 ; printf("<b><a target=_top href=\"http://www.texasflora.org\">Digital Flora of Texas</a> Herbarium Specimen Browser-"); if (!strcmp(final_mode, "main")) printf("Main Display") ; else if (!strcmp(final_mode, "mcty")) printf("Visual County Filter") ; else if (!strcmp(final_mode, "sfor")) printf("Get by Accession Number") ; else if (!strcmp(final_mode, "sing")) printf("Single Item Display") ; else if (!strcmp(final_mode, "slst")) printf("Specimen List") ; else if (!strcmp(final_mode, "imap")) printf("Item Map") ; else if (!strcmp(final_mode, "icty")) printf("Single County Specimen List") ; printf(" mode<br>"); // printf(" mode <br>Last updated: %s</b><br>",date) ; printf("<form>") ; printf("<input type=button value=\"Help\" onClick=\"top.popup_help();\">") ; printf("<input type=button value=\"Restart\" onClick=\"top.restart();\">") ; printf("<input type=button value=\"DataFiles\" onClick=\"top.popup_herbariadata();\">"); printf("<input type=button value=\"stats\" onClick=\"top.popup_stats();\">"); printf("<input type=button value=\"Contributors\" onClick=\"top.popup_cons();\">"); /* printf("<input type=button value=\"Settings\" onClick=\"top.display_settings();\">") ; */ if (strlen(mode) > 4) printf(" <b>Back to: </b>") ; i = 0 ; while (i+4 < strlen(mode)) { strncpy(new_mode, mode, i+4) ; new_mode[i+4] = '\0' ; if (!strncmp(mode+i, "main", 4)) button("Main Display", new_mode) ; else if (!strncmp(mode+i, "sfor", 4)) button("Get by Acc. Num.", new_mode) ; else if (!strncmp(mode+i, "imap", 4)) button("Item map", new_mode) ; else if (!strncmp(mode+i, "slst", 4)) button("Specimen List", new_mode) ; else if (!strncmp(mode+i, "icty", 4)) button("Specimens in County", new_mode) ; i += 4 ; } if (!strcmp(final_mode, "main") || !strcmp(final_mode, "slst") || !strcmp(final_mode, "imap")) printf(" <b>Also available: </b>") ; if (!strcmp(final_mode, "main")) { button("Get by Acc. Num.", "mainsfor") ; button("Visual County Filter", "mainmcty") ; } else if (!strcmp(final_mode, "slst")) { button("Item Map", "mainimap") ; button("Visual County Filter", "mainslstmcty") ; } else if (!strcmp(final_mode, "imap")) { button("Specimen List", "mainslst") ; button("Visual County Filter", "mainimapmcty") ; } printf("</form>") ; }
main() { char *set_id, *sets_list ; decode_query_string(2, "set_id", &set_id, "sets_list", &sets_list) ; return_header("text/html") ; printf("<title>Voting system: post a new issue (%s)</title>", set_id_to_name(sets_list, set_id)) ; printf("<h1>Voting system: post a new issue (%s)</h1>", set_id_to_name(sets_list, set_id)) ; printf("For more detailed explanations of the various form items ") ; printf("on this page, follow the help links near the items. <p>") ; printf("<form method=post action=\"/FLORA/cgi/voting_post\">") ; printf("<input type=hidden name=\"sets_list\" value=\"%s\">", sets_list) ; printf("<input type=hidden name=\"set_id\" value=\"%s\">", set_id) ; printf("Your voting username: <input type=text name=\"name\"> ") ; printf("Your password: <input type=password name=\"password\">") ; printf("<A HREF=\"/FLORA/voting/voting_user_password_help.html\">(help)</A> <BR>") ; printf("Do you want your name listed as the proposer of this issue?") ; printf("<select size=1 name=\"anon_post\">") ; printf("<option value=0>Yes") ; printf("<option value=1>No") ; printf("</select> ") ; printf("<A HREF=\"/FLORA/voting/voting_options_help.html\">(help)</A> <BR>") ; printf("Ballot type:") ; printf("<select size=1 name=\"secret_ballot\">") ; printf("<option value=1>Secret ballot") ; printf("<option value=0>Accountable ballot") ; printf("</select>") ; printf("<A HREF=\"/FLORA/voting/voting_options_help.html\">(help)</A> <BR>") ; printf("Should partial vote counts be visible before the end of the voting period?") ; printf("<select size=1 name=\"constant_update\">") ; printf("<option value=0>No") ; printf("<option value=1>Yes") ; printf("</select>") ; printf("<A HREF=\"/FLORA/voting/voting_options_help.html\">(help)</A> <BR>") ; printf("Should people be able to change their votes during the voting period?") ; printf("<select size=1 name=\"can_change_vote\">") ; printf("<option value=0>No") ; printf("<option value=1>Yes") ; printf("</select>") ; printf("<A HREF=\"/FLORA/voting/voting_options_help.html\">(help)</A> <BR>") ; printf("One-line description: <A HREF=\"/FLORA/voting/voting_shortdesc_help.html\">(help)</A> <BR>") ; printf("<input type=text name=\"shortdesc\" size=80> <BR>") ; printf("Full description: <A HREF=\"/FLORA/voting/voting_longdesc_help.html\">(help)</A> <BR>") ; printf("<textarea name=\"longdesc\" rows=4 cols=80>") ; printf("</textarea> <BR>") ; printf("Choices (one per line): <A HREF=\"/FLORA/voting/voting_choices_help.html\">(help)</A> <BR>") ; printf("<textarea name=\"choices\" rows=4 cols=80>") ; printf("</textarea> <BR>") ; printf("How many choices can be selected? ") ; printf("<input type=text size=4 name=multiple_choice value=\"1\"> ") ; printf("<A HREF=\"/FLORA/voting/voting_num_choices_help.html\">(help)</A><BR>") ; printf("Vote counting date (votes must be cast before this day) - ") ; printf("month: <select size=1 name=\"countmo\">") ; printf("<option value=0>January") ; printf("<option value=1>February") ; printf("<option value=2>March") ; printf("<option value=3>April") ; printf("<option value=4>May") ; printf("<option value=5>June") ; printf("<option value=6>July") ; printf("<option value=7>August") ; printf("<option value=8>September") ; printf("<option value=9>October") ; printf("<option value=10>November") ; printf("<option value=11>December") ; printf("</select>") ; printf("day: <input type=text name=\"countday\" size=3> ") ; printf("year: <input type=text size=5 name=\"countyr\" value=\"1996\"> ") ; printf("<A HREF=\"/FLORA/voting/voting_date_help.html\">(help)</A> <BR>") ; printf("<input type=submit value=\"Post issue to voting system\">") ; printf("<input type=reset value=\"Clear form\">") ; printf("</form>") ; }
main() { char *name, *password, *short_desc, *long_desc ; char *choices, *day_str, *month_str, *year_str ; char *anon_post_str, *secret_ballot_str, *constant_update_str ; char *can_change_vote_str, *multiple_choice_str ; decode_query_string(15, "set_id", &set_id, "sets_list", &sets_list, "name", &name, "password", &password, "shortdesc", &short_desc, "longdesc", &long_desc, "choices", &choices, "countday", &day_str, "countmo", &month_str, "countyr", &year_str, "anon_post", &anon_post_str, "secret_ballot", &secret_ballot_str, "constant_update", &constant_update_str, "can_change_vote", &can_change_vote_str, "multiple_choice", &multiple_choice_str) ; strip_trailing_spaces(name) ; strip_trailing_spaces(short_desc) ; strip_trailing_spaces(long_desc) ; strip_trailing_spaces(choices) ; if (!nonempty(name) || !nonempty(password) || !nonempty(short_desc) || !nonempty(long_desc) || !nonempty(choices) || !nonempty(day_str) || !nonempty(month_str) || !nonempty(year_str)) { return_nothing() ; } else { return_header("text/html") ; if (!verify_password(set_id, name, password)) { printf("<title>Sorry! Invalid user name/password pair</title>\n") ; printf("<h1>Sorry! Invalid user name/password pair</h1>\n") ; printf("The password you entered did not match the user name ") ; printf("you entered.\n") ; } else if (!date_ok(day_str, month_str, year_str)) { printf("<title>Sorry! Invalid date</title>\n") ; printf("<h1>Sorry! Invalid date</h1>\n") ; printf("The date you entered made no sense (for example, ") ; printf("you entered a day number that was invalid for the ") ; printf("month you chose) or was not a future date.\n") ; } else { char id_str[64], fname[FILENAME_MAX] ; struct tm count_time ; long count_time_val ; int num_choices, i ; char *new_choices ; FILE *fp ; if (!strcmp(anon_post_str, "0")) sprintf(id_str, "%s.%d", name, (long)time(NULL)) ; else sprintf(id_str, "anonymous.%d", (long)time(NULL)) ; count_time.tm_sec = 1 ; count_time.tm_min = 0 ; count_time.tm_hour = 0 ; count_time.tm_mday = atoi(day_str) ; count_time.tm_mon = atoi(month_str) ; count_time.tm_year = atoi(year_str)-1900 ; count_time.tm_isdst = -1 ; count_time_val = (long)mktime(&count_time) ; /* remove "blank" choice lines */ { char *s, *t ; new_choices = (char *)malloc(sizeof(char) * (strlen(choices)+1)) ; s = choices ; t = new_choices ; while (*s != '\0') { while (isspace(*s)) s++ ; while (*s != '\n' && *s != '\0') { *t = *s ; t++ ; s++ ; } *t = *s ; if (*s != '\0') { s++ ; t++ ; } } if (new_choices[(int)strlen(new_choices)-1] == '\n') new_choices[(int)strlen(new_choices)-1] = '\0' ; } for (i=0, num_choices=1 ; i < (int)strlen(new_choices) ; i++) if (new_choices[i] == '\n') num_choices++ ; sprintf(fname, "%s/%s.issues", file_prefix, set_id) ; fp = fopen(fname, "a") ; lock_file(fp) ; fprintf(fp, "%s\n%d\n%d\n", id_str, count_time_val, num_choices) ; fprintf(fp, "%s\n", multiple_choice_str) ; fprintf(fp, "%d\n", atoi(secret_ballot_str) << 3 | atoi(anon_post_str) << 2 | atoi(can_change_vote_str) << 1 | atoi(constant_update_str) << 0) ; fprintf(fp, "%s\n", short_desc) ; fclose(fp) ; sprintf(fname, "%s/%s.descriptions", file_prefix, set_id) ; fp = fopen(fname, "a") ; lock_file(fp) ; fprintf(fp, "BEGIN %s\n", id_str) ; fprintf(fp, "%s\n", long_desc) ; fprintf(fp, "END %s\n", id_str) ; fclose(fp) ; sprintf(fname, "%s/%s.choices", file_prefix, set_id) ; fp = fopen(fname, "a") ; lock_file(fp) ; fprintf(fp, "BEGIN %s\n", id_str) ; fprintf(fp, "%s\n", new_choices) ; fprintf(fp, "END %s\n", id_str) ; fclose(fp) ; printf("<title>Issue added</title>\n") ; printf("<h1>Issue added</h1>\n") ; printf("Your new issue has been added to the voting system. ") ; printf("You may now go to: <ul>") ; printf("<li>The overall ") ; printf("<a href=\"/FLORA/cgi/voting_list?sets_list=%s&set_id=%s\">issue list</a>", sets_list, set_id) ; printf("<li>The new issue's ") ; printf("<a href=\"/FLORA/cgi/voting_issue?set_id=%s&issue_id=%s\">issue page</a>", set_id, id_str) ; printf("</ul>") ; printf("or use your browser's \"back\" function to return to ") ; printf("where you came from.") ; send_mail(name, anon_post_str, count_time_val, short_desc, id_str) ; } } }
main() { char *ncode_in, *tcode_in, *gcode_in, *fcode_in ; char *ntype_in, *all_in, *fam_in, *gen_in, *spec_in, *tri_in, *quad_in ; char *cutoff_in, *nonbonap_in ; int need_name, request_level, cutoff_level ; char name_html[128], *name_plain ; char qstr[256] ; int i ; void *qd ; long num_hits ; if (!mg_db_available("/bwg/FLORA/tracy/mgdata", "tracyspecs_map")) { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The database of specimens used to draw maps, which is ") ; puts("required to process ") ; puts("your query, is currently being rebuilt. Please try again ") ; puts("in a little while.") ; exit(0) ; } decode_query_string(12, "ncode", &ncode_in, /* bonap name code */ "tcode", &tcode_in, /* bonap taxon code */ "gcode", &gcode_in, /* ncode of genus */ "fcode", &fcode_in, /* ncode of family */ "ntype", &ntype_in, /* native/bonap_n/bonap_t */ "all", &all_in, "fam", &fam_in, "gen", &gen_in, "spec", &spec_in, "infra", &tri_in, "infra2", &quad_in, "cutoff", &cutoff_in /* clip level of map */) ; need_name = 0 ; if (nonempty(ncode_in) || nonempty(tcode_in) || nonempty(gcode_in) || nonempty(fcode_in)) { char *code, *prefix ; if (nonempty(ncode_in)) { code = ncode_in ; prefix = "qqbnn" ; } else if (nonempty(tcode_in)) { code = tcode_in ; prefix = "qqbtn" ; } else if (nonempty(gcode_in)){ code = gcode_in ; prefix = "qqgco" ; } else if (nonempty(fcode_in)) { code = fcode_in ; prefix = "qqfco" ; } get_bonap_info_by_code(code, name_html, &request_level) ; strcpy(qstr, prefix) ; for (i=0 ; code[i] != '\0' ; i++) sprintf(qstr+strlen(qstr), "%c", code[i]+'A'-'0') ; } else /* no bonap code, doing it by name */ { /* determine request level */ if (nonempty(all_in)) { request_level = 0 ; sprintf(qstr, "qqspc") ; } else if (nonempty(fam_in)) { request_level = 1 ; sprintf(qstr, "qqfam%s", fam_in) ; } else if (nonempty(gen_in)) { if (nonempty(spec_in)) { if (nonempty(tri_in)) { if (nonempty(quad_in)) { request_level = 5 ; sprintf(qstr, "qqgen%s&qqspe%s&qqtri%s&qqqua%s", fam_in, gen_in, tri_in, quad_in) ; } else { request_level = 4 ; sprintf(qstr, "qqgen%s&qqspe%s&qqtri%s", fam_in, gen_in, tri_in) ; } } else { request_level = 3 ; sprintf(qstr, "qqgen%s&qqspe%s", gen_in, spec_in) ; } } else { request_level = 2 ; sprintf(qstr, "qqgen%s", gen_in) ; } } else { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The URL you requested is malformed. When querying by name,") ; puts("you must provide one of the following:") ; puts("<ul>") ; puts("<li>A request for all specimens") ; puts("<li>A family") ; puts("<li>A genus") ; puts("<li>A genus and species") ; puts("<li>A genus, species, and tri-level infra") ; puts("<li>A genus, species, tri- and quad-level infras") ; puts("</ul>") ; puts("Please check the URL structure and try again.") ; exit(1) ; } if (request_level > 0) { if (nonempty(ntype_in) && strcmp(ntype_in, "native")) { char ncode[10], tcode[10], *prefix, *code ; get_bonap_info_by_qstr(qstr, name_html, ncode, tcode) ; prefix = !strcmp(ntype_in, "bonap_n") ? "qqbnn" : "qqbtn" ; code = !strcmp(ntype_in, "bonap_n") ? ncode : tcode ; switch(request_level) { case 1: sprintf(qstr, "qqfco%s", tcode) ; break ; case 2: sprintf(qstr, "qqgco%s", tcode) ; break ; case 3: sprintf(qstr, "(%s%s|qqsco%s", prefix, code, tcode) ; break ; case 4: sprintf(qstr, "(%s%s|qqtco%s", prefix, code, tcode) ; break ; case 5: sprintf(qstr, "%s%s", prefix, code) ; break ; } } else need_name = 1 ; } } /* after all this drill "name_html" should contain the html form of the thing being queried for or need_name != 0 */ if (nonempty(cutoff_in)) { if (!strcmp(cutoff_in, "fam") && request_level <= 1) { cutoff_level = 1 ; sprintf(qstr+strlen(qstr), "&qqfrp") ; } else if (!strcmp(cutoff_in, "gen") && request_level <= 2) { cutoff_level = 2 ; sprintf(qstr+strlen(qstr), "&qqgrp") ; } else if (!strcmp(cutoff_in, "spec") && request_level <= 3) { sprintf(qstr+strlen(qstr), "&qqtax") ; cutoff_level = 3 ; } else { return_header("text/html") ; puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("The URL you requested is malformed. When supplying a cutoff,") ; puts("the cutoff must be at a taxonomic level less than or equal to ") ; puts("the level of the query (for example, you cannot have a cutoff ") ; puts("of \"family\" when mapping a genus). Please check the URL ") ; puts("and try again.") ; exit(1) ; } } else cutoff_level = 0 ; mg_bool_query(qstr,"/bwg/FLORA/tracy/mgdata", "tracyspecs_map", &qd) ; num_hits = mg_get_num_returned(qd) ; return_header("text/html") ; printf("<body bgcolor=\"#ffffff\">\n") ; if (num_hits == 0) { puts("<title>Sorry!</title>") ; puts("<h1>Sorry!</h1>") ; puts("There are no items in the database which corresponded to your ") ; puts("query.") ; } else { int first ; int rbs[] = {162, 54, 0, 0, 0} ; int gs[] = {255, 255, 217, 140, 86} ; int single_rbs[]={0} ; int single_gs[]={217} ; void *map_info ; map_info = map_initialize("/bwg/FLORA/cgi/maps","tx", GRADED_VALUE) ; if (cutoff_level != 0 && cutoff_level == request_level) map_assign_graded_colors(map_info, 1, single_rbs, single_gs, single_rbs) ; else map_assign_graded_colors(map_info, 5, rbs, gs, rbs) ; if (need_name) { void *lp=NULL ; char tri_html[80], quad_html[80] ; mg_setup_doc_line_producer(qd, mg_get_doc_num(qd), &lp) ; while (mg_dlp_more_lines(lp)) { char s[256] ; mg_dlp_next_line(lp, s) ; if (request_level == 1) { if (!strncmp(s, "qqfah ", 6)) strcpy(name_html, s+6) ; } else if (request_level == 2) { if (!strncmp(s, "qqgeh ", 6)) strcpy(name_html, s+6) ; } else { if (!strncmp(s, "qqsph ", 6)) strcpy(name_html, s+6) ; else if (!strncmp(s, "qqiah ", 6)) strcpy(tri_html, s+6) ; else if (!strncmp(s, "qqibh ", 6)) strcpy(quad_html, s+6) ; } } if (request_level >= 4) sprintf(name_html+strlen(name_html), " %s", tri_html) ; if (request_level == 5) sprintf(name_html+strlen(name_html), " %s", quad_html) ; } do { add_to_county_bins(map_info, mg_get_doc_num(qd)) ; } while (mg_goto_next_doc(qd)) ; printf("<title>Flora of Texas Consortium - Texas Plant Distributions</title>\n"); printf("<h1>Flora of Texas Consortium - Texas Plant Distributions</h1>\n") ; printf("<b>Currently mapping: ") ; switch(request_level) { case 0: /* all */ switch (cutoff_level) { case 0: printf("all specimens") ; break ; case 1: printf("all families") ; break ; case 2: printf("all genera") ; break ; case 3: printf("all species") ; break ; } break ; case 1: /* family */ switch (cutoff_level) { case 0: printf("specimens of family ") ; break ; case 1: printf("distribution of family ") ; break ; case 2: printf("genera of family ") ; break ; case 3: printf("species of family ") ; break ; } break ; case 2: /* genus */ switch (cutoff_level) { case 0: printf("specimens of genus ") ; break ; case 2: printf("distribution of genus ") ; break ; case 3: printf("species of genus ") ; break ; } break ; case 3: /* species */ switch (cutoff_level) { case 0: printf("specimens of ") ; break ; case 3: printf("distribution of ") ; break ; } break ; case 4: /* tri-rank */ case 5: /* quad-rank */ printf("speciemens of ") ; break ; } if (request_level > 0) printf("%s", name_html) ; printf("</b><p>\n") ; if (nonempty(ntype_in) && !strcmp(ntype_in, "bonap_t")) { puts("Items whose names are defined as synonymous to ") ; puts("the name requested are included in this map.<p>") ; } if (cutoff_level > 0 && request_level == cutoff_level) { map_output_img(map_info, 0, NULL, NULL, NULL) ; } else { puts("Click on a colored county to get a list of mapped items ") ; puts("present in that county. <p>") ; printf("<b>Color Key (number of ") ; switch(cutoff_level) { case 0: printf("specimens") ; break ; case 1: printf("families") ; break ; case 2: printf("genera") ; break ; case 3: printf("species") ; break ; } printf(" per county):<p>") ; map_output_graded_color_key(map_info) ; printf("</b><p>\n") ; printf("<form method=get action=\"/FLORA/cgi/ftc_hsbdb_list1\">") ; map_output_form_elem(map_info, NULL, NULL, NULL) ; if (nonempty(cutoff_in)) printf("<input type=hidden name=cutoff value=\"%s\">", cutoff_in) ; if (nonempty(ntype_in)) printf("<input type=hidden name=ntype value=\"%s\">", ntype_in) ; if (nonempty(fcode_in)) printf("<input type=hidden name=fcode value=\"%s\">", fcode_in) ; if (nonempty(gcode_in)) printf("<input type=hidden name=gcode value=\"%s\">", gcode_in) ; if (nonempty(ncode_in)) printf("<input type=hidden name=ncode value=\"%s\">", ncode_in) ; if (nonempty(tcode_in)) printf("<input type=hidden name=tcode value=\"%s\">", tcode_in) ; if (nonempty(all_in)) printf("<input type=hidden name=all value=\"%s\">", all_in) ; if (nonempty(fam_in)) printf("<input type=hidden name=fam value=\"%s\">", fam_in) ; if (nonempty(gen_in)) printf("<input type=hidden name=gen value=\"%s\">", gen_in) ; if (nonempty(spec_in)) printf("<input type=hidden name=spec value=\"%s\">", spec_in) ; if (nonempty(tri_in)) printf("<input type=hidden name=infra value=\"%s\">", tri_in) ; if (nonempty(quad_in)) printf("<input type=hidden name=infra2 value=\"%s\">", quad_in) ; printf("</form>") ; } puts("<hr>") ; puts("This page was constructed by a program written by ") ; puts("<a href=\"mailto:[email protected]\">") ; puts("Erich Schneider</a> of the ") ; puts("<a href=\"http://www.csdl.tamu.edu\">") ; puts("Center for the Study of Digital Libraries</a> ") ; puts("working for the ") ; puts("<a href=\"http://www.csdl.tamu.edu/FLORA/tamuherb.htm\">") ; puts("Texas A&M Bioinformatics Working Group</a>.") ; } }
main() { void *qd ; char command[256] ; int cur_fam_cutoff ; int cur_gen_cutoff ; int cur_tax_cutoff ; int total_families ; int total_genera ; int total_taxa ; int total_specimens ; int genera_in_family ; int taxa_in_family ; int specimens_in_family ; int taxa_in_genus ; int specimens_in_genus ; int specimens_in_taxon ; int item_num ; taxon *new_fam_ptr ; taxon *new_gen_ptr ; taxon *tax_ptr ; taxon **fam_array, **gen_array, **spec_array ; char *cur_fam_name ; char *cur_gen_name ; char *cur_tax_name ; int cur_tax_hybrid ; int cur_gen_hybrid ; char *loc_in ; char *herb_in ; char *items_in ; char *coll_in ; char *cult_in ; char *query_save = NULL ; FILE *fp ; taxon *query_root ; taxon *fam_root ; taxon *fam_ptr ; taxon *gen_ptr ; taxon *spec_ptr ; family_info *this_family_info ; genus_info *this_genus_info ; taxon_info *this_taxon_info ; char *fam_out ; char *gen_out ; char *spec_out ; int new_taxon, new_genus, new_family ; int getting_everything = 0 ; int i,j,k ; int restrictions ; /* the CGI input to the program has two vars: "loc", a list of UT Texas county codes concatenated together w/o delimieters "items", a list of the form: family;genus;genus;genus;/;family;genus;genus;/;family;genus... which indicates what items are to be "expanded" */ decode_query_string(6, "loc", &loc_in, "items", &items_in, "herb", &herb_in, "sort", &do_sort, "coll", &coll_in, "cult", &cult_in) ; restrictions = 0 ; if (nonempty(loc_in)) restrictions++ ; if (nonempty(herb_in)) restrictions++ ; if (nonempty(coll_in)) restrictions++ ; if (nonempty(cult_in)) restrictions++ ; /* parse the "items" value and create a taxon tree in query_root */ query_root = NULL ; if (nonempty(items_in)) { char *item ; int new_family = 1 ; query_save = strdup(items_in) ; item = strtok(items_in, ";") ; while (item != NULL) { if (item[0] == '/') new_family = 1 ; else if (new_family) { fam_ptr = insert_taxon_item(&query_root, item, NULL, NULL) ; new_family = 0 ; } else { insert_taxon_item(&(fam_ptr->nextlevel), item, NULL, NULL) ; } item = strtok(NULL, ";") ; } } /* The query. We want to get the numbers of the relevant records. If "loc" hasn't been set, we want all of them, and they're stored in a file. Otherwise we have to query MG. */ { int i ; char qstr[2048] ; if (restrictions==0) sprintf(qstr, "qqspc") ; if (nonempty(cult_in)) { sprintf(qstr+strlen(qstr), "qqcul%s", cult_in) ; if (restrictions > 1) { sprintf(qstr+strlen(qstr), "&") ; restrictions-- ; } } if (nonempty(loc_in)) { sprintf(qstr+strlen(qstr), "(") ; for (i=0 ; loc_in[i] != '\0' ; i+=3) { sprintf(qstr+strlen(qstr), "qqloc%c%c%c", loc_in[i], loc_in[i+1], loc_in[i+2]) ; if (loc_in[i+3] != '\0') sprintf(qstr+strlen(qstr), "|") ; } sprintf(qstr+strlen(qstr), ")") ; if (restrictions > 1) { sprintf(qstr+strlen(qstr), "&") ; restrictions-- ; } } if (nonempty(herb_in)) { char *temp, *tok ; temp = strdup(herb_in) ; tok = strtok(temp, " ") ; sprintf(qstr+strlen(qstr), "(") ; do { sprintf(qstr+strlen(qstr), "qqhrb%s", tok) ; tok = strtok(NULL, " ") ; if (tok != NULL) sprintf(qstr+strlen(qstr), "|") ; } while (tok != NULL) ; sprintf(qstr+strlen(qstr), ")") ; free(temp) ; if (restrictions > 1) { sprintf(qstr+strlen(qstr), "&") ; restrictions-- ; } } if (nonempty(coll_in)) { int first, count ; char num_str[8] ; char s[80] ; { char fname[FILENAME_MAX] ; sprintf(fname, "%s/collector_list", HSB_DATA_PATH) ; fp = fopen(fname, "r") ; } count = 0 ; first = 1 ; sprintf(qstr+strlen(qstr), "(") ; while (!feof(fp)) { fgets(s, 80, fp) ; if (strstr(s, coll_in) != NULL) { sprintf(num_str, "%d", count) ; for (i=0 ; num_str[i] != '\0' ; i++) num_str[i] += 'A' - '0' ; if (!first) sprintf(qstr+strlen(qstr), "|") ; first = 0 ; sprintf(qstr+strlen(qstr), "qqcnu%s", num_str) ; } count++ ; } sprintf(qstr+strlen(qstr), ")") ; fclose(fp) ; } mg_bool_query(qstr, HSB_DATA_PATH, "tracyspecs", &qd) ; } /* parse the returned output */ /* these files have the format name1 x1 name2 x2 name3 x3 ... and indicate what names are associated with what record #s. 1 to x1 have name1, x1+1 to x2 have name2, etc. */ { char fname[FILENAME_MAX] ; sprintf(fname, "%s/family_ranges", HSB_DATA_PATH) ; fam_fp = fopen(fname, "r") ; sprintf(fname, "%s/genus_ranges", HSB_DATA_PATH) ; gen_fp = fopen(fname, "r") ; sprintf(fname, "%s/species_ranges", HSB_DATA_PATH) ; tax_fp = fopen(fname, "r") ; } /* in the cutoff variables, we keep track of the record number which, when we exceed it, will cause us to change family/genus/species. They are set at 0 initially so that we immediately load the names from the files */ cur_fam_cutoff = cur_gen_cutoff = cur_tax_cutoff = 0 ; /* we use the taxon tree stored in query_root to tell us what to expand */ fam_ptr = query_root ; gen_ptr = (fam_ptr == NULL ? NULL : fam_ptr->nextlevel) ; fam_root = NULL ; total_families = 0 ; total_genera = 0 ; total_taxa = 0 ; total_specimens = 0 ; if (mg_get_num_returned(qd) > 0) { do { item_num = mg_get_doc_num(qd) ; if (item_num <= cur_fam_cutoff) { if (item_num <= cur_gen_cutoff) { if (item_num <= cur_tax_cutoff) /* do nothing */ ; else { new_taxon = 1 ; /* if the current family and genus are both being expanded, put a record for the last taxon in the tree (the family and genus have already been added) */ if (tax_ptr_name_match(fam_ptr, cur_fam_name) && tax_ptr_name_match(gen_ptr, cur_gen_name)) { new_fam_ptr = insert_taxon_item(&fam_root, cur_fam_name, NULL, NULL) ; new_gen_ptr = insert_taxon_item(&(new_fam_ptr->nextlevel), cur_gen_name, NULL, hybrid_cmp) ; this_taxon_info = new_taxon_info(cur_tax_hybrid, specimens_in_taxon) ; insert_taxon_item(&(new_gen_ptr->nextlevel), cur_tax_name, this_taxon_info, hybrid_cmp) ; } get_next_taxon(item_num, &cur_tax_cutoff, &cur_tax_hybrid, &cur_tax_name) ; } } else { new_genus = 1 ; new_taxon = 1 ; /* if the current family is being expanded, put a record for the last genus in the tree (the family has already been added) */ if (tax_ptr_name_match(fam_ptr, cur_fam_name)) { new_fam_ptr = insert_taxon_item(&fam_root, cur_fam_name, NULL, NULL) ; this_genus_info = new_genus_info(cur_gen_hybrid, taxa_in_genus, specimens_in_genus) ; new_gen_ptr = insert_taxon_item(&(new_fam_ptr->nextlevel), cur_gen_name, this_genus_info, hybrid_cmp) ; /* if, additionally, the last genus was being expanded, put an entry for the last taxon of it in the tree */ if (tax_ptr_name_match(gen_ptr, cur_gen_name)) { this_taxon_info = new_taxon_info(cur_tax_hybrid, specimens_in_taxon) ; insert_taxon_item(&(new_gen_ptr->nextlevel), cur_tax_name, this_taxon_info, hybrid_cmp) ; gen_ptr = gen_ptr->next ; } } get_next_taxon(item_num, &cur_tax_cutoff, &cur_tax_hybrid, &cur_tax_name) ; get_next_genus(item_num, &cur_gen_cutoff, &cur_gen_hybrid, &cur_gen_name) ; } } else { new_family = 1 ; new_genus = 1 ; new_taxon = 1 ; if (cur_fam_cutoff != 0) { /* i.e. not the first item */ /* we always put an entry for the last family in the tree */ this_family_info = new_family_info(genera_in_family, taxa_in_family, specimens_in_family) ; new_fam_ptr = insert_taxon_item(&fam_root, cur_fam_name, this_family_info, hybrid_cmp) ; /* if we were expanding the last family, put a record for the last genus in the tree */ if (tax_ptr_name_match(fam_ptr, cur_fam_name)) { this_genus_info = new_genus_info(cur_gen_hybrid, taxa_in_genus, specimens_in_genus) ; new_gen_ptr = insert_taxon_item(&(new_fam_ptr->nextlevel), cur_gen_name, this_genus_info, hybrid_cmp) ; /* if we were expanded the last genus, put a record for the last taxon in the tree */ if (tax_ptr_name_match(gen_ptr, cur_gen_name)) { this_taxon_info = new_taxon_info(cur_tax_hybrid, specimens_in_taxon) ; insert_taxon_item(&(new_gen_ptr->nextlevel), cur_tax_name, this_taxon_info, hybrid_cmp) ; } fam_ptr = fam_ptr->next ; gen_ptr = (fam_ptr == NULL ? NULL : fam_ptr->nextlevel) ; } } get_next_taxon(item_num, &cur_tax_cutoff, &cur_tax_hybrid, &cur_tax_name) ; get_next_genus(item_num, &cur_gen_cutoff, &cur_gen_hybrid, &cur_gen_name) ; get_next_family(item_num, &cur_fam_cutoff, &cur_fam_name) ; } if (new_family) { total_families++ ; specimens_in_family = 0 ; taxa_in_family = 0 ; genera_in_family = 0 ; new_family = 0 ; } if (new_genus) { total_genera++ ; genera_in_family++ ; specimens_in_genus = 0 ; taxa_in_genus = 0 ; new_genus = 0 ; } if (new_taxon) { total_taxa++ ; taxa_in_family++ ; taxa_in_genus++ ; specimens_in_taxon = 0 ; new_taxon = 0 ; } total_specimens++ ; specimens_in_family++ ; specimens_in_genus++ ; specimens_in_taxon++ ; } while (mg_goto_next_doc(qd)) ; /* need to put the info for the last family examined in the tree */ if (total_specimens > 0) { this_family_info = new_family_info(genera_in_family, taxa_in_family, specimens_in_family) ; new_fam_ptr = insert_taxon_item(&fam_root, cur_fam_name, this_family_info, NULL) ; /* if we were expanding the last family, put it in too */ if (tax_ptr_name_match(fam_ptr, cur_fam_name)) { this_genus_info = new_genus_info(cur_gen_hybrid, taxa_in_genus, specimens_in_genus) ; new_gen_ptr = insert_taxon_item(&(new_fam_ptr->nextlevel), cur_gen_name, this_genus_info, hybrid_cmp) ; /* and if we were expanding the last genus, it goes in as well */ if (tax_ptr_name_match(gen_ptr, cur_gen_name)) { this_taxon_info = new_taxon_info(cur_tax_hybrid, specimens_in_taxon) ; insert_taxon_item(&(new_gen_ptr->nextlevel), cur_tax_name, this_taxon_info, hybrid_cmp) ; } } } } fclose(fam_fp) ; fclose(gen_fp) ; fclose(tax_fp) ; return_header("text/html") ; printf("<script>\n") ; if (query_save != NULL) printf("top.items='%s';\n", query_save) ; else printf("top.items='';\n") ; printf("</script>\n") ; if (nonempty(loc_in) || nonempty(herb_in) || nonempty(cult_in)) { printf("<b>Selection criteria</b>:<br>\n") ; if (nonempty(cult_in)) printf("Showing only specimens taken from %s material<br>\n", !strcmp(cult_in, "yes") ? "cultivated" : "non-cultivated") ; printf("Counties: <b>") ; if (nonempty(loc_in)) { int i, j ; char cur_loc[4] ; char *cname ; for (i=0 ; loc_in[i] != '\0' ; i+=3) { strncpy(cur_loc, loc_in+i, 3) ; cur_loc[3] = '\0' ; cname = map_convert_region_name(HSB_MAP_PATH, "tx", "ut_abbr", "cname", cur_loc) ; printf("%s%s", cname, loc_in[i+3] != '\0' ? ", " : "") ; } } else printf("all") ; printf("</b><br>\n") ; printf("Herbaria: <b>") ; if (nonempty(herb_in)) printf("%s", herb_in) ; else printf("all") ; printf("</b><br>") ; printf("<p>\n") ; } /* if (nonempty(coll_in)) printf("Collector string: %s<br>\n", coll_in) ; */ if (total_specimens > 0) { printf("%d %s, %d %s, %d %s, %d %s ", total_families, family_str(total_families), total_genera, genus_str(total_genera), total_taxa, taxon_str(total_taxa), total_specimens, specimen_str(total_specimens)) ; printf("<a href=\"javascript:top.show_specs('all=yes');\">") ; printf("(specimens)</a> ") ; printf("<a href=\"javascript:top.do_map('all=yes');\">") ; printf("(map)</a><br>\n") ; pack_taxon_array(fam_root, &fam_array, &total_families) ; if (nonempty(do_sort)) qsort(fam_array, total_families, sizeof(taxon *), (int (*)(const void *, const void *))fam_compare) ; for (i=0 ; i< total_families ; i++) { char fam_print_str[256], gen_print_str[256], tax_print_str[256] ; int num_genera, num_taxa, num_specs ; fam_ptr = fam_array[i] ; num_genera = ((family_info *)(fam_ptr->other_data))->num_genera ; num_taxa = ((family_info *)(fam_ptr->other_data))->num_taxa ; num_specs = ((family_info *)(fam_ptr->other_data))->num_specs ; printf("<a name=\"fam%s\"></a>", fam_ptr->name) ; if (!tax_ptr_name_match(fam_ptr, "xxx")) printf("Family ") ; dump_items_anchor(query_root, fam_ptr->name, NULL) ; if (!tax_ptr_name_match(fam_ptr, "xxx")) printf("<b>%s</b></a>", fam_ptr->name) ; else printf("No family listed</a>") ; printf(" (%d %s, %d %s, %d %s) ", num_genera, genus_str(num_genera), num_taxa, taxon_str(num_taxa), num_specs, specimen_str(num_specs)) ; dump_show_specs_anchor(fam_ptr->name, NULL, NULL) ; printf("(%s)</a>", specimen_str(num_specs)) ; putchar(' ') ; dump_do_map_anchor(fam_ptr->name, NULL, NULL) ; printf("(map)</a>") ; printf("<br>\n") ; pack_taxon_array(fam_ptr->nextlevel, &gen_array, &genera_in_family) ; if (nonempty(do_sort)) qsort(gen_array, genera_in_family, sizeof(taxon *), (int (*)(const void *, const void *))gen_compare) ; for (j=0 ; j < genera_in_family ; j++) { gen_ptr = gen_array[j] ; num_taxa = ((genus_info *)(gen_ptr->other_data))->num_taxa ; num_specs = ((genus_info *)(gen_ptr->other_data))->num_specs ; printf("<spacer type=horizontal size=20>") ; printf("<a name=\"fam%s_gen%s\"></a>", fam_ptr->name, gen_ptr->name); if (!tax_ptr_name_match(gen_ptr, "xxx")) printf("Genus ") ; dump_items_anchor(query_root, fam_ptr->name, gen_ptr->name) ; if (!tax_ptr_name_match(gen_ptr, "xxx")) printf("%s<i>%s</i></a>", ((genus_info *)(gen_ptr->other_data))->hybrid ? "X " : "", gen_ptr->name) ; else printf("No genus listed</a>") ; printf(" (%d %s, %d %s) ", num_taxa, taxon_str(num_taxa), num_specs, specimen_str(num_specs)) ; dump_show_specs_anchor(fam_ptr->name, gen_ptr->name, NULL) ; printf("(%s)</a>", specimen_str(num_specs)) ; putchar(' ') ; dump_do_map_anchor(fam_ptr->name, gen_ptr->name, NULL) ; printf("(map)</a>") ; printf("<br>\n") ; pack_taxon_array(gen_ptr->nextlevel, &spec_array, &taxa_in_genus) ; if (nonempty(do_sort)) qsort(spec_array, taxa_in_genus, sizeof(taxon *), (int (*)(const void *, const void *))taxon_compare) ; for (k=0 ; k < taxa_in_genus ; k++) { spec_ptr = spec_array[k] ; printf("<spacer type=horizontal size=40>") ; num_specs = ((taxon_info *)(spec_ptr->other_data))->num_specs ; if (!tax_ptr_name_match(spec_ptr, "xxx")) { if (((genus_info *)(gen_ptr->other_data))->hybrid) { if (((taxon_info *)(spec_ptr->other_data))->hybrid) sprintf(tax_print_str, "X <i>%s</i> X <i>%s</i>", gen_ptr->name, spec_ptr->name) ; else sprintf(tax_print_str, "X <i>%s %s</i>", gen_ptr->name, spec_ptr->name) ; } else { if (((taxon_info *)(spec_ptr->other_data))->hybrid) sprintf(tax_print_str, "<i>%s</i> X <i>%s</i>", gen_ptr->name, spec_ptr->name) ; else sprintf(tax_print_str, "<i>%s %s</i>", gen_ptr->name, spec_ptr->name) ; } } else sprintf(tax_print_str, "No species listed") ; printf("%s (%d %s) ", tax_print_str, num_specs, specimen_str(num_specs)) ; dump_show_specs_anchor(fam_ptr->name, gen_ptr->name, spec_ptr->name) ; printf("(%s)</a>", specimen_str(num_specs)) ; putchar(' ') ; dump_do_map_anchor(fam_ptr->name, gen_ptr->name, spec_ptr->name) ; printf("(map)</a>") ; printf("<br>\n") ; } free(spec_array) ; } free(gen_array) ; } free(fam_array) ; } else printf("No specimens meet these specifications.") ; }
main() { char *all_in = NULL ; char *grp_in = NULL ; char *fam_in = NULL ; char *gen_in = NULL ; char *spec_in = NULL ; char *x_in = NULL, *y_in = NULL ; char *loc_in = NULL ; char *loc_name = NULL ; char query_str[512] ; void *qd, *lp=NULL ; taxon *root, *grp_p, *fam_p, *gen_p, *spe_p, *inf_p ; char grp_out[32], fam_out[32], gen_out[32], spec_out[32] ; decode_query_string(8, "all", &all_in, "grp", &grp_in, "fam", &fam_in, "gen", &gen_in, "spec", &spec_in, "x", &x_in, "y", &y_in, "loc", &loc_in) ; if (nonempty(x_in)) { loc_in = map_convert_xy_to_name(atoi(x_in),atoi(y_in), "/bwg/FLORA/cgi/maps", "ca_pswrs", "abbr") ; if (loc_in == NULL) { return_nothing() ; exit(1) ; } } if (nonempty(loc_in)) loc_name = map_convert_region_name("/bwg/FLORA/cgi/maps", "ca_pswrs", "abbr", "name", loc_in) ; if (!mg_db_available("/bwg/FLORA/calflora/mgdata", "calmap")) { return_header("text/html") ; sorry() ; exit(1) ; } if (nonempty(all_in)) sprintf(query_str, "qqall") ; else if (nonempty(grp_in)) sprintf(query_str, "qqgro%s", grp_in) ; else if (nonempty(fam_in)) sprintf(query_str, "qqfam%s", fam_in) ; else if (nonempty(gen_in)) { if (nonempty(spec_in)) sprintf(query_str, "qqgen%s&qqspe%s", gen_in, spec_in) ; else sprintf(query_str, "qqgen%s", gen_in) ; } else { return_header("text/html") ; printf("<title>Sorry!</title>") ; printf("<h1>Sorry!</h1>") ; printf("Your list query to the CalFlora plant ") ; printf("distributions database was improperly formed.") ; printf("Please check that the URL ") ; printf("is properly formed, and contact Erich Schneider ") ; printf("<a href=\"mailto:[email protected]\">(<b>[email protected]") ; printf("</b>)</a> if you have further problems.") ; exit(1) ; } if (nonempty(loc_in)) sprintf(query_str+strlen(query_str), "&(qqcpl%s|qqupl%s|qqijl%s)", loc_in, loc_in, loc_in) ; mg_bool_query(query_str, "/herbaria/FLORA/calflora/mgdata", "calmap",&qd); if (mg_get_num_returned(qd) == 0) { if (nonempty(x_in)) { return_nothing() ; exit(1) ; } else { return_header("text/html") ; printf("<title>Sorry!</title>") ; printf("<h1>Sorry!</h1>") ; printf("Your request did not correspond to any items in the CalFlora ") ; printf("plant distributions database. Please check that the URL ") ; printf("is properly formed, and contact Erich Schneider ") ; printf("<a href=\"mailto:[email protected]\">(<b>[email protected]") ; printf("</b>)</a> if you have further problems.") ; exit(0) ; } } root = NULL ; do { int first=1 ; char *grp, fam[32], gen[32], spec[32], infra[32], source[64] ; char name[256], rank ; item_data_t *item_data ; mg_setup_doc_line_producer(qd, mg_get_doc_num(qd), &lp) ; while (mg_dlp_more_lines(lp)) { char s[256] ; mg_dlp_next_line(lp, s) ; if (first) { if (!strncmp(s, "qqgro", 5)) strcpy(grp_out, s+5) ; else if (!strncmp(s, "qqfam", 5)) strcpy(fam_out, s+5) ; else if (!strncmp(s, "qqgen", 5)) strcpy(gen_out, s+5) ; else if (!strncmp(s, "qqspe", 5)) strcpy(spec_out, strchr(s, ' ')+1) ; } if (!strncmp(s, "qqgro", 5)) { if (!strcmp(s+5, "Pteridophyte")) grp = "1Pteridophytes"; else if (!strcmp(s+5, "Gymnosperm")) grp="2Gymnosperms"; else if (!strcmp(s+5, "Dicot")) grp="3Dicots"; else if (!strcmp(s+5, "Monocot")) grp="4Monocots"; } else if (!strncmp(s, "qqfam", 5)) strcpy(fam, s+5) ; else if (!strncmp(s, "qqgen", 5)) strcpy(gen, s+5) ; else if (!strncmp(s, "qqspe", 5)) strcpy(spec, strchr(s, ' ')+1) ; else if (!strncmp(s, "qqtri", 5)) strcpy(infra, s+5) ; else if (!strncmp(s, "qqnam", 5)) strcpy(name, s+6) ; else if (!strncmp(s, "qqsrc", 5)) strcpy(source, s+6) ; else if (!strncmp(s, "qqrnk", 5)) rank = s[5] ; } grp_p = insert_taxon_item(&root, grp, NULL, 0) ; fam_p = insert_taxon_child(grp_p, fam, NULL, 0) ; gen_p = insert_taxon_child(fam_p, gen, NULL, 0) ; spe_p = insert_taxon_child(gen_p, spec, NULL, 0) ; item_data = (item_data_t *)malloc(sizeof(item_data_t)) ; item_data->name = strdup(name) ; if (strcmp(source, "No distribution source referenced")) item_data->has_dist = 1 ; else item_data->has_dist = 0 ; if (rank == 'b') { inf_p = insert_taxon_child(spe_p, infra, item_data, 1) ; } else { spe_p->other_data = item_data ; } first = 0 ; } while (mg_goto_next_doc(qd)) ; return_header("text/html") ; header() ; puts("<h1>") ; if (nonempty(all_in)) { printf("Plants ") ; if (nonempty(loc_name)) printf("of %s", loc_name) ; else printf("of California") ; } else if (nonempty(grp_in)) { printf("%ss ", grp_out) ; if (nonempty(loc_name)) printf("of %s", loc_name) ; else printf("of California") ; } else if (nonempty(fam_in)) { printf("Plants of family %s ", fam_out) ; if (nonempty(loc_name)) printf("in %s", loc_name) ; else printf("in California") ; } else if (nonempty(gen_in)) { if (!nonempty(spec_in)) printf("Plants of genus <i>%s</i> ", gen_out) ; else printf("Varieties/subspecies of <i>%s %s</i> ", gen_out, spec_out) ; if (nonempty(loc_name)) printf("in %s", loc_name) ; else printf("in California") ; } puts("</h1>") ; printf("Links in the list below go to diversity maps of the item ") ; printf("in question, or to distribution maps if the item is a ") ; printf("bottom-level species (indicated by the presence of an ") ; printf("authority). Species containing varieities or subspecies ") ; printf("which have distribution data in their own right have links ") ; printf("both to diversity maps of their infraspecific taxa as well ") ; printf("as to a map of their own distribution. A map of ") ; printf("<a href=\"/FLORA/cgi/calmap?all=yes&div=yes\">") ; printf("all California plants</a> in the database is also available.") ; printf("<p>") ; for (grp_p = root ; grp_p != NULL ; step_taxon(grp_p)) { printf("<a href=\"/FLORA/cgi/calmap?div=yes&grp=") ; switch(grp_p->name[0]) { case '1': printf("pteridophyte") ; break ; case '2': printf("gymnosperm") ; break ; case '3': printf("dicot") ; break ; case '4': printf("monocot") ; break ; } printf("\">") ; printf("%s", grp_p->name+1) ; printf("</a>") ; puts("<br><ul>") ; for (fam_p = grp_p->nextlevel ; fam_p != NULL ; step_taxon(fam_p)) { printf("Family ") ; printf("<a href=\"/FLORA/cgi/calmap?div=yes&fam=%s\">", fam_p->name) ; printf("%s", fam_p->name) ; printf("</a>") ; puts("<br><ul>") ; for (gen_p = fam_p->nextlevel ; gen_p != NULL ; step_taxon(gen_p)) { printf("Genus ") ; printf("<a href=\"/FLORA/cgi/calmap?div=yes&gen=%s\">", gen_p->name) ; printf("<i>%s</i>", gen_p->name) ; printf("</a>") ; printf("<br><ul>") ; for (spe_p = gen_p->nextlevel ; spe_p != NULL ; step_taxon(spe_p)) { int spec_has_own_identity = 0 ; int spec_has_infras = 0 ; int spec_has_distribution = 0 ; if (spe_p->other_data != NULL) spec_has_own_identity = 1 ; if (spe_p->nextlevel != NULL) spec_has_infras = 1 ; if (spec_has_own_identity && ((item_data_t *)spe_p->other_data)->has_dist) spec_has_distribution = 1; if (spec_has_distribution || spec_has_infras) { printf("<a href=\"/FLORA/cgi/calmap?") ; if (spec_has_infras) printf("div=yes&") ; printf("gen=%s&spec=%s\">", gen_p->name, spe_p->name) ; } if (spec_has_own_identity) { printf("%s", ((item_data_t *)spe_p->other_data)->name) ; } else { printf("<i>%s %s</i>", gen_p->name, spe_p->name) ; } if (spec_has_distribution || spec_has_infras) printf("</a>") ; if (spec_has_distribution && spec_has_infras) { printf(" <a href=\"/FLORA/cgi/calmap?") ; printf("gen=%s&spec=%s\">(species distribution)</a>", gen_p->name, spe_p->name) ; } if (!spec_has_distribution && !spec_has_infras) printf(" (No distribution data in database)") ; puts("<br>") ; if (spec_has_infras) { puts("<ul>") ; for (inf_p = spe_p->nextlevel ; inf_p != NULL ; step_taxon(inf_p)) { if (((item_data_t *)inf_p->other_data)->has_dist) { printf("<a href=\"/FLORA/cgi/calmap?") ; printf("gen=%s&spec=%s&inf=%s\">", gen_p->name, spe_p->name, inf_p->name) ; } printf("%s", ((item_data_t *)inf_p->other_data)->name) ; if (((item_data_t *)inf_p->other_data)->has_dist) printf("</a>") ; else printf(" (No distribution data in database)") ; puts("<br>") ; } puts("</ul>") ; } } puts("</ul>") ; } puts("</ul>") ; } puts("</ul>") ; } footer() ; }
main() { char *id_str, fname[FILENAME_MAX] ; FILE *fp ; int done ; char *begin_str, *end_str ; issue_desc_t issue ; decode_query_string(2, "set_id", &set_id, "issue_id", &id_str) ; get_issue(set_id, id_str, &issue) ; begin_str = (char *)malloc(sizeof(char) * (strlen(id_str)+8)) ; sprintf(begin_str, "BEGIN %s\n", id_str) ; end_str = (char *)malloc(sizeof(char) * (strlen(id_str)+6)) ; sprintf(end_str, "END %s\n", id_str) ; no_cache() ; return_header("text/html") ; if (difftime(issue.expire_time, time(NULL)) > 0) { char s[80] ; int val_count ; /* issue is still open */ printf("<title>Vote on issue: %s</title>\n", issue.short_desc) ; printf("<h1>Vote on issue: %s</h1>\n", issue.short_desc) ; if (issue.secret_ballot) printf("<b>This vote is using a secret ballot.</b><br>") ; else { printf("<b>This vote is NOT using a secret ballot. ") ; printf("Your name and vote will be known to everybody!</b><br>") ; } if (issue.constant_update) { printf("<b>Partial voting results will be constantly updated ") ; printf("and visible on this page.</b><br>") ; } if (issue.can_change_vote) { printf("<b>You can change your vote at any time before the ") ; printf("counting date by voting again.</b><br>") ; } else { printf("<b>You cannot change your vote once it is made.</b><br>") ; } printf("<form method=post action=\"/FLORA/cgi/voting_cast\">") ; printf("<input type=hidden name=\"set_id\" value=\"%s\">", set_id) ; printf("<input type=hidden name=\"issue_id\" value=\"%s\">", id_str) ; printf("Your voting username: <input type=text name=\"name\"> ") ; printf("Your password: <input type=password name=\"password\"><br>") ; printf("<b>Description of issue:</b>") ; printf("<pre>") ; sprintf(fname, "%s/%s.descriptions", file_prefix, set_id) ; fp = fopen(fname, "r") ; do { fgets(s, 80, fp) ; } while (strcmp(s, begin_str)) ; while (strcmp(s, end_str)) { fgets(s, 80, fp) ; if (strcmp(s, end_str)) dump_line_with_links(s) ; } fclose(fp) ; printf("</pre>") ; if (issue.multiple_choice > 1) printf("<b>Select up to %d choices:</b>", issue.multiple_choice) ; else printf("<b>Select a choice:</b>") ; printf("<pre>") ; sprintf(fname, "%s/%s.choices", file_prefix, set_id) ; fp = fopen(fname, "r") ; do { fgets(s, 80, fp) ; } while (strcmp(s, begin_str)) ; val_count = 1 ; while (strcmp(s, end_str)) { fgets(s, 80, fp) ; if (strcmp(s, end_str)) { printf("<input type=%s name=choice value=%d> ", issue.multiple_choice > 1 ? "checkbox" : "radio", val_count++) ; dump_line_with_links(s) ; } } fclose(fp) ; printf("<input type=%s name=choice value=%d> Abstain\n", issue.multiple_choice > 1 ? "checkbox" : "radio", val_count) ; printf("</pre>\n") ; printf("<input type=submit value=\"Cast your vote\">") ; printf("</form>") ; if (issue.constant_update) { printf("<b>Current voting results:</b>\n") ; dump_issue_results(issue) ; } } else { char s[80] ; printf("<title>Results of vote on issue: %s</title>\n", issue.short_desc) ; printf("<h1>Results of vote on issue: %s</h1>\n", issue.short_desc) ; printf("<b>Description of issue:</b>") ; printf("<pre>") ; sprintf(fname, "%s/%s.descriptions", file_prefix, set_id) ; fp = fopen(fname, "r") ; do { fgets(s, 80, fp) ; } while (strcmp(s, begin_str)) ; while (strcmp(s, end_str)) { fgets(s, 80, fp) ; if (strcmp(s, end_str)) dump_line_with_links(s) ; } fclose(fp) ; printf("</pre>") ; printf("<b>Voting results:</b>\n") ; dump_issue_results(issue) ; } }