diff --git a/src/ucf/wrhelp.c b/src/ucf/wrhelp.c index a40a9fe..cc0b837 100755 --- a/src/ucf/wrhelp.c +++ b/src/ucf/wrhelp.c @@ -2,10 +2,12 @@ #include #include #include +#include + +#include "complex.h" +#include "proto.h" +#include "mach.h" -#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 ; @@ -16,7 +18,7 @@ long int imode, *nerr; long int ncerr, nlw, numsave, nlscrn; FILE *nun; void zgpmsg(); - + int i; /*===================================================================== * PURPOSE: To write (copy) the contents of a help package to the @@ -67,12 +69,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 ) { @@ -96,43 +105,19 @@ long int imode, *nerr; 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; - } + /* Show the help file using a PAGER if possible. */ + if (kfilename) { + char *syscom; + char *pager = getenv("PAGER"); + + if (!pager || pager[0] == '\0') + pager = "less"; + syscom = malloc(strlen(pager) + 1 + strlen(kfilename) + 1); + sprintf(syscom, "%s %s", pager, kfilename); + setenv("LESS", "isRXM+%", 0); + system(syscom); } - - /* -- Loop back until done. */ - goto L_3000; - + goto L_6000; L_5000: /* - Process error during read. */