home *** CD-ROM | disk | FTP | other *** search
- From: <talcott!bradley!brad>
- Subject: A program called 'rpt'
- Newsgroups: mod.sources
- Approved: jpn@panda.UUCP
-
- Mod.sources: Volume 4, Issue 63
- Submitted by: Bradley Smith <talcott!bradley!brad>
-
-
- Here is the submission of a program called 'rpt'. We find it more useful
- than repeat on 'csh' and since 'sh' doesn't have it I wrote this.
-
-
- Bradley Smith UUCP: {cepu,ihnp4,noao,uiucdcs}!bradley!brad
- Text Processing ARPA: cepu!bradley!brad@UCLA-LOCUS
- Bradley University PH: (309) 676-7611 Ext. 446
- Peoria, IL 61625
-
- : This is a shar archive. Extract with sh, not csh.
- : This archive ends with exit, so do not worry about trailing junk.
- echo 'Extracting rpt.1'
- sed 's/^X//' > rpt.1 << '+ END-OF-FILE rpt.1'
- X.TH RPT 1
- X.SH NAME
- Xrpt \- general purpose repeat command
- X.SH SYNOPSIS
- X.B rpt
- X[ -inputfilename ]
- X.I count command
- X.SH DESCRIPTION
- XExecutes \fIcommand\fR the number of times specified by \fIcount\fR.
- X\fIcommand\fR may be a simple command, a pipeline, a command
- Xlist, a parenthesized command list or a quoted command list.
- XAll metacharacters in a parenthesized command list must be
- Xpreceded by a backslash.
- X.PP
- XInput for \fIcommand\fR may be taken from a file by adding
- Xa `-inputfilename' flag.
- XInput will be read in as many times as specified in \fIcount\fR.
- X.SH EXAMPLES
- X.nf
- Xrpt 100 nroff -T12 letter
- X\0\0\0formats letter 100 times
- Xrpt -names 50 nroff -T10 label
- X\0\0\0formats label 50 times using names as input file each time
- Xrpt 15 tbl costs | nroff -Tcrt12 | col | lpr
- X\0\0\0formats costs 15 times; `tbl costs' is input to rest of
- X\0\0\0pipeline during each execution
- Xrpt 15 "tbl cost | nroff -Tcrt12 | col | lpr"
- X\0\0\0similar to above, except all of quoted list before `| lpr'
- X\0\0\0is input for lpr during each execution
- Xrpt 50 \\( nroff -T12 file1 \\; nroff -T10 file2 \\)
- X\0\0\0parenthesized command list formats file1 and file2 50 times
- X\0\0\0in 12 and 10 pitch, respectively
- X.fi
- + END-OF-FILE rpt.1
- chmod 'u=r,g=r,o=' 'rpt.1'
- echo ' -r--r----- 1 brad 1192 Feb 11 22:23 rpt.1 (as sent)'
- echo -n ' '
- /bin/ls -l rpt.1
- echo 'Extracting rpt.c'
- sed 's/^X//' > rpt.c << '+ END-OF-FILE rpt.c'
- X/*
- X * rpt - repeat command much like csh but works on both sh and csh
- X *
- X * By Bradley Smith , Sep 1984
- X * {ihnp4,uiucdcs,cepu}!bradley!brad
- X * Bradley University
- X * Text Processing
- X * Peoria, IL 61625
- X */
- X#include <stdio.h>
- X#include <signal.h>
- X
- Xint pid;
- Xmain(argc, argv)
- Xchar *argv[];
- Xint argc;
- X{
- X register int i, j;
- X char *c;
- X int status[2], inpfd, swi, ret;
- X int onintr();
- X
- X
- X swi = 0;
- X if(argv[1][0] == '-') { /* input file */
- X c = argv[1];
- X c++;
- X swi = 1;
- X argv++;
- X argc--;
- X }
- X
- X if((swi== 0) && (argc < 3)) {
- X fprintf(stderr,"Usage: %s [-inputfile] count command\n",
- X argv[0]);
- X exit(4);
- X }
- X signal(SIGINT, onintr);
- X signal(SIGQUIT, onintr);
- X signal(SIGKILL, onintr);
- X ++argv;
- X --argc;
- X i = atoi(*argv);
- X argv++;
- X --argc;
- X for(j = 0; j < i; j++) {
- X pid = fork();
- X if(pid == 0) { /* child process */
- X signal(SIGINT,SIG_DFL);
- X signal(SIGQUIT,SIG_DFL);
- X signal(SIGKILL,SIG_DFL);
- X if(swi==1) { /* check on input */
- X if((inpfd=open(c,0))== (-1))
- X fprintf(stderr,"Can't open '%s'\n", c);
- X else {
- X close(0);
- X if((ret=dup(inpfd))) {
- X fprintf(stderr,"Error %d on dup\n",
- X ret);
- X }
- X }
- X }
- X run( argv, argc);
- X _exit(2);
- X }
- X while((wait(status)) != pid)
- X ;
- X }
- X exit(0);
- X}
- Xrun(argv, argc)
- Xchar **argv;
- Xint argc;
- X{
- X char **cp;
- X char cmd[5120],*cx;
- X
- X cp = argv;
- X cx = cmd;
- X
- X while(argc > 0) {
- X sprintf(cx,"%s ", *cp);
- X cx = strlen(cmd) + cmd;
- X cp++;
- X --argc;
- X }
- X execl("/bin/sh","sh","-c",cmd,0);
- X
- X}
- Xonintr()
- X{
- X sleep(2);
- X fprintf(stderr,"\nInterrupt...\n");
- X exit(1);
- X}
- + END-OF-FILE rpt.c
- chmod 'u=rw,g=rw,o=' 'rpt.c'
- echo ' -rw-rw---- 1 brad 1535 Feb 11 22:34 rpt.c (as sent)'
- echo -n ' '
- /bin/ls -l rpt.c
- exit 0
-
-