1 /* $Header: /p/tcsh/cvsroot/tcsh/sh.set.c,v 3.70 2006/08/24 20:56:31 christos Exp $ */
3 * sh.set.c: Setting and Clearing of variables
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 RCSID("$tcsh: sh.set.c,v 3.70 2006/08/24 20:56:31 christos Exp $")
40 #ifdef HAVE_NL_LANGINFO
44 extern int GotTermCaps
;
47 static void update_vars (Char
*);
48 static Char
*getinx (Char
*, int *);
49 static void asx (Char
*, int, Char
*);
50 static struct varent
*getvx (Char
*, int);
51 static Char
*xset (Char
*, Char
***);
52 static Char
*operate (int, Char
*, Char
*);
53 static void putn1 (unsigned);
54 static struct varent
*madrof (Char
*, struct varent
*);
55 static void unsetv1 (struct varent
*);
56 static void balance (struct varent
*, int, int);
65 if (eq(vp
, STRpath
)) {
66 struct varent
*p
= adrof(STRpath
);
68 stderror(ERR_NAME
| ERR_UNDVAR
);
74 else if (eq(vp
, STRhistchars
)) {
75 Char
*pn
= varval(vp
);
80 else if (eq(vp
, STRpromptchars
)) {
81 Char
*pn
= varval(vp
);
86 else if (eq(vp
, STRhistlit
)) {
89 else if (eq(vp
, STRuser
)) {
90 tsetenv(STRKUSER
, varval(vp
));
91 tsetenv(STRLOGNAME
, varval(vp
));
93 else if (eq(vp
, STRgroup
)) {
94 tsetenv(STRKGROUP
, varval(vp
));
96 else if (eq(vp
, STRwordchars
)) {
97 word_chars
= varval(vp
);
99 else if (eq(vp
, STRloginsh
)) {
102 else if (eq(vp
, STRsymlinks
)) {
103 Char
*pn
= varval(vp
);
105 if (eq(pn
, STRignore
))
106 symlinks
= SYM_IGNORE
;
107 else if (eq(pn
, STRexpand
))
108 symlinks
= SYM_EXPAND
;
109 else if (eq(pn
, STRchase
))
110 symlinks
= SYM_CHASE
;
114 else if (eq(vp
, STRterm
)) {
115 Char
*cp
= varval(vp
);
116 tsetenv(STRKTERM
, cp
);
117 #ifdef DOESNT_WORK_RIGHT
118 cp
= getenv("TERMCAP");
119 if (cp
&& (*cp
!= '/')) /* if TERMCAP and not a path */
120 Unsetenv(STRTERMCAP
);
121 #endif /* DOESNT_WORK_RIGHT */
123 if (noediting
&& Strcmp(cp
, STRnetwork
) != 0 &&
124 Strcmp(cp
, STRunknown
) != 0 && Strcmp(cp
, STRdumb
) != 0) {
129 ed_Init(); /* reset the editor */
131 else if (eq(vp
, STRhome
)) {
134 cp
= Strsave(varval(vp
)); /* get the old value back */
135 cleanup_push(cp
, xfree
);
138 * convert to cononical pathname (possibly resolving symlinks)
140 canon
= dcanon(cp
, cp
);
143 cleanup_push(canon
, xfree
);
145 setcopy(vp
, canon
, VAR_READWRITE
); /* have to save the new val */
147 /* and now mirror home with HOME */
148 tsetenv(STRKHOME
, canon
);
149 /* fix directory stack for new tilde home */
151 cleanup_until(canon
);
153 else if (eq(vp
, STRedit
)) {
156 /* PWP: add more stuff in here later */
158 else if (eq(vp
, STRshlvl
)) {
159 tsetenv(STRKSHLVL
, varval(vp
));
161 else if (eq(vp
, STRignoreeof
)) {
164 for ((cp
= varval(STRignoreeof
)); cp
&& *cp
; cp
++) {
169 numeof
= numeof
* 10 + *cp
- '0';
171 if (numeof
<= 0) numeof
= 26; /* Sanity check */
173 else if (eq(vp
, STRbackslash_quote
)) {
176 else if (eq(vp
, STRdirstack
)) {
179 else if (eq(vp
, STRrecognize_only_executables
)) {
182 else if (eq(vp
, STRkillring
)) {
183 SetKillRing(getn(varval(vp
)));
186 else if (eq(vp
, STRwatch
)) {
189 #endif /* HAVENOUTMP */
190 else if (eq(vp
, STRimplicitcd
)) {
191 implicit_cd
= ((eq(varval(vp
), STRverbose
)) ? 2 : 1);
194 else if (eq(vp
, STRcolor
)) {
197 #endif /* COLOR_LS_F */
198 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
199 else if(eq(vp
, CHECK_MBYTEVAR
) || eq(vp
, STRnokanji
)) {
200 update_dspmbyte_vars();
204 else if (eq(vp
, STRcatalog
)) {
208 #if defined(FILEC) && defined(TIOCSTI)
209 else if (eq(vp
, STRfilec
))
212 #endif /* NLS_CATALOGS */
218 doset(Char
**v
, struct command
*c
)
225 int flags
= VAR_READWRITE
;
235 * Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
237 if (*v
&& eq(*v
, STRmr
)) {
238 flags
= VAR_READONLY
;
242 if (*v
&& eq(*v
, STRmf
) && !last_match
) {
247 if (*v
&& eq(*v
, STRml
) && !first_match
) {
255 plist(&shvhed
, flags
);
262 for (; alnum(*p
); p
++)
264 if (vp
== p
|| !letter(*vp
))
265 stderror(ERR_NAME
| ERR_VARBEGIN
);
268 p
= getinx(p
, &subscr
);
270 if ((op
= *p
) != 0) {
272 if (*p
== 0 && *v
&& **v
== '(')
275 else if (*v
&& eq(*v
, STRequal
)) {
281 stderror(ERR_NAME
| ERR_SYNTAX
);
282 if (eq(p
, STRLparen
)) {
286 stderror(ERR_NAME
| ERR_SYNTAX
);
289 stderror(ERR_NAME
| ERR_MISSING
, ')');
302 set1(vp
, vecp
, &shvhed
, flags
);
310 cleanup_push(copy
, xfree
);
311 asx(vp
, subscr
, copy
);
312 cleanup_ignore(copy
);
316 setv(vp
, Strsave(p
), flags
);
318 } while ((p
= *v
++) != NULL
);
322 getinx(Char
*cp
, int *ip
)
326 while (*cp
&& Isdigit(*cp
))
327 *ip
= *ip
* 10 + *cp
++ - '0';
329 stderror(ERR_NAME
| ERR_SUBSCRIPT
);
334 asx(Char
*vp
, int subscr
, Char
*p
)
336 struct varent
*v
= getvx(vp
, subscr
);
339 if (v
->v_flags
& VAR_READONLY
)
340 stderror(ERR_READONLY
|ERR_NAME
, v
->v_name
);
341 prev
= v
->vec
[subscr
- 1];
342 cleanup_push(prev
, xfree
);
343 v
->vec
[subscr
- 1] = globone(p
, G_APPEND
);
347 static struct varent
*
348 getvx(Char
*vp
, int subscr
)
350 struct varent
*v
= adrof(vp
);
354 if (subscr
< 1 || subscr
> blklen(v
->vec
))
355 stderror(ERR_NAME
| ERR_RANGE
);
361 dolet(Char
**v
, struct command
*dummy
)
379 for (; alnum(*p
); p
++)
381 if (vp
== p
|| !letter(*vp
))
382 stderror(ERR_NAME
| ERR_VARBEGIN
);
385 p
= getinx(p
, &subscr
);
392 stderror(ERR_NAME
| ERR_ASSIGN
);
395 * if there is no expression after the '=' then print a "Syntax Error"
398 if (*p
== '\0' && *v
== NULL
)
399 stderror(ERR_NAME
| ERR_ASSIGN
);
402 cleanup_push(vp
, xfree
);
411 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
417 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
418 stderror(ERR_NAME
| ERR_SYNTAX
);
421 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
425 cleanup_push(p
, xfree
);
430 setv(vp
, p
, VAR_READWRITE
);
434 struct varent
*gv
= getvx(vp
, subscr
);
437 val
= operate(op
, gv
->vec
[subscr
- 1], p
);
438 cleanup_push(val
, xfree
);
439 asx(vp
, subscr
, val
);
446 val
= operate(op
, varval(vp
), p
);
447 cleanup_push(val
, xfree
);
448 setv(vp
, val
, VAR_READWRITE
);
454 } while ((p
= *v
++) != NULL
);
458 xset(Char
*cp
, Char
***vp
)
468 return (putn(expr(vp
)));
472 operate(int op
, Char
*vp
, Char
*p
)
486 if (op
== '<' || op
== '>')
493 stderror(ERR_NAME
| ERR_EXPRESSION
);
502 Char nbuf
[(CHAR_BIT
* sizeof (n
) + 2) / 3 + 2]; /* Enough even for octal */
511 return (Strsave(nbuf
));
519 *putp
++ = n
% 10 + '0';
528 if (!cp
) /* PWP: extra error checking */
529 stderror(ERR_NAME
| ERR_BADNUM
);
532 if (cp
[0] == '+' && cp
[1])
538 stderror(ERR_NAME
| ERR_BADNUM
);
542 n
= n
* 10 + *cp
++ - '0';
544 stderror(ERR_NAME
| ERR_BADNUM
);
545 return (sign
? -n
: n
);
549 value1(Char
*var
, struct varent
*head
)
553 if (!var
|| !head
) /* PWP: extra error checking */
556 vp
= adrof1(var
, head
);
557 return ((vp
== NULL
|| vp
->vec
== NULL
|| vp
->vec
[0] == NULL
) ?
558 STRNULL
: vp
->vec
[0]);
561 static struct varent
*
562 madrof(Char
*pat
, struct varent
*vp
)
566 for (vp
= vp
->v_left
; vp
; vp
= vp
->v_right
) {
567 if (vp
->v_left
&& (vp1
= madrof(pat
, vp
)) != NULL
)
569 if (Gmatch(vp
->v_name
, pat
))
576 adrof1(const Char
*name
, struct varent
*v
)
581 while (v
&& ((cmp
= *name
- *v
->v_name
) != 0 ||
582 (cmp
= Strcmp(name
, v
->v_name
)) != 0))
591 setcopy(const Char
*var
, const Char
*val
, int flags
)
596 cleanup_push(copy
, xfree
);
597 setv(var
, copy
, flags
);
598 cleanup_ignore(copy
);
603 * The caller is responsible for putting value in a safe place
606 setv(const Char
*var
, Char
*val
, int flags
)
608 Char
**vec
= xmalloc(2 * sizeof(Char
**));
612 set1(var
, vec
, &shvhed
, flags
);
616 set1(const Char
*var
, Char
**vec
, struct varent
*head
, int flags
)
620 if ((flags
& VAR_NOGLOB
) == 0) {
625 vec
= globall(oldv
, gflag
);
628 stderror(ERR_NAME
| ERR_NOMATCH
);
634 * Uniqueness addition from: Michael Veksler <mveksler@vnet.ibm.com>
636 if ( flags
& (VAR_FIRST
| VAR_LAST
) ) {
638 * Code for -f (VAR_FIRST) and -l (VAR_LAST) options.
640 * Delete all duplicate words leaving "holes" in the word array (vec).
641 * Then remove the "holes", keeping the order of the words unchanged.
643 if (vec
&& vec
[0] && vec
[1]) { /* more than one word ? */
647 for (num_items
= 0; vec
[num_items
]; num_items
++)
649 if (flags
& VAR_FIRST
) {
650 /* delete duplications, keeping first occurance */
651 for (i
= 1; i
< num_items
; i
++)
652 for (j
= 0; j
< i
; j
++)
653 /* If have earlier identical item, remove i'th item */
654 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
659 } else if (flags
& VAR_LAST
) {
660 /* delete duplications, keeping last occurance */
661 for (i
= 0; i
< num_items
- 1; i
++)
662 for (j
= i
+ 1; j
< num_items
; j
++)
663 /* If have later identical item, remove i'th item */
664 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
665 /* remove identical item (the first) */
670 /* Compress items - remove empty items */
671 for (j
= i
= 0; i
< num_items
; i
++)
675 /* NULL-fy remaining items */
676 for (; j
< num_items
; j
++)
679 /* don't let the attribute propagate */
680 flags
&= ~(VAR_FIRST
|VAR_LAST
);
682 setq(var
, vec
, head
, flags
);
687 setq(const Char
*name
, Char
**vec
, struct varent
*p
, int flags
)
692 f
= 0; /* tree hangs off the header's left link */
693 while ((c
= p
->v_link
[f
]) != 0) {
694 if ((f
= *name
- *c
->v_name
) == 0 &&
695 (f
= Strcmp(name
, c
->v_name
)) == 0) {
696 if (c
->v_flags
& VAR_READONLY
)
697 stderror(ERR_READONLY
|ERR_NAME
, c
->v_name
);
706 p
->v_link
[f
] = c
= xmalloc(sizeof(struct varent
));
707 c
->v_name
= Strsave(name
);
710 c
->v_left
= c
->v_right
= 0;
718 unset(Char
**v
, struct command
*c
)
720 int did_roe
, did_edit
;
723 did_roe
= adrof(STRrecognize_only_executables
) != NULL
;
724 did_edit
= adrof(STRedit
) != NULL
;
727 #if defined(FILEC) && defined(TIOCSTI)
728 if (adrof(STRfilec
) == 0)
730 #endif /* FILEC && TIOCSTI */
732 if (adrof(STRhistchars
) == 0) {
736 if (adrof(STRignoreeof
) == 0)
738 if (adrof(STRpromptchars
) == 0) {
742 if (adrof(STRhistlit
) == 0)
744 if (adrof(STRloginsh
) == 0)
746 if (adrof(STRwordchars
) == 0)
747 word_chars
= STR_WORD_CHARS
;
748 if (adrof(STRedit
) == 0)
750 if (adrof(STRbackslash_quote
) == 0)
752 if (adrof(STRsymlinks
) == 0)
754 if (adrof(STRimplicitcd
) == 0)
756 if (adrof(STRkillring
) == 0)
758 if (did_edit
&& noediting
&& adrof(STRedit
) == 0)
760 if (did_roe
&& adrof(STRrecognize_only_executables
) == 0)
763 if (adrof(STRcolor
) == 0)
765 #endif /* COLOR_LS_F */
766 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
767 update_dspmbyte_vars();
772 #endif /* NLS_CATALOGS */
776 unset1(Char
*v
[], struct varent
*head
)
783 while ((vp
= madrof(*v
, head
)) != NULL
)
784 if (vp
->v_flags
& VAR_READONLY
)
785 stderror(ERR_READONLY
|ERR_NAME
, vp
->v_name
);
789 setname(short2str(*v
));
798 if ((vp
= adrof1(var
, &shvhed
)) == 0)
804 unsetv1(struct varent
*p
)
806 struct varent
*c
, *pp
;
810 * Free associated memory first to avoid complications.
815 * If p is missing one child, then we can move the other into where p is.
816 * Otherwise, we find the predecessor of p, which is guaranteed to have no
817 * right child, copy it into p, and move it's left child into it.
821 else if (p
->v_left
== 0)
824 for (c
= p
->v_left
; c
->v_right
; c
= c
->v_right
)
826 p
->v_name
= c
->v_name
;
827 p
->v_flags
= c
->v_flags
;
834 * Move c into where p is.
837 f
= pp
->v_right
== p
;
838 if ((pp
->v_link
[f
] = c
) != 0)
841 * Free the deleted node, and rebalance.
850 setcopy(cp
, STRNULL
, VAR_READWRITE
);
855 shift(Char
**v
, struct command
*c
)
868 if (argv
== NULL
|| argv
->vec
== NULL
)
870 if (argv
->vec
[0] == 0)
871 stderror(ERR_NAME
| ERR_NOMORE
);
872 lshift(argv
->vec
, 1);
877 exportpath(Char
**val
)
879 struct Strbuf buf
= Strbuf_INIT
;
884 Strbuf_append(&buf
, *val
++);
885 if (*val
== 0 || eq(*val
, STRRparen
))
887 Strbuf_append1(&buf
, PATHSEP
);
889 exppath
= Strbuf_finish(&buf
);
890 cleanup_push(exppath
, xfree
);
891 tsetenv(STRKPATH
, exppath
);
892 cleanup_until(exppath
);
897 * Lint thinks these have null effect
899 /* macros to do single rotations on node p */
900 # define rright(p) (\
902 (t)->v_parent = (p)->v_parent,\
903 (((p)->v_left = t->v_right) != NULL) ?\
904 (t->v_right->v_parent = (p)) : 0,\
905 (t->v_right = (p))->v_parent = t,\
909 ((t)->v_parent = (p)->v_parent,\
910 ((p)->v_right = t->v_left) != NULL) ? \
911 (t->v_left->v_parent = (p)) : 0,\
912 (t->v_left = (p))->v_parent = t,\
915 static struct varent
*
916 rleft(struct varent
*p
)
920 static struct varent
*
921 rright(struct varent
*p
)
930 * Rebalance a tree, starting at p and up.
931 * F == 0 means we've come from p's left child.
932 * D == 1 means we've just done a delete, otherwise an insert.
935 balance(struct varent
*p
, int f
, int d
)
940 struct varent
*t
; /* used by the rotate macros */
944 ff
= 0; /* Sun's lint is dumb! */
948 * Ok, from here on, p is the node we're operating on; pp is it's parent; f
949 * is the branch of p from which we have come; ff is the branch of pp which
952 for (; (pp
= p
->v_parent
) != 0; p
= pp
, f
= ff
) {
953 ff
= pp
->v_right
== p
;
954 if (f
^ d
) { /* right heavy */
956 case -1: /* was left heavy */
959 case 0: /* was balanced */
962 case 1: /* was already right heavy */
963 switch (p
->v_right
->v_bal
) {
964 case 1: /* single rotate */
965 pp
->v_link
[ff
] = rleft(p
);
966 p
->v_left
->v_bal
= 0;
969 case 0: /* single rotate */
970 pp
->v_link
[ff
] = rleft(p
);
971 p
->v_left
->v_bal
= 1;
974 case -1: /* double rotate */
975 (void) rright(p
->v_right
);
976 pp
->v_link
[ff
] = rleft(p
);
978 p
->v_bal
< 1 ? 0 : -1;
980 p
->v_bal
> -1 ? 0 : 1;
991 else { /* left heavy */
993 case 1: /* was right heavy */
996 case 0: /* was balanced */
999 case -1: /* was already left heavy */
1000 switch (p
->v_left
->v_bal
) {
1001 case -1: /* single rotate */
1002 pp
->v_link
[ff
] = rright(p
);
1003 p
->v_right
->v_bal
= 0;
1006 case 0: /* single rotate */
1007 pp
->v_link
[ff
] = rright(p
);
1008 p
->v_right
->v_bal
= -1;
1011 case 1: /* double rotate */
1012 (void) rleft(p
->v_left
);
1013 pp
->v_link
[ff
] = rright(p
);
1015 p
->v_bal
< 1 ? 0 : -1;
1017 p
->v_bal
> -1 ? 0 : 1;
1029 * If from insert, then we terminate when p is balanced. If from
1030 * delete, then we terminate when p is unbalanced.
1032 if ((p
->v_bal
== 0) ^ d
)
1038 plist(struct varent
*p
, int what
)
1047 if (p
->v_parent
== 0) /* is it the header? */
1049 if ((p
->v_flags
& what
) != 0) {
1051 int old_pintr_disabled
;
1053 pintr_push_enable(&old_pintr_disabled
);
1054 cleanup_until(&old_pintr_disabled
);
1056 len
= blklen(p
->vec
);
1057 xprintf("%S\t", p
->v_name
);
1072 } while (p
->v_right
== c
);
1077 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
1078 extern int dspmbyte_ls
;
1081 update_dspmbyte_vars(void)
1087 /* if variable "nokanji" is set, multi-byte display is disabled */
1088 if ((vp
= adrof(CHECK_MBYTEVAR
)) && !adrof(STRnokanji
)) {
1091 if(eq (dstr1
, STRsjis
))
1093 else if (eq(dstr1
, STReuc
))
1095 else if (eq(dstr1
, STRbig5
))
1097 else if (eq(dstr1
, STRutf8
))
1099 else if ((dstr1
[0] - '0') >= 0 && (dstr1
[0] - '0') <= 3) {
1103 xprintf(CGETS(18, 2,
1104 "Warning: unknown multibyte display; using default(euc(JP))\n"));
1107 if (dstr1
&& vp
->vec
[1] && eq(vp
->vec
[1], STRls
))
1111 for (lp
= 0; lp
< 256 && iskcode
> 0; lp
++) {
1115 _cmap
[lp
] = _cmap_mbyte
[lp
];
1116 _mbmap
[lp
] = _mbmap_sjis
[lp
];
1120 _cmap
[lp
] = _cmap_mbyte
[lp
];
1121 _mbmap
[lp
] = _mbmap_euc
[lp
];
1125 _cmap
[lp
] = _cmap_mbyte
[lp
];
1126 _mbmap
[lp
] = _mbmap_big5
[lp
];
1130 _cmap
[lp
] = _cmap_mbyte
[lp
];
1131 _mbmap
[lp
] = _mbmap_utf8
[lp
];
1134 xprintf(CGETS(18, 3,
1135 "Warning: unknown multibyte code %d; multibyte disabled\n"),
1137 _cmap
[lp
] = _cmap_c
[lp
];
1138 _mbmap
[lp
] = 0; /* Default map all 0 */
1144 /* check original table */
1145 if (Strlen(dstr1
) != 256) {
1146 xprintf(CGETS(18, 4,
1147 "Warning: Invalid multibyte table length (%d); multibyte disabled\n"),
1151 for (lp
= 0; lp
< 256 && _enable_mbdisp
== 1; lp
++) {
1152 if (!((dstr1
[lp
] - '0') >= 0 && (dstr1
[lp
] - '0') <= 3)) {
1153 xprintf(CGETS(18, 4,
1154 "Warning: bad multibyte code at offset +%d; multibyte diabled\n"),
1160 /* set original table */
1161 for (lp
= 0; lp
< 256; lp
++) {
1162 if (_enable_mbdisp
== 1) {
1163 _cmap
[lp
] = _cmap_mbyte
[lp
];
1164 _mbmap
[lp
] = (unsigned short) ((dstr1
[lp
] - '0') & 0x0f);
1167 _cmap
[lp
] = _cmap_c
[lp
];
1168 _mbmap
[lp
] = 0; /* Default map all 0 */
1174 for (lp
= 0; lp
< 256; lp
++) {
1175 _cmap
[lp
] = _cmap_c
[lp
];
1176 _mbmap
[lp
] = 0; /* Default map all 0 */
1181 #ifdef MBYTEDEBUG /* Sorry, use for beta testing */
1184 for (lp
= 0; lp
< 256; lp
++)
1185 mbmapstr
[lp
] = _mbmap
[lp
] + '0';
1187 setcopy(STRmbytemap
, mbmapstr
, VAR_READWRITE
);
1189 #endif /* MBYTEMAP */
1192 /* dspkanji/dspmbyte autosetting */
1193 /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
1195 autoset_dspmbyte(const Char
*pcp
)
1198 static const struct dspm_autoset_Table
{
1202 { STRLANGEUCJP
, STReuc
},
1203 { STRLANGEUCKR
, STReuc
},
1204 { STRLANGEUCZH
, STReuc
},
1205 { STRLANGEUCJPB
, STReuc
},
1206 { STRLANGEUCKRB
, STReuc
},
1207 { STRLANGEUCZHB
, STReuc
},
1209 { STRLANGEUCJPC
, STReuc
},
1211 { STRLANGSJIS
, STRsjis
},
1212 { STRLANGSJISB
, STRsjis
},
1213 { STRLANGBIG5
, STRbig5
},
1214 { STRstarutfstar8
, STRutf8
},
1217 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
1218 static const struct dspm_autoset_Table dspmc
[] = {
1219 { STRstarutfstar8
, STRutf8
},
1221 { STRGB2312
, STReuc
},
1222 { STRLANGBIG5
, STRbig5
},
1227 codeset
= str2short(nl_langinfo(CODESET
));
1228 if (*codeset
!= '\0') {
1229 for (i
= 0; dspmc
[i
].n
; i
++) {
1231 if (dspmc
[i
].n
[0] && t_pmatch(pcp
, dspmc
[i
].n
, &estr
, 0) > 0) {
1232 setcopy(CHECK_MBYTEVAR
, dspmc
[i
].v
, VAR_READWRITE
);
1233 update_dspmbyte_vars();
1243 for (i
= 0; dspmt
[i
].n
; i
++) {
1245 if (dspmt
[i
].n
[0] && t_pmatch(pcp
, dspmt
[i
].n
, &estr
, 0) > 0) {
1246 setcopy(CHECK_MBYTEVAR
, dspmt
[i
].v
, VAR_READWRITE
);
1247 update_dspmbyte_vars();