diff --git a/inc/proto.h b/inc/proto.h index 934b03e..75368fa 100755 --- a/inc/proto.h +++ b/inc/proto.h @@ -420,6 +420,7 @@ long existsvlist(char *vars, long int *node); void expandwfdiscs(); +void external_pager(char *filename); void extrma(); void eyeomg(); void fastcontdata(); @@ -789,6 +790,7 @@ long inquirev(); void inqvsp(); void inspect(); void inter(); +int internal_pager(FILE *nun); long ipow(long b, long x); @@ -1322,6 +1324,7 @@ void settextsize1(); void settextsize2(); void settexttype(); void settextwait(); +void setup_pager(); void setvmodified(); void setvport(); void setvportborder(); @@ -1807,6 +1810,7 @@ void zgetc(long array[], long pnumc); void zgimsg(); +void zgpmsg(char *prmt, long prmtlen, char *msg, long msglen); void zgtfun(); void zinquire(char *kname, diff --git a/src/top/initsac.c b/src/top/initsac.c index ec7e0c0..78344b3 100755 --- a/src/top/initsac.c +++ b/src/top/initsac.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "../../inc/complex.h" #include "../../inc/proto.h" @@ -52,6 +53,8 @@ #include "../../inc/wild.h" #undef DOINITS +/* external pager program we use to view help fils */ +char *pager; void /*FUNCTION*/ initsac() { @@ -136,14 +139,13 @@ void /*FUNCTION*/ initsac() xabout () ; } + setup_pager(); + L_8888: return; } /* end of function */ - - - void /*FUNCTION*/ initblkdata() { long int _i, _r; @@ -172,3 +174,31 @@ void /*FUNCTION*/ initblkdata() return ; } /* end of function */ +void setup_pager() +{ + char *pager_search_list[] = { "less", "more", NULL }; + char *pager_dir_list[] = { "/usr/bin", "/bin", NULL }; + char *buf = NULL; + + pager = getenv("PAGER"); + if (pager && pager[0] == '\0') + pager = NULL; + + if (pager == NULL) { + const char **i, **j; + + pager = NULL; + for (i = pager_search_list; *i; i++) { + for (j = pager_dir_list; *j; j++) { + if (buf) + free(buf); + buf = (char *)malloc(strlen(*j) + strlen(*i) + 2); + sprintf(buf, "%s/%s", *j, *i); + if (access(buf, X_OK) == 0) { + pager = buf; + return; + } + } + } + } +} diff --git a/src/ucf/wrhelp.c b/src/ucf/wrhelp.c index a40a9fe..0d43218 100755 --- a/src/ucf/wrhelp.c +++ b/src/ucf/wrhelp.c @@ -2,21 +2,23 @@ #include #include #include +#include + +#include "complex.h" +#include "proto.h" +#include "mach.h" + +extern char *pager; -#include "../../inc/complex.h" -#include "../../inc/proto.h" -#include "../../inc/mach.h" void /*FUNCTION*/ wrhelp(ktoken, ktoken_s, imode, lprint, nerr) char *ktoken; int ktoken_s; long lprint ; long int imode, *nerr; { - char kmsg[MCMSG+1], kerase[41]; - char kresp[9], kfilename[ MCPFN + 1 ] ; - long int ncerr, nlw, numsave, nlscrn; + char kfilename[ MCPFN + 1 ] ; + long int ncerr; FILE *nun; - void zgpmsg(); - + int i; /*===================================================================== * PURPOSE: To write (copy) the contents of a help package to the @@ -59,7 +61,6 @@ long int imode, *nerr; *===================================================================== */ /* PROCEDURE: */ *nerr = 0; - nlw = 0; /* - Activate automatic output message mode. */ @@ -67,12 +68,19 @@ long int imode, *nerr; /* - Open requested help package. */ - ophelp( ktoken,ktoken_s, &nun, kfilename , nerr ); + ophelp(ktoken, ktoken_s, &nun, kfilename, nerr); if( *nerr != 0 ) goto L_8888; if( nun == NULL ) goto L_5000; + /* Get rid of the trailing white-space characters in kfilename */ + for (i = 0; i < MCPFN + 1; i++) + if (isspace(kfilename[i]) || kfilename[i] == '\0') + break; + if (i < MCPFN + 1) + kfilename[i] = '\0'; + /* If this is the PRINTHELP command, print the file and return, else go on and send it to the monitor one line at a time. */ if ( lprint ) { @@ -85,81 +93,107 @@ long int imode, *nerr; goto L_6000 ; } - /* - Set the message type */ - - typmsg( "OUTPUT" ); - - /* - Get screen attributes (number of lines per screen and - * text to send to erase screen, if any.) */ - - getalphainfo( &nlscrn, kerase,41 ); - if( nlscrn <= 0 ) - nlscrn = 23; - - /* - For each line of text in help package. */ - -L_3000: - if(fgets(kmsg,MCMSG+1,nun)==NULL){ - if(feof(nun)) goto L_6000; - goto L_5000; - } - if(kmsg[(numsave=strlen(kmsg)-1)] == '\n') kmsg[numsave]=' '; - - aplmsg( kmsg,MCMSG+1 ); - nlw = nlw + 1; - - - /* -- After a screen full of info, see if user wants to see more. */ - if( nlw > (nlscrn - 2) ){ - outmsg(); - clrmsg(); - setmsg("OUTPUT",99); - zgpmsg( "More? $",8, kresp, 9 ); - - upcase( kresp, 1, kresp, 9 ); - - if( kresp[0] == 'N' ){ - goto L_6000; - } - else if( kresp[0] == 'Q' ){ - /* *nerr = -1; */ - goto L_6000; - } - else{ - nlw = 0; - } + if (pager) { + external_pager(kfilename); + goto L_6000; + } else { + if (internal_pager(nun) == 0) + goto L_6000; } - /* -- Loop back until done. */ - goto L_3000; - - L_5000: /* - Process error during read. */ - setmsg( "OUTPUT", 1104 ); apcmsg( ktoken,ktoken_s ); outmsg(); clrmsg(); - if(nun == NULL) { + if(nun == NULL) return; - } L_6000: /* - Close help package and return when: * (1) end-of-file encountered. * (2) user requests that remainder of file not be printed. */ - zcloses( &nun, &ncerr ); /* - Deactivate automatic output message mode. */ - autooutmsg( FALSE ); L_8888: return; +} + +/** + * Using internal pager to view a file + * + * @param nun + * the input file pointer + * + * @return + * 0 upon successful completion, -1 otherwise + */ +int internal_pager(FILE *nun) +{ + char kmsg[MCMSG+1], kerase[41]; + long nlw = 0, numsave, nlscrn; + char kresp[9]; + + /* - Set the message type */ + typmsg( "OUTPUT" ); + + /* - Get screen attributes (number of lines per screen and + * text to send to erase screen, if any.) */ + getalphainfo(&nlscrn, kerase, 41); + if(nlscrn <= 0) + nlscrn = 23; + + for (;;) { + if(fgets(kmsg, MCMSG + 1, nun)==NULL){ + if(feof(nun)) + return 0; + return -1; + } + numsave = strlen(kmsg) - 1; + if(kmsg[numsave] == '\n') + kmsg[numsave] = ' '; + + aplmsg(kmsg,MCMSG + 1); + nlw = nlw + 1; + + /* -- After a screen full of info, see if user wants to see more. */ + if( nlw > (nlscrn - 2) ){ + outmsg(); + clrmsg(); + setmsg("OUTPUT", 99); + zgpmsg("More? $", 8, kresp, 9); -} /* end of function */ + upcase(kresp, 1, kresp, 9); + if (kresp[0] == 'N' || kresp[0] == 'Q') + return 0; + else + nlw = 0; + } + } +} + +/** + * Using external pager to view a file + * + * @param filename + * the input file + * + * @return Nothing + */ +void external_pager(char *filename) +{ + char *syscom; + + syscom = (char *)malloc(strlen(pager) + 1 + strlen(filename) + 1); + sprintf(syscom, "%s %s", pager, filename); + setenv("LESS", "isRXM+%", 0); + if (system(syscom) != 0) + fprintf(stderr, "Error loading pager %s!\n", pager); +}