1998-02-27 07:54:42 +03:00
|
|
|
/* Hypertext file browser.
|
|
|
|
Copyright (C) 1994, 1995 Miguel de Icaza.
|
|
|
|
Copyright (C) 1994, 1995 Janne Kukonlehto
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
Implements the hypertext file viewer.
|
|
|
|
The hypertext file is a file that may have one or more nodes. Each
|
|
|
|
node ends with a ^D character and starts with a bracket, then the
|
|
|
|
name of the node and then a closing bracket.
|
|
|
|
|
|
|
|
Links in the hypertext file are specified like this: the text that
|
|
|
|
will be highlighted should have a leading ^A, then it comes the
|
|
|
|
text, then a ^B indicating that highlighting is done, then the name
|
|
|
|
of the node you want to link to and then a ^C.
|
|
|
|
|
|
|
|
The file must contain a ^D at the beginning and at the end of the
|
|
|
|
file or the program will not be able to detect the end of file.
|
|
|
|
|
|
|
|
Lazyness/widgeting attack: This file does use the dialog manager
|
|
|
|
and uses mainly the dialog to achieve the help work. there is only
|
|
|
|
one specialized widget and it's only used to forward the mouse messages
|
|
|
|
to the appropiate routine.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2001-09-03 09:07:40 +04:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "global.h"
|
2001-09-07 21:52:19 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "color.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
#include "win.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "key.h" /* For mi_getch() */
|
|
|
|
#include "help.h"
|
|
|
|
#include "dlg.h" /* For Dlg_head */
|
|
|
|
#include "widget.h" /* For Widget */
|
2002-09-02 11:48:01 +04:00
|
|
|
#include "wtools.h" /* For common_dialog_repaint() */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#define MAXLINKNAME 80
|
|
|
|
#define HISTORY_SIZE 20
|
2002-09-22 21:03:28 +04:00
|
|
|
#define HELP_WINDOW_WIDTH (HELP_TEXT_WIDTH + 4)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-22 21:03:28 +04:00
|
|
|
#define STRING_LINK_START "\01"
|
|
|
|
#define STRING_LINK_POINTER "\02"
|
|
|
|
#define STRING_LINK_END "\03"
|
|
|
|
#define STRING_NODE_END "\04"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
static char *data; /* Pointer to the loaded data file */
|
2002-09-02 06:40:22 +04:00
|
|
|
static int help_lines; /* Lines in help viewer */
|
1998-02-27 07:54:42 +03:00
|
|
|
static int history_ptr; /* For the history queue */
|
1998-09-22 17:06:59 +04:00
|
|
|
static char *main_node; /* The main node */
|
1998-02-27 07:54:42 +03:00
|
|
|
static char *last_shown = 0; /* Last byte shown in a screen */
|
|
|
|
static int end_of_node = 0; /* Flag: the last character of the node shown? */
|
2001-06-05 20:41:44 +04:00
|
|
|
static char *currentpoint, *startpoint;
|
1998-02-27 07:54:42 +03:00
|
|
|
static char *selected_item;
|
|
|
|
|
|
|
|
/* The widget variables */
|
|
|
|
static Dlg_head *whelp;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char *page; /* Pointer to the selected page */
|
|
|
|
char *link; /* Pointer to the selected link */
|
|
|
|
} history [HISTORY_SIZE];
|
|
|
|
|
|
|
|
/* Link areas for the mouse */
|
|
|
|
typedef struct Link_Area {
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
char *link_name;
|
|
|
|
struct Link_Area *next;
|
|
|
|
} Link_Area;
|
|
|
|
|
|
|
|
static Link_Area *link_area = NULL;
|
|
|
|
static int inside_link_area = 0;
|
|
|
|
|
2003-09-08 01:24:01 +04:00
|
|
|
static cb_ret_t help_callback (struct Dlg_head *h, dlg_msg_t, int parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-10 11:55:35 +03:00
|
|
|
#ifdef HAS_ACS_AS_PCCHARS
|
2002-08-16 13:07:20 +04:00
|
|
|
static const struct {
|
1998-03-24 02:06:36 +03:00
|
|
|
int acscode;
|
|
|
|
int pccode;
|
|
|
|
} acs2pc_table [] = {
|
|
|
|
{ 'q', 0xC4 },
|
|
|
|
{ 'x', 0xB3 },
|
|
|
|
{ 'l', 0xDA },
|
|
|
|
{ 'k', 0xBF },
|
|
|
|
{ 'm', 0xC0 },
|
|
|
|
{ 'j', 0xD9 },
|
|
|
|
{ 'a', 0xB0 },
|
|
|
|
{ 'u', 0xB4 },
|
|
|
|
{ 't', 0xC3 },
|
|
|
|
{ 'w', 0xC2 },
|
|
|
|
{ 'v', 0xC1 },
|
|
|
|
{ 'n', 0xC5 },
|
|
|
|
{ 0, 0 } };
|
|
|
|
|
|
|
|
static int acs2pc (int acscode)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; acs2pc_table[i].acscode != 0; i++)
|
|
|
|
if (acscode == acs2pc_table[i].acscode) {
|
|
|
|
return acs2pc_table[i].pccode;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* returns the position where text was found in the start buffer */
|
|
|
|
/* or 0 if not found */
|
1998-12-03 00:27:27 +03:00
|
|
|
static char *
|
|
|
|
search_string (char *start, char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *d = text;
|
|
|
|
char *e = start;
|
|
|
|
|
|
|
|
/* fmt sometimes replaces a space with a newline in the help file */
|
|
|
|
/* Replace the newlines in the link name with spaces to correct the situation */
|
|
|
|
while (*d){
|
|
|
|
if (*d == '\n')
|
|
|
|
*d = ' ';
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
/* Do search */
|
|
|
|
for (d = text; *e; e++){
|
|
|
|
if (*d == *e)
|
|
|
|
d++;
|
|
|
|
else
|
|
|
|
d = text;
|
|
|
|
if (!*d)
|
|
|
|
return e+1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Searches text in the buffer pointed by start. Search ends */
|
|
|
|
/* if the CHAR_NODE_END is found in the text. Returns 0 on failure */
|
|
|
|
static char *search_string_node (char *start, char *text)
|
|
|
|
{
|
|
|
|
char *d = text;
|
|
|
|
char *e = start;
|
|
|
|
|
|
|
|
if (!start)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (; *e && *e != CHAR_NODE_END; e++){
|
|
|
|
if (*d == *e)
|
|
|
|
d++;
|
|
|
|
else
|
|
|
|
d = text;
|
|
|
|
if (!*d)
|
|
|
|
return e+1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Searches the_char in the buffer pointer by start and searches */
|
|
|
|
/* it can search forward (direction = 1) or backward (direction = -1) */
|
|
|
|
static char *search_char_node (char *start, char the_char, int direction)
|
|
|
|
{
|
|
|
|
char *e;
|
|
|
|
|
|
|
|
e = start;
|
|
|
|
|
|
|
|
for (; *e && (*e != CHAR_NODE_END); e += direction){
|
|
|
|
if (*e == the_char)
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the new current pointer when moved lines lines */
|
|
|
|
static char *move_forward2 (char *c, int lines)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int line;
|
|
|
|
|
|
|
|
currentpoint = c;
|
|
|
|
for (line = 0, p = currentpoint; *p && *p != CHAR_NODE_END; p++){
|
|
|
|
if (line == lines)
|
|
|
|
return currentpoint = p;
|
|
|
|
if (*p == '\n')
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
return currentpoint = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *move_backward2 (char *c, int lines)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int line;
|
|
|
|
|
|
|
|
currentpoint = c;
|
|
|
|
for (line = 0, p = currentpoint; *p && p >= data; p--){
|
|
|
|
if (*p == CHAR_NODE_END)
|
|
|
|
{
|
|
|
|
/* We reached the beginning of the node */
|
|
|
|
/* Skip the node headers */
|
|
|
|
while (*p != ']') p++;
|
|
|
|
return currentpoint = p + 2;
|
|
|
|
}
|
|
|
|
if (*(p - 1) == '\n')
|
|
|
|
line++;
|
|
|
|
if (line == lines)
|
|
|
|
return currentpoint = p;
|
|
|
|
}
|
|
|
|
return currentpoint = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_forward (int i)
|
|
|
|
{
|
|
|
|
if (end_of_node)
|
|
|
|
return;
|
|
|
|
currentpoint = move_forward2 (currentpoint, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_backward (int i)
|
|
|
|
{
|
|
|
|
currentpoint = move_backward2 (currentpoint, ++i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_to_top (int dummy)
|
|
|
|
{
|
|
|
|
while (currentpoint > data && *currentpoint != CHAR_NODE_END)
|
|
|
|
currentpoint--;
|
|
|
|
while (*currentpoint != ']')
|
|
|
|
currentpoint++;
|
|
|
|
currentpoint = currentpoint + 1;
|
|
|
|
selected_item = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_to_bottom (int dummy)
|
|
|
|
{
|
|
|
|
while (*currentpoint && *currentpoint != CHAR_NODE_END)
|
|
|
|
currentpoint++;
|
|
|
|
currentpoint--;
|
|
|
|
move_backward (help_lines - 1);
|
|
|
|
}
|
|
|
|
|
2002-08-19 09:00:58 +04:00
|
|
|
static char *help_follow_link (char *start, char *selected_item)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char link_name [MAXLINKNAME];
|
|
|
|
char *p;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (!selected_item)
|
|
|
|
return start;
|
|
|
|
|
|
|
|
for (p = selected_item; *p && *p != CHAR_NODE_END && *p != CHAR_LINK_POINTER; p++)
|
|
|
|
;
|
|
|
|
if (*p == CHAR_LINK_POINTER){
|
|
|
|
link_name [0] = '[';
|
|
|
|
for (i = 1; *p != CHAR_LINK_END && *p && *p != CHAR_NODE_END && i < MAXLINKNAME-3; )
|
|
|
|
link_name [i++] = *++p;
|
|
|
|
link_name [i-1] = ']';
|
|
|
|
link_name [i] = 0;
|
|
|
|
p = search_string (data, link_name);
|
|
|
|
if (p)
|
|
|
|
return p;
|
|
|
|
}
|
2002-11-12 20:46:54 +03:00
|
|
|
|
|
|
|
/* Create a replacement page with the error message */
|
|
|
|
return _(" Help file format error\n");
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *select_next_link (char *start, char *current_link)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (!current_link)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = search_string_node (current_link, STRING_LINK_END);
|
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
p = search_string_node (p, STRING_LINK_START);
|
|
|
|
if (!p)
|
|
|
|
return NULL;
|
|
|
|
return p - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *select_prev_link (char *start, char *current_link)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (!current_link)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = current_link - 1;
|
|
|
|
if (p <= start)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = search_char_node (p, CHAR_LINK_START, -1);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_link_area (int x, int y, char *link_name)
|
|
|
|
{
|
|
|
|
Link_Area *new;
|
|
|
|
|
|
|
|
if (inside_link_area)
|
2002-10-21 08:13:49 +04:00
|
|
|
message (0, _("Warning"), _(" Internal bug: Double start of link area "));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Allocate memory for a new link area */
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
new = g_new (Link_Area, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
new->next = link_area;
|
|
|
|
link_area = new;
|
|
|
|
|
|
|
|
/* Save the beginning coordinates of the link area */
|
|
|
|
link_area->x1 = x;
|
|
|
|
link_area->y1 = y;
|
|
|
|
|
|
|
|
/* Save the name of the destination anchor */
|
|
|
|
link_area->link_name = link_name;
|
|
|
|
|
|
|
|
inside_link_area = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void end_link_area (int x, int y)
|
|
|
|
{
|
|
|
|
if (inside_link_area){
|
|
|
|
/* Save the end coordinates of the link area */
|
|
|
|
link_area->x2 = x;
|
|
|
|
link_area->y2 = y;
|
|
|
|
|
|
|
|
inside_link_area = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clear_link_areas (void)
|
|
|
|
{
|
|
|
|
Link_Area *current;
|
|
|
|
|
|
|
|
while (link_area){
|
|
|
|
current = link_area;
|
|
|
|
link_area = current -> next;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (current);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
inside_link_area = 0;
|
|
|
|
}
|
|
|
|
|
2002-11-13 07:01:04 +03:00
|
|
|
static void help_show (Dlg_head *h, char *paint_start)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int col, line, c;
|
|
|
|
int painting = 1;
|
|
|
|
int acs; /* Flag: Alternate character set active? */
|
|
|
|
int repeat_paint;
|
|
|
|
int active_col, active_line;/* Active link position */
|
|
|
|
|
2002-09-02 11:48:01 +04:00
|
|
|
attrset (HELP_NORMAL_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
do {
|
|
|
|
|
|
|
|
line = col = acs = active_col = active_line = repeat_paint = 0;
|
|
|
|
|
|
|
|
clear_link_areas ();
|
|
|
|
if (selected_item < paint_start)
|
|
|
|
selected_item = NULL;
|
|
|
|
|
2002-08-31 18:20:14 +04:00
|
|
|
for (p = paint_start; *p && *p != CHAR_NODE_END && line < help_lines; p++) {
|
2002-08-16 13:07:20 +04:00
|
|
|
c = (unsigned char)*p;
|
1998-02-27 07:54:42 +03:00
|
|
|
switch (c){
|
|
|
|
case CHAR_LINK_START:
|
|
|
|
if (selected_item == NULL)
|
|
|
|
selected_item = p;
|
|
|
|
if (p == selected_item){
|
|
|
|
attrset (HELP_SLINK_COLOR);
|
|
|
|
|
|
|
|
/* Store the coordinates of the link */
|
|
|
|
active_col = col + 2;
|
|
|
|
active_line = line + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
attrset (HELP_LINK_COLOR);
|
|
|
|
start_link_area (col, line, p);
|
|
|
|
break;
|
|
|
|
case CHAR_LINK_POINTER:
|
|
|
|
painting = 0;
|
|
|
|
end_link_area (col - 1, line);
|
|
|
|
break;
|
|
|
|
case CHAR_LINK_END:
|
|
|
|
painting = 1;
|
|
|
|
attrset (HELP_NORMAL_COLOR);
|
|
|
|
break;
|
|
|
|
case CHAR_ALTERNATE:
|
|
|
|
acs = 1;
|
|
|
|
break;
|
|
|
|
case CHAR_NORMAL:
|
|
|
|
acs = 0;
|
|
|
|
break;
|
|
|
|
case CHAR_VERSION:
|
|
|
|
dlg_move (h, line+2, col+2);
|
|
|
|
addstr (VERSION);
|
|
|
|
col += strlen (VERSION);
|
|
|
|
break;
|
2002-09-22 20:40:33 +04:00
|
|
|
case CHAR_FONT_BOLD:
|
1998-02-27 07:54:42 +03:00
|
|
|
attrset (HELP_BOLD_COLOR);
|
|
|
|
break;
|
2002-09-22 20:40:33 +04:00
|
|
|
case CHAR_FONT_ITALIC:
|
1998-02-27 07:54:42 +03:00
|
|
|
attrset (HELP_ITALIC_COLOR);
|
|
|
|
break;
|
2002-09-22 20:40:33 +04:00
|
|
|
case CHAR_FONT_NORMAL:
|
1998-02-27 07:54:42 +03:00
|
|
|
attrset (HELP_NORMAL_COLOR);
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
line++;
|
|
|
|
col = 0;
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
col = (col/8 + 1) * 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!painting)
|
|
|
|
continue;
|
|
|
|
if (col > HELP_WINDOW_WIDTH-1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dlg_move (h, line+2, col+2);
|
|
|
|
if (acs){
|
|
|
|
if (c == ' ' || c == '.')
|
|
|
|
addch (c);
|
|
|
|
else
|
|
|
|
#ifndef HAVE_SLANG
|
1998-03-24 02:06:36 +03:00
|
|
|
addch (acs_map [c]);
|
|
|
|
#else
|
|
|
|
SLsmg_draw_object (h->y + line + 2, h->x + col + 2, c);
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
} else
|
|
|
|
addch (c);
|
|
|
|
col++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_shown = p;
|
|
|
|
end_of_node = line < help_lines;
|
|
|
|
attrset (HELP_NORMAL_COLOR);
|
|
|
|
if (selected_item >= last_shown){
|
|
|
|
if (link_area != NULL){
|
|
|
|
selected_item = link_area->link_name;
|
|
|
|
repeat_paint = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
selected_item = NULL;
|
|
|
|
}
|
|
|
|
} while (repeat_paint);
|
|
|
|
|
|
|
|
/* Position the cursor over a nice link */
|
|
|
|
if (active_col)
|
|
|
|
dlg_move (h, active_line, active_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int help_event (Gpm_Event *event, Widget *w)
|
|
|
|
{
|
|
|
|
Link_Area *current_area;
|
|
|
|
|
|
|
|
if (! (event->type & GPM_UP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The event is relative to the dialog window, adjust it: */
|
|
|
|
event->y -= 2;
|
|
|
|
|
|
|
|
if (event->buttons & GPM_B_RIGHT){
|
|
|
|
currentpoint = startpoint = history [history_ptr].page;
|
|
|
|
selected_item = history [history_ptr].link;
|
|
|
|
history_ptr--;
|
|
|
|
if (history_ptr < 0)
|
|
|
|
history_ptr = HISTORY_SIZE-1;
|
|
|
|
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (w->parent, DLG_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test whether the mouse click is inside one of the link areas */
|
|
|
|
current_area = link_area;
|
|
|
|
while (current_area)
|
|
|
|
{
|
|
|
|
/* Test one line link area */
|
|
|
|
if (event->y == current_area->y1 && event->x >= current_area->x1 &&
|
|
|
|
event->y == current_area->y2 && event->x <= current_area->x2)
|
|
|
|
break;
|
|
|
|
/* Test two line link area */
|
|
|
|
if (current_area->y1 + 1 == current_area->y2){
|
|
|
|
/* The first line */
|
|
|
|
if (event->y == current_area->y1 && event->x >= current_area->x1)
|
|
|
|
break;
|
|
|
|
/* The second line */
|
|
|
|
if (event->y == current_area->y2 && event->x <= current_area->x2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Mouse will not work with link areas of more than two lines */
|
|
|
|
|
|
|
|
current_area = current_area -> next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test whether a link area was found */
|
|
|
|
if (current_area){
|
|
|
|
/* The click was inside a link area -> follow the link */
|
|
|
|
history_ptr = (history_ptr+1) % HISTORY_SIZE;
|
|
|
|
history [history_ptr].page = currentpoint;
|
|
|
|
history [history_ptr].link = current_area->link_name;
|
|
|
|
currentpoint = startpoint = help_follow_link (currentpoint, current_area->link_name);
|
|
|
|
selected_item = NULL;
|
|
|
|
} else{
|
|
|
|
if (event->y < 0)
|
|
|
|
move_backward (help_lines - 1);
|
|
|
|
else if (event->y >= help_lines)
|
|
|
|
move_forward (help_lines - 1);
|
|
|
|
else if (event->y < help_lines/2)
|
|
|
|
move_backward (1);
|
|
|
|
else
|
|
|
|
move_forward (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the new node */
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (w->parent, DLG_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show help */
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
help_help_cmd (Dlg_head *h)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
history_ptr = (history_ptr+1) % HISTORY_SIZE;
|
|
|
|
history [history_ptr].page = currentpoint;
|
|
|
|
history [history_ptr].link = selected_item;
|
|
|
|
currentpoint = startpoint = search_string (data, "[How to use help]") + 1;
|
|
|
|
selected_item = NULL;
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (h, DLG_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
2002-09-03 11:15:01 +04:00
|
|
|
help_index_cmd (Dlg_head * h)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *new_item;
|
|
|
|
|
2002-09-03 11:15:01 +04:00
|
|
|
if (!(new_item = search_string (data, "[Contents]"))) {
|
|
|
|
message (1, MSG_ERROR, _(" Cannot find node %s in help file "),
|
|
|
|
"[Contents]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
history_ptr = (history_ptr + 1) % HISTORY_SIZE;
|
|
|
|
history[history_ptr].page = currentpoint;
|
|
|
|
history[history_ptr].link = selected_item;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-03 11:15:01 +04:00
|
|
|
currentpoint = startpoint = new_item + 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
selected_item = NULL;
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (h, DLG_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 07:01:04 +03:00
|
|
|
static void help_quit_cmd (void *x)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-22 17:06:59 +04:00
|
|
|
dlg_stop ((Dlg_head *)x);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void prev_node_cmd (Dlg_head *h)
|
|
|
|
{
|
|
|
|
currentpoint = startpoint = history [history_ptr].page;
|
|
|
|
selected_item = history [history_ptr].link;
|
|
|
|
history_ptr--;
|
|
|
|
if (history_ptr < 0)
|
|
|
|
history_ptr = HISTORY_SIZE-1;
|
|
|
|
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (h, DLG_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-11-13 05:27:00 +03:00
|
|
|
static int md_callback (Widget *w, int msg, int par)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-11-13 05:27:00 +03:00
|
|
|
return default_proc (msg, par);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static Widget *mousedispatch_new (int y, int x, int yl, int xl)
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
Widget *w = g_new (Widget, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
init_widget (w, y, x, yl, xl,
|
2003-09-01 03:29:49 +04:00
|
|
|
(callback_fn) md_callback, 0, (mouse_h) help_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2003-09-08 01:24:01 +04:00
|
|
|
static cb_ret_t
|
|
|
|
help_handle_key (struct Dlg_head *h, int c)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *new_item;
|
|
|
|
|
|
|
|
if (c != KEY_UP && c != KEY_DOWN &&
|
|
|
|
check_movement_keys (c, 1, help_lines, currentpoint,
|
|
|
|
(movefn) move_backward2,
|
|
|
|
(movefn) move_forward2,
|
|
|
|
(movefn) move_to_top,
|
|
|
|
(movefn) move_to_bottom))
|
|
|
|
/* Nothing */;
|
|
|
|
else switch (c){
|
|
|
|
case 'l':
|
|
|
|
case KEY_LEFT:
|
|
|
|
prev_node_cmd (h);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case KEY_RIGHT:
|
|
|
|
/* follow link */
|
|
|
|
if (!selected_item){
|
|
|
|
#ifdef WE_WANT_TO_GO_BACKWARD_ON_KEY_RIGHT
|
|
|
|
/* Is there any reason why the right key would take us
|
|
|
|
* backward if there are no links selected?, I agree
|
|
|
|
* with Torben than doing nothing in this case is better
|
|
|
|
*/
|
|
|
|
/* If there are no links, go backward in history */
|
|
|
|
history_ptr--;
|
|
|
|
if (history_ptr < 0)
|
|
|
|
history_ptr = HISTORY_SIZE-1;
|
|
|
|
|
|
|
|
currentpoint = startpoint = history [history_ptr].page;
|
|
|
|
selected_item = history [history_ptr].link;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
history_ptr = (history_ptr+1) % HISTORY_SIZE;
|
|
|
|
history [history_ptr].page = currentpoint;
|
|
|
|
history [history_ptr].link = selected_item;
|
|
|
|
currentpoint = startpoint = help_follow_link (currentpoint, selected_item) + 1;
|
|
|
|
}
|
|
|
|
selected_item = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_DOWN:
|
|
|
|
case '\t':
|
|
|
|
/* select next link */
|
|
|
|
new_item = select_next_link (startpoint, selected_item);
|
|
|
|
if (new_item){
|
|
|
|
selected_item = new_item;
|
|
|
|
if (selected_item >= last_shown){
|
|
|
|
if (c == KEY_DOWN)
|
|
|
|
move_forward (1);
|
|
|
|
else
|
|
|
|
selected_item = NULL;
|
|
|
|
}
|
|
|
|
} else if (c == KEY_DOWN)
|
|
|
|
move_forward (1);
|
|
|
|
else
|
|
|
|
selected_item = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_UP:
|
|
|
|
case ALT ('\t'):
|
|
|
|
/* select previous link */
|
|
|
|
new_item = select_prev_link (startpoint, selected_item);
|
|
|
|
selected_item = new_item;
|
|
|
|
if (selected_item < currentpoint || selected_item >= last_shown){
|
|
|
|
if (c == KEY_UP)
|
|
|
|
move_backward (1);
|
|
|
|
else{
|
|
|
|
if (link_area != NULL)
|
|
|
|
selected_item = link_area->link_name;
|
|
|
|
else
|
|
|
|
selected_item = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
/* Next node */
|
|
|
|
new_item = currentpoint;
|
|
|
|
while (*new_item && *new_item != CHAR_NODE_END)
|
|
|
|
new_item++;
|
|
|
|
if (*++new_item == '['){
|
2002-09-05 10:51:46 +04:00
|
|
|
while (*++new_item) {
|
2002-09-05 10:55:50 +04:00
|
|
|
if (*new_item == ']' && *++new_item && *++new_item) {
|
2002-09-05 10:51:46 +04:00
|
|
|
currentpoint = new_item;
|
|
|
|
selected_item = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
/* Previous node */
|
|
|
|
new_item = currentpoint;
|
|
|
|
while (new_item > data + 1 && *new_item != CHAR_NODE_END)
|
|
|
|
new_item--;
|
|
|
|
new_item--;
|
|
|
|
while (new_item > data && *new_item != CHAR_NODE_END)
|
|
|
|
new_item--;
|
|
|
|
while (*new_item != ']')
|
|
|
|
new_item++;
|
|
|
|
currentpoint = new_item + 2;
|
|
|
|
selected_item = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
help_index_cmd (h);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESC_CHAR:
|
|
|
|
case XCTRL('g'):
|
1998-03-14 03:42:23 +03:00
|
|
|
dlg_stop (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-09-08 01:24:01 +04:00
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
}
|
2003-09-08 01:24:01 +04:00
|
|
|
help_callback (h, DLG_DRAW, 0);
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2003-09-08 01:24:01 +04:00
|
|
|
static cb_ret_t
|
|
|
|
help_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-09-08 01:24:01 +04:00
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
case DLG_DRAW:
|
2002-09-02 11:48:01 +04:00
|
|
|
common_dialog_repaint (h);
|
2002-11-13 07:01:04 +03:00
|
|
|
help_show (h, currentpoint);
|
2003-09-08 01:24:01 +04:00
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case DLG_KEY:
|
2003-09-08 01:24:01 +04:00
|
|
|
return help_handle_key (h, parm);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return default_dlg_callback (h, msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
|
|
|
interactive_display_finish (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
clear_link_areas ();
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (data);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
void
|
|
|
|
interactive_display (char *filename, char *node)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-09-03 10:53:11 +04:00
|
|
|
WButtonBar *help_bar;
|
|
|
|
Widget *md;
|
|
|
|
char *hlpfile = filename;
|
2001-06-09 11:13:46 +04:00
|
|
|
|
|
|
|
if (filename)
|
|
|
|
data = load_file (filename);
|
|
|
|
else
|
|
|
|
data = load_mc_home_file ("mc.hlp", &hlpfile);
|
|
|
|
|
2002-09-03 10:53:11 +04:00
|
|
|
if (data == NULL) {
|
|
|
|
message (1, MSG_ERROR, _(" Cannot open file %s \n %s "), hlpfile,
|
|
|
|
unix_error_string (errno));
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2001-06-09 11:13:46 +04:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
g_free (hlpfile);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2002-09-03 10:53:11 +04:00
|
|
|
if (!node || !*node)
|
|
|
|
node = "[main]";
|
|
|
|
|
|
|
|
if (!(main_node = search_string (data, node))) {
|
|
|
|
message (1, MSG_ERROR, _(" Cannot find node %s in help file "),
|
|
|
|
node);
|
2002-09-03 11:22:23 +04:00
|
|
|
|
|
|
|
/* Fallback to [main], return if it also cannot be found */
|
|
|
|
main_node = search_string (data, "[main]");
|
|
|
|
if (!main_node) {
|
|
|
|
interactive_display_finish ();
|
|
|
|
return;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-09-02 06:40:22 +04:00
|
|
|
help_lines = min (LINES - 4, max (2 * LINES / 3, 18));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-03 10:53:11 +04:00
|
|
|
whelp =
|
|
|
|
create_dlg (0, 0, help_lines + 4, HELP_WINDOW_WIDTH + 4,
|
|
|
|
dialog_colors, help_callback, "[Help]", _("Help"),
|
|
|
|
DLG_TRYUP | DLG_CENTER | DLG_WANT_TAB);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-22 17:06:59 +04:00
|
|
|
selected_item = search_string_node (main_node, STRING_LINK_START) - 1;
|
|
|
|
currentpoint = startpoint = main_node + 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-03 10:53:11 +04:00
|
|
|
for (history_ptr = HISTORY_SIZE; history_ptr;) {
|
1998-02-27 07:54:42 +03:00
|
|
|
history_ptr--;
|
2002-09-03 10:53:11 +04:00
|
|
|
history[history_ptr].page = currentpoint;
|
|
|
|
history[history_ptr].link = selected_item;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-08-22 03:02:19 +04:00
|
|
|
help_bar = buttonbar_new (1);
|
1998-02-27 07:54:42 +03:00
|
|
|
help_bar->widget.y -= whelp->y;
|
|
|
|
help_bar->widget.x -= whelp->x;
|
2002-09-03 10:53:11 +04:00
|
|
|
|
|
|
|
md = mousedispatch_new (1, 1, help_lines, HELP_WINDOW_WIDTH - 2);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
add_widget (whelp, help_bar);
|
|
|
|
add_widget (whelp, md);
|
|
|
|
|
2002-11-13 02:33:15 +03:00
|
|
|
define_label_data (whelp, 1, _("Help"), (buttonbarfn) help_help_cmd,
|
2002-09-03 10:53:11 +04:00
|
|
|
whelp);
|
2002-11-13 02:33:15 +03:00
|
|
|
define_label_data (whelp, 2, _("Index"), (buttonbarfn) help_index_cmd,
|
|
|
|
whelp);
|
|
|
|
define_label_data (whelp, 3, _("Prev"), (buttonbarfn) prev_node_cmd,
|
|
|
|
whelp);
|
|
|
|
define_label (whelp, 4, "", 0);
|
|
|
|
define_label (whelp, 5, "", 0);
|
|
|
|
define_label (whelp, 6, "", 0);
|
|
|
|
define_label (whelp, 7, "", 0);
|
|
|
|
define_label (whelp, 8, "", 0);
|
|
|
|
define_label (whelp, 9, "", 0);
|
2002-11-13 07:01:04 +03:00
|
|
|
define_label_data (whelp, 10, _("Quit"), help_quit_cmd, whelp);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
run_dlg (whelp);
|
|
|
|
interactive_display_finish ();
|
|
|
|
destroy_dlg (whelp);
|
|
|
|
}
|
|
|
|
|