Check-in [67a12fd87a]
Overview
Comment:Updated libconfig
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 67a12fd87aa23392fcd41f89e22a843d7bc78284
User & Date: rkeene on 2004-11-17 09:49:52
Other Links: manifest | tags
Context
2004-11-22
02:00
Added a .spec file Changed license to MIT libconfig 0.1.3 check-in: 4596d49a10 user: rkeene tags: trunk, 0.1.3
2004-11-17
09:49
Updated libconfig check-in: 67a12fd87a user: rkeene tags: trunk
2004-10-31
20:46
Changed to `strtoull' to `strtoll' and updated code. Changed URL in header Added TODO libconfig 0.1.1 check-in: 59af3f328b user: rkeene tags: trunk, 0.1.1
Changes

Modified .cvsignore from [a1cfe0d8d0] to [3ec037ded0].

     9      9   test.cfg
    10     10   .*.swp
    11     11   lc_geterrstr.3
    12     12   lc_register_var.3
    13     13   lc_register_callback.3
    14     14   lc_process.3
    15     15   lc_geterrno.3
           16  +libconfig.3

Modified .fossil-settings/ignore-glob from [e33f8b5756] to [f46eab9da1].

    14     14   lc_geterrstr.3/*
    15     15   lc_process.3
    16     16   lc_process.3/*
    17     17   lc_register_callback.3
    18     18   lc_register_callback.3/*
    19     19   lc_register_var.3
    20     20   lc_register_var.3/*
           21  +libconfig.3
           22  +libconfig.3/*
    21     23   libconfig.a
    22     24   libconfig.a/*
    23     25   libconfig.h
    24     26   libconfig.h/*
    25     27   libconfig.so
    26     28   libconfig.so/*
    27     29   test-lc
    28     30   test-lc/*
    29     31   test.cfg
    30     32   test.cfg/*

Modified configure.in from [eed6770815] to [4479b835cc].

     1      1   AC_REVISION($Revision $)
     2         -AC_INIT(libconfig, 0.1.1)
            2  +AC_INIT(libconfig, 0.1.2)
     3      3   AC_CONFIG_HEADER(config.h)
     4      4   
     5      5   dnl Find out about the host OS
     6      6   DC_CHK_OS_INFO
     7      7   
     8      8   dnl Checks for programs.
     9      9   AC_PROG_CC

Modified lc_register_callback.3.in from [43854d99e9] to [0102cb6d66].

    33     33   .RE
    34     34   
    35     35   .TP
    36     36   .IR "lc_var_type_t type"
    37     37   .RS
    38     38   The
    39     39   .IR type
    40         -parameter indicates the type of values that are acceptable for this callback.  Currently only LC_VAR_NONE is acceptable, since callbacks may not have values (though they may have arguments).
           40  +parameter indicates the type of values that are acceptable for this callback.  A value of LC_VAR_NONE means that the command will accept no arguments, while a value of LC_VAR_UNKNOWN indicates that it's not known whether or not an argument is applicable, this will also disable command line processing.  Any other value is currently ignored.
    41     41   .RE
    42     42   
    43     43   .TP
    44     44   .IR "int (*callback)(...)"
    45     45   .RS
    46     46   The
    47     47   .IR callback

Modified lc_register_var.3.in from [33f89d18c6] to [ed1d29b572].

    63     63   .TP
    64     64   LC_VAR_SIZE_INT
    65     65   For a "int" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "int *".
    66     66   .TP
    67     67   LC_VAR_SIZE_SHORT
    68     68   For a "short" integer type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "short *".
    69     69   .TP
           70  +LC_VAR_SIZE_SIZE_T
           71  +For a "size_t" data type that can have size modifiers, such as 'G' or gigabytes, 'M' for megabytes, 'K' for kilobytes.  The data passed should be of type "size_t *".
           72  +.TP
    70     73   LC_VAR_TIME
    71     74   Not implemented.
    72     75   .TP
    73     76   LC_VAR_DATE
    74     77   Not implemented.
    75     78   .TP
    76     79   LC_VAR_BOOL_BY_EXISTANCE
    77     80   This type of variable takes no arguments, it is set to true (1) by its existance in a configuration file, environment variable, or on the command line.  If it is not specified, the value of the data passed is not changed.  The data passed should be of type "int *".
           81  +.TP
           82  +LC_VAR_CIDR
           83  +XXX: blah
           84  +.TP
           85  +LC_VAR_IP
           86  +XXX: blah
    78     87   
    79     88   .SH "RETURN VALUE"
    80     89   On success 0 is returned, otherwise -1 is returned.
    81     90   
    82     91   .SH EXAMPLE
    83     92   .nf
    84     93   #include <libconfig.h>

Modified libconfig.c from [0729e92710] to [65d4398d3f].

    46     46   	char **dataval;
    47     47   
    48     48   	dataval = data;
    49     49   	*dataval = strdup(value);
    50     50   
    51     51   	return(0);
    52     52   }
           53  +
           54  +static int lc_process_var_cidr(void *data, const char *value) {
           55  +	
           56  +
           57  +	return(0);
           58  +}
           59  +
           60  +static int lc_process_var_ip(void *data, const char *value) {
           61  +	uint32_t *dataval = NULL, retval = 0;
           62  +	const char *dotptr = NULL;
           63  +	int tmpval = -1;
           64  +
           65  +	dataval = data;
           66  +
           67  +	dotptr = value;
           68  +
           69  +	while (1) {
           70  +		tmpval = atoi(dotptr);
           71  +		if (tmpval < 0) {
           72  +			break;
           73  +		}
           74  +
           75  +		retval <<= 8;
           76  +		retval |= tmpval;
           77  +
           78  +		dotptr = strpbrk(dotptr, "./ \t");
           79  +		if (dotptr == NULL) {
           80  +			break;
           81  +		}
           82  +		if (*dotptr != '.') {
           83  +			break;
           84  +		}
           85  +		dotptr++;
           86  +	}
           87  +
           88  +	*dataval = retval;
           89  +
           90  +	return(0);
           91  +}
    53     92   
    54     93   static int lc_process_var_longlong(void *data, const char *value) {
    55     94   	long long *dataval;
    56     95   
    57     96   	dataval = data;
    58     97   	*dataval = strtoll(value, NULL, 10);
    59     98   
................................................................................
   187    226   	short *dataval;
   188    227   
   189    228   	dataval = data;
   190    229   	*dataval = lc_process_size(value);
   191    230   
   192    231   	return(0);
   193    232   }
          233  +
          234  +static int lc_process_var_sizesizet(void *data, const char *value) {
          235  +	size_t *dataval;
          236  +
          237  +	dataval = data;
          238  +	*dataval = lc_process_size(value);
          239  +
          240  +	return(0);
          241  +}
          242  +
   194    243   
   195    244   static int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
   196    245   	switch (type) {
   197    246   		case LC_VAR_STRING:
   198    247   			return(lc_process_var_string(data, value));
   199    248   			break;
   200    249   		case LC_VAR_LONG_LONG:
................................................................................
   223    272   			break;
   224    273   		case LC_VAR_SIZE_SHORT:
   225    274   			return(lc_process_var_sizeshort(data, value));
   226    275   			break;
   227    276   		case LC_VAR_BOOL_BY_EXISTANCE:
   228    277   			return(lc_process_var_bool_byexistance(data, value));
   229    278   			break;
          279  +		case LC_VAR_SIZE_SIZE_T:
          280  +			return(lc_process_var_sizesizet(data, value));
          281  +			break;
          282  +		case LC_VAR_IP:
          283  +			return(lc_process_var_ip(data, value));
          284  +			break;
   230    285   		case LC_VAR_TIME:
   231    286   		case LC_VAR_DATE:
   232    287   		case LC_VAR_FILENAME:
   233    288   		case LC_VAR_DIRECTORY:
   234    289   #ifdef DEBUG
   235    290   			fprintf(stderr, "Not implemented yet!\n");
   236    291   #endif

Modified libconfig.h.in from [6db6e4f548] to [f10199222d].

    33     33           LC_VAR_SIZE_INT,
    34     34           LC_VAR_SIZE_SHORT,
    35     35           LC_VAR_TIME,
    36     36           LC_VAR_DATE,
    37     37           LC_VAR_SECTION,
    38     38           LC_VAR_SECTIONSTART,
    39     39           LC_VAR_SECTIONEND,
    40         -        LC_VAR_BOOL_BY_EXISTANCE
           40  +        LC_VAR_BOOL_BY_EXISTANCE,
           41  +        LC_VAR_SIZE_SIZE_T,
           42  +	LC_VAR_CIDR,
           43  +	LC_VAR_IP,
    41     44   } lc_var_type_t;
    42     45   
    43     46   __BLANK_LINE__
    44     47   
    45     48   typedef enum {
    46     49           LC_FLAGS_VAR,
    47     50           LC_FLAGS_CMDLINE,

Modified test-lc.c from [d4be221f35] to [0d1d1a962e].

    27     27   
    28     28   	fprintf(stderr, "IfModule (%s)\n", argarg);
    29     29   	return(LC_CBRET_IGNORESECTION);
    30     30   }
    31     31   
    32     32   int main(int argc, char **argv) {
    33     33   	char *joeval = NULL;
    34         -	long long xval = -1;
           34  +	size_t xval = -1;
    35     35   	int onoff = -1;
    36     36   	int lcpret = -1;
    37     37   	int i = 0;
    38     38   	int onoff2 = 0;
    39         -	lc_err_t errs;
           39  +	uint32_t ipaddr;
    40     40   
    41     41   	lc_register_var("Section", LC_VAR_SECTION, NULL, 0);
    42     42   	lc_register_var("Somesection", LC_VAR_SECTION, NULL, 0);
    43     43   	lc_register_var("Section.Test", LC_VAR_STRING, &joeval, 'j');
    44         -	lc_register_var("bob", LC_VAR_SIZE_LONG_LONG, &xval, 's');
           44  +	lc_register_var("bob", LC_VAR_SIZE_SIZE_T, &xval, 's');
    45     45   	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
    46     46   	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
           47  +	lc_register_var("ipaddr", LC_VAR_IP, &ipaddr, 'i');
    47     48   	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
    48     49   	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
    49     50   	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
    50     51   	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
    51     52   	if (lcpret < 0) {
    52     53   		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
    53     54   		return(EXIT_FAILURE);
................................................................................
    54     55   	}
    55     56   
    56     57   	if (joeval != NULL) {
    57     58   		fprintf(stderr, "joeval = \"%s\"\n", joeval);
    58     59   	} else {
    59     60   		fprintf(stderr, "joeval = \"(null)\"\n");
    60     61   	}
    61         -	fprintf(stderr, "xval = %lli\n", xval);
           62  +	fprintf(stderr, "xval = %llu\n", (unsigned long long) xval);
    62     63   	fprintf(stderr, "onoff = %i\n", onoff);
    63     64   	fprintf(stderr, "long = %i\n", onoff2);
           65  +	fprintf(stderr, "ip = %08lx\n", (unsigned long) ipaddr);
    64     66   	for (i = lc_optind; i < argc; i++) {
    65     67   		fprintf(stderr, "argv[%i] = \"%s\"\n", i, argv[i]);
    66     68   	}
    67     69   
    68     70   	return(0);
    69     71   }