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
909f6f27
Commit
909f6f27
authored
20 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created strListReadFile() and strListWriteFile() functions to read and write
string lists to/from files.
parent
b5efbcbe
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
+54
-8
54 additions, 8 deletions
src/xpdev/str_list.c
src/xpdev/str_list.h
+11
-0
11 additions, 0 deletions
src/xpdev/str_list.h
with
65 additions
and
8 deletions
src/xpdev/str_list.c
+
54
−
8
View file @
909f6f27
...
...
@@ -58,7 +58,7 @@ size_t strListCount(const str_list_t list)
if
(
list
==
NULL
)
return
(
0
);
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
;
return
(
i
);
...
...
@@ -141,11 +141,12 @@ str_list_t strListAdd(str_list_t* list, const char* str)
str_list_t
strListAddList
(
str_list_t
*
list
,
const
str_list_t
add_list
)
{
size_t
i
,
j
;
size_t
i
;
size_t
count
;
j
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
]
;
i
++
)
strListAddAt
(
list
,
add_list
[
i
],
j
++
);
count
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
strListAddAt
(
list
,
add_list
[
i
],
count
++
);
return
(
*
list
);
}
...
...
@@ -166,7 +167,7 @@ str_list_t strListInsertList(str_list_t* list, const str_list_t add_list, size_t
{
size_t
i
;
for
(
i
=
0
;
add_list
[
i
]
;
i
++
)
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
strListInsert
(
list
,
add_list
[
i
],
index
++
);
return
(
*
list
);
...
...
@@ -208,7 +209,7 @@ str_list_t strListMerge(str_list_t* list, str_list_t add_list)
size_t
i
,
j
;
j
=
strListCount
(
*
list
);
for
(
i
=
0
;
add_list
[
i
]
;
i
++
)
for
(
i
=
0
;
add_list
[
i
]
!=
NULL
;
i
++
)
str_list_append
(
list
,
add_list
[
i
],
j
++
);
return
(
*
list
);
...
...
@@ -259,7 +260,7 @@ void strListFreeStrings(str_list_t list)
size_t
i
;
if
(
list
!=
NULL
)
{
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
free
(
list
[
i
]);
list
[
0
]
=
NULL
;
/* terminate */
}
...
...
@@ -272,3 +273,48 @@ void strListFree(str_list_t* list)
free
(
*
list
);
}
}
str_list_t
strListReadFile
(
FILE
*
fp
,
str_list_t
*
list
,
size_t
max_line_len
)
{
char
*
buf
;
size_t
count
;
if
(
max_line_len
<
1
)
max_line_len
=
2048
;
if
(
list
==
NULL
)
{
if
((
*
list
=
strListInit
())
==
NULL
)
return
(
NULL
);
}
if
((
buf
=
malloc
(
max_line_len
+
1
))
==
NULL
)
return
(
NULL
);
count
=
strListCount
(
*
list
);
while
(
!
feof
(
fp
))
{
if
(
fgets
(
buf
,
max_line_len
+
1
,
fp
)
==
NULL
)
break
;
strListAddAt
(
list
,
buf
,
count
++
);
}
free
(
buf
);
return
(
*
list
);
}
size_t
strListWriteFile
(
FILE
*
fp
,
const
str_list_t
list
,
const
char
*
separator
)
{
size_t
i
;
if
(
list
==
NULL
)
return
(
0
);
for
(
i
=
0
;
list
[
i
]
!=
NULL
;
i
++
)
{
if
(
fputs
(
list
[
i
],
fp
)
==
EOF
)
break
;
if
(
seperator
!=
NULL
&&
fputs
(
seperator
,
fp
)
==
EOF
)
break
;
}
return
(
i
);
}
This diff is collapsed.
Click to expand it.
src/xpdev/str_list.h
+
11
−
0
View file @
909f6f27
...
...
@@ -95,6 +95,17 @@ void strListSortAlphaReverse(str_list_t list);
void
strListSortAlphaCase
(
str_list_t
list
);
void
strListSortAlphaCaseReverse
(
str_list_t
list
);
/************/
/* File I/O */
/************/
/* Read lines from file appending each line to string list */
/* Pass NULL list to have list allocated for you */
str_list_t
strListReadFile
(
FILE
*
fp
,
str_list_t
*
list
,
size_t
max_line_len
);
/* Write to file (fp) each string in the list, optionally separated by separator (e.g. "\n") */
size_t
strListWriteFile
(
FILE
*
fp
,
const
str_list_t
list
,
const
char
*
separator
);
#if defined(__cplusplus)
}
#endif
...
...
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