1 /* $Id: str.h,v 1.6 2003/07/29 22:35:18 mastermind Exp $ */
2 
3 /*
4  * Copyright (c) 1998-2003, Alexander Marx
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *    - Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *    - Redistributions in binary form must reproduce the above
14  *      copyright notice, this list of conditions and the following
15  *      disclaimer in the documentation and/or other materials provided
16  *      with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  *
32  */
33 
34 #ifndef __easy_eSTR_H
35 #define __easy_eSTR_H 1
36 
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <stdarg.h>
41 #include <string.h>
42 #include <ctype.h>
43 
44 
45 /* ------------------------------------------------------------------------ */
46 
47 #define BOOL		short
48 #define TRUE		1
49 #define FALSE		0
50 
51 #define BSET(_f, _m)	((_f)|=(_m))
52 #define BTST(_f, _m)	(((_f)&(_m))==(_m))
53 #define BCLR(_f, _m)	((_f)&=(~(_m)))
54 #define BCHG(_f, _m)	((_f)^=(_m))
55 
56 #define BnTST(_f, _m) 	((((_f)&(_m))^(_m))==(_m))
57 
58 #define	eSTR_BLOCK_SIZE	512
59 
60 #define	eSTR_HEAD	1
61 #define	eSTR_TAIL	2
62 #define	eSTR_FWD	3
63 #define	eSTR_BWD	4
64 
65 #define	eSTR_LEAD	1
66 #define	eSTR_TRAIL	2
67 #define	eSTR_BODY	4
68 #define	eSTR_BOTH	(eSTR_LEAD|eSTR_TRAIL)
69 #define	eSTR_ALL	(eSTR_BOTH|eSTR_BODY)
70 
71 #define eSTR_END	(NULL)
72 
73 
74 /* ------------------------------------------------------------------------ */
75 
76 typedef struct {
77 	char *str;
78 	long idx, len;
79 } eSTR;
80 
81 
82 /* --- Public Functions --------------------------------------------------- */
83 
84 eSTR *newSTR(const char *s);
85 eSTR *va_newSTR(const char *s, ...);
86 eSTR *clrSTR(eSTR *str);
87 eSTR *cpySTR(eSTR *dest_str, const eSTR *src_str);
88 eSTR *dupSTR(const eSTR *src_str);
89 eSTR *setSTR(eSTR *str, const char *s);
90 eSTR *spcSTR(unsigned long len);
91 void freeSTR(eSTR *str);
92 
93 int putSTR(const eSTR *str, FILE *fh);
94 int putsSTR(const eSTR *str, FILE *fh);
95 eSTR *getSTR(FILE *fh);
96 eSTR *getlineSTR(FILE *fh);
97 
98 char *strSTR(const eSTR *str);
99 long lenSTR(const eSTR *str);
100 
101 char traverseSTR(eSTR *str, int move_to);
102 char *adrSTR(const eSTR *str);
103 long idxSTR(const eSTR *str);
104 char chrSTR(eSTR *str);
105 
106 eSTR *upperSTR(eSTR *str);
107 eSTR *lowerSTR(eSTR *str);
108 eSTR *reverseSTR(eSTR *str);
109 eSTR *stripSTR(eSTR *str, int where, const char *s);
110 
111 char *tokSTR(eSTR *str, const char *s);
112 
113 eSTR *catSTR(eSTR *dest_str, const char *s);
114 eSTR *va_catSTR(eSTR *dest_str, ...);
115 eSTR *catSTRs(eSTR *dest_str, const eSTR *src_str);
116 
117 eSTR *leftSTR(const eSTR *str, long idx);
118 eSTR *rightSTR(const eSTR *str, long idx);
119 eSTR *midSTR(const eSTR *str, long idx, long len);
120 
121 long subsSTR(const eSTR *haystack, const char *needle);
122 long subcSTR(const eSTR *haystack, char needly);
123 BOOL verifySTR(const eSTR *str, const char *s);
124 
125 int cmpSTR(const eSTR *str, const char *s);
126 int cmpSTRs(const eSTR *s1, const eSTR *s2);
127 
128 
129 /* new4cydump */
130 
131 eSTR *infileSTR(const char *file);
132 int outfileSTR(const eSTR *str, const char *file);
133 int tounixSTR(eSTR *str);
134 
135 
136 /* --- Private Functions -------------------------------------------------- */
137 
138 #ifdef __easy_eSTR_C
139 
140 static int copy(eSTR *dest_str, const eSTR *src_str);
141 static void destroy(eSTR *str);
142 static void init(eSTR *str);
143 
144 #endif
145 
146 
147 /* ------------------------------------------------------------------------ */
148 
149 #endif /* eSTR_H */
150