~ubuntu-branches/ubuntu/gutsy/upstart/gutsy

« back to all changes in this revision

Viewing changes to debian/patches/00-libnih-update.patch

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2007-03-11 19:19:00 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070311191900-y59f23fd1c6t493g
Tags: 0.3.8-1
* New upstream release:
  - much improved initctl tool.

* Update my standard prep_/undo_/rm_conffile functions to take into account
  current dpkg behaviour wrt obsolete conffiles.  The conffile is now moved
  out of the way in preinst and the moved file deleted in postinst, or moved
  back in postrm abort-upgrade.  This means it's not there when dpkg
  configures the new version, so the conffile is not left in the list.
* Purge backups of modified obsolete conffiles when the package is purged.

* Update runlevel and respawn rule generated in migrate-inittab.pl
  LP: #89314

* Drop 00-libnih-update.patch and 01-libnih-sparc-ftbfs.patch; new upstream
  release includes an up-to-date libnih which contains both patches.
* Drop 10-cant-stop-execless-job.patch; included upstream.
* Drop 20-complex-event-config.patch; this is going to be significantly
  changed upstream, and we don't want to ship something strange.
* Drop 30-fix-warnings.patch; included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
=== modified file 'ChangeLog.nih'
2
 
--- ChangeLog.nih       2007-02-09 17:30:41 +0000
3
 
+++ ChangeLog.nih       2007-02-11 17:01:06 +0000
4
 
@@ -1,3 +1,37 @@
5
 
+2007-02-11  Johan Kiviniemi  <johan@kiviniemi.name>
6
 
+
7
 
+       * nih/hash.h (NIH_HASH_FOREACH, NIH_HASH_FOREACH_SAFE): Added missing
8
 
+       parenthesis around hash, in case it's a complicated expression with
9
 
+       unsurprising precedence results.
10
 
+
11
 
+2007-02-11  Scott James Remnant  <scott@netsplit.com>
12
 
+
13
 
+       * nih/config.c (nih_config_skip_whitespace): It turns out that when
14
 
+       parsing, it's often useful to skip any whitespace while retaining the
15
 
+       "step over newlines" behaviour.  Seperate it out into its own 
16
 
+       function.
17
 
+       (nih_config_next_token): Call the new function.
18
 
+       * nih/config.h: Add prototype.
19
 
+       * nih/tests/test_config.c (test_skip_whitespace): Check the function
20
 
+
21
 
+       * nih/config.c: Remove macro definitions
22
 
+       * nih/config.h: and make them public instead
23
 
+       * nih/tests/test_config.c: Use macros.
24
 
+
25
 
+       * nih/config.c (nih_config_next_token): Strange hybrid function,
26
 
+       it behaves like next_arg() but accepts the same arguments as token();
27
 
+       it skips whitespace, but only if the initial whitespace character is
28
 
+       in the delim argument.
29
 
+       (nih_config_next_arg): This becomes a wrapper around next_token.
30
 
+       * nih/config.h: Add prototype.
31
 
+       * nih/tests/test_config.c (test_next_token): Check the new function.
32
 
+
33
 
+       * nih/config.c (nih_config_next_token): Rename to nih_config_token,
34
 
+       since this doesn't behave like the next_arg() function, and we want
35
 
+       a similar token function that behaves like that.
36
 
+       * nih/config.h: Update.
37
 
+       * nih/tests/test_config.c (test_next_token): Rename and update.
38
 
+
39
 
 2007-02-09  Scott James Remnant  <scott@netsplit.com>
40
 
 
41
 
        * nih/hash.h (NIH_HASH_FOREACH_SAFE): Oops, s/list/hash/
42
 
 
43
 
=== modified file 'nih/config.c'
44
 
--- nih/config.c        2007-02-06 12:44:12 +0000
45
 
+++ nih/config.c        2007-02-11 16:28:57 +0000
46
 
@@ -39,30 +39,6 @@
47
 
 #include <nih/errors.h>
48
 
 
49
 
 
50
 
-/**
51
 
- * WS:
52
 
- *
53
 
- * Definition of what characters we consider whitespace.
54
 
- **/
55
 
-#define WS " \t\r"
56
 
-
57
 
-/**
58
 
- * CNL:
59
 
- *
60
 
- * Definition of what characters nominally end a line; a comment start
61
 
- * character or a newline.
62
 
- **/
63
 
-#define CNL "#\n"
64
 
-
65
 
-/**
66
 
- * CNLWS:
67
 
- *
68
 
- * Defintion of what characters nominally separate tokens.
69
 
- **/
70
 
-#define CNLWS " \t\r#\n"
71
 
-
72
 
-
73
 
-
74
 
 /* Prototypes for static functions */
75
 
 static ssize_t          nih_config_block_end  (const char *file, size_t len,
76
 
                                               size_t *lineno, size_t *pos,
77
 
@@ -107,7 +83,7 @@
78
 
        nih_assert (file != NULL);
79
 
 
80
 
        p = (pos ? *pos : 0);
81
 
-       if ((p < len) && (! strchr (CNL, file[p]))) {
82
 
+       if ((p < len) && (! strchr (NIH_CONFIG_CNL, file[p]))) {
83
 
                return TRUE;
84
 
        } else {
85
 
                return FALSE;
86
 
@@ -116,7 +92,7 @@
87
 
 
88
 
 
89
 
 /**
90
 
- * nih_config_next_token:
91
 
+ * nih_config_token:
92
 
  * @file: file or string to parse,
93
 
  * @len: length of @file,
94
 
  * @pos: offset within @file,
95
 
@@ -125,7 +101,7 @@
96
 
  * @delim: characters to stop on,
97
 
  * @dequote: remove quotes and escapes.
98
 
  *
99
 
- * Extracts a single token from @file which is stopped when any character
100
 
+ * Parses a single token from @file which is stopped when any character
101
 
  * in @delim is encountered outside of a quoted string and not escaped
102
 
  * using a backslash.
103
 
  *
104
 
@@ -154,13 +130,13 @@
105
 
  * or negative value on raised error.
106
 
  **/
107
 
 ssize_t
108
 
-nih_config_next_token (const char *file,
109
 
-                      size_t      len,
110
 
-                      size_t     *pos,
111
 
-                      size_t     *lineno,
112
 
-                      char       *dest,
113
 
-                      const char *delim,
114
 
-                      int         dequote)
115
 
+nih_config_token (const char *file,
116
 
+                 size_t      len,
117
 
+                 size_t     *pos,
118
 
+                 size_t     *lineno,
119
 
+                 char       *dest,
120
 
+                 const char *delim,
121
 
+                 int         dequote)
122
 
 {
123
 
        size_t  p, ws = 0, nlws = 0, qc = 0, i = 0;
124
 
        ssize_t ret;
125
 
@@ -208,7 +184,7 @@
126
 
                                if (lineno)
127
 
                                        (*lineno)++;
128
 
                                continue;
129
 
-                       } else if (strchr (WS, file[p])) {
130
 
+                       } else if (strchr (NIH_CONFIG_WS, file[p])) {
131
 
                                ws++;
132
 
                                continue;
133
 
                        }
134
 
@@ -217,7 +193,7 @@
135
 
                        isq = TRUE;
136
 
                } else if (strchr (delim, file[p])) {
137
 
                        break;
138
 
-               } else if (strchr (WS, file[p])) {
139
 
+               } else if (strchr (NIH_CONFIG_WS, file[p])) {
140
 
                        ws++;
141
 
                        continue;
142
 
                }
143
 
@@ -294,17 +270,20 @@
144
 
 }
145
 
 
146
 
 /**
147
 
- * nih_config_next_arg:
148
 
+ * nih_config_next_token:
149
 
  * @parent: parent of returned argument,
150
 
  * @file: file or string to parse,
151
 
  * @len: length of @file,
152
 
  * @pos: offset within @file,
153
 
- * @lineno: line number.
154
 
+ * @lineno: line number,
155
 
+ * @delim: characters to stop on,
156
 
+ * @dequote: remove quotes and escapes.
157
 
  *
158
 
- * Extracts a single argument from @file, a dequoted token that is stopped
159
 
- * on any comment, space or newline character that is not quoted or escaped
160
 
- * with a backslash.  Any whitespace after the argument is also consumed,
161
 
- * but not returned, including that with escaped newlines within it.
162
 
+ * Extracts a single token from @file which is stopped when any character
163
 
+ * in @delim is encountered outside of a quoted string and not escaped
164
 
+ * using a backslash.  If @delim contains any whitespace character, then
165
 
+ * all whitespace after the token is also consumed, but not returned,
166
 
+ * including that with escaped newlines within it.
167
 
  *
168
 
  * @file may be a memory mapped file, in which case @pos should be given
169
 
  * as the offset within and @len should be the length of the file as a
170
 
@@ -317,20 +296,25 @@
171
 
  * If @lineno is given it will be incremented each time a new line is
172
 
  * discovered in the file.
173
 
  *
174
 
+ * If you also want quotes to be removed and escaped characters to be
175
 
+ * replaced with the character itself, set @dequote to TRUE.
176
 
+ *
177
 
  * If @parent is not NULL, it should be a pointer to another allocated
178
 
  * block which will be used as the parent for this block.  When @parent
179
 
  * is freed, the returned block will be freed too.  If you have clean-up
180
 
  * that would need to be run, you can assign a destructor function using
181
 
  * the nih_alloc_set_destructor() function.
182
 
  *
183
 
- * Returns: the argument found or NULL on raised error.
184
 
+ * Returns: the token found or NULL on raised error.
185
 
  **/
186
 
 char *
187
 
-nih_config_next_arg (const void *parent,
188
 
-                    const char *file,
189
 
-                    size_t      len,
190
 
-                    size_t     *pos,
191
 
-                    size_t     *lineno)
192
 
+nih_config_next_token (const void *parent,
193
 
+                      const char *file,
194
 
+                      size_t      len,
195
 
+                      size_t     *pos,
196
 
+                      size_t     *lineno,
197
 
+                      const char *delim,
198
 
+                      int         dequote)
199
 
 {
200
 
        size_t   p, arg_start, arg_end;
201
 
        ssize_t  arg_len;
202
 
@@ -340,8 +324,8 @@
203
 
 
204
 
        p = (pos ? *pos : 0);
205
 
        arg_start = p;
206
 
-       arg_len = nih_config_next_token (file, len, &p, lineno,
207
 
-                                        NULL, CNLWS, TRUE);
208
 
+       arg_len = nih_config_token (file, len, &p, lineno,
209
 
+                                   NULL, delim, dequote);
210
 
        arg_end = p;
211
 
 
212
 
        if (arg_len < 0) {
213
 
@@ -352,38 +336,15 @@
214
 
                goto finish;
215
 
        }
216
 
 
217
 
-       /* Skip any amount of whitespace between them, we also need to
218
 
-        * detect an escaped newline here.
219
 
-        */
220
 
-       while (p < len) {
221
 
-               if (file[p] == '\\') {
222
 
-                       /* Escape character, only continue scanning if
223
 
-                        * the next character is newline
224
 
-                        */
225
 
-                       if ((len - p > 1) && (file[p + 1] == '\n')) {
226
 
-                               p++;
227
 
-                       } else {
228
 
-                               break;
229
 
-                       }
230
 
-               } else if (! strchr (WS, file[p])) {
231
 
-                       break;
232
 
-               }
233
 
-
234
 
-               if (file[p] == '\n')
235
 
-                       if (lineno)
236
 
-                               (*lineno)++;
237
 
-
238
 
-               /* Whitespace characer */
239
 
-               p++;
240
 
-       }
241
 
+       nih_config_skip_whitespace (file, len, &p, lineno);
242
 
 
243
 
        /* Copy in the new token */
244
 
        arg = nih_alloc (parent, arg_len + 1);
245
 
        if (! arg)
246
 
                nih_return_system_error (NULL);
247
 
 
248
 
-       if (nih_config_next_token (file + arg_start, arg_end - arg_start, NULL,
249
 
-                                  NULL, arg, CNLWS, TRUE) < 0)
250
 
+       if (nih_config_token (file + arg_start, arg_end - arg_start, NULL,
251
 
+                             NULL, arg, delim, dequote) < 0)
252
 
                goto finish;
253
 
 
254
 
 finish:
255
 
@@ -394,6 +355,51 @@
256
 
 }
257
 
 
258
 
 /**
259
 
+ * nih_config_next_arg:
260
 
+ * @parent: parent of returned argument,
261
 
+ * @file: file or string to parse,
262
 
+ * @len: length of @file,
263
 
+ * @pos: offset within @file,
264
 
+ * @lineno: line number.
265
 
+ *
266
 
+ * Extracts a single argument from @file, a dequoted token that is stopped
267
 
+ * on any comment, space or newline character that is not quoted or escaped
268
 
+ * with a backslash.  Any whitespace after the argument is also consumed,
269
 
+ * but not returned, including that with escaped newlines within it.
270
 
+ *
271
 
+ * @file may be a memory mapped file, in which case @pos should be given
272
 
+ * as the offset within and @len should be the length of the file as a
273
 
+ * whole.
274
 
+ *
275
 
+ * If @pos is given then it will be used as the offset within @file to
276
 
+ * begin (otherwise the start is assumed), and will be updated to point
277
 
+ * to @delim or past the end of the file.
278
 
+ *
279
 
+ * If @lineno is given it will be incremented each time a new line is
280
 
+ * discovered in the file.
281
 
+ *
282
 
+ * If @parent is not NULL, it should be a pointer to another allocated
283
 
+ * block which will be used as the parent for this block.  When @parent
284
 
+ * is freed, the returned block will be freed too.  If you have clean-up
285
 
+ * that would need to be run, you can assign a destructor function using
286
 
+ * the nih_alloc_set_destructor() function.
287
 
+ *
288
 
+ * Returns: the argument found or NULL on raised error.
289
 
+ **/
290
 
+char *
291
 
+nih_config_next_arg (const void *parent,
292
 
+                    const char *file,
293
 
+                    size_t      len,
294
 
+                    size_t     *pos,
295
 
+                    size_t     *lineno)
296
 
+{
297
 
+       nih_assert (file != NULL);
298
 
+
299
 
+       return nih_config_next_token (parent, file, len, pos, lineno,
300
 
+                                     NIH_CONFIG_CNLWS, TRUE);
301
 
+}
302
 
+
303
 
+/**
304
 
  * nih_config_next_line:
305
 
  * @file: file or string to parse,
306
 
  * @len: length of @file,
307
 
@@ -435,6 +441,63 @@
308
 
        }
309
 
 }
310
 
 
311
 
+
312
 
+/**
313
 
+ * nih_config_skip_whitespace:
314
 
+ * @file: file or string to parse,
315
 
+ * @len: length of @file,
316
 
+ * @pos: offset within @file,
317
 
+ * @lineno: line number.
318
 
+ *
319
 
+ * Skips an amount of whitespace and finds either the next token or the end
320
 
+ * of the current line in @file.  Escaped newlines within the whitespace
321
 
+ * are treated as whitespace.
322
 
+ *
323
 
+ * @file may be a memory mapped file, in which case @pos should be given
324
 
+ * as the offset within and @len should be the length of the file as a
325
 
+ * whole.
326
 
+ *
327
 
+ * @pos is used as the offset within @file to begin, and will be updated
328
 
+ * to point to past the end of the line or file.
329
 
+ *
330
 
+ * If @lineno is given it will be incremented each time a new line is
331
 
+ * discovered in the file.
332
 
+ **/
333
 
+void
334
 
+nih_config_skip_whitespace (const char *file,
335
 
+                           size_t      len,
336
 
+                           size_t     *pos,
337
 
+                           size_t     *lineno)
338
 
+{
339
 
+       nih_assert (file != NULL);
340
 
+       nih_assert (pos != NULL);
341
 
+
342
 
+       /* Skip any amount of whitespace between them, we also need to
343
 
+        * detect an escaped newline here.
344
 
+        */
345
 
+       while (*pos < len) {
346
 
+               if (file[*pos] == '\\') {
347
 
+                       /* Escape character, only continue scanning if
348
 
+                        * the next character is newline
349
 
+                        */
350
 
+                       if ((len - *pos > 1) && (file[*pos + 1] == '\n')) {
351
 
+                               (*pos)++;
352
 
+                       } else {
353
 
+                               break;
354
 
+                       }
355
 
+               } else if (! strchr (NIH_CONFIG_WS, file[*pos])) {
356
 
+                       break;
357
 
+               }
358
 
+
359
 
+               if (file[*pos] == '\n')
360
 
+                       if (lineno)
361
 
+                               (*lineno)++;
362
 
+
363
 
+               /* Whitespace characer */
364
 
+               (*pos)++;
365
 
+       }
366
 
+}
367
 
+
368
 
 /**
369
 
  * nih_config_skip_comment:
370
 
  * @file: file or string to parse,
371
 
@@ -614,14 +677,14 @@
372
 
         */
373
 
        p = (pos ? *pos : 0);
374
 
        cmd_start = p;
375
 
-       cmd_len = nih_config_next_token (file, len, &p, lineno,
376
 
-                                        NULL, CNL, FALSE);
377
 
+       cmd_len = nih_config_token (file, len, &p, lineno, NULL,
378
 
+                                   NIH_CONFIG_CNL, FALSE);
379
 
        cmd_end = p;
380
 
 
381
 
        if (cmd_len < 0)
382
 
                goto finish;
383
 
 
384
 
-       /* nih_config_next_token will eat up to the end of the file, a comment
385
 
+       /* nih_config_token will eat up to the end of the file, a comment
386
 
         * or a newline; so this must always succeed.
387
 
         */
388
 
        if (nih_config_skip_comment (file, len, &p, lineno) < 0)
389
 
@@ -632,8 +695,8 @@
390
 
        if (! cmd)
391
 
                nih_return_system_error (NULL);
392
 
 
393
 
-       if (nih_config_next_token (file + cmd_start, cmd_end - cmd_start, NULL,
394
 
-                                  NULL, cmd, CNL, FALSE) < 0)
395
 
+       if (nih_config_token (file + cmd_start, cmd_end - cmd_start, NULL,
396
 
+                             NULL, cmd, NIH_CONFIG_CNL, FALSE) < 0)
397
 
                goto finish;
398
 
 
399
 
 finish:
400
 
@@ -719,7 +782,7 @@
401
 
                line_start = p;
402
 
                if (ws < 0) {
403
 
                        /* Count initial whitespace */
404
 
-                       while ((p < len) && strchr (WS, file[p]))
405
 
+                       while ((p < len) && strchr (NIH_CONFIG_WS, file[p]))
406
 
                                p++;
407
 
 
408
 
                        ws = p - line_start;
409
 
@@ -813,7 +876,7 @@
410
 
        p = *pos;
411
 
 
412
 
        /* Skip initial whitespace */
413
 
-       while ((p < len) && strchr (WS, file[p]))
414
 
+       while ((p < len) && strchr (NIH_CONFIG_WS, file[p]))
415
 
                p++;
416
 
 
417
 
        /* Check the first word (check we have at least 4 chars because of
418
 
@@ -823,12 +886,12 @@
419
 
                return -1;
420
 
 
421
 
        /* Must be whitespace after */
422
 
-       if (! strchr (WS, file[p + 3]))
423
 
+       if (! strchr (NIH_CONFIG_WS, file[p + 3]))
424
 
                return -1;
425
 
 
426
 
        /* Find the second word */
427
 
        p += 3;
428
 
-       while ((p < len) && strchr (WS, file[p]))
429
 
+       while ((p < len) && strchr (NIH_CONFIG_WS, file[p]))
430
 
                p++;
431
 
 
432
 
        /* Check the second word */
433
 
@@ -838,7 +901,7 @@
434
 
 
435
 
        /* May be followed by whitespace */
436
 
        p += strlen (type);
437
 
-       while ((p < len) && strchr (WS, file[p]))
438
 
+       while ((p < len) && strchr (NIH_CONFIG_WS, file[p]))
439
 
                p++;
440
 
 
441
 
        /* May be a comment, in which case eat up to the newline
442
 
@@ -1017,7 +1080,7 @@
443
 
 
444
 
        while (p < len) {
445
 
                /* Skip initial whitespace */
446
 
-               while ((p < len) && strchr (WS, file[p]))
447
 
+               while ((p < len) && strchr (NIH_CONFIG_WS, file[p]))
448
 
                        p++;
449
 
 
450
 
                /* Skip lines with only comments in them; because has_token
451
 
 
452
 
=== modified file 'nih/config.h'
453
 
--- nih/config.h        2007-01-22 01:51:17 +0000
454
 
+++ nih/config.h        2007-02-11 16:35:38 +0000
455
 
@@ -87,51 +87,78 @@
456
 
 #define NIH_CONFIG_LAST { NULL, NULL }
457
 
 
458
 
 
459
 
+/**
460
 
+ * NIH_CONFIG_WS:
461
 
+ *
462
 
+ * Definition of what characters we consider whitespace.
463
 
+ **/
464
 
+#define NIH_CONFIG_WS " \t\r"
465
 
+
466
 
+/**
467
 
+ * NIH_CONFIG_CNL:
468
 
+ *
469
 
+ * Definition of what characters nominally end a line; a comment start
470
 
+ * character or a newline.
471
 
+ **/
472
 
+#define NIH_CONFIG_CNL "#\n"
473
 
+
474
 
+/**
475
 
+ * NIH_CONFIG_CNLWS:
476
 
+ *
477
 
+ * Defintion of what characters nominally separate tokens.
478
 
+ **/
479
 
+#define NIH_CONFIG_CNLWS " \t\r#\n"
480
 
+
481
 
+
482
 
 NIH_BEGIN_EXTERN
483
 
 
484
 
-int       nih_config_has_token     (const char *file, size_t len, size_t *pos,
485
 
-                                   size_t *lineno);
486
 
-
487
 
-ssize_t   nih_config_next_token    (const char *file, size_t len, size_t *pos,
488
 
-                                   size_t *lineno, char *dest,
489
 
-                                   const char *delim, int dequote)
490
 
-       __attribute__ ((warn_unused_result));
491
 
-char *    nih_config_next_arg      (const void *parent,
492
 
-                                   const char *file, size_t len, size_t *pos,
493
 
-                                   size_t *lineno)
494
 
-       __attribute__ ((warn_unused_result, malloc));
495
 
-void      nih_config_next_line     (const char *file, size_t len, size_t *pos,
496
 
-                                   size_t *lineno);
497
 
-int       nih_config_skip_comment  (const char *file, size_t len, size_t *pos,
498
 
-                                   size_t *lineno)
499
 
-       __attribute__ ((warn_unused_result));
500
 
-
501
 
-char **   nih_config_parse_args    (const void *parent,
502
 
-                                   const char *file, size_t len, size_t *pos,
503
 
-                                   size_t *lineno)
504
 
-       __attribute__ ((warn_unused_result, malloc));
505
 
-char *    nih_config_parse_command (const void *parent,
506
 
-                                   const char *file, size_t len, size_t *pos,
507
 
-                                   size_t *lineno)
508
 
-       __attribute__ ((warn_unused_result, malloc));
509
 
-
510
 
-char *    nih_config_parse_block   (const void *parent,
511
 
-                                   const char *file, size_t len, size_t *pos,
512
 
-                                   size_t *lineno, const char *type)
513
 
-       __attribute__ ((warn_unused_result, malloc));
514
 
-
515
 
-int       nih_config_parse_stanza  (const char *file, size_t len, size_t *pos,
516
 
-                                   size_t *lineno, NihConfigStanza *stanzas,
517
 
-                                   void *data)
518
 
-       __attribute__ ((warn_unused_result));
519
 
-
520
 
-int       nih_config_parse_file    (const char *file, size_t len, size_t *pos,
521
 
-                                   size_t *lineno, NihConfigStanza *stanzas,
522
 
-                                   void *data)
523
 
-       __attribute__ ((warn_unused_result));
524
 
-int       nih_config_parse         (const char *filename,
525
 
-                                   size_t *pos, size_t *lineno,
526
 
-                                   NihConfigStanza *stanzas, void *data)
527
 
+int       nih_config_has_token       (const char *file, size_t len,
528
 
+                                     size_t *pos, size_t *lineno);
529
 
+
530
 
+ssize_t   nih_config_token           (const char *file, size_t len,
531
 
+                                     size_t *pos, size_t *lineno, char *dest,
532
 
+                                     const char *delim, int dequote)
533
 
+       __attribute__ ((warn_unused_result));
534
 
+char *    nih_config_next_token      (const void *parent, const char *file,
535
 
+                                     size_t len, size_t *pos, size_t *lineno,
536
 
+                                     const char *delim, int dequote)
537
 
+       __attribute__ ((warn_unused_result, malloc));
538
 
+char *    nih_config_next_arg        (const void *parent, const char *file,
539
 
+                                     size_t len, size_t *pos, size_t *lineno)
540
 
+       __attribute__ ((warn_unused_result, malloc));
541
 
+void      nih_config_next_line       (const char *file, size_t len,
542
 
+                                     size_t *pos, size_t *lineno);
543
 
+
544
 
+void      nih_config_skip_whitespace (const char *file, size_t len,
545
 
+                                     size_t *pos, size_t *lineno);
546
 
+int       nih_config_skip_comment    (const char *file, size_t len,
547
 
+                                     size_t *pos, size_t *lineno)
548
 
+       __attribute__ ((warn_unused_result));
549
 
+
550
 
+char **   nih_config_parse_args      (const void *parent, const char *file,
551
 
+                                     size_t len, size_t *pos, size_t *lineno)
552
 
+       __attribute__ ((warn_unused_result, malloc));
553
 
+char *    nih_config_parse_command   (const void *parent, const char *file,
554
 
+                                     size_t len, size_t *pos, size_t *lineno)
555
 
+       __attribute__ ((warn_unused_result, malloc));
556
 
+
557
 
+char *    nih_config_parse_block     (const void *parent, const char *file,
558
 
+                                     size_t len, size_t *pos, size_t *lineno,
559
 
+                                     const char *type)
560
 
+       __attribute__ ((warn_unused_result, malloc));
561
 
+
562
 
+int       nih_config_parse_stanza    (const char *file, size_t len,
563
 
+                                     size_t *pos, size_t *lineno,
564
 
+                                     NihConfigStanza *stanzas, void *data)
565
 
+       __attribute__ ((warn_unused_result));
566
 
+
567
 
+int       nih_config_parse_file      (const char *file, size_t len,
568
 
+                                     size_t *pos, size_t *lineno,
569
 
+                                     NihConfigStanza *stanzas, void *data)
570
 
+       __attribute__ ((warn_unused_result));
571
 
+int       nih_config_parse           (const char *filename, size_t *pos,
572
 
+                                     size_t *lineno, NihConfigStanza *stanzas,
573
 
+                                     void *data)
574
 
        __attribute__ ((warn_unused_result));
575
 
 
576
 
 NIH_END_EXTERN
577
 
 
578
 
=== modified file 'nih/hash.c'
579
 
--- nih/hash.c  2007-02-09 16:46:45 +0000
580
 
+++ nih/hash.c  2007-02-11 00:28:30 +0000
581
 
@@ -2,7 +2,7 @@
582
 
  *
583
 
  * hash.c - Fuller/Noll/Vo hash table implementation
584
 
  *
585
 
- * Copyright © 2006 Scott James Remnant <scott@netsplit.com>.
586
 
+ * Copyright © 2007 Scott James Remnant <scott@netsplit.com>.
587
 
  *
588
 
  * This program is free software; you can redistribute it and/or modify
589
 
  * it under the terms of the GNU General Public License as published by
590
 
 
591
 
=== modified file 'nih/hash.h'
592
 
--- nih/hash.h  2007-02-09 17:30:41 +0000
593
 
+++ nih/hash.h  2007-02-11 17:00:37 +0000
594
 
@@ -72,8 +72,9 @@
595
 
  * NIH_HASH_FOREACH_SAFE() instead.
596
 
  **/
597
 
 #define NIH_HASH_FOREACH(hash, iter) \
598
 
-       for (size_t _##iter##_i = 0; _##iter##_i < hash->size; _##iter##_i++) \
599
 
-               NIH_LIST_FOREACH (&hash->bins[_##iter##_i], iter)
600
 
+       for (size_t _##iter##_i = 0; _##iter##_i < (hash)->size; \
601
 
+            _##iter##_i++) \
602
 
+               NIH_LIST_FOREACH (&(hash)->bins[_##iter##_i], iter)
603
 
 
604
 
 /**
605
 
  * NIH_HASH_FOREACH_SAFE:
606
 
@@ -94,8 +95,9 @@
607
 
  * would need to use NIH_HASH_FOREACH() instead, as this would skip it.
608
 
  **/
609
 
 #define NIH_HASH_FOREACH_SAFE(hash, iter) \
610
 
-       for (size_t _##iter##_i = 0; _##iter##_i < hash->size; _##iter##_i++) \
611
 
-               NIH_LIST_FOREACH_SAFE (&hash->bins[_##iter##_i], iter)
612
 
+       for (size_t _##iter##_i = 0; _##iter##_i < (hash)->size; \
613
 
+            _##iter##_i++) \
614
 
+               NIH_LIST_FOREACH_SAFE (&(hash)->bins[_##iter##_i], iter)
615
 
 
616
 
 
617
 
 NIH_BEGIN_EXTERN
618
 
 
619
 
=== modified file 'nih/tests/test_config.c'
620
 
--- nih/tests/test_config.c     2007-01-21 11:49:36 +0000
621
 
+++ nih/tests/test_config.c     2007-02-11 16:37:48 +0000
622
 
@@ -99,14 +99,14 @@
623
 
 
624
 
 
625
 
 void
626
 
-test_next_token (void)
627
 
+test_token (void)
628
 
 {
629
 
        char      buf[1024], dest[1024];
630
 
        size_t    pos, lineno;
631
 
        ssize_t   ret;
632
 
        NihError *err;
633
 
 
634
 
-       TEST_FUNCTION ("nih_config_next_token");
635
 
+       TEST_FUNCTION ("nih_config_token");
636
 
        program_name = "test";
637
 
 
638
 
        /* Check that we can obtain the length of the first simple token
639
 
@@ -117,8 +117,8 @@
640
 
        strcpy (buf, "this is a test");
641
 
        pos = 0;
642
 
 
643
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
644
 
-                                    NULL, " ", FALSE);
645
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
646
 
+                               NULL, " ", FALSE);
647
 
 
648
 
        TEST_EQ (ret, 4);
649
 
        TEST_EQ (pos, 4);
650
 
@@ -130,8 +130,8 @@
651
 
        TEST_FEATURE ("with token filling string");
652
 
        strcpy (buf, "wibble");
653
 
        pos = 0;
654
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
655
 
-                                    NULL, " ", FALSE);
656
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
657
 
+                               NULL, " ", FALSE);
658
 
 
659
 
        TEST_EQ (ret, 6);
660
 
        TEST_EQ (pos, 6);
661
 
@@ -142,8 +142,8 @@
662
 
         */
663
 
        TEST_FEATURE ("with token to extract");
664
 
        strcpy (buf, "this is a test");
665
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
666
 
-                                    dest, " ", FALSE);
667
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
668
 
+                               dest, " ", FALSE);
669
 
 
670
 
        TEST_EQ (ret, 4);
671
 
        TEST_EQ_STR (dest, "this");
672
 
@@ -154,8 +154,8 @@
673
 
         */
674
 
        TEST_FEATURE ("with token inside string");
675
 
        pos = 5;
676
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
677
 
-                                    NULL, " ", FALSE);
678
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
679
 
+                               NULL, " ", FALSE);
680
 
 
681
 
        TEST_EQ (ret, 2);
682
 
        TEST_EQ (pos, 7);
683
 
@@ -168,8 +168,8 @@
684
 
        TEST_FEATURE ("with double quotes inside token");
685
 
        strcpy (buf, "\"this is a\" test");
686
 
        pos = 0;
687
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
688
 
-                                    NULL, " ", FALSE);
689
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
690
 
+                               NULL, " ", FALSE);
691
 
 
692
 
        TEST_EQ (ret, 11);
693
 
        TEST_EQ (pos, 11);
694
 
@@ -179,8 +179,8 @@
695
 
         * quotes, we should still get those.
696
 
         */
697
 
        TEST_FEATURE ("with double quotes around token to extract");
698
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
699
 
-                                    dest, " ", FALSE);
700
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
701
 
+                               dest, " ", FALSE);
702
 
 
703
 
        TEST_EQ (ret, 11);
704
 
        TEST_EQ_STR (dest, "\"this is a\"");
705
 
@@ -191,8 +191,8 @@
706
 
         */
707
 
        TEST_FEATURE ("with double quotes and dequoting");
708
 
        pos = 0;
709
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
710
 
-                                    NULL, " ", TRUE);
711
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
712
 
+                               NULL, " ", TRUE);
713
 
 
714
 
        TEST_EQ (ret, 9);
715
 
        TEST_EQ (pos, 11);
716
 
@@ -202,8 +202,8 @@
717
 
         * removed.
718
 
         */
719
 
        TEST_FEATURE ("with double quotes and extract with dequoting");
720
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
721
 
-                                    dest, " ", TRUE);
722
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
723
 
+                               dest, " ", TRUE);
724
 
 
725
 
        TEST_EQ (ret, 9);
726
 
        TEST_EQ_STR (dest, "this is a");
727
 
@@ -216,8 +216,8 @@
728
 
        TEST_FEATURE ("with single quotes inside token");
729
 
        strcpy (buf, "\'this is a\' test");
730
 
        pos = 0;
731
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
732
 
-                                    NULL, " ", FALSE);
733
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
734
 
+                               NULL, " ", FALSE);
735
 
 
736
 
        TEST_EQ (ret, 11);
737
 
        TEST_EQ (pos, 11);
738
 
@@ -230,8 +230,8 @@
739
 
        TEST_FEATURE ("with escaped spaces inside token");
740
 
        strcpy (buf, "this\\ is\\ a test");
741
 
        pos = 0;
742
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
743
 
-                                    NULL, " ", FALSE);
744
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
745
 
+                               NULL, " ", FALSE);
746
 
 
747
 
        TEST_EQ (ret, 11);
748
 
        TEST_EQ (pos, 11);
749
 
@@ -241,8 +241,8 @@
750
 
         * around the delimiter.
751
 
         */
752
 
        TEST_FEATURE ("with escaped spaces within extracted token");
753
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
754
 
-                                    dest, " ", FALSE);
755
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
756
 
+                               dest, " ", FALSE);
757
 
 
758
 
        TEST_EQ (ret, 11);
759
 
        TEST_EQ_STR (dest, "this\\ is\\ a");
760
 
@@ -253,8 +253,8 @@
761
 
         */
762
 
        TEST_FEATURE ("with escaped spaces inside token and dequoting");
763
 
        pos = 0;
764
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
765
 
-                                    NULL, " ", TRUE);
766
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
767
 
+                               NULL, " ", TRUE);
768
 
 
769
 
        TEST_EQ (ret, 9);
770
 
        TEST_EQ (pos, 11);
771
 
@@ -264,8 +264,8 @@
772
 
         * around the delimiter, while removing them.
773
 
         */
774
 
        TEST_FEATURE ("with escaped spaces within extracted dequoted token");
775
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
776
 
-                                    dest, " ", TRUE);
777
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
778
 
+                               dest, " ", TRUE);
779
 
 
780
 
        TEST_EQ (ret, 9);
781
 
        TEST_EQ_STR (dest, "this is a");
782
 
@@ -278,8 +278,8 @@
783
 
        strcpy (buf, "\"this is \n a\" test");
784
 
        pos = 0;
785
 
        lineno = 1;
786
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
787
 
-                                    NULL, " ", FALSE);
788
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
789
 
+                               NULL, " ", FALSE);
790
 
 
791
 
        TEST_EQ (ret, 11);
792
 
        TEST_EQ (pos, 13);
793
 
@@ -290,8 +290,8 @@
794
 
         * string only returns a single space for the newline.
795
 
         */
796
 
        TEST_FEATURE ("with newline inside extracted quoted string");
797
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
798
 
-                                    dest, " ", FALSE);
799
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
800
 
+                               dest, " ", FALSE);
801
 
 
802
 
        TEST_EQ (ret, 11);
803
 
        TEST_EQ_STR (dest, "\"this is a\"");
804
 
@@ -303,8 +303,8 @@
805
 
        TEST_FEATURE ("with newline inside quoted string and lineno set");
806
 
        pos = 0;
807
 
        lineno = 1;
808
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
809
 
-                                    NULL, " ", FALSE);
810
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
811
 
+                               NULL, " ", FALSE);
812
 
 
813
 
        TEST_EQ (ret, 11);
814
 
        TEST_EQ (pos, 13);
815
 
@@ -318,8 +318,8 @@
816
 
        strcpy (buf, "this \\\n is a:test");
817
 
        pos = 0;
818
 
        lineno = 1;
819
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
820
 
-                                    NULL, ":", FALSE);
821
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
822
 
+                               NULL, ":", FALSE);
823
 
 
824
 
        TEST_EQ (ret, 9);
825
 
        TEST_EQ (pos, 12);
826
 
@@ -330,8 +330,8 @@
827
 
         * returns a single space for the newline.
828
 
         */
829
 
        TEST_FEATURE ("with escaped newline inside extracted string");
830
 
-       ret = nih_config_next_token (buf, strlen (buf), NULL, NULL,
831
 
-                                    dest, ":", FALSE);
832
 
+       ret = nih_config_token (buf, strlen (buf), NULL, NULL,
833
 
+                               dest, ":", FALSE);
834
 
 
835
 
        TEST_EQ (ret, 9);
836
 
        TEST_EQ_STR (dest, "this is a");
837
 
@@ -343,8 +343,8 @@
838
 
        TEST_FEATURE ("with escaped newline inside string and lineno set");
839
 
        pos = 0;
840
 
        lineno = 1;
841
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
842
 
-                                    NULL, ":", FALSE);
843
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
844
 
+                               NULL, ":", FALSE);
845
 
 
846
 
        TEST_EQ (ret, 9);
847
 
        TEST_EQ (pos, 12);
848
 
@@ -359,8 +359,8 @@
849
 
        pos = 0;
850
 
        lineno = 1;
851
 
 
852
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
853
 
-                                    NULL, " ", FALSE);
854
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
855
 
+                               NULL, " ", FALSE);
856
 
 
857
 
        TEST_LT (ret, 0);
858
 
        TEST_EQ (pos, 7);
859
 
@@ -379,8 +379,8 @@
860
 
        pos = 0;
861
 
        lineno = 1;
862
 
 
863
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, &lineno,
864
 
-                                    NULL, " ", FALSE);
865
 
+       ret = nih_config_token (buf, strlen (buf), &pos, &lineno,
866
 
+                               NULL, " ", FALSE);
867
 
 
868
 
        TEST_LT (ret, 0);
869
 
        TEST_EQ (pos, 8);
870
 
@@ -397,14 +397,281 @@
871
 
        TEST_FEATURE ("with empty token");
872
 
        strcpy (buf, " wibble");
873
 
        pos = 0;
874
 
-       ret = nih_config_next_token (buf, strlen (buf), &pos, NULL,
875
 
-                                    NULL, " ", FALSE);
876
 
+       ret = nih_config_token (buf, strlen (buf), &pos, NULL,
877
 
+                               NULL, " ", FALSE);
878
 
 
879
 
        TEST_EQ (ret, 0);
880
 
        TEST_EQ (pos, 0);
881
 
 }
882
 
 
883
 
 void
884
 
+test_next_token (void)
885
 
+{
886
 
+       char      buf[1024];
887
 
+       char     *str;
888
 
+       size_t    pos, lineno;
889
 
+       NihError *err;
890
 
+
891
 
+       TEST_FUNCTION ("nih_config_next_token");
892
 
+
893
 
+       /* Check that we can extract a token at the start of a string,
894
 
+        * and have the position pointing past the whitespace to the next
895
 
+        * argument.
896
 
+        */
897
 
+       TEST_FEATURE ("with token at start of string");
898
 
+       TEST_ALLOC_FAIL {
899
 
+               strcpy (buf, "this is a test");
900
 
+               pos = 0;
901
 
+
902
 
+               str = nih_config_next_token (NULL, buf,
903
 
+                                            strlen (buf), &pos, NULL,
904
 
+                                            NIH_CONFIG_CNLWS, FALSE);
905
 
+
906
 
+               if (test_alloc_failed) {
907
 
+                       TEST_EQ_P (str, NULL);
908
 
+                       TEST_EQ (pos, 0);
909
 
+
910
 
+                       err = nih_error_get ();
911
 
+                       TEST_EQ (err->number, ENOMEM);
912
 
+                       nih_free (err);
913
 
+                       continue;
914
 
+               }
915
 
+
916
 
+               TEST_EQ (pos, 5);
917
 
+               TEST_ALLOC_SIZE (str, 5);
918
 
+               TEST_EQ_STR (str, "this");
919
 
+
920
 
+               nih_free (str);
921
 
+       }
922
 
+
923
 
+
924
 
+       /* Check that we can extract an argument inside a string
925
 
+        */
926
 
+       TEST_FEATURE ("with token inside string");
927
 
+       TEST_ALLOC_FAIL {
928
 
+               strcpy (buf, "this is a test");
929
 
+               pos = 5;
930
 
+
931
 
+               str = nih_config_next_token (NULL, buf,
932
 
+                                            strlen (buf), &pos, NULL,
933
 
+                                            NIH_CONFIG_CNLWS, FALSE);
934
 
+
935
 
+               if (test_alloc_failed) {
936
 
+                       TEST_EQ_P (str, NULL);
937
 
+                       TEST_EQ (pos, 5);
938
 
+
939
 
+                       err = nih_error_get ();
940
 
+                       TEST_EQ (err->number, ENOMEM);
941
 
+                       nih_free (err);
942
 
+                       continue;
943
 
+               }
944
 
+
945
 
+               TEST_EQ (pos, 8);
946
 
+               TEST_ALLOC_SIZE (str, 3);
947
 
+               TEST_EQ_STR (str, "is");
948
 
+
949
 
+               nih_free (str);
950
 
+       }
951
 
+
952
 
+
953
 
+       /* Check that all trailing whitespace is eaten after the token. */
954
 
+       TEST_FEATURE ("with consecutive whitespace after token");
955
 
+       TEST_ALLOC_FAIL {
956
 
+               strcpy (buf, "this \t  is a test");
957
 
+               pos = 0;
958
 
+
959
 
+               str = nih_config_next_token (NULL, buf,
960
 
+                                            strlen (buf), &pos, NULL,
961
 
+                                            NIH_CONFIG_CNLWS, FALSE);
962
 
+
963
 
+               if (test_alloc_failed) {
964
 
+                       TEST_EQ_P (str, NULL);
965
 
+                       TEST_EQ (pos, 0);
966
 
+
967
 
+                       err = nih_error_get ();
968
 
+                       TEST_EQ (err->number, ENOMEM);
969
 
+                       nih_free (err);
970
 
+                       continue;
971
 
+               }
972
 
+
973
 
+               TEST_EQ (pos, 8);
974
 
+               TEST_ALLOC_SIZE (str, 5);
975
 
+               TEST_EQ_STR (str, "this");
976
 
+
977
 
+               nih_free (str);
978
 
+       }
979
 
+
980
 
+
981
 
+       /* Check that any escaped newlines in the whitespace are skipped
982
 
+        * over
983
 
+        */
984
 
+       TEST_FEATURE ("with escaped newlines in whitespace");
985
 
+       TEST_ALLOC_FAIL {
986
 
+               strcpy (buf, "this \\\n is a test");
987
 
+               pos = 0;
988
 
+
989
 
+               str = nih_config_next_token (NULL, buf,
990
 
+                                            strlen (buf), &pos, NULL,
991
 
+                                            NIH_CONFIG_CNLWS, FALSE);
992
 
+
993
 
+               if (test_alloc_failed) {
994
 
+                       TEST_EQ_P (str, NULL);
995
 
+                       TEST_EQ (pos, 0);
996
 
+
997
 
+                       err = nih_error_get ();
998
 
+                       TEST_EQ (err->number, ENOMEM);
999
 
+                       nih_free (err);
1000
 
+                       continue;
1001
 
+               }
1002
 
+
1003
 
+               TEST_EQ (pos, 8);
1004
 
+               TEST_ALLOC_SIZE (str, 5);
1005
 
+               TEST_EQ_STR (str, "this");
1006
 
+
1007
 
+               nih_free (str);
1008
 
+       }
1009
 
+
1010
 
+
1011
 
+       /* Check that the line number is incremented for any escaped newlines
1012
 
+        * in the whitespace.
1013
 
+        */
1014
 
+       TEST_FEATURE ("with line number set");
1015
 
+       TEST_ALLOC_FAIL {
1016
 
+               pos = 0;
1017
 
+               lineno = 1;
1018
 
+
1019
 
+               str = nih_config_next_token (NULL, buf,
1020
 
+                                            strlen (buf), &pos, &lineno,
1021
 
+                                            NIH_CONFIG_CNLWS, FALSE);
1022
 
+
1023
 
+               if (test_alloc_failed) {
1024
 
+                       TEST_EQ_P (str, NULL);
1025
 
+                       TEST_EQ (pos, 0);
1026
 
+                       TEST_EQ (lineno, 2);
1027
 
+
1028
 
+                       err = nih_error_get ();
1029
 
+                       TEST_EQ (err->number, ENOMEM);
1030
 
+                       nih_free (err);
1031
 
+                       continue;
1032
 
+               }
1033
 
+
1034
 
+               TEST_EQ (pos, 8);
1035
 
+               TEST_EQ (lineno, 2);
1036
 
+               TEST_ALLOC_SIZE (str, 5);
1037
 
+               TEST_EQ_STR (str, "this");
1038
 
+
1039
 
+               nih_free (str);
1040
 
+       }
1041
 
+
1042
 
+
1043
 
+       /* Check that the returned token can have the quotes left in it,
1044
 
+        * but the whitespace around the newline collapsed.
1045
 
+        */
1046
 
+       TEST_FEATURE ("with token containing quotes");
1047
 
+       TEST_ALLOC_FAIL {
1048
 
+               strcpy (buf, "\"this \\\n is\" a test");
1049
 
+               pos = 0;
1050
 
+
1051
 
+               str = nih_config_next_token (NULL, buf,
1052
 
+                                            strlen (buf), &pos, NULL,
1053
 
+                                            NIH_CONFIG_CNLWS, FALSE);
1054
 
+
1055
 
+               if (test_alloc_failed) {
1056
 
+                       TEST_EQ_P (str, NULL);
1057
 
+                       TEST_EQ (pos, 0);
1058
 
+
1059
 
+                       err = nih_error_get ();
1060
 
+                       TEST_EQ (err->number, ENOMEM);
1061
 
+                       nih_free (err);
1062
 
+                       continue;
1063
 
+               }
1064
 
+
1065
 
+               TEST_EQ (pos, 13);
1066
 
+               TEST_ALLOC_SIZE (str, 10);
1067
 
+               TEST_EQ_STR (str, "\"this is\"");
1068
 
+
1069
 
+               nih_free (str);
1070
 
+       }
1071
 
+
1072
 
+
1073
 
+       /* Check that the returned token can be thoroughly dequoted and any
1074
 
+        * whitespace around an embedded newline collapsed to a single
1075
 
+        * space.
1076
 
+        */
1077
 
+       TEST_FEATURE ("with quoted whitespace and newline in token");
1078
 
+       TEST_ALLOC_FAIL {
1079
 
+               strcpy (buf, "\"this \\\n is\" a test");
1080
 
+               pos = 0;
1081
 
+
1082
 
+               str = nih_config_next_token (NULL, buf,
1083
 
+                                            strlen (buf), &pos, NULL,
1084
 
+                                            NIH_CONFIG_CNLWS, TRUE);
1085
 
+
1086
 
+               if (test_alloc_failed) {
1087
 
+                       TEST_EQ_P (str, NULL);
1088
 
+                       TEST_EQ (pos, 0);
1089
 
+
1090
 
+                       err = nih_error_get ();
1091
 
+                       TEST_EQ (err->number, ENOMEM);
1092
 
+                       nih_free (err);
1093
 
+                       continue;
1094
 
+               }
1095
 
+
1096
 
+               TEST_EQ (pos, 13);
1097
 
+               TEST_ALLOC_SIZE (str, 8);
1098
 
+               TEST_EQ_STR (str, "this is");
1099
 
+
1100
 
+               nih_free (str);
1101
 
+       }
1102
 
+
1103
 
+
1104
 
+       /* Check that an error is raised if there is no token at that
1105
 
+        * position.
1106
 
+        */
1107
 
+       TEST_FEATURE ("with empty line");
1108
 
+       TEST_ALLOC_FAIL {
1109
 
+               strcpy (buf, "\nthis is a test");
1110
 
+               pos = 0;
1111
 
+               lineno = 1;
1112
 
+
1113
 
+               str = nih_config_next_token (NULL, buf,
1114
 
+                                            strlen (buf), &pos, &lineno,
1115
 
+                                            NIH_CONFIG_CNLWS, FALSE);
1116
 
+
1117
 
+               TEST_EQ_P (str, NULL);
1118
 
+               TEST_EQ (pos, 0);
1119
 
+               TEST_EQ (lineno, 1);
1120
 
+
1121
 
+               err = nih_error_get ();
1122
 
+               TEST_EQ (err->number, NIH_CONFIG_EXPECTED_TOKEN);
1123
 
+               nih_free (err);
1124
 
+       }
1125
 
+
1126
 
+
1127
 
+       /* Check that a parse error being found with the argument causes an
1128
 
+        * error to be raised, with pos and lineno at the site of the error.
1129
 
+        */
1130
 
+       TEST_FEATURE ("with parser error");
1131
 
+       TEST_ALLOC_FAIL {
1132
 
+               strcpy (buf, "\"this is a test\nand so is this");
1133
 
+               pos = 0;
1134
 
+               lineno = 1;
1135
 
+
1136
 
+               str = nih_config_next_token (NULL, buf,
1137
 
+                                            strlen (buf), &pos, &lineno,
1138
 
+                                            NIH_CONFIG_CNLWS, FALSE);
1139
 
+
1140
 
+               TEST_EQ_P (str, NULL);
1141
 
+               TEST_EQ (pos, 30);
1142
 
+               TEST_EQ (lineno, 2);
1143
 
+
1144
 
+               err = nih_error_get ();
1145
 
+               TEST_EQ (err->number, NIH_CONFIG_UNTERMINATED_QUOTE);
1146
 
+               nih_free (err);
1147
 
+       }
1148
 
+}
1149
 
+
1150
 
+void
1151
 
 test_next_arg (void)
1152
 
 {
1153
 
        char      buf[1024];
1154
 
@@ -691,6 +958,70 @@
1155
 
 }
1156
 
 
1157
 
 void
1158
 
+test_skip_whitespace (void)
1159
 
+{
1160
 
+       char   buf[1024];
1161
 
+       size_t pos, lineno;
1162
 
+
1163
 
+       TEST_FUNCTION ("nih_config_next_whitespace");
1164
 
+
1165
 
+       /* Check that we can skip an amount of plain whitespace characters
1166
 
+        * until the next token, pointing pos at is.
1167
 
+        */
1168
 
+       TEST_FEATURE ("with plain whitespace");
1169
 
+       strcpy (buf, "a  plain string\n");
1170
 
+       pos = 1;
1171
 
+       lineno = 1;
1172
 
+
1173
 
+       nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno);
1174
 
+
1175
 
+       TEST_EQ (pos, 3);
1176
 
+       TEST_EQ (lineno, 1);
1177
 
+
1178
 
+
1179
 
+       /* Check that we can skip a more complex series of whitespace
1180
 
+        * characters until the next token.
1181
 
+        */
1182
 
+       TEST_FEATURE ("with complex whitespace");
1183
 
+       strcpy (buf, "a more   \t  \r  complex string\n");
1184
 
+       pos = 6;
1185
 
+       lineno = 1;
1186
 
+
1187
 
+       nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno);
1188
 
+
1189
 
+       TEST_EQ (pos, 15);
1190
 
+       TEST_EQ (lineno, 1);
1191
 
+
1192
 
+
1193
 
+       /* Check that we can skip whitespace characters up until the end
1194
 
+        * of the line, but that we don't step over it.
1195
 
+        */
1196
 
+       TEST_FEATURE ("with whitespace at end of line");
1197
 
+       strcpy (buf, "trailing whitespace  \t\r\n");
1198
 
+       pos = 19;
1199
 
+       lineno = 1;
1200
 
+
1201
 
+       nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno);
1202
 
+
1203
 
+       TEST_EQ (pos, 23);
1204
 
+       TEST_EQ (lineno, 1);
1205
 
+
1206
 
+
1207
 
+       /* Check that we step over an escaped newline embedded in the
1208
 
+        * whitespace, and increment lineno.
1209
 
+        */
1210
 
+       TEST_FEATURE ("with escaped newline");
1211
 
+       strcpy (buf, "this has \\\n a newline");
1212
 
+       pos = 8;
1213
 
+       lineno = 1;
1214
 
+
1215
 
+       nih_config_skip_whitespace (buf, strlen (buf), &pos, &lineno);
1216
 
+
1217
 
+       TEST_EQ (pos, 12);
1218
 
+       TEST_EQ (lineno, 2);
1219
 
+}
1220
 
+
1221
 
+void
1222
 
 test_skip_comment (void)
1223
 
 {
1224
 
        char      buf[1024];
1225
 
@@ -2306,9 +2637,11 @@
1226
 
       char *argv[])
1227
 
 {
1228
 
        test_has_token ();
1229
 
+       test_token ();
1230
 
        test_next_token ();
1231
 
        test_next_arg ();
1232
 
        test_next_line ();
1233
 
+       test_skip_whitespace ();
1234
 
        test_skip_comment ();
1235
 
        test_parse_args ();
1236
 
        test_parse_command ();
1237