| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TX string to TX-string-list conversion and handling functions |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 24-07-2005 Initial version, split off from TXUTIL |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /*****************************************************************************/ |
|---|
| 43 | // Add string to string-list (allocate memory) |
|---|
| 44 | /*****************************************************************************/ |
|---|
| 45 | char *TxStrListAdd // RET added string |
|---|
| 46 | ( |
|---|
| 47 | TXSTRLIST **list, // IN address of list (head) |
|---|
| 48 | char *str // IN string to add |
|---|
| 49 | ) |
|---|
| 50 | { |
|---|
| 51 | char *rc = NULL; // function return |
|---|
| 52 | TXSTRLIST **elem = list; |
|---|
| 53 | |
|---|
| 54 | ENTER(); |
|---|
| 55 | |
|---|
| 56 | if (list && str) |
|---|
| 57 | { |
|---|
| 58 | while (*elem != NULL) // find end of list |
|---|
| 59 | { |
|---|
| 60 | *elem = (*elem)->next; |
|---|
| 61 | } |
|---|
| 62 | if ((*elem = TxAlloc( 1, sizeof(TXSTRLIST))) != NULL) |
|---|
| 63 | { |
|---|
| 64 | if ((rc = TxAlloc( 1, strlen( str) +1)) != NULL) |
|---|
| 65 | { |
|---|
| 66 | strcpy( rc, str); |
|---|
| 67 | (*elem)->string = rc; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | RETURN (rc); |
|---|
| 72 | } // end 'TxStrListAdd' |
|---|
| 73 | /*---------------------------------------------------------------------------*/ |
|---|
| 74 | |
|---|
| 75 | /*****************************************************************************/ |
|---|
| 76 | // Free string-list (free memory) |
|---|
| 77 | /*****************************************************************************/ |
|---|
| 78 | void TxStrListFree |
|---|
| 79 | ( |
|---|
| 80 | TXSTRLIST **list // IN address of list (head) |
|---|
| 81 | ) |
|---|
| 82 | { |
|---|
| 83 | TXSTRLIST **elem; |
|---|
| 84 | TXSTRLIST **next; |
|---|
| 85 | |
|---|
| 86 | ENTER(); |
|---|
| 87 | |
|---|
| 88 | for (elem = list; *elem; elem = next) |
|---|
| 89 | { |
|---|
| 90 | next = &(( *elem)->next); |
|---|
| 91 | TxFreeMem( *elem); |
|---|
| 92 | } |
|---|
| 93 | VRETURN(); |
|---|
| 94 | } // end 'TxStrListFree' |
|---|
| 95 | /*---------------------------------------------------------------------------*/ |
|---|