Пример #1
0
void rom_history_clear(rom_history_t *hist)
{
   size_t i;
   if (!hist)
      return;

   for (i = 0; i < hist->cap; i++)
      rom_history_free_entry(&hist->entries[i]);
   hist->size = 0;
}
Пример #2
0
void rom_history_free(rom_history_t *hist)
{
   size_t i;
   if (!hist)
      return;

   if (hist->conf_path)
      rom_history_write_file(hist);
   free(hist->conf_path);

   for (i = 0; i < hist->cap; i++)
      rom_history_free_entry(&hist->entries[i]);
   free(hist->entries);

   free(hist);
}
Пример #3
0
void rom_history_push(void *data,
      const char *path, const char *core_path,
      const char *core_name)
{
   size_t i;
   rom_history_t *hist = (rom_history_t*)data;

   if (!hist)
      return;

   for (i = 0; i < hist->size; i++)
   {
      bool equal_path = (!path && !hist->entries[i].path) ||
         (path && hist->entries[i].path && !strcmp(path, hist->entries[i].path));

      // Core name can have changed while still being the same core.
      // Differentiate based on the core path only.
      if (equal_path && !strcmp(hist->entries[i].core_path, core_path))
      {
         if (i == 0)
            return;

         // Seen it before, bump to top.
         struct rom_history_entry tmp = hist->entries[i];
         memmove(hist->entries + 1, hist->entries,
               i * sizeof(struct rom_history_entry));
         hist->entries[0] = tmp;
         return;
      }
   }

   if (hist->size == hist->cap)
   {
      rom_history_free_entry(&hist->entries[hist->cap - 1]);
      hist->size--;
   }

   memmove(hist->entries + 1, hist->entries,
         (hist->cap - 1) * sizeof(struct rom_history_entry));

   hist->entries[0].path      = path ? strdup(path) : NULL;
   hist->entries[0].core_path = strdup(core_path);
   hist->entries[0].core_name = strdup(core_name);
   hist->size++;
}