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