std::string build_name(std::string start_name) { std::string check_name = start_name + ".png"; if (exists(check_name.c_str())) { return build_name(start_name + "1"); } else { return check_name; } }
static const char* nominal_name(ast_t* ast) { AST_GET_CHILDREN(ast, package, name, typeargs); ast_t* def = (ast_t*)ast_data(ast); ast_t* pkg = ast_nearest(def, TK_PACKAGE); const char* s = package_symbol(pkg); return build_name(s, ast_name(name), typeargs, false); }
/*-------------------------------------------------------------------------*/ void build_filename(char *dest_filename, const char *src_filename, const char *filepattern) { char drive[MAXDRIVE], dir[MAXDIR], filename_file[MAXFILE], filename_ext[MAXEXT], filepattern_file[MAXFILE], filepattern_ext[MAXEXT], tmp_filename[MAXFILE], tmp_ext[MAXEXT]; _splitpath(src_filename, drive, dir, filename_file, filename_ext); _splitpath(filepattern, drive, dir, filepattern_file, filepattern_ext); build_name(tmp_filename, filename_file, filepattern_file); build_name(tmp_ext, filename_ext, filepattern_ext); strmcpy(dest_filename, drive, MAXPATH); strmcat(dest_filename, dir, MAXPATH); strmcat(dest_filename, tmp_filename, MAXPATH); strmcat(dest_filename, tmp_ext, MAXPATH); }
int32 lua_dobuffer(const char *buff, int32 size, const char *name) { char newname[SIZE_PREF + 25]; ZIO z; int32 status; if (!name) { build_name(buff, newname); name = newname; } luaZ_mopen(&z, buff, size, name); status = do_main(&z, buff[0] == ID_CHUNK); return status; }
pn_messenger_t *pn_messenger(const char *name) { pn_messenger_t *m = malloc(sizeof(pn_messenger_t)); if (m) { m->name = build_name(name); m->timeout = -1; m->driver = pn_driver(); m->size = 0; m->listeners = 0; m->credit = 0; m->next_tag = 0; m->error = pn_error(); } return m; }
/* address_new_prefill: takes over the string ownership! */ static void address_new_prefill(LibBalsaAddress * address, GList * address_list, gchar * nickn, gchar * givenn, gchar * surn, gchar * fulln, gchar * org) { address->address_list = address_list; address->first_name = givenn ? givenn : g_strdup(nickn ? nickn : ""); address->last_name = surn ? surn : g_strdup(""); address->full_name = build_name(fulln, address->first_name, surn); g_free(fulln); address->organization = org ? org : g_strdup(""); address->nick_name = nickn ? nickn : g_strdup(address->full_name ? address->full_name : _("No-Id")); if (address->full_name == NULL) address->full_name = g_strdup(_("No-Name")); }
const char* genname_type(ast_t* ast) { switch(ast_id(ast)) { case TK_UNIONTYPE: case TK_ISECTTYPE: return stringtab("$object"); case TK_TUPLETYPE: return build_name(NULL, "$tuple", ast, false); case TK_NOMINAL: return nominal_name(ast); default: {} } assert(0); return NULL; }
/* * Write various lines to the output stream. */ static void lbab_ldif_write_dn(FILE * stream, LibBalsaAddress * address) { gchar *cn = NULL; gchar *value, *value_spec; if (address->full_name != NULL && address->full_name[0] != '\0') { cn = g_strdup(address->full_name); } else { cn = build_name(NULL, address->first_name, address->last_name); if (cn == NULL) { cn = g_strdup(_("No-Name")); } else { if (cn[0] == '\0') { g_free(cn); cn = g_strdup(_("No-Name")); } } } if (address->address_list && address->address_list->data) { value = g_strdup_printf("cn=%s,mail=%s", cn, (gchar *) address->address_list->data); } else value = g_strdup_printf("cn=%s", cn); value_spec = string_to_value_spec(value); fprintf(stream, "dn:%s\n", value_spec); g_free(value_spec); g_free(value); value_spec = string_to_value_spec(cn); fprintf(stream, "cn:%s\n", value_spec); g_free(value_spec); g_free(cn); }
const char* genname_dispatch(const char* type) { return build_name(type, "$dispatch", NULL, false); }
const char* genname_unbox(const char* name) { return build_name(name, "$unbox", NULL, false); }
const char* genname_fun(const char* type, const char* name, ast_t* typeargs) { return build_name(type, name, typeargs, true); }
const char* genname_be(const char* name) { return build_name(name, "_send", NULL, false); }
const char* genname_descriptor(const char* type) { return build_name(type, "$desc", NULL, false); }
const char* genname_instance(const char* type) { return build_name(type, "$inst", NULL, false); }
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>") ; }
int render_png(Graph* graph) { int i_side = (graph->side_length - 1) * SPACING + PADDING; //Cairo ImageSurface. This one will be saved afterwards as a png file Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, i_side + PADDING * 2, i_side + PADDING * 2); //Cairo Context. Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create(surface); cr->save(); // save the state of the context cr->set_source_rgb(1.0, 1.0, 1.0); cr->paint(); // fill image with the color cr->restore(); // color is back to black now //Storing state to start drawing cr->save(); //setting brush color to black cr->set_source_rgb(0.0, 0.0, 0.0); cr->set_line_width(1.0); //drawing lines for (int i = 0; i < graph->side_length; i++) { for (int j = 0; j < graph->side_length; j++) { //for a current node Node* current = graph->matrix.at(i).at(j); //find all friends for (int k = 0; k < current->friends.size(); k++) { pair<int, int> current_friend = *std::next(current->friends.begin(), k); //Move brush to current node cr->move_to(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING); //Draw a line to current friend cr->line_to(current_friend.first * SPACING + PADDING, current_friend.second * SPACING + PADDING); cr->stroke(); } } } //setting brush color to red cr->set_source_rgb(1.0, 0.0, 0.0); //drawing vertices after lines are drawn for (int i = 0; i < graph->side_length; i++) { for (int j = 0; j < graph->side_length; j++) { Node* current = graph->matrix.at(i).at(j); cr->arc(current->coors.first * SPACING + PADDING, current->coors.second * SPACING + PADDING, 1.0, 0.0, 2.0 * M_PI); cr->stroke(); } } cr->restore(); #ifdef CAIRO_HAS_PNG_FUNCTIONS std::string filename = build_name("result"); surface->write_to_png(filename); std::cout << "Wrote png file \"" << filename << "\"" << std::endl; #else std::cout << "You must compile cairo with PNG support for this example to work." << std::endl; #endif }
const char* genname_deserialise(const char* type) { return build_name(type, "$deserialise", NULL, false); }
const char* genname_tracetuple(const char* type) { return build_name(type, "$tracetuple", NULL, false); }
const char* genname_fieldlist(const char* type) { return build_name(type, "$fields", NULL, false); }
const char* genname_traitlist(const char* type) { return build_name(type, "$traits", NULL, false); }
const char* genname_typeid(const char* type) { return build_name(type, "$id", NULL, false); }
/* * given an inode number, this returns the full path name inside the subvolume * to that file/directory. cache_dirid and cache_name are used to * cache the results so we can avoid tree searches if a later call goes * to the same directory or file name */ static char *ino_resolve(int fd, u64 ino, u64 *cache_dirid, char **cache_name) { u64 dirid; char *dirname; char *name; char *full; int ret; struct btrfs_ioctl_search_args args; struct btrfs_ioctl_search_key *sk = &args.key; struct btrfs_ioctl_search_header *sh; unsigned long off = 0; int namelen; int e; memset(&args, 0, sizeof(args)); sk->tree_id = 0; /* * step one, we search for the inode back ref. We just use the first * one */ sk->min_objectid = ino; sk->max_objectid = ino; sk->max_type = BTRFS_INODE_REF_KEY; sk->max_offset = (u64)-1; sk->min_type = BTRFS_INODE_REF_KEY; sk->max_transid = (u64)-1; sk->nr_items = 1; ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args); e = errno; if (ret < 0) { fprintf(stderr, "ERROR: can't perform the search - %s\n", strerror(e)); return NULL; } /* the ioctl returns the number of item it found in nr_items */ if (sk->nr_items == 0) return NULL; off = 0; sh = (struct btrfs_ioctl_search_header *)(args.buf + off); if (sh->type == BTRFS_INODE_REF_KEY) { struct btrfs_inode_ref *ref; dirid = sh->offset; ref = (struct btrfs_inode_ref *)(sh + 1); namelen = btrfs_stack_inode_ref_name_len(ref); name = (char *)(ref + 1); name = strndup(name, namelen); /* use our cached value */ if (dirid == *cache_dirid && *cache_name) { dirname = *cache_name; goto build; } } else { return NULL; } /* * the inode backref gives us the file name and the parent directory id. * From here we use __ino_resolve to get the path to the parent */ dirname = __ino_resolve(fd, dirid); build: full = build_name(dirname, name); if (*cache_name && dirname != *cache_name) free(*cache_name); *cache_name = dirname; *cache_dirid = dirid; free(name); return full; }
const char* genname_finalise(const char* type) { return build_name(type, "_final", NULL, false); }