This is dstring.h in view mode; [Download] [Up]
/* dstring v1.0.0 Dynamic string library
* Copyright (c) 1994 Bill Bereza
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* To reach the author
*
* email:
* berezaw@river.it.gvsu.edu ac368@leo.nmc.edu
*
* $Log: dstring.h,v $
* Revision 1.16 94/12/13 21:52:05 berezaw
* change DCHAR to plain 'char'
*
* Revision 1.15 94/12/08 10:41:52 berezaw
* daddchar() now returns DCHAR with 0 on error
*
* Revision 1.14 94/12/03 00:09:50 berezaw
* changed all uses of (char) to (DCHAR)
*
* Revision 1.13 94/12/02 13:55:25 berezaw
* change DCHAR to char
*
* Revision 1.12 94/12/02 11:50:35 berezaw
* added DCHAR #definitions
*
* Revision 1.11 94/12/02 11:34:28 berezaw
* changed datatype of _dchar to int
*
* Revision 1.10 94/11/28 12:04:04 berezaw
* *** empty log message ***
*
*
* @(#)dstring.h 1.9 (Bill Bereza) 11/15/94
* $Header: /Users/berezaw/src/dynstr/RCS/dstring.h,v 1.16 94/12/13 21:52:05 berezaw Exp $
*/
#ifndef DSTRING_H
#define DSTRING_H
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#define DCHAR char
struct _dchar { /* You shouldn't do ANYTHING with these structures!
* Future versions of the library may use different
* structures or no structures at all.
*/
DCHAR _character;
struct _dchar *_next;
};
struct _dstring {
struct _dchar *_first;
struct _dchar *_last;
size_t _length; /* The _length value should not be
* relied on too much. It is not possible
* to change this value and expect the library
* to only work on that many characters.
* Most functions only check for a NULL _next
* value as an end of string signifier.
*
* The _length value should be accurate as to the
* real length of the string, but it has no control
* over how the functions will work
*
* I may change the functions later to rely
* on the value of _length rather than on an
* ending NULL pointer. This would make tokenizing
* a little safer if the _length controlled
* functions like freechars()
*/
};
#define DSTRING struct _dstring
extern DSTRING *initdstr(void);
/* initdstr will allocate space for the dstring structure
* and set all the values in the structure to zero or null
*
* returns pointer to DSTRING if successful, else returns NULL
*/
extern void freedchars(DSTRING *oldstring);
/* freechars frees all the characters in the dstring
* and resets the length to zero
*
* the argument must be a previously initialized dstring
*
* no return value
*/
extern void freedstr(DSTRING *oldstring);
/* freedstr will free all space used by the dstring struct
* including the list of characters
*
* the argument should be a dstring struct that has already been allocated
*
* freedstr has no return value
*/
extern DCHAR daddchar(DSTRING *oldstring, DCHAR addchar);
/* daddchar will add one character to the dstring struct
*
* dstring must already be initialized with initdstr first
*
* daddchar returns 0 if it couldn't add a char
* and returns the char added if successful
*/
extern size_t dstrlen(DSTRING *oldstring);
/* #define dstrlen(ostr) ((ostr)->_length) */
/* dstrlen returns the number of characters in the DSTRING
*
* the dstring must already be initialized
*/
extern DCHAR *arrdstr(DSTRING *oldstring);
/* arrdstr will allocate space for a character array and
* copy all characters from DSTRING into the array
*
* the chracter pointer can be void or an unitialized pointer
* DSTRING must be previously initialized
*
* returns a pointer to the character array
*/
extern DSTRING *dstrarr(DCHAR *oldchar_array);
/* dstrarr converts a character array into a dynamic string
*
* DSTRING should be an unitialized pointer and char should be a character array
* delimited by '\0'
*
* returns a pointer to DSTRING, or NULL on error
*/
extern DSTRING *dstrarrcat(DSTRING *oldstring, DCHAR *oldchar_array);
/* dstrarrcat appends the char array onto the end of dstring
*
* DSTRING must be an initialized dstring, and char must be character array
* delimited by '\0'
*
* returns a pointer to the DSTRING, NULL on failure
*/
extern DSTRING *dstrcat(DSTRING *old_to, DSTRING *old_from);
/* dstrcat appends the chars from the second dstring onto the end
* of the first dstring
*
* both arguments must be previously initialized dstrings
*
* returns NULL on error, else returns pointer to the first string
*/
extern DSTRING *dstrcpy(DSTRING *old_from);
/* dstrcpy copies the elements from the second dstring and creates another dstring
* pointed to by the first dstring pointer
*
* the second dstring must be previously initialized
*
* returns NULL on error, else returns a pointer to the new dstring
*/
extern DCHAR *arrdstrfromhead(DSTRING *oldstring, size_t number_of);
/* arrdstrfromhead returns a pointer to a character array of size_t elements
* the elements in the array are the first size_t characters of dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DCHAR *arrdstrfromtail(DSTRING *oldstring, size_t number_of);
/* arrdstrfromtail returns a pointer to a character array of size_t elements
* the elements in the array are the last size_t characters of dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DCHAR *arrdstrrmfromhead(DSTRING *oldstring, size_t number_of);
/* arrdstrfromhead returns a pointer to a character array of size_t elements
* the elements in the array are the first size_t characters of dstring
* the elements return have been removed from the dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DCHAR *arrdstrrmfromtail(DSTRING *oldstring, size_t number_of);
/* arrdstrfromtail returns a pointer to a character array of size_t elements
* the elements in the array are the last size_t characters of dstring
* the elements return have been removed from the dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DSTRING *dstrfromhead(DSTRING *oldstring, size_t number_of);
/* dstrfromhead returns a pointer to a dstring of size_t elements
* the elements in the string are the first size_t characters of dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DSTRING *dstrfromtail(DSTRING *oldstring, size_t number_of);
/* dstrfromtail returns a pointer to a dstring of size_t elements
* the elements in the dstring are the last size_t characters of dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DSTRING *dstrrmfromhead(DSTRING *oldstring, size_t number_of);
/* dstrfromhead returns a pointer to a dstring of size_t elements
* the elements in the dstring are the first size_t characters of dstring
* the elements return have been removed from the dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern DSTRING *dstrrmfromtail(DSTRING *oldstring, size_t number_of);
/* dstrfromtail returns a pointer to a dstring of size_t elements
* the elements in the dstring are the last size_t characters of dstring
* the elements return have been removed from the dstring
*
* dstring must be previously initialized, size_t must be a number >= 1
*
* returns a NULL on error, if size_t is greater than the length of dstring
* then a character array of all elements is returned
*/
extern signed long int dstrcmp(DSTRING *ds1, DSTRING *ds2);
/* dstrcmp compares ds1 to ds2 and returns a value
* that depends on which is larger
*
* both dstrings must be previously initialized
*
* if both strings are empty it returns a 0, if one is empty it returns
* a positive value which is that of the first character in the non-empty
* string.
*
* if both strings have characters then it looks for the first non-matching
* character. if all chars match or one string runs out before a non-match
* is found, it will return 0
*
* if a non-match is found, then the function will return the value of
* the first character minus the value of the second character,
* so if the first string is greater it should return a positive value
* else a negative value
*/
extern signed long int dstrncmp(DSTRING *ds1, DSTRING *ds2, size_t n);
/* dstrncmp works just like dstrcmp except it will only check at most n chars
*
* See Also: dstrcmp()
*/
extern signed long int dstrarrcmp(DSTRING *ds1, DCHAR *ds2);
/* dstrarrcmp works just like dstrcmp except that the second string is a
* regular array
*
* See Also: dstrcmp()
*/
extern signed long int dstrarrncmp(DSTRING *ds1, DCHAR *ds2, size_t n);
/* dstrarrncmp works just like dstrarrcmp except that it only checks at most n
* characters
*
* See Also: dstrarrcmp(), dstrcmp()
*/
extern DSTRING *dstrchr(DSTRING *dstr, DCHAR ch);
/* dstrchr returns a pointer beginning at the first occurence of ch in dstr
*
* Note: The pointer returned is only a pointer to a DSTRING structure.
* The character in the returned dstring are the same data as in
* original dstr. You must NOT use freedstr() on the returned pointer.
*
* dstr must be a previously initialized dstring
* the pointer returned points to the same data as in dstr,
* and must be free'd using only a normal free()
*
* returns a NULL on error
*/
extern DSTRING *dstrrchr(DSTRING *dstr, DCHAR ch);
/* dstrrchr returns a dstring pointer beginning at the last occurence of ch
* in the dstring.
*
* returns NULL on error
*
* See Also: dstrchr()
*/
extern size_t dstrarrspn(DSTRING *dstr, DCHAR *chlist);
/* dstrarrspn returns length of prefix of dstr
* consisting of characters in chlist
*/
extern size_t dstrarrcspn(DSTRING *dstr, DCHAR *chlist);
/* dstrarrcspan returns length of prefix of dstr
* consisting of characters NOT in chlist
*/
extern size_t dstrspn(DSTRING *dstr, DSTRING *chlist);
/* dstrspn returns length of prefix of dstr
* consisting of characters in chlist
*/
extern size_t dstrcspn(DSTRING *dstr, DSTRING *chlist);
/* dstrcspn returns length of prefix of dstr
* consisting of characters NOT in chlist
*/
extern DSTRING *dstrpbrk(DSTRING *dstr, DSTRING *ch);
/* dstrpbrk returns a DSTRING pointer to the first
* occurence in dstring dstr of any character
* in ch, or NULL if none are present
*
* If the pointer is not null, then the value must
* be free'd using only free()
*
* See Also: dstrchr()
*/
extern DSTRING *dstrarrpbrk(DSTRING *dstr, DCHAR *ch);
/* dstrarrbrk returns a dstring pointer to the first
* occurence in dstring dstr of any character in
* ch, or NULL if none are present
*
* If the pointer is not null, then the value must
* be free'd using only free()
*
* See Also: dstrchr()
*/
extern DSTRING *dstrstr(DSTRING *dstr, DSTRING *cs);
/* dstrstr returns a DSTRING pointer to the first
* occurence in dstring dstr of dstring ch
* or NULL if none are present
*
* If the pointer is not null, then the value must
* be free'd using only free()
*
* See Also: dstrchr()
*/
extern DSTRING *dstrarrstr(DSTRING *dstr, DCHAR *cs);
/* dstrarrstr returns a DSTRING pointer to the first
* occurence in dstring dstr of string cs
* or NULL if none are present
*
* If the pointer is not null, then the value must
* be free'd using only free()
*
* See Also: dstrchr()
*/
#define dstrerror(n) dstrarr(strerror((n)))
/* dstrerror returns a dstring pointer to implementation-defined
* error string corresponding to n
*/
#endif /* DSTRING_H */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.