home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_mru.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  2.4 KB  |  100 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include <string.h>
  25.  
  26. #include "imap_mru.h"
  27.  
  28. MRU_t* 
  29. mru_create(void)
  30. {
  31.    MRU_t *mru = g_new(MRU_t, 1);
  32.    mru->list = NULL;
  33.    mru->max_size = DEFAULT_MRU_SIZE;
  34.    return mru;
  35. }
  36.  
  37. void 
  38. mru_destruct(MRU_t *mru)
  39. {
  40.    g_list_foreach(mru->list, (GFunc) g_free, NULL);
  41.    g_free(mru);
  42. }
  43.  
  44. static void
  45. mru_remove_link(MRU_t *mru, GList *link)
  46. {
  47.    g_free(link->data);
  48.    mru->list = g_list_remove_link(mru->list, link);
  49. }
  50.  
  51. static GList*
  52. mru_find_link(MRU_t *mru, const gchar *filename)
  53. {
  54.    return g_list_find_custom(mru->list, (gpointer) filename, 
  55.                  (GCompareFunc) strcmp);
  56. }
  57.  
  58. void 
  59. mru_add(MRU_t *mru, const gchar *filename)
  60. {
  61.    if (g_list_length(mru->list) == mru->max_size)
  62.       mru_remove_link(mru, g_list_last(mru->list));
  63.    mru->list = g_list_prepend(mru->list, g_strdup(filename));
  64. }
  65.  
  66. void 
  67. mru_remove(MRU_t *mru, const gchar *filename)
  68. {
  69.    mru_remove_link(mru, mru_find_link(mru, filename));
  70. }
  71.  
  72. void
  73. mru_set_first(MRU_t *mru, const gchar *filename)
  74. {
  75.    GList *link = mru_find_link(mru, filename);
  76.    if (link)
  77.       mru->list = g_list_prepend(g_list_remove_link(mru->list, link), 
  78.                  link->data);
  79.    else
  80.       mru_add(mru, filename);
  81. }
  82.  
  83. void 
  84. mru_set_size(MRU_t *mru, gint size)
  85. {
  86.    gint diff;
  87.  
  88.    for (diff = g_list_length(mru->list) - size; diff > 0; diff--)
  89.       mru_remove_link(mru, g_list_last(mru->list));
  90.    mru->max_size = size;
  91. }
  92.  
  93. void
  94. mru_write(MRU_t *mru, FILE *out)
  95. {
  96.    GList *p;
  97.    for (p = mru->list; p; p = p->next)
  98.       fprintf(out, "(mru-entry %s)\n", (gchar*) p->data);
  99. }
  100.