081e6815 |
1 | /* -*-c-*- |
2 | * |
f3a542e8 |
3 | * $Id: str.h,v 1.2 1999/05/26 20:52:57 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 $ |
f3a542e8 |
33 | * Revision 1.2 1999/05/26 20:52:57 mdw |
34 | * Add new `rest' argument for `str_split'. |
35 | * |
081e6815 |
36 | * Revision 1.1 1999/05/17 20:37:01 mdw |
37 | * Some trivial string hacks. |
38 | * |
39 | */ |
40 | |
41 | #ifndef STR_H |
42 | #define STR_H |
43 | |
44 | #ifdef __cplusplus |
45 | extern "C" { |
46 | #endif |
47 | |
48 | /*----- Header files ------------------------------------------------------*/ |
49 | |
50 | #include <stddef.h> |
51 | |
52 | /*----- Functions provided ------------------------------------------------*/ |
53 | |
54 | /* --- @str_getword@ --- * |
55 | * |
56 | * Arguments: @char **pp@ = address of pointer into string |
57 | * |
58 | * Returns: Pointer to the next space-separated word from the string, |
59 | * or null. |
60 | * |
61 | * Use: Parses off space-separated words from a string. |
62 | */ |
63 | |
64 | extern char *str_getword(char **/*pp*/); |
65 | |
66 | /* --- @str_split@ --- * |
67 | * |
68 | * Arguments: @char *p@ = pointer to string |
69 | * @char *v[]@ = pointer to array to fill in |
70 | * @size_t c@ = count of strings to fill in |
f3a542e8 |
71 | * @char **rest@ = where to store the remainder of the string |
081e6815 |
72 | * |
73 | * Returns: Number of strings filled in. |
74 | * |
75 | * Use: Fills an array with pointers to the individual words of a |
76 | * string. The string is modified in place to contain zero |
77 | * bytes at the word boundaries, and the words have leading |
78 | * and trailing space stripped off. No more than @c@ words |
79 | * are read; the actual number is returned as the value of the |
80 | * function. Unused slots in the array are populated with |
f3a542e8 |
81 | * null bytes. If there's any string left, the address of the |
82 | * remainder is stored in @rest@ (if it's non-null); otherwise |
83 | * @rest@ is set to a null pointer. |
081e6815 |
84 | */ |
85 | |
f3a542e8 |
86 | extern size_t str_split(char */*p*/, char */*v*/[], |
87 | size_t /*c*/, char **/*rest*/); |
081e6815 |
88 | |
89 | /* --- @str_sanitize@ --- * |
90 | * |
91 | * Arguments: @char *d@ = destination buffer |
92 | * @const char *p@ = pointer to source string |
93 | * @size_t sz@ = size of destination buffer |
94 | * |
95 | * Returns: --- |
96 | * |
97 | * Use: Writes a string into a buffer, being careful not to overflow |
98 | * the buffer, to null terminate the result, and to prevent |
99 | * nasty nonprintable characters ending up in the buffer. |
100 | */ |
101 | |
102 | extern void str_sanitize(char */*d*/, const char */*p*/, size_t /*sz*/); |
103 | |
104 | /*----- That's all, folks -------------------------------------------------*/ |
105 | |
106 | #ifdef __cplusplus |
107 | } |
108 | #endif |
109 | |
110 | #endif |