diff options
| author | Paul Richards <paul@FreeBSD.org> | 1995-03-01 08:19:06 +0000 |
|---|---|---|
| committer | Paul Richards <paul@FreeBSD.org> | 1995-03-01 08:19:06 +0000 |
| commit | be7d950dc87bef2e5728cd6b5ae22c29a7f9c8ec (patch) | |
| tree | 753e04f0080c2a52b255d5d8e021697c2200b32b /lib/libforms/examples | |
| parent | 1214e6da665ee16823d658e7860740f8c0a90e6a (diff) | |
Notes
Diffstat (limited to 'lib/libforms/examples')
| -rw-r--r-- | lib/libforms/examples/Makefile | 10 | ||||
| -rw-r--r-- | lib/libforms/examples/example.c | 60 | ||||
| -rw-r--r-- | lib/libforms/examples/example.frm | 28 |
3 files changed, 57 insertions, 41 deletions
diff --git a/lib/libforms/examples/Makefile b/lib/libforms/examples/Makefile index e098b6897c2d..4f0a23fafdd7 100644 --- a/lib/libforms/examples/Makefile +++ b/lib/libforms/examples/Makefile @@ -1,7 +1,7 @@ PROG = example NOMAN = yet -SRCS = example.c frm.tab.h +SRCS = example.c CFLAGS = -g -static @@ -11,11 +11,7 @@ FORMDIR=${.CURDIR}/../obj FORMDIR=${.CURDIR}/.. .endif -LDADD = -L${FORMDIR} -lforms -lncurses -lmytinfo - -CLEANFILES += frm.tab.h - -frm.tab.h: - fib example.frm +LDADD = -L${FORMDIR} -lforms -lncurses -lmytinfo -ll +DPADD = /usr/lib/libforms.a .include <bsd.prog.mk> diff --git a/lib/libforms/examples/example.c b/lib/libforms/examples/example.c index 120fdb14efd5..f2dad1c9a6a7 100644 --- a/lib/libforms/examples/example.c +++ b/lib/libforms/examples/example.c @@ -1,4 +1,4 @@ -/*- +/* * Copyright (c) 1995 * Paul Richards. All rights reserved. * @@ -33,36 +33,62 @@ */ #include <stdio.h> #include "../forms.h" -#include "frm.tab.h" main() { + struct Tuple *tuple; + struct Form *form; int res; initscr(); - initfrm(&example); - if (!example.window) { - fprintf(stderr, "\nUnable to initialize forms library.\n"); - endwin(); - exit(1); + form_bind_tuple("exit_form", FT_FUNC, &exit_form); + form_bind_tuple("cancel_form", FT_FUNC, &cancel_form); + + if (form_load("example.frm") == FS_ERROR) + exit(0);; + + form = form_start("example"); + + if (!form) { + err(-1, "No form returned"); + exit(0); } - keypad(example.window, TRUE); + + keypad(form->window, TRUE); + cbreak(); + noecho(); + + tuple = form_get_tuple("example", FT_FORM); + if (!tuple) + err(0, "No such form"); + else + form = (struct Form *)tuple->addr; print_status("This is the status line"); - while (!(res = update_form(&example))); - wclear(example.window); - wrefresh(example.window); + res = form_show("example"); + + while (form->status == FS_RUNNING) { + do_field(form); + wrefresh(form->window); + } + + wclear(form->window); + wrefresh(form->window); - if (res == F_DONE) { + if (form->status == FS_EXIT) { printf("You're entries were:\n\n"); - printf("%s\n",input1.input); - printf("%s\n",input2.input); - printf("%s\n",menu1.options[example_fields[7].field.menu->selected]); - } else if (res == F_CANCEL) + tuple = form_get_tuple("input1", FT_FIELD_INST); + printf("Input 1 = %s\n", ((struct Field *)tuple->addr)->field.input->input); + tuple = form_get_tuple("input2", FT_FIELD_INST); + printf("Input 2 = %s\n", ((struct Field *)tuple->addr)->field.input->input); + tuple = form_get_tuple("menu1", FT_FIELD_INST); + res = ((struct Field *)tuple->addr)->field.menu->selected; + printf("Menu selected = %d, %s\n", res, + ((struct Field *)tuple->addr)->field.menu->options[res]); + } else if (form->status == FS_CANCEL) printf("You cancelled the form\n"); - endfrm(&example); endwin(); } diff --git a/lib/libforms/examples/example.frm b/lib/libforms/examples/example.frm index e2ebd8004a44..d1f5349237bd 100644 --- a/lib/libforms/examples/example.frm +++ b/lib/libforms/examples/example.frm @@ -1,9 +1,4 @@ -Colours example { - pair = red, yellow - pair = blue, white -} - -field1 { attributes = A_BLINK|A_BOLD text = "This text is bold and flashy" } +field1 { attributes = 0 text = "This text is bold and flashy" } field2 { height = 2 @@ -28,28 +23,27 @@ field7 { selected = 0 options = "Choose", "another", "of", "these" } field8 { width = 6 action = "EXIT" function = exit_form } field9 { - attributes = COLOR_PAIR(1) - highlight = COLOR_PAIR(1)|A_BOLD - action = "CANCEL" - function = cancel_form +action = "CANCEL" +function = cancel_form } Form example at 0,0 { height = 25 width = 80 + start = input1 colortable = example - attributes = COLOR_PAIR(1) + attributes = 0 - Title {attributes = COLOR_PAIR(2) text = "A Simple Demo"} at 0,30 + Title {attributes = 0 text = "A Simple Demo"} at 0,30 field1 at 3,23 field2 at 7, 2 field4 at 11, 2 field6 at 15, 2 - input1 {field3} at 7,45, next=input2, up=input2, down=input2 - input2 {field5} at 11,45, next=menu1, up=input1, down=menu1 - menu1 {field7} at 15,45, next=quit, up=input2, down=quit - quit {field8} at 20,20, up=menu1, right=cancel - cancel {field9} at 20,43, up=input1, down=input1, left=quit, right=input1 + input1 {field3} at 7,45, next=input2 + input2 {field5} at 11,45, next=menu1 + menu1 {field7} at 15,45, next=quit + quit {field8} at 20,20, up = menu1, right = cancel + cancel {field9} at 20,43, next=input1 } |
