From e5372aca255f61cf5852efee79e429cbf637ae5f Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 1 Mar 1995 08:19:06 +0000 Subject: Completely rewrite libforms so everything is done at runtime rather than at compile time. Should have same functionality as old libforms but with new mechanism. Lots of new features that use the new mechanism are still to be added. --- lib/libforms/examples/example.c | 60 +++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 17 deletions(-) (limited to 'lib/libforms/examples/example.c') diff --git a/lib/libforms/examples/example.c b/lib/libforms/examples/example.c index 120fdb1..f2dad1c 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 #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(); } -- cgit v1.1