blob: c4eb1a44be6584c274e0a60432026248307d0043 [file] [log] [blame]
Rob Landley28964802008-01-19 17:08:39 -06001/* vi: set sw=4 ts=4:
2 *
Rob Landley6a9e5b42008-01-10 14:34:15 -06003 * sed.c - Stream editor.
4 *
Rob Landley28964802008-01-19 17:08:39 -06005 * Copyright 2008 Rob Landley <rob@landley.net>
6 *
Rob Landley6a9e5b42008-01-10 14:34:15 -06007 * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c
Rob Landley28964802008-01-19 17:08:39 -06008
Rob Landley55928b12008-01-19 17:43:27 -06009USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN))
10
Rob Landley28964802008-01-19 17:08:39 -060011config SED
12 bool "sed"
13 default n
14 help
15 usage: sed [-irn] {command | [-e command]...} [FILE...]
16
17 Stream EDitor, transforms text by appling commands to each line
18 of input.
19*/
Rob Landley6a9e5b42008-01-10 14:34:15 -060020
21#include "toys.h"
22#include "lib/xregcomp.h"
23
Rob Landleyb1aaba12008-01-20 17:25:44 -060024DEFINE_GLOBALS(
25 struct arg_list *commands;
26)
27
28#define TT this.sed
29
Rob Landley6a9e5b42008-01-10 14:34:15 -060030struct sed_command {
31 // Doubly linked list of commands.
32 struct sed_command *next, *prev;
33
34 // Regexes for s/match/data/ and /match_begin/,/match_end/command
35 regex_t *match, *match_begin, *match_end;
36
37 // For numeric ranges ala 10,20command
38 int first_line, last_line;
39
40 // Which match to replace, 0 for all.
41 int which;
42
43 // s and w commands can write to a file. Slight optimization: we use 0
44 // instead of -1 to mean no file here, because even when there's no stdin
45 // our input file would take fd 0.
46 int outfd;
47
48 // Data string for (saicytb)
49 char *data;
50
51 // Which command letter is this?
52 char command;
53};
54
Rob Landley6a9e5b42008-01-10 14:34:15 -060055void sed_main(void)
56{
57 struct arg_list *test;
58
59 for (test = TT.commands; test; test = test->next)
60 dprintf(2,"command=%s\n",test->arg);
61
62 printf("Hello world\n");
63}