aboutsummaryrefslogtreecommitdiff
path: root/src/wordsplit.c
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-06-13BugfixSergey Poznyakoff1
* lib/wordsplit.c (_wsplt_store_errctx): Fix typo in the error message. (wsplt_assign_var): Fix a +1 offset of the ws_envidx field.
2019-06-05wordsplit: special handling for WRDSE_USAGE.Sergey Poznyakoff1
* src/wordsplit.c (wordsplit_run): Initialize ws_errctx early. This ensures that wordsplit_strerror gets correct data after WRDSE_USAGE. (wordsplit_free): Return immediately if errno was WRDSE_USAGE.
2019-05-16Minor fix.Sergey Poznyakoff1
* src/wordsplit.c (_wsplt_seterr_sub): Propagate error context.
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-15BugfixSergey Poznyakoff1
* src/wordsplit.c (wordsplit_finish): Fix typo. (wsplt_assign_param): Use _wsplt_seterr
2019-05-14Fix behaviour of $* and $@ in quoted contextSergey Poznyakoff1
2019-05-14wordsplit: whitespace cleanupSergey Poznyakoff1
2019-05-14wordsplit: implement $* and $@Sergey 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-05-13wordsplit: return single empty string on empty input in WRDSF_NOSPLIT modeSergey Poznyakoff1
* src/wordsplit.c (wordsplit_finish): Make sure at one non-null argument is always returned in WRDSF_NOSPLIT mode. * tests/wordsplit.at: Add new test.
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-07-31Minor fixes in wordsplitSergey Poznyakoff1
* src/wordsplit.c (find_closing_paren): paren is char const * (wsplt_unquote_char, wsplt_quote_char): mark as static (exptab) <descr>: mark as const.
2018-05-22Minor fixSergey Poznyakoff1
* src/wordsplit.c (wordsplit_run): Return consistent error code.
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-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-11-21BugfixesSergey Poznyakoff1
* src/jsonfmt.c (json_format_obj): Use grecs_symtab_count and grecs_symtab_foreach. * src/wordsplit.c: Always pass format strings as first argument to wsp->ws_error.
2016-07-04Update copyright yearsSergey Poznyakoff1
2016-02-23Reword some diagnosticsSergey Poznyakoff1
2016-01-21Implement grecs_list_compare; other minor fixes.Sergey Poznyakoff1
* src/grecs.hin (grecs_list_compare) (grecs_node_unlink): New protos. * src/list.c (grecs_list_compare): New function. * src/wordsplit.c (wordsplit_getwords): Word count is size_t * src/wordsplit.h (wordsplit_getwords): Fix proto.
2015-12-17Minor improvement in wordsplit.Sergey Poznyakoff1
* src/wordsplit.h (WRDSX_WORD, WRDSX_QUOTE): New defines. * src/wordsplit.c: Use them when initializing ws_escape.
2015-12-17Update copyright yearsSergey Poznyakoff1
2015-12-17wordsplit: fix ws trimming and return_delim optionSergey Poznyakoff1
* src/wordsplit.c (_WSNF_DELIM): New node flag (wsnode_flagstr): Print 'd' for that flag. (expvar): Don't set WRDSF_WS when expanding variable value. This fixes, e.g., expansion of a$x if x begins with a whitespace. (wsnode_nullelim): A _WSNF_DELIM node breaks join chain. (wordsplit_trimws): Don't affect nodes within join chains. (scan_word): Set _WSNF_DELIM for returned delimiters. * tests/wordsplit.at (TESTWSP): 8th argument - prologue shell code. Use it to unset environment variables in env/getenv tests. Test ws elimination with return_delims set.
2015-12-17wordsplit: improve docs, add new functionSergey Poznyakoff1
* src/wordsplit.c (wordsplit_getwords): New functon. * src/wordsplit.h (wordsplit_getwords): New proto. * doc/wordsplit.3: Add example section, document wordsplit_getwords.
2015-12-17Finish wordsplit docs, improve testsSergey Poznyakoff1
2015-12-17Improve wordsplitSergey Poznyakoff1
* src/wordsplit.c: Implement default assignment, word expansion in variable defaults, distinction between ${variable:-word} and ${variable-word}. * doc/wordsplit.3: New file. * src/wordsplit.h (wordsplit)<ws_envbuf,ws_envidx> <ws_envsiz>: New members. (WRDSF_ARGV): Remove. (WRDSF_OPTIONS): New flag. (WRDSO_ARGV): New option bit. * tests/wordsplit.at: Add new tests. * tests/wsp.c: Set WRDSF_OPTIONS flag if one of the options is requested.
2015-12-17Improve wordsplit documentation and debug output.Sergey Poznyakoff1
2015-12-17Various improvements in wordsplitSergey Poznyakoff1
* src/wordsplit.c (wordsplit_trimws): Retutn int. (wordsplit_tildexpand,wordsplit_pathexpand): Add missing return. (wordsplit_process_list): Rewrite in a table-driven fashion.
2015-12-17wordsplit: implement tilde and pathname expansionSergey Poznyakoff1
* src/wordsplit.c (wordsplit_tildexpand) (wordsplit_pathexpand): New functions. (wordsplit_process_list): Run tilde and pathname expansion if WRDSF_PATHEXPAND flag is set. * src/wordsplit.h (wordsplit)<ws_options>: New member. (WRDSF_PATHEXPAND): New flag. (WRDSO_NULLGLOB,WRDSO_FAILGLOB) (WRDSO_DOTGLOB): New defines. * tests/wsp.c: New options pathexpand, nullglob, failglob, dotglob. Fix help output.
2015-12-17wordsplit: perform quote removal before command substitutionSergey Poznyakoff1
2015-12-17cleanup in wordsplitSergey Poznyakoff1
2015-12-17wordsplit: fix variable expansion within commandsSergey Poznyakoff1
* src/wordsplit.c (_wsplt_seterr): New static function. Use instead of assigning value to ws_errno. (coalesce_segment): Propagate _WSNF_QUOTE flag to the resulting node. (wordsplit_process_list): Coalesce the list before running command expansion. * tests/testsuite.at: Test wordsplit first. If it fails, most other tests will fail too. * tests/wordsplit.at: Test command expansion.
2015-12-17Change prototypes of ws_getvar and ws_command.Sergey Poznyakoff1
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.
2015-12-17wordsplit: implement command expansionSergey Poznyakoff1
* src/wordsplit.c (wordsplit_init): Change handling of lacking WRDSF_NOCMD. (find_closing_cbrace): Rename to find_closing_paren, take additional argument. All uses changed. (node_expand_vars): Rewrite as a generalized function node_expand. (wordsplit_varexp): Use node_expand. (expcmd, wordsplit_cmdexp): New functions. (scan_word): Handle $(command) notation (wordsplit_process_list): Command expansion. * src/wordsplit.h (wordsplit) <ws_command>: New member. * tests/wsp.c (wsp_runcmd): New function. (main): Set ws_command unless WRDSF_NOCMD flag is set.
2015-12-17Update copyright dates.Sergey Poznyakoff1
2015-12-17wordsplit: Fix expansion of ${...}Sergey Poznyakoff1
* src/wordsplit.c (expvar): Ensure value is set. Pass WRDSF_QUOTE to wordsplit (scan_word): Treat ${...} as a single word. * tests/wordsplit.at: Add more tests. * tests/wsp.c: Fix error message.
2015-12-17wordsplit: support ${x:-word}, ${x:+word} and ${x:?word}Sergey Poznyakoff1
* src/wordsplit.c (expvar): Support default value.
2015-12-17wordsplit: ws_getvar allocates memory.Sergey Poznyakoff1
* src/wordsplit.c (ISVARBEG,ISVARCHR): New macros. (expvar): ws_getvar allocates memory. * src/wordsplit.h (wordsplit)<ws_getvar>: Remove const from the return value: the function should allocate memory.
2015-12-16Remove unused variableSergey Poznyakoff1
2013-02-26Introduce an alternative callback function calling convention.Sergey Poznyakoff1
Depending on the tree-api option to the GRECS_SETUP macro, the signature of callback functions changes. If the option is supplied, a pointer to grecs_node_t is passwd to callback functions as an argument instead of pointers to the value and locus. * am/grecs.m4 (GRECS_SETUP): New option tree-api. * src/.gitignore: Add grecs.h * src/Make.am: Build grecs.h * src/grecs.h: Rename to src/grecs.hin (GRECS_TREE_API): New define (grecs_callback_fn): Provide two alternative signatures depending on the value of GRECS_TREE_API. All uses updated. * src/tree.c (fake_callback): Update signature. (grecs_process_ident) (stmt_begin,stmt_end): Update calls to callback. * tests/gcfset.c: Likewise.
2012-01-13Synchronize wordsplit with the Mailutils version.Sergey Poznyakoff1
2012-01-03Happy GNU YearSergey Poznyakoff1
2011-05-15Provide a framework for multiple parsers. Implement meta1 parser.Sergey Poznyakoff1
* Makefile.am (EXTRA_DIST): Add build-aux/yyrename * am/grecs.m4: New options: parser-meta1 and all-parsers * src/.gitignore: Update. * src/Make.am [GRECS_COND_META1_PARSER]: Set GRECS_PARSER_META1 and GRECS_EXTRA_META1 (GRECS_SRC): Add new files. (EXTRA_DIST): Add GRECS_EXTRA_META1. (LEXCOMPILE,YACCCOMPILE): Redefine * src/grecs-gram.y: Don't include yygrecs.h (grecs_vasprintf,grecs_asprintf): Move to a separate file. (grecs_parse): Rename to grecs_grecs_parser. Actual grecs_parse is defined in parser.c (grecs_gram_trace): Move to parser.c * src/grecs-lex.l: Don't include yygrecs.h Use line_acc functions. * src/grecs.h (grecs_trace_flags): New extern. (GRECS_TRACE_GRAM, GRECS_TRACE_LEX): New flags. (grecs_lex_begin): Change signature. (grecs_grecs_parser,grecs_meta1_parser): New protos. (grecs_line_acc_create) (grecs_line_acc_free,grecs_line_acc_grow_char) (grecs_line_acc_grow_char_unescape) (grecs_line_acc_grow) (grecs_line_acc_grow_unescape_last): New protos. (GRECS_TXTACC_BUFSIZE): New const (grecs_txtacc_create,grecs_txtacc_free) (grecs_txtacc_grow,grecs_txtacc_finish) (grecs_txtacc_free_string): New protos. (grecs_value_match): New proto. * src/wordsplit.c (quote_transtab): Translate \" * src/yygrecs.h: Remove. * src/yytrans: New file. * build-aux/yyrename: New file. * src/asprintf.c: New file. * src/lineacc.c: New file. * src/meta1-gram.y: New file. * src/meta1-lex.l: New file. * src/parser.c: New file. * src/txtacc.c: New file. * doc/grecs_parse.3: Update. * doc/GRECS_SETUP.3: Update.
2011-05-01Update copyright years. Add docs.Sergey Poznyakoff1
2011-04-30Bugfixes and improvements.Sergey Poznyakoff1
* am/grecs.m4 (GRECS_INCLUDES): New substitute variable. * src/Makefile.am (INCLUDES): Add GRECS_INCLUDES. * src/grecs-gram.y: Remove leftover uses of xmalloc. * src/grecs.h (grecs_zalloc, grecs_calloc): New protos. * src/mem.c (grecs_zalloc, grecs_calloc): New functions. * src/wordsplit.c [ENABLE_NLS]: include gettext.h
2011-04-18Minor fixSergey Poznyakoff1

Return to:

Send suggestions and report system problems to the System administrator.