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
8e1e5c9c
Commit
8e1e5c9c
authored
20 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created strListDelete() and strListReplace().
Changed some return types to more logical/useful values.
parent
e0368e71
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/str_list.c
+86
-35
86 additions, 35 deletions
src/xpdev/str_list.c
src/xpdev/str_list.h
+13
-7
13 additions, 7 deletions
src/xpdev/str_list.h
with
99 additions
and
42 deletions
src/xpdev/str_list.c
+
86
−
35
View file @
8e1e5c9c
...
...
@@ -64,7 +64,7 @@ size_t strListCount(const str_list_t list)
return
(
i
);
}
static
str_list_t
str_list_append
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
static
char
*
str_list_append
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
{
str_list_t
lp
;
...
...
@@ -75,10 +75,10 @@ static str_list_t str_list_append(str_list_t* list, char* str, size_t index)
lp
[
index
++
]
=
str
;
lp
[
index
]
=
NULL
;
/* terminate list */
return
(
lp
);
return
(
str
);
}
static
str_list_t
str_list_insert
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
static
char
*
str_list_insert
(
str_list_t
*
list
,
char
*
str
,
size_t
index
)
{
size_t
i
;
size_t
count
;
...
...
@@ -97,16 +97,21 @@ static str_list_t str_list_insert(str_list_t* list, char* str, size_t index)
lp
[
i
]
=
lp
[
i
-
1
];
lp
[
index
]
=
str
;
return
(
lp
);
return
(
str
);
}
str_list_t
strListRemove
(
str_list_t
*
list
,
size_t
index
)
char
*
strListRemove
(
str_list_t
*
list
,
size_t
index
)
{
char
*
str
;
size_t
i
;
size_t
count
;
str_list_t
lp
;
count
=
strListCount
(
*
list
);
if
(
index
==
STR_LIST_LAST_INDEX
&&
count
)
index
=
count
-
1
;
if
(
index
>=
count
)
/* invalid index, do nothing */
return
(
NULL
);
...
...
@@ -115,14 +120,49 @@ str_list_t strListRemove(str_list_t* list, size_t index)
return
(
NULL
);
*
list
=
lp
;
str
=
lp
[
index
];
for
(
i
=
index
;
i
<
count
;
i
++
)
lp
[
i
]
=
lp
[
i
+
1
];
lp
[
count
]
=
NULL
;
return
(
lp
);
return
(
str
);
}
BOOL
strListDelete
(
str_list_t
*
list
,
size_t
index
)
{
char
*
str
;
if
((
str
=
strListRemove
(
list
,
index
))
==
NULL
)
return
(
FALSE
);
free
(
str
);
return
(
TRUE
);
}
char
*
strListReplace
(
const
str_list_t
list
,
size_t
index
,
const
char
*
str
)
{
char
*
buf
;
size_t
count
;
count
=
strListCount
(
list
);
if
(
index
==
STR_LIST_LAST_INDEX
&&
count
)
index
=
count
-
1
;
if
(
index
>=
count
)
/* invalid index, do nothing */
return
(
NULL
);
if
((
buf
=
(
char
*
)
realloc
(
list
[
index
],
strlen
(
str
)
+
1
))
==
NULL
)
return
(
NULL
);
list
[
index
]
=
buf
;
strcpy
(
buf
,
str
);
return
(
buf
);
}
str_list_t
strListAppend
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
char
*
strListAppend
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
{
char
*
buf
;
...
...
@@ -131,13 +171,13 @@ str_list_t strListAppend(str_list_t* list, const char* str, size_t index)
strcpy
(
buf
,
str
);
if
(
index
==
STR_LIST_
APPEND
)
if
(
index
==
STR_LIST_
LAST_INDEX
)
index
=
strListCount
(
*
list
);
return
(
str_list_append
(
list
,
buf
,
index
));
}
s
tr_list
_t
strListAppendList
(
str_list_t
*
list
,
const
str_list_t
add_list
)
s
ize
_t
strListAppendList
(
str_list_t
*
list
,
const
str_list_t
add_list
)
{
size_t
i
;
size_t
count
;
...
...
@@ -146,10 +186,10 @@ str_list_t strListAppendList(str_list_t* list, const str_list_t add_list)
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
strListAppend
(
list
,
add_list
[
i
],
count
++
);
return
(
*
lis
t
);
return
(
coun
t
);
}
str_list_t
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
char
*
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
)
{
char
*
buf
;
...
...
@@ -161,29 +201,37 @@ str_list_t strListInsert(str_list_t* list, const char* str, size_t index)
return
(
str_list_insert
(
list
,
buf
,
index
));
}
s
tr_list
_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
add_list
,
size_t
index
)
s
ize
_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
add_list
,
size_t
index
)
{
size_t
i
;
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
strListInsert
(
list
,
add_list
[
i
],
index
++
);
if
(
strListInsert
(
list
,
add_list
[
i
],
index
++
)
==
NULL
)
break
;
return
(
*
list
);
return
(
i
);
}
str_list_t
strListSplit
(
str_list_t
*
l
ist
,
char
*
str
,
const
char
*
delimit
)
str_list_t
strListSplit
(
str_list_t
*
l
p
,
char
*
str
,
const
char
*
delimit
)
{
size_t
count
;
char
*
token
;
str_list_t
list
;
if
(
list
==
NULL
)
{
if
((
*
list
=
strListInit
())
==
NULL
)
return
(
NULL
);
}
if
(
lp
==
NULL
)
{
if
((
list
=
strListInit
())
==
NULL
)
return
(
0
);
lp
=&
list
;
count
=
0
;
}
else
count
=
strListCount
(
*
lp
);
for
(
token
=
strtok
(
str
,
delimit
);
token
!=
NULL
;
token
=
strtok
(
NULL
,
delimit
))
strListAppend
(
list
,
token
,
STR_LIST_APPEND
);
if
(
strListAppend
(
lp
,
token
,
count
++
)
==
NULL
)
break
;
return
(
*
l
ist
);
return
(
*
l
p
);
}
str_list_t
strListSplitCopy
(
str_list_t
*
list
,
const
char
*
str
,
const
char
*
delimit
)
...
...
@@ -195,22 +243,23 @@ str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delim
strcpy
(
buf
,
str
);
*
list
=
strListSplit
(
list
,
buf
,
delimit
);
*
list
=
strListSplit
(
list
,
buf
,
delimit
);
free
(
buf
);
return
(
*
list
);
}
s
tr_list
_t
strListMerge
(
str_list_t
*
list
,
str_list_t
add_list
)
s
ize
_t
strListMerge
(
str_list_t
*
list
,
str_list_t
add_list
)
{
size_t
i
,
j
;
size_t
i
;
size_t
count
;
j
=
strListCount
(
*
list
);
count
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
str_list_append
(
list
,
add_list
[
i
],
j
++
);
str_list_append
(
list
,
add_list
[
i
],
count
++
);
return
(
*
list
);
return
(
i
);
}
static
int
strListCompareAlpha
(
const
void
*
arg1
,
const
void
*
arg2
)
...
...
@@ -272,20 +321,22 @@ void strListFree(str_list_t* list)
}
}
str_list_t
strListReadFile
(
FILE
*
fp
,
str_list_t
*
l
ist
,
size_t
max_line_len
,
BOOL
pad
)
str_list_t
strListReadFile
(
FILE
*
fp
,
str_list_t
*
l
p
,
size_t
max_line_len
,
BOOL
pad
)
{
char
*
buf
=
NULL
;
size_t
count
;
str_list_t
list
;
if
(
max_line_len
<
1
)
max_line_len
=
2048
;
if
(
l
ist
==
NULL
)
{
if
((
*
list
=
strListInit
())
==
NULL
)
if
(
l
p
==
NULL
)
{
if
((
list
=
strListInit
())
==
NULL
)
return
(
NULL
);
lp
=&
list
;
}
count
=
strListCount
(
*
l
ist
);
count
=
strListCount
(
*
l
p
);
while
(
!
feof
(
fp
))
{
if
(
buf
==
NULL
&&
(
buf
=
malloc
(
max_line_len
+
1
))
==
NULL
)
return
(
NULL
);
...
...
@@ -293,16 +344,16 @@ str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len, BOOL
if
(
fgets
(
buf
,
max_line_len
+
1
,
fp
)
==
NULL
)
break
;
if
(
pad
)
{
str_list_append
(
l
ist
,
buf
,
count
++
);
str_list_append
(
l
p
,
buf
,
count
++
);
buf
=
NULL
;
}
else
strListAppend
(
l
ist
,
buf
,
count
++
);
strListAppend
(
l
p
,
buf
,
count
++
);
}
if
(
buf
)
if
(
buf
!=
NULL
)
free
(
buf
);
return
(
*
l
ist
);
return
(
*
l
p
);
}
size_t
strListWriteFile
(
FILE
*
fp
,
const
str_list_t
list
,
const
char
*
separator
)
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/str_list.h
+
13
−
7
View file @
8e1e5c9c
...
...
@@ -45,7 +45,7 @@
extern
"C"
{
#endif
#define STR_LIST_
APPEND
(~0)
#define STR_LIST_
LAST_INDEX
(~0)
typedef
char
**
str_list_t
;
...
...
@@ -60,19 +60,25 @@ 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
strListAppend
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
char
*
strListAppend
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
/* Append a string list onto another string list */
s
tr_list
_t
strListAppendList
(
str_list_t
*
list
,
const
str_list_t
append_list
);
s
ize
_t
strListAppendList
(
str_list_t
*
list
,
const
str_list_t
append_list
);
/* Inserts a string into the list at a specific index */
str_list_t
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
char
*
strListInsert
(
str_list_t
*
list
,
const
char
*
str
,
size_t
index
);
/* Insert a string list into another string list */
s
tr_list
_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
append_list
,
size_t
index
);
s
ize
_t
strListInsertList
(
str_list_t
*
list
,
const
str_list_t
append_list
,
size_t
index
);
/* Remove a string at a specific index */
str_list_t
strListRemove
(
str_list_t
*
list
,
size_t
index
);
char
*
strListRemove
(
str_list_t
*
list
,
size_t
index
);
/* Remove and free a string at a specific index */
BOOL
strListDelete
(
str_list_t
*
list
,
size_t
index
);
/* Replace a string at a specific index */
char
*
strListReplace
(
const
str_list_t
list
,
size_t
index
,
const
char
*
str
);
/* Add to an exiting or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
...
...
@@ -82,7 +88,7 @@ str_list_t strListSplit(str_list_t* list, char* str, const char* delimit);
str_list_t
strListSplitCopy
(
str_list_t
*
list
,
const
char
*
str
,
const
char
*
delimit
);
/* Merge 2 string lists (no copying of string data) */
s
tr_list
_t
strListMerge
(
str_list_t
*
list
,
str_list_t
append_list
);
s
ize
_t
strListMerge
(
str_list_t
*
list
,
str_list_t
append_list
);
/* Count the number of strings in the list and returns the count */
size_t
strListCount
(
const
str_list_t
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