123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- #ifndef __WORDSPLIT_H
- #define __WORDSPLIT_H
- #include <stddef.h>
- #include <attribute.h>
- typedef struct wordsplit wordsplit_t;
- struct wordsplit
- {
- size_t ws_wordc;
- char **ws_wordv;
- size_t ws_offs;
- size_t ws_wordn;
- unsigned ws_flags;
- unsigned ws_options;
- size_t ws_maxwords;
- size_t ws_wordi;
- const char *ws_delim;
- const char *ws_comment;
- const char *ws_escape[2];
- void (*ws_alloc_die) (wordsplit_t *wsp);
-
- void (*ws_error) (const char *, ...)
- ATTRIBUTE_FORMAT ((printf, 1, 2));
-
- void (*ws_debug) (const char *, ...)
- ATTRIBUTE_FORMAT ((printf, 1, 2));
-
- const char **ws_env;
- char **ws_envbuf;
- size_t ws_envidx;
- size_t ws_envsiz;
- int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
-
- void *ws_closure;
- int (*ws_command) (char **ret, const char *cmd, size_t len, char **argv,
- void *clos);
-
- 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;
-
- int ws_lvl;
- };
- #define WORDSPLIT_ENV_INIT 16
- #define WRDSF_APPEND 0x00000001
- #define WRDSF_DOOFFS 0x00000002
- #define WRDSF_NOCMD 0x00000004
- #define WRDSF_REUSE 0x00000008
- #define WRDSF_SHOWERR 0x00000010
- #define WRDSF_UNDEF 0x00000020
- #define WRDSF_NOVAR 0x00000040
- #define WRDSF_ENOMEMABRT 0x00000080
- #define WRDSF_WS 0x00000100
- #define WRDSF_SQUOTE 0x00000200
- #define WRDSF_DQUOTE 0x00000400
- #define WRDSF_QUOTE (WRDSF_SQUOTE|WRDSF_DQUOTE)
- #define WRDSF_SQUEEZE_DELIMS 0x00000800
- #define WRDSF_RETURN_DELIMS 0x00001000
- #define WRDSF_SED_EXPR 0x00002000
- #define WRDSF_DELIM 0x00004000
- #define WRDSF_COMMENT 0x00008000
- #define WRDSF_ALLOC_DIE 0x00010000
- #define WRDSF_ERROR 0x00020000
- #define WRDSF_DEBUG 0x00040000
- #define WRDSF_ENV 0x00080000
- #define WRDSF_GETVAR 0x00100000
- #define WRDSF_SHOWDBG 0x00200000
- #define WRDSF_NOSPLIT 0x00400000
- #define WRDSF_KEEPUNDEF 0x00800000
- #define WRDSF_WARNUNDEF 0x01000000
- #define WRDSF_CESCAPES 0x02000000
- #define WRDSF_CLOSURE 0x04000000
- #define WRDSF_ENV_KV 0x08000000
- #define WRDSF_ESCAPE 0x10000000
- #define WRDSF_INCREMENTAL 0x20000000
- #define WRDSF_PATHEXPAND 0x40000000
- #define WRDSF_OPTIONS 0x80000000
- #define WRDSF_DEFFLAGS \
- (WRDSF_NOVAR | WRDSF_NOCMD | \
- WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | WRDSF_CESCAPES)
- #define WRDSO_NULLGLOB 0x00000001
- #define WRDSO_FAILGLOB 0x00000002
- #define WRDSO_DOTGLOB 0x00000004
- #define WRDSO_ARGV 0x00000008
- #define WRDSO_BSKEEP_WORD 0x00000010
- #define WRDSO_OESC_WORD 0x00000020
- #define WRDSO_XESC_WORD 0x00000040
- #define WRDSO_MAXWORDS 0x00000080
- #define WRDSO_BSKEEP_QUOTE 0x00000100
- #define WRDSO_OESC_QUOTE 0x00000200
- #define WRDSO_XESC_QUOTE 0x00000400
- #define WRDSO_BSKEEP WRDSO_BSKEEP_WORD
- #define WRDSO_OESC WRDSO_OESC_WORD
- #define WRDSO_XESC WRDSO_XESC_WORD
- #define WRDSX_WORD 0
- #define WRDSX_QUOTE 1
- #define WRDSO_ESC_SET(ws,q,f) ((ws)->ws_options |= ((f) << 4*(q)))
- #define WRDSO_ESC_TEST(ws,q,f) ((ws)->ws_options & ((f) << 4*(q)))
- #define WRDSE_OK 0
- #define WRDSE_EOF WRDSE_OK
- #define WRDSE_QUOTE 1
- #define WRDSE_NOSPACE 2
- #define WRDSE_USAGE 3
- #define WRDSE_CBRACE 4
- #define WRDSE_UNDEF 5
- #define WRDSE_NOINPUT 6
- #define WRDSE_PAREN 7
- #define WRDSE_GLOBERR 8
- #define WRDSE_USERERR 9
- int wordsplit (const char *s, wordsplit_t *ws, unsigned flags);
- int wordsplit_len (const char *s, size_t len, wordsplit_t *ws, unsigned flags);
- void wordsplit_free (wordsplit_t *ws);
- void wordsplit_free_words (wordsplit_t *ws);
- void wordsplit_free_envbuf (wordsplit_t *ws);
- int wordsplit_get_words (wordsplit_t *ws, size_t *wordc, char ***wordv);
- int wordsplit_append (wordsplit_t *wsp, int argc, char **argv);
- int wordsplit_c_unquote_char (int c);
- int wordsplit_c_quote_char (int c);
- size_t wordsplit_c_quoted_length (const char *str, int quote_hex, int *quote);
- void wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
- void wordsplit_perror (wordsplit_t *ws);
- const char *wordsplit_strerror (wordsplit_t *ws);
- void wordsplit_clearerr (wordsplit_t *ws);
- #endif
|