1 /* $Header: /p/tcsh/cvsroot/tcsh/sh.set.c,v 3.86 2014/10/28 18:40:46 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.86 2014/10/28 18:40:46 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 (tcsh_number_t
);
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
);
83 else if (eq(vp
, STRpromptchars
)) {
84 Char
*pn
= varval(vp
);
92 else if (eq(vp
, STRhistlit
)) {
95 else if (eq(vp
, STRuser
)) {
96 tsetenv(STRKUSER
, varval(vp
));
97 tsetenv(STRLOGNAME
, varval(vp
));
99 else if (eq(vp
, STRgroup
)) {
100 tsetenv(STRKGROUP
, varval(vp
));
102 else if (eq(vp
, STRwordchars
)) {
103 word_chars
= varval(vp
);
105 else if (eq(vp
, STRloginsh
)) {
108 else if (eq(vp
, STRanyerror
)) {
111 else if (eq(vp
, STRsymlinks
)) {
112 Char
*pn
= varval(vp
);
114 if (eq(pn
, STRignore
))
115 symlinks
= SYM_IGNORE
;
116 else if (eq(pn
, STRexpand
))
117 symlinks
= SYM_EXPAND
;
118 else if (eq(pn
, STRchase
))
119 symlinks
= SYM_CHASE
;
123 else if (eq(vp
, STRterm
)) {
124 Char
*cp
= varval(vp
);
125 tsetenv(STRKTERM
, cp
);
126 #ifdef DOESNT_WORK_RIGHT
127 cp
= getenv("TERMCAP");
128 if (cp
&& (*cp
!= '/')) /* if TERMCAP and not a path */
129 Unsetenv(STRTERMCAP
);
130 #endif /* DOESNT_WORK_RIGHT */
132 if (noediting
&& Strcmp(cp
, STRnetwork
) != 0 &&
133 Strcmp(cp
, STRunknown
) != 0 && Strcmp(cp
, STRdumb
) != 0) {
138 ed_Init(); /* reset the editor */
140 else if (eq(vp
, STRhome
)) {
143 cp
= Strsave(varval(vp
)); /* get the old value back */
144 cleanup_push(cp
, xfree
);
147 * convert to cononical pathname (possibly resolving symlinks)
149 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
, STRshlvl
)) {
168 tsetenv(STRKSHLVL
, varval(vp
));
170 else if (eq(vp
, STRignoreeof
)) {
173 for ((cp
= varval(STRignoreeof
)); cp
&& *cp
; cp
++) {
178 numeof
= numeof
* 10 + *cp
- '0';
180 if (numeof
<= 0) numeof
= 26; /* Sanity check */
182 else if (eq(vp
, STRbackslash_quote
)) {
185 else if (eq(vp
, STRcompat_expr
)) {
188 else if (eq(vp
, STRdirstack
)) {
191 else if (eq(vp
, STRrecognize_only_executables
)) {
194 else if (eq(vp
, STRkillring
)) {
195 SetKillRing((int)getn(varval(vp
)));
197 else if (eq(vp
, STRhistory
)) {
198 sethistory((int)getn(varval(vp
)));
201 else if (eq(vp
, STRwatch
)) {
204 #endif /* HAVENOUTMP */
205 else if (eq(vp
, STRimplicitcd
)) {
206 implicit_cd
= ((eq(varval(vp
), STRverbose
)) ? 2 : 1);
208 else if (eq(vp
, STRcdtohome
)) {
212 else if (eq(vp
, STRcolor
)) {
215 #endif /* COLOR_LS_F */
216 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
217 else if(eq(vp
, CHECK_MBYTEVAR
) || eq(vp
, STRnokanji
)) {
218 update_dspmbyte_vars();
222 else if (eq(vp
, STRcatalog
)) {
226 #if defined(FILEC) && defined(TIOCSTI)
227 else if (eq(vp
, STRfilec
))
230 #endif /* NLS_CATALOGS */
236 doset(Char
**v
, struct command
*c
)
243 int flags
= VAR_READWRITE
;
253 * Readonly addition From: Tim P. Starrin <noid@cyborg.larc.nasa.gov>
255 if (*v
&& eq(*v
, STRmr
)) {
256 flags
= VAR_READONLY
;
260 if (*v
&& eq(*v
, STRmf
) && !last_match
) {
265 if (*v
&& eq(*v
, STRml
) && !first_match
) {
273 plist(&shvhed
, flags
);
280 stderror(ERR_NAME
| ERR_VARBEGIN
);
286 p
= getinx(p
, &subscr
);
288 if (*p
!= '\0' && *p
!= '=')
289 stderror(ERR_NAME
| ERR_VARALNUM
);
292 if (*p
== '\0' && *v
!= NULL
&& **v
== '(')
295 else if (*v
&& eq(*v
, STRequal
)) {
299 if (eq(p
, STRLparen
)) {
303 stderror(ERR_NAME
| ERR_SYNTAX
);
306 stderror(ERR_NAME
| ERR_MISSING
, ')');
319 set1(vp
, vecp
, &shvhed
, flags
);
327 cleanup_push(copy
, xfree
);
328 asx(vp
, subscr
, copy
);
329 cleanup_ignore(copy
);
333 setv(vp
, Strsave(p
), flags
);
335 } while ((p
= *v
++) != NULL
);
339 getinx(Char
*cp
, int *ip
)
343 while (*cp
&& Isdigit(*cp
))
344 *ip
= *ip
* 10 + *cp
++ - '0';
346 stderror(ERR_NAME
| ERR_SUBSCRIPT
);
351 asx(Char
*vp
, int subscr
, Char
*p
)
353 struct varent
*v
= getvx(vp
, subscr
);
356 if (v
->v_flags
& VAR_READONLY
)
357 stderror(ERR_READONLY
|ERR_NAME
, v
->v_name
);
358 prev
= v
->vec
[subscr
- 1];
359 cleanup_push(prev
, xfree
);
360 v
->vec
[subscr
- 1] = globone(p
, G_APPEND
);
364 static struct varent
*
365 getvx(Char
*vp
, int subscr
)
367 struct varent
*v
= adrof(vp
);
371 if (subscr
< 1 || subscr
> blklen(v
->vec
))
372 stderror(ERR_NAME
| ERR_RANGE
);
378 dolet(Char
**v
, struct command
*dummy
)
396 for (; alnum(*p
); p
++)
398 if (vp
== p
|| !letter(*vp
))
399 stderror(ERR_NAME
| ERR_VARBEGIN
);
402 p
= getinx(p
, &subscr
);
409 stderror(ERR_NAME
| ERR_ASSIGN
);
412 * if there is no expression after the '=' then print a "Syntax Error"
415 if (*p
== '\0' && *v
== NULL
)
416 stderror(ERR_NAME
| ERR_ASSIGN
);
419 cleanup_push(vp
, xfree
);
428 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
434 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
435 stderror(ERR_NAME
| ERR_SYNTAX
);
438 stderror(ERR_NAME
| ERR_UNKNOWNOP
);
442 cleanup_push(p
, xfree
);
447 setv(vp
, p
, VAR_READWRITE
);
451 struct varent
*gv
= getvx(vp
, subscr
);
454 val
= operate(op
, gv
->vec
[subscr
- 1], p
);
455 cleanup_push(val
, xfree
);
456 asx(vp
, subscr
, val
);
463 val
= operate(op
, varval(vp
), p
);
464 cleanup_push(val
, xfree
);
465 setv(vp
, val
, VAR_READWRITE
);
471 } while ((p
= *v
++) != NULL
);
475 xset(Char
*cp
, Char
***vp
)
485 return (putn(expr(vp
)));
489 operate(int op
, Char
*vp
, Char
*p
)
503 if (op
== '<' || op
== '>')
510 stderror(ERR_NAME
| ERR_EXPRESSION
);
517 putn(tcsh_number_t n
)
519 Char nbuf
[1024]; /* Enough even for octal */
528 return (Strsave(nbuf
));
532 putn1(tcsh_number_t n
)
536 *putp
++ = (Char
)(n
% 10 + '0');
546 if (!cp
) /* PWP: extra error checking */
547 stderror(ERR_NAME
| ERR_BADNUM
);
550 if (cp
[0] == '+' && cp
[1])
556 stderror(ERR_NAME
| ERR_BADNUM
);
559 if (cp
[0] == '0' && cp
[1] && is_set(STRparseoctal
))
567 if (base
== 8 && *cp
>= '8')
568 stderror(ERR_NAME
| ERR_BADNUM
);
569 n
= n
* base
+ *cp
++ - '0';
572 stderror(ERR_NAME
| ERR_BADNUM
);
573 return (sign
? -n
: n
);
577 value1(Char
*var
, struct varent
*head
)
581 if (!var
|| !head
) /* PWP: extra error checking */
584 vp
= adrof1(var
, head
);
585 return ((vp
== NULL
|| vp
->vec
== NULL
|| vp
->vec
[0] == NULL
) ?
586 STRNULL
: vp
->vec
[0]);
589 static struct varent
*
590 madrof(Char
*pat
, struct varent
*vp
)
594 for (vp
= vp
->v_left
; vp
; vp
= vp
->v_right
) {
595 if (vp
->v_left
&& (vp1
= madrof(pat
, vp
)) != NULL
)
597 if (Gmatch(vp
->v_name
, pat
))
604 adrof1(const Char
*name
, struct varent
*v
)
609 while (v
&& ((cmp
= *name
- *v
->v_name
) != 0 ||
610 (cmp
= Strcmp(name
, v
->v_name
)) != 0))
619 setcopy(const Char
*var
, const Char
*val
, int flags
)
624 cleanup_push(copy
, xfree
);
625 setv(var
, copy
, flags
);
626 cleanup_ignore(copy
);
631 * The caller is responsible for putting value in a safe place
634 setv(const Char
*var
, Char
*val
, int flags
)
636 Char
**vec
= xmalloc(2 * sizeof(Char
**));
640 set1(var
, vec
, &shvhed
, flags
);
644 set1(const Char
*var
, Char
**vec
, struct varent
*head
, int flags
)
648 if ((flags
& VAR_NOGLOB
) == 0) {
653 vec
= globall(oldv
, gflag
);
656 stderror(ERR_NAME
| ERR_NOMATCH
);
662 * Uniqueness addition from: Michael Veksler <mveksler@vnet.ibm.com>
664 if ( flags
& (VAR_FIRST
| VAR_LAST
) ) {
666 * Code for -f (VAR_FIRST) and -l (VAR_LAST) options.
668 * Delete all duplicate words leaving "holes" in the word array (vec).
669 * Then remove the "holes", keeping the order of the words unchanged.
671 if (vec
&& vec
[0] && vec
[1]) { /* more than one word ? */
675 for (num_items
= 0; vec
[num_items
]; num_items
++)
677 if (flags
& VAR_FIRST
) {
678 /* delete duplications, keeping first occurance */
679 for (i
= 1; i
< num_items
; i
++)
680 for (j
= 0; j
< i
; j
++)
681 /* If have earlier identical item, remove i'th item */
682 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
687 } else if (flags
& VAR_LAST
) {
688 /* delete duplications, keeping last occurance */
689 for (i
= 0; i
< num_items
- 1; i
++)
690 for (j
= i
+ 1; j
< num_items
; j
++)
691 /* If have later identical item, remove i'th item */
692 if (vec
[i
] && vec
[j
] && Strcmp(vec
[j
], vec
[i
]) == 0) {
693 /* remove identical item (the first) */
698 /* Compress items - remove empty items */
699 for (j
= i
= 0; i
< num_items
; i
++)
703 /* NULL-fy remaining items */
704 for (; j
< num_items
; j
++)
707 /* don't let the attribute propagate */
708 flags
&= ~(VAR_FIRST
|VAR_LAST
);
710 setq(var
, vec
, head
, flags
);
715 setq(const Char
*name
, Char
**vec
, struct varent
*p
, int flags
)
720 f
= 0; /* tree hangs off the header's left link */
721 while ((c
= p
->v_link
[f
]) != 0) {
722 if ((f
= *name
- *c
->v_name
) == 0 &&
723 (f
= Strcmp(name
, c
->v_name
)) == 0) {
724 if (c
->v_flags
& VAR_READONLY
)
725 stderror(ERR_READONLY
|ERR_NAME
, c
->v_name
);
734 p
->v_link
[f
] = c
= xmalloc(sizeof(struct varent
));
735 c
->v_name
= Strsave(name
);
738 c
->v_left
= c
->v_right
= 0;
746 unset(Char
**v
, struct command
*c
)
748 int did_roe
, did_edit
;
751 did_roe
= adrof(STRrecognize_only_executables
) != NULL
;
752 did_edit
= adrof(STRedit
) != NULL
;
755 #if defined(FILEC) && defined(TIOCSTI)
756 if (adrof(STRfilec
) == 0)
758 #endif /* FILEC && TIOCSTI */
760 if (adrof(STRhistchars
) == 0) {
764 if (adrof(STRignoreeof
) == 0)
766 if (adrof(STRpromptchars
) == 0) {
767 PRCH
= tcsh
? '>' : '%';
770 if (adrof(STRhistlit
) == 0)
772 if (adrof(STRloginsh
) == 0)
774 if (adrof(STRanyerror
) == 0)
776 if (adrof(STRwordchars
) == 0)
777 word_chars
= STR_WORD_CHARS
;
778 if (adrof(STRedit
) == 0)
780 if (adrof(STRbackslash_quote
) == 0)
782 if (adrof(STRcompat_expr
) == 0)
784 if (adrof(STRsymlinks
) == 0)
786 if (adrof(STRimplicitcd
) == 0)
788 if (adrof(STRcdtohome
) == 0)
790 if (adrof(STRkillring
) == 0)
792 if (did_edit
&& noediting
&& adrof(STRedit
) == 0)
794 if (did_roe
&& adrof(STRrecognize_only_executables
) == 0)
796 if (adrof(STRhistory
) == 0)
799 if (adrof(STRcolor
) == 0)
801 #endif /* COLOR_LS_F */
802 #if defined(KANJI) && defined(SHORT_STRINGS) && defined(DSPMBYTE)
803 update_dspmbyte_vars();
808 #endif /* NLS_CATALOGS */
812 unset1(Char
*v
[], struct varent
*head
)
819 while ((vp
= madrof(*v
, head
)) != NULL
)
820 if (vp
->v_flags
& VAR_READONLY
)
821 stderror(ERR_READONLY
|ERR_NAME
, vp
->v_name
);
825 setname(short2str(*v
));
834 if ((vp
= adrof1(var
, &shvhed
)) == 0)
840 unsetv1(struct varent
*p
)
842 struct varent
*c
, *pp
;
846 * Free associated memory first to avoid complications.
851 * If p is missing one child, then we can move the other into where p is.
852 * Otherwise, we find the predecessor of p, which is guaranteed to have no
853 * right child, copy it into p, and move it's left child into it.
857 else if (p
->v_left
== 0)
860 for (c
= p
->v_left
; c
->v_right
; c
= c
->v_right
)
862 p
->v_name
= c
->v_name
;
863 p
->v_flags
= c
->v_flags
;
870 * Move c into where p is.
873 f
= pp
->v_right
== p
;
874 if ((pp
->v_link
[f
] = c
) != 0)
877 * Free the deleted node, and rebalance.
883 /* Set variable name to NULL. */
885 setNS(const Char
*varName
)
887 setcopy(varName
, STRNULL
, VAR_READWRITE
);
892 shift(Char
**v
, struct command
*c
)
905 if (argv
== NULL
|| argv
->vec
== NULL
)
907 if (argv
->vec
[0] == 0)
908 stderror(ERR_NAME
| ERR_NOMORE
);
909 lshift(argv
->vec
, 1);
914 exportpath(Char
**val
)
916 struct Strbuf buf
= Strbuf_INIT
;
921 Strbuf_append(&buf
, *val
++);
922 if (*val
== 0 || eq(*val
, STRRparen
))
924 Strbuf_append1(&buf
, PATHSEP
);
926 exppath
= Strbuf_finish(&buf
);
927 cleanup_push(exppath
, xfree
);
928 tsetenv(STRKPATH
, exppath
);
929 cleanup_until(exppath
);
934 * Lint thinks these have null effect
936 /* macros to do single rotations on node p */
937 # define rright(p) (\
939 (t)->v_parent = (p)->v_parent,\
940 (((p)->v_left = t->v_right) != NULL) ?\
941 (t->v_right->v_parent = (p)) : 0,\
942 (t->v_right = (p))->v_parent = t,\
946 ((t)->v_parent = (p)->v_parent,\
947 ((p)->v_right = t->v_left) != NULL) ? \
948 (t->v_left->v_parent = (p)) : 0,\
949 (t->v_left = (p))->v_parent = t,\
952 static struct varent
*
953 rleft(struct varent
*p
)
957 static struct varent
*
958 rright(struct varent
*p
)
967 * Rebalance a tree, starting at p and up.
968 * F == 0 means we've come from p's left child.
969 * D == 1 means we've just done a delete, otherwise an insert.
972 balance(struct varent
*p
, int f
, int d
)
977 struct varent
*t
; /* used by the rotate macros */
981 ff
= 0; /* Sun's lint is dumb! */
985 * Ok, from here on, p is the node we're operating on; pp is it's parent; f
986 * is the branch of p from which we have come; ff is the branch of pp which
989 for (; (pp
= p
->v_parent
) != 0; p
= pp
, f
= ff
) {
990 ff
= pp
->v_right
== p
;
991 if (f
^ d
) { /* right heavy */
993 case -1: /* was left heavy */
996 case 0: /* was balanced */
999 case 1: /* was already right heavy */
1000 switch (p
->v_right
->v_bal
) {
1001 case 1: /* single rotate */
1002 pp
->v_link
[ff
] = rleft(p
);
1003 p
->v_left
->v_bal
= 0;
1006 case 0: /* single rotate */
1007 pp
->v_link
[ff
] = rleft(p
);
1008 p
->v_left
->v_bal
= 1;
1011 case -1: /* double rotate */
1012 (void) rright(p
->v_right
);
1013 pp
->v_link
[ff
] = rleft(p
);
1015 p
->v_bal
< 1 ? 0 : -1;
1017 p
->v_bal
> -1 ? 0 : 1;
1028 else { /* left heavy */
1030 case 1: /* was right heavy */
1033 case 0: /* was balanced */
1036 case -1: /* was already left heavy */
1037 switch (p
->v_left
->v_bal
) {
1038 case -1: /* single rotate */
1039 pp
->v_link
[ff
] = rright(p
);
1040 p
->v_right
->v_bal
= 0;
1043 case 0: /* single rotate */
1044 pp
->v_link
[ff
] = rright(p
);
1045 p
->v_right
->v_bal
= -1;
1048 case 1: /* double rotate */
1049 (void) rleft(p
->v_left
);
1050 pp
->v_link
[ff
] = rright(p
);
1052 p
->v_bal
< 1 ? 0 : -1;
1054 p
->v_bal
> -1 ? 0 : 1;
1066 * If from insert, then we terminate when p is balanced. If from
1067 * delete, then we terminate when p is unbalanced.
1069 if ((p
->v_bal
== 0) ^ d
)
1075 plist(struct varent
*p
, int what
)
1084 if (p
->v_parent
== 0) /* is it the header? */
1086 if ((p
->v_flags
& what
) != 0) {
1088 int old_pintr_disabled
;
1090 pintr_push_enable(&old_pintr_disabled
);
1091 cleanup_until(&old_pintr_disabled
);
1093 len
= blklen(p
->vec
);
1094 xprintf("%S\t", p
->v_name
);
1109 } while (p
->v_right
== c
);
1115 # if defined(SHORT_STRINGS) && defined(DSPMBYTE)
1116 extern int dspmbyte_ls
;
1119 update_dspmbyte_vars(void)
1125 /* if variable "nokanji" is set, multi-byte display is disabled */
1126 if ((vp
= adrof(CHECK_MBYTEVAR
)) && !adrof(STRnokanji
)) {
1129 if(eq (dstr1
, STRsjis
))
1131 else if (eq(dstr1
, STReuc
))
1133 else if (eq(dstr1
, STRbig5
))
1135 else if (eq(dstr1
, STRutf8
))
1137 else if ((dstr1
[0] - '0') >= 0 && (dstr1
[0] - '0') <= 3) {
1141 xprintf(CGETS(18, 2,
1142 "Warning: unknown multibyte display; using default(euc(JP))\n"));
1145 if (dstr1
&& vp
->vec
[1] && eq(vp
->vec
[1], STRls
))
1149 for (lp
= 0; lp
< 256 && iskcode
> 0; lp
++) {
1153 _cmap
[lp
] = _cmap_mbyte
[lp
];
1154 _mbmap
[lp
] = _mbmap_sjis
[lp
];
1158 _cmap
[lp
] = _cmap_mbyte
[lp
];
1159 _mbmap
[lp
] = _mbmap_euc
[lp
];
1163 _cmap
[lp
] = _cmap_mbyte
[lp
];
1164 _mbmap
[lp
] = _mbmap_big5
[lp
];
1168 _cmap
[lp
] = _cmap_mbyte
[lp
];
1169 _mbmap
[lp
] = _mbmap_utf8
[lp
];
1172 xprintf(CGETS(18, 3,
1173 "Warning: unknown multibyte code %d; multibyte disabled\n"),
1175 _cmap
[lp
] = _cmap_c
[lp
];
1176 _mbmap
[lp
] = 0; /* Default map all 0 */
1182 /* check original table */
1183 if (Strlen(dstr1
) != 256) {
1184 xprintf(CGETS(18, 4,
1185 "Warning: Invalid multibyte table length (%d); multibyte disabled\n"),
1189 for (lp
= 0; lp
< 256 && _enable_mbdisp
== 1; lp
++) {
1190 if (!((dstr1
[lp
] - '0') >= 0 && (dstr1
[lp
] - '0') <= 3)) {
1191 xprintf(CGETS(18, 4,
1192 "Warning: bad multibyte code at offset +%d; multibyte diabled\n"),
1198 /* set original table */
1199 for (lp
= 0; lp
< 256; lp
++) {
1200 if (_enable_mbdisp
== 1) {
1201 _cmap
[lp
] = _cmap_mbyte
[lp
];
1202 _mbmap
[lp
] = (unsigned short) ((dstr1
[lp
] - '0') & 0x0f);
1205 _cmap
[lp
] = _cmap_c
[lp
];
1206 _mbmap
[lp
] = 0; /* Default map all 0 */
1212 for (lp
= 0; lp
< 256; lp
++) {
1213 _cmap
[lp
] = _cmap_c
[lp
];
1214 _mbmap
[lp
] = 0; /* Default map all 0 */
1219 #ifdef MBYTEDEBUG /* Sorry, use for beta testing */
1222 for (lp
= 0; lp
< 256; lp
++)
1223 mbmapstr
[lp
] = _mbmap
[lp
] + '0';
1225 setcopy(STRmbytemap
, mbmapstr
, VAR_READWRITE
);
1227 #endif /* MBYTEMAP */
1230 /* dspkanji/dspmbyte autosetting */
1231 /* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
1233 autoset_dspmbyte(const Char
*pcp
)
1236 static const struct dspm_autoset_Table
{
1240 { STRLANGEUCJP
, STReuc
},
1241 { STRLANGEUCKR
, STReuc
},
1242 { STRLANGEUCZH
, STReuc
},
1243 { STRLANGEUCJPB
, STReuc
},
1244 { STRLANGEUCKRB
, STReuc
},
1245 { STRLANGEUCZHB
, STReuc
},
1247 { STRLANGEUCJPC
, STReuc
},
1249 { STRLANGSJIS
, STRsjis
},
1250 { STRLANGSJISB
, STRsjis
},
1251 { STRLANGBIG5
, STRbig5
},
1252 { STRstarutfstar8
, STRutf8
},
1255 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
1256 static const struct dspm_autoset_Table dspmc
[] = {
1257 { STRstarutfstar8
, STRutf8
},
1259 { STRGB2312
, STReuc
},
1260 { STRLANGBIG5
, STRbig5
},
1265 codeset
= str2short(nl_langinfo(CODESET
));
1266 if (*codeset
!= '\0') {
1267 for (i
= 0; dspmc
[i
].n
; i
++) {
1269 if (dspmc
[i
].n
[0] && t_pmatch(pcp
, dspmc
[i
].n
, &estr
, 0) > 0) {
1270 setcopy(CHECK_MBYTEVAR
, dspmc
[i
].v
, VAR_READWRITE
);
1271 update_dspmbyte_vars();
1281 for (i
= 0; dspmt
[i
].n
; i
++) {
1283 if (dspmt
[i
].n
[0] && t_pmatch(pcp
, dspmt
[i
].n
, &estr
, 0) > 0) {
1284 setcopy(CHECK_MBYTEVAR
, dspmt
[i
].v
, VAR_READWRITE
);
1285 update_dspmbyte_vars();
1290 # elif defined(AUTOSET_KANJI)
1294 char *codeset
= nl_langinfo(CODESET
);
1296 if (*codeset
== '\0') {
1297 if (adrof(STRnokanji
) == NULL
)
1302 if (strcasestr(codeset
, "SHIFT_JIS") == (char*)0) {
1303 if (adrof(STRnokanji
) == NULL
)
1308 if (adrof(STRnokanji
) != NULL
)