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 exportpath (Char
**);
57 static void balance (struct varent
*, int, int);
66 if (eq(vp
, STRpath
)) {
67 struct varent
*p
= adrof(STRpath
);
69 stderror(ERR_NAME
| ERR_UNDVAR
);
75 else if (eq(vp
, STRhistchars
)) {
76 Char
*pn
= varval(vp
);
81 else if (eq(vp
, STRpromptchars
)) {
82 Char
*pn
= varval(vp
);
87 else if (eq(vp
, STRhistlit
)) {
90 else if (eq(vp
, STRuser
)) {
91 tsetenv(STRKUSER
, varval(vp
));
92 tsetenv(STRLOGNAME
, varval(vp
));
94 else if (eq(vp
, STRgroup
)) {
95 tsetenv(STRKGROUP
, varval(vp
));
97 else if (eq(vp
, STRwordchars
)) {
98 word_chars
= varval(vp
);
100 else if (eq(vp
, STRloginsh
)) {
103 else if (eq(vp
, STRsymlinks
)) {
104 Char
*pn
= varval(vp
);
106 if (eq(pn
, STRignore
))
107 symlinks
= SYM_IGNORE
;
108 else if (eq(pn
, STRexpand
))
109 symlinks
= SYM_EXPAND
;
110 else if (eq(pn
, STRchase
))
111 symlinks
= SYM_CHASE
;
115 else if (eq(vp
, STRterm
)) {
116 Char
*cp
= varval(vp
);
117 tsetenv(STRKTERM
, cp
);
118 #ifdef DOESNT_WORK_RIGHT
119 cp
= getenv("TERMCAP");
120 if (cp
&& (*cp
!= '/')) /* if TERMCAP and not a path */
121 Unsetenv(STRTERMCAP
);
122 #endif /* DOESNT_WORK_RIGHT */
124 if (noediting
&& Strcmp(cp
, STRnetwork
) != 0 &&
125 Strcmp(cp
, STRunknown
) != 0 && Strcmp(cp
, STRdumb
) != 0) {
130 ed_Init(); /* reset the editor */
132 else if (eq(vp
, STRhome
)) {
135 cp
= Strsave(varval(vp
)); /* get the old value back */
136 cleanup_push(cp
, xfree
);
139 * convert to cononical pathname (possibly resolving symlinks)
141 canon
= dcanon(cp
, cp
);
144 cleanup_push(canon
, xfree
);
146 setcopy(vp
, canon
, VAR_READWRITE
); /* have to save the new val */
148 /* and now mirror home with HOME */
149 tsetenv(STRKHOME
, canon
);
150 /* fix directory stack for new tilde home */
152 cleanup_until(canon
);
154 else if (eq(vp
, STRedit
)) {
157 /* PWP: add more stuff in here later */
159 else if (eq(vp
, STRshlvl
)) {
160 tsetenv(STRKSHLVL
, varval(vp
));
162 else if (eq(vp
, STRignoreeof
)) {
165 for ((cp
= varval(STRignoreeof
)); cp
&& *cp
; cp
++) {
170 numeof
= numeof
* 10 + *cp
- '0';
172 if (numeof
<= 0) numeof
= 26; /* Sanity check */
174 else if (eq(vp
, STRbackslash_quote
)) {
177 else if (eq(vp
, STRdirstack
)) {
180 else if (eq(vp
, STRrecognize_only_executables
)) {
183 else if (eq(vp
, STRkillring
)) {
184 SetKillRing(getn(varval(vp
)));
187 else if (eq(vp
, STRwatch
)) {
190 #endif /* HAVENOUTMP */
191 else if (eq(vp
, STRimplicitcd
)) {
192 implicit_cd
= ((eq(varval(vp
), STRverbose
)) ? 2 : 1);
195 else if (eq(vp
, STRcolor
)) {
198 #endif /* COLOR_LS_F */
199 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
200 else if(eq(vp
, CHECK_MBYTEVAR
) || eq(vp
, STRnokanji
)) {
201 update_dspmbyte_vars();
205 else if (eq(vp
, STRcatalog
)) {
209 #if defined(FILEC) && defined(TIOCSTI)
210 else if (eq(vp
, STRfilec
))
213 #endif /* NLS_CATALOGS */
219 doset(Char
**v
, struct command
*c
)
226 int flags
= VAR_READWRITE
;
236 * Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
238 if (*v
&& eq(*v
, STRmr
)) {
239 flags
= VAR_READONLY
;
243 if (*v
&& eq(*v
, STRmf
) && !last_match
) {
248 if (*v
&& eq(*v
, STRml
) && !first_match
) {
256 plist(&shvhed
, flags
);
263 for (; alnum(*p
); p
++)
265 if (vp
== p
|| !letter(*vp
))
266 stderror(ERR_NAME
| ERR_VARBEGIN
);
269 p
= getinx(p
, &subscr
);
271 if ((op
= *p
) != 0) {
273 if (*p
== 0 && *v
&& **v
== '(')
276 else if (*v
&& eq(*v
, STRequal
)) {
282 stderror(ERR_NAME
| ERR_SYNTAX
);
283 if (eq(p
, STRLparen
)) {
287 stderror(ERR_NAME
| ERR_SYNTAX
);
290 stderror(ERR_NAME
| ERR_MISSING
, ')');
303 set1(vp
, vecp
, &shvhed
, flags
);
311 cleanup_push(copy
, xfree
);
312 asx(vp
, subscr
, copy
);
313 cleanup_ignore(copy
);
317 setv(vp
, Strsave(p
), flags
);
319 } while ((p
= *v
++) != NULL
);
323 getinx(Char
*cp
, int *ip
)
327 while (*cp
&& Isdigit(*cp
))
328 *ip
= *ip
* 10 + *cp
++ - '0';
330 stderror(ERR_NAME
| ERR_SUBSCRIPT
);
335 asx(Char
*vp
, int subscr
, Char
*p
)
337 struct varent
*v
= getvx(vp
, subscr
);
340 if (v
->v_flags
& VAR_READONLY
)
341 stderror(ERR_READONLY
|ERR_NAME
, v
->v_name
);
342 prev
= v
->vec
[subscr
- 1];
343 cleanup_push(prev
, xfree
);
344 v
->vec
[subscr
- 1] = globone(p
, G_APPEND
);
348 static struct varent
*
349 getvx(Char
*vp
, int subscr
)
351 struct varent
*v
= adrof(vp
);
355 if (subscr
< 1 || subscr
> blklen(v
->vec
))
356 stderror(ERR_NAME
| ERR_RANGE
);
362 dolet(Char
**v
, struct command
*dummy
)
380 for (; alnum(*p
); p
++)
382 if (vp
== p
|| !letter(*vp
))
383 stderror(ERR_NAME
| ERR_VARBEGIN
);
386 p
= getinx(p
, &subscr
);
393 stderror(ERR_NAME
| ERR_ASSIGN
);
396 * if there is no expression after the '=' then print a "Syntax Error"
399 if (*p
== '\0' && *v
== NULL
)
400 stderror(ERR_NAME
| ERR_ASSIGN
);
403 cleanup_push(vp
, xfree
);
412 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
418 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
419 stderror(ERR_NAME
| ERR_SYNTAX
);
422 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
426 cleanup_push(p
, xfree
);
431 setv(vp
, p
, VAR_READWRITE
);
435 struct varent
*gv
= getvx(vp
, subscr
);
438 val
= operate(op
, gv
->vec
[subscr
- 1], p
);
439 cleanup_push(val
, xfree
);
440 asx(vp
, subscr
, val
);
447 val
= operate(op
, varval(vp
), p
);
448 cleanup_push(val
, xfree
);
449 setv(vp
, val
, VAR_READWRITE
);
455 } while ((p
= *v
++) != NULL
);
459 xset(Char
*cp
, Char
***vp
)
469 return (putn(expr(vp
)));
473 operate(int op
, Char
*vp
, Char
*p
)
487 if (op
== '<' || op
== '>')
494 stderror(ERR_NAME
| ERR_EXPRESSION
);
503 Char nbuf
[(CHAR_BIT
* sizeof (n
) + 2) / 3 + 2]; /* Enough even for octal */
512 return (Strsave(nbuf
));
520 *putp
++ = n
% 10 + '0';
529 if (!cp
) /* PWP: extra error checking */
530 stderror(ERR_NAME
| ERR_BADNUM
);
533 if (cp
[0] == '+' && cp
[1])
539 stderror(ERR_NAME
| ERR_BADNUM
);
543 n
= n
* 10 + *cp
++ - '0';
545 stderror(ERR_NAME
| ERR_BADNUM
);
546 return (sign
? -n
: n
);
550 value1(Char
*var
, struct varent
*head
)
554 if (!var
|| !head
) /* PWP: extra error checking */
557 vp
= adrof1(var
, head
);
558 return ((vp
== NULL
|| vp
->vec
== NULL
|| vp
->vec
[0] == NULL
) ?
559 STRNULL
: vp
->vec
[0]);
562 static struct varent
*
563 madrof(Char
*pat
, struct varent
*vp
)
567 for (vp
= vp
->v_left
; vp
; vp
= vp
->v_right
) {
568 if (vp
->v_left
&& (vp1
= madrof(pat
, vp
)) != NULL
)
570 if (Gmatch(vp
->v_name
, pat
))
577 adrof1(const Char
*name
, struct varent
*v
)
582 while (v
&& ((cmp
= *name
- *v
->v_name
) != 0 ||
583 (cmp
= Strcmp(name
, v
->v_name
)) != 0))
592 setcopy(const Char
*var
, const Char
*val
, int flags
)
597 cleanup_push(copy
, xfree
);
598 setv(var
, copy
, flags
);
599 cleanup_ignore(copy
);
604 * The caller is responsible for putting value in a safe place
607 setv(const Char
*var
, Char
*val
, int flags
)
609 Char
**vec
= xmalloc(2 * sizeof(Char
**));
613 set1(var
, vec
, &shvhed
, flags
);
617 set1(const Char
*var
, Char
**vec
, struct varent
*head
, int flags
)
621 if ((flags
& VAR_NOGLOB
) == 0) {
626 vec
= globall(oldv
, gflag
);
629 stderror(ERR_NAME
| ERR_NOMATCH
);
635 * Uniqueness addition from: Michael Veksler <mveksler@vnet.ibm.com>
637 if ( flags
& (VAR_FIRST
| VAR_LAST
) ) {
639 * Code for -f (VAR_FIRST) and -l (VAR_LAST) options.
641 * Delete all duplicate words leaving "holes" in the word array (vec).
642 * Then remove the "holes", keeping the order of the words unchanged.
644 if (vec
&& vec
[0] && vec
[1]) { /* more than one word ? */
648 for (num_items
= 0; vec
[num_items
]; num_items
++)
650 if (flags
& VAR_FIRST
) {
651 /* delete duplications, keeping first occurance */
652 for (i
= 1; i
< num_items
; i
++)
653 for (j
= 0; j
< i
; j
++)
654 /* If have earlier identical item, remove i'th item */
655 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
660 } else if (flags
& VAR_LAST
) {
661 /* delete duplications, keeping last occurance */
662 for (i
= 0; i
< num_items
- 1; i
++)
663 for (j
= i
+ 1; j
< num_items
; j
++)
664 /* If have later identical item, remove i'th item */
665 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
666 /* remove identical item (the first) */
671 /* Compress items - remove empty items */
672 for (j
= i
= 0; i
< num_items
; i
++)
676 /* NULL-fy remaining items */
677 for (; j
< num_items
; j
++)
680 /* don't let the attribute propagate */
681 flags
&= ~(VAR_FIRST
|VAR_LAST
);
683 setq(var
, vec
, head
, flags
);
688 setq(const Char
*name
, Char
**vec
, struct varent
*p
, int flags
)
693 f
= 0; /* tree hangs off the header's left link */
694 while ((c
= p
->v_link
[f
]) != 0) {
695 if ((f
= *name
- *c
->v_name
) == 0 &&
696 (f
= Strcmp(name
, c
->v_name
)) == 0) {
697 if (c
->v_flags
& VAR_READONLY
)
698 stderror(ERR_READONLY
|ERR_NAME
, c
->v_name
);
707 p
->v_link
[f
] = c
= xmalloc(sizeof(struct varent
));
708 c
->v_name
= Strsave(name
);
711 c
->v_left
= c
->v_right
= 0;
719 unset(Char
**v
, struct command
*c
)
721 int did_roe
, did_edit
;
724 did_roe
= adrof(STRrecognize_only_executables
) != NULL
;
725 did_edit
= adrof(STRedit
) != NULL
;
728 #if defined(FILEC) && defined(TIOCSTI)
729 if (adrof(STRfilec
) == 0)
731 #endif /* FILEC && TIOCSTI */
733 if (adrof(STRhistchars
) == 0) {
737 if (adrof(STRignoreeof
) == 0)
739 if (adrof(STRpromptchars
) == 0) {
743 if (adrof(STRhistlit
) == 0)
745 if (adrof(STRloginsh
) == 0)
747 if (adrof(STRwordchars
) == 0)
748 word_chars
= STR_WORD_CHARS
;
749 if (adrof(STRedit
) == 0)
751 if (adrof(STRbackslash_quote
) == 0)
753 if (adrof(STRsymlinks
) == 0)
755 if (adrof(STRimplicitcd
) == 0)
757 if (adrof(STRkillring
) == 0)
759 if (did_edit
&& noediting
&& adrof(STRedit
) == 0)
761 if (did_roe
&& adrof(STRrecognize_only_executables
) == 0)
764 if (adrof(STRcolor
) == 0)
766 #endif /* COLOR_LS_F */
767 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
768 update_dspmbyte_vars();
773 #endif /* NLS_CATALOGS */
777 unset1(Char
*v
[], struct varent
*head
)
784 while ((vp
= madrof(*v
, head
)) != NULL
)
785 if (vp
->v_flags
& VAR_READONLY
)
786 stderror(ERR_READONLY
|ERR_NAME
, vp
->v_name
);
790 setname(short2str(*v
));
799 if ((vp
= adrof1(var
, &shvhed
)) == 0)
805 unsetv1(struct varent
*p
)
807 struct varent
*c
, *pp
;
811 * Free associated memory first to avoid complications.
816 * If p is missing one child, then we can move the other into where p is.
817 * Otherwise, we find the predecessor of p, which is guaranteed to have no
818 * right child, copy it into p, and move it's left child into it.
822 else if (p
->v_left
== 0)
825 for (c
= p
->v_left
; c
->v_right
; c
= c
->v_right
)
827 p
->v_name
= c
->v_name
;
828 p
->v_flags
= c
->v_flags
;
835 * Move c into where p is.
838 f
= pp
->v_right
== p
;
839 if ((pp
->v_link
[f
] = c
) != 0)
842 * Free the deleted node, and rebalance.
851 setcopy(cp
, STRNULL
, VAR_READWRITE
);
856 shift(Char
**v
, struct command
*c
)
869 if (argv
== NULL
|| argv
->vec
== NULL
)
871 if (argv
->vec
[0] == 0)
872 stderror(ERR_NAME
| ERR_NOMORE
);
873 lshift(argv
->vec
, 1);
878 exportpath(Char
**val
)
880 struct Strbuf buf
= Strbuf_INIT
;
885 Strbuf_append(&buf
, *val
++);
886 if (*val
== 0 || eq(*val
, STRRparen
))
888 Strbuf_append1(&buf
, PATHSEP
);
890 exppath
= Strbuf_finish(&buf
);
891 cleanup_push(exppath
, xfree
);
892 tsetenv(STRKPATH
, exppath
);
893 cleanup_until(exppath
);
898 * Lint thinks these have null effect
900 /* macros to do single rotations on node p */
901 # define rright(p) (\
903 (t)->v_parent = (p)->v_parent,\
904 (((p)->v_left = t->v_right) != NULL) ?\
905 (t->v_right->v_parent = (p)) : 0,\
906 (t->v_right = (p))->v_parent = t,\
910 ((t)->v_parent = (p)->v_parent,\
911 ((p)->v_right = t->v_left) != NULL) ? \
912 (t->v_left->v_parent = (p)) : 0,\
913 (t->v_left = (p))->v_parent = t,\
916 static struct varent
*
917 rleft(struct varent
*p
)
921 static struct varent
*
922 rright(struct varent
*p
)
931 * Rebalance a tree, starting at p and up.
932 * F == 0 means we've come from p's left child.
933 * D == 1 means we've just done a delete, otherwise an insert.
936 balance(struct varent
*p
, int f
, int d
)
941 struct varent
*t
; /* used by the rotate macros */
945 ff
= 0; /* Sun's lint is dumb! */
949 * Ok, from here on, p is the node we're operating on; pp is it's parent; f
950 * is the branch of p from which we have come; ff is the branch of pp which
953 for (; (pp
= p
->v_parent
) != 0; p
= pp
, f
= ff
) {
954 ff
= pp
->v_right
== p
;
955 if (f
^ d
) { /* right heavy */
957 case -1: /* was left heavy */
960 case 0: /* was balanced */
963 case 1: /* was already right heavy */
964 switch (p
->v_right
->v_bal
) {
965 case 1: /* single rotate */
966 pp
->v_link
[ff
] = rleft(p
);
967 p
->v_left
->v_bal
= 0;
970 case 0: /* single rotate */
971 pp
->v_link
[ff
] = rleft(p
);
972 p
->v_left
->v_bal
= 1;
975 case -1: /* double rotate */
976 (void) rright(p
->v_right
);
977 pp
->v_link
[ff
] = rleft(p
);
979 p
->v_bal
< 1 ? 0 : -1;
981 p
->v_bal
> -1 ? 0 : 1;
992 else { /* left heavy */
994 case 1: /* was right heavy */
997 case 0: /* was balanced */
1000 case -1: /* was already left heavy */
1001 switch (p
->v_left
->v_bal
) {
1002 case -1: /* single rotate */
1003 pp
->v_link
[ff
] = rright(p
);
1004 p
->v_right
->v_bal
= 0;
1007 case 0: /* single rotate */
1008 pp
->v_link
[ff
] = rright(p
);
1009 p
->v_right
->v_bal
= -1;
1012 case 1: /* double rotate */
1013 (void) rleft(p
->v_left
);
1014 pp
->v_link
[ff
] = rright(p
);
1016 p
->v_bal
< 1 ? 0 : -1;
1018 p
->v_bal
> -1 ? 0 : 1;
1030 * If from insert, then we terminate when p is balanced. If from
1031 * delete, then we terminate when p is unbalanced.
1033 if ((p
->v_bal
== 0) ^ d
)
1039 plist(struct varent
*p
, int what
)
1048 if (p
->v_parent
== 0) /* is it the header? */
1050 if ((p
->v_flags
& what
) != 0) {
1052 int old_pintr_disabled
;
1054 pintr_push_enable(&old_pintr_disabled
);
1055 cleanup_until(&old_pintr_disabled
);
1057 len
= blklen(p
->vec
);
1058 xprintf("%S\t", p
->v_name
);
1073 } while (p
->v_right
== c
);
1078 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
1079 extern int dspmbyte_ls
;
1082 update_dspmbyte_vars(void)
1088 /* if variable "nokanji" is set, multi-byte display is disabled */
1089 if ((vp
= adrof(CHECK_MBYTEVAR
)) && !adrof(STRnokanji
)) {
1092 if(eq (dstr1
, STRsjis
))
1094 else if (eq(dstr1
, STReuc
))
1096 else if (eq(dstr1
, STRbig5
))
1098 else if (eq(dstr1
, STRutf8
))
1100 else if ((dstr1
[0] - '0') >= 0 && (dstr1
[0] - '0') <= 3) {
1104 xprintf(CGETS(18, 2,
1105 "Warning: unknown multibyte display; using default(euc(JP))\n"));
1108 if (dstr1
&& vp
->vec
[1] && eq(vp
->vec
[1], STRls
))
1112 for (lp
= 0; lp
< 256 && iskcode
> 0; lp
++) {
1116 _cmap
[lp
] = _cmap_mbyte
[lp
];
1117 _mbmap
[lp
] = _mbmap_sjis
[lp
];
1121 _cmap
[lp
] = _cmap_mbyte
[lp
];
1122 _mbmap
[lp
] = _mbmap_euc
[lp
];
1126 _cmap
[lp
] = _cmap_mbyte
[lp
];
1127 _mbmap
[lp
] = _mbmap_big5
[lp
];
1131 _cmap
[lp
] = _cmap_mbyte
[lp
];
1132 _mbmap
[lp
] = _mbmap_utf8
[lp
];
1135 xprintf(CGETS(18, 3,
1136 "Warning: unknown multibyte code %d; multibyte disabled\n"),
1138 _cmap
[lp
] = _cmap_c
[lp
];
1139 _mbmap
[lp
] = 0; /* Default map all 0 */
1145 /* check original table */
1146 if (Strlen(dstr1
) != 256) {
1147 xprintf(CGETS(18, 4,
1148 "Warning: Invalid multibyte table length (%d); multibyte disabled\n"),
1152 for (lp
= 0; lp
< 256 && _enable_mbdisp
== 1; lp
++) {
1153 if (!((dstr1
[lp
] - '0') >= 0 && (dstr1
[lp
] - '0') <= 3)) {
1154 xprintf(CGETS(18, 4,
1155 "Warning: bad multibyte code at offset +%d; multibyte diabled\n"),
1161 /* set original table */
1162 for (lp
= 0; lp
< 256; lp
++) {
1163 if (_enable_mbdisp
== 1) {
1164 _cmap
[lp
] = _cmap_mbyte
[lp
];
1165 _mbmap
[lp
] = (unsigned short) ((dstr1
[lp
] - '0') & 0x0f);
1168 _cmap
[lp
] = _cmap_c
[lp
];
1169 _mbmap
[lp
] = 0; /* Default map all 0 */
1175 for (lp
= 0; lp
< 256; lp
++) {
1176 _cmap
[lp
] = _cmap_c
[lp
];
1177 _mbmap
[lp
] = 0; /* Default map all 0 */
1182 #ifdef MBYTEDEBUG /* Sorry, use for beta testing */
1185 for (lp
= 0; lp
< 256; lp
++)
1186 mbmapstr
[lp
] = _mbmap
[lp
] + '0';
1188 setcopy(STRmbytemap
, mbmapstr
, VAR_READWRITE
);
1190 #endif /* MBYTEMAP */
1193 /* dspkanji/dspmbyte autosetting */
1194 /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
1196 autoset_dspmbyte(const Char
*pcp
)
1199 static const struct dspm_autoset_Table
{
1203 { STRLANGEUCJP
, STReuc
},
1204 { STRLANGEUCKR
, STReuc
},
1205 { STRLANGEUCZH
, STReuc
},
1206 { STRLANGEUCJPB
, STReuc
},
1207 { STRLANGEUCKRB
, STReuc
},
1208 { STRLANGEUCZHB
, STReuc
},
1210 { STRLANGEUCJPC
, STReuc
},
1212 { STRLANGSJIS
, STRsjis
},
1213 { STRLANGSJISB
, STRsjis
},
1214 { STRLANGBIG5
, STRbig5
},
1215 { STRstarutfstar8
, STRutf8
},
1218 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
1219 static const struct dspm_autoset_Table dspmc
[] = {
1220 { STRstarutfstar8
, STRutf8
},
1222 { STRGB2312
, STReuc
},
1223 { STRLANGBIG5
, STRbig5
},
1228 codeset
= str2short(nl_langinfo(CODESET
));
1229 if (*codeset
!= '\0') {
1230 for (i
= 0; dspmc
[i
].n
; i
++) {
1232 if (dspmc
[i
].n
[0] && t_pmatch(pcp
, dspmc
[i
].n
, &estr
, 0) > 0) {
1233 setcopy(CHECK_MBYTEVAR
, dspmc
[i
].v
, VAR_READWRITE
);
1234 update_dspmbyte_vars();
1244 for (i
= 0; dspmt
[i
].n
; i
++) {
1246 if (dspmt
[i
].n
[0] && t_pmatch(pcp
, dspmt
[i
].n
, &estr
, 0) > 0) {
1247 setcopy(CHECK_MBYTEVAR
, dspmt
[i
].v
, VAR_READWRITE
);
1248 update_dspmbyte_vars();