set.c revision 1.39 1 /* $NetBSD: set.c,v 1.39 2022/09/14 16:15:51 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1980, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)set.c 8.1 (Berkeley) 5/31/93";
36 #else
37 __RCSID("$NetBSD: set.c,v 1.39 2022/09/14 16:15:51 christos Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include <sys/types.h>
42
43 #include <stdarg.h>
44 #include <stdlib.h>
45
46 #include <string.h>
47
48 #include "csh.h"
49 #include "extern.h"
50
51 static Char *getinx(Char *, int *);
52 static void asx(Char *, int, Char *);
53 static struct varent *getvx(Char *, int);
54 static Char *xset(Char *, Char ***);
55 static Char *operate(int, Char *, Char *);
56 static void putn1(int);
57 static struct varent *madrof(Char *, struct varent *);
58 static void unsetv1(struct varent *);
59 static void exportpath(Char **);
60 static void balance(struct varent *, int, int);
61
62 static int wantediting;
63
64 #ifdef EDIT
65 static const char *
66 alias_text(void *dummy __unused, const char *name)
67 {
68 static char *buf;
69 struct varent *vp;
70 Char **av;
71 char *p;
72 size_t len;
73
74 vp = adrof1(str2short(name), &aliases);
75 if (vp == NULL)
76 return NULL;
77
78 len = 0;
79 for (av = vp->vec; *av; av++) {
80 len += strlen(vis_str(*av));
81 if (av[1])
82 len++;
83 }
84 len++;
85 free(buf);
86 p = buf = xmalloc(len);
87 for (av = vp->vec; *av; av++) {
88 const char *s = vis_str(*av);
89 while ((*p++ = *s++) != '\0')
90 continue;
91 if (av[1])
92 *p++ = ' ';
93 }
94 *p = '\0';
95 return buf;
96 }
97 #endif
98
99 /*
100 * C Shell
101 */
102
103 static void
104 update_vars(Char *vp)
105 {
106 if (eq(vp, STRpath)) {
107 struct varent *pt = adrof(STRpath);
108 if (pt == NULL)
109 stderror(ERR_NAME | ERR_UNDVAR);
110 else {
111 exportpath(pt->vec);
112 dohash(NULL, NULL);
113 }
114 }
115 else if (eq(vp, STRhistchars)) {
116 Char *pn = value(STRhistchars);
117
118 HIST = *pn++;
119 HISTSUB = *pn;
120 }
121 else if (eq(vp, STRuser)) {
122 Setenv(STRUSER, value(vp));
123 Setenv(STRLOGNAME, value(vp));
124 }
125 else if (eq(vp, STRwordchars)) {
126 word_chars = value(vp);
127 }
128 else if (eq(vp, STRterm))
129 Setenv(STRTERM, value(vp));
130 else if (eq(vp, STRhome)) {
131 Char *cp;
132
133 cp = Strsave(value(vp)); /* get the old value back */
134
135 /*
136 * convert to canonical pathname (possibly resolving symlinks)
137 */
138 cp = dcanon(cp, cp);
139
140 set(vp, Strsave(cp)); /* have to save the new val */
141
142 /* and now mirror home with HOME */
143 Setenv(STRHOME, cp);
144 /* fix directory stack for new tilde home */
145 dtilde();
146 free(cp);
147 }
148 #ifdef FILEC
149 else if (eq(vp, STRfilec))
150 filec = 1;
151 #endif
152 #ifdef EDIT
153 else if (eq(vp, STRedit))
154 wantediting = 1;
155 #endif
156 }
157
158 void
159 /*ARGSUSED*/
160 doset(Char **v, struct command *t)
161 {
162 Char op, *p, **vecp, *vp;
163 int subscr = 0; /* XXX: GCC */
164 int hadsub;
165
166 v++;
167 p = *v++;
168 if (p == 0) {
169 prvars();
170 return;
171 }
172 do {
173 hadsub = 0;
174 vp = p;
175 if (letter(*p))
176 for (; alnum(*p); p++)
177 continue;
178 if (vp == p || !letter(*vp))
179 stderror(ERR_NAME | ERR_VARBEGIN);
180 if ((p - vp) > MAXVARLEN)
181 stderror(ERR_NAME | ERR_VARTOOLONG);
182 if (*p == '[') {
183 hadsub++;
184 p = getinx(p, &subscr);
185 }
186 if ((op = *p) != '\0') {
187 *p++ = 0;
188 if (*p == 0 && *v && **v == '(')
189 p = *v++;
190 }
191 else if (*v && eq(*v, STRequal)) {
192 op = '=', v++;
193 if (*v)
194 p = *v++;
195 }
196 if (op && op != '=')
197 stderror(ERR_NAME | ERR_SYNTAX);
198 if (eq(p, STRLparen)) {
199 Char **e = v;
200
201 if (hadsub)
202 stderror(ERR_NAME | ERR_SYNTAX);
203 for (;;) {
204 if (!*e)
205 stderror(ERR_NAME | ERR_MISSING, ')');
206 if (**e == ')')
207 break;
208 e++;
209 }
210 p = *e;
211 *e = 0;
212 vecp = saveblk(v);
213 set1(vp, vecp, &shvhed);
214 *e = p;
215 v = e + 1;
216 }
217 else if (hadsub)
218 asx(vp, subscr, Strsave(p));
219 else
220 set(vp, Strsave(p));
221 update_vars(vp);
222 } while ((p = *v++) != NULL);
223 }
224
225 static Char *
226 getinx(Char *cp, int *ip)
227 {
228 *ip = 0;
229 *cp++ = 0;
230 while (*cp && Isdigit(*cp))
231 *ip = *ip * 10 + *cp++ - '0';
232 if (*cp++ != ']')
233 stderror(ERR_NAME | ERR_SUBSCRIPT);
234 return (cp);
235 }
236
237 static void
238 asx(Char *vp, int subscr, Char *p)
239 {
240 struct varent *v;
241
242 v = getvx(vp, subscr);
243 free(v->vec[subscr - 1]);
244 v->vec[subscr - 1] = globone(p, G_APPEND);
245 }
246
247 static struct varent *
248 getvx(Char *vp, int subscr)
249 {
250 struct varent *v;
251
252 v = adrof(vp);
253 if (v == 0)
254 udvar(vp);
255 if (subscr < 1 || subscr > blklen(v->vec))
256 stderror(ERR_NAME | ERR_RANGE);
257 return (v);
258 }
259
260 void
261 /*ARGSUSED*/
262 dolet(Char **v, struct command *t)
263 {
264 Char c, op, *p, *vp;
265 int subscr = 0; /* XXX: GCC */
266 int hadsub;
267
268 v++;
269 p = *v++;
270 if (p == 0) {
271 prvars();
272 return;
273 }
274 do {
275 hadsub = 0;
276 vp = p;
277 if (letter(*p))
278 for (; alnum(*p); p++)
279 continue;
280 if (vp == p || !letter(*vp))
281 stderror(ERR_NAME | ERR_VARBEGIN);
282 if ((p - vp) > MAXVARLEN)
283 stderror(ERR_NAME | ERR_VARTOOLONG);
284 if (*p == '[') {
285 hadsub++;
286 p = getinx(p, &subscr);
287 }
288 if (*p == 0 && *v)
289 p = *v++;
290 if ((op = *p) != '\0')
291 *p++ = 0;
292 else
293 stderror(ERR_NAME | ERR_ASSIGN);
294
295 if (*p == '\0' && *v == NULL)
296 stderror(ERR_NAME | ERR_ASSIGN);
297
298 vp = Strsave(vp);
299 if (op == '=') {
300 c = '=';
301 p = xset(p, &v);
302 }
303 else {
304 c = *p++;
305 if (any("+-", c)) {
306 if (c != op || *p)
307 stderror(ERR_NAME | ERR_UNKNOWNOP);
308 p = Strsave(STR1);
309 }
310 else {
311 if (any("<>", op)) {
312 if (c != op)
313 stderror(ERR_NAME | ERR_UNKNOWNOP);
314 c = *p++;
315 stderror(ERR_NAME | ERR_SYNTAX);
316 }
317 if (c != '=')
318 stderror(ERR_NAME | ERR_UNKNOWNOP);
319 p = xset(p, &v);
320 }
321 }
322 if (op == '=') {
323 if (hadsub)
324 asx(vp, subscr, p);
325 else
326 set(vp, p);
327 } else if (hadsub) {
328 struct varent *gv = getvx(vp, subscr);
329
330 asx(vp, subscr, operate(op, gv->vec[subscr - 1], p));
331 }
332 else
333 set(vp, operate(op, value(vp), p));
334 if (eq(vp, STRpath)) {
335 struct varent *pt = adrof(STRpath);
336 if (pt == NULL)
337 stderror(ERR_NAME | ERR_UNDVAR);
338 else {
339 exportpath(pt->vec);
340 dohash(NULL, NULL);
341 }
342 }
343 free(vp);
344 if (c != '=')
345 free(p);
346 } while ((p = *v++) != NULL);
347 }
348
349 static Char *
350 xset(Char *cp, Char ***vp)
351 {
352 Char *dp;
353
354 if (*cp) {
355 dp = Strsave(cp);
356 --(*vp);
357 free(** vp);
358 **vp = dp;
359 }
360 return (putn(expr(vp)));
361 }
362
363 static Char *
364 operate(int op, Char *vp, Char *p)
365 {
366 Char opr[2], **v, *vec[5], **vecp;
367 int i;
368
369 v = vec;
370 vecp = v;
371 if (op != '=') {
372 if (*vp)
373 *v++ = vp;
374 opr[0] = (Char)op;
375 opr[1] = 0;
376 *v++ = opr;
377 if (op == '<' || op == '>')
378 *v++ = opr;
379 }
380 *v++ = p;
381 *v++ = 0;
382 i = expr(&vecp);
383 if (*vecp)
384 stderror(ERR_NAME | ERR_EXPRESSION);
385 return (putn(i));
386 }
387
388 static Char *putp;
389
390 Char *
391 putn(int n)
392 {
393 static Char numbers[15];
394
395 putp = numbers;
396 if (n < 0) {
397 n = -n;
398 *putp++ = '-';
399 }
400 if ((unsigned int)n == 0x80000000U) {
401 *putp++ = '2';
402 n = 147483648;
403 }
404 putn1(n);
405 *putp = 0;
406 return (Strsave(numbers));
407 }
408
409 static void
410 putn1(int n)
411 {
412 if (n > 9)
413 putn1(n / 10);
414 *putp++ = (Char)(n % 10 + '0');
415 }
416
417 int
418 getn(Char *cp)
419 {
420 int n, sign;
421
422 sign = 0;
423 if (cp[0] == '+' && cp[1])
424 cp++;
425 if (*cp == '-') {
426 sign++;
427 cp++;
428 if (!Isdigit(*cp))
429 stderror(ERR_NAME | ERR_BADNUM);
430 }
431 n = 0;
432 while (Isdigit(*cp))
433 n = n * 10 + *cp++ - '0';
434 if (*cp)
435 stderror(ERR_NAME | ERR_BADNUM);
436 return (sign ? -n : n);
437 }
438
439 Char *
440 value1(Char *var, struct varent *head)
441 {
442 struct varent *vp;
443
444 vp = adrof1(var, head);
445 return (vp == 0 || vp->vec[0] == 0 ? STRNULL : vp->vec[0]);
446 }
447
448 static struct varent *
449 madrof(Char *pat, struct varent *vp)
450 {
451 struct varent *vp1;
452
453 for (; vp; vp = vp->v_right) {
454 if (vp->v_left && (vp1 = madrof(pat, vp->v_left)))
455 return vp1;
456 if (Gmatch(vp->v_name, pat))
457 return vp;
458 }
459 return vp;
460 }
461
462 struct varent *
463 adrof1(Char *name, struct varent *v)
464 {
465 int cmp;
466
467 v = v->v_left;
468 while (v && ((cmp = *name - *v->v_name) ||
469 (cmp = Strcmp(name, v->v_name))))
470 if (cmp < 0)
471 v = v->v_left;
472 else
473 v = v->v_right;
474 return v;
475 }
476
477 /*
478 * The caller is responsible for putting value in a safe place
479 */
480 void
481 set(Char *var, Char *val)
482 {
483 Char **vec;
484
485 vec = xmalloc(2 * sizeof(*vec));
486 vec[0] = val;
487 vec[1] = 0;
488 set1(var, vec, &shvhed);
489 }
490
491 void
492 set1(Char *var, Char **vec, struct varent *head)
493 {
494 Char **oldv;
495
496 oldv = vec;
497 gflag = 0;
498 tglob(oldv);
499 if (gflag) {
500 vec = globall(oldv);
501 if (vec == 0) {
502 blkfree(oldv);
503 stderror(ERR_NAME | ERR_NOMATCH);
504 }
505 blkfree(oldv);
506 gargv = 0;
507 }
508 setq(var, vec, head);
509 }
510
511 void
512 setq(Char *name, Char **vec, struct varent *p)
513 {
514 struct varent *c;
515 int f;
516
517 f = 0; /* tree hangs off the header's left link */
518 while ((c = p->v_link[f]) != NULL) {
519 if ((f = *name - *c->v_name) == 0 &&
520 (f = Strcmp(name, c->v_name)) == 0) {
521 blkfree(c->vec);
522 goto found;
523 }
524 p = c;
525 f = f > 0;
526 }
527 p->v_link[f] = c = xmalloc(sizeof(*c));
528 c->v_name = Strsave(name);
529 c->v_bal = 0;
530 c->v_left = c->v_right = 0;
531 c->v_parent = p;
532 balance(p, f, 0);
533 found:
534 trim(c->vec = vec);
535 }
536
537 void
538 /*ARGSUSED*/
539 unset(Char **v, struct command *t)
540 {
541 unset1(v, &shvhed);
542 if (adrof(STRhistchars) == 0) {
543 HIST = '!';
544 HISTSUB = '^';
545 }
546 if (adrof(STRwordchars) == 0)
547 word_chars = STR_WORD_CHARS;
548 #ifdef FILEC
549 if (adrof(STRfilec) == 0)
550 filec = 0;
551 #endif
552 #ifdef EDIT
553 if (adrof(STRedit) == 0)
554 wantediting = 0;
555 #endif
556 }
557
558 extern int insource;
559 void
560 updateediting(void)
561 {
562 if (insource || wantediting == editing)
563 return;
564
565 if (wantediting) {
566 HistEvent ev;
567 Char *vn = value(STRhistchars);
568
569 el = el_init_fd(getprogname(), cshin, cshout, csherr,
570 SHIN, SHOUT, SHERR);
571 el_set(el, EL_EDITOR, *vn ? short2str(vn) : "emacs");
572 el_set(el, EL_PROMPT, printpromptstr);
573 el_set(el, EL_ALIAS_TEXT, alias_text, NULL);
574 el_set(el, EL_SAFEREAD, 1);
575 el_set(el, EL_ADDFN, "rl-complete",
576 "ReadLine compatible completion function", _el_fn_complete);
577 el_set(el, EL_BIND, "^I", adrof(STRfilec) ? "rl-complete" : "ed-insert",
578 NULL);
579 hi = history_init();
580 history(hi, &ev, H_SETSIZE, getn(value(STRhistory)));
581 loadhist(Histlist.Hnext);
582 el_set(el, EL_HIST, history, hi);
583 } else {
584 if (el)
585 el_end(el);
586 if (hi)
587 history_end(hi);
588 el = NULL;
589 hi = NULL;
590 }
591 editing = wantediting;
592 }
593
594 void
595 unset1(Char *v[], struct varent *head)
596 {
597 struct varent *vp;
598 int cnt;
599
600 while (*++v) {
601 cnt = 0;
602 while ((vp = madrof(*v, head->v_left)) != NULL)
603 unsetv1(vp), cnt++;
604 if (cnt == 0)
605 setname(vis_str(*v));
606 }
607 }
608
609 void
610 unsetv(Char *var)
611 {
612 struct varent *vp;
613
614 if ((vp = adrof1(var, &shvhed)) == 0)
615 udvar(var);
616 unsetv1(vp);
617 }
618
619 static void
620 unsetv1(struct varent *p)
621 {
622 struct varent *c, *pp;
623 int f;
624
625 /*
626 * Free associated memory first to avoid complications.
627 */
628 blkfree(p->vec);
629 free(p->v_name);
630 /*
631 * If p is missing one child, then we can move the other into where p is.
632 * Otherwise, we find the predecessor of p, which is guaranteed to have no
633 * right child, copy it into p, and move its left child into it.
634 */
635 if (p->v_right == 0)
636 c = p->v_left;
637 else if (p->v_left == 0)
638 c = p->v_right;
639 else {
640 for (c = p->v_left; c->v_right; c = c->v_right)
641 continue;
642 p->v_name = c->v_name;
643 p->vec = c->vec;
644 p = c;
645 c = p->v_left;
646 }
647 /*
648 * Move c into where p is.
649 */
650 pp = p->v_parent;
651 f = pp->v_right == p;
652 if ((pp->v_link[f] = c) != NULL)
653 c->v_parent = pp;
654 /*
655 * Free the deleted node, and rebalance.
656 */
657 free(p);
658 balance(pp, f, 1);
659 }
660
661 void
662 setNS(Char *cp)
663 {
664 set(cp, Strsave(STRNULL));
665 }
666
667 void
668 /*ARGSUSED*/
669 shift(Char **v, struct command *t)
670 {
671 struct varent *argv;
672 Char *name;
673
674 v++;
675 name = *v;
676 if (name == 0)
677 name = STRargv;
678 else
679 (void) strip(name);
680 argv = adrof(name);
681 if (argv == 0)
682 udvar(name);
683 if (argv->vec[0] == 0)
684 stderror(ERR_NAME | ERR_NOMORE);
685 lshift(argv->vec, 1);
686 update_vars(name);
687 }
688
689 static void
690 exportpath(Char **val)
691 {
692 Char exppath[BUFSIZE];
693
694 exppath[0] = 0;
695 if (val)
696 while (*val) {
697 if (Strlen(*val) + Strlen(exppath) + 2 > BUFSIZE) {
698 (void)fprintf(csherr,
699 "Warning: ridiculously long PATH truncated\n");
700 break;
701 }
702 (void)Strcat(exppath, *val++);
703 if (*val == 0 || eq(*val, STRRparen))
704 break;
705 (void)Strcat(exppath, STRcolon);
706 }
707 Setenv(STRPATH, exppath);
708 }
709
710 #ifndef lint
711 /*
712 * Lint thinks these have null effect
713 */
714 /* macros to do single rotations on node p */
715 #define rright(p) (\
716 t = (p)->v_left,\
717 (t)->v_parent = (p)->v_parent,\
718 ((p)->v_left = t->v_right) ? (t->v_right->v_parent = (p)) : 0,\
719 (t->v_right = (p))->v_parent = t,\
720 (p) = t)
721 #define rleft(p) (\
722 t = (p)->v_right,\
723 (t)->v_parent = (p)->v_parent,\
724 ((p)->v_right = t->v_left) ? (t->v_left->v_parent = (p)) : 0,\
725 (t->v_left = (p))->v_parent = t,\
726 (p) = t)
727 #else
728 struct varent *
729 rleft(struct varent *p)
730 {
731 return (p);
732 }
733 struct varent *
734 rright(struct varent *p)
735 {
736 return (p);
737 }
738 #endif /* ! lint */
739
740
741 /*
742 * Rebalance a tree, starting at p and up.
743 * F == 0 means we've come from p's left child.
744 * D == 1 means we've just done a delete, otherwise an insert.
745 */
746 static void
747 balance(struct varent *p, int f, int d)
748 {
749 struct varent *pp;
750
751 #ifndef lint
752 struct varent *t; /* used by the rotate macros */
753
754 #endif
755 int ff;
756
757 /*
758 * Ok, from here on, p is the node we're operating on; pp is its parent; f
759 * is the branch of p from which we have come; ff is the branch of pp which
760 * is p.
761 */
762 for (; (pp = p->v_parent) != NULL; p = pp, f = ff) {
763 ff = pp->v_right == p;
764 if (f ^ d) { /* right heavy */
765 switch (p->v_bal) {
766 case -1: /* was left heavy */
767 p->v_bal = 0;
768 break;
769 case 0: /* was balanced */
770 p->v_bal = 1;
771 break;
772 case 1: /* was already right heavy */
773 switch (p->v_right->v_bal) {
774 case 1: /* single rotate */
775 pp->v_link[ff] = rleft(p);
776 p->v_left->v_bal = 0;
777 p->v_bal = 0;
778 break;
779 case 0: /* single rotate */
780 pp->v_link[ff] = rleft(p);
781 p->v_left->v_bal = 1;
782 p->v_bal = -1;
783 break;
784 case -1: /* double rotate */
785 (void) rright(p->v_right);
786 pp->v_link[ff] = rleft(p);
787 p->v_left->v_bal =
788 p->v_bal < 1 ? 0 : -1;
789 p->v_right->v_bal =
790 p->v_bal > -1 ? 0 : 1;
791 p->v_bal = 0;
792 break;
793 }
794 break;
795 }
796 }
797 else { /* left heavy */
798 switch (p->v_bal) {
799 case 1: /* was right heavy */
800 p->v_bal = 0;
801 break;
802 case 0: /* was balanced */
803 p->v_bal = -1;
804 break;
805 case -1: /* was already left heavy */
806 switch (p->v_left->v_bal) {
807 case -1: /* single rotate */
808 pp->v_link[ff] = rright(p);
809 p->v_right->v_bal = 0;
810 p->v_bal = 0;
811 break;
812 case 0: /* single rotate */
813 pp->v_link[ff] = rright(p);
814 p->v_right->v_bal = -1;
815 p->v_bal = 1;
816 break;
817 case 1: /* double rotate */
818 (void) rleft(p->v_left);
819 pp->v_link[ff] = rright(p);
820 p->v_left->v_bal =
821 p->v_bal < 1 ? 0 : -1;
822 p->v_right->v_bal =
823 p->v_bal > -1 ? 0 : 1;
824 p->v_bal = 0;
825 break;
826 }
827 break;
828 }
829 }
830 /*
831 * If from insert, then we terminate when p is balanced. If from
832 * delete, then we terminate when p is unbalanced.
833 */
834 if ((p->v_bal == 0) ^ d)
835 break;
836 }
837 }
838
839 void
840 plist(struct varent *p)
841 {
842 struct varent *c;
843 sigset_t nsigset;
844 int len;
845
846 if (setintr) {
847 sigemptyset(&nsigset);
848 (void)sigaddset(&nsigset, SIGINT);
849 (void)sigprocmask(SIG_UNBLOCK, &nsigset, NULL);
850 }
851
852 for (;;) {
853 while (p->v_left)
854 p = p->v_left;
855 x:
856 if (p->v_parent == 0) /* is it the header? */
857 return;
858 len = blklen(p->vec);
859 (void)fprintf(cshout, "%s\t", short2str(p->v_name));
860 if (len != 1)
861 (void)fputc('(', cshout);
862 blkpr(cshout, p->vec);
863 if (len != 1)
864 (void)fputc(')', cshout);
865 (void)fputc('\n', cshout);
866 if (p->v_right) {
867 p = p->v_right;
868 continue;
869 }
870 do {
871 c = p;
872 p = p->v_parent;
873 } while (p->v_right == c);
874 goto x;
875 }
876 }
877