vm read_vm(int task_id) { unsigned i, top, func_id, max; int vector; char c; vm the_vm; if (dbio_scanf("%u %d %u%c", &top, &vector, &func_id, &c) != 4 || (c == ' ' ? dbio_scanf("%u%c", &max, &c) != 2 || c != '\n' : (max = DEFAULT_MAX_STACK_DEPTH, c != '\n'))) { errlog("READ_VM: Bad vm header\n"); return 0; } the_vm = new_vm(task_id, top + 1); the_vm->max_stack_size = max; the_vm->top_activ_stack = top; the_vm->root_activ_vector = vector; the_vm->func_id = func_id; for (i = 0; i <= top; i++) if (!read_activ(&the_vm->activ_stack[i], i == 0 ? vector : MAIN_VECTOR)) { errlog("READ_VM: Bad activ number %d\n", i); return 0; } return the_vm; }
static int read_db_file(void) { Objid oid; int nobjs, nprogs, nusers; Var user_list; int i, vnum, dummy; db_verb_handle h; Program *program; waif_before_loading(); if (dbio_scanf(header_format_string, &dbio_input_version) != 1) dbio_input_version = DBV_Prehistory; if (!check_version(dbio_input_version)) { errlog("READ_DB_FILE: Unknown DB version number: %d\n", dbio_input_version); return 0; } /* I use a `dummy' variable here and elsewhere instead of the `*' * assignment-suppression syntax of `scanf' because it allows more * straightforward error checking; unfortunately, the standard says that * suppressed assignments are not counted in determining the returned value * of `scanf'... */ if (dbio_scanf("%d\n%d\n%d\n%d\n", &nobjs, &nprogs, &dummy, &nusers) != 4) { errlog("READ_DB_FILE: Bad header\n"); return 0; } user_list = new_list(nusers); for (i = 1; i <= nusers; i++) { user_list.v.list[i].type = TYPE_OBJ; user_list.v.list[i].v.obj = dbio_read_objid(); } dbpriv_set_all_users(user_list); oklog("LOADING: Reading %d objects...\n", nobjs); for (i = 1; i <= nobjs; i++) { if (!read_object()) { errlog("READ_DB_FILE: Bad object #%d.\n", i - 1); return 0; } if (i % 10000 == 0 || i == nobjs) oklog("LOADING: Done reading %d objects ...\n", i); } if (!validate_hierarchies()) { errlog("READ_DB_FILE: Errors in object hierarchies.\n"); return 0; } oklog("LOADING: Reading %d MOO verb programs...\n", nprogs); for (i = 1; i <= nprogs; i++) { if (dbio_scanf("#%d:%d\n", &oid, &vnum) != 2) { errlog("READ_DB_FILE: Bad program header, i = %d.\n", i); return 0; } if (!valid(oid)) { errlog("READ_DB_FILE: Verb for non-existant object: #%d:%d.\n", oid, vnum); return 0; } h = db_find_indexed_verb(oid, vnum + 1); /* DB file is 0-based. */ if (!h.ptr) { errlog("READ_DB_FILE: Unknown verb index: #%d:%d.\n", oid, vnum); return 0; } program = dbio_read_program(dbio_input_version, fmt_verb_name, &h); if (!program) { errlog("READ_DB_FILE: Unparsable program #%d:%d.\n", oid, vnum); return 0; } db_set_verb_program(h, program); if (i % 5000 == 0 || i == nprogs) oklog("LOADING: Done reading %d verb programs...\n", i); } oklog("LOADING: Reading forked and suspended tasks...\n"); if (!read_task_queue()) { errlog("READ_DB_FILE: Can't read task queue.\n"); return 0; } oklog("LOADING: Reading list of formerly active connections...\n"); if (!read_active_connections()) { errlog("DB_READ: Can't read active connections.\n"); return 0; } waif_after_loading(); return 1; }
static int read_object(void) { Objid oid; Object *o; char s[20]; int i; Verbdef *v, **prevv; int nprops; if (dbio_scanf("#%d", &oid) != 1 || oid != db_last_used_objid() + 1) return 0; dbio_read_line(s, sizeof(s)); if (strcmp(s, " recycled\n") == 0) { dbpriv_new_recycled_object(); return 1; } else if (strcmp(s, "\n") != 0) return 0; o = dbpriv_new_object(); o->name = dbio_read_string_intern(); (void) dbio_read_string(); /* discard old handles string */ o->flags = dbio_read_num(); o->owner = dbio_read_objid(); o->location = dbio_read_objid(); o->contents = dbio_read_objid(); o->next = dbio_read_objid(); o->lastcontents = NOTHING; o->parent = dbio_read_objid(); o->child = dbio_read_objid(); o->sibling = dbio_read_objid(); o->lastchild = NOTHING; o->verbdefs = 0; prevv = &(o->verbdefs); for (i = dbio_read_num(); i > 0; i--) { v = mymalloc(sizeof(Verbdef), M_VERBDEF); read_verbdef(v); *prevv = v; prevv = &(v->next); } o->propdefs.cur_length = 0; o->propdefs.max_length = 0; o->propdefs.l = 0; if ((i = dbio_read_num()) != 0) { o->propdefs.l = mymalloc(i * sizeof(Propdef), M_PROPDEF); o->propdefs.cur_length = i; o->propdefs.max_length = i; for (i = 0; i < o->propdefs.cur_length; i++) o->propdefs.l[i] = read_propdef(); } nprops = dbio_read_num(); if (nprops) o->propval = mymalloc(nprops * sizeof(Pval), M_PVAL); else o->propval = 0; for (i = 0; i < nprops; i++) { read_propval(o->propval + i); } return 1; }