Ejemplo n.º 1
0
Archivo: new.c Proyecto: ItsJimi/42
t_mlx	*new_mlx(t_mlx *mlx, int av, char *name)
{
	mlx->w = 500;
	mlx->h = 500;
	mlx->av = av;
	mlx->menu = 0;
	mlx->mouse_on = 0;
	mlx->x1 = -1.5;
	mlx->x2 = 1.5;
	mlx->y1 = -1.5;
	mlx->y2 = 1.5;
	mlx->max = 20;
	mlx->movex = 0;
	mlx->movey = 0;
	mlx->zoom = 1;
	if (av == 6)
		mlx->max = 1;
	mlx->change_color = 0;
	if (!(mlx->mlx = mlx_init()))
		str_exit(-1, "new.c : Error line 75");
	if (!(mlx->win = mlx_new_window(mlx->mlx, mlx->w, mlx->h, str_maj(name))))
		str_exit(-1, "new.c : Error line 77");
	mlx->img = new_img(mlx);
	return (mlx);
}
Ejemplo n.º 2
0
Archivo: new.c Proyecto: ItsJimi/42
t_img	*new_xpm(t_mlx *mlx, int w, int h)
{
	t_img	*img;

	if (!(img = (t_img *)malloc(sizeof(*img))))
		str_exit(-1, "new.c : Error line 55", mlx);
	if (!(img->img = mlx_xpm_file_to_image(mlx->mlx, "skybox.xpm", &w, &h)))
		str_exit(-1, "No skybox", mlx);
	img->addr = mlx_get_data_addr(img->img, &(img->bpp), &(img->size_l),
		&(img->endian));
	return (img);
}
Ejemplo n.º 3
0
Archivo: new.c Proyecto: ItsJimi/42
t_img	*new_img(t_mlx *mlx, int width, int height)
{
	t_img	*img;

	if (!(img = (t_img *)malloc(sizeof(*img))))
		str_exit(-1, "new.c : Error line 55", mlx);
	img->img = mlx_new_image(mlx->mlx, width, height);
	img->addr = mlx_get_data_addr(img->img, &(img->bpp), &(img->size_l),
		&(img->endian));
	return (img);
}
Ejemplo n.º 4
0
Archivo: new.c Proyecto: ItsJimi/42
t_point	*new_point(int x, int y, char *z, t_mlx *mlx)
{
	t_point	*point;

	if (!(point = (t_point *)malloc(sizeof(*point))))
		str_exit(-1, "new.c : Error line 52\n", mlx);
	point->x = x;
	point->y = y;
	point->z = ft_atoi(z);
	if (point->z == 42)
	{
		mlx->beginx = x;
		mlx->beginy = y;
	}
	if (y == 0 && ft_atoi(z) != 1)
		str_exit(-1, "** ERROR MAP **", mlx);
	if (x == 0 && ft_atoi(z) != 1)
		str_exit(-1, "** ERROR MAP **", mlx);
	return (point);
}
Ejemplo n.º 5
0
Archivo: new.c Proyecto: ItsJimi/42
t_img	*new_img(t_mlx *mlx)
{
	t_img	*img;

	if (!(img = (t_img *)malloc(sizeof(*img))))
		str_exit(-1, "new.c : Error line 19");
	img->img = mlx_new_image(mlx->mlx, mlx->w, mlx->h);
	img->addr = mlx_get_data_addr(img->img, &(img->bpp), &(img->size_l),
		&(img->endian));
	return (img);
}
Ejemplo n.º 6
0
Archivo: new.c Proyecto: ItsJimi/42
t_line	*new_line(int x1, int y1, int x2, int y2)
{
	t_line	*line;

	if (!(line = (t_line *)malloc(sizeof(*line))))
		str_exit(-1, "new.c : Error line 51");
	line->x1 = x1;
	line->y1 = y1;
	line->x2 = x2;
	line->y2 = y2;
	return (line);
}
Ejemplo n.º 7
0
Archivo: new.c Proyecto: ItsJimi/42
t_mlx	*new_mlx(t_mlx *mlx, char *av)
{
	mlx->w = 2560;
	mlx->h = 1440;
	if (!(mlx->mlx = mlx_init()))
		str_exit(-1, "new.c : Error line 34");
	if (!(mlx->win = mlx_new_window(mlx->mlx, mlx->w, mlx->h, "F D F")))
		str_exit(-1, "new.c : Error line 36");
	mlx->img = new_img(mlx);
	mlx->decalx = 300;
	mlx->decaly = 300;
	mlx->perspx = 0;
	mlx->perspy = 0;
	mlx->space = 10;
	mlx->dim = 3;
	mlx->erasing = 0;
	mlx->av = av;
	mlx->menu = 0;
	mlx->change_color = 11;
	return (mlx);
}
Ejemplo n.º 8
0
Archivo: new.c Proyecto: ItsJimi/42
t_point	*new_point(int x, int y, char *z)
{
	t_point	*point;

	if (!(point = (t_point *)malloc(sizeof(*point))))
		str_exit(-1, "new.c : Error line 19");
	point->x = x;
	point->y = y;
	point->z = ft_atoi(z);
	point->color = find_color(z);
	point->savecolor = point->color;
	free(z);
	return (point);
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: Krboo/fdf
int		main(int ac, char **av)
{
	t_map *map;
	t_env *e;

	if (ac != 2 || ft_strcmp(av[1], "/dev/null") == 0 || \
	ft_strncmp(av[1], "/dev", 4) == 0)
		str_exit("Usage : ./fdf <mapfile.fdf>");
	e = (t_env *)malloc(sizeof(t_env));
	map = (t_map *)malloc(sizeof(t_map));
	e->off = XCENTER;
	e->off2 = YCENTER;
	e->zoom = 42;
	e->zh = 1;
	e->rot = 0;
	e->roty = M_PI / 2;
	map->av = av;
	e->coord = ft_get_coord(map);
	ft_mlx(e);
	free_all(e, map);
	return (0);
}
Ejemplo n.º 10
0
Archivo: key.c Proyecto: ItsJimi/42
int			key(int keycode, t_mlx *mlx)
{
	float	a;
	float	b;

	mlx->imgview->addr = ft_memset(mlx->imgview->addr, 0, mlx->w * mlx->h * 4
	- 1);
	mlx->imgmap->addr = ft_memset(mlx->imgmap->addr, 0, mlx->mapw * mlx->maph *
	4 - 1);
	a = cos(mlx->deg * (PI / 180)) / 4;
	b = sin(mlx->deg * (PI / 180)) / 4;
	key1(keycode, mlx, a, b);
	key2(keycode, mlx, a, b);
	key3(keycode, mlx, a, b);
	key4(keycode, mlx, a, b);
	if (keycode == 53)
		str_exit(0, "ESC", mlx);
	if (keycode == 0)
		mlx->deg -= 5;
	if (keycode == 2)
		mlx->deg += 5;
	draw(mlx);
	return (0);
}
Ejemplo n.º 11
0
Bool zpl_read_with_args(char** argv, int argc, Bool with_management, void* user_data)
{
   const char* options = "D:mP:sv:";

   unsigned long seed = 13021967UL;
   char**        param_table;
   int           param_count = 0;
   int           c;
   int           i;
   Prog*         prog = NULL;
   Set*          set;
   void*         lp  = NULL;
   Bool          ret = FALSE;
   char*         inppipe = NULL;
   Bool          use_startval = FALSE;
   
   stkchk_init();

   yydebug       = 0;
   yy_flex_debug = 0;
   param_table   = malloc(sizeof(*param_table));

   zpl_print_banner(stdout, FALSE);

   /* getopt might be called more than once
    */
   optind = 1;
   
   while((c = getopt(argc, argv, options)) != -1)
   {
      switch(c)
      {
      case 'D' :
         param_table =
            realloc(param_table, ((unsigned int)param_count + 1) * sizeof(*param_table));
         param_table[param_count] = strdup(optarg);

         if (verbose >= VERB_DEBUG)
            printf("Parameter %d [%s]\n", param_count, param_table[param_count]);

         param_count++;
         break;
      case 'm' :
         use_startval = TRUE;
         break;
      case 'P' :
         inppipe = strdup(optarg);
         break;
      case 's' :
         seed = (unsigned long)atol(optarg);
         break;
      case 'v' :
         verbose = atoi(optarg);
         break;
      case '?':
         fprintf(stderr, "Unknown option '%c'\n", c);
         return FALSE;
      default :
         abort();
      }
   }
   if ((argc - optind) < 1)
   {
      fprintf(stderr, "Filename missing\n");
      free(param_table);

      return FALSE;
   }

   blk_init();
   str_init();
   rand_init(seed);
   numb_init(with_management);
   elem_init();
   set_init();
   mio_init();
   interns_init();
   local_init();
   
   if (0 == setjmp( zpl_read_env))
   {
      is_longjmp_ok = TRUE;
      
      /* Make symbol to hold entries of internal variables
       */
      set = set_pseudo_new();
      (void)symbol_new(SYMBOL_NAME_INTERNAL, SYM_VAR, set, 100, NULL);
      set_free(set);
   
      /* Now store the param defines
       */
      for(i = 0; i < param_count; i++)
         zpl_add_parameter(param_table[i]);

      prog = prog_new();

      for(i = optind; i < argc; i++)
         prog_load(prog, inppipe, argv[i]);

      if (prog_is_empty(prog))
         fprintf(stderr, "*** Error 168: No program statements to execute\n");
      else
      {
         if (verbose >= VERB_DEBUG)
            prog_print(stderr, prog);
   
         lp = xlp_alloc(argv[optind], use_startval, user_data);

         prog_execute(prog, lp);

         ret = TRUE;
      }
   }
   is_longjmp_ok = FALSE;

   if (lp != NULL)
      xlp_free(lp);

   /* Now clean up. 
    */
   if (inppipe != NULL)
      free(inppipe);
   
   for(i = 0; i < param_count; i++)
      free(param_table[i]);
   free(param_table);

   if (prog != NULL)
      prog_free(prog);

   local_exit();
   interns_exit();
   mio_exit();
   symbol_exit();
   define_exit();
   set_exit();
   elem_exit();
   numb_exit();
   str_exit();
   blk_exit();

   return ret;
}
Ejemplo n.º 12
0
Bool zpl_read(const char* filename, Bool with_management, void* user_data)
{
   Prog*       prog = NULL;
   Set*        set;
   void*       lp  = NULL;
   Bool        ret = FALSE;

   stkchk_init();
   
   yydebug       = 0;
   yy_flex_debug = 0;

   zpl_print_banner(stdout, FALSE);

   blk_init();
   str_init();
   rand_init(13021967UL);
   numb_init(with_management);
   elem_init();
   set_init();
   mio_init();
   interns_init();
   local_init();
   
   if (0 == setjmp(zpl_read_env))
   {
      is_longjmp_ok = TRUE;
      
      set = set_pseudo_new();
      (void)symbol_new(SYMBOL_NAME_INTERNAL, SYM_VAR, set, 100, NULL);
      set_free(set);
   
      prog = prog_new();

      prog_load(prog, NULL, filename);

      if (prog_is_empty(prog))
         fprintf(stderr, "*** Error 168: No program statements to execute\n");
      else
      {
         if (verbose >= VERB_DEBUG)
            prog_print(stderr, prog);
   
         lp = xlp_alloc(filename, FALSE, user_data);

         prog_execute(prog, lp);

         ret = TRUE;
      }
   }
   is_longjmp_ok = FALSE;

   if (lp != NULL)
      xlp_free(lp);

   if (prog != NULL)
      prog_free(prog);

   local_exit();
   interns_exit();
   mio_exit();
   symbol_exit();
   define_exit();
   set_exit();
   elem_exit();
   numb_exit();
   str_exit();
   blk_exit();
   
   return ret;
}
Ejemplo n.º 13
0
int main(int argc, char* const* argv)
{
   Prog*         prog;
   Set*          set;
   void*         lp;
   const char*   extension = "";
   char*         filter    = strdup("%s");
   char*         outfile;
   char*         tblfile;
   char*         ordfile;
   char*         mstfile;
   char*         basefile = NULL;
   char*         inppipe  = NULL;
   char*         outpipe;
   LpFormat      format   = LP_FORM_LPF;
   FILE*         fp;
   Bool          write_order = FALSE;
   Bool          write_mst   = FALSE;
   Bool          presolve    = FALSE;
   int           name_length = 0;
   char*         prog_text;
   unsigned long seed = 13021967UL;
   char**        param_table;
   int           param_count = 0;
   int           c;
   int           i;
   FILE*         (*openfile)(const char*, const char*) = fopen;
   int           (*closefile)(FILE*)                   = fclose;

   stkchk_init();
   
   yydebug       = 0;
   yy_flex_debug = 0;
   verbose       = VERB_NORMAL;
   param_table   = malloc(sizeof(*param_table));
   
   while((c = getopt(argc, argv, options)) != -1)
   {
      switch(c)
      {
      case 'b' :
         yydebug = 1;
         break;
      case 'D' :
         param_table =
            realloc(param_table, ((unsigned int)param_count + 1) * sizeof(*param_table));
         param_table[param_count] = strdup(optarg);
         param_count++;
         break;
      case 'h' :
         zpl_print_banner(stdout, TRUE);
         printf(usage, argv[0]);
         puts(help);
         exit(0);
      case 'f' :
         yy_flex_debug = 1;
         break;
      case 'F' :
         free(filter);
         
         filter    = strdup(optarg);
         openfile  = popen;
         closefile = pclose;
         break;
      case 'l' :
         name_length = atoi(optarg);
         break;
      case 'm' :
         write_mst = TRUE;
         break;
      case 'n' :
         if (*optarg != 'c')
         {
            fprintf(stderr, usage, argv[0]);
            exit(0);
         }
         switch(optarg[1])
         {
         case 'm' :
            conname_format(CON_FORM_MAKE);
            break;
         case 'n' :
            conname_format(CON_FORM_NAME);
            break;
         case 'f' :
            conname_format(CON_FORM_FULL);
            break;
         default :
            fprintf(stderr, usage, argv[0]);
            exit(0);
         }
         break;
      case 'o' :
         basefile = strdup(optarg);
         break;
      case 'O' :
         presolve = TRUE;
         break;
      case 'P' :
         inppipe = strdup(optarg);
         break;
      case 's' :
         seed = (unsigned long)atol(optarg);
         break;
      case 'r' :
         write_order = TRUE;
         break;
      case 't' :
         switch(tolower(*optarg))
         {
         case 'h' :
            format = LP_FORM_HUM;
            break;
         case 'm' :
            format = LP_FORM_MPS;
            break;
         case 'l' :
            format = LP_FORM_LPF;
            break;
         case 'p' :
            format = LP_FORM_PIP;
            break;
         case 'r' :
            format = LP_FORM_RLP;
            break;
         default :
            if (verbose > VERB_QUIET)
               fprintf(stderr,
                  "--- Warning 103: Output format \"%s\" not supported, using LP format\n",
                  optarg);
            format = LP_FORM_LPF;
            break;
         }
         break;
      case 'v' :
         verbose = atoi(optarg);
         break;
      case 'V' :
         printf("%s\n", VERSION);
         exit(0);
      case '?':
         fprintf(stderr, usage, argv[0]);
         exit(0);
      default :
         abort();
      }
   }
   if ((argc - optind) < 1)
   {
      fprintf(stderr, usage, argv[0]);      
      exit(0);
   }

   zpl_print_banner(stdout, TRUE);
   
   if (basefile == NULL)
      basefile = strip_extension(strdup(strip_path(argv[optind])));

   switch(format)
   {
   case LP_FORM_LPF :
      extension = ".lp";
      break;
   case LP_FORM_MPS :
      extension = ".mps";
      break;
   case LP_FORM_HUM :
      extension = ".hum";
      break;
   case LP_FORM_RLP :
      extension = ".rlp";
      break;
   case LP_FORM_PIP :
      extension = ".pip";
      break;
   default :
      abort();
   }
   assert(extension != NULL);

   outfile = add_extention(basefile, extension);
   tblfile = add_extention(basefile, ".tbl");
   ordfile = add_extention(basefile, ".ord");
   mstfile = add_extention(basefile, ".mst");
   
   outpipe = malloc(strlen(basefile) + strlen(filter) + 256);

   assert(outpipe != NULL);

   blk_init();
   str_init();
   rand_init(seed);
   numb_init(TRUE);
   elem_init();
   set_init();
   mio_init();
   interns_init();
   local_init();
   
   /* Make symbol to hold entries of internal variables
    */
   set = set_pseudo_new();
   (void)symbol_new(SYMBOL_NAME_INTERNAL, SYM_VAR, set, 100, NULL);
   set_free(set);
   
   /* Now store the param defines
    */
   for(i = 0; i < param_count; i++)
      zpl_add_parameter(param_table[i]);

   /* Next we read in the zpl program(s)
    */
   prog = prog_new();

   for(i = optind; i < argc; i++)
      prog_load(prog, inppipe, argv[i]);

   if (prog_is_empty(prog))
   {
      fprintf(stderr, "*** Error 168: No program statements to execute\n");
      exit(EXIT_FAILURE);
   }
   if (verbose >= VERB_DEBUG)
      prog_print(stderr, prog);
   
   lp = xlp_alloc(argv[optind], write_mst || write_order, NULL);
   zlp_setnamelen(lp, name_length);
   
   prog_execute(prog, lp);

   /* Presolve
    */
   if (presolve)
      fprintf(stderr, "--- Warning: Presolve no longer support. If you need it, send me an email\n");
#if 0 
      if (!zlp_presolve())
         exit(EXIT_SUCCESS);
#endif
   if (verbose >= VERB_NORMAL)
      zlp_stat(lp);
   
   /* Write order file 
    */
   if (write_order)
   {
      sprintf(outpipe, filter, ordfile, "ord");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed ");
         perror(ordfile);
         exit(EXIT_FAILURE);
      }
      zlp_orderfile(lp, fp, format);
         
      check_write_ok(fp, ordfile);
         
      (void)(*closefile)(fp);
   }
   /* Write MST file 
    */
   if (write_mst)
   {
      sprintf(outpipe, filter, mstfile, "mst");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed ");
         perror(mstfile);
         exit(EXIT_FAILURE);
      }
      zlp_mstfile(lp, fp, format);
         
      check_write_ok(fp, mstfile);
         
      (void)(*closefile)(fp);
   }
   /* Write Output
    */
   sprintf(outpipe, filter, outfile, "lp");

   if (verbose >= VERB_NORMAL)
      printf("Writing [%s]\n", outpipe);

   if (NULL == (fp = (*openfile)(outpipe, "w")))
   {
      fprintf(stderr, "*** Error 104: File open failed ");
      perror(outfile);
      exit(EXIT_FAILURE);
   }
   if (format != LP_FORM_RLP)
      prog_text = prog_tostr(prog, format == LP_FORM_MPS ? "* " : "\\ ", title, 128);
   else
   {
      prog_text = malloc(strlen(title) + 4);
      
      assert(prog_text != NULL);

      sprintf(prog_text, "\\%s\n", title);
   }
   zlp_write(lp, fp, format, prog_text);

   check_write_ok(fp, outfile);

   (void)(*closefile)(fp);

   /* We do not need the translation table for human readable format
    * Has to be written after the LP file, so the scaling has been done.
    */
   if (format != LP_FORM_HUM)
   {
      /* Write translation table
       */
      sprintf(outpipe, filter, tblfile, "tbl");

      if (verbose >= VERB_NORMAL)
         printf("Writing [%s]\n", outpipe);

      if (NULL == (fp = (*openfile)(outpipe, "w")))
      {
         fprintf(stderr, "*** Error 104: File open failed");
         perror(tblfile);
         exit(EXIT_FAILURE);
      }
      zlp_transtable(lp, fp, format);

      check_write_ok(fp, tblfile);

      (void)(*closefile)(fp);
   }




   free(prog_text);
   
   if (verbose >= VERB_DEBUG) 
      symbol_print_all(stderr);

#if defined(__INSURE__) || !defined(NDEBUG) || defined(FREEMEM)
   
   /* Now clean up. 
    */
   if (inppipe != NULL)
      free(inppipe);
   
   for(i = 0; i < param_count; i++)
      free(param_table[i]);
   free(param_table);
   
   prog_free(prog);

   local_exit();
   interns_exit();
   xlp_free(lp);
   mio_exit();
   symbol_exit();
   define_exit();
   set_exit();
   elem_exit();
   numb_exit();
   str_exit();
   blk_exit();
   
   free(mstfile);
   free(ordfile);
   free(outfile);
   free(tblfile);
   free(basefile);
   free(filter);
   free(outpipe);

   if (verbose >= VERB_NORMAL)
   {
      mem_display(stdout);
      stkchk_maximum(stdout);
   }
#endif /* __INSURE__ || !NDEBUG || FREEMEM */
   return 0;
}