Example #1
0
void func_reassign_connection(void) {
    cData       * args;
    Conn * c;
    Obj     * obj;

    /* Accept a objnum. */
    if (!func_init_1(&args, OBJNUM))
        return;

    c = find_connection(cur_frame->object);
    if (c) {
        obj = cache_retrieve(args[0].u.objnum);
        if (!obj)
            THROW((objnf_id, "Object #%l does not exist.", args[0].u.objnum))
        else if (find_connection(obj)) {
            cthrow(perm_id, "Object %O already has a connection.", obj->objnum);
            cache_discard(obj);
            return;
        }
        c->objnum = obj->objnum;
        cache_discard(obj);
        cur_frame->object->conn = NULL;
        pop(1);
        push_int(1);
    } else {
Example #2
0
File: file.c Project: nrhtr/genesis
/*
// --------------------------------------------------------------------
//
// NOTE: If you send the object along, it is assumed it is the CORRECT
// object bound to this function, sending the wrong object can cause
// problems.
//
*/
void file_discard(filec_t * file, Obj * obj)
{
    filec_t **fp, *f;

    /* clear the object's file variable */
    if (obj == NULL) {
        if (file->objnum != INV_OBJNUM) {
            Obj *obj = cache_retrieve(file->objnum);

            if (obj != NULL) {
                obj->file = NULL;
                cache_discard(obj);
            }
        }
    } else {
        obj->file = NULL;
    }

    /* pull it out of the 'files' list */
    fp = &files;
    while (*fp) {
        f = *fp;
        if (f->objnum == file->objnum) {
            if (!f->f.closed)
                close_file(f);
            *fp = f->next;
            break;
        } else {
            fp = &f->next;
        }
    }

    /* toss the file proper */
    string_discard(file->path);

    efree(file);
}