Changeset e19eb97 for variable.c


Ignore:
Timestamp:
Aug 15, 2009, 7:08:18 PM (15 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
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)
Message:
Add const qualifiers for char * and void *.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • variable.c

    rfa4562c re19eb97  
    375375/* commonly useful */
    376376
    377 int owl_variable_int_validate_gt0(owl_variable *v, void *newval)
     377int owl_variable_int_validate_gt0(owl_variable *v, const void *newval)
    378378{
    379379  if (newval == NULL) return(0);
     
    382382}
    383383
    384 int owl_variable_int_validate_positive(owl_variable *v, void *newval)
     384int owl_variable_int_validate_positive(owl_variable *v, const void *newval)
    385385{
    386386  if (newval == NULL) return(0);
     
    390390
    391391/* typewinsize */
    392 int owl_variable_typewinsize_set(owl_variable *v, void *newval)
     392int owl_variable_typewinsize_set(owl_variable *v, const void *newval)
    393393{
    394394  int rv;
     
    399399
    400400/* debug (cache value in g->debug) */
    401 int owl_variable_debug_set(owl_variable *v, void *newval)
     401int owl_variable_debug_set(owl_variable *v, const void *newval)
    402402{
    403403  if (newval && (*(const int*)newval == 1 || *(const int*)newval == 0)) {
     
    408408
    409409/* When 'aaway' is changed, need to notify the AIM server */
    410 int owl_variable_aaway_set(owl_variable *v, void *newval)
     410int owl_variable_aaway_set(owl_variable *v, const void *newval)
    411411{
    412412  if (newval) {
     
    420420}
    421421
    422 int owl_variable_pseudologins_set(owl_variable *v, void *newval)
     422int owl_variable_pseudologins_set(owl_variable *v, const void *newval)
    423423{
    424424  if (newval) {
     
    432432/* note that changing the value of this will clobber
    433433 * any user setting of this */
    434 int owl_variable_disable_ctrl_d_set(owl_variable *v, void *newval)
     434int owl_variable_disable_ctrl_d_set(owl_variable *v, const void *newval)
    435435{
    436436
     
    449449}
    450450
    451 int owl_variable_tty_set(owl_variable *v, void *newval)
     451int owl_variable_tty_set(owl_variable *v, const void *newval)
    452452{
    453453  owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval);
     
    531531}
    532532
    533 owl_variable * owl_variable_newvar(char *name, char *summary, char * description) {
     533owl_variable * owl_variable_newvar(const char *name, const char *summary, const char * description) {
    534534  owl_variable * var = owl_malloc(sizeof(owl_variable));
    535535  memset(var, 0, sizeof(owl_variable));
     
    540540}
    541541
    542 void owl_variable_update(owl_variable *var, char *summary, char *desc) {
     542void owl_variable_update(owl_variable *var, const char *summary, const char *desc) {
    543543  if(var->summary) owl_free(var->summary);
    544544  var->summary = owl_strdup(summary);
     
    547547}
    548548
    549 void owl_variable_dict_newvar_string(owl_vardict * vd, char *name, char *summ, char * desc, char * initval) {
     549void owl_variable_dict_newvar_string(owl_vardict * vd, const char *name, const char *summ, const char * desc, const char * initval) {
    550550  owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING);
    551551  if(old) {
     
    567567}
    568568
    569 void owl_variable_dict_newvar_int(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
     569void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) {
    570570  owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT);
    571571  if(old) {
     
    588588}
    589589
    590 void owl_variable_dict_newvar_bool(owl_vardict * vd, char *name, char *summ, char * desc, int initval) {
     590void owl_variable_dict_newvar_bool(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) {
    591591  owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL);
    592592  if(old) {
     
    628628
    629629
    630 char *owl_variable_get_description(owl_variable *v) {
     630const char *owl_variable_get_description(owl_variable *v) {
    631631  return v->description;
    632632}
    633633
    634 char *owl_variable_get_summary(owl_variable *v) {
     634const char *owl_variable_get_summary(owl_variable *v) {
    635635  return v->summary;
    636636}
    637637
    638 char *owl_variable_get_validsettings(owl_variable *v) {
     638const char *owl_variable_get_validsettings(owl_variable *v) {
    639639  if (v->validsettings) {
    640640    return v->validsettings;
     
    647647
    648648/* returns 0 on success, prints a status msg if msg is true */
    649 int owl_variable_set_fromstring(owl_vardict *d, char *name, char *value, int msg, int requirebool) {
     649int owl_variable_set_fromstring(owl_vardict *d, const char *name, const char *value, int msg, int requirebool) {
    650650  owl_variable *v;
    651651  char buff2[1024];
     
    676676}
    677677 
    678 int owl_variable_set_string(owl_vardict *d, char *name, char *newval) {
     678int owl_variable_set_string(owl_vardict *d, const char *name, const char *newval) {
    679679  owl_variable *v;
    680680  if (!name) return(-1);
     
    685685}
    686686 
    687 int owl_variable_set_int(owl_vardict *d, char *name, int newval) {
     687int owl_variable_set_int(owl_vardict *d, const char *name, int newval) {
    688688  owl_variable *v;
    689689  if (!name) return(-1);
     
    694694}
    695695 
    696 int owl_variable_set_bool_on(owl_vardict *d, char *name) {
     696int owl_variable_set_bool_on(owl_vardict *d, const char *name) {
    697697  return owl_variable_set_int(d,name,1);
    698698}
    699699
    700 int owl_variable_set_bool_off(owl_vardict *d, char *name) {
     700int owl_variable_set_bool_off(owl_vardict *d, const char *name) {
    701701  return owl_variable_set_int(d,name,0);
    702702}
    703703
    704 int owl_variable_get_tostring(owl_vardict *d, char *name, char *buf, int bufsize) {
     704int owl_variable_get_tostring(owl_vardict *d, const char *name, char *buf, int bufsize) {
    705705  owl_variable *v;
    706706  if (!name) return(-1);
     
    710710}
    711711
    712 int owl_variable_get_default_tostring(owl_vardict *d, char *name, char *buf, int bufsize) {
     712int owl_variable_get_default_tostring(owl_vardict *d, const char *name, char *buf, int bufsize) {
    713713  owl_variable *v;
    714714  if (!name) return(-1);
     
    722722}
    723723
    724 owl_variable *owl_variable_get_var(owl_vardict *d, char *name, int require_type) {
     724owl_variable *owl_variable_get_var(owl_vardict *d, const char *name, int require_type) {
    725725  owl_variable *v;
    726726  if (!name) return(NULL);
     
    731731
    732732/* returns a reference */
    733 void *owl_variable_get(owl_vardict *d, char *name, int require_type) {
     733const void *owl_variable_get(owl_vardict *d, const char *name, int require_type) {
    734734  owl_variable *v = owl_variable_get_var(d, name, require_type);
    735735  if(v == NULL) return NULL;
     
    738738
    739739/* returns a reference */
    740 char *owl_variable_get_string(owl_vardict *d, char *name) {
     740const char *owl_variable_get_string(owl_vardict *d, const char *name) {
    741741  return owl_variable_get(d,name, OWL_VARIABLE_STRING);
    742742}
    743743
    744744/* returns a reference */
    745 void *owl_variable_get_other(owl_vardict *d, char *name) {
     745const void *owl_variable_get_other(owl_vardict *d, const char *name) {
    746746  return owl_variable_get(d,name, OWL_VARIABLE_OTHER);
    747747}
    748748
    749 int owl_variable_get_int(owl_vardict *d, char *name) {
     749int owl_variable_get_int(owl_vardict *d, const char *name) {
    750750  const int *pi;
    751751  pi = owl_variable_get(d,name,OWL_VARIABLE_INT);
     
    754754}
    755755
    756 int owl_variable_get_bool(owl_vardict *d, char *name) {
     756int owl_variable_get_bool(owl_vardict *d, const char *name) {
    757757  const int *pi;
    758758  pi = owl_variable_get(d,name,OWL_VARIABLE_BOOL);
     
    761761}
    762762
    763 void owl_variable_describe(owl_vardict *d, char *name, owl_fmtext *fm) {
     763void owl_variable_describe(owl_vardict *d, const char *name, owl_fmtext *fm) {
    764764  char defaultbuf[50];
    765765  char buf[1024];
     
    785785}
    786786
    787 void owl_variable_get_help(owl_vardict *d, char *name, owl_fmtext *fm) {
     787void owl_variable_get_help(owl_vardict *d, const char *name, owl_fmtext *fm) {
    788788  char buff[1024];
    789789  int bufflen = 1023;
     
    839839/* default common functions */
    840840
    841 void *owl_variable_get_default(owl_variable *v) {
     841const void *owl_variable_get_default(owl_variable *v) {
    842842  return v->val;
    843843}
     
    849849/* default functions for booleans */
    850850
    851 int owl_variable_bool_validate_default(owl_variable *v, void *newval) {
     851int owl_variable_bool_validate_default(owl_variable *v, const void *newval) {
    852852  if (newval == NULL) return(0);
    853853  else if (*(const int*)newval==1 || *(const int*)newval==0) return(1);
     
    855855}
    856856
    857 int owl_variable_bool_set_default(owl_variable *v, void *newval) {
     857int owl_variable_bool_set_default(owl_variable *v, const void *newval) {
    858858  if (v->validate_fn) {
    859859    if (!v->validate_fn(v, newval)) return(-1);
     
    863863}
    864864
    865 int owl_variable_bool_set_fromstring_default(owl_variable *v, char *newval) {
     865int owl_variable_bool_set_fromstring_default(owl_variable *v, const char *newval) {
    866866  int i;
    867867  if (!strcmp(newval, "on")) i=1;
     
    871871}
    872872
    873 int owl_variable_bool_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {
     873int owl_variable_bool_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) {
    874874  if (val == NULL) {
    875875    snprintf(buf, bufsize, "<null>");
     
    889889/* default functions for integers */
    890890
    891 int owl_variable_int_validate_default(owl_variable *v, void *newval) {
     891int owl_variable_int_validate_default(owl_variable *v, const void *newval) {
    892892  if (newval == NULL) return(0);
    893893  else return (1);
    894894}
    895895
    896 int owl_variable_int_set_default(owl_variable *v, void *newval) {
     896int owl_variable_int_set_default(owl_variable *v, const void *newval) {
    897897  if (v->validate_fn) {
    898898    if (!v->validate_fn(v, newval)) return(-1);
     
    902902}
    903903
    904 int owl_variable_int_set_fromstring_default(owl_variable *v, char *newval) {
     904int owl_variable_int_set_fromstring_default(owl_variable *v, const char *newval) {
    905905  int i;
    906   char *ep = "x";
     906  const char *ep = "x";
    907907  i = strtol(newval, (char **)&ep, 10);
    908908  if (*ep || ep==newval) return(-1);
     
    910910}
    911911
    912 int owl_variable_int_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {
     912int owl_variable_int_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) {
    913913  if (val == NULL) {
    914914    snprintf(buf, bufsize, "<null>");
     
    922922/* default functions for enums (a variant of integers) */
    923923
    924 int owl_variable_enum_validate(owl_variable *v, void *newval) { 
     924int owl_variable_enum_validate(owl_variable *v, const void *newval) { 
    925925  char **enums;
    926926  int nenums, val;
     
    936936}
    937937
    938 int owl_variable_enum_set_fromstring(owl_variable *v, char *newval) {
     938int owl_variable_enum_set_fromstring(owl_variable *v, const char *newval) {
    939939  char **enums;
    940940  int nenums, i, val=-1;
     
    952952}
    953953
    954 int owl_variable_enum_get_tostring(owl_variable *v, char* buf, int bufsize, void *val) {
     954int owl_variable_enum_get_tostring(owl_variable *v, char* buf, int bufsize, const void *val) {
    955955  char **enums;
    956956  int nenums, i;
     
    973973/* default functions for stringeans */
    974974
    975 int owl_variable_string_validate_default(struct _owl_variable *v, void *newval) {
     975int owl_variable_string_validate_default(struct _owl_variable *v, const void *newval) {
    976976  if (newval == NULL) return(0);
    977977  else return (1);
    978978}
    979979
    980 int owl_variable_string_set_default(owl_variable *v, void *newval) {
     980int owl_variable_string_set_default(owl_variable *v, const void *newval) {
    981981  if (v->validate_fn) {
    982982    if (!v->validate_fn(v, newval)) return(-1);
     
    987987}
    988988
    989 int owl_variable_string_set_fromstring_default(owl_variable *v, char *newval) {
     989int owl_variable_string_set_fromstring_default(owl_variable *v, const char *newval) {
    990990  return (v->set_fn(v, newval));
    991991}
    992992
    993 int owl_variable_string_get_tostring_default(owl_variable *v, char* buf, int bufsize, void *val) {
     993int owl_variable_string_get_tostring_default(owl_variable *v, char* buf, int bufsize, const void *val) {
    994994  if (val == NULL) {
    995995    snprintf(buf, bufsize, "<null>");
    996996    return -1;
    997997  } else {
    998     snprintf(buf, bufsize, "%s", (char*)val);
     998    snprintf(buf, bufsize, "%s", (const char*)val);
    999999    return 0;
    10001000  }
     
    10151015  int numfailed=0;
    10161016  char buf[1024];
    1017   void *v;
     1017  const void *v;
    10181018
    10191019  in_regtest = 1;
Note: See TracChangeset for help on using the changeset viewer.