annotate toys/sed.c @ 233:d4176f3f3835

Zap toys/Config.in and instead create generated/Config.in from contents of toys/*.c. Move relevant info into comment at the top of each toys/*.c. Also convert more of Makefile into a thin wrapper around shell scripts that actually do the work. (Makefile is only still there for the user interface.)
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:08:39 -0600
parents 31dc682c18ad
children 163498bf547b
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
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
9 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
10 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
11 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
12 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
13 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
14
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
15 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
16 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
17 */
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 #include "toys.h"
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "lib/xregcomp.h"
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 struct sed_command {
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 // Doubly linked list of commands.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 struct sed_command *next, *prev;
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 // 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
27 regex_t *match, *match_begin, *match_end;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
28
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 // For numeric ranges ala 10,20command
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 int first_line, last_line;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
31
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 // Which match to replace, 0 for all.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 int which;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
34
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 // 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
36 // 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
37 // our input file would take fd 0.
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 int outfd;
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 // Data string for (saicytb)
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 char *data;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
42
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 // Which command letter is this?
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 char command;
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 };
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
46
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 231
diff changeset
47 #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
48
231
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 void sed_main(void)
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 {
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 struct arg_list *test;
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 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
54 dprintf(2,"command=%s\n",test->arg);
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
55
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 printf("Hello world\n");
31dc682c18ad Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 }