Skip to content

Commit

Permalink
Bump iogii (0.2) (code-golf#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yewzir authored Jan 1, 2025
1 parent b17aaf2 commit 7f25a63
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/data/langs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ example = '''
args = [ '/usr/bin/iogiiwrapper', '-' ]
experiment = 1770
size = '34.1 MiB'
version = '0.1'
version = '0.2'
website = 'https://golfscript.com/iogii/'
example = '''
# Printing
Expand Down
2 changes: 1 addition & 1 deletion langs/iogii/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM alpine:3.21 AS builder

RUN apk add --no-cache gcc musl-dev

ENV VER=0.1
ENV VER=0.2

RUN wget -cO /usr/bin/iogii https://golfscript.com/iogii/iogii-$VER-alpha \
&& chmod +x /usr/bin/iogii
Expand Down
47 changes: 10 additions & 37 deletions langs/iogii/iogiiwrapper.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#define ERR_AND_EXIT(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0)

const char* iogii = "/usr/bin/iogii", *code = "code.iog", *input = "argv.txt";
const char* iogii = "/usr/bin/iogii", *code = "code.iog";

int main(int argc, char* argv[]) {
if (!strcmp(argv[1], "--version")) {
Expand All @@ -33,39 +31,14 @@ int main(int argc, char* argv[]) {
if (fclose(fp))
ERR_AND_EXIT("fclose");

int fd;
int iargc = argc + 2;
char** iargv = malloc(iargc * sizeof(char*));
iargv[0] = (char*) iogii;
iargv[1] = (char*) code;
iargv[2] = "--";
memcpy(&iargv[3], &argv[2], (argc - 2) * sizeof(char*));
iargv[iargc - 1] = NULL;

if (!(fd = open(input, O_CREAT | O_TRUNC | O_WRONLY, 0644)))
ERR_AND_EXIT("open");

for (int i = 2; i < argc; i++)
if (write(fd, argv[i], strlen(argv[i])) < 0 || write(fd, "\n", sizeof(char)) < 0) {
if (close(fd))
ERR_AND_EXIT("close");

ERR_AND_EXIT("write");
}

if (close(fd))
ERR_AND_EXIT("close");

pid_t pid;

if (!(pid = fork())) {
if (dup2(open(input, O_RDONLY), STDIN_FILENO))
ERR_AND_EXIT("dup2");

execl(iogii, iogii, code, NULL);
ERR_AND_EXIT("execl");
}

int status;

waitpid(pid, &status, 0);

if (!WIFEXITED(status))
exit(EXIT_FAILURE);

if (WEXITSTATUS(status))
return WEXITSTATUS(status);
execv(iogii, iargv);
ERR_AND_EXIT("execv");
}

0 comments on commit 7f25a63

Please sign in to comment.