Annotation of sbbs/src/xpdev/str_list.h, revision 1.1.1.1

1.1       root        1: /* str_list.h */
                      2: 
                      3: /* Functions to deal with NULL-terminated string lists */
                      4: 
                      5: /* $Id: str_list.h,v 1.20 2005/10/12 22:46:36 rswindell Exp $ */
                      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:  *                                                                                                                                                     *
                     11:  * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html         *
                     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: 
                    101: /* Count the number of strings in the list and returns the count */
                    102: size_t         strListCount(const str_list_t);
                    103: 
                    104: /* Sort the strings in the string list */
                    105: void           strListSortAlpha(str_list_t);
                    106: void           strListSortAlphaReverse(str_list_t);
                    107: 
                    108: /* Case-sensitive sorting */
                    109: void           strListSortAlphaCase(str_list_t);
                    110: void           strListSortAlphaCaseReverse(str_list_t);
                    111: 
                    112: /* Create/Copy/Append/Free NULL-terminated string block */
                    113: /* (e.g. for environment variable blocks) */
                    114: char*          strListCreateBlock(str_list_t);
                    115: char*          strListCopyBlock(char* block);
                    116: char*          strListAppendBlock(char* block, str_list_t);
                    117: size_t         strListBlockLength(char* block);
                    118: void           strListFreeBlock(char*);
                    119: 
                    120: /************/
                    121: /* File I/O */
                    122: /************/
                    123: 
                    124: /* Read lines from file appending each line to string list */
                    125: /* Pass NULL list to have list allocated for you */
                    126: str_list_t     strListReadFile(FILE*, str_list_t*, size_t max_line_len);
                    127: size_t         strListInsertFile(FILE*, str_list_t*, size_t index, size_t max_line_len);
                    128: 
                    129: /* Write to file (fp) each string in the list, optionally separated by separator (e.g. "\n") */
                    130: size_t         strListWriteFile(FILE*, const str_list_t, const char* separator);
                    131: 
                    132: #if defined(__cplusplus)
                    133: }
                    134: #endif
                    135: 
                    136: #endif /* Don't add anything after this line */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.