2 * sh.set.c: Setting and Clearing of variables
5 * Copyright (c) 1980, 1991 The Regents of the University of California.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #ifdef HAVE_NL_LANGINFO
40 extern int GotTermCaps
;
43 static void update_vars (Char
*);
44 static Char
*getinx (Char
*, int *);
45 static void asx (Char
*, int, Char
*);
46 static struct varent
*getvx (Char
*, int);
47 static Char
*xset (Char
*, Char
***);
48 static Char
*operate (int, Char
*, Char
*);
49 static void putn1 (tcsh_number_t
);
50 static struct varent
*madrof (Char
*, struct varent
*);
51 static void unsetv1 (struct varent
*);
52 static void balance (struct varent
*, int, int);
53 static int set_noclobber (Char
**);
62 if (eq(vp
, STRpath
)) {
63 struct varent
*p
= adrof(STRpath
);
65 stderror(ERR_NAME
| ERR_UNDVAR
);
71 else if (eq(vp
, STRnoclobber
)) {
72 struct varent
*p
= adrof(STRnoclobber
);
74 stderror(ERR_NAME
| ERR_UNDVAR
);
76 no_clobber
= set_noclobber(p
->vec
);
78 else if (eq(vp
, STRhistchars
)) {
79 Char
*pn
= varval(vp
);
87 else if (eq(vp
, STRpromptchars
)) {
88 Char
*pn
= varval(vp
);
96 else if (eq(vp
, STRhistlit
)) {
99 else if (eq(vp
, STRuser
)) {
100 tsetenv(STRKUSER
, varval(vp
));
101 tsetenv(STRLOGNAME
, varval(vp
));
103 else if (eq(vp
, STRgroup
)) {
104 tsetenv(STRKGROUP
, varval(vp
));
106 else if (eq(vp
, STRwordchars
)) {
107 word_chars
= varval(vp
);
109 else if (eq(vp
, STRloginsh
)) {
112 else if (eq(vp
, STRanyerror
)) {
115 else if (eq(vp
, STRsymlinks
)) {
116 Char
*pn
= varval(vp
);
118 if (eq(pn
, STRignore
))
119 symlinks
= SYM_IGNORE
;
120 else if (eq(pn
, STRexpand
))
121 symlinks
= SYM_EXPAND
;
122 else if (eq(pn
, STRchase
))
123 symlinks
= SYM_CHASE
;
127 else if (eq(vp
, STRterm
)) {
128 Char
*cp
= varval(vp
);
129 tsetenv(STRKTERM
, cp
);
130 #ifdef DOESNT_WORK_RIGHT
131 cp
= getenv("TERMCAP");
132 if (cp
&& (*cp
!= '/')) /* if TERMCAP and not a path */
133 Unsetenv(STRTERMCAP
);
134 #endif /* DOESNT_WORK_RIGHT */
136 if (noediting
&& Strcmp(cp
, STRnetwork
) != 0 &&
137 Strcmp(cp
, STRunknown
) != 0 && Strcmp(cp
, STRdumb
) != 0) {
142 ed_Init(); /* reset the editor */
144 else if (eq(vp
, STRhome
)) {
147 cp
= Strsave(varval(vp
)); /* get the old value back */
149 * convert to cononical pathname (possibly resolving symlinks)
151 canon
= dcanon(cp
, cp
);
152 cleanup_push(canon
, xfree
);
154 setcopy(vp
, canon
, VAR_READWRITE
); /* have to save the new val */
156 /* and now mirror home with HOME */
157 tsetenv(STRKHOME
, canon
);
158 /* fix directory stack for new tilde home */
160 cleanup_until(canon
);
162 else if (eq(vp
, STRedit
)) {
165 /* PWP: add more stuff in here later */
167 else if (eq(vp
, STRvimode
)) {
171 else if (eq(vp
, STRshlvl
)) {
172 tsetenv(STRKSHLVL
, varval(vp
));
174 else if (eq(vp
, STRignoreeof
)) {
177 for ((cp
= varval(STRignoreeof
)); cp
&& *cp
; cp
++) {
182 numeof
= numeof
* 10 + *cp
- '0';
184 if (numeof
<= 0) numeof
= 26; /* Sanity check */
186 else if (eq(vp
, STRbackslash_quote
)) {
189 else if (eq(vp
, STRcompat_expr
)) {
192 else if (eq(vp
, STRdirstack
)) {
195 else if (eq(vp
, STRrecognize_only_executables
)) {
198 else if (eq(vp
, STRkillring
)) {
199 SetKillRing((int)getn(varval(vp
)));
201 else if (eq(vp
, STRhistory
)) {
202 sethistory((int)getn(varval(vp
)));
205 else if (eq(vp
, STRwatch
)) {
208 #endif /* HAVENOUTMP */
209 else if (eq(vp
, STRimplicitcd
)) {
210 implicit_cd
= ((eq(varval(vp
), STRverbose
)) ? 2 : 1);
212 else if (eq(vp
, STRcdtohome
)) {
216 else if (eq(vp
, STRcolor
)) {
219 #endif /* COLOR_LS_F */
220 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
221 else if (eq(vp
, CHECK_MBYTEVAR
) || eq(vp
, STRnokanji
)) {
222 update_dspmbyte_vars();
226 else if (eq(vp
, STRcatalog
)) {
230 #if defined(FILEC) && defined(TIOCSTI)
231 else if (eq(vp
, STRfilec
))
234 #endif /* NLS_CATALOGS */
240 doset(Char
**v
, struct command
*c
)
247 int flags
= VAR_READWRITE
;
257 * Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
259 if (*v
&& eq(*v
, STRmr
)) {
260 flags
= VAR_READONLY
;
264 if (*v
&& eq(*v
, STRmf
) && !last_match
) {
269 if (*v
&& eq(*v
, STRml
) && !first_match
) {
277 plist(&shvhed
, flags
);
284 stderror(ERR_NAME
| ERR_VARBEGIN
);
290 p
= getinx(p
, &subscr
);
292 if (*p
!= '\0' && *p
!= '=')
293 stderror(ERR_NAME
| ERR_VARALNUM
);
296 if (*p
== '\0' && *v
!= NULL
&& **v
== '(')
299 else if (*v
&& eq(*v
, STRequal
)) {
303 if (eq(p
, STRLparen
)) {
307 stderror(ERR_NAME
| ERR_SYNTAX
);
310 stderror(ERR_NAME
| ERR_MISSING
, ')');
323 set1(vp
, vecp
, &shvhed
, flags
);
331 cleanup_push(copy
, xfree
);
332 asx(vp
, subscr
, copy
);
333 cleanup_ignore(copy
);
337 setv(vp
, Strsave(p
), flags
);
339 } while ((p
= *v
++) != NULL
);
343 getinx(Char
*cp
, int *ip
)
347 while (*cp
&& Isdigit(*cp
))
348 *ip
= *ip
* 10 + *cp
++ - '0';
350 stderror(ERR_NAME
| ERR_SUBSCRIPT
);
355 asx(Char
*vp
, int subscr
, Char
*p
)
357 struct varent
*v
= getvx(vp
, subscr
);
360 if (v
->v_flags
& VAR_READONLY
)
361 stderror(ERR_READONLY
|ERR_NAME
, v
->v_name
);
362 prev
= v
->vec
[subscr
- 1];
363 cleanup_push(prev
, xfree
);
364 v
->vec
[subscr
- 1] = globone(p
, G_APPEND
);
368 static struct varent
*
369 getvx(Char
*vp
, int subscr
)
371 struct varent
*v
= adrof(vp
);
375 if (subscr
< 1 || subscr
> blklen(v
->vec
))
376 stderror(ERR_NAME
| ERR_RANGE
);
382 dolet(Char
**v
, struct command
*dummy
)
400 for (; alnum(*p
); p
++)
402 if (vp
== p
|| !letter(*vp
))
403 stderror(ERR_NAME
| ERR_VARBEGIN
);
406 p
= getinx(p
, &subscr
);
413 stderror(ERR_NAME
| ERR_ASSIGN
);
416 * if there is no expression after the '=' then print a "Syntax Error"
419 if (*p
== '\0' && *v
== NULL
)
420 stderror(ERR_NAME
| ERR_ASSIGN
);
423 cleanup_push(vp
, xfree
);
432 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
438 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
439 stderror(ERR_NAME
| ERR_SYNTAX
);
442 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
446 cleanup_push(p
, xfree
);
451 setv(vp
, p
, VAR_READWRITE
);
455 struct varent
*gv
= getvx(vp
, subscr
);
458 val
= operate(op
, gv
->vec
[subscr
- 1], p
);
459 cleanup_push(val
, xfree
);
460 asx(vp
, subscr
, val
);
467 val
= operate(op
, varval(vp
), p
);
468 cleanup_push(val
, xfree
);
469 setv(vp
, val
, VAR_READWRITE
);
475 } while ((p
= *v
++) != NULL
);
479 xset(Char
*cp
, Char
***vp
)
489 return (putn(expr(vp
)));
493 operate(int op
, Char
*vp
, Char
*p
)
507 if (op
== '<' || op
== '>')
514 stderror(ERR_NAME
| ERR_EXPRESSION
);
521 putn(tcsh_number_t n
)
523 Char nbuf
[1024]; /* Enough even for octal */
532 return (Strsave(nbuf
));
536 putn1(tcsh_number_t n
)
540 *putp
++ = (Char
)(n
% 10 + '0');
550 if (!cp
) /* PWP: extra error checking */
551 stderror(ERR_NAME
| ERR_BADNUM
);
554 if (cp
[0] == '+' && cp
[1])
560 stderror(ERR_NAME
| ERR_BADNUM
);
563 if (cp
[0] == '0' && cp
[1] && is_set(STRparseoctal
))
571 if (base
== 8 && *cp
>= '8')
572 stderror(ERR_NAME
| ERR_BADNUM
);
573 n
= n
* base
+ *cp
++ - '0';
576 stderror(ERR_NAME
| ERR_BADNUM
);
577 return (sign
? -n
: n
);
581 value1(Char
*var
, struct varent
*head
)
585 if (!var
|| !head
) /* PWP: extra error checking */
588 vp
= adrof1(var
, head
);
589 return ((vp
== NULL
|| vp
->vec
== NULL
|| vp
->vec
[0] == NULL
) ?
590 STRNULL
: vp
->vec
[0]);
593 static struct varent
*
594 madrof(Char
*pat
, struct varent
*vp
)
598 for (vp
= vp
->v_left
; vp
; vp
= vp
->v_right
) {
599 if (vp
->v_left
&& (vp1
= madrof(pat
, vp
)) != NULL
)
601 if (Gmatch(vp
->v_name
, pat
))
608 adrof1(const Char
*name
, struct varent
*v
)
613 while (v
&& ((cmp
= *name
- *v
->v_name
) != 0 ||
614 (cmp
= Strcmp(name
, v
->v_name
)) != 0))
623 setcopy(const Char
*var
, const Char
*val
, int flags
)
628 cleanup_push(copy
, xfree
);
629 setv(var
, copy
, flags
);
630 cleanup_ignore(copy
);
635 * The caller is responsible for putting value in a safe place
638 setv(const Char
*var
, Char
*val
, int flags
)
640 Char
**vec
= xmalloc(2 * sizeof(Char
**));
644 set1(var
, vec
, &shvhed
, flags
);
648 set1(const Char
*var
, Char
**vec
, struct varent
*head
, int flags
)
652 if ((flags
& VAR_NOGLOB
) == 0) {
657 vec
= globall(oldv
, gflag
);
660 stderror(ERR_NAME
| ERR_NOMATCH
);
666 * Uniqueness addition from: Michael Veksler <mveksler@vnet.ibm.com>
668 if ( flags
& (VAR_FIRST
| VAR_LAST
) ) {
670 * Code for -f (VAR_FIRST) and -l (VAR_LAST) options.
672 * Delete all duplicate words leaving "holes" in the word array (vec).
673 * Then remove the "holes", keeping the order of the words unchanged.
675 if (vec
[0] && vec
[1]) { /* more than one word ? */
679 for (num_items
= 0; vec
[num_items
]; num_items
++)
681 if (flags
& VAR_FIRST
) {
682 /* delete duplications, keeping first occurance */
683 for (i
= 1; i
< num_items
; i
++)
684 for (j
= 0; j
< i
; j
++)
685 /* If have earlier identical item, remove i'th item */
686 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
691 } else if (flags
& VAR_LAST
) {
692 /* delete duplications, keeping last occurance */
693 for (i
= 0; i
< num_items
- 1; i
++)
694 for (j
= i
+ 1; j
< num_items
; j
++)
695 /* If have later identical item, remove i'th item */
696 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
697 /* remove identical item (the first) */
702 /* Compress items - remove empty items */
703 for (j
= i
= 0; i
< num_items
; i
++)
707 /* NULL-fy remaining items */
708 for (; j
< num_items
; j
++)
711 /* don't let the attribute propagate */
712 flags
&= ~(VAR_FIRST
|VAR_LAST
);
714 setq(var
, vec
, head
, flags
);
719 setq(const Char
*name
, Char
**vec
, struct varent
*p
, int flags
)
724 f
= 0; /* tree hangs off the header's left link */
725 while ((c
= p
->v_link
[f
]) != 0) {
726 if ((f
= *name
- *c
->v_name
) == 0 &&
727 (f
= Strcmp(name
, c
->v_name
)) == 0) {
728 if (c
->v_flags
& VAR_READONLY
) {
729 if (flags
& VAR_NOERROR
)
731 stderror(ERR_READONLY
|ERR_NAME
, c
->v_name
);
741 p
->v_link
[f
] = c
= xmalloc(sizeof(struct varent
));
742 c
->v_name
= Strsave(name
);
745 c
->v_left
= c
->v_right
= 0;
753 unset(Char
**v
, struct command
*c
)
755 int did_roe
, did_edit
;
758 did_roe
= adrof(STRrecognize_only_executables
) != NULL
;
759 did_edit
= adrof(STRedit
) != NULL
;
762 #if defined(FILEC) && defined(TIOCSTI)
763 if (adrof(STRfilec
) == 0)
765 #endif /* FILEC && TIOCSTI */
767 if (adrof(STRhistchars
) == 0) {
771 if (adrof(STRignoreeof
) == 0)
773 if (adrof(STRpromptchars
) == 0) {
774 PRCH
= tcsh
? '>' : '%';
777 if (adrof(STRnoclobber
) == 0)
779 if (adrof(STRhistlit
) == 0)
781 if (adrof(STRloginsh
) == 0)
783 if (adrof(STRanyerror
) == 0)
785 if (adrof(STRwordchars
) == 0)
786 word_chars
= STR_WORD_CHARS
;
787 if (adrof(STRedit
) == 0)
789 if (adrof(STRbackslash_quote
) == 0)
791 if (adrof(STRcompat_expr
) == 0)
793 if (adrof(STRsymlinks
) == 0)
795 if (adrof(STRimplicitcd
) == 0)
797 if (adrof(STRcdtohome
) == 0)
799 if (adrof(STRkillring
) == 0)
801 if (did_edit
&& noediting
&& adrof(STRedit
) == 0)
803 if (adrof(STRvimode
) == 0)
805 if (did_roe
&& adrof(STRrecognize_only_executables
) == 0)
807 if (adrof(STRhistory
) == 0)
810 if (adrof(STRcolor
) == 0)
812 #endif /* COLOR_LS_F */
813 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
814 update_dspmbyte_vars();
820 #endif /* NLS_CATALOGS */
824 unset1(Char
*v
[], struct varent
*head
)
831 while ((vp
= madrof(*v
, head
)) != NULL
)
832 if (vp
->v_flags
& VAR_READONLY
)
833 stderror(ERR_READONLY
|ERR_NAME
, vp
->v_name
);
837 setname(short2str(*v
));
846 if ((vp
= adrof1(var
, &shvhed
)) == 0)
852 unsetv1(struct varent
*p
)
854 struct varent
*c
, *pp
;
858 * Free associated memory first to avoid complications.
863 * If p is missing one child, then we can move the other into where p is.
864 * Otherwise, we find the predecessor of p, which is guaranteed to have no
865 * right child, copy it into p, and move it's left child into it.
869 else if (p
->v_left
== 0)
872 for (c
= p
->v_left
; c
->v_right
; c
= c
->v_right
)
874 p
->v_name
= c
->v_name
;
875 p
->v_flags
= c
->v_flags
;
882 * Move c into where p is.
885 f
= pp
->v_right
== p
;
886 if ((pp
->v_link
[f
] = c
) != 0)
889 * Free the deleted node, and rebalance.
895 /* Set variable name to NULL. */
897 setNS(const Char
*varName
)
899 setcopy(varName
, STRNULL
, VAR_READWRITE
);
904 shift(Char
**v
, struct command
*c
)
917 if (argv
== NULL
|| argv
->vec
== NULL
)
919 if (argv
->vec
[0] == 0)
920 stderror(ERR_NAME
| ERR_NOMORE
);
921 lshift(argv
->vec
, 1);
926 exportpath(Char
**val
)
928 struct Strbuf buf
= Strbuf_INIT
;
933 Strbuf_append(&buf
, *val
++);
934 if (*val
== 0 || eq(*val
, STRRparen
))
936 Strbuf_append1(&buf
, PATHSEP
);
938 exppath
= Strbuf_finish(&buf
);
939 cleanup_push(exppath
, xfree
);
940 tsetenv(STRKPATH
, exppath
);
941 cleanup_until(exppath
);
945 set_noclobber(Char
**val
)
948 int nc
= NOCLOBBER_DEFAULT
;
953 if (*val
== 0 || eq(*val
, STRRparen
))
958 if (eq(option
, STRnotempty
))
959 nc
|= NOCLOBBER_NOTEMPTY
;
960 else if (eq(option
, STRask
))
968 * Lint thinks these have null effect
970 /* macros to do single rotations on node p */
971 # define rright(p) (\
973 (t)->v_parent = (p)->v_parent,\
974 (((p)->v_left = t->v_right) != NULL) ?\
975 (t->v_right->v_parent = (p)) : 0,\
976 (t->v_right = (p))->v_parent = t,\
980 ((t)->v_parent = (p)->v_parent,\
981 ((p)->v_right = t->v_left) != NULL) ? \
982 (t->v_left->v_parent = (p)) : 0,\
983 (t->v_left = (p))->v_parent = t,\
986 static struct varent
*
987 rleft(struct varent
*p
)
991 static struct varent
*
992 rright(struct varent
*p
)
1001 * Rebalance a tree, starting at p and up.
1002 * F == 0 means we've come from p's left child.
1003 * D == 1 means we've just done a delete, otherwise an insert.
1006 balance(struct varent
*p
, int f
, int d
)
1011 struct varent
*t
; /* used by the rotate macros */
1015 ff
= 0; /* Sun's lint is dumb! */
1019 * Ok, from here on, p is the node we're operating on; pp is it's parent; f
1020 * is the branch of p from which we have come; ff is the branch of pp which
1023 for (; (pp
= p
->v_parent
) != 0; p
= pp
, f
= ff
) {
1024 ff
= pp
->v_right
== p
;
1025 if (f
^ d
) { /* right heavy */
1027 case -1: /* was left heavy */
1030 case 0: /* was balanced */
1033 case 1: /* was already right heavy */
1034 switch (p
->v_right
->v_bal
) {
1035 case 1: /* single rotate */
1036 pp
->v_link
[ff
] = rleft(p
);
1037 p
->v_left
->v_bal
= 0;
1040 case 0: /* single rotate */
1041 pp
->v_link
[ff
] = rleft(p
);
1042 p
->v_left
->v_bal
= 1;
1045 case -1: /* double rotate */
1046 (void) rright(p
->v_right
);
1047 pp
->v_link
[ff
] = rleft(p
);
1049 p
->v_bal
< 1 ? 0 : -1;
1051 p
->v_bal
> -1 ? 0 : 1;
1062 else { /* left heavy */
1064 case 1: /* was right heavy */
1067 case 0: /* was balanced */
1070 case -1: /* was already left heavy */
1071 switch (p
->v_left
->v_bal
) {
1072 case -1: /* single rotate */
1073 pp
->v_link
[ff
] = rright(p
);
1074 p
->v_right
->v_bal
= 0;
1077 case 0: /* single rotate */
1078 pp
->v_link
[ff
] = rright(p
);
1079 p
->v_right
->v_bal
= -1;
1082 case 1: /* double rotate */
1083 (void) rleft(p
->v_left
);
1084 pp
->v_link
[ff
] = rright(p
);
1086 p
->v_bal
< 1 ? 0 : -1;
1088 p
->v_bal
> -1 ? 0 : 1;
1100 * If from insert, then we terminate when p is balanced. If from
1101 * delete, then we terminate when p is unbalanced.
1103 if ((p
->v_bal
== 0) ^ d
)
1109 plist(struct varent
*p
, int what
)
1118 if (p
->v_parent
== 0) /* is it the header? */
1120 if ((p
->v_flags
& what
) != 0) {
1122 int old_pintr_disabled
;
1124 pintr_push_enable(&old_pintr_disabled
);
1125 cleanup_until(&old_pintr_disabled
);
1127 len
= blklen(p
->vec
);
1128 xprintf("%" TCSH_S
"\t", p
->v_name
);
1143 } while (p
->v_right
== c
);
1149 # if defined(SHORT_STRINGS) && defined(DSPMBYTE)
1150 extern int dspmbyte_ls
;
1153 update_dspmbyte_vars(void)
1159 /* if variable "nokanji" is set, multi-byte display is disabled */
1160 if ((vp
= adrof(CHECK_MBYTEVAR
)) && !adrof(STRnokanji
)) {
1163 if (eq (dstr1
, STRsjis
))
1165 else if (eq(dstr1
, STReuc
))
1167 else if (eq(dstr1
, STRbig5
))
1169 else if (eq(dstr1
, STRutf8
))
1171 else if ((dstr1
[0] - '0') >= 0 && (dstr1
[0] - '0') <= 3) {
1175 xprintf(CGETS(18, 2,
1176 "Warning: unknown multibyte display; using default(euc(JP))\n"));
1179 if (dstr1
&& vp
->vec
[1] && eq(vp
->vec
[1], STRls
))
1183 for (lp
= 0; lp
< 256 && iskcode
> 0; lp
++) {
1187 _cmap
[lp
] = _cmap_mbyte
[lp
];
1188 _mbmap
[lp
] = _mbmap_sjis
[lp
];
1192 _cmap
[lp
] = _cmap_mbyte
[lp
];
1193 _mbmap
[lp
] = _mbmap_euc
[lp
];
1197 _cmap
[lp
] = _cmap_mbyte
[lp
];
1198 _mbmap
[lp
] = _mbmap_big5
[lp
];
1202 _cmap
[lp
] = _cmap_mbyte
[lp
];
1203 _mbmap
[lp
] = _mbmap_utf8
[lp
];
1206 xprintf(CGETS(18, 3,
1207 "Warning: unknown multibyte code %d; multibyte disabled\n"),
1209 _cmap
[lp
] = _cmap_c
[lp
];
1210 _mbmap
[lp
] = 0; /* Default map all 0 */
1216 /* check original table */
1217 if (Strlen(dstr1
) != 256) {
1218 xprintf(CGETS(18, 4,
1219 "Warning: Invalid multibyte table length (%d); multibyte disabled\n"),
1223 for (lp
= 0; lp
< 256 && _enable_mbdisp
== 1; lp
++) {
1224 if (!((dstr1
[lp
] - '0') >= 0 && (dstr1
[lp
] - '0') <= 3)) {
1225 xprintf(CGETS(18, 4,
1226 "Warning: bad multibyte code at offset +%d; multibyte diabled\n"),
1232 /* set original table */
1233 for (lp
= 0; lp
< 256; lp
++) {
1234 if (_enable_mbdisp
== 1) {
1235 _cmap
[lp
] = _cmap_mbyte
[lp
];
1236 _mbmap
[lp
] = (unsigned short) ((dstr1
[lp
] - '0') & 0x0f);
1239 _cmap
[lp
] = _cmap_c
[lp
];
1240 _mbmap
[lp
] = 0; /* Default map all 0 */
1246 for (lp
= 0; lp
< 256; lp
++) {
1247 _cmap
[lp
] = _cmap_c
[lp
];
1248 _mbmap
[lp
] = 0; /* Default map all 0 */
1253 #ifdef MBYTEDEBUG /* Sorry, use for beta testing */
1256 for (lp
= 0; lp
< 256; lp
++)
1257 mbmapstr
[lp
] = _mbmap
[lp
] + '0';
1259 setcopy(STRmbytemap
, mbmapstr
, VAR_READWRITE
);
1261 #endif /* MBYTEMAP */
1264 /* dspkanji/dspmbyte autosetting */
1265 /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
1267 autoset_dspmbyte(const Char
*pcp
)
1270 static const struct dspm_autoset_Table
{
1274 { STRLANGEUCJP
, STReuc
},
1275 { STRLANGEUCKR
, STReuc
},
1276 { STRLANGEUCZH
, STReuc
},
1277 { STRLANGEUCJPB
, STReuc
},
1278 { STRLANGEUCKRB
, STReuc
},
1279 { STRLANGEUCZHB
, STReuc
},
1281 { STRLANGEUCJPC
, STReuc
},
1283 { STRLANGSJIS
, STRsjis
},
1284 { STRLANGSJISB
, STRsjis
},
1285 { STRLANGBIG5
, STRbig5
},
1286 { STRstarutfstar8
, STRutf8
},
1289 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
1290 static const struct dspm_autoset_Table dspmc
[] = {
1291 { STRstarutfstar8
, STRutf8
},
1293 { STRGB2312
, STReuc
},
1294 { STRLANGBIG5
, STRbig5
},
1299 codeset
= str2short(nl_langinfo(CODESET
));
1300 if (*codeset
!= '\0') {
1301 for (i
= 0; dspmc
[i
].n
; i
++) {
1303 if (dspmc
[i
].n
[0] && t_pmatch(pcp
, dspmc
[i
].n
, &estr
, 0) > 0) {
1304 setcopy(CHECK_MBYTEVAR
, dspmc
[i
].v
, VAR_READWRITE
);
1305 update_dspmbyte_vars();
1315 for (i
= 0; dspmt
[i
].n
; i
++) {
1317 if (dspmt
[i
].n
[0] && t_pmatch(pcp
, dspmt
[i
].n
, &estr
, 0) > 0) {
1318 setcopy(CHECK_MBYTEVAR
, dspmt
[i
].v
, VAR_READWRITE
);
1319 update_dspmbyte_vars();
1324 # elif defined(AUTOSET_KANJI)
1328 char *codeset
= nl_langinfo(CODESET
);
1330 if (*codeset
== '\0') {
1331 if (adrof(STRnokanji
) == NULL
)
1336 if (strcasestr(codeset
, "SHIFT_JIS") == (char*)0) {
1337 if (adrof(STRnokanji
) == NULL
)
1342 if (adrof(STRnokanji
) != NULL
)
1349 update_wordchars(void)
1351 if ((word_chars
== STR_WORD_CHARS
) || (word_chars
== STR_WORD_CHARS_VI
)) {
1352 word_chars
= (VImode
? STR_WORD_CHARS_VI
: STR_WORD_CHARS
);
1357 setstrstatus(Char
*str
)
1359 setv(STRstatus
, str
, VAR_READWRITE
|VAR_NOERROR
);
1365 setcopy(STRstatus
, n
? STR1
: STR0
, VAR_READWRITE
|VAR_NOERROR
);
1371 return getn(varval(STRstatus
));