4556587 [rkeene@sledge /home/rkeene/devel/libconfig-0.2.5]$ cat -n lc_register_var.3.in
   1: .TH LC_REGISTER_VAR 3 "25 Oct 04" "@PACKAGE_STRING@"
   2: .SH NAME
   3: lc_register_var \- Register a variable for automatic processing.
   4: 
   5: .SH SYNOPSIS
   6: .B #include <libconfig.h>
   7: .sp
   8: .BI "int lc_register_var(const char *" var ", lc_var_type_t " type ", void *" data ", char " opt ");"
   9: 
  10: .SH DESCRIPTION
  11: The
  12: .BR lc_register_var (3)
  13: function registers a variable for automatic processing.
  14: The
  15: .IR var
  16: parameter specifies the variable name for processing.  This name can exist in a configuration file, an environment variable, or on the command line.
  17: The
  18: .IR opt
  19: parameter specifies the single letter short option that can be specified on the command line to change the value of the variable specified by the
  20: .IR data
  21: parameter.  A value of '\0' can be specified for no short option.
  22: 
  23: The
  24: .IR type 
  25: parameter is of type
  26: .IR lc_var_type_t
  27: which specifies the type of the
  28: .IR data
  29: parameter.
  30: Valid values for
  31: .IR type
  32: are:
  33: .TP
  34: LC_VAR_STRING
  35: For a string type variable.  The data passed should be of type "char **".  The data will be set to a region of memory that has been allocated with malloc() and can be released be free()'d.
  36: .TP
  37: LC_VAR_LONG_LONG
  38: For a "long long" integer type variable.  The data passed should be of type "long long *".
  39: .TP
  40: LC_VAR_LONG
  41: For a "long" integer type variable.  The data passed should be of type "long *".
  42: .TP
  43: LC_VAR_INT
  44: For a "int" integer type variable.  The data passed should be of type "int *".
  45: .TP
  46: LC_VAR_SHORT
  47: For a "short" integer type variable.  The data passed should be of type "short *".
  48: .TP
  49: LC_VAR_FLOAT
  50: For a "float" floating point type variable.  The data passed should be of type "float *".
  51: .TP
  52: LC_VAR_DOUBLE
  53: For a "double" floating point type variable.  The data passed should be of type "double *".
  54: .TP
  55: LC_VAR_BOOL
  56: For a boolean type variable.  The data passed should be of type "int *".  When a true value is specified the variable is set to 1.  When a false value is specified the variable is set to 0.  Any other value sets the variable to -1.  Valid true values are: enable, true, yes, on, y, and 1.  Valid false values are: disable, false, off, no, n, and 0.
  57: .TP
  58: LC_VAR_FILENAME
  59: Not implemented.
  60: .TP
  61: LC_VAR_DIRECTORY
  62: Not implemented.
  63: .TP
  64: LC_VAR_SIZE_LONG_LONG
  65: For a "long long" 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 "long long *".
  66: .TP
  67: LC_VAR_SIZE_LONG
  68: For a "long" 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 "long *".
  69: .TP
  70: LC_VAR_SIZE_INT
  71: 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 *".
  72: .TP
  73: LC_VAR_SIZE_SHORT
  74: 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 *".
  75: .TP
  76: LC_VAR_SIZE_SIZE_T
  77: 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 *".
  78: .TP
  79: LC_VAR_TIME
  80: Not implemented.
  81: .TP
  82: LC_VAR_DATE
  83: Not implemented.
  84: .TP
  85: LC_VAR_BOOL_BY_EXISTANCE
  86: 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 *".
  87: .TP
  88: LC_VAR_CIDR
  89: This type of variable accepts a CIDR format netmask and IP.  This is not yet implemented. (XXX)
  90: .TP
  91: LC_VAR_IP
  92: This type of variable accepts an IP address in decimal-dot format.  The value is stored in a uint32_t in network byte order.
  93: .TP
  94: LC_VAR_HOSTNAME
  95: This type of variable accepts an address in hostname format.  The value is stored in a uint32_t in network byte order.
  96: .TP
  97: LC_VAR_ADDR
  98: This type of variable accepts an address in either hostname or decimal-dot format.  The value is stored in a uint32_t in network byte order.
  99: 
 100: .SH "RETURN VALUE"
 101: On success 0 is returned, otherwise -1 is returned.
 102: 
 103: .SH EXAMPLE
 104: .nf
 105: #include <libconfig.h>
 106: #include <stdlib.h>
 107: #include <stdio.h>
 108: 
 109: int main(int argc, char **argv) {
 110: 	int lc_p_ret, lc_rv_ret;
 111: 	char *filename = NULL;
 112: 	long int counter = -1;
 113: 
 114: 	lc_rv_ret = lc_register_var("Begin", LC_VAR_LONG,
 115: 	                            &counter, 'c');
 116: 	if (lc_rv_ret != 0) {
 117: 		fprintf(stderr, "Error registering variable: %i.\\n",
 118: 		        lc_geterrno());
 119: 		return(EXIT_FAILURE);
 120: 	}
 121: 
 122: 	lc_rv_ret = lc_register_var("File", LC_VAR_STRING,
 123: 	                            &filename, 'f');
 124: 	if (lc_rv_ret != 0) {
 125: 		fprintf(stderr, "Error registering variable: %i.\\n",
 126: 		        lc_geterrno());
 127: 		return(EXIT_FAILURE);
 128: 	}
 129: 
 130: 	lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE,
 131: 	                      NULL);
 132: 
 133: 	lc_cleanup();
 134: 
 135: 	if (lc_p_ret != 0) {
 136: 		fprintf(stderr, "Error processing configuration: \\
 137: 		        %s\\n", lc_geterrstr());
 138: 		return(EXIT_FAILURE);
 139: 	}
 140: 
 141: 	if (filename != NULL) {
 142: 		printf("File specified was: %s\\n", filename);
 143: 	} else {
 144: 		printf("No filename specified.\\n");
 145: 	}
 146: 
 147: 	if (counter != -1) {
 148: 		printf("Counter was specified as: %ld\\n", counter);
 149: 	} else {
 150: 		printf("Counter was not specified.\\n");
 151: 	}
 152: 
 153: 	return(EXIT_SUCCESS);
 154: }
 155: .fi
 156: 
 157: .SH "SEE ALSO"
 158: .BR libconfig (3),
 159: .BR lc_register_callback (3),                          
 160: .BR lc_geterrno (3),                                                                                                           
 161: .BR lc_geterrstr (3),                                                                                                          
 162: .BR lc_seterrstr (3),                                                                                                          
 163: .BR lc_handle_type (3),
 164: .BR lc_process (3),                                                                                                            
 165: .BR lc_process_file (3),                                                                                                       
 166: .BR lc_cleanup (3)
4556588 [rkeene@sledge /home/rkeene/devel/libconfig-0.2.5]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2007-01-16 09:12:07