00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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(const stp_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 stp_param_string_t *
00090 stp_string_list_find(const stp_string_list_t *list, const char *name)
00091 {
00092 return (stp_param_string_t *) stp_list_item_get_data
00093 (stp_list_get_item_by_name((const stp_list_t *)list, name));
00094 }
00095
00096 size_t
00097 stp_string_list_count(const stp_string_list_t *list)
00098 {
00099 return stp_list_get_length((const stp_list_t *)list);
00100 }
00101
00102 stp_string_list_t *
00103 stp_string_list_create_copy(const stp_string_list_t *list)
00104 {
00105 return (stp_string_list_t *) stp_list_copy((const stp_list_t *)list);
00106 }
00107
00108 stp_string_list_t *
00109 stp_string_list_create_from_params(const stp_param_string_t *list,
00110 size_t count)
00111 {
00112 size_t i = 0;
00113 stp_string_list_t *retval = stp_string_list_create();
00114 for (i = 0; i < count; i++)
00115 stp_string_list_add_string(retval, list[i].name, list[i].text);
00116 return retval;
00117 }
00118
00119 void
00120 stp_string_list_add_string(stp_string_list_t *list,
00121 const char *name,
00122 const char *text)
00123 {
00124 stp_param_string_t *new_string = stp_malloc(sizeof(stp_param_string_t));
00125 new_string->name = stp_strdup(name);
00126 new_string->text = stp_strdup(text);
00127 stp_list_item_create((stp_list_t *) list, NULL, new_string);
00128 }
00129
00130 void
00131 stp_string_list_remove_string(stp_string_list_t *list,
00132 const char *name)
00133 {
00134 stp_list_item_t *item =
00135 stp_list_get_item_by_name((const stp_list_t *) list, name);
00136 if (item)
00137 stp_list_item_destroy((stp_list_t *) list, item);
00138 }
00139
00140 int
00141 stp_string_list_is_present(const stp_string_list_t *list,
00142 const char *value)
00143 {
00144 if (list && value &&
00145 stp_list_get_item_by_name((const stp_list_t *) list, value))
00146 return 1;
00147 else
00148 return 0;
00149 }