diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-01 11:14:58 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-01 11:14:58 +0300 |
commit | 78b25d9756403fef919684738f7aecb2cdcee465 (patch) | |
tree | d43f312f8f994be9d485dcc9c7c8ded3f415898f /lib/forlan.c | |
parent | f2ce145a8d27d18db064fc35313b7495f868b18b (diff) | |
download | eclat-78b25d9756403fef919684738f7aecb2cdcee465.tar.gz eclat-78b25d9756403fef919684738f7aecb2cdcee465.tar.bz2 |
Implement get-console-output command.
* etc/Makefile.am: Add new files.
* etc/get-console-output.fln: New file.
* lib/forlan.c: New built-in function "decode".
* lib/forlangrm.y: Fix grammar to allow functions to
return any data type, not only node.
* src/Makefile.am (eclat_SOURCES): Add new files.
* src/eclat.c: Register get-console-output command.
* src/eclat.h (eclat_get_console_output): New proto.
* src/getconout.c: New file.
* tests/Makefile.am: Add new files.
* tests/testsuite.at: Include new files.
* tests/decode.at: New test case.
* tests/get-console-output.at: New test case.
* tests/last.at: Minor change.
Diffstat (limited to 'lib/forlan.c')
-rw-r--r-- | lib/forlan.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/forlan.c b/lib/forlan.c index 6c4a44a..f12e00b 100644 --- a/lib/forlan.c +++ b/lib/forlan.c @@ -808,12 +808,40 @@ func_sort(forlan_eval_env_t env, struct grecs_list *list) grecs_tree_sort(val->v.node, node_ident_cmp); } +void +func_decode(forlan_eval_env_t env, struct grecs_list *list) +{ + struct forlan_value *val = list->head->data; + struct grecs_txtacc *acc = grecs_txtacc_create(); + char *p; + + for (p = val->v.string; *p; ) { + size_t ilen, olen; + unsigned char *optr; + + while (*p && isspace(*p)) + p++; + if (!*p) + break; + ilen = strcspn(p, " \t\f\n"); + eclat_base64_decode(p, ilen, &optr, &olen); + grecs_txtacc_grow(acc, optr, olen); + free(optr); + + p += ilen; + } + grecs_txtacc_grow_char(acc, 0); + env->retval.v.string = grecs_txtacc_finish(acc, 1); + grecs_txtacc_free(acc); +} + static struct forlan_function functab[] = { { "dump", forlan_value_void, "n", 1, 1, func_dump }, { "print", forlan_value_void, "", 1, -1, func_print }, { "error", forlan_value_void, "", 1, -1, func_error }, { "parent", forlan_value_node, "n", 1, 1, func_parent }, { "sort", forlan_value_void, "n", 1, 1, func_sort }, + { "decode", forlan_value_literal, "s", 1, 1, func_decode }, { NULL } }; |