pg.c revision 4fce32e15d9c284a06aea2e40852f6674f03b63e
f56e4fe56fdf66d711e5fafaa71c2587dd9a066fChristian Maeder * CDDL HEADER START
accab0bf9b8aa690d70174f41fe94370323959b9Christian Maeder * The contents of this file are subject to the terms of the
f56e4fe56fdf66d711e5fafaa71c2587dd9a066fChristian Maeder * Common Development and Distribution License, Version 1.0 only
f56e4fe56fdf66d711e5fafaa71c2587dd9a066fChristian Maeder * (the "License"). You may not use this file except in compliance
accab0bf9b8aa690d70174f41fe94370323959b9Christian Maeder * with the License.
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
#include <signal.h>
#include <setjmp.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdio.h>
#include <wchar.h>
#include <curses.h>
#include <term.h>
#include <errno.h>
#include <stdlib.h>
#include <regexpr.h>
#include <limits.h>
#include <locale.h>
#include <string.h>
#include <unistd.h>
#include <wait.h>
#include <libw.h>
#include <regexpr.h>
static void lineset(int);
static char *setprompt();
static void help();
static void re_error(int);
static void save_pipe();
static void erase_line(int);
static void kill_line();
static void doclear();
static void sopr(char *, int);
static void prompt(char *);
static void error(char *);
static void terminit();
static void compact();
static int mrdchar();
static int skipf(int);
static int readch();
static int ttyin();
static int number();
static int command(char *);
static int screen(char *);
static int fgetputc();
static char *pg_strchr();
static void on_brk(),
end_it();
static char **fnames;
static int initline;
static short nfiles;
static char *shell;
static int catch_susp;
static void onsusp();
struct screen_stat {
short is_eof;
static void usage(void);
int prnames = 0;
int opt;
usage();
while (i < argc) {
argc--;
srchopt++;
initopt = 0;
initopt++;
srchopt = 0;
for (; isdigit(*s); s++)
usage();
while (i < argc) {
argc--;
switch (opt) {
eof_pause = 0;
usage();
if (out_is_tty) {
terminit();
catch_susp++;
if (window == 0)
if (initline <= 0)
prnames++;
if (nfiles == 0) {
nfiles++;
fnum++;
status = 0;
if (out_is_tty)
if (prnames) {
stdout);
stdout);
fnum++;
if (pipe_in)
save_pipe();
end_it();
setprompt(s)
int pct_d = 0;
switch (pstr[i++] = *s++) {
return (pstr);
pct_d++;
return (pstr);
char *file_name;
int cmd_ret = 0;
short hadchance = 0;
if (!firstf)
firstf = 0;
if (initopt) {
initopt = 0;
} else if (srchopt) {
srchopt = 0;
if (cmd_ret)
return (cmd_ret);
hadchance = 0;
if (clropt) {
doclear();
if (brk_hit) {
brk_hit = 0;
hadchance++;
char *filename;
char *cmdend;
int skip;
int len;
end_it();
brk_hit = 0;
if (errors)
errors = 0;
kill_line();
if (ttyin())
switch (wc) {
CHECKEND();
help();
CHECKEND();
inwait = 0;
BEEP();
CHECKEND();
if (nlines == 0)
BEEP();
inwait = 0;
CHECKEND();
if (sign == 0)
inwait = 0;
if (!*cmdptr) {
BEEP();
BEEP();
kill_line();
CHECKEND();
inwait = 0;
end_it();
CHECKEND();
if (sign == 0)
if (nlines == 0)
nlines++;
inwait = 0;
CHECKEND();
if (nlines == 0) {
nlines++;
if (sign == 0)
switch (sign) {
inwait = 0;
if (nlines == 0) {
nlines++;
if (sign == 0)
switch (sign) {
inwait = 0;
CHECKEND();
if (sign == 0)
if (nlines == 0)
nlines++;
BEEP();
inwait = 0;
return (skip);
CHECKEND();
if (sign == 0)
if (nlines == 0)
nlines++;
BEEP();
inwait = 0;
return (skip);
CHECKEND();
inwait = 0;
if (sign < 0) {
BEEP();
if (nlines == 0)
nlines++;
cmdptr--;
wc_e = *p;
cmdend--;
inwait = 0;
if (catch_susp)
errno = 0;
if (catch_susp)
BEEP();
number()
sign = 0;
p = cmdptr;
BLANKS(p);
while (isdigit(*p))
cmdptr = p;
ttyin()
char *sptr, *p;
int slash = 0;
int state = 0;
static int readch();
int len;
(void) fixterm();
BEEP();
length = 0;
p = cmdbuf;
while (p < sptr) {
oldp = p;
if (len <= 0) {
wchar = (unsigned char)*p;
p += len;
while (width--)
if (hard_copy)
(void) resetterm();
width = 0;
if (slash) {
slash = 0;
sptr--;
promptlen--;
BEEP();
slash++;
BEEP();
p = multic;
while (length--)
(void) putchar(*p++);
kill_line();
(void) resetterm();
int *pstate;
wchar_t c;
char *pc;
static char *psign;
static char *pnumber;
static char *pcommand;
static int slash;
if (*pstate == 0) {
slash = 0;
slash++;
switch (*pstate) {
slash = 0;
switch (*pstate) {
if (nflag)
readch()
help()
if (clropt)
doclear();
stdout);
int nskip;
if (nskip == 0)
if (nskip == 0)
return (nskip);
static FILE *
char *fs;
FILE *f;
int fd;
int f_was_opened;
pipe_in = 0;
f = stdin;
f = tmp_fin;
f_was_opened = 0;
if (f_was_opened)
(void) fclose(f);
if (f_was_opened)
(void) fclose(f);
if (f != stdin) {
if (f_was_opened)
(void) fclose(f);
re_error(i)
static struct messages {
char *message;
int number;
} re_errmsg[] = {
char buf[];
off_t n;
int direction;
static char *expbuf;
char *nexpbuf;
int END_COND;
if (regerrno) {
if (expbuf)
if (brk_hit)
if ((n -= direction) == 0) {
switch (leave_search) {
BEEP();
* So...there are basically three cases that this routine
static off_t
int how;
if (how == 0)
eoflag = 0;
if (doliseof) {
eoflag++;
return (EOF);
if (pipe_in)
dot++;
newdol(f);
eoflag++;
doliseof++;
return (EOF);
if (pipe_in) {
return (BOF);
static int (*rdchar)();
mrdchar()
static off_t
getline(f)
FILE *f;
int column;
static int savlength;
wchar_t c;
fileptr = f;
if (savlength)
if ((c = mrdchar()) <= 0) {
clearerr(f);
return (column);
return (EOF);
if (length < 0) {
width = 0;
p += length;
length = 0;
if (column > 0)
column--;
column = 0;
if (savlength == 0) {
c = fgetwc(f);
(void) ungetwc(c, f);
(void) (*rdchar)(f);
} else if (c == EOF)
clearerr(f);
(void) ungetwc(c, f);
savlength = 0;
return (column);
save_input(f)
FILE *f;
if (pipe_in) {
save_pipe();
pipe_in = 0;
if (!doliseof)
if (brk_hit) {
brk_hit = 0;
FILE *f;
int how;
eoflag = 0;
doliseof = 0;
FILE *f;
int diff;
compact();
dol++;
if (!pipe_in)
compact()
end_it();
int err_ret;
(void) saveterm();
(void) resetterm();
if (columns <= 0)
clropt = 0;
char *mess;
kill_line();
errors++;
char *filename;
int pagenum;
int count;
int len, n;
if (count) {
for (; *p; p += len) {
promptlen += n;
doclear()
if (clear_screen)
erase_line(0);
int col;
if (promptlen == 0)
if (hard_copy)
if (col == 0)
if (clr_eol) {
promptlen = 0;
if (!inwait) {
BEEP();
brk_hit = 0;
end_it()
if (out_is_tty) {
kill_line();
(void) resetterm();
if (termflg)
if (tmp_fin)
if (tmp_fou)
onsusp()
int ttou_is_dfl;
(void) resetterm();
if (ttou_is_dfl)
#ifdef __STDC__
(void) resetterm();
if (inwait)
char *str;
wchar_t c;
while (*str) {
if (c == *str)
return (str);
str++;
usage()