示例#1
0
static program_t *search_inherited(char *  str, program_t *  prg, int *  offpnt)
{
    program_t *tmp;
    int i;

    debug(d_flag, ("search_inherited started"));
    debug(d_flag, ("searching for PRG(/%s) in PRG(/%s)", str, prg->name));
    debug(d_flag, ("num_inherited=%d\n", prg->num_inherited));

    for (i = 0; i < (int) prg->num_inherited; i++) {
	debug(d_flag, ("index %d:", i));
	debug(d_flag, ("checking PRG(/%s)", prg->inherit[i].prog->name));

	if (strcmp(str, prg->inherit[i].prog->name) == 0) {
	    debug(d_flag, ("match found"));

	    *offpnt = prg->inherit[i].variable_index_offset;
	    return prg->inherit[i].prog;
	} else if ((tmp = search_inherited(str, prg->inherit[i].prog,
					  offpnt))) {
	    debug(d_flag, ("deferred match found"));

	    *offpnt += prg->inherit[i].variable_index_offset;
	    return tmp;
	}
    }
    debug(d_flag, ("search_inherited failed"));

    return (program_t *) 0;
}
示例#2
0
void
f_replace_program P2(int, num_arg, int, instruction)
{
    replace_ob_t *tmp;
    int name_len;
    char *name, *xname;
    program_t *new_prog;
    int var_offset;

    if (sp->type != T_STRING)
	bad_arg(1, instruction);
#ifdef DEBUG
    if (d_flag)
	debug_message("replace_program called\n");
#endif
    if (!current_object)
	error("replace_program called with no current object\n");
    if (current_object == simul_efun_ob)
	error("replace_program on simul_efun object\n");

    if (current_object->prog->func_ref)
	error("cannot replace a program with function references.\n");

    name_len = strlen(sp->u.string);
    name = (char *) DMALLOC(name_len + 3, TAG_TEMPORARY, "replace_program");
    xname = name;
    strcpy(name, sp->u.string);
    if (name[name_len - 2] != '.' || name[name_len - 1] != 'c')
	strcat(name, ".c");
    if (*name == '/')
	name++;
    new_prog = search_inherited(name, current_object->prog, &var_offset);
    FREE(xname);
    if (!new_prog) {
	error("program to replace the current with has to be inherited\n");
    }
    if (!(tmp = retrieve_replace_program_entry())) {
	tmp = ALLOCATE(replace_ob_t, TAG_TEMPORARY, "replace_program");
	tmp->ob = current_object;
	tmp->next = obj_list_replace;
	obj_list_replace = tmp;
    }
    tmp->new_prog = new_prog;
    tmp->var_offset = var_offset;
#ifdef DEBUG
    if (d_flag)
	debug_message("replace_program finished\n");
#endif
    free_string_svalue(sp--);
}
示例#3
0
static program_t *search_inherited P3(char *, str, program_t *, prg, int *, offpnt)
{
    program_t *tmp;
    int i;

#ifdef DEBUG
    if (d_flag) {
	debug_message("search_inherited started\n");
	debug_message("searching for PRG(%s) in PRG(%s)\n", str, prg->name);
	debug_message("num_inherited=%d\n", prg->num_inherited);
    }
#endif
    for (i = 0; i < (int) prg->num_inherited; i++) {
#ifdef DEBUG
	if (d_flag) {
	    debug_message("index %d:\n", i);
	    debug_message("checking PRG(%s)\n", prg->inherit[i].prog->name);
	}
#endif
	if (strcmp(str, prg->inherit[i].prog->name) == 0) {
#ifdef DEBUG
	    if (d_flag)
		debug_message("match found\n");
#endif
	    *offpnt = prg->inherit[i].variable_index_offset;
	    return prg->inherit[i].prog;
	} else if ((tmp = search_inherited(str, prg->inherit[i].prog,
					  offpnt))) {
#ifdef DEBUG
	    if (d_flag)
		debug_message("deferred match found\n");
#endif
	    *offpnt += prg->inherit[i].variable_index_offset;
	    return tmp;
	}
    }
#ifdef DEBUG
    if (d_flag)
	debug_message("search_inherited failed\n");
#endif
    return (program_t *) 0;
}