This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 5
[perl5.git] / ext / curses / bsdcurses.mus
CommitLineData
79072805 1/* $RCSfile: bsdcurses.mus,v $$Revision: 4.1 $$Date: 92/08/07 18:28:50 $
f1ca563b
LW
2 *
3 * $Log: bsdcurses.mus,v $
79072805
LW
4 * Revision 4.1 92/08/07 18:28:50 lwall
5 *
68decaef
LW
6 * Revision 4.0.1.2 92/06/08 16:05:28 lwall
7 * patch20: &getcap eventually dumped core in bsdcurses
8 *
f1ca563b
LW
9 * Revision 4.0.1.1 91/11/05 19:04:53 lwall
10 * initial checkin
11 *
12 * Revision 4.0 91/03/20 01:56:13 lwall
13 * 4.0 baseline.
14 *
15 * Revision 3.0.1.1 90/08/09 04:05:21 lwall
16 * patch19: Initial revision
17 *
18 */
19
20#include "EXTERN.h"
21#include "perl.h"
22
23char *savestr();
24
25#include <curses.h>
26
27static enum uservars {
28 UV_curscr,
29 UV_stdscr,
30 UV_Def_term,
31 UV_My_term,
32 UV_ttytype,
33 UV_LINES,
34 UV_COLS,
35 UV_ERR,
36 UV_OK,
37};
38
39static enum usersubs {
40 US_addch,
41 US_waddch,
42 US_addstr,
43 US_waddstr,
44 US_box,
45 US_clear,
46 US_wclear,
47 US_clearok,
48 US_clrtobot,
49 US_wclrtobot,
50 US_clrtoeol,
51 US_wclrtoeol,
52 US_delch,
53 US_wdelch,
54 US_deleteln,
55 US_wdeleteln,
56 US_erase,
57 US_werase,
58 US_flushok,
59 US_idlok,
60 US_insch,
61 US_winsch,
62 US_insertln,
63 US_winsertln,
64 US_move,
65 US_wmove,
66 US_overlay,
67 US_overwrite,
68 US_printw,
69 US_wprintw,
70 US_refresh,
71 US_wrefresh,
72 US_standout,
73 US_wstandout,
74 US_standend,
75 US_wstandend,
76 US_cbreak,
77 US_nocbreak,
78 US_echo,
79 US_noecho,
80 US_getch,
81 US_wgetch,
82 US_getstr,
83 US_wgetstr,
84 US_raw,
85 US_noraw,
86 US_scanw,
87 US_wscanw,
88 US_baudrate,
89 US_delwin,
90 US_endwin,
91 US_erasechar,
92 US_getcap,
93 US_getyx,
94 US_inch,
95 US_winch,
96 US_initscr,
97 US_killchar,
98 US_leaveok,
99 US_longname,
100 US_fullname,
101 US_mvwin,
102 US_newwin,
103 US_nl,
104 US_nonl,
105 US_scrollok,
106 US_subwin,
107 US_touchline,
108 US_touchoverlap,
109 US_touchwin,
110 US_unctrl,
111 US_gettmode,
112 US_mvcur,
113 US_scroll,
114 US_savetty,
115 US_resetty,
116 US_setterm,
117 US_tstp,
118 US__putchar,
119 US_testcallback,
120};
121
122static int usersub();
123static int userset();
124static int userval();
125
126int
127init_curses()
128{
129 struct ufuncs uf;
130 char *filename = "curses.c";
131
132 uf.uf_set = userset;
133 uf.uf_val = userval;
134
135#define MAGICVAR(name, ix) uf.uf_index = ix, magicname(name, &uf, sizeof uf)
136
137 MAGICVAR("curscr", UV_curscr);
138 MAGICVAR("stdscr", UV_stdscr);
139 MAGICVAR("Def_term",UV_Def_term);
140 MAGICVAR("My_term", UV_My_term);
141 MAGICVAR("ttytype", UV_ttytype);
142 MAGICVAR("LINES", UV_LINES);
143 MAGICVAR("COLS", UV_COLS);
144 MAGICVAR("ERR", UV_ERR);
145 MAGICVAR("OK", UV_OK);
146
147 make_usub("addch", US_addch, usersub, filename);
148 make_usub("waddch", US_waddch, usersub, filename);
149 make_usub("addstr", US_addstr, usersub, filename);
150 make_usub("waddstr", US_waddstr, usersub, filename);
151 make_usub("box", US_box, usersub, filename);
152 make_usub("clear", US_clear, usersub, filename);
153 make_usub("wclear", US_wclear, usersub, filename);
154 make_usub("clearok", US_clearok, usersub, filename);
155 make_usub("clrtobot", US_clrtobot, usersub, filename);
156 make_usub("wclrtobot", US_wclrtobot, usersub, filename);
157 make_usub("clrtoeol", US_clrtoeol, usersub, filename);
158 make_usub("wclrtoeol", US_wclrtoeol, usersub, filename);
159 make_usub("delch", US_delch, usersub, filename);
160 make_usub("wdelch", US_wdelch, usersub, filename);
161 make_usub("deleteln", US_deleteln, usersub, filename);
162 make_usub("wdeleteln", US_wdeleteln, usersub, filename);
163 make_usub("erase", US_erase, usersub, filename);
164 make_usub("werase", US_werase, usersub, filename);
165 make_usub("flushok", US_flushok, usersub, filename);
166 make_usub("idlok", US_idlok, usersub, filename);
167 make_usub("insch", US_insch, usersub, filename);
168 make_usub("winsch", US_winsch, usersub, filename);
169 make_usub("insertln", US_insertln, usersub, filename);
170 make_usub("winsertln", US_winsertln, usersub, filename);
171 make_usub("move", US_move, usersub, filename);
172 make_usub("wmove", US_wmove, usersub, filename);
173 make_usub("overlay", US_overlay, usersub, filename);
174 make_usub("overwrite", US_overwrite, usersub, filename);
175 make_usub("printw", US_printw, usersub, filename);
176 make_usub("wprintw", US_wprintw, usersub, filename);
177 make_usub("refresh", US_refresh, usersub, filename);
178 make_usub("wrefresh", US_wrefresh, usersub, filename);
179 make_usub("standout", US_standout, usersub, filename);
180 make_usub("wstandout", US_wstandout, usersub, filename);
181 make_usub("standend", US_standend, usersub, filename);
182 make_usub("wstandend", US_wstandend, usersub, filename);
183 make_usub("cbreak", US_cbreak, usersub, filename);
184 make_usub("nocbreak", US_nocbreak, usersub, filename);
185 make_usub("echo", US_echo, usersub, filename);
186 make_usub("noecho", US_noecho, usersub, filename);
187 make_usub("getch", US_getch, usersub, filename);
188 make_usub("wgetch", US_wgetch, usersub, filename);
189 make_usub("getstr", US_getstr, usersub, filename);
190 make_usub("wgetstr", US_wgetstr, usersub, filename);
191 make_usub("raw", US_raw, usersub, filename);
192 make_usub("noraw", US_noraw, usersub, filename);
193 make_usub("scanw", US_scanw, usersub, filename);
194 make_usub("wscanw", US_wscanw, usersub, filename);
195 make_usub("baudrate", US_baudrate, usersub, filename);
196 make_usub("delwin", US_delwin, usersub, filename);
197 make_usub("endwin", US_endwin, usersub, filename);
198 make_usub("erasechar", US_erasechar, usersub, filename);
199 make_usub("getcap", US_getcap, usersub, filename);
200 make_usub("getyx", US_getyx, usersub, filename);
201 make_usub("inch", US_inch, usersub, filename);
202 make_usub("winch", US_winch, usersub, filename);
203 make_usub("initscr", US_initscr, usersub, filename);
204 make_usub("killchar", US_killchar, usersub, filename);
205 make_usub("leaveok", US_leaveok, usersub, filename);
206 make_usub("longname", US_longname, usersub, filename);
207 make_usub("fullname", US_fullname, usersub, filename);
208 make_usub("mvwin", US_mvwin, usersub, filename);
209 make_usub("newwin", US_newwin, usersub, filename);
210 make_usub("nl", US_nl, usersub, filename);
211 make_usub("nonl", US_nonl, usersub, filename);
212 make_usub("scrollok", US_scrollok, usersub, filename);
213 make_usub("subwin", US_subwin, usersub, filename);
214 make_usub("touchline", US_touchline, usersub, filename);
215 make_usub("touchoverlap", US_touchoverlap,usersub, filename);
216 make_usub("touchwin", US_touchwin, usersub, filename);
217 make_usub("unctrl", US_unctrl, usersub, filename);
218 make_usub("gettmode", US_gettmode, usersub, filename);
219 make_usub("mvcur", US_mvcur, usersub, filename);
220 make_usub("scroll", US_scroll, usersub, filename);
221 make_usub("savetty", US_savetty, usersub, filename);
222 make_usub("resetty", US_resetty, usersub, filename);
223 make_usub("setterm", US_setterm, usersub, filename);
224 make_usub("tstp", US_tstp, usersub, filename);
225 make_usub("_putchar", US__putchar, usersub, filename);
226 make_usub("testcallback", US_testcallback,usersub, filename);
227};
228
229static int
230usersub(ix, sp, items)
231int ix;
232register int sp;
233register int items;
234{
235 STR **st = stack->ary_array + sp;
236 register int i;
237 register char *tmps;
238 register STR *Str; /* used in str_get and str_gnum macros */
239
240 switch (ix) {
241CASE int addch
242I char ch
243END
244
245CASE int waddch
246I WINDOW* win
247I char ch
248END
249
250CASE int addstr
251I char* str
252END
253
254CASE int waddstr
255I WINDOW* win
256I char* str
257END
258
259CASE int box
260I WINDOW* win
261I char vert
262I char hor
263END
264
265CASE int clear
266END
267
268CASE int wclear
269I WINDOW* win
270END
271
272CASE int clearok
273I WINDOW* win
274I bool boolf
275END
276
277CASE int clrtobot
278END
279
280CASE int wclrtobot
281I WINDOW* win
282END
283
284CASE int clrtoeol
285END
286
287CASE int wclrtoeol
288I WINDOW* win
289END
290
291CASE int delch
292END
293
294CASE int wdelch
295I WINDOW* win
296END
297
298CASE int deleteln
299END
300
301CASE int wdeleteln
302I WINDOW* win
303END
304
305CASE int erase
306END
307
308CASE int werase
309I WINDOW* win
310END
311
312CASE int flushok
313I WINDOW* win
314I bool boolf
315END
316
317CASE int idlok
318I WINDOW* win
319I bool boolf
320END
321
322CASE int insch
323I char c
324END
325
326CASE int winsch
327I WINDOW* win
328I char c
329END
330
331CASE int insertln
332END
333
334CASE int winsertln
335I WINDOW* win
336END
337
338CASE int move
339I int y
340I int x
341END
342
343CASE int wmove
344I WINDOW* win
345I int y
346I int x
347END
348
349CASE int overlay
350I WINDOW* win1
351I WINDOW* win2
352END
353
354CASE int overwrite
355I WINDOW* win1
356I WINDOW* win2
357END
358
359 case US_printw:
360 if (items < 1)
361 fatal("Usage: &printw($fmt, $arg1, $arg2, ... )");
362 else {
363 int retval;
364 STR* str = str_new(0);
365
79072805 366 do_sprintf(str, items, st + 1);
f1ca563b
LW
367 retval = addstr(str->str_ptr);
368 str_numset(st[0], (double) retval);
369 str_free(str);
370 }
371 return sp;
372
373 case US_wprintw:
374 if (items < 2)
375 fatal("Usage: &wprintw($win, $fmt, $arg1, $arg2, ... )");
376 else {
377 int retval;
378 STR* str = str_new(0);
379 WINDOW* win = *(WINDOW**) str_get(st[1]);
380
381 do_sprintf(str, items - 1, st + 1);
382 retval = waddstr(win, str->str_ptr);
383 str_numset(st[0], (double) retval);
384 str_free(str);
385 }
386 return sp;
387
388CASE int refresh
389END
390
391CASE int wrefresh
392I WINDOW* win
393END
394
395CASE int standout
396END
397
398CASE int wstandout
399I WINDOW* win
400END
401
402CASE int standend
403END
404
405CASE int wstandend
406I WINDOW* win
407END
408
409CASE int cbreak
410END
411
412CASE int nocbreak
413END
414
415CASE int echo
416END
417
418CASE int noecho
419END
420
421 case US_getch:
422 if (items != 0)
423 fatal("Usage: &getch()");
424 else {
425 int retval;
426 char retch;
427
428 retval = getch();
429 if (retval == EOF)
430 st[0] = &str_undef;
431 else {
432 retch = retval;
433 str_nset(st[0], &retch, 1);
434 }
435 }
436 return sp;
437
438 case US_wgetch:
439 if (items != 1)
440 fatal("Usage: &wgetch($win)");
441 else {
442 int retval;
443 char retch;
444 WINDOW* win = *(WINDOW**) str_get(st[1]);
445
446 retval = wgetch(win);
447 if (retval == EOF)
448 st[0] = &str_undef;
449 else {
450 retch = retval;
451 str_nset(st[0], &retch, 1);
452 }
453 }
454 return sp;
455
456CASE int getstr
457IO char* str
458END
459
460CASE int wgetstr
461I WINDOW* win
462IO char* str
463END
464
465CASE int raw
466END
467
468CASE int noraw
469END
470
471CASE int baudrate
472END
473
474CASE int delwin
475I WINDOW* win
476END
477
478CASE int endwin
479END
480
481CASE int erasechar
482END
483
68decaef
LW
484 case US_getcap:
485 if (items != 1)
486 fatal("Usage: &getcap($str)");
487 else {
488 char* retval;
489 char* str = (char*) str_get(st[1]);
490 char output[50], *outputp = output;
491
492 retval = tgetstr(str, &outputp);
493 str_set(st[0], (char*) retval);
494 }
495 return sp;
f1ca563b
LW
496
497 case US_getyx:
498 if (items != 3)
499 fatal("Usage: &getyx($win, $y, $x)");
500 else {
501 int retval;
502 STR* str = str_new(0);
503 WINDOW* win = *(WINDOW**) str_get(st[1]);
504 int y;
505 int x;
506
507 do_sprintf(str, items - 1, st + 1);
508 retval = getyx(win, y, x);
509 str_numset(st[2], (double)y);
510 str_numset(st[3], (double)x);
511 str_numset(st[0], (double) retval);
512 str_free(str);
513 }
514 return sp;
515
516
517CASE int inch
518END
519
520CASE int winch
521I WINDOW* win
522END
523
524CASE WINDOW* initscr
525END
526
527CASE int killchar
528END
529
530CASE int leaveok
531I WINDOW* win
532I bool boolf
533END
534
535CASE char* longname
536I char* termbuf
537IO char* name
538END
539
540CASE int fullname
541I char* termbuf
542IO char* name
543END
544
545CASE int mvwin
546I WINDOW* win
547I int y
548I int x
549END
550
551CASE WINDOW* newwin
552I int lines
553I int cols
554I int begin_y
555I int begin_x
556END
557
558CASE int nl
559END
560
561CASE int nonl
562END
563
564CASE int scrollok
565I WINDOW* win
566I bool boolf
567END
568
569CASE WINDOW* subwin
570I WINDOW* win
571I int lines
572I int cols
573I int begin_y
574I int begin_x
575END
576
577CASE int touchline
578I WINDOW* win
579I int y
580I int startx
581I int endx
582END
583
584CASE int touchoverlap
585I WINDOW* win1
586I WINDOW* win2
587END
588
589CASE int touchwin
590I WINDOW* win
591END
592
593CASE char* unctrl
594I char ch
595END
596
597CASE int gettmode
598END
599
600CASE int mvcur
601I int lasty
602I int lastx
603I int newy
604I int newx
605END
606
607CASE int scroll
608I WINDOW* win
609END
610
611CASE int savetty
612END
613
614CASE void resetty
615END
616
617CASE int setterm
618I char* name
619END
620
621CASE int tstp
622END
623
624CASE int _putchar
625I char ch
626END
627
628 case US_testcallback:
629 sp = callback("callback", sp + items, curcsv->wantarray, 1, items);
630 break;
631
632 default:
633 fatal("Unimplemented user-defined subroutine");
634 }
635 return sp;
636}
637
638static int
639userval(ix, str)
640int ix;
641STR *str;
642{
643 switch (ix) {
644 case UV_COLS:
645 str_numset(str, (double)COLS);
646 break;
647 case UV_Def_term:
648 str_set(str, Def_term);
649 break;
650 case UV_ERR:
651 str_numset(str, (double)ERR);
652 break;
653 case UV_LINES:
654 str_numset(str, (double)LINES);
655 break;
656 case UV_My_term:
657 str_numset(str, (double)My_term);
658 break;
659 case UV_OK:
660 str_numset(str, (double)OK);
661 break;
662 case UV_curscr:
663 str_nset(str, &curscr, sizeof(WINDOW*));
664 break;
665 case UV_stdscr:
666 str_nset(str, &stdscr, sizeof(WINDOW*));
667 break;
668 case UV_ttytype:
669 str_set(str, ttytype);
670 break;
671 }
672 return 0;
673}
674
675static int
676userset(ix, str)
677int ix;
678STR *str;
679{
680 switch (ix) {
681 case UV_COLS:
682 COLS = (int)str_gnum(str);
683 break;
684 case UV_Def_term:
685 Def_term = savestr(str_get(str)); /* never freed */
686 break;
687 case UV_LINES:
688 LINES = (int)str_gnum(str);
689 break;
690 case UV_My_term:
691 My_term = (bool)str_gnum(str);
692 break;
693 case UV_ttytype:
694 strcpy(ttytype, str_get(str)); /* hope it fits */
695 break;
696 }
697 return 0;
698}