|
|
1.1 root 1: /* str_list.h */
2:
3: /* Functions to deal with NULL-terminated string lists */
4:
1.1.1.2 ! root 5: /* $Id: str_list.h,v 1.22 2009/08/14 10:02:22 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This library is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU Lesser General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU Lesser General Public License for more details: lgpl.txt or *
18: * http://www.fsf.org/copyleft/lesser.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #ifndef _STR_LIST_H
39: #define _STR_LIST_H
40:
41: #include <stdio.h> /* FILE */
42: #include <stddef.h> /* size_t */
43: #include "gen_defs.h"
44:
45: #if defined(__cplusplus)
46: extern "C" {
47: #endif
48:
49: #define STR_LIST_LAST_INDEX (~0)
50:
51: typedef char** str_list_t;
52:
53: /* Returns an allocated and terminated string list */
54: str_list_t strListInit(void);
55:
56: /* Frees the strings in the list (and the list itself) */
57: void strListFree(str_list_t*);
58:
59: /* Frees the strings in the list */
60: void strListFreeStrings(str_list_t);
61:
62: /* Pass a pointer to a string list, the string to add (append) */
63: /* Returns the updated list or NULL on error */
64: char* strListAppend(str_list_t*, const char* str, size_t index);
65:
66: /* Append a string list onto another string list */
67: size_t strListAppendList(str_list_t*, const str_list_t append_list);
68:
69: /* Inserts a string into the list at a specific index */
70: char* strListInsert(str_list_t*, const char* str, size_t index);
71:
72: /* Insert a string list into another string list */
73: size_t strListInsertList(str_list_t*, const str_list_t append_list, size_t index);
74:
75: /* Remove a string at a specific index */
76: char* strListRemove(str_list_t*, size_t index);
77:
78: /* Remove and free a string at a specific index */
79: BOOL strListDelete(str_list_t*, size_t index);
80:
81: /* Replace a string at a specific index */
82: char* strListReplace(const str_list_t, size_t index, const char* str);
83:
84: /* Swap the strings at index1 and index2 */
85: BOOL strListSwap(const str_list_t, size_t index1, size_t index2);
86:
87: /* Convenience macros for pushing, popping strings (LIFO stack) */
88: #define strListPush(list, str) strListAppend(list, str, STR_LIST_LAST_INDEX)
89: #define strListPop(list) strListRemove(list, STR_LIST_LAST_INDEX)
90:
91: /* Add to an exiting or new string list by splitting specified string (str) */
92: /* into multiple strings, separated by one of the delimit characters */
93: str_list_t strListSplit(str_list_t*, char* str, const char* delimit);
94:
95: /* Same as above, but copies str to temporary heap buffer first */
96: str_list_t strListSplitCopy(str_list_t*, const char* str, const char* delimit);
97:
98: /* Merge 2 string lists (no copying of string data) */
99: size_t strListMerge(str_list_t*, str_list_t append_list);
100:
1.1.1.2 ! root 101: /* Create a single delimited string from the specified list */
! 102: /* If buf is NULL, the buf is malloc'd and should be freed using strListFreeBlock() */
! 103: /* Note: maxlen includes '\0' terminator */
! 104: char* strListCombine(str_list_t, char* buf, size_t maxlen, const char* delimit);
! 105:
1.1 root 106: /* Count the number of strings in the list and returns the count */
107: size_t strListCount(const str_list_t);
108:
1.1.1.2 ! root 109: /* Returns the index of the specified str (by ptr compare) or -1 if not found */
! 110: int strListIndexOf(const str_list_t, const char* str);
! 111:
1.1 root 112: /* Sort the strings in the string list */
113: void strListSortAlpha(str_list_t);
114: void strListSortAlphaReverse(str_list_t);
115:
116: /* Case-sensitive sorting */
117: void strListSortAlphaCase(str_list_t);
118: void strListSortAlphaCaseReverse(str_list_t);
119:
120: /* Create/Copy/Append/Free NULL-terminated string block */
121: /* (e.g. for environment variable blocks) */
122: char* strListCreateBlock(str_list_t);
123: char* strListCopyBlock(char* block);
124: char* strListAppendBlock(char* block, str_list_t);
125: size_t strListBlockLength(char* block);
126: void strListFreeBlock(char*);
127:
128: /************/
129: /* File I/O */
130: /************/
131:
132: /* Read lines from file appending each line to string list */
133: /* Pass NULL list to have list allocated for you */
134: str_list_t strListReadFile(FILE*, str_list_t*, size_t max_line_len);
135: size_t strListInsertFile(FILE*, str_list_t*, size_t index, size_t max_line_len);
136:
137: /* Write to file (fp) each string in the list, optionally separated by separator (e.g. "\n") */
138: size_t strListWriteFile(FILE*, const str_list_t, const char* separator);
139:
140: #if defined(__cplusplus)
141: }
142: #endif
143:
144: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.