Mercurial > hg > toybox
annotate toys/pending/sed.c @ 808:c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 24 Feb 2013 13:48:15 -0600 |
parents | 134d337ea880 |
children | 63db77909fc8 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
1 /* sed.c - Stream editor. |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
231
diff
changeset
|
2 * |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
3 * Copyright 2012 Rob Landley <rob@landley.net> |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
231
diff
changeset
|
4 * |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
5 * See http://opengroup.org/onlinepubs/9699919799/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
|
6 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
7 USE_SED(NEWTOY(sed, "irne*f*", TOYFLAG_BIN)) |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
8 |
233
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 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
10 bool "sed" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
11 default n |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
12 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
13 usage: sed [-irn] {command | [-e command]...} [FILE...] |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
231
diff
changeset
|
14 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
15 Stream EDitor, transforms text by appling script of command to each line |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
16 of input. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
17 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
18 -e Add expression to the command script (if no -e, use first argument) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
19 -i Modify file in place |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
20 -n No default output (p commands only) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
21 -r Use extended regular expression syntex |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
231
diff
changeset
|
22 */ |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
24 #define FOR_sed |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 #include "toys.h" |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 #include "lib/xregcomp.h" |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
28 GLOBALS( |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
29 struct arg_list *files; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
30 struct arg_list *scripts; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
31 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
32 void *commands; |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
33 ) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
34 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
35 // Digested version of what sed commands can actually tell use to do. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
36 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
37 |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 struct sed_command { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
39 // double_list compatibility (easier to create in-order) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
40 struct sed_command *next, *prev; |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
42 // data string for (saicytb) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
43 char c, *data; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
44 // Regexes for s/match/data/ and /begin/,/end/command |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
45 regex_t *rmatch, *rbegin, *rend; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
46 // For numeric ranges ala 10,20command |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
47 long lstart, lstop; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
48 // Which match to replace, 0 for all. s and w commands can write to a file |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
49 int which, outfd; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
50 }; |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
52 // Space. Space. Gotta get past space. Spaaaaaaaace! (But not newline.) |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
53 static void spaceorb(char **s) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
54 { |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
55 while (**s == ' ' || **s == '\t') ++*s; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
56 } |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
58 // Parse sed commands |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
59 |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
60 static void parse_scripts(void) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
61 { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
62 struct arg_list *script; |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
63 int which = 0, i; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
64 |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
65 // Loop through list of scripts collated from command line and/or files |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
66 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
67 for (script = TT.scripts; script; script = script->next) { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
68 char *str = script->arg; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
69 struct sed_command *cmd; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
70 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
71 // we can get multiple commands from a string (semicolons and such) |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
72 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
73 which++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
74 for (i=1;;) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
75 if (!*str) break; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
76 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
77 cmd = xzalloc(sizeof(struct sed_command)); |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
79 // Identify prefix |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
80 for (;;) { |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
81 spaceorb(&str); |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
82 if (*str == '^') { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
83 if (cmd->lstart) goto parse_fail; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
84 cmd->lstart = -1; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
85 str++; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
86 continue; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
87 } else if (*str == '$') { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
88 cmd->lstop = LONG_MAX; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
89 str++; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
90 break; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
91 } else if (isdigit(*str)) { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
92 long ll = strtol(str, &str, 10); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
93 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
94 if (ll<0) goto parse_fail; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
95 if (cmd->lstart) { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
96 cmd->lstop = ll; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
97 break; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
98 } else cmd->lstart = ll; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
99 } else if (*str == '/' || *str == '\\') { |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
100 // set begin/end |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
101 printf("regex\n"); |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
102 exit(1); |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
103 } else if (!cmd->lstart && !cmd->rbegin) break; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
104 else goto parse_fail; // , with no range after it |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
106 spaceorb(&str); |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
107 if (*str != ',') break; |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
108 str++; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
109 } |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
110 i = stridx("{bcdDgGhHlnNpPstwxyrqia= \t#:}", *str); |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
111 if (i == -1) goto parse_fail; |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
113 dlist_add_nomalloc((struct double_list **)&TT.commands, |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
114 (struct double_list *)cmd); |
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
115 exit(1); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
116 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
117 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
118 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
119 return; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
120 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
121 parse_fail: |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
122 error_exit("bad expression %d@%d: %s", which, i, script->arg+i); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
123 } |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 void sed_main(void) |
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
127 char **files=toys.optargs; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
128 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
129 // If no -e, use first argument |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
130 if (!TT.scripts) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
131 if (!*files) error_exit("Need script"); |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
132 (TT.scripts = xzalloc(sizeof(struct arg_list)))->arg = *(files++); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
133 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
134 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
135 parse_scripts(); |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 |
808
c6eb6208c9b9
Sed's still just a stub, but clean it up enough so it at least compiles.
Rob Landley <rob@landley.net>
parents:
803
diff
changeset
|
137 while (*files) dprintf(2,"file=%s\n", *(files++)); |
231
31dc682c18ad
Very early stub of sed, does nothing yet.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 } |