diff options
author | Rob Landley <rob@landley.net> | 2008-01-10 14:34:15 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2008-01-10 14:34:15 -0600 |
commit | 6a9e5b4654e76585e38c6c6002eccba9b4b1b310 (patch) | |
tree | ec7422e6973812bd09f1b781197330f5c9c7c326 /toys | |
parent | bd9155198f000037ec5b9d1e4ef26eae80bbb202 (diff) | |
download | toybox-6a9e5b4654e76585e38c6c6002eccba9b4b1b310.tar.gz |
Very early stub of sed, does nothing yet.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/Config.in | 9 | ||||
-rw-r--r-- | toys/sed.c | 46 | ||||
-rw-r--r-- | toys/toylist.h | 14 |
3 files changed, 65 insertions, 4 deletions
diff --git a/toys/Config.in b/toys/Config.in index 4fabd6ef..f1083233 100644 --- a/toys/Config.in +++ b/toys/Config.in @@ -330,6 +330,15 @@ config READLINK_F -f Show full cannonical path, with no symlinks in it. Returns nonzero if nothing could currently exist at this location. +config SED + bool "sed" + default n + help + usage: sed [-irn] {command | [-e command]...} [FILE...] + + Stream EDitor, transforms text by appling commands to each line + of input. + config SHA1SUM bool "sha1sum" default y diff --git a/toys/sed.c b/toys/sed.c new file mode 100644 index 00000000..39753399 --- /dev/null +++ b/toys/sed.c @@ -0,0 +1,46 @@ +/* vi: set sw=4 ts=4: */ +/* + * sed.c - Stream editor. + * + * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c + */ + +#include "toys.h" +#include "lib/xregcomp.h" + +#define TT toy.sed + +struct sed_command { + // Doubly linked list of commands. + struct sed_command *next, *prev; + + // Regexes for s/match/data/ and /match_begin/,/match_end/command + regex_t *match, *match_begin, *match_end; + + // For numeric ranges ala 10,20command + int first_line, last_line; + + // Which match to replace, 0 for all. + int which; + + // s and w commands can write to a file. Slight optimization: we use 0 + // instead of -1 to mean no file here, because even when there's no stdin + // our input file would take fd 0. + int outfd; + + // Data string for (saicytb) + char *data; + + // Which command letter is this? + char command; +}; + +void sed_main(void) +{ + struct arg_list *test; + + for (test = TT.commands; test; test = test->next) + dprintf(2,"command=%s\n",test->arg); + + printf("Hello world\n"); +} diff --git a/toys/toylist.h b/toys/toylist.h index 2dd8620f..1f01c547 100644 --- a/toys/toylist.h +++ b/toys/toylist.h @@ -53,6 +53,10 @@ struct mke2fs_data { struct ext2_superblock sb; }; +struct mkfifo_data { + char *mode; +}; + struct netcat_data { char *filename; // -f read from filename instead of network long quit_delay; // -q Exit after EOF from stdin after # seconds. @@ -77,6 +81,10 @@ struct patch_data { char *tempname, *oldname; }; +struct sed_data { + struct arg_list *commands; +}; + struct sleep_data { long seconds; }; @@ -91,10 +99,6 @@ struct toysh_data { char *command; }; -struct mkfifo_data { - char *mode; -}; - extern union toy_union { struct dmesg_data dmesg; struct df_data df; @@ -103,6 +107,7 @@ extern union toy_union { struct netcat_data netcat; struct oneit_data oneit; struct patch_data patch; + struct sed_data sed; struct sleep_data sleep; struct touch_data touch; struct toysh_data toysh; @@ -155,6 +160,7 @@ USE_ONEIT(NEWTOY(oneit, "+<1c:p", TOYFLAG_SBIN)) USE_PATCH(NEWTOY(patch, "up#i:R", TOYFLAG_USR|TOYFLAG_BIN)) USE_PWD(NEWTOY(pwd, NULL, TOYFLAG_BIN)) USE_READLINK(NEWTOY(readlink, "<1f", TOYFLAG_BIN)) +USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN)) USE_TOYSH(OLDTOY(sh, toysh, "c:i", TOYFLAG_BIN)) USE_SHA1SUM(NEWTOY(sha1sum, NULL, TOYFLAG_USR|TOYFLAG_BIN)) USE_SLEEP(NEWTOY(sleep, "<1", TOYFLAG_BIN)) |