forked from gutschke/wy60
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwy60.c
6424 lines (6010 loc) · 231 KB
/
wy60.c
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2001, 2002, 2009 Markus Gutschke <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Added hack to fix issue on concurrent computers and VCF mode John Quirk 2012
*/
#include "wy60.h"
#undef DEBUG_LOG_SESSION
#undef DEBUG_LOG_NATIVE
#undef DEBUG_LOG_HOST
#undef DEBUG_SINGLE_STEP
#undef DEBUG_DECODE
#define WY60_VERSION PACKAGE_NAME" v"PACKAGE_VERSION" (" __DATE__ ")"
enum { E_NORMAL, E_ESC, E_SKIP_ONE, E_SKIP_LINE, E_SKIP_DEL, E_FILL_SCREEN,
E_GOTO_SEGMENT, E_GOTO_ROW_CODE, E_GOTO_COLUMN_CODE, E_GOTO_ROW,
E_GOTO_COLUMN, E_SET_FIELD_ATTRIBUTE, E_SET_ATTRIBUTE,
E_GRAPHICS_CHARACTER, E_SET_FEATURES, E_FUNCTION_KEY,
E_SET_SEGMENT_POSITION, E_SELECT_PAGE, E_CSI_D, E_CSI_E };
enum { T_NORMAL = 0, T_BLANK = 1, T_BLINK = 2, T_REVERSE = 4,
T_UNDERSCORE = 8, T_DIM = 64, T_BOTH = 68, T_ALL = 79,
T_PROTECTED = 256, T_GRAPHICS = 512 };
enum { J_AUTO = 0, J_ON, J_OFF };
enum { P_OFF, P_TRANSPARENT, P_AUXILIARY };
typedef struct KeyDefs {
struct KeyDefs *left, *right, *down;
char ch;
const char *name;
const char *nativeKeys;
const char *wy60Keys;
} KeyDefs;
typedef struct ScreenBuffer {
unsigned short **attributes;
char **lineBuffer;
int cursorX;
int cursorY;
int maximumWidth;
int maximumHeight;
} ScreenBuffer;
static void failure(int exitCode, const char *message, ...);
static void flushConsole(void);
static void gotoXYforce(int x, int y);
static void processSignal(int signalNumber, int pid, int pty);
static void putCapability(const char *capability);
static int putConsole(int ch);
static void putGraphics(char ch);
static void showCursor(int flag);
static void updateAttributes(void);
static int euid, egid, uid, gid, oldStylePty, streamsIO, jobControl;
static char ptyName[40];
static struct termios defaultTermios;
static sigjmp_buf mainJumpBuffer, auxiliaryJumpBuffer;
static int useAuxiliarySignalHandler;
static int needsReset, needsClearingBuffers, isPrinting;
static int screenWidth, screenHeight, originalWidth, originalHeight;
static int nominalWidth, nominalHeight, useNominalGeometry;
static int mode, protected, writeProtection, currentAttributes;
static int normalAttributes, protectedAttributes = T_REVERSE;
static int protectedPersonality = T_REVERSE;
static int insertMode, graphicsMode, cursorIsHidden, currentPage;
static int changedDimensions, targetColumn, targetRow;
static ScreenBuffer *screenBuffer[3], *currentBuffer;
static char extraData[1024];
static int extraDataLength;
static int vtStyleCursorReporting;
static int wyStyleCursorReporting;
static KeyDefs *keyDefinitions, *currentKeySequence;
static char *commandName;
static int loginShell, isLoginWrapper;
static char outputBuffer[16384];
static int outputBufferLength;
static char inputBuffer[128];
static int inputBufferLength;
static char *cfgTerm = "wyse60";
static char *cfgShell = "/bin/sh";
static char *cfgIdentifier = "\x06";
static char *cfgResize = "";
static char *cfgWriteProtect = "";
static char *cfgPrintCommand = "auto";
static char *cfgA1 = "";
static char *cfgA3 = "";
static char *cfgB2 = "";
static char *cfgC1 = "";
static char *cfgC3 = "";
static char *cfgBackspace = "\x08";
static char *cfgBacktab = "\x1BI";
static char *cfgBegin = "";
static char *cfgCancel = "";
static char *cfgClear = "";
static char *cfgClearAllTabs = "";
static char *cfgClearTab = "";
static char *cfgClose = "";
static char *cfgCommand = "";
static char *cfgCopy = "";
static char *cfgCreate = "";
static char *cfgDelete = "\x1BW";
static char *cfgDeleteLine = "\x1BR";
static char *cfgDown = "\x0A";
static char *cfgEnd = "\x1BT";
static char *cfgEndOfLine = "\x1BY";
static char *cfgEndOfScreen = "\x1BT";
static char *cfgEnter = "\x1B""7";
static char *cfgExit = "";
static char *cfgExitInsertMode = "";
static char *cfgFind = "";
static char *cfgHelp = "";
static char *cfgHome = "\x1E";
static char *cfgInsert = "\x1B""E";
static char *cfgInsertLine = "\x1BQ";
static char *cfgLeft = "\x08";
static char *cfgLowerLeft = "";
static char *cfgMark = "";
static char *cfgMessage = "";
static char *cfgMove = "";
static char *cfgNext = "\x1BK";
static char *cfgOpen = "";
static char *cfgOptions = "";
static char *cfgPageDown = "\x1BK";
static char *cfgPageUp = "\x1BJ";
static char *cfgPrevious = "\x1BJ";
static char *cfgPrint = "\x1BP";
static char *cfgRedo = "";
static char *cfgReference = "";
static char *cfgRefresh = "";
static char *cfgReplace = "\x1Br";
static char *cfgRestart = "";
static char *cfgResume = "";
static char *cfgRight = "\x0C";
static char *cfgSave = "";
static char *cfgScrollDown = "";
static char *cfgScrollUp = "";
static char *cfgSelect = "";
static char *cfgSetTab = "";
static char *cfgSuspend = "\x1A";
static char *cfgUndo = "";
static char *cfgUp = "\x0B";
static char *cfgShiftBegin = "";
static char *cfgShiftCancel = "";
static char *cfgShiftCommand = "";
static char *cfgShiftCopy = "";
static char *cfgShiftCreate = "";
static char *cfgShiftDelete = "\x1BR";
static char *cfgShiftDeleteLine = "\x1BW";
static char *cfgShiftEnd = "\x1BT";
static char *cfgShiftEndOfLine = "\x1BT";
static char *cfgShiftExit = "";
static char *cfgShiftFind = "";
static char *cfgShiftHelp = "";
static char *cfgShiftHome = "\x1B{";
static char *cfgShiftInsert = "\x1BQ";
static char *cfgShiftLeft = "\x08";
static char *cfgShiftMessage = "";
static char *cfgShiftMove = "";
static char *cfgShiftNext = "\x1BK";
static char *cfgShiftOptions = "";
static char *cfgShiftPrevious = "\x1BJ";
static char *cfgShiftPrint = "\x1BP";
static char *cfgShiftRedo = "";
static char *cfgShiftReplace = "\x1Br";
static char *cfgShiftResume = "";
static char *cfgShiftRight = "\x0C";
static char *cfgShiftSave = "";
static char *cfgShiftSuspend = "";
static char *cfgShiftUndo = "";
static char *cfgF0 = "";
static char *cfgF1 = "\x01@\r";
static char *cfgF2 = "\x01""A\r";
static char *cfgF3 = "\x01""B\r";
static char *cfgF4 = "\x01""C\r";
static char *cfgF5 = "\x01""D\r";
static char *cfgF6 = "\x01""E\r";
static char *cfgF7 = "\x01""F\r";
static char *cfgF8 = "\x01G\r";
static char *cfgF9 = "\x01H\r";
static char *cfgF10 = "\x01I\r";
static char *cfgF11 = "\x01J\r";
static char *cfgF12 = "\x01K\r";
static char *cfgF13 = "\x01`\r";
static char *cfgF14 = "\x01""a\r";
static char *cfgF15 = "\x01""b\r";
static char *cfgF16 = "\x01""c\r";
static char *cfgF17 = "\x01""d\r";
static char *cfgF18 = "\x01""e\r";
static char *cfgF19 = "\x01""f\r";
static char *cfgF20 = "\x01g\r";
static char *cfgF21 = "\x01h\r";
static char *cfgF22 = "\x01i\r";
static char *cfgF23 = "\x01j\r";
static char *cfgF24 = "\x01k\r";
static char *cfgF25 = "\x01L\r";
static char *cfgF26 = "\x01M\r";
static char *cfgF27 = "\x01N\r";
static char *cfgF28 = "\x01O\r";
static char *cfgF29 = "\x01l\r";
static char *cfgF30 = "\x01m\r";
static char *cfgF31 = "\x01n\r";
static char *cfgF32 = "\x01o\r";
static char *cfgF33 = "";
static char *cfgF34 = "";
static char *cfgF35 = "";
static char *cfgF36 = "";
static char *cfgF37 = "";
static char *cfgF38 = "";
static char *cfgF39 = "";
static char *cfgF40 = "";
static char *cfgF41 = "";
static char *cfgF42 = "";
static char *cfgF43 = "";
static char *cfgF44 = "";
static char *cfgF45 = "";
static char *cfgF46 = "";
static char *cfgF47 = "";
static char *cfgF48 = "";
static char *cfgF49 = "";
static char *cfgF50 = "";
static char *cfgF51 = "";
static char *cfgF52 = "";
static char *cfgF53 = "";
static char *cfgF54 = "";
static char *cfgF55 = "";
static char *cfgF56 = "";
static char *cfgF57 = "";
static char *cfgF58 = "";
static char *cfgF59 = "";
static char *cfgF60 = "";
static char *cfgF61 = "";
static char *cfgF62 = "";
static char *cfgF63 = "";
static char *cfgAlta = "\x1B""a";
static char *cfgAltb = "\x1B""b";
static char *cfgAltc = "\x1B""c";
static char *cfgAltd = "\x1B""d";
static char *cfgAlte = "\x1B""e";
static char *cfgAltf = "\x1B""f";
static char *cfgAltg = "\x1B""g";
static char *cfgAlth = "\x1B""h";
static char *cfgAlti = "\x1B""i";
static char *cfgAltj = "\x1B""j";
static char *cfgAltk = "\x1B""k";
static char *cfgAltl = "\x1B""l";
static char *cfgAltm = "\x1B""m";
static char *cfgAltn = "\x1B""n";
static char *cfgAlto = "\x1B""o";
static char *cfgAltp = "\x1B""p";
static char *cfgAltq = "\x1B""q";
static char *cfgAltr = "\x1B""r";
static char *cfgAlts = "\x1B""s";
static char *cfgAltt = "\x1B""t";
static char *cfgAltu = "\x1B""u";
static char *cfgAltv = "\x1B""v";
static char *cfgAltw = "\x1B""w";
static char *cfgAltx = "\x1B""x";
static char *cfgAlty = "\x1B""y";
static char *cfgAltz = "\x1B""z";
static char *cfgAltA = "\x1B""A";
static char *cfgAltB = "\x1B""B";
static char *cfgAltC = "\x1B""C";
static char *cfgAltD = "\x1B""D";
static char *cfgAltE = "\x1B""E";
static char *cfgAltF = "\x1B""F";
static char *cfgAltG = "\x1B""G";
static char *cfgAltH = "\x1B""H";
static char *cfgAltI = "\x1B""I";
static char *cfgAltJ = "\x1B""J";
static char *cfgAltK = "\x1B""K";
static char *cfgAltL = "\x1B""L";
static char *cfgAltM = "\x1B""M";
static char *cfgAltN = "\x1B""N";
static char *cfgAltO = "\x1B""O";
static char *cfgAltP = "\x1B""P";
static char *cfgAltQ = "\x1B""Q";
static char *cfgAltR = "\x1B""R";
static char *cfgAltS = "\x1B""S";
static char *cfgAltT = "\x1B""T";
static char *cfgAltU = "\x1B""U";
static char *cfgAltV = "\x1B""V";
static char *cfgAltW = "\x1B""W";
static char *cfgAltX = "\x1B""X";
static char *cfgAltY = "\x1B""Y";
static char *cfgAltZ = "\x1B""Z";
static char *cfgAlt0 = "\x1B""0";
static char *cfgAlt1 = "\x1B""1";
static char *cfgAlt2 = "\x1B""2";
static char *cfgAlt3 = "\x1B""3";
static char *cfgAlt4 = "\x1B""4";
static char *cfgAlt5 = "\x1B""5";
static char *cfgAlt6 = "\x1B""6";
static char *cfgAlt7 = "\x1B""7";
static char *cfgAlt8 = "\x1B""8";
static char *cfgAlt9 = "\x1B""9";
static char *cfgAltSpace = "\x1B ";
static char *cfgAltExclamation = "\x1B!";
static char *cfgAltDoubleQuote = "\x1B\"";
static char *cfgAltPound = "\x1B#";
static char *cfgAltDollar = "\x1B$";
static char *cfgAltPercent = "\x1B%";
static char *cfgAltAmpersand = "\x1B&";
static char *cfgAltSingleQuote = "\x1B\'";
static char *cfgAltLeftParen = "\x1B(";
static char *cfgAltRightParen = "\x1B)";
static char *cfgAltAsterisk = "\x1B*";
static char *cfgAltPlus = "\x1B+";
static char *cfgAltComma = "\x1B,";
static char *cfgAltDash = "\x1B-";
static char *cfgAltPeriod = "\x1B.";
static char *cfgAltSlash = "\x1B/";
static char *cfgAltColon = "\x1B:";
static char *cfgAltSemicolon = "\x1B;";
static char *cfgAltLess = "\x1B<";
static char *cfgAltEquals = "\x1B=";
static char *cfgAltGreater = "\x1B>";
static char *cfgAltQuestion = "\x1B?";
static char *cfgAltAt = "\x1B@";
static char *cfgAltLeftBracket = "\x1B[";
static char *cfgAltBackslash = "\x1B\\";
static char *cfgAltRightBracket = "\x1B]";
static char *cfgAltCircumflex = "\x1B^";
static char *cfgAltUnderscore = "\x1B_";
static char *cfgAltBacktick = "\x1B`";
static char *cfgAltLeftBrace = "\x1B{";
static char *cfgAltPipe = "\x1B|";
static char *cfgAltRightBrace = "\x1B}";
static char *cfgAltTilde = "\x1B~";
static char *cfgAltBackspace = "\x1B\x7F";
#ifdef DEBUG_LOG_SESSION
static void logCharacters(int mode, const char *buffer, int size) {
static int logFd = -2;
static long lastTimeStamp;
struct timeval timeValue;
if (logFd == -2) {
char *logger;
if ((logger = getenv("WY60LOGFILE")) != NULL) {
logFd = creat(logger, 0644);
gettimeofday(&timeValue, 0);
lastTimeStamp = timeValue.tv_sec*10 + timeValue.tv_usec/100000;
} else
logFd = -1;
}
if (logFd >= 0) {
static void flushConsole(void);
int header[4];
gettimeofday(&timeValue, 0);
header[0] = htonl(sizeof(header));
header[1] = htonl(size + sizeof(header));
header[2] = htonl(mode);
header[3] = htonl(timeValue.tv_sec*10 + timeValue.tv_usec/100000 -
lastTimeStamp);
lastTimeStamp = timeValue.tv_sec*10 + timeValue.tv_usec/100000;
flushConsole();
write(logFd, header, sizeof(header));
write(logFd, buffer, size);
}
return;
}
#else
#define logCharacters(mode,buffer,size) do {} while (0)
#endif
#ifdef DEBUG_LOG_HOST
static void logHostCharacter(int mode, char ch) {
static int logFd = -2;
if (logFd == -2) {
char *logger;
if ((logger = getenv("WY60HOST")) != NULL) {
logFd = creat(logger, 0644);
} else
logFd = -1;
}
if (logFd >= 0) {
static void flushConsole(void);
char buffer[80];
if (isatty(logFd))
strcpy(buffer, mode ? "\x1B[35m" : "\x1B[32m");
else
*buffer = '\000';
if ((unsigned char)ch < (unsigned char)' ') {
sprintf(strchr(buffer, '\000'), "^%c", ch | '@');
} else if (ch & 0x80) {
sprintf(strchr(buffer, '\000'), "\\x%02X", ch);
} else {
sprintf(strchr(buffer, '\000'), "%c", ch);
}
if (isatty(logFd))
strcat(buffer, "\x1B[39m");
flushConsole();
write(logFd, buffer, strlen(buffer));
}
}
static void logHostString(const char *buffer) {
for (; *buffer; buffer++)
logHostCharacter(0, *buffer);
return;
}
static void logHostKey(char ch) {
logHostCharacter(1, ch);
return;
}
#else
#define logHostCharacter(m,ch) do {} while (0)
#define logHostString(buffer) do {} while (0)
#define logHostKey(ch) do {} while (0)
#endif
#ifdef DEBUG_DECODE
static char _decodeBuffer[1024];
static int _decodeFd = -2;
static void logDecode(const char *format, ...) {
if (_decodeFd == -2) {
char *logger;
if ((logger = getenv("WY60DECODE")) != NULL) {
_decodeFd = creat(logger, 0644);
} else
_decodeFd = -1;
}
if (_decodeFd >= 0) {
va_list argList;
char *ptr;
int len;
va_start(argList, format);
if (!*_decodeBuffer && isatty(_decodeFd))
strcpy(_decodeBuffer, "\x1B[34m");
ptr = strrchr(_decodeBuffer, '\000');
len = &_decodeBuffer[sizeof(_decodeBuffer) - 7] - ptr;
vsnprintf(ptr, len, format, argList);
va_end(argList);
}
return;
}
static void logDecodeFlush(void) {
if (_decodeFd >= 0) {
static void flushConsole(void);
if (isatty(_decodeFd))
strcat(_decodeBuffer, "\x1B[39m");
strcat(_decodeBuffer, "\r\n");
flushConsole();
write(_decodeFd, _decodeBuffer, strlen(_decodeBuffer));
*_decodeBuffer = '\000';
}
return;
}
#else
#if defined(__GNUC__) && HAVE_VARIADICMACROS && \
!defined(_AIX) && !(defined(__APPLE__) && defined(__MACH__))
#define logDecode(format,args...) do {} while (0)
#define logDecodeFlush() do {} while (0)
#else
static void logDecode(const char *format, ...) { return; }
static void logDecodeFlush(void) { return; }
#endif
#endif
#if !HAVE_SYS_POLL_H
struct pollfd {
int fd;
short int events;
short int revents;
};
enum { POLLIN = 1, POLLPRI = 2, POLLOUT = 4,
POLLERR = 8, POLLHUP = 16, POLLNVAL = 32 };
static int poll(struct pollfd *fds, unsigned long nfds, int timeout) {
// This emulation function is somewhat limited. Most notably, it will never
// report POLLERR, POLLHUP, or POLLNVAL. The calling code has to detect
// these error conditions by some other means (typically by read() or write()
// reporting end-of-file).
fd_set readFds, writeFds, exceptionFds;
struct timeval *timeoutPtr, timeoutStruct;
int i, rc, fd;
FD_ZERO(&readFds);
FD_ZERO(&writeFds);
FD_ZERO(&exceptionFds);
fd = -1;
for (i = nfds; i--; ) {
if (fds[i].events & POLLIN)
FD_SET(fds[i].fd, &readFds);
if (fds[i].events & POLLOUT)
FD_SET(fds[i].fd, &writeFds);
if (fds[i].events & POLLPRI)
FD_SET(fds[i].fd, &exceptionFds);
if (fds[i].fd > fd)
fd = fds[i].fd;
fds[i].revents = 0;
}
if (timeout < 0)
timeoutPtr = NULL;
else {
timeoutStruct.tv_sec = timeout/1000;
timeoutStruct.tv_usec = (timeout%1000) * 1000;
timeoutPtr = &timeoutStruct;
}
i = select(fd + 1, &readFds, &writeFds, &exceptionFds,
timeoutPtr);
if (i <= 0)
rc = i;
else {
rc = 0;
for (i = nfds; i--; ) {
if (FD_ISSET(fds[i].fd, &readFds))
fds[i].revents |= POLLIN;
if (FD_ISSET(fds[i].fd, &writeFds))
fds[i].revents |= POLLOUT;
if (FD_ISSET(fds[i].fd, &exceptionFds))
fds[i].revents |= POLLPRI;
if (fds[i].revents)
rc++;
}
}
return(rc);
}
#endif
#if !HAVE_TERM_H && !HAVE_NCURSES_TERM_H
#undef auto_right_margin
#undef eat_newline_glitch
#undef acs_chars
#undef bell
#undef carriage_return
#undef clear_screen
#undef clr_eol
#undef clr_eos
#undef cursor_address
#undef cursor_down
#undef cursor_home
#undef cursor_invisible
#undef cursor_left
#undef cursor_normal
#undef cursor_right
#undef cursor_up
#undef cursor_visible
#undef delete_character
#undef delete_line
#undef ena_acs
#undef enter_alt_charset_mode
#undef enter_blink_mode
#undef enter_bold_mode
#undef enter_ca_mode
#undef enter_dim_mode
#undef enter_insert_mode
#undef enter_standout_mode
#undef enter_underline_mode
#undef exit_alt_charset_mode
#undef exit_attribute_mode
#undef exit_ca_mode
#undef exit_insert_mode
#undef exit_standout_mode
#undef exit_underline_mode
#undef init_1string
#undef init_2string
#undef init_3string
#undef init_file
#undef init_prog
#undef insert_character
#undef insert_line
#undef key_a1
#undef key_a3
#undef key_b2
#undef key_backspace
#undef key_beg
#undef key_btab
#undef key_c1
#undef key_c3
#undef key_cancel
#undef key_catab
#undef key_clear
#undef key_close
#undef key_command
#undef key_copy
#undef key_create
#undef key_ctab
#undef key_dc
#undef key_dl
#undef key_down
#undef key_eic
#undef key_end
#undef key_enter
#undef key_eol
#undef key_eos
#undef key_exit
#undef key_f0
#undef key_f1
#undef key_f2
#undef key_f3
#undef key_f4
#undef key_f5
#undef key_f6
#undef key_f7
#undef key_f8
#undef key_f9
#undef key_f10
#undef key_f11
#undef key_f12
#undef key_f13
#undef key_f14
#undef key_f15
#undef key_f16
#undef key_f17
#undef key_f18
#undef key_f19
#undef key_f20
#undef key_f21
#undef key_f22
#undef key_f23
#undef key_f24
#undef key_f25
#undef key_f26
#undef key_f27
#undef key_f28
#undef key_f29
#undef key_f30
#undef key_f31
#undef key_f32
#undef key_f33
#undef key_f34
#undef key_f35
#undef key_f36
#undef key_f37
#undef key_f38
#undef key_f39
#undef key_f40
#undef key_f41
#undef key_f42
#undef key_f43
#undef key_f44
#undef key_f45
#undef key_f46
#undef key_f47
#undef key_f48
#undef key_f49
#undef key_f50
#undef key_f51
#undef key_f52
#undef key_f53
#undef key_f54
#undef key_f55
#undef key_f56
#undef key_f57
#undef key_f58
#undef key_f59
#undef key_f60
#undef key_f61
#undef key_f62
#undef key_f63
#undef key_find
#undef key_help
#undef key_home
#undef key_ic
#undef key_il
#undef key_left
#undef key_ll
#undef key_mark
#undef key_message
#undef key_move
#undef key_next
#undef key_npage
#undef key_open
#undef key_options
#undef key_ppage
#undef key_previous
#undef key_print
#undef key_redo
#undef key_reference
#undef key_refresh
#undef key_replace
#undef key_restart
#undef key_resume
#undef key_right
#undef key_save
#undef key_sbeg
#undef key_scancel
#undef key_scommand
#undef key_scopy
#undef key_screate
#undef key_sdc
#undef key_sdl
#undef key_select
#undef key_send
#undef key_seol
#undef key_sexit
#undef key_sf
#undef key_sfind
#undef key_shelp
#undef key_shome
#undef key_sic
#undef key_sleft
#undef key_smessage
#undef key_smove
#undef key_snext
#undef key_soptions
#undef key_sprevious
#undef key_sprint
#undef key_sr
#undef key_sredo
#undef key_sreplace
#undef key_sright
#undef key_srsume
#undef key_ssave
#undef key_ssuspend
#undef key_stab
#undef key_sundo
#undef key_suspend
#undef key_undo
#undef key_up
#undef orig_pair
#undef parm_delete_line
#undef parm_down_cursor
#undef parm_insert_line
#undef parm_left_cursor
#undef parm_right_cursor
#undef parm_up_cursor
#undef reset_1string
#undef reset_2string
#undef reset_3string
#undef reset_file
#undef scroll_forward
#undef set_a_foreground
#undef set_attributes
#undef set_foreground
#define auto_right_margin wy60_auto_right_margin
#define eat_newline_glitch wy60_eat_newline_glitch
#define acs_chars wy60_acs_chars
#define bell wy60_bell
#define carriage_return wy60_carriage_return
#define clear_screen wy60_clear_screen
#define clr_eol wy60_clr_eol
#define clr_eos wy60_clr_eos
#define cursor_address wy60_cursor_address
#define cursor_down wy60_cursor_down
#define cursor_home wy60_cursor_home
#define cursor_invisible wy60_cursor_invisible
#define cursor_left wy60_cursor_left
#define cursor_normal wy60_cursor_normal
#define cursor_right wy60_cursor_right
#define cursor_up wy60_cursor_up
#define cursor_visible wy60_cursor_visible
#define delete_character wy60_delete_character
#define delete_line wy60_delete_line
#define ena_acs wy60_ena_acs
#define enter_alt_charset_mode wy60_enter_alt_charset_mode
#define enter_blink_mode wy60_enter_blink_mode
#define enter_bold_mode wy60_enter_bold_mode
#define enter_ca_mode wy60_enter_ca_mode
#define enter_dim_mode wy60_enter_dim_mode
#define enter_insert_mode wy60_enter_insert_mode
#define enter_standout_mode wy60_enter_standout_mode
#define enter_underline_mode wy60_enter_underline_mode
#define exit_alt_charset_mode wy60_exit_alt_charset_mode
#define exit_attribute_mode wy60_exit_attribute_mode
#define exit_ca_mode wy60_exit_ca_mode
#define exit_insert_mode wy60_exit_insert_mode
#define exit_standout_mode wy60_exit_standout_mode
#define exit_underline_mode wy60_exit_underline_mode
#define init_1string wy60_init_1string
#define init_2string wy60_init_2string
#define init_3string wy60_init_3string
#define init_file wy60_init_file
#define init_prog wy60_init_prog
#define insert_character wy60_insert_character
#define insert_line wy60_insert_line
#define key_a1 wy60_key_a1
#define key_a3 wy60_key_a3
#define key_b2 wy60_key_b2
#define key_backspace wy60_key_backspace
#define key_beg wy60_key_beg
#define key_btab wy60_key_btab
#define key_c1 wy60_key_c1
#define key_c3 wy60_key_c3
#define key_cancel wy60_key_cancel
#define key_catab wy60_key_catab
#define key_clear wy60_key_clear
#define key_close wy60_key_close
#define key_command wy60_key_command
#define key_copy wy60_key_copy
#define key_create wy60_key_create
#define key_ctab wy60_key_ctab
#define key_dc wy60_key_dc
#define key_dl wy60_key_dl
#define key_down wy60_key_down
#define key_eic wy60_key_eic
#define key_end wy60_key_end
#define key_enter wy60_key_enter
#define key_eol wy60_key_eol
#define key_eos wy60_key_eos
#define key_exit wy60_key_exit
#define key_f0 wy60_key_f0
#define key_f1 wy60_key_f1
#define key_f2 wy60_key_f2
#define key_f3 wy60_key_f3
#define key_f4 wy60_key_f4
#define key_f5 wy60_key_f5
#define key_f6 wy60_key_f6
#define key_f7 wy60_key_f7
#define key_f8 wy60_key_f8
#define key_f9 wy60_key_f9
#define key_f10 wy60_key_f10
#define key_f11 wy60_key_f11
#define key_f12 wy60_key_f12
#define key_f13 wy60_key_f13
#define key_f14 wy60_key_f14
#define key_f15 wy60_key_f15
#define key_f16 wy60_key_f16
#define key_f17 wy60_key_f17
#define key_f18 wy60_key_f18
#define key_f19 wy60_key_f19
#define key_f20 wy60_key_f20
#define key_f21 wy60_key_f21
#define key_f22 wy60_key_f22
#define key_f23 wy60_key_f23
#define key_f24 wy60_key_f24
#define key_f25 wy60_key_f25
#define key_f26 wy60_key_f26
#define key_f27 wy60_key_f27
#define key_f28 wy60_key_f28
#define key_f29 wy60_key_f29
#define key_f30 wy60_key_f30
#define key_f31 wy60_key_f31
#define key_f32 wy60_key_f32
#define key_f33 wy60_key_f33
#define key_f34 wy60_key_f34
#define key_f35 wy60_key_f35
#define key_f36 wy60_key_f36
#define key_f37 wy60_key_f37
#define key_f38 wy60_key_f38
#define key_f39 wy60_key_f39
#define key_f40 wy60_key_f40
#define key_f41 wy60_key_f41
#define key_f42 wy60_key_f42
#define key_f43 wy60_key_f43
#define key_f44 wy60_key_f44
#define key_f45 wy60_key_f45
#define key_f46 wy60_key_f46
#define key_f47 wy60_key_f47
#define key_f48 wy60_key_f48
#define key_f49 wy60_key_f49
#define key_f50 wy60_key_f50
#define key_f51 wy60_key_f51
#define key_f52 wy60_key_f52
#define key_f53 wy60_key_f53
#define key_f54 wy60_key_f54
#define key_f55 wy60_key_f55
#define key_f56 wy60_key_f56
#define key_f57 wy60_key_f57
#define key_f58 wy60_key_f58
#define key_f59 wy60_key_f59
#define key_f60 wy60_key_f60
#define key_f61 wy60_key_f61
#define key_f62 wy60_key_f62
#define key_f63 wy60_key_f63
#define key_find wy60_key_find
#define key_help wy60_key_help
#define key_home wy60_key_home
#define key_ic wy60_key_ic
#define key_il wy60_key_il
#define key_left wy60_key_left
#define key_ll wy60_key_ll
#define key_mark wy60_key_mark
#define key_message wy60_key_message
#define key_move wy60_key_move
#define key_next wy60_key_next
#define key_npage wy60_key_npage
#define key_open wy60_key_open
#define key_options wy60_key_options
#define key_ppage wy60_key_ppage
#define key_previous wy60_key_previous
#define key_print wy60_key_print
#define key_redo wy60_key_redo
#define key_reference wy60_key_reference
#define key_refresh wy60_key_refresh
#define key_replace wy60_key_replace
#define key_restart wy60_key_restart
#define key_resume wy60_key_resume
#define key_right wy60_key_right
#define key_save wy60_key_save
#define key_sbeg wy60_key_sbeg
#define key_scancel wy60_key_scancel
#define key_scommand wy60_key_scommand
#define key_scopy wy60_key_scopy
#define key_screate wy60_key_screate
#define key_sdc wy60_key_sdc
#define key_sdl wy60_key_sdl
#define key_select wy60_key_select
#define key_send wy60_key_send
#define key_seol wy60_key_seol
#define key_sexit wy60_key_sexit
#define key_sf wy60_key_sf
#define key_sfind wy60_key_sfind
#define key_shelp wy60_key_shelp
#define key_shome wy60_key_shome
#define key_sic wy60_key_sic
#define key_sleft wy60_key_sleft
#define key_smessage wy60_key_smessage
#define key_smove wy60_key_smove
#define key_snext wy60_key_snext
#define key_soptions wy60_key_soptions
#define key_sprevious wy60_key_sprevious
#define key_sprint wy60_key_sprint
#define key_sr wy60_key_sr
#define key_sredo wy60_key_sredo
#define key_sreplace wy60_key_sreplace
#define key_sright wy60_key_sright
#define key_srsume wy60_key_srsume
#define key_ssave wy60_key_ssave
#define key_ssuspend wy60_key_ssuspend
#define key_stab wy60_key_stab
#define key_sundo wy60_key_sundo
#define key_suspend wy60_key_suspend
#define key_undo wy60_key_undo
#define key_up wy60_key_up
#define orig_pair wy60_orig_pair
#define parm_delete_line wy60_parm_delete_line
#define parm_down_cursor wy60_parm_down_cursor
#define parm_insert_line wy60_parm_insert_line
#define parm_left_cursor wy60_parm_left_cursor
#define parm_right_cursor wy60_parm_right_cursor
#define parm_up_cursor wy60_parm_up_cursor
#define reset_1string wy60_reset_1string
#define reset_2string wy60_reset_2string
#define reset_3string wy60_reset_3string
#define reset_file wy60_reset_file
#define scroll_forward wy60_scroll_forward
#define set_a_foreground wy60_set_a_foreground
#define set_attributes wy60_set_attributes
#define set_foreground wy60_set_foreground
static int auto_right_margin;
static int eat_newline_glitch;
static const char *acs_chars;
static const char *bell;
static const char *carriage_return;
static const char *clear_screen;
static const char *clr_eol;
static const char *clr_eos;
static const char *cursor_address;
static const char *cursor_down;
static const char *cursor_home;
static const char *cursor_invisible;
static const char *cursor_left;
static const char *cursor_normal;
static const char *cursor_right;
static const char *cursor_up;
static const char *cursor_visible;
static const char *delete_character;
static const char *delete_line;