Beispiel #1
0
static Eina_File *
check_bc(Eina_File *of, const char *fname, Eina_Bool *bc)
{
   if (of)
     {
        struct stat bc_stat, sc_stat;
        /* original file doesn't exist, only bytecode does, use bytecode */
        if (stat(fname, &sc_stat) < 0)
          return of;
        if (stat(eina_file_filename_get(of), &bc_stat) < 0)
          {
             /* what? */
             eina_file_close(of);
             goto generate;
          }
        /* bytecode is newer than original file, use bytecode */
        if (bc_stat.st_mtime > sc_stat.st_mtime)
          return of;
        /* bytecode is not new enough; trigger regeneration */
        eina_file_close(of);
     }
generate:
   *bc = EINA_TRUE;
   return eina_file_open(fname, EINA_FALSE);
}
Beispiel #2
0
EAPI const char *elm_code_file_path_get(Elm_Code_File *file)
{
   if (!file->file)
     return NULL;

   return eina_file_filename_get(file->file);
}
Beispiel #3
0
EAPI const char *elm_code_file_filename_get(Elm_Code_File *file)
{
   if (!file->file)
     return NULL;

   return basename((char *)eina_file_filename_get(file->file));
}
Beispiel #4
0
/**
 * @brief Function to retrieve supported languages.
 *
 * This function parses a xml file containing tvdb language data,
 * and adds it to a hash table (which it initializes).
 * The xml data will be downloaded, or (optionally) read from a file.
 *
 * If you no longer need the data, you'll have to free the hashtable
 * (with eina_hash_free()), but not the data in the table.
 *
 * @param lang_file_path Path to a XML file containing TVDB's supported languages.
 * This allows to provide a custom XML language file.
 * It is recommended to pass NULL. In this case the languages.xml file provide with
 * etvdb will be used and, if not available, the languages will be retrieved online.
 *
 * @return a pointer to a Eina hashtable on success, NULL on failure
 *
 * @ingroup Infrastructure
 */
EAPI Eina_Hash *etvdb_languages_get(const char *lang_file_path)
{
	char uri[URI_MAX];
	Download xml;
	Eina_File *file = NULL;
	Eina_Hash *hash = NULL;
	Parser_Data pdata;

	hash = eina_hash_string_superfast_new(_hash_free_cb);

	if(!hash) {
		ERR("Hash table not valid or initialized.");
		return NULL;
	}

	/* use path passed to the function or default */
	if (lang_file_path) {
		file = eina_file_open(lang_file_path, EINA_FALSE);
	}
	else {
		file = eina_file_open(DATA_LANG_FILE_XML, EINA_FALSE);
	}

	/* if no local file can be read, download xml data */
	if (file) {
		xml.len = eina_file_size_get(file);
		xml.data = eina_file_map_all(file, EINA_FILE_POPULATE);
		if(!xml.data)
			return NULL;

		DBG("Read %s file with size %d", eina_file_filename_get(file), (int)xml.len);
	}
	else {
		snprintf(uri, URI_MAX, TVDB_API_URI"/%s/languages.xml", etvdb_api_key);
		CURL_XML_DL_MEM(xml, uri) {
			ERR("Couldn't get languages from server.");
			return NULL;
		}
	}
static Eina_Bool
_load(Eina_File *ef, const char *key,
      Evas_Image_Property *prop,
      Evas_Image_Load_Opts *opts,
      void *pixels,
      int *error, Eina_Bool get_data)
{
   Eina_Bool res = EINA_FALSE;
   int w = 0, h = 0, alpha = 0;
   const char *dot1 = NULL, *dot2 = NULL, *end, *p;
   char *cmd = NULL, decoders[3][128], buf[4096];
   char *loader = "/evas/utils/evas_image_loader";
   char *img_loader = NULL;
   const char *libdir;
   // eg $libdir/evas/generic_loaders
   int cmd_len, len, decoders_num = 0, try_count = 0;
   int read_data = 0;
   char *tmpfname = NULL, *shmfname = NULL;
   DATA32 *body;
   FILE *f = NULL;

   libdir = _evas_module_libdir_get();
   cmd_len = strlen(libdir);
   cmd_len += strlen(loader);
   img_loader = alloca(cmd_len + 1);
   strcpy(img_loader, libdir);
   strcat(img_loader, loader);

   // params excluding file, key and loadopts
   cmd_len += 1024;
   cmd_len += strlen(eina_file_filename_get(ef)) * 2;
   if (key) cmd_len += strlen(key) * 2;
   cmd = alloca(cmd_len + 1);

   len = strlen(eina_file_filename_get(ef));
   if (len < 1)
     {
        *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   end = eina_file_filename_get(ef) + len;
   for (p = end - 1; p >= eina_file_filename_get(ef); p--)
     {
        if      ((!dot1) && (*p == '.')) dot1 = p;
        else if ((!dot2) && (*p == '.')) dot2 = p;
        else if ((dot1) && (dot2)) break;
    }
   if (dot2)
     {
        // double extn not too long
        if (((end - dot2) <= 10) && (!illegal_char(dot2)))
          {
             strncpy(&(decoders[decoders_num][0]), img_loader, 127);
             decoders[decoders_num][127] = 0;
             dotcat(&(decoders[decoders_num][0]), dot2);
             decoders_num++;
          }
        // single extn not too long
        if (((end - dot1) <= 5) && (!illegal_char(dot1)))
          {
             strncpy(&(decoders[decoders_num][0]), img_loader, 127);
             decoders[decoders_num][127] = 0;
             dotcat(&(decoders[decoders_num][0]), dot1);
             decoders_num++;
          }
        strncpy(decoders[decoders_num], img_loader, 127);
        decoders[decoders_num][127] = 0;
        decoders_num++;
     }
   else if (dot1)
     {
        // single extn not too long
        if (((end - dot1) <= 5) && (!illegal_char(dot1)))
          {
             strncpy(&(decoders[decoders_num][0]), img_loader, 127);
             decoders[decoders_num][127] = 0;
             dotcat(&(decoders[decoders_num][0]), dot1);
             decoders_num++;
          }
        strncpy(decoders[decoders_num], img_loader, 127);
        decoders[decoders_num][127] = 0;
        decoders_num++;
     }
   else
     {
        strncpy(decoders[decoders_num], img_loader, 127);
        decoders[decoders_num][127] = 0;
        decoders_num++;
     }

   for (try_count = 0; try_count < decoders_num; try_count++)
     {
        // FIXME: strcats could be more efficient, not that it matters much
        // here as we are about to build a cmd to exec via a shell that
        // will interpret shell stuff and path hunt that will then exec the
        // program itself that will dynamically link that will again
        // parse the arguments and finally do something...
        if (access(decoders[try_count], X_OK)) continue;

        strcpy(cmd, decoders[try_count]);
        strcat(cmd, " ");
        // filename first arg
        len = strlen(cmd);
        escape_copy(eina_file_filename_get(ef), cmd + len);
        if (!get_data)
          {
             strcat(cmd, " -head ");
          }
        if (key)
          {
             strcat(cmd, " -key ");
             len = strlen(cmd);
             escape_copy(key, cmd + len);
          }
        if (opts->scale_down_by > 1)
          {
             strcat(cmd, " -opt-scale-down-by ");
             snprintf(buf, sizeof(buf), "%i", opts->scale_down_by);
             strcat(cmd, buf);
          }
        if (opts->dpi > 0.0)
          {
             strcat(cmd, " -opt-dpi ");
             snprintf(buf, sizeof(buf), "%i", (int)(opts->dpi * 1000.0));
             strcat(cmd, buf);
          }
        if ((opts->w > 0) &&
            (opts->h > 0))
          {
             strcat(cmd, " -opt-size ");
             snprintf(buf, sizeof(buf), "%i %i", opts->w, opts->h);
             strcat(cmd, buf);
         }
        f = popen(cmd, "r");
        if (f) break;
     }
   if (!f)
     {
	*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
	return EINA_FALSE;
     }
   while (fgets(buf, sizeof(buf), f))
     {
        len = strlen(buf);
        if (len > 0)
          {
             if (buf[len - 1] == '\n') buf[len - 1] = 0;
             if (!strncmp(buf, "size ", 5))
               {
                  int tw = 0, th = 0;

                  len = sscanf(buf, "%*s %i %i", &tw, &th);
                  if (len == 2)
                    {
                       if ((tw > 0) && (th > 0))
                         {
                            w = tw;
                            h = th;
                         }
                    }
               }
             else if (!strncmp(buf, "alpha ", 6))
               {
                  int ta;

                  len = sscanf(buf, "%*s %i", &ta);
                  if (len == 1)
                    {
                       alpha = ta;
                    }
               }
             else if (!strncmp(buf, "tmpfile ", 8))
               {
                  tmpfname = buf + 8;
                  goto getdata;
               }
#ifdef HAVE_SHM_OPEN
             else if (!strncmp(buf, "shmfile ", 8))
               {
                  shmfname = buf + 8;
                  goto getdata;
               }
#endif
             else if (!strncmp(buf, "data", 4))
               {
                  read_data = 1;
                  goto getdata;
               }
             else if (!strncmp(buf, "done", 4))
               {
                  read_data = 2;
                  goto getdata;
               }
          }
     }
getdata:
   if ((!read_data) && (!tmpfname) && (!shmfname))
     {
	*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
	goto on_error;
     }
   if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE) ||
       IMG_TOO_BIG(w, h))
     {
	*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
	goto on_error;
     }

   if (!get_data)
     {
        if (alpha) prop->alpha = 1;
        prop->w = w;
        prop->h = h;
     }
   else
     {
        if ((int)prop->w != w ||
            (int)prop->h != h)
          {
             *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
             goto on_error;
          }
        body = pixels;

        if ((tmpfname) || (shmfname))
          {
             int fd = -1;

             // open
             if (tmpfname)
                fd = open(tmpfname, O_RDONLY, S_IRUSR);
#ifdef HAVE_SHM_OPEN
             else if (shmfname)
                fd = shm_open(shmfname, O_RDONLY, S_IRUSR);
#endif
             if (fd >= 0)
               {
                  void *addr;

                  eina_mmap_safety_enabled_set(EINA_TRUE);

                  // mmap
                  addr = mmap(NULL, w * h * sizeof(DATA32),
                              PROT_READ, MAP_SHARED, fd, 0);
                  if (addr != MAP_FAILED)
                    {
                       memcpy(body, addr, w * h * sizeof(DATA32));
                       munmap(addr, w * h * sizeof(DATA32));
                    }
                  // close
                  if (tmpfname)
                    {
                       close(fd);
                       unlink(tmpfname);
                    }
#ifdef HAVE_SHM_OPEN
                  else if (shmfname)
                    {
                       close(fd);
                       shm_unlink(shmfname);
                    }
#endif
               }
             else
               {
                  *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
                  goto on_error;
               }
          }
        else if (read_data)
          {
             if (fread(body, w * h * sizeof(DATA32), 1, f) != 1)
               {
                  *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
                  goto on_error;
               }
          }
     }

   res = EINA_TRUE;
   *error = EVAS_LOAD_ERROR_NONE;

 on_error:
   if (f) pclose(f);
   return res;
}
Beispiel #6
0
void
evas_model_load_file_obj(Evas_Canvas3D_Mesh *mesh, Eina_File *file)
{
   long i;
   OBJ_Counts counts;//count elements of mesh in .obj
   Eina_Bool will_check_next_char = EINA_FALSE;
   Eina_Bool first_char_is_v = EINA_FALSE;
   Eina_Bool first_char_is_f = EINA_FALSE;
   float *pos = NULL, *nor = NULL, *tex = NULL;
   int stride_pos = 0, stride_nor = 0, stride_tex = 0;
   int j, k, data_for_one_point;
   char *current, *map;
   float *_vertices_obj = NULL, *_normales_obj = NULL, *_tex_coords_obj = NULL;
   int *_triangles;

   map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);

   if (map == NULL)
     {
        ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
        return;
     }

   counts = _count_elements(map);
   _vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float));
   data_for_one_point = 1;
   if (counts.existence_of_normal)
     {
        data_for_one_point++;
        _normales_obj = malloc(counts._normal_counter * 3 * sizeof(float));
     }
   if (counts.existence_of_tex_point)
     {
        data_for_one_point++;
        _tex_coords_obj = malloc(counts._texture_point_counter * 3 * sizeof(float));
     }
   _triangles = malloc(counts._triangles_counter * 9 * sizeof(int));

   if ((map == NULL) || (_vertices_obj == NULL) || (_triangles == NULL) ||
       ((counts.existence_of_normal) && (_normales_obj == NULL)) ||
       ((counts.existence_of_tex_point) && (_tex_coords_obj == NULL)))
     {
        ERR("Allocate memory is failed.");
        free(_vertices_obj);
        free(_triangles);
        if (counts.existence_of_normal)
          free(_normales_obj);
        if (counts.existence_of_tex_point)
          free(_tex_coords_obj);
        return;
     }

   current = map;
   i = 0;
   /* put data to arrays */
   for (; *current != '\00'; i++)
     {
        if (will_check_next_char)
          {
             if (first_char_is_v)
               {
                  switch (*current)
                    {
                     case ' ':
                       PUT_DATA_TO_ARRAY(vertices, vertex)
                       i--;
                       break;
                     case 't':
                       current++;
                       if (counts.existence_of_tex_point)
                         {
                            PUT_DATA_TO_ARRAY(tex_coords, texture_point)
                         }
                       break;
                     case 'n':
                       current++;
                       if (counts.existence_of_normal)
                         {
                            PUT_DATA_TO_ARRAY(normales, normal)
                         }
                       break;
                     default:
                       break;
                    }
                  first_char_is_v = EINA_FALSE;
                  will_check_next_char = EINA_FALSE;
               }
             else if (first_char_is_f)
               {
                  char *auxiliary_pointer = current;
                  int count_of_triangles_in_line;
                  int the_first_point = counts.current_triangles_counter;

                  _analyze_face_line(auxiliary_pointer,
                                   &count_of_triangles_in_line);
                  current++;
                  i++;
                  _read_point(_triangles, 1, counts,
                              the_first_point,
                              current);

                  AFTER_NEXT_SPACE(current)

                  for (j = 0; j < count_of_triangles_in_line; j++)
                    {
                       auxiliary_pointer = current;
                       if (counts.current_triangles_counter != the_first_point)
                         {
                            ARRAY_2D(_triangles, counts.current_triangles_counter, 0, 9) = \
                            ARRAY_2D(_triangles, the_first_point, 0, 9);
                            ARRAY_2D(_triangles, counts.current_triangles_counter, 1, 9) = \
                            ARRAY_2D(_triangles, the_first_point, 1, 9);
                            ARRAY_2D(_triangles, counts.current_triangles_counter, 2, 9) = \
                            ARRAY_2D(_triangles, the_first_point, 2, 9);
                         }

                       _read_point(_triangles, 2, counts,
                                   counts.current_triangles_counter,
                                   auxiliary_pointer);
                       AFTER_NEXT_SPACE(auxiliary_pointer);
                       _read_point(_triangles, 3, counts,
                                   counts.current_triangles_counter,
                                   auxiliary_pointer);
                       AFTER_NEXT_SPACE(current);

                       counts.current_triangles_counter++;
                    }
                  first_char_is_f = EINA_FALSE;
               }
             else
               {
                  switch (*current)
                    {
                     case 'v':
                       first_char_is_v = EINA_TRUE;
                       break;
                     case 'f':
                       first_char_is_f = EINA_TRUE;
                       break;
                     case 'm':
                       will_check_next_char = EINA_FALSE;
                       break;
                     default:
                       will_check_next_char = EINA_FALSE;
                       break;
                    }
               }
          }
Beispiel #7
0
static Eina_Bool
_evas_image_file_header(Evas_Module *em, Image_Entry *ie, int *error)
{
   Evas_Image_Load_Func *evas_image_load_func = NULL;
   Eina_Bool r = EINA_TRUE;
   
   if (!evas_module_load(em)) goto load_error;
   evas_image_load_func = em->functions;
   evas_module_use(em);
   *error = EVAS_LOAD_ERROR_NONE;
   if (evas_image_load_func)
     {
        Evas_Image_Property property;
        const char *file;

        if (!ie->f)
          {
             ie->f = eina_file_open(ie->file, EINA_FALSE);
             file = ie->file;
          }
        else
          {
             file = eina_file_filename_get(ie->f);
          }
        if (!ie->f)
          {
             *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
             goto load_error;
          }

	ie->loader_data = evas_image_load_func->file_open(ie->f, ie->key,
							  &ie->load_opts,
							  &ie->animated,
							  error);
	if (!ie->loader_data)
	  {
             goto load_error;
	  }

        memset(&property, 0, sizeof (Evas_Image_Property));
        if (evas_image_load_func->file_head(ie->loader_data, &property,
                                            error) &&
            (*error == EVAS_LOAD_ERROR_NONE))
          {
             DBG("loaded file head using module '%s' (%p): %s",
                 em->definition->name, em, file);

             ie->w = property.w;
             ie->h = property.h;
             ie->scale = property.scale;
             ie->flags.alpha = property.alpha;
	     if (ie->load_opts.orientation &&
		 ie->load_opts.degree != 0)
	       ie->flags.rotated = EINA_TRUE;
             r = EINA_FALSE;
          }
        else
          {
             evas_image_load_func->file_close(ie->loader_data);
             ie->loader_data = NULL;
             evas_module_unload(em);
             INF("failed to load file head using module '%s' (%p): "
                 "%s (%s)",
                 em->definition->name, em, file, evas_load_error_str(*error));
          }
     }
   else
     {
     load_error:
        evas_module_unload(em);
        WRN("failed to load module '%s'.", em->definition->name);
     }

   return r;
}