1: .TH LC_PROCESS 3 "25 Oct 04" "@PACKAGE_STRING@" 2: .SH NAME 3: lc_process \- Begin processing configuration files. 4: 5: .SH SYNOPSIS 6: .B #include <libconfig.h> 7: .sp 8: .BI "int lc_process(int " argc ", char **" argv ", const char *" appname ", lc_conf_type_t " type ", const char *" extra ");" 9: 10: .SH DESCRIPTION 11: The 12: .BR lc_process (3) 13: function begins processing of the command line arguments, environment variables, and command line options. 14: The 15: .I argc 16: and 17: .I argv 18: parameters should be in the same format as passed to the 19: .B main 20: function of your program. 21: The 22: .I appname 23: parameter should be a reasonable form of the name of the application. 24: The 25: .I type 26: parameter should describe the format of the configuration file (see below). 27: The 28: .I extra 29: parameter should list any extra configuration files to process. 30: 31: Valid type parameter values: 32: .TP 33: LC_CONF_SECTION 34: This type of configuration file is similar to the Windows INI-file style. 35: An example configuration file: 36: .nf 37: [section] 38: variable = value 39: .fi 40: 41: .TP 42: LC_CONF_APACHE 43: This type of configuration file is similar to the Apache configuration file. 44: An example configuration file: 45: .nf 46: <Section argument> 47: variable value 48: </Section> 49: .fi 50: 51: .TP 52: LC_CONF_SPACE 53: This is a simple, flat configuration file. It has no section headers. 54: An example configuration file: 55: .nf 56: variable value 57: .fi 58: 59: .SH "RETURN VALUE" 60: On success 0 is returned, otherwise -1 is returned. 61: 62: .SH EXAMPLE 63: .nf 64: #include <libconfig.h> 65: #include <stdlib.h> 66: #include <stdio.h> 67: 68: int main(int argc, char **argv) { 69: int lc_p_ret, lc_rv_ret; 70: char *filename = NULL; 71: 72: lc_rv_ret = lc_register_var("File", LC_VAR_STRING, 73: &filename, 'f'); 74: if (lc_rv_ret != 0) { 75: fprintf(stderr, "Error registering variable: %i.\\n", 76: lc_geterrno()); 77: return(EXIT_FAILURE); 78: } 79: 80: lc_p_ret = lc_process(argc, argv, "example", LC_CONF_APACHE, 81: NULL); 82: 83: lc_cleanup(); 84: 85: if (lc_p_ret != 0) { 86: fprintf(stderr, "Error processing configuration: \\ 87: %s\\n", lc_geterrstr()); 88: return(EXIT_FAILURE); 89: } 90: 91: if (filename != NULL) { 92: printf("File specified was: %s\\n", filename); 93: } else { 94: printf("No filename specified.\\n"); 95: } 96: 97: return(EXIT_SUCCESS); 98: } 99: .fi 100: 101: .SH "SEE ALSO" 102: .BR libconfig (3), 103: .BR lc_register_var (3), 104: .BR lc_register_callback (3), 105: .BR lc_geterrno (3), 106: .BR lc_geterrstr (3), 107: .BR lc_seterrstr (3), 108: .BR lc_handle_type (3), 109: .BR lc_process_file (3), 110: .BR lc_cleanup (3) |