Commit 04acfdec7184de0f9c7cc1045bd9fc2eaeb00712

Authored by perry
1 parent 0556b301
Exists in master

Substituicao de todas as chamadas ncurses por callbacks de forma que

o codigo 3270 fique desvinculado da camada de interface.
g3270.cbp
... ... @@ -18,22 +18,11 @@
18 18 <Option projectResourceIncludeDirsRelation="0"/>
19 19 </Target>
20 20 </Build>
21   - <Unit filename="configure">
22   - <Option compilerVar=""/>
23   - <Option objectName="configure"/>
24   - <Option target="default"/>
25   - </Unit>
26 21 <Unit filename="src/Makefile">
27 22 <Option compilerVar=""/>
28 23 <Option objectName="src/Makefile"/>
29 24 <Option target="default"/>
30 25 </Unit>
31   - <Unit filename="src/gtk.mk">
32   - <Option compilerVar=""/>
33   - <Option compile="0"/>
34   - <Option link="0"/>
35   - <Option target="default"/>
36   - </Unit>
37 26 <Unit filename="src/lib/3270ds.h">
38 27 <Option compilerVar=""/>
39 28 <Option compile="0"/>
... ... @@ -127,6 +116,12 @@
127 116 <Option link="0"/>
128 117 <Option target="default"/>
129 118 </Unit>
  119 + <Unit filename="src/lib/conf.h">
  120 + <Option compilerVar=""/>
  121 + <Option compile="0"/>
  122 + <Option link="0"/>
  123 + <Option target="default"/>
  124 + </Unit>
130 125 <Unit filename="src/lib/ctlr.c">
131 126 <Option compilerVar="CC"/>
132 127 <Option target="default"/>
... ... @@ -257,6 +252,12 @@
257 252 <Option link="0"/>
258 253 <Option target="default"/>
259 254 </Unit>
  255 + <Unit filename="src/lib/lib3270.h">
  256 + <Option compilerVar=""/>
  257 + <Option compile="0"/>
  258 + <Option link="0"/>
  259 + <Option target="default"/>
  260 + </Unit>
260 261 <Unit filename="src/lib/localdefs.h">
261 262 <Option compilerVar=""/>
262 263 <Option compile="0"/>
... ...
src/lib/Makefile
... ... @@ -40,7 +40,7 @@ INSTALL_DATA = ${INSTALL} -m 644
40 40 XCPPFLAGS = -I. -DLIBX3270DIR=\"$(LIBX3270DIR)\" -D_POSIX_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE
41 41 CFLAGS = -g -O2 $(XCPPFLAGS) $(CDEBUGFLAGS)
42 42 LDFLAGS =
43   -LIBS = -lnsl -lncurses -lutil
  43 +LIBS = -lnsl -lutil
44 44  
45 45 version.o: $(VOBJS) version.txt mkversion.sh
46 46 @chmod +x mkversion.sh version.txt
... ...
src/lib/keymap.c
... ... @@ -35,10 +35,10 @@
35 35 extern int cCOLS;
36 36  
37 37 #undef COLOR_BLACK
38   -#undef COLOR_RED
  38 +#undef COLOR_RED
39 39 #undef COLOR_GREEN
40 40 #undef COLOR_YELLOW
41   -#undef COLOR_BLUE
  41 +#undef COLOR_BLUE
42 42 #undef COLOR_WHITE
43 43 #if defined(HAVE_NCURSES_H) /*[*/
44 44 #include <ncurses.h>
... ... @@ -66,6 +66,9 @@ struct keymap {
66 66  
67 67 #define IS_INACTIVE(k) ((k)->hints[0] & KM_INACTIVE)
68 68  
  69 +KEYBOARD_INFO *keyboard_info_3270 = 0;
  70 +
  71 +
69 72 static struct keymap *master_keymap = NULL;
70 73 static struct keymap **nextk = &master_keymap;
71 74  
... ... @@ -418,7 +421,7 @@ longer_match(struct keymap *k, int nc)
418 421  
419 422 /*
420 423 * Helper function that returns a keymap action, sets the status line, and
421   - * traces the result.
  424 + * traces the result.
422 425 *
423 426 * If s is NULL, then this is a failed initial lookup.
424 427 * If s is 'ignore', then this is a lookup in progress (k non-NULL) or a
... ... @@ -560,118 +563,31 @@ lookup_key(int code)
560 563 }
561 564  
562 565 /* Complain. */
563   - beep();
  566 + if(keyboard_info_3270 && keyboard_info_3270->beep)
  567 + keyboard_info_3270->beep();
  568 +
564 569 trace_event(" keymap lookup failure after partial match\n");
565 570 return status_ret(ignore, NULL);
566 571 }
567 572  
568   -static struct {
569   - const char *name;
570   - int code;
571   -} ncurses_key[] = {
572   - { "BREAK", KEY_BREAK },
573   - { "DOWN", KEY_DOWN },
574   - { "UP", KEY_UP },
575   - { "LEFT", KEY_LEFT },
576   - { "RIGHT", KEY_RIGHT },
577   - { "HOME", KEY_HOME },
578   - { "BACKSPACE", KEY_BACKSPACE },
579   - { "F0", KEY_F0 },
580   - { "DL", KEY_DL },
581   - { "IL", KEY_IL },
582   - { "DC", KEY_DC },
583   - { "IC", KEY_IC },
584   - { "EIC", KEY_EIC },
585   - { "CLEAR", KEY_CLEAR },
586   - { "EOS", KEY_EOS },
587   - { "EOL", KEY_EOL },
588   - { "SF", KEY_SF },
589   - { "SR", KEY_SR },
590   - { "NPAGE", KEY_NPAGE },
591   - { "PPAGE", KEY_PPAGE },
592   - { "STAB", KEY_STAB },
593   - { "CTAB", KEY_CTAB },
594   - { "CATAB", KEY_CATAB },
595   - { "ENTER", KEY_ENTER },
596   - { "SRESET", KEY_SRESET },
597   - { "RESET", KEY_RESET },
598   - { "PRINT", KEY_PRINT },
599   - { "LL", KEY_LL },
600   - { "A1", KEY_A1 },
601   - { "A3", KEY_A3 },
602   - { "B2", KEY_B2 },
603   - { "C1", KEY_C1 },
604   - { "C3", KEY_C3 },
605   - { "BTAB", KEY_BTAB },
606   - { "BEG", KEY_BEG },
607   - { "CANCEL", KEY_CANCEL },
608   - { "CLOSE", KEY_CLOSE },
609   - { "COMMAND", KEY_COMMAND },
610   - { "COPY", KEY_COPY },
611   - { "CREATE", KEY_CREATE },
612   - { "END", KEY_END },
613   - { "EXIT", KEY_EXIT },
614   - { "FIND", KEY_FIND },
615   - { "HELP", KEY_HELP },
616   - { "MARK", KEY_MARK },
617   - { "MESSAGE", KEY_MESSAGE },
618   - { "MOVE", KEY_MOVE },
619   - { "NEXT", KEY_NEXT },
620   - { "OPEN", KEY_OPEN },
621   - { "OPTIONS", KEY_OPTIONS },
622   - { "PREVIOUS", KEY_PREVIOUS },
623   - { "REDO", KEY_REDO },
624   - { "REFERENCE", KEY_REFERENCE },
625   - { "REFRESH", KEY_REFRESH },
626   - { "REPLACE", KEY_REPLACE },
627   - { "RESTART", KEY_RESTART },
628   - { "RESUME", KEY_RESUME },
629   - { "SAVE", KEY_SAVE },
630   - { "SBEG", KEY_SBEG },
631   - { "SCANCEL", KEY_SCANCEL },
632   - { "SCOMMAND", KEY_SCOMMAND },
633   - { "SCOPY", KEY_SCOPY },
634   - { "SCREATE", KEY_SCREATE },
635   - { "SDC", KEY_SDC },
636   - { "SDL", KEY_SDL },
637   - { "SELECT", KEY_SELECT },
638   - { "SEND", KEY_SEND },
639   - { "SEOL", KEY_SEOL },
640   - { "SEXIT", KEY_SEXIT },
641   - { "SFIND", KEY_SFIND },
642   - { "SHELP", KEY_SHELP },
643   - { "SHOME", KEY_SHOME },
644   - { "SIC", KEY_SIC },
645   - { "SLEFT", KEY_SLEFT },
646   - { "SMESSAGE", KEY_SMESSAGE },
647   - { "SMOVE", KEY_SMOVE },
648   - { "SNEXT", KEY_SNEXT },
649   - { "SOPTIONS", KEY_SOPTIONS },
650   - { "SPREVIOUS", KEY_SPREVIOUS },
651   - { "SPRINT", KEY_SPRINT },
652   - { "SREDO", KEY_SREDO },
653   - { "SREPLACE", KEY_SREPLACE },
654   - { "SRIGHT", KEY_SRIGHT },
655   - { "SRSUME", KEY_SRSUME },
656   - { "SSAVE", KEY_SSAVE },
657   - { "SSUSPEND", KEY_SSUSPEND },
658   - { "SUNDO", KEY_SUNDO },
659   - { "SUSPEND", KEY_SUSPEND },
660   - { "UNDO", KEY_UNDO },
661   - { CN, 0 }
662   -};
663   -
664 573 /* Look up a curses symbolic key. */
665 574 static int
666 575 lookup_ccode(const char *s)
667 576 {
668 577 int i;
  578 + const KEYTABLE *key;
  579 +
669 580 unsigned long f;
670 581 char *ptr;
671 582  
672   - for (i = 0; ncurses_key[i].name != CN; i++) {
673   - if (!strcmp(s, ncurses_key[i].name))
674   - return ncurses_key[i].code;
  583 + if(!(keyboard_info_3270 || keyboard_info_3270->keys))
  584 + return -1;
  585 +
  586 + key = keyboard_info_3270->keys;
  587 +
  588 + for (i = 0; key[i].name != CN; i++) {
  589 + if (!strcmp(s, key[i].name))
  590 + return key[i].code;
675 591 }
676 592 if (s[0] == 'F' &&
677 593 (f = strtoul(s + 1, &ptr, 10)) < 64 &&
... ... @@ -686,11 +602,17 @@ lookup_ccode(const char *s)
686 602 static const char *
687 603 lookup_cname(int ccode)
688 604 {
689   - int i;
  605 + const KEYTABLE *key;
  606 + int i;
  607 +
  608 + if(!(keyboard_info_3270 || keyboard_info_3270->keys))
  609 + return CN;
  610 +
  611 + key = keyboard_info_3270->keys;
690 612  
691   - for (i = 0; ncurses_key[i].name != CN; i++) {
692   - if (ccode == ncurses_key[i].code)
693   - return ncurses_key[i].name;
  613 + for (i = 0; key[i].name != CN; i++) {
  614 + if (ccode == key[i].code)
  615 + return key[i].name;
694 616 }
695 617 if (ccode >= KEY_F0 && ccode < KEY_F0 + 64) {
696 618 static char buf[10];
... ...
src/lib/keymapc.h
... ... @@ -20,3 +20,25 @@ extern void keymap_init(void);
20 20 extern char *lookup_key(int k);
21 21 extern void keymap_dump(void);
22 22 extern const char *decode_key(int k, int hint, char *buf);
  23 +
  24 +#pragma pack(1)
  25 +
  26 +typedef struct _keytable
  27 +{
  28 + const char *name;
  29 + int code;
  30 +} KEYTABLE;
  31 +
  32 +typedef struct _keyboard_info
  33 +{
  34 + unsigned short sz;
  35 + unsigned short magic;
  36 +
  37 + void (*beep)(void);
  38 +
  39 + const KEYTABLE *keys;
  40 +} KEYBOARD_INFO;
  41 +
  42 +#pragma pack()
  43 +
  44 +
... ...
src/lib/screen.c
... ... @@ -13,7 +13,7 @@
13 13  
14 14 /*
15 15 * screen.c
16   - * A curses-based 3270 Terminal Emulator
  16 + *
17 17 * Screen drawing
18 18 */
19 19  
... ... @@ -37,1381 +37,143 @@
37 37 #include "widec.h"
38 38 #include "xioc.h"
39 39  
40   -#undef COLS
41   -extern int cCOLS;
42   -
43   -#undef COLOR_BLACK
44   -#undef COLOR_RED
45   -#undef COLOR_GREEN
46   -#undef COLOR_YELLOW
47   -#undef COLOR_BLUE
48   -#undef COLOR_WHITE
49   -#if defined(HAVE_NCURSES_H) /*[*/
50   -#include <ncurses.h>
51   -#else /*][*/
52   -#include <curses.h>
53   -#endif /*]*/
54   -
55   -static int cp[8][8][2];
56   -static int cmap[16] = {
57   - COLOR_BLACK, /* neutral black */
58   - COLOR_BLUE, /* blue */
59   - COLOR_RED, /* red */
60   - COLOR_MAGENTA, /* pink */
61   - COLOR_GREEN, /* green */
62   - COLOR_CYAN, /* turquoise */
63   - COLOR_YELLOW, /* yellow */
64   - COLOR_WHITE, /* neutral white */
65   -
66   - COLOR_BLACK, /* black */
67   - COLOR_BLUE, /* deep blue */
68   - COLOR_YELLOW, /* orange */
69   - COLOR_BLUE, /* deep blue */
70   - COLOR_GREEN, /* pale green */
71   - COLOR_CYAN, /* pale turquoise */
72   - COLOR_BLACK, /* grey */
73   - COLOR_WHITE /* white */
74   -};
75   -static int defattr = A_NORMAL;
76   -static unsigned long input_id;
77   -
78   -Boolean escaped = True;
79   -
80   -enum ts { TS_AUTO, TS_ON, TS_OFF };
81   -enum ts me_mode = TS_AUTO;
82   -enum ts ab_mode = TS_AUTO;
83   -
84   -#if defined(C3270_80_132) /*[*/
85   -struct screen_spec {
86   - int rows, cols;
87   - char *mode_switch;
88   -} screen_spec;
89   -struct screen_spec altscreen_spec, defscreen_spec;
90   -static SCREEN *def_screen = NULL, *alt_screen = NULL;
91   -static SCREEN *cur_screen = NULL;
92   -static void parse_screen_spec(const char *str, struct screen_spec *spec);
93   -#endif /*]*/
94   -
95   -static int status_row = 0; /* Row to display the status line on */
96   -static int status_skip = 0; /* Row to blank above the status line */
  40 +/*---[ Publics ]--------------------------------------------------------------*/
97 41  
98   -static Boolean curses_alt = False;
  42 +SCREEN_CALLBACK *screen_callbacks_3270 = 0;
  43 +Boolean escaped = True;
99 44  
100   -static void kybd_input(void);
101   -static void kybd_input2(int k, Boolean derived);
102   -static void draw_oia(void);
103   -static void status_connect(Boolean ignored);
104   -static void status_3270_mode(Boolean ignored);
105   -static void status_printer(Boolean on);
106   -static int get_color_pair(int fg, int bg);
107   -static int color_from_fa(unsigned char);
108   -static void screen_init2(void);
109   -static void set_status_row(int screen_rows, int emulator_rows);
110   -static Boolean ts_value(const char *s, enum ts *tsp);
111   -static int linedraw_to_acs(unsigned char c);
112   -static int apl_to_acs(unsigned char c);
113 45  
114 46 /* Initialize the screen. */
115   -void
116   -screen_init(void)
117   -{
118   - int want_ov_rows = ov_rows;
119   - int want_ov_cols = ov_cols;
120   - Boolean oversize = False;
121   -
122   -#if !defined(C3270_80_132) /*[*/
123   - /* Disallow altscreen/defscreen. */
124   - if ((appres.altscreen != CN) || (appres.defscreen != CN)) {
125   - (void) fprintf(stderr, "altscreen/defscreen not supported\n");
126   - exit(1);
127   - }
128   - /* Initialize curses. */
129   - if (initscr() == NULL) {
130   - (void) fprintf(stderr, "Can't initialize terminal.\n");
131   - exit(1);
132   - }
133   -#else /*][*/
134   - /* Parse altscreen/defscreen. */
135   - if ((appres.altscreen != CN) ^ (appres.defscreen != CN)) {
136   - (void) fprintf(stderr,
137   - "Must specify both altscreen and defscreen\n");
138   - exit(1);
139   - }
140   - if (appres.altscreen != CN) {
141   - parse_screen_spec(appres.altscreen, &altscreen_spec);
142   - if (altscreen_spec.rows < 27 || altscreen_spec.cols < 132) {
143   - (void) fprintf(stderr, "Rows and/or cols too small on "
144   - "alternate screen (mininum 27x132)\n");
145   - exit(1);
146   - }
147   - parse_screen_spec(appres.defscreen, &defscreen_spec);
148   - if (defscreen_spec.rows < 24 || defscreen_spec.cols < 80) {
149   - (void) fprintf(stderr, "Rows and/or cols too small on "
150   - "default screen (mininum 24x80)\n");
151   - exit(1);
152   - }
153   - }
154   -
155   - /* Set up ncurses, and see if it's within bounds. */
156   - if (appres.defscreen != CN) {
157   - char nbuf[64];
158   -
159   - (void) sprintf(nbuf, "COLUMNS=%d", defscreen_spec.cols);
160   - putenv(NewString(nbuf));
161   - (void) sprintf(nbuf, "LINES=%d", defscreen_spec.rows);
162   - putenv(NewString(nbuf));
163   - def_screen = newterm(NULL, stdout, stdin);
164   - if (def_screen == NULL) {
165   - (void) fprintf(stderr,
166   - "Can't initialize %dx%d defscreen terminal.\n",
167   - defscreen_spec.rows, defscreen_spec.cols);
168   - exit(1);
169   - }
170   - (void) write(1, defscreen_spec.mode_switch,
171   - strlen(defscreen_spec.mode_switch));
172   - }
173   - if (appres.altscreen) {
174   - char nbuf[64];
175   -
176   - (void) sprintf(nbuf, "COLUMNS=%d", altscreen_spec.cols);
177   - putenv(NewString(nbuf));
178   - (void) sprintf(nbuf, "LINES=%d", altscreen_spec.rows);
179   - putenv(NewString(nbuf));
180   - }
181   - alt_screen = newterm(NULL, stdout, stdin);
182   - if (alt_screen == NULL) {
183   - (void) fprintf(stderr, "Can't initialize terminal.\n");
184   - exit(1);
185   - }
186   - if (appres.altscreen) {
187   - set_term(alt_screen);
188   - cur_screen = alt_screen;
189   - }
190   -
191   - /* If they want 80/132 switching, then they want a model 5. */
192   - if (def_screen != NULL && model_num != 5) {
193   - appres.model = NewString("5");
194   - set_rows_cols(5, 0, 0);
195   - }
196   -#endif /*]*/
197   -
198   - while (LINES < maxROWS || COLS < maxCOLS) {
199   - char buf[2];
200   -
201   - /*
202   - * First, cancel any oversize. This will get us to the correct
203   - * model number, if there is any.
204   - */
205   - if ((ov_cols && ov_cols > COLS) ||
206   - (ov_rows && ov_rows > LINES)) {
207   - ov_cols = 0;
208   - ov_rows = 0;
209   - oversize = True;
210   - continue;
211   - }
212   -
213   - /* If we're at the smallest screen now, give up. */
214   - if (model_num == 2) {
215   - (void) fprintf(stderr, "Emulator won't fit on a %dx%d "
216   - "display.\n", LINES, COLS);
217   - exit(1);
218   - }
219   -
220   - /* Try a smaller model. */
221   - (void) sprintf(buf, "%d", model_num - 1);
222   - appres.model = NewString(buf);
223   - set_rows_cols(model_num - 1, 0, 0);
224   - }
225   -
226   - /*
227   - * Now, if they wanted an oversize, but didn't get it, try applying it
228   - * again.
229   - */
230   - if (oversize) {
231   - if (want_ov_rows > LINES - 2)
232   - want_ov_rows = LINES - 2;
233   - if (want_ov_rows < maxROWS)
234   - want_ov_rows = maxROWS;
235   - if (want_ov_cols > COLS)
236   - want_ov_cols = COLS;
237   - set_rows_cols(model_num, want_ov_cols, want_ov_rows);
238   - }
239   -
240   - /* Figure out where the status line goes, if it fits. */
241   -#if defined(C3270_80_132) /*[*/
242   - if (def_screen != NULL) {
243   - /* Start out in defscreen mode. */
244   - set_status_row(defscreen_spec.rows, 24);
245   - } else
246   -#endif /*]*/
247   - {
248   - /* Start out in altscreen mode. */
249   - set_status_row(LINES, maxROWS);
250   - }
251   -
252   - /* Set up callbacks for state changes. */
253   - register_schange(ST_CONNECT, status_connect);
254   - register_schange(ST_3270_MODE, status_3270_mode);
255   - register_schange(ST_PRINTER, status_printer);
256   -
257   - /* Play with curses color. */
258   - if (appres.m3279) {
259   - start_color();
260   - if (has_colors() && COLORS >= 8) {
261   - defattr = get_color_pair(COLOR_BLUE, COLOR_BLACK);
262   -#if defined(C3270_80_132) && defined(NCURSES_VERSION) /*[*/
263   - if (def_screen != NULL) {
264   - SCREEN *s = cur_screen;
265   -
266   - /*
267   - * Initialize the colors for the other
268   - * screen.
269   - */
270   - if (s == def_screen)
271   - set_term(alt_screen);
272   - else
273   - set_term(def_screen);
274   - start_color();
275   - curses_alt = !curses_alt;
276   - (void) get_color_pair(COLOR_BLUE, COLOR_BLACK);
277   - curses_alt = !curses_alt;
278   - set_term(s);
279   -
280   - }
281   -#endif /*]*/
282   - }
283   - else {
284   - appres.m3279 = False;
285   - /* Get the terminal name right. */
286   - set_rows_cols(model_num, want_ov_cols, want_ov_rows);
287   - }
288   - }
289   -
290   - /* See about keyboard Meta-key behavior. */
291   - if (!ts_value(appres.meta_escape, &me_mode))
292   - (void) fprintf(stderr, "invalid %s value: '%s', "
293   - "assuming 'auto'\n", ResMetaEscape, appres.meta_escape);
294   - if (me_mode == TS_AUTO)
295   - me_mode = tigetflag("km")? TS_OFF: TS_ON;
296   -
297   - /* See about all-bold behavior. */
298   - if (appres.all_bold_on)
299   - ab_mode = TS_ON;
300   - else if (!ts_value(appres.all_bold, &ab_mode))
301   - (void) fprintf(stderr, "invalid %s value: '%s', "
302   - "assuming 'auto'\n", ResAllBold, appres.all_bold);
303   - if (ab_mode == TS_AUTO)
304   - ab_mode = appres.m3279? TS_ON: TS_OFF;
305   - if (ab_mode == TS_ON)
306   - defattr |= A_BOLD;
307   -
308   - /* Set up the controller. */
309   - ctlr_init(-1);
310   - ctlr_reinit(-1);
311   -
312   - /* Finish screen initialization. */
313   - screen_init2();
314   - screen_suspend();
315   -}
316   -
317   -/* Configure the TTY settings for a curses screen. */
318   -static void
319   -setup_tty(void)
320   -{
321   - if (appres.cbreak_mode)
322   - cbreak();
323   - else
324   - raw();
325   - noecho();
326   - nonl();
327   - intrflush(stdscr,FALSE);
328   - if (appres.curses_keypad)
329   - keypad(stdscr, TRUE);
330   - meta(stdscr, TRUE);
331   - nodelay(stdscr, TRUE);
332   - refresh();
333   -}
334   -
335   -#if defined(C3270_80_132) /*[*/
336   -static void
337   -swap_screens(SCREEN *new_screen)
338   -{
339   - set_term(new_screen);
340   - cur_screen = new_screen;
341   -}
342   -#endif /*]*/
343   -
344   -/* Secondary screen initialization. */
345   -static void
346   -screen_init2(void)
347   -{
348   - /*
349   - * Finish initializing ncurses. This should be the first time that it
350   - * will send anything to the terminal.
351   - */
352   - escaped = False;
353   -
354   - /* Set up the keyboard. */
355   - setup_tty();
356   -#if defined(C3270_80_132) /*[*/
357   - if (def_screen != NULL) {
358   - /*
359   - * The first setup_tty() set up altscreen.
360   - * Set up defscreen now, and leave it as the
361   - * current curses screen.
362   - */
363   - swap_screens(def_screen);
364   - setup_tty();
365   - }
366   -#endif /*]*/
367   -
368   - /* Subscribe to input events. */
369   - input_id = AddInput(0, kybd_input);
370   -
371   - /* Ignore SIGINT and SIGTSTP. */
372   - signal(SIGINT, SIG_IGN);
373   - signal(SIGTSTP, SIG_IGN);
374   -
375   -#if defined(C3270_80_132) /*[*/
376   - /* Ignore SIGWINCH -- it might happen when we do 80/132 changes. */
377   - if (def_screen != NULL)
378   - signal(SIGWINCH, SIG_IGN);
379   -#endif /*]*/
380   -}
381   -
382   -/* Calculate where the status line goes now. */
383   -static void
384   -set_status_row(int screen_rows, int emulator_rows)
385   -{
386   - if (screen_rows < emulator_rows + 1) {
387   - status_row = status_skip = 0;
388   - } else if (screen_rows == emulator_rows + 1) {
389   - status_skip = 0;
390   - status_row = emulator_rows;
391   - } else {
392   - status_skip = screen_rows - 2;
393   - status_row = screen_rows - 1;
394   - }
395   -}
396   -
397   -/*
398   - * Parse a tri-state resource value.
399   - * Returns True for success, False for failure.
400   - */
401   -static Boolean
402   -ts_value(const char *s, enum ts *tsp)
  47 +void screen_init(void)
403 48 {
404   - *tsp = TS_AUTO;
405   -
406   - if (s != CN && s[0]) {
407   - int sl = strlen(s);
408   -
409   - if (!strncasecmp(s, "true", sl))
410   - *tsp = TS_ON;
411   - else if (!strncasecmp(s, "false", sl))
412   - *tsp = TS_OFF;
413   - else if (strncasecmp(s, "auto", sl))
414   - return False;
415   - }
416   - return True;
417   -}
418   -
419   -/* Allocate a color pair. */
420   -static int
421   -get_color_pair(int fg, int bg)
422   -{
423   - static int next_pair[2] = { 1, 1 };
424   - int pair;
425   -#if defined(C3270_80_132) && defined(NCURSES_VERSION) /*[*/
426   - /* ncurses allocates colors for each screen. */
427   - int pair_index = !!curses_alt;
428   -#else /*][*/
429   - /* curses allocates colors globally. */
430   - const int pair_index = 0;
431   -#endif /*]*/
432   -
433   - if ((pair = cp[fg][bg][pair_index]))
434   - return COLOR_PAIR(pair);
435   - if (next_pair[pair_index] >= COLOR_PAIRS)
436   - return 0;
437   - if (init_pair(next_pair[pair_index], fg, bg) != OK)
438   - return 0;
439   - pair = cp[fg][bg][pair_index] = next_pair[pair_index]++;
440   - return COLOR_PAIR(pair);
441   -}
442   -
443   -static int
444   -color_from_fa(unsigned char fa)
445   -{
446   - static int field_colors[4] = {
447   - COLOR_GREEN, /* default */
448   - COLOR_RED, /* intensified */
449   - COLOR_BLUE, /* protected */
450   - COLOR_WHITE /* protected, intensified */
451   -# define DEFCOLOR_MAP(f) \
452   - ((((f) & FA_PROTECT) >> 4) | (((f) & FA_INT_HIGH_SEL) >> 3))
453   -
454   - };
455   -
456   - if (appres.m3279) {
457   - int fg;
458   -
459   - fg = field_colors[DEFCOLOR_MAP(fa)];
460   - return get_color_pair(fg, COLOR_BLACK) |
461   - (((ab_mode == TS_ON) || FA_IS_HIGH(fa))? A_BOLD: A_NORMAL);
462   - } else
463   - return ((ab_mode == TS_ON) || FA_IS_HIGH(fa))? A_BOLD: A_NORMAL;
  49 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_init)
  50 + screen_callbacks_3270->screen_init();
464 51 }
465 52  
466 53 /* Display what's in the buffer. */
467   -void
468   -screen_disp(Boolean erasing unused)
  54 +void screen_disp(Boolean erasing)
469 55 {
470   - int row, col;
471   - int a;
472   - int c;
473   - unsigned char fa;
474   - extern Boolean screen_alt;
475   - struct screen_spec *cur_spec;
476   -#if defined(X3270_DBCS) /*[*/
477   - enum dbcs_state d;
478   -#endif /*]*/
479   -
480   - /* This may be called when it isn't time. */
481   - if (escaped)
482   - return;
483   -
484   -#if defined(C3270_80_132) /*[*/
485   - /* See if they've switched screens on us. */
486   - if (def_screen != NULL && screen_alt != curses_alt) {
487   - if (screen_alt) {
488   - (void) write(1, altscreen_spec.mode_switch,
489   - strlen(altscreen_spec.mode_switch));
490   - trace_event("Switching to alt (%dx%d) screen.\n",
491   - altscreen_spec.rows, altscreen_spec.cols);
492   - swap_screens(alt_screen);
493   - cur_spec = &altscreen_spec;
494   - } else {
495   - (void) write(1, defscreen_spec.mode_switch,
496   - strlen(defscreen_spec.mode_switch));
497   - trace_event("Switching to default (%dx%d) screen.\n",
498   - defscreen_spec.rows, defscreen_spec.cols);
499   - swap_screens(def_screen);
500   - cur_spec = &defscreen_spec;
501   - }
502   -
503   - /* Figure out where the status line goes now, if it fits. */
504   - set_status_row(cur_spec->rows, ROWS);
505   -
506   - curses_alt = screen_alt;
507   -
508   - /* Tell curses to forget what may be on the screen already. */
509   - endwin();
510   - erase();
511   - }
512   -#endif /*]*/
513   -
514   - fa = get_field_attribute(0);
515   - a = color_from_fa(fa);
516   - for (row = 0; row < ROWS; row++) {
517   - int baddr;
518   -
519   - if (!flipped)
520   - move(row, 0);
521   - for (col = 0; col < cCOLS; col++) {
522   - if (flipped)
523   - move(row, cCOLS-1 - col);
524   - baddr = row*cCOLS+col;
525   - if (ea_buf[baddr].fa) {
526   - fa = ea_buf[baddr].fa;
527   - if (appres.m3279) {
528   - if (ea_buf[baddr].fg ||
529   - ea_buf[baddr].bg) {
530   - int fg, bg;
531   -
532   - if (ea_buf[baddr].fg)
533   - fg = cmap[ea_buf[baddr].fg
534   - & 0x0f];
535   - else
536   - fg = COLOR_WHITE;
537   - if (ea_buf[baddr].bg)
538   - bg = cmap[ea_buf[baddr].bg
539   - & 0x0f];
540   - else
541   - bg = COLOR_BLACK;
542   - a = get_color_pair(fg, bg) |
543   - ((ab_mode == TS_ON)?
544   - A_BOLD: A_NORMAL);
545   - } else {
546   - a = color_from_fa(fa);
547   - }
548   - } else {
549   - a = FA_IS_HIGH(fa)? A_BOLD: A_NORMAL;
550   - }
551   - if (ea_buf[baddr].gr & GR_BLINK)
552   - a |= A_BLINK;
553   - if (ea_buf[baddr].gr & GR_REVERSE)
554   - a |= A_REVERSE;
555   - if (ea_buf[baddr].gr & GR_UNDERLINE)
556   - a |= A_UNDERLINE;
557   - if (ea_buf[baddr].gr & GR_INTENSIFY)
558   - a |= A_BOLD;
559   - attrset(defattr);
560   - addch(' ');
561   - } else if (FA_IS_ZERO(fa)) {
562   - attrset(a);
563   - addch(' ');
564   - } else {
565   - if (ea_buf[baddr].gr ||
566   - ea_buf[baddr].fg ||
567   - ea_buf[baddr].bg) {
568   - int b = ((ab_mode == TS_ON) ||
569   - FA_IS_HIGH(fa))? A_BOLD:
570   - A_NORMAL;
571   -
572   - if (ea_buf[baddr].gr & GR_BLINK)
573   - b |= A_BLINK;
574   - if (ea_buf[baddr].gr & GR_REVERSE)
575   - b |= A_REVERSE;
576   - if (ea_buf[baddr].gr & GR_UNDERLINE)
577   - b |= A_UNDERLINE;
578   - if (ea_buf[baddr].gr & GR_INTENSIFY)
579   - b |= A_BOLD;
580   - if (appres.m3279 &&
581   - (ea_buf[baddr].fg ||
582   - ea_buf[baddr].bg)) {
583   - int fg, bg;
584   -
585   - if (ea_buf[baddr].fg)
586   - fg = cmap[ea_buf[baddr].fg
587   - & 0x0f];
588   - else
589   - fg = COLOR_WHITE;
590   - if (ea_buf[baddr].bg)
591   - bg = cmap[ea_buf[baddr].bg
592   - & 0x0f];
593   - else
594   - bg = COLOR_BLACK;
595   - b |= get_color_pair(fg, bg);
596   - } else
597   - b |= a;
598   -
599   - attrset(b);
600   - } else {
601   - (void) attrset(a);
602   - }
603   -#if defined(X3270_DBCS) /*[*/
604   - d = ctlr_dbcs_state(baddr);
605   - if (IS_LEFT(d)) {
606   - int xaddr = baddr;
607   - char mb[16];
608   - int len;
609   - int i;
610   -
611   - INC_BA(xaddr);
612   - len = dbcs_to_mb(ea_buf[baddr].cc,
613   - ea_buf[xaddr].cc,
614   - mb);
615   - for (i = 0; i < len; i++) {
616   - addch(mb[i] & 0xff);
617   - }
618   - } else if (!IS_RIGHT(d)) {
619   -#endif /*]*/
620   - if (ea_buf[baddr].cs == CS_LINEDRAW) {
621   - c = linedraw_to_acs(ea_buf[baddr].cc);
622   - if (c != -1)
623   - addch(c);
624   - else
625   - addch(' ');
626   - } else if (ea_buf[baddr].cs == CS_APL ||
627   - (ea_buf[baddr].cs & CS_GE)) {
628   - c = apl_to_acs(ea_buf[baddr].cc);
629   - if (c != -1)
630   - addch(c);
631   - else
632   - addch(' ');
633   - } else {
634   - if (toggled(MONOCASE))
635   - addch(asc2uc[ebc2asc[ea_buf[baddr].cc]]);
636   - else
637   - addch(ebc2asc[ea_buf[baddr].cc]);
638   - }
639   -#if defined(X3270_DBCS) /*[*/
640   - }
641   -#endif /*]*/
642   - }
643   - }
644   - }
645   - if (status_row)
646   - draw_oia();
647   - (void) attrset(defattr);
648   - if (flipped)
649   - move(cursor_addr / cCOLS, cCOLS-1 - (cursor_addr % cCOLS));
650   - else
651   - move(cursor_addr / cCOLS, cursor_addr % cCOLS);
652   - refresh();
653   -}
654   -
655   -/* ESC processing. */
656   -static unsigned long eto = 0L;
657   -static Boolean meta_escape = False;
658   -
659   -static void
660   -escape_timeout(void)
661   -{
662   - trace_event("Timeout waiting for key following Escape, processing "
663   - "separately\n");
664   - eto = 0L;
665   - meta_escape = False;
666   - kybd_input2(0x1b, False);
  56 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_disp)
  57 + screen_callbacks_3270->screen_disp(erasing);
667 58 }
668 59  
669   -/* Keyboard input. */
670   -static void
671   -kybd_input(void)
  60 +void screen_suspend(void)
672 61 {
673   - int k;
674   - Boolean first = True;
675   - static Boolean failed_first = False;
676   -
677   - for (;;) {
678   - Boolean derived = False;
679   - char dbuf[128];
680   -
681   - if (isendwin())
682   - return;
683   - k = wgetch(stdscr);
684   - if (k == ERR) {
685   - if (first) {
686   - if (failed_first) {
687   - trace_event("End of File, exiting.\n");
688   - x3270_exit(1);
689   - }
690   - failed_first = True;
691   - }
692   - return;
693   - } else {
694   - failed_first = False;
695   - }
696   - trace_event("Key %s (0x%x)\n", decode_key(k, 0, dbuf), k);
697   -
698   - /* Handle Meta-Escapes. */
699   - if (meta_escape) {
700   - if (eto != 0L) {
701   - RemoveTimeOut(eto);
702   - eto = 0L;
703   - }
704   - meta_escape = False;
705   - k |= 0x80;
706   - derived = True;
707   - } else if (me_mode == TS_ON && k == 0x1b) {
708   - eto = AddTimeOut(100L, escape_timeout);
709   - trace_event(" waiting to see if Escape is followed by"
710   - " another key\n");
711   - meta_escape = True;
712   - continue;
713   - }
714   - kybd_input2(k, derived);
715   - first = False;
716   - }
  62 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_suspend)
  63 + screen_callbacks_3270->screen_suspend();
717 64 }
718 65  
719   -static void
720   -kybd_input2(int k, Boolean derived)
  66 +void screen_resume(void)
721 67 {
722   - char buf[16];
723   - char *action;
724   - char dbuf1[128], dbuf2[128];
725   -
726   - if (derived)
727   - trace_event(" combining <Key>Escape and %s into %s (0x%x)\n",
728   - decode_key(k & 0x7f, 0, dbuf1),
729   - decode_key(k, KM_META, dbuf2), k);
730   - action = lookup_key(k);
731   - if (action != CN) {
732   - if (strcmp(action, "[ignore]"))
733   - push_keymap_action(action);
734   - return;
735   - }
736   - ia_cause = IA_DEFAULT;
737   -
738   - /* These first cases apply to both 3270 and NVT modes. */
739   - switch (k) {
740   - case 0x1d:
741   - action_internal(Escape_action, IA_DEFAULT, CN, CN);
742   - return;
743   - case KEY_UP:
744   - action_internal(Up_action, IA_DEFAULT, CN, CN);
745   - return;
746   - case KEY_DOWN:
747   - action_internal(Down_action, IA_DEFAULT, CN, CN);
748   - return;
749   - case KEY_LEFT:
750   - action_internal(Left_action, IA_DEFAULT, CN, CN);
751   - return;
752   - case KEY_RIGHT:
753   - action_internal(Right_action, IA_DEFAULT, CN, CN);
754   - return;
755   - case KEY_HOME:
756   - action_internal(Home_action, IA_DEFAULT, CN, CN);
757   - return;
758   - default:
759   - break;
760   - }
761   -
762   - /* Then look for 3270-only cases. */
763   - if (IN_3270) switch(k) {
764   - /* These cases apply only to 3270 mode. */
765   - case 0x03:
766   - action_internal(Clear_action, IA_DEFAULT, CN, CN);
767   - return;
768   - case 0x12:
769   - action_internal(Reset_action, IA_DEFAULT, CN, CN);
770   - return;
771   - case 'L' & 0x1f:
772   - action_internal(Redraw_action, IA_DEFAULT, CN, CN);
773   - return;
774   - case '\t':
775   - action_internal(Tab_action, IA_DEFAULT, CN, CN);
776   - return;
777   - case 0177:
778   - case KEY_DC:
779   - action_internal(Delete_action, IA_DEFAULT, CN, CN);
780   - return;
781   - case '\b':
782   - case KEY_BACKSPACE:
783   - action_internal(BackSpace_action, IA_DEFAULT, CN, CN);
784   - return;
785   - case '\r':
786   - action_internal(Enter_action, IA_DEFAULT, CN, CN);
787   - return;
788   - case '\n':
789   - action_internal(Newline_action, IA_DEFAULT, CN, CN);
790   - return;
791   - case KEY_HOME:
792   - action_internal(Home_action, IA_DEFAULT, CN, CN);
793   - return;
794   - default:
795   - break;
796   - }
797   -
798   - /* Do some NVT-only translations. */
799   - if (IN_ANSI) switch(k) {
800   - case KEY_DC:
801   - k = 0x7f;
802   - break;
803   - case KEY_BACKSPACE:
804   - k = '\b';
805   - break;
806   - }
807   -
808   - /* Catch PF keys. */
809   - if (k >= KEY_F(1) && k <= KEY_F(24)) {
810   - (void) sprintf(buf, "%d", k - KEY_F0);
811   - action_internal(PF_action, IA_DEFAULT, buf, CN);
812   - return;
813   - }
814   -
815   - /* Then any other 8-bit ASCII character. */
816   - if (!(k & ~0xff)) {
817   - char ks[6];
818   - String params[2];
819   - Cardinal one;
820   -
821   - if (k >= ' ') {
822   - ks[0] = k;
823   - ks[1] = '\0';
824   - } else {
825   - (void) sprintf(ks, "0x%x", k);
826   - }
827   - params[0] = ks;
828   - params[1] = CN;
829   - one = 1;
830   - Key_action(NULL, NULL, params, &one);
831   - return;
832   - }
833   - trace_event(" dropped (no default)\n");
  68 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_resume)
  69 + screen_callbacks_3270->screen_resume();
834 70 }
835 71  
836   -void
837   -screen_suspend(void)
  72 +void cursor_move(int baddr)
838 73 {
839   - static Boolean need_to_scroll = False;
840   -
841   - if (!escaped) {
842   - escaped = True;
843   -#if defined(C3270_80_132) /*[*/
844   - if (def_screen != NULL) {
845   - /*
846   - * Call endwin() for the last-defined screen
847   - * (altscreen) first. Note that this will leave
848   - * the curses screen set to defscreen when this
849   - * function exits; if the 3270 is really in altscreen
850   - * mode, we will have to switch it back when we resume
851   - * the screen, below.
852   - */
853   - if (!curses_alt)
854   - swap_screens(alt_screen);
855   - endwin();
856   - swap_screens(def_screen);
857   - endwin();
858   - } else {
859   - endwin();
860   - }
861   -#else /*][*/
862   - endwin();
863   -#endif /*]*/
864   -
865   - if (need_to_scroll)
866   - printf("\n");
867   - else
868   - need_to_scroll = True;
869   -#if defined(C3270_80_132) /*[*/
870   - if (curses_alt && def_screen != NULL) {
871   - (void) write(1, defscreen_spec.mode_switch,
872   - strlen(defscreen_spec.mode_switch));
873   - }
874   -#endif /*]*/
875   - RemoveInput(input_id);
876   - }
  74 + if(screen_callbacks_3270 && screen_callbacks_3270->cursor_move)
  75 + screen_callbacks_3270->cursor_move(baddr);
877 76 }
878 77  
879   -void
880   -screen_resume(void)
  78 +void toggle_monocase(struct toggle *t, enum toggle_type tt)
881 79 {
882   - escaped = False;
883   -
884   -#if defined(C3270_80_132) /*[*/
885   - if (def_screen != NULL && curses_alt) {
886   - /*
887   - * When we suspended the screen, we switched to defscreen so
888   - * that endwin() got called in the right order. Switch back.
889   - */
890   - swap_screens(alt_screen);
891   - (void) write(1, altscreen_spec.mode_switch,
892   - strlen(altscreen_spec.mode_switch));
893   - }
894   -#endif /*]*/
895   - screen_disp(False);
896   - refresh();
897   - input_id = AddInput(0, kybd_input);
  80 + if(screen_callbacks_3270 && screen_callbacks_3270->toggle_monocase)
  81 + screen_callbacks_3270->toggle_monocase(t,tt);
898 82 }
899 83  
900   -void
901   -cursor_move(int baddr)
  84 +void status_ctlr_done(void)
902 85 {
903   - cursor_addr = baddr;
  86 + if(screen_callbacks_3270 && screen_callbacks_3270->status_ctlr_done)
  87 + screen_callbacks_3270->status_ctlr_done();
904 88 }
905 89  
906   -void
907   -toggle_monocase(struct toggle *t unused, enum toggle_type tt unused)
  90 +void status_insert_mode(Boolean on)
908 91 {
909   - screen_disp(False);
  92 + if(screen_callbacks_3270 && screen_callbacks_3270->status_insert_mode)
  93 + screen_callbacks_3270->status_insert_mode(on);
910 94 }
911 95  
912   -/* Status line stuff. */
913   -
914   -static Boolean status_ta = False;
915   -static Boolean status_rm = False;
916   -static Boolean status_im = False;
917   -static Boolean oia_boxsolid = False;
918   -static Boolean oia_undera = True;
919   -static Boolean oia_compose = False;
920   -static Boolean oia_printer = False;
921   -static unsigned char oia_compose_char = 0;
922   -static enum keytype oia_compose_keytype = KT_STD;
923   -#define LUCNT 8
924   -static char oia_lu[LUCNT+1];
925   -
926   -static char *status_msg = "";
927   -
928   -void
929   -status_ctlr_done(void)
  96 +void status_minus(void)
930 97 {
931   - oia_undera = True;
  98 + if(screen_callbacks_3270 && screen_callbacks_3270->status_minus)
  99 + screen_callbacks_3270->status_minus();
932 100 }
933 101  
934   -void
935   -status_insert_mode(Boolean on)
  102 +void status_oerr(int error_type)
936 103 {
937   - status_im = on;
  104 + if(screen_callbacks_3270 && screen_callbacks_3270->status_oerr)
  105 + screen_callbacks_3270->status_oerr(error_type);
938 106 }
939 107  
940   -void
941   -status_minus(void)
  108 +void status_reset(void)
942 109 {
943   - status_msg = "X -f";
  110 + if(screen_callbacks_3270 && screen_callbacks_3270->status_reset)
  111 + screen_callbacks_3270->status_reset();
944 112 }
945 113  
946   -void
947   -status_oerr(int error_type)
  114 +void status_reverse_mode(Boolean on)
948 115 {
949   - switch (error_type) {
950   - case KL_OERR_PROTECTED:
951   - status_msg = "X Protected";
952   - break;
953   - case KL_OERR_NUMERIC:
954   - status_msg = "X Numeric";
955   - break;
956   - case KL_OERR_OVERFLOW:
957   - status_msg = "X Overflow";
958   - break;
959   - }
  116 + if(screen_callbacks_3270 && screen_callbacks_3270->status_reverse_mode)
  117 + screen_callbacks_3270->status_reverse_mode(on);
960 118 }
961 119  
962   -void
963   -status_reset(void)
  120 +void status_syswait(void)
964 121 {
965   - if (kybdlock & KL_ENTER_INHIBIT)
966   - status_msg = "X Inhibit";
967   - else if (kybdlock & KL_DEFERRED_UNLOCK)
968   - status_msg = "X";
969   - else
970   - status_msg = "";
  122 + if(screen_callbacks_3270 && screen_callbacks_3270->status_syswait)
  123 + screen_callbacks_3270->status_syswait();
971 124 }
972 125  
973   -void
974   -status_reverse_mode(Boolean on)
  126 +void status_twait(void)
975 127 {
976   - status_rm = on;
  128 + if(screen_callbacks_3270 && screen_callbacks_3270->status_twait)
  129 + screen_callbacks_3270->status_twait();
977 130 }
978 131  
979   -void
980   -status_syswait(void)
  132 +void status_typeahead(Boolean on)
981 133 {
982   - status_msg = "X SYSTEM";
  134 + if(screen_callbacks_3270 && screen_callbacks_3270->status_typeahead)
  135 + screen_callbacks_3270->status_typeahead(on);
983 136 }
984 137  
985   -void
986   -status_twait(void)
  138 +void status_compose(Boolean on, unsigned char c, enum keytype keytype)
987 139 {
988   - oia_undera = False;
989   - status_msg = "X Wait";
  140 + if(screen_callbacks_3270 && screen_callbacks_3270->status_compose)
  141 + screen_callbacks_3270->status_compose(on,c,keytype);
990 142 }
991 143  
992   -void
993   -status_typeahead(Boolean on)
  144 +void status_lu(const char *lu)
994 145 {
995   - status_ta = on;
  146 + if(screen_callbacks_3270 && screen_callbacks_3270->status_lu)
  147 + screen_callbacks_3270->status_lu(lu);
996 148 }
997 149  
998   -void
999   -status_compose(Boolean on, unsigned char c, enum keytype keytype)
  150 +void Redraw_action(Widget w, XEvent *event, String *params, Cardinal *num_params)
1000 151 {
1001   - oia_compose = on;
1002   - oia_compose_char = c;
1003   - oia_compose_keytype = keytype;
  152 + if(screen_callbacks_3270 && screen_callbacks_3270->Redraw_action)
  153 + screen_callbacks_3270->Redraw_action(w,event,params,num_params);
1004 154 }
1005 155  
1006   -void
1007   -status_lu(const char *lu)
  156 +void ring_bell(void)
1008 157 {
1009   - if (lu != NULL) {
1010   - (void) strncpy(oia_lu, lu, LUCNT);
1011   - oia_lu[LUCNT] = '\0';
1012   - } else
1013   - (void) memset(oia_lu, '\0', sizeof(oia_lu));
  158 + if(screen_callbacks_3270 && screen_callbacks_3270->ring_bell)
  159 + screen_callbacks_3270->ring_bell();
1014 160 }
1015 161  
1016   -static void
1017   -status_connect(Boolean connected)
  162 +void screen_flip(void)
1018 163 {
1019   - if (connected) {
1020   - oia_boxsolid = IN_3270 && !IN_SSCP;
1021   - if (kybdlock & KL_AWAITING_FIRST)
1022   - status_msg = "X";
1023   - else
1024   - status_msg = "";
1025   - } else {
1026   - oia_boxsolid = False;
1027   - status_msg = "X Disconnected";
1028   - }
  164 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_flip)
  165 + screen_callbacks_3270->screen_flip();
1029 166 }
1030 167  
1031   -static void
1032   -status_3270_mode(Boolean ignored unused)
  168 +void screen_132(void)
1033 169 {
1034   - oia_boxsolid = IN_3270 && !IN_SSCP;
1035   - if (oia_boxsolid)
1036   - oia_undera = True;
  170 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_width)
  171 + screen_callbacks_3270->screen_width(132);
1037 172 }
1038 173  
1039   -static void
1040   -status_printer(Boolean on)
  174 +void screen_80(void)
1041 175 {
1042   - oia_printer = on;
  176 + if(screen_callbacks_3270 && screen_callbacks_3270->screen_width)
  177 + screen_callbacks_3270->screen_width(80);
1043 178 }
1044 179  
1045   -static void
1046   -draw_oia(void)
1047   -{
1048   - int rmargin;
1049   -
1050   -#if defined(C3270_80_132) /*[*/
1051   - if (def_screen != NULL) {
1052   - if (curses_alt)
1053   - rmargin = altscreen_spec.cols - 1;
1054   - else
1055   - rmargin = defscreen_spec.cols - 1;
1056   - } else
1057   -#endif /*]*/
1058   - {
1059   - rmargin = maxCOLS - 1;
1060   - }
1061   -
1062   - /* Make sure the status line region is filled in properly. */
1063   - if (appres.m3279) {
1064   - int i;
1065   -
1066   - attrset(defattr);
1067   - if (status_skip) {
1068   - move(status_skip, 0);
1069   - for (i = 0; i < rmargin; i++) {
1070   - printw(" ");
1071   - }
1072   - }
1073   - move(status_row, 0);
1074   - for (i = 0; i < rmargin; i++) {
1075   - printw(" ");
1076   - }
1077   - }
1078   -
1079   - (void) attrset(A_REVERSE | defattr);
1080   - mvprintw(status_row, 0, "4");
1081   - (void) attrset(A_UNDERLINE | defattr);
1082   - if (oia_undera)
1083   - printw("%c", IN_E? 'B': 'A');
1084   - else
1085   - printw(" ");
1086   - (void) attrset(A_REVERSE | defattr);
1087   - if (IN_ANSI)
1088   - printw("N");
1089   - else if (oia_boxsolid)
1090   - printw(" ");
1091   - else if (IN_SSCP)
1092   - printw("S");
1093   - else
1094   - printw("?");
1095   -
1096   - (void) attrset(defattr);
1097   - mvprintw(status_row, 8, "%-11s", status_msg);
1098   - mvprintw(status_row, rmargin-36,
1099   - "%c%c %c %c%c%c",
1100   - oia_compose? 'C': ' ',
1101   - oia_compose? oia_compose_char: ' ',
1102   - status_ta? 'T': ' ',
1103   - status_rm? 'R': ' ',
1104   - status_im? 'I': ' ',
1105   - oia_printer? 'P': ' ');
1106   -
1107   - mvprintw(status_row, rmargin-25, "%s", oia_lu);
1108   - mvprintw(status_row, rmargin-7,
1109   - "%03d/%03d", cursor_addr/cCOLS + 1, cursor_addr%cCOLS + 1);
1110   -}
1111   -
1112   -void
1113   -Redraw_action(Widget w unused, XEvent *event unused, String *params unused,
1114   - Cardinal *num_params unused)
1115   -{
1116   - if (!escaped) {
1117   - endwin();
1118   - refresh();
1119   - }
1120   -}
1121   -
1122   -void
1123   -ring_bell(void)
1124   -{
1125   - beep();
1126   -}
1127   -
1128   -void
1129   -screen_flip(void)
1130   -{
1131   - flipped = !flipped;
1132   - screen_disp(False);
1133   -}
1134   -
1135   -#if defined(C3270_80_132) /*[*/
1136   -/* Alt/default screen spec parsing. */
1137   -static void
1138   -parse_screen_spec(const char *str, struct screen_spec *spec)
1139   -{
1140   - char msbuf[3];
1141   - char *s, *t, c;
1142   - Boolean escaped = False;
1143   -
1144   - if (sscanf(str, "%dx%d=%2s", &spec->rows, &spec->cols, msbuf) != 3) {
1145   - (void) fprintf(stderr, "Invalid screen screen spec '%s', must "
1146   - "be '<rows>x<cols>=<init_string>'\n", str);
1147   - exit(1);
1148   - }
1149   - s = strchr(str, '=') + 1;
1150   - spec->mode_switch = Malloc(strlen(s) + 1);
1151   - t = spec->mode_switch;
1152   - while ((c = *s++)) {
1153   - if (escaped) {
1154   - switch (c) {
1155   - case 'E':
1156   - *t++ = 0x1b;
1157   - break;
1158   - case 'n':
1159   - *t++ = '\n';
1160   - break;
1161   - case 'r':
1162   - *t++ = '\r';
1163   - break;
1164   - case 'b':
1165   - *t++ = '\b';
1166   - break;
1167   - case 't':
1168   - *t++ = '\t';
1169   - break;
1170   - case '\\':
1171   - *t++ = '\\';
1172   - break;
1173   - default:
1174   - *t++ = c;
1175   - break;
1176   - }
1177   - escaped = False;
1178   - } else if (c == '\\')
1179   - escaped = True;
1180   - else
1181   - *t++ = c;
1182   - }
1183   - *t = '\0';
1184   -}
1185   -#endif /*]*/
1186   -
1187   -void
1188   -screen_132(void)
1189   -{
1190   -#if defined(C3270_80_132) /*[*/
1191   - if (cur_screen != alt_screen) {
1192   - swap_screens(alt_screen);
1193   - (void) write(1, altscreen_spec.mode_switch,
1194   - strlen(altscreen_spec.mode_switch));
1195   - ctlr_erase(True);
1196   - screen_disp(True);
1197   - }
1198   -#endif /*]*/
1199   -}
1200   -
1201   -void
1202   -screen_80(void)
1203   -{
1204   -#if defined(C3270_80_132) /*[*/
1205   - if (cur_screen != def_screen) {
1206   - swap_screens(def_screen);
1207   - (void) write(1, defscreen_spec.mode_switch,
1208   - strlen(defscreen_spec.mode_switch));
1209   - ctlr_erase(False);
1210   - screen_disp(True);
1211   - }
1212   -#endif /*]*/
1213   -}
1214   -
1215   -/*
1216   - * Translate an x3270 font line-drawing character (the first two rows of a
1217   - * standard X11 fixed-width font) to a curses ACS character.
1218   - *
1219   - * Returns -1 if there is no translation.
1220   - */
1221   -static int
1222   -linedraw_to_acs(unsigned char c)
1223   -{
1224   - switch (c) {
1225   -#if defined(ACS_BLOCK) /*[*/
1226   - case 0x0:
1227   - return ACS_BLOCK;
1228   -#endif /*]*/
1229   -#if defined(ACS_DIAMOND) /*[*/
1230   - case 0x1:
1231   - return ACS_DIAMOND;
1232   -#endif /*]*/
1233   -#if defined(ACS_CKBOARD) /*[*/
1234   - case 0x2:
1235   - return ACS_CKBOARD;
1236   -#endif /*]*/
1237   -#if defined(ACS_DEGREE) /*[*/
1238   - case 0x7:
1239   - return ACS_DEGREE;
1240   -#endif /*]*/
1241   -#if defined(ACS_PLMINUS) /*[*/
1242   - case 0x8:
1243   - return ACS_PLMINUS;
1244   -#endif /*]*/
1245   -#if defined(ACS_BOARD) /*[*/
1246   - case 0x9:
1247   - return ACS_BOARD;
1248   -#endif /*]*/
1249   -#if defined(ACS_LANTERN) /*[*/
1250   - case 0xa:
1251   - return ACS_LANTERN;
1252   -#endif /*]*/
1253   -#if defined(ACS_LRCORNER) /*[*/
1254   - case 0xb:
1255   - return ACS_LRCORNER;
1256   -#endif /*]*/
1257   -#if defined(ACS_URCORNER) /*[*/
1258   - case 0xc:
1259   - return ACS_URCORNER;
1260   -#endif /*]*/
1261   -#if defined(ACS_ULCORNER) /*[*/
1262   - case 0xd:
1263   - return ACS_ULCORNER;
1264   -#endif /*]*/
1265   -#if defined(ACS_LLCORNER) /*[*/
1266   - case 0xe:
1267   - return ACS_LLCORNER;
1268   -#endif /*]*/
1269   -#if defined(ACS_PLUS) /*[*/
1270   - case 0xf:
1271   - return ACS_PLUS;
1272   -#endif /*]*/
1273   -#if defined(ACS_S1) /*[*/
1274   - case 0x10:
1275   - return ACS_S1;
1276   -#endif /*]*/
1277   -#if defined(ACS_S3) /*[*/
1278   - case 0x11:
1279   - return ACS_S3;
1280   -#endif /*]*/
1281   -#if defined(ACS_HLINE) /*[*/
1282   - case 0x12:
1283   - return ACS_HLINE;
1284   -#endif /*]*/
1285   -#if defined(ACS_S7) /*[*/
1286   - case 0x13:
1287   - return ACS_S7;
1288   -#endif /*]*/
1289   -#if defined(ACS_S9) /*[*/
1290   - case 0x14:
1291   - return ACS_S9;
1292   -#endif /*]*/
1293   -#if defined(ACS_LTEE) /*[*/
1294   - case 0x15:
1295   - return ACS_LTEE;
1296   -#endif /*]*/
1297   -#if defined(ACS_RTEE) /*[*/
1298   - case 0x16:
1299   - return ACS_RTEE;
1300   -#endif /*]*/
1301   -#if defined(ACS_BTEE) /*[*/
1302   - case 0x17:
1303   - return ACS_BTEE;
1304   -#endif /*]*/
1305   -#if defined(ACS_TTEE) /*[*/
1306   - case 0x18:
1307   - return ACS_TTEE;
1308   -#endif /*]*/
1309   -#if defined(ACS_VLINE) /*[*/
1310   - case 0x19:
1311   - return ACS_VLINE;
1312   -#endif /*]*/
1313   -#if defined(ACS_LEQUAL) /*[*/
1314   - case 0x1a:
1315   - return ACS_LEQUAL;
1316   -#endif /*]*/
1317   -#if defined(ACS_GEQUAL) /*[*/
1318   - case 0x1b:
1319   - return ACS_GEQUAL;
1320   -#endif /*]*/
1321   -#if defined(ACS_PI) /*[*/
1322   - case 0x1c:
1323   - return ACS_PI;
1324   -#endif /*]*/
1325   -#if defined(ACS_NEQUAL) /*[*/
1326   - case 0x1d:
1327   - return ACS_NEQUAL;
1328   -#endif /*]*/
1329   -#if defined(ACS_STERLING) /*[*/
1330   - case 0x1e:
1331   - return ACS_STERLING;
1332   -#endif /*]*/
1333   -#if defined(ACS_BULLET) /*[*/
1334   - case 0x1f:
1335   - return ACS_BULLET;
1336   -#endif /*]*/
1337   - default:
1338   - return -1;
1339   - }
1340   -}
1341   -
1342   -static int
1343   -apl_to_acs(unsigned char c)
1344   -{
1345   - switch (c) {
1346   -#if defined(ACS_DEGREE) /*[*/
1347   - case 0xaf: /* CG 0xd1 */
1348   - return ACS_DEGREE;
1349   -#endif /*]*/
1350   -#if defined(ACS_LRCORNER) /*[*/
1351   - case 0xd4: /* CG 0xac */
1352   - return ACS_LRCORNER;
1353   -#endif /*]*/
1354   -#if defined(ACS_URCORNER) /*[*/
1355   - case 0xd5: /* CG 0xad */
1356   - return ACS_URCORNER;
1357   -#endif /*]*/
1358   -#if defined(ACS_ULCORNER) /*[*/
1359   - case 0xc5: /* CG 0xa4 */
1360   - return ACS_ULCORNER;
1361   -#endif /*]*/
1362   -#if defined(ACS_LLCORNER) /*[*/
1363   - case 0xc4: /* CG 0xa3 */
1364   - return ACS_LLCORNER;
1365   -#endif /*]*/
1366   -#if defined(ACS_PLUS) /*[*/
1367   - case 0xd3: /* CG 0xab */
1368   - return ACS_PLUS;
1369   -#endif /*]*/
1370   -#if defined(ACS_HLINE) /*[*/
1371   - case 0xa2: /* CG 0x92 */
1372   - return ACS_HLINE;
1373   -#endif /*]*/
1374   -#if defined(ACS_LTEE) /*[*/
1375   - case 0xc6: /* CG 0xa5 */
1376   - return ACS_LTEE;
1377   -#endif /*]*/
1378   -#if defined(ACS_RTEE) /*[*/
1379   - case 0xd6: /* CG 0xae */
1380   - return ACS_RTEE;
1381   -#endif /*]*/
1382   -#if defined(ACS_BTEE) /*[*/
1383   - case 0xc7: /* CG 0xa6 */
1384   - return ACS_BTEE;
1385   -#endif /*]*/
1386   -#if defined(ACS_TTEE) /*[*/
1387   - case 0xd7: /* CG 0xaf */
1388   - return ACS_TTEE;
1389   -#endif /*]*/
1390   -#if defined(ACS_VLINE) /*[*/
1391   - case 0x85: /* CG 0xa84? */
1392   - return ACS_VLINE;
1393   -#endif /*]*/
1394   -#if defined(ACS_LEQUAL) /*[*/
1395   - case 0x8c: /* CG 0xf7 */
1396   - return ACS_LEQUAL;
1397   -#endif /*]*/
1398   -#if defined(ACS_GEQUAL) /*[*/
1399   - case 0xae: /* CG 0xd9 */
1400   - return ACS_GEQUAL;
1401   -#endif /*]*/
1402   -#if defined(ACS_NEQUAL) /*[*/
1403   - case 0xbe: /* CG 0x3e */
1404   - return ACS_NEQUAL;
1405   -#endif /*]*/
1406   -#if defined(ACS_BULLET) /*[*/
1407   - case 0xa3: /* CG 0x93 */
1408   - return ACS_BULLET;
1409   -#endif /*]*/
1410   - case 0xad:
1411   - return '[';
1412   - case 0xbd:
1413   - return ']';
1414   - default:
1415   - return -1;
1416   - }
1417   -}
... ...
src/lib/screenc.h
... ... @@ -13,6 +13,48 @@
13 13  
14 14 /* c3270 version of screenc.h */
15 15  
  16 +
  17 +#pragma pack(1)
  18 +
  19 +#define SCREEN_MAGIC 0x4871
  20 +
  21 +typedef struct _screen_callback
  22 +{
  23 + unsigned short sz;
  24 + unsigned short magic;
  25 +
  26 + void (*screen_init)(void);
  27 + void (*screen_disp)(Boolean erasing unused);
  28 + void (*screen_suspend)(void);
  29 + void (*screen_resume)(void);
  30 +
  31 + void (*cursor_move)(int baddr);
  32 + void (*toggle_monocase)(struct toggle *t unused, enum toggle_type tt unused);
  33 +
  34 + void (*status_ctlr_done)(void);
  35 + void (*status_insert_mode)(Boolean on);
  36 + void (*status_minus)(void);
  37 + void (*status_oerr)(int error_type);
  38 + void (*status_reset)(void);
  39 + void (*status_reverse_mode)(Boolean on);
  40 + void (*status_syswait)(void);
  41 + void (*status_twait)(void);
  42 + void (*status_typeahead)(Boolean on);
  43 + void (*status_compose)(Boolean on, unsigned char c, enum keytype keytype);
  44 + void (*status_lu)(const char *lu);
  45 +
  46 + void (*ring_bell)(void);
  47 + void (*screen_flip)(void);
  48 + void (*screen_width)(int width);
  49 +
  50 + void (*Redraw_action)(Widget w, XEvent *event, String *params, Cardinal *num_params);
  51 +
  52 +} SCREEN_CALLBACK;
  53 +
  54 +#pragma pack()
  55 +
  56 +extern SCREEN_CALLBACK *screen_callbacks_3270;
  57 +
16 58 #define blink_start()
17 59 #define display_heightMM() 100
18 60 #define display_height() 1
... ... @@ -25,17 +67,25 @@
25 67 #define screen_scroll()
26 68  
27 69 extern void cursor_move(int baddr);
  70 +extern void cursor_move(int baddr);
  71 +extern void ring_bell(void);
28 72 extern void ring_bell(void);
29 73 extern void screen_132(void);
  74 +extern void screen_132(void);
  75 +extern void screen_80(void);
30 76 extern void screen_80(void);
31 77 extern void screen_disp(Boolean erasing);
  78 +extern void screen_disp(Boolean erasing);
32 79 extern void screen_init(void);
  80 +extern void screen_init(void);
  81 +extern void screen_flip(void);
33 82 extern void screen_flip(void);
34 83 extern void screen_resume(void);
35 84 extern void screen_suspend(void);
36   -extern FILE *start_pager(void);
37 85 extern void toggle_monocase(struct toggle *t, enum toggle_type tt);
38 86  
  87 +extern FILE *start_pager(void);
  88 +
39 89 extern Boolean escaped;
40 90  
41 91 extern void Escape_action(Widget w, XEvent *event, String *params,
... ...