void dot_emit_if (FILE * file, struct node_t * node, struct node_t * context) { char *node_name, *child_name; node_name = gen_name (node); child_name = gen_name (node->child[1]); fprintf(file, "%s -> %s [label =\"true\"];\n", node_name, child_name); dot_gen_graph (file, node->child[1], (node->next != NULL ? node->next : context)); if (node->child[2] != NULL) { free (child_name); child_name = gen_name (node->child[2]); fprintf(file, "%s -> %s [label =\"false\"];\n", node_name, child_name); dot_gen_graph (file, node->child[2], (node->next != NULL ? node->next : context)); } else { char * next; if (node->next != NULL) next = gen_name (node->next); else next = gen_name (context); fprintf (file, "%s -> %s [label =\"false\"];\n", node_name, next); free (next); } free (node_name); free (child_name); dot_gen_graph (file, node->next, context); return; }
static void asgn_from( ref* reference, int column) { TEXT variable[MAX_REF_SIZE]; TEXT temp[MAX_REF_SIZE]; for (; reference; reference = reference->ref_next) { const gpre_fld* field = reference->ref_field; align(column); gen_name(variable, reference); const TEXT* value; if (reference->ref_source) { value = gen_name(temp, reference->ref_source); } else { value = reference->ref_value; } // To avoid chopping off a double byte kanji character in between // the two bytes, generate calls to gds__ftof2 gds$_vtof2, // gds$_vtov2 and jrd_vtof2 wherever necessary if (!field || field->fld_dtype == dtype_text) fprintf(gpreGlob.out_file, VTO_CALL, JRD_VTOF, value, variable, field ? field->fld_length : 0); else if (!field || field->fld_dtype == dtype_cstring) fprintf(gpreGlob.out_file, VTO_CALL, GDS_VTOV, value, variable, field ? field->fld_length : 0); else fprintf(gpreGlob.out_file, "%s = %s;", variable, value); } }
void dot_gen_shapes (FILE * file, struct node_t * node) { if (node && node->kind == stmt_k) { char * name; int i = 0; name = gen_name (node); switch (node->type.stmt) { case if_k: fprintf (file, "%s [shape=diamond];", name); break; case while_k: fprintf (file, "%s [shape=diamond];", name); break; case read_k: case write_k: case attrib_k: /* do nothing */ break; default: fprintf(stderr, "BUG\n"); exit(EXIT_FAILURE); } free(name); for (i = 0; i < MAX_CHILDREN; i++) dot_gen_shapes (file, node->child[i]); dot_gen_shapes (file, node->next); } return; }
void build_dir (int n) { int i; int fd; char *name; for (i = 0; i < n; i++) { name = gen_name(); fd = open(gen_name(), O_RDWR | O_CREAT, 0666); if (fd == -1) { perror(name); } else { close(fd); } } }
static void gen_at_end( const act* action, int column) { TEXT s[MAX_REF_SIZE]; const gpre_req* request = action->act_request; printa(column, "if (!%s) ", gen_name(s, request->req_eof)); }
string Autobits::gen_name(Macuse & mu) { Unumber v = val(mu); if (mu.children.size() != 4) throw Err(LNFUN); string bit0 = getid(mu.children[2]); string bit1 = getid(mu.children[3]); return gen_name(v, bit0, bit1); }
static void gen_variable( const act* action, int column) { char s[MAX_REF_SIZE]; align(column); fprintf(gpreGlob.out_file, "%s", gen_name(s, action->act_object)); }
void dot_emit_while (FILE * file, struct node_t * node, struct node_t * context) { char *node_name, *child_name; char * next; node_name = gen_name (node); child_name = gen_name (node->child[1]); fprintf(file, "%s -> %s [label =\"true\"];\n", node_name, child_name); dot_gen_graph (file, node->child[1], node); if (node->next) next = gen_name (node->next); else next = gen_name (context); fprintf (file, "%s -> %s [label =\"false\"];\n", node_name, next); free (next); free (node_name); free (child_name); dot_gen_graph (file, node->next, context); return; }
void generate_list(person_t* people, int number){ int random=0; //generate people randomly for(int i=0; i<number;i++){ random=rand()%MAX_AGE; gen_name((people+i)->name); (people+i)->age=random; } }
bool torture_mangle(int dummy) { static struct cli_state *cli; int i; bool ret = True; printf("starting mangle test\n"); if (!torture_open_connection(&cli, 0)) { return False; } /* we will use an internal tdb to store the names we have used */ tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); if (!tdb) { printf("ERROR: Failed to open tdb\n"); return False; } cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); cli_rmdir(cli, "\\mangle_test"); if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\mangle_test"))) { printf("ERROR: Failed to make directory\n"); return False; } for (i=0;i<torture_numops;i++) { fstring name; ZERO_STRUCT(name); gen_name(name); if (!test_one(cli, name)) { ret = False; break; } if (total && total % 100 == 0) { printf("collisions %u/%u - %.2f%% (%u failures)\r", collisions, total, (100.0*collisions) / total, failures); } } cli_unlink(cli, "\\mangle_test\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); if (!NT_STATUS_IS_OK(cli_rmdir(cli, "\\mangle_test"))) { printf("ERROR: Failed to remove directory\n"); return False; } printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", collisions, total, (100.0*collisions) / total, failures); torture_close_connection(cli); printf("mangle test finished\n"); return (ret && (failures == 0)); }
static void bhv_setTag(struct Behavior *bhv) { if (bhv->Object.Any._id) { // generics case struct Generic *gen = CAST(struct Generic*, bhv); if (bhv->id) cos_abort("generic '%s' at (%s,%d) has already an id", gen_name(gen), gen_file(gen), gen_line(gen)); if ( (bhv->Object.Any._id & COS_ID_TAGMSK) ) cos_abort("generic '%s' at (%s,%d) has invalid initialization", gen_name(gen), gen_file(gen), gen_line(gen)); bhv->id = bhv->Object.Any._id | bhv_tag(); bhv->Object.Any._id = 0; } else { // classes case
static struct lump randlump(void) { struct lump a; a.size = twister_urand(13) + 3; a.d = ezalloc(a.size); gen_name(a.d, a.size); return a; }
void dot_gen_graph (FILE * file, struct node_t * node, struct node_t * context) { char * name, * next; if (node && node->kind == stmt_k) { switch (node->type.stmt) { case if_k: dot_emit_if (file, node, context); break; case while_k: dot_emit_while (file, node, context); break; case read_k: case write_k: case attrib_k: name = gen_name (node); fprintf (file, "%s", name); if (node->next != NULL) { next = gen_name (node->next); fprintf (file, " -> %s", next); free (next); } else { if (context != NULL) { next = gen_name (context); fprintf (file, " -> %s", next); free (next); } } fprintf(file, ";\n"); free (name); dot_gen_graph (file, node->next, context); break; default: fprintf(stderr, "BUG\n"); exit(EXIT_FAILURE); } } return; }
void bg_shm_free(bg_shm_t * shm) { munmap(shm->addr, shm->size); if(shm->wr) { char name[SHM_NAME_MAX]; gen_name(shm->id, name); shm_unlink(name); } free(shm); }
static void gen_emodify( const act* action, int column) { TEXT s1[MAX_REF_SIZE], s2[MAX_REF_SIZE]; const upd* modify = (upd*) action->act_object; for (const ref* reference = modify->upd_port->por_references; reference; reference = reference->ref_next) { const ref* source = reference->ref_source; if (!source) { continue; } const gpre_fld* field = reference->ref_field; align(column); switch (field->fld_dtype) { case dtype_text: fprintf(gpreGlob.out_file, "jrd_ftof (%s, %d, %s, %d);", gen_name(s1, source), field->fld_length, gen_name(s2, reference), field->fld_length); break; case dtype_cstring: fprintf(gpreGlob.out_file, "gds__vtov((const char*) %s, (char*) %s, %d);", gen_name(s1, source), gen_name(s2, reference), field->fld_length); break; default: fprintf(gpreGlob.out_file, "%s = %s;", gen_name(s1, reference), gen_name(s2, source)); } } gen_send(action->act_request, modify->upd_port, column, false); }
int main (int argc, char *argv[]) { int rc; char *oldpath; char *newpath; punyopt(argc, argv, NULL, NULL); newpath = Option.dest; oldpath = gen_name(Option.name_size); rc = symlink(oldpath, newpath); if (rc) eprintf("symlink %s -> %s failed:", oldpath, newpath); return 0; }
gen_t oldest_query_geneneration(rdf_db *db, gen_t *reindex_gen) { int tid; gen_t gen = db->snapshots.keep; gen_t ren = GEN_MAX; query_admin *qa = &db->queries; per_thread *td = &qa->query.per_thread; DEBUG(20, if ( db->snapshots.keep != GEN_MAX ) { char buf[64]; Sdprintf("Oldest snapshot gen = %s\n", gen_name(db->snapshots.keep, buf)); });
void dot_gen_while_label(FILE * file, struct node_t * node) { char * name; if (node && node->kind == stmt_k && node->type.stmt == while_k) { name = gen_name (node); fprintf (file, "%s [label = \" ", name); dot_gen_labels (file, node->child[0]); fprintf (file, "\" ];\n"); free (name); dot_gen_labels (file, node->child[1]); } return; }
static void gen_for( const act* action, int column) { TEXT s[MAX_REF_SIZE]; gen_s_start(action, column); align(column); const gpre_req* request = action->act_request; fprintf(gpreGlob.out_file, "while (1)"); column += INDENT; begin(column); align(column); gen_receive(action->act_request, request->req_primary); align(column); fprintf(gpreGlob.out_file, "if (!%s) break;", gen_name(s, request->req_eof)); }
int fill (int n) { int i; int rc; char *name; for (i = 0; i < n; i++) { do { name = gen_name(); } while (find_string(name) != qERR_NOT_FOUND); rc = insert_string(name); if (rc != 0) { return rc; } } return 0; }
BOOL torture_mangle(struct torture_context *torture, struct smbcli_state *cli) { extern int torture_numops; int i; /* we will use an internal tdb to store the names we have used */ tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0); if (!tdb) { printf("ERROR: Failed to open tdb\n"); return False; } if (!torture_setup_dir(cli, "\\mangle_test")) { return False; } for (i=0;i<torture_numops;i++) { fstring name; ZERO_STRUCT(name); gen_name(name); if (!test_one(cli, name)) { break; } if (total && total % 100 == 0) { printf("collisions %u/%u - %.2f%% (%u failures)\r", collisions, total, (100.0*collisions) / total, failures); } } smbcli_unlink(cli->tree, "\\mangle_test\\*"); if (NT_STATUS_IS_ERR(smbcli_rmdir(cli->tree, "\\mangle_test"))) { printf("ERROR: Failed to remove directory\n"); return False; } printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n", collisions, total, (100.0*collisions) / total, failures); return (failures == 0); }
static void asgn_to( ref* reference) { TEXT s[MAX_REF_SIZE]; ref* source = reference->ref_friend; gpre_fld* field = source->ref_field; gen_name(s, source); // Repeated later down in function gen_emodify, but then // emitting jrd_ftof call. if (!field || field->fld_dtype == dtype_text) fprintf(gpreGlob.out_file, "gds__ftov (%s, %d, %s, sizeof(%s));", s, field ? field->fld_length : 0, reference->ref_value, reference->ref_value); else if (!field || field->fld_dtype == dtype_cstring) fprintf(gpreGlob.out_file, "gds__vtov((const char*) %s, (char*) %s, sizeof(%s));", s, reference->ref_value, reference->ref_value); else fprintf(gpreGlob.out_file, "%s = %s;", reference->ref_value, s); }
int mixp (int argc, char *argv[]) { int n; int i; int rc; int sum; char *name; int x; if (argc > 1) { n = atoi(argv[1]); } else { n = 10; } sum = num_recs(); for (i = 0; i < n; i++) { if (!sum || random_percent(51)) { do { name = gen_name(); } while (find_string(name) != qERR_NOT_FOUND); rc = insert_string(name); if (rc != 0) { return rc; } ++sum; x = num_recs(); aver(sum == x); } else { x = urand(sum); rc = del_ith(x);//urand(sum)); if (rc) { return rc; } --sum; x = num_recs(); aver(sum == x); } } return 0; }
int genp (int argc, char *argv[]) { int n; int i; int rc; char *name; if (argc > 1) { n = atoi(argv[1]); } else { n = 10; } for (i = 0; i < n; i++) { name = gen_name(); rc = Mknode(name, S_IFDIR); if (rc) { return rc; } } return 0; }
bg_shm_t * bg_shm_alloc_read(int id, int size) { void * addr; bg_shm_t * ret = NULL; int shm_fd; char name[SHM_NAME_MAX]; int real_size = get_real_size(size); gen_name(id, name); shm_fd = shm_open(name, O_RDWR, 0); if(shm_fd < 0) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "shm_open of %s failed: %s", name, strerror(errno)); goto fail; } if((addr = mmap(0, real_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0)) == MAP_FAILED) { bg_log(BG_LOG_ERROR, LOG_DOMAIN, "mmap failed: %s", strerror(errno)); goto fail; } ret = calloc(1, sizeof(*ret)); ret->addr = addr; ret->size = size; ret->rc = (refcounter_t*)(ret->addr + align_size(size)); ret->id = id; bg_log(BG_LOG_DEBUG, LOG_DOMAIN, "created shm segment (read) %s", name); fail: if(shm_fd >= 0) close(shm_fd); return ret; }
int genp (int argc, char *argv[]) { int n; int i; int rc; char *name; if (argc > 1) { n = atoi(argv[1]); } else { n = 10; } for (i = 0; i < n; i++) { do { name = gen_name(); } while (find_string(name) == 0); rc = insert_string(name); if (rc != 0) { return rc; } } return 0; }
/* * /wcreate - * * Creates a new world, and if requested, loads it into the current world * list. * * Permissions: * - command.world.wcreate * Needed to execute the command. */ void c_wcreate::execute (player *pl, command_reader& reader) { if (!pl->perm ("command.world.wcreate")) return; reader.add_option ("load", "l"); reader.add_option ("width", "w", true, true); reader.add_option ("depth", "d", true, true); reader.add_option ("provider", "p", true, true); reader.add_option ("generator", "g", true, true); reader.add_option ("seed", "s", true, true); if (!reader.parse (this, pl)) return; if (reader.no_args () || reader.arg_count () > 1) { this->show_summary (pl); return; } //---- /* * Parse arguments: */ // world name std::string& world_name = reader.arg (0); if (!world::is_valid_name (world_name.c_str ())) { pl->message ("§c * §eWorld names must be under §a32 §echaracters long and " "may only contain alpha§f-§enumeric characters§f, §edots§f, " "§ehyphens and underscores§f."); return; } // world width int world_width = 0; auto opt_width = reader.opt ("width"); if (opt_width->found ()) { auto& arg = opt_width->arg (0); if (!arg.is_int ()) { pl->message ("§c * §eArgument to flag §c--width §emust be an integer§f."); return; } world_width = arg.as_int (); if (world_width < 0) world_width = 0; } // world depth int world_depth = 0; auto opt_depth = reader.opt ("depth"); if (opt_depth->found ()) { auto& arg = opt_depth->arg (0); if (!arg.is_int ()) { pl->message ("§c * §eArgument to flag §c--depth §emust be an integer§f."); return; } world_depth = arg.as_int (); if (world_depth < 0) world_depth = 0; } // world provider std::string provider_name ("hw"); auto opt_prov = reader.opt ("provider"); if (opt_prov->found ()) { auto& arg = opt_prov->arg (0); provider_name.assign (arg.as_str ()); } // world generator std::string gen_name ("flatgrass"); auto opt_gen = reader.opt ("generator"); if (opt_gen->found ()) { auto& arg = opt_gen->arg (0); gen_name.assign (arg.as_str ()); } // generator seed int gen_seed = std::chrono::duration_cast<std::chrono::milliseconds> ( std::chrono::high_resolution_clock::now ().time_since_epoch ()).count () & 0x7FFFFFFF; auto opt_seed = reader.opt ("seed"); if (opt_seed->found ()) { auto& arg = opt_seed->arg (0); if (arg.is_int ()) gen_seed = arg.as_int (); else gen_seed = std::hash<std::string> () (arg.as_str ()) & 0x7FFFFFFF; } // load world bool load_world = reader.opt ("load")->found (); //---- if (load_world && (pl->get_server ().find_world (world_name.c_str ()) != nullptr)) { pl->message ("§c * §eA world with the same name is already loaded§f."); return; } world_generator *gen = world_generator::create (gen_name.c_str (), gen_seed); if (!gen) { pl->message ("§c * §eInvalid world generator§f: §c" + gen_name); return; } world_provider *prov = world_provider::create (provider_name.c_str (), "data/worlds", world_name.c_str ()); if (!prov) { pl->message ("§c * §eInvalid world provider§f: §c" + provider_name); delete gen; return; } { std::ostringstream ss; pl->message ("§eCreating a new world with the name of §a" + world_name + "§f:"); ss << "§eWorld dimensions§f: §c"; if (world_width == 0) ss << "§binf"; else ss << "§a" << world_width; ss << " §ex §a256 §ex "; if (world_depth == 0) ss << "§binf"; else ss << "§a" << world_depth; pl->message (ss.str ()); ss.clear (); ss.str (std::string ()); if ((world_width == 0) || (world_depth == 0)) ss << "§eEstimated size §f(§ewhen full§f): §cinfinite"; else { double est_kb = ((world_width * world_depth) / 256) * 7.2375 + 49.7; ss.clear (); ss.str (std::string ()); ss << "§eEstimated size §f(§ewhen full§f): §c~"; if (est_kb >= 1024.0) ss << (est_kb / 1024.0) << "MB"; else ss << est_kb << "KB"; } pl->message (ss.str ()); ss.clear (); ss.str (std::string ()); ss << "§eGenerator§f: §b" << gen_name << "§f, §eProvider§f: §b" << provider_name; pl->message (ss.str ()); ss.clear (); ss.str (std::string ()); ss << "§eWorld seed§f: §a" << gen_seed; pl->message (ss.str ()); } world *wr = new world (pl->get_server (), world_name.c_str (), pl->get_logger (), gen, prov); wr->set_width (world_width); wr->set_depth (world_depth); wr->prepare_spawn (10, true); wr->save_all (); if (load_world) { if (!pl->get_server ().add_world (wr)) { delete wr; pl->message ("§cFailed to load world§7."); } wr->start (); pl->get_server ().get_players ().message ( "§3World §b" + world_name + " §3has been loaded§b!"); } else { delete wr; } }
char * place_name(const ethnicity * e) { return gen_name(e, NAME_PLACE); }
void dot_gen_labels (FILE * file, struct node_t * node) { char *name; if (node) { switch (node->kind) { case stmt_k: switch (node->type.stmt) { case if_k: dot_gen_if_label(file, node); break; case while_k: dot_gen_while_label(file, node); break; case attrib_k: name = gen_name (node); fprintf (file, "%s [label = \"", name); fprintf (file, "%s = ", node->attr.name); dot_gen_labels (file, node->child[0]); fprintf (file, "\" ];\n"); free (name); break; case read_k: name = gen_name (node); fprintf (file, "%s [label = \"", name); fprintf(file, "leia "); dot_gen_labels (file, node->child[0]); fprintf (file, "\" ];\n"); free (name); break; case write_k: name = gen_name (node); fprintf (file, "%s [label = \"", name); fprintf(file, "escreva "); dot_gen_labels (file, node->child[0]); fprintf (file, "\" ];\n"); free (name); break; } break; case expr_k: switch (node->type.expr) { case const_k: fprintf (file, "%d", node->attr.val); break; case op_k: dot_gen_labels (file, node->child[0]); dot_print_op(file, node->attr.op); dot_gen_labels (file, node->child[1]); break; case id_k: fprintf (file, "%s", node->attr.name); break; } break; } dot_gen_labels (file, node->next); } }
char * person_name(const ethnicity * e) { return gen_name(e, NAME_PERSON); }