move psops to wip because broken
This commit is contained in:
20
wip/psops/Makefile
Normal file
20
wip/psops/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
CFLAGS += -g -I../libpsargs
|
||||
|
||||
all: pscat
|
||||
|
||||
pscat: pscat.o ../libpsargs/libpsargs.o
|
||||
$(CC) $(CFLAGS) -o $@ pscat.o ../libpsargs/libpsargs.o
|
||||
|
||||
pscat.o: pscat.c psops.c
|
||||
$(CC) $(CFLAGS) -DPSCAT=1 -c -o $@ pscat.c
|
||||
|
||||
pspipe: pspipe.o ../libpsargs/libpsargs.o
|
||||
$(CC) $(CFLAGS) -o $@ pspipe.o ../libpsargs/libpsargs.o
|
||||
|
||||
pspipe.o: pscat.c psops.c
|
||||
$(CC) $(CFLAGS) -DPSPIPE=1 -c -o $@ pscat.c
|
||||
|
||||
../libpsargs/libpsargs.o:
|
||||
$(MAKE) -C ../libpsargs
|
||||
|
||||
.PHONY: all
|
||||
39
wip/psops/pscat.1
Normal file
39
wip/psops/pscat.1
Normal file
@@ -0,0 +1,39 @@
|
||||
.TH PSCAT 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
pscat \- concatenate the output of processes
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
pscat
|
||||
"["
|
||||
.RB [ utility
|
||||
.RB [ argument... ]]
|
||||
"]" ...
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Pscat executes multiple commands, one after the other.
|
||||
This allows multiple processes to be piped as one to another program.
|
||||
|
||||
.SH DIAGNOSTICS
|
||||
|
||||
Pscat will print an error message and exit with the appropriate status from sysexits(3) if executed improperly.
|
||||
Pscat will exit with the sum of the child processes' exit statuses if run correctly.
|
||||
|
||||
.SH BUGS
|
||||
|
||||
Pscat's exit status isn't useful when run correctly; there's no way to tell which process failed if one did.
|
||||
This issue of ergonomics isn't obviously mendable as processes' standard outputs and standard errors are meant to both be conveyed.
|
||||
If either could be ignored the individual exit statuses could simply be printed.
|
||||
.PP
|
||||
Pscat's function is redundant to the sh(1) construct
|
||||
.RB { utility ; utility ;}
|
||||
- this is a feature, not a bug.
|
||||
.PP
|
||||
pscat [ cat | cat ] will pipe "pscat [ cat" into "cat ]", which is a potentially unexpected result of a command.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Public domain.
|
||||
33
wip/psops/pscat.c
Normal file
33
wip/psops/pscat.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <errno.h> /* errno */
|
||||
#include <stdio.h> /* fprintf(3), stderr, "psops.c" */
|
||||
#include <string.h> /* strerror(3) */
|
||||
#include <sysexits.h> /* EX_OSERR, "psops.c" */
|
||||
#include <unistd.h> /* execvp(3) */
|
||||
#include <sys/types.h> /* <sys/wait.h> */
|
||||
#include <sys/wait.h> /* wait(2) */
|
||||
|
||||
#include "libpsargs.h" /* corresponding_arg(3), "psops.c" */
|
||||
|
||||
static char *program_name = "pscat";
|
||||
|
||||
int
|
||||
f(char **argv){
|
||||
int child;
|
||||
char **corr;
|
||||
|
||||
*(corr = corresponding_arg(argv)) = NULL;
|
||||
switch(fork()){
|
||||
case -1:
|
||||
fprintf(stderr, "%s: %s\n", program_name, strerror(errno));
|
||||
return EX_OSERR;
|
||||
case 0: execvp(argv[1], argv+1);
|
||||
default:
|
||||
wait(&child);
|
||||
argv = corr;
|
||||
return *++argv == NULL
|
||||
? WIFEXITED(child) * WEXITSTATUS(child)
|
||||
: f(argv);
|
||||
}
|
||||
}
|
||||
|
||||
#include "psops.c"
|
||||
20
wip/psops/psops.c
Normal file
20
wip/psops/psops.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/* #include <stdio.h> /* fprintf(3), stderr */
|
||||
|
||||
#ifndef EX_USAGE
|
||||
# define EX_USAGE 64 /* NetBSD sysexits(3) compat */
|
||||
#endif
|
||||
|
||||
/* #include "libpsargs.h" /* check_arg(3) */
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if(argc != 0)
|
||||
program_name = argv[0];
|
||||
if(check_arg(++argv) == 0){
|
||||
fprintf(stderr,
|
||||
"Usage: %s \"[\" [utility [argument...]] \"]\" ...\n",
|
||||
program_name
|
||||
);
|
||||
return EX_USAGE;
|
||||
}else return f(argv);
|
||||
}
|
||||
53
wip/psops/pspipe.c
Normal file
53
wip/psops/pspipe.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <errno.h> /* errno */
|
||||
#include <stdio.h> /* fprintf(3), stderr, "psops.c" */
|
||||
#include <string.h> /* strerror(3) */
|
||||
#include <sysexits.h> /* EX_OSERR */
|
||||
#include <unistd.h> /* execvp(3) */
|
||||
#include <sys/types.h> /* <sys/wait.h> */
|
||||
#include <sys/wait.h> /* wait(2) */
|
||||
|
||||
#include "libpsargs.h" /* corresponding_arg(3), "psops.c" */
|
||||
|
||||
static char *program_name = "pspipe";
|
||||
|
||||
/* At the start of the loop argv[0] is { '[', '\0' } and file descriptor 0 is
|
||||
* the intended standard input */
|
||||
int
|
||||
f(char **argv){
|
||||
static int child;
|
||||
char **corr;
|
||||
int fd[2];
|
||||
int r;
|
||||
|
||||
*(corr = corresponding_arg(argv)) = NULL;
|
||||
if(corr[1] != NULL){
|
||||
if(pipe(fd) != 0){
|
||||
fprintf(stderr,
|
||||
"%s: %s: %s\n",
|
||||
program_name, argv[1], strerror(errno)
|
||||
);
|
||||
return EX_OSERR;
|
||||
}
|
||||
if((r = fork()) == -1){
|
||||
fprintf(stderr, "%s: %s\n",
|
||||
program_name, strerror(errno)
|
||||
);
|
||||
return EX_OSERR;
|
||||
}
|
||||
if(r == 0)
|
||||
dup2(fd[0], 0);
|
||||
else
|
||||
dup2(fd[1], 1);
|
||||
close(fd[1]);
|
||||
close(fd[0]);
|
||||
if(r == 1)
|
||||
execvp(argv[1], argv+1);
|
||||
}
|
||||
|
||||
argv = corr;
|
||||
return *++argv == NULL
|
||||
? WEXITSTATUS(child)
|
||||
: f(corr + 1);
|
||||
}
|
||||
|
||||
#include "psops.c"
|
||||
Reference in New Issue
Block a user