File: flihelpbrowsercb.c

package info (click to toggle)
xplot 1.19-9.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 460 kB
  • sloc: ansic: 1,264; sh: 359; makefile: 86
file content (75 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

#include <ctype.h> 
#include <fli.h>
#include <stdio.h>
#include <string.h> 

void fli_help_browser_cb (FL_OBJECT *ob, long data)
{
    register int
	thisindex = (int) data,
	active = 0;
    register FILE
	*f = fli_help_browser [thisindex].f;
    char
	selection [1025],
	buf [1025],
	*cp;
    register FL_FORM
	*form = fli_help_browser [thisindex].form;
    register FL_OBJECT
	*textw = fli_help_browser [thisindex].textbrowser;

    /* determine clicked selection, put it in variable selection */
    strcpy (buf, fl_get_browser_line (ob, fl_get_browser (ob)));

    if (ob == textw)		/* for text window, strip off [] */ 
    {
	if (sscanf (buf, "%*[^[][%s]", selection) < 1)
	    return;
	if (! (cp = strchr (selection, ']')) )
	    return;
	* (cp + 1) = '\0';
    }
    else			/* for index/contents, strip off whitesp */
    {
	cp = buf;
	while (isspace (*cp))
	    cp++;
	strcpy (selection, cp);
	if ( (cp = strchr (selection, '\n')) )
	    *cp = '\0';
	strcat (selection, "]");
    }

    /* selection is now the string and a terminating ] , but not
       the leading [ */ 

    rewind (f);
    fl_clear_browser (textw);

    fl_freeze_form (form);
    while (1)
    {
	fgets (buf, 1024, f);
	if (feof (f))
	    break;

	if (buf [0] == '[')
	{
	    if (active)
		break;
	    else if (! strncmp (buf + 1, selection, strlen (selection)))
		active = 1;
	}
	else
	{
	    if (active)
		fl_add_browser_line (textw, buf);
	}
    }
    fl_unfreeze_form (form);

    /* all done */ 
}