summaryrefslogtreecommitdiff
path: root/usr/src/cmd/tip/cmds.c
blob: cfea2c6c82f4b6fb61b158bc34d85f4c5ee7d07b (plain)
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
/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Copyright (c) 1983 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#include "tip.h"
#include <limits.h>
#ifdef USG
#include <unistd.h>
#else
#include <vfork.h>
#endif

/*
 * tip
 *
 * miscellaneous commands
 */

struct termios arg;
struct termios defarg;
int	FD;
int	fildes[2];
int	repdes[2];
int	pid;
int	sfd;
int	stoprompt;
int	timedout;
int	quant[] = { 60, 60, 24 };

char	copyname[80];
char	fname[80];
char	ccc;
char	null = '\0';
char	*sep[] = { "second", "minute", "hour" };
static	char *argv[10];		/* argument vector for take and put */

sigjmp_buf intbuf;		/* for interrupts and timeouts */

void	timeout(void);		/* timeout function called on alarm */
void	intcopy(void);		/* interrupt routine for file transfers */
void	transfer(char *, int, char *);
void	transmit(FILE *, char *, char *);
void	send(char);
void	execute(char *);
void	prtime(char *, time_t);
void	hardwareflow(char *);
void	intr(char *);
int	args(char *, char *[], size_t);
int	anyof(char *, char *);

/*
 * FTP - remote ==> local
 *  get a file from the remote host
 */
void
getfl(int c)
{
	char buf[256], *cp;

	(void) putchar(c);
	/*
	 * get the UNIX receiving file's name
	 */
	if (prompt("Local file name? ", copyname, sizeof (copyname)))
		return;
	cp = expand(copyname);
	if (cp == NOSTR)
		return;
	if ((sfd = creat(cp, 0666)) < 0) {
		(void) printf("\r\n%s: cannot creat\r\n", copyname);
		return;
	}

	/*
	 * collect parameters
	 */
	if (prompt("List command for remote system? ", buf, sizeof (buf))) {
		(void) unlink(copyname);
		return;
	}
	transfer(buf, sfd, value(EOFREAD));
}

/*
 * Cu-like take command
 */
/* ARGSUSED */
void
cu_take(int cc)
{
	int fd, argc;
	char line[BUFSIZ], *cp;

	if (prompt("[take] ", copyname, sizeof (copyname)))
		return;
	argc = args(copyname, argv, sizeof (argv)/sizeof (char *));
	if (argc < 1 || argc > 2) {
		(void) printf("usage: <take> from [to]\r\n");
		return;
	}
	if (argc == 1)
		argv[1] = argv[0];
	cp = expand(argv[1]);
	if (cp == NOSTR)
		return;
	if ((fd = creat(cp, 0666)) < 0) {
		(void) printf("\r\n%s: cannot create\r\n", argv[1]);
		return;
	}
	(void) snprintf(line, sizeof (line), "cat %s; echo \01", argv[0]);
	transfer(line, fd, "\01");
}

/*
 * Bulk transfer routine --
 *  used by getfl(), cu_take(), and pipefile()
 */
void
transfer(char *buf, int fd, char *eofchars)
{
	int ct;
	char c, buffer[BUFSIZ];
	char *p = buffer;	/* can't be register because of longjmp */
	int cnt, eof, bol;
	time_t start;
	sig_handler_t	f;

	parwrite(FD, (unsigned char *)buf, strlen(buf));
	(void) kill(pid, SIGIOT);
	/* Wait until read process stops */
	(void) read(repdes[0], (char *)&ccc, 1);

	/*
	 * finish command
	 */
	parwrite(FD, (unsigned char *)"\r", 1);
	do
		(void) read(FD, &c, 1);
	while ((c&0177) != '\n')
		;

	if (sigsetjmp(intbuf, 1))
		goto out;
	f = signal(SIGINT, (sig_handler_t)intcopy);
	intr("on");

	start = time(0);
	bol = 1;
	ct = 0;
	for (;;) {
		eof = read(FD, &c, 1) <= 0;
		if (noparity)
			c &= 0377;
		else
			c &= 0177;
		if (eof || (bol && any(c, eofchars)))
			break;
		if (c == 0)
			continue;	/* ignore nulls */
		if (c == '\r')
			continue;
		*p++ = c;

		if (c == '\n') {
			bol = 1;
			if (boolean(value(VERBOSE)))
				(void) printf("\r%d", ++ct);
		} else
			bol = 0;
		if ((cnt = (p-buffer)) == number(value(FRAMESIZE))) {
			if (write(fd, buffer, cnt) != cnt) {
				(void) printf("\r\nwrite error\r\n");
				goto out;
			}
			p = buffer;
		}
	}
out:
	if ((cnt = (p-buffer)) != 0)
		if (write(fd, buffer, cnt) != cnt)
			(void) printf("\r\nwrite error\r\n");

	if (boolean(value(VERBOSE)))
		prtime(" lines transferred in ", time(0)-start);
	intr("off");
	(void) write(fildes[1], (char *)&ccc, 1);
	(void) signal(SIGINT, f);
	(void) close(fd);
}

/*
 * FTP - remote ==> local process
 *   send remote input to local process via pipe
 */
/* ARGSUSED */
void
pipefile(int cc)
{
	int cpid, pdes[2];
	char buf[256];
	int status, p;

	if (prompt("Local command? ", buf, sizeof (buf)))
		return;

	if (pipe(pdes)) {
		(void) printf("can't establish pipe\r\n");
		return;
	}

	if ((cpid = fork()) < 0) {
		(void) printf("can't fork!\r\n");
		return;
	} else if (cpid) {
		if (prompt("List command for remote system? ", buf,
		    sizeof (buf))) {
			(void) close(pdes[0]), (void) close(pdes[1]);
			(void) kill(cpid, SIGKILL);
		} else {
			(void) close(pdes[0]);
			(void) signal(SIGPIPE, (sig_handler_t)intcopy);
			transfer(buf, pdes[1], value(EOFREAD));
			(void) signal(SIGPIPE, SIG_DFL);
			while ((p = wait(&status)) > 0 && p != cpid)
				;
		}
	} else {
		int f;

		userperm();
		(void) dup2(pdes[0], 0);
		(void) close(pdes[0]);
		for (f = 3; f < 20; f++)
			(void) close(f);
		execute(buf);
		(void) printf("can't execl!\r\n");
		exit(0);
	}
}

/*
 * FTP - local ==> remote
 *  send local file to remote host
 *  terminate transmission with pseudo EOF sequence
 */
void
tip_sendfile(int cc)
{
	FILE *fd;
	char *fnamex;

	(void) putchar(cc);
	/*
	 * get file name
	 */
	if (prompt("Local file name? ", fname, sizeof (fname)))
		return;

	/*
	 * look up file
	 */
	fnamex = expand(fname);
	if (fnamex == NOSTR)
		return;
	if ((fd = fopen(fnamex, "r")) == NULL) {
		(void) printf("%s: cannot open\r\n", fname);
		return;
	}
	transmit(fd, value(EOFWRITE), NULL);
	if (!boolean(value(ECHOCHECK))) {
		struct termios buf;

		(void) ioctl(FD, TCGETS, (char *)&buf);	/* this does a */
		(void) ioctl(FD, TCSETSF, (char *)&buf);	/* wflushtty */
	}
}

/*
 * Bulk transfer routine to remote host --
 *   used by tip_sendfile() and cu_put()
 */
void
transmit(FILE *fd, char *eofchars, char *command)
{
	sig_handler_t	ointr;
	char *pc, lastc, rc;
	int c, ccount, lcount;
	time_t start_t, stop_t;

	(void) kill(pid, SIGIOT);	/* put TIPOUT into a wait state */
	timedout = 0;
	if (sigsetjmp(intbuf, 1)) {
		if (timedout)
			(void) printf("\r\ntimed out at eol\r\n");
		(void) alarm(0);
		goto out;
	}
	ointr = signal(SIGINT, (sig_handler_t)intcopy);
	intr("on");
	(void) read(repdes[0], (char *)&ccc, 1);
	if (command != NULL) {
		for (pc = command; *pc; pc++)
			send(*pc);
		if (boolean(value(ECHOCHECK)))
			(void) read(FD, (char *)&c, 1);	/* trailing \n */
		else {
			struct termios buf;
			/* wait for remote stty to take effect */
			(void) sleep(5);
			/* this does a */
			(void) ioctl(FD, TCGETS, (char *)&buf);
			/* wflushtty */
			(void) ioctl(FD, TCSETSF, (char *)&buf);
		}
	}
	lcount = 0;
	lastc = '\0';
	start_t = time(0);
	if (boolean(value(RAWFTP))) {
		while ((c = getc(fd)) != EOF) {
			lcount++;
			send(c);
			if (boolean(value(VERBOSE)) && lcount%100 == 0)
				(void) printf("\r%d", lcount);
		}
		if (boolean(value(VERBOSE)))
			(void) printf("\r%d", lcount);
		goto out;
	}
	for (;;) {
		ccount = 0;
		do {
			c = getc(fd);
			if (c == EOF)
				goto out;
			if (c == 0177)
				continue;
			lastc = c;
			if (c < 040) {
				if (c == '\n') {
					c = '\r';
				} else if (c == '\t') {
					if (boolean(value(TABEXPAND))) {
						send(' ');
						while ((++ccount % 8) != 0)
							send(' ');
						continue;
					}
				} else
					continue;
			}
			send(c);
		} while (c != '\r');
		if (boolean(value(VERBOSE)))
			(void) printf("\r%d", ++lcount);
		if (boolean(value(ECHOCHECK))) {
			(void) alarm(number(value(ETIMEOUT)));
			do {	/* wait for prompt */
				(void) read(FD, &rc, 1);
			} while ((rc&0177) != character(value(PROMPT)));
			(void) alarm(0);
		}
	}
out:
	if (lastc != '\n' && !boolean(value(RAWFTP)))
		send('\r');
	if (eofchars)
		for (pc = eofchars; *pc; pc++)
			send(*pc);
	stop_t = time(0);
	(void) fclose(fd);
	if (boolean(value(VERBOSE)))
		if (boolean(value(RAWFTP)))
			prtime(" chars transferred in ", stop_t-start_t);
		else
			prtime(" lines transferred in ", stop_t-start_t);
	(void) write(fildes[1], (char *)&ccc, 1);
	intr("off");
	(void) signal(SIGINT, ointr);
}

/*
 * Cu-like put command
 */
/* ARGSUSED */
void
cu_put(int cc)
{
	FILE *fd;
	char line[BUFSIZ];
	int argc;
	char *copynamex;

	if (prompt("[put] ", copyname, sizeof (copyname)))
		return;
	argc = args(copyname, argv, sizeof (argv)/sizeof (char *));
	if (argc < 1 || argc > 2) {
		(void) printf("usage: <put> from [to]\r\n");
		return;
	}
	if (argc == 1)
		argv[1] = argv[0];
	copynamex = expand(argv[0]);
	if (copynamex == NOSTR)
		return;
	if ((fd = fopen(copynamex, "r")) == NULL) {
		(void) printf("%s: cannot open\r\n", copynamex);
		return;
	}
	if (boolean(value(ECHOCHECK)))
		(void) snprintf(line, sizeof (line), "cat>%s\r", argv[1]);
	else
		(void) snprintf(line, sizeof (line),
		    "stty -echo; cat>%s; stty echo\r", argv[1]);
	transmit(fd, "\04", line);
}

/*
 * FTP - send single character
 *  wait for echo & handle timeout
 */
void
send(char c)
{
	char cc;
	int retry = 0;

	cc = c;
	parwrite(FD, (unsigned char *)&cc, 1);
#ifdef notdef
	if (number(value(CDELAY)) > 0 && c != '\r')
		nap(number(value(CDELAY)));
#endif
	if (!boolean(value(ECHOCHECK))) {
#ifdef notdef
		if (number(value(LDELAY)) > 0 && c == '\r')
			nap(number(value(LDELAY)));
#endif
		return;
	}
tryagain:
	timedout = 0;
	if (sigsetjmp(intbuf, 1) && timedout) {
		(void) printf("\r\ntimeout error (%s)\r\n", ctrl(c));
		if (retry++ > 3)
			return;
		parwrite(FD, (unsigned char *)&null, 1); /* poke it */
		goto tryagain;
	}
	(void) alarm(number(value(ETIMEOUT)));
	(void) read(FD, &cc, 1);
	(void) alarm(0);
}

void
timeout(void)
{
	(void) signal(SIGALRM, (sig_handler_t)timeout);
	timedout = 1;
	siglongjmp(intbuf, 1);
}

/*
 * Stolen from consh() -- puts a remote file on the output of a local command.
 *	Identical to consh() except for where stdout goes.
 */
void
pipeout(int c)
{
	char buf[256];
	int cpid, status, p;
	time_t start;

	(void) putchar(c);
	if (prompt("Local command? ", buf, sizeof (buf)))
		return;
	(void) kill(pid, SIGIOT);	/* put TIPOUT into a wait state */
	(void) signal(SIGINT, SIG_IGN);
	(void) signal(SIGQUIT, SIG_IGN);
	intr("on");
	(void) read(repdes[0], (char *)&ccc, 1);
	/*
	 * Set up file descriptors in the child and
	 *  let it go...
	 */
	if ((cpid = fork()) < 0)
		(void) printf("can't fork!\r\n");
	else if (cpid) {
		start = time(0);
		while ((p = wait(&status)) > 0 && p != cpid)
			;
	} else {
		int i;

		userperm();
		(void) dup2(FD, 1);
		for (i = 3; i < 20; i++)
			(void) close(i);
		(void) signal(SIGINT, SIG_DFL);
		(void) signal(SIGQUIT, SIG_DFL);
		execute(buf);
		(void) printf("can't find `%s'\r\n", buf);
		exit(0);
	}
	if (boolean(value(VERBOSE)))
		prtime("away for ", time(0)-start);
	(void) write(fildes[1], (char *)&ccc, 1);
	intr("off");
	(void) signal(SIGINT, SIG_DFL);
	(void) signal(SIGQUIT, SIG_DFL);
}

/*
 * Fork a program with:
 *  0 <-> remote tty in
 *  1 <-> remote tty out
 *  2 <-> local tty stderr out
 */
void
consh(int c)
{
	char buf[256];
	int cpid, status, p;
	sig_handler_t	ointr, oquit;
	time_t start;

	(void) putchar(c);
	if (prompt("Local command? ", buf, sizeof (buf)))
		return;
	(void) kill(pid, SIGIOT);	/* put TIPOUT into a wait state */
	(void) read(repdes[0], (char *)&ccc, 1);
	ointr = signal(SIGINT, SIG_IGN);
	oquit = signal(SIGQUIT, SIG_IGN);
	unraw();
	/*
	 * Set up file descriptors in the child and
	 *  let it go...
	 */
	if ((cpid = fork()) < 0)
		(void) printf("can't fork!\r\n");
	else if (cpid) {
		start = time(0);
		while ((p = wait(&status)) > 0 && p != cpid)
			;
		raw();
		(void) signal(SIGINT, ointr);
		(void) signal(SIGQUIT, oquit);
	} else {
		int i;

		userperm();
		(void) dup2(FD, 0);
		(void) dup2(0, 1);
		for (i = 3; i < 20; i++)
			(void) close(i);
		(void) signal(SIGINT, SIG_DFL);
		(void) signal(SIGQUIT, SIG_DFL);
		execute(buf);
		(void) printf("can't find `%s'\r\n", buf);
		exit(0);
	}
	if (boolean(value(VERBOSE)))
		prtime("\r\naway for ", time(0)-start);
	(void) write(fildes[1], (char *)&ccc, 1);
}

/*
 * Escape to local shell
 */
/* ARGSUSED */
void
shell(int cc)
{
	int shpid, status;
	sig_handler_t	ointr, oquit;
	char *cp;

	(void) printf("[sh]\r\n");
	ointr = signal(SIGINT, SIG_IGN);
	oquit = signal(SIGQUIT, SIG_IGN);
	unraw();
	if (shpid = fork()) {
		while (shpid != wait(&status))
			;
		raw();
		(void) printf("\r\n!\r\n");
		(void) signal(SIGINT, ointr);
		(void) signal(SIGQUIT, oquit);
	} else {
		userperm();
		(void) signal(SIGQUIT, SIG_DFL);
		(void) signal(SIGINT, SIG_DFL);
		if ((cp = strrchr(value(SHELL), '/')) == NULL)
			cp = value(SHELL);
		else
			cp++;
		(void) execl(value(SHELL), cp, 0);
		(void) printf("\r\ncan't execl!\r\n");
		exit(1);
	}
}

/*
 * TIPIN portion of scripting
 *   initiate the conversation with TIPOUT
 */
void
setscript(void)
{
	char c;

	if (strlen(value(RECORD)) >= PATH_MAX-1) {
		(void) fprintf(stderr, "tip: record file name too long\r\n");
		return;
	}
	/*
	 * enable TIPOUT side for dialogue
	 */
	(void) kill(pid, SIGEMT);
	if (boolean(value(SCRIPT)))
		(void) write(fildes[1], value(RECORD), strlen(value(RECORD)));
	(void) write(fildes[1], "\n", 1);
	/*
	 * wait for TIPOUT to finish
	 */
	(void) read(repdes[0], &c, 1);
	if (c == 'n')
		(void) fprintf(stderr, "tip: can't create record file %s\r\n",
		    value(RECORD));
}

/*
 * Change current working directory of
 *   local portion of tip
 */
/* ARGSUSED */
void
chdirectory(int cc)
{
	char dirname[80];
	char *cp = dirname;

	if (prompt("[cd] ", dirname, sizeof (dirname))) {
		if (stoprompt)
			return;
		cp = value(HOME);
	}
	if (chdir(cp) < 0)
		(void) printf("%s: bad directory\r\n", cp);
	(void) printf("!\r\n");
}

void
tip_abort(char *msg)
{
	/* don't want to hear about our child */
	(void) signal(SIGCHLD, SIG_DFL);
	(void) kill(pid, SIGTERM);
	myperm();
	disconnect(msg);
	if (msg != NOSTR)
		(void) printf("\r\n%s", msg);
	(void) printf("\r\n[EOT]\r\n");
	delock(uucplock);
	unraw();
	exit(0);
}

/* ARGSUSED */
void
finish(int cc)
{
	char *dismsg;

	if ((dismsg = value(DISCONNECT)) != NOSTR) {
		(void) write(FD, dismsg, strlen(dismsg));
		(void) sleep(5);
	}
	tip_abort(NOSTR);
}

void
intcopy(void)
{

	(void) signal(SIGINT, SIG_IGN);
	siglongjmp(intbuf, 1);
}

void
execute(char *s)
{
	char *cp;

	if ((cp = strrchr(value(SHELL), '/')) == NULL)
		cp = value(SHELL);
	else
		cp++;
	(void) execl(value(SHELL), cp, "-c", s, 0);
}

int
args(char *buf, char *a[], size_t na)
{
	char *p = buf, *start;
	char **parg = a;
	int n = 0;

	do {
		while (*p && (*p == ' ' || *p == '\t'))
			p++;
		start = p;
		if (*p)
			*parg = p;
		while (*p && (*p != ' ' && *p != '\t'))
			p++;
		if (p != start)
			parg++, n++;
		if (*p)
			*p++ = '\0';
	} while (*p && n < na);

	return (n);
}

void
prtime(char *s, time_t a)
{
	int i;
	int nums[3];

	for (i = 0; i < 3; i++) {
		nums[i] = (int)(a % quant[i]);
		a /= quant[i];
	}
	(void) printf("%s", s);
	while (--i >= 0)
		if (nums[i] || i == 0 && nums[1] == 0 && nums[2] == 0)
			(void) printf("%d %s%c ", nums[i], sep[i],
			    nums[i] == 1 ? '\0' : 's');
	(void) printf("\r\n!\r\n");
}

/* ARGSUSED */
void
variable(int cc)
{
	char	buf[256];

	if (prompt("[set] ", buf, sizeof (buf)))
		return;
	vlex(buf);
	if (vtable[BEAUTIFY].v_access&CHANGED) {
		vtable[BEAUTIFY].v_access &= ~CHANGED;
		(void) kill(pid, SIGSYS);
	}
	if (vtable[SCRIPT].v_access&CHANGED) {
		vtable[SCRIPT].v_access &= ~CHANGED;
		setscript();
		/*
		 * So that "set record=blah script" doesn't
		 *  cause two transactions to occur.
		 */
		if (vtable[RECORD].v_access&CHANGED)
			vtable[RECORD].v_access &= ~CHANGED;
	}
	if (vtable[RECORD].v_access&CHANGED) {
		vtable[RECORD].v_access &= ~CHANGED;
		if (boolean(value(SCRIPT)))
			setscript();
	}
	if (vtable[TAND].v_access&CHANGED) {
		vtable[TAND].v_access &= ~CHANGED;
		if (boolean(value(TAND)))
			tandem("on");
		else
			tandem("off");
	}
	if (vtable[LECHO].v_access&CHANGED) {
		vtable[LECHO].v_access &= ~CHANGED;
		boolean(value(HALFDUPLEX)) = boolean(value(LECHO));
	}
	if (vtable[PARITY].v_access&CHANGED) {
		vtable[PARITY].v_access &= ~CHANGED;
		setparity(NULL);
	}
	if (vtable[BAUDRATE].v_access&CHANGED) {
		vtable[BAUDRATE].v_access &= ~CHANGED;
		ttysetup(speed(number(value(BAUDRATE))));
	}
	if (vtable[HARDWAREFLOW].v_access & CHANGED) {
		vtable[HARDWAREFLOW].v_access &= ~CHANGED;
		if (boolean(value(HARDWAREFLOW)))
			hardwareflow("on");
		else
			hardwareflow("off");
	}
}

/*
 * Turn tandem mode on or off for remote tty.
 */
void
tandem(char *option)
{
	struct termios rmtty;

	(void) ioctl(FD, TCGETS, (char *)&rmtty);
	if (equal(option, "on")) {
		rmtty.c_iflag |= IXOFF|IXON;
		arg.c_iflag |= IXOFF|IXON;
		rmtty.c_cc[VSTART] = defarg.c_cc[VSTART];
		rmtty.c_cc[VSTOP] = defarg.c_cc[VSTOP];
	} else {
		rmtty.c_iflag &= ~(IXOFF|IXON);
		arg.c_iflag &= ~(IXOFF|IXON);
	}
	(void) ioctl(FD, TCSETSF, (char *)&rmtty);
	(void) ioctl(0, TCSETSF, (char *)&arg);
}

/*
 * Turn hardwareflow mode on or off for remote tty.
 */
void
hardwareflow(char *option)
{
	struct termios rmtty;

	(void) ioctl(FD, TCGETS, (char *)&rmtty);
	if (equal(option, "on")) {
		rmtty.c_cflag |= (CRTSCTS|CRTSXOFF);
	} else {
		rmtty.c_cflag &= ~(CRTSCTS|CRTSXOFF);
	}
	(void) ioctl(FD, TCSETSF, (char *)&rmtty);
}

/*
 * Turn interrupts from local tty on or off.
 */
void
intr(char *option)
{

	if (equal(option, "on"))
		arg.c_lflag |= ISIG;
	else
		arg.c_lflag &= ~ISIG;
	(void) ioctl(0, TCSETSF, (char *)&arg);
}

/*
 * Send a break.
 */
/* ARGSUSED */
void
genbrk(int cc)
{

	(void) ioctl(FD, TCSBRK, 0);
}

/*
 * Suspend tip
 */
void
suspend(int c)
{

	unraw();
	(void) kill(c == _CTRL('y') ? getpid() : 0, SIGTSTP);
	raw();
}

/*
 *	expand a file name if it includes shell meta characters
 */

char *
expand(char name[])
{
	static char xname[BUFSIZ];
	char cmdbuf[BUFSIZ];
	int pid, l;
	char *cp, *Shell;
	int s, pivec[2];

	if (!anyof(name, "~{[*?$`'\"\\"))
		return (name);
	if (pipe(pivec) < 0) {
		perror("pipe");
		return (name);
	}
	(void) snprintf(cmdbuf, sizeof (cmdbuf), "echo %s", name);
	if ((pid = vfork()) == 0) {
		userperm();
		Shell = value(SHELL);
		if (Shell == NOSTR)
			Shell = "/bin/sh";
		(void) close(pivec[0]);
		(void) close(1);
		(void) dup(pivec[1]);
		(void) close(pivec[1]);
		(void) close(2);
		(void) execl(Shell, Shell, "-c", cmdbuf, 0);
		_exit(1);
	}
	if (pid == -1) {
		perror("fork");
		(void) close(pivec[0]);
		(void) close(pivec[1]);
		return (NOSTR);
	}
	(void) close(pivec[1]);
	l = read(pivec[0], xname, BUFSIZ);
	(void) close(pivec[0]);
	while (wait(&s) != pid)
		;
	s &= 0377;
	if (s != 0 && s != SIGPIPE) {
		(void) fprintf(stderr, "\"Echo\" failed\n");
		return (NOSTR);
	}
	if (l < 0) {
		perror("read");
		return (NOSTR);
	}
	if (l == 0) {
		(void) fprintf(stderr, "\"%s\": No match\n", name);
		return (NOSTR);
	}
	if (l == BUFSIZ) {
		(void) fprintf(stderr, "Buffer overflow expanding \"%s\"\n",
		    name);
		return (NOSTR);
	}
	xname[l] = 0;
	for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
		;
	*++cp = '\0';
	return (xname);
}

/*
 * Are any of the characters in the two strings the same?
 */

int
anyof(char *s1, char *s2)
{
	int c;

	while ((c = *s1++) != 0)
		if (any(c, s2))
			return (1);
	return (0);
}