1 /***************************************************************
4 * Author: Marc van Kempen
8 * Copyright (c) 1995, Marc van Kempen
10 * All rights reserved.
12 * This software may be used, modified, copied, distributed, and
13 * sold, in both source and binary form provided that the above
14 * copyright and these terms are retained, verbatim, as the first
15 * lines of this file. Under no circumstances is the author
16 * responsible for the proper functioning of this software, nor does
17 * the author assume any responsibility for damages incurred with
20 ***************************************************************/
23 #include <sys/param.h>
24 #include <sys/types.h>
29 static char _helpfilebuf[MAXPATHLEN];
30 static char _helplinebuf[77]; /* limit the helpline to 76 characters */
31 static char *_helpfile = NULL;
32 static char *_helpline = NULL;
34 /******************************************************************
38 ******************************************************************/
41 use_helpfile(char *hfile)
43 * desc: set the helpfile to be opened on pressing F1 to <helpfile>
47 _helpfile = _helpfilebuf;
48 strcpy(_helpfile, hfile);
54 } /* use_helpfile() */
57 display_helpfile(void)
59 * desc: display the current helpfile in a window
66 static int in_help = FALSE;
67 char *savehline = NULL;
69 if (in_help) return; /* dont call help when you're in help */
71 if (_helpfile != NULL) {
72 if ((w = dupwin(newscr)) == NULL) {
73 dialog_notify("No memory to dup previous screen\n");
76 if ((f = fopen(_helpfile, "r")) == NULL) {
77 sprintf(msg, "Can't open helpfile : %s\n", _helpfile);
81 if (fstat(fileno(f), &sb)) {
82 sprintf(msg, "Can't stat helpfile : %s\n", _helpfile);
86 if ((buf = (char *) malloc( sb.st_size )) == NULL) {
87 sprintf(msg, "Could not malloc space for helpfile : %s\n", _helpfile);
91 if (fread(buf, 1, sb.st_size, f) != sb.st_size) {
92 sprintf(msg, "Could not read entire help file : %s", _helpfile);
99 savehline = get_helpline();
100 use_helpline("Use arrowkeys, PgUp, PgDn, Home and End to move through text");
101 dialog_mesgbox("Online help", buf, LINES-4, COLS-4);
102 restore_helpline(savehline);
113 } /* display_helpfile() */
116 /******************************************************************
120 ******************************************************************/
123 use_helpline(char *hline)
125 * desc: set the helpline to printed in dialogs
129 _helpline = _helplinebuf;
130 if (strlen(hline) > 76) {
131 /* only display the first 76 characters in the helpline */
132 strncpy(_helpline, hline, 76);
135 strcpy(_helpline, hline);
142 } /* use_helpline() */
145 display_helpline(WINDOW *w, int y, int width)
147 * desc: display the helpline at the given coordinates <y, x> in the window <w>
150 if (_helpline != NULL) {
151 if (strlen(_helpline) > width - 6) {
152 _helpline[width - 6] = 0;
154 wmove(w, y, (int) (width - strlen(_helpline)- 4) / 2);
155 wattrset(w, title_attr);
157 waddstr(w, _helpline);
169 * desc: allocate new space, copy the helpline to it and return a pointer to it
175 hlp = (char *) malloc( strlen(_helpline) + 1 );
176 strcpy(hlp, _helpline);
182 } /* get_helpline() */
185 restore_helpline(char *helpline)
187 * Desc: set the helpline to <helpline> and free the space allocated to it
190 use_helpline(helpline);
194 } /* restore_helpline() */