jac@yoko.rutgers.edu (Jonathan A. Chandross) (12/02/90)
Submitted-by: NONE
Posting-number: Volume 1, Source:10
Archive-name: util/page
Architecture: ANY_2
Version-number: 1.00
Enclosed is page.c. It allows you to view a file one page at a
time.
Enjoy.
=page.c
-
-/*
- *
- * page.c
- *
- * Examine a file one screenful at a time.
- *
- * Developed for the AZTEC C system for the Apple ][+, Apple //e computer.
- * Based on a more.c by aluxe!ira.
- *
- * Bob Cunningham
- * bob@kahala.soest.hawaii.edu
- * November 19, 1983
- *
- * Version 1.00
- *
- * This code is offered without any warranty or support.
- *
- */
-
-#include "kbctl.h"
-#include "stdio.h"
-
-#define SCRNSIZE 24
-#define MAXLINE 1000
-#define NEWPAGE ioctl( 1, KB_CLEAR)
-
-char str_e[] = " End of ";
-char str_m[] = "--More-- ";
-char str_more[] = " [Hit 'space' to continue, 'q' to quit] ";
-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("page: illegal option %c\n",
- *s );
- argc = 0;
- break;
- }
- if ( argc < 1 )
- {
- printf("Usage: page file1 [ file2 file3 .. ]\n");
- exit(1);
- }
- else
- *--argv;
- if ( argc >= 2 )
- flag = 1;
- while ( --argc >= 0 )
- {
- if ((fp = fopen(*++argv, "r")) == NULL)
- {
- printf("page: can't open %s\n", *argv);
- exit(1);
- }
- NEWPAGE;
- if (flag)
- {
- printf(":::::::::::::::::::\n");
- printf("%s\n",*argv);
- printf(":::::::::::::::::::\n");
- lineno = 2;
- }
- fp->bufsiz = 2048;
- file_len = strlen (*argv);
- while ( (len = getline(line, MAXLINE, fp)) > 0)
- {
- lineno++;
- write( 1, line, len );
- if ( lineno % srnsize == 0 )
- {
- if ( more(str_m,*argv) == -1 )
- exit(0);
- lineno = 0;
- }
- }
- fclose(fp);
- if ( (argc >= 1) )
- {
- fflush(stdout);
- if ( more(str_e,*argv) == -1 )
- exit(0);
- }
- 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(msg,file)
- char *msg;
- char *file;
- {
- int c;
-
- ioctl ( 1, KB_INV, 1 );
- write ( 1, msg, 11);
- write ( 1, file, file_len);
- write ( 1, str_more, 42 );
- 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);
- NEWPAGE;
- }
-
+ END OF ARCHIVE