Mercurial > hg > toybox
annotate toys/sed.c @ 231:31dc682c18ad
Very early stub of sed, does nothing yet.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 10 Jan 2008 14:34:15 -0600 |
parents | |
children | d4176f3f3835 |
rev | line source |
---|---|
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* vi: set sw=4 ts=4: */ |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 /* |
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 * |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * See http://www.opengroup.org/onlinepubs/009695399/utilities/sed.c |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 */ |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 #include "toys.h" |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 #include "lib/xregcomp.h" |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 #define TT toy.sed |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 struct sed_command { |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 // Doubly linked list of commands. |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 struct sed_command *next, *prev; |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 // 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
|
18 regex_t *match, *match_begin, *match_end; |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 // For numeric ranges ala 10,20command |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 int first_line, last_line; |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 // Which match to replace, 0 for all. |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 int which; |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 // 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
|
27 // 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
|
28 // our input file would take fd 0. |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 int outfd; |
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 // Data string for (saicytb) |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 char *data; |
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 command letter is this? |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 char command; |
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 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 void sed_main(void) |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 { |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 struct arg_list *test; |
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 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
|
43 dprintf(2,"command=%s\n",test->arg); |
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 printf("Hello world\n"); |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 } |