Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/main/print-vars.c

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

Generated on Wed Aug 25 07:56:14 2004 for libgimpprint API Reference by doxygen 1.3.6