--- pgp/src/more.c 2018/04/24 16:38:22 1.1.1.2 +++ pgp/src/more.c 2018/04/24 16:42:02 1.1.1.6 @@ -1,21 +1,22 @@ /* more.c - Unix-style "more" paging output for PGP. PGP: Pretty Good(tm) Privacy - public key cryptography for the masses. - (c) Copyright 1990-1992 by Philip Zimmermann. All rights reserved. + (c) Copyright 1990-1994 by Philip Zimmermann. All rights reserved. The author assumes no liability for damages resulting from the use of this software, even if the damage results from defects in this software. No warranty is expressed or implied. - All the source code Philip Zimmermann wrote for PGP is available for - free under the "Copyleft" General Public License from the Free - Software Foundation. A copy of that license agreement is included in - the source release package of PGP. Code developed by others for PGP - is also freely available. Other code that has been incorporated into - PGP from other sources was either originally published in the public - domain or was used with permission from the various authors. See the - PGP User's Guide for more complete information about licensing, - patent restrictions on certain algorithms, trademarks, copyrights, - and export controls. + Note that while most PGP source modules bear Philip Zimmermann's + copyright notice, many of them have been revised or entirely written + by contributors who frequently failed to put their names in their + code. Code that has been incorporated into PGP from other authors + was either originally published in the public domain or is used with + permission from the various authors. + + PGP is available for free to the public under certain restrictions. + See the PGP User's Guide (included in the release package) for + important information about licensing, patent restrictions on + certain algorithms, trademarks, copyrights, and export controls. */ #include @@ -28,24 +29,27 @@ #ifdef sco #include #include +FILE *popen(); #endif +#include "system.h" #include "mpilib.h" #include "language.h" #include "fileio.h" #include "pgp.h" - -/* Prototype for getch() */ - -int getch( void ); +#include "more.h" +#include "charset.h" #ifdef MSDOS +#ifndef __GO32__ +#include +#endif #define DEFAULT_LINES 25 /* MSDOS actually has a 25-line screen */ #else #define DEFAULT_LINES 24 #endif /* MSDOS */ #define DEFAULT_COLUMNS 80 -int screen_lines = DEFAULT_LINES, screen_columns = DEFAULT_COLUMNS; +static int screen_lines = DEFAULT_LINES, screen_columns = DEFAULT_COLUMNS; #define TAB 0x09 /* ASCII tab char */ #define CR '\r' /* Carriage return char */ @@ -136,8 +140,7 @@ static void getScreenSize(void) /* Rot b #endif /* TIOCGWINSZ */ /* Make sure that we're outputting to a terminal */ - if (!isatty(fileno(stderr))) - { + if (!isatty(fileno(stderr))) { screen_lines = DEFAULT_LINES; screen_columns = DEFAULT_COLUMNS; return; @@ -158,7 +161,8 @@ static void getScreenSize(void) /* Rot b #ifdef TIOCGWINSZ /* See what ioctl() has to say (overrides terminfo & termcap) */ if ((!screen_lines || !screen_columns) && ioctl(fileno(stderr),TIOCGWINSZ,&windowInfo) != -1) - { if (!screen_lines && windowInfo.ws_row > 0) + { + if (!screen_lines && windowInfo.ws_row > 0) screen_lines = (int)windowInfo.ws_row; if (!screen_columns && windowInfo.ws_col > 0 ) @@ -168,7 +172,8 @@ static void getScreenSize(void) /* Rot b #ifdef TIOCGSIZE /* See what ioctl() has to say (overrides terminfo & termcap) */ if ((!screen_lines || !screen_columns) && ioctl(fileno(stderr),TIOCGSIZE,&windowInfo) != -1) - { if (!screen_lines && windowInfo.ts_lines > 0) + { + if (!screen_lines && windowInfo.ts_lines > 0) screen_lines = (int)windowInfo.ts_lines; if (!screen_columns && windowInfo.ts_cols > 0) @@ -178,7 +183,8 @@ static void getScreenSize(void) /* Rot b #ifdef WIOCGETD /* See what ioctl() has to say (overrides terminfo & termcap) */ if ((!screen_lines || !screen_columns) && ioctl(fileno(stderr),WIOCGETD,&windowInfo) != -1) - { if (!screen_lines && windowInfo.uw_height > 0) + { + if (!screen_lines && windowInfo.uw_height > 0) screen_lines = (int)(windowInfo.uw_height / windowInfo.uw_vs); if (!screen_columns && windowInfo.uw_width > 0) @@ -191,7 +197,8 @@ static void getScreenSize(void) /* Rot b #ifdef USE_TERMCAP /* See what terminfo/termcap has to say */ if (!screen_lines || !screen_columns) - { if ((termInfo = getenv("TERM")) == (char *)NULL) + { + if ((termInfo = getenv("TERM")) == (char *)NULL) termInfo = UNKNOWN_TERM; if ((tgetent(termBuffer, termInfo) <= 0)) @@ -211,16 +218,9 @@ static void getScreenSize(void) /* Rot b #endif /* UNIX */ } -/* Certain systems need to go into a "break" mode */ -#ifdef UNIX -#define NEEDBREAK -#endif -#ifdef AMIGA -#define NEEDBREAK -#endif #ifdef ATARI -#define reverse_attr() printf("\033p") -#define norm_attr() printf("\033q") +#define reverse_attr() printf("\033p") +#define norm_attr() printf("\033q") #else #define reverse_attr() #define norm_attr() @@ -249,30 +249,38 @@ int more_file(char *fileName) if ((inFile = fopen(fileName,FOPRBIN)) == NULL) /* Can't see how this could fail since we just created the file */ - return(-1); + return -1; fread(buf, 1, 16, inFile); - if (compressSignature(buf) >= 0) - { fprintf(pgpout, PSTR("\n\007File '%s' is not a text file; cannot display.\n"), + if (compressSignature( (byte *) buf) >= 0) + { + fprintf(pgpout, LANG("\n\007File '%s' is not a text file; cannot display.\n"), fileName); - return(-1); + return -1; } /* PAGER set in config.txt overrides environment variable, set PAGER in config.txt to 'pgp' to use builtin pager */ - if (pager[0] == '\0') - { + if (pager[0] == '\0') { if ((p = getenv("PAGER")) != NULL) strncpy(pager, p, sizeof(pager) - 1); } - /* Use built-in pager if PAGER is not set or if this is for your eyes only */ + if (strcmp(pager, "cat") == 0) { + fclose(inFile); + writePhantomOutput(fileName); + return 0; + } + + /* Use built-in pager if PAGER is not set or if this is for your eyes only, + this currently doesn't work, the _CONSOLE filename isn't used as the real + filename anymore */ if ((strcmp(fileName,CONSOLE_FILENAME) != 0) && (strlen(pager) != 0) && strcmp("pgp", pager)) { fclose(inFile); #ifdef UNIX if (strchr(fileName, '\'') != NULL) - return(-1); + return -1; sprintf(cmd, "%s '%s'", pager, fileName); #else sprintf(cmd, "%s %s", pager, fileName); @@ -282,12 +290,13 @@ int more_file(char *fileName) *p = '\\'; #endif #endif - return(system(cmd)); + fflush(pgpout); + return system(cmd); } #ifdef UNIX - if (!isatty(fileno(stdout))) - { fclose(inFile); + if (!isatty(fileno(stdout))) { + fclose(inFile); writePhantomOutput(fileName); return 0; } @@ -301,54 +310,51 @@ int more_file(char *fileName) rewind(inFile); lineno = 1; -#ifdef NEEDBREAK ttycbreak(); -#endif + putchar('\n'); - while (TRUE) - { ch = getc(inFile); - if (ch == LF) - { lines++; + for (;;) { + ch = getc(inFile); + if (ch == LF) { + lines++; + putchar('\n'); + chars = 0; + ++lineno; + } else if (ch == CR) { + lines++; putchar('\n'); chars = 0; ++lineno; + + /* Skip following LF if there is one */ + if ((ch = getc(inFile)) != LF && ch != EOF) + ungetc(ch,inFile); + } else if (((unsigned char) ch >= ' ' && ch != EOF) || ch == TAB) + { + /* Legal char or tab, print it */ + putchar(ch); + chars += (ch == TAB) ? 8 : 1; } - else - if (ch == CR) - { lines++; - putchar('\n'); - chars = 0; - ++lineno; - - /* Skip following LF if there is one */ - if ((ch = getc(inFile)) != LF && ch != EOF) - ungetc(ch,inFile); - } - else - if (((unsigned char) ch >= ' ' && ch != EOF) || ch == TAB) - { /* Legal char or tab, print it */ - putchar(ch); - chars += (ch == TAB) ? 8 : 1; - } /* If we've reach the max.no of columns we can handle, skip the rest of the line */ - if (chars == screen_columns - 1) - { chars = 0; - while ((ch = getc(inFile)) != CR && ch != LF && ch != EOF ); + if (chars == screen_columns - 1) { + chars = 0; + while ((ch = getc(inFile)) != CR && ch != LF && ch != EOF ) + ; if (ch != EOF) ungetc(ch,inFile); } /* If we've reached the max.no of rows we can handle, wait for the user to hit a key */ - while (ch == EOF || lines == screen_lines - 1) - { /* Print prompt at end of screen */ + while (ch == EOF || lines == screen_lines - 1) { + /* Print prompt at end of screen */ reverse_attr(); if (ch == EOF) - printf(PSTR("\nDone...hit any key\r")); + printf(LANG("\nDone...hit any key\r")); else - printf(PSTR("More -- %d%% -- Hit space for next screen, Enter for new line, 'Q' to quit --\r"), + printf(LANG("More -- %d%% -- Hit space for next screen, Enter for new line, 'Q' to quit --\r"), ( 100 * ftell( inFile ) ) / fileLen ); norm_attr(); fflush(stdout); @@ -360,12 +366,13 @@ int more_file(char *fileName) putchar(' '); putchar('\r'); fflush(stdout); - if (c == 'B' && lineno > screen_lines) /* go Back a page */ - { int seek_line = lineno - 2*screen_lines + 3; + if (c == 'B' && lineno > screen_lines) { + /* go Back a page */ + int seek_line = lineno - 2*screen_lines + 3; lineno = 1; rewind(inFile); - if (seek_line > 1) - { printf("...skipping\n"); + if (seek_line > 1) { + printf("...skipping\n"); while ((ch = getc(inFile)) != EOF) if (ch == '\n') if (++lineno == seek_line) @@ -373,9 +380,8 @@ int more_file(char *fileName) } ch = '\0'; lines = 0; - } - else - { if (c == 'Q' || ch == EOF) + } else { + if (c == 'Q' || ch == EOF) goto done; if (c == ' ' || c == '\n' || c == '\r' || c == 'J') lines -= (c == ' ') ? screen_lines - 2 : 1; /* Do n more lines */ @@ -383,11 +389,10 @@ int more_file(char *fileName) } } done: -#ifdef NEEDBREAK ttynorm(); -#endif + fclose(inFile); - return(0); + return 0; } /* more_file */ @@ -402,25 +407,26 @@ static FILE *savepgpout; int -open_more() +open_more(void) { +#ifdef UNIX char *p; +#endif if (mfile || piping) close_more(); savepgpout = pgpout; #ifdef UNIX - if (pager[0] == '\0') - { + fflush(pgpout); + if (pager[0] == '\0') { if ((p = getenv("PAGER")) != NULL) strncpy(pager, p, sizeof(pager) - 1); } /* Use built-in pager if PAGER is not set or set to "pgp" */ - if ((strlen(pager) != 0) && strcmp("pgp", pager)) - { - if ((pgpout = popen(pager, "w")) != NULL) - { piping = TRUE; + if ((strlen(pager) != 0) && strcmp("pgp", pager)) { + if ((pgpout = popen(pager, "w")) != NULL) { + piping = TRUE; return 0; } perror("popen"); @@ -429,20 +435,19 @@ open_more() #endif if ((mfile = tempfile(TMP_TMPDIR|TMP_WIPE)) == NULL) return -1; - if ((pgpout = fopen(mfile, FOPWTXT)) == NULL) - { + if ((pgpout = fopen(mfile, FOPWTXT)) == NULL) { pgpout = savepgpout; rmtemp(mfile); return -1; } /* user will not see anything until close_more() is called */ - fprintf(savepgpout,PSTR("Just a moment...")); + fprintf(savepgpout,LANG("Just a moment...")); fflush(savepgpout); return 0; } int -close_more() +close_more(void) { if (!mfile && !piping) return 0;