Changeset 6503194
- Timestamp:
- Oct 10, 2011, 8:07:20 PM (14 years ago)
- Parents:
- ef4074b (diff), e21b921 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.h
rb9517cf rc0e728a 237 237 void *pval_default; /* for types other and string */ 238 238 int ival_default; /* for types int and bool */ 239 c onst char *validsettings;/* documentation of valid settings */239 char *validsettings; /* documentation of valid settings */ 240 240 char *summary; /* summary of usage */ 241 241 char *description; /* detailed description */ -
perl/lib/BarnOwl.pm
r7803326 rcce9369 17 17 add_io_dispatch remove_io_dispatch 18 18 new_command 19 new_variable_int new_variable_bool new_variable_string 19 new_variable_int new_variable_bool new_variable_string new_variable_enum 20 20 quote redisplay); 21 21 our %EXPORT_TAGS = (all => \@EXPORT_OK); … … 389 389 =head2 new_variable_string NAME [{ARGS}] 390 390 391 Add a new owl variable, either an int, a bool, or a string, with the 392 specified name. 391 =head2 new_variable_enum NAME [{ARGS}] 392 393 Add a new owl variable, either an int, a bool, a string, or an enum, 394 with the specified name. 393 395 394 396 ARGS can optionally contain the following keys: … … 398 400 =item default 399 401 400 The default and initial value for the variable 402 The default and initial value for the variable. 403 Note that this should be a string value for an enum. 401 404 402 405 =item summary … … 408 411 A longer description of the function of the variable 409 412 413 =item valid_settings 414 415 A listref of valid setttings for the enum variable, or a string describing 416 the valid settings for any other type of variable. The settings for an enum 417 variable may not contain any commas. You should not specify valid settings 418 for boolean variables. 419 410 420 =back 411 421 … … 413 423 414 424 sub new_variable_int { 415 unshift @_, \&BarnOwl::Internal::new_variable_int, 0; 416 goto \&_new_variable; 425 _new_variable(\&BarnOwl::Internal::new_variable_int, 0, "<int>", @_); 417 426 } 418 427 419 428 sub new_variable_bool { 420 unshift @_, \&BarnOwl::Internal::new_variable_bool, 0; 421 goto \&_new_variable; 429 _new_variable(\&BarnOwl::Internal::new_variable_bool, 0, "on,off", @_); 422 430 } 423 431 424 432 sub new_variable_string { 425 unshift @_, \&BarnOwl::Internal::new_variable_string, ""; 426 goto \&_new_variable; 427 } 428 429 sub _new_variable { 430 my $func = shift; 431 my $default_default = shift; 433 _new_variable(\&BarnOwl::Internal::new_variable_string, "", "<string>", @_); 434 } 435 436 sub new_variable_enum { 432 437 my $name = shift; 433 438 my $args = shift || {}; … … 435 440 summary => "", 436 441 description => "", 437 default => $default_default,438 442 %{$args}); 439 $func->($name, $args{default}, $args{summary}, $args{description}); 443 444 my @valid_settings = @{$args{valid_settings}}; 445 if (defined $args{default}) { 446 ($args{default}) = grep { $args{default} eq $valid_settings[$_] } 0..$#valid_settings; # turn the string default into a numerical default 447 } else { 448 $args{default} = 0; 449 } 450 $args{valid_settings} = join ",", @valid_settings; 451 452 BarnOwl::Internal::new_variable_enum($name, $args{default}, $args{summary}, $args{description}, $args{valid_settings}); 453 } 454 455 sub _new_variable { 456 my $func = shift; 457 my $default_default = shift; 458 my $default_valid_settings = shift; 459 my $name = shift; 460 my $args = shift || {}; 461 my %args = ( 462 summary => "", 463 description => "", 464 default => $default_default, 465 valid_settings => $default_valid_settings, 466 %{$args}); 467 $func->($name, $args{default}, $args{summary}, $args{description}, $args{valid_settings}); 440 468 } 441 469 -
perlglue.xs
re89ec48 rcce9369 405 405 406 406 void 407 new_variable_string(name, ival, summ, desc )407 new_variable_string(name, ival, summ, desc, validset) 408 408 const char * name 409 409 const char * ival 410 410 const char * summ 411 411 const char * desc 412 const char * validset 412 413 CODE: 413 414 owl_variable_dict_newvar_string(owl_global_get_vardict(&g), … … 415 416 summ, 416 417 desc, 417 ival); 418 419 void 420 new_variable_int(name, ival, summ, desc) 418 ival, 419 validset); 420 421 void 422 new_variable_int(name, ival, summ, desc, validset) 421 423 const char * name 422 424 int ival 423 425 const char * summ 424 426 const char * desc 427 const char * validset 425 428 CODE: 426 429 owl_variable_dict_newvar_int(owl_global_get_vardict(&g), … … 428 431 summ, 429 432 desc, 430 ival); 431 432 void 433 new_variable_bool(name, ival, summ, desc) 433 ival, 434 validset); 435 436 void 437 new_variable_bool(name, ival, summ, desc, validset) 434 438 const char * name 435 439 int ival 436 440 const char * summ 437 441 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); 439 446 owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), 440 447 name, … … 442 449 desc, 443 450 ival); 451 452 void 453 new_variable_enum(name, ival, summ, desc, validset) 454 const char * name 455 int ival 456 const char * summ 457 const char * desc 458 const char * validset 459 CODE: 460 owl_variable_dict_newvar_enum(owl_global_get_vardict(&g), 461 name, 462 summ, 463 desc, 464 ival, 465 validset); 444 466 445 467 void -
tester.c
ra74a044 re21b921 390 390 FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var)); 391 391 392 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval" );392 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval", "<string>"); 393 393 FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar"))); 394 394 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var))); … … 397 397 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var))); 398 398 399 owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); 399 owl_variable_dict_newvar_enum(&vd, "enumvar", "", "", 0, "foo,bar,baz"); 400 FAIL_UNLESS("get new enum var", NULL != (var = owl_variable_get_var(&vd, "enumvar"))); 401 FAIL_UNLESS("get new enum var", NULL != (v = owl_variable_get(var))); 402 FAIL_UNLESS("get new enum val tostring", !strcmp("foo", value = owl_variable_get_tostring(var))); 403 g_free(value); 404 FAIL_UNLESS("valid update enum var", 0 == owl_variable_set_int(var, 1)); 405 FAIL_UNLESS("update int enum val tostring", !strcmp("bar", value = owl_variable_get_tostring(var))); 406 g_free(value); 407 FAIL_UNLESS("update int enum val", 1 == owl_variable_get_int(var)); 408 FAIL_UNLESS("invalid update enum var", -1 == owl_variable_set_int(var, 5)); 409 FAIL_UNLESS("no update int enum val", 1 == owl_variable_get_int(var)); 410 FAIL_UNLESS("valid update enum var fromstring", 0 == owl_variable_set_fromstring(var, "baz", 0)); 411 FAIL_UNLESS("update int enum val fromstring", 2 == owl_variable_get_int(var)); 412 FAIL_UNLESS("invalid update enum var fromstring", -1 == owl_variable_set_fromstring(var, "xxx", 0)); 413 FAIL_UNLESS("no update int enum val fromstring", 2 == owl_variable_get_int(var)); 414 415 owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47, 0); 400 416 FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar"))); 401 417 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var))); … … 411 427 FAIL_UNLESS("update bool val", !owl_variable_get_bool(var)); 412 428 413 owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL );429 owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL, "<string>"); 414 430 FAIL_UNLESS("get new string (NULL) var", NULL != (var = owl_variable_get_var(&vd, "nullstringvar"))); 415 431 FAIL_UNLESS("get string (NULL)", NULL == (value = owl_variable_get_tostring(var))); -
variable.c
rf271129 rcce9369 3 3 4 4 #define OWLVAR_BOOL(name,default,summary,description) \ 5 { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \5 { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, g_strdup("on,off"), g_strdup(summary), g_strdup(description), NULL, \ 6 6 NULL, NULL, NULL, NULL, NULL, NULL } 7 7 8 8 #define OWLVAR_BOOL_FULL(name,default,summary,description,validate,set,get) \ 9 { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, "on,off", g_strdup(summary), g_strdup(description), NULL, \9 { g_strdup(name), OWL_VARIABLE_BOOL, NULL, default, g_strdup("on,off"), g_strdup(summary), g_strdup(description), NULL, \ 10 10 validate, set, NULL, get, NULL, NULL } 11 11 12 12 #define OWLVAR_INT(name,default,summary,description) \ 13 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, "<int>", g_strdup(summary), g_strdup(description), NULL, \13 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup("<int>"), g_strdup(summary), g_strdup(description), NULL, \ 14 14 NULL, NULL, NULL, NULL, NULL, NULL } 15 15 16 16 #define OWLVAR_INT_FULL(name,default,summary,description,validset,validate,set,get) \ 17 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \17 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \ 18 18 validate, set, NULL, get, NULL, NULL } 19 19 20 20 #define OWLVAR_PATH(name,default,summary,description) \ 21 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<path>", g_strdup(summary), g_strdup(description), NULL, \21 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup("<path>"), g_strdup(summary), g_strdup(description), NULL, \ 22 22 NULL, NULL, NULL, NULL, NULL, NULL } 23 23 24 24 #define OWLVAR_STRING(name,default,summary,description) \ 25 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, "<string>", g_strdup(summary), g_strdup(description), NULL, \25 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup("<string>"), g_strdup(summary), g_strdup(description), NULL, \ 26 26 NULL, NULL, NULL, NULL, NULL, NULL } 27 27 28 28 #define OWLVAR_STRING_FULL(name,default,validset,summary,description,validate,set,get) \ 29 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, validset, g_strdup(summary), g_strdup(description), NULL, \29 { g_strdup(name), OWL_VARIABLE_STRING, g_strdup(default), 0, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \ 30 30 validate, set, NULL, get, NULL, NULL } 31 31 … … 34 34 * correspond to the values that may be specified. */ 35 35 #define OWLVAR_ENUM(name,default,summary,description,validset) \ 36 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \36 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \ 37 37 owl_variable_enum_validate, \ 38 38 NULL, owl_variable_enum_set_fromstring, \ … … 41 41 42 42 #define OWLVAR_ENUM_FULL(name,default,summary,description,validset,validate, set, get) \ 43 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, validset, g_strdup(summary), g_strdup(description), NULL, \43 { g_strdup(name), OWL_VARIABLE_INT, NULL, default, g_strdup(validset), g_strdup(summary), g_strdup(description), NULL, \ 44 44 validate, \ 45 45 set, owl_variable_enum_set_fromstring, \ … … 568 568 int owl_variable_dict_add_from_list(owl_vardict *vd, owl_variable *variables_to_init) 569 569 { 570 int ret; 570 571 owl_variable *var, *cur; 571 572 for (var = variables_to_init; var->name != NULL; var++) { … … 576 577 cur->summary = g_strdup(var->summary); 577 578 cur->description = g_strdup(var->description); 578 switch (cur->type) { 579 cur->validsettings = g_strdup(var->validsettings); 580 if (cur->type == OWL_VARIABLE_STRING) 581 cur->pval_default = g_strdup(var->pval_default); 582 ret = owl_variable_init_defaults(cur); 583 if (ret != 0) { 584 fprintf(stderr, "owl_variable_setup: invalid variable type\n"); 585 return ret; 586 } 587 owl_dict_insert_element(vd, cur->name, cur, NULL); 588 } 589 return 0; 590 } 591 592 int owl_variable_init_defaults(owl_variable *cur) 593 { 594 switch (cur->type) { 579 595 case OWL_VARIABLE_OTHER: 580 596 cur->set_fn(cur, cur->pval_default); … … 593 609 if (!cur->delete_fn) 594 610 cur->delete_fn = owl_variable_delete_default; 595 cur->pval_default = g_strdup(var->pval_default);596 611 cur->set_fn(cur, cur->pval_default); 597 612 break; … … 629 644 break; 630 645 default: 631 fprintf(stderr, "owl_variable_setup: invalid variable type\n"); 632 return(-2); 633 } 634 owl_dict_insert_element(vd, cur->name, cur, NULL); 646 return -2; 635 647 } 636 648 return 0; … … 642 654 } 643 655 644 CALLER_OWN owl_variable *owl_variable_newvar(const char *name, const char *summary, const char *description )656 CALLER_OWN owl_variable *owl_variable_newvar(const char *name, const char *summary, const char *description, const char *validsettings, int type) 645 657 { 646 658 owl_variable * var = g_new0(owl_variable, 1); … … 648 660 var->summary = g_strdup(summary); 649 661 var->description = g_strdup(description); 662 var->validsettings = g_strdup(validsettings); 663 var->type = type; 650 664 return var; 651 665 } 652 666 653 void owl_variable_update(owl_variable *var, const char *summary, const char *desc) { 654 g_free(var->summary); 655 var->summary = g_strdup(summary); 656 g_free(var->description); 657 var->description = g_strdup(desc); 658 } 659 660 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval) 667 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval, const char *validsettings) 661 668 { 662 669 owl_variable *old = owl_variable_get_var(vd, name); 663 if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) { 664 owl_variable_update(old, summ, desc); 665 g_free(old->pval_default); 666 old->pval_default = g_strdup(initval); 667 } else { 668 owl_variable * var = owl_variable_newvar(name, summ, desc); 669 var->type = OWL_VARIABLE_STRING; 670 var->validsettings = "<string>"; 671 var->pval_default = g_strdup(initval); 672 var->set_fn = owl_variable_string_set_default; 673 var->set_fromstring_fn = owl_variable_string_set_fromstring_default; 674 var->get_fn = owl_variable_get_default; 675 var->get_tostring_fn = owl_variable_string_get_tostring_default; 676 var->delete_fn = owl_variable_delete_default; 677 var->set_fn(var, initval); 678 owl_variable_dict_add_variable(vd, var); 679 } 680 } 681 682 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval) 670 char *oldval = NULL; 671 if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) 672 oldval = owl_variable_get_tostring(old); 673 owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_STRING); 674 var->pval_default = g_strdup(initval); 675 owl_variable_init_defaults(var); 676 if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) 677 var->set_fn(var, oldval); 678 g_free(oldval); 679 owl_variable_dict_add_variable(vd, var); 680 } 681 682 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval, const char *validsettings) 683 683 { 684 684 owl_variable *old = owl_variable_get_var(vd, name); 685 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) { 686 owl_variable_update(old, summ, desc); 687 old->ival_default = initval; 688 } else { 689 owl_variable * var = owl_variable_newvar(name, summ, desc); 690 var->type = OWL_VARIABLE_INT; 691 var->validsettings = "<int>"; 692 var->ival_default = initval; 693 var->validate_fn = owl_variable_int_validate_default; 694 var->set_fn = owl_variable_int_set_default; 695 var->set_fromstring_fn = owl_variable_int_set_fromstring_default; 696 var->get_fn = owl_variable_get_default; 697 var->get_tostring_fn = owl_variable_int_get_tostring_default; 698 var->delete_fn = owl_variable_delete_default; 699 var->val = g_new(int, 1); 700 var->set_fn(var, &initval); 701 owl_variable_dict_add_variable(vd, var); 702 } 685 int oldval; 686 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) 687 oldval = owl_variable_get_int(old); 688 owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_INT); 689 var->ival_default = initval; 690 owl_variable_init_defaults(var); 691 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) 692 var->set_fn(var, &oldval); 693 owl_variable_dict_add_variable(vd, var); 703 694 } 704 695 … … 706 697 { 707 698 owl_variable *old = owl_variable_get_var(vd, name); 708 if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) { 709 owl_variable_update(old, summ, desc); 710 old->ival_default = initval; 711 } else { 712 owl_variable * var = owl_variable_newvar(name, summ, desc); 713 var->type = OWL_VARIABLE_BOOL; 714 var->validsettings = "on,off"; 715 var->ival_default = initval; 716 var->validate_fn = owl_variable_bool_validate_default; 717 var->set_fn = owl_variable_bool_set_default; 718 var->set_fromstring_fn = owl_variable_bool_set_fromstring_default; 719 var->get_fn = owl_variable_get_default; 720 var->get_tostring_fn = owl_variable_bool_get_tostring_default; 721 var->delete_fn = owl_variable_delete_default; 722 var->val = g_new(int, 1); 723 var->set_fn(var, &initval); 724 owl_variable_dict_add_variable(vd, var); 725 } 699 int oldval; 700 if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) 701 oldval = owl_variable_get_bool(old); 702 owl_variable *var = owl_variable_newvar(name, summ, desc, "on,off", OWL_VARIABLE_BOOL); 703 var->ival_default = initval; 704 owl_variable_init_defaults(var); 705 if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) 706 var->set_fn(var, &oldval); 707 owl_variable_dict_add_variable(vd, var); 708 } 709 710 void owl_variable_dict_newvar_enum(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval, const char *validsettings) 711 { 712 owl_variable *old = owl_variable_get_var(vd, name); 713 int oldval; 714 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) 715 oldval = owl_variable_get_int(old); 716 owl_variable *var = owl_variable_newvar(name, summ, desc, validsettings, OWL_VARIABLE_INT); 717 var->ival_default = initval; 718 var->validate_fn = owl_variable_enum_validate; 719 var->set_fromstring_fn = owl_variable_enum_set_fromstring; 720 var->get_tostring_fn = owl_variable_enum_get_tostring; 721 owl_variable_init_defaults(var); 722 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) 723 var->set_fn(var, &oldval); 724 owl_variable_dict_add_variable(vd, var); 726 725 } 727 726 … … 741 740 g_free(v->summary); 742 741 g_free(v->description); 742 g_free(v->validsettings); 743 743 if (v->type == OWL_VARIABLE_STRING) 744 744 g_free(v->pval_default); -
commands.c
r7803326 rf89cc6f 1985 1985 } 1986 1986 /* check for a zwrite -m */ 1987 z = owl_zwrite_new( buff);1987 z = owl_zwrite_new(argc, argv); 1988 1988 if (!z) { 1989 1989 owl_function_error("Error in zwrite arguments"); -
perl/lib/BarnOwl/ModuleLoader.pm
rf544216 rf34728b 127 127 } 128 128 129 sub complete_module_name { 130 return sort(keys %modules); 131 } 132 129 133 sub register_keybindings { 130 134 BarnOwl::new_command('reload-modules', sub {BarnOwl::ModuleLoader->reload}, { … … 138 142 description => q{Reloads a single module located in ~/.owl/modules or the system modules directory} 139 143 }); 144 145 BarnOwl::Completion::register_completer('reload-module', \&complete_module_name); 140 146 } 141 147 -
util.c
r6646fdb r7b89e8c 262 262 CALLER_OWN char *owl_arg_quote(const char *arg) 263 263 { 264 GString *buf = g_string_new(""); ;264 GString *buf = g_string_new(""); 265 265 owl_string_append_quoted_arg(buf, arg); 266 return g_string_free(buf, false); 267 } 268 269 /* Returns a quoted version of argv. owl_parseline on the result should give 270 * back the input. */ 271 CALLER_OWN char *owl_argv_quote(int argc, const char *const *argv) 272 { 273 int i; 274 GString *buf = g_string_new(""); 275 for (i = 0; i < argc; i++) { 276 if (i > 0) 277 g_string_append_c(buf, ' '); 278 owl_string_append_quoted_arg(buf, argv[i]); 279 } 266 280 return g_string_free(buf, false); 267 281 } -
zephyr.c
rf271129 rd953ede 909 909 g_free(to); 910 910 911 z = owl_zwrite_new (tmpbuff);911 z = owl_zwrite_new_from_line(tmpbuff); 912 912 g_free(tmpbuff); 913 913 if (z == NULL) { -
zwrite.c
rf271129 ref4074b 1 1 #include "owl.h" 2 2 3 CALLER_OWN owl_zwrite *owl_zwrite_new (const char *line)3 CALLER_OWN owl_zwrite *owl_zwrite_new_from_line(const char *line) 4 4 { 5 5 owl_zwrite *z = g_new(owl_zwrite, 1); 6 if (owl_zwrite_create_from_line(z, line) <0) {7 owl_zwrite_delete(z);6 if (owl_zwrite_create_from_line(z, line) != 0) { 7 g_free(z); 8 8 return NULL; 9 9 } … … 11 11 } 12 12 13 CALLER_OWN owl_zwrite *owl_zwrite_new(int argc, const char *const *argv) 14 { 15 owl_zwrite *z = g_new(owl_zwrite, 1); 16 if (owl_zwrite_create(z, argc, argv) != 0) { 17 g_free(z); 18 return NULL; 19 } 20 return z; 21 } 22 13 23 G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create_from_line(owl_zwrite *z, const char *line) 14 24 { 15 int argc , badargs, myargc;25 int argc; 16 26 char **argv; 17 const char *const *myargv; 27 int ret; 28 29 /* parse the command line for options */ 30 argv = owl_parseline(line, &argc); 31 if (argc < 0) { 32 owl_function_error("Unbalanced quotes in zwrite"); 33 return -1; 34 } 35 ret = owl_zwrite_create(z, argc, strs(argv)); 36 g_strfreev(argv); 37 return ret; 38 } 39 40 G_GNUC_WARN_UNUSED_RESULT int owl_zwrite_create(owl_zwrite *z, int argc, const char *const *argv) 41 { 42 int badargs = 0; 18 43 char *msg = NULL; 19 20 badargs=0;21 44 22 45 /* start with null entries */ … … 31 54 z->noping=0; 32 55 z->recips = g_ptr_array_new(); 33 z->zwriteline = g_strdup(line); 34 35 /* parse the command line for options */ 36 argv=owl_parseline(line, &argc); 37 myargv=strs(argv); 38 if (argc<0) { 39 owl_function_error("Unbalanced quotes in zwrite"); 40 return(-1); 41 } 42 myargc=argc; 43 if (myargc && *(myargv[0])!='-') { 44 z->cmd=g_strdup(myargv[0]); 45 myargc--; 46 myargv++; 47 } 48 while (myargc) { 49 if (!strcmp(myargv[0], "-c")) { 50 if (myargc<2) { 51 badargs=1; 52 break; 53 } 54 z->class=owl_validate_utf8(myargv[1]); 55 myargv+=2; 56 myargc-=2; 57 } else if (!strcmp(myargv[0], "-i")) { 58 if (myargc<2) { 59 badargs=1; 60 break; 61 } 62 z->inst=owl_validate_utf8(myargv[1]); 63 myargv+=2; 64 myargc-=2; 65 } else if (!strcmp(myargv[0], "-r")) { 66 if (myargc<2) { 67 badargs=1; 68 break; 69 } 70 z->realm=owl_validate_utf8(myargv[1]); 71 myargv+=2; 72 myargc-=2; 73 } else if (!strcmp(myargv[0], "-s")) { 74 if (myargc<2) { 75 badargs=1; 76 break; 77 } 78 z->zsig=owl_validate_utf8(myargv[1]); 79 myargv+=2; 80 myargc-=2; 81 } else if (!strcmp(myargv[0], "-O")) { 82 if (myargc<2) { 83 badargs=1; 84 break; 85 } 86 z->opcode=owl_validate_utf8(myargv[1]); 87 myargv+=2; 88 myargc-=2; 89 } else if (!strcmp(myargv[0], "-m")) { 90 if (myargc<2) { 56 z->zwriteline = owl_argv_quote(argc, argv); 57 58 if (argc && *(argv[0])!='-') { 59 z->cmd=g_strdup(argv[0]); 60 argc--; 61 argv++; 62 } 63 while (argc) { 64 if (!strcmp(argv[0], "-c")) { 65 if (argc<2) { 66 badargs=1; 67 break; 68 } 69 z->class=owl_validate_utf8(argv[1]); 70 argv+=2; 71 argc-=2; 72 } else if (!strcmp(argv[0], "-i")) { 73 if (argc<2) { 74 badargs=1; 75 break; 76 } 77 z->inst=owl_validate_utf8(argv[1]); 78 argv+=2; 79 argc-=2; 80 } else if (!strcmp(argv[0], "-r")) { 81 if (argc<2) { 82 badargs=1; 83 break; 84 } 85 z->realm=owl_validate_utf8(argv[1]); 86 argv+=2; 87 argc-=2; 88 } else if (!strcmp(argv[0], "-s")) { 89 if (argc<2) { 90 badargs=1; 91 break; 92 } 93 z->zsig=owl_validate_utf8(argv[1]); 94 argv+=2; 95 argc-=2; 96 } else if (!strcmp(argv[0], "-O")) { 97 if (argc<2) { 98 badargs=1; 99 break; 100 } 101 z->opcode=owl_validate_utf8(argv[1]); 102 argv+=2; 103 argc-=2; 104 } else if (!strcmp(argv[0], "-m")) { 105 if (argc<2) { 91 106 badargs=1; 92 107 break; … … 99 114 100 115 /* Once we have -m, gobble up everything else on the line */ 101 myargv++;102 myargc--;103 msg = g_strjoinv(" ", (char**) myargv);116 argv++; 117 argc--; 118 msg = g_strjoinv(" ", (char**)argv); 104 119 break; 105 } else if (!strcmp( myargv[0], "-C")) {120 } else if (!strcmp(argv[0], "-C")) { 106 121 z->cc=1; 107 myargv++;108 myargc--;109 } else if (!strcmp( myargv[0], "-n")) {122 argv++; 123 argc--; 124 } else if (!strcmp(argv[0], "-n")) { 110 125 z->noping=1; 111 myargv++;112 myargc--;126 argv++; 127 argc--; 113 128 } else { 114 129 /* anything unattached is a recipient */ 115 g_ptr_array_add(z->recips, owl_validate_utf8( myargv[0]));116 myargv++;117 myargc--;130 g_ptr_array_add(z->recips, owl_validate_utf8(argv[0])); 131 argv++; 132 argc--; 118 133 } 119 134 } 120 135 121 g_strfreev(argv);122 123 136 if (badargs) { 137 owl_zwrite_cleanup(z); 124 138 return(-1); 125 139 } … … 129 143 z->recips->len == 0) { 130 144 owl_function_error("You must specify a recipient for zwrite"); 145 owl_zwrite_cleanup(z); 131 146 return(-1); 132 147 } … … 254 269 owl_zwrite z; 255 270 int rv; 256 rv =owl_zwrite_create_from_line(&z, cmd);257 if (rv ) return(rv);271 rv = owl_zwrite_create_from_line(&z, cmd); 272 if (rv != 0) return rv; 258 273 if (!owl_zwrite_is_message_set(&z)) { 259 274 owl_zwrite_set_message(&z, msg);
Note: See TracChangeset
for help on using the changeset viewer.