blob: d15436ce2582b7746e5ab0f66785acecda41c3d7 [file] [log] [blame]
Guido van Rossumf6971e21994-08-30 12:25:20 +00001/***********************************************************
2Copyright 1994 by Lance Ellinghouse,
3Cathedral City, California Republic, United States of America.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the name of Lance Ellinghouse
12not be used in advertising or publicity pertaining to distribution
13of the software without specific, written prior permission.
14
15LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
18INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossumfbea2f31994-08-31 22:05:27 +000025/******************************************************************
26This is a curses implimentation. I have tried to be as complete
27as possible. If there are functions you need that are not included,
28please let me know and/or send me some diffs.
29
30There are 3 basic types exported by this module:
31 1) Screen - This is not currently used
32 2) Window - This is the basic type. This is equivalent to "WINDOW *".
33 3) Pad - This is similar to Window, but works with Pads as defined
34 in curses.
35
36Most of the routines can be looked up using the curses man page.
37
38Here is a list of the currently supported methods and attributes
39in the curses module:
40
41Return Value Func/Attr Description
42--------------------------------------------------------------------------
43StringObject __version__ This returns a string representing
44 the current version of this module
45WindowObject initscr() This initializes the screen for use
46None endwin() Closes down the screen and returns
47 things as they were before calling
48 initscr()
49True/FalseObject isendwin() Has endwin() been called?
50IntObject doupdate() Updates screen and returns number
51 of bytes written to screen
52WindowObject newwin(nlines,ncols,begin_y,begin_x)
53 newwin(begin_y,begin_x)
54 newwin() creates and returns
55 a new window.
56None beep() Beep the screen if possible
57None flash() Flash the screen if possible
58None ungetch(int) Push the int back so next getch()
59 will return it.
60 Note: argument is an INT, not a CHAR
61None flushinp() Flush all input buffers
62None cbreak() Enter cbreak mode
63None nocbreak() Leave cbreak mode
64None echo() Enter echo mode
65None noecho() Leave echo mode
66None nl() Enter nl mode
67None nonl() Leave nl mode
68None raw() Enter raw mode
69None noraw() Leave raw mode
70None intrflush(int) Set or reset interruptable flush
71 mode, int=1 if set, 0 if notset.
72None meta(int) Allow 8 bit or 7 bit chars.
73 int=1 is 8 bit, int=0 is 7 bit
74StringObject keyname(int) return the text representation
75 of a KEY_ value. (see below)
76
77Here is a list of the currently supported methods and attributes
78in the WindowObject:
79
80Return Value Func/Attr Description
81--------------------------------------------------------------------------
82IntObject refresh() Do refresh
83IntObject nooutrefresh() Mark for refresh but wait
84True/False mvwin(new_y,new_x) Move Window
85True/False move(new_y,new_x) Move Cursor
86WindowObject subwin(nlines,ncols,begin_y,begin_x)
87 subwin(begin_y,begin_x)
88True/False addch(y,x,ch,attr)
89 addch(y,x,ch)
90 addch(ch,attr)
91 addch(ch)
92True/False insch(y,x,ch,attr)
93 insch(y,x,ch)
94 insch(ch,attr)
95 insch(ch)
96True/False delch(y,x)
97 delch()
98True/False echochar(ch,attr)
99 echochar(ch)
100True/False addstr(y,x,str,attr)
101 addstr(y,x,str)
102 addstr(str,attr)
103 addstr(str)
104True/False attron(attr)
105True/False attroff(attr)
106True/False attrset(sttr)
107True/False standend()
108True/False standout()
109True/False box(vertch,horch) vertch and horch are INTS
110 box()
111None erase()
112None deleteln()
113None insertln()
114(y,x) getyx()
115(y,x) getbegyx()
116(y,x) getmaxyx()
117None clear()
118None clrtobot()
119None clrtoeol()
120None scroll()
121None touchwin()
122None touchline(start,count)
123IntObject getch(y,x)
124 getch()
125StringObject getstr(y,x)
126 getstr()
127IntObject inch(y,x)
128 inch()
129None clearok(int) int=0 or int=1
130None idlok(int) int=0 or int=1
131None leaveok(int) int=0 or int=1
132None scrollok(int) int=0 or int=1
133None setscrreg(top,bottom)
134None nodelay(int) int=0 or int=1
135None notimeout(int) int=0 or int=1
136******************************************************************/
137
138
Guido van Rossumf6971e21994-08-30 12:25:20 +0000139/* curses module */
140
141#include "allobjects.h"
142#include "fileobject.h"
143#include "modsupport.h"
144
145#include <curses.h>
146
147#include "rename1.h"
148
149typedef struct {
150 PyObject_HEAD
151 SCREEN *scr;
152} PyCursesScreenObject;
153
154typedef struct {
155 PyObject_HEAD
156 WINDOW *win;
157 WINDOW *parent;
158} PyCursesWindowObject;
159
160typedef struct {
161 PyObject_HEAD
162 WINDOW *pad;
163} PyCursesPadObject;
164
165staticforward PyTypeObject PyCursesScreen_Type;
166staticforward PyTypeObject PyCursesWindow_Type;
167staticforward PyTypeObject PyCursesPad_Type;
168
169#define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type)
170#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
171#define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type)
172
173/* Defines */
174PyObject *PyCurses_OK;
175PyObject *PyCurses_ERR;
176
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000177/******************************************************************
178
179Change Log:
180
181Version 1.0: 94/08/30:
182 This is the first release of this software.
183 Released to the Internet via python-list@cwi.nl
184
185******************************************************************/
186char *PyCursesVersion = "1.0 first release"
187
Guido van Rossumf6971e21994-08-30 12:25:20 +0000188/* ------------- SCREEN routines --------------- */
189#ifdef NOT_YET
190static PyObject *
191PyCursesScreen_New(arg)
192 PyObject * arg;
193{
194 char *term_type;
195 PyFileObject *in_fo;
196 PyFileObject *out_fo;
197 PyCursesScreenObject *xp;
198 xp = (PyObject *)PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
199 if (xp == NULL)
200 return NULL;
201 return (PyObject *)xp;
202}
203#endif
204/* ------------- WINDOW routines --------------- */
205static PyObject *
206PyCursesWindow_New(win)
207 WINDOW *win;
208{
209 PyCursesWindowObject *wo;
210 wo = (PyCursesWindowObject *)PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
211 if (wo == NULL)
212 return NULL;
213 wo->win = win;
214 wo->parent = (WINDOW *)NULL;
215 return (PyObject *)wo;
216}
217
218static void
219PyCursesWindow_Dealloc(wo)
220 PyCursesWindowObject *wo;
221{
222 if (wo->win != stdscr)
223 delwin(wo->win);
224 PyMem_DEL(wo);
225}
226
227static PyObject *
228PyCursesWindow_Refresh(self,arg)
229 PyCursesWindowObject *self;
230 PyObject * arg;
231{
232 if (!PyArg_NoArgs(arg))
233 return (PyObject *)NULL;
234 return (PyObject *)PyInt_FromLong(wrefresh(self->win));
235}
236
237static PyObject *
238PyCursesWindow_NoOutRefresh(self,arg)
239 PyCursesWindowObject *self;
240 PyObject * arg;
241{
242 if (!PyArg_NoArgs(arg))
243 return (PyObject *)NULL;
244 return (PyObject *)PyInt_FromLong(wnoutrefresh(self->win));
245}
246
247static PyObject *
248PyCursesWindow_MoveWin(self,arg)
249 PyCursesWindowObject *self;
250 PyObject * arg;
251{
252 int rtn;
253 int x, y;
254 if (!PyArg_Parse(arg,"(ii)", &y, &x))
255 return (PyObject *)NULL;
256 rtn = mvwin(self->win,y,x);
257 if (rtn == OK) {
258 Py_INCREF(PyCurses_OK);
259 return (PyObject *)PyCurses_OK;
260 }
261 Py_INCREF(PyCurses_ERR);
262 return (PyObject *)PyCurses_ERR;
263}
264
265static PyObject *
266PyCursesWindow_Move(self,arg)
267 PyCursesWindowObject *self;
268 PyObject * arg;
269{
270 int rtn;
271 int x, y;
272 if (!PyArg_Parse(arg,"(ii)", &y, &x))
273 return (PyObject *)NULL;
274 rtn = wmove(self->win,y,x);
275 if (rtn == OK) {
276 Py_INCREF(PyCurses_OK);
277 return (PyObject *)PyCurses_OK;
278 }
279 Py_INCREF(PyCurses_ERR);
280 return (PyObject *)PyCurses_ERR;
281}
282
283static PyObject *
284PyCursesWindow_SubWin(self,arg)
285 PyCursesWindowObject *self;
286 PyObject * arg;
287{
288 WINDOW *win;
289 PyCursesWindowObject *rtn_win;
290 int nlines, ncols, begin_y, begin_x;
291 nlines = 0;
292 ncols = 0;
293 if (!PyArg_Parse(arg,
294 "(iiii);nlines,ncols,begin_y,begin_x",
295 &nlines,&ncols,&begin_y,&begin_x))
296 if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
297 return (PyObject *)NULL;
298 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
299 if (win == NULL) {
300 Py_INCREF(Py_None);
301 return (PyObject *)Py_None;
302 }
303 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
304 rtn_win->parent = self->win;
305 return (PyObject *)rtn_win;
306}
307
308static PyObject *
309PyCursesWindow_AddCh(self,arg)
310 PyCursesWindowObject *self;
311 PyObject * arg;
312{
313 int rtn;
314 int x, y;
315 int ch;
316 int attr;
317 int attr_old;
318 int use_xy = TRUE;
319 int use_attr = TRUE;
320 switch (PyTuple_Size(arg)) {
321 case 2:
322 case 4:
323 use_attr = TRUE;
324 break;
325 default:
326 use_attr = FALSE;
327 }
328 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
329 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
330 use_xy = FALSE;
331 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
332 if (!PyArg_Parse(arg,"i;ch", &ch))
333 return (PyObject *)NULL;
334 }
335 }
336 if (use_attr == TRUE) {
337 attr_old = getattrs(self->win);
338 wattrset(self->win,attr);
339 }
340 if (use_xy == TRUE)
341 rtn = mvwaddch(self->win,y,x,ch);
342 else
343 rtn = waddch(self->win,ch);
344 if (use_attr == TRUE)
345 wattrset(self->win,attr_old);
346 if (rtn == OK) {
347 Py_INCREF(PyCurses_OK);
348 return (PyObject *)PyCurses_OK;
349 }
350 Py_INCREF(PyCurses_ERR);
351 return (PyObject *)PyCurses_ERR;
352}
353
354static PyObject *
355PyCursesWindow_InsCh(self,arg)
356 PyCursesWindowObject *self;
357 PyObject * arg;
358{
359 int rtn;
360 int x, y;
361 int ch;
362 int use_xy = TRUE;
363 int attr, attr_old, use_attr = FALSE;
364 switch (PyTuple_Size(arg)) {
365 case 2:
366 case 4:
367 use_attr = TRUE;
368 break;
369 default:
370 use_attr = FALSE;
371 }
372 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
373 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
374 use_xy = FALSE;
375 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
376 if (!PyArg_Parse(arg,"i;ch", &ch))
377 return (PyObject *)NULL;
378 }
379 }
380 if (use_attr == TRUE) {
381 attr_old = getattrs(self->win);
382 wattrset(self->win,attr);
383 }
384 if (use_xy == TRUE)
385 rtn = mvwinsch(self->win,y,x,ch);
386 else
387 rtn = winsch(self->win,ch);
388 if (use_attr == TRUE)
389 wattrset(self->win,attr_old);
390 if (rtn == OK) {
391 Py_INCREF(PyCurses_OK);
392 return (PyObject *)PyCurses_OK;
393 }
394 Py_INCREF(PyCurses_ERR);
395 return (PyObject *)PyCurses_ERR;
396}
397
398static PyObject *
399PyCursesWindow_DelCh(self,arg)
400 PyCursesWindowObject *self;
401 PyObject * arg;
402{
403 int rtn;
404 int x, y;
405 int use_xy = TRUE;
406 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
407 use_xy = FALSE;
408 if (use_xy == TRUE)
409 rtn = mvwdelch(self->win,y,x);
410 else
411 rtn = wdelch(self->win);
412 if (rtn == OK) {
413 Py_INCREF(PyCurses_OK);
414 return (PyObject *)PyCurses_OK;
415 }
416 Py_INCREF(PyCurses_ERR);
417 return (PyObject *)PyCurses_ERR;
418}
419
420static PyObject *
421PyCursesWindow_EchoChar(self,arg)
422 PyCursesWindowObject *self;
423 PyObject * arg;
424{
425 int rtn;
426 int ch;
427 int attr, attr_old, use_attr = TRUE;
428 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) {
429 use_attr = FALSE;
430 if (!PyArg_Parse(arg,"i;ch", &ch))
431 return (PyObject *)NULL;
432 }
433 if (use_attr == TRUE) {
434 attr_old = getattrs(self->win);
435 wattrset(self->win,attr);
436 }
437 rtn = wechochar(self->win,ch);
438 if (use_attr == TRUE)
439 wattrset(self->win,attr_old);
440 if (rtn == OK) {
441 Py_INCREF(PyCurses_OK);
442 return (PyObject *)PyCurses_OK;
443 }
444 Py_INCREF(PyCurses_ERR);
445 return (PyObject *)PyCurses_ERR;
446}
447
448static PyObject *
449PyCursesWindow_AddStr(self,arg)
450 PyCursesWindowObject *self;
451 PyObject * arg;
452{
453 int rtn;
454 int x, y;
455 char *str;
456 int use_xy = TRUE;
457 int attr, attr_old, use_attr = TRUE;
458 switch (PyTuple_Size(arg)) {
459 case 2:
460 case 4:
461 use_attr = TRUE;
462 break;
463 default:
464 use_attr = FALSE;
465 }
466 if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr)) {
467 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str)) {
468 use_xy = FALSE;
469 if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
470 if (!PyArg_Parse(arg,"s;str", &str))
471 return (PyObject *)NULL;
472 }
473 }
474 if (use_attr == TRUE) {
475 attr_old = getattrs(self->win);
476 wattrset(self->win,attr);
477 }
478 if (use_xy == TRUE)
479 rtn = mvwaddstr(self->win,y,x,str);
480 else
481 rtn = waddstr(self->win,str);
482 if (use_attr == TRUE)
483 wattrset(self->win,attr_old);
484 if (rtn == OK) {
485 Py_INCREF(PyCurses_OK);
486 return (PyObject *)PyCurses_OK;
487 }
488 Py_INCREF(PyCurses_ERR);
489 return (PyObject *)PyCurses_ERR;
490}
491
492static PyObject *
493PyCursesWindow_AttrOn(self,arg)
494 PyCursesWindowObject *self;
495 PyObject * arg;
496{
497 int rtn;
498 int ch;
499 if (!PyArg_Parse(arg,"i;attr", &ch))
500 return (PyObject *)NULL;
501 rtn = wattron(self->win,ch);
502 if (rtn == OK) {
503 Py_INCREF(PyCurses_OK);
504 return (PyObject *)PyCurses_OK;
505 }
506 Py_INCREF(PyCurses_ERR);
507 return (PyObject *)PyCurses_ERR;
508}
509
510static PyObject *
511PyCursesWindow_AttrOff(self,arg)
512 PyCursesWindowObject *self;
513 PyObject * arg;
514{
515 int rtn;
516 int ch;
517 if (!PyArg_Parse(arg,"i;attr", &ch))
518 return (PyObject *)NULL;
519 rtn = wattroff(self->win,ch);
520 if (rtn == OK) {
521 Py_INCREF(PyCurses_OK);
522 return (PyObject *)PyCurses_OK;
523 }
524 Py_INCREF(PyCurses_ERR);
525 return (PyObject *)PyCurses_ERR;
526}
527
528static PyObject *
529PyCursesWindow_AttrSet(self,arg)
530 PyCursesWindowObject *self;
531 PyObject * arg;
532{
533 int rtn;
534 int ch;
535 if (!PyArg_Parse(arg,"i;attr", &ch))
536 return (PyObject *)NULL;
537 rtn = wattrset(self->win,ch);
538 if (rtn == OK) {
539 Py_INCREF(PyCurses_OK);
540 return (PyObject *)PyCurses_OK;
541 }
542 Py_INCREF(PyCurses_ERR);
543 return (PyObject *)PyCurses_ERR;
544}
545
546static PyObject *
547PyCursesWindow_StandEnd(self,arg)
548 PyCursesWindowObject *self;
549 PyObject * arg;
550{
551 int rtn;
552 if (!PyArg_NoArgs(arg))
553 return (PyObject *)NULL;
554 rtn = wstandend(self->win);
555 if (rtn == OK) {
556 Py_INCREF(PyCurses_OK);
557 return (PyObject *)PyCurses_OK;
558 }
559 Py_INCREF(PyCurses_ERR);
560 return (PyObject *)PyCurses_ERR;
561}
562
563static PyObject *
564PyCursesWindow_StandOut(self,arg)
565 PyCursesWindowObject *self;
566 PyObject * arg;
567{
568 int rtn;
569 if (!PyArg_NoArgs(arg))
570 return (PyObject *)NULL;
571 rtn = wstandout(self->win);
572 if (rtn == OK) {
573 Py_INCREF(PyCurses_OK);
574 return (PyObject *)PyCurses_OK;
575 }
576 Py_INCREF(PyCurses_ERR);
577 return (PyObject *)PyCurses_ERR;
578}
579
580static PyObject *
581PyCursesWindow_Box(self,arg)
582 PyCursesWindowObject *self;
583 PyObject * arg;
584{
585 int rtn;
586 int ch1=0,ch2=0;
587 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
588 PyErr_Clear();
589 rtn = box(self->win,ch1,ch2);
590 if (rtn == OK) {
591 Py_INCREF(PyCurses_OK);
592 return (PyObject *)PyCurses_OK;
593 }
594 Py_INCREF(PyCurses_ERR);
595 return (PyObject *)PyCurses_ERR;
596}
597
598static PyObject *
599PyCursesWindow_Erase(self,arg)
600 PyCursesWindowObject *self;
601 PyObject * arg;
602{
603 if (!PyArg_NoArgs(arg))
604 return (PyObject *)NULL;
605 werase(self->win);
606 Py_INCREF(Py_None);
607 return (PyObject *)Py_None;
608}
609
610static PyObject *
611PyCursesWindow_DeleteLine(self,arg)
612 PyCursesWindowObject *self;
613 PyObject * arg;
614{
615 if (!PyArg_NoArgs(arg))
616 return (PyObject *)NULL;
617 wdeleteln(self->win);
618 Py_INCREF(Py_None);
619 return (PyObject *)Py_None;
620}
621
622static PyObject *
623PyCursesWindow_InsertLine(self,arg)
624 PyCursesWindowObject *self;
625 PyObject * arg;
626{
627 if (!PyArg_NoArgs(arg))
628 return (PyObject *)NULL;
629 winsertln(self->win);
630 Py_INCREF(Py_None);
631 return (PyObject *)Py_None;
632}
633
634static PyObject *
635PyCursesWindow_GetYX(self,arg)
636 PyCursesWindowObject *self;
637 PyObject * arg;
638{
639 int x, y;
640 if (!PyArg_NoArgs(arg))
641 return (PyObject *)NULL;
642 getyx(self->win,y,x);
643 return (PyObject *)Py_BuildValue("(ii)", y, x);
644}
645
646static PyObject *
647PyCursesWindow_GetBegYX(self,arg)
648 PyCursesWindowObject *self;
649 PyObject * arg;
650{
651 int x, y;
652 if (!PyArg_NoArgs(arg))
653 return (PyObject *)NULL;
654 getbegyx(self->win,y,x);
655 return (PyObject *)Py_BuildValue("(ii)", y, x);
656}
657
658static PyObject *
659PyCursesWindow_GetMaxYX(self,arg)
660 PyCursesWindowObject *self;
661 PyObject * arg;
662{
663 int x, y;
664 if (!PyArg_NoArgs(arg))
665 return (PyObject *)NULL;
666 getmaxyx(self->win,y,x);
667 return (PyObject *)Py_BuildValue("(ii)", y, x);
668}
669
670static PyObject *
671PyCursesWindow_Clear(self,arg)
672 PyCursesWindowObject *self;
673 PyObject * arg;
674{
675 if (!PyArg_NoArgs(arg))
676 return (PyObject *)NULL;
677 wclear(self->win);
678 Py_INCREF(Py_None);
679 return (PyObject *)Py_None;
680}
681
682static PyObject *
683PyCursesWindow_ClearToBottom(self,arg)
684 PyCursesWindowObject *self;
685 PyObject * arg;
686{
687 if (!PyArg_NoArgs(arg))
688 return (PyObject *)NULL;
689 wclrtobot(self->win);
690 Py_INCREF(Py_None);
691 return (PyObject *)Py_None;
692}
693
694static PyObject *
695PyCursesWindow_ClearToEOL(self,arg)
696 PyCursesWindowObject *self;
697 PyObject * arg;
698{
699 if (!PyArg_NoArgs(arg))
700 return (PyObject *)NULL;
701 wclrtoeol(self->win);
702 Py_INCREF(Py_None);
703 return (PyObject *)Py_None;
704}
705
706static PyObject *
707PyCursesWindow_Scroll(self,arg)
708 PyCursesWindowObject *self;
709 PyObject * arg;
710{
711 if (!PyArg_NoArgs(arg))
712 return (PyObject *)NULL;
713 scroll(self->win);
714 Py_INCREF(Py_None);
715 return (PyObject *)Py_None;
716}
717
718static PyObject *
719PyCursesWindow_TouchWin(self,arg)
720 PyCursesWindowObject *self;
721 PyObject * arg;
722{
723 if (!PyArg_NoArgs(arg))
724 return (PyObject *)NULL;
725 touchwin(self->win);
726 Py_INCREF(Py_None);
727 return (PyObject *)Py_None;
728}
729
730static PyObject *
731PyCursesWindow_TouchLine(self,arg)
732 PyCursesWindowObject *self;
733 PyObject * arg;
734{
735 int st, cnt;
736 if (!PyArg_Parse(arg,"(ii);start, count",&st,&cnt))
737 return (PyObject *)NULL;
738 touchline(self->win,st,cnt);
739 Py_INCREF(Py_None);
740 return (PyObject *)Py_None;
741}
742
743static PyObject *
744PyCursesWindow_GetCh(self,arg)
745 PyCursesWindowObject *self;
746 PyObject * arg;
747{
748 int x, y;
749 int use_xy = TRUE;
750 int rtn;
751 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
752 use_xy = FALSE;
753 if (use_xy == TRUE)
754 rtn = mvwgetch(self->win,y,x);
755 else
756 rtn = wgetch(self->win);
757 return (PyObject *)PyInt_FromLong(rtn);
758}
759
760static PyObject *
761PyCursesWindow_GetStr(self,arg)
762 PyCursesWindowObject *self;
763 PyObject * arg;
764{
765 int x, y;
766 int use_xy = TRUE;
767 char rtn[1024]; /* This should be big enough.. I hope */
768 int rtn2;
769 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
770 use_xy = FALSE;
771 if (use_xy == TRUE)
772 rtn2 = mvwgetstr(self->win,y,x,rtn);
773 else
774 rtn2 = wgetstr(self->win,rtn);
775 if (rtn2 == ERR)
776 rtn[0] = 0;
777 return (PyObject *)PyString_FromString(rtn);
778}
779
780static PyObject *
781PyCursesWindow_InCh(self,arg)
782 PyCursesWindowObject *self;
783 PyObject * arg;
784{
785 int x, y;
786 int use_xy = TRUE;
787 int rtn;
788 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
789 use_xy = FALSE;
790 if (use_xy == TRUE)
791 rtn = mvwinch(self->win,y,x);
792 else
793 rtn = winch(self->win);
794 return (PyObject *)PyInt_FromLong(rtn);
795}
796
797static PyObject *
798PyCursesWindow_ClearOk(self,arg)
799 PyCursesWindowObject *self;
800 PyObject * arg;
801{
802 int val;
803 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
804 return (PyObject *)NULL;
805 clearok(self->win,val);
806 Py_INCREF(Py_None);
807 return (PyObject *)Py_None;
808}
809
810static PyObject *
811PyCursesWindow_IdlOk(self,arg)
812 PyCursesWindowObject *self;
813 PyObject * arg;
814{
815 int val;
816 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
817 return (PyObject *)NULL;
818 idlok(self->win,val);
819 Py_INCREF(Py_None);
820 return (PyObject *)Py_None;
821}
822
823static PyObject *
824PyCursesWindow_LeaveOk(self,arg)
825 PyCursesWindowObject *self;
826 PyObject * arg;
827{
828 int val;
829 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
830 return (PyObject *)NULL;
831 leaveok(self->win,val);
832 Py_INCREF(Py_None);
833 return (PyObject *)Py_None;
834}
835
836static PyObject *
837PyCursesWindow_ScrollOk(self,arg)
838 PyCursesWindowObject *self;
839 PyObject * arg;
840{
841 int val;
842 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
843 return (PyObject *)NULL;
844 scrollok(self->win,val);
845 Py_INCREF(Py_None);
846 return (PyObject *)Py_None;
847}
848
849static PyObject *
850PyCursesWindow_SetScrollRegion(self,arg)
851 PyCursesWindowObject *self;
852 PyObject * arg;
853{
854 int x, y;
855 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
856 return (PyObject *)NULL;
857 wsetscrreg(self->win,y,x);
858 Py_INCREF(Py_None);
859 return (PyObject *)Py_None;
860}
861
862static PyObject *
863PyCursesWindow_KeyPad(self,arg)
864 PyCursesWindowObject * self;
865 PyObject * arg;
866{
867 int ch;
868 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
869 return (PyObject *)NULL;
870 keypad(self->win,ch);
871 Py_INCREF(Py_None);
872 return (PyObject *)Py_None;
873}
874
875static PyObject *
876PyCursesWindow_NoDelay(self,arg)
877 PyCursesWindowObject * self;
878 PyObject * arg;
879{
880 int ch;
881 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
882 return (PyObject *)NULL;
883 nodelay(self->win,ch);
884 Py_INCREF(Py_None);
885 return (PyObject *)Py_None;
886}
887
888static PyObject *
889PyCursesWindow_NoTimeout(self,arg)
890 PyCursesWindowObject * self;
891 PyObject * arg;
892{
893 int ch;
894 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
895 return (PyObject *)NULL;
896 notimeout(self->win,ch);
897 Py_INCREF(Py_None);
898 return (PyObject *)Py_None;
899}
900
901static PyMethodDef PyCursesWindow_Methods[] = {
902 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
903 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
904 {"mvwin", (PyCFunction)PyCursesWindow_MoveWin},
905 {"move", (PyCFunction)PyCursesWindow_Move},
906 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
907 {"addch", (PyCFunction)PyCursesWindow_AddCh},
908 {"insch", (PyCFunction)PyCursesWindow_InsCh},
909 {"delch", (PyCFunction)PyCursesWindow_DelCh},
910 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
911 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
912 {"attron", (PyCFunction)PyCursesWindow_AttrOn},
913 {"attroff", (PyCFunction)PyCursesWindow_AttrOff},
914 {"attrset", (PyCFunction)PyCursesWindow_AttrSet},
915 {"standend", (PyCFunction)PyCursesWindow_StandEnd},
916 {"standout", (PyCFunction)PyCursesWindow_StandOut},
917 {"box", (PyCFunction)PyCursesWindow_Box},
918 {"erase", (PyCFunction)PyCursesWindow_Erase},
919 {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine},
920 {"insertln", (PyCFunction)PyCursesWindow_InsertLine},
921 {"getyx", (PyCFunction)PyCursesWindow_GetYX},
922 {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX},
923 {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX},
924 {"clear", (PyCFunction)PyCursesWindow_Clear},
925 {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom},
926 {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL},
927 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
928 {"touchwin", (PyCFunction)PyCursesWindow_TouchWin},
929 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
930 {"getch", (PyCFunction)PyCursesWindow_GetCh},
931 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
932 {"inch", (PyCFunction)PyCursesWindow_InCh},
933 {"clearok", (PyCFunction)PyCursesWindow_ClearOk},
934 {"idlok", (PyCFunction)PyCursesWindow_IdlOk},
935 {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk},
936 {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk},
937 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
938 {"keypad", (PyCFunction)PyCursesWindow_KeyPad},
939 {"nodelay", (PyCFunction)PyCursesWindow_NoDelay},
940 {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout},
941 {NULL, (PyCFunction)NULL} /* sentinel */
942};
943
944static PyObject *
945PyCursesWindow_GetAttr(self, name)
946 PyCursesWindowObject *self;
947 char *name;
948{
949 return findmethod(PyCursesWindow_Methods, (PyObject *)self, name);
950}
951
952/* --------------- PAD routines ---------------- */
953static PyObject *
954PyCursesPad_New(pad)
955 WINDOW *pad;
956{
957 PyCursesPadObject *po;
958 po = (PyCursesPadObject *)PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
959 if (po == NULL)
960 return NULL;
961 po->pad = pad;
962 return (PyObject *)po;
963}
964
965/* -------------------------------------------------------*/
966static PyTypeObject PyCursesScreen_Type = {
967 PyObject_HEAD_INIT(&PyType_Type)
968 0, /*ob_size*/
969 "curses screen", /*tp_name*/
970 sizeof(PyCursesScreenObject), /*tp_basicsize*/
971 0, /*tp_itemsize*/
972 /* methods */
973 (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
974 0, /*tp_print*/
975 (getattrfunc)0, /*tp_getattr*/
976 (setattrfunc)0, /*tp_setattr*/
977 0, /*tp_compare*/
978 0, /*tp_repr*/
979 0, /*tp_as_number*/
980 0, /*tp_as_sequence*/
981 0, /*tp_as_mapping*/
982 0, /*tp_hash*/
983};
984
985static PyTypeObject PyCursesWindow_Type = {
986 PyObject_HEAD_INIT(&PyType_Type)
987 0, /*ob_size*/
988 "curses window", /*tp_name*/
989 sizeof(PyCursesWindowObject), /*tp_basicsize*/
990 0, /*tp_itemsize*/
991 /* methods */
992 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
993 0, /*tp_print*/
994 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
995 (setattrfunc)0, /*tp_setattr*/
996 0, /*tp_compare*/
997 0, /*tp_repr*/
998 0, /*tp_as_number*/
999 0, /*tp_as_sequence*/
1000 0, /*tp_as_mapping*/
1001 0, /*tp_hash*/
1002};
1003
1004static PyTypeObject PyCursesPad_Type = {
1005 PyObject_HEAD_INIT(&PyType_Type)
1006 0, /*ob_size*/
1007 "curses pad", /*tp_name*/
1008 sizeof(PyCursesPadObject), /*tp_basicsize*/
1009 0, /*tp_itemsize*/
1010 /* methods */
1011 (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
1012 0, /*tp_print*/
1013 (getattrfunc)0, /*tp_getattr*/
1014 (setattrfunc)0, /*tp_setattr*/
1015 0, /*tp_compare*/
1016 0, /*tp_repr*/
1017 0, /*tp_as_number*/
1018 0, /*tp_as_sequence*/
1019 0, /*tp_as_mapping*/
1020 0, /*tp_hash*/
1021};
1022
1023/* -------------------------------------------------------*/
1024
1025static PyObject *
1026PyCurses_InitScr(self, args)
1027 PyObject * self;
1028 PyObject * args;
1029{
1030 static int already_inited = FALSE;
1031 if (!PyArg_NoArgs(args))
1032 return (PyObject *)NULL;
1033 if (already_inited == TRUE) {
1034 wrefresh(stdscr);
1035 return (PyObject *)PyCursesWindow_New(stdscr);
1036 }
1037 already_inited = TRUE;
1038 return (PyObject *)PyCursesWindow_New(initscr());
1039}
1040
1041static PyObject *
1042PyCurses_EndWin(self, args)
1043 PyObject * self;
1044 PyObject * args;
1045{
1046 if (!PyArg_NoArgs(args))
1047 return (PyObject *)NULL;
1048 endwin();
1049 Py_INCREF(Py_None);
1050 return Py_None;
1051}
1052
1053static PyObject *
1054PyCurses_IsEndWin(self, args)
1055 PyObject * self;
1056 PyObject * args;
1057{
1058 if (!PyArg_NoArgs(args))
1059 return (PyObject *)NULL;
1060 if (isendwin() == FALSE) {
1061 Py_INCREF(Py_False);
1062 return Py_False;
1063 }
1064 Py_INCREF(Py_True);
1065 return Py_True;
1066}
1067
1068static PyObject *
1069PyCurses_DoUpdate(self,arg)
1070 PyObject * self;
1071 PyObject * arg;
1072{
1073 if (!PyArg_NoArgs(arg))
1074 return (PyObject *)NULL;
1075 return (PyObject *)PyInt_FromLong(doupdate());
1076}
1077
1078static PyObject *
1079PyCurses_NewWindow(self,arg)
1080 PyObject * self;
1081 PyObject * arg;
1082{
1083 WINDOW *win;
1084 int nlines, ncols, begin_y, begin_x;
1085 nlines = 0;
1086 ncols = 0;
1087 if (!PyArg_Parse(arg,
1088 "(iiii);nlines,ncols,begin_y,begin_x",
1089 &nlines,&ncols,&begin_y,&begin_x))
1090 if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
1091 return (PyObject *)NULL;
1092 win = newwin(nlines,ncols,begin_y,begin_x);
1093 if (win == NULL) {
1094 Py_INCREF(Py_None);
1095 return (PyObject *)Py_None;
1096 }
1097 return (PyObject *)PyCursesWindow_New(win);
1098}
1099
1100static PyObject *
1101PyCurses_Beep(self,arg)
1102 PyObject * self;
1103 PyObject * arg;
1104{
1105 if (!PyArg_NoArgs(arg))
1106 return (PyObject *)NULL;
1107 beep();
1108 Py_INCREF(Py_None);
1109 return (PyObject *)Py_None;
1110}
1111
1112static PyObject *
1113PyCurses_Flash(self,arg)
1114 PyObject * self;
1115 PyObject * arg;
1116{
1117 if (!PyArg_NoArgs(arg))
1118 return (PyObject *)NULL;
1119 flash();
1120 Py_INCREF(Py_None);
1121 return (PyObject *)Py_None;
1122}
1123
1124static PyObject *
1125PyCurses_UngetCh(self,arg)
1126 PyObject * self;
1127 PyObject * arg;
1128{
1129 int ch;
1130 if (!PyArg_Parse(arg,"i;integer",&ch))
1131 return (PyObject *)NULL;
1132 ungetch(ch);
1133 Py_INCREF(Py_None);
1134 return (PyObject *)Py_None;
1135}
1136
1137static PyObject *
1138PyCurses_FlushInp(self,arg)
1139 PyObject * self;
1140 PyObject * arg;
1141{
1142 if (!PyArg_NoArgs(arg))
1143 return (PyObject *)NULL;
1144 flushinp();
1145 Py_INCREF(Py_None);
1146 return (PyObject *)Py_None;
1147}
1148
1149static PyObject *
1150PyCurses_CBreak(self,arg)
1151 PyObject * self;
1152 PyObject * arg;
1153{
1154 if (!PyArg_NoArgs(arg))
1155 return (PyObject *)NULL;
1156 cbreak();
1157 Py_INCREF(Py_None);
1158 return (PyObject *)Py_None;
1159}
1160
1161static PyObject *
1162PyCurses_NoCBreak(self,arg)
1163 PyObject * self;
1164 PyObject * arg;
1165{
1166 if (!PyArg_NoArgs(arg))
1167 return (PyObject *)NULL;
1168 nocbreak();
1169 Py_INCREF(Py_None);
1170 return (PyObject *)Py_None;
1171}
1172
1173static PyObject *
1174PyCurses_Echo(self,arg)
1175 PyObject * self;
1176 PyObject * arg;
1177{
1178 if (!PyArg_NoArgs(arg))
1179 return (PyObject *)NULL;
1180 echo();
1181 Py_INCREF(Py_None);
1182 return (PyObject *)Py_None;
1183}
1184
1185static PyObject *
1186PyCurses_NoEcho(self,arg)
1187 PyObject * self;
1188 PyObject * arg;
1189{
1190 if (!PyArg_NoArgs(arg))
1191 return (PyObject *)NULL;
1192 noecho();
1193 Py_INCREF(Py_None);
1194 return (PyObject *)Py_None;
1195}
1196
1197static PyObject *
1198PyCurses_Nl(self,arg)
1199 PyObject * self;
1200 PyObject * arg;
1201{
1202 if (!PyArg_NoArgs(arg))
1203 return (PyObject *)NULL;
1204 nl();
1205 Py_INCREF(Py_None);
1206 return (PyObject *)Py_None;
1207}
1208
1209static PyObject *
1210PyCurses_NoNl(self,arg)
1211 PyObject * self;
1212 PyObject * arg;
1213{
1214 if (!PyArg_NoArgs(arg))
1215 return (PyObject *)NULL;
1216 nonl();
1217 Py_INCREF(Py_None);
1218 return (PyObject *)Py_None;
1219}
1220
1221static PyObject *
1222PyCurses_Raw(self,arg)
1223 PyObject * self;
1224 PyObject * arg;
1225{
1226 if (!PyArg_NoArgs(arg))
1227 return (PyObject *)NULL;
1228 raw();
1229 Py_INCREF(Py_None);
1230 return (PyObject *)Py_None;
1231}
1232
1233static PyObject *
1234PyCurses_NoRaw(self,arg)
1235 PyObject * self;
1236 PyObject * arg;
1237{
1238 if (!PyArg_NoArgs(arg))
1239 return (PyObject *)NULL;
1240 noraw();
1241 Py_INCREF(Py_None);
1242 return (PyObject *)Py_None;
1243}
1244
1245static PyObject *
1246PyCurses_IntrFlush(self,arg)
1247 PyObject * self;
1248 PyObject * arg;
1249{
1250 int ch;
1251 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1252 return (PyObject *)NULL;
1253 intrflush(NULL,ch);
1254 Py_INCREF(Py_None);
1255 return (PyObject *)Py_None;
1256}
1257
1258static PyObject *
1259PyCurses_Meta(self,arg)
1260 PyObject * self;
1261 PyObject * arg;
1262{
1263 int ch;
1264 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1265 return (PyObject *)NULL;
1266 meta(NULL,ch);
1267 Py_INCREF(Py_None);
1268 return (PyObject *)Py_None;
1269}
1270
1271static PyObject *
1272PyCurses_KeyName(self,arg)
1273 PyObject * self;
1274 PyObject * arg;
1275{
1276 int ch;
1277 if (!PyArg_Parse(arg,"i",&ch))
1278 return (PyObject *)NULL;
1279 return PyString_FromString((char *)keyname(ch));
1280}
1281
1282#ifdef NOT_YET
1283static PyObject *
1284PyCurses_NewTerm(self, args)
1285 PyObject * self;
1286 PyObject * args;
1287{
1288}
1289
1290static PyObject *
1291PyCurses_SetTerm(self, args)
1292 PyObject * self;
1293 PyObject * args;
1294{
1295}
1296#endif
1297
1298/* List of functions defined in the module */
1299
1300static PyMethodDef PyCurses_methods[] = {
1301 {"initscr", (PyCFunction)PyCurses_InitScr},
1302 {"endwin", (PyCFunction)PyCurses_EndWin},
1303 {"isendwin", (PyCFunction)PyCurses_IsEndWin},
1304 {"doupdate", (PyCFunction)PyCurses_DoUpdate},
1305 {"newwin", (PyCFunction)PyCurses_NewWindow},
1306 {"beep", (PyCFunction)PyCurses_Beep},
1307 {"flash", (PyCFunction)PyCurses_Flash},
1308 {"ungetch", (PyCFunction)PyCurses_UngetCh},
1309 {"flushinp", (PyCFunction)PyCurses_FlushInp},
1310 {"cbreak", (PyCFunction)PyCurses_CBreak},
1311 {"nocbreak", (PyCFunction)PyCurses_NoCBreak},
1312 {"echo", (PyCFunction)PyCurses_Echo},
1313 {"noecho", (PyCFunction)PyCurses_NoEcho},
1314 {"nl", (PyCFunction)PyCurses_Nl},
1315 {"nonl", (PyCFunction)PyCurses_NoNl},
1316 {"raw", (PyCFunction)PyCurses_Raw},
1317 {"noraw", (PyCFunction)PyCurses_NoRaw},
1318 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
1319 {"meta", (PyCFunction)PyCurses_Meta},
1320 {"keyname", (PyCFunction)PyCurses_KeyName},
1321#ifdef NOT_YET
1322 {"newterm", (PyCFunction)PyCurses_NewTerm},
1323 {"set_term", (PyCFunction)PyCurses_SetTerm},
1324#endif
1325 {NULL, NULL} /* sentinel */
1326};
1327
1328/* Initialization function for the module */
1329
1330void
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001331initncurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001332{
1333 PyObject *m, *d, *x;
1334
1335 /* Create the module and add the functions */
1336 m = Py_InitModule("ncurses", PyCurses_methods);
1337
1338 PyCurses_OK = Py_True;
1339 PyCurses_ERR = Py_False;
1340 Py_INCREF(PyCurses_OK);
1341 Py_INCREF(PyCurses_ERR);
1342 /* Add some symbolic constants to the module */
1343 d = PyModule_GetDict(m);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001344
1345 /* Make the version available */
1346 PyDict_SetItemString(d,"__version__",
1347 PyString_FromString(PyCursesVersion));
1348
Guido van Rossumf6971e21994-08-30 12:25:20 +00001349 /* Here are some defines */
1350 PyDict_SetItemString(d,"OK", PyCurses_OK);
1351 PyDict_SetItemString(d,"ERR",PyCurses_ERR);
1352
1353#define SetDictChar(string,ch) \
1354 PyDict_SetItemString(d,string,PyInt_FromLong(ch));
1355
1356 /* Here are some graphic symbols you can use */
1357 SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
1358 SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
1359 SetDictChar("ACS_LLCORNER",(ACS_LLCORNER));
1360 SetDictChar("ACS_URCORNER",(ACS_URCORNER));
1361 SetDictChar("ACS_LRCORNER",(ACS_LRCORNER));
1362 SetDictChar("ACS_RTEE", (ACS_RTEE));
1363 SetDictChar("ACS_LTEE", (ACS_LTEE));
1364 SetDictChar("ACS_BTEE", (ACS_BTEE));
1365 SetDictChar("ACS_TTEE", (ACS_TTEE));
1366 SetDictChar("ACS_HLINE", (ACS_HLINE));
1367 SetDictChar("ACS_VLINE", (ACS_VLINE));
1368 SetDictChar("ACS_PLUS", (ACS_PLUS));
1369 SetDictChar("ACS_S1", (ACS_S1));
1370 SetDictChar("ACS_S9", (ACS_S9));
1371 SetDictChar("ACS_DIAMOND", (ACS_DIAMOND));
1372 SetDictChar("ACS_CKBOARD", (ACS_CKBOARD));
1373 SetDictChar("ACS_DEGREE", (ACS_DEGREE));
1374 SetDictChar("ACS_PLMINUS", (ACS_PLMINUS));
1375 SetDictChar("ACS_BULLET", (ACS_BULLET));
1376 SetDictChar("ACS_LARROW", (ACS_RARROW));
1377 SetDictChar("ACS_DARROW", (ACS_DARROW));
1378 SetDictChar("ACS_UARROW", (ACS_UARROW));
1379 SetDictChar("ACS_BOARD", (ACS_BOARD));
1380 SetDictChar("ACS_LANTERN", (ACS_LANTERN));
1381 SetDictChar("ACS_BLOCK", (ACS_BLOCK));
1382
1383 /* Here are some attributes you can add to chars to print */
1384 PyDict_SetItemString(d, "A_NORMAL", PyInt_FromLong(A_NORMAL));
1385 PyDict_SetItemString(d, "A_STANDOUT", PyInt_FromLong(A_STANDOUT));
1386 PyDict_SetItemString(d, "A_UNDERLINE", PyInt_FromLong(A_UNDERLINE));
1387 PyDict_SetItemString(d, "A_REVERSE", PyInt_FromLong(A_REVERSE));
1388 PyDict_SetItemString(d, "A_BLINK", PyInt_FromLong(A_BLINK));
1389 PyDict_SetItemString(d, "A_DIM", PyInt_FromLong(A_DIM));
1390 PyDict_SetItemString(d, "A_BOLD", PyInt_FromLong(A_BOLD));
1391 PyDict_SetItemString(d, "A_ALTCHARSET",PyInt_FromLong(A_ALTCHARSET));
1392
1393 /* Now set everything up for KEY_ variables */
1394 {
1395 int key;
1396 char *key_n;
1397 char *key_n2;
1398 for (key=KEY_MIN;key < KEY_MAX; key++) {
1399 key_n = (char *)keyname(key);
1400 if (strcmp(key_n,"UNKNOWN KEY")==0)
1401 continue;
1402 if (strncmp(key_n,"KEY_F(",6)==0) {
1403 char *p1, *p2;
1404 key_n2 = malloc(strlen(key_n)+1);
1405 p1 = key_n;
1406 p2 = key_n2;
1407 while (*p1) {
1408 if (*p1 != '(' && *p1 != ')') {
1409 *p2 = *p1;
1410 p2++;
1411 }
1412 p1++;
1413 }
1414 *p2 = (char)0;
1415 } else
1416 key_n2 = key_n;
1417 PyDict_SetItemString(d,key_n2,PyInt_FromLong(key));
1418 if (key_n2 != key_n)
1419 free(key_n2);
1420 }
1421 SetDictChar("KEY_MIN",KEY_MIN);
1422 SetDictChar("KEY_MAX",KEY_MAX);
1423 }
1424
1425 /* Check for errors */
1426 if (PyErr_Occurred())
1427 Py_FatalError("can't initialize module syslog");
1428}