4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
25 * Copyright 2015 PALO, Richard.
40 static size_t map_table_resultlen(itmc_map_t
*);
41 static int data_pair_compare(itmc_data_pair_t
**, itmc_data_pair_t
**);
42 static long data_to_long(itm_data_t
*);
44 static itm_tbl_hdr_t
*map_table_indexed_fixed(itmc_data_pair_t
**,
45 itm_size_t
, itm_data_t
*, long, itm_num_t
);
46 static itm_tbl_hdr_t
*map_table_dense_encoding(itmc_data_pair_t
**,
47 itm_size_t
, itm_data_t
*, unsigned long,
48 unsigned char *, unsigned char *, long,
50 static itm_tbl_hdr_t
*map_table_lookup_fixed(itmc_data_pair_t
**,
51 itm_size_t
, itm_data_t
*, long, itm_size_t
);
52 static itm_tbl_hdr_t
*map_table_hash(itmc_data_pair_t
**, itm_size_t
,
53 itm_data_t
*, long, long, itm_size_t
,
55 static itm_tbl_hdr_t
*map_table_lookup_var();
56 static void put_dense_encoding_default(char *, unsigned char *,
57 unsigned char *, unsigned char *, long, long, long);
58 static size_t map_table_resultlen(itmc_map_t
*);
59 static void map_range_adjust_byte_seq(unsigned char *,
60 unsigned char *, long, itmc_data_pair_t
*);
61 static void map_range_make_result(char *, itm_size_t
, itm_size_t
,
63 static size_t map_table_num_range(itmc_data_pair_t
*);
64 static itmc_map_type_t
check_map_type(itmc_map_attr_t
*);
67 static itmc_name_t
*name_lookup(itm_data_t
*, itm_type_t
);
68 static itmc_name_t
*name_refer(itm_data_t
*, itm_type_t
, itmc_ref_t
*);
69 static itmc_name_t
*name_register(itm_data_t
*, itm_type_t
, itmc_ref_t
*);
70 static void op_hirarchy(itm_tbl_hdr_t
*, itmc_obj_t
*);
71 static obj_array_t
obj_list_to_array(itm_size_t
, itmc_obj_t
*, itm_size_t
);
75 itm_def_process(itm_data_t
*itm_name
)
80 TRACE_MESSAGE('y', ("itm_def_process\n"));
83 itm_hdr
= malloc_vital(sizeof (itm_hdr_t
));
84 (void) memset(itm_hdr
, 0, sizeof (itm_hdr_t
));
86 if ((NULL
!= cmd_opt
.interpreter
) &&
87 (0 < (len
= strlen(cmd_opt
.interpreter
)))) {
88 itm_hdr
->interpreter
= *(str_to_data(len
, cmd_opt
.interpreter
));
90 if ((sizeof (itm_place_t
)) < itm_hdr
->interpreter
.size
) {
91 (void) obj_register(ITMC_OBJ_STRING
, NULL
,
92 (void *)itm_hdr
->interpreter
.place
.itm_ptr
,
93 itm_hdr
->interpreter
.size
,
94 &(itm_hdr
->interpreter
.place
),
98 itm_hdr
->type_id
= *itm_name
;
99 if ((sizeof (itm_place_t
)) < itm_hdr
->type_id
.size
) {
100 (void) obj_register(ITMC_OBJ_STRING
, NULL
,
101 (void *)itm_hdr
->type_id
.place
.itm_ptr
,
102 itm_hdr
->type_id
.size
,
103 &(itm_hdr
->type_id
.place
),
107 (void) assemble(itm_hdr
);
115 itm_data_t
*cond_name
,
117 itm_data_t
*act_name
)
122 du
= malloc_vital(sizeof (itmc_obj_t
));
123 du
->type
= ITMC_OBJ_DIREC
;
125 du
->obj
= direc
= malloc_vital(sizeof (itm_direc_t
));
128 direc
->condition
.itm_ptr
= (uintptr_t)NULL
;
129 cond
->referencer
= &(direc
->condition
);
131 } else if (NULL
!= cond_name
) {
132 direc
->condition
.itm_ptr
= (itm_place2_t
)(cond_name
);
133 du
->ref
[0] = obj_register(ITMC_OBJ_COND
, cond_name
, NULL
, 0,
134 &(direc
->condition
), OBJ_REG_TAIL
);
136 direc
->condition
.itm_ptr
= 0;
141 if (NULL
!= act_name
) {
142 direc
->action
.itm_ptr
= (itm_place2_t
)(act_name
);
143 du
->ref
[1] = obj_register(ITMC_OBJ_ACTION
, act_name
, NULL
, 0,
144 &(direc
->action
), OBJ_REG_TAIL
);
145 } else if (NULL
!= act
&& act
->tbl_hdr
!= NULL
) {
146 direc
->action
.itm_ptr
= (itm_place2_t
)(act
->tbl_hdr
);
147 du
->ref
[1] = obj_register(act
->type
,
148 (itm_data_t
*)(act
->tbl_hdr
->name
.itm_ptr
),
149 act
->tbl_hdr
, act
->tbl_hdr
->size
,
150 &(direc
->action
), OBJ_REG_TAIL
);
162 obj_table(itm_type_t tbl_type
,
164 itmc_obj_t
*obj_list
,
168 obj_array_t obj_array
;
170 obj_array
= obj_list_to_array(sizeof (itm_tbl_hdr_t
),
174 tbl
->type
= tbl_type
;
177 tbl
->name
.itm_pad
= 0;
179 tbl
->name
.itm_ptr
= (itm_place2_t
)name
;
182 tbl
->name
.itm_pad
= 0;
184 tbl
->name
.itm_ptr
= (uintptr_t)NULL
;
186 tbl
->size
= (sizeof (itm_tbl_hdr_t
)) + (obj_array
.num
*obj_size
);
187 tbl
->number
= obj_array
.num
;
189 if ((ITM_TBL_MASK
&tbl
->type
) == ITM_TBL_OP
) {
190 op_hirarchy(tbl
, obj_list
);
199 obj_list_to_array(itm_size_t hdr_size
, itmc_obj_t
*obj_list
,
202 obj_array_t obj_array
;
206 for (obj_array
.num
= 0, ol
= obj_list
;
207 ol
; obj_array
.num
+= 1, ol
= ol
->next
) {
211 obj_array
.obj
= malloc_vital(hdr_size
+ (size
* obj_array
.num
));
213 if (obj_array
.num
== 0)
216 for (offset
= hdr_size
, ol
= obj_list
;
217 ol
; offset
+= size
, ol
= ol
->next
) {
218 (void) memcpy((char *)(obj_array
.obj
) + offset
, ol
->obj
, size
);
220 ol
->ref
[0]->referencer
=
221 (void *)((char *)(ol
->ref
[0]->referencer
) +
222 ((char *)(obj_array
.obj
) -
223 (char *)(ol
->obj
) + offset
));
226 ol
->ref
[1]->referencer
=
227 (void *)((char *)(ol
->ref
[1]->referencer
) +
228 ((char *)(obj_array
.obj
) -
229 (char *)(ol
->obj
) + offset
));
232 ol
->ref
[2]->referencer
=
233 (void *)((char *)(ol
->ref
[2]->referencer
) +
234 ((char *)(obj_array
.obj
) -
235 (char *)(ol
->obj
) + offset
));
243 op_hirarchy(itm_tbl_hdr_t
*optbl
,
244 itmc_obj_t
*obj_list
)
250 TRACE_MESSAGE('l', ("op_hirarchy (optbl=%x)\n", optbl
));
251 o
= malloc_vital(sizeof (itm_op_outer_t
));
252 o
->link
= itm_op_outer
;
257 for (ol
= obj_list
; ol
!= NULL
; ol
= ol
->next
) {
258 if ((ol
->type
== ITMC_OBJ_OP
) &&
259 (((itm_op_t
*)ol
->obj
)->type
== ITM_OP_OPERATION
)) {
260 in
= malloc_vital(sizeof (itm_op_inner_t
));
263 TRACE_MESSAGE('L', ("o->in(%x) in->in(%x)\n",
265 in
->ref
= ol
->ref
[0];
270 for (in
= o
->in
; in
!= NULL
; in
= in
->in
) {
271 TRACE_MESSAGE('L', ("o=%x in=%x in->in=%x\n",
273 TRACE_MESSAGE('L', ("o(table)%x->in(ref)=%x\n",
281 obj_list_append(itmc_obj_t
*obj_list
, itmc_obj_t
*obj
)
291 obj_list
->last
->next
= obj
;
292 obj_list
->last
= obj
;
301 obj_register(itm_type_t type
, itm_data_t
*name
,
302 void *obj
, size_t size
, itm_place_t
*ref
,
303 itm_type_t reg_place
)
307 TRACE_MESSAGE('O', ("obj_register: %6ld %08p %08p %08ld %08p %ld\n",
308 type
, name
, obj
, size
, ref
, reg_place
));
310 refp
= malloc_vital(sizeof (itmc_ref_t
));
312 refp
->referencee
= obj
;
314 refp
->reloc
.itm_pad
= 0;
316 refp
->reloc
.itm_ptr
= 0;
318 refp
->referencer
= ref
;
321 if (NULL
== obj
) { /* reference to named object */
323 if (0 == error_deferred
) {
324 /* should never happen */
326 gettext("internal error: "
327 "obj_register: (NULL == obj) "
328 "&& (NULL == name)\n"));
329 exit(ITMC_STATUS_SYS2
);
333 refp
->name
= name_refer(name
, type
, refp
);
335 } else if ((NULL
!= name
) && (0 < name
->size
)) {
336 /* definition of named object */
337 refp
->name
= name_register(name
, type
, refp
);
340 if ((ITMC_OBJ_FIRST
<= type
) && (type
<= ITMC_OBJ_LAST
)) {
343 refp
->next
= ref_first
[type
];
344 ref_first
[type
] = refp
;
345 if (NULL
== ref_last
[type
]) {
346 ref_last
[type
] = refp
;
350 if (ref_first
[type
]) {
351 ref_last
[type
]->next
= refp
;
353 ref_first
[type
] = refp
;
355 ref_last
[type
] = refp
;
359 itm_error(gettext("obj_register: illegal object type\n"));
360 exit(ITMC_STATUS_SYS2
);
368 range_table(itm_data_t
*name
, itmc_obj_t
*obj_list
)
372 itmc_data_pair_t
*rp
;
374 itm_tbl_hdr_t
*table
;
375 itm_size_t length
= 0;
378 itm_size_t table_size
;
380 /* count range, determine length */
381 for (num
= 0, ol
= obj_list
; ol
; ol
= ol
->next
, num
++) {
382 rp
= (itmc_data_pair_t
*)(ol
->obj
);
384 if (rp
->data0
.size
== 0) {
385 itm_error(gettext("between has null range\n"));
389 length
= rp
->data0
.size
;
391 if ((rp
->data0
.size
!= length
) ||
392 (rp
->data1
.size
!= length
)) {
394 "length of source sequences must be the same\n"));
400 itm_error(gettext("between has no ranges\n"));
404 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
405 (sizeof (itm_range_hdr_t
)) + (length
* num
) * 2);
406 table_size
= ITMROUNDUP(table_size
);
408 table
= malloc_vital(table_size
);
409 table
->type
= ITM_TBL_RANGE
;
411 table
->name
.itm_ptr
= (itm_place2_t
)name
;
412 table
->size
= table_size
;
415 rh
= (itm_range_hdr_t
*)(table
+ 1);
418 p
= (char *)(rh
+ 1);
419 for (ol
= obj_list
, i
= 0; ol
; ol
= ol
->next
, i
++) {
420 rp
= (itmc_data_pair_t
*)(ol
->obj
);
421 (void) memcpy(p
, (NSPTR(&(rp
->data0
))), length
);
423 (void) memcpy(p
, (NSPTR(&(rp
->data1
))), length
);
431 * escape sequence table for stateful code set sequence
434 escseq_table(itm_data_t
*name
, itmc_obj_t
*obj_list
)
439 itm_escapeseq_hdr_t
*eh
;
440 itm_tbl_hdr_t
*table
;
441 itm_size_t len_max
= 0;
444 itm_size_t table_size
;
447 len_min
= ((itm_data_t
*)(ol
->obj
))->size
;
448 for (num
= 0; NULL
!= ol
; ol
= ol
->next
, num
++) {
449 ep
= (itm_data_t
*)(ol
->obj
);
450 if (ep
->size
< len_min
) len_min
= ep
->size
;
451 if (ep
->size
> len_max
) len_max
= ep
->size
;
455 ("escape sequence is defined without sequence\n"));
458 } else if (0 == len_min
) {
459 itm_error(gettext("null sequence\n"));
464 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
465 (sizeof (itm_escapeseq_hdr_t
)) +
466 (sizeof (itm_data_t
) * num
));
467 table_size
= ITMROUNDUP(table_size
);
468 table
= malloc_vital(table_size
);
469 table
->type
= ITM_TBL_ESCAPESEQ
;
471 table
->name
.itm_ptr
= (itm_place2_t
)name
;
472 table
->size
= table_size
;
475 eh
= (itm_escapeseq_hdr_t
*)(table
+ 1);
476 eh
->len_max
= len_max
;
477 eh
->len_min
= len_min
;
479 for (ol
= obj_list
, ep
= (itm_data_t
*)(eh
+ 1);
481 ol
= ol
->next
, ep
++) {
482 *ep
= *((itm_data_t
*)(ol
->obj
));
483 if ((sizeof (itm_place_t
)) < ep
->size
) {
484 (void) obj_register(ITMC_OBJ_DATA
, NULL
,
485 (void *)(ep
->place
.itm_ptr
), ep
->size
,
486 &(ep
->place
), OBJ_REG_TAIL
);
489 (void) qsort((itm_data_t
*)(eh
+ 1), num
, sizeof (itm_data_t
),
490 (int (*)(const void *, const void *))data_compare
);
492 for (i
= 0, ep
= (itm_data_t
*)(eh
+ 1);
495 if (0 <= data_compare(ep
, (ep
+ 1))) {
498 "same escape sequences are defined: "
500 data_to_hexadecimal(ep
),
501 data_to_hexadecimal(ep
+ 1));
513 map_table(itm_data_t
*name
, itmc_map_t
*map_list
,
514 itmc_map_attr_t
*attr
)
519 itmc_data_pair_t
**tpp
;
520 itm_tbl_hdr_t
*table
;
523 long source_fixed_len
= 1;
524 long pass_through
= 0;
525 long default_count
= 0;
526 itm_data_t
*default_data
= NULL
;
527 long error_deferred_local
= 0;
528 unsigned long dense_encoded_map_ent
;
529 unsigned long simple_indexed_map_ent
;
530 itm_size_t source_start
;
531 itm_size_t source_end
;
533 unsigned char *byte_seq_min
;
534 unsigned char *byte_seq_max
;
537 itmc_map_type_t map_type
= ITMC_MAP_UNKNOWN
;
538 itmc_map_name_type_t
*map_name_type
;
540 long result_len_specfied
= 0;
543 itmc_data_pair_t
**dp1
;
544 itm_num_t error_count
= 0;
547 map_type
= check_map_type(attr
);
549 if (ITMC_MAP_UNKNOWN
== map_type
) {
550 map_type
= ITMC_MAP_AUTOMATIC
;
552 hash_factor
= ((NULL
!= attr
) && (attr
->hash_factor
!= 0)) ?
556 map_name_type
= cmd_opt
.map_name_type
;
557 for (; map_name_type
; map_name_type
= map_name_type
->next
) {
558 if ('\0' == *(map_name_type
->name
)) {
559 map_type
= map_name_type
->type
;
560 hash_factor
= map_name_type
->hash_factor
;
564 map_name_type
= cmd_opt
.map_name_type
;
565 if ((NULL
!= name
) && (NULL
!= cmd_opt
.map_name_type
)) {
567 for (; map_name_type
; map_name_type
= map_name_type
->next
) {
568 if (0 == strcmp(map_name_type
->name
, (char *)p
)) {
569 map_type
= map_name_type
->type
;
570 hash_factor
= map_name_type
->hash_factor
;
577 if (MAXSEQUENCE
< attr
->resultlen
) {
579 gettext("output_byte_length must be less than %1$d\n"),
584 result_len_specfied
= attr
->resultlen
;
586 result_len_specfied
= 0;
589 for (num
= 0, ml
= map_list
; ml
; ml
= ml
->next
, num
++) {
592 if (0 == ml
->data_pair
.data0
.size
) {
593 if (0 == ml
->data_pair
.data1
.size
) {
595 default_data
= (itm_data_t
*)(-1);
598 default_data
= &(ml
->data_pair
.data1
);
603 } else if (0 == ml
->data_pair
.data1
.size
) {
604 /* error source sequence */
609 if ((0 < source_len
) &&
610 (0 < ml
->data_pair
.data0
.size
) &&
611 (source_len
!= ml
->data_pair
.data0
.size
)) {
612 source_fixed_len
= 0;
616 if (source_len
< ml
->data_pair
.data0
.size
) {
617 source_len
= ml
->data_pair
.data0
.size
;
619 if (result_len
< ml
->data_pair
.data1
.size
) {
620 result_len
= ml
->data_pair
.data1
.size
;
623 /* map source has range */
624 if (0 < ml
->data_pair
.range
.size
) {
625 if (ml
->data_pair
.range
.size
!=
626 ml
->data_pair
.data0
.size
) {
628 gettext("length of source range must be "
629 "the same: 0x%1$s 0x%2$s\n"),
630 data_to_hexadecimal(&(ml
->data_pair
.data0
)),
632 &(ml
->data_pair
.range
)));
636 if (0 <= data_compare(&(ml
->data_pair
.data0
),
637 &((ml
->data_pair
.range
)))) {
639 gettext("source range error: 0x%1$s 0x%2$s\n"),
641 &(ml
->data_pair
.data0
)),
643 &(ml
->data_pair
.range
)));
647 j
= map_table_resultlen(ml
);
648 if (result_len
< j
) {
655 gettext("no mapping pair\n"));
660 if (0 != result_len_specfied
) {
661 if (result_len
> result_len_specfied
) {
663 gettext("result value length is "
664 "over specifed output_byte_length(%1$ld)\n"),
665 result_len_specfied
);
669 result_len
= result_len_specfied
;
671 byte_seq_min
= malloc_vital((sizeof (unsigned char)) * source_len
);
672 byte_seq_max
= malloc_vital((sizeof (unsigned char)) * source_len
);
673 for (num
= 0, ml
= map_list
; ml
; ml
= ml
->next
, num
++) {
674 if (0 == ml
->data_pair
.data0
.size
) {
678 p
= (unsigned char *)(NSPTR(&((ml
->data_pair
).data0
)));
679 for (i
= 0; i
< source_len
; i
++) {
680 *(byte_seq_min
+ i
) = *(p
+ i
);
681 *(byte_seq_max
+ i
) = *(p
+ i
);
685 for (num
= 0, ml
= map_list
; ml
; ml
= ml
->next
, num
++) {
686 if (0 == ml
->data_pair
.data0
.size
) {
690 if (ml
->data_pair
.range
.size
> 0) {
691 map_range_adjust_byte_seq(byte_seq_min
, byte_seq_max
,
692 source_len
, &(ml
->data_pair
));
694 p
= (unsigned char *)(NSPTR(&((ml
->data_pair
).data0
)));
695 for (i
= 0; i
< source_len
; i
++) {
696 if (*(p
+ i
) < *(byte_seq_min
+ i
)) {
697 *(byte_seq_min
+ i
) = *(p
+ i
);
699 if (*(byte_seq_max
+ i
) < *(p
+ i
)) {
700 *(byte_seq_max
+ i
) = *(p
+ i
);
705 for (dense_encoded_map_ent
= 1, i
= 0; i
< source_len
; i
++) {
706 u
= dense_encoded_map_ent
;
707 dense_encoded_map_ent
*=
708 (*(byte_seq_max
+ i
) - *(byte_seq_min
+ i
) + 1);
709 if (dense_encoded_map_ent
< u
) {
710 dense_encoded_map_ent
= (ulong_t
)(~0);
717 TRACE_MESSAGE('m', ("map_table: ent=%lu num=%lu ",
718 dense_encoded_map_ent
, num
));
719 TRACE_MESSAGE('m', ("byte_seq_min=0x"));
720 for (i
= 0; i
< source_len
; i
++) {
721 TRACE_MESSAGE('m', ("%02x", *(byte_seq_min
+ i
)));
723 TRACE_MESSAGE('m', (" byte_seq_max=0x"));
724 for (i
= 0; i
< source_len
; i
++) {
725 TRACE_MESSAGE('m', ("%02x", *(byte_seq_max
+ i
)));
727 TRACE_MESSAGE('m', ("\n"));
731 tpp
= malloc_vital((sizeof (itmc_data_pair_t
*)) * num
);
732 for (num
= 0, num2
= 0, ml
= map_list
; ml
; ml
= ml
->next
) {
733 if (0 < ml
->data_pair
.data0
.size
) {
735 *(tpp
+ num
) = &(ml
->data_pair
);
738 if (ml
->data_pair
.range
.size
> 0) {
740 map_table_num_range(&(ml
->data_pair
));
743 if (0 == ml
->data_pair
.data1
.size
) {
744 /* specified error sequence */
745 error_count
+= range_num
;
749 (void) qsort(tpp
, num
, sizeof (itmc_data_pair_t
*),
750 (int (*)(const void *, const void *))data_pair_compare
);
752 /* check if map_pair range and next map_pair are overrapped */
753 for (n
= 0, dp1
= tpp
; n
< (num
-1); n
++, dp1
++) {
754 if (((*(dp1
+0))->range
.size
!= 0) &&
755 (0 <= data_compare(&((*(dp1
+0))->range
),
756 &((*(dp1
+1))->data0
)))) {
758 gettext("ranges of source sequences "
759 "overrapped: %1$s %2$s\n"),
760 data_to_hexadecimal(&((*(dp1
+0))->range
)),
761 data_to_hexadecimal(&((*(dp1
+1))->data0
)));
767 if (1 < default_count
) {
769 gettext("default is specified %1$d times in a map\n"),
771 error_deferred_local
+= 1;
773 if ((1 == default_count
) && (!source_fixed_len
)) {
775 gettext("default is specified,"
776 " but length of source data is not fixed\n"));
777 error_deferred_local
+= 1;
779 if ((1 <= pass_through
) && (source_len
!= result_len
)) {
781 gettext("\"default no_change_copy\" is "
782 "specified, but size does not match\n"));
783 error_deferred_local
+= 1;
786 if (error_deferred_local
) {
787 error_deferred
+= error_deferred_local
;
791 if (source_fixed_len
) {
792 source_start
= data_to_long(&((*(tpp
+ 0))->data0
));
793 source_end
= data_to_long(&((*(tpp
+ num
- 1))->data0
));
794 if (0 < (*(tpp
+ num
- 1))->range
.size
) {
795 source_end
= data_to_long(&((*(tpp
+ num
- 1))->range
));
798 simple_indexed_map_ent
= source_end
- source_start
+ 1;
800 TRACE_MESSAGE('m', ("map_table: simple_indexed_map_ent=%lu\n",
801 simple_indexed_map_ent
));
804 case ITMC_MAP_AUTOMATIC
:
805 if ((source_len
<= 2) &&
806 (((ulong_t
)(~0) == dense_encoded_map_ent
) ||
807 (simple_indexed_map_ent
<
808 (dense_encoded_map_ent
* 2)))) {
810 * for small source sequence,
811 * if dense table is not so large
812 * compared with simple table,
815 map_type
= ITMC_MAP_SIMPLE_INDEX
;
816 } else if (cmd_opt
.large_table
) {
817 if ((sizeof (long)) < source_len
) {
819 gettext("length of source is too long "
820 "for large table: %ld\n"),
825 map_type
= ITMC_MAP_SIMPLE_INDEX
;
826 } else if (((ulong_t
)(~0) == dense_encoded_map_ent
) ||
827 ((0xffff < dense_encoded_map_ent
) &&
828 ((num2
* 8) < dense_encoded_map_ent
))) {
830 * if dense can be used and not too large
831 * ( less than (hash table entry * 8),
834 map_type
= ITMC_MAP_SIMPLE_HASH
;
836 map_type
= ITMC_MAP_DENSE_ENCODING
;
839 case ITMC_MAP_SIMPLE_INDEX
:
840 if ((sizeof (long)) < source_len
) {
842 gettext("length of source is too long "
843 "for index lookup: %ld\n"),
849 case ITMC_MAP_SIMPLE_HASH
:
850 for (i
= 2, u
= 256; i
< (sizeof (long)); i
++) {
855 gettext("map is too large for hashing: %lu\n"),
861 case ITMC_MAP_DENSE_ENCODING
:
862 for (i
= 2, u
= 256; i
< (sizeof (long)); i
++) {
865 if (u
< dense_encoded_map_ent
) {
868 "map is too large for dense encoding: "
870 dense_encoded_map_ent
);
875 case ITMC_MAP_BINARY_SEARCH
:
876 for (i
= 2, u
= 256; i
< (sizeof (long)); i
++) {
881 gettext("length of source is too long for "
882 "binary search: %ld\n"),
892 case ITMC_MAP_SIMPLE_INDEX
:
893 table
= map_table_indexed_fixed(
894 tpp
, num
, default_data
,
895 result_len
, error_count
);
897 case ITMC_MAP_SIMPLE_HASH
:
898 table
= map_table_hash(tpp
, num
, default_data
,
899 hash_factor
, result_len
, num2
,
902 case ITMC_MAP_DENSE_ENCODING
:
903 table
= map_table_dense_encoding(tpp
, num
,
905 dense_encoded_map_ent
,
906 byte_seq_min
, byte_seq_max
,
907 result_len
, error_count
);
909 case ITMC_MAP_BINARY_SEARCH
:
910 table
= map_table_lookup_fixed(tpp
, num
,
916 table
= map_table_lookup_var();
919 if ((NULL
!= name
) && (NULL
!= table
)) {
920 table
->name
.itm_ptr
= (itm_place2_t
)name
;
927 static itmc_map_type_t
928 check_map_type(itmc_map_attr_t
*attr
)
932 if (NULL
== attr
->type
) {
935 for (i
= 0; NULL
!= map_type_name
[i
].name
; i
++) {
936 if (0 == strncmp(((char *)&(attr
->type
->place
)),
937 map_type_name
[i
].name
, attr
->type
->size
)) {
938 return (map_type_name
[i
].type
);
945 static itm_tbl_hdr_t
*
946 map_table_indexed_fixed(
947 itmc_data_pair_t
**tpp
,
949 itm_data_t
*default_data
,
951 itm_num_t error_count
)
953 itm_tbl_hdr_t
*header
;
954 itm_map_idx_fix_hdr_t
*sub_hdr
;
957 itm_size_t source_start
;
958 itm_size_t source_end
;
959 itm_size_t entry_num
;
960 itm_size_t table_size
;
967 TRACE_MESSAGE('m', ("map_table_range : %ld\n", num
));
969 source
= &((*(tpp
+ 0))->data0
);
970 assert((sizeof (itm_place_t
)) >= source
->size
);
972 if ((1 == source
->size
) &&
977 source_start
= data_to_long(&((*(tpp
+ 0))->data0
));
978 source_end
= data_to_long(&((*(tpp
+ num
- 1))->data0
));
979 if (0 < (*(tpp
+ num
- 1))->range
.size
)
980 source_end
= data_to_long(&((*(tpp
+ num
- 1))->range
));
983 entry_num
= source_end
- source_start
+ 1;
985 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
986 (sizeof (itm_map_idx_fix_hdr_t
)) +
987 (resultlen
* entry_num
));
988 if (0 < error_count
) {
989 table_size
+= entry_num
;
991 if (NULL
== default_data
) {
992 if ((num
< entry_num
) ||
993 (error_count
<= 0)) {
994 table_size
+= entry_num
;
996 } else if ((itm_data_t
*)(-1) != default_data
) {
997 table_size
+= resultlen
;
1000 table_size
= ITMROUNDUP(table_size
);
1001 header
= malloc_vital(table_size
);
1002 sub_hdr
= (itm_map_idx_fix_hdr_t
*)(header
+ 1);
1003 table
= (char *)(sub_hdr
+ 1);
1005 if ((1 == (*tpp
)->data0
.size
) &&
1006 (1 == (*tpp
)->data1
.size
)) {
1007 header
->type
= ITM_TBL_MAP_INDEX_FIXED_1_1
;
1009 header
->type
= ITM_TBL_MAP_INDEX_FIXED
;
1011 header
->name
.itm_ptr
= 0;
1012 header
->size
= table_size
;
1013 header
->number
= entry_num
;
1015 sub_hdr
->source_len
= (*tpp
)->data0
.size
;
1016 sub_hdr
->result_len
= resultlen
;
1017 sub_hdr
->start
.itm_ptr
= source_start
;
1018 sub_hdr
->end
.itm_ptr
= source_end
;
1019 sub_hdr
->error_num
= error_count
; /* > 0; so pad4 = 0 */
1021 if (NULL
!= default_data
) {
1022 if ((itm_data_t
*)(-1) == default_data
) {
1023 sub_hdr
->default_error
= -1;
1025 sub_hdr
->pad3_num
= (pad_t
)(~0);
1028 sub_hdr
->default_error
= 0;
1031 if (num
< entry_num
) {
1032 sub_hdr
->default_error
= 1;
1034 sub_hdr
->default_error
= 2;
1038 error_table
= (table
+ (resultlen
* entry_num
));
1039 if (-1 == sub_hdr
->default_error
) {
1040 if (source
->size
!= resultlen
) {
1042 gettext("\"default no_change_copy\" is "
1043 "specified, but size does not match\n"));
1044 exit(ITMC_STATUS_BT
);
1049 i
++, j
+= resultlen
) {
1050 for (k
= 0; k
< resultlen
; k
++) {
1052 (((source_start
+ i
) >>
1053 ((resultlen
- k
- 1) * 8)) &
1057 } else if (0 == sub_hdr
->default_error
) {
1058 error_table
+= resultlen
;
1059 if (default_data
->size
<= (sizeof (itm_place_t
))) {
1061 i
< (entry_num
+ 1); /* last one is for default */
1062 i
++, j
+= resultlen
) {
1063 (void) memcpy(table
+ j
+
1064 (resultlen
- default_data
->size
),
1065 (void *)(&(default_data
->place
.itm_64d
)),
1066 default_data
->size
);
1070 i
< (entry_num
+ 1); /* last one is for default */
1071 i
++, j
+= resultlen
) {
1072 (void) memcpy(table
+ j
+
1073 (resultlen
- default_data
->size
),
1074 (void *)(default_data
->place
.itm_ptr
),
1075 default_data
->size
);
1079 if (1 == sub_hdr
->default_error
) {
1080 (void) memset(error_table
, 1, entry_num
);
1081 for (i
= 0; i
< num
; i
++) {
1082 if (0 == (*(tpp
+ i
))->data1
.size
) {
1083 continue; /* error sequence */
1085 j
= data_to_long(&((*(tpp
+ i
))->data0
)) -
1087 k
= ((*(tpp
+ i
))->range
.size
) == 0 ? j
:
1088 data_to_long(&((*(tpp
+ i
))->range
)) -
1090 for (; j
<= k
; j
++) {
1091 *(error_table
+ j
) = 0;
1094 } else if (0 < error_count
) {
1095 (void) memset(error_table
, 0, entry_num
);
1096 for (i
= 0; i
< num
; i
++) {
1097 if (0 == (*(tpp
+ i
))->data1
.size
) {
1098 /* error sequence */
1099 j
= data_to_long(&((*(tpp
+ i
))->data0
)) -
1101 k
= ((*(tpp
+ i
))->range
.size
) == 0 ? j
:
1102 data_to_long(&((*(tpp
+ i
))->range
)) -
1104 for (; j
<= k
; j
++) {
1105 *(error_table
+ j
) = 1;
1111 p
= malloc_vital(sizeof (uchar_t
*) * resultlen
);
1112 for (i
= 0; i
< num
; i
++) {
1113 j
= data_to_long(&((*(tpp
+ i
))->data0
)) - source_start
;
1114 if (0 != (*(tpp
+ i
))->range
.size
)
1115 k
= data_to_long(&((*(tpp
+ i
))->range
)) -
1119 (void) memset(p
, 0, sizeof (uchar_t
*) * resultlen
);
1120 (void) memcpy(p
+ (resultlen
- (*(tpp
+ i
))->data1
.size
),
1121 ((caddr_t
)NSPTR(&((*(tpp
+ i
))->data1
))),
1122 (*(tpp
+ i
))->data1
.size
);
1123 map_range_make_result(table
, j
, k
, p
, resultlen
);
1133 static itm_tbl_hdr_t
*
1134 map_table_lookup_fixed(
1135 itmc_data_pair_t
**tpp
,
1137 itm_data_t
*default_data
,
1141 itm_tbl_hdr_t
*header
;
1142 itm_map_lookup_hdr_t
*sub_hdr
;
1144 itm_size_t table_size
;
1150 uchar_t
*source_data
;
1151 uchar_t
*result_data
;
1153 TRACE_MESSAGE('m', ("map_table_lookup_fixed : %ld(%ld) 0x%lx\n",
1154 num
, num2
, default_data
));
1156 source
= &((*(tpp
+ 0))->data0
);
1158 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
1159 (sizeof (itm_map_idx_fix_hdr_t
)) +
1160 ((source
->size
+ 1 + resultlen
) * num2
));
1161 if ((NULL
!= default_data
) &&
1162 (((itm_data_t
*)(-1)) != default_data
)) {
1163 table_size
+= (source
->size
+ 1 + resultlen
);
1165 table_size
= ITMROUNDUP(table_size
);
1166 header
= malloc_vital(table_size
);
1167 sub_hdr
= (itm_map_lookup_hdr_t
*)(header
+ 1);
1168 table
= (char *)(sub_hdr
+ 1);
1170 header
->type
= ITM_TBL_MAP_LOOKUP
;
1171 header
->name
.itm_ptr
= 0;
1172 header
->size
= table_size
;
1173 header
->number
= num2
;
1174 if (NULL
!= default_data
) {
1175 if ((itm_data_t
*)(-1) == default_data
) {
1177 sub_hdr
->pad3_num
= (pad_t
)(~0);
1179 sub_hdr
->default_error
= -1;
1181 sub_hdr
->default_error
= 0;
1184 sub_hdr
->default_error
= 2;
1187 sub_hdr
->source_len
= source
->size
;
1188 sub_hdr
->result_len
= resultlen
;
1191 source_data
= malloc_vital(source
->size
);
1192 result_data
= malloc_vital(resultlen
);
1193 for (i
= 0, j
= 0; i
< num
; i
++) {
1194 (void) memcpy(table
+ j
,
1195 NSPTR(&((*(tpp
+ i
))->data0
)), source
->size
);
1197 if (0 == (*(tpp
+ i
))->data1
.size
) {
1198 *(table
+ j
) = 1; /* specified error */
1201 /* *(table + j) = 0; ** valid */
1203 (void) memcpy(table
+ j
+
1204 (resultlen
- (*(tpp
+ i
))->data1
.size
),
1205 NSPTR(&((*(tpp
+ i
))->data1
)),
1206 (*(tpp
+ i
))->data1
.size
);
1210 if ((*(tpp
+ i
))->range
.size
!= 0) {
1211 (void) memcpy(source_data
,
1212 NSPTR(&((*(tpp
+ i
))->data0
)),
1214 (void) memset(result_data
, 0, resultlen
);
1215 (void) memcpy(result_data
+
1216 (resultlen
- (*(tpp
+ i
))->data1
.size
),
1217 NSPTR(&((*(tpp
+ i
))->data1
)),
1218 (*(tpp
+ i
))->data1
.size
);
1219 h
= map_table_num_range((*(tpp
+ i
)));
1220 for (k
= 0; k
< h
; k
++) {
1226 (source_data
+ source
->size
- 1);
1231 for (++dp
; m
> 0; m
--, dp
++) {
1237 (void) memcpy(table
+ j
,
1238 source_data
, source
->size
);
1241 if (0 == (*(tpp
+ i
))->data1
.size
) {
1242 *(table
+ j
) = 1; /* specified error */
1245 /* *(table + j) = 0; ** valid */
1247 for (m
= 0, dp
= (uchar_t
*)
1248 (result_data
+ resultlen
- 1);
1261 (void) memcpy(table
+ j
, result_data
,
1272 if ((NULL
!= default_data
) &&
1273 (((itm_data_t
*)(-1)) != default_data
)) {
1274 (void) memset(table
+ j
, 0, source
->size
+ 1 + resultlen
);
1275 (void) memcpy(table
+ j
+ source
->size
+ 1 +
1276 (resultlen
- default_data
->size
),
1277 NSPTR(default_data
), default_data
->size
);
1285 static itm_tbl_hdr_t
*
1287 itmc_data_pair_t
**tpp
,
1289 itm_data_t
*default_data
,
1293 itm_num_t error_count
)
1295 itm_tbl_hdr_t
*header
;
1296 itm_map_hash_hdr_t
*sub_hdr
;
1297 itm_size_t table_size
;
1300 itm_size_t hash_table_num
;
1302 itm_size_t of_table_num
;
1303 itm_size_t pair_size
;
1315 uchar_t
*source_data
;
1316 uchar_t
*result_data
;
1322 TRACE_MESSAGE('m', ("map_table_hash : %ld(%ld) 0x%lx\n",
1323 num
, num2
, default_data
));
1324 source
= &((*(tpp
+ 0))->data0
);
1325 pair_size
= (source
->size
+ 1 + resultlen
);
1327 if (100 <= hash_factor
) {
1328 hash_table_num
= (num2
* (hash_factor
/ 100.0));
1330 hash_table_num
= (num2
* 2);
1332 if (hash_table_num
< 256) {
1333 hash_table_num
= 256;
1335 source_data
= malloc_vital(source
->size
);
1336 result_data
= malloc_vital(resultlen
);
1338 hash_table
= malloc_vital(hash_table_num
);
1339 for (i
= 0, of_table_num
= 0; i
< num
; i
++) {
1340 hash_value
= hash(NSPTR(&((*(tpp
+ i
))->data0
)),
1341 (*(tpp
+ i
))->data0
.size
,
1343 if (0 == *(hash_table
+ hash_value
)) {
1344 *(hash_table
+ hash_value
) = 1;
1346 *(hash_table
+ hash_value
) = 2;
1350 if ((*(tpp
+ i
))->range
.size
!= 0) {
1351 (void) memcpy(source_data
,
1352 NSPTR(&((*(tpp
+ i
))->data0
)),
1354 h
= map_table_num_range((*(tpp
+ i
)));
1355 for (n
= 0; n
< h
; n
++) {
1358 (source_data
+ source
->size
- 1);
1363 for (++dp
; m
> 0; m
--, dp
++) {
1369 hash_value
= hash((char *)source_data
,
1373 if (0 == *(hash_table
+ hash_value
)) {
1374 *(hash_table
+ hash_value
) = 1;
1376 *(hash_table
+ hash_value
) = 2;
1389 for (i
= 0; i
< hash_table_num
; i
++) {
1390 if (2 == *(hash_table
+ i
)) {
1391 (void) putchar('2');
1393 } else if (1 == *(hash_table
+ i
)) {
1394 (void) putchar('1');
1396 } else if (0 == *(hash_table
+ i
)) {
1397 (void) putchar('-');
1400 (void) putchar('*');
1404 (void) putchar('\n');
1409 (void) putchar('\n');
1410 (void) printf("null=%ld one=%ld conflict=%ld\n",
1411 hash_none
, hash_one
, hash_conflict
);
1416 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
1417 (sizeof (itm_map_hash_hdr_t
)) +
1419 (pair_size
* hash_table_num
) +
1420 (pair_size
* of_table_num
));
1421 if ((NULL
!= default_data
) &&
1422 (((itm_data_t
*)(-1)) != default_data
)) {
1423 table_size
+= pair_size
;
1425 table_size
= ITMROUNDUP(table_size
);
1426 header
= malloc_vital(table_size
);
1427 sub_hdr
= (itm_map_hash_hdr_t
*)(header
+ 1);
1428 error_table
= (char *)(sub_hdr
+ 1);
1429 hash_table
= error_table
+ hash_table_num
;
1430 of_table
= hash_table
+ (pair_size
* hash_table_num
);
1432 header
->type
= ITM_TBL_MAP_HASH
;
1433 header
->name
.itm_ptr
= 0;
1434 header
->size
= table_size
;
1435 header
->number
= num2
;
1436 if (NULL
!= default_data
) {
1437 if ((itm_data_t
*)(-1) == default_data
) {
1438 sub_hdr
->default_error
= -1;
1440 sub_hdr
->pad7_num
= (pad_t
)(~0);
1443 sub_hdr
->default_error
= 0;
1446 sub_hdr
->default_error
= 2;
1449 sub_hdr
->source_len
= source
->size
;
1450 sub_hdr
->result_len
= resultlen
;
1451 sub_hdr
->hash_tbl_size
= (pair_size
* hash_table_num
);
1452 sub_hdr
->hash_tbl_num
= hash_table_num
;
1453 sub_hdr
->hash_of_size
=
1454 (pair_size
* of_table_num
);
1455 sub_hdr
->hash_of_num
= of_table_num
;
1456 sub_hdr
->error_num
= error_count
; /* > 0; so pad4 = 0 */
1459 for (i
= 0, j
= 0, k
= 0; i
< num
; i
++) {
1460 hash_value
= hash(NSPTR(&((*(tpp
+ i
))->data0
)),
1461 (*(tpp
+ i
))->data0
.size
,
1463 p
= error_table
+ hash_value
;
1464 if (*p
) { /* conflict */
1472 p
= hash_table
+ (pair_size
* hash_value
);
1475 (void) memcpy(p
, NSPTR(&((*(tpp
+ i
))->data0
)), source
->size
);
1477 if (0 == (*(tpp
+ i
))->data1
.size
) {
1478 (*p
) = 1; /* specified error */
1481 /* (*p) = 0; ** valid */
1484 (resultlen
- (*(tpp
+ i
))->data1
.size
));
1486 (resultlen
- (*(tpp
+ i
))->data1
.size
),
1487 NSPTR(&((*(tpp
+ i
))->data1
)),
1488 (*(tpp
+ i
))->data1
.size
);
1491 if ((*(tpp
+ i
))->range
.size
!= 0) {
1492 (void) memcpy(source_data
,
1493 NSPTR(&((*(tpp
+ i
))->data0
)),
1495 (void) memset(result_data
, 0,
1496 (resultlen
- (*(tpp
+ i
))->data1
.size
));
1497 (void) memcpy(result_data
+
1498 (resultlen
- (*(tpp
+ i
))->data1
.size
),
1499 NSPTR(&((*(tpp
+ i
))->data1
)),
1500 (*(tpp
+ i
))->data1
.size
);
1501 h
= map_table_num_range((*(tpp
+ i
)));
1502 for (n
= 0; n
< h
; n
++) {
1505 (source_data
+ source
->size
- 1);
1510 for (++dp
; m
> 0; m
--, dp
++) {
1517 hash_value
= hash((char *)source_data
,
1520 p
= error_table
+ hash_value
;
1521 if (*p
) { /* conflict */
1530 (pair_size
* hash_value
);
1532 (void) memcpy(p
, source_data
, source
->size
);
1535 if (0 == (*(tpp
+ i
))->data1
.size
) {
1536 (*p
) = 1; /* specified error */
1539 /* (*p) = 0; ** valid */
1541 for (m
= 0, dp
= (uchar_t
*)
1542 (result_data
+ resultlen
- 1);
1555 result_data
, resultlen
);
1564 if ((NULL
!= default_data
) &&
1565 (((itm_data_t
*)(-1)) != default_data
)) {
1566 j
= ((pair_size
* hash_table_num
) +
1567 (pair_size
* of_table_num
));
1568 (void) memcpy(hash_table
+ j
+ (resultlen
- default_data
->size
),
1569 NSPTR(default_data
), default_data
->size
);
1571 #if defined(ENABLE_TRACE)
1572 for (i
= 0, p
= of_table
; i
< of_table_num
; i
++, p
+= 5) {
1573 (void) printf("0x%02x%02x%02x%02x 0x%02x\n",
1574 ((unsigned char)(*(p
+ 0))),
1575 ((unsigned char)(*(p
+ 1))),
1576 ((unsigned char)(*(p
+ 2))),
1577 ((unsigned char)(*(p
+ 3))),
1578 ((unsigned char)(*(p
+ 4))));
1587 static itm_tbl_hdr_t
*
1588 map_table_dense_encoding(
1589 itmc_data_pair_t
**tpp
,
1591 itm_data_t
*default_data
,
1592 unsigned long entry_num
,
1593 unsigned char *byte_seq_min
,
1594 unsigned char *byte_seq_max
,
1596 itm_num_t error_count
)
1599 itm_tbl_hdr_t
*header
;
1600 itm_map_dense_enc_hdr_t
*sub_hdr
;
1603 itm_size_t table_size
;
1609 unsigned char *byte_seq_def
;
1611 TRACE_MESSAGE('m', ("map_table_dense_encoding : %ld\n", num
));
1613 source
= &((*(tpp
+ 0))->data0
);
1616 table_size
= ((sizeof (itm_tbl_hdr_t
)) +
1617 (sizeof (itm_map_dense_enc_hdr_t
)) +
1618 (source
->size
+ source
->size
) +
1619 (resultlen
* entry_num
));
1620 if (0 < error_count
) {
1621 table_size
+= entry_num
;
1623 if (NULL
== default_data
) {
1624 if ((num
< entry_num
) ||
1625 (error_count
<= 0)) {
1626 table_size
+= entry_num
;
1628 } else if ((itm_data_t
*)(-1) != default_data
) {
1629 table_size
+= resultlen
;
1632 table_size
= ITMROUNDUP(table_size
);
1633 header
= malloc_vital(table_size
);
1634 sub_hdr
= (itm_map_dense_enc_hdr_t
*)(header
+ 1);
1635 table
= (char *)(sub_hdr
+ 1) + source
->size
+ source
->size
;
1637 header
->type
= ITM_TBL_MAP_DENSE_ENC
;
1638 header
->name
.itm_ptr
= 0;
1639 header
->size
= table_size
;
1640 header
->number
= entry_num
;
1642 sub_hdr
->source_len
= (*tpp
)->data0
.size
;
1643 sub_hdr
->result_len
= resultlen
;
1644 sub_hdr
->error_num
= error_count
; /* > 0; so pad4 = 0 */
1646 if (NULL
!= default_data
) {
1647 if ((itm_data_t
*)(-1) == default_data
) {
1648 sub_hdr
->default_error
= -1;
1650 sub_hdr
->pad3_num
= (pad_t
)(~0);
1654 sub_hdr
->default_error
= 0;
1657 if (num
< entry_num
) {
1658 sub_hdr
->default_error
= 1;
1660 sub_hdr
->default_error
= 2;
1664 (void) memcpy((char *)(sub_hdr
+ 1), byte_seq_min
, source
->size
);
1665 (void) memcpy((char *)(sub_hdr
+ 1) + source
->size
,
1666 byte_seq_max
, source
->size
);
1668 if (-1 == sub_hdr
->default_error
) {
1669 byte_seq_def
= malloc_vital((sizeof (unsigned char *)) *
1671 if (source
->size
!= resultlen
) {
1673 gettext("\"default no_change_copy\" is "
1674 "specified, but size does not match\n"));
1675 exit(ITMC_STATUS_BT
);
1677 put_dense_encoding_default(
1678 table
, byte_seq_min
, byte_seq_max
, byte_seq_def
,
1679 resultlen
- 1, 0, 0);
1681 } else if (0 == sub_hdr
->default_error
) {
1682 if (default_data
->size
<= (sizeof (itm_place_t
))) {
1684 i
< (entry_num
+ 1); /* 1:default data */
1685 i
++, j
+= resultlen
) {
1686 (void) memcpy(table
+ j
+
1687 (resultlen
- default_data
->size
),
1688 (void *)(&(default_data
->place
.itm_64d
)),
1689 default_data
->size
);
1693 i
< (entry_num
+ 1); /* 1:default data */
1694 i
++, j
+= resultlen
) {
1695 (void) memcpy(table
+ j
+
1696 (resultlen
- default_data
->size
),
1697 (void *)(default_data
->place
.itm_ptr
),
1698 default_data
->size
);
1702 if (1 == sub_hdr
->default_error
) {
1703 (void) memset(table
+ (resultlen
* entry_num
), 1, entry_num
);
1704 error_table
= (table
+ (resultlen
* entry_num
));
1705 for (i
= 0; i
< num
; i
++) {
1706 if (0 == (*(tpp
+ i
))->data1
.size
) {
1707 continue; /* error sequence */
1709 j
= hash_dense_encoding(NSPTR(&((*(tpp
+ i
))->data0
)),
1710 (*(tpp
+ i
))->data0
.size
,
1711 byte_seq_min
, byte_seq_max
);
1712 k
= ((*(tpp
+ i
))->range
.size
) == 0 ? j
:
1713 hash_dense_encoding(NSPTR(&((*(tpp
+ i
))->range
)),
1714 (*(tpp
+ i
))->data0
.size
,
1715 byte_seq_min
, byte_seq_max
);
1716 for (; j
<= k
; j
++) {
1717 *(error_table
+ j
) = 0;
1720 } else if (0 < error_count
) {
1721 error_table
= (table
+ (resultlen
* entry_num
));
1722 if (0 == sub_hdr
->default_error
) {
1723 error_table
+= resultlen
;
1725 (void) memset(error_table
, 0, entry_num
);
1726 for (i
= 0; i
< num
; i
++) {
1727 if (0 == (*(tpp
+ i
))->data1
.size
) {
1728 j
= hash_dense_encoding(
1729 NSPTR(&((*(tpp
+ i
))->data0
)),
1730 (*(tpp
+ i
))->data0
.size
,
1731 byte_seq_min
, byte_seq_max
);
1732 k
= ((*(tpp
+ i
))->range
.size
) == 0 ? j
:
1733 hash_dense_encoding(
1734 NSPTR(&((*(tpp
+ i
))->range
)),
1735 (*(tpp
+ i
))->data0
.size
,
1736 byte_seq_min
, byte_seq_max
);
1737 for (; j
<= k
; j
++) {
1738 *(error_table
+ j
) = 1; /* specified */
1745 p
= malloc_vital(resultlen
);
1746 for (i
= 0; i
< num
; i
++) {
1747 j
= hash_dense_encoding(NSPTR(&((*(tpp
+ i
))->data0
)),
1748 (*(tpp
+ i
))->data0
.size
,
1749 byte_seq_min
, byte_seq_max
);
1751 if (0 != (*(tpp
+ i
))->range
.size
)
1752 k
= hash_dense_encoding(
1753 NSPTR(&((*(tpp
+ i
))->range
)),
1754 (*(tpp
+ i
))->range
.size
,
1755 byte_seq_min
, byte_seq_max
);
1758 (void) memset(p
, 0, (resultlen
- (*(tpp
+ i
))->data1
.size
));
1759 (void) memcpy(p
+ (resultlen
- (*(tpp
+ i
))->data1
.size
),
1760 ((caddr_t
)NSPTR(&((*(tpp
+ i
))->data1
))),
1761 (*(tpp
+ i
))->data1
.size
);
1762 map_range_make_result(table
, j
, k
, p
, resultlen
);
1771 put_dense_encoding_default(
1773 unsigned char *byte_seq_min
,
1774 unsigned char *byte_seq_max
,
1775 unsigned char *byte_seq_def
,
1778 long dense_encoded_value
)
1782 if (position
< pos_max
) {
1783 for (i
= *(byte_seq_min
+ position
);
1784 i
<= *(byte_seq_max
+ position
); i
++) {
1785 *(byte_seq_def
+ position
) = i
;
1786 put_dense_encoding_default(
1788 byte_seq_min
, byte_seq_max
,
1790 pos_max
, position
+ 1,
1791 ((dense_encoded_value
+ i
) *
1792 (*(byte_seq_max
+ position
) -
1793 *(byte_seq_min
+ position
) + 1)));
1798 for (i
= *(byte_seq_min
+ position
);
1799 i
<= *(byte_seq_max
+ position
); i
++) {
1800 *(byte_seq_def
+ position
) = i
;
1801 (void) memcpy(table
+
1802 ((pos_max
+ 1) * (dense_encoded_value
+ i
- 1)),
1803 byte_seq_def
, pos_max
+ 1);
1809 dense_enc_index_to_byte_seq(
1812 unsigned char *byte_seq_min
,
1813 unsigned char *byte_seq_max
)
1816 static long buf_len
;
1822 if (buf_len
< (2 + (length
* 2) + 1)) {
1824 buf_len
= (2 + (length
* 2) + 1) + 16;
1825 buf
= malloc_vital(buf_len
);
1828 *(buf
+ (length
* 2)) = '\0';
1832 for (i
= length
- 1; 0 <= i
; --i
) {
1833 residue
= value
% (*(byte_seq_max
+ i
) -
1834 *(byte_seq_min
+ i
) + 1);
1835 value
/= (*(byte_seq_max
+ i
) -
1836 *(byte_seq_min
+ i
) + 1);
1838 residue
+= *(byte_seq_min
+ i
);
1839 l
= ((0xf0 & residue
) >> 4);
1841 *(p
+ (i
* 2)) = ('0' + l
);
1843 *(p
+ (i
* 2)) = ('a' + l
- 10);
1845 l
= (0x0f & residue
);
1847 *(p
+ (i
* 2) + 1) = ('0' + l
);
1849 *(p
+ (i
* 2) + 1) = ('a' + l
- 10);
1857 map_table_lookup_var()
1860 "length of all source sequences must be the same\n"));
1861 error_deferred
+= 1;
1868 map_range_adjust_byte_seq(
1869 unsigned char *byte_seq_min
,
1870 unsigned char *byte_seq_max
,
1872 itmc_data_pair_t
*pair
)
1874 unsigned char *p
, *p2
;
1878 p
= (unsigned char *)(NSPTR(&((pair
)->data0
)));
1879 p2
= (unsigned char *)(NSPTR(&((pair
)->range
)));
1881 for (i
= 0; i
< source_len
; i
++) {
1885 if (*(p
+ i
) != *(p2
+ i
))
1887 if (*(p
+ i
) < *(byte_seq_min
+ i
)) {
1888 *(byte_seq_min
+ i
) = *(p
+ i
);
1890 if (*(byte_seq_max
+ i
) < *(p2
+ i
)) {
1891 *(byte_seq_max
+ i
) = *(p2
+ i
);
1894 for (; i
< source_len
; i
++) {
1895 *(byte_seq_min
+ i
) = 0x00;
1896 *(byte_seq_max
+ i
) = 0xff;
1901 * result value + (source range value - source base value)
1902 * and just caluculate its length
1905 map_table_resultlen(itmc_map_t
*ml
)
1914 j
= ml
->data_pair
.data0
.size
;
1915 if (j
< ml
->data_pair
.data1
.size
) j
= ml
->data_pair
.data1
.size
;
1916 if (j
< ml
->data_pair
.range
.size
) j
= ml
->data_pair
.range
.size
;
1917 c1
= (uchar_t
*)(NSPTR(&((ml
->data_pair
).data0
))) +
1918 ml
->data_pair
.data0
.size
- 1;
1919 c2
= (uchar_t
*)(NSPTR(&((ml
->data_pair
).data1
))) +
1920 ml
->data_pair
.data1
.size
- 1;
1921 c3
= (uchar_t
*)(NSPTR(&((ml
->data_pair
.range
)))) +
1922 ml
->data_pair
.range
.size
- 1;
1924 for (len
= 0; len
< j
; len
++, c1
--, c2
--, c3
--) {
1925 if (len
< ml
->data_pair
.data0
.size
) m
-= *c1
;
1926 if (len
< ml
->data_pair
.data1
.size
) m
+= *c2
;
1927 if (len
< ml
->data_pair
.range
.size
) m
+= *c3
;
1933 TRACE_MESSAGE('g', ("map_table_resutlen: source(0x%s..0x%s), "
1934 "result(0x%s.... len= %ld)\n",
1935 data_to_hexadecimal(&(ml
->data_pair
.data0
)),
1936 data_to_hexadecimal(&(ml
->data_pair
.range
)),
1937 data_to_hexadecimal(&(ml
->data_pair
.data1
)),
1946 map_range_make_result(
1948 itm_size_t range_start
,
1949 itm_size_t range_end
,
1951 itm_size_t result_size
)
1956 uchar_t
*dp
; /* unsigned for ++ operation */
1958 for (i
= range_start
, p
= i
* result_size
;
1959 i
<= range_end
; i
++, p
+= result_size
) {
1960 (void) memcpy(table
+ p
, result_data
, result_size
);
1961 for (j
= 0, dp
= (uchar_t
*)(result_data
+ result_size
- 1);
1966 for (++dp
; j
> 0; j
--, dp
++) {
1979 map_table_num_range(itmc_data_pair_t
*pair
)
1987 assert(0 < pair
->range
.size
);
1988 j
= pair
->data0
.size
;
1989 if (j
< pair
->range
.size
)
1990 j
= pair
->range
.size
;
1991 c1
= ((uchar_t
*)(NSPTR(&(pair
->data0
)))) + pair
->data0
.size
- 1;
1992 c2
= ((uchar_t
*)(NSPTR(&(pair
->range
)))) + pair
->range
.size
- 1;
1994 for (i
= 0; i
< j
; i
++, c1
--, c2
--) {
1995 if (i
< pair
->range
.size
) num2
= *c2
;
1996 if (i
< pair
->data0
.size
) num2
-= *c1
;
1997 TRACE_MESSAGE('G', (" num += %d(=%d-%d)\n ",
1998 *c2
- *c1
, *c2
, *c1
));
2002 TRACE_MESSAGE('g', ("map_table_num_range: source(0x%s..0x%s), "
2004 data_to_hexadecimal(&(pair
->data0
)),
2005 data_to_hexadecimal(&(pair
->range
)),
2014 map_list_append(itmc_map_t
*map_list
, itmc_map_t
*map_pair
)
2016 if (0 == map_pair
) {
2020 map_pair
->next
= NULL
;
2021 map_pair
->last
= map_pair
;
2024 map_list
->last
->next
= map_pair
;
2025 map_list
->last
= map_pair
;
2035 op_self(itm_op_type_t type
)
2037 return (op_unit(type
, NULL
, 0, NULL
, 0, NULL
, 0));
2042 op_unary(itm_op_type_t type
, void *data
, size_t data_size
)
2044 return (op_unit(type
, data
, data_size
, NULL
, 0, NULL
, 0));
2048 op_unit(itm_op_type_t type
,
2049 void *data0
, size_t data0_size
,
2050 void *data1
, size_t data1_size
,
2051 void *data2
, size_t data2_size
)
2056 op
= malloc_vital(sizeof (itm_op_t
));
2058 op
->data
.operand
[0].itm_ptr
= (itm_place2_t
)(data0
);
2059 op
->data
.operand
[1].itm_ptr
= (itm_place2_t
)(data1
);
2060 op
->data
.operand
[2].itm_ptr
= (itm_place2_t
)(data2
);
2062 obj
= malloc_vital(sizeof (itmc_obj_t
));
2063 obj
->type
= ITMC_OBJ_OP
;
2066 obj
->ref
[0] = obj
->ref
[1] = obj
->ref
[2] = NULL
;
2067 if (NULL
!= data0
) {
2068 obj
->ref
[0] = obj_register(ITMC_OBJ_EXPR
, NULL
,
2070 &(op
->data
.operand
[0]),
2073 if (NULL
!= data1
) {
2074 obj
->ref
[1] = obj_register(ITMC_OBJ_EXPR
, NULL
,
2076 &(op
->data
.operand
[1]),
2079 if (NULL
!= data2
) {
2080 obj
->ref
[2] = obj_register(ITMC_OBJ_EXPR
, NULL
,
2082 &(op
->data
.operand
[2]),
2093 op_self_num(itm_op_type_t type
, itm_num_t data
)
2098 op
= malloc_vital(sizeof (itm_op_t
));
2100 op
->data
.itm_opnum
= data
;
2102 op
->data
.itm_oppad
= (data
< 0) ? (pad_t
)(~0) : 0;
2104 obj
= malloc_vital(sizeof (itmc_obj_t
));
2105 obj
->type
= ITMC_OBJ_OP
;
2108 obj
->ref
[0] = obj
->ref
[1] = obj
->ref
[2] = NULL
;
2115 expr_self_num(itm_expr_type_t type
, itm_num_t data
)
2119 expr
= malloc_vital(sizeof (itm_expr_t
));
2121 expr
->data
.itm_exnum
= data
;
2123 expr
->data
.itm_expad
= (data
< 0) ? (pad_t
)(~0) : 0;
2130 expr_self(itm_expr_type_t type
, itm_data_t
*data
)
2135 expr
= malloc_vital(sizeof (itm_expr_t
));
2138 expr
->data
.value
.size
= 0;
2139 expr
->data
.value
.place
.itm_ptr
= 0;
2141 expr
->data
.value
= *(data
);
2145 case ITM_EXPR_NAME
: /* register */
2146 name
= name_lookup(data
, ITMC_OBJ_REGISTER
);
2147 if (&name_lookup_error
== name
) {
2149 } else if (NULL
== name
) {
2150 if (reg_id
>= MAXREGID
) {
2153 "more than %d variables are used\n"),
2155 exit(ITMC_STATUS_BT2
);
2157 name
= name_register(data
, ITMC_OBJ_REGISTER
, NULL
);
2158 name
->reg_id
= (reg_id
++);
2160 expr
->type
= ITM_EXPR_REG
;
2161 expr
->data
.itm_exnum
= name
->reg_id
;
2163 expr
->data
.itm_expad
=
2164 (expr
->data
.itm_exnum
< 0) ? (pad_t
)(~0) : 0;
2168 if ((sizeof (itm_place_t
)) < data
->size
) {
2169 (void) obj_register(ITMC_OBJ_DATA
, NULL
,
2170 (void *)(data
->place
.itm_ptr
), data
->size
,
2171 &(expr
->data
.value
.place
), OBJ_REG_TAIL
);
2180 expr_unary(itm_expr_type_t type
, itm_expr_t
*data0
)
2184 expr
= malloc_vital(sizeof (itm_expr_t
));
2186 expr
->data
.operand
[0].itm_ptr
= (itm_place2_t
)(data0
);
2187 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2188 data0
, sizeof (itm_expr_t
),
2189 &(expr
->data
.operand
[0]), OBJ_REG_TAIL
);
2196 expr_binary(itm_expr_type_t type
,
2197 itm_expr_t
*data0
, itm_expr_t
*data1
)
2204 expr
= malloc_vital(sizeof (itm_expr_t
));
2207 if (ITM_EXPR_SEQ
== data0
->type
) {
2208 p
= (unsigned char *)NSPTR(&(data0
->data
.value
));
2209 for (i
= 0, num
= 0; i
< data0
->data
.value
.size
; i
++, p
++) {
2210 num
= ((num
<< 8) | *p
);
2212 data0
= expr_self_num(ITM_EXPR_INT
, num
);
2214 if (ITM_EXPR_SEQ
== data1
->type
) {
2215 p
= (unsigned char *)NSPTR(&(data1
->data
.value
));
2216 for (i
= 0, num
= 0; i
< data1
->data
.value
.size
; i
++, p
++) {
2217 num
= ((num
<< 8) | *p
);
2219 data1
= expr_self_num(ITM_EXPR_INT
, num
);
2222 expr
->data
.operand
[0].itm_ptr
= (itm_place2_t
)(data0
);
2223 expr
->data
.operand
[1].itm_ptr
= (itm_place2_t
)(data1
);
2225 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2226 data0
, sizeof (itm_expr_t
),
2227 &(expr
->data
.operand
[0]), OBJ_REG_TAIL
);
2228 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2229 data1
, sizeof (itm_expr_t
),
2230 &(expr
->data
.operand
[1]), OBJ_REG_TAIL
);
2237 expr_binary2(itm_expr_type_t type
,
2238 itm_expr_t
*data0
, itm_expr_t
*data1
)
2245 if ((NULL
== data0
) || (NULL
== data1
)) {
2248 expr
= malloc_vital(sizeof (itm_expr_t
));
2251 switch (data0
->type
) {
2253 p
= (unsigned char *)NSPTR(&(data0
->data
.value
));
2254 for (i
= 0, num
= 0; i
< data0
->data
.value
.size
; i
++, p
++) {
2255 num
= ((num
<< 8) | *p
);
2257 data0
= expr_self_num(ITM_EXPR_INT
, num
);
2258 expr
->data
.operand
[0].itm_ptr
= (itm_place2_t
)(data0
);
2259 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2260 data0
, sizeof (itm_expr_t
),
2261 &(expr
->data
.operand
[0]), OBJ_REG_TAIL
);
2265 case ITM_EXPR_IN_VECTOR_D
:
2266 expr
->data
.operand
[0] = data0
->data
.operand
[0];
2269 expr
->data
.operand
[0].itm_ptr
= (itm_place2_t
)(data0
);
2270 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2271 data0
, sizeof (itm_expr_t
),
2272 &(expr
->data
.operand
[0]), OBJ_REG_TAIL
);
2276 switch (data1
->type
) {
2278 p
= (unsigned char *)NSPTR(&(data1
->data
.value
));
2279 for (i
= 0, num
= 0; i
< data1
->data
.value
.size
; i
++, p
++) {
2280 num
= ((num
<< 8) | *p
);
2282 data1
= expr_self_num(ITM_EXPR_INT
, num
);
2283 expr
->data
.operand
[1].itm_ptr
= (itm_place2_t
)(data1
);
2284 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2285 data1
, sizeof (itm_expr_t
),
2286 &(expr
->data
.operand
[1]), OBJ_REG_TAIL
);
2290 case ITM_EXPR_IN_VECTOR_D
:
2291 expr
->data
.operand
[1] = data1
->data
.operand
[0];
2294 expr
->data
.operand
[1].itm_ptr
= (itm_place2_t
)(data1
);
2295 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2296 data1
, sizeof (itm_expr_t
),
2297 &(expr
->data
.operand
[1]), OBJ_REG_TAIL
);
2305 expr_assign(itm_expr_type_t type
,
2306 itm_data_t
*data0
, itm_expr_t
*data1
)
2311 expr
= malloc_vital(sizeof (itm_expr_t
));
2313 expr
->data
.operand
[1].itm_ptr
= (itm_place2_t
)(data1
);
2315 name
= name_lookup(data0
, ITMC_OBJ_REGISTER
);
2316 if (&name_lookup_error
== name
) {
2318 exit(ITMC_STATUS_BT
);
2319 } else if (NULL
== name
) {
2320 name
= name_register(data0
, ITMC_OBJ_REGISTER
, NULL
);
2321 name
->reg_id
= (reg_id
++);
2323 expr
->data
.operand
[0].itm_ptr
= name
->reg_id
;
2325 (void) obj_register(ITMC_OBJ_EXPR
, NULL
,
2326 data1
, sizeof (itm_expr_t
),
2327 &(expr
->data
.operand
[1]), OBJ_REG_TAIL
);
2333 expr_seq_to_int(itm_expr_t
*expr
)
2339 if (ITM_EXPR_SEQ
== expr
->type
) {
2340 if ((sizeof (itm_place_t
)) < expr
->data
.value
.size
) {
2341 p
= (unsigned char *)(expr
->data
.value
.place
.itm_ptr
);
2343 p
= (unsigned char *)&(expr
->data
.value
.place
.itm_64d
);
2345 for (i
= 0, num
= 0;
2346 i
< expr
->data
.value
.size
;
2348 num
= ((num
<< 8) | *p
);
2351 expr
= expr_self_num(ITM_EXPR_INT
, num
);
2358 name_lookup(itm_data_t
*name
, itm_type_t type
)
2362 TRACE_MESSAGE('N', ("name_lookup\t: \"%-16s\" %2ld %2ld %2ld\n",
2363 name_to_str(name
), name
->size
, type
, name_id
));
2365 if (0 == name
->size
)
2367 for (p
= name_first
; p
; p
= p
->next
) {
2368 if ((name
->size
!= p
->name
.size
) ||
2369 (memcmp(NSPTR(name
), NSPTR(&(p
->name
)), name
->size
))) {
2372 if ((type
!= p
->type
) &&
2373 (((ITMC_OBJ_ACTION
!= type
) &&
2374 (ITMC_OBJ_ACTION
!= p
->type
)) ||
2375 ((ITMC_OBJ_ACTION
== type
) &&
2376 (ITMC_OBJ_DIREC
!= p
->type
) &&
2377 (ITMC_OBJ_OP
!= p
->type
) &&
2378 (ITMC_OBJ_MAP
!= p
->type
)) ||
2379 ((ITMC_OBJ_ACTION
== p
->type
) &&
2380 (ITMC_OBJ_DIREC
!= type
) &&
2381 (ITMC_OBJ_OP
!= type
) &&
2382 (ITMC_OBJ_MAP
!= type
)))) {
2384 gettext("name type conflict: \"%1$s\" "
2387 itm_name_type_name
[type
],
2388 itm_name_type_name
[p
->type
]);
2389 error_deferred
+= 1;
2390 return (&name_lookup_error
);
2400 name_refer(itm_data_t
*name
, itm_type_t type
, itmc_ref_t
*refp
)
2403 itmc_ref_link_t
*rl
;
2405 p
= name_lookup(name
, type
);
2407 TRACE_MESSAGE('N', ("name_refer\t: \"%-16s\" %2ld %2ld %08p %2d %08p\n",
2408 name_to_str(name
), name
->size
, type
, refp
, name_id
, p
));
2410 if (&name_lookup_error
== p
) {
2414 rl
= malloc_vital(sizeof (itmc_ref_link_t
));
2421 p
->ref_last
->next
= rl
;
2427 p
= malloc_vital(sizeof (itmc_name_t
));
2428 p
->id
= (name_id
++);
2433 p
->reloc
.itm_pad
= 0;
2435 p
->reloc
.itm_ptr
= 0;
2441 name_last
->next
= p
;
2452 name_register(itm_data_t
*name
, itm_type_t type
, itmc_ref_t
*refp
)
2456 TRACE_MESSAGE('N', ("name_register\t: \"%-16s\" %2ld %2ld %08p %2ld\n",
2457 name_to_str(name
), name
->size
, type
, refp
, name_id
));
2460 p
= name_lookup(name
, type
);
2461 if (&name_lookup_error
== p
) {
2465 if (NULL
!= p
->object
) {
2467 "same names are specified: %1$s\n"),
2469 error_deferred
+= 1;
2474 p
= malloc_vital(sizeof (itmc_name_t
));
2475 p
->id
= (name_id
++);
2480 p
->reloc
.itm_ptr
= 0;
2482 p
->reloc
.itm_pad
= 0;
2484 p
->ref_first
= NULL
;
2489 name_last
->next
= p
;
2501 data_compare(const itm_data_t
*d0
, const itm_data_t
*d1
)
2503 if (d0
->size
< d1
->size
) {
2504 if (memcmp(NSPTR(d0
), NSPTR(d1
), d0
->size
) < 0) {
2509 } else if (d0
->size
== d1
->size
) {
2510 return (memcmp(NSPTR(d0
), NSPTR(d1
), d0
->size
));
2511 } else /* (d0->size > d1->size) */ {
2512 if (memcmp(NSPTR(d0
), NSPTR(d1
), d1
->size
) <= 0) {
2521 data_pair_compare(itmc_data_pair_t
**p0
, itmc_data_pair_t
**p1
)
2531 d0
= &((*p0
)->data0
);
2532 d1
= &((*p1
)->data0
);
2535 if (d0
->size
== d1
->size
) {
2537 } else if (d0
->size
< d1
->size
) {
2538 s
= d1
->size
- d0
->size
;
2539 for (i
= 0; i
< s
; i
++, c1
++) {
2546 assert(d0
->size
> d1
->size
);
2547 s
= d0
->size
- d1
->size
;
2548 for (i
= 0; i
< s
; i
++, c0
++) {
2555 r
= memcmp(c0
, c1
, s
);
2558 if (c0
== NSPTR(d0
)) {
2561 assert(c1
== NSPTR(d0
));
2565 "distinct source values are specified: 0x%1$s\n"),
2566 data_to_hexadecimal(d
));
2567 error_deferred
+= 1;
2574 data_to_long(itm_data_t
*data
)
2580 if ((sizeof (itm_place_t
)) < data
->size
) {
2583 for (l
= 0, i
= 0, p
= (unsigned char *)&(data
->place
);