str_list.h 4.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* str_list.h */

/* Functions to deal with NULL-terminated string lists */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
 * Copyright 2004 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		*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU Lesser General Public License for more details: lgpl.txt or	*
 * http://www.fsf.org/copyleft/lesser.html									*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#ifndef _STR_LIST_H
#define _STR_LIST_H

#include "gen_defs.h"

#if defined(__cplusplus)
extern "C" {
#endif

47 48
typedef char** str_list_t;

49
/* Returns an allocated and terminated string list */
50
str_list_t	strListInit(void);
51 52

/* Frees the strings in the list (and the list itself) */
53
void		strListFree(str_list_t* list);
54

rswindell's avatar
rswindell committed
55 56 57
/* Frees the strings in the list */
void		strListFreeStrings(str_list_t list);

58
/* Pass a pointer to a string list, the string to add (append) */
59
/* Returns the updated list or NULL on error */
rswindell's avatar
rswindell committed
60
str_list_t	strListAdd(str_list_t* list, const char* str, size_t index);
61

62
/* Append a string list onto another string list */
63 64 65 66 67
str_list_t	strListAddList(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);

68
/* Insert a string list into another string list */
69
str_list_t	strListInsertList(str_list_t* list, const str_list_t append_list, size_t index);
70

71 72 73
/* Remove a string at a specific index */
str_list_t	strListRemove(str_list_t* list, size_t index);

74 75 76 77 78 79
/* Add to an exiting or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
str_list_t	strListSplit(str_list_t* list, char* str, const char* delimit);

/* Same as above, but copies str to temporary heap buffer first */
str_list_t	strListSplitCopy(str_list_t* list, const char* str, const char* delimit);
80

81 82 83
/* Merge 2 string lists (no copying of string data) */
str_list_t	strListMerge(str_list_t* list, str_list_t append_list);

84
/* Count the number of strings in the list and returns the count */
85
size_t		strListCount(const str_list_t list);
86

87
/* Sort the strings in the string list */
rswindell's avatar
rswindell committed
88 89
void		strListSortAlpha(str_list_t list);
void		strListSortAlphaReverse(str_list_t list);
90 91

/* Case-sensitive sorting */
rswindell's avatar
rswindell committed
92 93 94
void		strListSortAlphaCase(str_list_t list);
void		strListSortAlphaCaseReverse(str_list_t list);

95 96 97 98 99 100 101 102 103 104 105
/************/
/* 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);

106 107 108 109 110
#if defined(__cplusplus)
}
#endif

#endif	/* Don't add anything after this line */