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]
25 * Copyright (c) 1988-2001 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
36 #include "db_headers.h"
37 #include "db_table.h" /* must come before db_entry */
41 #define PRINT_WIDTH 32
44 print_entry(entryp location
, entry_object
*e
)
46 printf("entry at location %d: \n", location
);
49 printf("\tnull object\n");
53 int size
= e
->en_cols
.en_cols_len
, i
, j
, col_width
;
54 entry_col
* entry
= e
->en_cols
.en_cols_val
;
56 printf("\ttype: %s\n", e
->en_type
? e
->en_type
: "none");
57 printf("\tnumber of columns: %d\n", size
);
59 for (i
= 0; i
< size
; i
++) {
60 printf("\t\t%d: flags=0x%x, length=%d, value=",
61 i
, entry
[i
].ec_flags
, entry
[i
].ec_value
.ec_value_len
);
62 col_width
= ((entry
[i
].ec_value
.ec_value_len
> PRINT_WIDTH
) ?
63 PRINT_WIDTH
: entry
[i
].ec_value
.ec_value_len
);
64 for (j
= 0; j
< col_width
; j
++) {
65 if (entry
[i
].ec_value
.ec_value_val
[j
] < 32) {
67 putchar(entry
[i
].ec_value
.ec_value_val
[j
]+32);
69 putchar(entry
[i
].ec_value
.ec_value_val
[j
]);
78 new_entry(entry_object
*old
)
80 entry_object
* newobj
= new entry_object
;
82 FATAL3("new_entry:: cannot allocate space", DB_MEMORY_LIMIT
,
85 if (copy_entry(old
, newobj
))
94 copy_entry(entry_object
* old
, entry_object
*nb
)
98 entry_col
*cols
, *newcols
= NULL
;
100 if (old
== NULL
) return FALSE
;
102 if (old
->en_type
== NULL
)
105 nb
->en_type
= strdup(old
->en_type
);
106 if (nb
->en_type
== NULL
)
108 "copy_entry: cannot allocate space for entry type",
109 DB_MEMORY_LIMIT
, FALSE
);
112 num_cols
= old
->en_cols
.en_cols_len
;
113 cols
= old
->en_cols
.en_cols_val
;
115 nb
->en_cols
.en_cols_val
= NULL
;
117 newcols
= new entry_col
[num_cols
];
118 if (newcols
== NULL
) {
121 FATAL3("copy_entry: cannot allocate space for columns",
122 DB_MEMORY_LIMIT
, FALSE
);
124 for (j
= 0; j
< num_cols
; j
++) {
125 newcols
[j
].ec_flags
= cols
[j
].ec_flags
;
126 tlen
= newcols
[j
].ec_value
.ec_value_len
=
127 cols
[j
].ec_value
.ec_value_len
;
128 newcols
[j
].ec_value
.ec_value_val
= new char[ tlen
];
129 if (newcols
[j
].ec_value
.ec_value_val
== NULL
) {
130 // cleanup space already allocated
133 for (i
= 0; i
< j
; i
++)
134 delete newcols
[i
].ec_value
.ec_value_val
;
137 "copy_entry: cannot allocate space for column value",
138 DB_MEMORY_LIMIT
, FALSE
);
140 memcpy(newcols
[j
].ec_value
.ec_value_val
,
141 cols
[j
].ec_value
.ec_value_val
,
145 nb
->en_cols
.en_cols_len
= num_cols
;
146 nb
->en_cols
.en_cols_val
= newcols
;
151 free_entry(entry_object
* obj
)
158 num_cols
= obj
->en_cols
.en_cols_len
;
159 cols
= obj
->en_cols
.en_cols_val
;
160 for (i
= 0; i
< num_cols
; i
++)
161 if (cols
[i
].ec_value
.ec_value_val
!= NULL
)
162 delete cols
[i
].ec_value
.ec_value_val
;
172 sameEntry(entry_object
*a
, entry_object
*b
) {
180 if (a
->en_type
!= 0 && b
->en_type
!= 0) {
181 if (strcmp(a
->en_type
, b
->en_type
) != 0)
183 } else if (a
->en_type
!= b
->en_type
) {
187 if (a
->en_cols
.en_cols_len
!= b
->en_cols
.en_cols_len
)
190 for (i
= 0; i
< a
->en_cols
.en_cols_len
; i
++) {
191 if (a
->en_cols
.en_cols_val
[i
].ec_flags
!=
192 b
->en_cols
.en_cols_val
[i
].ec_flags
)
194 if (a
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_len
!=
195 b
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_len
)
197 if (memcmp(a
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_val
,
198 b
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_val
,
199 a
->en_cols
.en_cols_val
[i
].ec_value
.ec_value_len
) != 0)