コード例 #1
0
ファイル: ls.c プロジェクト: cmgnn/42
t_file	*ft_open(char *name, int deep)
{
	t_dir	*entry;
	t_file	*file;
	t_file	*ret;
	DIR		*d;
	char	*tmp = NULL;

	d = opendir(name);
	ret = NULL;
	if (d)
	{
		while ((entry = readdir(d)))
		{
			if (ft_strcmp(entry->d_name, "..") && ft_strcmp(entry->d_name, "."))
			{
				file = init_file(entry->d_name);
				printf("%s\n", entry->d_name);
				if (entry->d_type & DT_DIR && deep != 0)
				{
					tmp = set_name_path(name, entry->d_name);
					file->dir = ft_open(tmp, deep - 1);
					ft_memdel((void**)&tmp);
				}
				addfile(&ret, file);
			}
		}
		closedir(d);
	}
	else
		printf("cannot acces to %s\n", name);
	return (ret);
}
コード例 #2
0
ファイル: tetri.c プロジェクト: HARM67/fillit
void		open_lst_tetri(t_app *app)
{
	int				fd;
	int				rt;
	unsigned char	*data;
	t_tetri			*cursor;

	rt = 1;
	fd = ft_open(app->av[1], O_RDONLY);
	rt = readfile(fd, &data, rt);
	app->tetri = new_tetri(idfrompiece(lire_piece(data), app->pieces));
	ft_free(data);
	cursor = app->tetri;
	rt = readfile(fd, &data, rt);
	while (rt != 0)
	{
		cursor = add_tetri(cursor, idfrompiece(lire_piece(data), app->pieces));
		ft_free(data);
		rt = readfile(fd, &data, rt);
	}
	close(fd);
	app->nb_tetri = count_tetri(app->tetri);
	if (app->nb_tetri > 26)
		ft_puterror();
	app->nb_point = app->nb_tetri * 4;
}
コード例 #3
0
ファイル: ft_bsq.c プロジェクト: MrPandawan/Piscine-C
void	ft_readbsq_file(char *av, t_caract *bsq, t_infos *elem)
{
	bsq->err = 0;
	bsq->fd = ft_open(av, bsq);
	if (bsq->err == 1)
		return ;
	bsq->st_size = ft_size_file(av, bsq->err);
	ft_buff_size(bsq);
	if (bsq->err == 1)
		return ;
	ft_check(bsq, elem);
	if (bsq->err == 1)
		return ;
	ft_position(bsq);
	if (bsq->err == 1)
		return ;
	ft_buff_int(bsq, elem, 0, 0);
	if (bsq->err == 1)
		return ;
	ft_bsq(bsq, elem, bsq->square->x, bsq->square->y);
	if (bsq->err == 1)
		return ;
	ft_print_bsq(bsq->double_buff, bsq);
	if (bsq->err == 1)
		return ;
	ft_free_all(bsq, elem);
}
コード例 #4
0
ファイル: funtab.c プロジェクト: Milkyway-at-home/nemo
nemo_main()
{
    FunctionTable *ftp;
    string fmt1, fmode = getparam("mode");
    char fmt[100];
    real x[MAX_LINES], y;
    bool Qinv;
    int i, n, mode=FUNTAB_SPLINE;

    if (hasvalue("x") && hasvalue("y")) error("Can only handle x= or y=");

    Qinv = hasvalue("y");
    if (streq(fmode,"linear")) mode = FUNTAB_LINEAR;

    if (Qinv) {
        n = nemoinpd(getparam("y"),x,MAX_LINES);
        if (n<0) error("Error # %d parsing y=; or too many?",n);
    } else {
        n = nemoinpd(getparam("x"),x,MAX_LINES);
        if (n<0) error("Error # %d parsing x=; or too many?",n);
    }
    fmt1 = getparam("format");
    sprintf(fmt,"%s %s\n",fmt1,fmt1);
    dprintf(1,"Using format=\"%s\"\n",fmt);

    if (Qinv)
        ftp = ft_open(getparam("in"), mode,
                  getiparam("ycol"), getiparam("xcol"));
    else
        ftp = ft_open(getparam("in"), mode,
                  getiparam("xcol"), getiparam("ycol"));


    for (i=0; i<n; i++) {
        if (mode == FUNTAB_LINEAR)
            y = ft_linear(ftp, x[i]);
        else if (mode == FUNTAB_SPLINE)
            y = ft_spline(ftp, x[i]);
        else
            error("Bad mode");        
        printf(fmt,x[i], y);
    }

    ft_close(ftp);                  
}
コード例 #5
0
int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
{
	dt_ops.finddevice = ft_finddevice;
	dt_ops.getprop = ft_getprop;
	dt_ops.setprop = ft_setprop;
	dt_ops.finalize = ft_finalize;

	return ft_open(&cxt, dt_blob, max_size, max_find_device,
			platform_ops.realloc);
}
コード例 #6
0
ファイル: file_in_open.c プロジェクト: Julow/libft
t_file_in		*ft_in_open(t_sub file)
{
	int				fd;
	t_file_in		*in;

	if ((fd = ft_open(file, O_RDONLY)) < 0)
		return (NULL);
	in = ft_in_fdopen(fd);
	in->opened = true;
	return (in);
}
コード例 #7
0
ファイル: io.c プロジェクト: YOKOKOYO/libft
int		main(void)
{
	int		fd = open("./io.test", O_RDWR | O_CREAT, S_IRWXU);

	write(fd, "12345678", 8);
	close(fd);
	char	*s = io_map_file(ft_open("./io.test", O_RDWR), PROT_READ | PROT_WRITE);
	char	msg[] = "patate";
	memcpy(s, msg, 6);
	io_unmap_file(s);
	return (0);
}
コード例 #8
0
ファイル: ft_main.c プロジェクト: gabfou/RT
int		main(void)
{
	t_env	e;
	int		fd;
	t_ray	ray;

	e = init_mlx(1000, 1022);
	init_env(&e);
	ray.origin = e.cam;
	fd = ft_open();
	e.list = recur_list_build(fd, NULL);
	close(fd);
	fd = ft_open();
	e.lights = recur_lights_build(fd, NULL);
	close(fd);
	e.ray = ray;
	mlx_do_key_autorepeaton(e.mlx);
	mlx_hook(e.win, 2, 1L << 0, key_hook, &e);
	mlx_expose_hook(e.win, expose_hook, &e);
	mlx_loop(e.mlx);
	return (0);
}
コード例 #9
0
int ft_init(void *dt_blob, unsigned int max_size, unsigned int max_find_device)
{
	dt_ops.finddevice = fdtm_finddevice;
	dt_ops.getprop = fdtm_getprop;
	dt_ops.setprop = fdtm_setprop;
	dt_ops.get_parent = fdtm_get_parent;
	dt_ops.create_node = fdtm_create_node;
	dt_ops.find_node_by_prop_value = fdtm_find_node_by_prop_value;
	dt_ops.finalize = fdtm_finalize;

	return ft_open(&cxt, dt_blob, max_size, max_find_device,
			platform_ops.realloc);
}
コード例 #10
0
ファイル: ls.c プロジェクト: cmgnn/42
int		main(int argc, char **argv)
{
	t_args	tmp;
	t_file	*root;

	argv++;
	if (!argc)
		ft_putstr_fd("OHHHHH my god!!!\n", 2);
	while (*argv)
	{
		if (**argv == '-')
		{
			set_options(&tmp);
		}
		else
			tmp.path = *argv;
		argv++;
	}
	root = ft_open(tmp.path, tmp.deep);
	return (ls(&tmp, root));
}
コード例 #11
0
ファイル: main.c プロジェクト: Dflk/ft_select
int			main(int ac, char **av)
{
	t_output	*output;
	t_elems		*select;
	int			fd;

	if ((fd = ft_open()) == -1)
		return (0);
	if (tgetent(NULL, getenv("TERM")) == -1)
		return (0);
	if (!(select = ft_fillselect(ac, av)))
		return (0);
	if (ft_termios(1) == -1)
		return (0);
	if ((output = ft_managedisplay(select, fd)))
	{
		ft_saveelems(select);
		ft_setsignals(output->fd);
		ft_select(select, output);
		free(ft_saveoutput(NULL));
	}
	ft_termios(0);
	return (0);
}
コード例 #12
0
ファイル: main.c プロジェクト: BenjaminSouchet/Fillit
int				main(int ac, char **av)
{
	int		fd;
	t_file	file;
	char	**tab;

	fd = 0;
	file = ft_init(file);
	tab = NULL;
	if (ac != 2)
		write(1, "usage: ./fillit input_file\n", 27);
	else
	{
		tab = ft_convert(ft_open(av[1], &fd, 0), &file.m, 0, 0);
		if (tab != NULL && ft_check(tab, file) != -1 && close(fd) != -1)
		{
			if (!(ft_resolve(tab, file, NULL)))
				write(1, "error\n", 6);
		}
		else
			write(1, "error\n", 6);
	}
	return (0);
}
コード例 #13
0
ファイル: flowy.c プロジェクト: josch/flowy2
int main(int argc, char **argv)
{
    struct ft_data *data;
    int num_threads;
    int i, ret;
    pthread_t *thread_ids;
    pthread_attr_t *thread_attrs;
    struct branch_info *binfos;
    struct group ***group_collections;
//    struct group **group_tuples;

    num_threads = 2;

    data = ft_open(STDIN_FILENO);

    binfos = (struct branch_info *)calloc(num_threads, sizeof(struct branch_info));
    if (binfos == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    /*
     * custom rules
     */

    struct filter_rule filter_rules_branch1[1] = {
        { data->offsets.dstport, 80, 0, filter_eq_uint16_t },
    };

    struct grouper_rule group_module_branch1[2] = {
        { data->offsets.srcaddr, data->offsets.srcaddr, 0, grouper_eq_uint32_t },
        { data->offsets.dstaddr, data->offsets.dstaddr, 0, grouper_eq_uint32_t },
//        { data->offsets.Last, data->offsets.First, 1, grouper_lt_uint32_t_rel }
    };

    struct grouper_aggr group_aggr_branch1[4] = {
        { 0, data->offsets.srcaddr, aggr_static_uint32_t },
        { 0, data->offsets.dstaddr, aggr_static_uint32_t },
        { 0, data->offsets.dOctets, aggr_sum_uint32_t },
        { 0, data->offsets.tcp_flags, aggr_or_uint16_t }
    };

    struct gfilter_rule gfilter_branch1[0] = {
    };

    binfos[0].data = data;
    binfos[0].filter_rules = filter_rules_branch1;
    binfos[0].num_filter_rules = 1;
    binfos[0].group_modules = group_module_branch1;
    binfos[0].num_group_modules = 2;
    binfos[0].aggr = group_aggr_branch1;
    binfos[0].num_aggr = 4;
    binfos[0].gfilter_rules = gfilter_branch1;
    binfos[0].num_gfilter_rules = 0;

    struct filter_rule filter_rules_branch2[1] = {
        { data->offsets.srcport, 80, 0, filter_eq_uint16_t },
    };

    struct grouper_rule group_module_branch2[2] = {
        { data->offsets.srcaddr, data->offsets.srcaddr, 0, grouper_eq_uint32_t },
        { data->offsets.dstaddr, data->offsets.dstaddr, 0, grouper_eq_uint32_t },
//        { data->offsets.Last, data->offsets.First, 1, grouper_lt_uint32_t_rel },
    };

    struct grouper_aggr group_aggr_branch2[4] = {
        { 0, data->offsets.srcaddr, aggr_static_uint32_t },
        { 0, data->offsets.dstaddr, aggr_static_uint32_t },
        { 0, data->offsets.dOctets, aggr_sum_uint32_t },
        { 0, data->offsets.tcp_flags, aggr_or_uint16_t }
    };

    struct gfilter_rule gfilter_branch2[0] = {
    };

    binfos[1].data = data;
    binfos[1].filter_rules = filter_rules_branch2;
    binfos[1].num_filter_rules = 1;
    binfos[1].group_modules = group_module_branch2;
    binfos[1].num_group_modules = 2;
    binfos[1].aggr = group_aggr_branch2;
    binfos[1].num_aggr = 4;
    binfos[1].gfilter_rules = gfilter_branch2;
    binfos[0].num_gfilter_rules = 0;

    /*
     * SPLITTER
     *
     * (mostly pthread stuff)
     */

    thread_ids = (pthread_t *)calloc(num_threads, sizeof(pthread_t));
    if (thread_ids == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    thread_attrs = (pthread_attr_t *)calloc(num_threads, sizeof(pthread_attr_t));
    if (thread_attrs == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    group_collections = (struct group ***)malloc(num_threads*sizeof(struct group **));
    if (group_collections == NULL) {
        perror("malloc");
        exit(EXIT_FAILURE);
    }

    for (i = 0; i < num_threads; i++) {
        ret = pthread_attr_init(&thread_attrs[i]);
        if (ret != 0) {
            errno = ret;
            perror("pthread_attr_init");
            exit(EXIT_FAILURE);
        }

        ret = pthread_create(&thread_ids[i], &thread_attrs[i], &branch_start, (void *)(&binfos[i]));
        if (ret != 0) {
            errno = ret;
            perror("pthread_create");
            exit(EXIT_FAILURE);
        }

        ret = pthread_attr_destroy(&thread_attrs[i]);
        if (ret != 0) {
            errno = ret;
            perror("pthread_attr_destroy");
            exit(EXIT_FAILURE);
        }
    }

    for (i = 0; i < num_threads; i++) {
        ret = pthread_join(thread_ids[i], (void **)(&group_collections[i]));
        if (ret != 0) {
            errno = ret;
            perror("pthread_join");
            exit(EXIT_FAILURE);
        }
    }

    exit(EXIT_SUCCESS);

    free(thread_ids);
    free(thread_attrs);
    free(binfos);

    /*
     * MERGER
     */

/*    struct merger_filter_rule mfilter[3] = {
        { 0, 0, 1, 1, 0, mfilter_equal },
        { 0, 2, 1, 2, 0, mfilter_lessthan },
    };*/

//    group_tuples = merger(group_collections, num_threads, mfilter);

    /*
     * UNGROUPER
     */

    // TODO: free group_collections at some point

    exit(EXIT_SUCCESS);
}