Mercurial > hg > toybox
comparison toys/posix/sed.c @ 653:2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 14:25:22 -0500 |
parents | toys/sed.c@7cb15eae1664 |
children | 6df4ccc0acbe |
comparison
equal
deleted
inserted
replaced
652:2d7c56913fda | 653:2986aa63a021 |
---|---|
1 /* vi: set sw=4 ts=4: | |
2 * | |
3 * sed.c - Stream editor. | |
4 * | |
5 * Copyright 2008 Rob Landley <rob@landley.net> | |
6 * | |
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c | |
8 | |
9 USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN)) | |
10 | |
11 config 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 */ | |
20 | |
21 #include "toys.h" | |
22 #include "lib/xregcomp.h" | |
23 | |
24 DEFINE_GLOBALS( | |
25 struct arg_list *commands; | |
26 ) | |
27 | |
28 #define TT this.sed | |
29 | |
30 struct 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 | |
55 void 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 } |