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
add08ce2
Commit
add08ce2
authored
20 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Changed use of strListAdd().
Removed ustrListAddAt() (not needed). Created iniReadFile() and iniWriteFile().
parent
909f6f27
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/xpdev/ini_file.c
+28
-3
28 additions, 3 deletions
src/xpdev/ini_file.c
src/xpdev/ini_file.h
+6
-0
6 additions, 0 deletions
src/xpdev/ini_file.h
src/xpdev/str_list.c
+8
-10
8 additions, 10 deletions
src/xpdev/str_list.c
src/xpdev/str_list.h
+1
-4
1 addition, 4 deletions
src/xpdev/str_list.h
with
43 additions
and
17 deletions
src/xpdev/ini_file.c
+
28
−
3
View file @
add08ce2
...
...
@@ -39,6 +39,7 @@
#include
<string.h>
/* strlen */
#include
<ctype.h>
/* isdigit */
#include
"sockwrap.h"
/* inet_addr */
#include
"filewrap.h"
/* chsize */
#include
"ini_file.h"
#define INI_MAX_LINE_LEN 256
/* Maximum length of entire line, includes '\0' */
...
...
@@ -152,7 +153,7 @@ str_list_t iniGetStringList(FILE* fp, const char* section, const char* key
token
=
strtok
(
list
,
sep
);
while
(
token
!=
NULL
)
{
truncsp
(
token
);
if
(
strListAdd
At
(
&
lp
,
token
,
items
++
)
==
NULL
)
if
(
strListAdd
(
&
lp
,
token
,
items
++
)
==
NULL
)
break
;
token
=
strtok
(
NULL
,
sep
);
}
...
...
@@ -215,7 +216,7 @@ str_list_t iniGetSectionList(FILE* fp, const char* prefix)
if
(
prefix
!=
NULL
)
if
(
strnicmp
(
p
,
prefix
,
strlen
(
prefix
))
!=
0
)
continue
;
if
(
strListAdd
At
(
&
lp
,
p
,
items
++
)
==
NULL
)
if
(
strListAdd
(
&
lp
,
p
,
items
++
)
==
NULL
)
break
;
}
...
...
@@ -255,7 +256,7 @@ str_list_t iniGetKeyList(FILE* fp, const char* section)
continue
;
*
tp
=
0
;
truncsp
(
p
);
if
(
strListAdd
At
(
&
lp
,
p
,
items
++
)
==
NULL
)
if
(
strListAdd
(
&
lp
,
p
,
items
++
)
==
NULL
)
break
;
}
...
...
@@ -433,3 +434,27 @@ ulong iniGetBitField(FILE* fp, const char* section, const char* key,
return
(
v
);
}
str_list_t
iniReadFile
(
FILE
*
fp
)
{
size_t
i
;
str_list_t
list
;
rewind
(
fp
);
list
=
strListReadFile
(
fp
,
NULL
,
INI_MAX_VALUE_LEN
);
if
(
list
!=
NULL
)
{
/* truncate the white-space off end of strings */
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
truncsp
(
list
[
i
]);
}
return
(
list
);
}
BOOL
iniWriteFile
(
FILE
*
fp
,
const
str_list_t
list
)
{
rewind
(
fp
);
chsize
(
fileno
(
fp
),
0
);
/* truncate */
return
(
strListWriteFile
(
fp
,
list
,
"
\n
"
)
==
strListCount
(
list
));
}
This diff is collapsed.
Click to expand it.
src/xpdev/ini_file.h
+
6
−
0
View file @
add08ce2
...
...
@@ -85,6 +85,12 @@ void* iniFreeStringList(str_list_t list);
/* Free named string list returned from iniGetNamedStringList */
void
*
iniFreeNamedStringList
(
named_string_t
**
list
);
/* File I/O Functions */
str_list_t
iniReadFile
(
FILE
*
fp
);
BOOL
iniWriteFile
(
FILE
*
fp
,
const
str_list_t
list
);
#if defined(__cplusplus)
}
#endif
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/str_list.c
+
8
−
10
View file @
add08ce2
...
...
@@ -122,7 +122,7 @@ str_list_t strListRemove(str_list_t* list, size_t index)
return
(
lp
);
}
str_list_t
strListAdd
At
(
str_list_t
*
list
,
const
char
*
str
,
size_t
count
)
str_list_t
strListAdd
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
{
char
*
buf
;
...
...
@@ -131,12 +131,10 @@ str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
strcpy
(
buf
,
str
);
return
(
str_list_append
(
list
,
buf
,
count
));
}
if
(
index
==
0
)
index
=
strListCount
(
*
list
);
str_list_t
strListAdd
(
str_list_t
*
list
,
const
char
*
str
)
{
return
strListAddAt
(
list
,
str
,
strListCount
(
*
list
));
return
(
str_list_append
(
list
,
buf
,
index
));
}
str_list_t
strListAddList
(
str_list_t
*
list
,
const
str_list_t
add_list
)
...
...
@@ -146,7 +144,7 @@ str_list_t strListAddList(str_list_t* list, const str_list_t add_list)
count
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
strListAdd
At
(
list
,
add_list
[
i
],
count
++
);
strListAdd
(
list
,
add_list
[
i
],
count
++
);
return
(
*
list
);
}
...
...
@@ -183,7 +181,7 @@ str_list_t strListSplit(str_list_t* list, char* str, const char* delimit)
}
for
(
token
=
strtok
(
str
,
delimit
);
token
!=
NULL
;
token
=
strtok
(
NULL
,
delimit
))
strListAdd
(
list
,
token
);
strListAdd
(
list
,
token
,
0
);
return
(
*
list
);
}
...
...
@@ -294,7 +292,7 @@ str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len)
while
(
!
feof
(
fp
))
{
if
(
fgets
(
buf
,
max_line_len
+
1
,
fp
)
==
NULL
)
break
;
strListAdd
At
(
list
,
buf
,
count
++
);
strListAdd
(
list
,
buf
,
count
++
);
}
free
(
buf
);
...
...
@@ -312,7 +310,7 @@ size_t strListWriteFile(FILE* fp, const str_list_t list, const char* separator)
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
{
if
(
fputs
(
list
[
i
],
fp
)
==
EOF
)
break
;
if
(
sep
e
rator
!=
NULL
&&
fputs
(
sep
e
rator
,
fp
)
==
EOF
)
if
(
sep
a
rator
!=
NULL
&&
fputs
(
sep
a
rator
,
fp
)
==
EOF
)
break
;
}
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/str_list.h
+
1
−
4
View file @
add08ce2
...
...
@@ -57,10 +57,7 @@ void strListFreeStrings(str_list_t list);
/* Pass a pointer to a string list, the string to add (append) */
/* Returns the updated list or NULL on error */
str_list_t
strListAdd
(
str_list_t
*
list
,
const
char
*
str
);
/* Adds a string into the list at a specific index */
str_list_t
strListAddAt
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
str_list_t
strListAdd
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
/* Append a string list onto another string list */
str_list_t
strListAddList
(
str_list_t
*
list
,
const
str_list_t
append_list
);
...
...
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