blob: 397533990ea4d3894be0a8ffc3707cc313858505 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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");
}
|