aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/sed.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
committerRob Landley <rob@landley.net>2012-08-25 14:25:22 -0500
commit3a9241add947cb6d24b5de7a8927517426a78795 (patch)
treed122ab6570439cd6b17c7d73ed8d4e085e0b8a95 /toys/posix/sed.c
parent689f095bc976417bf50810fe59a3b3ac32b21105 (diff)
downloadtoybox-3a9241add947cb6d24b5de7a8927517426a78795.tar.gz
Move commands into "posix", "lsb", and "other" menus/directories.
Diffstat (limited to 'toys/posix/sed.c')
-rw-r--r--toys/posix/sed.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
new file mode 100644
index 00000000..c4eb1a44
--- /dev/null
+++ b/toys/posix/sed.c
@@ -0,0 +1,63 @@
+/* vi: set sw=4 ts=4:
+ *
+ * sed.c - Stream editor.
+ *
+ * Copyright 2008 Rob Landley <rob@landley.net>
+ *
+ * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c
+
+USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN))
+
+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.
+*/
+
+#include "toys.h"
+#include "lib/xregcomp.h"
+
+DEFINE_GLOBALS(
+ struct arg_list *commands;
+)
+
+#define TT this.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");
+}