annotate util.c @ 34:9426f9eaf3d7 noffle

[svn] Change output of "noffle -a all" to standard mailbox format.
author enz
date Mon, 01 May 2000 10:23:31 +0100
parents 526a4c34ee2e
children 8e972daaeab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
2 util.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
4 $Id: util.c 32 2000-04-29 14:45:56Z enz $
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8 #include <errno.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <ctype.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <fnmatch.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include <sys/types.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include <sys/stat.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include <fcntl.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include <time.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include <unistd.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16 #include "config.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
17 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
18
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
19 static const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 nextWhiteSpace( const char *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 while ( *p && ! isspace( *p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 return p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
25 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27 static const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 nextNonWhiteSpace( const char *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
30 while ( *p && isspace( *p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32 return p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35 const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 Utl_restOfLn( const char *line, unsigned int token )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38 unsigned int i;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 const char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41 p = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42 for ( i = 0; i < token; ++i )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44 p = nextNonWhiteSpace( p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 p = nextWhiteSpace( p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
46 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47 p = nextNonWhiteSpace( p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 return p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51 const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52 Utl_getLn( Str result, const char *pos )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 int len = 0;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 const char *p = pos;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 if ( ! p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 while ( *p != '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 if ( *p == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63 if ( len > 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 Log_err( "Line not terminated by newline: '%s'", pos );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 *(result++) = *(p++);
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 ++len;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69 if ( len >= MAXCHAR - 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 *result = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 Log_err( "Utl_getLn: line too long: %s", result );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73 return ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 *result = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77 return ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 const char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82 Utl_ungetLn( const char *str, const char *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 if ( str == p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 --p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87 if ( *p != '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89 Log_dbg( "Utl_ungetLn: not at beginning of line" );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 return NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 --p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93 while ( TRUE )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 if ( p == str )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 return p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 if ( *p == '\n' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98 return p + 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 --p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
103 const char *
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
104 Utl_getHeaderLn( Str result, const char *p )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
105 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
106 const char * res = Utl_getLn( result, p );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
107
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
108 /* Look for followon line if this isn't a blank line. */
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
109 if ( res != NULL && !isspace( result[ 0 ] ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
110 while ( res != NULL && res[ 0 ] != '\n' && isspace( res[ 0 ] ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
111 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
112 Str nextLine;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
113 const char *here;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
114 char *next;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
115
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
116 here = res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
117 res = Utl_getLn( nextLine, res );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
118 next = Utl_stripWhiteSpace( nextLine );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
119
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
120 if ( next[ 0 ] != '\0' )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
121 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
122 Utl_catStr( result, " " );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
123 Utl_catStr( result, next );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
124 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
125 else
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
126 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
127 res = here;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
128 break;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
129 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
130 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
131
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
132 return res;
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
133 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
134
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
135 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
136 Utl_toLower( Str line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
137 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
138 char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
139
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
140 p = line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
141 while ( *p )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
142 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
143 *p = tolower( *p );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
144 ++p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
145 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
146 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
147
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
148 char *
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
149 Utl_stripWhiteSpace( char *line )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
150 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
151 char *p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
152
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
153 while ( isspace( *line ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
154 ++line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
155 p = line + strlen( line ) - 1;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
156 while ( isspace( *p ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
157 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
158 *p = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
159 --p;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
160 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
161 return line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
162 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
163
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
164 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
165 Utl_cpyStr( Str dst, const char *src )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
166 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
167 dst[ 0 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
168 strncat( dst, src, MAXCHAR );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
169 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
170
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
171 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
172 Utl_cpyStrN( Str dst, const char *src, size_t n )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
173 {
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
174 if ( n > MAXCHAR )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
175 n = MAXCHAR;
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
176 dst[ 0 ] = '\0';
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
177 strncat( dst, src, n );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
178 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
179
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
180 void
26
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
181 Utl_catStr( Str dst, const char *src )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
182 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
183 strncat( dst, src, MAXCHAR - strlen( dst ) );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
184 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
185
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
186 void
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
187 Utl_catStrN( Str dst, const char *src, size_t n )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
188 {
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
189 if ( n > MAXCHAR - strlen( dst ) )
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
190 n = MAXCHAR - strlen( dst );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
191 strncat( dst, src, n );
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
192 }
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
193
526a4c34ee2e [svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents: 0
diff changeset
194 void
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
195 Utl_stamp( Str file )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
196 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
197 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
198 time_t t;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
199
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
200 time( &t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
201 if ( ! ( f = fopen( file, "w" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
202 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
203 Log_err( "Could not open %s for writing (%s)",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
204 file, strerror( errno ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
205 return;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
206 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
207 fprintf( f, "%lu\n", t );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
208 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
209 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
210
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
211 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
212 Utl_getStamp( time_t *result, Str file )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
213 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
214 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
215
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
216 if ( ! ( f = fopen( file, "r" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
217 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
218 if ( fscanf( f, "%lu", result ) != 1 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
219 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
220 Log_err( "File %s corrupted", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
221 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
222 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
223 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
224 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
225 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
226 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
227
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
228 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
229 Utl_allocAndCpy( char **dst, const char *src )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
230 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
231 int len = strlen( src );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
232 if ( ! ( *dst = (char *)malloc( len + 1 ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
233 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
234 Log_err( "Cannot allocate string with length %lu", strlen( src ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
235 exit( EXIT_FAILURE );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
236 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
237 memcpy( *dst, src, len + 1 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
238 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
239
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
240 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
241 Utl_matchPattern( const char *text, const char *pattern )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
242 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
243 if ( pattern[ 0 ] == '*' && pattern[ 1 ] == '\0' )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
244 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
245 return ( fnmatch( pattern, text, 0 ) == 0 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
246 }