First import
git-svn-id: http://photonzero.com/dotfiles/trunk@1 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
commit
83d40113d2
60 changed files with 4264 additions and 0 deletions
15
bin/build/src/gettermsize/gettermsize.c
Normal file
15
bin/build/src/gettermsize/gettermsize.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
struct winsize size;
|
||||
ioctl(STDIN_FILENO, TIOCGWINSZ, (char *) &size);
|
||||
printf("%d x %d\n", size.ws_col, size.ws_row);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
59
bin/build/src/wye/wye.1
Normal file
59
bin/build/src/wye/wye.1
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
.\" $Id: wye.1,v 1.1 1999-05-03 10:04:59-07 mconst Exp mconst $
|
||||
.TH WYE 1
|
||||
.fi
|
||||
.SH NAME
|
||||
wye \- another pipe fitting
|
||||
.SH SYNOPSIS
|
||||
\fC`\fIsubcommand\fP | wye`\fR (note the backquotes!)
|
||||
.SH DESCRIPTION
|
||||
The \fCwye\fR utility is used to create systems of pipes and fifos
|
||||
(named pipes) more complicated than standard shell syntax allows.
|
||||
A single invocation of \fCwye\fR has the following effect: a temporary
|
||||
fifo is created; the name of this fifo is printed on standard output;
|
||||
and \fCwye\fR exits, leaving a child process in the background to copy
|
||||
any data received on standard input to the fifo. The net effect of
|
||||
this is that you can use the expression \fC`\fIsubcommand\fP | wye`\fR
|
||||
anywhere on a command line that you would use a filename, and the output of
|
||||
\fIsubcommand\fP will be piped appropriately to create the illusion that
|
||||
\fC`\fIsubcommand\fP | wye`\fR is a file, containing the output of
|
||||
\fIsubcommand\fR.
|
||||
.SH EXAMPLES
|
||||
Since \fCwye\fR is a simple command, I have given it a simple
|
||||
description; however, some examples are certainly in order.
|
||||
To print all lines of the standard input which contain the name
|
||||
of a file in the current directory:
|
||||
.nf
|
||||
|
||||
\fCfgrep \-f `ls | wye`\fR
|
||||
|
||||
.fi
|
||||
To show which users log on or off in the next minute:
|
||||
.nf
|
||||
|
||||
\fCdiff \-h `who | wye` `sleep 60; who | wye`\fR
|
||||
|
||||
.fi
|
||||
To change the names of all the files in the current directory to lowercase:
|
||||
.nf
|
||||
|
||||
\fCpaste `ls | wye` `ls | tr A\-Z a\-z | wye` | xargs \-n2 mv\fR
|
||||
.fi
|
||||
.SH FILES
|
||||
\fC/tmp/wye.??????\fR temporary fifos
|
||||
.SH BUGS
|
||||
The background \fCwye\fR process has a (hardcoded) one-hour timeout: if the
|
||||
fifo is not opened for reading by another process in that time, then the
|
||||
background \fCwye\fR process will terminate silently. Note that this will
|
||||
probably never happen unless the user has made a mistake and forgotten to
|
||||
use the fifo for anything.
|
||||
.PP
|
||||
There is no equivalent of \fCmkstemp\fR(\fC3\fR) for fifos, so we
|
||||
must provide the same functionality ourselves with \fCmktemp\fR(\fC3\fR)
|
||||
and \fCmkfifo\fR(\fC2\fR), repeating the calls if
|
||||
.SM EEXIST
|
||||
is returned.
|
||||
.SH AUTHOR
|
||||
Michael Constant (mconst@csua.berkeley.edu).
|
||||
.SH "SEE ALSO"
|
||||
\fCmktemp\fR(\fC3\fR), \fCmkstemp\fR(\fC3\fR), \fCmkfifo\fR(\fC2\fR),
|
||||
\fCtee\fR(\fC1\fR)
|
||||
72
bin/build/src/wye/wye.c
Normal file
72
bin/build/src/wye/wye.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* wye.c, written by Michael Constant (mconst@csua.berkeley.edu) and placed
|
||||
* in the public domain. $Id: wye.c,v 1.1 1999-05-03 10:04:59-07 mconst $ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define TEMPMASK "/tmp/wye.XXXXXX" /* the name of our tempfile */
|
||||
#define TIMEOUT 3600 /* time we wait for the fifo to open */
|
||||
|
||||
void cleanup(int sig);
|
||||
|
||||
char tempfile[]=TEMPMASK;
|
||||
|
||||
int main()
|
||||
{
|
||||
int ch;
|
||||
FILE *fp;
|
||||
|
||||
/* create the fifo. if we get EEXIST, then someone else created a
|
||||
* file with our intended name right before we did; we should pick
|
||||
* a new name and try again. see the source to mkstemp(3). */
|
||||
while (mkfifo(mktemp(tempfile), 0600) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
perror("wye: couldn't create fifo");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(tempfile, TEMPMASK);
|
||||
}
|
||||
|
||||
/* remove our tempfile if we die */
|
||||
signal(SIGHUP, cleanup);
|
||||
signal(SIGINT, cleanup);
|
||||
signal(SIGTERM, cleanup);
|
||||
signal(SIGALRM, cleanup);
|
||||
|
||||
/* fork a child to do the work */
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
perror("wye: couldn't fork");
|
||||
exit(1);
|
||||
|
||||
case 0:
|
||||
fclose(stdout); /* this is necessary for `cmd | wye` */
|
||||
alarm(TIMEOUT); /* this is if the fifo never opens */
|
||||
|
||||
/* this will block until someone else opens the fifo */
|
||||
if ((fp = fopen(tempfile, "w")) == NULL) {
|
||||
perror("wye: couldn't open fifo");
|
||||
exit(1); /* not as if anyone cares */
|
||||
}
|
||||
|
||||
alarm(0); /* cancel the alarm */
|
||||
unlink(tempfile); /* so it disappears when we're done */
|
||||
while ((ch = getchar()) != EOF) putc(ch, fp);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* output the name of the fifo */
|
||||
printf("%s\n", tempfile);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void cleanup(int sig)
|
||||
{
|
||||
unlink(tempfile);
|
||||
exit(2);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue