Changeset a695a68
- Timestamp:
- May 18, 2007, 4:54:51 PM (18 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- cd57601
- Parents:
- ec53338
- git-author:
- Nelson Elhage <nelhage@mit.edu> (05/18/07 16:54:42)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (05/18/07 16:54:51)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
perlglue.xs
rf6b319c ra695a68 323 323 char *rv = NULL; 324 324 CODE: 325 rv = owl_text_wordwrap(in, cols);325 rv = owl_text_wordwrap(in, cols); 326 326 RETVAL = rv; 327 327 OUTPUT: … … 329 329 CLEANUP: 330 330 if (rv) owl_free(rv); 331 332 void 333 new_variable_string_internal(name, ival, summ, desc) 334 char * name 335 char * ival 336 char * summ 337 char * desc 338 CODE: 339 owl_variable_dict_newvar_string(owl_global_get_vardict(&g), 340 name, 341 summ, 342 desc, 343 ival); 344 345 void 346 new_variable_int_internal(name, ival, summ, desc) 347 char * name 348 int ival 349 char * summ 350 char * desc 351 CODE: 352 owl_variable_dict_newvar_int(owl_global_get_vardict(&g), 353 name, 354 summ, 355 desc, 356 ival); 357 358 void 359 new_variable_bool_internal(name, ival, summ, desc) 360 char * name 361 int ival 362 char * summ 363 char * desc 364 CODE: 365 owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), 366 name, 367 summ, 368 desc, 369 ival); -
perlwrap.pm
rf6b319c ra695a68 78 78 no warnings 'uninitialized'; 79 79 BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description}); 80 } 81 82 sub new_variable_int { 83 unshift @_, \&BarnOwl::new_variable_int_internal, 0; 84 goto \&_new_variable; 85 } 86 87 sub new_variable_bool { 88 unshift @_, \&BarnOwl::new_variable_bool_internal, 0; 89 goto \&_new_variable; 90 } 91 92 sub new_variable_string { 93 unshift @_, \&BarnOwl::new_variable_string_internal, ""; 94 goto \&_new_variable; 95 } 96 97 sub _new_variable { 98 my $func = shift; 99 my $default_default = shift; 100 my $name = shift; 101 my $args = shift || {}; 102 my %args = ( 103 summary => "", 104 description => "", 105 default => $default_default, 106 %{$args}); 107 $func->($name, $args{default}, $args{summary}, $args{description}); 80 108 } 81 109 -
variable.c
r2fa15f0 ra695a68 518 518 } 519 519 520 void owl_variable_dict_add_variable(owl_vardict * vardict, 521 owl_variable * var) { 522 owl_dict_insert_element(vardict, var->name, (void*)var, NULL); 523 } 524 525 owl_variable * owl_variable_newvar(char *name, char *summary, char * description) { 526 owl_variable * var = (owl_variable*)owl_malloc(sizeof(owl_variable)); 527 memset(var, 0, sizeof(owl_variable)); 528 var->name = owl_strdup(name); 529 var->summary = owl_strdup(summary); 530 var->description = owl_strdup(description); 531 return var; 532 } 533 534 void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) { 535 owl_variable * var = owl_variable_newvar(name, summ, desc); 536 var->type = OWL_VARIABLE_STRING; 537 var->pval_default = owl_strdup(initval); 538 var->set_fn = owl_variable_string_set_default; 539 var->set_fromstring_fn = owl_variable_string_set_fromstring_default; 540 var->get_fn = owl_variable_get_default; 541 var->get_tostring_fn = owl_variable_string_get_tostring_default; 542 var->free_fn = owl_variable_free_default; 543 var->set_fn(var, initval); 544 owl_variable_dict_add_variable(vd, var); 545 } 546 547 void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) { 548 owl_variable * var = owl_variable_newvar(name, summ, desc); 549 var->type = OWL_VARIABLE_INT; 550 var->ival_default = initval; 551 var->validate_fn = owl_variable_int_validate_default; 552 var->set_fn = owl_variable_int_set_default; 553 var->set_fromstring_fn = owl_variable_int_set_fromstring_default; 554 var->get_fn = owl_variable_get_default; 555 var->get_tostring_fn = owl_variable_int_get_tostring_default; 556 var->free_fn = owl_variable_free_default; 557 var->val = owl_malloc(sizeof(int)); 558 var->set_fn(var, &initval); 559 owl_variable_dict_add_variable(vd, var); 560 } 561 562 void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) { 563 owl_variable * var = owl_variable_newvar(name, summ, desc); 564 var->type = OWL_VARIABLE_BOOL; 565 var->ival_default = initval; 566 var->validate_fn = owl_variable_bool_validate_default; 567 var->set_fn = owl_variable_bool_set_default; 568 var->set_fromstring_fn = owl_variable_bool_set_fromstring_default; 569 var->get_fn = owl_variable_get_default; 570 var->get_tostring_fn = owl_variable_bool_get_tostring_default; 571 var->free_fn = owl_variable_free_default; 572 var->val = owl_malloc(sizeof(int)); 573 var->set_fn(var, &initval); 574 owl_variable_dict_add_variable(vd, var); 575 } 576 520 577 void owl_variable_dict_free(owl_vardict *d) { 521 578 owl_dict_free_all(d, (void(*)(void*))owl_variable_free); … … 970 1027 FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser")); 971 1028 972 1029 owl_variable * v; 1030 1031 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); 1032 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING))); 1033 FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar"))); 1034 owl_variable_set_string(&vd, "stringvar", "new val"); 1035 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar"))); 1036 1037 owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); 1038 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT))); 1039 FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar")); 1040 owl_variable_set_int(&vd, "intvar", 17); 1041 FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar")); 1042 1043 owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1); 1044 FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL))); 1045 FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar")); 1046 owl_variable_set_bool_off(&vd, "boolvar"); 1047 FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar")); 973 1048 974 1049 owl_variable_dict_free(&vd);
Note: See TracChangeset
for help on using the changeset viewer.