1995-02-15 19:44:08 +00:00
|
|
|
/***************************************************************
|
|
|
|
*
|
|
|
|
* Program: help.c
|
|
|
|
* Author: Marc van Kempen
|
|
|
|
* Desc: get help
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995, Marc van Kempen
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software may be used, modified, copied, distributed, and
|
|
|
|
* sold, in both source and binary form provided that the above
|
|
|
|
* copyright and these terms are retained, verbatim, as the first
|
|
|
|
* lines of this file. Under no circumstances is the author
|
|
|
|
* responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with
|
|
|
|
* its use.
|
|
|
|
*
|
|
|
|
***************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dialog.h>
|
|
|
|
|
|
|
|
static char _helpfilebuf[MAXPATHLEN];
|
|
|
|
static char _helplinebuf[77]; /* limit the helpline to 76 characters */
|
|
|
|
static char *_helpfile = NULL;
|
|
|
|
static char *_helpline = NULL;
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
*
|
|
|
|
* helpfile routines
|
|
|
|
*
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
use_helpfile(char *hfile)
|
|
|
|
/*
|
|
|
|
* desc: set the helpfile to be opened on pressing F1 to <helpfile>
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if (hfile != NULL) {
|
|
|
|
_helpfile = _helpfilebuf;
|
|
|
|
strcpy(_helpfile, hfile);
|
|
|
|
} else {
|
|
|
|
_helpfile = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} /* use_helpfile() */
|
|
|
|
|
|
|
|
void
|
|
|
|
display_helpfile(void)
|
|
|
|
/*
|
|
|
|
* desc: display the current helpfile in a window
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
WINDOW *w;
|
|
|
|
FILE *f;
|
|
|
|
struct stat sb;
|
|
|
|
char msg[80], *buf;
|
|
|
|
static int in_help = FALSE;
|
1995-02-23 22:36:56 +00:00
|
|
|
char *savehline = NULL;
|
1995-02-15 19:44:08 +00:00
|
|
|
|
|
|
|
if (in_help) return; /* dont call help when you're in help */
|
|
|
|
|
|
|
|
if (_helpfile != NULL) {
|
1995-02-23 22:36:56 +00:00
|
|
|
if (_helpline != NULL) {
|
|
|
|
savehline = _helpline;
|
|
|
|
_helpline = NULL;
|
|
|
|
}
|
|
|
|
if ((w = dupwin(newscr)) == NULL) {
|
|
|
|
dialog_notify("No memory to dup previous screen\n");
|
|
|
|
goto ret;
|
|
|
|
}
|
1995-02-15 19:44:08 +00:00
|
|
|
if ((f = fopen(_helpfile, "r")) == NULL) {
|
|
|
|
sprintf(msg, "Can't open helpfile : %s\n", _helpfile);
|
|
|
|
dialog_notify(msg);
|
1995-02-23 22:36:56 +00:00
|
|
|
goto ret;
|
1995-02-15 19:44:08 +00:00
|
|
|
}
|
|
|
|
if (fstat(fileno(f), &sb)) {
|
|
|
|
sprintf(msg, "Can't stat helpfile : %s\n", _helpfile);
|
|
|
|
dialog_notify(msg);
|
1995-02-23 22:36:56 +00:00
|
|
|
goto ret;
|
1995-02-15 19:44:08 +00:00
|
|
|
}
|
|
|
|
if ((buf = (char *) malloc( sb.st_size )) == NULL) {
|
|
|
|
sprintf(msg, "Could not malloc space for helpfile : %s\n", _helpfile);
|
|
|
|
dialog_notify(msg);
|
1995-02-23 22:36:56 +00:00
|
|
|
goto ret;
|
1995-02-15 19:44:08 +00:00
|
|
|
}
|
|
|
|
if (fread(buf, 1, sb.st_size, f) != sb.st_size) {
|
|
|
|
sprintf(msg, "Could not read entire help file : %s", _helpfile);
|
|
|
|
dialog_notify(msg);
|
1995-02-23 22:36:56 +00:00
|
|
|
free(buf);
|
|
|
|
goto ret;
|
1995-02-15 19:44:08 +00:00
|
|
|
}
|
|
|
|
buf[sb.st_size] = 0;
|
|
|
|
in_help = TRUE;
|
|
|
|
dialog_mesgbox("Online help", buf, LINES-4, COLS-4);
|
|
|
|
in_help = FALSE;
|
1995-02-23 22:36:56 +00:00
|
|
|
touchwin(w);
|
1995-02-15 19:44:08 +00:00
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
|
|
|
free(buf);
|
|
|
|
} else {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
1995-02-23 22:36:56 +00:00
|
|
|
ret:
|
|
|
|
if (savehline != NULL)
|
|
|
|
_helpline = savehline;
|
|
|
|
|
1995-02-15 19:44:08 +00:00
|
|
|
return;
|
|
|
|
} /* display_helpfile() */
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
*
|
|
|
|
* helpline routines
|
|
|
|
*
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
use_helpline(char *hline)
|
|
|
|
/*
|
|
|
|
* desc: set the helpline to printed in dialogs
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if (hline) {
|
|
|
|
_helpline = _helplinebuf;
|
|
|
|
if (strlen(hline) > 76) {
|
|
|
|
/* only display the first 76 characters in the helpline */
|
|
|
|
strncpy(_helpline, hline, 76);
|
|
|
|
_helpline[76] = 0;
|
|
|
|
} else {
|
|
|
|
strcpy(_helpline, hline);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_helpline = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} /* use_helpline() */
|
|
|
|
|
|
|
|
void
|
|
|
|
display_helpline(WINDOW *w, int y, int width)
|
|
|
|
/*
|
|
|
|
* desc: display the helpline at the given coordinates <y, x> in the window <w>
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
if (_helpline != NULL) {
|
|
|
|
if (strlen(_helpline) > width - 6) {
|
|
|
|
_helpline[width - 6] = 0;
|
|
|
|
}
|
|
|
|
wmove(w, y, (int) (width - strlen(_helpline)- 4) / 2);
|
|
|
|
wattrset(w, title_attr);
|
|
|
|
waddstr(w, "[ ");
|
|
|
|
waddstr(w, _helpline);
|
|
|
|
waddstr(w, " ]");
|
|
|
|
} else {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|