aboutsummaryrefslogtreecommitdiff
path: root/include/wordsplit.h
AgeCommit message (Collapse)AuthorFiles
2019-07-10Import wordsplit as a submoduleSergey Poznyakoff1
* .gitmodules: New module: wordsplit * Makefile.am: Distribute wordsplit files. * am/grecs.m4 (GRECS_INCLUDES): Add wordsplit directory * doc/Makefile.am (dist_man_MANS): Distribute wordsplit/wordsplit.3 * doc/wordsplit.3: Remove. * include/Makefile.am (GRECS_HDR): Add wordsplit/wordsplit. * include/wordsplit.h: Remove. * src/Make-inst.am: Define nodist_libgrecs_la_SOURCES. * src/Make-shared.am: Likewise. * src/Make-static.am: Define nodist_libgrecs_a_SOURCES. * src/Make.am (GRECS_SRC): Remove wordsplit.c (NODIST_GRECS_SRC): Define to wordsplit.c (VPATH): Add the wordsplit directory. * src/wordsplit.c: Remove. * tests/wordsplit.at: Remove. * tests/wsp.c: Remove. * tests/Makefile.am: Build separate testsuite for wordsplit. Use VPATH to build wsp. * tests/.gitignore: Update.
2019-06-13wordsplit: configurable order of lookups if both WRDSF_ENV and WRDSF_GETVAR ↵Sergey Poznyakoff1
are set * lib/wordsplit.h (WRDSO_GETVARPREF): New option. * lib/wordsplit.c (wordsplit_find_env): Rewrite as wsplt_env_lookup wsplt_env_getvar): New function. (expvar): Select preference of wsplt_env_lookup vs. wsplt_env_getvar depending on the value if WRDSO_GETVARPREF option.
2019-05-15wordsplit: introduce error contextSergey Poznyakoff1
* include/wordsplit.h (wordsplit) <ws_errctx>: New field. * src/wordsplit.c (wordsplit_init): Initialize ws_errctx. (expvar,wordsplit_pathexpand): Save error context. (wordsplit_clearerr): Free error context. (wordsplit_perror): Use error context if available. * tests/wordsplit.at: Reflect changes.
2019-05-14Fix behaviour of $* and $@ in quoted contextSergey Poznyakoff1
2019-05-14wordsplit: whitespace cleanupSergey Poznyakoff1
2019-05-14wordsplit: rewrite positional parameters implementationSergey Poznyakoff1
This improves 3e07e3ad * include/wordsplit.h (ws_paramv,ws_paramc) (ws_parambuf,ws_paramidx,ws_paramsiz): New fields. (WRDSO_PARAMV,WRDSO_PARAM_NEGIDX): New options. (WRDSE_BADPARAM): New error code. (wordsplit_free_parambuf): New proto. * src/wordsplit.c (wordsplit_init): Initialize new fields. (wsplt_assign_var): Fix double-free and memory leak. (expvar): Expand positional parameters. (begin_var_p): Add '#' (wordsplit_free_envbuf): Fix condition. (wordsplit_free_parambuf): New function. (wordsplit_free): Call wordsplit_free_parambuf. (_wordsplit_errstr): New error description. * tests/wordsplit.at: Update wsp invocations. Test positional parameters. * tests/wsp.c: Rewrite.
2019-05-13wordsplit: optionally disable splitting of unexpandable variable and command ↵Sergey Poznyakoff1
refs * include/wordsplit.h (WRDSO_NOVARSPLIT) (WRDSO_NOCMDSPLIT): New options. * src/wordsplit.c (scan_word): Treat any variable reference, even containing whitespace, as a single word if WRDSO_NOVARSPLIT is set. Ditto for commands and WRDSO_NOCMDSPLIT. * tests/wordsplit.at: Add new tests. * tests/wsp.c: Recognize novarsplit and nocmdsplit options. For future use: recognize bskeep_words, bskeep_quote, bskeep.
2019-04-20Improve variable handling in wordsplit.Sergey Poznyakoff1
Positional variables ($N and ${N}) are recognized. Variable names in curly braces follow the same rules as unadorned ones. This commit also changes memory reallocation strategy in wsplt_assign_var. If ws_envbuf needs to be expanded, new allocation size is selected as 3/2 of the previous allocation, if that size is less than max(size_t).
2018-11-15Port mailutils commit 2c2e3c50d6Sergey Poznyakoff1
* include/wordsplit.h (WRDSO_ARGV): Remove. * src/wordsplit.c (expcmd): Always split command line into arguments. This fixes https://savannah.gnu.org/bugs/?54830 * tests/wsp.c: Implement internal commands, instead of calling shell ones. This fixes https://savannah.gnu.org/bugs/?54829. * tests/wordsplit.at: Rewrite command expansion tests.
2018-06-04json: improve parser reentrabilitySergey Poznyakoff1
* include/grecs/json.h (jsonlex_cleanup): New proto. * src/json-lex.l (jsonlex_setup): Initialize parser state. Initialize json_current_locus_point.file to a non-NULL value. (jsonlex_cleanup): New function. * src/json-gram.y (json_parse_string): Call jsonlex_cleanup before returning. * src/diag.c (default_print_diag): Print the passed errcode argument, instead of errno.
2018-05-22New feature: maxwordsSergey Poznyakoff1
This feature allows the user to limit the number of words returned by a call to wordsplit. When the number of words in expansion reaches the predefined limit, the rest of input line will be expanded and returned as a single last word. For example, to parse a /etc/passwd line: struct wordsplit ws; ws.ws_delim = ":"; ws.ws_maxwords = 7; ws.ws_options = WRDSO_MAXWORDS; wordsplit(str, &ws, WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM | WRDSF_OPTIONS); * doc/wordsplit.3: Document the maxwords feature. * include/wordsplit.h (wordsplit) <ws_maxwords> <ws_wordi>: New members. (WRDSO_MAXWORDS): New option. * src/wordsplit.c (WSP_RETURN_DELIMS): New macro. (_wsplt_subsplit): Rewrite. (wordsplit_init0): Don't reset node list. (wordsplit_init): Initialize ws_wordi and the node list. (wsnode_insert): Correctly insert lists. (coalesce_segment): Additional safety check. (wsnode_tail_coalesce): New static function. (wordsplit_finish): Postprocess delimiters. (expvar,expcmd): Use new _wsplt_subsplit. (wordsplit_varexp): Don't try to expand delimiter nodes. (skip_delim): Remove delimiter processing. It is now done in wordsplit_finish. (scan_word): New argument 'consume_all' instructs it to consume the rest of input as one token. (wordsplit_process_list): Handle wsp->ws_maxwords setting. This also fixed a long-standing bug: quotes weren't processed in WRDSF_NOSPLIT mode. See the testcase 59 (incremental nosplit). (wordsplit_run): Rewrite. (wordsplit_free): Free node list. * tests/wordsplit.at: Update for the new wsp output format. (incremental nosplit): Expect correct output. Add tests for the maxwords feature. * tests/wsp.c (maxwords): New flag. Print the ws_wordi value as "TOTALS" at the end of each run.
2018-05-21Minor fixesSergey Poznyakoff1
* README.submodule: Fix the description. * include/wordsplit.h: Fix typo.
2018-02-20Minor improvement in wordsplitSergey Poznyakoff1
* src/wordsplit.c (expvar): Gracefully handle NULL values in ENV_KV environment. * src/wordsplit.h: Fix typo in a comment. * doc/wordsplit.3: Update.
2017-11-10Pull fixes to wordsplit from mailutilsSergey Poznyakoff1
This includes the following commits pushed between 2015-09-19 and 2017-10-10: 090c7b9a Allow ws_getvar to set value to NULL and return MU_WRDSE_OK. The value is processed as if it were "", i.e. MU_WRDSE_UNDEF is returned. 64313fdf Fix MU_WRDSF_INCREMENTAL | MU_WRDSF_NOSPLIT 46d7640f Add wordsplit_append function 151eb4b9 Fix nested expansions and command expansions occurring after variable expansions. ad3cc340 Replace void wordsplit_getwords with int wordsplit_get_words. * include/wordsplit.h (wordsplit_get_words): New function. (wordsplit_getwords): Mark as deprecated. (wordsplit_append): New function. * src/wordsplit.c (wordsplit_append): New function. MU 46d7640f. (expvar): Treat NULL value as "". MU 090c7b9a. (expcmd): Allow command and variable expansions in subsplit. (exptab): Change ordering of expansions so that command expansion occurs first. This fixes nested expansions and command expansions occurring after variable expansions. MU 151eb4b9. (wordsplit_process_list): Update wsp->ws_endp in nosplit mode. This fixes wordsplit MU_WRDSF_INCREMENTAL | MU_WRDSF_NOSPLIT. MU 64313fdf. (wordsplit_get_words): New function. MU ad3cc340. * tests/wordsplit.at: Test the above changes. * tests/wsp.c: Accept extra arguments to append using wordsplit_append.
2016-07-04Split declarations between several header files.Sergey Poznyakoff1
* Makefile.am (SUBDIRS): Add include * am/grecs.m4 (GRECS_INCLUDES): Update (GRECS_COND_BUILD_INSTALL) (GRECS_COND_BUILD_SHARED) (GRECS_COND_BUILD_STATIC): New conditions. Build include/Makefile and include/grecs/Makefile. * configure.ac: Use src/grecs-gram.y as a source validity marker * include/Makefile.a: New file. * src/grecs.hin: Remove. Split into include/*. See below. * include/grecs.h: New file. * include/grecs/.gitignore: New file. * include/grecs/Makefile.am: New file. * include/grecs/doc.h: New file. * include/grecs/error.h: New file. * include/grecs/format.h: New file. * include/grecs/lex.h: New file. * include/grecs/list.h: New file. * include/grecs/mem.h: New file. * include/grecs/node.h: New file. * include/grecs/parser.h: New file. * include/grecs/preproc.h: New file. * include/grecs/sockaddr.h: New file. * include/grecs/symtab.h: New file. * include/grecs/table.h: New file. * include/grecs/tree.h: New file. * include/grecs/txtacc.h: New file. * include/grecs/types.h.in: New file. * include/grecs/util.h: New file. * include/grecs/value.h: New file. * include/grecs/version.h: New file. * src/grecs-locus.h: Move to ... * include/grecs/locus.h: ... here * src/grecsopt.h: Move to ... * include/grecs/opt.h: ... here * src/json.h: Move to ... * include/grecs/json.h: ... here * src/wordsplit.h: Move to ... * include/wordsplit.h: ... here * src/Make-inst.am (include_HEADERS): Remove. * src/Make-shared.am (grecsinclude_HEADERS) (noinst_HEADERS): Remove. * src/Make-static.am (noinst_HEADERS): Remove. * src/Make.am: Remove header-related stuff * src/bind-gram.y: Fix includes. * src/bind-lex.l: Likewise. * src/cidr.c: Likewise. * src/dhcpd-gram.y: Likewise. * src/dhcpd-lex.l: Likewise. * src/diag.c: Likewise. * src/format.c: Likewise. * src/grecs-gram.y: Likewise. * src/grecs-lex.l: Likewise. * src/json-gram.y: Likewise. * src/json-lex.l: Likewise. * src/jsonfmt.c: Likewise. * src/lookup.c: Likewise. * src/meta1-gram.y: Likewise. * src/meta1-lex.l: Likewise. * src/opthelp.c: Likewise. * src/preproc.c: Likewise. * src/sockaddr.c: Likewise. * src/txtacc.c: Likewise. * src/version.c: Likewise. * tests/gcfenum.c: Likewise. * tests/gcffmt.c: Likewise. * tests/gcfpeek.c: Likewise. * tests/gcfset.c: Likewise. * tests/gcfver.c: Likewise. * tests/json.c: Likewise.

Return to:

Send suggestions and report system problems to the System administrator.