testing/mozbase/mozprocess/tests/iniparser/iniparser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozprocess/tests/iniparser/iniparser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,273 @@
     1.4 +
     1.5 +/*-------------------------------------------------------------------------*/
     1.6 +/**
     1.7 +   @file    iniparser.h
     1.8 +   @author  N. Devillard
     1.9 +   @date    Sep 2007
    1.10 +   @version 3.0
    1.11 +   @brief   Parser for ini files.
    1.12 +*/
    1.13 +/*--------------------------------------------------------------------------*/
    1.14 +
    1.15 +/*
    1.16 +	$Id: iniparser.h,v 1.26 2011-03-02 20:15:13 ndevilla Exp $
    1.17 +	$Revision: 1.26 $
    1.18 +*/
    1.19 +
    1.20 +#ifndef _INIPARSER_H_
    1.21 +#define _INIPARSER_H_
    1.22 +
    1.23 +/*---------------------------------------------------------------------------
    1.24 +   								Includes
    1.25 + ---------------------------------------------------------------------------*/
    1.26 +
    1.27 +#include <stdio.h>
    1.28 +#include <stdlib.h>
    1.29 +#include <string.h>
    1.30 +
    1.31 +/*
    1.32 + * The following #include is necessary on many Unixes but not Linux.
    1.33 + * It is not needed for Windows platforms.
    1.34 + * Uncomment it if needed.
    1.35 + */
    1.36 +/* #include <unistd.h> */
    1.37 +
    1.38 +#include "dictionary.h"
    1.39 +
    1.40 +/*-------------------------------------------------------------------------*/
    1.41 +/**
    1.42 +  @brief    Get number of sections in a dictionary
    1.43 +  @param    d   Dictionary to examine
    1.44 +  @return   int Number of sections found in dictionary
    1.45 +
    1.46 +  This function returns the number of sections found in a dictionary.
    1.47 +  The test to recognize sections is done on the string stored in the
    1.48 +  dictionary: a section name is given as "section" whereas a key is
    1.49 +  stored as "section:key", thus the test looks for entries that do not
    1.50 +  contain a colon.
    1.51 +
    1.52 +  This clearly fails in the case a section name contains a colon, but
    1.53 +  this should simply be avoided.
    1.54 +
    1.55 +  This function returns -1 in case of error.
    1.56 + */
    1.57 +/*--------------------------------------------------------------------------*/
    1.58 +
    1.59 +int iniparser_getnsec(dictionary * d);
    1.60 +
    1.61 +
    1.62 +/*-------------------------------------------------------------------------*/
    1.63 +/**
    1.64 +  @brief    Get name for section n in a dictionary.
    1.65 +  @param    d   Dictionary to examine
    1.66 +  @param    n   Section number (from 0 to nsec-1).
    1.67 +  @return   Pointer to char string
    1.68 +
    1.69 +  This function locates the n-th section in a dictionary and returns
    1.70 +  its name as a pointer to a string statically allocated inside the
    1.71 +  dictionary. Do not free or modify the returned string!
    1.72 +
    1.73 +  This function returns NULL in case of error.
    1.74 + */
    1.75 +/*--------------------------------------------------------------------------*/
    1.76 +
    1.77 +char * iniparser_getsecname(dictionary * d, int n);
    1.78 +
    1.79 +
    1.80 +/*-------------------------------------------------------------------------*/
    1.81 +/**
    1.82 +  @brief    Save a dictionary to a loadable ini file
    1.83 +  @param    d   Dictionary to dump
    1.84 +  @param    f   Opened file pointer to dump to
    1.85 +  @return   void
    1.86 +
    1.87 +  This function dumps a given dictionary into a loadable ini file.
    1.88 +  It is Ok to specify @c stderr or @c stdout as output files.
    1.89 + */
    1.90 +/*--------------------------------------------------------------------------*/
    1.91 +
    1.92 +void iniparser_dump_ini(dictionary * d, FILE * f);
    1.93 +
    1.94 +/*-------------------------------------------------------------------------*/
    1.95 +/**
    1.96 +  @brief    Dump a dictionary to an opened file pointer.
    1.97 +  @param    d   Dictionary to dump.
    1.98 +  @param    f   Opened file pointer to dump to.
    1.99 +  @return   void
   1.100 +
   1.101 +  This function prints out the contents of a dictionary, one element by
   1.102 +  line, onto the provided file pointer. It is OK to specify @c stderr
   1.103 +  or @c stdout as output files. This function is meant for debugging
   1.104 +  purposes mostly.
   1.105 + */
   1.106 +/*--------------------------------------------------------------------------*/
   1.107 +void iniparser_dump(dictionary * d, FILE * f);
   1.108 +
   1.109 +/*-------------------------------------------------------------------------*/
   1.110 +/**
   1.111 +  @brief    Get the string associated to a key
   1.112 +  @param    d       Dictionary to search
   1.113 +  @param    key     Key string to look for
   1.114 +  @param    def     Default value to return if key not found.
   1.115 +  @return   pointer to statically allocated character string
   1.116 +
   1.117 +  This function queries a dictionary for a key. A key as read from an
   1.118 +  ini file is given as "section:key". If the key cannot be found,
   1.119 +  the pointer passed as 'def' is returned.
   1.120 +  The returned char pointer is pointing to a string allocated in
   1.121 +  the dictionary, do not free or modify it.
   1.122 + */
   1.123 +/*--------------------------------------------------------------------------*/
   1.124 +char * iniparser_getstring(dictionary * d, char * key, char * def);
   1.125 +
   1.126 +/*-------------------------------------------------------------------------*/
   1.127 +/**
   1.128 +  @brief    Get the string associated to a key, convert to an int
   1.129 +  @param    d Dictionary to search
   1.130 +  @param    key Key string to look for
   1.131 +  @param    notfound Value to return in case of error
   1.132 +  @return   integer
   1.133 +
   1.134 +  This function queries a dictionary for a key. A key as read from an
   1.135 +  ini file is given as "section:key". If the key cannot be found,
   1.136 +  the notfound value is returned.
   1.137 +
   1.138 +  Supported values for integers include the usual C notation
   1.139 +  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
   1.140 +  are supported. Examples:
   1.141 +
   1.142 +  - "42"      ->  42
   1.143 +  - "042"     ->  34 (octal -> decimal)
   1.144 +  - "0x42"    ->  66 (hexa  -> decimal)
   1.145 +
   1.146 +  Warning: the conversion may overflow in various ways. Conversion is
   1.147 +  totally outsourced to strtol(), see the associated man page for overflow
   1.148 +  handling.
   1.149 +
   1.150 +  Credits: Thanks to A. Becker for suggesting strtol()
   1.151 + */
   1.152 +/*--------------------------------------------------------------------------*/
   1.153 +int iniparser_getint(dictionary * d, char * key, int notfound);
   1.154 +
   1.155 +/*-------------------------------------------------------------------------*/
   1.156 +/**
   1.157 +  @brief    Get the string associated to a key, convert to a double
   1.158 +  @param    d Dictionary to search
   1.159 +  @param    key Key string to look for
   1.160 +  @param    notfound Value to return in case of error
   1.161 +  @return   double
   1.162 +
   1.163 +  This function queries a dictionary for a key. A key as read from an
   1.164 +  ini file is given as "section:key". If the key cannot be found,
   1.165 +  the notfound value is returned.
   1.166 + */
   1.167 +/*--------------------------------------------------------------------------*/
   1.168 +double iniparser_getdouble(dictionary * d, char * key, double notfound);
   1.169 +
   1.170 +/*-------------------------------------------------------------------------*/
   1.171 +/**
   1.172 +  @brief    Get the string associated to a key, convert to a boolean
   1.173 +  @param    d Dictionary to search
   1.174 +  @param    key Key string to look for
   1.175 +  @param    notfound Value to return in case of error
   1.176 +  @return   integer
   1.177 +
   1.178 +  This function queries a dictionary for a key. A key as read from an
   1.179 +  ini file is given as "section:key". If the key cannot be found,
   1.180 +  the notfound value is returned.
   1.181 +
   1.182 +  A true boolean is found if one of the following is matched:
   1.183 +
   1.184 +  - A string starting with 'y'
   1.185 +  - A string starting with 'Y'
   1.186 +  - A string starting with 't'
   1.187 +  - A string starting with 'T'
   1.188 +  - A string starting with '1'
   1.189 +
   1.190 +  A false boolean is found if one of the following is matched:
   1.191 +
   1.192 +  - A string starting with 'n'
   1.193 +  - A string starting with 'N'
   1.194 +  - A string starting with 'f'
   1.195 +  - A string starting with 'F'
   1.196 +  - A string starting with '0'
   1.197 +
   1.198 +  The notfound value returned if no boolean is identified, does not
   1.199 +  necessarily have to be 0 or 1.
   1.200 + */
   1.201 +/*--------------------------------------------------------------------------*/
   1.202 +int iniparser_getboolean(dictionary * d, char * key, int notfound);
   1.203 +
   1.204 +
   1.205 +/*-------------------------------------------------------------------------*/
   1.206 +/**
   1.207 +  @brief    Set an entry in a dictionary.
   1.208 +  @param    ini     Dictionary to modify.
   1.209 +  @param    entry   Entry to modify (entry name)
   1.210 +  @param    val     New value to associate to the entry.
   1.211 +  @return   int 0 if Ok, -1 otherwise.
   1.212 +
   1.213 +  If the given entry can be found in the dictionary, it is modified to
   1.214 +  contain the provided value. If it cannot be found, -1 is returned.
   1.215 +  It is Ok to set val to NULL.
   1.216 + */
   1.217 +/*--------------------------------------------------------------------------*/
   1.218 +int iniparser_set(dictionary * ini, char * entry, char * val);
   1.219 +
   1.220 +
   1.221 +/*-------------------------------------------------------------------------*/
   1.222 +/**
   1.223 +  @brief    Delete an entry in a dictionary
   1.224 +  @param    ini     Dictionary to modify
   1.225 +  @param    entry   Entry to delete (entry name)
   1.226 +  @return   void
   1.227 +
   1.228 +  If the given entry can be found, it is deleted from the dictionary.
   1.229 + */
   1.230 +/*--------------------------------------------------------------------------*/
   1.231 +void iniparser_unset(dictionary * ini, char * entry);
   1.232 +
   1.233 +/*-------------------------------------------------------------------------*/
   1.234 +/**
   1.235 +  @brief    Finds out if a given entry exists in a dictionary
   1.236 +  @param    ini     Dictionary to search
   1.237 +  @param    entry   Name of the entry to look for
   1.238 +  @return   integer 1 if entry exists, 0 otherwise
   1.239 +
   1.240 +  Finds out if a given entry exists in the dictionary. Since sections
   1.241 +  are stored as keys with NULL associated values, this is the only way
   1.242 +  of querying for the presence of sections in a dictionary.
   1.243 + */
   1.244 +/*--------------------------------------------------------------------------*/
   1.245 +int iniparser_find_entry(dictionary * ini, char * entry) ;
   1.246 +
   1.247 +/*-------------------------------------------------------------------------*/
   1.248 +/**
   1.249 +  @brief    Parse an ini file and return an allocated dictionary object
   1.250 +  @param    ininame Name of the ini file to read.
   1.251 +  @return   Pointer to newly allocated dictionary
   1.252 +
   1.253 +  This is the parser for ini files. This function is called, providing
   1.254 +  the name of the file to be read. It returns a dictionary object that
   1.255 +  should not be accessed directly, but through accessor functions
   1.256 +  instead.
   1.257 +
   1.258 +  The returned dictionary must be freed using iniparser_freedict().
   1.259 + */
   1.260 +/*--------------------------------------------------------------------------*/
   1.261 +dictionary * iniparser_load(char * ininame);
   1.262 +
   1.263 +/*-------------------------------------------------------------------------*/
   1.264 +/**
   1.265 +  @brief    Free all memory associated to an ini dictionary
   1.266 +  @param    d Dictionary to free
   1.267 +  @return   void
   1.268 +
   1.269 +  Free all memory associated to an ini dictionary.
   1.270 +  It is mandatory to call this function before the dictionary object
   1.271 +  gets out of the current context.
   1.272 + */
   1.273 +/*--------------------------------------------------------------------------*/
   1.274 +void iniparser_freedict(dictionary * d);
   1.275 +
   1.276 +#endif

mercurial