annotate toys/sed.c @ 234:163498bf547b

Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:43:27 -0600
parents d4176f3f3835
children 7cb15eae1664
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
2 *
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * sed.c - Stream editor.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
5 * Copyright 2008 Rob Landley <rob@landley.net>
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
6 *
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
8
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
9 USE_SED(NEWTOY(sed, "irne*", TOYFLAG_BIN))
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
10
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
11 config SED
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
12 bool "sed"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
13 default n
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
14 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
15 usage: sed [-irn] {command | [-e command]...} [FILE...]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
16
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
17 Stream EDitor, transforms text by appling commands to each line
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
18 of input.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
19 */
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
20
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 #include "toys.h"
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #include "lib/xregcomp.h"
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
23
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 struct sed_command {
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 // Doubly linked list of commands.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 struct sed_command *next, *prev;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
27
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 // Regexes for s/match/data/ and /match_begin/,/match_end/command
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 regex_t *match, *match_begin, *match_end;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
30
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 // For numeric ranges ala 10,20command
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 int first_line, last_line;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
33
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 // Which match to replace, 0 for all.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 int which;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
36
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 // s and w commands can write to a file. Slight optimization: we use 0
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 // instead of -1 to mean no file here, because even when there's no stdin
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 // our input file would take fd 0.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 int outfd;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
41
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 // Data string for (saicytb)
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 char *data;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
44
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 // Which command letter is this?
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 char command;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 };
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
48
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
49 #define TT toy.sed
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
50
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 void sed_main(void)
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 {
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 struct arg_list *test;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
54
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 for (test = TT.commands; test; test = test->next)
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 dprintf(2,"command=%s\n",test->arg);
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
57
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 printf("Hello world\n");
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 }