081e6815 |
1 | /* -*-c-*- |
2 | * |
c6e0eaf0 |
3 | * $Id: str.h,v 1.3 1999/12/10 23:42:04 mdw Exp $ |
081e6815 |
4 | * |
5 | * Functions for hacking with strings |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of the mLib utilities library. |
13 | * |
14 | * mLib is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * mLib is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with mLib; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: str.h,v $ |
c6e0eaf0 |
33 | * Revision 1.3 1999/12/10 23:42:04 mdw |
34 | * Change header file guard names. |
35 | * |
f3a542e8 |
36 | * Revision 1.2 1999/05/26 20:52:57 mdw |
37 | * Add new `rest' argument for `str_split'. |
38 | * |
081e6815 |
39 | * Revision 1.1 1999/05/17 20:37:01 mdw |
40 | * Some trivial string hacks. |
41 | * |
42 | */ |
43 | |
c6e0eaf0 |
44 | #ifndef MLIB_STR_H |
45 | #define MLIB_STR_H |
081e6815 |
46 | |
47 | #ifdef __cplusplus |
48 | extern "C" { |
49 | #endif |
50 | |
51 | /*----- Header files ------------------------------------------------------*/ |
52 | |
53 | #include <stddef.h> |
54 | |
55 | /*----- Functions provided ------------------------------------------------*/ |
56 | |
57 | /* --- @str_getword@ --- * |
58 | * |
59 | * Arguments: @char **pp@ = address of pointer into string |
60 | * |
61 | * Returns: Pointer to the next space-separated word from the string, |
62 | * or null. |
63 | * |
64 | * Use: Parses off space-separated words from a string. |
65 | */ |
66 | |
67 | extern char *str_getword(char **/*pp*/); |
68 | |
69 | /* --- @str_split@ --- * |
70 | * |
71 | * Arguments: @char *p@ = pointer to string |
72 | * @char *v[]@ = pointer to array to fill in |
73 | * @size_t c@ = count of strings to fill in |
f3a542e8 |
74 | * @char **rest@ = where to store the remainder of the string |
081e6815 |
75 | * |
76 | * Returns: Number of strings filled in. |
77 | * |
78 | * Use: Fills an array with pointers to the individual words of a |
79 | * string. The string is modified in place to contain zero |
80 | * bytes at the word boundaries, and the words have leading |
81 | * and trailing space stripped off. No more than @c@ words |
82 | * are read; the actual number is returned as the value of the |
83 | * function. Unused slots in the array are populated with |
f3a542e8 |
84 | * null bytes. If there's any string left, the address of the |
85 | * remainder is stored in @rest@ (if it's non-null); otherwise |
86 | * @rest@ is set to a null pointer. |
081e6815 |
87 | */ |
88 | |
f3a542e8 |
89 | extern size_t str_split(char */*p*/, char */*v*/[], |
90 | size_t /*c*/, char **/*rest*/); |
081e6815 |
91 | |
92 | /* --- @str_sanitize@ --- * |
93 | * |
94 | * Arguments: @char *d@ = destination buffer |
95 | * @const char *p@ = pointer to source string |
96 | * @size_t sz@ = size of destination buffer |
97 | * |
98 | * Returns: --- |
99 | * |
100 | * Use: Writes a string into a buffer, being careful not to overflow |
101 | * the buffer, to null terminate the result, and to prevent |
102 | * nasty nonprintable characters ending up in the buffer. |
103 | */ |
104 | |
105 | extern void str_sanitize(char */*d*/, const char */*p*/, size_t /*sz*/); |
106 | |
107 | /*----- That's all, folks -------------------------------------------------*/ |
108 | |
109 | #ifdef __cplusplus |
110 | } |
111 | #endif |
112 | |
113 | #endif |