예제 #1
0
파일: filler.c 프로젝트: Gryshchenko/filler
void		ft_read_from_terminal(t_filler *list, t_map *a, t_pie *a_p)
{
	char	*s;

	s = (void*)0;
	a->i = 0;
	a_p->i = 0;
	list->pie_found = 0;
	get_next_line(0, &s);
	if (!ft_strncmp(s, "$$$ exec p", 9) && (s[10] == '1' || s[10] == '2'))
		ft_players_detection(list, s);
	ft_strdel(&s);
	while (get_next_line(0, &s) == 1)
	{
		if (!ft_strncmp(s, "Piece", 5))
		{
			ft_array_piece_size(list, s);
			list->pie_found = 1;
		}
		else if (!ft_strncmp(s, "Plateau", 7))
			ft_array_size(list, s);
		else if (ft_strncmp(s, "Piece", 5) && ft_strncmp(s, "Plateau", 7)
				&& ft_strncmp(s, "    01", 6))
			ft_array_creat(list, a, a_p, s);
		free(s);
	}
}
예제 #2
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_destroy()
 * This will close and destroy all file descriptors in the file table. Should
 * only be called when the thread is exiting. In theory there shouldn't be
 * anything in here, except the stds, if they are attached to the thread.
 */
int ft_destroy(struct filetable* ft) {
    int i;
    for (i = ft_array_size(ft) - 1; i >= 0; i--) {
        ft_remove(ft, i);
    }
    kfree(ft);
    return 1;
}
예제 #3
0
파일: filetable.c 프로젝트: billxinli/cs350
int ft_set(struct filetable* ft, struct filedescriptor* fd, int fti) {
    if (fti >= ft_array_size(ft)) {
        return 1;
    }
    array_setguy(ft->filedescriptor, fti, fd);
    if (ft_get(ft, fti) == fd) {
        return 1;
    }
    return 0;
}
예제 #4
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_test()
 * This tests the implementation of the file table, insertion, deletion, fd recovery.
 * This test is not passable, it will crash the kernel.
 */
void ft_test(struct filetable* ft) {
    kprintf("filetable test begin\n");
    kprintf("inserting file descriptors\n");
    ft_attachstds(ft);
    kprintf("printing file descriptors\n");
    int i = 0;
    for (i = 0; i < ft_array_size(ft); i++) {
        struct filedescriptor *fd;
        fd = ft_get(ft, i);
        kprintf("filetable index: %d\n", i);
        kprintf("fdn: %d   ", fd->fdn);
        kprintf("\n");
    }
    kprintf("inserting more file descriptors\n");
    ft_attachstds(ft);
    kprintf("printing file descriptors\n");
    for (i = 0; i < ft_array_size(ft); i++) {
        struct filedescriptor *fd;
        fd = ft_get(ft, i);
        kprintf("filetable index: %d ", i);
        kprintf("fdn: %d ", fd->fdn);
        kprintf("\n");
    }
    kprintf("removing file descriptor 4\n");
    ft_remove(ft, 4);
    kprintf("inserting more file descriptors\n");
    ft_attachstds(ft);
    kprintf("printing file descriptors\n");
    for (i = 0; i < ft_array_size(ft); i++) {
        struct filedescriptor *fd;
        fd = ft_get(ft, i);
        kprintf("filetable index: %d ", i);
        kprintf("fdn: %d ", fd->fdn);
        kprintf("\n");
    }
    kprintf("inserting infinite number of file descriptors\n");
    for (i = 0; i < 2147483647; i++) {
        kprintf("ft_array_size: %d\n", ft_array_size(ft));
        ft_attachstds(ft);
    }   
    panic("test end");
}
예제 #5
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_size()
 * This returns how many file descriptors are opened to the thread.
 */
int ft_size(struct filetable *ft) {
    assert(ft != NULL);
    int total = array_getnum(ft->filedescriptor);
    int i = 0;
    for (i = 0; i < ft_array_size(ft); i++) {
        if (ft_get(ft, i) == NULL) {
            total--;
        }
    }
    return total;
}
예제 #6
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_test()
 * This tests the implementation of the file table, insertion, deletion, fd recovery.
 * This test is not passable, it will crash the kernel.
 */
void ft_test_list(struct filetable* ft) {
    kprintf("printing file descriptors\n");
    int i = 0;
    for (i = 0; i < ft_array_size(ft); i++) {
        struct filedescriptor *fd;
        fd = ft_get(ft, i);
        kprintf("filetable index: %d         ", i);

        if (fd != NULL) {
            kprintf("fdn: %d   ", fd->fdn);
        } else {
            kprintf("fdn: NULL   ");
        }
        kprintf("\n");
    }
}
예제 #7
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_add()
 * This adds the file descriptor to the file table, it does by checking if there
 * is a free file descriptor in the queue, if not, it will add to the end of the
 * array. This will recover and reuse closed file descriptor ids.
 */
int ft_add(struct filetable* ft, struct filedescriptor* fd) {
    int fdn = 0;
    for (fdn = 0; fdn < ft_array_size(ft) && fdn < OPEN_MAX; fdn++) {
        if (ft_get(ft, fdn) == NULL) {
            array_setguy(ft->filedescriptor, fdn, fd);
            return fdn;
        }
    }
    if (fdn == OPEN_MAX) {
        return -1;
    }
    if (array_add(ft->filedescriptor, fd) != 0) { //if error (ENOMEM)
        return -1;
    }
    fd->numOwners++;
    assert(fdn != 0);
    return fdn;
}
예제 #8
0
파일: filetable.c 프로젝트: billxinli/cs350
/*
 * ft_get()
 * This gets the file descriptor from a file table and the given file descriptor id.
 */
struct filedescriptor *ft_get(struct filetable *ft, int fti) {
    if (fti < 0) {
        return NULL;
    }
    //Since the stds are not attached to the thread, if the fd <=2 is requested,
    //then we will attach the stds to the thread.
    if (fti < 3) {
        if (array_getguy(ft->filedescriptor, fti) == NULL) {
            ft_attachstds(ft);
        }
    }
    //Doesn't exist.
    if (fti >= ft_array_size(ft)) { //changed > to >= since there shouldn't be an element ARRAY_SIZE --Matt
        return NULL;
    }
    struct filedescriptor *ret = array_getguy(ft->filedescriptor, fti);
    return ret;
}