more.c AZTEC C (fast version)
lra at aluxe.UUCP
lra at aluxe.UUCP
Wed Nov 16 13:30:27 AEST 1983
/*
* more.c ** 11-15-83
* Developed for the AZTEC C system for the
* Apple ][+, Apple //e computer.
*/
#include "kbctl.h"
#include "stdio.h"
#define SCRNSIZE 24
#define MAXLINE 1000
char str_m[] = "--More-- ";
char str_more[] = " [Hit 'space' to continue, 'q' to quit file] ";
int file_len;
main(argc, argv)
int argc;
char *argv[];
{
char line[MAXLINE], *s;
long lineno;
int flag, srnsize, len;
FILE * fp, *fopen();
flag = lineno = 0;
srnsize = SCRNSIZE - 2;
while (--argc > 0 && (*++argv)[0] == '-' )
for (s = argv[0] + 1; *s != '\0'; s++)
switch (*s) {
default:
printf("more: illegal option %c\n", *s );
argc = 0;
break;
}
if ( argc < 1 ) {
printf("Usage: more file1 [ file2 file3 .. ]\n");
exit(1);
} else
*--argv;
if ( argc >= 2 )
flag = 1;
while ( --argc >= 0 ) {
if ((fp = fopen(*++argv, "r")) == NULL) {
printf("more: can't open %s\n", *argv);
exit(1);
}
fp->bufsiz = 2048;
file_len = strlen (*argv);
while ( (len = getline(line, MAXLINE, fp)) > 0) {
lineno++;
if (flag && lineno == 1) {
printf("\n\n:::::::::::::::::::\n");
printf("File: %s\n", *argv);
printf(":::::::::::::::::::\n\n\n");
fflush(stdout);
if ( more(*argv) == -1 )
break;
}
write( 1, line, len );
if ( lineno % srnsize == 0 ) {
if ( more(*argv) == -1 )
break;
lineno = 2;
}
}
fclose(fp);
lineno = 0;
}
}
getline(s, lim, fp)
char *s;
int lim;
FILE *fp;
{
char c, *pc;
pc = s;
while (--lim > 0 && (c = agetc(fp) ) != EOF && c != '\n' )
*pc++ = c;
if (c == '\n' )
*pc++ = c;
*pc = '\0';
return((int)(pc - s));
}
more(file)
char *file;
{
int c;
ioctl ( 1, KB_INV, 1 );
write ( 1, str_m, 11);
write ( 1, file, file_len);
write ( 1, str_more, 47 );
ioctl ( 1, KB_INV, 0 );
c = getchar();
ioctl ( 1, KB_CURS, ( 23 << 8 ) | 0 );
ioctl ( 1, KB_CLEOL );
if ( c != ' ' && c != 'q' )
more(file);
if ( c == 'q' )
return(-1);
}
More information about the Comp.sources.unix
mailing list