Commit graph

94 commits

Author SHA1 Message Date
Sergey Poznyakoff
85ece41c6d Use size_t for wordc
* src/wordsplit.c (wordsplit_getwords): Word count is size_t
* src/wordsplit.h (wordsplit_getwords): Fix proto.
2016-01-21 08:19:17 +02:00
Sergey Poznyakoff
6d2bc16d3d Bugfix in test suite
* tests/wsp.c (make_env_kv): Fix array size
2015-12-19 16:59:50 +02:00
Sergey Poznyakoff
cb100a7faa Minor improvement
* src/wordsplit.h (WRDSX_WORD, WRDSX_QUOTE): New defines.
* src/wordsplit.c: Use them when initializing ws_escape.
2015-12-17 15:26:56 +02:00
Sergey Poznyakoff
6dba42a631 Update copyright years 2015-12-17 15:26:55 +02:00
Sergey Poznyakoff
cadf077236 Fix ws trimming and return_delim option
* 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-17 15:26:28 +02:00
Sergey Poznyakoff
1939ae3326 Minor fixes in documentation 2015-12-17 15:26:28 +02:00
Sergey Poznyakoff
3fca27c20b Minor fixes
* doc/wordsplit.3: Fix some wording.
* tests/wordsplit.at (TESTWSP): Generate unique keywords.
2015-12-17 15:26:28 +02:00
Sergey Poznyakoff
b712b11eef Improve docs, add new function
* 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-17 15:26:28 +02:00
Sergey Poznyakoff
943d725e7f Finish wordsplit docs, improve tests 2015-12-17 15:26:28 +02:00
Sergey Poznyakoff
9bebcfbc1c Implement default assignments, etc.
* 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-17 15:26:28 +02:00
Sergey Poznyakoff
73180a045d Improve wordsplit documentation and debug output. 2015-12-17 15:25:24 +02:00
Sergey Poznyakoff
731d730447 Test pathname expansion 2015-12-17 15:25:24 +02:00
Sergey Poznyakoff
00301604fd Various improvements
* 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-17 15:25:24 +02:00
Sergey Poznyakoff
08d3154b58 Implement tilde and pathname expansion
* 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-17 15:25:24 +02:00
Sergey Poznyakoff
b591f0aee6 Perform quote removal before command substitution 2015-12-17 15:25:24 +02:00
Sergey Poznyakoff
74ec801338 Cleanup. 2015-12-17 15:25:24 +02:00
Sergey Poznyakoff
6da71ddacb Fix variable expansion within commands
* 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-17 15:25:24 +02:00
Sergey Poznyakoff
4650905537 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.
2015-12-17 15:25:24 +02:00
Sergey Poznyakoff
2795912aa5 Implement command expansion
* 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-17 15:25:24 +02:00
Sergey Poznyakoff
83a979b74a Update copyright dates. 2015-12-17 15:24:37 +02:00
Sergey Poznyakoff
ff39e877ee Minor change
* tests/wsp.c (main): use additional variable to keep the
allocated value in incremental mode.
2015-12-17 15:24:37 +02:00
Sergey Poznyakoff
3ad0ad462c Fix the "alternate value" test 2015-12-17 15:24:37 +02:00
Sergey Poznyakoff
b834e13ac4 Test ws_getvar/ws_closure functionality.
* tests/wsp.c (help): Update.
(wsp_getvar): New function.
(main): Callect all arguments in form X=Y to an array
and set ws_getvar member if this array is not empty.
* tests/wordsplit.at: Add tests for ws_getenv function.
2015-12-17 15:24:37 +02:00
Sergey Poznyakoff
07a7d68690 Fix expansion of ${...}
* 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-17 15:24:37 +02:00
Sergey Poznyakoff
e082c9923e Support ${x:-word}, ${x:+word} and ${x:?word}
* src/wordsplit.c (expvar): Support default value.
2015-12-17 15:24:37 +02:00
Sergey Poznyakoff
9765ed3720 ws_getvar allocates memory
* 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-17 15:24:37 +02:00
Sergey Poznyakoff
29fb748305 Add wordsplit test (from mailutils)
* tests/wordsplit.at: New testcase.
* tests/wsp.c: New test program.
2015-12-17 15:22:41 +02:00
Sergey Poznyakoff
6e9ebcab71 Remove unused variable 2015-12-16 22:24:55 +02:00
Sergey Poznyakoff
d650c4bfcc * src/wordsplit.c (coalesce_segment): Fix null pointer dereference.
(wordsplit_perror): Add missing break.
2013-02-26 16:35:53 +02:00
Sergey Poznyakoff
55bf2d1d61 Synchronize wordsplit with the Mailutils version. 2012-01-13 23:11:56 +02:00
Sergey Poznyakoff
dd69afd04e Happy GNU Year 2012-01-03 13:31:36 +02:00
Sergey Poznyakoff
259f2874b3 Bugfix
* src/wordsplit.c (quote_transtab): Translate \"
2011-05-15 14:05:39 +03:00
Sergey Poznyakoff
4037b168f0 Merge branch 'master' of ssh://git.gnu.org.ua/gitroot/grecs 2011-05-05 14:41:55 +03:00
Sergey Poznyakoff
f234fe6789 Minor whitespace cleanup 2011-05-03 21:23:25 +03:00
Sergey Poznyakoff
6dec4f0a01 Update copyright years. Add docs. 2011-05-01 18:01:03 +03:00
Sergey Poznyakoff
67c1b9be95 Bugfix.
* src/wordsplit.c [ENABLE_NLS]: include gettext.h
2011-04-30 18:57:54 +03:00
Sergey Poznyakoff
d34f74c01c Minor fix 2011-04-18 22:23:24 +03:00
Sergey Poznyakoff
f43a26a3fa Apply fixes from Mailutils
* src/wordsplit.c: Apply fixes from Mailutils.
* src/wordsplit.h: Likewise.
2011-04-18 22:16:48 +03:00
Sergey Poznyakoff
5ebf70bffa Update copyright years.
Happy GNU Year!
2010-01-02 17:02:51 +02:00
Sergey Poznyakoff
9c5f3ad72c Minor fix
* src/wordsplit.c (scan_word): Ignore trailing whitespace.
2009-11-26 23:31:37 +02:00
Sergey Poznyakoff
52e27f35f0 Add missing include
* src/wordsplit.c: Include stdio.h
2009-10-19 18:46:31 +03:00
Sergey Poznyakoff
45b44769aa Fix handling of WRDSF_DOOFFS.
* src/wordsplit.c (wordsplit_init): Fix handling of WRDSF_DOOFFS.
2009-10-12 20:45:15 +03:00
Sergey Poznyakoff
9188468d31 Diverge from Wydawca gconf/ subdirectory into a separate project 2009-04-20 14:48:39 +03:00
Sergey Poznyakoff
271b3b3b63 Start writing wordsplit.
* gconf/wordsplit.c, gconf/wordsplit.h: New files.
* tests/wordsplit.at: New file.
* tests/wstest.c, tests/wsbatch.c: New files.
2009-03-11 12:36:26 +02:00