/********************************************************************
* lindner
* 3.30
* 1995/02/23 21:53:53
* /home/arcwelder/GopherSrc/CVS/gopher+/gopher/pager.c,v
* Exp
*
* Paul Lindner, University of Minnesota CIS.
*
* Copyright 1991, 92, 93, 94 by the Regents of the University of Minnesota
* see the file "Copyright" in the distribution for conditions of use.
*********************************************************************
* MODULE: pager.c
* neato pager..
*********************************************************************
* Revision History:
* pager.c,v
* Revision 3.30 1995/02/23 21:53:53 lindner
* Correct cast..
*
* Revision 3.29 1995/01/03 19:53:25 lindner
* Dynamic screen position code, long title fix from Allan L. Bazinet
*
* Revision 3.28 1994/12/03 01:52:19 lindner
* Don't auto exit paging at the end of the file
*
* Revision 3.27 1994/10/21 04:41:08 lindner
* Add ANSI attached printer code..
*
* Revision 3.26 1994/06/29 07:14:39 lindner
* Check for A_CHARTEXT before trying to use it
*
* Revision 3.25 1994/06/29 05:13:55 lindner
* Change to Stat.h
*
* Revision 3.24 1994/06/09 22:13:40 lindner
* More language conversions
*
* Revision 3.23 1994/06/09 16:35:57 lindner
* Fix typos
*
* Revision 3.22 1994/06/09 04:37:06 lindner
* (F.Macrides) Fixed PagerNextPage() and PagerSearch() to not add extra
* blank lines following lines that are exactly equal to the screen width
* on VMS. Added code to disallow 'm'ail if SecureMode or NoShellMode
* and the NOMAIL symbol was defined on compilation.
*
* Revision 3.21 1994/06/03 06:12:19 lindner
* Fix for redisplay after using help
*
* Revision 3.20 1994/05/19 14:08:05 lindner
* use fast malloc on VMS VAXC
*
* Revision 3.19 1994/05/18 03:59:41 lindner
* Change to FIOsystem() for VMS
*
* Revision 3.18 1994/05/17 05:48:06 lindner
* Massive internationalization change
*
* Revision 3.17 1994/05/14 04:13:47 lindner
* Internationalization...
*
*
*********************************************************************/
/** bytecount positions for each page.. (non-dynamic.. yet...) **/
/* static int positions[4000]; */ /** Bad programmer **/
static int *positions = NULL; /* not-so-bad programmer */
static int currentpage;
static int pos_max;
/*
* This is the beginning of a built in pager..
* it is very pretty..
*
*/
if (helpmenu == NULL) {
helpmenu = (char**) malloc(sizeof(char*) * 9);
helpmenu[0] = Gtxt("u, ^G, left : Return to menu",19);
helpmenu[1] = Gtxt("space, down : Move to the next page",20);
helpmenu[2] = Gtxt("b, up : Move to the previous page",21);
helpmenu[3] = Gtxt("/ : Search for text",22);
helpmenu[4] = Gtxt("m : mail current document",23);
helpmenu[5] = Gtxt("s : save current document",24);
helpmenu[6] = Gtxt("p : print current document",25);
helpmenu[7] = Gtxt("D : download current document",26);
helpmenu[8] = NULL;
}
/* Get a keystroke */
while (done==FALSE) {
PagerPercent(bytecount, totalbytes);
refresh();
ch = CURgetch(cur);
switch (ch) {
#ifdef VMS
case '\032': /* ^Z */
#endif
case KEY_LEFT:
case 'u':
case 'q':
case '\007':
done = TRUE;
break;
case '\006':
case '\n':
case ' ':
case KEY_DOWN:
case KEY_NPAGE:
if (bytecount < totalbytes)
PagerNextPage(cur, thefile, theline, &bytecount,
totalbytes);
break;
case '\002':
case KEY_UP:
case KEY_PPAGE:
case 'b':
if (currentpage > 1) {
PagerSeekPage(thefile, currentpage-2, &bytecount);
PagerNextPage(cur, thefile, theline, &bytecount,
totalbytes);
}
break;
case '^':
if (currentpage > 1) {
PagerSeekPage(thefile, 0, &bytecount);
PagerNextPage(cur, thefile, theline, &bytecount,
totalbytes);
}
break;
case '$':
if (bytecount < totalbytes)
do
PagerNextPage(cur, thefile, theline, &bytecount,
totalbytes);
while (bytecount < totalbytes);
break;
case '\037':
case KEY_HELP:
case 'h':
case '?':
PagerHelp(cur);
touchwin(stdscr);
break;
case 'p':
if (SecureMode || NoShellMode) {
CursesErrorMsg(Gtxt("Sorry, you are not allowed to print files",161));
touchwin(stdscr);
break;
}
printit = fopen(GSgetLocalFile(gs), "r");
if (printit == NULL) {
CursesErrorMsg(Gtxt("Cannot Open requested file..",71));
break;
}
CURexit(CursesScreen);
printf("Now printing on ANSI attached printer\n");
printf("\033[5i");
while (1) {
cp = fgets(printtmpstr, sizeof(printtmpstr), printit);
if (cp == NULL)
break;
fputs(cp, stdout);
}
fclose(printit);
printf("\f\033[4i");
printf(Gtxt("Press <RETURN> to continue",121));
getchar();
CURenter(CursesScreen);
touchwin(stdscr);
clearok(curscr, TRUE);
break;
}
if (!RCprintCommand(GlobalRC, GSgetLocalView(gs),
GSgetLocalFile(gs), command) ||
!strncasecmp(command, "- none -", 8) ||
strlen(command) == 0) {
CursesErrorMsg(Gtxt("Sorry, no method to print this document",156));
touchwin(stdscr);
break;
}
Dialogmess[0] = strdup(Gtxt("The filename is:",174));
Dialogmess[1] = strdup(GSgetLocalFile(gs));
Dialogmess[2] = NULL;
if (CURDialog(cur, Gtxt("Print current document",122), Dialogmess) != -1) {
if (FIOsystem(command))
CursesErrorMsg(Gtxt("Encountered printing problem, sorry...",84));
}
free(Dialogmess[0]);
free(Dialogmess[1]);
touchwin(stdscr);
clearok(curscr, TRUE);
break;
case 's':
if (!(SecureMode || NoShellMode))
Save_file(gs, NULL, GSgetLocalView(gs));
else
CursesErrorMsg(Gtxt("Sorry, you are not allowed to save files",162));
case 'm':
#ifdef NOMAIL
if (SecureMode || NoShellMode) {
CursesErrorMsg(Gtxt("Sorry, you are not allowed to do this", 64));
touchwin(stdscr);
break;
}
#endif
case '/':
/** Search ... ***/
if ((CURGetOneOption(CursesScreen, "",
Gtxt("Search text for:",141),
slashstring) < 0) ||
(slashstring[0] == '\0')) {
touchwin(stdscr);
break;
}
case 'n':
/** Next occurrence, and fall through from above.. **/
if (slashstring[0] == '\0') {
CursesErrorMsg(Gtxt("Use '/' to define search a first...",178));
touchwin(stdscr);
break;
}
savedpagenum = currentpage;
if (ch == '/')
PagerSeekPage(thefile, currentpage-1, &bytecount);