Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
461f6fef
Commit
461f6fef
authored
17 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created iniGet/ReadExistingString(), which do nothing (just return NULL) if
the key doesn't exist.
parent
ac733071
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/xpdev/ini_file.c
+45
-11
45 additions, 11 deletions
src/xpdev/ini_file.c
src/xpdev/ini_file.h
+8
-2
8 additions, 2 deletions
src/xpdev/ini_file.h
with
53 additions
and
13 deletions
src/xpdev/ini_file.c
+
45
−
11
View file @
461f6fef
...
...
@@ -298,9 +298,12 @@ BOOL iniKeyExists(str_list_t list, const char* section, const char* key)
char
val
[
INI_MAX_VALUE_LEN
];
size_t
i
;
if
(
list
==
NULL
)
return
(
FALSE
);
i
=
get_value
(
list
,
section
,
key
,
val
);
if
(
list
==
NULL
||
list
[
i
]
==
NULL
||
*
(
list
[
i
])
==
INI_OPEN_SECTION_CHAR
)
if
(
list
[
i
]
==
NULL
||
*
(
list
[
i
])
==
INI_OPEN_SECTION_CHAR
)
return
(
FALSE
);
return
(
TRUE
);
...
...
@@ -647,13 +650,18 @@ char* iniSetStringList(str_list_t* list, const char* section, const char* key
return
iniSetString
(
list
,
section
,
key
,
value
,
style
);
}
static
char
*
default_value
(
const
char
*
deflt
,
char
*
value
)
{
if
(
deflt
!=
NULL
&&
deflt
!=
value
)
sprintf
(
value
,
"%.*s"
,
INI_MAX_VALUE_LEN
-
1
,
deflt
);
return
(
deflt
);
}
char
*
iniReadString
(
FILE
*
fp
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
)
{
if
(
read_value
(
fp
,
section
,
key
,
value
)
==
NULL
||
*
value
==
0
/* blank */
)
{
if
(
deflt
!=
NULL
&&
deflt
!=
value
)
sprintf
(
value
,
"%.*s"
,
INI_MAX_VALUE_LEN
-
1
,
deflt
);
return
((
char
*
)
deflt
);
}
if
(
read_value
(
fp
,
section
,
key
,
value
)
==
NULL
||
*
value
==
0
/* blank */
)
return
default_value
(
deflt
,
value
);
return
(
value
);
}
...
...
@@ -662,11 +670,37 @@ char* iniGetString(str_list_t list, const char* section, const char* key, const
{
get_value
(
list
,
section
,
key
,
value
);
if
(
*
value
==
0
/* blank value or missing key */
)
{
if
(
deflt
!=
NULL
&&
deflt
!=
value
)
sprintf
(
value
,
"%.*s"
,
INI_MAX_VALUE_LEN
-
1
,
deflt
);
return
((
char
*
)
deflt
);
}
if
(
*
value
==
0
/* blank value or missing key */
)
return
default_value
(
deflt
,
value
);
return
(
value
);
}
char
*
iniReadExistingString
(
FILE
*
fp
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
)
{
if
(
read_value
(
fp
,
section
,
key
,
value
)
==
NULL
)
return
(
NULL
);
if
(
*
value
==
0
/* blank */
)
return
default_value
(
deflt
,
value
);
return
(
value
);
}
char
*
iniGetExistingString
(
str_list_t
list
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
)
{
size_t
i
;
if
(
list
==
NULL
)
return
(
NULL
);
i
=
get_value
(
list
,
section
,
key
,
value
);
if
(
list
[
i
]
==
NULL
||
*
(
list
[
i
])
==
INI_OPEN_SECTION_CHAR
)
/* missing key */
return
(
NULL
);
if
(
*
value
==
0
/* blank value */
)
return
default_value
(
deflt
,
value
);
return
(
value
);
}
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/ini_file.h
+
8
−
2
View file @
461f6fef
/* ini_file.h */
/* Functions to parse ini files */
/* Functions to parse ini
(initialization / configuration)
files */
/* $Id$ */
...
...
@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 200
5
Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 200
7
Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
...
...
@@ -79,6 +79,9 @@ str_list_t iniLogLevelStringList(void);
/* These functions read a single key of the specified type */
char
*
iniReadString
(
FILE
*
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
);
/* If the key doesn't exist, iniReadExistingString just returns NULL */
char
*
iniReadExistingString
(
FILE
*
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
);
str_list_t
iniReadStringList
(
FILE
*
,
const
char
*
section
,
const
char
*
key
,
const
char
*
sep
,
const
char
*
deflt
);
long
iniReadInteger
(
FILE
*
,
const
char
*
section
,
const
char
*
key
...
...
@@ -128,6 +131,9 @@ named_string_t**
char
*
iniGetString
(
str_list_t
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
);
/* If the key doesn't exist, iniGetExistingString just returns NULL */
char
*
iniGetExistingString
(
str_list_t
,
const
char
*
section
,
const
char
*
key
,
const
char
*
deflt
,
char
*
value
);
str_list_t
iniGetStringList
(
str_list_t
,
const
char
*
section
,
const
char
*
key
,
const
char
*
sep
,
const
char
*
deflt
);
long
iniGetInteger
(
str_list_t
,
const
char
*
section
,
const
char
*
key
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment