A slower and better download source
mbs at ecsvax.UUCP
mbs at ecsvax.UUCP
Mon Mar 5 11:38:19 AEST 1984
<>
For those of you who don't have protocol oriented file transder programs
and whose micro has trouble keeping up with a downloaded cat may want
to consider using the following program to download your sources. It
reads the file you wish to download 2 lines at a time, writes the
output to STDOUT, and then sleeps for 1 second. For me, it has
prevented the loss of a lot of data, since my micro has difficulty
keeping up. For those on the ecsvax machine, a copy of the object
code is in the directory /ecs/pub/misc under the name "copy", and
the source file is in the same directory, but named "copy.c".
--- Michael Smith
{ittvax!ittral, akgua!mcnc, decvax!mcnc}!ecsvax!mbs
main(argc, argv)
int argc;
char **argv;
{
char *p;
short fin;
extern char *get_line();
if( argc != 2 )
{
printf("invalid number of arguments\n");
exit(1);
}
if( (fin = open(argv[1], 0)) < 0 )
{
printf("cannot open: %s \n", argv[1]);
exit(1);
}
while( 1 )
{
p = get_line(fin);
write(1, p, strlen(p));
p = get_line(fin);
if( *p == '\0' )
{
close(fin); /* this condition signifies end-of-file */
exit(0);
}
write(1, p, strlen(p));
sleep(1);
}
}
char get_char(fyle)
short fyle;
{
char c;
if( read(fyle, &c, 1) != 1 ) return( -1 );
else return( c );
}
char *get_line(fyle)
short fyle;
{
char c;
register char *pb;
static char buf[512];
pb = buf;
while( (c = get_char(fyle)) > 0 )
if( c == '\n' )
{
*pb++ = '\n';
break;
}
else if ( c < 0 ) break;
else *pb++ = c;
*pb = '\0';
if( c < 0 ) return( pb );
else return( buf );
}
More information about the Comp.sources.unix
mailing list