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(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 }