diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-10-23 12:12:02 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-12-17 15:25:24 +0200 |
commit | e66e2edfa50c8535e05b334c6a5d867fafeb9469 (patch) | |
tree | 5af187dea3750df11c404658c624300bae324d97 /src/wordsplit.h | |
parent | beda81512afdcf16432ebd5b76930392f427a7fc (diff) | |
download | grecs-e66e2edfa50c8535e05b334c6a5d867fafeb9469.tar.gz grecs-e66e2edfa50c8535e05b334c6a5d867fafeb9469.tar.bz2 |
Change prototypes of ws_getvar and ws_command.
New invocation sequence ensures proper error handling.
This is an incompatible change. Authors using ws_getvar member will
have to rewrite their ws_getvar function accordingly.
* src/wordsplit.c (wordsplit_init0): Call wordsplit_clearerr
on reuse.
(wordsplit_init): Fix ws_errno
(expvar): Change invocation of ws_getvar.
(expcmd): Change invocation of ws_command.
(wordsplit_clearerr): New function.
(wordsplit_strerror): Handle WRDSE_USERERR.
* src/wordsplit.h (ws_getvar): Change return value and signature of
ws_getvar and ws_command.
New member 'ws_usererr'.
(WRDSF_ARGV): New flag.
(WRDSE_OK): New define. Same as WRDSE_EOF.
(WRDSE_USERERR): New error code.
(wordsplit_clearerr): New proto.
* tests/wsp.c (wsp_getvar, wsp_runcmd): Rewrite.
Diffstat (limited to 'src/wordsplit.h')
-rw-r--r-- | src/wordsplit.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/wordsplit.h b/src/wordsplit.h index 96088f9..4a0cd88 100644 --- a/src/wordsplit.h +++ b/src/wordsplit.h @@ -36,19 +36,20 @@ struct wordsplit __attribute__ ((__format__ (__printf__, 1, 2))); const char **ws_env; - char *(*ws_getvar) (const char *, size_t, void *); + int (*ws_getvar) (char **, const char *, size_t, void *); void *ws_closure; - char *(*ws_command) (const char *, size_t, struct wordsplit const *); + int (*ws_command) (char **, const char *, size_t, char **, void *); const char *ws_input; size_t ws_len; size_t ws_endp; int ws_errno; + char *ws_usererr; struct wordsplit_node *ws_head, *ws_tail; }; -/* Wordsplit flags. Only 2 bits of a 32-bit word remain unused. +/* Wordsplit flags. Only 1 bit of a 32-bit word remains unused. It is getting crowded... */ /* Append the words found to the array resulting from a previous call. */ @@ -125,10 +126,14 @@ struct wordsplit /* Incremental mode */ #define WRDSF_INCREMENTAL 0x20000000 +/* ws_command needs argv parameter */ +#define WRDSF_ARGV 0x40000000 + #define WRDSF_DEFFLAGS \ (WRDSF_NOVAR | WRDSF_NOCMD | \ WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES) +#define WRDSE_OK 0 #define WRDSE_EOF 0 #define WRDSE_QUOTE 1 #define WRDSE_NOSPACE 2 @@ -137,6 +142,7 @@ struct wordsplit #define WRDSE_CBRACE 5 #define WRDSE_UNDEF 6 #define WRDSE_NOINPUT 7 +#define WRDSE_USERERR 8 int wordsplit (const char *s, struct wordsplit *p, int flags); int wordsplit_len (const char *s, size_t len, @@ -157,5 +163,7 @@ void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); void wordsplit_perror (struct wordsplit *ws); const char *wordsplit_strerror (struct wordsplit *ws); +void wordsplit_clearerr (struct wordsplit *ws); + #endif |