From ef7899f01c6c20b7d18e1b668459a632a989f0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 12 Jul 2021 18:03:52 +0200 Subject: flip: Rewrite in C --- etc/flip | 3 --- etc/flip.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) delete mode 100755 etc/flip create mode 100644 etc/flip.c diff --git a/etc/flip b/etc/flip deleted file mode 100755 index 614bc67..0000000 --- a/etc/flip +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/perl - -exec (shift @ARGV, pop @ARGV, @ARGV); diff --git a/etc/flip.c b/etc/flip.c new file mode 100644 index 0000000..dcd6bc0 --- /dev/null +++ b/etc/flip.c @@ -0,0 +1,31 @@ +/* + * flip -- put last argument after first argument + * $ cc -O2 -o flip flip.c + */ + +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int i; + + if(argc-1 == 0){ + fprintf(stderr, "usage: %s command [arg ...]\n", argv[0]); + return 1; + } + + /* Move last argument after first argument. */ + if(argc-1 > 2){ + for(i = argc; i >= 3; i--) + argv[i] = argv[i-1]; + argv[2] = strdup(argv[argc]); + argv[argc] = NULL; + } + + execvp(argv[1], argv+1); +} -- cgit v1.2.3