Changeset cce9369


Ignore:
Timestamp:
Sep 30, 2011, 8:14:50 AM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
e21b921
Parents:
b54b06a
git-author:
Jason Gross <jgross@mit.edu> (07/12/11 19:20:46)
git-committer:
Jason Gross <jgross@mit.edu> (09/30/11 08:14:50)
Message:
Allowed custom validsettings for other non-boolean perl variables.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    rb54b06a rcce9369  
    413413=item valid_settings
    414414
    415 A listref of valid setttings for the enum variable.
    416 The settings must not contain any commas.
     415A listref of valid setttings for the enum variable, or a string describing
     416the valid settings for any other type of variable.  The settings for an enum
     417variable may not contain any commas.  You should not specify valid settings
     418for boolean variables.
    417419
    418420=back
     
    421423
    422424sub new_variable_int {
    423     unshift @_, \&BarnOwl::Internal::new_variable_int, 0;
    424     goto \&_new_variable;
     425    _new_variable(\&BarnOwl::Internal::new_variable_int, 0, "<int>", @_);
    425426}
    426427
    427428sub new_variable_bool {
    428     unshift @_, \&BarnOwl::Internal::new_variable_bool, 0;
    429     goto \&_new_variable;
     429    _new_variable(\&BarnOwl::Internal::new_variable_bool, 0, "on,off", @_);
    430430}
    431431
    432432sub new_variable_string {
    433     unshift @_, \&BarnOwl::Internal::new_variable_string, "";
    434     goto \&_new_variable;
     433    _new_variable(\&BarnOwl::Internal::new_variable_string, "", "<string>", @_);
    435434}
    436435
     
    457456    my $func = shift;
    458457    my $default_default = shift;
     458    my $default_valid_settings = shift;
    459459    my $name = shift;
    460460    my $args = shift || {};
    461461    my %args = (
    462         summary     => "",
    463         description => "",
    464         default     => $default_default,
     462        summary        => "",
     463        description    => "",
     464        default        => $default_default,
     465        valid_settings => $default_valid_settings,
    465466        %{$args});
    466     $func->($name, $args{default}, $args{summary}, $args{description});
     467    $func->($name, $args{default}, $args{summary}, $args{description}, $args{valid_settings});
    467468}
    468469
  • perlglue.xs

    rb54b06a rcce9369  
    405405
    406406void
    407 new_variable_string(name, ival, summ, desc)
     407new_variable_string(name, ival, summ, desc, validset)
    408408        const char * name
    409409        const char * ival
    410410        const char * summ
    411411        const char * desc
     412        const char * validset
    412413        CODE:
    413414        owl_variable_dict_newvar_string(owl_global_get_vardict(&g),
     
    415416                                        summ,
    416417                                        desc,
    417                                         ival);
    418 
    419 void
    420 new_variable_int(name, ival, summ, desc)
     418                                        ival,
     419                                        validset);
     420
     421void
     422new_variable_int(name, ival, summ, desc, validset)
    421423        const char * name
    422424        int ival
    423425        const char * summ
    424426        const char * desc
     427        const char * validset
    425428        CODE:
    426429        owl_variable_dict_newvar_int(owl_global_get_vardict(&g),
     
    428431                                     summ,
    429432                                     desc,
    430                                      ival);
    431 
    432 void
    433 new_variable_bool(name, ival, summ, desc)
     433                                     ival,
     434                                     validset);
     435
     436void
     437new_variable_bool(name, ival, summ, desc, validset)
    434438        const char * name
    435439        int ival
    436440        const char * summ
    437441        const char * desc
    438         CODE:
     442        const char * validset
     443        CODE:
     444        if (strcmp(validset, "on,off")) /* gcc complains if we don't do anything with it, but the perl code isn't nice enough to let us get rid of it */
     445                croak("Invalid bool variable valid settings: %s", validset);
    439446        owl_variable_dict_newvar_bool(owl_global_get_vardict(&g),
    440447                                      name,
  • tester.c

    ra74a044 rcce9369  
    390390  FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var));
    391391
    392   owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
     392  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval", "<string>");
    393393  FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar")));
    394394  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var)));
     
    397397  FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var)));
    398398
    399   owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
     399  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47, 0);
    400400  FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar")));
    401401  FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var)));
     
    411411  FAIL_UNLESS("update bool val", !owl_variable_get_bool(var));
    412412
    413   owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL);
     413  owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL, "<string>");
    414414  FAIL_UNLESS("get new string (NULL) var", NULL != (var = owl_variable_get_var(&vd, "nullstringvar")));
    415415  FAIL_UNLESS("get string (NULL)", NULL == (value = owl_variable_get_tostring(var)));
  • variable.c

    rc0e728a rcce9369  
    665665}
    666666
    667 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval)
     667void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval, const char *validsettings)
    668668{
    669669  owl_variable *old = owl_variable_get_var(vd, name);
     
    671671  if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING)
    672672    oldval = owl_variable_get_tostring(old);
    673   owl_variable *var = owl_variable_newvar(name, summ, desc, "<string>", OWL_VARIABLE_STRING);
     673  owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_STRING);
    674674  var->pval_default = g_strdup(initval);
    675675  owl_variable_init_defaults(var);
     
    680680}
    681681
    682 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval)
     682void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval, const char *validsettings)
    683683{
    684684  owl_variable *old = owl_variable_get_var(vd, name);
     
    686686  if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT)
    687687    oldval = owl_variable_get_int(old);
    688   owl_variable *var = owl_variable_newvar(name, summ, desc, "<int>", OWL_VARIABLE_INT);
     688  owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_INT);
    689689  var->ival_default = initval;
    690690  owl_variable_init_defaults(var);
Note: See TracChangeset for help on using the changeset viewer.