提交 455b6e1e 编写于 作者: N ndevilla

Switched to version 3.0

上级 88c50b7e
Author: Nicolas Devillard <ndevilla@free.fr>
Many thanks to the many people who contributed ideas, code, suggestions,
corrections, enhancements.
This tiny library has received countless contributions and I have
not kept track of all the people who contributed. Let them be thanked
for their ideas, code, suggestions, corrections, enhancements!
......@@ -12,4 +12,4 @@ iniParser installation instructions
Enjoy!
N. Devillard
Thu Jan 3 19:36:38 CET 2008
Wed Mar 2 21:14:17 CET 2011
Copyright (c) 2000-2007 by Nicolas Devillard.
Copyright (c) 2000-2011 by Nicolas Devillard.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a
......
Welcome to iniParser -- version 3.0b (beta)
released 03 Jan 2008
Welcome to iniParser -- version 3.0
released 02 Mar 2011
This modules offers parsing of ini files from the C level.
See a complete documentation in HTML format, from this directory
......@@ -9,4 +9,4 @@ open the file html/index.html with any HTML-capable browser.
Enjoy!
N.Devillard
Thu Jan 3 19:36:31 CET 2008
Wed Mar 2 21:46:14 CET 2011
#
# iniparser doc Makefile
#
all: html
html:
doxygen iniparser.dox
rm -f ../html/annotated.html
rm -f ../html/classes.html
rm -f ../html/doxygen.gif
rm -f ../html/files.html
rm -f ../html/functions.html
rm -f ../html/globals.html
rm -f ../html/iniparser_main.html
PROJECT_NAME = iniparser
PROJECT_NUMBER = 3.0
OUTPUT_DIRECTORY = ..
OUTPUT_LANGUAGE = English
EXTRACT_ALL = YES
EXTRACT_PRIVATE = NO
EXTRACT_STATIC = NO
HIDE_UNDOC_MEMBERS = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
INTERNAL_DOCS = NO
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
VERBATIM_HEADERS = NO
SHOW_INCLUDE_FILES = NO
JAVADOC_AUTOBRIEF = NO
INHERIT_DOCS = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 4
ENABLED_SECTIONS =
GENERATE_TODOLIST = NO
GENERATE_TESTLIST = NO
ALIASES =
MAX_INITIALIZER_LINES = 30
OPTIMIZE_OUTPUT_FOR_C = YES
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
INPUT = iniparser.main ../src
FILE_PATTERNS = iniparser.h
RECURSIVE = NO
EXCLUDE =
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
IMAGE_PATH =
INPUT_FILTER =
FILTER_SOURCE_FILES = NO
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
DISABLE_INDEX = YES
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
GENERATE_LATEX = NO
GENERATE_RTF = NO
GENERATE_MAN = NO
ENABLE_PREPROCESSING = NO
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = NO
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
PERL_PATH = /usr/bin/perl
HAVE_DOT = NO
SEARCHENGINE = NO
/**
@mainpage iniparser documentation
@section welcome Introduction
iniParser is a simple C library offering ini file parsing services.
The library is pretty small (less than 1500 lines of C) and robust, and
does not depend on any other external library to compile. It is written
in ANSI C and should compile on most platforms without difficulty.
@section inidef What is an ini file?
An ini file is an ASCII file describing simple parameters
(character strings, integers, floating-point values or booleans)
in an explicit format, easy to use and modify for users.
An ini file is segmented into Sections, declared by the following
syntax:
@verbatim
[Section Name]
@endverbatim
i.e. the section name enclosed in square brackets, alone on a
line. Sections names are allowed to contain any character but
square brackets or linefeeds.
In any section are zero or more variables, declared with the
following syntax:
@verbatim
Key = value ; comment
@endverbatim
The key is any string (possibly containing blanks). The value is
any character on the right side of the equal sign. Values can be
given enclosed with quotes. If no quotes are present, the value is
understood as containing all characters between the first and the
last non-blank characters before the comment. The following
declarations are identical:
@verbatim
Hello = "this is a long string value" ; comment
Hello = this is a long string value ; comment
@endverbatim
The semicolon and comment at the end of the line are optional. If
there is a comment, it starts from the first character after the
semicolon up to the end of the line.
Multi-line values can be provided by ending the line with a
backslash (\).
@verbatim
Multiple = Line 1 \
Line 2 \
Line 3 \
Line 4 ; comment
@endverbatim
This would yield: "multiple" <- "Line1 Line2 Line3 Line4"
Comments in an ini file are:
- Lines starting with a hash sign
- Blank lines (only blanks or tabs)
- Comments given on value lines after the semicolon (if present)
@section install Compiling/installing the library
Edit the Makefile to indicate the C compiler you want to use, the
options to provide to compile ANSI C, and possibly the options to pass
to the ar program on your machine to build a library (.a) from a set
of object (.o) files.
Defaults are set for the gcc compiler and the standard ar library
builder.
Type 'make', that should do it.
To use the library in your programs, add the following line on top
of your module:
@code
#include "iniparser.h"
@endcode
And link your program with the iniparser library by adding
@c -liniparser.a to the compile line.
See the file test/initest.c for an example.
iniparser is an ANSI C library. If you want to compile it
with a C++ compiler you will likely run into compatibility
issues. Headers probably have to include the extern "C"
hack and function prototypes will want to add some const
here and there to keep the compiler happy. This job is left
to the reader as there are too many C++ compilers around, each
with its own requirements as to what represents acceptable
C code in a C++ environment. You have been warned.
@section reference Library reference
The library is completely documented in its header file. On-line
documentation has been generated and can be consulted here:
- iniparser.h
@section usage Using the parser
Comments are discarded by the parser. Then sections are
identified, and in each section a new entry is created for every
keyword found. The keywords are stored with the following syntax:
@verbatim
[Section]
Keyword = value ; comment
@endverbatim
is converted to the following key pair:
@verbatim
("section:keyword", "value")
@endverbatim
This means that if you want to retrieve the value that was stored
in the section called @c Pizza, in the keyword @c Cheese,
you would make a request to the dictionary for
@c "pizza:cheese". All section and keyword names are converted
to lowercase before storage in the structure. The value side is
conserved as it has been parsed, though.
Section names are also stored in the structure. They are stored
using as key the section name, and a NULL associated value. They
can be queried through iniparser_find_entry().
To launch the parser, use the function called iniparser_load(), which
takes an input file name and returns a newly allocated @e dictionary
structure. This latter object should remain opaque to the user and only
accessed through the following accessor functions:
- iniparser_getstring()
- iniparser_getint()
- iniparser_getdouble()
- iniparser_getboolean()
Finally, discard this structure using iniparser_freedict().
All values parsed from the ini file are stored as strings. The
accessors are just converting these strings to the requested type on
the fly, but you could basically perform this conversion by yourself
after having called the string accessor.
Notice that iniparser_getboolean() will return an integer (0 or 1),
trying to make sense of what was found in the file. Strings starting
with "y", "Y", "t", "T" or "1" are considered true values (return 1),
strings starting with "n", "N", "f", "F", "0" are considered false
(return 0). This allows some flexibility in handling of boolean
answers.
If you want to add extra information into the structure that was not
present in the ini file, you can use iniparser_set() to insert a
string.
If you want to add a section to the structure, add a key
with a NULL value. Example:
@verbatim
iniparser_set(ini, "section", NULL);
iniparser_set(ini, "section:key1", NULL);
iniparser_set(ini, "section:key2", NULL);
@endverbatim
@section implementation A word about the implementation
The dictionary structure is a pretty simple dictionary
implementation which might find some uses in other applications.
If you are curious, look into the source.
@section defects Known defects
The dictionary structure is extremely unefficient for searching
as keys are sorted in the same order as they are read from the
ini file, which is convenient when dumping back to a file. The
simplistic first-approach linear search implemented there can
become a bottleneck if you have a very large number of keys.
People who need to load large amounts of data from an ini file
should definitely turn to more appropriate solutions: sqlite3 or
similar. There are otherwise many other dictionary implementations
available on the net to replace this one.
@section authors Authors
Nicolas Devillard (ndevilla AT free DOT fr).
*/
/* The standard CSS for doxygen */
body, table, div, p, dl {
font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif;
font-size: 12px;
}
/* @group Heading Levels */
h1 {
text-align: center;
font-size: 150%;
}
h2 {
font-size: 120%;
}
h3 {
font-size: 100%;
}
dt {
font-weight: bold;
}
div.multicol {
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
-moz-column-count: 3;
-webkit-column-count: 3;
}
p.startli, p.startdd, p.starttd {
margin-top: 2px;
}
p.endli {
margin-bottom: 0px;
}
p.enddd {
margin-bottom: 4px;
}
p.endtd {
margin-bottom: 2px;
}
/* @end */
caption {
font-weight: bold;
}
span.legend {
font-size: 70%;
text-align: center;
}
h3.version {
font-size: 90%;
text-align: center;
}
div.qindex, div.navtab{
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
padding: 2px;
}
div.qindex, div.navpath {
width: 100%;
line-height: 140%;
}
div.navtab {
margin-right: 15px;
}
/* @group Link Styling */
a {
color: #153788;
font-weight: normal;
text-decoration: none;
}
.contents a:visited {
color: #1b77c5;
}
a:hover {
text-decoration: underline;
}
a.qindex {
font-weight: bold;
}
a.qindexHL {
font-weight: bold;
background-color: #6666cc;
color: #ffffff;
border: 1px double #9295C2;
}
.contents a.qindexHL:visited {
color: #ffffff;
}
a.el {
font-weight: bold;
}
a.elRef {
}
a.code {
color: #3030f0;
}
a.codeRef {
color: #3030f0;
}
/* @end */
dl.el {
margin-left: -1cm;
}
.fragment {
font-family: monospace, fixed;
font-size: 105%;
}
pre.fragment {
border: 1px solid #CCCCCC;
background-color: #f5f5f5;
padding: 4px 6px;
margin: 4px 8px 4px 2px;
overflow: auto;
word-wrap: break-word;
font-size: 9pt;
line-height: 125%;
}
div.ah {
background-color: black;
font-weight: bold;
color: #ffffff;
margin-bottom: 3px;
margin-top: 3px
}
div.groupHeader {
margin-left: 16px;
margin-top: 12px;
margin-bottom: 6px;
font-weight: bold;
}
div.groupText {
margin-left: 16px;
font-style: italic;
}
body {
background: white;
color: black;
margin-right: 20px;
margin-left: 20px;
}
td.indexkey {
background-color: #e8eef2;
font-weight: bold;
border: 1px solid #CCCCCC;
margin: 2px 0px 2px 0;
padding: 2px 10px;
}
td.indexvalue {
background-color: #e8eef2;
border: 1px solid #CCCCCC;
padding: 2px 10px;
margin: 2px 0px;
}
tr.memlist {
background-color: #f0f0f0;
}
p.formulaDsp {
text-align: center;
}
img.formulaDsp {
}
img.formulaInl {
vertical-align: middle;
}
div.center {
text-align: center;
margin-top: 0px;
margin-bottom: 0px;
padding: 0px;
}
div.center img {
border: 0px;
}
img.footer {
border: 0px;
vertical-align: middle;
}
/* @group Code Colorization */
span.keyword {
color: #008000
}
span.keywordtype {
color: #604020
}
span.keywordflow {
color: #e08000
}
span.comment {
color: #800000
}
span.preprocessor {
color: #806020
}
span.stringliteral {
color: #002080
}
span.charliteral {
color: #008080
}
span.vhdldigit {
color: #ff00ff
}
span.vhdlchar {
color: #000000
}
span.vhdlkeyword {
color: #700070
}
span.vhdllogic {
color: #ff0000
}
/* @end */
.search {
color: #003399;
font-weight: bold;
}
form.search {
margin-bottom: 0px;
margin-top: 0px;
}
input.search {
font-size: 75%;
color: #000080;
font-weight: normal;
background-color: #e8eef2;
}
td.tiny {
font-size: 75%;
}
.dirtab {
padding: 4px;
border-collapse: collapse;
border: 1px solid #84b0c7;
}
th.dirtab {
background: #e8eef2;
font-weight: bold;
}
hr {
height: 0px;
border: none;
border-top: 1px solid #666;
}
hr.footer {
height: 1px;
}
/* @group Member Descriptions */
.mdescLeft, .mdescRight,
.memItemLeft, .memItemRight,
.memTemplItemLeft, .memTemplItemRight, .memTemplParams {
background-color: #FAFAFA;
border: none;
margin: 4px;
padding: 1px 0 0 8px;
}
.mdescLeft, .mdescRight {
padding: 0px 8px 4px 8px;
color: #555;
}
.memItemLeft, .memItemRight, .memTemplParams {
border-top: 1px solid #ccc;
}
.memItemLeft, .memTemplItemLeft {
white-space: nowrap;
}
.memTemplParams {
color: #606060;
white-space: nowrap;
}
/* @end */
/* @group Member Details */
/* Styles for detailed member documentation */
.memtemplate {
font-size: 80%;
color: #606060;
font-weight: normal;
margin-left: 3px;
}
.memnav {
background-color: #e8eef2;
border: 1px solid #84b0c7;
text-align: center;
margin: 2px;
margin-right: 15px;
padding: 2px;
}
.memitem {
padding: 0;
margin-bottom: 10px;
}
.memname {
white-space: nowrap;
font-weight: bold;
margin-left: 6px;
}
.memproto {
border-top: 1px solid #84b0c7;
border-left: 1px solid #84b0c7;
border-right: 1px solid #84b0c7;
padding: 0;
background-color: #d5e1e8;
font-weight: bold;
/* firefox specific markup */
background-image: -moz-linear-gradient(rgba(228, 233, 245, 1.0) 0%, rgba(193, 205, 232, 1.0) 100%);
-moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
-moz-border-radius-topright: 8px;
-moz-border-radius-topleft: 8px;
/* webkit specific markup */
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(228, 233, 245, 1.0)), to(rgba(193, 205, 232, 1.0)));
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
-webkit-border-top-right-radius: 8px;
-webkit-border-top-left-radius: 8px;
}
.memdoc {
border-bottom: 1px solid #84b0c7;
border-left: 1px solid #84b0c7;
border-right: 1px solid #84b0c7;
padding: 2px 5px;
background-color: #eef3f5;
border-top-width: 0;
/* firefox specific markup */
-moz-border-radius-bottomleft: 8px;
-moz-border-radius-bottomright: 8px;
-moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
/* webkit specific markup */
-webkit-border-bottom-left-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
}
.paramkey {
text-align: right;
}
.paramtype {
white-space: nowrap;
}
.paramname {
color: #602020;
white-space: nowrap;
}
.paramname em {
font-style: normal;
}
/* @end */
/* @group Directory (tree) */
/* for the tree view */
.ftvtree {
font-family: sans-serif;
margin: 0.5em;
}
/* these are for tree view when used as main index */
.directory {
font-size: 9pt;
font-weight: bold;
}
.directory h3 {
margin: 0px;
margin-top: 1em;
font-size: 11pt;
}
/*
The following two styles can be used to replace the root node title
with an image of your choice. Simply uncomment the next two styles,
specify the name of your image and be sure to set 'height' to the
proper pixel height of your image.
*/
/*
.directory h3.swap {
height: 61px;
background-repeat: no-repeat;
background-image: url("yourimage.gif");
}
.directory h3.swap span {
display: none;
}
*/
.directory > h3 {
margin-top: 0;
}
.directory p {
margin: 0px;
white-space: nowrap;
}
.directory div {
display: none;
margin: 0px;
}
.directory img {
vertical-align: -30%;
}
/* these are for tree view when not used as main index */
.directory-alt {
font-size: 100%;
font-weight: bold;
}
.directory-alt h3 {
margin: 0px;
margin-top: 1em;
font-size: 11pt;
}
.directory-alt > h3 {
margin-top: 0;
}
.directory-alt p {
margin: 0px;
white-space: nowrap;
}
.directory-alt div {
display: none;
margin: 0px;
}
.directory-alt img {
vertical-align: -30%;
}
/* @end */
address {
font-style: normal;
color: #333;
}
table.doxtable {
border-collapse:collapse;
}
table.doxtable td, table.doxtable th {
border: 1px solid #153788;
padding: 3px 7px 2px;
}
table.doxtable th {
background-color: #254798;
color: #FFFFFF;
font-size: 110%;
padding-bottom: 4px;
padding-top: 5px;
text-align:left;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>iniparser: Data Fields</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="tabs">
<ul>
<li><a href="globals.html"><span>All</span></a></li>
<li class="current"><a href="globals_func.html"><span>Functions</span></a></li>
</ul>
</div>
<div class="contents">
&nbsp;<ul>
<li>iniparser_dump()
: <a class="el" href="iniparser_8h.html#a046436b3489cd8854ba8e29109250324">iniparser.h</a>
</li>
<li>iniparser_dump_ini()
: <a class="el" href="iniparser_8h.html#aece0e32de371c9e9592d8333f816dfac">iniparser.h</a>
</li>
<li>iniparser_find_entry()
: <a class="el" href="iniparser_8h.html#a3d67c98bbc0cb5239f024ad54bdc63f1">iniparser.h</a>
</li>
<li>iniparser_freedict()
: <a class="el" href="iniparser_8h.html#a90549ee518523921886b74454ff872eb">iniparser.h</a>
</li>
<li>iniparser_getboolean()
: <a class="el" href="iniparser_8h.html#aa2ea2b34f6f4b3cf93c9d4f8f992811f">iniparser.h</a>
</li>
<li>iniparser_getdouble()
: <a class="el" href="iniparser_8h.html#a480d35322f1252344cf2246ac21ee559">iniparser.h</a>
</li>
<li>iniparser_getint()
: <a class="el" href="iniparser_8h.html#ab813340fa9c9a7fcfe6775d6e5e458c2">iniparser.h</a>
</li>
<li>iniparser_getnsec()
: <a class="el" href="iniparser_8h.html#a0b5d6cdc7587e2d27a30f5cdc4a91931">iniparser.h</a>
</li>
<li>iniparser_getsecname()
: <a class="el" href="iniparser_8h.html#a393212be805f395bbfdeb1bafa8bb72a">iniparser.h</a>
</li>
<li>iniparser_getstring()
: <a class="el" href="iniparser_8h.html#aec2e5539bc2be063d1323cdf65f162a3">iniparser.h</a>
</li>
<li>iniparser_load()
: <a class="el" href="iniparser_8h.html#a45d87791d4d2593781bfdfe2991c3a2d">iniparser.h</a>
</li>
<li>iniparser_set()
: <a class="el" href="iniparser_8h.html#aa5d5787f96d6982a937edb2fd499ba60">iniparser.h</a>
</li>
<li>iniparser_unset()
: <a class="el" href="iniparser_8h.html#a7b1a7f2492a35043867fa801b8f21e52">iniparser.h</a>
</li>
</ul>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Mar 2 22:04:59 2011 for iniparser by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>iniparser: iniparser documentation</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="contents">
<h1>iniparser documentation </h1><h3 class="version">3.0 </h3><h2><a class="anchor" id="welcome">
Introduction</a></h2>
<p>iniParser is a simple C library offering ini file parsing services. The library is pretty small (less than 1500 lines of C) and robust, and does not depend on any other external library to compile. It is written in ANSI C and should compile on most platforms without difficulty.</p>
<h2><a class="anchor" id="inidef">
What is an ini file?</a></h2>
<p>An ini file is an ASCII file describing simple parameters (character strings, integers, floating-point values or booleans) in an explicit format, easy to use and modify for users.</p>
<p>An ini file is segmented into Sections, declared by the following syntax:</p>
<div class="fragment"><pre class="fragment">
[Section Name]
</pre></div><p>i.e. the section name enclosed in square brackets, alone on a line. Sections names are allowed to contain any character but square brackets or linefeeds.</p>
<p>In any section are zero or more variables, declared with the following syntax:</p>
<div class="fragment"><pre class="fragment">
Key = value ; comment
</pre></div><p>The key is any string (possibly containing blanks). The value is any character on the right side of the equal sign. Values can be given enclosed with quotes. If no quotes are present, the value is understood as containing all characters between the first and the last non-blank characters before the comment. The following declarations are identical:</p>
<div class="fragment"><pre class="fragment">
Hello = "this is a long string value" ; comment
Hello = this is a long string value ; comment
</pre></div><p>The semicolon and comment at the end of the line are optional. If there is a comment, it starts from the first character after the semicolon up to the end of the line.</p>
<p>Multi-line values can be provided by ending the line with a backslash (\).</p>
<div class="fragment"><pre class="fragment">
Multiple = Line 1 \
Line 2 \
Line 3 \
Line 4 ; comment
</pre></div><p>This would yield: "multiple" &lt;- "Line1 Line2 Line3 Line4"</p>
<p>Comments in an ini file are:</p>
<ul>
<li>Lines starting with a hash sign</li>
<li>Blank lines (only blanks or tabs)</li>
<li>Comments given on value lines after the semicolon (if present)</li>
</ul>
<h2><a class="anchor" id="install">
Compiling/installing the library</a></h2>
<p>Edit the Makefile to indicate the C compiler you want to use, the options to provide to compile ANSI C, and possibly the options to pass to the ar program on your machine to build a library (.a) from a set of object (.o) files.</p>
<p>Defaults are set for the gcc compiler and the standard ar library builder.</p>
<p>Type 'make', that should do it.</p>
<p>To use the library in your programs, add the following line on top of your module:</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &quot;<a class="code" href="iniparser_8h.html" title="Parser for ini files.">iniparser.h</a>&quot;</span>
</pre></div><p>And link your program with the iniparser library by adding <code>-liniparser.a</code> to the compile line.</p>
<p>See the file test/initest.c for an example.</p>
<p>iniparser is an ANSI C library. If you want to compile it with a C++ compiler you will likely run into compatibility issues. Headers probably have to include the extern "C" hack and function prototypes will want to add some const here and there to keep the compiler happy. This job is left to the reader as there are too many C++ compilers around, each with its own requirements as to what represents acceptable C code in a C++ environment. You have been warned.</p>
<h2><a class="anchor" id="reference">
Library reference</a></h2>
<p>The library is completely documented in its header file. On-line documentation has been generated and can be consulted here:</p>
<ul>
<li><a class="el" href="iniparser_8h.html" title="Parser for ini files.">iniparser.h</a></li>
</ul>
<h2><a class="anchor" id="usage">
Using the parser</a></h2>
<p>Comments are discarded by the parser. Then sections are identified, and in each section a new entry is created for every keyword found. The keywords are stored with the following syntax:</p>
<div class="fragment"><pre class="fragment">
[Section]
Keyword = value ; comment
</pre></div><p>is converted to the following key pair:</p>
<div class="fragment"><pre class="fragment">
("section:keyword", "value")
</pre></div><p>This means that if you want to retrieve the value that was stored in the section called <code>Pizza</code>, in the keyword <code>Cheese</code>, you would make a request to the dictionary for <code>"pizza:cheese"</code>. All section and keyword names are converted to lowercase before storage in the structure. The value side is conserved as it has been parsed, though.</p>
<p>Section names are also stored in the structure. They are stored using as key the section name, and a NULL associated value. They can be queried through <a class="el" href="iniparser_8h.html#a3d67c98bbc0cb5239f024ad54bdc63f1" title="Finds out if a given entry exists in a dictionary.">iniparser_find_entry()</a>.</p>
<p>To launch the parser, use the function called <a class="el" href="iniparser_8h.html#a45d87791d4d2593781bfdfe2991c3a2d" title="Parse an ini file and return an allocated dictionary object.">iniparser_load()</a>, which takes an input file name and returns a newly allocated <em>dictionary</em> structure. This latter object should remain opaque to the user and only accessed through the following accessor functions:</p>
<ul>
<li><a class="el" href="iniparser_8h.html#aec2e5539bc2be063d1323cdf65f162a3" title="Get the string associated to a key.">iniparser_getstring()</a></li>
<li><a class="el" href="iniparser_8h.html#ab813340fa9c9a7fcfe6775d6e5e458c2" title="Get the string associated to a key, convert to an int.">iniparser_getint()</a></li>
<li><a class="el" href="iniparser_8h.html#a480d35322f1252344cf2246ac21ee559" title="Get the string associated to a key, convert to a double.">iniparser_getdouble()</a></li>
<li><a class="el" href="iniparser_8h.html#aa2ea2b34f6f4b3cf93c9d4f8f992811f" title="Get the string associated to a key, convert to a boolean.">iniparser_getboolean()</a></li>
</ul>
<p>Finally, discard this structure using <a class="el" href="iniparser_8h.html#a90549ee518523921886b74454ff872eb" title="Free all memory associated to an ini dictionary.">iniparser_freedict()</a>.</p>
<p>All values parsed from the ini file are stored as strings. The accessors are just converting these strings to the requested type on the fly, but you could basically perform this conversion by yourself after having called the string accessor.</p>
<p>Notice that <a class="el" href="iniparser_8h.html#aa2ea2b34f6f4b3cf93c9d4f8f992811f" title="Get the string associated to a key, convert to a boolean.">iniparser_getboolean()</a> will return an integer (0 or 1), trying to make sense of what was found in the file. Strings starting with "y", "Y", "t", "T" or "1" are considered true values (return 1), strings starting with "n", "N", "f", "F", "0" are considered false (return 0). This allows some flexibility in handling of boolean answers.</p>
<p>If you want to add extra information into the structure that was not present in the ini file, you can use <a class="el" href="iniparser_8h.html#aa5d5787f96d6982a937edb2fd499ba60" title="Set an entry in a dictionary.">iniparser_set()</a> to insert a string.</p>
<p>If you want to add a section to the structure, add a key with a NULL value. Example: </p>
<div class="fragment"><pre class="fragment">
iniparser_set(ini, "section", NULL);
iniparser_set(ini, "section:key1", NULL);
iniparser_set(ini, "section:key2", NULL);
</pre></div><h2><a class="anchor" id="implementation">
A word about the implementation</a></h2>
<p>The dictionary structure is a pretty simple dictionary implementation which might find some uses in other applications. If you are curious, look into the source.</p>
<h2><a class="anchor" id="defects">
Known defects</a></h2>
<p>The dictionary structure is extremely unefficient for searching as keys are sorted in the same order as they are read from the ini file, which is convenient when dumping back to a file. The simplistic first-approach linear search implemented there can become a bottleneck if you have a very large number of keys.</p>
<p>People who need to load large amounts of data from an ini file should definitely turn to more appropriate solutions: sqlite3 or similar. There are otherwise many other dictionary implementations available on the net to replace this one.</p>
<h2><a class="anchor" id="authors">
Authors</a></h2>
<p>Nicolas Devillard (ndevilla AT free DOT fr). </p>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Mar 2 22:04:58 2011 for iniparser by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
此差异已折叠。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>iniparser: iniparser.main File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="contents">
<h1>iniparser.main File Reference</h1><table border="0" cellpadding="0" cellspacing="0">
</table>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Mar 2 22:04:59 2011 for iniparser by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
/* tabs styles, based on http://www.alistapart.com/articles/slidingdoors */
DIV.tabs
{
float : left;
width : 100%;
background : url("tab_b.gif") repeat-x bottom;
margin-bottom : 4px;
}
DIV.tabs UL
{
margin : 0px;
padding-left : 10px;
list-style : none;
}
DIV.tabs LI, DIV.tabs FORM
{
display : inline;
margin : 0px;
padding : 0px;
}
DIV.tabs FORM
{
float : right;
}
DIV.tabs A
{
float : left;
background : url("tab_r.gif") no-repeat right top;
border-bottom : 1px solid #84B0C7;
font-size : 80%;
font-weight : bold;
text-decoration : none;
}
DIV.tabs A:hover
{
background-position: 100% -150px;
}
DIV.tabs A:link, DIV.tabs A:visited,
DIV.tabs A:active, DIV.tabs A:hover
{
color: #1A419D;
}
DIV.tabs SPAN
{
float : left;
display : block;
background : url("tab_l.gif") no-repeat left top;
padding : 5px 9px;
white-space : nowrap;
}
DIV.tabs #MSearchBox
{
float : right;
display : inline;
font-size : 1em;
}
DIV.tabs TD
{
font-size : 80%;
font-weight : bold;
text-decoration : none;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
DIV.tabs SPAN {float : none;}
/* End IE5-Mac hack */
DIV.tabs A:hover SPAN
{
background-position: 0% -150px;
}
DIV.tabs LI.current A
{
background-position: 100% -150px;
border-width : 0px;
}
DIV.tabs LI.current SPAN
{
background-position: 0% -150px;
padding-bottom : 6px;
}
DIV.navpath
{
background : none;
border : none;
border-bottom : 1px solid #84B0C7;
text-align : center;
margin : 2px;
padding : 2px;
}
......@@ -9,9 +9,9 @@
*/
/*--------------------------------------------------------------------------*/
/*
$Id: iniparser.c,v 2.18 2008-01-03 18:35:39 ndevilla Exp $
$Revision: 2.18 $
$Date: 2008-01-03 18:35:39 $
$Id: iniparser.c,v 2.19 2011-03-02 20:15:13 ndevilla Exp $
$Revision: 2.19 $
$Date: 2011-03-02 20:15:13 $
*/
/*---------------------------- Includes ------------------------------------*/
#include <ctype.h>
......@@ -48,7 +48,7 @@ typedef enum _line_status_ {
allocated, it will be modified at each function call (not re-entrant).
*/
/*--------------------------------------------------------------------------*/
static char * strlwc(const char * s)
static char * strlwc(char * s)
{
static char l[ASCIILINESZ+1];
int i ;
......@@ -265,7 +265,7 @@ void iniparser_dump_ini(dictionary * d, FILE * f)
the dictionary, do not free or modify it.
*/
/*--------------------------------------------------------------------------*/
char * iniparser_getstring(dictionary * d, const char * key, char * def)
char * iniparser_getstring(dictionary * d, char * key, char * def)
{
char * lc_key ;
char * sval ;
......@@ -305,7 +305,7 @@ char * iniparser_getstring(dictionary * d, const char * key, char * def)
Credits: Thanks to A. Becker for suggesting strtol()
*/
/*--------------------------------------------------------------------------*/
int iniparser_getint(dictionary * d, const char * key, int notfound)
int iniparser_getint(dictionary * d, char * key, int notfound)
{
char * str ;
......@@ -368,7 +368,7 @@ double iniparser_getdouble(dictionary * d, char * key, double notfound)
necessarily have to be 0 or 1.
*/
/*--------------------------------------------------------------------------*/
int iniparser_getboolean(dictionary * d, const char * key, int notfound)
int iniparser_getboolean(dictionary * d, char * key, int notfound)
{
char * c ;
int ret ;
......@@ -526,7 +526,7 @@ static line_status iniparser_line(
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame)
dictionary * iniparser_load(char * ininame)
{
FILE * in ;
......@@ -563,6 +563,8 @@ dictionary * iniparser_load(const char * ininame)
while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) {
lineno++ ;
len = (int)strlen(line)-1;
if (len==0)
continue;
/* Safety check against buffer overflows */
if (line[len]!='\n') {
fprintf(stderr,
......
......@@ -10,8 +10,8 @@
/*--------------------------------------------------------------------------*/
/*
$Id: iniparser.h,v 1.24 2007-11-23 21:38:19 ndevilla Exp $
$Revision: 1.24 $
$Id: iniparser.h,v 1.26 2011-03-02 20:15:13 ndevilla Exp $
$Revision: 1.26 $
*/
#ifndef _INIPARSER_H_
......@@ -34,13 +34,6 @@
#include "dictionary.h"
/*---------------------------------------------------------------------------
Macros
---------------------------------------------------------------------------*/
/** For backwards compatibility only */
#define iniparser_getstr(d, k) iniparser_getstring(d, k, NULL)
#define iniparser_setstr iniparser_setstring
/*-------------------------------------------------------------------------*/
/**
@brief Get number of sections in a dictionary
......@@ -125,7 +118,7 @@ void iniparser_dump(dictionary * d, FILE * f);
the dictionary, do not free or modify it.
*/
/*--------------------------------------------------------------------------*/
char * iniparser_getstring(dictionary * d, const char * key, char * def);
char * iniparser_getstring(dictionary * d, char * key, char * def);
/*-------------------------------------------------------------------------*/
/**
......@@ -154,7 +147,7 @@ char * iniparser_getstring(dictionary * d, const char * key, char * def);
Credits: Thanks to A. Becker for suggesting strtol()
*/
/*--------------------------------------------------------------------------*/
int iniparser_getint(dictionary * d, const char * key, int notfound);
int iniparser_getint(dictionary * d, char * key, int notfound);
/*-------------------------------------------------------------------------*/
/**
......@@ -203,7 +196,7 @@ double iniparser_getdouble(dictionary * d, char * key, double notfound);
necessarily have to be 0 or 1.
*/
/*--------------------------------------------------------------------------*/
int iniparser_getboolean(dictionary * d, const char * key, int notfound);
int iniparser_getboolean(dictionary * d, char * key, int notfound);
/*-------------------------------------------------------------------------*/
......@@ -219,7 +212,7 @@ int iniparser_getboolean(dictionary * d, const char * key, int notfound);
It is Ok to set val to NULL.
*/
/*--------------------------------------------------------------------------*/
int iniparser_setstring(dictionary * ini, char * entry, char * val);
int iniparser_set(dictionary * ini, char * entry, char * val);
/*-------------------------------------------------------------------------*/
......@@ -262,7 +255,7 @@ int iniparser_find_entry(dictionary * ini, char * entry) ;
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
dictionary * iniparser_load(const char * ininame);
dictionary * iniparser_load(char * ininame);
/*-------------------------------------------------------------------------*/
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册