--- a/usr/src/cmd/geniconvtbl/geniconvtbl.c Wed Jul 02 16:29:05 2008 -0700
+++ b/usr/src/cmd/geniconvtbl/geniconvtbl.c Wed Jul 02 17:06:30 2008 -0700
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 1999, 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -228,7 +227,7 @@
return ((void *)(-1));
}
(void) memset(ist->regs, 0,
- (sizeof (itm_num_t)) * hdr->reg_num);
+ (sizeof (itm_num_t)) * hdr->reg_num);
}
@@ -238,11 +237,8 @@
size_t ileft = 0;
unsigned char *op = NULL;
size_t oleft = 0;
- (void) eval_op_tbl(ist,
- ist->itm_hdr->op_init_tbl,
- &ip,
- &ileft,
- &op, &oleft);
+ (void) eval_op_tbl(ist, ist->itm_hdr->op_init_tbl, &ip,
+ &ileft, &op, &oleft);
} else {
op_init_default(ist);
}
@@ -304,11 +300,10 @@
retval = 0;
TRACE_MESSAGE('i', ("_icv_iconv(inbuf=%p inbytesleft=%ld "
- "outbuf=%p outbytesleft=%ld)\n",
- (NULL == inbuf) ? 0 : *inbuf,
- (NULL == inbytesleft) ? 0 : *inbytesleft,
- (NULL == outbuf) ? 0 : *outbuf,
- (NULL == outbytesleft) ? 0 : *outbytesleft));
+ "outbuf=%p outbytesleft=%ld)\n", (NULL == inbuf) ? 0 : *inbuf,
+ (NULL == inbytesleft) ? 0 : *inbytesleft,
+ (NULL == outbuf) ? 0 : *outbuf,
+ (NULL == outbytesleft) ? 0 : *outbytesleft));
/*
* If (NULL == inbuf || NULL == *inbuf) then this conversion is
@@ -317,10 +312,8 @@
if ((NULL == inbuf) || (NULL == *inbuf)) {
if (0 != hdr->op_reset_tbl.itm_ptr) {
ist->direc = ADDR(hdr->direc_init_tbl);
- retval = eval_op_tbl(ist,
- hdr->op_reset_tbl,
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, hdr->op_reset_tbl, inbuf,
+ inbytesleft, outbuf, outbytesleft);
if ((size_t)(-1) == retval) {
return (retval);
}
@@ -342,9 +335,8 @@
map = (char *)(map_hdr + 1);
if (1 == map_hdr->default_error) {
- retval = map_i_f(ist->direc,
- inbuf, inbytesleft,
- outbuf, outbytesleft, 0);
+ retval = map_i_f(ist->direc, inbuf, inbytesleft,
+ outbuf, outbytesleft, 0);
return (retval);
}
@@ -358,7 +350,7 @@
UPDATE_ARGS();
errno = E2BIG;
TRACE_MESSAGE('e', ("_icv_iconv: error=%d\n",
- errno));
+ errno));
return ((size_t)-1);
}
*(op++) = *(map + *(ip++));
@@ -369,24 +361,20 @@
UPDATE_ARGS();
return (0);
} else if (ITM_TBL_MAP_INDEX_FIXED == ist->direc->type) {
- retval = map_i_f(ist->direc,
- inbuf, inbytesleft,
- outbuf, outbytesleft, 0);
+ retval = map_i_f(ist->direc, inbuf, inbytesleft,
+ outbuf, outbytesleft, 0);
return (retval);
} else if (ITM_TBL_MAP_HASH == ist->direc->type) {
- retval = map_h_l(ist->direc,
- inbuf, inbytesleft,
- outbuf, outbytesleft, 0);
+ retval = map_h_l(ist->direc, inbuf, inbytesleft,
+ outbuf, outbytesleft, 0);
return (retval);
} else if (ITM_TBL_MAP_DENSE_ENC == ist->direc->type) {
- retval = map_d_e_l(ist->direc,
- inbuf, inbytesleft,
- outbuf, outbytesleft, 0);
+ retval = map_d_e_l(ist->direc, inbuf, inbytesleft,
+ outbuf, outbytesleft, 0);
return (retval);
} else if (ITM_TBL_MAP_LOOKUP == ist->direc->type) {
- retval = map_l_f(ist->direc,
- inbuf, inbytesleft,
- outbuf, outbytesleft, 0);
+ retval = map_l_f(ist->direc, inbuf, inbytesleft,
+ outbuf, outbytesleft, 0);
return (retval);
}
@@ -411,8 +399,7 @@
if (0 == ist->default_action.itm_ptr) {
errno = EILSEQ;
TRACE_MESSAGE('e',
- ("_icv_iconv:error=%d\n",
- errno));
+ ("_icv_iconv:error=%d\n", errno));
return ((size_t)(-1));
}
@@ -421,13 +408,12 @@
action = ist->default_action;
type = ((itm_tbl_hdr_t *)(ADDR(action)))->type;
TRACE_MESSAGE('E',
- ("escape seq (default action=%6p, type=%ld) "
- "excuting\n", action.itm_ptr, type));
+ ("escape seq (default action=%6p, "
+ "type=%ld) executing\n",
+ action.itm_ptr, type));
} else if (0 != direc->condition.itm_ptr) {
retval = eval_cond_tbl(ist, direc->condition,
- inbuf, inbytesleft,
- *outbytesleft,
- direc);
+ inbuf, inbytesleft, *outbytesleft, direc);
if ((size_t)(0) == retval) {
continue;
} else if ((size_t)(-1) == retval) {
@@ -443,13 +429,12 @@
}
TRACE_MESSAGE('a',
- ("inbytesleft=%ld; type=%ld:action=%p\n",
- *inbytesleft, type, action.itm_ptr));
+ ("inbytesleft=%ld; type=%ld:action=%p\n",
+ *inbytesleft, type, action.itm_ptr));
switch (ITM_TBL_MASK & type) {
case ITM_TBL_OP:
retval = eval_op_tbl(ist, action,
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ inbuf, inbytesleft, outbuf, outbytesleft);
if ((size_t)(-1) == retval) {
return (retval);
}
@@ -461,33 +446,29 @@
switch (type) {
case ITM_TBL_MAP_INDEX_FIXED_1_1:
case ITM_TBL_MAP_INDEX_FIXED:
- retval = map_i_f(
- ADDR(action),
- inbuf, inbytesleft,
- outbuf, outbytesleft,
- 1);
+ retval = map_i_f(ADDR(action),
+ inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
break;
case ITM_TBL_MAP_HASH:
retval = map_h_l(ADDR(action),
- inbuf, inbytesleft,
- outbuf, outbytesleft, 1);
+ inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
break;
case ITM_TBL_MAP_DENSE_ENC:
retval = map_d_e_l(ADDR(action),
- inbuf, inbytesleft,
- outbuf, outbytesleft, 1);
+ inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
break;
case ITM_TBL_MAP_LOOKUP:
- retval = map_l_f(
- ADDR(action),
- inbuf, inbytesleft,
- outbuf, outbytesleft,
- 1);
+ retval = map_l_f(ADDR(action),
+ inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
break;
default:
errno = ELIBBAD;
TRACE_MESSAGE('e',
- ("_icv_iconv:error=%d\n", errno));
+ ("_icv_iconv:error=%d\n", errno));
return ((size_t)(-1));
}
@@ -498,7 +479,7 @@
default: /* never */
errno = ELIBBAD;
TRACE_MESSAGE('e',
- ("_icv_iconv:error=%d\n", errno));
+ ("_icv_iconv:error=%d\n", errno));
return ((size_t)(-1));
}
break;
@@ -545,7 +526,7 @@
}
if (((j < map_hdr->start.itm_ptr) ||
- (map_hdr->end.itm_ptr < j)) &&
+ (map_hdr->end.itm_ptr < j)) &&
(0 < map_hdr->default_error)) {
errno = EILSEQ;
(*inbuf) = (void*) ((*inbuf) - map_hdr->source_len);
@@ -563,11 +544,10 @@
}
if ((j < map_hdr->start.itm_ptr) ||
- (map_hdr->end.itm_ptr < j)) {
+ (map_hdr->end.itm_ptr < j)) {
if (0 == map_hdr->default_error) {
p = (((unsigned char *)(map_hdr + 1)) +
- (map_hdr->result_len *
- (tbl_hdr->number)));
+ (map_hdr->result_len * (tbl_hdr->number)));
for (i = 0; i < map_hdr->result_len; i++) {
PUT(*(p + i));
}
@@ -580,27 +560,26 @@
} else {
char *map_error;
map_error = (((char *)(map_hdr + 1)) +
- (map_hdr->result_len *
- (tbl_hdr->number)) +
- (j - map_hdr->start.itm_ptr));
+ (map_hdr->result_len * (tbl_hdr->number)) +
+ (j - map_hdr->start.itm_ptr));
if (0 == map_hdr->default_error) {
map_error = (void *)
- (map_error + map_hdr->result_len);
+ (map_error + map_hdr->result_len);
}
if (((1 == map_hdr->default_error) ||
(0 < map_hdr->error_num)) &&
(0 != *(map_error))) {
errno = EILSEQ;
(*inbuf) = (void *)
- ((*inbuf) - map_hdr->source_len);
+ ((*inbuf) - map_hdr->source_len);
(*inbytesleft) += map_hdr->source_len;
TRACE_MESSAGE('e',
- ("map_i_f:error=%d\n", errno));
+ ("map_i_f:error=%d\n", errno));
return ((size_t)(-1));
}
p = (((unsigned char *)(map_hdr + 1)) +
- (map_hdr->result_len *
- (j - map_hdr->start.itm_ptr)));
+ (map_hdr->result_len *
+ (j - map_hdr->start.itm_ptr)));
for (i = 0; i < map_hdr->result_len; i++) {
PUT(*(p + i));
}
@@ -674,18 +653,18 @@
p = *inbuf;
} else if (0 == map_hdr->default_error) {
p = map + (pair_size * tbl_hdr->number) +
- map_hdr->source_len + 1;
+ map_hdr->source_len + 1;
} else if (0 < map_hdr->default_error) {
errno = EILSEQ;
TRACE_MESSAGE('e', ("map_l_f:error=%d\n",
- errno));
+ errno));
return ((size_t)(-1));
}
} else {
if (0 != (*p)) {
errno = EILSEQ;
TRACE_MESSAGE('e', ("map_l_f:error=%d\n",
- errno));
+ errno));
return ((size_t)(-1));
}
p++;
@@ -754,8 +733,8 @@
result = 1;
q = *inbuf;
- hash_value = hash((const char *)(q),
- source_len, map_hdr->hash_tbl_num);
+ hash_value = hash((const char *)(q), source_len,
+ map_hdr->hash_tbl_num);
p = map_hash + (pair_size * hash_value);
if (1 == *(map_error + hash_value)) {
for (i = 0, result = 0; i < source_len; i++) {
@@ -765,12 +744,10 @@
}
}
TRACE_MESSAGE('G',
- ("(h=%d): find pair without conflict\n",
- hash_value));
+ ("(h=%d): find pair without conflict\n",
+ hash_value));
} else if (0 == *(map_error + hash_value)) {
- TRACE_MESSAGE('G',
- ("(h=%d): No Pair\n",
- hash_value));
+ TRACE_MESSAGE('G', ("(h=%d): No Pair\n", hash_value));
result = -3;
} else /* if (0 < *(map_error + hash_value)) */ {
for (i = 0, result = 0; i < source_len; i++) {
@@ -801,11 +778,10 @@
} else if (0 < result) {
low = mid + 1;
} else { /* 0 == result */
- TRACE_MESSAGE('G',
- ("(h=%d): "
- "find data on out ot "
- "hashtable with CONFLICT\n",
- hash_value));
+ TRACE_MESSAGE('G', ("(h=%d): "
+ "find data on out of "
+ "hashtable with CONFLICT\n",
+ hash_value));
break;
}
}
@@ -817,21 +793,18 @@
} else if (0 == map_hdr->default_error) {
p = map_of + map_hdr->hash_of_size;
} else if (0 < map_hdr->default_error) {
- TRACE_MESSAGE('G',
- ("(h=%d): NO PAIR\n",
- hash_value));
+ TRACE_MESSAGE('G', ("(h=%d): NO PAIR\n",
+ hash_value));
errno = EILSEQ;
TRACE_MESSAGE('e',
- ("map_h_l:error=%d\n", errno));
+ ("map_h_l:error=%d\n", errno));
return ((size_t)(-1));
}
} else {
if (0 != (*p)) {
errno = EILSEQ;
- TRACE_MESSAGE('G',
- (" : error pair\n"));
- TRACE_MESSAGE('e', ("map_l_f:error\n",
- errno));
+ TRACE_MESSAGE('G', (" : error pair\n"));
+ TRACE_MESSAGE('e', ("map_l_f:error\n", errno));
return ((size_t)(-1));
}
p++;
@@ -877,8 +850,8 @@
TRACE_MESSAGE('i', ("map_d_e_l\n"));
map_hdr = (itm_map_dense_enc_hdr_t *)(tbl_hdr + 1);
- map_ptr = ((unsigned char *)(map_hdr + 1) +
- map_hdr->source_len + map_hdr->source_len);
+ map_ptr = ((unsigned char *)(map_hdr + 1) + map_hdr->source_len +
+ map_hdr->source_len);
map_error = (map_ptr + (tbl_hdr->number * map_hdr->result_len));
if (0 == map_hdr->default_error) {
map_error = (void *)(map_error + map_hdr->result_len);
@@ -894,7 +867,7 @@
}
j = hash_dense_encoding(*inbuf, map_hdr->source_len,
- byte_seq_min, byte_seq_max);
+ byte_seq_min, byte_seq_max);
if (((j < 0) || (tbl_hdr->number < j)) &&
(0 < map_hdr->default_error)) {
@@ -911,8 +884,8 @@
if ((j < 0) || (tbl_hdr->number < j)) {
if (0 == map_hdr->default_error) {
- p = (map_ptr +
- (tbl_hdr->number * map_hdr->result_len));
+ p = (map_ptr + (tbl_hdr->number *
+ map_hdr->result_len));
for (i = 0; i < map_hdr->result_len; i++) {
PUT(*(p + i));
}
@@ -928,7 +901,7 @@
if (0 != *(map_error + j)) {
errno = EILSEQ;
TRACE_MESSAGE('e',
- ("map_d_e_l:error=%d\n", errno));
+ ("map_d_e_l:error=%d\n", errno));
return ((size_t)(-1));
}
}
@@ -986,8 +959,8 @@
rtsh = (itm_range_hdr_t *)(rth + 1);
if (ileft < rtsh->len) {
errno = EINVAL;
- TRACE_MESSAGE('e',
- ("eval_cond_tbl:error=%d\n", errno));
+ TRACE_MESSAGE('e', ("eval_cond_tbl:error=%d\n",
+ errno));
retval = ((size_t)(-1));
goto eval_cond_return;
}
@@ -1010,8 +983,8 @@
}
if (0 == retval) {
TRACE_MESSAGE('b',
- ("out of between (%p) len= rtsh=%ld\n",
- *ip, rtsh->len));
+ ("out of between (%p) len= rtsh=%ld\n",
+ *ip, rtsh->len));
goto eval_cond_return;
}
break; /* continue */
@@ -1027,11 +1000,10 @@
if (NULL == ist->default_action.itm_ptr) {
ist->default_action = direc->action;
TRACE_MESSAGE('E',
- ("escape seq (default action=%6p, "
- "type=%ld) set\n",
- direc->action.itm_ptr,
- ((itm_tbl_hdr_t *)(ADDR(direc->action)))
- ->type));
+ ("escape seq (default action=%6p, "
+ "type=%ld) set\n",
+ direc->action.itm_ptr, ((itm_tbl_hdr_t *)
+ (ADDR(direc->action)))->type));
}
retval = 0;
if (*inbytesleft < eh->len_min) {
@@ -1045,14 +1017,14 @@
}
if (0 == memcmp(*inbuf, DADDR(d), d->size)) {
TRACE_MESSAGE('E',
- ("escape seq: discard=%ld chars\n",
- d->size));
- TRACE_MESSAGE('E', (
- "escape seq (default action=%6p, "
- "type=%ld) set\n",
- direc->action.itm_ptr,
- ((itm_tbl_hdr_t *)
- (ADDR(direc->action)))->type));
+ ("escape seq: discard=%ld chars\n",
+ d->size));
+ TRACE_MESSAGE('E',
+ ("escape seq (default "
+ "action=%6p, type=%ld) set\n",
+ direc->action.itm_ptr,
+ ((itm_tbl_hdr_t *)
+ (ADDR(direc->action)))->type));
ist->default_action = direc->action;
DISCARD(d->size);
retval = 2;
@@ -1065,7 +1037,7 @@
break; /* continue */
case ITM_COND_EXPR:
retval = eval_expr(ist, cond->operand.place,
- *inbytesleft, ip, outbytesleft);
+ *inbytesleft, ip, outbytesleft);
if (0 == retval) {
goto eval_cond_return;
} else {
@@ -1074,7 +1046,7 @@
break; /* continue */
default:
TRACE_MESSAGE('e', ("eval_cond_tbl:illegal cond=%d\n",
- cond->type));
+ cond->type));
retval = (size_t)-1;
goto eval_cond_return;
}
@@ -1121,9 +1093,8 @@
for (i = 0; i < op_hdr->number; i++, operation++,
op_place += (sizeof (itm_op_t))) {
TRACE_MESSAGE('O', ("eval_op_tbl: %ld %p\n", i, op_place));
- retval = eval_op(ist, op_place,
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op(ist, op_place, inbuf, inbytesleft,
+ outbuf, outbytesleft);
if (((long)(retval)) < 0) {
#if defined(OP_DEPTH_MAX)
ist->op_depth -= 1;
@@ -1169,10 +1140,12 @@
itm_size_t z;
unsigned char *p;
itm_expr_t *expr0;
+ itm_tbl_hdr_t *h;
+ itm_type_t t;
#define EVAL_EXPR(n) \
(expr0 = ADDR(operation->data.operand[(n)]), \
- (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \
+ (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \
expr0->data.itm_exnum : \
((expr0->type == ITM_EXPR_REG) ? \
REG(expr0->data.itm_exnum) : \
@@ -1191,12 +1164,12 @@
switch (operation->type) {
case ITM_OP_EXPR:
num = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
TRACE_MESSAGE('o', ("ITM_OP_EXPR: %ld\n", retval));
break;
case ITM_OP_ERROR:
num = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
errno = (int)num;
TRACE_MESSAGE('o', ("ITM_OP_ERROR: %ld\n", num));
retval = (size_t)(-1);
@@ -1214,7 +1187,7 @@
return ((size_t)(-1));
}
c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
PUT((uchar_t)c);
retval = *inbytesleft;
TRACE_MESSAGE('o', ("ITM_OP_OUT: %ld %ld\n", c, *inbytesleft));
@@ -1264,9 +1237,9 @@
return ((size_t)(-1));
}
z = (((0 <= expr->data.itm_exnum) &&
- (expr->data.itm_exnum < *inbytesleft)) ?
- (*((unsigned char *)(*inbuf + expr->data.itm_exnum))) :
- (((-1) == expr->data.itm_exnum) ? *inbytesleft : 0));
+ (expr->data.itm_exnum < *inbytesleft)) ?
+ (*((unsigned char *)(*inbuf + expr->data.itm_exnum))) :
+ (((-1) == expr->data.itm_exnum) ? *inbytesleft : 0));
PUT((uchar_t)z);
break;
case ITM_OP_DISCARD:
@@ -1274,12 +1247,11 @@
num = EVAL_EXPR(0);
#else /* !defined(EVAL_EXPR) */
num = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
#endif /* defined(EVAL_EXPR) */
TRACE_MESSAGE('o', ("ITM_OP_DISCARD: %ld\n", num));
#if defined(DISCARD)
- DISCARD((num <= *inbytesleft) ? ((ulong_t)num) :
- *inbytesleft);
+ DISCARD((num <= *inbytesleft) ? ((ulong_t)num) : *inbytesleft);
#else /* defined(DISCARD) */
for (num = ((num <= *inbytesleft) ? num : *inbytesleft);
0 < num; --num) {
@@ -1301,54 +1273,82 @@
break;
case ITM_OP_IF:
c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
TRACE_MESSAGE('o', ("ITM_OP_IF: %ld\n", c));
if (c) {
- retval = eval_op_tbl(ist,
- operation->data.operand[1],
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, operation->data.operand[1],
+ inbuf, inbytesleft, outbuf, outbytesleft);
}
break;
case ITM_OP_IF_ELSE:
c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
TRACE_MESSAGE('o', ("ITM_OP_IF_ELSE: %ld\n", c));
if (c) {
- retval = eval_op_tbl(ist,
- operation->data.operand[1],
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, operation->data.operand[1],
+ inbuf, inbytesleft, outbuf, outbytesleft);
} else {
- retval = eval_op_tbl(ist,
- operation->data.operand[2],
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, operation->data.operand[2],
+ inbuf, inbytesleft, outbuf, outbytesleft);
}
break;
case ITM_OP_DIRECTION:
TRACE_MESSAGE('o', ("ITM_OP_DIRECTION: %p\n",
- operation->data.operand[0].itm_ptr));
+ operation->data.operand[0].itm_ptr));
ist->direc = ADDR(operation->data.operand[0]);
return ((size_t)(-2));
case ITM_OP_MAP:
TRACE_MESSAGE('o', ("ITM_OP_MAP: %p\n",
- operation->data.operand[0].itm_ptr));
+ operation->data.operand[0].itm_ptr));
i = 0;
if (0 != operation->data.operand[1].itm_ptr) {
#if defined(EVAL_EXPR)
i = EVAL_EXPR(1);
#else /* !defined(EVAL_EXPR) */
i = eval_expr(ist, operation->data.operand[1],
- *inbytesleft, *inbuf, *outbytesleft);
+ *inbytesleft, *inbuf, *outbytesleft);
#endif /* defined(EVAL_EXPR) */
(*inbytesleft) -= i;
(*inbuf) += i;
}
- retval = map_i_f(ADDR(operation->data.operand[0]),
- inbuf, inbytesleft,
- outbuf, outbytesleft, 1);
+ /*
+ * Based on what is the maptype, we call the corresponding
+ * mapping function.
+ */
+ h = ADDR(operation->data.operand[0]);
+ t = h->type;
+ switch (t) {
+ case ITM_TBL_MAP_INDEX_FIXED:
+ case ITM_TBL_MAP_INDEX_FIXED_1_1:
+ retval = map_i_f(h, inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
+ break;
+ case ITM_TBL_MAP_HASH:
+ retval = map_h_l(h, inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
+ break;
+ case ITM_TBL_MAP_DENSE_ENC:
+ retval = map_d_e_l(h, inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
+ break;
+ case ITM_TBL_MAP_LOOKUP:
+ retval = map_l_f(h, inbuf, inbytesleft,
+ outbuf, outbytesleft, 1);
+ break;
+ default:
+ /*
+ * This should not be possible, but in case we
+ * have an incorrect maptype, don't fall back to
+ * map_i_f(). Instead, because it is an error, return
+ * an error. See CR 6622765.
+ */
+ errno = EBADF;
+ TRACE_MESSAGE('e', ("eval_op:error=%d\n", errno));
+ retval = (size_t)-1;
+ break;
+ }
+
if ((size_t)(-1) == retval) {
(*outbytesleft) += i;
(*outbuf) -= i;
@@ -1356,21 +1356,17 @@
break;
case ITM_OP_OPERATION:
TRACE_MESSAGE('o', ("ITM_OP_OPERATION: %p\n",
- operation->data.operand[0].itm_ptr));
- retval = eval_op_tbl(ist,
- operation->data.operand[0],
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ operation->data.operand[0].itm_ptr));
+ retval = eval_op_tbl(ist, operation->data.operand[0],
+ inbuf, inbytesleft, outbuf, outbytesleft);
break;
case ITM_OP_INIT:
TRACE_MESSAGE('o', ("ITM_OP_INIT: %p\n",
- ist->itm_hdr->op_init_tbl));
+ ist->itm_hdr->op_init_tbl));
if (0 != ist->itm_hdr->op_init_tbl.itm_ptr) {
- retval = eval_op_tbl(ist,
- ist->itm_hdr->op_init_tbl,
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, ist->itm_hdr->op_init_tbl,
+ inbuf, inbytesleft, outbuf, outbytesleft);
} else {
op_init_default(ist);
retval = (size_t)-2;
@@ -1378,12 +1374,10 @@
break;
case ITM_OP_RESET:
TRACE_MESSAGE('o', ("ITM_OP_RESET: %p\n",
- ist->itm_hdr->op_reset_tbl));
+ ist->itm_hdr->op_reset_tbl));
if (0 != ist->itm_hdr->op_reset_tbl.itm_ptr) {
- retval = eval_op_tbl(ist,
- ist->itm_hdr->op_reset_tbl,
- inbuf, inbytesleft,
- outbuf, outbytesleft);
+ retval = eval_op_tbl(ist, ist->itm_hdr->op_reset_tbl,
+ inbuf, inbytesleft, outbuf, outbytesleft);
} else {
op_reset_default(ist);
retval = (size_t)-2;
@@ -1396,25 +1390,25 @@
TRACE_MESSAGE('o', ("ITM_OP_RETURN\n"));
return (RETVALRET);
case ITM_OP_PRINTCHR:
- c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ c = eval_expr(ist, operation->data.operand[0], *inbytesleft,
+ *inbuf, *outbytesleft);
(void) fputc((uchar_t)c, stderr);
- TRACE_MESSAGE('o',
- ("ITM_OP_PRINTCHR: %ld %ld\n", c, *inbytesleft));
+ TRACE_MESSAGE('o', ("ITM_OP_PRINTCHR: %ld %ld\n",
+ c, *inbytesleft));
break;
case ITM_OP_PRINTHD:
- c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ c = eval_expr(ist, operation->data.operand[0], *inbytesleft,
+ *inbuf, *outbytesleft);
(void) fprintf(stderr, "%lx", c);
- TRACE_MESSAGE('o',
- ("ITM_OP_PRINTHD: %ld %ld\n", c, *inbytesleft));
+ TRACE_MESSAGE('o', ("ITM_OP_PRINTHD: %ld %ld\n",
+ c, *inbytesleft));
break;
case ITM_OP_PRINTINT:
- c = eval_expr(ist, operation->data.operand[0],
- *inbytesleft, *inbuf, *outbytesleft);
+ c = eval_expr(ist, operation->data.operand[0], *inbytesleft,
+ *inbuf, *outbytesleft);
(void) fprintf(stderr, "%ld", c);
- TRACE_MESSAGE('o',
- ("ITM_OP_PRINTINT: %ld %ld\n", c, *inbytesleft));
+ TRACE_MESSAGE('o', ("ITM_OP_PRINTINT: %ld %ld\n",
+ c, *inbytesleft));
break;
default: /* never */
errno = ELIBBAD;
@@ -1448,28 +1442,28 @@
itm_num_t num01;
#define EVAL_EXPR_E(n) (eval_expr(ist, expr->data.operand[(n)], \
- inbytesleft, inbuf, outbytesleft))
+ inbytesleft, inbuf, outbytesleft))
#define EVAL_EXPR_D(n) ((itm_num_t)(expr->data.operand[(n)].itm_ptr))
#define EVAL_EXPR_R(n) (REG((itm_num_t)(expr->data.operand[(n)].itm_ptr)))
#define EVAL_EXPR_INVD(n) \
((num0 ## n) = ((itm_num_t)(expr->data.operand[(n)].itm_ptr)), \
- ((num0 ## n) < 0) ? \
- (((-1) == (num0 ## n)) ? inbytesleft : 0) : \
- (((num0 ## n) < inbytesleft) ? \
- (*(unsigned char *)(inbuf + (num0 ## n))) : 0))
+ ((num0 ## n) < 0) ? \
+ (((-1) == (num0 ## n)) ? inbytesleft : 0) : \
+ (((num0 ## n) < inbytesleft) ? \
+ (*(unsigned char *)(inbuf + (num0 ## n))) : 0))
#define EVAL_EXPR(n) \
(expr0 = ADDR(expr->data.operand[(n)]), \
- (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \
- expr0->data.itm_exnum : \
- ((expr0->type == ITM_EXPR_REG) ? \
- REG(expr0->data.itm_exnum) : \
- ((expr0->type == ITM_EXPR_IN_VECTOR_D) ? \
- ((expr0->data.itm_exnum < 0) ? \
- (((-1) == expr0->data.itm_exnum) ? inbytesleft : 0) : \
- ((expr0->data.itm_exnum < inbytesleft) ? \
- (*(uchar_t *)(inbuf + expr0->data.itm_exnum)) : 0)) : \
- eval_expr(ist, expr->data.operand[(n)], \
- inbytesleft, inbuf, outbytesleft)))))
+ (itm_num_t)((expr0->type == ITM_EXPR_INT) ? \
+ expr0->data.itm_exnum : \
+ ((expr0->type == ITM_EXPR_REG) ? \
+ REG(expr0->data.itm_exnum) : \
+ ((expr0->type == ITM_EXPR_IN_VECTOR_D) ? \
+ ((expr0->data.itm_exnum < 0) ? \
+ (((-1) == expr0->data.itm_exnum) ? inbytesleft : 0) : \
+ ((expr0->data.itm_exnum < inbytesleft) ? \
+ (*(uchar_t *)(inbuf + expr0->data.itm_exnum)) : 0)) : \
+ eval_expr(ist, expr->data.operand[(n)], \
+ inbytesleft, inbuf, outbytesleft)))))
#define EVAL_OP_BIN_PROTO(op, name, name0, name1) \
case ITM_EXPR_##name##_##name0##_##name1: \
@@ -1697,7 +1691,7 @@
num = EVAL_EXPR(1);
if (expr->data.operand[0].itm_ptr < ist->itm_hdr->reg_num) {
return (*(ist->regs + expr->data.operand[0].itm_ptr)
- = num);
+ = num);
} else {
return (0);
}
@@ -1819,8 +1813,7 @@
(hdr->version[2] != ITM_VER_2) ||
(hdr->version[3] != ITM_VER_3) ||
(((size_t)(hdr->itm_size.itm_ptr)) != st.st_size)) {
- itm_ref_free(-1, ref, ref->name,
- ref->hdr, ref->len);
+ itm_ref_free(-1, ref, ref->name, ref->hdr, ref->len);
errno = ELIBBAD;
TRACE_MESSAGE('e', ("itm_ref_inc:error=%d\n", errno));
return (NULL);
@@ -1860,7 +1853,7 @@
{
if (0 < ist->itm_hdr->reg_num) {
(void) memset(ist->regs, 0,
- (sizeof (itm_num_t)) * ist->itm_hdr->reg_num);
+ (sizeof (itm_num_t)) * ist->itm_hdr->reg_num);
}
}
--- a/usr/src/uts/common/io/ldterm.c Wed Jul 02 16:29:05 2008 -0700
+++ b/usr/src/uts/common/io/ldterm.c Wed Jul 02 17:06:30 2008 -0700
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -521,160 +520,14 @@
};
/*
- * The byte length of a UTF-8 character can be decided by looking at the
- * first byte:
- *
- * Binary enc Code range Byte length
- *
- * 0xxx xxxx 0x00 ~ 0x7F 1
- * 110x xxxx 0xC0 ~ 0xDF 2
- * 1110 xxxx 0xE0 ~ 0xEF 3
- * 1111 0xxx 0xF0 ~ 0xF7 4
- * 1111 10xx 0xF8 ~ 0xFB 5
- * 1111 110x 0xFC ~ 0xFD 6
- *
- * Invalid leading bytes, esp., 0x80 ~ 0xBF, 0xFE, and, 0xFF, will be treated
- * as a single byte, single display column character.
- */
-static const uchar_t utf8_byte_length_tbl[0x100] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-
-/* C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF */
- 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-
-/* D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF */
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-
-/* E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF */
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
-
-/* F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF */
- 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-/*
- * Following is a vector of bit-masks to get used bits in the first byte of
- * a UTF-8 character. Index is remaining bytes of the UTF-8 character.
- */
-static const char masks_tbl[6] = { 0x00, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
-
-/*
- * The following two vectors are to provide valid minimum and
- * maximum values for the 2'nd byte of a multibyte UTF-8 character for
- * better illegal sequence checking as defined in the "UTF-8 Corrigendum" of
- * the Unicode 3.1 standard. The index value must be the value of
- * the first byte of an UTF-8 character.
+ * The following tables are from either u8_textprep.c or uconv.c at
+ * usr/src/common/unicode/. The tables are used to figure out corresponding
+ * UTF-8 character byte lengths and also the validity of given character bytes.
*/
-static const uchar_t valid_min_2nd_byte[0x100] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
-
-/* C0 C1 C2 C3 C4 C5 C6 C7 */
- 0, 0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* C8 C9 CA CB CC CD CE CF */
- 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* D0 D1 D2 D3 D4 D5 D6 D7 */
- 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* D8 D9 DA DB DC DD DE DF */
- 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* E0 E1 E2 E3 E4 E5 E6 E7 */
- 0xa0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* E8 E9 EA EB EC ED EE EF */
- 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
-
-/* F0 F1 F2 F3 F4 F5 F6 F7 */
- 0x90, 0x80, 0x80, 0x80, 0x80, 0, 0, 0,
-
- 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-static const uchar_t valid_max_2nd_byte[0x100] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
-
-/* C0 C1 C2 C3 C4 C5 C6 C7 */
- 0, 0, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* C8 C9 CA CB CC CD CE CF */
- 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* D0 D1 D2 D3 D4 D5 D6 D7 */
- 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* D8 D9 DA DB DC DD DE DF */
- 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* E0 E1 E2 E3 E4 E5 E6 E7 */
- 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* E8 E9 EA EB EC ED EE EF */
- 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
-
-/* F0 F1 F2 F3 F4 F5 F6 F7 */
- 0xbf, 0xbf, 0xbf, 0xbf, 0x8f, 0, 0, 0,
-
- 0, 0, 0, 0, 0, 0, 0, 0,
-};
+extern const int8_t u8_number_of_bytes[];
+extern const uchar_t u8_masks_tbl[];
+extern const uint8_t u8_valid_min_2nd_byte[];
+extern const uint8_t u8_valid_max_2nd_byte[];
/*
* Unicode character width definition tables from uwidth.c:
@@ -826,7 +679,7 @@
}
tp = (ldtermstd_state_t *)kmem_zalloc(sizeof (ldtermstd_state_t),
- KM_SLEEP);
+ KM_SLEEP);
/*
* Get termios defaults. These are stored as
@@ -1192,7 +1045,7 @@
freemsg(mp);
if ((mp = allocb(3, BPRI_HI)) == NULL) {
cmn_err(CE_WARN,
- "ldtermrput: no blocks");
+ "ldtermrput: no blocks");
return;
}
mp->b_datap->db_type = M_DATA;
@@ -1207,7 +1060,7 @@
freemsg(mp);
if ((mp = allocb(1, BPRI_HI)) == NULL) {
cmn_err(CE_WARN,
- "ldtermrput: no blocks");
+ "ldtermrput: no blocks");
return;
}
mp->b_datap->db_type = M_DATA;
@@ -1424,7 +1277,8 @@
tp->t_modes.c_iflag &
IXANY)) {
tp->t_state &=
- ~(TS_TTSTOP|TS_OFBLOCK);
+ ~(TS_TTSTOP |
+ TS_OFBLOCK);
(void) putnextctl(wrq,
M_START);
}
@@ -1568,7 +1422,7 @@
*/
if (q->q_first != NULL || !bcanputnext(q, mp->b_band) ||
- (tp->t_state & TS_RESCAN))
+ (tp->t_state & TS_RESCAN))
(void) putq(q, mp);
else
(void) ldtermrmsg(q, mp);
@@ -1831,8 +1685,7 @@
break;
}
} else
- bpt = ldterm_dononcanon(bp, bpt,
- ebsize, q, tp);
+ bpt = ldterm_dononcanon(bp, bpt, ebsize, q, tp);
if (bpt == NULL) {
cmn_err(CE_WARN,
"ldtermrsrv: out of blocks");
@@ -1894,7 +1747,7 @@
if ((tp->t_modes.c_lflag & IEXTEN) && c == tp->t_modes.c_cc[VLNEXT]) {
if (tp->t_modes.c_lflag & ECHO)
ldterm_outstring((unsigned char *)"^\b", 2, wrq,
- ebsize, tp);
+ ebsize, tp);
tp->t_state |= TS_SLNCH;
goto out;
}
@@ -2107,20 +1960,18 @@
} else { /* is the first byte of a multi-byte, or is ASCII */
if (ISASCII(c)) {
*tp->t_eucp++ =
- tp->t_csmethods.ldterm_dispwidth(c,
- (void *)tp,
- tp->t_modes.c_lflag & ECHOCTL);
+ tp->t_csmethods.ldterm_dispwidth(c,
+ (void *)tp, tp->t_modes.c_lflag & ECHOCTL);
tp->t_codeset = 0;
} else {
*tp->t_eucp++ =
- tp->t_csmethods.ldterm_dispwidth(c,
- (void *)tp,
- tp->t_modes.c_lflag & ECHOCTL);
+ tp->t_csmethods.ldterm_dispwidth(c,
+ (void *)tp, tp->t_modes.c_lflag & ECHOCTL);
tp->t_eucleft =
- tp->t_csmethods.ldterm_memwidth(c,
- (void *)tp) - 1;
+ tp->t_csmethods.ldterm_memwidth(c,
+ (void *)tp) - 1;
tp->t_codeset = ldterm_codeset(
- tp->t_csdata.codeset_type, c);
+ tp->t_csdata.codeset_type, c);
}
}
}
@@ -2278,7 +2129,7 @@
if ((tp->t_modes.c_lflag & XCASE) &&
omaptab[c])
ldterm_outstring(RUBOUT1, 3, q, ebsize,
- tp);
+ tp);
ldterm_outstring(RUBOUT1, 3, q, ebsize, tp);
break;
@@ -2290,7 +2141,7 @@
if ((tp->t_modes.c_lflag & ECHOCTL) &&
(tp->t_modes.c_lflag & IEXTEN))
ldterm_outstring(RUBOUT2, 6, q, ebsize,
- tp);
+ tp);
break;
case TAB:
@@ -2313,7 +2164,7 @@
}
}
} else if ((tp->t_modes.c_lflag & ECHOPRT) &&
- (tp->t_modes.c_lflag & IEXTEN)) {
+ (tp->t_modes.c_lflag & IEXTEN)) {
/*
* "Printing rubout"; echo it between \ and /.
*/
@@ -2389,14 +2240,14 @@
*/
u8[0] = *startp;
for (i = 1; (i < LDTERM_CS_MAX_BYTE_LENGTH) &&
- (*(readp + i) == 0);
- i++) {
+ (*(readp + i) == 0); i++) {
startp++;
if (startp >= bp->b_datap->db_lim) {
if (bp->b_cont) {
bp = bp->b_cont;
startp =
- bp->b_datap->db_base;
+ bp->b_datap->
+ db_base;
} else {
*readp = 1;
col++;
@@ -2705,7 +2556,7 @@
if ((*ip == 1 || *ip == 2 ||
*ip > UNKNOWN_WIDTH) && ISASCII(c)) {
ldterm_rubout((unsigned char) c, q,
- ebsize, tp);
+ ebsize, tp);
len = 0;
} else if (*ip) {
if (*ip == UNKNOWN_WIDTH) {
@@ -2716,7 +2567,7 @@
u8_2[i] =
u8[len-i-1];
*ip = ldterm_utf8_width(
- u8_2, len);
+ u8_2, len);
} else {
*ip = 1;
}
@@ -2827,7 +2678,7 @@
if (tp->t_modes.c_lflag & ECHO)
ldterm_outstring(
(unsigned char *)"^\b",
- 2, wrq, ebsize, tp);
+ 2, wrq, ebsize, tp);
tp->t_state |= TS_SLNCH;
continue; /* and ignore it */
}
@@ -2850,8 +2701,7 @@
* set.
*/
if (c == '\n')
- ldterm_outchar('\n',
- wrq, 1, tp);
+ ldterm_outchar('\n', wrq, 1, tp);
}
}
bp->b_wptr = wptr;
@@ -2890,7 +2740,7 @@
roomleft = IBSIZE;
}
DEBUG5(("roomleft=%d, bytes_in_bp=%d, tp->t_rd_request=%d\n",
- roomleft, bytes_in_bp, tp->t_rd_request));
+ roomleft, bytes_in_bp, tp->t_rd_request));
/*
* if there is a read pending before this data got
* here move bytes according to the minimum of room
@@ -3019,8 +2869,8 @@
return (i + 1);
/* echo only special control character and the Bell */
} else if ((c > 037 && c != 0177) || c == '\t' || c == '\n' ||
- c == '\r' || c == '\b' || c == 007 ||
- c == tp->t_modes.c_cc[VKILL]) {
+ c == '\r' || c == '\b' || c == 007 ||
+ c == tp->t_modes.c_cc[VKILL]) {
ldterm_outchar(c, q, ebsize, tp);
return (i + 1);
}
@@ -3209,11 +3059,12 @@
* eventually.
*/
if (*mp->b_rptr & FLUSHW) {
- if ((tp->t_state & TS_ISPTSTTY) &&
- (*mp->b_rptr & FLUSHBAND))
- flushband(q, *(mp->b_rptr + 1), FLUSHDATA);
- else
- flushq(q, FLUSHDATA);
+ if ((tp->t_state & TS_ISPTSTTY) &&
+ (*mp->b_rptr & FLUSHBAND))
+ flushband(q, *(mp->b_rptr + 1),
+ FLUSHDATA);
+ else
+ flushq(q, FLUSHDATA);
}
putnext(q, mp);
@@ -3465,7 +3316,7 @@
short flag = mp->b_flag;
residmp = ldterm_output_msg(q, mp, &omp,
- tp, OBSIZE, 0);
+ tp, OBSIZE, 0);
if ((mp = omp) == NULL)
break;
mp->b_band |= band;
@@ -3612,14 +3463,19 @@
if ((tp->t_state & TS_MEUC) &&
tp->t_eucign == 0 && NOTASCII(c)) {
tp->t_eucign =
- tp->t_csmethods.ldterm_memwidth(
- c, (void *)tp);
+ tp->t_csmethods.ldterm_memwidth(
+ c, (void *)tp);
tp->t_scratch_len = tp->t_eucign;
if (tp->t_csdata.codeset_type !=
LDTERM_CS_TYPE_UTF8) {
tp->t_col +=
-tp->t_csmethods.ldterm_dispwidth(c, (void *)tp, tp->t_modes.c_lflag & ECHOCTL);
+ tp->
+ t_csmethods.
+ ldterm_dispwidth(c,
+ (void *)tp,
+ tp->t_modes.c_lflag &
+ ECHOCTL);
}
}
@@ -3708,9 +3564,9 @@
bytes_to_move = bytes_left;
if (tp->t_state & TS_MEUC) {
bytes_moved = movtuc(bytes_to_move,
- ibp->b_rptr, obp->b_wptr,
- (tp->t_modes.c_oflag & OLCUC ?
- elcuctab : enotrantab));
+ ibp->b_rptr, obp->b_wptr,
+ (tp->t_modes.c_oflag & OLCUC ?
+ elcuctab : enotrantab));
} else {
bytes_moved = movtuc(bytes_to_move,
ibp->b_rptr, obp->b_wptr,
@@ -3754,15 +3610,15 @@
if ((tp->t_state & TS_MEUC) && tp->t_eucign == 0 &&
NOTASCII(c)) {
tp->t_eucign = tp->t_csmethods.ldterm_memwidth(
- c, (void *)tp);
+ c, (void *)tp);
tp->t_scratch_len = tp->t_eucign;
if (tp->t_csdata.codeset_type !=
LDTERM_CS_TYPE_UTF8) {
tp->t_col +=
tp->t_csmethods.ldterm_dispwidth(c,
- (void *)tp,
- tp->t_modes.c_lflag & ECHOCTL);
+ (void *)tp,
+ tp->t_modes.c_lflag & ECHOCTL);
}
}
@@ -4077,7 +3933,7 @@
bp->b_datap->db_type =
M_DELAY;
*bp->b_wptr++ =
- (uchar_t)count;
+ (uchar_t)count;
putnext(q, bp);
}
}
@@ -4311,17 +4167,13 @@
oldmodes = tp->t_amodes;
tp->t_amodes.c_iflag =
- (tp->t_amodes.c_iflag & 0xffff0000 |
- cb->c_iflag);
+ (tp->t_amodes.c_iflag & 0xffff0000 | cb->c_iflag);
tp->t_amodes.c_oflag =
- (tp->t_amodes.c_oflag & 0xffff0000 |
- cb->c_oflag);
+ (tp->t_amodes.c_oflag & 0xffff0000 | cb->c_oflag);
tp->t_amodes.c_cflag =
- (tp->t_amodes.c_cflag & 0xffff0000 |
- cb->c_cflag);
+ (tp->t_amodes.c_cflag & 0xffff0000 | cb->c_cflag);
tp->t_amodes.c_lflag =
- (tp->t_amodes.c_lflag & 0xffff0000 |
- cb->c_lflag);
+ (tp->t_amodes.c_lflag & 0xffff0000 | cb->c_lflag);
bcopy(cb->c_cc, tp->t_modes.c_cc, NCC);
/* TCGETS returns amodes, so update that too */
@@ -4543,11 +4395,14 @@
* this line!
*/
if (tp->t_msglen) {
- tp->t_eucp = tp->t_eucp_mp->b_rptr;
+ tp->t_eucp =
+ tp->t_eucp_mp->b_rptr;
for (i = tp->t_msglen; i; i--)
*tp->t_eucp++ = 1;
- } else
- tp->t_eucp = tp->t_eucp_mp->b_rptr;
+ } else {
+ tp->t_eucp =
+ tp->t_eucp_mp->b_rptr;
+ }
}
/* doing multi-byte handling */
tp->t_state |= TS_MEUC;
@@ -4566,19 +4421,19 @@
*/
bzero(&tp->t_csdata.eucpc_data,
(sizeof (ldterm_eucpc_data_t) *
- LDTERM_CS_MAX_CODESETS));
+ LDTERM_CS_MAX_CODESETS));
tp->t_csdata.eucpc_data[0].byte_length =
- tp->eucwioc.eucw[1];
+ tp->eucwioc.eucw[1];
tp->t_csdata.eucpc_data[0].screen_width =
- tp->eucwioc.scrw[1];
+ tp->eucwioc.scrw[1];
tp->t_csdata.eucpc_data[1].byte_length =
- tp->eucwioc.eucw[2];
+ tp->eucwioc.eucw[2];
tp->t_csdata.eucpc_data[1].screen_width =
- tp->eucwioc.scrw[2];
+ tp->eucwioc.scrw[2];
tp->t_csdata.eucpc_data[2].byte_length =
- tp->eucwioc.eucw[3];
+ tp->eucwioc.eucw[3];
tp->t_csdata.eucpc_data[2].screen_width =
- tp->eucwioc.scrw[3];
+ tp->eucwioc.scrw[3];
tp->t_csdata.version = LDTERM_DATA_VERSION;
tp->t_csdata.codeset_type = LDTERM_CS_TYPE_EUC;
/*
@@ -4587,7 +4442,7 @@
* the maximum possible.
*/
tp->t_csdata.csinfo_num =
- LDTERM_CS_TYPE_EUC_MAX_SUBCS;
+ LDTERM_CS_TYPE_EUC_MAX_SUBCS;
if (tp->t_csdata.locale_name != (char *)NULL) {
kmem_free(tp->t_csdata.locale_name,
strlen(tp->t_csdata.locale_name) + 1);
@@ -4664,10 +4519,10 @@
}
if ((csdp->codeset_type == LDTERM_CS_TYPE_EUC &&
- csdp->csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) ||
+ csdp->csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) ||
(csdp->codeset_type == LDTERM_CS_TYPE_PCCS &&
- (csdp->csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS ||
- csdp->csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) {
+ (csdp->csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS ||
+ csdp->csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) {
miocnak(q, mp, 0, ERANGE);
return;
}
@@ -4750,7 +4605,7 @@
if (!(tp->t_eucp_mp = allocb(CANBSIZ,
BPRI_HI))) {
cmn_err(CE_WARN,
- "Can't allocate eucp_mp");
+ "Can't allocate eucp_mp");
miocnak(q, mp, 0, ENOSR);
return;
}
@@ -4781,8 +4636,8 @@
tp->t_csdata.codeset_type = csdp->codeset_type;
tp->t_csdata.csinfo_num = csdp->csinfo_num;
bcopy(csdp->eucpc_data, tp->t_csdata.eucpc_data,
- sizeof (ldterm_eucpc_data_t) *
- LDTERM_CS_MAX_CODESETS);
+ sizeof (ldterm_eucpc_data_t) *
+ LDTERM_CS_MAX_CODESETS);
tp->t_csmethods = cs_methods[csdp->codeset_type];
if (csdp->codeset_type == LDTERM_CS_TYPE_EUC) {
@@ -4790,19 +4645,19 @@
tp->eucwioc.scrw[0] = 1;
tp->eucwioc.eucw[1] =
- csdp->eucpc_data[0].byte_length;
+ csdp->eucpc_data[0].byte_length;
tp->eucwioc.scrw[1] =
- csdp->eucpc_data[0].screen_width;
+ csdp->eucpc_data[0].screen_width;
tp->eucwioc.eucw[2] =
- csdp->eucpc_data[1].byte_length + 1;
+ csdp->eucpc_data[1].byte_length + 1;
tp->eucwioc.scrw[2] =
- csdp->eucpc_data[1].screen_width;
+ csdp->eucpc_data[1].screen_width;
tp->eucwioc.eucw[3] =
- csdp->eucpc_data[2].byte_length + 1;
+ csdp->eucpc_data[2].byte_length + 1;
tp->eucwioc.scrw[3] =
- csdp->eucpc_data[2].screen_width;
+ csdp->eucpc_data[2].screen_width;
} else {
/*
* We are not going to use this data
@@ -4844,7 +4699,7 @@
}
if (locale_name_sz > 1) {
tp->t_csdata.locale_name = (char *)kmem_alloc(
- locale_name_sz, KM_SLEEP);
+ locale_name_sz, KM_SLEEP);
(void) strcpy(tp->t_csdata.locale_name,
csdp->locale_name);
} else {
@@ -4873,12 +4728,12 @@
csdp->pad = tp->t_csdata.pad;
if (tp->t_csdata.locale_name) {
(void) strcpy(csdp->locale_name,
- tp->t_csdata.locale_name);
+ tp->t_csdata.locale_name);
} else {
csdp->locale_name[0] = '\0';
}
bcopy(tp->t_csdata.eucpc_data, csdp->eucpc_data,
- sizeof (ldterm_eucpc_data_t) * LDTERM_CS_MAX_CODESETS);
+ sizeof (ldterm_eucpc_data_t) * LDTERM_CS_MAX_CODESETS);
/*
* If the codeset is an EUC codeset and if it has 2nd and/or
* 3rd supplementary codesets, we subtract one from each
@@ -4993,7 +4848,7 @@
* stream head eventually.
*/
struct termios *cb =
- (struct termios *)mp->b_cont->b_rptr;
+ (struct termios *)mp->b_cont->b_rptr;
/*
* cflag has cflags sent upstream by the
@@ -5015,7 +4870,7 @@
* eventually.
*/
struct termio *cb =
- (struct termio *)mp->b_cont->b_rptr;
+ (struct termio *)mp->b_cont->b_rptr;
cb->c_iflag = tp->t_amodes.c_iflag; /* all except the */
cb->c_oflag = tp->t_amodes.c_oflag; /* cb->c_cflag */
@@ -5043,8 +4898,7 @@
{
ASSERT(q);
if (tp->t_vtid != 0) {
- DEBUG4(("vmin_satisfied: cancelled timer id %d\n",
- tp->t_vtid));
+ DEBUG4(("vmin_satisfied: cancelled timer id %d\n", tp->t_vtid));
(void) quntimeout(q, tp->t_vtid);
tp->t_vtid = 0;
}
@@ -5088,11 +4942,11 @@
if (V_MIN && V_TIME) {
/* EMPTY */
DEBUG4(("vmin_settimer: timer restarted, old tid=%d\n",
- tp->t_vtid));
+ tp->t_vtid));
} else {
/* EMPTY */
DEBUG4(("vmin_settimer: tid = %d was still active!\n",
- tp->t_vtid));
+ tp->t_vtid));
}
(void) quntimeout(q, tp->t_vtid);
tp->t_vtid = 0;
@@ -5499,12 +5353,22 @@
__ldterm_memwidth_utf8(uchar_t c, void *p)
{
ldtermstd_state_t *tp = (ldtermstd_state_t *)p;
-
- /* This is to silence the lint. */
+ int len;
+
+ /*
+ * If the codeset type doesn't match, we treat them as
+ * an illegal character and return 1.
+ */
if (tp->t_csdata.codeset_type != LDTERM_CS_TYPE_UTF8)
return (1);
- return ((int)utf8_byte_length_tbl[c]);
+ len = u8_number_of_bytes[c];
+
+ /*
+ * If this is a start of an illegal character, we treat
+ * such as an 1 byte character and screen out.
+ */
+ return ((len <= 0) ? 1 : len);
}
static uchar_t
@@ -5517,29 +5381,29 @@
if (length == 0)
return ('\0');
- j = utf8_byte_length_tbl[u8[0]] - 1;
+ j = u8_number_of_bytes[u8[0]] - 1;
/*
* If the UTF-8 character is out of UTF-16 code range, or,
* if it is either an ASCII character or an invalid leading byte for
* a UTF-8 character, return 1.
*/
- if (length > 4 || j == 0)
+ if (length > 4 || j <= 0)
return ('\1');
- intcode = u8[0] & masks_tbl[j];
+ intcode = u8[0] & u8_masks_tbl[j];
for (i = 1; j > 0; j--, i++) {
/*
- * The following additional checking is needed to
- * conform to the "UTF-8 Corrigendum" of the Unicode 3.1
- * standard.
+ * The following additional checking is needed to conform to
+ * the "UTF-8 Corrigendum" introduced at the Unicode 3.1 and
+ * then updated one more time at the Unicode 3.2.
*/
if (i == 1) {
- if (u8[i] < valid_min_2nd_byte[u8[0]] ||
- u8[i] > valid_max_2nd_byte[u8[0]])
+ if (u8[i] < u8_valid_min_2nd_byte[u8[0]] ||
+ u8[i] > u8_valid_max_2nd_byte[u8[0]])
return ('\1');
} else if (u8[i] < (uchar_t)LDTERM_CS_TYPE_UTF8_MIN_BYTE ||
- u8[i] > (uchar_t)LDTERM_CS_TYPE_UTF8_MAX_BYTE)
+ u8[i] > (uchar_t)LDTERM_CS_TYPE_UTF8_MAX_BYTE)
return ('\1');
/*
@@ -5552,22 +5416,27 @@
* six bits from the new byte.
*/
intcode = (intcode << LDTERM_CS_TYPE_UTF8_SHIFT_BITS) |
- (u8[i] & LDTERM_CS_TYPE_UTF8_BIT_MASK);
+ (u8[i] & LDTERM_CS_TYPE_UTF8_BIT_MASK);
}
+ i = 0;
if (intcode <= LDTERM_CS_TYPE_UTF8_MAX_P00) {
/* Basic Multilingual Plane. */
i = intcode / 4;
j = intcode % 4;
switch (j) {
case 0:
- return (ldterm_ucode[0][i].u0);
+ i = ldterm_ucode[0][i].u0;
+ break;
case 1:
- return (ldterm_ucode[0][i].u1);
+ i = ldterm_ucode[0][i].u1;
+ break;
case 2:
- return (ldterm_ucode[0][i].u2);
+ i = ldterm_ucode[0][i].u2;
+ break;
case 3:
- return (ldterm_ucode[0][i].u3);
+ i = ldterm_ucode[0][i].u3;
+ break;
}
} else if (intcode <= LDTERM_CS_TYPE_UTF8_MAX_P01) {
/* Secondary Multilingual Plane. */
@@ -5576,35 +5445,55 @@
j = intcode % 4;
switch (j) {
case 0:
- return (ldterm_ucode[1][i].u0);
+ i = ldterm_ucode[1][i].u0;
+ break;
case 1:
- return (ldterm_ucode[1][i].u1);
+ i = ldterm_ucode[1][i].u1;
+ break;
case 2:
- return (ldterm_ucode[1][i].u2);
+ i = ldterm_ucode[1][i].u2;
+ break;
case 3:
- return (ldterm_ucode[1][i].u3);
+ i = ldterm_ucode[1][i].u3;
+ break;
}
} else if ((intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKEXTB &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB) ||
- (intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP) ||
- (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P15 &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_P15) ||
- (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P16 &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_P16)) {
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKEXTB) ||
+ (intcode >= LDTERM_CS_TYPE_UTF8_MIN_CJKCOMP &&
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_CJKCOMP) ||
+ (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P15 &&
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_P15) ||
+ (intcode >= LDTERM_CS_TYPE_UTF8_MIN_P16 &&
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_P16)) {
/*
* Supplementary Plane for CJK Ideographs and
* Private Use Planes.
*/
return ('\2');
} else if ((intcode >= LDTERM_CS_TYPE_UTF8_MIN_P14 &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_P14) ||
- (intcode >= LDTERM_CS_TYPE_UTF8_MIN_VARSEL &&
- intcode <= LDTERM_CS_TYPE_UTF8_MAX_VARSEL)) {
- /* Special Purpose Plane. */
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_P14) ||
+ (intcode >= LDTERM_CS_TYPE_UTF8_MIN_VARSEL &&
+ intcode <= LDTERM_CS_TYPE_UTF8_MAX_VARSEL)) {
+ /*
+ * Some Special Purpose Plane characters:
+ * These are like control characters and not printable.
+ */
return ('\0');
}
- /* Anything else including invalid characters, we return 1. */
- return ('\1');
+ /*
+ * We return the display width of 1 for all character code points
+ * that we didn't catch from the above logic and also for combining
+ * and conjoining characters with width value of zero.
+ *
+ * In particular, the reason why we are returning 1 for combining
+ * and conjoining characters is because the GUI-based terminal
+ * emulators are not yet capable of properly handling such characters
+ * and in most of the cases, they just treat such characters as if
+ * they occupy a display cell. If the terminal emulators are capable of
+ * handling the characters correctly, then, this logic of returning
+ * 1 should be revisited and changed. See CR 6660526 for more
+ * details on this.
+ */
+ return ((i == 0) ? '\1' : (uchar_t)i);
}