Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

dcfp.h

Go to the documentation of this file.
00001 /*
00002  * dcfp - definition and configuration file parser
00003  * Copyright (c) 2002 Mark Smulders <Mark@PIRnet.nl>             
00004  *
00005  * This program is free software; you can redistribute it and/or modify  
00006  * it under the terms of the GNU General Public License as published by  
00007  * the Free Software Foundation; either version 2, or (at your option)   
00008  * any later version.                                                    
00009  *                                                                       
00010  * This program is distributed in the hope that it will be useful,       
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of        
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
00013  * GNU General Public License for more details.                          
00014  *                                                                       
00015  * You should have received a copy of the GNU General Public License     
00016  * along with this program; if not, write to the                         
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,          
00018  * Boston, MA 02111-1307, USA.                                           
00019  */
00020 
00021 #ifndef _DCFP_H
00022 #define _DCFP_H
00023 
00024 #include <stdio.h>
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 /* DCFP data struct explanation
00031  *
00032  *    data (dcfp_data_struct *)
00033  *     |
00034  *     |-- globalvars (dcfp_var_struct *)
00035  *     |      |-- type (string, either "str" or "int")
00036  *     |      |-- key   (string)
00037  *     |      |-- value (void pointer; either string or int)
00038  *     |      |-- next  (dcfp_var_struct *)
00039  *     |            |
00040  *     |            |-- type [ETCETERA]
00041  *     |
00042  *     |-- sections (dcfp_section_struct *)
00043  *            |
00044  *            |-- name (string)
00045  *            |-- globalvars (dcfp_var_struct *)
00046  *        |     |-- type
00047  *        |     |-- key
00048  *        |     |-- value
00049  *        |     |-- next [ETCETERA]
00050  *        |
00051  *        |-- subsections (dcfp_section_struct *)
00052  *            |     |-- name
00053  *            |     |-- globalvars (dcfp_var_struct *)
00054  *        |     |-- subsections (dcfp_section_struct *)
00055  *        |     |-- next [ETCETERA]
00056  *            |
00057  *        |-- next (dcfp_section_struct *) [ETCETERA]
00058  *            
00059  */
00060 
00061 /* Example conf file
00062  * ---------------------------------
00063  *
00064  * globalvar = "string value"
00065  * global_integer_var = 1234
00066  *
00067  * [SOMESECTION]
00068  *   sectionvar = " value"
00069  *
00070  *   [ASUBSECTION]
00071  *     subsectvar = "another value"
00072  *   [END ASUBSECTION]
00073  *
00074  *   another_sectionvar = 5678
00075  * [END SOMESECTION]
00076  *
00077  * yet_another_global = "var"
00078  *
00079  * ---------------------------------
00080  */
00081 
00082 /* // *** Typical Use *** //
00083  *
00084  *  #define FILENAME "test.conf" 
00085  *  int main (void) {
00086  *    dcfp_data_struct *data = NULL;
00087  *    data = dcfp_parse_file(FILENAME);
00088  *    //-> do something with the data ;-)
00089  *    dcfp_destroy_data_struct(data);
00090  *    return 0;
00091  *  }
00092  *  
00093  */
00094 
00095 
00096 /* dcfp data structures - data from file goes into these, dynamically */
00097 typedef struct dcfp_var_stype {
00098   char type[4];
00099   char *key;
00100   void *value;
00101   struct dcfp_var_stype *next;
00102 } dcfp_var_struct;
00103 
00104 typedef struct dcfp_section_stype {
00105   char *name;
00106   dcfp_var_struct *globalvars;
00107   struct dcfp_section_stype *sections;
00108   struct dcfp_section_stype *next;
00109 } dcfp_section_struct;
00110 
00111 typedef struct dcfp_data_stype {
00112   dcfp_var_struct *globalvars;
00113   dcfp_section_struct *sections;
00114 } dcfp_data_struct;
00115 
00116 /* public interface */
00117 const dcfp_data_struct *dcfp_parse_file(const char *filename);
00118 void dcfp_destroy_data_struct(dcfp_data_struct *data);
00119 int dcfp_global_section_exist(const dcfp_data_struct *data, const char *sectionname);
00120 const dcfp_section_struct *dcfp_get_global_section_by_name(const dcfp_data_struct *data, const char *name);
00121 const dcfp_section_struct *dcfp_get_subsection_by_name(const dcfp_section_struct *parentsection, const char *name);
00122 const void *dcfp_get_global_var(const dcfp_data_struct *data, const char *varname);
00123 const void *dcfp_get_var_from_section(const dcfp_section_struct *section, const char *varname);
00124 
00125 #ifdef __cplusplus
00126 }
00127 #endif
00128 
00129 #endif

Generated on Tue Jun 11 00:31:45 2002 for KLineakConfig by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002