mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Run fix-third-party.py and man2txt on sed
This commit is contained in:
parent
f0bf9f3389
commit
2227cefa5d
14 changed files with 735 additions and 214 deletions
1
Makefile
1
Makefile
|
@ -158,6 +158,7 @@ include third_party/maxmind/maxmind.mk
|
|||
include net/finger/finger.mk
|
||||
include third_party/double-conversion/double-conversion.mk
|
||||
include third_party/lua/lua.mk
|
||||
include third_party/sed/sed.mk
|
||||
include third_party/awk/awk.mk
|
||||
include third_party/make/make.mk
|
||||
include third_party/finger/finger.mk
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef LIBC_ISYSTEM_LIMITS_H_
|
||||
#define LIBC_ISYSTEM_LIMITS_H_
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/_posix.h"
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#ifndef LIBC_ISYSTEM_WCHAR_H_
|
||||
#define LIBC_ISYSTEM_WCHAR_H_
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/unicode.h"
|
||||
#include "libc/time/time.h"
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define S_IREAD 0000400 /* just use octal */
|
||||
#define S_IEXEC 0000100 /* just use octal */
|
||||
#define S_IWRITE 0000200 /* just use octal */
|
||||
#define S_ISTXT 0001000 /* just use octal */
|
||||
|
||||
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(mode) (((mode)&S_IFMT) == S_IFCHR)
|
||||
|
@ -37,4 +38,8 @@
|
|||
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)
|
||||
|
||||
#define S_BLKSIZE 512
|
||||
#define ALLPERMS (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_ */
|
||||
|
|
22
third_party/awk/main.c
vendored
22
third_party/awk/main.c
vendored
|
@ -108,26 +108,32 @@ getarg(int *argc, char ***argv, const char *msg)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *fs = NULL;
|
||||
struct sigaction sa;
|
||||
char *fn, *vn;
|
||||
|
||||
LoadZipArgs(&argc, &argv);
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
|
||||
cmdname = argv[0];
|
||||
|
||||
if (pledge("stdio rpath wpath cpath proc exec", NULL) == -1) {
|
||||
fprintf(stderr, "%s: pledge: incorrect arguments\n",
|
||||
cmdname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
fprintf(stderr,
|
||||
"usage: %s [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]\n",
|
||||
cmdname);
|
||||
exit(1);
|
||||
}
|
||||
{
|
||||
struct sigaction sa;
|
||||
sa.sa_sigaction = fpecatch;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
(void)sigaction(SIGFPE, &sa, NULL);
|
||||
}
|
||||
/*signal(SIGSEGV, segvcatch); experiment */
|
||||
|
||||
sa.sa_sigaction = fpecatch;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
(void)sigaction(SIGFPE, &sa, NULL);
|
||||
|
||||
/* Set and keep track of the random seed */
|
||||
srand_seed = 1;
|
||||
|
|
386
third_party/sed/README
vendored
Normal file
386
third_party/sed/README
vendored
Normal file
|
@ -0,0 +1,386 @@
|
|||
|
||||
SED(1) BSD General Commands Manual SED(1)
|
||||
|
||||
𝐍𝐀𝐌𝐄
|
||||
𝘀𝗲𝗱 — stream editor
|
||||
|
||||
𝐒𝐘𝐍𝐎𝐏𝐒𝐈𝐒
|
||||
𝘀𝗲𝗱 [-𝗮𝐄𝗹𝗻𝗿𝘂] c̲o̲m̲m̲a̲n̲d̲ [f̲i̲l̲e̲ .̲.̲.̲]
|
||||
𝘀𝗲𝗱 [-𝗮𝐄𝗹𝗻𝗿𝘂] [-𝗲 c̲o̲m̲m̲a̲n̲d̲] [-𝗳 c̲o̲m̲m̲a̲n̲d̲_f̲i̲l̲e̲] [-𝐈[e̲x̲t̲e̲n̲s̲i̲o̲n̲]]
|
||||
[-𝗶[e̲x̲t̲e̲n̲s̲i̲o̲n̲]] [f̲i̲l̲e̲ .̲.̲.̲]
|
||||
|
||||
𝐃𝐄𝐒𝐂𝐑𝐈𝐏𝐓𝐈𝐎𝐍
|
||||
The 𝘀𝗲𝗱 utility reads the specified files, or the standard input if no
|
||||
files are specified, modifying the input as specified by a list of com‐
|
||||
mands. The input is then written to the standard output.
|
||||
|
||||
A single command may be specified as the first argument to 𝘀𝗲𝗱. Multiple
|
||||
commands may be specified by using the -𝗲 or -𝗳 options. All commands are
|
||||
applied to the input in the order they are specified regardless of their
|
||||
origin.
|
||||
|
||||
The following options are available:
|
||||
|
||||
-𝗮 The files listed as parameters for the “w” functions are created
|
||||
(or truncated) before any processing begins, by default. The -𝗮
|
||||
option causes 𝘀𝗲𝗱 to delay opening each file until a command con‐
|
||||
taining the related “w” function is applied to a line of input.
|
||||
|
||||
-𝐄 Interpret regular expressions as extended (modern) regular expres‐
|
||||
sions rather than basic regular expressions (BRE's). The
|
||||
re_format(7) manual page fully describes both formats.
|
||||
|
||||
-𝗲 c̲o̲m̲m̲a̲n̲d̲
|
||||
Append the editing commands specified by the c̲o̲m̲m̲a̲n̲d̲ argument to
|
||||
the list of commands.
|
||||
|
||||
-𝗳 c̲o̲m̲m̲a̲n̲d̲_f̲i̲l̲e̲
|
||||
Append the editing commands found in the file c̲o̲m̲m̲a̲n̲d̲_f̲i̲l̲e̲ to the
|
||||
list of commands. The editing commands should each be listed on a
|
||||
separate line.
|
||||
|
||||
-𝐈[e̲x̲t̲e̲n̲s̲i̲o̲n̲]
|
||||
Edit files in-place, saving backups with the specified e̲x̲t̲e̲n̲s̲i̲o̲n̲.
|
||||
If no e̲x̲t̲e̲n̲s̲i̲o̲n̲ is given, no backup will be saved. It is not rec‐
|
||||
ommended to give a zero-length e̲x̲t̲e̲n̲s̲i̲o̲n̲ when in-place editing
|
||||
files, as you risk corruption or partial content in situations
|
||||
where disk space is exhausted, etc.
|
||||
|
||||
Note that in-place editing with -𝐈 still takes place in a single
|
||||
continuous line address space covering all files, although each
|
||||
file preserves its individuality instead of forming one output
|
||||
stream. The line counter is never reset between files, address
|
||||
ranges can span file boundaries, and the “$” address matches only
|
||||
the last line of the last file. (See S̲e̲d̲ A̲d̲d̲r̲e̲s̲s̲e̲s̲.) That can
|
||||
lead to unexpected results in many cases of in-place editing, where
|
||||
using -𝗶 is desired.
|
||||
|
||||
-𝗶[e̲x̲t̲e̲n̲s̲i̲o̲n̲]
|
||||
Edit files in-place similarly to -𝐈, but treat each file indepen‐
|
||||
dently from other files. In particular, line numbers in each file
|
||||
start at 1, the “$” address matches the last line of the current
|
||||
file, and address ranges are limited to the current file. (See S̲e̲d̲
|
||||
A̲d̲d̲r̲e̲s̲s̲e̲s̲.) The net result is as though each file were edited by a
|
||||
separate 𝘀𝗲𝗱 instance.
|
||||
|
||||
-𝗹 Make output line buffered.
|
||||
|
||||
-𝗻 By default, each line of input is echoed to the standard output af‐
|
||||
ter all of the commands have been applied to it. The -𝗻 option
|
||||
suppresses this behavior.
|
||||
|
||||
-𝗿 Same as -𝐄 for compatibility with GNU sed.
|
||||
|
||||
-𝘂 Make output unbuffered.
|
||||
|
||||
The form of a 𝘀𝗲𝗱 command is as follows:
|
||||
|
||||
[address[,address]]function[arguments]
|
||||
|
||||
Whitespace may be inserted before the first address and the function por‐
|
||||
tions of the command.
|
||||
|
||||
Normally, 𝘀𝗲𝗱 cyclically copies a line of input, not including its termi‐
|
||||
nating newline character, into a p̲a̲t̲t̲e̲r̲n̲ s̲p̲a̲c̲e̲, (unless there is something
|
||||
left after a “D” function), applies all of the commands with addresses that
|
||||
select that pattern space, copies the pattern space to the standard output,
|
||||
appending a newline, and deletes the pattern space.
|
||||
|
||||
Some of the functions use a h̲o̲l̲d̲ s̲p̲a̲c̲e̲ to save all or part of the pattern
|
||||
space for subsequent retrieval.
|
||||
|
||||
𝐒𝗲𝗱 𝐀𝗱𝗱𝗿𝗲𝘀𝘀𝗲𝘀
|
||||
An address is not required, but if specified must have one of the following
|
||||
formats:
|
||||
|
||||
• a number that counts input lines cumulatively across input files
|
||||
(or in each file independently if a -𝗶 option is in effect);
|
||||
|
||||
• a dollar (“$”) character that addresses the last line of input
|
||||
(or the last line of the current file if a -𝗶 option was speci‐
|
||||
fied);
|
||||
|
||||
• a context address that consists of a regular expression preceded
|
||||
and followed by a delimiter. The closing delimiter can also op‐
|
||||
tionally be followed by the “i” character, to indicate that the
|
||||
regular expression is to be matched in a case-insensitive way.
|
||||
|
||||
A command line with no addresses selects every pattern space.
|
||||
|
||||
A command line with one address selects all of the pattern spaces that
|
||||
match the address.
|
||||
|
||||
A command line with two addresses selects an inclusive range. This range
|
||||
starts with the first pattern space that matches the first address. The
|
||||
end of the range is the next following pattern space that matches the sec‐
|
||||
ond address. If the second address is a number less than or equal to the
|
||||
line number first selected, only that line is selected. The number in the
|
||||
second address may be prefixed with a (“+”) to specify the number of lines
|
||||
to match after the first pattern. In the case when the second address is a
|
||||
context address, 𝘀𝗲𝗱 does not re-match the second address against the pat‐
|
||||
tern space that matched the first address. Starting at the first line fol‐
|
||||
lowing the selected range, 𝘀𝗲𝗱 starts looking again for the first address.
|
||||
|
||||
Editing commands can be applied to non-selected pattern spaces by use of
|
||||
the exclamation character (“!”) function.
|
||||
|
||||
𝐒𝗲𝗱 𝐑𝗲𝗴𝘂𝗹𝗮𝗿 𝐄𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻𝘀
|
||||
The regular expressions used in 𝘀𝗲𝗱, by default, are basic regular expres‐
|
||||
sions (BREs, see re_format(7) for more information), but extended (modern)
|
||||
regular expressions can be used instead if the -𝐄 flag is given. In addi‐
|
||||
tion, 𝘀𝗲𝗱 has the following two additions to regular expressions:
|
||||
|
||||
1. In a context address, any character other than a backslash (“\”) or
|
||||
newline character may be used to delimit the regular expression. The
|
||||
opening delimiter needs to be preceded by a backslash unless it is a
|
||||
slash. For example, the context address \xabcx is equivalent to
|
||||
/abc/. Also, putting a backslash character before the delimiting
|
||||
character within the regular expression causes the character to be
|
||||
treated literally. For example, in the context address \xabc\xdefx,
|
||||
the RE delimiter is an “x” and the second “x” stands for itself, so
|
||||
that the regular expression is “abcxdef”.
|
||||
|
||||
2. The escape sequence \n matches a newline character embedded in the
|
||||
pattern space. You cannot, however, use a literal newline character
|
||||
in an address or in the substitute command.
|
||||
|
||||
One special feature of 𝘀𝗲𝗱 regular expressions is that they can default to
|
||||
the last regular expression used. If a regular expression is empty, i.e.,
|
||||
just the delimiter characters are specified, the last regular expression
|
||||
encountered is used instead. The last regular expression is defined as the
|
||||
last regular expression used as part of an address or substitute command,
|
||||
and at run-time, not compile-time. For example, the command “/abc/s//XXX/”
|
||||
will substitute “XXX” for the pattern “abc”.
|
||||
|
||||
𝐒𝗲𝗱 𝐅𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀
|
||||
In the following list of commands, the maximum number of permissible ad‐
|
||||
dresses for each command is indicated by [0addr], [1addr], or [2addr], rep‐
|
||||
resenting zero, one, or two addresses.
|
||||
|
||||
The argument t̲e̲x̲t̲ consists of one or more lines. To embed a newline in the
|
||||
text, precede it with a backslash. Other backslashes in text are deleted
|
||||
and the following character taken literally.
|
||||
|
||||
The “r” and “w” functions take an optional file parameter, which should be
|
||||
separated from the function letter by white space. Each file given as an
|
||||
argument to 𝘀𝗲𝗱 is created (or its contents truncated) before any input
|
||||
processing begins.
|
||||
|
||||
The “b”, “r”, “s”, “t”, “w”, “y”, “!”, and “:” functions all accept addi‐
|
||||
tional arguments. The following synopses indicate which arguments have to
|
||||
be separated from the function letters by white space characters.
|
||||
|
||||
Two of the functions take a function-list. This is a list of 𝘀𝗲𝗱 functions
|
||||
separated by newlines, as follows:
|
||||
|
||||
{ function
|
||||
function
|
||||
...
|
||||
function
|
||||
}
|
||||
|
||||
The “{” can be preceded by white space and can be followed by white space.
|
||||
The function can be preceded by white space. The terminating “}” must be
|
||||
preceded by a newline, and may also be preceded by white space.
|
||||
|
||||
[2addr] function-list
|
||||
Execute function-list only when the pattern space is selected.
|
||||
|
||||
[1addr]a\
|
||||
text Write t̲e̲x̲t̲ to standard output immediately before each attempt to
|
||||
read a line of input, whether by executing the “N” function or by
|
||||
beginning a new cycle.
|
||||
|
||||
[2addr]b[label]
|
||||
Branch to the “:” function with the specified label. If the label
|
||||
is not specified, branch to the end of the script.
|
||||
|
||||
[2addr]c\
|
||||
text Delete the pattern space. With 0 or 1 address or at the end of a
|
||||
2-address range, t̲e̲x̲t̲ is written to the standard output.
|
||||
|
||||
[2addr]d
|
||||
Delete the pattern space and start the next cycle.
|
||||
|
||||
[2addr]D
|
||||
Delete the initial segment of the pattern space through the first
|
||||
newline character and start the next cycle.
|
||||
|
||||
[2addr]g
|
||||
Replace the contents of the pattern space with the contents of the
|
||||
hold space.
|
||||
|
||||
[2addr]G
|
||||
Append a newline character followed by the contents of the hold
|
||||
space to the pattern space.
|
||||
|
||||
[2addr]h
|
||||
Replace the contents of the hold space with the contents of the
|
||||
pattern space.
|
||||
|
||||
[2addr]H
|
||||
Append a newline character followed by the contents of the pattern
|
||||
space to the hold space.
|
||||
|
||||
[1addr]i\
|
||||
text Write t̲e̲x̲t̲ to the standard output.
|
||||
|
||||
[2addr]l
|
||||
(The letter ell.) Write the pattern space to the standard output
|
||||
in a visually unambiguous form. This form is as follows:
|
||||
|
||||
backslash \\
|
||||
alert \a
|
||||
form-feed \f
|
||||
carriage-return \r
|
||||
tab \t
|
||||
vertical tab \v
|
||||
|
||||
Nonprintable characters are written as three-digit octal numbers
|
||||
(with a preceding backslash) for each byte in the character (most
|
||||
significant byte first). Long lines are folded, with the point of
|
||||
folding indicated by displaying a backslash followed by a newline.
|
||||
The end of each line is marked with a “$”.
|
||||
|
||||
[2addr]n
|
||||
Write the pattern space to the standard output if the default out‐
|
||||
put has not been suppressed, and replace the pattern space with the
|
||||
next line of input.
|
||||
|
||||
[2addr]N
|
||||
Append the next line of input to the pattern space, using an embed‐
|
||||
ded newline character to separate the appended material from the
|
||||
original contents. Note that the current line number changes.
|
||||
|
||||
[2addr]p
|
||||
Write the pattern space to standard output.
|
||||
|
||||
[2addr]P
|
||||
Write the pattern space, up to the first newline character to the
|
||||
standard output.
|
||||
|
||||
[1addr]q
|
||||
Branch to the end of the script and quit without starting a new cy‐
|
||||
cle.
|
||||
|
||||
[1addr]r file
|
||||
Copy the contents of f̲i̲l̲e̲ to the standard output immediately before
|
||||
the next attempt to read a line of input. If f̲i̲l̲e̲ cannot be read
|
||||
for any reason, it is silently ignored and no error condition is
|
||||
set.
|
||||
|
||||
[2addr]s/regular expression/replacement/flags
|
||||
Substitute the replacement string for the first instance of the
|
||||
regular expression in the pattern space. Any character other than
|
||||
backslash or newline can be used instead of a slash to delimit the
|
||||
RE and the replacement. Within the RE and the replacement, the RE
|
||||
delimiter itself can be used as a literal character if it is pre‐
|
||||
ceded by a backslash.
|
||||
|
||||
An ampersand (“&”) appearing in the replacement is replaced by the
|
||||
string matching the RE. The special meaning of “&” in this context
|
||||
can be suppressed by preceding it by a backslash. The string “\#”,
|
||||
where “#” is a digit, is replaced by the text matched by the corre‐
|
||||
sponding backreference expression (see re_format(7)).
|
||||
|
||||
A line can be split by substituting a newline character into it.
|
||||
To specify a newline character in the replacement string, precede
|
||||
it with a backslash.
|
||||
|
||||
The value of f̲l̲a̲g̲s̲ in the substitute function is zero or more of
|
||||
the following:
|
||||
|
||||
N̲ Make the substitution only for the N̲'th occurrence of
|
||||
the regular expression in the pattern space.
|
||||
|
||||
g Make the substitution for all non-overlapping matches
|
||||
of the regular expression, not just the first one.
|
||||
|
||||
p Write the pattern space to standard output if a re‐
|
||||
placement was made. If the replacement string is
|
||||
identical to that which it replaces, it is still con‐
|
||||
sidered to have been a replacement.
|
||||
|
||||
w f̲i̲l̲e̲ Append the pattern space to f̲i̲l̲e̲ if a replacement was
|
||||
made. If the replacement string is identical to that
|
||||
which it replaces, it is still considered to have
|
||||
been a replacement.
|
||||
|
||||
i or I Match the regular expression in a case-insensitive
|
||||
way.
|
||||
|
||||
[2addr]t [label]
|
||||
Branch to the “:” function bearing the label if any substitutions
|
||||
have been made since the most recent reading of an input line or
|
||||
execution of a “t” function. If no label is specified, branch to
|
||||
the end of the script.
|
||||
|
||||
[2addr]w f̲i̲l̲e̲
|
||||
Append the pattern space to the f̲i̲l̲e̲.
|
||||
|
||||
[2addr]x
|
||||
Swap the contents of the pattern and hold spaces.
|
||||
|
||||
[2addr]y/string1/string2/
|
||||
Replace all occurrences of characters in s̲t̲r̲i̲n̲g̲1̲ in the pattern
|
||||
space with the corresponding characters from s̲t̲r̲i̲n̲g̲2̲. Any charac‐
|
||||
ter other than a backslash or newline can be used instead of a
|
||||
slash to delimit the strings. Within s̲t̲r̲i̲n̲g̲1̲ and s̲t̲r̲i̲n̲g̲2̲, a back‐
|
||||
slash followed by any character other than a newline is that lit‐
|
||||
eral character, and a backslash followed by an ``n'' is replaced by
|
||||
a newline character.
|
||||
|
||||
[2addr]!function
|
||||
[2addr]!function-list
|
||||
Apply the function or function-list only to the lines that are n̲o̲t̲
|
||||
selected by the address(es).
|
||||
|
||||
[0addr]:label
|
||||
This function does nothing; it bears a label to which the “b” and
|
||||
“t” commands may branch.
|
||||
|
||||
[1addr]=
|
||||
Write the line number to the standard output followed by a newline
|
||||
character.
|
||||
|
||||
[0addr]
|
||||
Empty lines are ignored.
|
||||
|
||||
[0addr]#
|
||||
The “#” and the remainder of the line are ignored (treated as a
|
||||
comment), with the single exception that if the first two charac‐
|
||||
ters in the file are “#n”, the default output is suppressed. This
|
||||
is the same as specifying the -𝗻 option on the command line.
|
||||
|
||||
𝐄𝐍𝐕𝐈𝐑𝐎𝐍𝐌𝐄𝐍𝐓
|
||||
The COLUMNS, LANG, LC_ALL, LC_CTYPE and LC_COLLATE environment variables
|
||||
affect the execution of 𝘀𝗲𝗱 as described in environ(7).
|
||||
|
||||
𝐄𝐗𝐈𝐓 𝐒𝐓𝐀𝐓𝐔𝐒
|
||||
The 𝘀𝗲𝗱 utility exits 0 on success, and >0 if an error occurs.
|
||||
|
||||
𝐒𝐄𝐄 𝐀𝐋𝐒𝐎
|
||||
awk(1), ed(1), grep(1), regex(3), re_format(7)
|
||||
|
||||
𝐒𝐓𝐀𝐍𝐃𝐀𝐑𝐃𝐒
|
||||
The 𝘀𝗲𝗱 utility is expected to be a superset of the IEEE Std 1003.2
|
||||
(“POSIX.2”) specification.
|
||||
|
||||
The -𝗮, -𝐄, -𝐈, and -𝗶 options, the prefixing “+” in the second member of
|
||||
an address range, as well as the “I” flag to the address regular expression
|
||||
and substitution command are non-standard FreeBSD extensions and may not be
|
||||
available on other operating systems.
|
||||
|
||||
𝐇𝐈𝐒𝐓𝐎𝐑𝐘
|
||||
A 𝘀𝗲𝗱 command, written by L. E. McMahon, appeared in Version 7 AT&T UNIX.
|
||||
|
||||
𝐀𝐔𝐓𝐇𝐎𝐑𝐒
|
||||
Diomidis D. Spinellis <dds@FreeBSD.org>
|
||||
|
||||
𝐁𝐔𝐆𝐒
|
||||
Multibyte characters containing a byte with value 0x5C (ASCII ‘\’) may be
|
||||
incorrectly treated as line continuation characters in arguments to the
|
||||
“a”, “c” and “i” commands. Multibyte characters cannot be used as delim‐
|
||||
iters with the “s” and “y” commands.
|
||||
|
||||
BSD June 18, 2014 BSD
|
94
third_party/sed/compile.c
vendored
94
third_party/sed/compile.c
vendored
|
@ -1,3 +1,4 @@
|
|||
// clang-format off
|
||||
/* $NetBSD: compile.c,v 1.48 2019/10/05 20:23:55 christos Exp $ */
|
||||
|
||||
/*-
|
||||
|
@ -33,36 +34,53 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: compile.c,v 1.48 2019/10/05 20:23:55 christos Exp $");
|
||||
#ifdef __FBSDID
|
||||
__FBSDID("$FreeBSD: head/usr.bin/sed/compile.c 259132 2013-12-09 18:57:20Z eadler $");
|
||||
#endif
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/log/bsd.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/_posix.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
#if 0
|
||||
static const char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "extern.h"
|
||||
#include "third_party/sed/defs.h"
|
||||
#include "third_party/sed/extern.h"
|
||||
|
||||
#define LHSZ 128
|
||||
#define LHMASK (LHSZ - 1)
|
||||
|
@ -163,7 +181,7 @@ compile_stream(struct s_command **link)
|
|||
static char lbuf[_POSIX2_LINE_MAX + 1]; /* To save stack */
|
||||
struct s_command *cmd, *cmd2, *stack;
|
||||
struct s_format *fp;
|
||||
char re[_POSIX2_LINE_MAX + 1];
|
||||
char *re = gc(malloc(_POSIX2_LINE_MAX + 1));
|
||||
int naddr; /* Number of addresses */
|
||||
|
||||
stack = 0;
|
||||
|
@ -548,9 +566,15 @@ unescape(char **pp, char **spp)
|
|||
case 'r':
|
||||
*sp = '\r';
|
||||
break;
|
||||
case 't':
|
||||
*sp = '\t';
|
||||
break;
|
||||
case 'v':
|
||||
*sp = '\v';
|
||||
break;
|
||||
case 'e':
|
||||
*sp = '\e';
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -791,8 +815,8 @@ compile_tr(char *p, struct s_tr **py)
|
|||
struct s_tr *y;
|
||||
size_t i;
|
||||
const char *op, *np;
|
||||
char old[_POSIX2_LINE_MAX + 1];
|
||||
char new[_POSIX2_LINE_MAX + 1];
|
||||
char *old = gc(malloc(_POSIX2_LINE_MAX + 1));
|
||||
char *new = gc(malloc(_POSIX2_LINE_MAX + 1));
|
||||
size_t oclen, oldlen, nclen, newlen;
|
||||
mbstate_t mbs1, mbs2;
|
||||
|
||||
|
@ -816,11 +840,11 @@ compile_tr(char *p, struct s_tr **py)
|
|||
op = old;
|
||||
oldlen = mbsrtowcs(NULL, &op, 0, NULL);
|
||||
if (oldlen == (size_t)-1)
|
||||
err(1, NULL);
|
||||
err(1, "");
|
||||
np = new;
|
||||
newlen = mbsrtowcs(NULL, &np, 0, NULL);
|
||||
if (newlen == (size_t)-1)
|
||||
err(1, NULL);
|
||||
err(1, "");
|
||||
if (newlen != oldlen)
|
||||
errx(1, "%lu: %s: transform strings are not the same length",
|
||||
linenum, fname);
|
||||
|
@ -848,10 +872,10 @@ compile_tr(char *p, struct s_tr **py)
|
|||
while (*op != '\0') {
|
||||
oclen = mbrlen(op, MB_LEN_MAX, &mbs1);
|
||||
if (oclen == (size_t)-1 || oclen == (size_t)-2)
|
||||
errc(1, EILSEQ, NULL);
|
||||
err(1, "EILSEQ");
|
||||
nclen = mbrlen(np, MB_LEN_MAX, &mbs2);
|
||||
if (nclen == (size_t)-1 || nclen == (size_t)-2)
|
||||
errc(1, EILSEQ, NULL);
|
||||
err(1, "EILSEQ");
|
||||
if (oclen == 1 && nclen == 1)
|
||||
y->bytetab[(u_char)*op] = (u_char)*np;
|
||||
else {
|
||||
|
|
49
third_party/sed/defs.h
vendored
49
third_party/sed/defs.h
vendored
|
@ -1,40 +1,11 @@
|
|||
/* $NetBSD: defs.h,v 1.13 2020/05/15 22:39:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Diomidis Spinellis.
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Diomidis Spinellis of Imperial College, University of London.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)defs.h 8.1 (Berkeley) 6/6/93
|
||||
* $FreeBSD: head/usr.bin/sed/defs.h 192732 2009-05-25 06:45:33Z brian $
|
||||
*/
|
||||
#ifndef COSMOPOLITAN_THIRD_PARTY_SED_DEFS_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_SED_DEFS_H_
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/limits.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
* Types of address specifications
|
||||
|
@ -149,3 +120,7 @@ typedef struct {
|
|||
char *back; /* Backing memory. */
|
||||
size_t blen; /* Backing memory length. */
|
||||
} SPACE;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_SED_DEFS_H_ */
|
||||
|
|
50
third_party/sed/extern.h
vendored
50
third_party/sed/extern.h
vendored
|
@ -1,40 +1,12 @@
|
|||
/* $NetBSD: extern.h,v 1.20 2015/03/12 12:40:41 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992 Diomidis Spinellis.
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Diomidis Spinellis of Imperial College, University of London.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.1 (Berkeley) 6/6/93
|
||||
* $FreeBSD: head/usr.bin/sed/extern.h 170608 2007-06-12 12:05:24Z yar $
|
||||
*/
|
||||
#ifndef COSMOPOLITAN_THIRD_PARTY_SED_EXTERN_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_SED_EXTERN_H_
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
#include "third_party/sed/defs.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
// clang-format off
|
||||
|
||||
extern struct s_command *prog;
|
||||
extern struct s_appends *appends;
|
||||
|
@ -59,3 +31,7 @@ char *strregerror(int, regex_t *);
|
|||
void *xmalloc(size_t);
|
||||
void *xrealloc(void *, size_t);
|
||||
void *xcalloc(size_t, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_SED_EXTERN_H_ */
|
||||
|
|
121
third_party/sed/main.c
vendored
121
third_party/sed/main.c
vendored
|
@ -1,3 +1,4 @@
|
|||
// clang-format off
|
||||
/* $NetBSD: main.c,v 1.36 2020/05/15 22:39:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
|
@ -34,46 +35,84 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/mlock.h"
|
||||
#include "libc/sysv/consts/msync.h"
|
||||
#include "libc/sysv/consts/posix.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/madv.h"
|
||||
#include "libc/sysv/consts/mfd.h"
|
||||
#include "libc/sysv/consts/mremap.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/rusage.h"
|
||||
#include "libc/calls/sysparam.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
#include "libc/sysv/consts/prio.h"
|
||||
#include "libc/sysv/consts/rlim.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/sysv/consts/rusage.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/time/time.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: main.c,v 1.36 2020/05/15 22:39:54 christos Exp $");
|
||||
#ifdef __FBSDID
|
||||
__FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $");
|
||||
#endif
|
||||
#include "libc/log/bsd.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
// MISSING #include <libgen.h>
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/_posix.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static const char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <regex.h>
|
||||
#include <stddef.h>
|
||||
#define _WITH_GETLINE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
|
||||
#include "defs.h"
|
||||
#include "extern.h"
|
||||
#include "third_party/sed/defs.h"
|
||||
#include "third_party/sed/extern.h"
|
||||
|
||||
/*
|
||||
* Linked list of units (strings and files) to be compiled
|
||||
|
@ -127,7 +166,7 @@ u_long linenum;
|
|||
|
||||
static void add_compunit(enum e_cut, char *);
|
||||
static void add_file(char *);
|
||||
static void usage(void) __dead;
|
||||
static void usage(void) wontreturn;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
|
@ -135,7 +174,6 @@ main(int argc, char *argv[])
|
|||
int c, fflag;
|
||||
char *temp_arg;
|
||||
|
||||
setprogname(argv[0]);
|
||||
(void) setlocale(LC_ALL, "");
|
||||
|
||||
fflag = 0;
|
||||
|
@ -148,7 +186,7 @@ main(int argc, char *argv[])
|
|||
rflags = REG_EXTENDED;
|
||||
break;
|
||||
case 'I':
|
||||
inplace = optarg ? optarg : __UNCONST("");
|
||||
inplace = optarg ? optarg : (/*unconst*/char *)"";
|
||||
ispan = 1; /* span across input files */
|
||||
break;
|
||||
case 'a':
|
||||
|
@ -166,7 +204,7 @@ main(int argc, char *argv[])
|
|||
add_compunit(CU_FILE, optarg);
|
||||
break;
|
||||
case 'i':
|
||||
inplace = optarg ? optarg : __UNCONST("");
|
||||
inplace = optarg ? optarg : (/*unconst*/char *)"";
|
||||
ispan = 0; /* don't span across input files */
|
||||
break;
|
||||
case 'l':
|
||||
|
@ -225,7 +263,8 @@ usage(void)
|
|||
(void)fprintf(stderr,
|
||||
"Usage: %s [-aElnru] command [file ...]\n"
|
||||
"\t%s [-aElnru] [-e command] [-f command_file] [-I[extension]]\n"
|
||||
"\t [-i[extension]] [file ...]\n", getprogname(), getprogname());
|
||||
"\t [-i[extension]] [file ...]\n", program_invocation_name,
|
||||
program_invocation_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
52
third_party/sed/misc.c
vendored
52
third_party/sed/misc.c
vendored
|
@ -1,3 +1,4 @@
|
|||
// clang-format off
|
||||
/* $NetBSD: misc.c,v 1.15 2014/06/26 02:14:32 christos Exp $ */
|
||||
|
||||
/*-
|
||||
|
@ -33,31 +34,36 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: misc.c,v 1.15 2014/06/26 02:14:32 christos Exp $");
|
||||
#ifdef __FBSDID
|
||||
__FBSDID("$FreeBSD: head/usr.bin/sed/misc.c 200462 2009-12-13 03:14:06Z delphij $");
|
||||
#endif
|
||||
#include "libc/log/bsd.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/_posix.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#if 0
|
||||
static const char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "extern.h"
|
||||
#include "third_party/sed/defs.h"
|
||||
#include "third_party/sed/extern.h"
|
||||
|
||||
/*
|
||||
* malloc with result test
|
||||
|
|
98
third_party/sed/process.c
vendored
98
third_party/sed/process.c
vendored
|
@ -1,3 +1,4 @@
|
|||
// clang-format off
|
||||
/* $NetBSD: process.c,v 1.53 2020/05/15 22:39:54 christos Exp $ */
|
||||
|
||||
/*-
|
||||
|
@ -33,40 +34,71 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
#include "libc/calls/makedev.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/calls/typedef/u.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/stat.macros.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/s.h"
|
||||
#include "libc/sysv/consts/utime.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/calls/struct/winsize.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/fio.h"
|
||||
#include "libc/sysv/consts/modem.h"
|
||||
#include "libc/sysv/consts/pty.h"
|
||||
#include "libc/sysv/consts/sio.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
#include "libc/str/unicode.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: process.c,v 1.53 2020/05/15 22:39:54 christos Exp $");
|
||||
#ifdef __FBSDID
|
||||
__FBSDID("$FreeBSD: head/usr.bin/sed/process.c 192732 2009-05-25 06:45:33Z brian $");
|
||||
#endif
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/log/bsd.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sysv/consts/_posix.h"
|
||||
#include "third_party/regex/regex.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "third_party/getopt/getopt.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#if 0
|
||||
static const char sccsid[] = "@(#)process.c 8.6 (Berkeley) 4/20/94";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "extern.h"
|
||||
#include "third_party/sed/defs.h"
|
||||
#include "third_party/sed/extern.h"
|
||||
|
||||
static SPACE HS, PS, SS, YS;
|
||||
#define pd PS.deleted
|
||||
|
@ -554,7 +586,7 @@ flush_appends(void)
|
|||
{
|
||||
FILE *f;
|
||||
size_t count, i;
|
||||
char buf[8 * 1024];
|
||||
char *buf = gc(malloc(8 * 1024));
|
||||
|
||||
for (i = 0; i < appendx; i++)
|
||||
switch (appends[i].type) {
|
||||
|
|
68
third_party/sed/sed.mk
vendored
Normal file
68
third_party/sed/sed.mk
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
PKGS += THIRD_PARTY_SED
|
||||
|
||||
THIRD_PARTY_SED_SRCS = $(THIRD_PARTY_SED_A_SRCS)
|
||||
THIRD_PARTY_SED_HDRS = $(THIRD_PARTY_SED_A_HDRS)
|
||||
THIRD_PARTY_SED_INCS = $(THIRD_PARTY_SED_A_INCS)
|
||||
THIRD_PARTY_SED_BINS = $(THIRD_PARTY_SED_COMS) $(THIRD_PARTY_SED_COMS:%=%.dbg)
|
||||
THIRD_PARTY_SED_COMS = o/$(MODE)/third_party/sed/sed.com
|
||||
|
||||
THIRD_PARTY_SED_ARTIFACTS += THIRD_PARTY_SED_A
|
||||
THIRD_PARTY_SED = $(THIRD_PARTY_SED_A_DEPS) $(THIRD_PARTY_SED_A)
|
||||
THIRD_PARTY_SED_A = o/$(MODE)/third_party/sed/sed.a
|
||||
THIRD_PARTY_SED_A_FILES := $(wildcard third_party/sed/*)
|
||||
THIRD_PARTY_SED_A_HDRS = $(filter %.h,$(THIRD_PARTY_SED_A_FILES))
|
||||
THIRD_PARTY_SED_A_INCS = $(filter %.inc,$(THIRD_PARTY_SED_A_FILES))
|
||||
THIRD_PARTY_SED_A_SRCS = $(filter %.c,$(THIRD_PARTY_SED_A_FILES))
|
||||
THIRD_PARTY_SED_A_OBJS = $(THIRD_PARTY_SED_A_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
THIRD_PARTY_SED_A_DIRECTDEPS = \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_CALLS \
|
||||
LIBC_STDIO \
|
||||
LIBC_SYSV \
|
||||
LIBC_STR \
|
||||
LIBC_LOG \
|
||||
LIBC_STUBS \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_REGEX
|
||||
|
||||
THIRD_PARTY_SED_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_SED_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
THIRD_PARTY_SED_A_CHECKS = \
|
||||
$(THIRD_PARTY_SED_A).pkg \
|
||||
$(THIRD_PARTY_SED_A_HDRS:%=o/$(MODE)/%.ok)
|
||||
|
||||
$(THIRD_PARTY_SED_A): \
|
||||
third_party/sed/ \
|
||||
$(THIRD_PARTY_SED_A).pkg \
|
||||
$(THIRD_PARTY_SED_A_OBJS)
|
||||
|
||||
$(THIRD_PARTY_SED_A).pkg: \
|
||||
$(THIRD_PARTY_SED_A_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_SED_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/third_party/sed/sed.com.dbg: \
|
||||
$(THIRD_PARTY_SED) \
|
||||
o/$(MODE)/third_party/sed/main.o \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
THIRD_PARTY_SED_LIBS = $(foreach x,$(THIRD_PARTY_SED_ARTIFACTS),$($(x)))
|
||||
THIRD_PARTY_SED_SRCS = $(foreach x,$(THIRD_PARTY_SED_ARTIFACTS),$($(x)_SRCS))
|
||||
THIRD_PARTY_SED_CHECKS = $(foreach x,$(THIRD_PARTY_SED_ARTIFACTS),$($(x)_CHECKS))
|
||||
THIRD_PARTY_SED_OBJS = $(foreach x,$(THIRD_PARTY_SED_ARTIFACTS),$($(x)_OBJS))
|
||||
$(THIRD_PARTY_SED_OBJS): $(BUILD_FILES) third_party/sed/sed.mk
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/sed
|
||||
o/$(MODE)/third_party/sed: \
|
||||
$(THIRD_PARTY_SED_BINS) \
|
||||
$(THIRD_PARTY_SED_CHECKS)
|
1
third_party/third_party.mk
vendored
1
third_party/third_party.mk
vendored
|
@ -25,6 +25,7 @@ o/$(MODE)/third_party: \
|
|||
o/$(MODE)/third_party/regex \
|
||||
o/$(MODE)/third_party/smallz4 \
|
||||
o/$(MODE)/third_party/sqlite3 \
|
||||
o/$(MODE)/third_party/sed \
|
||||
o/$(MODE)/third_party/stb \
|
||||
o/$(MODE)/third_party/tidy \
|
||||
o/$(MODE)/third_party/unzip \
|
||||
|
|
Loading…
Reference in a new issue