1 /* LINUX5250
2 * Copyright (C) 2001-2008 Jay 'Eraserhead' Felice
3 *
4 * This file is part of TN5250.
5 *
6 * TN5250 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * TN5250 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /*
22 * This module provides Python language bindings for the 5250 library.
23 */
24
25 #include "tn5250-private.h"
26 #include <Python.h>
27
28 #include <stdlib.h>
29 #include <errno.h>
30
31 typedef struct {
32 PyObject_HEAD
33 Tn5250Config *conf;
34 } Tn5250_Config;
35
36 typedef struct {
37 PyObject_HEAD
38 Tn5250Terminal *term;
39 } Tn5250_Terminal;
40
41 typedef struct {
42 PyObject_HEAD
43 Tn5250Display *display;
44 } Tn5250_Display;
45
46 typedef struct {
47 PyObject_HEAD
48 Tn5250DBuffer *dbuffer;
49 } Tn5250_DisplayBuffer;
50
51 typedef struct {
52 PyObject_HEAD
53 Tn5250Field *field;
54 } Tn5250_Field;
55
56 typedef struct {
57 PyObject_HEAD
58 Tn5250PrintSession *psess;
59 } Tn5250_PrintSession;
60
61 typedef struct {
62 PyObject_HEAD
63 Tn5250Record *rec;
64 } Tn5250_Record;
65
66 staticforward PyTypeObject Tn5250_ConfigType;
67 staticforward PyTypeObject Tn5250_TerminalType;
68 staticforward PyTypeObject Tn5250_DisplayType;
69 staticforward PyTypeObject Tn5250_DisplayBufferType;
70 staticforward PyTypeObject Tn5250_FieldType;
71 staticforward PyTypeObject Tn5250_PrintSessionType;
72 staticforward PyTypeObject Tn5250_RecordType;
73
74 #define Tn5250_ConfigCheck(v) ((v)->ob_type == &Tn5250_ConfigType)
75 #define Tn5250_TerminalCheck(v) ((v)->ob_type == &Tn5250_TerminalType)
76 #define Tn5250_DisplayCheck(v) ((v)->ob_type == &Tn5250_DisplayType)
77 #define Tn5250_DisplayBufferCheck(v)((v)->ob_type == &Tn5250_DisplayBufferType)
78 #define Tn5250_FieldCheck(v) ((v)->ob_type == &Tn5250_FieldType)
79 #define Tn5250_PrintSessionCheck(v) ((v)->ob_type == &Tn5250_PrintSessionType)
80 #define Tn5250_RecordCheck(v) ((v)->ob_type == &Tn5250_RecordType)
81
82 /****************************************************************************/
83 /* Config class */
84 /****************************************************************************/
85
86 static PyObject*
tn5250_Config(func_self,args)87 tn5250_Config (func_self, args)
88 PyObject *func_self;
89 PyObject *args;
90 {
91 Tn5250_Config *self;
92 if (!PyArg_ParseTuple(args, ":Config"))
93 return NULL;
94 self = PyObject_NEW(Tn5250_Config, &Tn5250_ConfigType);
95 if (self == NULL)
96 return NULL;
97
98 self->conf = tn5250_config_new ();
99 return (PyObject*)self;
100 }
101
102 static void
tn5250_Config_dealloc(self)103 tn5250_Config_dealloc (self)
104 Tn5250_Config *self;
105 {
106 if (self->conf != NULL) {
107 tn5250_config_unref (self->conf);
108 self->conf = NULL;
109 }
110 /* PyObject_Del(self); */
111 }
112
113 static PyObject*
tn5250_Config_load(obj,args)114 tn5250_Config_load (obj, args)
115 PyObject *obj;
116 PyObject *args;
117 {
118 char *filename;
119 Tn5250_Config* self = (Tn5250_Config*)obj;
120 if (self == NULL || !Tn5250_ConfigCheck (self))
121 return PyErr_Format(PyExc_TypeError, "self is not a Config object.");
122 if (!PyArg_ParseTuple(args, "s:Config.load", &filename))
123 return NULL;
124 if (tn5250_config_load (self->conf, filename) == -1)
125 return PyErr_Format(PyExc_IOError, "%s: %s", filename,
126 strerror(errno));
127 Py_INCREF(Py_None);
128 return Py_None;
129 }
130
131 static PyObject*
tn5250_Config_load_default(obj,args)132 tn5250_Config_load_default (obj, args)
133 PyObject *obj;
134 PyObject *args;
135 {
136 Tn5250_Config* self = (Tn5250_Config*)obj;
137 if (self == NULL || !Tn5250_ConfigCheck (self))
138 return PyErr_Format(PyExc_TypeError, "self is not a Config object.");
139 if (!PyArg_ParseTuple(args, ":Config.load_default"))
140 return NULL;
141 if (tn5250_config_load_default (self->conf) == -1)
142 return PyErr_Format(PyExc_IOError, "%s", strerror(errno));
143 Py_INCREF(Py_None);
144 return Py_None;
145 }
146
147 static PyObject*
tn5250_Config_parse_argv(obj,args)148 tn5250_Config_parse_argv (obj, args)
149 PyObject* obj;
150 PyObject* args;
151 {
152 Tn5250_Config* self = (Tn5250_Config*)obj;
153 PyObject* list;
154 char **argv;
155 int i, argc, ret;
156
157 if (self == NULL || !Tn5250_ConfigCheck (self))
158 return PyErr_Format(PyExc_TypeError, "Config.parse_argv: self is not a Config object.");
159 if (PyTuple_GET_SIZE(args) != 1)
160 return PyErr_Format(PyExc_TypeError, "Config.parse_argv: expected 2 arguments, got 1.");
161 list = PyTuple_GetItem(args, 0);
162 if (! PyList_Check(list))
163 return PyErr_Format(PyExc_TypeError, "Config.parse_argv: args is not a list.");
164
165 /* Convert to a C-style argv list. */
166 argc = PyList_GET_SIZE(list);
167 argv = (char**)malloc (sizeof (char*)*argc);
168 if (argv == NULL)
169 return PyErr_NoMemory();
170
171 for (i = 0; i < argc; i++) {
172 PyObject* str;
173 char *data;
174 str = PyList_GetItem (list, i);
175 Py_INCREF(str);
176 data = PyString_AsString (str);
177 argv[i] = (char*)malloc (strlen(data)+1);
178
179 if (argv[i] == NULL) {
180 int j;
181 for (j = 0; j < i; j++)
182 free(argv[j]);
183 free(argv);
184 return PyErr_NoMemory ();
185 }
186
187 strcpy (argv[i], data);
188 Py_DECREF(str);
189 }
190
191 ret = tn5250_config_parse_argv (self->conf, argc, argv);
192
193 for (i = 0; i < argc; i++)
194 free (argv[i]);
195 free(argv);
196
197 if (ret == -1)
198 return PyErr_Format(PyExc_IOError, "%s", strerror(errno));
199 Py_INCREF(Py_None);
200 return Py_None;
201 }
202
203 static PyObject*
tn5250_Config_get(obj,args)204 tn5250_Config_get (obj, args)
205 PyObject* obj;
206 PyObject* args;
207 {
208 Tn5250_Config* self = (Tn5250_Config*)obj;
209 char *name;
210 const char *ret;
211
212 if (self == NULL || !Tn5250_ConfigCheck (self))
213 return PyErr_Format(PyExc_TypeError,"Config.get: not a Config object.");
214 if (!PyArg_ParseTuple(args, "s:Config.get", &name))
215 return NULL;
216 ret = tn5250_config_get (self->conf, name);
217 if (ret == NULL) {
218 Py_INCREF(Py_None);
219 return Py_None;
220 }
221 return PyString_FromString (ret);
222 }
223
224 static PyObject*
tn5250_Config_get_bool(obj,args)225 tn5250_Config_get_bool (obj, args)
226 PyObject* obj;
227 PyObject* args;
228 {
229 Tn5250_Config* self = (Tn5250_Config*)obj;
230 char *name;
231
232 if (self == NULL || !Tn5250_ConfigCheck (self))
233 return PyErr_Format(PyExc_TypeError,"Config.get_bool: not a Config object.");
234 if (!PyArg_ParseTuple(args, "s:Config.get_bool", &name))
235 return NULL;
236 if (tn5250_config_get_bool (self->conf, name))
237 return PyInt_FromLong(1);
238 else
239 return PyInt_FromLong(0);
240 }
241
242 static PyObject*
tn5250_Config_get_int(obj,args)243 tn5250_Config_get_int (obj, args)
244 PyObject* obj;
245 PyObject* args;
246 {
247 Tn5250_Config* self = (Tn5250_Config*)obj;
248 char *name;
249 int ret;
250
251 if (self == NULL || !Tn5250_ConfigCheck (self))
252 return PyErr_Format(PyExc_TypeError,"Config.get_int: not a Config object.");
253 if (!PyArg_ParseTuple(args, "s:Config.get_int", &name))
254 return NULL;
255 ret = tn5250_config_get_int (self->conf, name);
256 return PyInt_FromLong((long)ret);
257 }
258
259 static PyObject*
tn5250_Config_set(obj,args)260 tn5250_Config_set (obj, args)
261 PyObject* obj;
262 PyObject* args;
263 {
264 Tn5250_Config* self = (Tn5250_Config*)obj;
265 char *name, *value;
266
267 if (self == NULL || !Tn5250_ConfigCheck (self))
268 return PyErr_Format(PyExc_TypeError,"Config.set: not a Config object.");
269 if (!PyArg_ParseTuple(args, "ss:Config.set", &name, &value))
270 return NULL;
271 /* XXX: We should get rid of list values or something. */
272 tn5250_config_set (self->conf, name, CONFIG_STRING, value);
273 Py_INCREF(Py_None);
274 return Py_None;
275 }
276
277 static PyObject*
tn5250_Config_unset(obj,args)278 tn5250_Config_unset (obj, args)
279 PyObject* obj;
280 PyObject* args;
281 {
282 Tn5250_Config* self = (Tn5250_Config*)obj;
283 char *name;
284
285 if (self == NULL || !Tn5250_ConfigCheck (self))
286 return PyErr_Format(PyExc_TypeError,"Config.unset: not a Config object.");
287 if (!PyArg_ParseTuple(args, "s:Config.unset", &name))
288 return NULL;
289 tn5250_config_unset (self->conf, name);
290 Py_INCREF(Py_None);
291 return Py_None;
292 }
293
294 static PyObject*
tn5250_Config_promote(obj,args)295 tn5250_Config_promote (obj, args)
296 PyObject* obj;
297 PyObject* args;
298 {
299 Tn5250_Config* self = (Tn5250_Config*)obj;
300 char *name;
301
302 if (self == NULL || !Tn5250_ConfigCheck (self))
303 return PyErr_Format(PyExc_TypeError,"Config.promote: not a Config object.");
304 if (!PyArg_ParseTuple(args, "s:Config.get_bool", &name))
305 return NULL;
306 tn5250_config_promote (self->conf, name);
307 Py_INCREF(Py_None);
308 return Py_None;
309 }
310
311 static PyMethodDef Tn5250_ConfigMethods[] = {
312 { "load", tn5250_Config_load, METH_VARARGS },
313 { "load_default", tn5250_Config_load_default, METH_VARARGS },
314 { "parse_argv", tn5250_Config_parse_argv, METH_VARARGS },
315 { "get", tn5250_Config_get, METH_VARARGS },
316 { "get_bool", tn5250_Config_get_bool, METH_VARARGS },
317 { "get_int", tn5250_Config_get_int, METH_VARARGS },
318 { "set", tn5250_Config_set, METH_VARARGS },
319 { "unset", tn5250_Config_unset, METH_VARARGS },
320 { "promote", tn5250_Config_promote, METH_VARARGS },
321 {NULL, NULL}
322 };
323
324 static PyObject*
tn5250_Config_getattr(self,name)325 tn5250_Config_getattr (self, name)
326 Tn5250_Config* self;
327 char *name;
328 {
329 return Py_FindMethod (Tn5250_ConfigMethods, (PyObject*)self, name);
330 }
331
332 statichere PyTypeObject Tn5250_ConfigType = {
333 PyObject_HEAD_INIT(NULL)
334 0, /* ob_size */
335 "Config", /* tp_name */
336 sizeof (Tn5250_Config), /* tp_basicsize */
337 0, /* tp_itemsize */
338 /* methods */
339 (destructor)tn5250_Config_dealloc, /* tp_dealloc */
340 0, /* tp_print */
341 (getattrfunc)tn5250_Config_getattr, /* tp_getattr */
342 0, /* tp_setattr */
343 0, /* tp_compare */
344 0, /* tp_repr */
345 0, /* tp_as_number */
346 0, /* tp_as_sequence */
347 0, /* tp_as_mapping */
348 0, /* tp_hash */
349 };
350
351 /****************************************************************************/
352 /* Terminal class */
353 /****************************************************************************/
354
355 static PyObject*
tn5250_Terminal(obj,args)356 tn5250_Terminal (obj, args)
357 PyObject* obj;
358 PyObject* args;
359 {
360 Tn5250_Terminal* term;
361 if (!PyArg_ParseTuple(args, ":tn5250.Terminal"))
362 return NULL;
363 term = PyObject_NEW(Tn5250_Terminal, &Tn5250_TerminalType);
364 if (term == NULL)
365 return PyErr_NoMemory ();
366
367 term->term = NULL;
368 return (PyObject*)term;
369 }
370
371 static void
tn5250_Terminal_dealloc(self)372 tn5250_Terminal_dealloc (self)
373 Tn5250_Terminal* self;
374 {
375 /* XXX: Okay, we might have a reference counting problem here - what if
376 * the 5250 library is using this? */
377 if (self->term != NULL)
378 tn5250_terminal_destroy(self->term);
379 }
380
381 static PyObject*
tn5250_Terminal_init(obj,args)382 tn5250_Terminal_init (obj, args)
383 PyObject* obj;
384 PyObject* args;
385 {
386 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
387 if (self == NULL || !Tn5250_TerminalCheck (self))
388 return PyErr_Format(PyExc_TypeError,"Terminal.init: not a Terminal object.");
389 if (!PyArg_ParseTuple(args, ":Terminal.init"))
390 return NULL;
391 if (self->term != NULL)
392 tn5250_terminal_init(self->term);
393 Py_INCREF(Py_None);
394 return Py_None;
395 }
396
397 static PyObject*
tn5250_Terminal_term(obj,args)398 tn5250_Terminal_term (obj, args)
399 PyObject* obj;
400 PyObject* args;
401 {
402 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
403 if (self == NULL || !Tn5250_TerminalCheck (self))
404 return PyErr_Format(PyExc_TypeError,"Terminal.term: not a Terminal object.");
405 if (!PyArg_ParseTuple(args, ":Terminal.term"))
406 return NULL;
407 if (self->term != NULL)
408 tn5250_terminal_term(self->term);
409 Py_INCREF(Py_None);
410 return Py_None;
411 }
412
413 static PyObject*
tn5250_Terminal_width(obj,args)414 tn5250_Terminal_width (obj, args)
415 PyObject* obj;
416 PyObject* args;
417 {
418 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
419 if (self == NULL || !Tn5250_TerminalCheck (self))
420 return PyErr_Format(PyExc_TypeError,"Terminal.width: not a Terminal object.");
421 if (!PyArg_ParseTuple(args, ":Terminal.width"))
422 return NULL;
423 if (self->term != NULL)
424 return PyInt_FromLong((long)tn5250_terminal_width (self->term));
425 else {
426 Py_INCREF(Py_None);
427 return Py_None;
428 }
429 }
430
431 static PyObject*
tn5250_Terminal_height(obj,args)432 tn5250_Terminal_height (obj, args)
433 PyObject* obj;
434 PyObject* args;
435 {
436 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
437 if (self == NULL || !Tn5250_TerminalCheck (self))
438 return PyErr_Format(PyExc_TypeError,"Terminal.height: not a Terminal object.");
439 if (!PyArg_ParseTuple(args, ":Terminal.height"))
440 return NULL;
441 if (self->term != NULL)
442 return PyInt_FromLong((long)tn5250_terminal_height (self->term));
443 else {
444 Py_INCREF(Py_None);
445 return Py_None;
446 }
447 }
448
449 static PyObject*
tn5250_Terminal_flags(obj,args)450 tn5250_Terminal_flags (obj, args)
451 PyObject* obj;
452 PyObject* args;
453 {
454 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
455 if (self == NULL || !Tn5250_TerminalCheck (self))
456 return PyErr_Format(PyExc_TypeError,"Terminal.flags: not a Terminal object.");
457 if (!PyArg_ParseTuple(args, ":Terminal.flags"))
458 return NULL;
459 if (self->term != NULL)
460 return PyInt_FromLong((long)tn5250_terminal_flags (self->term));
461 else {
462 Py_INCREF(Py_None);
463 return Py_None;
464 }
465 }
466
467 static PyObject*
tn5250_Terminal_update(obj,args)468 tn5250_Terminal_update (obj, args)
469 PyObject* obj;
470 PyObject* args;
471 {
472 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
473 if (self == NULL || !Tn5250_TerminalCheck (self))
474 return PyErr_Format(PyExc_TypeError,"Terminal.update: not a Terminal object.");
475
476 /* XXX: Implement. */
477
478 Py_INCREF(Py_None);
479 return Py_None;
480 }
481
482 static PyObject*
tn5250_Terminal_update_indicators(obj,args)483 tn5250_Terminal_update_indicators (obj, args)
484 PyObject* obj;
485 PyObject* args;
486 {
487 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
488 if (self == NULL || !Tn5250_TerminalCheck (self))
489 return PyErr_Format(PyExc_TypeError,"Terminal.update_indicators: not a Terminal object.");
490
491 /* XXX: Implement. */
492
493 Py_INCREF(Py_None);
494 return Py_None;
495 }
496
497 static PyObject*
tn5250_Terminal_waitevent(obj,args)498 tn5250_Terminal_waitevent (obj, args)
499 PyObject* obj;
500 PyObject* args;
501 {
502 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
503 if (self == NULL || !Tn5250_TerminalCheck (self))
504 return PyErr_Format(PyExc_TypeError,"Terminal.waitevent: not a Terminal object.");
505 /* XXX: Implement. */
506 Py_INCREF(Py_None);
507 return Py_None;
508 }
509
510 static PyObject*
tn5250_Terminal_getkey(obj,args)511 tn5250_Terminal_getkey (obj, args)
512 PyObject* obj;
513 PyObject* args;
514 {
515 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
516 if (self == NULL || !Tn5250_TerminalCheck (self))
517 return PyErr_Format(PyExc_TypeError,"Terminal.getkey: not a Terminal object.");
518 /* XXX: Implement. */
519 Py_INCREF(Py_None);
520 return Py_None;
521 }
522
523 static PyObject*
tn5250_Terminal_beep(obj,args)524 tn5250_Terminal_beep (obj, args)
525 PyObject* obj;
526 PyObject* args;
527 {
528 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
529 if (self == NULL || !Tn5250_TerminalCheck (self))
530 return PyErr_Format(PyExc_TypeError,"Terminal.beep: not a Terminal object.");
531 if (self->term != NULL)
532 tn5250_terminal_beep (self->term);
533 Py_INCREF(Py_None);
534 return Py_None;
535 }
536
537 static PyObject*
tn5250_Terminal_config(obj,args)538 tn5250_Terminal_config (obj, args)
539 PyObject* obj;
540 PyObject* args;
541 {
542 Tn5250_Terminal* self = (Tn5250_Terminal*)obj;
543 Tn5250_Config* config;
544 PyObject* config_obj;
545 if (self == NULL || !Tn5250_TerminalCheck(obj))
546 return PyErr_Format(PyExc_TypeError,"not a Terminal object.");
547 if (!PyArg_ParseTuple(args, "O!:Terminal.config", &Tn5250_ConfigType, &config))
548 return NULL;
549 if (tn5250_terminal_config (self->term, config->conf) == -1) {
550 /* XXX: Exception. */
551 return NULL;
552 }
553 Py_INCREF(Py_None);
554 return Py_None;
555 }
556
557 static PyMethodDef Tn5250_TerminalMethods[] = {
558 { "init", tn5250_Terminal_init, METH_VARARGS },
559 { "term", tn5250_Terminal_term, METH_VARARGS },
560 { "width", tn5250_Terminal_width, METH_VARARGS },
561 { "height", tn5250_Terminal_height, METH_VARARGS },
562 { "flags", tn5250_Terminal_flags, METH_VARARGS },
563 { "update", tn5250_Terminal_update, METH_VARARGS },
564 { "update_indicators", tn5250_Terminal_update_indicators, METH_VARARGS },
565 { "waitevent", tn5250_Terminal_waitevent, METH_VARARGS },
566 { "getkey", tn5250_Terminal_getkey, METH_VARARGS },
567 { "beep", tn5250_Terminal_beep, METH_VARARGS },
568 { "config", tn5250_Terminal_config, METH_VARARGS },
569 { NULL, NULL}
570 };
571
572 static PyObject*
tn5250_Terminal_getattr(self,name)573 tn5250_Terminal_getattr (self, name)
574 Tn5250_Terminal* self;
575 char *name;
576 {
577 return Py_FindMethod (Tn5250_TerminalMethods, (PyObject*)self, name);
578 }
579
580 statichere PyTypeObject Tn5250_TerminalType = {
581 PyObject_HEAD_INIT(NULL)
582 0, /* ob_size */
583 "Terminal", /* tp_name */
584 sizeof (Tn5250_Terminal), /* tp_basicsize */
585 0, /* tp_itemsize */
586 /* methods */
587 (destructor)tn5250_Terminal_dealloc,/* tp_dealloc */
588 0, /* tp_print */
589 (getattrfunc)tn5250_Terminal_getattr,/* tp_getattr */
590 0, /* tp_setattr */
591 0, /* tp_compare */
592 0, /* tp_repr */
593 0, /* tp_as_number */
594 0, /* tp_as_sequence */
595 0, /* tp_as_mapping */
596 0, /* tp_hash */
597 };
598
599 /****************************************************************************/
600 /* CursesTerminal class */
601 /****************************************************************************/
602
603 #ifdef USE_CURSES
604 static PyObject*
tn5250_CursesTerminal(obj,args)605 tn5250_CursesTerminal (obj, args)
606 PyObject* obj;
607 PyObject* args;
608 {
609 Tn5250_Terminal* term = (Tn5250_Terminal*)tn5250_Terminal (obj, args);
610 if (term == NULL)
611 return NULL;
612
613 term->term = tn5250_curses_terminal_new ();
614 return (PyObject*)term;
615 }
616 #endif /* USE_CURSES */
617
618 /****************************************************************************/
619 /* DebugTerminal class (?) */
620 /****************************************************************************/
621
622 #ifndef NDEBUG
623 static PyObject*
tn5250_DebugTerminal(obj,args)624 tn5250_DebugTerminal (obj, args)
625 PyObject* obj;
626 PyObject* args;
627 {
628 /* XXX: Not implmented. */
629 Py_INCREF(Py_None);
630 return Py_None;
631 }
632 #endif
633
634 /****************************************************************************/
635 /* SlangTerminal class */
636 /****************************************************************************/
637
638 #ifdef USE_SLANG
639 static PyObject*
tn5250_SlangTerminal(obj,args)640 tn5250_SlangTerminal (obj, args)
641 PyObject* obj;
642 PyObject* args;
643 {
644 Tn5250_Terminal* term = (Tn5250_Terminal*)tn5250_Terminal (obj, args);
645 if (term == NULL)
646 return NULL;
647
648 term->term = tn5250_slang_terminal_new ();
649 return (PyObject*)term;
650 }
651 #endif /* USE_SLANG */
652
653 /****************************************************************************/
654 /* GTK+ Terminal class */
655 /****************************************************************************/
656
657 /****************************************************************************/
658 /* DisplayBuffer class */
659 /****************************************************************************/
660
661 static PyObject*
Tn5250_DisplayBuffer_wrap(dbuffer)662 Tn5250_DisplayBuffer_wrap (dbuffer)
663 Tn5250DBuffer* dbuffer;
664 {
665 Tn5250_DisplayBuffer* self;
666
667 if (dbuffer->script_slot != NULL)
668 return (PyObject*)dbuffer->script_slot;
669
670 self = PyObject_NEW(Tn5250_DisplayBuffer, &Tn5250_DisplayBufferType);
671 if (self == NULL) {
672 // XXX: Unreference the display buffer.
673 return NULL;
674 }
675 self->dbuffer = dbuffer;
676 dbuffer->script_slot = self;
677 return (PyObject*)self;
678 }
679
680
681 static PyObject*
tn5250_DisplayBuffer(func_self,args)682 tn5250_DisplayBuffer (func_self, args)
683 PyObject *func_self;
684 PyObject *args;
685 {
686 Tn5250DBuffer* dbuf;
687 int cols = 80, rows = 24;
688 if (!PyArg_ParseTuple(args, "|dd:DisplayBuffer", &rows, &cols))
689 return NULL;
690 dbuf = tn5250_dbuffer_new (rows, cols);
691 if (dbuf == NULL) {
692 /* Strerror */
693 return NULL;
694 }
695 return Tn5250_DisplayBuffer_wrap(dbuf);
696 }
697
698 static void
tn5250_DisplayBuffer_dealloc(self)699 tn5250_DisplayBuffer_dealloc (self)
700 Tn5250_DisplayBuffer* self;
701 {
702 /* XXX: Okay, we might have a reference counting problem here - what if
703 * the 5250 library is using this? */
704 if (self->dbuffer != NULL)
705 tn5250_dbuffer_destroy(self->dbuffer);
706 }
707
708 static PyObject*
tn5250_DisplayBuffer_copy(self,args)709 tn5250_DisplayBuffer_copy (self, args)
710 Tn5250_DisplayBuffer* self;
711 PyObject* args;
712 {
713 Tn5250_DisplayBuffer* newdbuf;
714
715 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
716 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
717 if (!PyArg_ParseTuple(args, ":DisplayBuffer.copy"))
718 return NULL;
719
720 newdbuf = PyObject_NEW(Tn5250_DisplayBuffer, &Tn5250_DisplayBufferType);
721 if (newdbuf == NULL)
722 return NULL;
723
724 newdbuf->dbuffer = tn5250_dbuffer_copy (self->dbuffer);
725 if (newdbuf->dbuffer == NULL) {
726 Py_DECREF(newdbuf);
727 return PyErr_NoMemory ();
728 }
729 return (PyObject*)newdbuf;
730 }
731
732 static PyObject*
tn5250_DisplayBuffer_set_size(self,args)733 tn5250_DisplayBuffer_set_size (self, args)
734 Tn5250_DisplayBuffer* self;
735 PyObject* args;
736 {
737 int cols = 80, rows = 24;
738 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
739 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
740 if (!PyArg_ParseTuple(args, "|dd:DisplayBuffer.set_size", &rows, &cols))
741 return NULL;
742
743 if (self->dbuffer != NULL)
744 tn5250_dbuffer_set_size (self->dbuffer, rows, cols);
745
746 Py_INCREF(Py_None);
747 return Py_None;
748 }
749
750 static PyObject*
tn5250_DisplayBuffer_cursor_set(self,args)751 tn5250_DisplayBuffer_cursor_set (self, args)
752 Tn5250_DisplayBuffer* self;
753 PyObject* args;
754 {
755 int y = 0, x = 0;
756 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
757 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
758 if (!PyArg_ParseTuple(args, "|dd:DisplayBuffer.cursor_set", &y, &x))
759 return NULL;
760
761 if (self->dbuffer != NULL)
762 tn5250_dbuffer_cursor_set (self->dbuffer, y, x);
763
764 Py_INCREF(Py_None);
765 return Py_None;
766 }
767
768 static PyObject*
tn5250_DisplayBuffer_clear(self,args)769 tn5250_DisplayBuffer_clear (self, args)
770 Tn5250_DisplayBuffer* self;
771 PyObject* args;
772 {
773 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
774 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
775 if (!PyArg_ParseTuple(args, ":DisplayBuffer.clear"))
776 return NULL;
777 if (self->dbuffer != NULL)
778 tn5250_dbuffer_clear (self->dbuffer);
779
780 Py_INCREF(Py_None);
781 return Py_None;
782 }
783
784 static PyObject*
tn5250_DisplayBuffer_right(self,args)785 tn5250_DisplayBuffer_right (self, args)
786 Tn5250_DisplayBuffer* self;
787 PyObject* args;
788 {
789 int count = 1;
790 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
791 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
792 if (!PyArg_ParseTuple(args, "|d:DisplayBuffer.right", &count))
793 return NULL;
794 if (self->dbuffer != NULL)
795 tn5250_dbuffer_right (self->dbuffer, count);
796 Py_INCREF(Py_None);
797 return Py_None;
798 }
799
800 static PyObject*
tn5250_DisplayBuffer_left(self,args)801 tn5250_DisplayBuffer_left (self, args)
802 Tn5250_DisplayBuffer* self;
803 PyObject* args;
804 {
805 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
806 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
807 if (!PyArg_ParseTuple(args, ":DisplayBuffer.left"))
808 return NULL;
809 if (self->dbuffer != NULL)
810 tn5250_dbuffer_left(self->dbuffer);
811 Py_INCREF(Py_None);
812 return Py_None;
813 }
814
815 static PyObject*
tn5250_DisplayBuffer_up(self,args)816 tn5250_DisplayBuffer_up (self, args)
817 Tn5250_DisplayBuffer* self;
818 PyObject* args;
819 {
820 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
821 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
822 if (!PyArg_ParseTuple(args, ":DisplayBuffer.up"))
823 return NULL;
824 if (self->dbuffer != NULL)
825 tn5250_dbuffer_up(self->dbuffer);
826 Py_INCREF(Py_None);
827 return Py_None;
828 }
829
830 static PyObject*
tn5250_DisplayBuffer_down(self,args)831 tn5250_DisplayBuffer_down (self, args)
832 Tn5250_DisplayBuffer* self;
833 PyObject* args;
834 {
835 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
836 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
837 if (!PyArg_ParseTuple(args, ":DisplayBuffer.down"))
838 return NULL;
839 if (self->dbuffer != NULL)
840 tn5250_dbuffer_down(self->dbuffer);
841 Py_INCREF(Py_None);
842 return Py_None;
843 }
844
845 static PyObject*
tn5250_DisplayBuffer_goto_ic(self,args)846 tn5250_DisplayBuffer_goto_ic (self, args)
847 Tn5250_DisplayBuffer* self;
848 PyObject* args;
849 {
850 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
851 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
852 if (!PyArg_ParseTuple(args, ":DisplayBuffer.goto_ic"))
853 return NULL;
854 if (self->dbuffer != NULL)
855 tn5250_dbuffer_goto_ic(self->dbuffer);
856 Py_INCREF(Py_None);
857 return Py_None;
858 }
859
860 static PyObject*
tn5250_DisplayBuffer_addch(self,args)861 tn5250_DisplayBuffer_addch (self, args)
862 Tn5250_DisplayBuffer* self;
863 PyObject* args;
864 {
865 unsigned char ch;
866 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
867 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
868 if (!PyArg_ParseTuple(args, "c:DisplayBuffer.addch", &ch))
869 return NULL;
870 if (self->dbuffer != NULL)
871 tn5250_dbuffer_addch (self->dbuffer, ch);
872 Py_INCREF(Py_None);
873 return Py_None;
874 }
875
876 static PyObject*
tn5250_DisplayBuffer_del(self,args)877 tn5250_DisplayBuffer_del (self, args)
878 Tn5250_DisplayBuffer* self;
879 PyObject* args;
880 {
881 int shiftcount;
882 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
883 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
884 if (!PyArg_ParseTuple(args, "d:DisplayBuffer.del", &shiftcount))
885 return NULL;
886 if (self->dbuffer != NULL)
887 tn5250_dbuffer_del (self->dbuffer, shiftcount);
888 Py_INCREF(Py_None);
889 return Py_None;
890 }
891
892 static PyObject*
tn5250_DisplayBuffer_ins(self,args)893 tn5250_DisplayBuffer_ins (self, args)
894 Tn5250_DisplayBuffer* self;
895 PyObject* args;
896 {
897 int shiftcount;
898 unsigned char c;
899 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
900 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
901 if (!PyArg_ParseTuple(args, "cd:DisplayBuffer.ins", &c, &shiftcount))
902 return NULL;
903 if (self->dbuffer != NULL)
904 tn5250_dbuffer_ins (self->dbuffer, c, shiftcount);
905 Py_INCREF(Py_None);
906 return Py_None;
907 }
908
909 static PyObject*
tn5250_DisplayBuffer_set_ic(self,args)910 tn5250_DisplayBuffer_set_ic (self, args)
911 Tn5250_DisplayBuffer* self;
912 PyObject* args;
913 {
914 int x, y;
915 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
916 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
917 if (!PyArg_ParseTuple(args, "dd:DisplayBuffer.set_ic", &x, &y))
918 return NULL;
919 if (self->dbuffer != NULL)
920 tn5250_dbuffer_set_ic (self->dbuffer, x, y);
921 Py_INCREF(Py_None);
922 return Py_None;
923 }
924
925 static PyObject*
tn5250_DisplayBuffer_roll(self,args)926 tn5250_DisplayBuffer_roll (self, args)
927 Tn5250_DisplayBuffer* self;
928 PyObject* args;
929 {
930 int top, bot, lines;
931 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
932 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
933 if (!PyArg_ParseTuple(args, "ddd:DisplayBuffer.roll", &top, &bot, &lines))
934 return NULL;
935 if (self->dbuffer != NULL)
936 tn5250_dbuffer_roll (self->dbuffer, top, bot, lines);
937 Py_INCREF(Py_None);
938 return Py_None;
939 }
940
941 static PyObject*
tn5250_DisplayBuffer_char_at(self,args)942 tn5250_DisplayBuffer_char_at (self, args)
943 Tn5250_DisplayBuffer* self;
944 PyObject* args;
945 {
946 int y, x;
947 unsigned char c;
948 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
949 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
950 if (!PyArg_ParseTuple(args, "dd:DisplayBuffer.char_at", &y, &x))
951 return NULL;
952 c = 0;
953 if (self->dbuffer != NULL)
954 c = tn5250_dbuffer_char_at (self->dbuffer, y, x);
955 return Py_BuildValue("c", c);
956 }
957
958 static PyObject*
tn5250_DisplayBuffer_width(self,args)959 tn5250_DisplayBuffer_width (self, args)
960 Tn5250_DisplayBuffer* self;
961 PyObject* args;
962 {
963 int wid;
964 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
965 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
966 if (!PyArg_ParseTuple(args, ":DisplayBuffer.width"))
967 return NULL;
968 wid = 0;
969 if (self->dbuffer != NULL)
970 wid = tn5250_dbuffer_width (self->dbuffer);
971 return Py_BuildValue("d", wid);
972 }
973
974 static PyObject*
tn5250_DisplayBuffer_height(self,args)975 tn5250_DisplayBuffer_height (self, args)
976 Tn5250_DisplayBuffer* self;
977 PyObject* args;
978 {
979 int wid;
980 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
981 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
982 if (!PyArg_ParseTuple(args, ":DisplayBuffer.height"))
983 return NULL;
984 wid = 0;
985 if (self->dbuffer != NULL)
986 wid = tn5250_dbuffer_height (self->dbuffer);
987 return Py_BuildValue("d", wid);
988 }
989
990 static PyObject*
tn5250_DisplayBuffer_cursor_x(self,args)991 tn5250_DisplayBuffer_cursor_x (self, args)
992 Tn5250_DisplayBuffer* self;
993 PyObject* args;
994 {
995 int wid;
996 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
997 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
998 if (!PyArg_ParseTuple(args, ":DisplayBuffer.cursor_x"))
999 return NULL;
1000 wid = 0;
1001 if (self->dbuffer != NULL)
1002 wid = tn5250_dbuffer_cursor_x (self->dbuffer);
1003 return Py_BuildValue("d", wid);
1004 }
1005
1006 static PyObject*
tn5250_DisplayBuffer_cursor_y(self,args)1007 tn5250_DisplayBuffer_cursor_y (self, args)
1008 Tn5250_DisplayBuffer* self;
1009 PyObject* args;
1010 {
1011 int wid;
1012 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1013 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1014 if (!PyArg_ParseTuple(args, ":DisplayBuffer.cursor_y"))
1015 return NULL;
1016 wid = 0;
1017 if (self->dbuffer != NULL)
1018 wid = tn5250_dbuffer_cursor_y (self->dbuffer);
1019 return Py_BuildValue("d", wid);
1020 }
1021
1022 static PyObject*
tn5250_DisplayBuffer_add_field(self,args)1023 tn5250_DisplayBuffer_add_field (self, args)
1024 Tn5250_DisplayBuffer* self;
1025 PyObject* args;
1026 {
1027 /* XXX: Implement. */
1028 Py_INCREF(Py_None);
1029 return Py_None;
1030 }
1031
1032 static PyObject*
tn5250_DisplayBuffer_clear_table(self,args)1033 tn5250_DisplayBuffer_clear_table (self, args)
1034 Tn5250_DisplayBuffer* self;
1035 PyObject* args;
1036 {
1037 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1038 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1039 if (!PyArg_ParseTuple(args, ":DisplayBuffer.clear_table"))
1040 return NULL;
1041 if (self->dbuffer != NULL)
1042 tn5250_dbuffer_clear_table(self->dbuffer);
1043 Py_INCREF(Py_None);
1044 return Py_None;
1045 }
1046
1047 static PyObject*
tn5250_DisplayBuffer_field_yx(self,args)1048 tn5250_DisplayBuffer_field_yx (self, args)
1049 Tn5250_DisplayBuffer* self;
1050 PyObject* args;
1051 {
1052 /* XXX: Implement */
1053 Py_INCREF(Py_None);
1054 return Py_None;
1055 }
1056
1057 static PyObject*
tn5250_DisplayBuffer_set_header_data(self,args)1058 tn5250_DisplayBuffer_set_header_data (self, args)
1059 Tn5250_DisplayBuffer* self;
1060 PyObject* args;
1061 {
1062 unsigned char *ptr;
1063 int len;
1064 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1065 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1066 if (!PyArg_ParseTuple(args, "s#:DisplayBuffer.set_header_data", &ptr, &len))
1067 return NULL;
1068 if (self->dbuffer != NULL)
1069 tn5250_dbuffer_set_header_data (self->dbuffer, ptr, len);
1070 Py_INCREF(Py_None);
1071 return Py_None;
1072 }
1073
1074 static PyObject*
tn5250_DisplayBuffer_send_data_for_aid_key(self,args)1075 tn5250_DisplayBuffer_send_data_for_aid_key (self, args)
1076 Tn5250_DisplayBuffer* self;
1077 PyObject* args;
1078 {
1079 int k = 0;
1080 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1081 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1082 if (!PyArg_ParseTuple(args, "d:DisplayBuffer.send_data_for_aid_key", &k))
1083 return NULL;
1084 if (self->dbuffer != NULL) {
1085 k = tn5250_dbuffer_send_data_for_aid_key (self->dbuffer, k);
1086 }
1087 return PyInt_FromLong((long)k);
1088 }
1089
1090 static PyObject*
tn5250_DisplayBuffer_field_data(self,args)1091 tn5250_DisplayBuffer_field_data (self, args)
1092 Tn5250_DisplayBuffer* self;
1093 PyObject* args;
1094 {
1095 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1096 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1097 if (!PyArg_ParseTuple(args, ":DisplayBuffer.field_data"))
1098 return NULL;
1099 if (self->dbuffer != NULL) {
1100 // XXX: Implement
1101 // ptr = tn5250_dbuffer_field_data (self->dbuffer);
1102 }
1103 Py_INCREF(Py_None);
1104 return Py_None;
1105 }
1106
1107 static PyObject*
tn5250_DisplayBuffer_msg_line(self,args)1108 tn5250_DisplayBuffer_msg_line (self, args)
1109 Tn5250_DisplayBuffer* self;
1110 PyObject* args;
1111 {
1112 int ml;
1113 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1114 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1115 if (!PyArg_ParseTuple(args, ":DisplayBuffer.msg_line"))
1116 return NULL;
1117 if (self->dbuffer != NULL)
1118 ml = tn5250_dbuffer_msg_line(self->dbuffer);
1119 return PyInt_FromLong((long)ml);
1120 }
1121
1122 static PyObject*
tn5250_DisplayBuffer_first_non_bypass(self,args)1123 tn5250_DisplayBuffer_first_non_bypass (self, args)
1124 Tn5250_DisplayBuffer* self;
1125 PyObject* args;
1126 {
1127 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1128 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1129 if (!PyArg_ParseTuple(args, ":DisplayBuffer.first_non_bypass"))
1130 return NULL;
1131 // XXX: Implement
1132 Py_INCREF(Py_None);
1133 return Py_None;
1134 }
1135
1136 static PyObject*
tn5250_DisplayBuffer_field_count(self,args)1137 tn5250_DisplayBuffer_field_count (self, args)
1138 Tn5250_DisplayBuffer* self;
1139 PyObject* args;
1140 {
1141 int c;
1142 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1143 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1144 if (!PyArg_ParseTuple(args, ":DisplayBuffer.field_count"))
1145 return NULL;
1146 if (self->dbuffer != NULL)
1147 c = tn5250_dbuffer_field_count (self->dbuffer);
1148 return PyInt_FromLong((long)c);
1149 }
1150
1151 static PyObject*
tn5250_DisplayBuffer_mdt(self,args)1152 tn5250_DisplayBuffer_mdt (self, args)
1153 Tn5250_DisplayBuffer* self;
1154 PyObject* args;
1155 {
1156 int mdt;
1157 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1158 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1159 if (!PyArg_ParseTuple(args, ":DisplayBuffer.mdt"))
1160 return NULL;
1161 if (self->dbuffer != NULL)
1162 mdt = tn5250_dbuffer_mdt(self->dbuffer);
1163 return PyInt_FromLong((long)mdt);
1164 }
1165
1166 static PyObject*
tn5250_DisplayBuffer_set_mdt(self,args)1167 tn5250_DisplayBuffer_set_mdt (self, args)
1168 Tn5250_DisplayBuffer* self;
1169 PyObject* args;
1170 {
1171 if (self == NULL || !Tn5250_DisplayBufferCheck (self))
1172 return PyErr_Format(PyExc_TypeError, "not a DisplayBuffer.");
1173 if (!PyArg_ParseTuple(args, ":DisplayBuffer.set_mdt"))
1174 return NULL;
1175 if (self->dbuffer != NULL)
1176 tn5250_dbuffer_set_mdt (self->dbuffer);
1177 Py_INCREF(Py_None);
1178 return Py_None;
1179 }
1180
1181
1182 static PyMethodDef Tn5250_DisplayBufferMethods[] = {
1183 { "copy", tn5250_DisplayBuffer_copy, METH_VARARGS },
1184 { "set_size", tn5250_DisplayBuffer_set_size, METH_VARARGS },
1185 { "cursor_set", tn5250_DisplayBuffer_cursor_set, METH_VARARGS },
1186 { "clear", tn5250_DisplayBuffer_clear, METH_VARARGS },
1187 { "right", tn5250_DisplayBuffer_right, METH_VARARGS },
1188 { "left", tn5250_DisplayBuffer_left, METH_VARARGS },
1189 { "up", tn5250_DisplayBuffer_up, METH_VARARGS },
1190 { "down", tn5250_DisplayBuffer_down, METH_VARARGS },
1191 { "goto_ic", tn5250_DisplayBuffer_goto_ic, METH_VARARGS },
1192 { "addch", tn5250_DisplayBuffer_addch, METH_VARARGS },
1193 { "del", tn5250_DisplayBuffer_del, METH_VARARGS },
1194 { "ins", tn5250_DisplayBuffer_ins, METH_VARARGS },
1195 { "set_ic", tn5250_DisplayBuffer_set_ic, METH_VARARGS },
1196 { "roll", tn5250_DisplayBuffer_roll, METH_VARARGS },
1197 { "char_at", tn5250_DisplayBuffer_char_at, METH_VARARGS },
1198 { "width", tn5250_DisplayBuffer_width, METH_VARARGS },
1199 { "height", tn5250_DisplayBuffer_height, METH_VARARGS },
1200 { "cursor_x", tn5250_DisplayBuffer_cursor_x, METH_VARARGS },
1201 { "cursor_y", tn5250_DisplayBuffer_cursor_y, METH_VARARGS },
1202 { "add_field", tn5250_DisplayBuffer_add_field, METH_VARARGS },
1203 { "clear_table", tn5250_DisplayBuffer_clear_table, METH_VARARGS },
1204 { "field_yx", tn5250_DisplayBuffer_field_yx, METH_VARARGS },
1205 { "set_header_data",tn5250_DisplayBuffer_set_header_data,METH_VARARGS },
1206 { "send_data_for_aid_key",tn5250_DisplayBuffer_send_data_for_aid_key,METH_VARARGS },
1207 { "field_data", tn5250_DisplayBuffer_field_data, METH_VARARGS },
1208 { "msg_line", tn5250_DisplayBuffer_msg_line, METH_VARARGS },
1209 { "first_non_bypass",tn5250_DisplayBuffer_first_non_bypass,METH_VARARGS },
1210 { "field_count", tn5250_DisplayBuffer_field_count, METH_VARARGS },
1211 { "mdt", tn5250_DisplayBuffer_mdt, METH_VARARGS },
1212 { "set_mdt", tn5250_DisplayBuffer_set_mdt, METH_VARARGS },
1213 { NULL, NULL }
1214 };
1215
1216 static PyObject*
tn5250_DisplayBuffer_getattr(self,name)1217 tn5250_DisplayBuffer_getattr (self, name)
1218 Tn5250_DisplayBuffer* self;
1219 char *name;
1220 {
1221 return Py_FindMethod (Tn5250_DisplayBufferMethods, (PyObject*)self, name);
1222 }
1223
1224 statichere PyTypeObject Tn5250_DisplayBufferType = {
1225 PyObject_HEAD_INIT(NULL)
1226 0, /* ob_size */
1227 "DisplayBuffer", /* tp_name */
1228 sizeof (Tn5250_DisplayBuffer), /* tp_basicsize */
1229 0, /* tp_itemsize */
1230 /* methods */
1231 (destructor)tn5250_DisplayBuffer_dealloc,/* tp_dealloc */
1232 0, /* tp_print */
1233 (getattrfunc)tn5250_DisplayBuffer_getattr,/* tp_getattr */
1234 0, /* tp_setattr */
1235 0, /* tp_compare */
1236 0, /* tp_repr */
1237 0, /* tp_as_number */
1238 0, /* tp_as_sequence */
1239 0, /* tp_as_mapping */
1240 0, /* tp_hash */
1241 };
1242
1243 /****************************************************************************/
1244 /* Display class */
1245 /****************************************************************************/
1246
1247 static PyObject*
tn5250_Display(func_self,args)1248 tn5250_Display (func_self, args)
1249 PyObject* func_self;
1250 PyObject* args;
1251 {
1252 Tn5250_Display *self;
1253 int cols = 80, rows = 24;
1254 if (!PyArg_ParseTuple(args, ":Display"))
1255 return NULL;
1256 self = PyObject_NEW(Tn5250_Display, &Tn5250_DisplayType);
1257 if (self == NULL)
1258 return NULL;
1259
1260 self->display = tn5250_display_new ();
1261 return (PyObject*)self;
1262 }
1263
1264 static void
tn5250_Display_dealloc(self)1265 tn5250_Display_dealloc (self)
1266 Tn5250_Display* self;
1267 {
1268 // XXX: Reference counting problems.
1269 if (self->display != NULL)
1270 tn5250_display_destroy (self->display);
1271 }
1272
1273 static PyObject*
tn5250_Display_config(self,args)1274 tn5250_Display_config (self, args)
1275 Tn5250_Display* self;
1276 PyObject* args;
1277 {
1278 Tn5250_Config* config;
1279 if (self == NULL || !Tn5250_DisplayCheck (self))
1280 return PyErr_Format(PyExc_TypeError, "not a Display.");
1281 if (!PyArg_ParseTuple(args, "O!:Display.config", &Tn5250_ConfigType, &config))
1282 return NULL;
1283 if (tn5250_display_config (self->display, config->conf) == -1) {
1284 /* XXX: Exception. */
1285 return NULL;
1286 }
1287 Py_INCREF(Py_None);
1288 return Py_None;
1289 }
1290
1291 static PyObject*
tn5250_Display_set_session(self,args)1292 tn5250_Display_set_session (self, args)
1293 Tn5250_Display* self;
1294 PyObject* args;
1295 {
1296 if (self == NULL || !Tn5250_DisplayCheck (self))
1297 return PyErr_Format(PyExc_TypeError, "not a Display.");
1298 if (!PyArg_ParseTuple(args, ":Display.set_session"))
1299 return NULL;
1300 // XXX: Implement
1301 Py_INCREF(Py_None);
1302 return Py_None;
1303 }
1304
1305 static PyObject*
tn5250_Display_push_dbuffer(self,args)1306 tn5250_Display_push_dbuffer (self, args)
1307 Tn5250_Display* self;
1308 PyObject* args;
1309 {
1310 Tn5250DBuffer* dbuffer;
1311 if (self == NULL || !Tn5250_DisplayCheck (self))
1312 return PyErr_Format(PyExc_TypeError, "not a Display.");
1313 if (!PyArg_ParseTuple(args, ":Display.push_dbuffer"))
1314 return NULL;
1315 dbuffer = tn5250_display_push_dbuffer(self->display);
1316 if (dbuffer == NULL) {
1317 // XXX: Strerror message
1318 return NULL;
1319 }
1320 return Tn5250_DisplayBuffer_wrap(dbuffer);
1321 }
1322
1323 static PyObject*
tn5250_Display_restore_dbuffer(self,args)1324 tn5250_Display_restore_dbuffer (self, args)
1325 Tn5250_Display* self;
1326 PyObject* args;
1327 {
1328 Tn5250_DisplayBuffer* dbuf;
1329 if (self == NULL || !Tn5250_DisplayCheck (self))
1330 return PyErr_Format(PyExc_TypeError, "not a Display.");
1331 if (!PyArg_ParseTuple(args, "O!:Display.restore_dbuffer", &Tn5250_DisplayBufferType, &dbuf))
1332 return NULL;
1333 if (self->display != NULL && dbuf->dbuffer != NULL)
1334 tn5250_display_restore_dbuffer (self->display, dbuf->dbuffer);
1335 Py_INCREF(Py_None);
1336 return Py_None;
1337 }
1338
1339 static PyObject*
tn5250_Display_set_terminal(self,args)1340 tn5250_Display_set_terminal (self, args)
1341 Tn5250_Display* self;
1342 PyObject* args;
1343 {
1344 Tn5250_Terminal *term;
1345 if (self == NULL || !Tn5250_DisplayCheck (self))
1346 return PyErr_Format(PyExc_TypeError, "not a Display.");
1347 if (!PyArg_ParseTuple(args, "O!:Display.set_terminal", &Tn5250_TerminalType, &term))
1348 return NULL;
1349 if (self->display != NULL && term->term != NULL)
1350 tn5250_display_set_terminal (self->display, term->term);
1351 Py_INCREF(Py_None);
1352 return Py_None;
1353 }
1354
1355 static PyObject*
tn5250_Display_update(self,args)1356 tn5250_Display_update (self, args)
1357 Tn5250_Display* self;
1358 PyObject* args;
1359 {
1360 if (self == NULL || !Tn5250_DisplayCheck (self))
1361 return PyErr_Format(PyExc_TypeError, "not a Display.");
1362 if (!PyArg_ParseTuple(args, ":Display.update"))
1363 return NULL;
1364 if (self->display != NULL)
1365 tn5250_display_update (self->display);
1366 Py_INCREF(Py_None);
1367 return Py_None;
1368 }
1369
1370 static PyObject*
tn5250_Display_waitevent(self,args)1371 tn5250_Display_waitevent (self, args)
1372 Tn5250_Display* self;
1373 PyObject* args;
1374 {
1375 int ret;
1376 if (self == NULL || !Tn5250_DisplayCheck (self))
1377 return PyErr_Format(PyExc_TypeError, "not a Display.");
1378 if (!PyArg_ParseTuple(args, ":Display.waitevent"))
1379 return NULL;
1380 ret = 0;
1381 if (self->display != NULL)
1382 ret = tn5250_display_waitevent (self->display);
1383 return PyInt_FromLong((long)ret);
1384 }
1385
1386 static PyObject*
tn5250_Display_getkey(self,args)1387 tn5250_Display_getkey (self, args)
1388 Tn5250_Display* self;
1389 PyObject* args;
1390 {
1391 int key;
1392 if (self == NULL || !Tn5250_DisplayCheck (self))
1393 return PyErr_Format(PyExc_TypeError, "not a Display.");
1394 if (!PyArg_ParseTuple(args, ":Display.getkey"))
1395 return NULL;
1396 key = -1;
1397 if (self->display != NULL)
1398 key = tn5250_display_getkey (self->display);
1399 return PyInt_FromLong((long)key);
1400 }
1401
1402 static PyObject*
tn5250_Display_field_at(self,args)1403 tn5250_Display_field_at (self, args)
1404 Tn5250_Display* self;
1405 PyObject* args;
1406 {
1407 int y, x;
1408 if (self == NULL || !Tn5250_DisplayCheck (self))
1409 return PyErr_Format(PyExc_TypeError, "not a Display.");
1410 if (!PyArg_ParseTuple(args, "dd:Display.field_at", &y, &x))
1411 return NULL;
1412 // XXX: Implement
1413 Py_INCREF(Py_None);
1414 return Py_None;
1415 }
1416
1417 static PyObject*
tn5250_Display_current_field(self,args)1418 tn5250_Display_current_field (self, args)
1419 Tn5250_Display* self;
1420 PyObject* args;
1421 {
1422 if (self == NULL || !Tn5250_DisplayCheck (self))
1423 return PyErr_Format(PyExc_TypeError, "not a Display.");
1424 if (!PyArg_ParseTuple(args, ":Display.current_field"))
1425 return NULL;
1426 // XXX: Implement
1427 Py_INCREF(Py_None);
1428 return Py_None;
1429 }
1430
1431 static PyObject*
tn5250_Display_next_field(self,args)1432 tn5250_Display_next_field (self, args)
1433 Tn5250_Display* self;
1434 PyObject* args;
1435 {
1436 if (self == NULL || !Tn5250_DisplayCheck (self))
1437 return PyErr_Format(PyExc_TypeError, "not a Display.");
1438 if (!PyArg_ParseTuple(args, ":Display.next_field"))
1439 return NULL;
1440 // XXX: Implement
1441 Py_INCREF(Py_None);
1442 return Py_None;
1443 }
1444
1445 static PyObject*
tn5250_Display_prev_field(self,args)1446 tn5250_Display_prev_field (self, args)
1447 Tn5250_Display* self;
1448 PyObject* args;
1449 {
1450 if (self == NULL || !Tn5250_DisplayCheck (self))
1451 return PyErr_Format(PyExc_TypeError, "not a Display.");
1452 if (!PyArg_ParseTuple(args, ":Display.prev_field"))
1453 return NULL;
1454 // XXX: Implement
1455 Py_INCREF(Py_None);
1456 return Py_None;
1457 }
1458
1459 static PyObject*
tn5250_Display_set_cursor_field(self,args)1460 tn5250_Display_set_cursor_field (self, args)
1461 Tn5250_Display* self;
1462 PyObject* args;
1463 {
1464 if (self == NULL || !Tn5250_DisplayCheck (self))
1465 return PyErr_Format(PyExc_TypeError, "not a Display.");
1466 if (!PyArg_ParseTuple(args, ":Display.set_cursor_field"))
1467 return NULL;
1468 // XXX: Implement
1469 Py_INCREF(Py_None);
1470 return Py_None;
1471 }
1472
1473 static PyObject*
tn5250_Display_set_cursor_home(self,args)1474 tn5250_Display_set_cursor_home (self, args)
1475 Tn5250_Display* self;
1476 PyObject* args;
1477 {
1478 if (self == NULL || !Tn5250_DisplayCheck (self))
1479 return PyErr_Format(PyExc_TypeError, "not a Display.");
1480 if (!PyArg_ParseTuple(args, ":Display.set_cursor_home"))
1481 return NULL;
1482 if (self->display != NULL)
1483 tn5250_display_set_cursor_home (self->display);
1484 Py_INCREF(Py_None);
1485 return Py_None;
1486 }
1487
1488 static PyObject*
tn5250_Display_set_cursor_next_field(self,args)1489 tn5250_Display_set_cursor_next_field (self, args)
1490 Tn5250_Display* self;
1491 PyObject* args;
1492 {
1493 if (self == NULL || !Tn5250_DisplayCheck (self))
1494 return PyErr_Format(PyExc_TypeError, "not a Display.");
1495 if (!PyArg_ParseTuple(args, ":Display.set_cursor_next_field"))
1496 return NULL;
1497 if (self->display != NULL)
1498 tn5250_display_set_cursor_next_field (self->display);
1499 Py_INCREF(Py_None);
1500 return Py_None;
1501 }
1502
1503 static PyObject*
tn5250_Display_set_cursor_prev_field(self,args)1504 tn5250_Display_set_cursor_prev_field (self, args)
1505 Tn5250_Display* self;
1506 PyObject* args;
1507 {
1508 if (self == NULL || !Tn5250_DisplayCheck (self))
1509 return PyErr_Format(PyExc_TypeError, "not a Display.");
1510 if (!PyArg_ParseTuple(args, ":Display.set_cursor_prev_field"))
1511 return NULL;
1512 if (self->display != NULL)
1513 tn5250_display_set_cursor_prev_field (self->display);
1514 Py_INCREF(Py_None);
1515 return Py_None;
1516 }
1517
1518 static PyObject*
tn5250_Display_shift_right(self,args)1519 tn5250_Display_shift_right (self, args)
1520 Tn5250_Display* self;
1521 PyObject* args;
1522 {
1523 if (self == NULL || !Tn5250_DisplayCheck (self))
1524 return PyErr_Format(PyExc_TypeError, "not a Display.");
1525 if (!PyArg_ParseTuple(args, ":Display.shift_right"))
1526 return NULL;
1527 // XXX: Implement
1528 Py_INCREF(Py_None);
1529 return Py_None;
1530 }
1531
1532 static PyObject*
tn5250_Display_field_adjust(self,args)1533 tn5250_Display_field_adjust (self, args)
1534 Tn5250_Display* self;
1535 PyObject* args;
1536 {
1537 if (self == NULL || !Tn5250_DisplayCheck (self))
1538 return PyErr_Format(PyExc_TypeError, "not a Display.");
1539 if (!PyArg_ParseTuple(args, ":Display.field_adjust"))
1540 return NULL;
1541 // XXX: Implement
1542 Py_INCREF(Py_None);
1543 return Py_None;
1544 }
1545
1546 static PyObject*
tn5250_Display_interactive_addch(self,args)1547 tn5250_Display_interactive_addch (self, args)
1548 Tn5250_Display* self;
1549 PyObject* args;
1550 {
1551 unsigned char ch;
1552 if (self == NULL || !Tn5250_DisplayCheck (self))
1553 return PyErr_Format(PyExc_TypeError, "not a Display.");
1554 if (!PyArg_ParseTuple(args, "c:Display.interactive_addch", &ch))
1555 return NULL;
1556 if (self->display != NULL)
1557 tn5250_display_interactive_addch (self->display, ch);
1558 Py_INCREF(Py_None);
1559 return Py_None;
1560 }
1561
1562 static PyObject*
tn5250_Display_beep(self,args)1563 tn5250_Display_beep (self, args)
1564 Tn5250_Display* self;
1565 PyObject* args;
1566 {
1567 if (self == NULL || !Tn5250_DisplayCheck (self))
1568 return PyErr_Format(PyExc_TypeError, "not a Display.");
1569 if (!PyArg_ParseTuple(args, ":Display.beep"))
1570 return NULL;
1571 if (self->display != NULL)
1572 tn5250_display_beep (self->display);
1573 Py_INCREF(Py_None);
1574 return Py_None;
1575 }
1576
1577 static PyObject*
tn5250_Display_do_aidkey(self,args)1578 tn5250_Display_do_aidkey (self, args)
1579 Tn5250_Display* self;
1580 PyObject* args;
1581 {
1582 int aidcode;
1583 if (self == NULL || !Tn5250_DisplayCheck (self))
1584 return PyErr_Format(PyExc_TypeError, "not a Display.");
1585 if (!PyArg_ParseTuple(args, "d:Display.do_aidkey", &aidcode))
1586 return NULL;
1587 if (self->display != NULL)
1588 tn5250_display_do_aidkey (self->display, aidcode);
1589 Py_INCREF(Py_None);
1590 return Py_None;
1591 }
1592
1593 static PyObject*
tn5250_Display_indicator_set(self,args)1594 tn5250_Display_indicator_set (self, args)
1595 Tn5250_Display* self;
1596 PyObject* args;
1597 {
1598 int inds;
1599 if (self == NULL || !Tn5250_DisplayCheck (self))
1600 return PyErr_Format(PyExc_TypeError, "not a Display.");
1601 if (!PyArg_ParseTuple(args, "d:Display.indicator_set", &inds))
1602 return NULL;
1603 if (self->display != NULL)
1604 tn5250_display_indicator_set (self->display, inds);
1605 Py_INCREF(Py_None);
1606 return Py_None;
1607 }
1608
1609 static PyObject*
tn5250_Display_indicator_clear(self,args)1610 tn5250_Display_indicator_clear (self, args)
1611 Tn5250_Display* self;
1612 PyObject* args;
1613 {
1614 int inds;
1615 if (self == NULL || !Tn5250_DisplayCheck (self))
1616 return PyErr_Format(PyExc_TypeError, "not a Display.");
1617 if (!PyArg_ParseTuple(args, "d:Display.indicator_clear", &inds))
1618 return NULL;
1619 if (self->display != NULL)
1620 tn5250_display_indicator_clear (self->display, inds);
1621 Py_INCREF(Py_None);
1622 return Py_None;
1623 }
1624
1625 static PyObject*
tn5250_Display_clear_unit(self,args)1626 tn5250_Display_clear_unit (self, args)
1627 Tn5250_Display* self;
1628 PyObject* args;
1629 {
1630 if (self == NULL || !Tn5250_DisplayCheck (self))
1631 return PyErr_Format(PyExc_TypeError, "not a Display.");
1632 if (!PyArg_ParseTuple(args, ":Display.clear_unit"))
1633 return NULL;
1634 if (self->display != NULL)
1635 tn5250_display_clear_unit (self->display);
1636 Py_INCREF(Py_None);
1637 return Py_None;
1638 }
1639
1640 static PyObject*
tn5250_Display_clear_unit_alternate(self,args)1641 tn5250_Display_clear_unit_alternate (self, args)
1642 Tn5250_Display* self;
1643 PyObject* args;
1644 {
1645 if (self == NULL || !Tn5250_DisplayCheck (self))
1646 return PyErr_Format(PyExc_TypeError, "not a Display.");
1647 if (!PyArg_ParseTuple(args, ":Display.clear_unit_alternate"))
1648 return NULL;
1649 if (self->display != NULL)
1650 tn5250_display_clear_unit_alternate (self->display);
1651 Py_INCREF(Py_None);
1652 return Py_None;
1653 }
1654
1655 static PyObject*
tn5250_Display_clear_format_table(self,args)1656 tn5250_Display_clear_format_table (self, args)
1657 Tn5250_Display* self;
1658 PyObject* args;
1659 {
1660 if (self == NULL || !Tn5250_DisplayCheck (self))
1661 return PyErr_Format(PyExc_TypeError, "not a Display.");
1662 if (!PyArg_ParseTuple(args, ":Display.clear_format_table"))
1663 return NULL;
1664 if (self->display != NULL)
1665 tn5250_display_clear_format_table (self->display);
1666 Py_INCREF(Py_None);
1667 return Py_None;
1668 }
1669
1670 static PyObject*
tn5250_Display_set_pending_insert(self,args)1671 tn5250_Display_set_pending_insert (self, args)
1672 Tn5250_Display* self;
1673 PyObject* args;
1674 {
1675 int y, x;
1676 if (self == NULL || !Tn5250_DisplayCheck (self))
1677 return PyErr_Format(PyExc_TypeError, "not a Display.");
1678 if (!PyArg_ParseTuple(args, "dd:Display.set_pending_insert", &y, &x))
1679 return NULL;
1680 if (self->display != NULL)
1681 tn5250_display_set_pending_insert (self->display, y, x);
1682 Py_INCREF(Py_None);
1683 return Py_None;
1684 }
1685
1686 static PyObject*
tn5250_Display_make_wtd_data(self,args)1687 tn5250_Display_make_wtd_data (self, args)
1688 Tn5250_Display* self;
1689 PyObject* args;
1690 {
1691 Tn5250Buffer buf;
1692 Tn5250_DisplayBuffer *dbuf = NULL;
1693 PyObject* ret;
1694
1695 if (self == NULL || !Tn5250_DisplayCheck (self))
1696 return PyErr_Format(PyExc_TypeError, "not a Display.");
1697 if (!PyArg_ParseTuple(args, "|O!:Display.make_wtd_data", &Tn5250_DisplayBufferType, &dbuf))
1698 return NULL;
1699 tn5250_buffer_init (&buf);
1700
1701 tn5250_display_make_wtd_data (self->display, &buf, dbuf ? dbuf->dbuffer : NULL);
1702 ret = Py_BuildValue("s#", tn5250_buffer_data(&buf), tn5250_buffer_length(&buf));
1703 tn5250_buffer_free(&buf);
1704 return ret;
1705 }
1706
1707 static PyObject*
tn5250_Display_save_msg_line(self,args)1708 tn5250_Display_save_msg_line (self, args)
1709 Tn5250_Display* self;
1710 PyObject* args;
1711 {
1712 if (self == NULL || !Tn5250_DisplayCheck (self))
1713 return PyErr_Format(PyExc_TypeError, "not a Display.");
1714 if (!PyArg_ParseTuple(args, ":Display.save_msg_line"))
1715 return NULL;
1716 if (self->display != NULL)
1717 tn5250_display_save_msg_line (self->display);
1718 Py_INCREF(Py_None);
1719 return Py_None;
1720 }
1721
1722 static PyObject*
tn5250_Display_set_char_map(self,args)1723 tn5250_Display_set_char_map (self, args)
1724 Tn5250_Display* self;
1725 PyObject* args;
1726 {
1727 char *mapname;
1728 if (self == NULL || !Tn5250_DisplayCheck (self))
1729 return PyErr_Format(PyExc_TypeError, "not a Display.");
1730 if (!PyArg_ParseTuple(args, "s:Display.set_char_map", &mapname))
1731 return NULL;
1732 if (self->display != NULL)
1733 tn5250_display_set_char_map (self->display, mapname);
1734 Py_INCREF(Py_None);
1735 return Py_None;
1736 }
1737
1738 static PyObject*
tn5250_Display_do_keys(self,args)1739 tn5250_Display_do_keys (self, args)
1740 Tn5250_Display* self;
1741 PyObject* args;
1742 {
1743 if (self == NULL || !Tn5250_DisplayCheck (self))
1744 return PyErr_Format(PyExc_TypeError, "not a Display.");
1745 if (!PyArg_ParseTuple(args, ":Display.do_keys"))
1746 return NULL;
1747 if (self->display != NULL)
1748 tn5250_display_do_keys (self->display);
1749 Py_INCREF(Py_None);
1750 return Py_None;
1751 }
1752
1753 static PyObject*
tn5250_Display_do_key(self,args)1754 tn5250_Display_do_key (self, args)
1755 Tn5250_Display* self;
1756 PyObject* args;
1757 {
1758 int key;
1759 if (self == NULL || !Tn5250_DisplayCheck (self))
1760 return PyErr_Format(PyExc_TypeError, "not a Display.");
1761 if (!PyArg_ParseTuple(args, "d:Display.do_key", &key))
1762 return NULL;
1763 if (self->display != NULL)
1764 tn5250_display_do_key (self->display, key);
1765 Py_INCREF(Py_None);
1766 return Py_None;
1767 }
1768
1769 static PyObject*
tn5250_Display_kf_backspace(self,args)1770 tn5250_Display_kf_backspace (self, args)
1771 Tn5250_Display* self;
1772 PyObject* args;
1773 {
1774 if (self == NULL || !Tn5250_DisplayCheck (self))
1775 return PyErr_Format(PyExc_TypeError, "not a Display.");
1776 if (!PyArg_ParseTuple(args, ":Display.kf_backspace"))
1777 return NULL;
1778 if (self->display != NULL)
1779 tn5250_display_kf_backspace (self->display);
1780 Py_INCREF(Py_None);
1781 return Py_None;
1782 }
1783
1784 static PyObject*
tn5250_Display_kf_up(self,args)1785 tn5250_Display_kf_up (self, args)
1786 Tn5250_Display* self;
1787 PyObject* args;
1788 {
1789 if (self == NULL || !Tn5250_DisplayCheck (self))
1790 return PyErr_Format(PyExc_TypeError, "not a Display.");
1791 if (!PyArg_ParseTuple(args, ":Display.kf_up"))
1792 return NULL;
1793 if (self->display != NULL)
1794 tn5250_display_kf_up (self->display);
1795 Py_INCREF(Py_None);
1796 return Py_None;
1797 }
1798
1799 static PyObject*
tn5250_Display_kf_down(self,args)1800 tn5250_Display_kf_down (self, args)
1801 Tn5250_Display* self;
1802 PyObject* args;
1803 {
1804 if (self == NULL || !Tn5250_DisplayCheck (self))
1805 return PyErr_Format(PyExc_TypeError, "not a Display.");
1806 if (!PyArg_ParseTuple(args, ":Display.kf_down"))
1807 return NULL;
1808 if (self->display != NULL)
1809 tn5250_display_kf_down (self->display);
1810 Py_INCREF(Py_None);
1811 return Py_None;
1812 }
1813
1814 static PyObject*
tn5250_Display_kf_left(self,args)1815 tn5250_Display_kf_left (self, args)
1816 Tn5250_Display* self;
1817 PyObject* args;
1818 {
1819 if (self == NULL || !Tn5250_DisplayCheck (self))
1820 return PyErr_Format(PyExc_TypeError, "not a Display.");
1821 if (!PyArg_ParseTuple(args, ":Display.kf_left"))
1822 return NULL;
1823 if (self->display != NULL)
1824 tn5250_display_kf_left (self->display);
1825 Py_INCREF(Py_None);
1826 return Py_None;
1827 }
1828
1829 static PyObject*
tn5250_Display_kf_right(self,args)1830 tn5250_Display_kf_right (self, args)
1831 Tn5250_Display* self;
1832 PyObject* args;
1833 {
1834 if (self == NULL || !Tn5250_DisplayCheck (self))
1835 return PyErr_Format(PyExc_TypeError, "not a Display.");
1836 if (!PyArg_ParseTuple(args, ":Display.kf_right"))
1837 return NULL;
1838 if (self->display != NULL)
1839 tn5250_display_kf_right (self->display);
1840 Py_INCREF(Py_None);
1841 return Py_None;
1842 }
1843
1844 static PyObject*
tn5250_Display_kf_field_exit(self,args)1845 tn5250_Display_kf_field_exit (self, args)
1846 Tn5250_Display* self;
1847 PyObject* args;
1848 {
1849 if (self == NULL || !Tn5250_DisplayCheck (self))
1850 return PyErr_Format(PyExc_TypeError, "not a Display.");
1851 if (!PyArg_ParseTuple(args, ":Display.kf_field_exit"))
1852 return NULL;
1853 if (self->display != NULL)
1854 tn5250_display_kf_field_exit (self->display);
1855 Py_INCREF(Py_None);
1856 return Py_None;
1857 }
1858
1859 static PyObject*
tn5250_Display_kf_field_minus(self,args)1860 tn5250_Display_kf_field_minus (self, args)
1861 Tn5250_Display* self;
1862 PyObject* args;
1863 {
1864 if (self == NULL || !Tn5250_DisplayCheck (self))
1865 return PyErr_Format(PyExc_TypeError, "not a Display.");
1866 if (!PyArg_ParseTuple(args, ":Display.kf_field_minus"))
1867 return NULL;
1868 if (self->display != NULL)
1869 tn5250_display_kf_field_minus (self->display);
1870 Py_INCREF(Py_None);
1871 return Py_None;
1872 }
1873
1874 static PyObject*
tn5250_Display_kf_field_plus(self,args)1875 tn5250_Display_kf_field_plus (self, args)
1876 Tn5250_Display* self;
1877 PyObject* args;
1878 {
1879 if (self == NULL || !Tn5250_DisplayCheck (self))
1880 return PyErr_Format(PyExc_TypeError, "not a Display.");
1881 if (!PyArg_ParseTuple(args, ":Display.kf_field_plus"))
1882 return NULL;
1883 if (self->display != NULL)
1884 tn5250_display_kf_field_plus (self->display);
1885 Py_INCREF(Py_None);
1886 return Py_None;
1887 }
1888
1889 static PyObject*
tn5250_Display_kf_dup(self,args)1890 tn5250_Display_kf_dup (self, args)
1891 Tn5250_Display* self;
1892 PyObject* args;
1893 {
1894 if (self == NULL || !Tn5250_DisplayCheck (self))
1895 return PyErr_Format(PyExc_TypeError, "not a Display.");
1896 if (!PyArg_ParseTuple(args, ":Display.kf_dup"))
1897 return NULL;
1898 if (self->display != NULL)
1899 tn5250_display_kf_dup (self->display);
1900 Py_INCREF(Py_None);
1901 return Py_None;
1902 }
1903
1904 static PyObject*
tn5250_Display_kf_insert(self,args)1905 tn5250_Display_kf_insert (self, args)
1906 Tn5250_Display* self;
1907 PyObject* args;
1908 {
1909 if (self == NULL || !Tn5250_DisplayCheck (self))
1910 return PyErr_Format(PyExc_TypeError, "not a Display.");
1911 if (!PyArg_ParseTuple(args, ":Display.kf_insert"))
1912 return NULL;
1913 if (self->display != NULL)
1914 tn5250_display_kf_insert (self->display);
1915 Py_INCREF(Py_None);
1916 return Py_None;
1917 }
1918
1919 static PyObject*
tn5250_Display_kf_tab(self,args)1920 tn5250_Display_kf_tab (self, args)
1921 Tn5250_Display* self;
1922 PyObject* args;
1923 {
1924 if (self == NULL || !Tn5250_DisplayCheck (self))
1925 return PyErr_Format(PyExc_TypeError, "not a Display.");
1926 if (!PyArg_ParseTuple(args, ":Display.kf_tab"))
1927 return NULL;
1928 if (self->display != NULL)
1929 tn5250_display_kf_tab (self->display);
1930 Py_INCREF(Py_None);
1931 return Py_None;
1932 }
1933
1934 static PyObject*
tn5250_Display_kf_backtab(self,args)1935 tn5250_Display_kf_backtab (self, args)
1936 Tn5250_Display* self;
1937 PyObject* args;
1938 {
1939 if (self == NULL || !Tn5250_DisplayCheck (self))
1940 return PyErr_Format(PyExc_TypeError, "not a Display.");
1941 if (!PyArg_ParseTuple(args, ":Display.kf_backtab"))
1942 return NULL;
1943 if (self->display != NULL)
1944 tn5250_display_kf_backtab (self->display);
1945 Py_INCREF(Py_None);
1946 return Py_None;
1947 }
1948
1949 static PyObject*
tn5250_Display_kf_end(self,args)1950 tn5250_Display_kf_end (self, args)
1951 Tn5250_Display* self;
1952 PyObject* args;
1953 {
1954 if (self == NULL || !Tn5250_DisplayCheck (self))
1955 return PyErr_Format(PyExc_TypeError, "not a Display.");
1956 if (!PyArg_ParseTuple(args, ":Display.kf_end"))
1957 return NULL;
1958 if (self->display != NULL)
1959 tn5250_display_kf_end (self->display);
1960 Py_INCREF(Py_None);
1961 return Py_None;
1962 }
1963
1964 static PyObject*
tn5250_Display_kf_home(self,args)1965 tn5250_Display_kf_home (self, args)
1966 Tn5250_Display* self;
1967 PyObject* args;
1968 {
1969 if (self == NULL || !Tn5250_DisplayCheck (self))
1970 return PyErr_Format(PyExc_TypeError, "not a Display.");
1971 if (!PyArg_ParseTuple(args, ":Display.kf_home"))
1972 return NULL;
1973 if (self->display != NULL)
1974 tn5250_display_kf_home (self->display);
1975 Py_INCREF(Py_None);
1976 return Py_None;
1977 }
1978
1979 static PyObject*
tn5250_Display_kf_delete(self,args)1980 tn5250_Display_kf_delete (self, args)
1981 Tn5250_Display* self;
1982 PyObject* args;
1983 {
1984 if (self == NULL || !Tn5250_DisplayCheck (self))
1985 return PyErr_Format(PyExc_TypeError, "not a Display.");
1986 if (!PyArg_ParseTuple(args, ":Display.kf_delete"))
1987 return NULL;
1988 if (self->display != NULL)
1989 tn5250_display_kf_delete (self->display);
1990 Py_INCREF(Py_None);
1991 return Py_None;
1992 }
1993
1994 static PyObject*
tn5250_Display_dbuffer(self,args)1995 tn5250_Display_dbuffer (self, args)
1996 Tn5250_Display* self;
1997 PyObject* args;
1998 {
1999 Tn5250DBuffer *dbuf;
2000 if (self == NULL || !Tn5250_DisplayCheck (self))
2001 return PyErr_Format(PyExc_TypeError, "not a Display.");
2002 if (!PyArg_ParseTuple(args, ":Display.dbuffer"))
2003 return NULL;
2004 dbuf = tn5250_display_dbuffer(self->display);
2005 return Tn5250_DisplayBuffer_wrap (dbuf);
2006 }
2007
2008 static PyObject*
tn5250_Display_indicators(self,args)2009 tn5250_Display_indicators (self, args)
2010 Tn5250_Display* self;
2011 PyObject* args;
2012 {
2013 int inds;
2014 if (self == NULL || !Tn5250_DisplayCheck (self))
2015 return PyErr_Format(PyExc_TypeError, "not a Display.");
2016 if (!PyArg_ParseTuple(args, ":Display.indicators"))
2017 return NULL;
2018 inds = 0;
2019 if (self->display != NULL)
2020 inds = tn5250_display_indicators (self->display);
2021 return PyInt_FromLong((long)inds);
2022 }
2023
2024 static PyObject*
tn5250_Display_inhibited(self,args)2025 tn5250_Display_inhibited (self, args)
2026 Tn5250_Display* self;
2027 PyObject* args;
2028 {
2029 int inh;
2030 if (self == NULL || !Tn5250_DisplayCheck (self))
2031 return PyErr_Format(PyExc_TypeError, "not a Display.");
2032 if (!PyArg_ParseTuple(args, ":Display.inhibited"))
2033 return NULL;
2034 inh = 0;
2035 if (self->display != NULL)
2036 inh = tn5250_display_inhibited (self->display);
2037 return PyInt_FromLong((long)inh);
2038 }
2039
2040 static PyObject*
tn5250_Display_inhibit(self,args)2041 tn5250_Display_inhibit (self, args)
2042 Tn5250_Display* self;
2043 PyObject* args;
2044 {
2045 if (self == NULL || !Tn5250_DisplayCheck (self))
2046 return PyErr_Format(PyExc_TypeError, "not a Display.");
2047 if (!PyArg_ParseTuple(args, ":Display.inhibit"))
2048 return NULL;
2049 if (self->display != NULL)
2050 tn5250_display_inhibit (self->display);
2051 Py_INCREF(Py_None);
2052 return Py_None;
2053 }
2054
2055 static PyObject*
tn5250_Display_uninhibit(self,args)2056 tn5250_Display_uninhibit (self, args)
2057 Tn5250_Display* self;
2058 PyObject* args;
2059 {
2060 if (self == NULL || !Tn5250_DisplayCheck (self))
2061 return PyErr_Format(PyExc_TypeError, "not a Display.");
2062 if (!PyArg_ParseTuple(args, ":Display.uninhibit"))
2063 return NULL;
2064 if (self->display != NULL)
2065 tn5250_display_uninhibit (self->display);
2066 Py_INCREF(Py_None);
2067 return Py_None;
2068 }
2069
2070 static PyObject*
tn5250_Display_cursor_x(self,args)2071 tn5250_Display_cursor_x (self, args)
2072 Tn5250_Display* self;
2073 PyObject* args;
2074 {
2075 int x;
2076 if (self == NULL || !Tn5250_DisplayCheck (self))
2077 return PyErr_Format(PyExc_TypeError, "not a Display.");
2078 if (!PyArg_ParseTuple(args, ":Display.cursor_x"))
2079 return NULL;
2080 x = 0;
2081 if (self->display != NULL)
2082 x = tn5250_display_cursor_x (self->display);
2083 return PyInt_FromLong((long)x);
2084 }
2085
2086 static PyObject*
tn5250_Display_cursor_y(self,args)2087 tn5250_Display_cursor_y (self, args)
2088 Tn5250_Display* self;
2089 PyObject* args;
2090 {
2091 int y;
2092 if (self == NULL || !Tn5250_DisplayCheck (self))
2093 return PyErr_Format(PyExc_TypeError, "not a Display.");
2094 if (!PyArg_ParseTuple(args, ":Display.cursor_y"))
2095 return NULL;
2096 y = 0;
2097 if (self->display != NULL)
2098 y = tn5250_display_cursor_y (self->display);
2099 return PyInt_FromLong ((long)y);
2100 }
2101
2102 static PyObject*
tn5250_Display_set_cursor(self,args)2103 tn5250_Display_set_cursor (self, args)
2104 Tn5250_Display* self;
2105 PyObject* args;
2106 {
2107 int y, x;
2108 if (self == NULL || !Tn5250_DisplayCheck (self))
2109 return PyErr_Format(PyExc_TypeError, "not a Display.");
2110 if (!PyArg_ParseTuple(args, "dd:Display.set_cursor", &y, &x))
2111 return NULL;
2112 if (self->display != NULL)
2113 tn5250_display_set_cursor (self->display, y, x);
2114 Py_INCREF(Py_None);
2115 return Py_None;
2116 }
2117
2118 static PyObject*
tn5250_Display_width(self,args)2119 tn5250_Display_width (self, args)
2120 Tn5250_Display* self;
2121 PyObject* args;
2122 {
2123 int w;
2124 if (self == NULL || !Tn5250_DisplayCheck (self))
2125 return PyErr_Format(PyExc_TypeError, "not a Display.");
2126 if (!PyArg_ParseTuple(args, ":Display.width"))
2127 return NULL;
2128 if (self->display != NULL)
2129 w = tn5250_display_width (self->display);
2130 return PyInt_FromLong((long)w);
2131 }
2132
2133 static PyObject*
tn5250_Display_height(self,args)2134 tn5250_Display_height (self, args)
2135 Tn5250_Display* self;
2136 PyObject* args;
2137 {
2138 int h;
2139 if (self == NULL || !Tn5250_DisplayCheck (self))
2140 return PyErr_Format(PyExc_TypeError, "not a Display.");
2141 if (!PyArg_ParseTuple(args, ":Display.height"))
2142 return NULL;
2143 if (self->display != NULL)
2144 h = tn5250_display_height (self->display);
2145 return PyInt_FromLong((long)h);
2146 }
2147
2148 static PyObject*
tn5250_Display_char_at(self,args)2149 tn5250_Display_char_at (self, args)
2150 Tn5250_Display* self;
2151 PyObject* args;
2152 {
2153 unsigned char ch;
2154 int y, x;
2155 if (self == NULL || !Tn5250_DisplayCheck (self))
2156 return PyErr_Format(PyExc_TypeError, "not a Display.");
2157 if (!PyArg_ParseTuple(args, "dd:Display.char_at", &y, &x))
2158 return NULL;
2159 ch = 0;
2160 if (self->display != NULL)
2161 ch = tn5250_display_char_at (self->display, y, x);
2162 return Py_BuildValue("c", ch);
2163 }
2164
2165 static PyObject*
tn5250_Display_addch(self,args)2166 tn5250_Display_addch (self, args)
2167 Tn5250_Display* self;
2168 PyObject* args;
2169 {
2170 unsigned char ch;
2171 if (self == NULL || !Tn5250_DisplayCheck (self))
2172 return PyErr_Format(PyExc_TypeError, "not a Display.");
2173 if (!PyArg_ParseTuple(args, "c:Display.addch", &ch))
2174 return NULL;
2175 if (self->display != NULL)
2176 tn5250_display_addch (self->display, ch);
2177 Py_INCREF(Py_None);
2178 return Py_None;
2179 }
2180
2181 static PyObject*
tn5250_Display_roll(self,args)2182 tn5250_Display_roll (self, args)
2183 Tn5250_Display* self;
2184 PyObject* args;
2185 {
2186 int top, bottom, lines;
2187 if (self == NULL || !Tn5250_DisplayCheck (self))
2188 return PyErr_Format(PyExc_TypeError, "not a Display.");
2189 if (!PyArg_ParseTuple(args, "ddd:Display.roll", &top, &bottom, &lines))
2190 return NULL;
2191 if (self->display != NULL)
2192 tn5250_display_roll (self->display, top, bottom, lines);
2193 Py_INCREF(Py_None);
2194 return Py_None;
2195 }
2196
2197 static PyObject*
tn5250_Display_set_ic(self,args)2198 tn5250_Display_set_ic (self, args)
2199 Tn5250_Display* self;
2200 PyObject* args;
2201 {
2202 int y, x;
2203 if (self == NULL || !Tn5250_DisplayCheck (self))
2204 return PyErr_Format(PyExc_TypeError, "not a Display.");
2205 if (!PyArg_ParseTuple(args, "dd:Display.set_ic", &y, &x))
2206 return NULL;
2207 if (self->display != NULL)
2208 tn5250_display_set_ic (self->display, y, x);
2209 Py_INCREF(Py_None);
2210 return Py_None;
2211 }
2212
2213 static PyObject*
tn5250_Display_set_header_data(self,args)2214 tn5250_Display_set_header_data (self, args)
2215 Tn5250_Display* self;
2216 PyObject* args;
2217 {
2218 unsigned char *ptr;
2219 int len;
2220 if (self == NULL || !Tn5250_DisplayCheck (self))
2221 return PyErr_Format(PyExc_TypeError, "not a Display.");
2222 if (!PyArg_ParseTuple(args, "s#:Display.set_header_data", &ptr, &len))
2223 return NULL;
2224 if (self->display != NULL)
2225 tn5250_display_set_header_data (self->display, ptr, len);
2226 Py_INCREF(Py_None);
2227 return Py_None;
2228 }
2229
2230 static PyObject*
tn5250_Display_clear_pending_insert(self,args)2231 tn5250_Display_clear_pending_insert (self, args)
2232 Tn5250_Display* self;
2233 PyObject* args;
2234 {
2235 if (self == NULL || !Tn5250_DisplayCheck (self))
2236 return PyErr_Format(PyExc_TypeError, "not a Display.");
2237 if (!PyArg_ParseTuple(args, ":Display.clear_pending_insert"))
2238 return NULL;
2239 if (self->display != NULL)
2240 tn5250_display_clear_pending_insert (self->display);
2241 Py_INCREF(Py_None);
2242 return Py_None;
2243 }
2244
2245 static PyObject*
tn5250_Display_pending_insert(self,args)2246 tn5250_Display_pending_insert (self, args)
2247 Tn5250_Display* self;
2248 PyObject* args;
2249 {
2250 int pins;
2251 if (self == NULL || !Tn5250_DisplayCheck (self))
2252 return PyErr_Format(PyExc_TypeError, "not a Display.");
2253 if (!PyArg_ParseTuple(args, ":Display.pending_insert"))
2254 return NULL;
2255 pins = 0;
2256 if (self->display != NULL)
2257 pins = tn5250_display_pending_insert(self->display);
2258 return PyInt_FromLong((long)pins);
2259 }
2260
2261 static PyObject*
tn5250_Display_field_data(self,args)2262 tn5250_Display_field_data (self, args)
2263 Tn5250_Display* self;
2264 PyObject* args;
2265 {
2266 if (self == NULL || !Tn5250_DisplayCheck (self))
2267 return PyErr_Format(PyExc_TypeError, "not a Display.");
2268 if (!PyArg_ParseTuple(args, ":Display.field_data"))
2269 return NULL;
2270 // XXX: Implement
2271 Py_INCREF(Py_None);
2272 return Py_None;
2273 }
2274
2275 static PyObject*
tn5250_Display_msg_line(self,args)2276 tn5250_Display_msg_line (self, args)
2277 Tn5250_Display* self;
2278 PyObject* args;
2279 {
2280 int ml;
2281 if (self == NULL || !Tn5250_DisplayCheck (self))
2282 return PyErr_Format(PyExc_TypeError, "not a Display.");
2283 if (!PyArg_ParseTuple(args, ":Display.msg_line"))
2284 return NULL;
2285 ml = 0;
2286 if (self->display != NULL)
2287 ml = tn5250_display_msg_line (self->display);
2288 return PyInt_FromLong((long)ml);
2289 }
2290
2291 static PyObject*
tn5250_Display_char_map(self,args)2292 tn5250_Display_char_map (self, args)
2293 Tn5250_Display* self;
2294 PyObject* args;
2295 {
2296 if (self == NULL || !Tn5250_DisplayCheck (self))
2297 return PyErr_Format(PyExc_TypeError, "not a Display.");
2298 if (!PyArg_ParseTuple(args, ":Display.char_map"))
2299 return NULL;
2300 // XXX: Implement
2301 Py_INCREF(Py_None);
2302 return Py_None;
2303 }
2304
2305
2306 static PyMethodDef Tn5250_DisplayMethods[] = {
2307 { "config", tn5250_Display_config, METH_VARARGS },
2308 { "set_session", tn5250_Display_set_session, METH_VARARGS },
2309 { "push_dbuffer", tn5250_Display_push_dbuffer, METH_VARARGS },
2310 { "restore_dbuffer", tn5250_Display_restore_dbuffer, METH_VARARGS },
2311 { "set_terminal", tn5250_Display_set_terminal, METH_VARARGS },
2312 { "update", tn5250_Display_update, METH_VARARGS },
2313 { "waitevent", tn5250_Display_waitevent, METH_VARARGS },
2314 { "getkey", tn5250_Display_getkey, METH_VARARGS },
2315 { "field_at", tn5250_Display_field_at, METH_VARARGS },
2316 { "current_field", tn5250_Display_current_field, METH_VARARGS },
2317 { "next_field", tn5250_Display_next_field, METH_VARARGS },
2318 { "prev_field", tn5250_Display_prev_field, METH_VARARGS },
2319 { "set_cursor_field", tn5250_Display_set_cursor_field, METH_VARARGS },
2320 { "set_cursor_home", tn5250_Display_set_cursor_home, METH_VARARGS },
2321 { "set_cursor_next_field",tn5250_Display_set_cursor_next_field,METH_VARARGS },
2322 { "set_cursor_prev_field",tn5250_Display_set_cursor_prev_field,METH_VARARGS },
2323 { "shift_right", tn5250_Display_shift_right, METH_VARARGS },
2324 { "field_adjust", tn5250_Display_field_adjust, METH_VARARGS },
2325 { "interactive_addch", tn5250_Display_interactive_addch, METH_VARARGS },
2326 { "beep", tn5250_Display_beep, METH_VARARGS },
2327 { "do_aidkey", tn5250_Display_do_aidkey, METH_VARARGS },
2328 { "indicator_set", tn5250_Display_indicator_set, METH_VARARGS },
2329 { "indicator_clear", tn5250_Display_indicator_clear, METH_VARARGS },
2330 { "clear_unit", tn5250_Display_clear_unit, METH_VARARGS },
2331 { "clear_unit_alternate",tn5250_Display_clear_unit_alternate,METH_VARARGS },
2332 { "clear_format_table", tn5250_Display_clear_format_table, METH_VARARGS },
2333 { "set_pending_insert", tn5250_Display_set_pending_insert, METH_VARARGS },
2334 { "make_wtd_data", tn5250_Display_make_wtd_data, METH_VARARGS },
2335 { "save_msg_line", tn5250_Display_save_msg_line, METH_VARARGS },
2336 { "set_char_map", tn5250_Display_set_char_map, METH_VARARGS },
2337 { "do_keys", tn5250_Display_do_keys, METH_VARARGS },
2338 { "do_key", tn5250_Display_do_key, METH_VARARGS },
2339 { "kf_backspace", tn5250_Display_kf_backspace, METH_VARARGS },
2340 { "kf_up", tn5250_Display_kf_up, METH_VARARGS },
2341 { "kf_down", tn5250_Display_kf_down, METH_VARARGS },
2342 { "kf_left", tn5250_Display_kf_left, METH_VARARGS },
2343 { "kf_right", tn5250_Display_kf_right, METH_VARARGS },
2344 { "kf_field_exit", tn5250_Display_kf_field_exit, METH_VARARGS },
2345 { "kf_field_minus", tn5250_Display_kf_field_minus, METH_VARARGS },
2346 { "kf_field_plus", tn5250_Display_kf_field_plus, METH_VARARGS },
2347 { "kf_dup", tn5250_Display_kf_dup, METH_VARARGS },
2348 { "kf_insert", tn5250_Display_kf_insert, METH_VARARGS },
2349 { "kf_tab", tn5250_Display_kf_tab, METH_VARARGS },
2350 { "kf_backtab", tn5250_Display_kf_backtab, METH_VARARGS },
2351 { "kf_end", tn5250_Display_kf_end, METH_VARARGS },
2352 { "kf_home", tn5250_Display_kf_home, METH_VARARGS },
2353 { "kf_delete", tn5250_Display_kf_delete, METH_VARARGS },
2354 { "dbuffer", tn5250_Display_dbuffer, METH_VARARGS },
2355 { "indicators", tn5250_Display_indicators, METH_VARARGS },
2356 { "inhibited", tn5250_Display_inhibited, METH_VARARGS },
2357 { "inhibit", tn5250_Display_inhibit, METH_VARARGS },
2358 { "uninhibit", tn5250_Display_uninhibit, METH_VARARGS },
2359 { "cursor_x", tn5250_Display_cursor_x, METH_VARARGS },
2360 { "cursor_y", tn5250_Display_cursor_y, METH_VARARGS },
2361 { "set_cursor", tn5250_Display_set_cursor, METH_VARARGS },
2362 { "width", tn5250_Display_width, METH_VARARGS },
2363 { "height", tn5250_Display_height, METH_VARARGS },
2364 { "char_at", tn5250_Display_char_at, METH_VARARGS },
2365 { "addch", tn5250_Display_addch, METH_VARARGS },
2366 { "roll", tn5250_Display_roll, METH_VARARGS },
2367 { "set_ic", tn5250_Display_set_ic, METH_VARARGS },
2368 { "set_header_data", tn5250_Display_set_header_data, METH_VARARGS },
2369 { "clear_pending_insert",tn5250_Display_clear_pending_insert,METH_VARARGS },
2370 { "pending_insert", tn5250_Display_pending_insert, METH_VARARGS },
2371 { "field_data", tn5250_Display_field_data, METH_VARARGS },
2372 { "msg_line", tn5250_Display_msg_line, METH_VARARGS },
2373 { "char_map", tn5250_Display_char_map, METH_VARARGS },
2374 { NULL, NULL }
2375 };
2376
2377 static PyObject*
tn5250_Display_getattr(self,name)2378 tn5250_Display_getattr (self, name)
2379 Tn5250_Display* self;
2380 char *name;
2381 {
2382 return Py_FindMethod (Tn5250_DisplayMethods, (PyObject*)self, name);
2383 }
2384
2385 statichere PyTypeObject Tn5250_DisplayType = {
2386 PyObject_HEAD_INIT(NULL)
2387 0, /* ob_size */
2388 "Display", /* tp_name */
2389 sizeof (Tn5250_Display), /* tp_basicsize */
2390 0, /* tp_itemsize */
2391 /* methods */
2392 (destructor)tn5250_Display_dealloc,/* tp_dealloc */
2393 0, /* tp_print */
2394 (getattrfunc)tn5250_Display_getattr,/* tp_getattr */
2395 0, /* tp_setattr */
2396 0, /* tp_compare */
2397 0, /* tp_repr */
2398 0, /* tp_as_number */
2399 0, /* tp_as_sequence */
2400 0, /* tp_as_mapping */
2401 0, /* tp_hash */
2402 };
2403
2404 /****************************************************************************/
2405 /* Field class */
2406 /****************************************************************************/
2407
2408 static void
tn5250_Field_dealloc(self)2409 tn5250_Field_dealloc (self)
2410 Tn5250_Field* self;
2411 {
2412 // XXX: Reference counting problems.
2413 if (self->field != NULL)
2414 tn5250_field_destroy (self->field);
2415 }
2416
2417 static PyObject*
Tn5250_Field_wrap(fld)2418 Tn5250_Field_wrap (fld)
2419 Tn5250Field *fld;
2420 {
2421 Tn5250_Field *field;
2422
2423 if (fld->script_slot)
2424 return (PyObject*)fld->script_slot;
2425
2426 field = PyObject_NEW(Tn5250_Field, &Tn5250_FieldType);
2427 field->field = fld;
2428 fld->script_slot = field;
2429 return (PyObject*)field;
2430 }
2431
2432 static PyObject*
tn5250_Field(func_self,args)2433 tn5250_Field (func_self, args)
2434 PyObject* func_self;
2435 PyObject* args;
2436 {
2437 int w;
2438 Tn5250Field *fld;
2439 if (!PyArg_ParseTuple(args, "d:Field", &w))
2440 return NULL;
2441
2442 fld = tn5250_field_new (w);
2443 if (fld == NULL) {
2444 // XXX: Strerror
2445 return NULL;
2446 }
2447
2448 return Tn5250_Field_wrap (fld);
2449 }
2450
2451 static PyObject*
tn5250_Field_copy(self,args)2452 tn5250_Field_copy (self, args)
2453 Tn5250_Field* self;
2454 PyObject* args;
2455 {
2456 // XXX: Maybe copy methods should follow python's protocol (deep/shallow
2457 // copies).
2458 Tn5250Field* fld;
2459 if (self == NULL || !Tn5250_FieldCheck (self))
2460 return PyErr_Format(PyExc_TypeError, "not a Field.");
2461 if (!PyArg_ParseTuple(args, ":Field.copy"))
2462 return NULL;
2463 fld = tn5250_field_copy (self->field);
2464 return Tn5250_Field_wrap (fld);
2465 }
2466
2467 static PyObject*
tn5250_Field_hit_test(self,args)2468 tn5250_Field_hit_test (self, args)
2469 Tn5250_Field* self;
2470 PyObject* args;
2471 {
2472 int y, x;
2473 if (self == NULL || !Tn5250_FieldCheck (self))
2474 return PyErr_Format(PyExc_TypeError, "not a Field.");
2475 if (!PyArg_ParseTuple(args, "dd:Field.hit_test", &y, &x))
2476 return NULL;
2477 if (tn5250_field_hit_test (self->field, y, x)) {
2478 Py_INCREF(Py_True);
2479 return Py_True;
2480 }
2481 Py_INCREF(Py_False);
2482 return Py_False;
2483 }
2484
2485 static PyObject*
tn5250_Field_start_pos(self,args)2486 tn5250_Field_start_pos (self, args)
2487 Tn5250_Field* self;
2488 PyObject* args;
2489 {
2490 int pos = 0;
2491 if (self == NULL || !Tn5250_FieldCheck (self))
2492 return PyErr_Format(PyExc_TypeError, "not a Field.");
2493 if (!PyArg_ParseTuple(args, ":Field.start_pos"))
2494 return NULL;
2495 if (self->field != NULL)
2496 pos = tn5250_field_start_pos (self->field);
2497 return PyInt_FromLong((long)pos);
2498 }
2499
2500 static PyObject*
tn5250_Field_end_pos(self,args)2501 tn5250_Field_end_pos (self, args)
2502 Tn5250_Field* self;
2503 PyObject* args;
2504 {
2505 int pos = 0;
2506 if (self == NULL || !Tn5250_FieldCheck (self))
2507 return PyErr_Format(PyExc_TypeError, "not a Field.");
2508 if (!PyArg_ParseTuple(args, ":Field.end_pos"))
2509 return NULL;
2510 if (self->field != NULL)
2511 pos = tn5250_field_end_pos (self->field);
2512 return PyInt_FromLong((long)pos);
2513 }
2514
2515 static PyObject*
tn5250_Field_end_row(self,args)2516 tn5250_Field_end_row (self, args)
2517 Tn5250_Field* self;
2518 PyObject* args;
2519 {
2520 int row = 0;
2521 if (self == NULL || !Tn5250_FieldCheck (self))
2522 return PyErr_Format(PyExc_TypeError, "not a Field.");
2523 if (!PyArg_ParseTuple(args, ":Field.end_row"))
2524 return NULL;
2525 if (self->field != NULL)
2526 row = tn5250_field_end_row (self->field);
2527 return PyInt_FromLong((long)row);
2528 }
2529
2530 static PyObject*
tn5250_Field_end_col(self,args)2531 tn5250_Field_end_col (self, args)
2532 Tn5250_Field* self;
2533 PyObject* args;
2534 {
2535 int col = 0;
2536 if (self == NULL || !Tn5250_FieldCheck (self))
2537 return PyErr_Format(PyExc_TypeError, "not a Field.");
2538 if (!PyArg_ParseTuple(args, ":Field.end_col"))
2539 return NULL;
2540 if (self->field != NULL)
2541 col = tn5250_field_end_col (self->field);
2542 return PyInt_FromLong((long)col);
2543 }
2544
2545 static PyObject*
tn5250_Field_description(self,args)2546 tn5250_Field_description (self, args)
2547 Tn5250_Field* self;
2548 PyObject* args;
2549 {
2550 if (self == NULL || !Tn5250_FieldCheck (self))
2551 return PyErr_Format(PyExc_TypeError, "not a Field.");
2552 if (!PyArg_ParseTuple(args, ":Field.description"))
2553 return NULL;
2554 if (self->field != NULL)
2555 return Py_BuildValue ("s", tn5250_field_description (self->field));
2556 Py_INCREF(Py_None);
2557 return Py_None;
2558 }
2559
2560 static PyObject*
tn5250_Field_adjust_description(self,args)2561 tn5250_Field_adjust_description (self, args)
2562 Tn5250_Field* self;
2563 PyObject* args;
2564 {
2565 if (self == NULL || !Tn5250_FieldCheck (self))
2566 return PyErr_Format(PyExc_TypeError, "not a Field.");
2567 if (!PyArg_ParseTuple(args, ":Field.adjust_description"))
2568 return NULL;
2569 if (self->field != NULL)
2570 return Py_BuildValue ("s", tn5250_field_adjust_description (self->field));
2571 Py_INCREF(Py_None);
2572 return Py_None;
2573 }
2574
2575 static PyObject*
tn5250_Field_count_left(self,args)2576 tn5250_Field_count_left (self, args)
2577 Tn5250_Field* self;
2578 PyObject* args;
2579 {
2580 int y, x;
2581 if (self == NULL || !Tn5250_FieldCheck (self))
2582 return PyErr_Format(PyExc_TypeError, "not a Field.");
2583 if (!PyArg_ParseTuple(args, "dd:Field.count_left", &y, &x))
2584 return NULL;
2585 if (self->field != NULL)
2586 return PyInt_FromLong((long)tn5250_field_count_left (self->field, y, x));
2587 Py_INCREF(Py_None);
2588 return Py_None;
2589 }
2590
2591 static PyObject*
tn5250_Field_count_right(self,args)2592 tn5250_Field_count_right (self, args)
2593 Tn5250_Field* self;
2594 PyObject* args;
2595 {
2596 int y, x;
2597 if (self == NULL || !Tn5250_FieldCheck (self))
2598 return PyErr_Format(PyExc_TypeError, "not a Field.");
2599 if (!PyArg_ParseTuple(args, "dd:Field.count_right", &y, &x))
2600 return NULL;
2601 if (self->field != NULL)
2602 return PyInt_FromLong((long)tn5250_field_count_right (self->field, y, x));
2603 Py_INCREF(Py_None);
2604 return Py_None;
2605 }
2606
2607 static PyObject*
tn5250_Field_set_mdt(self,args)2608 tn5250_Field_set_mdt (self, args)
2609 Tn5250_Field* self;
2610 PyObject* args;
2611 {
2612 if (self == NULL || !Tn5250_FieldCheck (self))
2613 return PyErr_Format(PyExc_TypeError, "not a Field.");
2614 if (!PyArg_ParseTuple(args, ":Field.set_mdt"))
2615 return NULL;
2616 if (self->field != NULL)
2617 tn5250_field_set_mdt (self->field);
2618 Py_INCREF(Py_None);
2619 return Py_None;
2620 }
2621
2622 static PyObject*
tn5250_Field_valid_char(self,args)2623 tn5250_Field_valid_char (self, args)
2624 Tn5250_Field* self;
2625 PyObject* args;
2626 {
2627 char ch;
2628 if (self == NULL || !Tn5250_FieldCheck (self))
2629 return PyErr_Format(PyExc_TypeError, "not a Field.");
2630 if (!PyArg_ParseTuple(args, "c:Field.valid_char", &ch))
2631 return NULL;
2632 if (self->field != NULL && tn5250_field_valid_char (self->field, ch)) {
2633 Py_INCREF(Py_True);
2634 return Py_True;
2635 }
2636 Py_INCREF(Py_False);
2637 return Py_False;
2638 }
2639
2640 static PyObject*
tn5250_Field_mdt(self,args)2641 tn5250_Field_mdt (self, args)
2642 Tn5250_Field* self;
2643 PyObject* args;
2644 {
2645 if (self == NULL || !Tn5250_FieldCheck (self))
2646 return PyErr_Format(PyExc_TypeError, "not a Field.");
2647 if (!PyArg_ParseTuple(args, ":Field.mdt"))
2648 return NULL;
2649 if (self->field && tn5250_field_mdt(self->field)) {
2650 Py_INCREF(Py_True);
2651 return Py_True;
2652 }
2653 Py_INCREF(Py_False);
2654 return Py_False;
2655 }
2656
2657 static PyObject*
tn5250_Field_clear_mdt(self,args)2658 tn5250_Field_clear_mdt (self, args)
2659 Tn5250_Field* self;
2660 PyObject* args;
2661 {
2662 if (self == NULL || !Tn5250_FieldCheck (self))
2663 return PyErr_Format(PyExc_TypeError, "not a Field.");
2664 if (!PyArg_ParseTuple(args, ":Field.clear_mdt"))
2665 return NULL;
2666 if (self->field != NULL)
2667 tn5250_field_clear_mdt (self->field);
2668 Py_INCREF(Py_None);
2669 return Py_None;
2670 }
2671
2672 static PyObject*
tn5250_Field_is_bypass(self,args)2673 tn5250_Field_is_bypass (self, args)
2674 Tn5250_Field* self;
2675 PyObject* args;
2676 {
2677 if (self == NULL || !Tn5250_FieldCheck (self))
2678 return PyErr_Format(PyExc_TypeError, "not a Field.");
2679 if (!PyArg_ParseTuple(args, ":Field.is_bypass"))
2680 return NULL;
2681 if (self->field != NULL && tn5250_field_is_bypass(self->field)) {
2682 Py_INCREF(Py_True);
2683 return Py_True;
2684 }
2685 Py_INCREF(Py_False);
2686 return Py_False;
2687 }
2688
2689 static PyObject*
tn5250_Field_is_dup_enable(self,args)2690 tn5250_Field_is_dup_enable (self, args)
2691 Tn5250_Field* self;
2692 PyObject* args;
2693 {
2694 if (self == NULL || !Tn5250_FieldCheck (self))
2695 return PyErr_Format(PyExc_TypeError, "not a Field.");
2696 if (!PyArg_ParseTuple(args, ":Field.is_dup_enable"))
2697 return NULL;
2698 if (self->field != NULL && tn5250_field_is_dup_enable (self->field)) {
2699 Py_INCREF(Py_True);
2700 return Py_True;
2701 }
2702 Py_INCREF(Py_False);
2703 return Py_False;
2704 }
2705
2706 static PyObject*
tn5250_Field_is_auto_enter(self,args)2707 tn5250_Field_is_auto_enter (self, args)
2708 Tn5250_Field* self;
2709 PyObject* args;
2710 {
2711 if (self == NULL || !Tn5250_FieldCheck (self))
2712 return PyErr_Format(PyExc_TypeError, "not a Field.");
2713 if (!PyArg_ParseTuple(args, ":Field.is_auto_enter"))
2714 return NULL;
2715 if (self->field != NULL && tn5250_field_is_auto_enter (self->field)) {
2716 Py_INCREF(Py_True);
2717 return Py_True;
2718 }
2719 Py_INCREF(Py_False);
2720 return Py_False;
2721 }
2722
2723 static PyObject*
tn5250_Field_is_fer(self,args)2724 tn5250_Field_is_fer (self, args)
2725 Tn5250_Field* self;
2726 PyObject* args;
2727 {
2728 if (self == NULL || !Tn5250_FieldCheck (self))
2729 return PyErr_Format(PyExc_TypeError, "not a Field.");
2730 if (!PyArg_ParseTuple(args, ":Field.is_fer"))
2731 return NULL;
2732 if (self->field != NULL && tn5250_field_is_fer (self->field)) {
2733 Py_INCREF(Py_True);
2734 return Py_True;
2735 }
2736 Py_INCREF(Py_False);
2737 return Py_False;
2738 }
2739
2740 static PyObject*
tn5250_Field_is_monocase(self,args)2741 tn5250_Field_is_monocase (self, args)
2742 Tn5250_Field* self;
2743 PyObject* args;
2744 {
2745 if (self == NULL || !Tn5250_FieldCheck (self))
2746 return PyErr_Format(PyExc_TypeError, "not a Field.");
2747 if (!PyArg_ParseTuple(args, ":Field.is_monocase"))
2748 return NULL;
2749 if (self->field != NULL && tn5250_field_is_fer(self->field)) {
2750 Py_INCREF(Py_True);
2751 return Py_True;
2752 }
2753 Py_INCREF(Py_False);
2754 return Py_False;
2755 }
2756
2757 static PyObject*
tn5250_Field_is_mandatory(self,args)2758 tn5250_Field_is_mandatory (self, args)
2759 Tn5250_Field* self;
2760 PyObject* args;
2761 {
2762 if (self == NULL || !Tn5250_FieldCheck (self))
2763 return PyErr_Format(PyExc_TypeError, "not a Field.");
2764 if (!PyArg_ParseTuple(args, ":Field.is_mandatory"))
2765 return NULL;
2766 if (self->field != NULL && tn5250_field_is_mandatory(self->field)) {
2767 Py_INCREF(Py_True);
2768 return Py_True;
2769 }
2770 Py_INCREF(Py_False);
2771 return Py_False;
2772 }
2773
2774 static PyObject*
tn5250_Field_mand_fill_type(self,args)2775 tn5250_Field_mand_fill_type (self, args)
2776 Tn5250_Field* self;
2777 PyObject* args;
2778 {
2779 if (self == NULL || !Tn5250_FieldCheck (self))
2780 return PyErr_Format(PyExc_TypeError, "not a Field.");
2781 if (!PyArg_ParseTuple(args, ":Field.mand_fill_type"))
2782 return NULL;
2783 if (self->field != NULL)
2784 return PyInt_FromLong(tn5250_field_mand_fill_type (self->field));
2785 Py_INCREF(Py_None);
2786 return Py_None;
2787 }
2788
2789 static PyObject*
tn5250_Field_is_no_adjust(self,args)2790 tn5250_Field_is_no_adjust (self, args)
2791 Tn5250_Field* self;
2792 PyObject* args;
2793 {
2794 if (self == NULL || !Tn5250_FieldCheck (self))
2795 return PyErr_Format(PyExc_TypeError, "not a Field.");
2796 if (!PyArg_ParseTuple(args, ":Field.is_no_adjust"))
2797 return NULL;
2798 if (self->field != NULL && tn5250_field_is_no_adjust (self->field)) {
2799 Py_INCREF(Py_True);
2800 return Py_True;
2801 }
2802 Py_INCREF(Py_False);
2803 return Py_False;
2804 }
2805
2806 static PyObject*
tn5250_Field_is_right_zero(self,args)2807 tn5250_Field_is_right_zero (self, args)
2808 Tn5250_Field* self;
2809 PyObject* args;
2810 {
2811 if (self == NULL || !Tn5250_FieldCheck (self))
2812 return PyErr_Format(PyExc_TypeError, "not a Field.");
2813 if (!PyArg_ParseTuple(args, ":Field.is_right_zero"))
2814 return NULL;
2815 if (self->field != NULL && tn5250_field_is_right_zero (self->field)) {
2816 Py_INCREF(Py_True);
2817 return Py_True;
2818 }
2819 Py_INCREF(Py_False);
2820 return Py_False;
2821 }
2822
2823 static PyObject*
tn5250_Field_is_right_blank(self,args)2824 tn5250_Field_is_right_blank (self, args)
2825 Tn5250_Field* self;
2826 PyObject* args;
2827 {
2828 if (self == NULL || !Tn5250_FieldCheck (self))
2829 return PyErr_Format(PyExc_TypeError, "not a Field.");
2830 if (!PyArg_ParseTuple(args, ":Field.is_right_blank"))
2831 return NULL;
2832 if (self->field != NULL && tn5250_field_is_right_zero (self->field)) {
2833 Py_INCREF(Py_True);
2834 return Py_True;
2835 }
2836 Py_INCREF(Py_False);
2837 return Py_False;
2838 }
2839
2840 static PyObject*
tn5250_Field_is_mand_fill(self,args)2841 tn5250_Field_is_mand_fill (self, args)
2842 Tn5250_Field* self;
2843 PyObject* args;
2844 {
2845 if (self == NULL || !Tn5250_FieldCheck (self))
2846 return PyErr_Format(PyExc_TypeError, "not a Field.");
2847 if (!PyArg_ParseTuple(args, ":Field.is_mand_fill"))
2848 return NULL;
2849 if (self->field != NULL && tn5250_field_is_mand_fill (self->field)) {
2850 Py_INCREF(Py_True);
2851 return Py_True;
2852 }
2853 Py_INCREF(Py_False);
2854 return Py_False;
2855 }
2856
2857 static PyObject*
tn5250_Field_type(self,args)2858 tn5250_Field_type (self, args)
2859 Tn5250_Field* self;
2860 PyObject* args;
2861 {
2862 if (self == NULL || !Tn5250_FieldCheck (self))
2863 return PyErr_Format(PyExc_TypeError, "not a Field.");
2864 if (!PyArg_ParseTuple(args, ":Field.type"))
2865 return NULL;
2866 if (self->field != NULL)
2867 return PyInt_FromLong(tn5250_field_type(self->field));
2868 Py_INCREF(Py_None);
2869 return Py_None;
2870 }
2871
2872
2873 static PyMethodDef Tn5250_FieldMethods[] = {
2874 { "copy", tn5250_Field_copy, METH_VARARGS },
2875 { "hit_test", tn5250_Field_hit_test, METH_VARARGS },
2876 { "start_pos", tn5250_Field_start_pos, METH_VARARGS },
2877 { "end_pos", tn5250_Field_end_pos, METH_VARARGS },
2878 { "end_row", tn5250_Field_end_row, METH_VARARGS },
2879 { "end_col", tn5250_Field_end_col, METH_VARARGS },
2880 { "description", tn5250_Field_description, METH_VARARGS },
2881 { "adjust_description", tn5250_Field_adjust_description, METH_VARARGS },
2882 { "count_left", tn5250_Field_count_left, METH_VARARGS },
2883 { "count_right", tn5250_Field_count_right, METH_VARARGS },
2884 { "set_mdt", tn5250_Field_set_mdt, METH_VARARGS },
2885 { "valid_char", tn5250_Field_valid_char, METH_VARARGS },
2886 { "mdt", tn5250_Field_mdt, METH_VARARGS },
2887 { "clear_mdt", tn5250_Field_clear_mdt, METH_VARARGS },
2888 { "is_bypass", tn5250_Field_is_bypass, METH_VARARGS },
2889 { "is_dup_enable", tn5250_Field_is_dup_enable, METH_VARARGS },
2890 { "is_auto_enter", tn5250_Field_is_auto_enter, METH_VARARGS },
2891 { "is_fer", tn5250_Field_is_fer, METH_VARARGS },
2892 { "is_monocase", tn5250_Field_is_monocase, METH_VARARGS },
2893 { "is_mandatory", tn5250_Field_is_mandatory, METH_VARARGS },
2894 { "mand_fill_type", tn5250_Field_mand_fill_type, METH_VARARGS },
2895 { "is_no_adjust", tn5250_Field_is_no_adjust, METH_VARARGS },
2896 { "is_right_zero", tn5250_Field_is_right_zero, METH_VARARGS },
2897 { "is_right_blank", tn5250_Field_is_right_blank, METH_VARARGS },
2898 { "is_mand_fill", tn5250_Field_is_mand_fill, METH_VARARGS },
2899 { "type", tn5250_Field_type, METH_VARARGS },
2900 { NULL, NULL }
2901 };
2902
2903 static PyObject*
tn5250_Field_getattr(self,name)2904 tn5250_Field_getattr (self, name)
2905 Tn5250_Field* self;
2906 char *name;
2907 {
2908 // XXX: set/get mdt as boolean flag.
2909 /* Hopefully, we aren't loosing the high bit in the case off the FFW and
2910 * FCW. (nah, because FFW and FCW are 16 bit, long is 32 bit...) */
2911 if (!strcmp (name, "FFW"))
2912 return PyInt_FromLong((long)self->field->FFW);
2913 if (!strcmp (name, "FCW"))
2914 return PyInt_FromLong((long)self->field->FCW);
2915 if (!strcmp (name, "attribute"))
2916 return Py_BuildValue("c", self->field->attribute);
2917 if (!strcmp (name, "start_row"))
2918 return PyInt_FromLong((long)self->field->start_row);
2919 if (!strcmp (name, "start_col"))
2920 return PyInt_FromLong((long)self->field->start_col);
2921 if (!strcmp (name, "length"))
2922 return PyInt_FromLong((long)self->field->length);
2923 if (!strcmp (name, "display_width"))
2924 return PyInt_FromLong((long)self->field->w);
2925 return Py_FindMethod (Tn5250_FieldMethods, (PyObject*)self, name);
2926 }
2927
2928 static int
tn5250_Field_setattr_helper(ptr,siz,obj)2929 tn5250_Field_setattr_helper (ptr, siz, obj)
2930 void *ptr;
2931 int siz;
2932 PyObject* obj;
2933 {
2934 PyObject* intobj;
2935 if (!PyNumber_Check(obj)) {
2936 PyErr_Format(PyExc_TypeError, "value must be a number.");
2937 return 1;
2938 }
2939 intobj = PyNumber_Int (obj);
2940 if (siz == sizeof(unsigned char)) {
2941 *((unsigned char *)ptr) = PyInt_AsLong(intobj);
2942 } else if (siz == sizeof (int)) {
2943 *((int*)ptr) = PyInt_AsLong(intobj);
2944 } else if (siz == sizeof (unsigned short)) {
2945 *((unsigned short *)ptr) = PyInt_AsLong(intobj);
2946 }
2947 Py_DECREF(intobj);
2948 return 0;
2949 }
2950
2951 static int
tn5250_Field_setattr(self,name,value)2952 tn5250_Field_setattr (self, name, value)
2953 Tn5250_Field* self;
2954 char *name;
2955 PyObject* value;
2956 {
2957 if (!strcmp (name, "FFW"))
2958 return tn5250_Field_setattr_helper (&self->field->FFW, sizeof (self->field->FFW), value);
2959 if (!strcmp (name, "FCW"))
2960 return tn5250_Field_setattr_helper (&self->field->FCW, sizeof (self->field->FCW), value);
2961 if (!strcmp (name, "attribute"))
2962 return tn5250_Field_setattr_helper (&self->field->attribute, sizeof (self->field->attribute), value);
2963 if (!strcmp (name, "start_row"))
2964 return tn5250_Field_setattr_helper (&self->field->start_row, sizeof (self->field->start_row), value);
2965 if (!strcmp (name, "start_col"))
2966 return tn5250_Field_setattr_helper (&self->field->start_col, sizeof (self->field->start_col), value);
2967 if (!strcmp (name, "length"))
2968 return tn5250_Field_setattr_helper (&self->field->length, sizeof (self->field->length), value);
2969 if (!strcmp (name, "display_width"))
2970 return tn5250_Field_setattr_helper (&self->field->w, sizeof (self->field->w), value);
2971 return 1;
2972 }
2973
2974 statichere PyTypeObject Tn5250_FieldType = {
2975 PyObject_HEAD_INIT(NULL)
2976 0, /* ob_size */
2977 "Field", /* tp_name */
2978 sizeof (Tn5250_Field), /* tp_basicsize */
2979 0, /* tp_itemsize */
2980 /* methods */
2981 (destructor)tn5250_Field_dealloc,/* tp_dealloc */
2982 0, /* tp_print */
2983 (getattrfunc)tn5250_Field_getattr,/* tp_getattr */
2984 (setattrfunc)tn5250_Field_setattr,/* tp_setattr */
2985 0, /* tp_compare */
2986 0, /* tp_repr */
2987 0, /* tp_as_number */
2988 0, /* tp_as_sequence */
2989 0, /* tp_as_mapping */
2990 0, /* tp_hash */
2991 };
2992
2993 /****************************************************************************/
2994 /* PrintSession class */
2995 /****************************************************************************/
2996
2997 static PyObject*
Tn5250_PrintSession_wrap(psess)2998 Tn5250_PrintSession_wrap (psess)
2999 Tn5250PrintSession* psess;
3000 {
3001 Tn5250_PrintSession* self;
3002
3003 if (psess != NULL && psess->script_slot != NULL)
3004 return (PyObject*)psess->script_slot;
3005
3006 self = PyObject_NEW(Tn5250_PrintSession, &Tn5250_PrintSessionType);
3007 if (self == NULL) {
3008 // XXX: decref the psess
3009 return NULL;
3010 }
3011
3012 self->psess = psess;
3013 psess->script_slot = self;
3014 return (PyObject*)self;
3015 }
3016
3017 static PyObject*
tn5250_PrintSession(func_self,args)3018 tn5250_PrintSession (func_self, args)
3019 PyObject* func_self;
3020 PyObject* args;
3021 {
3022 Tn5250PrintSession* psess;
3023
3024 psess = tn5250_print_session_new ();
3025 if (psess == NULL) {
3026 // XXX: Strerror
3027 return NULL;
3028 }
3029
3030 return Tn5250_PrintSession_wrap(psess);
3031 }
3032
3033 static void
tn5250_PrintSession_dealloc(self)3034 tn5250_PrintSession_dealloc (self)
3035 Tn5250_PrintSession* self;
3036 {
3037 // XXX: Reference counting problems.
3038 if (self->psess != NULL)
3039 tn5250_print_session_destroy (self->psess);
3040 }
3041
3042 static PyObject*
tn5250_PrintSession_set_fd(self,args)3043 tn5250_PrintSession_set_fd (self, args)
3044 Tn5250_PrintSession* self;
3045 PyObject* args;
3046 {
3047 SOCKET_TYPE fd;
3048 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3049 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3050 if (!PyArg_ParseTuple(args, "d:PrintSession.set_fd", &fd))
3051 return NULL;
3052 if (self->psess != NULL)
3053 tn5250_print_session_set_fd (self->psess, fd);
3054 Py_INCREF(Py_None);
3055 return Py_None;
3056 }
3057
3058 static PyObject*
tn5250_PrintSession_get_response_code(self,args)3059 tn5250_PrintSession_get_response_code (self, args)
3060 Tn5250_PrintSession* self;
3061 PyObject* args;
3062 {
3063 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3064 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3065 if (!PyArg_ParseTuple(args, ":PrintSession.get_response_code"))
3066 return NULL;
3067 // XXX: Implement
3068 Py_INCREF(Py_None);
3069 return Py_None;
3070 }
3071
3072 static PyObject*
tn5250_PrintSession_set_stream(self,args)3073 tn5250_PrintSession_set_stream (self, args)
3074 Tn5250_PrintSession* self;
3075 PyObject* args;
3076 {
3077 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3078 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3079 if (!PyArg_ParseTuple(args, ":PrintSession.set_stream"))
3080 return NULL;
3081 // XXX: Implement
3082 Py_INCREF(Py_None);
3083 return Py_None;
3084 }
3085
3086 static PyObject*
tn5250_PrintSession_set_output_command(self,args)3087 tn5250_PrintSession_set_output_command (self, args)
3088 Tn5250_PrintSession* self;
3089 PyObject* args;
3090 {
3091 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3092 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3093 if (!PyArg_ParseTuple(args, ":PrintSession.set_output_command"))
3094 return NULL;
3095 // XXX: Implement
3096 Py_INCREF(Py_None);
3097 return Py_None;
3098 }
3099
3100 static PyObject*
tn5250_PrintSession_set_char_map(self,args)3101 tn5250_PrintSession_set_char_map (self, args)
3102 Tn5250_PrintSession* self;
3103 PyObject* args;
3104 {
3105 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3106 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3107 if (!PyArg_ParseTuple(args, ":PrintSession.set_char_map"))
3108 return NULL;
3109 // XXX: Implement
3110 Py_INCREF(Py_None);
3111 return Py_None;
3112 }
3113
3114 static PyObject*
tn5250_PrintSession_main_loop(self,args)3115 tn5250_PrintSession_main_loop (self, args)
3116 Tn5250_PrintSession* self;
3117 PyObject* args;
3118 {
3119 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3120 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3121 if (!PyArg_ParseTuple(args, ":PrintSession.main_loop"))
3122 return NULL;
3123 // XXX: Implement
3124 Py_INCREF(Py_None);
3125 return Py_None;
3126 }
3127
3128 static PyObject*
tn5250_PrintSession_stream(self,args)3129 tn5250_PrintSession_stream (self, args)
3130 Tn5250_PrintSession* self;
3131 PyObject* args;
3132 {
3133 if (self == NULL || !Tn5250_PrintSessionCheck (self))
3134 return PyErr_Format(PyExc_TypeError, "not a PrintSession.");
3135 if (!PyArg_ParseTuple(args, ":PrintSession.stream"))
3136 return NULL;
3137 // XXX: Implement
3138 Py_INCREF(Py_None);
3139 return Py_None;
3140 }
3141
3142
3143 static PyMethodDef Tn5250_PrintSessionMethods[] = {
3144 { "set_fd", tn5250_PrintSession_set_fd, METH_VARARGS },
3145 { "get_response_code",tn5250_PrintSession_get_response_code,METH_VARARGS },
3146 { "set_stream", tn5250_PrintSession_set_stream, METH_VARARGS },
3147 { "set_output_command",tn5250_PrintSession_set_output_command,METH_VARARGS },
3148 { "set_char_map", tn5250_PrintSession_set_char_map, METH_VARARGS },
3149 { "main_loop", tn5250_PrintSession_main_loop, METH_VARARGS },
3150 { "stream", tn5250_PrintSession_stream, METH_VARARGS },
3151 { NULL, NULL }
3152 };
3153
3154 static PyObject*
tn5250_PrintSession_getattr(self,name)3155 tn5250_PrintSession_getattr (self, name)
3156 Tn5250_PrintSession* self;
3157 char *name;
3158 {
3159 return Py_FindMethod (Tn5250_PrintSessionMethods, (PyObject*)self, name);
3160 }
3161
3162 statichere PyTypeObject Tn5250_PrintSessionType = {
3163 PyObject_HEAD_INIT(NULL)
3164 0, /* ob_size */
3165 "PrintSession", /* tp_name */
3166 sizeof (Tn5250_PrintSession), /* tp_basicsize */
3167 0, /* tp_itemsize */
3168 /* methods */
3169 (destructor)tn5250_PrintSession_dealloc,/* tp_dealloc */
3170 0, /* tp_print */
3171 (getattrfunc)tn5250_PrintSession_getattr,/* tp_getattr */
3172 0, /* tp_setattr */
3173 0, /* tp_compare */
3174 0, /* tp_repr */
3175 0, /* tp_as_number */
3176 0, /* tp_as_sequence */
3177 0, /* tp_as_mapping */
3178 0, /* tp_hash */
3179 };
3180
3181 /****************************************************************************/
3182 /* Record class */
3183 /****************************************************************************/
3184
3185 static PyObject*
tn5250_Record(func_self,args)3186 tn5250_Record (func_self, args)
3187 PyObject *func_self;
3188 PyObject *args;
3189 {
3190 Tn5250_Record *self;
3191 if (!PyArg_ParseTuple(args, ":Record"))
3192 return NULL;
3193 self = PyObject_NEW(Tn5250_Record, &Tn5250_RecordType);
3194 if (self == NULL)
3195 return NULL;
3196
3197 self->rec = tn5250_record_new ();
3198 return (PyObject*)self;
3199 }
3200
3201 static PyObject*
tn5250_Record_get_byte(self,args)3202 tn5250_Record_get_byte (self, args)
3203 Tn5250_Record* self;
3204 PyObject *args;
3205 {
3206 int b;
3207 if (self == NULL || !Tn5250_RecordCheck (self))
3208 return PyErr_Format(PyExc_TypeError, "not a Record.");
3209 if (!PyArg_ParseTuple(args, ":Record.get_byte"))
3210 return NULL;
3211 b = tn5250_record_get_byte (self->rec);
3212 return PyInt_FromLong((long)b);
3213 }
3214
3215 static PyObject*
tn5250_Record_unget_byte(self,args)3216 tn5250_Record_unget_byte (self, args)
3217 Tn5250_Record* self;
3218 PyObject *args;
3219 {
3220 if (self == NULL || !Tn5250_RecordCheck (self))
3221 return PyErr_Format(PyExc_TypeError, "not a Record.");
3222 if (!PyArg_ParseTuple(args, ":Record.unget_byte"))
3223 return NULL;
3224 tn5250_record_unget_byte (self->rec);
3225 Py_INCREF(Py_None);
3226 return Py_None;
3227 }
3228
3229 static PyObject*
tn5250_Record_is_chain_end(self,args)3230 tn5250_Record_is_chain_end (self, args)
3231 Tn5250_Record* self;
3232 PyObject *args;
3233 {
3234 if (self == NULL || !Tn5250_RecordCheck (self))
3235 return PyErr_Format(PyExc_TypeError, "not a Record.");
3236 if (!PyArg_ParseTuple(args, ":Record.is_chain_end"))
3237 return NULL;
3238 if (tn5250_record_is_chain_end (self->rec))
3239 return PyInt_FromLong(1);
3240 Py_INCREF(Py_None);
3241 return Py_None;
3242 }
3243
3244 static PyObject*
tn5250_Record_skip_to_end(self,args)3245 tn5250_Record_skip_to_end (self, args)
3246 Tn5250_Record* self;
3247 PyObject* args;
3248 {
3249 if (self == NULL || !Tn5250_RecordCheck (self))
3250 return PyErr_Format(PyExc_TypeError, "not a Record.");
3251 if (!PyArg_ParseTuple(args, ":Record.skip_to_end"))
3252 return NULL;
3253 tn5250_record_skip_to_end (self->rec);
3254 Py_INCREF(Py_None);
3255 return Py_None;
3256 }
3257
3258 static PyObject*
tn5250_Record_length(self,args)3259 tn5250_Record_length (self, args)
3260 Tn5250_Record* self;
3261 PyObject* args;
3262 {
3263 int l;
3264 if (self == NULL || !Tn5250_RecordCheck (self))
3265 return PyErr_Format(PyExc_TypeError, "not a Record.");
3266 if (!PyArg_ParseTuple(args, ":Record.length"))
3267 return NULL;
3268 l = tn5250_record_length (self->rec);
3269 return PyInt_FromLong(l);
3270 }
3271
3272 static PyObject*
tn5250_Record_append_byte(self,args)3273 tn5250_Record_append_byte (self, args)
3274 Tn5250_Record *self;
3275 PyObject* args;
3276 {
3277 int c;
3278 if (self == NULL || !Tn5250_RecordCheck (self))
3279 return PyErr_Format(PyExc_TypeError, "not a Record.");
3280 if (!PyArg_ParseTuple(args, "d:Record.append_byte", &c))
3281 return NULL;
3282 tn5250_record_append_byte (self->rec, c);
3283 Py_INCREF(Py_None);
3284 return Py_None;
3285 }
3286
3287 static PyObject*
tn5250_Record_data(self,args)3288 tn5250_Record_data (self, args)
3289 Tn5250_Record* self;
3290 PyObject* args;
3291 {
3292 char *data;
3293 if (self == NULL || !Tn5250_RecordCheck (self))
3294 return PyErr_Format(PyExc_TypeError, "not a Record.");
3295 if (!PyArg_ParseTuple(args, ":Record.data"))
3296 return NULL;
3297 return PyString_FromStringAndSize (tn5250_record_data (self->rec),
3298 tn5250_record_length (self->rec));
3299 }
3300
3301 static PyObject*
tn5250_Record_set_cur_pos(self,args)3302 tn5250_Record_set_cur_pos (self, args)
3303 Tn5250_Record* self;
3304 PyObject* args;
3305 {
3306 int newpos;
3307 if (self == NULL || !Tn5250_RecordCheck (self))
3308 return PyErr_Format(PyExc_TypeError, "not a Record.");
3309 if (!PyArg_ParseTuple(args, "d:Record.set_cur_pos", &newpos))
3310 return NULL;
3311 tn5250_record_set_cur_pos (self->rec, newpos);
3312 Py_INCREF(Py_None);
3313 return Py_None;
3314 }
3315
3316 static PyObject*
tn5250_Record_opcode(self,args)3317 tn5250_Record_opcode (self, args)
3318 Tn5250_Record* self;
3319 PyObject* args;
3320 {
3321 int op;
3322 if (self == NULL || !Tn5250_RecordCheck (self))
3323 return PyErr_Format(PyExc_TypeError, "not a Record.");
3324 if (!PyArg_ParseTuple(args, ":Record.opcode"))
3325 return NULL;
3326 op = tn5250_record_opcode(self->rec);
3327 return PyInt_FromLong((long)op);
3328 }
3329
3330 static PyObject*
tn5250_Record_flow_type(self,args)3331 tn5250_Record_flow_type (self, args)
3332 Tn5250_Record* self;
3333 PyObject* args;
3334 {
3335 int ft;
3336 if (self == NULL || !Tn5250_RecordCheck (self))
3337 return PyErr_Format(PyExc_TypeError, "not a Record.");
3338 if (!PyArg_ParseTuple(args, ":Record.flow_type"))
3339 return NULL;
3340 ft = tn5250_record_flow_type(self->rec);
3341 return PyInt_FromLong((long)ft);
3342 }
3343
3344 static PyObject*
tn5250_Record_flags(self,args)3345 tn5250_Record_flags (self, args)
3346 Tn5250_Record* self;
3347 PyObject* args;
3348 {
3349 int f;
3350 if (self == NULL || !Tn5250_RecordCheck (self))
3351 return PyErr_Format(PyExc_TypeError, "not a Record.");
3352 if (!PyArg_ParseTuple(args, ":Record.flags"))
3353 return NULL;
3354 f = tn5250_record_flags(self->rec);
3355 return PyInt_FromLong((long)f);
3356 }
3357
3358 static PyObject*
tn5250_Record_sys_request(self,args)3359 tn5250_Record_sys_request (self, args)
3360 Tn5250_Record* self;
3361 PyObject* args;
3362 {
3363 if (self == NULL || !Tn5250_RecordCheck (self))
3364 return PyErr_Format(PyExc_TypeError, "not a Record.");
3365 if (!PyArg_ParseTuple(args, ":Record.sys_request"))
3366 return NULL;
3367 if (tn5250_record_sys_request (self->rec))
3368 return PyInt_FromLong(1);
3369 Py_INCREF(Py_None);
3370 return Py_None;
3371 }
3372
3373 static PyObject*
tn5250_Record_attention(self,args)3374 tn5250_Record_attention (self, args)
3375 Tn5250_Record* self;
3376 PyObject* args;
3377 {
3378 if (self == NULL || !Tn5250_RecordCheck (self))
3379 return PyErr_Format(PyExc_TypeError, "not a Record.");
3380 if (!PyArg_ParseTuple(args, ":Record.attention"))
3381 return NULL;
3382 if (tn5250_record_attention (self->rec))
3383 return PyInt_FromLong(1);
3384 Py_INCREF(Py_None);
3385 return Py_None;
3386 }
3387
3388 static PyObject*
tn5250_Record_dump(self,args)3389 tn5250_Record_dump (self, args)
3390 Tn5250_Record* self;
3391 PyObject* args;
3392 {
3393 if (self == NULL || !Tn5250_RecordCheck (self))
3394 return PyErr_Format(PyExc_TypeError, "not a Record.");
3395 if (!PyArg_ParseTuple(args, ":Record.dump"))
3396 return NULL;
3397 tn5250_record_dump (self->rec);
3398 Py_INCREF(Py_None);
3399 return Py_None;
3400 }
3401
3402 static void
tn5250_Record_dealloc(self)3403 tn5250_Record_dealloc (self)
3404 Tn5250_Record* self;
3405 {
3406 // XXX: Reference counting problems.
3407 if (self->rec != NULL)
3408 tn5250_record_destroy (self->rec);
3409 }
3410
3411 static PyMethodDef Tn5250_RecordMethods[] = {
3412 { "get_byte", tn5250_Record_get_byte, METH_VARARGS },
3413 { "unget_byte", tn5250_Record_unget_byte, METH_VARARGS },
3414 { "is_chain_end", tn5250_Record_is_chain_end, METH_VARARGS },
3415 { "skip_to_end", tn5250_Record_skip_to_end, METH_VARARGS },
3416 { "length", tn5250_Record_length, METH_VARARGS },
3417 { "append_byte", tn5250_Record_append_byte, METH_VARARGS },
3418 { "data", tn5250_Record_data, METH_VARARGS },
3419 { "set_cur_pos", tn5250_Record_set_cur_pos, METH_VARARGS },
3420 { "opcode", tn5250_Record_opcode, METH_VARARGS },
3421 { "flow_type", tn5250_Record_flow_type, METH_VARARGS },
3422 { "flags", tn5250_Record_flags, METH_VARARGS },
3423 { "sys_request", tn5250_Record_sys_request, METH_VARARGS },
3424 { "attention", tn5250_Record_attention, METH_VARARGS },
3425 { "dump", tn5250_Record_dump, METH_VARARGS },
3426 { NULL, NULL }
3427 };
3428
3429 static PyObject*
tn5250_Record_getattr(self,name)3430 tn5250_Record_getattr (self, name)
3431 Tn5250_Record* self;
3432 char *name;
3433 {
3434 return Py_FindMethod (Tn5250_RecordMethods, (PyObject*)self, name);
3435 }
3436
3437 statichere PyTypeObject Tn5250_RecordType = {
3438 PyObject_HEAD_INIT(NULL)
3439 0, /* ob_size */
3440 "Record", /* tp_name */
3441 sizeof (Tn5250_Record), /* tp_basicsize */
3442 0, /* tp_itemsize */
3443 /* methods */
3444 (destructor)tn5250_Record_dealloc, /* tp_dealloc */
3445 0, /* tp_print */
3446 (getattrfunc)tn5250_Record_getattr, /* tp_getattr */
3447 0, /* tp_setattr */
3448 0, /* tp_compare */
3449 0, /* tp_repr */
3450 0, /* tp_as_number */
3451 0, /* tp_as_sequence */
3452 0, /* tp_as_mapping */
3453 0, /* tp_hash */
3454 };
3455
3456 /****************************************************************************/
3457 /* Session class */
3458 /****************************************************************************/
3459
3460 /****************************************************************************/
3461 /* Stream class */
3462 /****************************************************************************/
3463
3464 /****************************************************************************/
3465 /* CharMap class */
3466 /****************************************************************************/
3467
3468 /****************************************************************************/
3469 /* WTDContext class */
3470 /****************************************************************************/
3471
3472 /****************************************************************************/
3473 /* Initialization... */
3474 /****************************************************************************/
3475
3476 static PyMethodDef Tn5250Methods[] = {
3477 { "Config", tn5250_Config, METH_VARARGS },
3478 { "Terminal", tn5250_Terminal, METH_VARARGS },
3479 #ifdef USE_CURSES
3480 { "CursesTerminal", tn5250_CursesTerminal, METH_VARARGS },
3481 #endif /* USE_CURSES */
3482 #ifndef NDEBUG
3483 { "DebugTerminal", tn5250_DebugTerminal, METH_VARARGS },
3484 #endif /* NDEBUG */
3485 #ifdef USE_SLANG
3486 { "SlangTerminal", tn5250_SlangTerminal, METH_VARARGS },
3487 #endif /* USE_SLANG */
3488 { "DisplayBuffer", tn5250_DisplayBuffer, METH_VARARGS },
3489 { "Display", tn5250_Display, METH_VARARGS },
3490 { "Field", tn5250_Field, METH_VARARGS },
3491 { "PrintSession", tn5250_PrintSession, METH_VARARGS },
3492 { "Record", tn5250_Record, METH_VARARGS },
3493 { NULL, NULL }
3494 };
3495
3496 void
inittn5250()3497 inittn5250()
3498 {
3499 PyObject *m, *d;
3500
3501 Tn5250_ConfigType.ob_type = &PyType_Type;
3502
3503 m = Py_InitModule("tn5250", Tn5250Methods);
3504 }
3505
3506 /* vi:set sts=4 sw=4 cindent: */
3507