Changeset e19eb97 for variable.c
- Timestamp:
- Aug 15, 2009, 7:08:18 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 1077891a
- Parents:
- fa4562c
- git-author:
- Anders Kaseorg <andersk@mit.edu> (08/04/09 02:37:51)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (08/15/09 19:08:18)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
variable.c
rfa4562c re19eb97 375 375 /* commonly useful */ 376 376 377 int owl_variable_int_validate_gt0(owl_variable *v, void *newval)377 int owl_variable_int_validate_gt0(owl_variable *v, const void *newval) 378 378 { 379 379 if (newval == NULL) return(0); … … 382 382 } 383 383 384 int owl_variable_int_validate_positive(owl_variable *v, void *newval)384 int owl_variable_int_validate_positive(owl_variable *v, const void *newval) 385 385 { 386 386 if (newval == NULL) return(0); … … 390 390 391 391 /* typewinsize */ 392 int owl_variable_typewinsize_set(owl_variable *v, void *newval)392 int owl_variable_typewinsize_set(owl_variable *v, const void *newval) 393 393 { 394 394 int rv; … … 399 399 400 400 /* debug (cache value in g->debug) */ 401 int owl_variable_debug_set(owl_variable *v, void *newval)401 int owl_variable_debug_set(owl_variable *v, const void *newval) 402 402 { 403 403 if (newval && (*(const int*)newval == 1 || *(const int*)newval == 0)) { … … 408 408 409 409 /* When 'aaway' is changed, need to notify the AIM server */ 410 int owl_variable_aaway_set(owl_variable *v, void *newval)410 int owl_variable_aaway_set(owl_variable *v, const void *newval) 411 411 { 412 412 if (newval) { … … 420 420 } 421 421 422 int owl_variable_pseudologins_set(owl_variable *v, void *newval)422 int owl_variable_pseudologins_set(owl_variable *v, const void *newval) 423 423 { 424 424 if (newval) { … … 432 432 /* note that changing the value of this will clobber 433 433 * any user setting of this */ 434 int owl_variable_disable_ctrl_d_set(owl_variable *v, void *newval)434 int owl_variable_disable_ctrl_d_set(owl_variable *v, const void *newval) 435 435 { 436 436 … … 449 449 } 450 450 451 int owl_variable_tty_set(owl_variable *v, void *newval)451 int owl_variable_tty_set(owl_variable *v, const void *newval) 452 452 { 453 453 owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval); … … 531 531 } 532 532 533 owl_variable * owl_variable_newvar(c har *name, char *summary,char * description) {533 owl_variable * owl_variable_newvar(const char *name, const char *summary, const char * description) { 534 534 owl_variable * var = owl_malloc(sizeof(owl_variable)); 535 535 memset(var, 0, sizeof(owl_variable)); … … 540 540 } 541 541 542 void owl_variable_update(owl_variable *var, c har *summary,char *desc) {542 void owl_variable_update(owl_variable *var, const char *summary, const char *desc) { 543 543 if(var->summary) owl_free(var->summary); 544 544 var->summary = owl_strdup(summary); … … 547 547 } 548 548 549 void owl_variable_dict_newvar_string(owl_vardict * vd, c har *name, char *summ, char * desc,char * initval) {549 void owl_variable_dict_newvar_string(owl_vardict * vd, const char *name, const char *summ, const char * desc, const char * initval) { 550 550 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING); 551 551 if(old) { … … 567 567 } 568 568 569 void owl_variable_dict_newvar_int(owl_vardict * vd, c har *name, char *summ,char * desc, int initval) {569 void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 570 570 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT); 571 571 if(old) { … … 588 588 } 589 589 590 void owl_variable_dict_newvar_bool(owl_vardict * vd, c har *name, char *summ,char * desc, int initval) {590 void owl_variable_dict_newvar_bool(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 591 591 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL); 592 592 if(old) { … … 628 628 629 629 630 c har *owl_variable_get_description(owl_variable *v) {630 const char *owl_variable_get_description(owl_variable *v) { 631 631 return v->description; 632 632 } 633 633 634 c har *owl_variable_get_summary(owl_variable *v) {634 const char *owl_variable_get_summary(owl_variable *v) { 635 635 return v->summary; 636 636 } 637 637 638 c har *owl_variable_get_validsettings(owl_variable *v) {638 const char *owl_variable_get_validsettings(owl_variable *v) { 639 639 if (v->validsettings) { 640 640 return v->validsettings; … … 647 647 648 648 /* returns 0 on success, prints a status msg if msg is true */ 649 int owl_variable_set_fromstring(owl_vardict *d, c har *name,char *value, int msg, int requirebool) {649 int owl_variable_set_fromstring(owl_vardict *d, const char *name, const char *value, int msg, int requirebool) { 650 650 owl_variable *v; 651 651 char buff2[1024]; … … 676 676 } 677 677 678 int owl_variable_set_string(owl_vardict *d, c har *name,char *newval) {678 int owl_variable_set_string(owl_vardict *d, const char *name, const char *newval) { 679 679 owl_variable *v; 680 680 if (!name) return(-1); … … 685 685 } 686 686 687 int owl_variable_set_int(owl_vardict *d, c har *name, int newval) {687 int owl_variable_set_int(owl_vardict *d, const char *name, int newval) { 688 688 owl_variable *v; 689 689 if (!name) return(-1); … … 694 694 } 695 695 696 int owl_variable_set_bool_on(owl_vardict *d, c har *name) {696 int owl_variable_set_bool_on(owl_vardict *d, const char *name) { 697 697 return owl_variable_set_int(d,name,1); 698 698 } 699 699 700 int owl_variable_set_bool_off(owl_vardict *d, c har *name) {700 int owl_variable_set_bool_off(owl_vardict *d, const char *name) { 701 701 return owl_variable_set_int(d,name,0); 702 702 } 703 703 704 int owl_variable_get_tostring(owl_vardict *d, c har *name, char *buf, int bufsize) {704 int owl_variable_get_tostring(owl_vardict *d, const char *name, char *buf, int bufsize) { 705 705 owl_variable *v; 706 706 if (!name) return(-1); … … 710 710 } 711 711 712 int owl_variable_get_default_tostring(owl_vardict *d, c har *name, char *buf, int bufsize) {712 int owl_variable_get_default_tostring(owl_vardict *d, const char *name, char *buf, int bufsize) { 713 713 owl_variable *v; 714 714 if (!name) return(-1); … … 722 722 } 723 723 724 owl_variable *owl_variable_get_var(owl_vardict *d, c har *name, int require_type) {724 owl_variable *owl_variable_get_var(owl_vardict *d, const char *name, int require_type) { 725 725 owl_variable *v; 726 726 if (!name) return(NULL); … … 731 731 732 732 /* returns a reference */ 733 void *owl_variable_get(owl_vardict *d,char *name, int require_type) {733 const void *owl_variable_get(owl_vardict *d, const char *name, int require_type) { 734 734 owl_variable *v = owl_variable_get_var(d, name, require_type); 735 735 if(v == NULL) return NULL; … … 738 738 739 739 /* returns a reference */ 740 c har *owl_variable_get_string(owl_vardict *d,char *name) {740 const char *owl_variable_get_string(owl_vardict *d, const char *name) { 741 741 return owl_variable_get(d,name, OWL_VARIABLE_STRING); 742 742 } 743 743 744 744 /* returns a reference */ 745 void *owl_variable_get_other(owl_vardict *d,char *name) {745 const void *owl_variable_get_other(owl_vardict *d, const char *name) { 746 746 return owl_variable_get(d,name, OWL_VARIABLE_OTHER); 747 747 } 748 748 749 int owl_variable_get_int(owl_vardict *d, c har *name) {749 int owl_variable_get_int(owl_vardict *d, const char *name) { 750 750 const int *pi; 751 751 pi = owl_variable_get(d,name,OWL_VARIABLE_INT); … … 754 754 } 755 755 756 int owl_variable_get_bool(owl_vardict *d, c har *name) {756 int owl_variable_get_bool(owl_vardict *d, const char *name) { 757 757 const int *pi; 758 758 pi = owl_variable_get(d,name,OWL_VARIABLE_BOOL); … … 761 761 } 762 762 763 void owl_variable_describe(owl_vardict *d, c har *name, owl_fmtext *fm) {763 void owl_variable_describe(owl_vardict *d, const char *name, owl_fmtext *fm) { 764 764 char defaultbuf[50]; 765 765 char buf[1024]; … … 785 785 } 786 786 787 void owl_variable_get_help(owl_vardict *d, c har *name, owl_fmtext *fm) {787 void owl_variable_get_help(owl_vardict *d, const char *name, owl_fmtext *fm) { 788 788 char buff[1024]; 789 789 int bufflen = 1023; … … 839 839 /* default common functions */ 840 840 841 void *owl_variable_get_default(owl_variable *v) {841 const void *owl_variable_get_default(owl_variable *v) { 842 842 return v->val; 843 843 } … … 849 849 /* default functions for booleans */ 850 850 851 int owl_variable_bool_validate_default(owl_variable *v, void *newval) {851 int owl_variable_bool_validate_default(owl_variable *v, const void *newval) { 852 852 if (newval == NULL) return(0); 853 853 else if (*(const int*)newval==1 || *(const int*)newval==0) return(1); … … 855 855 } 856 856 857 int owl_variable_bool_set_default(owl_variable *v, void *newval) {857 int owl_variable_bool_set_default(owl_variable *v, const void *newval) { 858 858 if (v->validate_fn) { 859 859 if (!v->validate_fn(v, newval)) return(-1); … … 863 863 } 864 864 865 int owl_variable_bool_set_fromstring_default(owl_variable *v, c har *newval) {865 int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval) { 866 866 int i; 867 867 if (!strcmp(newval, "on")) i=1; … … 871 871 } 872 872 873 int owl_variable_bool_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {873 int owl_variable_bool_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) { 874 874 if (val == NULL) { 875 875 snprintf(buf, bufsize, "<null>"); … … 889 889 /* default functions for integers */ 890 890 891 int owl_variable_int_validate_default(owl_variable *v, void *newval) {891 int owl_variable_int_validate_default(owl_variable *v, const void *newval) { 892 892 if (newval == NULL) return(0); 893 893 else return (1); 894 894 } 895 895 896 int owl_variable_int_set_default(owl_variable *v, void *newval) {896 int owl_variable_int_set_default(owl_variable *v, const void *newval) { 897 897 if (v->validate_fn) { 898 898 if (!v->validate_fn(v, newval)) return(-1); … … 902 902 } 903 903 904 int owl_variable_int_set_fromstring_default(owl_variable *v, c har *newval) {904 int owl_variable_int_set_fromstring_default(owl_variable *v, const char *newval) { 905 905 int i; 906 c har *ep = "x";906 const char *ep = "x"; 907 907 i = strtol(newval, (char **)&ep, 10); 908 908 if (*ep || ep==newval) return(-1); … … 910 910 } 911 911 912 int owl_variable_int_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {912 int owl_variable_int_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) { 913 913 if (val == NULL) { 914 914 snprintf(buf, bufsize, "<null>"); … … 922 922 /* default functions for enums (a variant of integers) */ 923 923 924 int owl_variable_enum_validate(owl_variable *v, void *newval) {924 int owl_variable_enum_validate(owl_variable *v, const void *newval) { 925 925 char **enums; 926 926 int nenums, val; … … 936 936 } 937 937 938 int owl_variable_enum_set_fromstring(owl_variable *v, c har *newval) {938 int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval) { 939 939 char **enums; 940 940 int nenums, i, val=-1; … … 952 952 } 953 953 954 int owl_variable_enum_get_tostring(owl_variable *v, char* buf, int bufsize, void *val) {954 int owl_variable_enum_get_tostring(owl_variable *v, char* buf, int bufsize, const void *val) { 955 955 char **enums; 956 956 int nenums, i; … … 973 973 /* default functions for stringeans */ 974 974 975 int owl_variable_string_validate_default(struct _owl_variable *v, void *newval) {975 int owl_variable_string_validate_default(struct _owl_variable *v, const void *newval) { 976 976 if (newval == NULL) return(0); 977 977 else return (1); 978 978 } 979 979 980 int owl_variable_string_set_default(owl_variable *v, void *newval) {980 int owl_variable_string_set_default(owl_variable *v, const void *newval) { 981 981 if (v->validate_fn) { 982 982 if (!v->validate_fn(v, newval)) return(-1); … … 987 987 } 988 988 989 int owl_variable_string_set_fromstring_default(owl_variable *v, c har *newval) {989 int owl_variable_string_set_fromstring_default(owl_variable *v, const char *newval) { 990 990 return (v->set_fn(v, newval)); 991 991 } 992 992 993 int owl_variable_string_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {993 int owl_variable_string_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) { 994 994 if (val == NULL) { 995 995 snprintf(buf, bufsize, "<null>"); 996 996 return -1; 997 997 } else { 998 snprintf(buf, bufsize, "%s", (c har*)val);998 snprintf(buf, bufsize, "%s", (const char*)val); 999 999 return 0; 1000 1000 } … … 1015 1015 int numfailed=0; 1016 1016 char buf[1024]; 1017 void *v;1017 const void *v; 1018 1018 1019 1019 in_regtest = 1;
Note: See TracChangeset
for help on using the changeset viewer.