|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 1307 (0x51b)
Types: TextFile
Names: »repeat.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen
└─⟦this⟧ »cph85dist/stat/src/repeat.c«
#include "unixstat.h"
PGM(repeat,Repeat a File or String,5.0,2/27/85)
/* Copyright (c) 1982 Gary Perlman (see Copyright file) */
char *
saveit ()
{
static char tmpfile[BUFSIZ];
register int C;
register FILE *ioptr;
#ifndef MSDOS /* use fixed temp file on MSDOS */
VOID sprintf (tmpfile, "/tmp/repeat%d", getpid ());
#else
VOID strcpy (tmpfile, "repeat.tmp");
#endif
if (ioptr = fopen (tmpfile, "w"))
{
checkstdin (Argv0);
while ((C = getchar ()) != EOF)
putc (C, ioptr);
VOID fclose (ioptr);
}
return (tmpfile);
}
main (argc, argv) char **argv;
{
int count;
ARGV0;
if (argc != 2 && argc != 3)
USAGE (count [file])
if (!INTEGER (argv[1]))
ERRNUM (argv[1],repetition count)
count = atoi (argv[1]);
if (argc == 2)
{
if (count < 0)
ERRMSG0 (No string repetition for standard input)
repeat (saveit (), count);
}
else repeat (argv[2], count);
exit (0);
}
repeat (name, n)
char *name; /* string or file to be repeated */
int n; /* if < 0 then just print name */
{
register int C;
register FILE *ioptr;
if (n < 0)
while (n++ < 0)
puts (name);
else if (ioptr = fopen (name, "r"))
{
while (n-- > 0)
{
while ((C = getc (ioptr)) != EOF)
putchar (C);
if (n > 0) rewind (ioptr);
}
fclose (ioptr);
}
else
ERROPEN (name)
}