コード例 #1
0
ファイル: parser.c プロジェクト: gabfou/RT
int		parse_exp(t_list **tokens)
{
	if (parse_scene(tokens) == 0)
		return (0);
	if (parse_object(tokens) == 0)
		return (0);
	return (1);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: amitnahum/graphics-raytracer
int main(int argc, const char * argv[]) {
    FILE *f;
    char object_name[256];
    Scene *s = new Scene();
    Light *light;
    Sphere *sphere;
    Plane *plane;
    int lights_loc=0;
    int spheres_loc=0;
    int planes_loc=0;
    f =fopen(filename, "r" );
    if (f==NULL) {
        printf("%s not found",filename);
    }
    unsigned int number_of_lines = 0;
    int ch;
    
    while (EOF != (ch=getc(f)))
        if ('\n' == ch)
            ++number_of_lines;
    printf("%u\n", number_of_lines);
    fseek(f, 0, SEEK_SET);
    fseek(f, 5, SEEK_CUR);

    parse_scene(f,s);
    for (int i=0; i<number_of_lines ; i++) {
        printf("loop number: %d",i);
        fscanf(f,"%5s ", object_name);
        if (strcmp(object_name,"light")==0){ //equal
            printf("light detected");
            light = new Light();
            parse_light(f, light);
            lights[lights_loc++]=*light;
        }
        else if (strcmp(object_name,"spher")==0) {
            printf("sphere detected\n");
            sphere = new Sphere();
            parse_sphere(f, sphere);
            spheres[spheres_loc++]=*sphere;
        }
        else if (strcmp(object_name,"plane")==0) {
            printf("plane detected\n");
            plane = new Plane();
            parse_plane(f, plane);
            planes[planes_loc++]=*plane;
        }
        else {
            printf("Syntax input error - parser fail");
            break;
        }
    }
    fclose(f);
    
}
コード例 #3
0
ファイル: load_scenes.c プロジェクト: Julow/rtv1
static bool	parse_scenes(t_xml_parser *xml, t_vector *dst)
{
	while (ft_xml_next(xml))
		if (xml->token != XML_TOKEN_START)
			return (ASSERT(false));
		else if (!ft_subequ(ft_xml_name(xml), SUBC("scene")))
			return (ft_xml_error(xml, SUBC("Invalid markup")));
		else if (!parse_scene(xml, ft_vpush(dst, NULL, 1)))
			return (false);
	return (BOOL_OF(xml->token != XML_TOKEN_ERROR));
}
コード例 #4
0
ファイル: parser.c プロジェクト: kube/RT
void		parse_file(char *file_name)
{
	int		file;

	file = open(file_name, O_RDONLY);
	if (file > -1)
		parse_scene(file);
	else
	{
		ft_putendl_fd("Failed opening file.", 2);
		exit(1);
	}
}
コード例 #5
0
ファイル: parse_file.c プロジェクト: Sorikairo/Raytracer
void		parse_file(const int sfd, const char *filename, t_img_buff *cl)
{
  int		fd;
  t_file	*file;
  t_scene	scene;
  char		*buff;
  int		len;

  if ((fd = open(filename, O_RDONLY)) < 0)
    exit(EXIT_FAILURE);
  file = fd_open_file(fd, FILE_R);
  init_scene_client(&scene);
  if (!parse_scene(&scene, file))
    exit(0);
  cl->img = NULL;
  buff = xmalloc_and_set(NULL, sizeof(*buff) * 10);
  fprintf(stdout, "Parsing done.\nWaiting for server...\n");
  if ((len = read(sfd, buff, 9)) < 0)
    return;
  buff[len] = 0;
  cl->cli_max = atoi(buff);
  get_coord(&scene, cl);
}