mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Get awk to build and make it hackable
This commit is contained in:
parent
2f1679e5cf
commit
99a92048b4
19 changed files with 885 additions and 596 deletions
|
@ -654,7 +654,8 @@ typedef struct {
|
|||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if defined(__GNUC__) || defined(__llvm__)
|
||||
#pragma GCC diagnostic ignored "-Wundef" /* complaints about __ASSEMBLER__/__LINKER__ */
|
||||
#pragma GCC diagnostic ignored \
|
||||
"-Wundef" /* complaints about __ASSEMBLER__/__LINKER__ */
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare" /* lint needs to change */
|
||||
#pragma GCC diagnostic ignored "-Wtype-limits" /* makes macros unsafe */
|
||||
#pragma GCC diagnostic ignored "-Woverflow" /* also breaks macros */
|
||||
|
@ -733,7 +734,6 @@ typedef struct {
|
|||
#pragma GCC diagnostic error "-Wwrite-strings"
|
||||
#pragma GCC diagnostic error "-Wtrampolines"
|
||||
#pragma GCC diagnostic error "-Wmaybe-uninitialized"
|
||||
#pragma GCC diagnostic error "-Wredundant-decls"
|
||||
#if __GNUC__ >= 6
|
||||
#pragma GCC diagnostic error "-Wnonnull-compare"
|
||||
#if defined(COSMO) && !defined(MODE_DBG) && !defined(STACK_FRAME_UNLIMITED)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sicode.h"
|
||||
#endif
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define _STDIO_H
|
||||
#define L_ctermid 20
|
||||
#define FILENAME_MAX PATH_MAX
|
||||
#define FOPEN_MAX 1000
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
|
275
third_party/awk/README
vendored
Normal file
275
third_party/awk/README
vendored
Normal file
|
@ -0,0 +1,275 @@
|
|||
|
||||
AWK(1) General Commands Manual AWK(1)
|
||||
|
||||
|
||||
|
||||
𝐍𝐀𝐌𝐄
|
||||
awk - pattern-directed scanning and processing language
|
||||
|
||||
𝐒𝐘𝐍𝐎𝐏𝐒𝐈𝐒
|
||||
𝗮𝘄𝗸 [ -𝐅 f̲s̲ ] [ -𝘃 v̲a̲r̲=̲v̲a̲l̲u̲e̲ ] [ '̲p̲r̲o̲g̲'̲ | -𝗳 p̲r̲o̲g̲f̲i̲l̲e̲ ] [ f̲i̲l̲e̲ .̲.̲.̲ ]
|
||||
|
||||
𝐃𝐄𝐒𝐂𝐑𝐈𝐏𝐓𝐈𝐎𝐍
|
||||
A̲w̲k̲ scans each input f̲i̲l̲e̲ for lines that match any of a set of patterns
|
||||
specified literally in p̲r̲o̲g̲ or in one or more files specified as -𝗳 p̲r̲o̲g̲‐̲
|
||||
f̲i̲l̲e̲. With each pattern there can be an associated action that will be
|
||||
performed when a line of a f̲i̲l̲e̲ matches the pattern. Each line is
|
||||
matched against the pattern portion of every pattern-action statement;
|
||||
the associated action is performed for each matched pattern. The file
|
||||
name - means the standard input. Any f̲i̲l̲e̲ of the form v̲a̲r̲=̲v̲a̲l̲u̲e̲ is
|
||||
treated as an assignment, not a filename, and is executed at the time it
|
||||
would have been opened if it were a filename. The option -𝘃 followed by
|
||||
v̲a̲r̲=̲v̲a̲l̲u̲e̲ is an assignment to be done before p̲r̲o̲g̲ is executed; any number
|
||||
of -𝘃 options may be present. The -𝐅 f̲s̲ option defines the input field
|
||||
separator to be the regular expression f̲s̲.
|
||||
|
||||
An input line is normally made up of fields separated by white space, or
|
||||
by the regular expression 𝐅𝐒. The fields are denoted $𝟭, $𝟮, ..., while
|
||||
$𝟬 refers to the entire line. If 𝐅𝐒 is null, the input line is split
|
||||
into one field per character.
|
||||
|
||||
A pattern-action statement has the form:
|
||||
|
||||
p̲a̲t̲t̲e̲r̲n̲ { a̲c̲t̲i̲o̲n̲ }
|
||||
|
||||
A missing { a̲c̲t̲i̲o̲n̲ } means print the line; a missing pattern always
|
||||
matches. Pattern-action statements are separated by newlines or semi‐
|
||||
colons.
|
||||
|
||||
An action is a sequence of statements. A statement can be one of the
|
||||
following:
|
||||
|
||||
if( e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ) s̲t̲a̲t̲e̲m̲e̲n̲t̲ [ else s̲t̲a̲t̲e̲m̲e̲n̲t̲ ]
|
||||
while( e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ) s̲t̲a̲t̲e̲m̲e̲n̲t̲
|
||||
for( e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ; e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ; e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ) s̲t̲a̲t̲e̲m̲e̲n̲t̲
|
||||
for( v̲a̲r̲ in a̲r̲r̲a̲y̲ ) s̲t̲a̲t̲e̲m̲e̲n̲t̲
|
||||
do s̲t̲a̲t̲e̲m̲e̲n̲t̲ while( e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ )
|
||||
break
|
||||
continue
|
||||
{ [ s̲t̲a̲t̲e̲m̲e̲n̲t̲ .̲.̲.̲ ] }
|
||||
e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ # commonly v̲a̲r̲ =̲ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲
|
||||
print [ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲-̲l̲i̲s̲t̲ ] [ > e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ]
|
||||
printf f̲o̲r̲m̲a̲t̲ [ , e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲-̲l̲i̲s̲t̲ ] [ > e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ]
|
||||
return [ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ]
|
||||
next # skip remaining patterns on this input line
|
||||
nextfile # skip rest of this file, open next, start at top
|
||||
delete a̲r̲r̲a̲y̲[ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ]# delete an array element
|
||||
delete a̲r̲r̲a̲y̲ # delete all elements of array
|
||||
exit [ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ ] # exit immediately; status is e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲
|
||||
|
||||
Statements are terminated by semicolons, newlines or right braces. An
|
||||
empty e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲-̲l̲i̲s̲t̲ stands for $𝟬. String constants are quoted " ",
|
||||
with the usual C escapes recognized within. Expressions take on string
|
||||
or numeric values as appropriate, and are built using the operators + - *
|
||||
/ % ^ (exponentiation), and concatenation (indicated by white space).
|
||||
The operators ! ++ -- += -= *= /= %= ^= > >= < <= == != ?: are also
|
||||
available in expressions. Variables may be scalars, array elements (de‐
|
||||
noted x̲[i̲]) or fields. Variables are initialized to the null string.
|
||||
Array subscripts may be any string, not necessarily numeric; this allows
|
||||
for a form of associative memory. Multiple subscripts such as [𝗶,𝗷,𝗸]
|
||||
are permitted; the constituents are concatenated, separated by the value
|
||||
of 𝐒𝐔𝐁𝐒𝐄𝐏.
|
||||
|
||||
The 𝗽𝗿𝗶𝗻𝘁 statement prints its arguments on the standard output (or on a
|
||||
file if > f̲i̲l̲e̲ or >> f̲i̲l̲e̲ is present or on a pipe if | c̲m̲d̲ is present),
|
||||
separated by the current output field separator, and terminated by the
|
||||
output record separator. f̲i̲l̲e̲ and c̲m̲d̲ may be literal names or parenthe‐
|
||||
sized expressions; identical string values in different statements denote
|
||||
the same open file. The 𝗽𝗿𝗶𝗻𝘁𝗳 statement formats its expression list ac‐
|
||||
cording to the f̲o̲r̲m̲a̲t̲ (see p̲r̲i̲n̲t̲f̲(3)). The built-in function 𝗰𝗹𝗼𝘀𝗲(e̲x̲p̲r̲)
|
||||
closes the file or pipe e̲x̲p̲r̲. The built-in function 𝗳𝗳𝗹𝘂𝘀𝗵(e̲x̲p̲r̲) flushes
|
||||
any buffered output for the file or pipe e̲x̲p̲r̲.
|
||||
|
||||
The mathematical functions 𝗮𝘁𝗮𝗻𝟮, 𝗰𝗼𝘀, 𝗲𝘅𝗽, 𝗹𝗼𝗴, 𝘀𝗶𝗻, and 𝘀𝗾𝗿𝘁 are built
|
||||
in. Other built-in functions:
|
||||
|
||||
|
||||
𝗹𝗲𝗻𝗴𝘁𝗵 the length of its argument taken as a string, number of elements
|
||||
in an array for an array argument, or length of $𝟬 if no argu‐
|
||||
ment.
|
||||
𝗿𝗮𝗻𝗱 random number on [0,1).
|
||||
𝘀𝗿𝗮𝗻𝗱 sets seed for 𝗿𝗮𝗻𝗱 and returns the previous seed.
|
||||
𝗶𝗻𝘁 truncates to an integer value.
|
||||
𝘀𝘂𝗯𝘀𝘁𝗿(s̲, m̲ [, n̲])
|
||||
the n̲-character substring of s̲ that begins at position m̲ counted
|
||||
from 1. If no n̲, use the rest of the string.
|
||||
𝗶𝗻𝗱𝗲𝘅(s̲, t̲)
|
||||
the position in s̲ where the string t̲ occurs, or 0 if it does not.
|
||||
𝗺𝗮𝘁𝗰𝗵(s̲, r̲)
|
||||
the position in s̲ where the regular expression r̲ occurs, or 0 if
|
||||
it does not. The variables 𝐑𝐒𝐓𝐀𝐑𝐓 and 𝐑𝐋𝐄𝐍𝐆𝐓𝐇 are set to the po‐
|
||||
sition and length of the matched string.
|
||||
𝘀𝗽𝗹𝗶𝘁(s̲, a̲ [, f̲s̲])
|
||||
splits the string s̲ into array elements a̲[𝟭], a̲[𝟮], ..., a̲[n̲],
|
||||
and returns n̲. The separation is done with the regular expres‐
|
||||
sion f̲s̲ or with the field separator 𝐅𝐒 if f̲s̲ is not given. An
|
||||
empty string as field separator splits the string into one array
|
||||
element per character.
|
||||
𝘀𝘂𝗯(r̲, t̲ [, s̲])
|
||||
substitutes t̲ for the first occurrence of the regular expression
|
||||
r̲ in the string s̲. If s̲ is not given, $𝟬 is used.
|
||||
𝗴𝘀𝘂𝗯(r̲, t̲ [, s̲])
|
||||
same as 𝘀𝘂𝗯 except that all occurrences of the regular expression
|
||||
are replaced; 𝘀𝘂𝗯 and 𝗴𝘀𝘂𝗯 return the number of replacements.
|
||||
𝘀𝗽𝗿𝗶𝗻𝘁𝗳(f̲m̲t̲, e̲x̲p̲r̲, .̲.̲.̲)
|
||||
the string resulting from formatting e̲x̲p̲r̲ .̲.̲.̲ according to the
|
||||
p̲r̲i̲n̲t̲f̲(3) format f̲m̲t̲.
|
||||
𝘀𝘆𝘀𝘁𝗲𝗺(c̲m̲d̲)
|
||||
executes c̲m̲d̲ and returns its exit status. This will be -1 upon
|
||||
error, c̲m̲d̲'s exit status upon a normal exit, 256 + s̲i̲g̲ upon
|
||||
death-by-signal, where s̲i̲g̲ is the number of the murdering signal,
|
||||
or 512 + s̲i̲g̲ if there was a core dump.
|
||||
𝘁𝗼𝗹𝗼𝘄𝗲𝗿(s̲t̲r̲)
|
||||
returns a copy of s̲t̲r̲ with all upper-case characters translated
|
||||
to their corresponding lower-case equivalents.
|
||||
𝘁𝗼𝘂𝗽𝗽𝗲𝗿(s̲t̲r̲)
|
||||
returns a copy of s̲t̲r̲ with all lower-case characters translated
|
||||
to their corresponding upper-case equivalents.
|
||||
|
||||
The ``function'' 𝗴𝗲𝘁𝗹𝗶𝗻𝗲 sets $𝟬 to the next input record from the cur‐
|
||||
rent input file; 𝗴𝗲𝘁𝗹𝗶𝗻𝗲 < f̲i̲l̲e̲ sets $𝟬 to the next record from f̲i̲l̲e̲.
|
||||
𝗴𝗲𝘁𝗹𝗶𝗻𝗲 x̲ sets variable x̲ instead. Finally, c̲m̲d̲ | 𝗴𝗲𝘁𝗹𝗶𝗻𝗲 pipes the out‐
|
||||
put of c̲m̲d̲ into 𝗴𝗲𝘁𝗹𝗶𝗻𝗲; each call of 𝗴𝗲𝘁𝗹𝗶𝗻𝗲 returns the next line of
|
||||
output from c̲m̲d̲. In all cases, 𝗴𝗲𝘁𝗹𝗶𝗻𝗲 returns 1 for a successful input,
|
||||
0 for end of file, and -1 for an error.
|
||||
|
||||
Patterns are arbitrary Boolean combinations (with ! || &&) of regular ex‐
|
||||
pressions and relational expressions. Regular expressions are as in
|
||||
e̲g̲r̲e̲p̲; see g̲r̲e̲p̲(1). Isolated regular expressions in a pattern apply to
|
||||
the entire line. Regular expressions may also occur in relational ex‐
|
||||
pressions, using the operators ~ and !~. /r̲e̲/ is a constant regular ex‐
|
||||
pression; any string (constant or variable) may be used as a regular ex‐
|
||||
pression, except in the position of an isolated regular expression in a
|
||||
pattern.
|
||||
|
||||
A pattern may consist of two patterns separated by a comma; in this case,
|
||||
the action is performed for all lines from an occurrence of the first
|
||||
pattern though an occurrence of the second.
|
||||
|
||||
A relational expression is one of the following:
|
||||
|
||||
e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ m̲a̲t̲c̲h̲o̲p̲ r̲e̲g̲u̲l̲a̲r̲-̲e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲
|
||||
e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ r̲e̲l̲o̲p̲ e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲
|
||||
e̲x̲p̲r̲e̲s̲s̲i̲o̲n̲ 𝗶𝗻 a̲r̲r̲a̲y̲-̲n̲a̲m̲e̲
|
||||
(e̲x̲p̲r̲,e̲x̲p̲r̲,̲.̲.̲.̲) 𝗶𝗻 a̲r̲r̲a̲y̲-̲n̲a̲m̲e̲
|
||||
|
||||
where a r̲e̲l̲o̲p̲ is any of the six relational operators in C, and a m̲a̲t̲c̲h̲o̲p̲
|
||||
is either ~ (matches) or !~ (does not match). A conditional is an arith‐
|
||||
metic expression, a relational expression, or a Boolean combination of
|
||||
these.
|
||||
|
||||
The special patterns 𝐁𝐄𝐆𝐈𝐍 and 𝐄𝐍𝐃 may be used to capture control before
|
||||
the first input line is read and after the last. 𝐁𝐄𝐆𝐈𝐍 and 𝐄𝐍𝐃 do not
|
||||
combine with other patterns. They may appear multiple times in a program
|
||||
and execute in the order they are read by a̲w̲k̲.
|
||||
|
||||
Variable names with special meanings:
|
||||
|
||||
|
||||
𝐀𝐑𝐆𝐂 argument count, assignable.
|
||||
𝐀𝐑𝐆𝐕 argument array, assignable; non-null members are taken as file‐
|
||||
names.
|
||||
𝐂𝐎𝐍𝐕𝐅𝐌𝐓 conversion format used when converting numbers (default %.𝟲𝗴).
|
||||
𝐄𝐍𝐕𝐈𝐑𝐎𝐍 array of environment variables; subscripts are names.
|
||||
𝐅𝐈𝐋𝐄𝐍𝐀𝐌𝐄 the name of the current input file.
|
||||
𝐅𝐍𝐑 ordinal number of the current record in the current file.
|
||||
𝐅𝐒 regular expression used to separate fields; also settable by
|
||||
option -𝐅f̲s̲.
|
||||
𝐍𝐅 number of fields in the current record.
|
||||
𝐍𝐑 ordinal number of the current record.
|
||||
𝐎𝐅𝐌𝐓 output format for numbers (default %.𝟲𝗴).
|
||||
𝐎𝐅𝐒 output field separator (default space).
|
||||
𝐎𝐑𝐒 output record separator (default newline).
|
||||
𝐑𝐋𝐄𝐍𝐆𝐓𝐇 the length of a string matched by 𝗺𝗮𝘁𝗰𝗵.
|
||||
𝐑𝐒 input record separator (default newline). If empty, blank
|
||||
lines separate records. If more than one character long, 𝐑𝐒 is
|
||||
treated as a regular expression, and records are separated by
|
||||
text matching the expression.
|
||||
𝐑𝐒𝐓𝐀𝐑𝐓 the start position of a string matched by 𝗺𝗮𝘁𝗰𝗵.
|
||||
𝐒𝐔𝐁𝐒𝐄𝐏 separates multiple subscripts (default 034).
|
||||
|
||||
Functions may be defined (at the position of a pattern-action statement)
|
||||
thus:
|
||||
|
||||
𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻 𝗳𝗼𝗼(𝗮, 𝗯, 𝗰) { ...; 𝗿𝗲𝘁𝘂𝗿𝗻 𝘅 }
|
||||
|
||||
Parameters are passed by value if scalar and by reference if array name;
|
||||
functions may be called recursively. Parameters are local to the func‐
|
||||
tion; all other variables are global. Thus local variables may be cre‐
|
||||
ated by providing excess parameters in the function definition.
|
||||
|
||||
𝐄𝐍𝐕𝐈𝐑𝐎𝐍𝐌𝐄𝐍𝐓 𝐕𝐀𝐑𝐈𝐀𝐁𝐋𝐄𝐒
|
||||
If 𝐏𝐎𝐒𝐈𝐗𝐋𝐘_𝐂𝐎𝐑𝐑𝐄𝐂𝐓 is set in the environment, then a̲w̲k̲ follows the POSIX
|
||||
rules for 𝘀𝘂𝗯 and 𝗴𝘀𝘂𝗯 with respect to consecutive backslashes and amper‐
|
||||
sands.
|
||||
|
||||
𝐄𝐗𝐀𝐌𝐏𝐋𝐄𝐒
|
||||
length($0) > 72
|
||||
Print lines longer than 72 characters.
|
||||
|
||||
{ print $2, $1 }
|
||||
Print first two fields in opposite order.
|
||||
|
||||
BEGIN { FS = ",[ \t]*|[ \t]+" }
|
||||
{ print $2, $1 }
|
||||
Same, with input fields separated by comma and/or spaces and tabs.
|
||||
|
||||
{ s += $1 }
|
||||
END { print "sum is", s, " average is", s/NR }
|
||||
Add up first column, print sum and average.
|
||||
|
||||
/start/, /stop/
|
||||
Print all lines between start/stop pairs.
|
||||
|
||||
BEGIN { # Simulate echo(1)
|
||||
for (i = 1; i < ARGC; i++) printf "%s ", ARGV[i]
|
||||
printf "\n"
|
||||
exit }
|
||||
|
||||
𝐒𝐄𝐄 𝐀𝐋𝐒𝐎
|
||||
g̲r̲e̲p̲(1), l̲e̲x̲(1), s̲e̲d̲(1)
|
||||
A. V. Aho, B. W. Kernighan, P. J. Weinberger, T̲h̲e̲ A̲W̲K̲ P̲r̲o̲g̲r̲a̲m̲m̲i̲n̲g̲ L̲a̲n̲‐̲
|
||||
g̲u̲a̲g̲e̲, Addison-Wesley, 1988. ISBN 0-201-07981-X.
|
||||
|
||||
𝐁𝐔𝐆𝐒
|
||||
There are no explicit conversions between numbers and strings. To force
|
||||
an expression to be treated as a number add 0 to it; to force it to be
|
||||
treated as a string concatenate "" to it.
|
||||
|
||||
The scope rules for variables in functions are a botch; the syntax is
|
||||
worse.
|
||||
|
||||
Only eight-bit characters sets are handled correctly.
|
||||
|
||||
𝐔𝐍𝐔𝐒𝐔𝐀𝐋 𝐅𝐋𝐎𝐀𝐓𝐈𝐍𝐆-𝐏𝐎𝐈𝐍𝐓 𝐕𝐀𝐋𝐔𝐄𝐒
|
||||
A̲w̲k̲ was designed before IEEE 754 arithmetic defined Not-A-Number (NaN)
|
||||
and Infinity values, which are supported by all modern floating-point
|
||||
hardware.
|
||||
|
||||
Because a̲w̲k̲ uses s̲t̲r̲t̲o̲d̲(3) and a̲t̲o̲f̲(3) to convert string values to dou‐
|
||||
ble-precision floating-point values, modern C libraries also convert
|
||||
strings starting with 𝗶𝗻𝗳 and 𝗻𝗮𝗻 into infinity and NaN values respec‐
|
||||
tively. This led to strange results, with something like this:
|
||||
|
||||
echo nancy | awk '{ print $1 + 0 }'
|
||||
|
||||
printing 𝗻𝗮𝗻 instead of zero.
|
||||
|
||||
A̲w̲k̲ now follows GNU AWK, and prefilters string values before attempting
|
||||
to convert them to numbers, as follows:
|
||||
|
||||
H̲e̲x̲a̲d̲e̲c̲i̲m̲a̲l̲ v̲a̲l̲u̲e̲s̲
|
||||
Hexadecimal values (allowed since C99) convert to zero, as they
|
||||
did prior to C99.
|
||||
|
||||
N̲a̲N̲ v̲a̲l̲u̲e̲s̲
|
||||
The two strings +𝗻𝗮𝗻 and -𝗻𝗮𝗻 (case independent) convert to NaN.
|
||||
No others do. (NaNs can have signs.)
|
||||
|
||||
I̲n̲f̲i̲n̲i̲t̲y̲ v̲a̲l̲u̲e̲s̲
|
||||
The two strings +𝗶𝗻𝗳 and -𝗶𝗻𝗳 (case independent) convert to posi‐
|
||||
tive and negative infinity, respectively. No others do.
|
||||
|
||||
|
||||
|
||||
AWK(1)
|
224
third_party/awk/awk.h
vendored
224
third_party/awk/awk.h
vendored
|
@ -1,35 +1,12 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#if __STDC_VERSION__ <= 199901L
|
||||
#define noreturn
|
||||
#else
|
||||
#include <stdnoreturn.h>
|
||||
#endif
|
||||
#ifndef COSMOPOLITAN_THIRD_PARTY_AWK_AWK_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_AWK_AWK_H_
|
||||
#include "libc/assert.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/literal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
/* clang-format off */
|
||||
|
||||
typedef double Awkfloat;
|
||||
|
||||
|
@ -254,5 +231,186 @@ typedef struct fa {
|
|||
struct rrow re[1]; /* variable: actual size set by calling malloc */
|
||||
} fa;
|
||||
|
||||
extern int yywrap(void);
|
||||
extern void setfname(Cell *);
|
||||
extern int constnode(Node *);
|
||||
extern char *strnode(Node *);
|
||||
extern Node *notnull(Node *);
|
||||
extern int yyparse(void);
|
||||
|
||||
#include "proto.h"
|
||||
extern int yylex(void);
|
||||
extern void startreg(void);
|
||||
extern int input(void);
|
||||
extern void unput(int);
|
||||
extern void unputstr(const char *);
|
||||
extern int yylook(void);
|
||||
extern int yyback(int *, int);
|
||||
extern int yyinput(void);
|
||||
|
||||
extern fa *makedfa(const char *, bool);
|
||||
extern fa *mkdfa(const char *, bool);
|
||||
extern int makeinit(fa *, bool);
|
||||
extern void penter(Node *);
|
||||
extern void freetr(Node *);
|
||||
extern int hexstr(const uschar **);
|
||||
extern int quoted(const uschar **);
|
||||
extern char *cclenter(const char *);
|
||||
extern wontreturn void overflo(const char *);
|
||||
extern void cfoll(fa *, Node *);
|
||||
extern int first(Node *);
|
||||
extern void follow(Node *);
|
||||
extern int member(int, const char *);
|
||||
extern int match(fa *, const char *);
|
||||
extern int pmatch(fa *, const char *);
|
||||
extern int nematch(fa *, const char *);
|
||||
extern bool fnematch(fa *, FILE *, char **, int *, int);
|
||||
extern Node *reparse(const char *);
|
||||
extern Node *regexp(void);
|
||||
extern Node *primary(void);
|
||||
extern Node *concat(Node *);
|
||||
extern Node *alt(Node *);
|
||||
extern Node *unary(Node *);
|
||||
extern int relex(void);
|
||||
extern int cgoto(fa *, int, int);
|
||||
extern void freefa(fa *);
|
||||
|
||||
extern int pgetc(void);
|
||||
extern char *cursource(void);
|
||||
|
||||
extern Node *nodealloc(int);
|
||||
extern Node *exptostat(Node *);
|
||||
extern Node *node1(int, Node *);
|
||||
extern Node *node2(int, Node *, Node *);
|
||||
extern Node *node3(int, Node *, Node *, Node *);
|
||||
extern Node *node4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat3(int, Node *, Node *, Node *);
|
||||
extern Node *op2(int, Node *, Node *);
|
||||
extern Node *op1(int, Node *);
|
||||
extern Node *stat1(int, Node *);
|
||||
extern Node *op3(int, Node *, Node *, Node *);
|
||||
extern Node *op4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat2(int, Node *, Node *);
|
||||
extern Node *stat4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *celltonode(Cell *, int);
|
||||
extern Node *rectonode(void);
|
||||
extern Node *makearr(Node *);
|
||||
extern Node *pa2stat(Node *, Node *, Node *);
|
||||
extern Node *linkum(Node *, Node *);
|
||||
extern void defn(Cell *, Node *, Node *);
|
||||
extern int isarg(const char *);
|
||||
extern const char *tokname(int);
|
||||
extern Cell *(*proctab[])(Node **, int);
|
||||
extern int ptoi(void *);
|
||||
extern Node *itonp(int);
|
||||
|
||||
extern void syminit(void);
|
||||
extern void arginit(int, char **);
|
||||
extern void envinit(char **);
|
||||
extern Array *makesymtab(int);
|
||||
extern void freesymtab(Cell *);
|
||||
extern void freeelem(Cell *, const char *);
|
||||
extern Cell *setsymtab(const char *, const char *, double, unsigned int, Array *);
|
||||
extern int hash(const char *, int);
|
||||
extern void rehash(Array *);
|
||||
extern Cell *lookup(const char *, Array *);
|
||||
extern double setfval(Cell *, double);
|
||||
extern void funnyvar(Cell *, const char *);
|
||||
extern char *setsval(Cell *, const char *);
|
||||
extern double getfval(Cell *);
|
||||
extern char *getsval(Cell *);
|
||||
extern char *getpssval(Cell *); /* for print */
|
||||
extern char *tostring(const char *);
|
||||
extern char *tostringN(const char *, size_t);
|
||||
extern char *qstring(const char *, int);
|
||||
extern Cell *catstr(Cell *, Cell *);
|
||||
|
||||
extern void recinit(unsigned int);
|
||||
extern void initgetrec(void);
|
||||
extern void makefields(int, int);
|
||||
extern void growfldtab(int n);
|
||||
extern void savefs(void);
|
||||
extern int getrec(char **, int *, bool);
|
||||
extern void nextfile(void);
|
||||
extern int readrec(char **buf, int *bufsize, FILE *inf, bool isnew);
|
||||
extern char *getargv(int);
|
||||
extern void setclvar(char *);
|
||||
extern void fldbld(void);
|
||||
extern void cleanfld(int, int);
|
||||
extern void newfld(int);
|
||||
extern void setlastfld(int);
|
||||
extern int refldbld(const char *, const char *);
|
||||
extern void recbld(void);
|
||||
extern Cell *fieldadr(int);
|
||||
extern void yyerror(const char *);
|
||||
extern void bracecheck(void);
|
||||
extern void bcheck2(int, int, int);
|
||||
extern void SYNTAX(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern wontreturn void FATAL(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern void WARNING(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern void error(void);
|
||||
extern void eprint(void);
|
||||
extern void bclass(int);
|
||||
extern double errcheck(double, const char *);
|
||||
extern int isclvar(const char *);
|
||||
extern bool is_valid_number(const char *s, bool trailing_stuff_ok,
|
||||
bool *no_trailing, double *result);
|
||||
#define is_number(s, val) is_valid_number(s, false, NULL, val)
|
||||
|
||||
extern int adjbuf(char **pb, int *sz, int min, int q, char **pbp, const char *what);
|
||||
extern void run(Node *);
|
||||
extern Cell *execute(Node *);
|
||||
extern Cell *program(Node **, int);
|
||||
extern Cell *call(Node **, int);
|
||||
extern Cell *copycell(Cell *);
|
||||
extern Cell *arg(Node **, int);
|
||||
extern Cell *jump(Node **, int);
|
||||
extern Cell *awkgetline(Node **, int);
|
||||
extern Cell *getnf(Node **, int);
|
||||
extern Cell *array(Node **, int);
|
||||
extern Cell *awkdelete(Node **, int);
|
||||
extern Cell *intest(Node **, int);
|
||||
extern Cell *matchop(Node **, int);
|
||||
extern Cell *boolop(Node **, int);
|
||||
extern Cell *relop(Node **, int);
|
||||
extern void tfree(Cell *);
|
||||
extern Cell *gettemp(void);
|
||||
extern Cell *field(Node **, int);
|
||||
extern Cell *indirect(Node **, int);
|
||||
extern Cell *substr(Node **, int);
|
||||
extern Cell *sindex(Node **, int);
|
||||
extern int format(char **, int *, const char *, Node *);
|
||||
extern Cell *awksprintf(Node **, int);
|
||||
extern Cell *awkprintf(Node **, int);
|
||||
extern Cell *arith(Node **, int);
|
||||
extern double ipow(double, int);
|
||||
extern Cell *incrdecr(Node **, int);
|
||||
extern Cell *assign(Node **, int);
|
||||
extern Cell *cat(Node **, int);
|
||||
extern Cell *pastat(Node **, int);
|
||||
extern Cell *dopa2(Node **, int);
|
||||
extern Cell *split(Node **, int);
|
||||
extern Cell *condexpr(Node **, int);
|
||||
extern Cell *ifstat(Node **, int);
|
||||
extern Cell *whilestat(Node **, int);
|
||||
extern Cell *dostat(Node **, int);
|
||||
extern Cell *forstat(Node **, int);
|
||||
extern Cell *instat(Node **, int);
|
||||
extern Cell *bltin(Node **, int);
|
||||
extern Cell *printstat(Node **, int);
|
||||
extern Cell *nullproc(Node **, int);
|
||||
extern FILE *redirect(int, Node *);
|
||||
extern FILE *openfile(int, const char *, bool *);
|
||||
extern const char *filename(FILE *);
|
||||
extern Cell *closefile(Node **, int);
|
||||
extern void closeall(void);
|
||||
extern Cell *sub(Node **, int);
|
||||
extern Cell *gsub(Node **, int);
|
||||
|
||||
extern const char *flags2str(int flags);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_AWK_AWK_H_ */
|
||||
|
|
11
third_party/awk/awk.mk
vendored
11
third_party/awk/awk.mk
vendored
|
@ -7,6 +7,7 @@ THIRD_PARTY_AWK_SRCS = $(THIRD_PARTY_AWK_A_SRCS)
|
|||
THIRD_PARTY_AWK_HDRS = $(THIRD_PARTY_AWK_A_HDRS)
|
||||
THIRD_PARTY_AWK_INCS = $(THIRD_PARTY_AWK_A_INCS)
|
||||
THIRD_PARTY_AWK_BINS = $(THIRD_PARTY_AWK_COMS) $(THIRD_PARTY_AWK_COMS:%=%.dbg)
|
||||
THIRD_PARTY_AWK_COMS = o/$(MODE)/third_party/awk/awk.com
|
||||
|
||||
THIRD_PARTY_AWK_ARTIFACTS += THIRD_PARTY_AWK_A
|
||||
THIRD_PARTY_AWK = $(THIRD_PARTY_AWK_A_DEPS) $(THIRD_PARTY_AWK_A)
|
||||
|
@ -27,7 +28,10 @@ THIRD_PARTY_AWK_A_DIRECTDEPS = \
|
|||
LIBC_STDIO \
|
||||
LIBC_SYSV \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS
|
||||
LIBC_STUBS \
|
||||
LIBC_TINYMATH \
|
||||
TOOL_ARGS \
|
||||
THIRD_PARTY_GDTOA
|
||||
|
||||
THIRD_PARTY_AWK_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_AWK_A_DIRECTDEPS),$($(x))))
|
||||
|
@ -47,14 +51,11 @@ $(THIRD_PARTY_AWK_A).pkg: \
|
|||
|
||||
o/$(MODE)/third_party/awk/awk.com.dbg: \
|
||||
$(THIRD_PARTY_AWK) \
|
||||
o/$(MODE)/third_party/awk/awk.o \
|
||||
o/$(MODE)/third_party/awk/main.o \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
THIRD_PARTY_AWK_COMS = \
|
||||
o/$(MODE)/third_party/awk/awk.com
|
||||
|
||||
THIRD_PARTY_AWK_LIBS = $(foreach x,$(THIRD_PARTY_AWK_ARTIFACTS),$($(x)))
|
||||
THIRD_PARTY_AWK_SRCS = $(foreach x,$(THIRD_PARTY_AWK_ARTIFACTS),$($(x)_SRCS))
|
||||
THIRD_PARTY_AWK_CHECKS = $(foreach x,$(THIRD_PARTY_AWK_ARTIFACTS),$($(x)_CHECKS))
|
||||
|
|
11
third_party/awk/awkgram.y
vendored
11
third_party/awk/awkgram.y
vendored
|
@ -23,9 +23,14 @@ THIS SOFTWARE.
|
|||
****************************************************************/
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "awk.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/str/str.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
|
||||
void checkdup(Node *list, Cell *item);
|
||||
int yywrap(void) { return(1); }
|
||||
|
|
90
third_party/awk/b.c
vendored
90
third_party/awk/b.c
vendored
|
@ -1,39 +1,40 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
// clang-format off
|
||||
|
||||
/* lasciate ogne speranza, voi ch'intrate. */
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.tab.h"
|
||||
|
||||
#define MAXLIN 22
|
||||
|
||||
#define type(v) (v)->nobj /* badly overloaded here */
|
||||
|
@ -866,25 +867,6 @@ Node *unary(Node *np)
|
|||
* must be less than twice the size of their full name.
|
||||
*/
|
||||
|
||||
/* Because isblank doesn't show up in any of the header files on any
|
||||
* system i use, it's defined here. if some other locale has a richer
|
||||
* definition of "blank", define HAS_ISBLANK and provide your own
|
||||
* version.
|
||||
* the parentheses here are an attempt to find a path through the maze
|
||||
* of macro definition and/or function and/or version provided. thanks
|
||||
* to nelson beebe for the suggestion; let's see if it works everywhere.
|
||||
*/
|
||||
|
||||
/* #define HAS_ISBLANK */
|
||||
#ifndef HAS_ISBLANK
|
||||
|
||||
int (xisblank)(int c)
|
||||
{
|
||||
return c==' ' || c=='\t';
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static const struct charclass {
|
||||
const char *cc_name;
|
||||
int cc_namelen;
|
||||
|
@ -892,11 +874,7 @@ static const struct charclass {
|
|||
} charclasses[] = {
|
||||
{ "alnum", 5, isalnum },
|
||||
{ "alpha", 5, isalpha },
|
||||
#ifndef HAS_ISBLANK
|
||||
{ "blank", 5, xisblank },
|
||||
#else
|
||||
{ "blank", 5, isblank },
|
||||
#endif
|
||||
{ "cntrl", 5, iscntrl },
|
||||
{ "digit", 5, isdigit },
|
||||
{ "graph", 5, isgraph },
|
||||
|
|
74
third_party/awk/lex.c
vendored
74
third_party/awk/lex.c
vendored
|
@ -1,35 +1,47 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
// clang-format off
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.tab.h"
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
extern bool infunc;
|
||||
|
||||
int lineno = 1;
|
||||
|
|
86
third_party/awk/lib.c
vendored
86
third_party/awk/lib.c
vendored
|
@ -1,38 +1,50 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "awk.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/ffs.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
// clang-format off
|
||||
|
||||
char EMPTY[] = { '\0' };
|
||||
FILE *infile = NULL;
|
||||
|
@ -585,9 +597,11 @@ void yyerror(const char *s)
|
|||
SYNTAX("%s", s);
|
||||
}
|
||||
|
||||
extern char *cmdname;
|
||||
|
||||
void SYNTAX(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname, *curfname;
|
||||
extern char *curfname;
|
||||
static int been_here = 0;
|
||||
va_list varg;
|
||||
|
||||
|
@ -637,7 +651,6 @@ void bcheck2(int n, int c1, int c2)
|
|||
|
||||
void FATAL(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname;
|
||||
va_list varg;
|
||||
|
||||
fflush(stdout);
|
||||
|
@ -653,7 +666,6 @@ void FATAL(const char *fmt, ...)
|
|||
|
||||
void WARNING(const char *fmt, ...)
|
||||
{
|
||||
extern char *cmdname;
|
||||
va_list varg;
|
||||
|
||||
fflush(stdout);
|
||||
|
|
126
third_party/awk/main.c
vendored
126
third_party/awk/main.c
vendored
|
@ -1,39 +1,48 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/struct/sockaddr.internal.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/str/locale.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sicode.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "tool/args/args.h"
|
||||
// clang-format off
|
||||
|
||||
const char *version = "version 20220530";
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include "awk.h"
|
||||
|
||||
extern char **environ;
|
||||
extern int nfields;
|
||||
|
||||
int dbg = 0;
|
||||
|
@ -41,7 +50,6 @@ Awkfloat srand_seed = 1;
|
|||
char *cmdname; /* gets argv[0] for error messages */
|
||||
extern FILE *yyin; /* lex input file */
|
||||
char *lexprog; /* points to program argument if it exists */
|
||||
extern int errorflag; /* non-zero if any syntax errors; set by yyerror */
|
||||
enum compile_states compile_time = ERROR_PRINTING;
|
||||
|
||||
static char **pfile; /* program filenames from -f's */
|
||||
|
@ -51,31 +59,21 @@ static size_t curpfile; /* current filename */
|
|||
|
||||
bool safe = false; /* true => "safe" mode */
|
||||
|
||||
static noreturn void fpecatch(int n
|
||||
#ifdef SA_SIGINFO
|
||||
, siginfo_t *si, void *uc
|
||||
#endif
|
||||
)
|
||||
static wontreturn void fpecatch(int n, siginfo_t *si, ucontext_t *uc)
|
||||
{
|
||||
#ifdef SA_SIGINFO
|
||||
static const char *emsg[] = {
|
||||
[0] = "Unknown error",
|
||||
[FPE_INTDIV] = "Integer divide by zero",
|
||||
[FPE_INTOVF] = "Integer overflow",
|
||||
[FPE_FLTDIV] = "Floating point divide by zero",
|
||||
[FPE_FLTOVF] = "Floating point overflow",
|
||||
[FPE_FLTUND] = "Floating point underflow",
|
||||
[FPE_FLTRES] = "Floating point inexact result",
|
||||
[FPE_FLTINV] = "Invalid Floating point operation",
|
||||
[FPE_FLTSUB] = "Subscript out of range",
|
||||
};
|
||||
#endif
|
||||
FATAL("floating point exception"
|
||||
#ifdef SA_SIGINFO
|
||||
": %s", (size_t)si->si_code < sizeof(emsg) / sizeof(emsg[0]) &&
|
||||
emsg[si->si_code] ? emsg[si->si_code] : emsg[0]
|
||||
#endif
|
||||
);
|
||||
const char *emsg[10];
|
||||
emsg[0] = "Unknown error";
|
||||
emsg[FPE_INTDIV] = "Integer divide by zero";
|
||||
emsg[FPE_INTOVF] = "Integer overflow";
|
||||
emsg[FPE_FLTDIV] = "Floating point divide by zero";
|
||||
emsg[FPE_FLTOVF] = "Floating point overflow";
|
||||
emsg[FPE_FLTUND] = "Floating point underflow";
|
||||
emsg[FPE_FLTRES] = "Floating point inexact result";
|
||||
emsg[FPE_FLTINV] = "Invalid Floating point operation";
|
||||
emsg[FPE_FLTSUB] = "Subscript out of range";
|
||||
FATAL("floating point exception: %s",
|
||||
(size_t)si->si_code < sizeof(emsg) / sizeof(emsg[0]) &&
|
||||
emsg[si->si_code] ? emsg[si->si_code] : emsg[0]);
|
||||
}
|
||||
|
||||
/* Can this work with recursive calls? I don't think so.
|
||||
|
@ -112,6 +110,7 @@ int main(int argc, char *argv[])
|
|||
const char *fs = NULL;
|
||||
char *fn, *vn;
|
||||
|
||||
LoadZipArgs(&argc, &argv);
|
||||
setlocale(LC_CTYPE, "");
|
||||
setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */
|
||||
cmdname = argv[0];
|
||||
|
@ -121,7 +120,6 @@ int main(int argc, char *argv[])
|
|||
cmdname);
|
||||
exit(1);
|
||||
}
|
||||
#ifdef SA_SIGINFO
|
||||
{
|
||||
struct sigaction sa;
|
||||
sa.sa_sigaction = fpecatch;
|
||||
|
@ -129,9 +127,6 @@ int main(int argc, char *argv[])
|
|||
sigemptyset(&sa.sa_mask);
|
||||
(void)sigaction(SIGFPE, &sa, NULL);
|
||||
}
|
||||
#else
|
||||
(void)signal(SIGFPE, fpecatch);
|
||||
#endif
|
||||
/*signal(SIGSEGV, segvcatch); experiment */
|
||||
|
||||
/* Set and keep track of the random seed */
|
||||
|
@ -209,11 +204,6 @@ int main(int argc, char *argv[])
|
|||
if (!safe)
|
||||
envinit(environ);
|
||||
yyparse();
|
||||
#if 0
|
||||
// Doing this would comply with POSIX, but is not compatible with
|
||||
// other awks and with what most users expect. So comment it out.
|
||||
setlocale(LC_NUMERIC, ""); /* back to whatever it is locally */
|
||||
#endif
|
||||
if (fs)
|
||||
*FS = qstring(fs, '\0');
|
||||
DPRINTF("errorflag=%d\n", errorflag);
|
||||
|
|
74
third_party/awk/maketab.c
vendored
74
third_party/awk/maketab.c
vendored
|
@ -1,26 +1,38 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
* this program makes the table to link function names
|
||||
|
@ -28,12 +40,6 @@ THIS SOFTWARE.
|
|||
* it finds the indices in awkgram.tab.h, produced by bison.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.tab.h"
|
||||
|
||||
struct xx
|
||||
{ int token;
|
||||
const char *name;
|
||||
|
@ -120,9 +126,13 @@ int main(int argc, char *argv[])
|
|||
char buf[200], name[200], def[200];
|
||||
enum { TOK_UNKNOWN, TOK_ENUM, TOK_DEFINE } tokentype = TOK_UNKNOWN;
|
||||
|
||||
printf("#include <stdio.h>\n");
|
||||
printf("#include \"awk.h\"\n");
|
||||
printf("#include \"awkgram.tab.h\"\n\n");
|
||||
printf("#include \"libc/calls/calls.h\"\n");
|
||||
printf("#include \"libc/fmt/fmt.h\"\n");
|
||||
printf("#include \"libc/stdio/lock.h\"\n");
|
||||
printf("#include \"libc/stdio/stdio.h\"\n");
|
||||
printf("#include \"libc/stdio/temp.h\"\n");
|
||||
printf("#include \"third_party/awk/awk.h\"\n");
|
||||
printf("#include \"third_party/awk/awkgram.tab.h\"\n\n");
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: maketab YTAB_H\n");
|
||||
|
|
61
third_party/awk/parse.c
vendored
61
third_party/awk/parse.c
vendored
|
@ -1,33 +1,36 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.tab.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
// clang-format off
|
||||
|
||||
Node *nodealloc(int n)
|
||||
{
|
||||
|
|
33
third_party/awk/proctab.c
vendored
33
third_party/awk/proctab.c
vendored
|
@ -1,11 +1,34 @@
|
|||
// clang-format off
|
||||
#include "libc/calls/calls.h"
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/stdio/lock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/temp.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
// clang-format off
|
||||
|
||||
static const char * const printname[95] = {
|
||||
"FIRSTTOKEN", /* 258 */
|
||||
|
|
206
third_party/awk/proto.h
vendored
206
third_party/awk/proto.h
vendored
|
@ -1,206 +0,0 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
extern int yywrap(void);
|
||||
extern void setfname(Cell *);
|
||||
extern int constnode(Node *);
|
||||
extern char *strnode(Node *);
|
||||
extern Node *notnull(Node *);
|
||||
extern int yyparse(void);
|
||||
|
||||
extern int yylex(void);
|
||||
extern void startreg(void);
|
||||
extern int input(void);
|
||||
extern void unput(int);
|
||||
extern void unputstr(const char *);
|
||||
extern int yylook(void);
|
||||
extern int yyback(int *, int);
|
||||
extern int yyinput(void);
|
||||
|
||||
extern fa *makedfa(const char *, bool);
|
||||
extern fa *mkdfa(const char *, bool);
|
||||
extern int makeinit(fa *, bool);
|
||||
extern void penter(Node *);
|
||||
extern void freetr(Node *);
|
||||
extern int hexstr(const uschar **);
|
||||
extern int quoted(const uschar **);
|
||||
extern char *cclenter(const char *);
|
||||
extern noreturn void overflo(const char *);
|
||||
extern void cfoll(fa *, Node *);
|
||||
extern int first(Node *);
|
||||
extern void follow(Node *);
|
||||
extern int member(int, const char *);
|
||||
extern int match(fa *, const char *);
|
||||
extern int pmatch(fa *, const char *);
|
||||
extern int nematch(fa *, const char *);
|
||||
extern bool fnematch(fa *, FILE *, char **, int *, int);
|
||||
extern Node *reparse(const char *);
|
||||
extern Node *regexp(void);
|
||||
extern Node *primary(void);
|
||||
extern Node *concat(Node *);
|
||||
extern Node *alt(Node *);
|
||||
extern Node *unary(Node *);
|
||||
extern int relex(void);
|
||||
extern int cgoto(fa *, int, int);
|
||||
extern void freefa(fa *);
|
||||
|
||||
extern int pgetc(void);
|
||||
extern char *cursource(void);
|
||||
|
||||
extern Node *nodealloc(int);
|
||||
extern Node *exptostat(Node *);
|
||||
extern Node *node1(int, Node *);
|
||||
extern Node *node2(int, Node *, Node *);
|
||||
extern Node *node3(int, Node *, Node *, Node *);
|
||||
extern Node *node4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat3(int, Node *, Node *, Node *);
|
||||
extern Node *op2(int, Node *, Node *);
|
||||
extern Node *op1(int, Node *);
|
||||
extern Node *stat1(int, Node *);
|
||||
extern Node *op3(int, Node *, Node *, Node *);
|
||||
extern Node *op4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *stat2(int, Node *, Node *);
|
||||
extern Node *stat4(int, Node *, Node *, Node *, Node *);
|
||||
extern Node *celltonode(Cell *, int);
|
||||
extern Node *rectonode(void);
|
||||
extern Node *makearr(Node *);
|
||||
extern Node *pa2stat(Node *, Node *, Node *);
|
||||
extern Node *linkum(Node *, Node *);
|
||||
extern void defn(Cell *, Node *, Node *);
|
||||
extern int isarg(const char *);
|
||||
extern const char *tokname(int);
|
||||
extern Cell *(*proctab[])(Node **, int);
|
||||
extern int ptoi(void *);
|
||||
extern Node *itonp(int);
|
||||
|
||||
extern void syminit(void);
|
||||
extern void arginit(int, char **);
|
||||
extern void envinit(char **);
|
||||
extern Array *makesymtab(int);
|
||||
extern void freesymtab(Cell *);
|
||||
extern void freeelem(Cell *, const char *);
|
||||
extern Cell *setsymtab(const char *, const char *, double, unsigned int, Array *);
|
||||
extern int hash(const char *, int);
|
||||
extern void rehash(Array *);
|
||||
extern Cell *lookup(const char *, Array *);
|
||||
extern double setfval(Cell *, double);
|
||||
extern void funnyvar(Cell *, const char *);
|
||||
extern char *setsval(Cell *, const char *);
|
||||
extern double getfval(Cell *);
|
||||
extern char *getsval(Cell *);
|
||||
extern char *getpssval(Cell *); /* for print */
|
||||
extern char *tostring(const char *);
|
||||
extern char *tostringN(const char *, size_t);
|
||||
extern char *qstring(const char *, int);
|
||||
extern Cell *catstr(Cell *, Cell *);
|
||||
|
||||
extern void recinit(unsigned int);
|
||||
extern void initgetrec(void);
|
||||
extern void makefields(int, int);
|
||||
extern void growfldtab(int n);
|
||||
extern void savefs(void);
|
||||
extern int getrec(char **, int *, bool);
|
||||
extern void nextfile(void);
|
||||
extern int readrec(char **buf, int *bufsize, FILE *inf, bool isnew);
|
||||
extern char *getargv(int);
|
||||
extern void setclvar(char *);
|
||||
extern void fldbld(void);
|
||||
extern void cleanfld(int, int);
|
||||
extern void newfld(int);
|
||||
extern void setlastfld(int);
|
||||
extern int refldbld(const char *, const char *);
|
||||
extern void recbld(void);
|
||||
extern Cell *fieldadr(int);
|
||||
extern void yyerror(const char *);
|
||||
extern void bracecheck(void);
|
||||
extern void bcheck2(int, int, int);
|
||||
extern void SYNTAX(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern noreturn void FATAL(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern void WARNING(const char *, ...)
|
||||
__attribute__((__format__(__printf__, 1, 2)));
|
||||
extern void error(void);
|
||||
extern void eprint(void);
|
||||
extern void bclass(int);
|
||||
extern double errcheck(double, const char *);
|
||||
extern int isclvar(const char *);
|
||||
extern bool is_valid_number(const char *s, bool trailing_stuff_ok,
|
||||
bool *no_trailing, double *result);
|
||||
#define is_number(s, val) is_valid_number(s, false, NULL, val)
|
||||
|
||||
extern int adjbuf(char **pb, int *sz, int min, int q, char **pbp, const char *what);
|
||||
extern void run(Node *);
|
||||
extern Cell *execute(Node *);
|
||||
extern Cell *program(Node **, int);
|
||||
extern Cell *call(Node **, int);
|
||||
extern Cell *copycell(Cell *);
|
||||
extern Cell *arg(Node **, int);
|
||||
extern Cell *jump(Node **, int);
|
||||
extern Cell *awkgetline(Node **, int);
|
||||
extern Cell *getnf(Node **, int);
|
||||
extern Cell *array(Node **, int);
|
||||
extern Cell *awkdelete(Node **, int);
|
||||
extern Cell *intest(Node **, int);
|
||||
extern Cell *matchop(Node **, int);
|
||||
extern Cell *boolop(Node **, int);
|
||||
extern Cell *relop(Node **, int);
|
||||
extern void tfree(Cell *);
|
||||
extern Cell *gettemp(void);
|
||||
extern Cell *field(Node **, int);
|
||||
extern Cell *indirect(Node **, int);
|
||||
extern Cell *substr(Node **, int);
|
||||
extern Cell *sindex(Node **, int);
|
||||
extern int format(char **, int *, const char *, Node *);
|
||||
extern Cell *awksprintf(Node **, int);
|
||||
extern Cell *awkprintf(Node **, int);
|
||||
extern Cell *arith(Node **, int);
|
||||
extern double ipow(double, int);
|
||||
extern Cell *incrdecr(Node **, int);
|
||||
extern Cell *assign(Node **, int);
|
||||
extern Cell *cat(Node **, int);
|
||||
extern Cell *pastat(Node **, int);
|
||||
extern Cell *dopa2(Node **, int);
|
||||
extern Cell *split(Node **, int);
|
||||
extern Cell *condexpr(Node **, int);
|
||||
extern Cell *ifstat(Node **, int);
|
||||
extern Cell *whilestat(Node **, int);
|
||||
extern Cell *dostat(Node **, int);
|
||||
extern Cell *forstat(Node **, int);
|
||||
extern Cell *instat(Node **, int);
|
||||
extern Cell *bltin(Node **, int);
|
||||
extern Cell *printstat(Node **, int);
|
||||
extern Cell *nullproc(Node **, int);
|
||||
extern FILE *redirect(int, Node *);
|
||||
extern FILE *openfile(int, const char *, bool *);
|
||||
extern const char *filename(FILE *);
|
||||
extern Cell *closefile(Node **, int);
|
||||
extern void closeall(void);
|
||||
extern Cell *sub(Node **, int);
|
||||
extern Cell *gsub(Node **, int);
|
||||
|
||||
extern FILE *popen(const char *, const char *);
|
||||
extern int pclose(FILE *);
|
||||
|
||||
extern const char *flags2str(int flags);
|
33
third_party/awk/reflow.awk
vendored
Normal file
33
third_party/awk/reflow.awk
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
# fmt - format
|
||||
# input: text
|
||||
# output: text formatted into lines of <= 72 characters
|
||||
|
||||
BEGIN {
|
||||
maxlen = 72
|
||||
}
|
||||
|
||||
/^[ \t]/ { printline(); print; next } # verbatim
|
||||
###/^ +/ { printline(); } # whitespace == break
|
||||
|
||||
/./ { for (i = 1; i <= NF; i++) addword($i); next }
|
||||
|
||||
/^$/ { printline(); print "" }
|
||||
END { printline() }
|
||||
|
||||
function addword(w) {
|
||||
## print "adding [", w, "] ", length(w), length(line), maxlen
|
||||
if (length(line) + length(w) > maxlen)
|
||||
printline()
|
||||
if (length(w) > 2 && ( w ~ /[\.!]["?)]?$/ || w ~ /[?!]"?$/) &&
|
||||
w !~ /^(Mr|Dr|Ms|Mrs|vs|Ph.D)\.$/)
|
||||
w = w " "
|
||||
line = line " " w
|
||||
}
|
||||
|
||||
function printline() {
|
||||
if (length(line) > 0) {
|
||||
sub(/ +$/, "", line)
|
||||
print substr(line, 2) # removes leading blank
|
||||
line = ""
|
||||
}
|
||||
}
|
100
third_party/awk/run.c
vendored
100
third_party/awk/run.c
vendored
|
@ -1,44 +1,46 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <setjmp.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include "awk.h"
|
||||
#include "awkgram.tab.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/fd.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/awk/awkgram.tab.h"
|
||||
#include "third_party/libcxx/math.h"
|
||||
// clang-format off
|
||||
|
||||
static void stdinit(void);
|
||||
static void flush_all(void);
|
||||
|
@ -56,23 +58,7 @@ void tempfree(Cell *p) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/* do we really need these? */
|
||||
/* #ifdef _NFILE */
|
||||
/* #ifndef FOPEN_MAX */
|
||||
/* #define FOPEN_MAX _NFILE */
|
||||
/* #endif */
|
||||
/* #endif */
|
||||
/* */
|
||||
/* #ifndef FOPEN_MAX */
|
||||
/* #define FOPEN_MAX 40 */ /* max number of open files */
|
||||
/* #endif */
|
||||
/* */
|
||||
/* #ifndef RAND_MAX */
|
||||
/* #define RAND_MAX 32767 */ /* all that ansi guarantees */
|
||||
/* #endif */
|
||||
|
||||
jmp_buf env;
|
||||
extern int pairstack[];
|
||||
extern Awkfloat srand_seed;
|
||||
|
||||
Node *winner = NULL; /* root of parse tree */
|
||||
|
@ -1659,10 +1645,8 @@ Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg lis
|
|||
u = WEXITSTATUS(status);
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
u = WTERMSIG(status) + 256;
|
||||
#ifdef WCOREDUMP
|
||||
if (WCOREDUMP(status))
|
||||
u += 256;
|
||||
#endif
|
||||
} else /* something else?!? */
|
||||
u = 0;
|
||||
}
|
||||
|
|
66
third_party/awk/tran.c
vendored
66
third_party/awk/tran.c
vendored
|
@ -1,34 +1,38 @@
|
|||
/****************************************************************
|
||||
Copyright (C) Lucent Technologies 1997
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and
|
||||
its documentation for any purpose and without fee is hereby
|
||||
granted, provided that the above copyright notice appear in all
|
||||
copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name Lucent Technologies or any of
|
||||
its entities not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "awk.h"
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Copyright (C) Lucent Technologies 1997 │
|
||||
│ All Rights Reserved │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and distribute this software and │
|
||||
│ its documentation for any purpose and without fee is hereby │
|
||||
│ granted, provided that the above copyright notice appear in all │
|
||||
│ copies and that both that the copyright notice and this │
|
||||
│ permission notice and warranty disclaimer appear in supporting │
|
||||
│ documentation, and that the name Lucent Technologies or any of │
|
||||
│ its entities not be used in advertising or publicity pertaining │
|
||||
│ to distribution of the software without specific, written prior │
|
||||
│ permission. │
|
||||
│ │
|
||||
│ LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, │
|
||||
│ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. │
|
||||
│ IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY │
|
||||
│ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES │
|
||||
│ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER │
|
||||
│ IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, │
|
||||
│ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF │
|
||||
│ THIS SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#define DEBUG
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/awk/awk.h"
|
||||
#include "third_party/libcxx/math.h"
|
||||
// clang-format off
|
||||
|
||||
#define FULLTAB 2 /* rehash when table gets this x full */
|
||||
#define GROWTAB 4 /* grow table by this factor */
|
||||
|
|
5
tool/scripts/man2txt
Executable file
5
tool/scripts/man2txt
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
for x; do
|
||||
nroff -mandoc -rLL=80n -rLT=80n -Tutf8 <"$x" |
|
||||
o//tool/viz/ascii2utf8.com
|
||||
done
|
Loading…
Reference in a new issue