From 1030dc837b10a03a02a85d5504cbeec168ce49e2 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Mon, 03 May 2010 21:53:47 +0000 Subject: Import XaoS r489 (trunk after version 3.5) --- (limited to 'src/util/help.c') diff --git a/src/util/help.c b/src/util/help.c new file mode 100644 index 0000000..adaabb7 --- /dev/null +++ b/src/util/help.c @@ -0,0 +1,95 @@ +#ifdef _plan9_ +#include +#include +#else +#include +#endif +#include +#include +#include +#include +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 -- cgit v0.9.1