Skip to content

Commit dbbab51

Browse files
authored
add awk lang (#778)
1 parent cd59abf commit dbbab51

File tree

8 files changed

+58
-4
lines changed

8 files changed

+58
-4
lines changed

config/langs.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ mov $0, %edi
9090
syscall
9191
'''
9292

93+
[AWK]
94+
size = '707 KiB'
95+
version = '5.2.0'
96+
website = 'https://www.gnu.org/software/gawk/'
97+
example = '''
98+
BEGIN {
99+
# Printing
100+
print("Hello, World")
101+
102+
# Looping
103+
for (i=0; i<=10; i++) {
104+
printf("%i\n", i)
105+
}
106+
}
107+
108+
# Arguments are available via STDIN in the form of records
109+
# Each record is NULL terminated
110+
# By default, AWK automatically performs actions on each record
111+
{
112+
# $0 is the full record while $1-$NF accesses individual fields in the record,
113+
# where NF is the number of fields in the current record
114+
print($0)
115+
}
116+
'''
117+
93118
[Bash]
94119
size = '1.17 MiB'
95120
version = '5.2.2'

db/a-schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CREATE TYPE layout AS ENUM ('default', 'tabs');
4848
CREATE TYPE keymap AS ENUM ('default', 'vim');
4949

5050
CREATE TYPE lang AS ENUM (
51-
'assembly', 'bash', 'basic', 'brainfuck', 'c', 'c-sharp', 'cpp', 'cobol',
51+
'assembly', 'awk', 'bash', 'basic', 'brainfuck', 'c', 'c-sharp', 'cpp', 'cobol',
5252
'crystal', 'd', 'dart', 'elixir', 'f-sharp', 'fish', 'fortran', 'go',
5353
'golfscript', 'haskell', 'hexagony', 'j', 'java', 'javascript', 'julia',
5454
'k', 'lisp', 'lua', 'nim', 'pascal', 'perl', 'php', 'powershell',

docker/dev.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ COPY --from=codegolf/lang-tcl ["/", "/langs/tcl/rootfs/" ] # 1.81 M
4646
COPY --from=codegolf/lang-c ["/", "/langs/c/rootfs/" ] # 1.61 MiB
4747
COPY --from=codegolf/lang-bash ["/", "/langs/bash/rootfs/" ] # 1.17 MiB
4848
COPY --from=codegolf/lang-sql ["/", "/langs/sql/rootfs/" ] # 1.11 MiB
49+
COPY --from=codegolf/lang-awk ["/", "/langs/awk/rootfs/" ] # 707 KiB
4950
COPY --from=codegolf/lang-wren ["/", "/langs/wren/rootfs/" ] # 484 KiB
5051
COPY --from=codegolf/lang-lua ["/", "/langs/lua/rootfs/" ] # 342 KiB
5152
COPY --from=codegolf/lang-k ["/", "/langs/k/rootfs/" ] # 258 KiB

docker/live.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ COPY --from=codegolf/lang-tcl ["/", "/langs/tcl/rootfs/" ] # 1.81 M
5959
COPY --from=codegolf/lang-c ["/", "/langs/c/rootfs/" ] # 1.61 MiB
6060
COPY --from=codegolf/lang-bash ["/", "/langs/bash/rootfs/" ] # 1.17 MiB
6161
COPY --from=codegolf/lang-sql ["/", "/langs/sql/rootfs/" ] # 1.11 MiB
62+
COPY --from=codegolf/lang-awk ["/", "/langs/awk/rootfs/" ] # 707 KiB
6263
COPY --from=codegolf/lang-wren ["/", "/langs/wren/rootfs/" ] # 484 KiB
6364
COPY --from=codegolf/lang-lua ["/", "/langs/lua/rootfs/" ] # 342 KiB
6465
COPY --from=codegolf/lang-k ["/", "/langs/k/rootfs/" ] # 258 KiB

hole/play.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ func play(ctx context.Context, holeID, langID, code string, score *Scorecard) {
197197

198198
cmd.Args = []string{"/usr/bin/defasm", "--size-out=3", "-w", "-r"}
199199
cmd.ExtraFiles = []*os.File{asmBytesWrite}
200+
case "awk":
201+
cmd.Args = []string{"/usr/bin/gawk", "-v", "RS=\\0", code}
200202
case "bash":
201203
cmd.Args = []string{"/usr/bin/bash", "-s", "-"}
202204
case "brainfuck":
@@ -263,7 +265,8 @@ func play(ctx context.Context, holeID, langID, code string, score *Scorecard) {
263265

264266
// Args
265267
switch langID {
266-
case "brainfuck", "fish":
268+
case "awk", "brainfuck", "fish":
269+
// Hole args passed through stdin for these langs separated by a null byte
267270
args := ""
268271
for _, arg := range score.Args {
269272
args += arg + "\x00"
@@ -279,8 +282,8 @@ func play(ctx context.Context, holeID, langID, code string, score *Scorecard) {
279282

280283
// Code
281284
switch langID {
282-
case "brainfuck", "elixir", "fish", "golfscript", "javascript", "perl", "sed":
283-
// For these code is passed as an argument above.
285+
case "awk", "brainfuck", "elixir", "fish", "golfscript", "javascript", "perl", "sed":
286+
// For these langs, code is passed as an argument above.
284287
case "k":
285288
code = preprocessKCode(holeID, code)
286289
cmd.Stdin = strings.NewReader(code)

langs/awk/Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM alpine:3.16 as builder
2+
3+
RUN apk add --no-cache build-base curl
4+
5+
RUN curl https://ftp.gnu.org/gnu/gawk/gawk-5.2.0.tar.xz | tar xJ
6+
7+
RUN mv gawk-* gawk \
8+
&& cd gawk \
9+
&& ./configure \
10+
--disable-extension \
11+
--disable-lint \
12+
LDFLAGS="-static" \
13+
&& make \
14+
&& strip gawk
15+
16+
FROM codegolf/lang-base
17+
18+
COPY --from=0 /gawk/gawk /usr/bin/
19+
20+
ENTRYPOINT ["gawk"]
21+
22+
CMD ["--version"]

latest-langs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use HTTP::Tiny;
44
use TOML::Thumb;
55

66
constant @urls = (
7+
'AWK' => 'AWK',
78
'Bash' => 'Bash_(Unix_shell)',
89
'BASIC' => 'FreeBASIC',
910
'C' => 'Tiny_C_Compiler',

svg/awk.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)