# Source: klineakconfig/dcfp.h |
Annotated List
Files
Globals
Hierarchy
Index

    /*
     * dcfp - definition and configuration file parser
     * Copyright (c) 2002 Mark Smulders
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2, or (at your option)
     * any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the
     * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     * Boston, MA 02111-1307, USA.
     */

    #ifndef _DCFP_H
    #define _DCFP_H

    #include

    #ifdef __cplusplus
    extern "C" {
    #endif

    /* DCFP data struct explanation
     *
     *    data (dcfp_data_struct *)
     *     |
     *     |-- globalvars (dcfp_var_struct *)
     *     |      |-- type (string, either "str" or "int")
     *     |      |-- key   (string)
     *     |      |-- value (void pointer; either string or int)
     *     |      |-- next  (dcfp_var_struct *)
     *     |            |
     *     |            |-- type [ETCETERA]
     *     |
     *     |-- sections (dcfp_section_struct *)
     *            |
     *  	      |-- name (string)
     *     	      |-- globalvars (dcfp_var_struct *)
     *	      |     |-- type
     *	      |     |-- key
     *	      |     |-- value
     *	      |     |-- next [ETCETERA]
     *	      |
     *	      |-- subsections (dcfp_section_struct *)
     *  	      |     |-- name
     *  	      |     |-- globalvars (dcfp_var_struct *)
     *	      |     |-- subsections (dcfp_section_struct *)
     *	      |     |-- next [ETCETERA]
     *   	      |
     *	      |-- next (dcfp_section_struct *) [ETCETERA]
     *
     */

    /* Example conf file
     * ---------------------------------
     *
     * globalvar = "string value"
     * global_integer_var = 1234
     *
     * [SOMESECTION]
     *   sectionvar = " value"
     *
     *   [ASUBSECTION]
     *     subsectvar = "another value"
     *   [END ASUBSECTION]
     *
     *   another_sectionvar = 5678
     * [END SOMESECTION]
     *
     * yet_another_global = "var"
     *
     * ---------------------------------
     */

    /* // *** Typical Use *** //
     *
     *  #define FILENAME "test.conf"
     *  int main (void) {
     *    dcfp_data_struct *data = NULL;
     *    data = dcfp_parse_file(FILENAME);
     *    //-> do something with the data ;-)
     *    dcfp_destroy_data_struct(data);
     *    return 0;
     *  }
     *
     */

    /* dcfp data structures - data from file goes into these, dynamically */
    typedef struct dcfp_var_stype {
      char type[4];
      char *key;
      void *value;
      struct dcfp_var_stype *next;
    } dcfp_var_struct;

    typedef struct dcfp_section_stype {
      char *name;
      dcfp_var_struct *globalvars;
      struct dcfp_section_stype *sections;
      struct dcfp_section_stype *next;
    } dcfp_section_struct;

    typedef struct dcfp_data_stype {
      dcfp_var_struct *globalvars;
      dcfp_section_struct *sections;
    } dcfp_data_struct;

    /* public interface */
    const dcfp_data_struct *dcfp_parse_file(const char *filename);
    void dcfp_destroy_data_struct(dcfp_data_struct *data);
    int dcfp_global_section_exist(const dcfp_data_struct *data, const char *sectionname);
    const dcfp_section_struct *dcfp_get_global_section_by_name(const dcfp_data_struct *data, const char *name);
    const dcfp_section_struct *dcfp_get_subsection_by_name(const dcfp_section_struct *parentsection, const char *name);
    const void *dcfp_get_global_var(const dcfp_data_struct *data, const char *varname);
    const void *dcfp_get_var_from_section(const dcfp_section_struct *section, const char *varname);

    #ifdef __cplusplus
    }
    #endif

    #endif

Generated by: sheldonl on shugaru on Thu Oct 10 23:58:14 2002, using kdoc 2.0a53.