Skip to content

Commit f9596f5

Browse files
author
sf-mensch
committed
fixing compilation of [r5215] - [feature-requests:#459] COLLATING SEQUENCE for [!WITH_DB]
1 parent 93d5877 commit f9596f5

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

libcob/fileio.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ indexed_keydesc (cob_file *f, struct keydesc *kd, cob_file_key *key)
301301
}
302302
/* LCOV_EXCL_STOP */
303303
keylen = 0;
304-
for (part=0; part < key->count_components; part++) {
304+
for (part = 0; part < key->count_components; part++) {
305305
struct keypart *k_part = &kd->k_part[part];
306306
k_part->kp_start = key->component[part]->data - f->record->data;
307307
k_part->kp_leng = key->component[part]->size;
@@ -725,6 +725,18 @@ struct indexed_file {
725725
DB_LOCK bdb_record_lock;
726726
};
727727

728+
/* collation aware key comparision,
729+
currently only used for BDB, likely used in general later */
730+
static int
731+
indexed_key_compare (const unsigned char *k1, const unsigned char *k2,
732+
size_t sz, const unsigned char *col)
733+
{
734+
if (col) {
735+
return cob_cmps (k1, k2, sz, col);
736+
}
737+
return memcmp (k1, k2, sz);
738+
}
739+
728740
/* Return total length of the key */
729741
static int
730742
bdb_keylen (cob_file *f, int idx)
@@ -899,6 +911,21 @@ bdb_close_index (cob_file *f, int index)
899911
return 1;
900912
}
901913

914+
static int
915+
bdb_bt_compare (DB *db, const DBT *k1, const DBT *k2)
916+
{
917+
const unsigned char *col = (unsigned char *)DBT_GET_APP_DATA(k1);
918+
/* LCOV_EXCL_START */
919+
if (col == NULL) {
920+
cob_runtime_error ("bdb_bt_compare was set but no collating sequence was stored in DBT");
921+
}
922+
if (k1->size != k2->size) {
923+
cob_runtime_error ("bdb_bt_compare was given keys of different length");
924+
}
925+
/* LCOV_EXCL_STOP */
926+
return indexed_key_compare (k1->data, k2->data, k2->size, col);
927+
}
928+
902929
#endif /* WITH_DB */
903930

904931

@@ -4162,31 +4189,6 @@ indexed_file_delete (cob_file *f, const char *filename)
41624189
#endif
41634190
}
41644191

4165-
static int
4166-
indexed_key_compare (const unsigned char *k1, const unsigned char *k2,
4167-
size_t sz, const unsigned char *col)
4168-
{
4169-
if (col == NULL) {
4170-
return memcmp (k1, k2, sz);
4171-
} else {
4172-
return cob_cmps (k1, k2, sz, col);
4173-
}
4174-
}
4175-
4176-
static int
4177-
bdb_bt_compare(DB *db, const DBT *k1, const DBT *k2)
4178-
{
4179-
const unsigned char *col = (unsigned char *)DBT_GET_APP_DATA(k1);
4180-
/* LCOV_EXCL_START */
4181-
if (col == NULL) {
4182-
cob_runtime_error ("bdb_bt_compare was set but no collating sequence was stored in DBT");
4183-
}
4184-
if (k1->size != k2->size) {
4185-
cob_runtime_error ("bdb_bt_compare was given keys of different length");
4186-
}
4187-
/* LCOV_EXCL_STOP */
4188-
return indexed_key_compare(k1->data, k2->data, k2->size, col);
4189-
}
41904192

41914193
/* OPEN INDEXED file */
41924194

0 commit comments

Comments
 (0)