-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecuutil.c
1450 lines (1293 loc) · 33.9 KB
/
ecuutil.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
/*+-----------------------------------------------------------------------
ecuutil.c -- utility routines for extended calling unit
wht@wht.net
Defined functions:
arg_token(parsestr, termchars)
ascii_name_to_hex(name)
ascii_to_hex(ascii)
base_name(fullname)
build_arg_array(cmd, arg, arg_max_quan, narg_rtn)
build_str_array(str, arg, arg_max_quan, narg_rtn)
build_valid_baud_string()
cfree(p, num, size)
disp_line_termio(fd, text)
disp_stat(st)
disp_termio(ttt, text)
find_shell_chars(command)
get_curr_dir(cdir, cdir_max)
get_home_dir(home_dir)
graphic_char_text(ch, incl_3char)
hex_to_ascii_name(char_val)
make_ecu_subdir()
mem_cpy(dest, src, len)
mkdir_auto(dirfn)
mode_map(mode, mode_str)
pad_zstr_to_len(zstr, len)
perror_errmsg(str)
Rdchk(fd)
skip_ld_break(zstr)
str_classify(sc, str)
str_token(parsestr, termchars)
strerror(err_no)
strip_trail_break(zstr)
yes_or_no(strarg)
Some of these routines are the first coding I did in C
and they just aren't worth improving ... like pad_zstr_to_len().
Don't be too harsh on me.
------------------------------------------------------------------------*/
/*+:EDITS:*/
/*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
/*:04-05-1998-17:32-wht@kepler-move feval code to get_uname_sys/nodename */
/*:11-21-1997-05:18-wht@kepler-remove parity bit in graphic_char_text */
/*:11-20-1997-15:35-wht@kepler-add more shell chars to find_shell_chars() */
/*:02-09-1997-20:20-wht@yuriatin-add base_name */
/*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
/*:10-11-1996-02:35-wht@gyro-sunos can live off of CFG_FionreadInFilioH */
/*:10-11-1996-02:09-wht@yuriatin-add CFG_FionreadInFilioH */
/*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
/*:08-20-1996-12:39-wht@kepler-locale/ctype fixes from ache@nagual.ru */
/*:07-31-1996-16:33-wht@kepler-apply Andrey Chernov FreeBSD getwd() patch */
/*:01-01-1996-18:34-wht@kepler-massage disp_termio for CSIZE */
/*:12-28-1995-12:54-wht@kepler-Andrey Chernov FreeBSD fixes */
/*:12-06-1995-13:30-wht@n4hgf-termecu w/errno -1 consideration */
/*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
/*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
/*:10-14-1995-17:08-wht@kepler-'struct termio' to 'struct TERMIO' */
/*:10-14-1995-16:55-wht@kepler-except FreeBSD, print max of 8 c_cc */
/*:10-14-1995-16:17-wht@kepler-add build_valid_baud_string */
/*:09-17-1995-16:28-wht@kepler-remove obsolete #if 0 code */
/*:06-15-1995-07:09-wht@kepler-dynamic CFG_HasStrerror */
/*:03-12-1995-01:03-wht@kepler-use ECU_MAXPN and clean up get_curr_dir */
/*:03-12-1995-00:57-wht@kepler-get_home_dir now a void function */
/*:03-11-1995-17:51-wht@kepler-type for getwd for Linux */
/*:01-12-1995-15:19-wht@n4hgf-apply Andrew Chernov 8-bit clean+FreeBSD patch */
/*:06-03-1994-16:42-wht@kepler-non-termios disp_termio handled iflag badly */
/*:05-29-1994-05:06-wht@n4hgf-2-char input to ascii_name_to_hex now working */
/*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
/*:04-07-1994-13:41-wht@n4hgf-fix LINUX get_curr_dir */
/*:12-12-1993-14:22-wht@fep-MOTSVR3 support */
/*:11-12-1993-11:00-wht@n4hgf-Linux changes by bob@vancouver.zadall.com */
/*:10-02-1993-22:03-wht@n4hgf-some nitpicking cleanup */
/*:07-24-1993-14:12-wht@n4hgf-reorganize ascii_ctlstr */
/*:01-30-1993-12:17-wht@n4hgf-remove gcc < 1.40 bug workaround */
/*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
/*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
/*:05-08-1992-02:42-wht@n4hgf-select-based Nap was buggy on EINTR */
/*:04-05-1992-15:31-wht@n4hgf-no more use of memmove in any environment */
/*:02-22-1992-16:19-wht@n4hgf-build arg/str array now handles zero tokens */
/*:11-26-1991-19:36-wht@n4hgf-add str_classify and yes_or_no uses it */
/*:09-01-1991-12:46-wht@n4hgf2-show sun flow control bit */
/*:08-30-1991-20:09-wht@n4hgf2-sun Nap was not returning a value */
/*:08-25-1991-14:39-wht@n4hgf-SVR4 port thanks to aega84!lh */
/*:08-17-1991-14:11-root@n4hgf-ascii_to_hex supports "csi" */
/*:08-13-1991-13:53-wht@n4hgf-UNIX and ISC nap() broken; XENIX still wins */
/*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
/*:04-16-1991-15:45-wht@n4hgf-gcc cannot use memmove */
/*:03-18-1991-22:31-wht@n4hgf-ISC 2.2 has mkdir() */
/*:02-03-1991-14:23-wht@n4hgf-hack workaround for get_home_dir under x286 */
/*:01-25-1991-16:23-wht@n4hgf-source name wrong in headers */
/*:12-26-1990-14:32-wht@n4hgf-use memmove or Duff's Device in mem_cpy() */
/*:12-04-1990-00:58-wht@n4hgf-allow alternating between str/arg_token */
/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
#include "ecu.h"
#include "termecu.h"
#include "ecufork.h"
#include "ecukey.h"
#include "ecu_pwd.h"
#include <sys/utsname.h>
#if defined(SVR4)
#include <sys/termiox.h>
extern int hx_flag;
#endif
/*
* system independence for strerror functionality
*/
#if !defined(CFG_HasStrerror)
extern char *sys_errlist[];
extern int sys_nerr;
#endif
char curr_dir[ECU_MAXPN]; /* current working directory of process */
char *str_token_static = (char *)0;
static char *ascii_ctlstr[] =
{
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS ", "HT ", "NL ", "VT ", "FF ", "CR ", "SO ", "SI ",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM ", "SUB", "ESC", "FS ", "GS ", "RS ", "US ", "SP "
};
char *valid_baud_string = "";
static char uname_rtnstring[128];
/*+-------------------------------------------------------------------------
mem_cpy(dest,src,len) - memcpy() with non-destructive overlapping copy
use Duff's device for speed
--------------------------------------------------------------------------*/
void
mem_cpy(dest, src, len)
char *dest;
char *src;
int len;
{
int itmp = (len + 15) / 16;
if ((unsigned long)dest > (unsigned long)src)
{
dest += len;
src += len;
switch (len % 16)
{
case 0:
do
{
*--dest = *--src;
case 15: *--dest = *--src;
case 14: *--dest = *--src;
case 13: *--dest = *--src;
case 12: *--dest = *--src;
case 11: *--dest = *--src;
case 10: *--dest = *--src;
case 9: *--dest = *--src;
case 8: *--dest = *--src;
case 7: *--dest = *--src;
case 6: *--dest = *--src;
case 5: *--dest = *--src;
case 4: *--dest = *--src;
case 3: *--dest = *--src;
case 2: *--dest = *--src;
case 1: *--dest = *--src;
}
while (--itmp > 0);
}
}
else
{
switch (len % 16)
{
case 0:
do
{
*dest++ = *src++;
case 15: *dest++ = *src++;
case 14: *dest++ = *src++;
case 13: *dest++ = *src++;
case 12: *dest++ = *src++;
case 11: *dest++ = *src++;
case 10: *dest++ = *src++;
case 9: *dest++ = *src++;
case 8: *dest++ = *src++;
case 7: *dest++ = *src++;
case 6: *dest++ = *src++;
case 5: *dest++ = *src++;
case 4: *dest++ = *src++;
case 3: *dest++ = *src++;
case 2: *dest++ = *src++;
case 1: *dest++ = *src++;
}
while (--itmp > 0);
}
}
} /* end of mem_cpy */
/*+-------------------------------------------------------------------------
skip_ld_break(zstr) - skip leading spaces and tabs
--------------------------------------------------------------------------*/
char *
skip_ld_break(zstr)
char *zstr;
{
while (isspace((uchar) * zstr))
zstr++;
return (zstr);
} /* end of skip_ld_break */
/*+-------------------------------------------------------------------------
strip_trail_break(zstr) - strip trailing spaces and tabs
--------------------------------------------------------------------------*/
void
strip_trail_break(zstr)
char *zstr;
{
int itmp = strlen(zstr);
char *zptr = zstr + itmp - 1;
while (itmp && isspace((uchar) * zptr))
{
*zptr-- = 0;
itmp--;
}
} /* end of strip_trail_break */
/*+-----------------------------------------------------------------------
pad_zstr_to_len(zstr,len)
pads with spaces to specified length, unless already longer than
len in which case the string is truncated to 'len' characters.
------------------------------------------------------------------------*/
void
pad_zstr_to_len(zstr, len)
char *zstr;
int len;
{
int izstr;
izstr = strlen(zstr);
if (izstr >= len)
zstr[len] = 0;
else
{
while (izstr < len)
zstr[izstr++] = 0x20;
zstr[izstr] = 0;
}
} /* end of pad_zstr_to_len */
/*+-----------------------------------------------------------------------
arg_token(parsestr,termchars)
Get next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
calls), where tokens are nonempty strings separated by runs of chars
from termchars. Writes nulls into parsestr to end tokens.
termchars need not remain constant from call to call.
Treats multiple occurrences of a termchar as one delimiter (does not
allow null fields).
------------------------------------------------------------------------*/
char *
arg_token(parsestr, termchars)
char *parsestr;
char *termchars;
{
char *parseptr;
char *token;
if (!parsestr && !str_token_static)
return ((char *)0);
if (parsestr)
{
str_token_static = (char *)0;
parseptr = parsestr;
}
else
parseptr = str_token_static;
while (*parseptr)
{
if (!strchr(termchars, *parseptr))
break;
parseptr++;
}
if (!*parseptr)
{
str_token_static = (char *)0;
return ((char *)0);
}
token = parseptr;
/*
* tokens beginning with apostrophe or quotes kept together
*/
if (*token == '\'')
{
token++;
parseptr++;
while (*parseptr)
{
if (*parseptr == '\'')
{
str_token_static = parseptr + 1;
*parseptr = 0;
return (token);
}
parseptr++;
}
str_token_static = (char *)0;
return (token);
}
else if (*token == '"')
{
token++;
parseptr++;
while (*parseptr)
{
if (*parseptr == '"')
{
str_token_static = parseptr + 1;
*parseptr = 0;
return (token);
}
parseptr++;
}
str_token_static = (char *)0;
return (token);
}
while (*parseptr)
{
if (strchr(termchars, *parseptr))
{
*parseptr = 0;
str_token_static = parseptr + 1;
while (*str_token_static)
{
if (!strchr(termchars, *str_token_static))
break;
str_token_static++;
}
return (token);
}
parseptr++;
}
str_token_static = (char *)0;
return (token);
} /* end of arg_token */
/*+-------------------------------------------------------------------------
build_arg_array(cmd,arg,arg_max_quan,&narg)
--------------------------------------------------------------------------*/
void
build_arg_array(cmd, arg, arg_max_quan, narg_rtn)
char *cmd;
char **arg;
int arg_max_quan;
int *narg_rtn;
{
int narg;
str_token_static = (char *)0;
memset((char *)arg, 0, sizeof(char *) * arg_max_quan);
if (!(arg[0] = arg_token(cmd, " \t\r\n")))
{
*narg_rtn = 0;
return;
}
for (narg = 1; narg < arg_max_quan; ++narg)
{
if (!(arg[narg] = arg_token((char *)0, " \t\r\n")))
break;
}
*narg_rtn = narg;
} /* end of build_arg_array */
/*+-----------------------------------------------------------------------
str_token(parsestr,termchars)
Get next token from string parsestr ((char *)0 on 2nd, 3rd, etc.
calls), where tokens are nonempty strings separated by runs of chars
from termchars. Writes nulls into parsestr to end tokens.
termchars need not remain constant from call to call.
Treats each occurrence of a termchar as delimiter (allows null
fields).
------------------------------------------------------------------------*/
char *
str_token(parsestr, termchars)
char *parsestr;
char *termchars;
{
char *termptr;
char *parseptr;
char *token;
if (!parsestr && !str_token_static)
return ((char *)0);
if (parsestr)
{
str_token_static = (char *)0;
parseptr = parsestr;
}
else
parseptr = str_token_static;
while (*parseptr)
{
for (termptr = termchars; *termptr != 0; termptr++)
{
if (*parseptr == *termptr)
goto FOUND_TERM;
}
if (!*termptr)
break;
parseptr++;
}
if (!*parseptr)
{
str_token_static = (char *)0;
return ((char *)0);
}
FOUND_TERM:
token = parseptr;
while (*parseptr)
{
for (termptr = termchars; *termptr;)
{
if (*parseptr == *termptr++)
{
str_token_static = parseptr + 1;
*parseptr = 0;
return (token);
}
}
parseptr++;
}
str_token_static = (char *)0;
return (token);
} /* end of str_token */
/*+-------------------------------------------------------------------------
build_str_array(str,arg,arg_max_quan,&narg)
--------------------------------------------------------------------------*/
void
build_str_array(str, arg, arg_max_quan, narg_rtn)
char *str;
char **arg;
int arg_max_quan;
int *narg_rtn;
{
int narg;
str_token_static = (char *)0;
memset((char *)arg, 0, sizeof(char *) * arg_max_quan);
if (!(arg[0] = str_token(str, " \t\r\n")))
{
*narg_rtn = 0;
return;
}
for (narg = 1; narg < arg_max_quan; ++narg)
{
if (!(arg[narg] = str_token((char *)0, " \t\r\n")))
break;
}
*narg_rtn = narg;
} /* end of build_str_array */
/*+-----------------------------------------------------------------------
graphic_char_text(character,incl_3char) - Make all chars "printable"
returns pointer to a static string containing printable version
of a character. If control char, printed as "^A", etc.
if incl_3char set true, then space + ASCII assignment (e.g. "NUL") is
appended to the string for non-printable graphics
------------------------------------------------------------------------*/
char *
graphic_char_text(ch, incl_3char)
uchar ch;
int incl_3char;
{
static char gg[16];
ch &= 0x7F;
if (isprint(ch))
{
gg[0] = ch;
gg[1] = 0;
}
else
{
gg[0] = '^';
if (ch == 0x7F)
{
gg[1] = '?';
if (incl_3char)
strcpy(&gg[2], " DEL");
else
gg[2] = 0;
}
else
{
gg[1] = ch + 0x40;
if (incl_3char)
{
gg[2] = 0x20;
strcpy(gg + 3, ascii_ctlstr[ch]);
gg[7] = 0;
}
else
gg[2] = 0;
}
}
return (gg);
} /* end of graphic_char_text */
/*+-----------------------------------------------------------------------
mode_map(mode,mode_str) build drwxrwxrwx string
------------------------------------------------------------------------*/
char *
mode_map(mode, mode_str)
unsigned short mode;
char *mode_str;
{
unsigned ftype = mode & S_IFMT;
char *rtn;
static char result[12];
rtn = (mode_str == (char *)0) ? result : mode_str;
/* drwxrwxrwx */
/* 0123456789 */
strcpy(rtn, "----------");
switch (ftype)
{
case S_IFIFO:
*rtn = 'p';
break; /* FIFO (named pipe) */
case S_IFDIR:
*rtn = 'd';
break; /* directory */
case S_IFCHR:
*rtn = 'c';
break; /* character special */
case S_IFBLK:
*rtn = 'b';
break; /* block special */
case S_IFREG:
*rtn = '-';
break; /* regular */
#if defined(S_IFLNK)
case S_IFLNK:
*rtn = 'l';
break; /* symbolic link */
#endif
#if defined(S_IFSOCK)
case S_IFSOCK:
*rtn = 's';
break; /* socket */
#endif
#if defined(S_IFNAM)
case S_IFNAM: /* name space entry */
#if defined(S_IFNAM)
if (mode & S_INSEM) /* semaphore */
{
*rtn = 's';
break;
}
#endif
#if defined(S_INSHD)
if (mode & S_INSHD) /* shared memory */
{
*rtn = 'm';
break;
}
break;
#endif
#endif
default:
*rtn = '?';
break; /* ??? */
}
if (mode & 000400)
*(rtn + 1) = 'r';
if (mode & 000200)
*(rtn + 2) = 'w';
if (mode & 000100)
*(rtn + 3) = 'x';
if (mode & 004000)
*(rtn + 3) = 's';
if (mode & 000040)
*(rtn + 4) = 'r';
if (mode & 000020)
*(rtn + 5) = 'w';
if (mode & 000010)
*(rtn + 6) = 'x';
if (mode & 002000)
*(rtn + 6) = 's';
if (mode & 000004)
*(rtn + 7) = 'r';
if (mode & 000002)
*(rtn + 8) = 'w';
if (mode & 000001)
*(rtn + 9) = 'x';
if (mode & 001000)
*(rtn + 9) = 't';
return (rtn);
} /* end of mode_map */
/*+-----------------------------------------------------------------------
disp_termio(ttt,text) - display termio 'ttt' on console/plog
------------------------------------------------------------------------*/
void
disp_termio(ttt, text)
struct TERMIO *ttt;
char *text;
{
int flag;
int i_cc;
char *bitrate;
char dbits;
char parity;
pprintf("---------> %s\n", text);
#if defined(CFG_TermiosLineio)
flag = ttt->c_iflag;
pprintf("iflag: %07o IGNBRK:%d BRKINT:%d IGNPAR:%d ",
flag,
(flag & IGNBRK) ? 1 : 0,
(flag & BRKINT) ? 1 : 0,
(flag & IGNPAR) ? 1 : 0);
pprintf("PARENB:%d PARMRK:%d INPCK:%d ISTRIP:%d\n",
(flag & PARENB) ? 1 : 0,
(flag & PARMRK) ? 1 : 0,
(flag & INPCK) ? 1 : 0,
(flag & ISTRIP) ? 1 : 0);
pprintf(" INLCR:%d IGNCR:%d ICRNL:%d ",
(flag & INLCR) ? 1 : 0,
(flag & IGNCR) ? 1 : 0,
(flag & ICRNL) ? 1 : 0);
pprintf("IXON:%d IXANY:%d IXOFF:%d\n",
(flag & IXON) ? 1 : 0,
(flag & IXANY) ? 1 : 0,
(flag & IXOFF) ? 1 : 0);
flag = ttt->c_oflag;
pprintf("oflag: %07o OPOST:%d ONLCR:%d\n",
flag,
(flag & OPOST) ? 1 : 0,
(flag & ONLCR) ? 1 : 0);
flag = ttt->c_lflag;
pprintf("lflag: %07o ISIG:%d ICANON:%d ECHO:%d ECHOE:%d\n",
flag,
(flag & ISIG) ? 1 : 0,
(flag & ICANON) ? 1 : 0,
(flag & ECHO) ? 1 : 0,
(flag & ECHOE) ? 1 : 0);
pprintf(" ECHOK:%d ECHONL:%d NOFLSH:%d",
(flag & ECHOK) ? 1 : 0,
(flag & ECHONL) ? 1 : 0,
(flag & NOFLSH) ? 1 : 0);
#else
flag = ttt->c_iflag;
pprintf("iflag: %07o IGNBRK:%d BRKINT:%d IGNPAR:%d ",
flag,
(flag & IGNBRK) ? 1 : 0,
(flag & BRKINT) ? 1 : 0,
(flag & IGNPAR) ? 1 : 0);
pprintf("PARENB:%d PARMRK:%d INPCK:%d ISTRIP:%d\n",
(flag & PARENB) ? 1 : 0,
(flag & PARMRK) ? 1 : 0,
(flag & INPCK) ? 1 : 0,
(flag & ISTRIP) ? 1 : 0);
pprintf(" INLCR:%d IGNCR:%d ICRNL:%d IUCLC:%d ",
(flag & INLCR) ? 1 : 0,
(flag & IGNCR) ? 1 : 0,
(flag & ICRNL) ? 1 : 0,
(flag & IUCLC) ? 1 : 0);
pprintf("IXON:%d IXANY:%d IXOFF:%d\n",
(flag & IXON) ? 1 : 0,
(flag & IXANY) ? 1 : 0,
(flag & IXOFF) ? 1 : 0);
flag = ttt->c_oflag;
pprintf("oflag: %07o OPOST:%d OLCUC:%d ONLCR:%d OCRNL:%d ",
flag,
(flag & OPOST) ? 1 : 0,
(flag & OLCUC) ? 1 : 0,
(flag & ONLCR) ? 1 : 0,
(flag & OCRNL) ? 1 : 0);
pprintf("ONOCR:%d ONLRET:%d OFDEL:%d\n",
(flag & ONOCR) ? 1 : 0,
(flag & ONLRET) ? 1 : 0,
(flag & OFDEL) ? 1 : 0);
flag = ttt->c_lflag;
pprintf("lflag: %07o ISIG:%d ICANON:%d XCASE:%d ECHO:%d ECHOE:%d\n",
flag,
(flag & ISIG) ? 1 : 0,
(flag & ICANON) ? 1 : 0,
(flag & XCASE) ? 1 : 0,
(flag & ECHO) ? 1 : 0,
(flag & ECHOE) ? 1 : 0);
pprintf(" ECHOK:%d ECHONL:%d NOFLSH:%d",
(flag & ECHOK) ? 1 : 0,
(flag & ECHONL) ? 1 : 0,
(flag & NOFLSH) ? 1 : 0);
#if defined(XCLUDE)
pprintf(" XCLUDE:%d", (flag & XCLUDE) ? 1 : 0);
#endif
#endif
pprintf("\n");
flag = ttt->c_cflag;
pprintf("cflag: %07o ", ttt->c_cflag);
switch (ecugetspeed(ttt))
{
case B0:
bitrate = "HUP";
break;
case B50:
bitrate = "50";
break;
case B75:
bitrate = "75";
break;
case B110:
bitrate = "110";
break;
case B134:
bitrate = "134.5";
break;
case B150:
bitrate = "150";
break;
case B200:
bitrate = "200";
break;
case B300:
bitrate = "300";
break;
case B600:
bitrate = "600";
break;
case B1200:
bitrate = "1200";
break;
case B1800:
bitrate = "1800";
break;
case B2400:
bitrate = "2400";
break;
case B4800:
bitrate = "4800";
break;
case B9600:
bitrate = "9600";
break;
#if defined(B19200)
case B19200:
bitrate = "19200";
break;
#endif
#if defined(B38400)
case B38400:
bitrate = "38400";
break;
#endif
#if defined(B57600)
case B57600:
bitrate = "57600";
break;
#endif
#if defined(B115200)
case B115200:
bitrate = "115200";
break;
#endif
default:
switch (ecugetspeed(ttt))
{
case EXTA:
bitrate = "EXTA";
break;
case EXTB:
bitrate = "EXTB";
break;
default:
bitrate = "????";
break;
}
}
#ifndef CSIZE
#define CSIZE CS8
#endif
switch (flag & CSIZE)
{
case CS8:
dbits = '8';
break;
case CS7:
dbits = '7';
break;
case CS6:
dbits = '6';
break;
case CS5:
dbits = '5';
break;
default:
dbits = '?';
break;
}
parity = (flag & PARENB) ? ((flag & PARODD) ? 'O' : 'E') : 'N';
pprintf("%s-%c-%c-%d ", bitrate, dbits, parity, (flag & CSTOPB) ? 2 : 1);
pprintf("CREAD:%d HUPCL:%d CLOCAL:%d",
(flag & CREAD) ? 1 : 0,
(flag & HUPCL) ? 1 : 0,
(flag & CLOCAL) ? 1 : 0);
#if defined(RTSFLOW) /* SCO */
pprintf(" RTSFLOW:%d CTSFLOW:%d",
(flag & RTSFLOW) ? 1 : 0,
(flag & CTSFLOW) ? 1 : 0);
#endif
#if defined(CRTSFL) /* SCO 3.2v4 */
pprintf("\n CRTSFL:%d",
(flag & CRTSFL) ? 1 : 0);
#endif
#if defined(RTSXOFF) /* SVR4 */
pprintf(" RTSXOFF:%d CTSXON:%d",
(hx_flag & RTSXOFF) ? 1 : 0,
(hx_flag & CTSXON) ? 1 : 0);
#endif
#ifdef CRTSCTS /* sun */
pprintf(" CRTSCTS:%d", (flag & CRTSCTS) ? 1 : 0);
#endif
pputs("\n");
#ifdef __FreeBSD__
pputs("ctls: ");
for (i_cc = 0; i_cc < NCC; i_cc++)
{
if (i_cc == 7 || i_cc == 19)
continue;
pprintf("%02x ", ttt->c_cc[i_cc]);
}
pputs("\n");
pputs("(hex) EOF EOL EL2 ERS WRS KIL ");
pputs("RPR INT QUI SSP DSP STA STP LNX DIS MIN TIM STA\n");
#else
pprintf("ctl chars: ");
for (i_cc = 0; i_cc < ((NCC > 8) ? 8 : NCC); i_cc++)
pprintf("%02x ", ttt->c_cc[i_cc]);
pputs(" (hex)\n");
pputs(" INTR QUIT ERAS KILL EOF EOL ");
pputs("EOL2 SWTCH VMIN-EOF VTIME-EOL\n");
#endif
} /* end of disp_termio */
/*+-------------------------------------------------------------------------
disp_stat(st)
--------------------------------------------------------------------------*/
void
disp_stat(st)
struct stat *st;
{
char mdmap[32];
struct passwd *pw;
if (pw = getpwuid(st->st_uid))
pprintf("owner: %s ", pw->pw_name);
else
pprintf("uid: %d ", st->st_uid);
endpwent();
mode_map(st->st_mode, mdmap);
pprintf("mode: %s ", mdmap);
pprintf("inode: %5u dev: %3u rdev: %u,%u (0x%04x)\n",
(UINT) st->st_ino, (UINT) st->st_dev,
(UINT16) st->st_rdev >> 8, (UINT16) st->st_rdev & 0xFF,
(UINT16) st->st_rdev);
} /* end of disp_stat */
/*+-----------------------------------------------------------------------
disp_line_termio(fd)
Get current termio structure for file descriptor fd
and display on stderr
------------------------------------------------------------------------*/
void
disp_line_termio(fd, text)
int fd; /* file descriptor */
char *text;
{
struct TERMIO fd_termio;
struct stat fd_stat;
char text2[128];
ecugetattr(fd, &fd_termio);
sprintf(text2, "fd: %d %s", fd, text);
disp_termio(&fd_termio, text2);
fstat(fd, &fd_stat);
disp_stat(&fd_stat);
} /* end of disp_line_termio */
/*+-----------------------------------------------------------------------
ascii_name_to_hex(name)
return value of ascii ctl char name (e.g., "NUL") 0 - 0x1F
support CSI "ascii" 0x9B (for ESC + '[' ANSI)
returns -1 if input not valid
------------------------------------------------------------------------*/
ascii_name_to_hex(name)
char *name;
{
char **cpptr;
int itmp;
char s4[4];
if (!strcmpi(name, "del"))
return (0x7F);
else if (!strcmpi(name, "csi"))
return (0x9B);
else if ((itmp = strlen(name)) < 3)
{
if (!itmp)
return (-1);
memcpy(s4, " ", 4);
memcpy(s4, name, itmp);
name = s4;
}
cpptr = ascii_ctlstr;
for (itmp = 0; itmp <= SPACE; itmp++)
{
if (!strcmpi(name, *cpptr))
return (itmp);
cpptr++;
}
return (-1);
} /* end of ascii_name_to_hex */
/*+-------------------------------------------------------------------------
ascii_to_hex(ascii)
--------------------------------------------------------------------------*/
int
ascii_to_hex(ascii)
char *ascii;
{
int hexval;
if (strlen(ascii) == 1)
return (*ascii);
else if (!strncmp(ascii, "0x", 2))
{
sscanf(ascii + 2, "%x", &hexval);
return (hexval & 0xFF);
}
else if (*ascii == '^')
return (*(ascii + 1) & 0x1F);
else
return (ascii_name_to_hex(ascii));
} /* end of ascii_to_hex */
/*+-------------------------------------------------------------------------
hex_to_ascii_name(char_val)