Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / gtx / input.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 #include <roken.h>
14
15 #include <lwp.h>
16
17 #include "gtxobjects.h"
18 #include "gtxwindows.h"
19 #include "gtxcurseswin.h"
20 #include "gtxinput.h"
21 #include "gtxkeymap.h"
22 #include "gtxframe.h"
23 #include <afs/stds.h>
24
25
26 /* process input */
27 void *
28 gtx_InputServer(void *param)
29 {
30 struct gwin *awin = (struct gwin *) param;
31
32 int tc;
33 int code;
34 struct gtx_frame *tframe;
35
36 WOP_DISPLAY(awin); /* start off with a clean display */
37 while (1) {
38 /* get a character from the generic window */
39 tframe = awin->w_frame;
40 code = WOP_WAIT(awin);
41 if (code) {
42 printf("***WAIT FAILURE %d****\n", code);
43 exit(1);
44 }
45 tc = WOP_GETCHAR(awin);
46 tframe->flags &= ~GTXFRAME_NEWDISPLAY; /* OK to clear now */
47 if (tc < 0)
48 break; /* EOF or some such */
49 /* otherwise, process the character and go get a new one */
50 gtxframe_ClearMessageLine(tframe);
51 tframe->flags &= ~(GTXFRAME_RECURSIVEEND | GTXFRAME_RECURSIVEERR);
52 keymap_ProcessKey(tframe->keystate, tc, awin);
53 tframe = awin->w_frame; /* in case command changed it */
54 if (tframe->flags & GTXFRAME_RECURSIVEEND) {
55 tframe->flags &= ~GTXFRAME_RECURSIVEEND;
56 return 0;
57 }
58 tframe->flags &= ~GTXFRAME_RECURSIVEEND;
59 WOP_DISPLAY(awin); /* eventually calls gtxframe_Display */
60 }
61 return 0;
62 }
63
64 struct gwin *
65 gtx_Init(int astartInput,
66 int atype) /* type of window to create */
67 {
68 PROCESS junk;
69 struct onode_initparams oi_params; /* object init params */
70 struct gwin_initparams wi_params; /* window initialization params */
71 struct gwin *twin;
72 int code;
73
74 /* setup the main window structure */
75 wi_params.i_type = GATOR_WIN_CURSES;
76 wi_params.i_x = 0;
77 wi_params.i_y = 0;
78 wi_params.i_width = 80;
79 wi_params.i_height = 200;
80 wi_params.i_debug = 0; /* or 1 if we want debugging done */
81
82 /*
83 * Set up the basic onode initialization parameters, throwing in
84 * the graphics-specific stuff.
85 */
86 oi_params.i_debug = 0; /* or 1 if we want debugging */
87 oi_params.i_gwparams = &wi_params;
88
89 code = gator_objects_init(&oi_params);
90 if (code)
91 return NULL;
92
93 /* if we start input thread */
94 IOMGR_Initialize(); /* input thread uses it */
95 if (astartInput) {
96 code = LWP_CreateProcess(gtx_InputServer, 8192, LWP_NORMAL_PRIORITY,
97 NULL, "gx-listener", &junk);
98 if (code)
99 return NULL;
100 }
101
102 /* all done */
103 twin = &gator_basegwin;
104 return twin;
105 }