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

src/main/print-vars.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: print-vars.c,v 1.71 2004/05/07 19:20:33 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 /*
00025  * This file must include only standard C header files.  The core code must
00026  * compile on generic platforms that don't support glib, gimp, gtk, etc.
00027  */
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 #include <math.h>
00033 #ifdef HAVE_LIMITS_H
00034 #include <limits.h>
00035 #endif
00036 #include <string.h>
00037 #include <gimp-print/gimp-print.h>
00038 #include "gimp-print-internal.h"
00039 #include <gimp-print/gimp-print-intl-internal.h>
00040 #include "generic-options.h"
00041 
00042 typedef struct
00043 {
00044   char *name;
00045   stp_parameter_type_t typ;
00046   stp_parameter_activity_t active;
00047   union
00048   {
00049     int ival;
00050     int bval;
00051     double dval;
00052     stp_curve_t *cval;
00053     stp_array_t *aval;
00054     stp_raw_t rval;
00055   } value;
00056 } value_t;
00057 
00058 struct stp_compdata
00059 {
00060   char *name;
00061   stp_copy_data_func_t copyfunc;
00062   stp_free_data_func_t freefunc;
00063   void *data;
00064 };
00065 
00066 struct stp_vars                 /* Plug-in variables */
00067 {
00068   char *driver;                 /* Name of printer "driver" */
00069   char *color_conversion;       /* Color module in use */
00070   int   left;                   /* Offset from left-upper corner, points */
00071   int   top;                    /* ... */
00072   int   width;                  /* Width of the image, points */
00073   int   height;                 /* ... */
00074   int   page_width;             /* Width of page in points */
00075   int   page_height;            /* Height of page in points */
00076   stp_list_t *params[STP_PARAMETER_TYPE_INVALID];
00077   stp_list_t *internal_data;
00078   void (*outfunc)(void *data, const char *buffer, size_t bytes);
00079   void *outdata;
00080   void (*errfunc)(void *data, const char *buffer, size_t bytes);
00081   void *errdata;
00082   int verified;                 /* Ensure that params are OK! */
00083 };
00084 
00085 static int standard_vars_initialized = 0;
00086 
00087 static stp_vars_t default_vars;
00088 
00089 static void
00090 null_vars(void)
00091 {
00092   stp_erprintf("Null stp_vars_t! Please report this bug.\n");
00093   stp_abort();
00094 }
00095 
00096 static inline void
00097 check_vars(const stp_vars_t *v)
00098 {
00099   if (v == NULL)
00100     null_vars();
00101 }
00102 
00103 static const char *
00104 value_namefunc(const void *item)
00105 {
00106   const value_t *v = (const value_t *) (item);
00107   return v->name;
00108 }
00109 
00110 static void
00111 value_freefunc(void *item)
00112 {
00113   value_t *v = (value_t *) (item);
00114   switch (v->typ)
00115     {
00116     case STP_PARAMETER_TYPE_STRING_LIST:
00117     case STP_PARAMETER_TYPE_FILE:
00118     case STP_PARAMETER_TYPE_RAW:
00119       stp_free((void *) v->value.rval.data);
00120       break;
00121     case STP_PARAMETER_TYPE_CURVE:
00122       if (v->value.cval)
00123         stp_curve_destroy(v->value.cval);
00124       break;
00125     case STP_PARAMETER_TYPE_ARRAY:
00126       stp_array_destroy(v->value.aval);
00127       break;
00128     default:
00129       break;
00130     }
00131   stp_free(v->name);
00132   stp_free(v);
00133 }
00134 
00135 static stp_list_t *
00136 create_vars_list(void)
00137 {
00138   stp_list_t *ret = stp_list_create();
00139   stp_list_set_freefunc(ret, value_freefunc);
00140   stp_list_set_namefunc(ret, value_namefunc);
00141   return ret;
00142 }
00143 
00144 static void
00145 copy_to_raw(stp_raw_t *raw, const void *data, size_t bytes)
00146 {
00147   char *ndata = stp_malloc(bytes + 1);
00148   memcpy(ndata, data, bytes);
00149   ndata[bytes] = '\0';
00150   raw->data = (void *) ndata;
00151   raw->bytes = bytes;
00152 }
00153 
00154 static value_t *
00155 value_copy(const void *item)
00156 {
00157   value_t *ret = stp_malloc(sizeof(value_t));
00158   const value_t *v = (const value_t *) (item);
00159   ret->name = stp_strdup(v->name);
00160   ret->typ = v->typ;
00161   ret->active = v->active;
00162   switch (v->typ)
00163     {
00164     case STP_PARAMETER_TYPE_CURVE:
00165       ret->value.cval = stp_curve_create_copy(v->value.cval);
00166       break;
00167     case STP_PARAMETER_TYPE_ARRAY:
00168       ret->value.aval = stp_array_create_copy(v->value.aval);
00169       break;
00170     case STP_PARAMETER_TYPE_STRING_LIST:
00171     case STP_PARAMETER_TYPE_FILE:
00172     case STP_PARAMETER_TYPE_RAW:
00173       copy_to_raw(&(ret->value.rval), v->value.rval.data, v->value.rval.bytes);
00174       break;
00175     case STP_PARAMETER_TYPE_INT:
00176     case STP_PARAMETER_TYPE_BOOLEAN:
00177       ret->value.ival = v->value.ival;
00178       break;
00179     case STP_PARAMETER_TYPE_DOUBLE:
00180       ret->value.dval = v->value.dval;
00181       break;
00182     default:
00183       break;
00184     }
00185   return ret;
00186 }
00187 
00188 static stp_list_t *
00189 copy_value_list(const stp_list_t *src)
00190 {
00191   stp_list_t *ret = create_vars_list();
00192   const stp_list_item_t *item = stp_list_get_start((const stp_list_t *)src);
00193   while (item)
00194     {
00195       stp_list_item_create(ret, NULL, value_copy(stp_list_item_get_data(item)));
00196       item = stp_list_item_next(item);
00197     }
00198   return ret;
00199 }
00200 
00201 static const char *
00202 compdata_namefunc(const void *item)
00203 {
00204   const compdata_t *cd = (const compdata_t *) (item);
00205   return cd->name;
00206 }
00207 
00208 static void
00209 compdata_freefunc(void *item)
00210 {
00211   compdata_t *cd = (compdata_t *) (item);
00212   if (cd->freefunc)
00213     (cd->freefunc)(cd->data);
00214   stp_free(cd->name);
00215   stp_free(cd);
00216 }
00217 
00218 static void *
00219 compdata_copyfunc(const void *item)
00220 {
00221   const compdata_t *cd = (const compdata_t *) (item);
00222   if (cd->copyfunc)
00223     return (cd->copyfunc)(cd->data);
00224   else
00225     return cd->data;
00226 }
00227 
00228 void
00229 stp_allocate_component_data(stp_vars_t *v,
00230                              const char *name,
00231                              stp_copy_data_func_t copyfunc,
00232                              stp_free_data_func_t freefunc,
00233                              void *data)
00234 {
00235   compdata_t *cd;
00236   stp_list_item_t *item;
00237   check_vars(v);
00238   cd = stp_malloc(sizeof(compdata_t));
00239   item = stp_list_get_item_by_name(v->internal_data, name);
00240   if (item)
00241     stp_list_item_destroy(v->internal_data, item);
00242   cd->name = stp_strdup(name);
00243   cd->copyfunc = copyfunc;
00244   cd->freefunc = freefunc;
00245   cd->data = data;
00246   stp_list_item_create(v->internal_data, NULL, cd);
00247 }
00248 
00249 void
00250 stp_destroy_component_data(stp_vars_t *v, const char *name)
00251 {
00252   stp_list_item_t *item;
00253   check_vars(v);
00254   item = stp_list_get_item_by_name(v->internal_data, name);
00255   if (item)
00256     stp_list_item_destroy(v->internal_data, item);
00257 }
00258 
00259 void *
00260 stp_get_component_data(const stp_vars_t *v, const char *name)
00261 {
00262   stp_list_item_t *item;
00263   check_vars(v);
00264   item = stp_list_get_item_by_name(v->internal_data, name);
00265   if (item)
00266     return ((compdata_t *) stp_list_item_get_data(item))->data;
00267   else
00268     return NULL;
00269 }
00270 
00271 static stp_list_t *
00272 create_compdata_list(void)
00273 {
00274   stp_list_t *ret = stp_list_create();
00275   stp_list_set_freefunc(ret, compdata_freefunc);
00276   stp_list_set_namefunc(ret, compdata_namefunc);
00277   return ret;
00278 }
00279 
00280 static stp_list_t *
00281 copy_compdata_list(const stp_list_t *src)
00282 {
00283   stp_list_t *ret = create_compdata_list();
00284   const stp_list_item_t *item = stp_list_get_start(src);
00285   while (item)
00286     {
00287       stp_list_item_create(ret, NULL, compdata_copyfunc(item));
00288       item = stp_list_item_next(item);
00289     }
00290   return ret;
00291 }
00292 
00293 static void
00294 initialize_standard_vars(void)
00295 {
00296   if (!standard_vars_initialized)
00297     {
00298       int i;
00299       for (i = 0; i < STP_PARAMETER_TYPE_INVALID; i++)
00300         default_vars.params[i] = create_vars_list();
00301       default_vars.driver = stp_strdup("ps2");
00302       default_vars.color_conversion = stp_strdup("traditional");
00303       default_vars.internal_data = create_compdata_list();
00304       standard_vars_initialized = 1;
00305     }
00306 }
00307 
00308 const stp_vars_t *
00309 stp_default_settings(void)
00310 {
00311   initialize_standard_vars();
00312   return (stp_vars_t *) &default_vars;
00313 }
00314 
00315 stp_vars_t *
00316 stp_vars_create(void)
00317 {
00318   int i;
00319   stp_vars_t *retval = stp_zalloc(sizeof(stp_vars_t));
00320   initialize_standard_vars();
00321   for (i = 0; i < STP_PARAMETER_TYPE_INVALID; i++)
00322     retval->params[i] = create_vars_list();
00323   retval->internal_data = create_compdata_list();
00324   stp_vars_copy(retval, (stp_vars_t *)&default_vars);
00325   return (retval);
00326 }
00327 
00328 void
00329 stp_vars_destroy(stp_vars_t *v)
00330 {
00331   int i;
00332   check_vars(v);
00333   for (i = 0; i < STP_PARAMETER_TYPE_INVALID; i++)
00334     stp_list_destroy(v->params[i]);
00335   stp_list_destroy(v->internal_data);
00336   STP_SAFE_FREE(v->driver);
00337   STP_SAFE_FREE(v->color_conversion);
00338   stp_free(v);
00339 }
00340 
00341 #define DEF_STRING_FUNCS(s, pre)                                \
00342 void                                                            \
00343 pre##_set_##s(stp_vars_t *v, const char *val)                   \
00344 {                                                               \
00345   check_vars(v);                                                \
00346   if (val)                                                      \
00347     stp_dprintf(STP_DBG_VARS, v, "set %s to %s\n", #s, val);    \
00348   else                                                          \
00349     stp_dprintf(STP_DBG_VARS, v, "clear %s\n", #s);             \
00350   if (v->s == val)                                              \
00351     return;                                                     \
00352   STP_SAFE_FREE(v->s);                                          \
00353   v->s = stp_strdup(val);                                       \
00354   v->verified = 0;                                              \
00355 }                                                               \
00356                                                                 \
00357 void                                                            \
00358 pre##_set_##s##_n(stp_vars_t *v, const char *val, int n)        \
00359 {                                                               \
00360   check_vars(v);                                                \
00361   if (v->s == val)                                              \
00362     return;                                                     \
00363   STP_SAFE_FREE(v->s);                                          \
00364   v->s = stp_strndup(val, n);                                   \
00365   v->verified = 0;                                              \
00366 }                                                               \
00367                                                                 \
00368 const char *                                                    \
00369 pre##_get_##s(const stp_vars_t *v)                              \
00370 {                                                               \
00371   check_vars(v);                                                \
00372   return v->s;                                                  \
00373 }
00374 
00375 #define DEF_FUNCS(s, t, pre)                            \
00376 void                                                    \
00377 pre##_set_##s(stp_vars_t *v, t val)                     \
00378 {                                                       \
00379   check_vars(v);                                        \
00380   v->verified = 0;                                      \
00381   v->s = val;                                           \
00382 }                                                       \
00383                                                         \
00384 t                                                       \
00385 pre##_get_##s(const stp_vars_t *v)                      \
00386 {                                                       \
00387   check_vars(v);                                        \
00388   return v->s;                                          \
00389 }
00390 
00391 DEF_STRING_FUNCS(driver, stp)
00392 DEF_STRING_FUNCS(color_conversion, stp)
00393 DEF_FUNCS(left, int, stp)
00394 DEF_FUNCS(top, int, stp)
00395 DEF_FUNCS(width, int, stp)
00396 DEF_FUNCS(height, int, stp)
00397 DEF_FUNCS(page_width, int, stp)
00398 DEF_FUNCS(page_height, int, stp)
00399 DEF_FUNCS(outdata, void *, stp)
00400 DEF_FUNCS(errdata, void *, stp)
00401 DEF_FUNCS(outfunc, stp_outfunc_t, stp)
00402 DEF_FUNCS(errfunc, stp_outfunc_t, stp)
00403 
00404 void
00405 stp_set_verified(stp_vars_t *v, int val)
00406 {
00407   check_vars(v);
00408   v->verified = val;
00409 }
00410 
00411 int
00412 stp_get_verified(const stp_vars_t *v)
00413 {
00414   check_vars(v);
00415   return v->verified;
00416 }
00417 
00418 static void
00419 set_default_raw_parameter(stp_list_t *list, const char *parameter,
00420                           const char *value, size_t bytes, int typ)
00421 {
00422   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00423   if (value && !item)
00424     {
00425       value_t *val = stp_malloc(sizeof(value_t));
00426       val->name = stp_strdup(parameter);
00427       val->typ = typ;
00428       val->active = STP_PARAMETER_DEFAULTED;
00429       stp_list_item_create(list, NULL, val);
00430       copy_to_raw(&(val->value.rval), value, bytes);
00431     }
00432 }
00433 
00434 static void
00435 set_raw_parameter(stp_list_t *list, const char *parameter, const char *value,
00436                   size_t bytes, int typ)
00437 {
00438   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00439   if (value)
00440     {
00441       value_t *val;
00442       if (item)
00443         {
00444           val = (value_t *) stp_list_item_get_data(item);
00445           if (val->active == STP_PARAMETER_DEFAULTED)
00446             val->active = STP_PARAMETER_ACTIVE;
00447           stp_free((void *) val->value.rval.data);
00448         }
00449       else
00450         {
00451           val = stp_malloc(sizeof(value_t));
00452           val->name = stp_strdup(parameter);
00453           val->typ = typ;
00454           val->active = STP_PARAMETER_ACTIVE;
00455           stp_list_item_create(list, NULL, val);
00456         }
00457       copy_to_raw(&(val->value.rval), value, bytes);
00458     }
00459   else if (item)
00460     stp_list_item_destroy(list, item);
00461 }
00462 
00463 void
00464 stp_set_string_parameter_n(stp_vars_t *v, const char *parameter,
00465                            const char *value, size_t bytes)
00466 {
00467   stp_list_t *list = v->params[STP_PARAMETER_TYPE_STRING_LIST];
00468   if (value)
00469     stp_dprintf(STP_DBG_VARS, v, "stp_set_string_parameter(%s, %s)\n",
00470                 parameter, value);
00471   else
00472     stp_dprintf(STP_DBG_VARS, v, "stp_set_string_parameter(%s)\n",
00473                 parameter);
00474   set_raw_parameter(list, parameter, value, bytes,
00475                     STP_PARAMETER_TYPE_STRING_LIST);
00476   stp_set_verified(v, 0);
00477 }
00478 
00479 void
00480 stp_set_string_parameter(stp_vars_t *v, const char *parameter,
00481                          const char *value)
00482 {
00483   int byte_count = 0;
00484   if (value)
00485     {
00486       byte_count = strlen(value);
00487       stp_dprintf(STP_DBG_VARS, v, "stp_set_string_parameter(%s, %s)\n",
00488                   parameter, value);
00489     }
00490   else
00491     stp_dprintf(STP_DBG_VARS, v, "stp_set_string_parameter(%s)\n",
00492                 parameter);
00493   stp_set_string_parameter_n(v, parameter, value, byte_count);
00494   stp_set_verified(v, 0);
00495 }
00496 
00497 void
00498 stp_set_default_string_parameter_n(stp_vars_t *v, const char *parameter,
00499                                    const char *value, size_t bytes)
00500 {
00501   stp_list_t *list = v->params[STP_PARAMETER_TYPE_STRING_LIST];
00502   set_default_raw_parameter(list, parameter, value, bytes,
00503                             STP_PARAMETER_TYPE_STRING_LIST);
00504   stp_set_verified(v, 0);
00505 }
00506 
00507 void
00508 stp_set_default_string_parameter(stp_vars_t *v, const char *parameter,
00509                                  const char *value)
00510 {
00511   int byte_count = 0;
00512   if (value)
00513     {
00514       byte_count = strlen(value);
00515       stp_dprintf(STP_DBG_VARS, v,
00516                   "stp_set_default_string_parameter(%s, %s)\n",
00517                   parameter, value);
00518     }
00519   else
00520     stp_dprintf(STP_DBG_VARS, v, "stp_set_default_string_parameter(%s)\n",
00521                 parameter);
00522   stp_set_default_string_parameter_n(v, parameter, value, byte_count);
00523   stp_set_verified(v, 0);
00524 }
00525 
00526 void
00527 stp_clear_string_parameter(stp_vars_t *v, const char *parameter)
00528 {
00529   stp_set_string_parameter(v, parameter, NULL);
00530 }
00531 
00532 const char *
00533 stp_get_string_parameter(const stp_vars_t *v, const char *parameter)
00534 {
00535   stp_list_t *list = v->params[STP_PARAMETER_TYPE_STRING_LIST];
00536   value_t *val;
00537   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00538   if (item)
00539     {
00540       val = (value_t *) stp_list_item_get_data(item);
00541       return val->value.rval.data;
00542     }
00543   else
00544     return NULL;
00545 }
00546 
00547 void
00548 stp_set_raw_parameter(stp_vars_t *v, const char *parameter,
00549                       const void *value, size_t bytes)
00550 {
00551   stp_list_t *list = v->params[STP_PARAMETER_TYPE_RAW];
00552   set_raw_parameter(list, parameter, value, bytes, STP_PARAMETER_TYPE_RAW);
00553   stp_set_verified(v, 0);
00554 }
00555 
00556 void
00557 stp_set_default_raw_parameter(stp_vars_t *v, const char *parameter,
00558                               const void *value, size_t bytes)
00559 {
00560   stp_list_t *list = v->params[STP_PARAMETER_TYPE_RAW];
00561   set_default_raw_parameter(list, parameter, value, bytes,
00562                             STP_PARAMETER_TYPE_RAW);
00563   stp_set_verified(v, 0);
00564 }
00565 
00566 void
00567 stp_clear_raw_parameter(stp_vars_t *v, const char *parameter)
00568 {
00569   stp_set_raw_parameter(v, parameter, NULL, 0);
00570 }
00571 
00572 const stp_raw_t *
00573 stp_get_raw_parameter(const stp_vars_t *v, const char *parameter)
00574 {
00575   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_RAW];
00576   const value_t *val;
00577   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00578   if (item)
00579     {
00580       val = (const value_t *) stp_list_item_get_data(item);
00581       return &(val->value.rval);
00582     }
00583   else
00584     return NULL;
00585 }
00586 
00587 void
00588 stp_set_file_parameter(stp_vars_t *v, const char *parameter,
00589                        const char *value)
00590 {
00591   stp_list_t *list = v->params[STP_PARAMETER_TYPE_FILE];
00592   size_t byte_count = 0;
00593   if (value)
00594     byte_count = strlen(value);
00595   set_raw_parameter(list, parameter, value, byte_count,
00596                     STP_PARAMETER_TYPE_FILE);
00597   stp_set_verified(v, 0);
00598 }
00599 
00600 void
00601 stp_set_file_parameter_n(stp_vars_t *v, const char *parameter,
00602                          const char *value, size_t byte_count)
00603 {
00604   stp_list_t *list = v->params[STP_PARAMETER_TYPE_FILE];
00605   set_raw_parameter(list, parameter, value, byte_count,
00606                     STP_PARAMETER_TYPE_FILE);
00607   stp_set_verified(v, 0);
00608 }
00609 
00610 void
00611 stp_set_default_file_parameter(stp_vars_t *v, const char *parameter,
00612                                const char *value)
00613 {
00614   stp_list_t *list = v->params[STP_PARAMETER_TYPE_FILE];
00615   size_t byte_count = 0;
00616   if (value)
00617     byte_count = strlen(value);
00618   set_default_raw_parameter(list, parameter, value, byte_count,
00619                             STP_PARAMETER_TYPE_FILE);
00620   stp_set_verified(v, 0);
00621 }
00622 
00623 void
00624 stp_set_default_file_parameter_n(stp_vars_t *v, const char *parameter,
00625                                  const char *value, size_t byte_count)
00626 {
00627   stp_list_t *list = v->params[STP_PARAMETER_TYPE_FILE];
00628   set_default_raw_parameter(list, parameter, value, byte_count,
00629                             STP_PARAMETER_TYPE_FILE);
00630   stp_set_verified(v, 0);
00631 }
00632 
00633 void
00634 stp_clear_file_parameter(stp_vars_t *v, const char *parameter)
00635 {
00636   stp_set_file_parameter(v, parameter, NULL);
00637 }
00638 
00639 const char *
00640 stp_get_file_parameter(const stp_vars_t *v, const char *parameter)
00641 {
00642   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_FILE];
00643   const value_t *val;
00644   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00645   if (item)
00646     {
00647       val = (const value_t *) stp_list_item_get_data(item);
00648       return val->value.rval.data;
00649     }
00650   else
00651     return NULL;
00652 }
00653 
00654 void
00655 stp_set_curve_parameter(stp_vars_t *v, const char *parameter,
00656                         const stp_curve_t *curve)
00657 {
00658   stp_list_t *list = v->params[STP_PARAMETER_TYPE_CURVE];
00659   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00660   if (curve)
00661     {
00662       value_t *val;
00663       if (item)
00664         {
00665           val = (value_t *) stp_list_item_get_data(item);
00666           if (val->active == STP_PARAMETER_DEFAULTED)
00667             val->active = STP_PARAMETER_ACTIVE;
00668           if (val->value.cval)
00669             stp_curve_destroy(val->value.cval);
00670         }
00671       else
00672         {
00673           val = stp_malloc(sizeof(value_t));
00674           val->name = stp_strdup(parameter);
00675           val->typ = STP_PARAMETER_TYPE_CURVE;
00676           val->active = STP_PARAMETER_ACTIVE;
00677           stp_list_item_create(list, NULL, val);
00678         }
00679       val->value.cval = stp_curve_create_copy(curve);
00680     }
00681   else if (item)
00682     stp_list_item_destroy(list, item);
00683   stp_set_verified(v, 0);
00684 }
00685 
00686 void
00687 stp_set_default_curve_parameter(stp_vars_t *v, const char *parameter,
00688                                 const stp_curve_t *curve)
00689 {
00690   stp_list_t *list = v->params[STP_PARAMETER_TYPE_CURVE];
00691   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00692   if (!item)
00693     {
00694       if (curve)
00695         {
00696           value_t *val;
00697           val = stp_malloc(sizeof(value_t));
00698           val->name = stp_strdup(parameter);
00699           val->typ = STP_PARAMETER_TYPE_CURVE;
00700           val->active = STP_PARAMETER_DEFAULTED;
00701           stp_list_item_create(list, NULL, val);
00702           val->value.cval = stp_curve_create_copy(curve);
00703         }
00704     }
00705   stp_set_verified(v, 0);
00706 }
00707 
00708 void
00709 stp_clear_curve_parameter(stp_vars_t *v, const char *parameter)
00710 {
00711   stp_set_curve_parameter(v, parameter, NULL);
00712 }
00713 
00714 const stp_curve_t *
00715 stp_get_curve_parameter(const stp_vars_t *v, const char *parameter)
00716 {
00717   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_CURVE];
00718   const value_t *val;
00719   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00720   if (item)
00721     {
00722       val = (value_t *) stp_list_item_get_data(item);
00723       return val->value.cval;
00724     }
00725   else
00726     return NULL;
00727 }
00728 
00729 void
00730 stp_set_array_parameter(stp_vars_t *v, const char *parameter,
00731                         const stp_array_t *array)
00732 {
00733   stp_list_t *list = v->params[STP_PARAMETER_TYPE_ARRAY];
00734   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00735   if (array)
00736     {
00737       value_t *val;
00738       if (item)
00739         {
00740           val = (value_t *) stp_list_item_get_data(item);
00741           if (val->active == STP_PARAMETER_DEFAULTED)
00742             val->active = STP_PARAMETER_ACTIVE;
00743           stp_array_destroy(val->value.aval);
00744         }
00745       else
00746         {
00747           val = stp_malloc(sizeof(value_t));
00748           val->name = stp_strdup(parameter);
00749           val->typ = STP_PARAMETER_TYPE_ARRAY;
00750           val->active = STP_PARAMETER_ACTIVE;
00751           stp_list_item_create(list, NULL, val);
00752         }
00753       val->value.aval = stp_array_create_copy(array);
00754     }
00755   else if (item)
00756     stp_list_item_destroy(list, item);
00757   stp_set_verified(v, 0);
00758 }
00759 
00760 void
00761 stp_set_default_array_parameter(stp_vars_t *v, const char *parameter,
00762                                 const stp_array_t *array)
00763 {
00764   stp_list_t *list = v->params[STP_PARAMETER_TYPE_ARRAY];
00765   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00766   if (!item)
00767     {
00768       if (array)
00769         {
00770           value_t *val;
00771           val = stp_malloc(sizeof(value_t));
00772           val->name = stp_strdup(parameter);
00773           val->typ = STP_PARAMETER_TYPE_ARRAY;
00774           val->active = STP_PARAMETER_DEFAULTED;
00775           stp_list_item_create(list, NULL, val);
00776           val->value.aval = stp_array_create_copy(array);
00777         }
00778     }
00779   stp_set_verified(v, 0);
00780 }
00781 
00782 void
00783 stp_clear_array_parameter(stp_vars_t *v, const char *parameter)
00784 {
00785   stp_set_array_parameter(v, parameter, NULL);
00786 }
00787 
00788 const stp_array_t *
00789 stp_get_array_parameter(const stp_vars_t *v, const char *parameter)
00790 {
00791   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_ARRAY];
00792   const value_t *val;
00793   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00794   if (item)
00795     {
00796       val = (const value_t *) stp_list_item_get_data(item);
00797       return val->value.aval;
00798     }
00799   else
00800     return NULL;
00801 }
00802 
00803 void
00804 stp_set_int_parameter(stp_vars_t *v, const char *parameter, int ival)
00805 {
00806   stp_list_t *list = v->params[STP_PARAMETER_TYPE_INT];
00807   value_t *val;
00808   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00809   if (item)
00810     {
00811       val = (value_t *) stp_list_item_get_data(item);
00812       if (val->active == STP_PARAMETER_DEFAULTED)
00813         val->active = STP_PARAMETER_ACTIVE;
00814     }
00815   else
00816     {
00817       val = stp_malloc(sizeof(value_t));
00818       val->name = stp_strdup(parameter);
00819       val->typ = STP_PARAMETER_TYPE_INT;
00820       val->active = STP_PARAMETER_ACTIVE;
00821       stp_list_item_create(list, NULL, val);
00822     }
00823   val->value.ival = ival;
00824   stp_set_verified(v, 0);
00825 }
00826 
00827 void
00828 stp_set_default_int_parameter(stp_vars_t *v, const char *parameter, int ival)
00829 {
00830   stp_list_t *list = v->params[STP_PARAMETER_TYPE_INT];
00831   value_t *val;
00832   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00833   if (!item)
00834     {
00835       val = stp_malloc(sizeof(value_t));
00836       val->name = stp_strdup(parameter);
00837       val->typ = STP_PARAMETER_TYPE_INT;
00838       val->active = STP_PARAMETER_DEFAULTED;
00839       stp_list_item_create(list, NULL, val);
00840       val->value.ival = ival;
00841     }
00842   stp_set_verified(v, 0);
00843 }
00844 
00845 void
00846 stp_clear_int_parameter(stp_vars_t *v, const char *parameter)
00847 {
00848   stp_list_t *list = v->params[STP_PARAMETER_TYPE_INT];
00849   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00850   if (item)
00851     stp_list_item_destroy(list, item);
00852   stp_set_verified(v, 0);
00853 }
00854 
00855 int
00856 stp_get_int_parameter(const stp_vars_t *v, const char *parameter)
00857 {
00858   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_INT];
00859   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00860   if (item)
00861     {
00862       const value_t *val = (const value_t *) stp_list_item_get_data(item);
00863       return val->value.ival;
00864     }
00865   else
00866     {
00867       stp_parameter_t desc;
00868       stp_describe_parameter(v, parameter, &desc);
00869       if (desc.p_type == STP_PARAMETER_TYPE_INT)
00870         {
00871           int intval = desc.deflt.integer;
00872           stp_parameter_description_destroy(&desc);
00873           return intval;
00874         }
00875       else
00876         {
00877           stp_parameter_description_destroy(&desc);
00878           stp_erprintf
00879             ("GIMP-PRINT: Attempt to retrieve unset integer parameter %s\n",
00880              parameter);
00881           return 0;
00882         }
00883     }
00884 }
00885 
00886 void
00887 stp_set_boolean_parameter(stp_vars_t *v, const char *parameter, int ival)
00888 {
00889   stp_list_t *list = v->params[STP_PARAMETER_TYPE_BOOLEAN];
00890   value_t *val;
00891   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00892   if (item)
00893     {
00894       val = (value_t *) stp_list_item_get_data(item);
00895       if (val->active == STP_PARAMETER_DEFAULTED)
00896         val->active = STP_PARAMETER_ACTIVE;
00897     }
00898   else
00899     {
00900       val = stp_malloc(sizeof(value_t));
00901       val->name = stp_strdup(parameter);
00902       val->typ = STP_PARAMETER_TYPE_BOOLEAN;
00903       val->active = STP_PARAMETER_ACTIVE;
00904       stp_list_item_create(list, NULL, val);
00905     }
00906   if (ival)
00907     val->value.ival = 1;
00908   else
00909     val->value.ival = 0;
00910   stp_set_verified(v, 0);
00911 }
00912 
00913 void
00914 stp_set_default_boolean_parameter(stp_vars_t *v, const char *parameter,
00915                                   int ival)
00916 {
00917   stp_list_t *list = v->params[STP_PARAMETER_TYPE_BOOLEAN];
00918   value_t *val;
00919   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00920   if (!item)
00921     {
00922       val = stp_malloc(sizeof(value_t));
00923       val->name = stp_strdup(parameter);
00924       val->typ = STP_PARAMETER_TYPE_BOOLEAN;
00925       val->active = STP_PARAMETER_DEFAULTED;
00926       stp_list_item_create(list, NULL, val);
00927       if (ival)
00928         val->value.ival = 1;
00929       else
00930         val->value.ival = 0;
00931     }
00932   stp_set_verified(v, 0);
00933 }
00934 
00935 void
00936 stp_clear_boolean_parameter(stp_vars_t *v, const char *parameter)
00937 {
00938   stp_list_t *list = v->params[STP_PARAMETER_TYPE_BOOLEAN];
00939   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00940   if (item)
00941     stp_list_item_destroy(list, item);
00942   stp_set_verified(v, 0);
00943 }
00944 
00945 int
00946 stp_get_boolean_parameter(const stp_vars_t *v, const char *parameter)
00947 {
00948   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_BOOLEAN];
00949   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00950   if (item)
00951     {
00952       const value_t *val = (const value_t *) stp_list_item_get_data(item);
00953       return val->value.ival;
00954     }
00955   else
00956     {
00957       stp_parameter_t desc;
00958       stp_describe_parameter(v, parameter, &desc);
00959       if (desc.p_type == STP_PARAMETER_TYPE_BOOLEAN)
00960         {
00961           int boolean = desc.deflt.boolean;
00962           stp_parameter_description_destroy(&desc);
00963           return boolean;
00964         }
00965       else
00966         {
00967           stp_parameter_description_destroy(&desc);
00968           stp_erprintf
00969             ("GIMP-PRINT: Attempt to retrieve unset boolean parameter %s\n",
00970              parameter);
00971           return 0;
00972         }
00973     }
00974 }
00975 
00976 void
00977 stp_set_float_parameter(stp_vars_t *v, const char *parameter, double dval)
00978 {
00979   stp_list_t *list = v->params[STP_PARAMETER_TYPE_DOUBLE];
00980   value_t *val;
00981   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
00982   if (item)
00983     {
00984       val = (value_t *) stp_list_item_get_data(item);
00985       if (val->active == STP_PARAMETER_DEFAULTED)
00986         val->active = STP_PARAMETER_ACTIVE;
00987     }
00988   else
00989     {
00990       val = stp_malloc(sizeof(value_t));
00991       val->name = stp_strdup(parameter);
00992       val->typ = STP_PARAMETER_TYPE_DOUBLE;
00993       val->active = STP_PARAMETER_ACTIVE;
00994       stp_list_item_create(list, NULL, val);
00995     }
00996   val->value.dval = dval;
00997   stp_set_verified(v, 0);
00998 }
00999 
01000 void
01001 stp_set_default_float_parameter(stp_vars_t *v, const char *parameter,
01002                                 double dval)
01003 {
01004   stp_list_t *list = v->params[STP_PARAMETER_TYPE_DOUBLE];
01005   value_t *val;
01006   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01007   if (!item)
01008     {
01009       val = stp_malloc(sizeof(value_t));
01010       val->name = stp_strdup(parameter);
01011       val->typ = STP_PARAMETER_TYPE_DOUBLE;
01012       val->active = STP_PARAMETER_DEFAULTED;
01013       stp_list_item_create(list, NULL, val);
01014       val->value.dval = dval;
01015     }
01016   stp_set_verified(v, 0);
01017 }
01018 
01019 void
01020 stp_clear_float_parameter(stp_vars_t *v, const char *parameter)
01021 {
01022   stp_list_t *list = v->params[STP_PARAMETER_TYPE_DOUBLE];
01023   stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01024   if (item)
01025     stp_list_item_destroy(list, item);
01026   stp_set_verified(v, 0);
01027 }
01028 
01029 double
01030 stp_get_float_parameter(const stp_vars_t *v, const char *parameter)
01031 {
01032   const stp_list_t *list = v->params[STP_PARAMETER_TYPE_DOUBLE];
01033   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01034   if (item)
01035     {
01036       const value_t *val = (value_t *) stp_list_item_get_data(item);
01037       return val->value.dval;
01038     }
01039   else
01040     {
01041       stp_parameter_t desc;
01042       stp_describe_parameter(v, parameter, &desc);
01043       if (desc.p_type == STP_PARAMETER_TYPE_DOUBLE)
01044         {
01045           double dbl = desc.deflt.dbl;
01046           stp_parameter_description_destroy(&desc);
01047           return dbl;
01048         }
01049       else
01050         {
01051           stp_parameter_description_destroy(&desc);
01052           stp_erprintf
01053             ("GIMP-PRINT: Attempt to retrieve unset float parameter %s\n",
01054              parameter);
01055           return 1.0;
01056         }
01057     }
01058 }
01059 
01060 void
01061 stp_scale_float_parameter(stp_vars_t *v, const char *parameter,
01062                           double scale)
01063 {
01064   double val;
01065   if (stp_check_float_parameter(v, parameter, STP_PARAMETER_DEFAULTED))
01066     val = stp_get_float_parameter(v, parameter);
01067   else
01068     {
01069       stp_parameter_t desc;
01070       stp_describe_parameter(v, parameter, &desc);
01071       if (desc.p_type != STP_PARAMETER_TYPE_DOUBLE)
01072         {
01073           stp_parameter_description_destroy(&desc);
01074           return;
01075         }
01076       val = desc.deflt.dbl;
01077       stp_parameter_description_destroy(&desc);
01078     }
01079   stp_set_float_parameter(v, parameter, val * scale);
01080 }
01081 
01082 static int
01083 check_parameter_generic(const stp_vars_t *v, stp_parameter_type_t p_type,
01084                         const char *parameter, stp_parameter_activity_t active)
01085 {
01086   const stp_list_t *list = v->params[p_type];
01087   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01088   if (item &&
01089       active <= ((const value_t *) stp_list_item_get_data(item))->active)
01090     return 1;
01091   else
01092     return 0;
01093 }
01094 
01095 #define CHECK_FUNCTION(type, index)                                     \
01096 int                                                                     \
01097 stp_check_##type##_parameter(const stp_vars_t *v, const char *parameter,        \
01098                              stp_parameter_activity_t active)           \
01099 {                                                                       \
01100   return check_parameter_generic(v, index, parameter, active);          \
01101 }
01102 
01103 CHECK_FUNCTION(string, STP_PARAMETER_TYPE_STRING_LIST)
01104 CHECK_FUNCTION(file, STP_PARAMETER_TYPE_FILE)
01105 CHECK_FUNCTION(float, STP_PARAMETER_TYPE_DOUBLE)
01106 CHECK_FUNCTION(int, STP_PARAMETER_TYPE_INT)
01107 CHECK_FUNCTION(boolean, STP_PARAMETER_TYPE_BOOLEAN)
01108 CHECK_FUNCTION(curve, STP_PARAMETER_TYPE_CURVE)
01109 CHECK_FUNCTION(array, STP_PARAMETER_TYPE_ARRAY)
01110 CHECK_FUNCTION(raw, STP_PARAMETER_TYPE_RAW)
01111 
01112 static stp_parameter_activity_t
01113 get_parameter_active_generic(const stp_vars_t *v, stp_parameter_type_t p_type,
01114                              const char *parameter)
01115 {
01116   const stp_list_t *list = v->params[p_type];
01117   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01118   if (item)
01119     return ((const value_t *) stp_list_item_get_data(item))->active;
01120   else
01121     return 0;
01122 }
01123 
01124 #define GET_PARAMETER_ACTIVE_FUNCTION(type, index)                           \
01125 stp_parameter_activity_t                                                     \
01126 stp_get_##type##_parameter_active(const stp_vars_t *v, const char *parameter) \
01127 {                                                                            \
01128   return get_parameter_active_generic(v, index, parameter);                  \
01129 }
01130 
01131 GET_PARAMETER_ACTIVE_FUNCTION(string, STP_PARAMETER_TYPE_STRING_LIST)
01132 GET_PARAMETER_ACTIVE_FUNCTION(file, STP_PARAMETER_TYPE_FILE)
01133 GET_PARAMETER_ACTIVE_FUNCTION(float, STP_PARAMETER_TYPE_DOUBLE)
01134 GET_PARAMETER_ACTIVE_FUNCTION(int, STP_PARAMETER_TYPE_INT)
01135 GET_PARAMETER_ACTIVE_FUNCTION(boolean, STP_PARAMETER_TYPE_BOOLEAN)
01136 GET_PARAMETER_ACTIVE_FUNCTION(curve, STP_PARAMETER_TYPE_CURVE)
01137 GET_PARAMETER_ACTIVE_FUNCTION(array, STP_PARAMETER_TYPE_ARRAY)
01138 GET_PARAMETER_ACTIVE_FUNCTION(raw, STP_PARAMETER_TYPE_RAW)
01139 
01140 static void
01141 set_parameter_active_generic(const stp_vars_t *v, stp_parameter_type_t p_type,
01142                              const char *parameter,
01143                              stp_parameter_activity_t active)
01144 {
01145   const stp_list_t *list = v->params[p_type];
01146   const stp_list_item_t *item = stp_list_get_item_by_name(list, parameter);
01147   if (item && (active == STP_PARAMETER_ACTIVE ||
01148                active == STP_PARAMETER_INACTIVE))
01149     ((value_t *) stp_list_item_get_data(item))->active = active;
01150 }
01151 
01152 #define SET_PARAMETER_ACTIVE_FUNCTION(type, index)                           \
01153 void                                                                         \
01154 stp_set_##type##_parameter_active(const stp_vars_t *v, const char *parameter, \
01155                                   stp_parameter_activity_t active)           \
01156 {                                                                            \
01157   set_parameter_active_generic(v, index, parameter, active);                 \
01158 }
01159 
01160 SET_PARAMETER_ACTIVE_FUNCTION(string, STP_PARAMETER_TYPE_STRING_LIST)
01161 SET_PARAMETER_ACTIVE_FUNCTION(file, STP_PARAMETER_TYPE_FILE)
01162 SET_PARAMETER_ACTIVE_FUNCTION(float, STP_PARAMETER_TYPE_DOUBLE)
01163 SET_PARAMETER_ACTIVE_FUNCTION(int, STP_PARAMETER_TYPE_INT)
01164 SET_PARAMETER_ACTIVE_FUNCTION(boolean, STP_PARAMETER_TYPE_BOOLEAN)
01165 SET_PARAMETER_ACTIVE_FUNCTION(curve, STP_PARAMETER_TYPE_CURVE)
01166 SET_PARAMETER_ACTIVE_FUNCTION(array, STP_PARAMETER_TYPE_ARRAY)
01167 SET_PARAMETER_ACTIVE_FUNCTION(raw, STP_PARAMETER_TYPE_RAW)
01168 
01169 void
01170 stp_fill_parameter_settings(stp_parameter_t *desc,
01171                             const stp_parameter_t *param)
01172 {
01173   if (param)
01174     {
01175       desc->p_type = param->p_type;
01176       desc->p_level = param->p_level;
01177       desc->p_class = param->p_class;
01178       desc->is_mandatory = param->is_mandatory;
01179       desc->is_active = param->is_active;
01180       desc->channel = param->channel;
01181       desc->verify_this_parameter = param->verify_this_parameter;
01182       desc->read_only = param->read_only;
01183       desc->name = param->name;
01184       desc->text = param->text;
01185       desc->category = param->category;
01186       desc->help = param->help;
01187       return;
01188     }
01189 }
01190 
01191 void
01192 stp_vars_copy(stp_vars_t *vd, const stp_vars_t *vs)
01193 {
01194   int i;
01195 
01196   if (vs == vd)
01197     return;
01198   stp_set_driver(vd, stp_get_driver(vs));
01199   stp_set_color_conversion(vd, stp_get_color_conversion(vs));
01200   stp_set_left(vd, stp_get_left(vs));
01201   stp_set_top(vd, stp_get_top(vs));
01202   stp_set_width(vd, stp_get_width(vs));
01203   stp_set_height(vd, stp_get_height(vs));
01204   stp_set_page_width(vd, stp_get_page_width(vs));
01205   stp_set_page_height(vd, stp_get_page_height(vs));
01206   stp_set_outdata(vd, stp_get_outdata(vs));
01207   stp_set_errdata(vd, stp_get_errdata(vs));
01208   stp_set_outfunc(vd, stp_get_outfunc(vs));
01209   stp_set_errfunc(vd, stp_get_errfunc(vs));
01210   for (i = 0; i < STP_PARAMETER_TYPE_INVALID; i++)
01211     {
01212       stp_list_destroy(vd->params[i]);
01213       vd->params[i] = copy_value_list(vs->params[i]);
01214     }
01215   stp_list_destroy(vd->internal_data);
01216   vd->internal_data = copy_compdata_list(vs->internal_data);
01217   stp_set_verified(vd, stp_get_verified(vs));
01218 }
01219 
01220 void
01221 stp_prune_inactive_options(stp_vars_t *v)
01222 {
01223   stp_parameter_list_t params = stp_get_parameter_list(v);
01224   int i;
01225   for (i = 0; i < STP_PARAMETER_TYPE_INVALID; i++)
01226     {
01227       stp_list_t *list = v->params[i];
01228       stp_list_item_t *item = stp_list_get_start(list);
01229       while (item)
01230         {
01231           stp_list_item_t *next = stp_list_item_next(item);
01232           value_t *var = (value_t *)stp_list_item_get_data(item);
01233           if (var->active < STP_PARAMETER_DEFAULTED ||
01234               !(stp_parameter_find(params, var->name)))
01235             stp_list_item_destroy(list, item);
01236           item = next;
01237         }
01238     }
01239   stp_parameter_list_destroy(params);
01240 }
01241 
01242 stp_vars_t *
01243 stp_vars_create_copy(const stp_vars_t *vs)
01244 {
01245   stp_vars_t *vd = stp_vars_create();
01246   stp_vars_copy(vd, vs);
01247   return (vd);
01248 }
01249 
01250 static const char *
01251 param_namefunc(const void *item)
01252 {
01253   const stp_parameter_t *param = (const stp_parameter_t *)(item);
01254   return param->name;
01255 }
01256 
01257 static const char *
01258 param_longnamefunc(const void *item)
01259 {
01260   const stp_parameter_t *param = (const stp_parameter_t *) (item);
01261   return param->text;
01262 }
01263 
01264 stp_parameter_list_t
01265 stp_parameter_list_create(void)
01266 {
01267   stp_list_t *ret = stp_list_create();
01268   stp_list_set_namefunc(ret, param_namefunc);
01269   stp_list_set_long_namefunc(ret, param_longnamefunc);
01270   return (stp_parameter_list_t) ret;
01271 }
01272 
01273 void
01274 stp_parameter_list_add_param(stp_parameter_list_t list,
01275                              const stp_parameter_t *item)
01276 {
01277   stp_list_t *ilist = (stp_list_t *) list;
01278   stp_list_item_create(ilist, NULL, item);
01279 }
01280 
01281 void
01282 stp_describe_parameter(const stp_vars_t *v, const char *name,
01283                        stp_parameter_t *description)
01284 {
01285   description->p_type = STP_PARAMETER_TYPE_INVALID;
01286 /* Set these to NULL in case stpi_*_describe_parameter() doesn't */
01287   description->bounds.str = NULL;
01288   description->deflt.str = NULL;
01289   stp_printer_describe_parameter(v, name, description);
01290   if (description->p_type != STP_PARAMETER_TYPE_INVALID)
01291     return;
01292   stp_color_describe_parameter(v, name, description);
01293   if (description->p_type != STP_PARAMETER_TYPE_INVALID)
01294     return;
01295   stp_dither_describe_parameter(v, name, description);
01296   if (description->p_type != STP_PARAMETER_TYPE_INVALID)
01297     return;
01298   stpi_describe_generic_parameter(v, name, description);
01299 }
01300 
01301 void
01302 stp_parameter_description_destroy(stp_parameter_t *desc)
01303 {
01304   switch (desc->p_type)
01305     {
01306     case STP_PARAMETER_TYPE_CURVE:
01307       if (desc->bounds.curve)
01308         stp_curve_destroy(desc->bounds.curve);
01309       desc->bounds.curve = NULL;
01310       break;
01311     case STP_PARAMETER_TYPE_ARRAY:
01312       if (desc->bounds.array)
01313         stp_array_destroy(desc->bounds.array);
01314       desc->bounds.array = NULL;
01315       break;
01316     case STP_PARAMETER_TYPE_STRING_LIST:
01317       if (desc->bounds.str)
01318         stp_string_list_destroy(desc->bounds.str);
01319       desc->bounds.str = NULL;
01320       break;
01321     default:
01322       break;
01323     }
01324 }
01325 
01326 const stp_parameter_t *
01327 stp_parameter_find_in_settings(const stp_vars_t *v, const char *name)
01328 {
01329   stp_parameter_list_t param_list = stp_get_parameter_list(v);
01330   const stp_parameter_t *param = stp_parameter_find(param_list, name);
01331   stp_parameter_list_destroy(param_list);
01332   return param;
01333 }
01334 
01335 size_t
01336 stp_parameter_list_count(stp_const_parameter_list_t list)
01337 {
01338   const stp_list_t *ilist = (const stp_list_t *)list;
01339   return stp_list_get_length(ilist);
01340 }
01341 
01342 const stp_parameter_t *
01343 stp_parameter_find(stp_const_parameter_list_t list, const char *name)
01344 {
01345   const stp_list_t *ilist = (const stp_list_t *)list;
01346   const stp_list_item_t *item = stp_list_get_item_by_name(ilist, name);
01347   if (item)
01348     return (const stp_parameter_t *) stp_list_item_get_data(item);
01349   else
01350     return NULL;
01351 }
01352 
01353 const stp_parameter_t *
01354 stp_parameter_list_param(stp_const_parameter_list_t list, size_t item)
01355 {
01356   const stp_list_t *ilist = (const stp_list_t *)list;
01357   if (item >= stp_list_get_length(ilist))
01358     return NULL;
01359   else
01360     return (const stp_parameter_t *)
01361       stp_list_item_get_data(stp_list_get_item_by_index(ilist, item));
01362 }
01363 
01364 void
01365 stp_parameter_list_destroy(stp_parameter_list_t list)
01366 {
01367   stp_list_destroy((stp_list_t *)list);
01368 }
01369 
01370 stp_parameter_list_t
01371 stp_parameter_list_copy(stp_const_parameter_list_t list)
01372 {
01373   stp_list_t *ret = stp_parameter_list_create();
01374   int i;
01375   size_t count = stp_parameter_list_count(list);
01376   for (i = 0; i < count; i++)
01377     stp_list_item_create(ret, NULL, stp_parameter_list_param(list, i));
01378   return (stp_parameter_list_t) ret;
01379 }
01380 
01381 void
01382 stp_parameter_list_append(stp_parameter_list_t list,
01383                           stp_const_parameter_list_t append)
01384 {
01385   int i;
01386   stp_list_t *ilist = (stp_list_t *)list;
01387   size_t count = stp_parameter_list_count(append);
01388   for (i = 0; i < count; i++)
01389     {
01390       const stp_parameter_t *param = stp_parameter_list_param(append, i);
01391       if (!stp_list_get_item_by_name(ilist, param->name))
01392         stp_list_item_create(ilist, NULL, param);
01393     }
01394 }

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