p.c (schily-2021-08-14.tar.bz2) | : | p.c (schily-2021-09-18.tar.bz2) | ||
---|---|---|---|---|
/* @(#)p.c 1.73 21/07/22 Copyright 1985-2021 J. Schilling */ | /* @(#)p.c 1.75 21/08/20 Copyright 1985-2021 J. Schilling */ | |||
#include <schily/mconfig.h> | #include <schily/mconfig.h> | |||
#ifndef lint | #ifndef lint | |||
static UConst char sccsid[] = | static UConst char sccsid[] = | |||
"@(#)p.c 1.73 21/07/22 Copyright 1985-2021 J. Schilling"; | "@(#)p.c 1.75 21/08/20 Copyright 1985-2021 J. Schilling"; | |||
#endif | #endif | |||
/* | /* | |||
* Print some files on screen | * Print some files on screen | |||
* | * | |||
* Copyright (c) 1985-2021 J. Schilling | * Copyright (c) 1985-2021 J. Schilling | |||
*/ | */ | |||
/* | /* | |||
* The contents of this file are subject to the terms of the | * The contents of this file are subject to the terms of the | |||
* Common Development and Distribution License, Version 1.0 only | * Common Development and Distribution License, Version 1.0 only | |||
* (the "License"). You may not use this file except in compliance | * (the "License"). You may not use this file except in compliance | |||
skipping to change at line 48 | skipping to change at line 48 | |||
#include <schily/errno.h> | #include <schily/errno.h> | |||
#define ungetch dos_ungetch /* Avoid DOS/curses ungetch() type clash */ | #define ungetch dos_ungetch /* Avoid DOS/curses ungetch() type clash */ | |||
#include <schily/termios.h> | #include <schily/termios.h> | |||
#undef ungetch /* Restore our old value */ | #undef ungetch /* Restore our old value */ | |||
#include <schily/nlsdefs.h> | #include <schily/nlsdefs.h> | |||
#include <schily/limits.h> /* for MB_LEN_MAX */ | #include <schily/limits.h> /* for MB_LEN_MAX */ | |||
#include <schily/ctype.h> /* For isprint() */ | #include <schily/ctype.h> /* For isprint() */ | |||
#include <schily/wchar.h> /* wchar_t */ | #include <schily/wchar.h> /* wchar_t */ | |||
#include <schily/wctype.h> /* For iswprint() */ | #include <schily/wctype.h> /* For iswprint() */ | |||
#include <schily/patmatch.h> | #include <schily/patmatch.h> | |||
#define GT_COMERR /* #define comerr gtcomerr */ | ||||
#define GT_ERROR /* #define error gterror */ | ||||
#include <schily/schily.h> | #include <schily/schily.h> | |||
#define SEARCHSIZE 256 | #define SEARCHSIZE 256 | |||
#define DEF_PSIZE 24; | #define DEF_PSIZE 24; | |||
#define DEF_LWIDTH 80; | #define DEF_LWIDTH 80; | |||
#if MB_LEN_MAX > 1 | #if MB_LEN_MAX > 1 | |||
/* | /* | |||
* We are on a platform that supports multi byte characters. | * We are on a platform that supports multi byte characters. | |||
*/ | */ | |||
skipping to change at line 311 | skipping to change at line 313 | |||
int i; | int i; | |||
int cac; | int cac; | |||
char *const *cav; | char *const *cav; | |||
int fac; | int fac; | |||
char **fav; | char **fav; | |||
save_args(ac, av); | save_args(ac, av); | |||
(void) setlocale(LC_ALL, ""); | (void) setlocale(LC_ALL, ""); | |||
#ifdef USE_NLS | ||||
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ | ||||
#define TEXT_DOMAIN "p" /* Use this only if it weren't */ | ||||
#endif | ||||
{ char *dir; | ||||
dir = searchfileinpath("share/locale", F_OK, | ||||
SIP_ANY_FILE|SIP_NO_PATH, NULL); | ||||
if (dir) | ||||
(void) bindtextdomain(TEXT_DOMAIN, dir); | ||||
else | ||||
#if defined(PROTOTYPES) && defined(INS_BASE) | ||||
(void) bindtextdomain(TEXT_DOMAIN, INS_BASE "/share/locale"); | ||||
#else | ||||
(void) bindtextdomain(TEXT_DOMAIN, "/usr/share/locale"); | ||||
#endif | ||||
(void) textdomain(TEXT_DOMAIN); | ||||
} | ||||
#endif /* USE_NLS */ | ||||
cac = --ac; | cac = --ac; | |||
cav = ++av; | cav = ++av; | |||
if (getallargs(&cac, &cav, options, &help, &prvers, &debug, &nobeep, | if (getallargs(&cac, &cav, options, &help, &prvers, &debug, &nobeep, | |||
&psize, &psize, | &psize, &psize, | |||
&lwidth, &lwidth, | &lwidth, &lwidth, | |||
&supressblank, &supressblank, | &supressblank, &supressblank, | |||
&clear, &clear, | &clear, &clear, | |||
&dosmode, &autodos, | &dosmode, &autodos, | |||
&endline, &endline, | &endline, &endline, | |||
skipping to change at line 333 | skipping to change at line 354 | |||
&silent, &silent, | &silent, &silent, | |||
&tab, &tab, | &tab, &tab, | |||
&ununderline, | &ununderline, | |||
&visible, &visible) < 0) { | &visible, &visible) < 0) { | |||
errmsgno(EX_BAD, "Bad flag: %s.\n", cav[0]); | errmsgno(EX_BAD, "Bad flag: %s.\n", cav[0]); | |||
usage(EX_BAD); | usage(EX_BAD); | |||
} | } | |||
if (help) usage(0); | if (help) usage(0); | |||
if (prvers) { | if (prvers) { | |||
/* BEGIN CSTYLED */ | /* BEGIN CSTYLED */ | |||
printf("p %s %s (%s-%s-%s)\n\n", "2.3", "2021/07/22", HOST_CPU, H | gtprintf("p %s %s (%s-%s-%s)\n\n", "2.4", "2021/08/20", HOST_CPU, | |||
OST_VENDOR, HOST_OS); | HOST_VENDOR, HOST_OS); | |||
printf("Copyright (C) 1985, 87-92, 95-99, 2000-2021 Jörg Schillin | gtprintf("Copyright (C) 1985, 87-92, 95-99, 2000-2021 %s\n", _("J | |||
g\n"); | örg Schilling")); | |||
printf("This is free software; see the source for copying conditi | gtprintf("This is free software; see the source for copying condi | |||
ons. There is NO\n"); | tions. There is NO\n"); | |||
printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A P | gtprintf("warranty; not even for MERCHANTABILITY or FITNESS FOR A | |||
ARTICULAR PURPOSE.\n"); | PARTICULAR PURPOSE.\n"); | |||
/* END CSTYLED */ | /* END CSTYLED */ | |||
exit(0); | exit(0); | |||
} | } | |||
shell = getenv("BEEP"); | shell = getenv("BEEP"); | |||
if (shell != NULL && streql(shell, "off")) | if (shell != NULL && streql(shell, "off")) | |||
nobeep = TRUE; | nobeep = TRUE; | |||
if ((editor = getenv("EDITOR")) == NULL) | if ((editor = getenv("EDITOR")) == NULL) | |||
editor = "vi"; | editor = "vi"; | |||
if ((shell = getenv("SHELL")) == NULL) | if ((shell = getenv("SHELL")) == NULL) | |||
skipping to change at line 448 | skipping to change at line 469 | |||
} else { | } else { | |||
if (cac < fac) { | if (cac < fac) { | |||
cac++, cav--; | cac++, cav--; | |||
} | } | |||
} | } | |||
if (silent) break; | if (silent) break; | |||
if (i++ == 0) putchar('\n'); | if (i++ == 0) putchar('\n'); | |||
err: | err: | |||
start_standout(); | start_standout(); | |||
printf("NEXT FILE (%s)?", *cav); | gtprintf("NEXT FILE (%s)?", *cav); | |||
end_standout(); | end_standout(); | |||
fflush(stdout); | fflush(stdout); | |||
lines = psize-2; | lines = psize-2; | |||
switch (get_action()) { | switch (get_action()) { | |||
case -1: | case -1: | |||
goto err; | goto err; | |||
case 1: | case 1: | |||
continue; | continue; | |||
skipping to change at line 668 | skipping to change at line 689 | |||
off_t size = -1; | off_t size = -1; | |||
off_t pos = -1; | off_t pos = -1; | |||
lines = psize-2; | lines = psize-2; | |||
if (f) { | if (f) { | |||
size = filesize(f); | size = filesize(f); | |||
pos = filepos(f) - len; | pos = filepos(f) - len; | |||
} | } | |||
start_standout(); | start_standout(); | |||
if (!*filename || !f || size < 0 || pos < 0) | if (!*filename || !f || size < 0 || pos < 0) | |||
printf("%s%c MORE?", | gtprintf("%s%c MORE?", | |||
filename, | filename, | |||
*filename ? ':' : '-'); | *filename ? ':' : '-'); | |||
else { | else { | |||
percent = (float)pos; | percent = (float)pos; | |||
percent /= (float)size; | percent /= (float)size; | |||
percent *= 100.0; | percent *= 100.0; | |||
printf("%s%c %.1f %% MORE?", | gtprintf("%s%c %.1f %% MORE?", | |||
filename, | filename, | |||
*filename ? ':' : '-', | *filename ? ':' : '-', | |||
percent); | percent); | |||
} | } | |||
end_standout(); | end_standout(); | |||
fflush(stdout); | fflush(stdout); | |||
} | } | |||
LOCAL BOOL | LOCAL BOOL | |||
more() | more() | |||
skipping to change at line 821 | skipping to change at line 842 | |||
clearline(); | clearline(); | |||
return (-1); | return (-1); | |||
} | } | |||
return (0); | return (0); | |||
} | } | |||
LOCAL void | LOCAL void | |||
onlinehelp() | onlinehelp() | |||
{ | { | |||
/* BEGIN CSTYLED */ | /* BEGIN CSTYLED */ | |||
printf("\n--------------------------------------------------------------- | gtprintf("\n------------------------------------------------------------- | |||
\n"); | --\n"); | |||
printf("N, n Next File\n"); | gtprintf("N, n Next File\n"); | |||
printf("P, p Previous File\n"); | gtprintf("P, p Previous File\n"); | |||
printf("S, s, ^C, ^D, ^\\, DEL Exit (stop)\n"); | gtprintf("S, s, ^C, ^D, ^\\, DEL Exit (stop)\n"); | |||
printf("Y, y, <return>, <space> Display next screenfull of text\n"); | gtprintf("Y, y, <return>, <space> Display next screenfull of text\n | |||
printf("H, h Display next half screenfull of text\n"); | "); | |||
printf("Q, q Display next quarter screenfull of text\n | gtprintf("H, h Display next half screenfull of text\n"); | |||
"); | gtprintf("Q, q Display next quarter screenfull of text\n | |||
printf("L, l Display next line of text\n"); | "); | |||
printf("1-9 Display next <n> lines of text\n"); | gtprintf("L, l Display next line of text\n"); | |||
printf("/pattern Search for <pattern>\n"); | gtprintf("1-9 Display next <n> lines of text\n"); | |||
printf("R, r Re-search for <pattern>\n"); | gtprintf("/pattern Search for <pattern>\n"); | |||
printf("^L Redraw screen\n"); | gtprintf("R, r Re-search for <pattern>\n"); | |||
printf("? Display this message\n"); | gtprintf("^L Redraw screen\n"); | |||
printf("! Execute command\n"); | gtprintf("? Display this message\n"); | |||
printf("V, v Edit file\n"); | gtprintf("! Execute command\n"); | |||
printf("---------------------------------------------------------------\n | gtprintf("V, v Edit file\n"); | |||
"); | gtprintf("--------------------------------------------------------------- | |||
\n"); | ||||
/* END CSTYLED */ | /* END CSTYLED */ | |||
} | } | |||
LOCAL void | LOCAL void | |||
redraw() | redraw() | |||
{ | { | |||
if (f && fileseek(f, ofpos) < 0) { | if (f && fileseek(f, ofpos) < 0) { | |||
if (!nobeep) | if (!nobeep) | |||
putchar('\007'); | putchar('\007'); | |||
clearline(); | clearline(); | |||
skipping to change at line 1187 | skipping to change at line 1208 | |||
patlen = strlen(searchbuf); | patlen = strlen(searchbuf); | |||
#endif | #endif | |||
aux = (int *) malloc(patlen * sizeof (int)); | aux = (int *) malloc(patlen * sizeof (int)); | |||
state = (int *) malloc((patlen+1) * sizeof (int)); | state = (int *) malloc((patlen+1) * sizeof (int)); | |||
#if MB_LEN_MAX > 1 | #if MB_LEN_MAX > 1 | |||
alt = patwcompile(searchbuf, patlen, aux); | alt = patwcompile(searchbuf, patlen, aux); | |||
#else | #else | |||
alt = patcompile((unsigned char *)searchbuf, patlen, aux); | alt = patcompile((unsigned char *)searchbuf, patlen, aux); | |||
#endif | #endif | |||
if (!alt) { | if (!alt) { | |||
printf("Bad Pattern.\r"); | gtprintf("Bad Pattern.\r"); | |||
fflush(stdout); | fflush(stdout); | |||
sleep(1); | sleep(1); | |||
return (FALSE); | return (FALSE); | |||
} | } | |||
return (TRUE); | return (TRUE); | |||
} | } | |||
LOCAL int | LOCAL int | |||
do_search() | do_search() | |||
{ | { | |||
skipping to change at line 1210 | skipping to change at line 1231 | |||
unsigned char *sp; | unsigned char *sp; | |||
register int rest = len; | register int rest = len; | |||
off_t curpos; | off_t curpos; | |||
BOOL skipping = FALSE; | BOOL skipping = FALSE; | |||
int newlines = 0; | int newlines = 0; | |||
unsigned char sbuf[P_BUFSIZE]; | unsigned char sbuf[P_BUFSIZE]; | |||
if (!alt) { | if (!alt) { | |||
if (!nobeep) | if (!nobeep) | |||
putchar('\007'); | putchar('\007'); | |||
printf("No previous search.\r"); | gtprintf("No previous search.\r"); | |||
fflush(stdout); | fflush(stdout); | |||
#ifdef DEBUG | #ifdef DEBUG | |||
sleep(1); | sleep(1); | |||
#endif | #endif | |||
return (-1); | return (-1); | |||
} | } | |||
curpos = filepos(f)-len; | curpos = filepos(f)-len; | |||
#ifdef DEBUG | #ifdef DEBUG | |||
fprintf(stderr, | fprintf(stderr, | |||
skipping to change at line 1236 | skipping to change at line 1257 | |||
int olen; | int olen; | |||
/* | /* | |||
* We may be operating on a copy and thus | * We may be operating on a copy and thus | |||
* need to set "len" to the remaining characters to | * need to set "len" to the remaining characters to | |||
* tell fill_buf() that it needs to do a refill. | * tell fill_buf() that it needs to do a refill. | |||
*/ | */ | |||
olen = len = rest; | olen = len = rest; | |||
if (fill_buf() <= 0 || olen == len) { | if (fill_buf() <= 0 || olen == len) { | |||
if (!nobeep) | if (!nobeep) | |||
putchar('\007'); | putchar('\007'); | |||
printf("Pattern not found.\r"); | gtprintf("Pattern not found.\r"); | |||
fflush(stdout); | fflush(stdout); | |||
if (f && fileseek(f, curpos) >= 0) | if (f && fileseek(f, curpos) >= 0) | |||
len = 0; | len = 0; | |||
return (-1); | return (-1); | |||
} | } | |||
newlines = 0; | newlines = 0; | |||
} | } | |||
rbp = lp = sp = bp; | rbp = lp = sp = bp; | |||
rest = len; | rest = len; | |||
if (underline && | if (underline && | |||
skipping to change at line 1302 | skipping to change at line 1323 | |||
return (0); | return (0); | |||
} | } | |||
if (*rbp++ == '\n') { | if (*rbp++ == '\n') { | |||
/* | /* | |||
* Remember last line start pointer. | * Remember last line start pointer. | |||
*/ | */ | |||
lp = rbp; | lp = rbp; | |||
newlines++; | newlines++; | |||
if (!skipping) { | if (!skipping) { | |||
skipping = TRUE; | skipping = TRUE; | |||
printf("skipping...\r"); | gtprintf("skipping...\r"); | |||
fflush(stdout); | fflush(stdout); | |||
} | } | |||
#ifdef DEBUG | #ifdef DEBUG | |||
fprintf(stderr, "."); | fprintf(stderr, "."); | |||
#endif | #endif | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
End of changes. 13 change blocks. | ||||
36 lines changed or deleted | 58 lines changed or added |