Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

src/main/string-list.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: string-list.c,v 1.15 2004/04/25 12:17:54 rleigh Exp $"
00003  *
00004  *   Print plug-in driver utility functions for the GIMP.
00005  *
00006  *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
00007  *      Robert Krawitz (rlk@alum.mit.edu)
00008  *
00009  *   This program is free software; you can redistribute it and/or modify it
00010  *   under the terms of the GNU General Public License as published by the Free
00011  *   Software Foundation; either version 2 of the License, or (at your option)
00012  *   any later version.
00013  *
00014  *   This program is distributed in the hope that it will be useful, but
00015  *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00016  *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00017  *   for more details.
00018  *
00019  *   You should have received a copy of the GNU General Public License
00020  *   along with this program; if not, write to the Free Software
00021  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 #include <gimp-print/gimp-print.h>
00028 #include "gimp-print-internal.h"
00029 #include <gimp-print/gimp-print-intl-internal.h>
00030 #include <string.h>
00031 
00032 static void
00033 free_list_element(void *item)
00034 {
00035   stp_param_string_t *string = (stp_param_string_t *) (item);
00036   stp_free((char *) string->name);
00037   stp_free((char *) string->text);
00038   stp_free(string);
00039 }
00040 
00041 static const char *
00042 namefunc(const void *item)
00043 {
00044   const stp_param_string_t *string = (const stp_param_string_t *) (item);
00045   return string->name;
00046 }
00047 
00048 static void *
00049 copyfunc(const void *item)
00050 {
00051   const stp_param_string_t *string = (const stp_param_string_t *) (item);
00052   stp_param_string_t *new_string = stp_malloc(sizeof(stp_param_string_t));
00053   new_string->name = stp_strdup(string->name);
00054   new_string->text = stp_strdup(string->text);
00055   return new_string;
00056 }
00057 
00058 static const char *
00059 long_namefunc(const void *item)
00060 {
00061   const stp_param_string_t *string = (const stp_param_string_t *) (item);
00062   return string->text;
00063 }
00064 
00065 stp_string_list_t
00066 stp_string_list_create(void)
00067 {
00068   stp_list_t *ret = stp_list_create();
00069   stp_list_set_freefunc(ret, free_list_element);
00070   stp_list_set_namefunc(ret, namefunc);
00071   stp_list_set_copyfunc(ret, copyfunc);
00072   stp_list_set_long_namefunc(ret, long_namefunc);
00073   return (stp_string_list_t) ret;
00074 }
00075 
00076 void
00077 stp_string_list_destroy(stp_string_list_t list)
00078 {
00079   stp_list_destroy((stp_list_t *) list);
00080 }
00081 
00082 stp_param_string_t *
00083 stp_string_list_param(stp_const_string_list_t list, size_t element)
00084 {
00085   return (stp_param_string_t *) stp_list_item_get_data
00086     (stp_list_get_item_by_index((const stp_list_t *)list, element));
00087 }
00088 
00089 size_t
00090 stp_string_list_count(stp_const_string_list_t list)
00091 {
00092   return stp_list_get_length((const stp_list_t *)list);
00093 }
00094 
00095 stp_string_list_t
00096 stp_string_list_create_copy(stp_const_string_list_t list)
00097 {
00098   return (stp_string_list_t) stp_list_copy((const stp_list_t *)list);
00099 }
00100 
00101 stp_string_list_t
00102 stp_string_list_create_from_params(const stp_param_string_t *list,
00103                                    size_t count)
00104 {
00105   size_t i = 0;
00106   stp_string_list_t retval = stp_string_list_create();
00107   for (i = 0; i < count; i++)
00108     stp_string_list_add_string(retval, list[i].name, list[i].text);
00109   return retval;
00110 }
00111 
00112 void
00113 stp_string_list_add_string(stp_string_list_t list,
00114                            const char *name, const char *text)
00115 {
00116   stp_param_string_t *new_string = stp_malloc(sizeof(stp_param_string_t));
00117   new_string->name = stp_strdup(name);
00118   new_string->text = stp_strdup(text);
00119   stp_list_item_create((stp_list_t *) list, NULL, new_string);
00120 }
00121 
00122 int
00123 stp_string_list_is_present(stp_const_string_list_t list, const char *value)
00124 {
00125   if (list && value)
00126     {
00127       size_t i = 0;
00128       size_t count = stp_string_list_count(list);
00129       for (i = 0; i < count; i++)
00130         {
00131           stp_param_string_t *p = stp_string_list_param(list, i);
00132           if (strcmp(p->name, value) == 0)
00133             return 1;
00134         }
00135     }
00136   return 0;
00137 }

Generated on Wed May 12 20:21:33 2004 for libgimpprint API Reference by doxygen1.2.17