Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/util/help.c
blob: adaabb7594bf88240fa3cfcf58615a53ac4480a5 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifdef _plan9_
#include <u.h>
#include <libc.h>
#else
#include <stdlib.h>
#endif
#include <ctype.h>
#include <config.h>
#include <xio.h>
#include <xshl.h>
struct helpstatus {
    int eol;
    xio_file file;
};
static int gethelp(void *userdata)
{
    struct helpstatus *s = (struct helpstatus *) userdata;
    int c = xio_getc(s->file);
    if (c == '\r')
	return (gethelp(userdata));
    if (c < 0 || c > 255)
	return 0;
    if (c == '%' && s->eol)
	return 0;
    s->eol = (c == '\n');
    return c;
}

struct xshl_line *help_make(CONST char *command,
			    int getwidth(void *, int flags,
					 CONST char *text), int width,
			    int smallheight, int bigheight)
{
    struct helpstatus *s = (struct helpstatus *) malloc(sizeof(*s));
    struct xshl_line *line;
    s->file = xio_gethelp();
    if (s->file == XIO_FAILED) {
	free(s);
	return 0;
    }
    s->eol = 1;
    while (1) {
	int c;
	c = xio_getc(s->file);
	if (c == '%' && s->eol) {
	    c = xio_getc(s->file);
	    do {
		int i = 0;
		i = 0;
		while (command[i] && c == command[i]) {
		    c = xio_getc(s->file);
		    i++;
		}
		if (!command[i]) {
		    if (isspace(c)) {
			while (c != '\n' && !xio_feof(s->file))
			    c = xio_getc(s->file);
			line =
			    xshl_interpret(s, gethelp, width, getwidth, 0,
					   smallheight, bigheight);
			xio_close(s->file);
			free(s);
			return (line);
		    }
		} else {
		    while (c != '\n' && c != ' ' && !xio_feof(s->file))
			c = xio_getc(s->file);
		    if (c == ' ')
			while (c == ' ')
			    c = xio_getc(s->file);
		}
	    }
	    while (c != '\n' && !xio_feof(s->file));
	}			/*c==% */
	s->eol = (c == '\n');
	if (xio_feof(s->file)) {
	    xio_close(s->file);
	    return NULL;
	}
    }				/*while 1 */
}

#if _NEVER_
void help_print(char *name, int skip, int width)
{
    struct xshl_line *l;
    l = help_make(name, xshl_textlen, width, 1, 1);
    if (l == NULL) {
	printf("Help not available!\n");
	return;
    }
    xshl_print(skip, l);
    xshl_free(l);
}
#endif