示例#1
0
static dat_converter_match_key_t* dat_converter_match_key_create(
      const char* format)
{
   dat_converter_match_key_t* match_key;
   dat_converter_match_key_t* current_mk;
   char* dot;

   match_key = malloc(sizeof(*match_key));
   match_key->value = strdup(format);
   match_key->next = NULL;
   current_mk = match_key;

   dot = match_key->value;
   while (*dot++)
   {
      if (*dot == '.')
      {
         *dot++ = '\0';
         current_mk->hash = djb2_calculate(current_mk->value);
         current_mk->next = malloc(sizeof(*match_key));
         current_mk = current_mk->next;
         current_mk->value = dot;
         current_mk->next = NULL;
      }
   }
   current_mk->hash = djb2_calculate(current_mk->value);

   return match_key;
}
示例#2
0
static int cb_http_conn_default(void *data_, size_t len)
{
   http_handle_t *http = (http_handle_t*)data_;

   if (!http)
      return -1;

   http->handle = net_http_new(http->connection.handle);

   if (!http->handle)
   {
      RARCH_ERR("Could not create new HTTP session handle.\n");
      return -1;
   }

   http->cb     = NULL;

   if (http->connection.elem1[0] != '\0')
   {
      uint32_t label_hash = djb2_calculate(http->connection.elem1);

      switch (label_hash)
      {
         case CB_CORE_UPDATER_DOWNLOAD:
            http->cb = &cb_core_updater_download;
            break;
         case CB_CORE_UPDATER_LIST:
            http->cb = &cb_core_updater_list;
            break;
      }
   }

   return 0;
}
bool rarch_task_push_image_load(const char *fullpath,
      const char *type, retro_task_callback_t cb, void *user_data)
{
#if defined(HAVE_RPNG) && defined(HAVE_MENU)
   nbio_handle_t *nbio          = NULL;
   retro_task_t *t              = NULL;
   uint32_t cb_type_hash        = 0;
   struct nbio_t* handle        = NULL;

   cb_type_hash = djb2_calculate(type);

   handle = nbio_open(fullpath, NBIO_READ);

   if (!handle)
   {
      RARCH_ERR("[image load] Failed to open '%s': %s.\n",
            fullpath, strerror(errno));
      return false;
   }

   nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));

   if (!nbio)
      return false;

   nbio->handle       = handle;
   nbio->is_finished  = false;
   nbio->cb           = &cb_nbio_default;
   nbio->status       = NBIO_STATUS_TRANSFER;
   nbio->image.status = NBIO_IMAGE_STATUS_TRANSFER;

   if (cb_type_hash == CB_MENU_WALLPAPER)
      nbio->cb = &cb_nbio_image_menu_wallpaper;
   else if (cb_type_hash == CB_MENU_THUMBNAIL)
      nbio->cb = &cb_nbio_image_menu_thumbnail;

   nbio_begin_read(handle);

   t = (retro_task_t*)calloc(1, sizeof(*t));

   if (!t)
   {
      free(nbio);
      return false;
   }

   t->state = nbio;
   t->handler = rarch_task_file_load_handler;
   t->callback = cb;
   t->user_data = user_data;

   task_queue_ctl(TASK_QUEUE_CTL_PUSH, t);
#endif
   return true;
}
示例#4
0
static void dat_converter_list_append(dat_converter_list_t* dst, void* item)
{
   if (dst->count == dst->capacity)
   {
      dst->capacity <<= 1;
      dst->values = realloc(dst->values, sizeof(*dst->values) * dst->capacity);
   }
   switch (dst->type)
   {
   case DAT_CONVERTER_TOKEN_LIST:
   {
      dat_converter_token_t* token = (dat_converter_token_t*) item;
      dst->values[dst->count].token = *token;
      break;
   }
   case DAT_CONVERTER_STRING_LIST:
   {
      char* str = (char*) item;
      dst->values[dst->count].string = str;
      break;
   }
   case DAT_CONVERTER_MAP_LIST:
   {
      dat_converter_map_t* map = (dat_converter_map_t*) item;
      if (!map->key)
         dst->values[dst->count].map = *map;
      else
      {
         map->hash = djb2_calculate(map->key);
         dat_converter_bt_node_t* new_node =
            dat_converter_bt_node_insert(dst, &dst->bt_root, map);

         if (!new_node)
            return;

         dst->values[dst->count].map = *map;
         new_node->index = dst->count;
         new_node->hash = map->hash;
      }
      break;
   }
   case DAT_CONVERTER_LIST_LIST:
   {
      dat_converter_list_t* list = (dat_converter_list_t*) item;
      dst->values[dst->count].list = list;
      break;
   }
   default:
      return;
   }
   dst->count++;
}
示例#5
0
static void gl_cg_set_program_base_attrib(void *data, unsigned i)
{
   cg_shader_data_t *cg = (cg_shader_data_t*)data;
   CGparameter         param = cgGetFirstParameter(
         cg->prg[i].vprg, CG_PROGRAM);

   for (; param; param = cgGetNextParameter(param))
   {
      uint32_t semantic_hash;
      const char *semantic = NULL;
      if (cgGetParameterDirection(param) != CG_IN 
            || cgGetParameterVariability(param) != CG_VARYING)
         continue;

      semantic = cgGetParameterSemantic(param);
      if (!semantic)
         continue;

      RARCH_LOG("CG: Found semantic \"%s\" in prog #%u.\n", semantic, i);

      semantic_hash = djb2_calculate(semantic);

      switch (semantic_hash)
      {
         case SEMANTIC_TEXCOORD:
         case SEMANTIC_TEXCOORD0:
            cg->prg[i].tex     = param;
            break;
         case SEMANTIC_COLOR:
         case SEMANTIC_COLOR0:
            cg->prg[i].color   = param;
            break;
         case SEMANTIC_POSITION:
            cg->prg[i].vertex  = param;
            break;
         case SEMANTIC_TEXCOORD1:
            cg->prg[i].lut_tex = param;
            break;
      }
   }

   if (!cg->prg[i].tex)
      cg->prg[i].tex     = cgGetNamedParameter(cg->prg[i].vprg, "IN.tex_coord");
   if (!cg->prg[i].color)
      cg->prg[i].color   = cgGetNamedParameter(cg->prg[i].vprg, "IN.color");
   if (!cg->prg[i].vertex)
      cg->prg[i].vertex  = cgGetNamedParameter(cg->prg[i].vprg, "IN.vertex_coord");
   if (!cg->prg[i].lut_tex)
      cg->prg[i].lut_tex = cgGetNamedParameter(cg->prg[i].vprg, "IN.lut_tex_coord");
}
示例#6
0
/** 
 * wrap_str_to_mode:
 * @type              : Wrap type in human-readable string format.
 *
 * Translates wrap mode from human-readable string to enum mode value.
 *
 * Returns: enum mode value of wrap type.
 **/
static enum gfx_wrap_type wrap_str_to_mode(const char *wrap_mode)
{
   uint32_t wrap_mode_hash = djb2_calculate(wrap_mode);

   switch (wrap_mode_hash)
   {
      case WRAP_MODE_CLAMP_TO_BORDER:
         return RARCH_WRAP_BORDER;
      case WRAP_MODE_CLAMP_TO_EDGE:
         return RARCH_WRAP_EDGE;
      case WRAP_MODE_REPEAT:
         return RARCH_WRAP_REPEAT;
      case WRAP_MODE_MIRRORED_REPEAT:
         return RARCH_WRAP_MIRRORED_REPEAT;
   }

   RARCH_WARN("Invalid wrapping type %s. Valid ones are: clamp_to_border (default), clamp_to_edge, repeat and mirrored_repeat. Falling back to default.\n",
         wrap_mode);
   return RARCH_WRAP_DEFAULT;
}
示例#7
0
/**
 * path_is_compressed_file:
 * @path               : path
 *
 * Checks if path is a compressed file.
 *
 * Returns: true (1) if path is a compressed file, otherwise false (0).
 **/
bool path_is_compressed_file(const char* path)
{
#ifdef HAVE_COMPRESSION
   const char* file_ext   = path_get_extension(path);
   uint32_t file_ext_hash = djb2_calculate(file_ext);

   switch (file_ext_hash)
   {
#ifdef HAVE_7ZIP
      case FILE_EXT_7Z:
         return true;
#endif
#ifdef HAVE_ZLIB
      case FILE_EXT_ZIP:
         return true;
#endif
   }

#endif
   return false;
}
示例#8
0
static struct config_entry_list *config_get_entry(const config_file_t *conf,
      const char *key, struct config_entry_list **prev)
{
   struct config_entry_list *entry;
   struct config_entry_list *previous = NULL;

   uint32_t hash = djb2_calculate(key);

   if (prev)
      previous = *prev;

   for (entry = conf->entries; entry; entry = entry->next)
   {
      if (hash == entry->key_hash && !strcmp(key, entry->key))
         return entry;

      previous = entry;
   }

   if (prev)
      *prev = previous;

   return NULL;
}
示例#9
0
/** 
 * video_shader_parse_imports:
 * @conf              : Preset file to read from.
 * @shader            : Shader passes handle.
 *
 * Resolves import parameters belonging to shaders. 
 *
 * Returns: true (1) if successful, otherwise false (0).
 **/
static bool video_shader_parse_imports(config_file_t *conf,
      struct video_shader *shader)
{
   const char *id     = NULL;
   char *save         = NULL;
   char imports[1024] = {0};

   if (!config_get_array(conf, "imports", imports, sizeof(imports)))
      return true;

   for (id = strtok_r(imports, ";", &save);
         id && shader->variables < GFX_MAX_VARIABLES;
         shader->variables++, id = strtok_r(NULL, ";", &save))
   {
      uint32_t semantic_hash;
      char semantic_buf[64]   = {0};
      char wram_buf[64]       = {0};
      char input_slot_buf[64] = {0};
      char mask_buf[64]       = {0};
      char equal_buf[64]      = {0};
      char semantic[64]       = {0};
      unsigned addr           = 0;
      unsigned mask           = 0;
      unsigned equal          = 0;
      struct state_tracker_uniform_info *var = 
         &shader->variable[shader->variables];

      strlcpy(var->id, id, sizeof(var->id));

      snprintf(semantic_buf, sizeof(semantic_buf), "%s_semantic", id);
      snprintf(wram_buf, sizeof(wram_buf), "%s_wram", id);
      snprintf(input_slot_buf, sizeof(input_slot_buf), "%s_input_slot", id);
      snprintf(mask_buf, sizeof(mask_buf), "%s_mask", id);
      snprintf(equal_buf, sizeof(equal_buf), "%s_equal", id);

      if (!config_get_array(conf, semantic_buf, semantic, sizeof(semantic)))
      {
         RARCH_ERR("No semantic for import variable.\n");
         return false;
      }

      semantic_hash = djb2_calculate(semantic);

      switch (semantic_hash)
      {
         case SEMANTIC_CAPTURE:
            var->type = RARCH_STATE_CAPTURE;
            break;
         case SEMANTIC_TRANSITION:
            var->type = RARCH_STATE_TRANSITION;
            break;
         case SEMANTIC_TRANSITION_COUNT:
            var->type = RARCH_STATE_TRANSITION_COUNT;
            break;
         case SEMANTIC_CAPTURE_PREVIOUS:
            var->type = RARCH_STATE_CAPTURE_PREV;
            break;
         case SEMANTIC_TRANSITION_PREVIOUS:
            var->type = RARCH_STATE_TRANSITION_PREV;
            break;
         case SEMANTIC_PYTHON:
            var->type = RARCH_STATE_PYTHON;
            break;
         default:
            RARCH_ERR("Invalid semantic.\n");
            return false;
      }


      if (var->type != RARCH_STATE_PYTHON)
      {
         unsigned input_slot = 0;

         if (config_get_uint(conf, input_slot_buf, &input_slot))
         {
            switch (input_slot)
            {
               case 1:
                  var->ram_type = RARCH_STATE_INPUT_SLOT1;
                  break;

               case 2:
                  var->ram_type = RARCH_STATE_INPUT_SLOT2;
                  break;

               default:
                  RARCH_ERR("Invalid input slot for import.\n");
                  return false;
            }
         }
         else if (config_get_hex(conf, wram_buf, &addr))
         {
            var->ram_type = RARCH_STATE_WRAM;
            var->addr = addr;
         }
         else
         {
            RARCH_ERR("No address assigned to semantic.\n");
            return false;
         }
      }

      if (config_get_hex(conf, mask_buf, &mask))
         var->mask = mask;
      if (config_get_hex(conf, equal_buf, &equal))
         var->equal = equal;
   }

   config_get_path(conf, "import_script",
         shader->script_path, sizeof(shader->script_path));
   config_get_array(conf, "import_script_class",
         shader->script_class, sizeof(shader->script_class));

   return true;
}
示例#10
0
/** 
 * video_shader_parse_pass:
 * @conf              : Preset file to read from.
 * @pass              : Shader passes handle.
 * @i                 : Index of shader pass.
 *
 * Parses shader pass from preset file.
 *
 * Returns: true (1) if successful, otherwise false (0).
 **/
static bool video_shader_parse_pass(config_file_t *conf, struct video_shader_pass *pass, unsigned i)
{
   char shader_name[64]         = {0};
   char filter_name_buf[64]     = {0};
   char wrap_name_buf[64]       = {0};
   char wrap_mode[64]           = {0};
   char frame_count_mod_buf[64] = {0};
   char srgb_output_buf[64]     = {0};
   char fp_fbo_buf[64]          = {0};
   char mipmap_buf[64]          = {0};
   char alias_buf[64]           = {0};
   char scale_name_buf[64]      = {0};
   char attr_name_buf[64]       = {0};
   char scale_type[64]          = {0};
   char scale_type_x[64]        = {0};
   char scale_type_y[64]        = {0};
   char frame_count_mod[64]     = {0};
   struct gfx_fbo_scale *scale  = NULL;
   bool smooth                  = false;
   float fattr                  = 0.0f;
   int iattr                    = 0;

   /* Source */
   snprintf(shader_name, sizeof(shader_name), "shader%u", i);
   if (!config_get_path(conf, shader_name, pass->source.path, sizeof(pass->source.path)))
   {
      RARCH_ERR("Couldn't parse shader source (%s).\n", shader_name);
      return false;
   }
   
   /* Smooth */
   snprintf(filter_name_buf, sizeof(filter_name_buf), "filter_linear%u", i);
   if (config_get_bool(conf, filter_name_buf, &smooth))
      pass->filter = smooth ? RARCH_FILTER_LINEAR : RARCH_FILTER_NEAREST;
   else
      pass->filter = RARCH_FILTER_UNSPEC;

   /* Wrapping mode */
   snprintf(wrap_name_buf, sizeof(wrap_name_buf), "wrap_mode%u", i);
   if (config_get_array(conf, wrap_name_buf, wrap_mode, sizeof(wrap_mode)))
      pass->wrap = wrap_str_to_mode(wrap_mode);

   /* Frame count mod */
   snprintf(frame_count_mod_buf, sizeof(frame_count_mod_buf), "frame_count_mod%u", i);
   if (config_get_array(conf, frame_count_mod_buf,
            frame_count_mod, sizeof(frame_count_mod)))
      pass->frame_count_mod = strtoul(frame_count_mod, NULL, 0);

   /* FBO types and mipmapping */
   snprintf(srgb_output_buf, sizeof(srgb_output_buf), "srgb_framebuffer%u", i);
   config_get_bool(conf, srgb_output_buf, &pass->fbo.srgb_fbo);

   snprintf(fp_fbo_buf, sizeof(fp_fbo_buf), "float_framebuffer%u", i);
   config_get_bool(conf, fp_fbo_buf, &pass->fbo.fp_fbo);

   snprintf(mipmap_buf, sizeof(mipmap_buf), "mipmap_input%u", i);
   config_get_bool(conf, mipmap_buf, &pass->mipmap);

   snprintf(alias_buf, sizeof(alias_buf), "alias%u", i);
   if (!config_get_array(conf, alias_buf, pass->alias, sizeof(pass->alias)))
      *pass->alias = '\0';

   /* Scale */
   scale = &pass->fbo;
   snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type%u", i);
   config_get_array(conf, scale_name_buf, scale_type, sizeof(scale_type));

   snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_x%u", i);
   config_get_array(conf, scale_name_buf, scale_type_x, sizeof(scale_type_x));

   snprintf(scale_name_buf, sizeof(scale_name_buf), "scale_type_y%u", i);
   config_get_array(conf, scale_name_buf, scale_type_y, sizeof(scale_type_y));

   if (!*scale_type && !*scale_type_x && !*scale_type_y)
      return true;

   if (*scale_type)
   {
      strlcpy(scale_type_x, scale_type, sizeof(scale_type_x));
      strlcpy(scale_type_y, scale_type, sizeof(scale_type_y));
   }

   scale->valid   = true;
   scale->type_x  = RARCH_SCALE_INPUT;
   scale->type_y  = RARCH_SCALE_INPUT;
   scale->scale_x = 1.0;
   scale->scale_y = 1.0;

   if (*scale_type_x)
   {
      uint32_t scale_type_x_hash = djb2_calculate(scale_type_x);

      switch (scale_type_x_hash)
      {
         case SCALE_TYPE_SOURCE:
            scale->type_x = RARCH_SCALE_INPUT;
            break;
         case SCALE_TYPE_VIEWPORT:
            scale->type_x = RARCH_SCALE_VIEWPORT;
            break;
         case SCALE_TYPE_ABSOLUTE:
            scale->type_x = RARCH_SCALE_ABSOLUTE;
            break;
         default:
            RARCH_ERR("Invalid attribute.\n");
            return false;
      }
   }

   if (*scale_type_y)
   {
      uint32_t scale_type_y_hash = djb2_calculate(scale_type_y);

      switch (scale_type_y_hash)
      {
         case SCALE_TYPE_SOURCE:
            scale->type_y = RARCH_SCALE_INPUT;
            break;
         case SCALE_TYPE_VIEWPORT:
            scale->type_y = RARCH_SCALE_VIEWPORT;
            break;
         case SCALE_TYPE_ABSOLUTE:
            scale->type_y = RARCH_SCALE_ABSOLUTE;
            break;
         default:
            RARCH_ERR("Invalid attribute.\n");
            return false;
      }
   }

   snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i);
   if (scale->type_x == RARCH_SCALE_ABSOLUTE)
   {
      if (config_get_int(conf, attr_name_buf, &iattr))
         scale->abs_x = iattr;
      else
      {
         snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i);
         if (config_get_int(conf, attr_name_buf, &iattr))
            scale->abs_x = iattr;
      }
   }
   else
   {
      if (config_get_float(conf, attr_name_buf, &fattr))
         scale->scale_x = fattr;
      else
      {
         snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_x%u", i);
         if (config_get_float(conf, attr_name_buf, &fattr))
            scale->scale_x = fattr;
      }
   }

   snprintf(attr_name_buf, sizeof(attr_name_buf), "scale%u", i);
   if (scale->type_y == RARCH_SCALE_ABSOLUTE)
   {
      if (config_get_int(conf, attr_name_buf, &iattr))
         scale->abs_y = iattr;
      else
      {
         snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i);
         if (config_get_int(conf, attr_name_buf, &iattr))
            scale->abs_y = iattr;
      }
   }
   else
   {
      if (config_get_float(conf, attr_name_buf, &fattr))
         scale->scale_y = fattr;
      else
      {
         snprintf(attr_name_buf, sizeof(attr_name_buf), "scale_y%u", i);
         if (config_get_float(conf, attr_name_buf, &fattr))
            scale->scale_y = fattr;
      }
   }

   return true;
}
示例#11
0
static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio)
{
   char elem0[PATH_MAX_LENGTH];
   unsigned elem0_hash          = 0;
   uint32_t cb_type_hash        = 0;
   struct nbio_t* handle        = NULL;
   struct string_list *str_list = NULL;
   const char *path             = NULL;

   if (!nbio)
      return -1;
   
   path                         = msg_queue_pull(nbio->msg_queue);

   if (!path)
      return -1;

   /* Can only deal with one NBIO transfer at a time for now */
   if (nbio->handle)
      return -1; 

   str_list                     = string_split(path, "|"); 

   if (!str_list || (str_list->size < 1))
      goto error;

   strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
   elem0_hash = djb2_calculate(elem0);

   /* TODO/FIXME - should be able to deal with this
    * in a better way. */
   switch(elem0_hash)
   {
      case CB_MENU_WALLPAPER:
      case CB_MENU_BOXART:
         goto error;
      default:
         break;
   }

   if (str_list->size > 1)
      cb_type_hash = djb2_calculate(str_list->elems[1].data);

   handle = nbio_open(elem0, NBIO_READ);

   if (!handle)
   {
      RARCH_ERR("Could not create new file loading handle.\n");
      goto error;
   }

   nbio->handle      = handle;
   nbio->is_finished = false;
   nbio->cb          = &cb_nbio_default;

   switch (cb_type_hash)
   {
#if defined(HAVE_MENU) && defined(HAVE_RPNG)
      case CB_MENU_WALLPAPER:
         nbio->cb = &cb_nbio_image_menu_wallpaper;
         break;
      case CB_MENU_BOXART:
         nbio->cb = &cb_nbio_image_menu_boxart;
         break;
#endif
   }

   nbio_begin_read(handle);

   string_list_free(str_list);


   return 0;

error:
   if (str_list)
      string_list_free(str_list);

   return -1;
}
示例#12
0
uint32_t msg_hash_calculate(const char *s)
{
   return djb2_calculate(s);
}
示例#13
0
static bool parse_line(config_file_t *conf,
      struct config_entry_list *list, char *line)
{
   char *comment   = NULL;
   char *key       = (char*)malloc(9);
   char *key_tmp   = NULL;
   size_t cur_size = 8;
   size_t idx      = 0;

   if (!key)
      return false;

   if (!line || !*line)
   {
      free(key);
      return false;
   }

   comment = strip_comment(line);

   /* Starting line with # and include includes config files. */
   if ((comment == line) && (conf->include_depth < MAX_INCLUDE_DEPTH))
   {
      comment++;
      if (strstr(comment, "include ") == comment)
      {
         add_sub_conf(conf, comment + strlen("include "));
         free(key);
         return false;
      }
   }
   else if (conf->include_depth >= MAX_INCLUDE_DEPTH)
   {
      fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n");
   }

   /* Skips to first character. */
   while (isspace((int)*line))
      line++;

   while (isgraph((int)*line))
   {
      if (idx == cur_size)
      {
         cur_size *= 2;
         key_tmp = (char*)realloc(key, cur_size + 1);

         if (!key_tmp)
         {
            free(key);
            return false;
         }

         key = key_tmp;
      }

      key[idx++] = *line++;
   }
   key[idx] = '\0';
   list->key = key;
   list->key_hash = djb2_calculate(key);

   list->value = extract_value(line, true);
   if (!list->value)
   {
      list->key = NULL;
      free(key);
      return false;
   }

   return true;
}