death to trailing whitespace
[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 <stdlib.h>
14
15 #ifdef AFS_HPUX_ENV
16 #include <sys/types.h>
17 #endif
18 #include <lwp.h>
19 #include "gtxobjects.h"
20 #include "gtxwindows.h"
21 #include "gtxcurseswin.h"
22 #include "gtxinput.h"
23 #include "gtxkeymap.h"
24 #include "gtxframe.h"
25 #include <afs/stds.h>
26
27
28 /* process input */
29 void *
30 gtx_InputServer(void *param)
31 {
32     struct gwin *awin = (struct gwin *) param;
33
34     int tc;
35     int code;
36     struct gtx_frame *tframe;
37
38     WOP_DISPLAY(awin);          /* start off with a clean display */
39     while (1) {
40         /* get a character from the generic window */
41         tframe = awin->w_frame;
42         code = WOP_WAIT(awin);
43         if (code) {
44             printf("***WAIT FAILURE %d****\n", code);
45             exit(1);
46         }
47         tc = WOP_GETCHAR(awin);
48         tframe->flags &= ~GTXFRAME_NEWDISPLAY;  /* OK to clear now */
49         if (tc < 0)
50             break;              /* EOF or some such */
51         /* otherwise, process the character and go get a new one */
52         gtxframe_ClearMessageLine(tframe);
53         tframe->flags &= ~(GTXFRAME_RECURSIVEEND | GTXFRAME_RECURSIVEERR);
54         keymap_ProcessKey(tframe->keystate, tc, awin);
55         tframe = awin->w_frame; /* in case command changed it */
56         if (tframe->flags & GTXFRAME_RECURSIVEEND) {
57             tframe->flags &= ~GTXFRAME_RECURSIVEEND;
58             return 0;
59         }
60         tframe->flags &= ~GTXFRAME_RECURSIVEEND;
61         WOP_DISPLAY(awin);      /* eventually calls gtxframe_Display */
62     }
63     return 0;
64 }
65
66 struct gwin *
67 gtx_Init(int astartInput,
68          int atype)                     /* type of window to create */
69 {
70     PROCESS junk;
71     struct onode_initparams oi_params;  /* object init params */
72     struct gwin_initparams wi_params;   /* window initialization params */
73     struct gwin *twin;
74     int code;
75
76     /* setup the main window structure */
77     wi_params.i_type = GATOR_WIN_CURSES;
78     wi_params.i_x = 0;
79     wi_params.i_y = 0;
80     wi_params.i_width = 80;
81     wi_params.i_height = 200;
82     wi_params.i_debug = 0;      /* or 1 if we want debugging done */
83
84     /*
85      * Set up the basic onode initialization parameters, throwing in
86      * the graphics-specific stuff.
87      */
88     oi_params.i_debug = 0;      /* or 1 if we want debugging */
89     oi_params.i_gwparams = &wi_params;
90
91     code = gator_objects_init(&oi_params);
92     if (code)
93         return NULL;
94
95     /* if we start input thread */
96     IOMGR_Initialize();         /* input thread uses it */
97     if (astartInput)
98         code =
99             LWP_CreateProcess(gtx_InputServer, 8192, LWP_NORMAL_PRIORITY,
100                               (void *)0, "gx-listener", &junk);
101     /* all done */
102     twin = &gator_basegwin;
103     return twin;
104 }