Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/util/help.c
diff options
context:
space:
mode:
authorBernie Innocenti <bernie@codewiz.org>2010-05-03 21:53:47 (GMT)
committer Bernie Innocenti <bernie@codewiz.org>2010-05-03 21:53:47 (GMT)
commit1030dc837b10a03a02a85d5504cbeec168ce49e2 (patch)
tree698eefa87ac437deaf36a4141b326f8ce7986692 /src/util/help.c
Import XaoS r489 (trunk after version 3.5)
Diffstat (limited to 'src/util/help.c')
-rw-r--r--src/util/help.c95
1 files changed, 95 insertions, 0 deletions
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 <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