示例#1
0
文件: vfs.c 项目: thomasloven/os4
void chroot(inode_t *node)
{
	CALLOCP(message, vfsm);
	message->m.msg_type = VFSM_CHRD;
	memcopy((uint8_t *)&message->chrd.rd, (uint8_t *)node, sizeof(inode_t));

	send2(VFS_PID,message);
	free(waitmsg(VFS_PID,0));
	
	free(message);
}
示例#2
0
文件: vfs.c 项目: thomasloven/os4
stat_t *fstat(uint32_t filp)
{
	CALLOCP(message, vfsm);
	message->m.msg_type = VFSM_FSTAT;
	message->fstat.filp = filp;
	
	send2(VFS_PID, message);
	
	vfsm *reply = (vfsm *)waitmsg(VFS_PID,0);
	memcopy((uint8_t *)&stat, (uint8_t *)&reply->fstat_reply.node, sizeof(stat_t));
	free(message);
	free(reply);
	return &stat;
}
示例#3
0
文件: vfs.c 项目: thomasloven/os4
uint32_t read(uint32_t fp, uint32_t length, char *buffer)
{
	CALLOCP(message, vfsm);
	message->m.msg_type = VFSM_READ;
	message->read.filp = fp;
	message->read.length = length;
	message->read.buffer = buffer;
	
	send2(VFS_PID, message);
	
	vfsm *reply = (vfsm *)waitmsg(VFS_PID,0);
	uint32_t ret = reply->read_reply.length;
	free(reply);
	return ret;
}
示例#4
0
文件: vfs.c 项目: thomasloven/os4
uint32_t open(char *path)
{
	CALLOCP(message, vfsm);
	message->m.msg_type = VFSM_OPEN;
	message->open.path_len = strlen(path)+1;
	message->open.path = path;
	
	send2(VFS_PID, message);
	
	vfsm *reply = waitmsg(VFS_PID,0);
	uint32_t ret = reply->open_reply.filp;
	free(message);
	free(reply);
	
	return ret;
}
示例#5
0
文件: vfs.c 项目: thomasloven/os4
dirent_t *readdir(inode_t *node, uint32_t offset)
{
	CALLOCP(message, vfsm);
	message->m.msg_type = VFSM_READDIR;
	memcopy((uint8_t *)&message->readdir.node, (uint8_t *)node, sizeof(inode_t));
	message->readdir.num = offset;
	
	send2(VFS_PID, message);
	
	vfsm *reply = waitmsg(VFS_PID,0);
	memcopy((uint8_t *)&dirent, (uint8_t *)&reply->readdir_reply.dirent, sizeof(dirent_t));
	free(message);
	free(reply);
	
	return &dirent;
}
示例#6
0
文件: vnode.c 项目: thomasloven/os4
vnode_t *get_vnode(uint32_t driver_num, uint32_t inode_num)
{
	vnode_t *vnode = find_vnode(driver_num, inode_num);
	if(!vnode)
	{
		vnode = get_free_vnode();
		vfs_msg_getnode *getnode_msg = (vfs_msg_getnode *)calloc(sizeof(vfs_msg_getnode));
		getnode_msg->msg_type = VFSM_GETNODE;
		getnode_msg->node.driver_num = driver_num;
		getnode_msg->node.inode_num = inode_num;
		send2(driver_num, getnode_msg);
		free(getnode_msg);
		getnode_msg = waitmsg(driver_num,0);
		if(getnode_msg->node.driver_num)
		{
			memcopy((uint8_t *)vnode, (uint8_t *)&getnode_msg->node, sizeof(vnode_t));
		} else {
			_syscall_printf("\nGetnode failed!",0);
		}
		free(getnode_msg);
	}
	return vnode;
}
示例#7
0
文件: readtxt.c 项目: j13s/devil
int newpigfile(char *pigname, FILE *pogfile) {
    char *pigfname = NULL, *palfname = NULL;
    int i;
    FILE *pf;


    if (!pig.current_pigname || strcmp(pig.current_pigname, pigname)
       || pogfile != pig.pogfile) { /* new pig-file */
        checkmem( pigfname = MALLOC(strlen(pigname) +
                                    strlen(init.pigpaths[init.d_ver]) + 2) );
        strcpy(pigfname, init.pigpaths[init.d_ver]);
        strcat(pigfname, "/");
        strcat(pigfname, pigname);
        strcpy(&pigfname[strlen(pigfname) - 3], "pig");

        if ( ( pf = fopen(pigfname, "rb") ) == NULL ) {
            printf("Can't open pigfile in newpigfile: '%s'\n", pigfname);
            FREE(pigfname);
            return 0;
        }

        if ( !readtxts(pf) ) {
            fclose(pf);
            FREE(pigfname);
            return 0;
        }

        if (pogfile != pig.pogfile) {
            fclose(pig.pogfile);
        }

        readpogfile(pogfile);
        pig.pogfile = pogfile;
        checkmem( palfname = MALLOC(strlen(pigname) + 1) );
        strcpy(palfname, pigname);
        palfname[strlen(palfname) - 4] = 0;

        for (i = 0; i < strlen(palfname); i++) {
            palfname[i] = toupper(palfname[i]);
        }

        for (i = 0; i < NUM_PALETTES; i++) {
            if ( !strcmp(palettes[i].name, palfname) ) {
                break;
            }
        }

        if (i == NUM_PALETTES) {
            waitmsg(TXT_CANTFINDPALETTE, palfname, palettes[i = 1].name);
        }

        FREE(palfname);
        FREE(pig.current_pigname);
        checkmem( pig.current_pigname = MALLOC(strlen(pigname) + 1) );
        strcpy(pig.current_pigname, pigname);

        if (pig.pigfile) {
            fclose(pig.pigfile);
        }

        pig.pigfile = pf;
        changepigfile(palettes[i].name);
        view.lightcolors = &palettes[i].lighttables[256 * NUM_SECURITY];
        newpalette(palettes[i].palette);
        inittxts();
    }

    return 1;
}
示例#8
0
文件: readtxt.c 项目: j13s/devil
void readpogfile(FILE *f) {
    struct POG_header head;
    struct pig_txt pt;
    unsigned short int *texture_index, i;


    if (f == NULL) {
        return;
    }

    printmsg(TXT_READINGPOGFILE);
    rewind(f);

    if (fread(&head, sizeof(struct POG_header), 1, f) != 1) {
        printmsg(TXT_POGERRORINHEADER);
        return;
    }

    if ( strncmp(head.signature, "DPOG", 4) ) {
        printmsg(TXT_POGERRORINHEADER);
        return;
    }

    checkmem( texture_index = MALLOC(sizeof(short int) * head.num_textures) );

    if (fread(texture_index, sizeof(short int), head.num_textures, f) !=
        head.num_textures) {
        FREE(texture_index);
        printmsg(TXT_POGERRORINHEADER);
        return;
    }

    for (i = 0; i < head.num_textures; i++) {
        /* the following -- is very strange */
        if (--texture_index[i] >= pig.num_pigtxts) {
            waitmsg(TXT_POGINVALIDINDEX, i, texture_index[i]);
            continue;
        }

        if (fread(&pt, 18, 1, f) != 1) {
            waitmsg(TXT_POGFILENOTCOMPLETE, i);
            FREE(texture_index);
            return;
        }

        pt.f = f;
        memset(pt.name, ' ', 8);
        strncpy(pt.name, pt.rname, 8);
        pt.name[8] = 0;
        pt.xsize = pt.rlxsize + ( (pt.ruxsize & 0x0f) << 8 );
        pt.ysize = pt.rysize + ( (pt.ruxsize & 0xf0) << 4 );

        if (pt.xsize != 64 || pt.ysize != 64) {
            waitmsg(TXT_POGINVALIDSIZE, i, pt.xsize, pt.ysize);
            continue;
        }

        pt.pigno = texture_index[i];
        pt.num_anims = pt.anim_t2 = 0;
        pt.data = NULL;
        pt.offset += head.num_textures * (18 + 2) + sizeof(struct POG_header);

        if (pig.pig_txts[texture_index[i]].data) {
            FREE(pig.pig_txts[texture_index[i]].data);
        }

        pig.pig_txts[texture_index[i]] = pt;
    }

    FREE(texture_index);
}
示例#9
0
文件: tools.c 项目: j13s/devil
/* in t is the old structure (NULL is possible), newtype is the new type1 of
   the thing and c is for the orientation */
struct thing *changething(struct thing *t, struct thing *clone, int newtype,
                          struct cube *c)
{
    struct thing *t2;
    struct point coords[3];
    int j, i, starts[11];
    size_t size = 0;
    void *data = NULL;
    struct node *n;


    if (t != NULL && newtype == t->type1) {
        return t;
    }

    switch (newtype) {
        case tt1_robot:
            size = init.d_ver >= d2_10_sw ? sizeof(struct D2_robot) :
                   sizeof(struct D1_robot);
            data = init.d_ver >=
                   d2_10_sw ? (void *)&D2_stdrobot : (void *)&D1_stdrobot;
            break;

        case tt1_hostage:
            size = sizeof(struct item);
            data = &stdhostage;
            break;

        case tt1_secretstart: /* secret start */
            size = sizeof(struct start);

            if (l->secretstart) {
                waitmsg(TXT_ONLYONESECRETSTART, l->secretstart->no);
            }

            for (n = l->sdoors.head; n->next != NULL; n = n->next) {
                if (n->d.sd->type == switch_secretexit) {
                    break;
                }
            }

            if (n->next == NULL) {
                waitmsg(TXT_NOSECRETDOORFORSTART);
            }

            data = &stdsecretstart;
            break;

        case tt1_dmstart:
        case tt1_coopstart:
            size = sizeof(struct start);
            data = newtype == tt1_dmstart ? &stdstart : &stdcoopstart;

            if (init.d_ver >= d2_10_sw && newtype == tt1_coopstart) {
                for (n = l->things.head, j = 0; n->next != NULL; n =
                         n->next) {
                    if (n->d.t->type1 == newtype) {
                        j++;
                    }
                }

                ( (struct thing *)data )->type2 = 0;

                if (j >= 4) {
                    waitmsg(TXT_TOOMANYSTARTS);
                }
            }
            else {
                for (i = 0; i < 11; i++) {
                    starts[i] = 0;
                }

                for (n = l->things.head; n->next != NULL; n = n->next) {
                    if (n->d.t->type1 == newtype && n->d.t->type2 < 11) {
                        starts[n->d.t->type2] = 1;
                    }
                }

                for (i = (newtype == 4 ? 0 : 8), j = 0;
                     i < (newtype == 4 ? 8 : 11) && !j; i++) {
                    if (starts[i] == 0) {
                        j = 1;
                        ( (struct thing *)data )->type2 = newtype ==
                                                          4 ? i : 0;
                    }
                }

                if (!j) {
                    waitmsg(TXT_TOOMANYSTARTS);
                }
            }

            break;

        case tt1_mine:
            size = sizeof(struct mine);
            data = &stdmine;
            break;

        case tt1_item:
            size = sizeof(struct item);
            data = &stditem;
            break;

        case tt1_reactor:
            size = sizeof(struct reactor);
            data = &stdreactor;
            break;

        default:
            fprintf(errf, "Unknown thingtype: %d\n", newtype);
            my_assert(0);
    }

    if (clone != NULL) {
        data = clone;
    }

    checkmem( t2 = MALLOC(size) );
    memcpy(t2, data, size);

    if (t != NULL) {
        t2->p[0] = t->p[0];
        t2->nc = t->nc;
        t2->type1 = newtype;
        t2->tagged = t->tagged;
    }
    else {
        t2->nc = NULL;
    }

    if (t != NULL) { /* orientation */
        for (j = 0; j < 9; j++) {
            t2->orientation[j] = t->orientation[j];
        }
    }
    else {
        for (j = 0; j < 3; j++) {
            coords[0].x[j] =
                c->p[wallpts[view.currwall][(view.curredge -
                                             1) & 3]]->d.p->x[j]
                - c->p[wallpts[view.currwall][view.curredge]]->d
                .p->x[j];
            coords[2].x[j] =
                c->p[wallpts[view.currwall][(view.curredge +
                                             1) & 3]]->d.p->x[j]
                - c->p[wallpts[view.currwall][view.curredge]]->d
                .p->x[j];
        }

        normalize(&coords[0]);

        for (j = 0; j < 3; j++) {
            coords[2].x[j] -= SCALAR(&coords[0], &coords[2]) * coords[0].x[j];
        }

        normalize(&coords[2]);
        VECTOR(&coords[1], &coords[2], &coords[0]);

        for (j = 0; j < 3; j++) {
            for (i = 0; i < 3; i++) {
                t2->orientation[j * 3 + i] = coords[j].x[i] * 65536;
            }
        }
    }

    if (t) {
        if (t->nc) {
            for (n = t->nc->d.c->things.head; n->next != NULL; n =
                     n->next)                   {
                if (n->d.t == t) {
                    break;
                }
            }

            if (n->next) {
                n->d.t = t2;
            }
        }

        FREE(t);
    }

    setthingpts(t2);
    setthingcube(t2);
    return t2;
}
示例#10
0
static void
FindPattern(RING * gbl,
	    int *infile,
	    int key)
{
    int foo;
    char *s;
    int next, save = *infile;
    static DYN *text;
    static HIST *History;
    static int order;		/* saves last legal search order */
    static int ok_expr;

    if (key == '/' || key == '?') {

	dyn_init(&text, BUFSIZ);
	if (!(s = dlog_string(gbl, "Target: ", LINES - 1, &text, (DYN **) 0,
			      &History, EOS, BUFSIZ))
	    || !*s) {
	    UsePattern = FALSE;
	    return;
	}
	if (key == '/')
	    order = 1;
	if (key == '?')
	    order = -1;
	next = order;

    } else if (order && (s = dyn_string(text))) {
	next = (key == 'n') ? order : -order;
    } else {
	waitmsg("No previous regular expression");
	return;
    }

    if (ok_expr)
	OLD_REGEX(ToFind);
    if ((ok_expr = NEW_REGEX(ToFind, s)) != 0) {

	UsePattern = TRUE;
	if (SamePattern(s)) {
	    if (ispunct(key))
		return;
	} else {
	    if (next < 0) ;
	    else if (JumpBackwards(infile, NumP(1)) < 0)
		return;
	}

	if (next < 0) {
	    while (JumpBackwards(infile, NumP(2)) >= 0) {
		if (FoundPattern(infile))
		    return;
	    }
	} else {
	    while (!feof(InFile)) {
		if (FoundPattern(infile))
		    return;
	    }
	}

	*infile = TopOfPage(save, &foo);
	if (JumpToLine(*infile) >= 0)
	    (void) StartPage(infile, FALSE, &foo);
	waitmsg("Expression not found");

    } else {
	order = 0;
	UsePattern = FALSE;
	BAD_REGEX(ToFind);
	showC(gbl);
    }
}