diff --git a/src/alice/alice.cpp b/src/alice/alice.cpp index d0fd014d28..812f05bc04 100644 --- a/src/alice/alice.cpp +++ b/src/alice/alice.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: alice.cpp,v 1.36 2003-09-22 14:11:14 brodsom Exp $ +// $Id: alice.cpp,v 1.37 2003-09-25 11:48:56 robocop Exp $ // // 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" // conditionals, as the engine now fully supports @@ -105,7 +105,7 @@ static bool fAnsiCP = false; static void ALICE_error(USHORT number); // overloaded to keep down param count static inline void translate_cp(TEXT* sz); -static void expand_filename(TEXT*, TEXT*); +static void expand_filename(const TEXT*, TEXT*); #ifndef SUPERSERVER static int output_main(SLONG, UCHAR*); #endif @@ -182,12 +182,6 @@ int common_main(int argc, pfn_svc_output output_proc, SLONG output_data) { - IN_SW_TAB table = alice_in_sw_table; - - bool error; - TEXT* database; - TEXT string[512]; - ULONG switches; #ifdef SERVICE_REDIRECT SLONG redir_in; SLONG redir_out; @@ -226,7 +220,7 @@ int common_main(int argc, tdgbl->sw_service_thd = false; tdgbl->service_blk = NULL; tdgbl->status = - /* TMN: cast away volatile */ + // TMN: cast away volatile (long *) tdgbl->status_vector; if (argc > 1 && !strcmp(argv[1], "-svc")) { @@ -287,18 +281,23 @@ int common_main(int argc, // Start by parsing switches - error = false; - switches = 0; + bool error = false; + ULONG switches = 0; tdgbl->ALICE_data.ua_shutdown_delay = 0; - database = NULL; + TEXT* database = NULL; + TEXT string[512]; + argv++; + // tested outside the loop + const in_sw_tab_t* table = alice_in_sw_table; while (--argc > 0) { if ((*argv)[0] != '-') { if (database) { - ALICE_error(1, database, 0, 0, 0, 0); /* msg 1: "data base file name (%s) already given", */ + ALICE_error(1, database, 0, 0, 0, 0); + // msg 1: "data base file name (%s) already given", } database = *argv++; @@ -314,7 +313,7 @@ int common_main(int argc, #endif continue; } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (!string[1]) { continue; } @@ -322,7 +321,7 @@ int common_main(int argc, { const TEXT* p = (TEXT*) table->in_sw_name; if (!p) { - ALICE_print(2, *--argv, 0, 0, 0, 0); /* msg 2: invalid switch %s */ + ALICE_print(2, *--argv, 0, 0, 0, 0); // msg 2: invalid switch %s error = true; break; } @@ -342,11 +341,11 @@ int common_main(int argc, tdgbl->ALICE_data.ua_debug++; } if (table->in_sw_value == sw_z) { - ALICE_print(3, GDS_VERSION, 0, 0, 0, 0); /* msg 3: gfix version %s */ + ALICE_print(3, GDS_VERSION, 0, 0, 0, 0); // msg 3: gfix version %s } if ((table->in_sw_incompatibilities & switches) || (table->in_sw_requires && !(table->in_sw_requires & switches))) { - ALICE_print(4, 0, 0, 0, 0, 0); /* msg 4: incompatible switch combination */ + ALICE_print(4, 0, 0, 0, 0, 0); // msg 4: incompatible switch combination error = true; break; } @@ -354,53 +353,53 @@ int common_main(int argc, if (table->in_sw_value & sw_begin_log) { if (--argc <= 0) { - ALICE_error(5); /* msg 5: replay log pathname required */ + ALICE_error(5); // msg 5: replay log pathname required } - expand_filename(*argv++, /* TMN: cast away volatile */ + expand_filename(*argv++, // TMN: cast away volatile (TEXT *) tdgbl->ALICE_data.ua_log_file); } if (table->in_sw_value & (sw_buffers)) { if (--argc <= 0) { - ALICE_error(6); /* msg 6: number of page buffers for cache required */ + ALICE_error(6); // msg 6: number of page buffers for cache required } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if ((!(tdgbl->ALICE_data.ua_page_buffers = atoi(string))) && (strcmp(string, "0"))) { - ALICE_error(7); /* msg 7: numeric value required */ + ALICE_error(7); // msg 7: numeric value required } if (tdgbl->ALICE_data.ua_page_buffers < 0) { - ALICE_error(8); /* msg 8: positive numeric value required */ + ALICE_error(8); // msg 8: positive numeric value required } } if (table->in_sw_value & (sw_housekeeping)) { if (--argc <= 0) { - ALICE_error(113); /* msg 113: dialect number required */ + ALICE_error(113); // msg 113: dialect number required } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if ((!(tdgbl->ALICE_data.ua_sweep_interval = atoi(string))) && (strcmp(string, "0"))) { - ALICE_error(7); /* msg 7: numeric value required */ + ALICE_error(7); // msg 7: numeric value required } if (tdgbl->ALICE_data.ua_sweep_interval < 0) { - ALICE_error(8); /* msg 8: positive numeric value required */ + ALICE_error(8); // msg 8: positive numeric value required } } if (table->in_sw_value & (sw_set_db_dialect)) { if (--argc <= 0) { - ALICE_error(113); /* msg 113: dialect info is required XXX */ + ALICE_error(113); // msg 113: dialect info is required XXX } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if ((!(tdgbl->ALICE_data.ua_db_SQL_dialect = atoi(string))) && (strcmp(string, "0"))) { - ALICE_error(7); /* msg 7: numeric value required */ + ALICE_error(7); // msg 7: numeric value required } // JMB: Removed because tdgbl->ALICE_data.ua_db_SQL_dialect is @@ -416,7 +415,7 @@ int common_main(int argc, if (--argc <= 0) { ALICE_error(10); /* msg 10: transaction number or "all" required */ } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (!(tdgbl->ALICE_data.ua_transaction = atoi(string))) { if (strcmp(string, "all")) { ALICE_error(10); /* msg 10: transaction number or "all" required */ @@ -430,7 +429,7 @@ int common_main(int argc, if (--argc <= 0) { ALICE_error(11); /* msg 11: "sync" or "async" required */ } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (!strcmp(string, ALICE_SW_SYNC)) { tdgbl->ALICE_data.ua_force = true; } else if (!strcmp(string, ALICE_SW_ASYNC)) { @@ -444,7 +443,7 @@ int common_main(int argc, if (--argc <= 0) { ALICE_error(12); /* msg 12: "full" or "reserve" required */ } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (!strcmp(string, "full")) { tdgbl->ALICE_data.ua_use = true; } else if (!strcmp(string, "reserve")) { @@ -456,7 +455,7 @@ int common_main(int argc, if (table->in_sw_value & sw_user) { if (--argc <= 0) { - ALICE_error(13); /* msg 13: user name required */ + ALICE_error(13); // msg 13: user name required } tdgbl->ALICE_data.ua_user = const_cast(reinterpret_cast(*argv++)); @@ -464,7 +463,7 @@ int common_main(int argc, if (table->in_sw_value & sw_password) { if (--argc <= 0) { - ALICE_error(14); /* msg 14: password required */ + ALICE_error(14); // msg 14: password required } tdgbl->ALICE_data.ua_password = const_cast(reinterpret_cast(*argv++)); @@ -472,9 +471,9 @@ int common_main(int argc, if (table->in_sw_value & sw_disable) { if (--argc <= 0) { - ALICE_error(15); /* msg 15: subsystem name */ + ALICE_error(15); // msg 15: subsystem name } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (strcmp(string, "wal")) { ALICE_error(16); /* msg 16: "wal" required */ } @@ -482,18 +481,18 @@ int common_main(int argc, if (table->in_sw_value & (sw_attach | sw_force | sw_tran | sw_cache)) { if (--argc <= 0) { - ALICE_error(17); /* msg 17: number of seconds required */ + ALICE_error(17); // msg 17: number of seconds required } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if ((!(tdgbl->ALICE_data.ua_shutdown_delay = atoi(string))) && (strcmp(string, "0"))) { - ALICE_error(7); /* msg 7: numeric value required */ + ALICE_error(7); // msg 7: numeric value required } if (tdgbl->ALICE_data.ua_shutdown_delay < 0 || tdgbl->ALICE_data.ua_shutdown_delay > 32767) { - ALICE_error(18); /* msg 18: numeric value between 0 and 32767 inclusive required */ + ALICE_error(18); // msg 18: numeric value between 0 and 32767 inclusive required } } @@ -501,7 +500,7 @@ int common_main(int argc, if (--argc <= 0) { ALICE_error(110); /* msg 110: "read_only" or "read_write" required */ } - ALICE_down_case(*argv++, string); + ALICE_down_case(*argv++, string, sizeof(string)); if (!strcmp(string, ALICE_SW_MODE_RO)) { tdgbl->ALICE_data.ua_read_only = true; } else if (!strcmp(string, ALICE_SW_MODE_RW)) { @@ -518,7 +517,7 @@ int common_main(int argc, if ((switches & sw_shut) && !(switches & ((sw_attach | sw_force | sw_tran | sw_cache)))) { - ALICE_error(19); /* msg 19: must specify type of shutdown */ + ALICE_error(19); // msg 19: must specify type of shutdown } // catch the case where -z is only command line option @@ -529,7 +528,7 @@ int common_main(int argc, if (!switches || !(switches & ~(sw_user | sw_password))) { #ifndef SUPERSERVER - ALICE_print(20, 0, 0, 0, 0, 0); /* msg 20: please retry, specifying an option */ + ALICE_print(20, 0, 0, 0, 0, 0); // msg 20: please retry, specifying an option #endif error = true; } @@ -550,7 +549,7 @@ int common_main(int argc, } if (!database) { - ALICE_error(23); /* msg 23: please retry, giving a database name */ + ALICE_error(23); // msg 23: please retry, giving a database name } // generate the database parameter block for the attach, @@ -609,13 +608,13 @@ int common_main(int argc, int exit_code = tdgbl->exit_code; - /* Close the status output file */ + // Close the status output file if (tdgbl->sw_redirect == REDIRECT && tdgbl->output_file != NULL) { ib_fclose(tdgbl->output_file); tdgbl->output_file = NULL; } - /* Free all unfreed memory used by Gfix itself */ + // Free all unfreed memory used by Gfix itself ALLA_fini(); RESTORE_THREAD_DATA; @@ -627,7 +626,7 @@ int common_main(int argc, gds_alloc_report(0, __FILE__, __LINE__); #endif - /* All returns occur from this point - even normal returns */ + // All returns occur from this point - even normal returns return exit_code; } // catch @@ -640,11 +639,10 @@ int common_main(int argc, // Copy a string, down casing as we go. // -void ALICE_down_case(TEXT * in, TEXT * out) +void ALICE_down_case(const TEXT* in, TEXT* out, const size_t buf_size) { - TEXT c; - - while (c = *in++) { + const TEXT* const end = out + buf_size - 1; + for (TEXT c = *in++; c && out < end; c = *in++) { *out++ = (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } *out = 0; @@ -657,11 +655,11 @@ void ALICE_down_case(TEXT * in, TEXT * out) // void ALICE_print(USHORT number, - TEXT* arg1, - TEXT* arg2, - TEXT* arg3, - TEXT* arg4, - TEXT* arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { TEXT buffer[256]; @@ -678,14 +676,11 @@ void ALICE_print(USHORT number, // to allow redirecting output. // -void ALICE_print_status(ISC_STATUS* status_vector) +void ALICE_print_status(const ISC_STATUS* status_vector) { - ISC_STATUS* vector; - SCHAR s[1024]; - if (status_vector) { - vector = status_vector; + const ISC_STATUS* vector = status_vector; #ifdef SUPERSERVER int i = 0, j; TGBL tdgbl = GET_THREAD_DATA; @@ -699,11 +694,13 @@ void ALICE_print_status(ISC_STATUS* status_vector) } } #endif + + SCHAR s[1024]; isc_interprete(s, &vector); translate_cp(s); alice_output("%s\n", s); - /* Continuation of error */ + // Continuation of error s[0] = '-'; while (isc_interprete(s + 1, &vector)) { translate_cp(s); @@ -719,11 +716,11 @@ void ALICE_print_status(ISC_STATUS* status_vector) // void ALICE_error(USHORT number, - TEXT* arg1, - TEXT* arg2, - TEXT* arg3, - TEXT* arg4, - TEXT* arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { TGBL tdgbl = GET_THREAD_DATA; TEXT buffer[256]; @@ -813,9 +810,9 @@ static inline void translate_cp(TEXT* sz) // // Fully expand a file name. If the file doesn't exist, do something // intelligent. -// +// CVC: The above comment is either a joke or a copy/paste. -static void expand_filename(TEXT * filename, TEXT * expanded_name) +static void expand_filename(const TEXT* filename, TEXT* expanded_name) { strcpy(expanded_name, filename); } diff --git a/src/alice/alice_meta.epp b/src/alice/alice_meta.epp index 884c7dec0d..0305776c59 100644 --- a/src/alice/alice_meta.epp +++ b/src/alice/alice_meta.epp @@ -4,7 +4,7 @@ *____________________________________________________________ * * PROGRAM: Alice (All Else) Utility - * MODULE: met.e + * MODULE: alice_meta.epp * DESCRIPTION: Metadata lookup routines * * The contents of this file are subject to the Interbase Public @@ -27,7 +27,7 @@ * *____________________________________________________________ * - * $Id: alice_meta.epp,v 1.20 2003-09-23 19:47:22 brodsom Exp $ + * $Id: alice_meta.epp,v 1.21 2003-09-25 11:48:57 robocop Exp $ */ #include "firebird.h" @@ -69,18 +69,18 @@ static USHORT snarf_blob(SLONG[2], USHORT, TEXT *); fields in system relations */ -typedef struct rfr_tab_t { +struct rfr_tab_t { TEXT *relation; TEXT *field; int bit_mask; -} *RFR_TAB; +}; -static rfr_tab_t rfr_table[] = { +static const rfr_tab_t rfr_table[] = { { "RDB$TRANSACTIONS", "RDB$TRANSACTION_DESCRIPTION", CAP_transactions }, { 0, 0, 0 } }; -static inline void return_error(ISC_STATUS *user_status) +static inline void return_error(ISC_STATUS* user_status) { ALICE_print_status(gds_status); Firebird::status_exception::raise(0); @@ -92,12 +92,10 @@ static inline void return_error(ISC_STATUS *user_status) * Drop all the entries from RDB$LOG_FILES */ -void MET_disable_wal(ISC_STATUS * user_status, isc_db_handle handle) +void MET_disable_wal(ISC_STATUS* user_status, isc_db_handle handle) { FRBRD *request = NULL; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; if (!(DB = handle)) return; @@ -107,7 +105,8 @@ void MET_disable_wal(ISC_STATUS * user_status, isc_db_handle handle) return_error(user_status); END_ERROR; FOR(REQUEST_HANDLE request) - X IN RDB$LOG_FILES ERASE X; + X IN RDB$LOG_FILES + ERASE X; END_FOR COMMIT ON_ERROR @@ -123,15 +122,14 @@ void MET_disable_wal(ISC_STATUS * user_status, isc_db_handle handle) * already been attached. */ -void MET_get_state(ISC_STATUS * user_status, TDR trans) +void MET_get_state(ISC_STATUS* user_status, TDR trans) { - FRBRD *request = NULL; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + FRBRD* request = NULL; + TGBL tdgbl = GET_THREAD_DATA; if (!(DB = trans->tdr_db_handle) || - !(trans->tdr_db_caps & CAP_transactions)) { + !(trans->tdr_db_caps & CAP_transactions)) + { trans->tdr_state = TRA_unknown; return; } @@ -169,14 +167,11 @@ void MET_get_state(ISC_STATUS * user_status, TDR trans) * in other databases. */ -TDR MET_get_transaction(ISC_STATUS * user_status, isc_db_handle handle, SLONG id) +TDR MET_get_transaction(ISC_STATUS* user_status, isc_db_handle handle, SLONG id) { - FRBRD *request = NULL; + FRBRD* request = NULL; TDR trans = NULL; - USHORT capabilities; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; if (!(DB = handle)) return 0; @@ -186,7 +181,7 @@ TDR MET_get_transaction(ISC_STATUS * user_status, isc_db_handle handle, SLONG id return_error(user_status); END_ERROR; - capabilities = get_capabilities(user_status); + const USHORT capabilities = get_capabilities(user_status); if (capabilities & CAP_transactions) { FOR(REQUEST_HANDLE request) @@ -223,11 +218,9 @@ TDR MET_get_transaction(ISC_STATUS * user_status, isc_db_handle handle, SLONG id * the database for a particular transaction. */ -void MET_set_capabilities(ISC_STATUS * user_status, TDR trans) +void MET_set_capabilities(ISC_STATUS* user_status, TDR trans) { - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; if (!(DB = trans->tdr_db_handle)) return; @@ -251,21 +244,16 @@ void MET_set_capabilities(ISC_STATUS * user_status, TDR trans) * Eat a string with a byte-encoded length. */ -static STR alloc_string(TEXT ** ptr) +static STR alloc_string(TEXT** ptr) { - TEXT *p, *q; - USHORT length; - STR string; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; + TEXT* p = *ptr; - p = *ptr; + USHORT length = (USHORT) *p++; + STR string = FB_NEW_RPT(*tdgbl->ALICE_default_pool, length + 1) str; - length = (USHORT) * p++; - string = FB_NEW_RPT(*tdgbl->ALICE_default_pool, length + 1) str; - - q = (TEXT *) string->str_data; + TEXT* q = (TEXT *) string->str_data; while (length--) *q++ = *p++; *q = 0; @@ -283,25 +271,21 @@ static STR alloc_string(TEXT ** ptr) * the database for a particular transaction. */ -static USHORT get_capabilities(ISC_STATUS * user_status) +static USHORT get_capabilities(ISC_STATUS* user_status) { - FRBRD *req; - RFR_TAB rel_field_table; USHORT capabilities = CAP_none; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; +// Look for desired fields in system relations + FRBRD* req = NULL; - req = NULL; - -/* Look for desired fields in system relations */ - - for (rel_field_table = rfr_table; rel_field_table->relation; - rel_field_table++) { - FOR(REQUEST_HANDLE req) x IN DB. - RDB$RELATION_FIELDS WITH x.RDB$RELATION_NAME = - rel_field_table->relation AND x.RDB$FIELD_NAME = - rel_field_table->field capabilities |= rel_field_table->bit_mask; + for (const rfr_tab_t* rel_field_table = rfr_table; rel_field_table->relation; + rel_field_table++) + { + FOR(REQUEST_HANDLE req) x IN DB.RDB$RELATION_FIELDS + WITH x.RDB$RELATION_NAME = rel_field_table->relation + AND x.RDB$FIELD_NAME = rel_field_table->field + capabilities |= rel_field_table->bit_mask; END_FOR ON_ERROR return_error(user_status); @@ -328,25 +312,22 @@ static TDR get_description(SLONG blob_id[2]) { SLONG id_length, id; USHORT length; - TEXT buffer[1024], *bigger_buffer, *p; - TDR trans, ptr; - STR host_site, database_path; - TGBL tdgbl; + TEXT buffer[1024], *bigger_buffer; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - p = buffer; + TEXT* p = buffer; if (length = snarf_blob(blob_id, (USHORT) sizeof(buffer), buffer)) { p = bigger_buffer = (TEXT *) gds__alloc((SLONG) length); snarf_blob(blob_id, length, bigger_buffer); } - trans = NULL; - host_site = database_path = NULL; - -/* skip version number */ + TDR trans = NULL; + STR host_site = NULL, database_path = NULL; +// skip version number p++; + + TDR ptr; while (*p) switch (*p++) { @@ -401,11 +382,9 @@ static void parse_fullpath(TDR trans) { TEXT *start, *p, *q, *end; USHORT length; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - -/* start at the end of the full pathname */ +// start at the end of the full pathname start = p = (TEXT*) trans->tdr_fullpath->str_data; while (*p) @@ -447,7 +426,7 @@ static void parse_fullpath(TDR trans) p -= 2; trans->tdr_filename = p + 1; - /* now find the last remote node in the chain */ + // now find the last remote node in the chain while (p > start && (*p == ':' || *p == '^' || *p == '@')) p--; @@ -478,28 +457,24 @@ static USHORT snarf_blob(SLONG blob_id[2], USHORT buffer_length, TEXT * buffer) { USHORT returned_length; - TEXT *ptr, *end; ISC_STATUS status; - FRBRD *blob; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; if (buffer_length) buffer[0] = 0; if (buffer_length > 1) buffer[1] = 0; - blob = NULL; + FRBRD* blob = NULL; if (gds__open_blob(gds_status, &DB, &gds_trans, &blob, (GDS_QUAD*) blob_id)) { ALICE_print_status(gds_status); return 0; } -/* get the blob into the buffer, if it fits */ +// get the blob into the buffer, if it fits - ptr = buffer; - end = buffer + buffer_length; + TEXT* ptr = buffer; + TEXT* const end = buffer + buffer_length; for (;;) { if (ptr >= end) break; @@ -512,7 +487,7 @@ static USHORT snarf_blob(SLONG blob_id[2], ptr += returned_length; } -/* snarf failed, get length of blob for retry */ +// snarf failed, get length of blob for retry if (!buffer_length) for (;;) { @@ -531,3 +506,4 @@ static USHORT snarf_blob(SLONG blob_id[2], return buffer_length; } + diff --git a/src/alice/alice_proto.h b/src/alice/alice_proto.h index 8d3b5f3f8e..a6c1c447e4 100644 --- a/src/alice/alice_proto.h +++ b/src/alice/alice_proto.h @@ -2,7 +2,7 @@ /* * PROGRAM: Alice (All Else) Utility * MODULE: alice_proto.h - * DESCRIPTION: Prototype header file for alice.c + * DESCRIPTION: Prototype header file for alice.cpp * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file @@ -29,9 +29,12 @@ int ALICE_main(SVC service); #endif -void ALICE_down_case(TEXT*, TEXT*); -void ALICE_print(USHORT, TEXT*, TEXT*, TEXT*, TEXT*, TEXT*); -void ALICE_error(USHORT, TEXT*, TEXT*, TEXT*, TEXT*, TEXT*); -void ALICE_print_status(ISC_STATUS*); +void ALICE_down_case(const TEXT*, TEXT*, const size_t); +void ALICE_print(USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); +void ALICE_error(USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); +void ALICE_print_status(const ISC_STATUS*); #endif // ALICE_ALICE_PROTO_H + diff --git a/src/alice/all.cpp b/src/alice/all.cpp index bd20b98bc1..0472487b04 100644 --- a/src/alice/all.cpp +++ b/src/alice/all.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: all.cpp,v 1.12 2003-09-15 16:25:49 brodsom Exp $ +// $Id: all.cpp,v 1.13 2003-09-25 11:48:57 robocop Exp $ // #include "../alice/all.h" @@ -50,7 +50,7 @@ void ALLA_fini(void) { TGBL tdgbl = GET_THREAD_DATA; - for(tgbl::pool_vec_t::iterator curr = tdgbl->pools.begin(); + for (tgbl::pool_vec_t::iterator curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) { AliceMemoryPool::deletePool(*curr); @@ -70,9 +70,7 @@ void ALLA_fini(void) void ALLA_init(void) { - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; #ifdef NOT_USED_OR_REPLACED tdgbl->ALICE_default_pool = tdgbl->ALICE_permanent_pool = AliceMemoryPool::create_new_pool(); @@ -97,13 +95,10 @@ void AliceMemoryPool::ALLA_push(class blk *object, class lls** stack) * Push an object on an LLS stack. * **************************************/ - class lls* node; - AliceMemoryPool* pool; - TGBL tdgbl = GET_THREAD_DATA; - pool = tdgbl->ALICE_default_pool; + AliceMemoryPool* pool = tdgbl->ALICE_default_pool; - node = pool->lls_cache.newBlock(); + class lls* node = pool->lls_cache.newBlock(); node->lls_object = object; node->lls_next = *stack; *stack = node; @@ -123,15 +118,11 @@ BLK AliceMemoryPool::ALLA_pop(LLS *stack) * further use. * **************************************/ - LLS node; - AliceMemoryPool* pool; - BLK object; - - node = *stack; + LLS node = *stack; *stack = node->lls_next; - object = node->lls_object; + BLK object = node->lls_object; - pool = (AliceMemoryPool*)MemoryPool::blk_pool(node); + AliceMemoryPool* pool = (AliceMemoryPool*)MemoryPool::blk_pool(node); pool->lls_cache.returnBlock(node); return object; @@ -157,7 +148,7 @@ AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent) AliceMemoryPool* pool = new(0, parent) AliceMemoryPool(parent); tgbl::pool_vec_t::iterator curr; - for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + for (curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) { if (!*curr) { @@ -167,7 +158,7 @@ AliceMemoryPool* AliceMemoryPool::create_new_pool(MemoryPool* parent) } tdgbl->pools.resize(tdgbl->pools.size() + 10); - for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + for (curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) { if (!*curr) { @@ -186,7 +177,7 @@ void AliceMemoryPool::deletePool(AliceMemoryPool* pool) { TGBL tdgbl = GET_THREAD_DATA; tgbl::pool_vec_t::iterator curr; - for(curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) + for (curr = tdgbl->pools.begin(); curr != tdgbl->pools.end(); ++curr) { if (*curr == pool) { @@ -197,3 +188,4 @@ void AliceMemoryPool::deletePool(AliceMemoryPool* pool) { pool->lls_cache.~BlockCache(); MemoryPool::deletePool(pool); } + diff --git a/src/alice/exe.cpp b/src/alice/exe.cpp index c4c68ad5fb..01542c841b 100644 --- a/src/alice/exe.cpp +++ b/src/alice/exe.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: exe.cpp,v 1.18 2003-09-22 08:49:45 brodsom Exp $ +// $Id: exe.cpp,v 1.19 2003-09-25 11:48:57 robocop Exp $ // // 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE" // conditionals, as the engine now fully supports @@ -85,29 +85,22 @@ static inline void stuff_dpb_long(UCHAR **d, int blr) int EXE_action(TEXT * database, ULONG switches) { UCHAR dpb[128]; - USHORT dpb_length; - bool error; - FRBRD *handle; - UCHAR error_string[128]; - USHORT i; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; ALLA_init(); - for (i = 0; i < MAX_VAL_ERRORS; i++) + for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) tdgbl->ALICE_data.ua_val_errors[i] = 0; // generate the database parameter block for the attach, // based on the various switches - dpb_length = build_dpb(dpb, switches); + const USHORT dpb_length = build_dpb(dpb, switches); - error = false; - handle = NULL; + bool error = false; + FRBRD* handle = NULL; gds__attach_database(tdgbl->status, 0, database, &handle, dpb_length, - reinterpret_cast (dpb)); + reinterpret_cast(dpb)); SVC_STARTED(tdgbl->service_blk); @@ -118,10 +111,11 @@ int EXE_action(TEXT * database, ULONG switches) ALICE_print_status(tdgbl->status); if (handle != NULL) { + UCHAR error_string[128]; if ((switches & sw_validate) && (tdgbl->status[1] != isc_bug_check)) { gds__database_info(tdgbl->status, &handle, sizeof(val_errors), val_errors, sizeof(error_string), - reinterpret_cast < char *>(error_string)); + reinterpret_cast(error_string)); extract_db_info(error_string); } @@ -145,28 +139,22 @@ int EXE_action(TEXT * database, ULONG switches) int EXE_two_phase(TEXT * database, ULONG switches) { UCHAR dpb[128]; - USHORT dpb_length; - bool error; - FRBRD *handle; - USHORT i; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; ALLA_init(); - for (i = 0; i < MAX_VAL_ERRORS; i++) + for (USHORT i = 0; i < MAX_VAL_ERRORS; i++) tdgbl->ALICE_data.ua_val_errors[i] = 0; // generate the database parameter block for the attach, // based on the various switches - dpb_length = build_dpb(dpb, switches); + const USHORT dpb_length = build_dpb(dpb, switches); - error = false; - handle = NULL; + bool error = false; + FRBRD* handle = NULL; gds__attach_database(tdgbl->status, 0, database, &handle, - dpb_length, reinterpret_cast < char *>(dpb)); + dpb_length, reinterpret_cast(dpb)); SVC_STARTED(tdgbl->service_blk); @@ -196,15 +184,10 @@ int EXE_two_phase(TEXT * database, ULONG switches) static USHORT build_dpb(UCHAR * dpb, ULONG switches) { - UCHAR *dpb2; - USHORT dpb_length; - SSHORT i; TEXT *q; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - dpb2 = dpb; + UCHAR* dpb2 = dpb; *dpb2++ = gds_dpb_version1; *dpb2++ = isc_dpb_gfix_attach; *dpb2++ = 0; @@ -235,12 +218,10 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) else if (switches & sw_housekeeping) { *dpb2++ = gds_dpb_sweep_interval; *dpb2++ = 4; - for (i = 0; i < 4; - i++, tdgbl->ALICE_data.ua_sweep_interval = - tdgbl->ALICE_data.ua_sweep_interval >> 8) + for (int i = 0; i < 4; i++, (tdgbl->ALICE_data.ua_sweep_interval >>= 8)) { - /* TMN: Here we should really have the following assert */ - /* assert(tdgbl->ALICE_data.ua_sweep_interval <= MAX_UCHAR); */ + // TMN: Here we should really have the following assert + // assert(tdgbl->ALICE_data.ua_sweep_interval <= MAX_UCHAR); *dpb2++ = (UCHAR) tdgbl->ALICE_data.ua_sweep_interval; } } @@ -253,12 +234,10 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) else if (switches & sw_buffers) { *dpb2++ = isc_dpb_set_page_buffers; *dpb2++ = 4; - for (i = 0; i < 4; - i++, tdgbl->ALICE_data.ua_page_buffers = - tdgbl->ALICE_data.ua_page_buffers >> 8) + for (int i = 0; i < 4; i++, (tdgbl->ALICE_data.ua_page_buffers >>= 8)) { - /* TMN: Here we should really have the following assert */ - /* assert(tdgbl->ALICE_data.ua_page_buffers <= MAX_UCHAR); */ + // TMN: Here we should really have the following assert + // assert(tdgbl->ALICE_data.ua_page_buffers <= MAX_UCHAR); *dpb2++ = (UCHAR) tdgbl->ALICE_data.ua_page_buffers; } } @@ -300,10 +279,10 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) *dpb2 |= gds_dpb_shut_transaction; dpb2++; *dpb2++ = gds_dpb_shutdown_delay; - *dpb2++ = 2; /* Build room for shutdown delay */ - /* TMN: Here we should really have the following assert */ - /* assert(tdgbl->ALICE_data.ua_page_buffers <= MAX_USHORT); */ - /* or maybe even compare with MAX_SSHORT */ + *dpb2++ = 2; // Build room for shutdown delay + // TMN: Here we should really have the following assert + // assert(tdgbl->ALICE_data.ua_page_buffers <= MAX_USHORT); + // or maybe even compare with MAX_SSHORT *dpb2++ = (UCHAR) tdgbl->ALICE_data.ua_shutdown_delay; *dpb2++ = (UCHAR) (tdgbl->ALICE_data.ua_shutdown_delay >> 8); } @@ -327,8 +306,8 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) if (tdgbl->ALICE_data.ua_user) { *dpb2++ = gds_dpb_user_name; - *dpb2++ = strlen(reinterpret_cast (tdgbl->ALICE_data.ua_user)); - for (q = reinterpret_cast (tdgbl->ALICE_data.ua_user); *q;) + *dpb2++ = strlen(reinterpret_cast(tdgbl->ALICE_data.ua_user)); + for (q = reinterpret_cast(tdgbl->ALICE_data.ua_user); *q;) *dpb2++ = *q++; } @@ -337,12 +316,12 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) *dpb2++ = gds_dpb_password; else *dpb2++ = gds_dpb_password_enc; - *dpb2++ = strlen(reinterpret_cast (tdgbl->ALICE_data.ua_password)); - for (q = reinterpret_cast < TEXT * >(tdgbl->ALICE_data.ua_password); *q;) + *dpb2++ = strlen(reinterpret_cast(tdgbl->ALICE_data.ua_password)); + for (q = reinterpret_cast(tdgbl->ALICE_data.ua_password); *q;) *dpb2++ = *q++; } - dpb_length = dpb2 - dpb; + USHORT dpb_length = dpb2 - dpb; if (dpb_length == 1) dpb_length = 0; @@ -355,24 +334,20 @@ static USHORT build_dpb(UCHAR * dpb, ULONG switches) // Extract database info from string // -static void extract_db_info(UCHAR * db_info_buffer) +static void extract_db_info(UCHAR* db_info_buffer) { UCHAR item; - UCHAR *p; - SLONG length; - TGBL tdgbl; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - p = db_info_buffer; + UCHAR* p = db_info_buffer; while ((item = *p++) != gds_info_end) { - length = gds__vax_integer(p, 2); + const SLONG length = gds__vax_integer(p, 2); p += 2; - /* TMN: Here we should really have the following assert */ - /* assert(length <= MAX_SSHORT); */ - /* for all cases that use 'length' as input to 'gds__vax_integer' */ + // TMN: Here we should really have the following assert + // assert(length <= MAX_SSHORT); + // for all cases that use 'length' as input to 'gds__vax_integer' switch (item) { case isc_info_page_errors: tdgbl->ALICE_data.ua_val_errors[VAL_PAGE_ERRORS] = diff --git a/src/alice/tdr.cpp b/src/alice/tdr.cpp index 9f130cd8bb..f24db5e160 100644 --- a/src/alice/tdr.cpp +++ b/src/alice/tdr.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: tdr.cpp,v 1.23 2003-09-22 08:49:45 brodsom Exp $ +// $Id: tdr.cpp,v 1.24 2003-09-25 11:48:57 robocop Exp $ // // 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete "Apollo" port // @@ -80,7 +80,7 @@ static UCHAR limbo_info[] = { gds_info_limbo, gds_info_end }; USHORT TDR_analyze(TDR trans) { - USHORT state, advice = TRA_none; + USHORT advice = TRA_none; if (trans == NULL) return TRA_none; @@ -88,7 +88,7 @@ USHORT TDR_analyze(TDR trans) // if the tdr for the first transaction is missing, // we can assume it was committed - state = trans->tdr_state; + USHORT state = trans->tdr_state; if (state == TRA_none) state = TRA_commit; else if (state == TRA_unknown) @@ -96,14 +96,16 @@ USHORT TDR_analyze(TDR trans) for (trans = trans->tdr_next; trans; trans = trans->tdr_next) { switch (trans->tdr_state) { - /* an explicitly committed transaction necessitates a check for the - perverse case of a rollback, otherwise a commit if at all possible */ + // an explicitly committed transaction necessitates a check for the + // perverse case of a rollback, otherwise a commit if at all possible case TRA_commit: if (state == TRA_rollback) { - ALICE_print(105, 0, 0, 0, 0, 0); /* msg 105: Warning: Multidatabase transaction is in inconsistent state for recovery. */ - ALICE_print(106, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 106: Transaction %ld was committed, but prior ones were rolled back. */ + ALICE_print(105, 0, 0, 0, 0, 0); + // msg 105: Warning: Multidatabase transaction is in inconsistent state for recovery. + ALICE_print(106, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 106: Transaction %ld was committed, but prior ones were rolled back. return 0; } else @@ -128,9 +130,11 @@ USHORT TDR_analyze(TDR trans) case TRA_rollback: if ((state == TRA_commit) || (state == TRA_none)) { - ALICE_print(105, 0, 0, 0, 0, 0); /* msg 105: Warning: Multidatabase transaction is in inconsistent state for recovery. */ - ALICE_print(107, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 107: Transaction %ld was rolled back, but prior ones were committed. */ + ALICE_print(105, 0, 0, 0, 0, 0); + // msg 105: Warning: Multidatabase transaction is in inconsistent state for recovery. + ALICE_print(107, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 107: Transaction %ld was rolled back, but prior ones were committed. return 0; } @@ -158,8 +162,8 @@ USHORT TDR_analyze(TDR trans) break; default: - ALICE_print(67, reinterpret_cast < char *>(trans->tdr_state), 0, - 0, 0, 0); /* msg 67: Transaction state %d not in valid range. */ + ALICE_print(67, reinterpret_cast(trans->tdr_state), 0, + 0, 0, 0); // msg 67: Transaction state %d not in valid range. return 0; } } @@ -178,16 +182,14 @@ bool TDR_attach_database(ISC_STATUS * status_vector, TDR trans, TEXT * pathname) { - UCHAR dpb[128], *d, *q; - USHORT dpb_length; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + UCHAR dpb[128]; + TGBL tdgbl = GET_THREAD_DATA; if (tdgbl->ALICE_data.ua_debug) - ALICE_print(68, pathname, 0, 0, 0, 0); /* msg 68: ATTACH_DATABASE: attempted attach of %s */ + ALICE_print(68, pathname, 0, 0, 0, 0); + // msg 68: ATTACH_DATABASE: attempted attach of %s - d = dpb; + UCHAR* d = dpb; *d++ = gds_dpb_version1; *d++ = gds_dpb_no_garbage_collect; @@ -197,8 +199,8 @@ bool TDR_attach_database(ISC_STATUS * status_vector, if (tdgbl->ALICE_data.ua_user) { *d++ = gds_dpb_user_name; - *d++ = strlen(reinterpret_cast (tdgbl->ALICE_data.ua_user)); - for (q = tdgbl->ALICE_data.ua_user; *q;) + *d++ = strlen(reinterpret_cast(tdgbl->ALICE_data.ua_user)); + for (const UCHAR* q = tdgbl->ALICE_data.ua_user; *q;) *d++ = *q++; } @@ -208,13 +210,12 @@ bool TDR_attach_database(ISC_STATUS * status_vector, else *d++ = gds_dpb_password_enc; *d++ = - strlen(reinterpret_cast < - const char *>(tdgbl->ALICE_data.ua_password)); - for (q = tdgbl->ALICE_data.ua_password; *q;) + strlen(reinterpret_cast(tdgbl->ALICE_data.ua_password)); + for (const UCHAR* q = tdgbl->ALICE_data.ua_password; *q;) *d++ = *q++; } - dpb_length = d - dpb; + USHORT dpb_length = d - dpb; if (dpb_length == 1) dpb_length = 0; @@ -222,11 +223,11 @@ bool TDR_attach_database(ISC_STATUS * status_vector, gds__attach_database(status_vector, 0, pathname, &trans->tdr_db_handle, dpb_length, - reinterpret_cast < char *>(dpb)); + reinterpret_cast(dpb)); if (status_vector[1]) { if (tdgbl->ALICE_data.ua_debug) { - ALICE_print(69, 0, 0, 0, 0, 0); /* msg 69: failed */ + ALICE_print(69, 0, 0, 0, 0, 0); // msg 69: failed ALICE_print_status(status_vector); } return false; @@ -235,7 +236,7 @@ bool TDR_attach_database(ISC_STATUS * status_vector, MET_set_capabilities(status_vector, trans); if (tdgbl->ALICE_data.ua_debug) - ALICE_print(70, 0, 0, 0, 0, 0); /* msg 70: succeeded */ + ALICE_print(70, 0, 0, 0, 0, 0); // msg 70: succeeded return true; } @@ -251,9 +252,8 @@ bool TDR_attach_database(ISC_STATUS * status_vector, void TDR_get_states(TDR trans) { ISC_STATUS_ARRAY status_vector; - TDR ptr; - for (ptr = trans; ptr; ptr = ptr->tdr_next) + for (TDR ptr = trans; ptr; ptr = ptr->tdr_next) MET_get_state(status_vector, ptr); } @@ -267,10 +267,9 @@ void TDR_get_states(TDR trans) void TDR_shutdown_databases(TDR trans) { - TDR ptr; ISC_STATUS_ARRAY status_vector; - for (ptr = trans; ptr; ptr = ptr->tdr_next) + for (TDR ptr = trans; ptr; ptr = ptr->tdr_next) gds__detach_database(status_vector, &ptr->tdr_db_handle); } @@ -290,31 +289,26 @@ void TDR_shutdown_databases(TDR trans) void TDR_list_limbo(FRBRD *handle, TEXT * name, ULONG switches) { - UCHAR buffer[1024], *ptr; + UCHAR buffer[1024]; ISC_STATUS_ARRAY status_vector; SLONG id; - USHORT item; - bool flag; - USHORT length; TDR trans; - TGBL tdgbl; - - tdgbl = GET_THREAD_DATA; + TGBL tdgbl = GET_THREAD_DATA; if (gds__database_info(status_vector, &handle, sizeof(limbo_info), - reinterpret_cast < char *>(limbo_info), + reinterpret_cast(limbo_info), sizeof(buffer), - reinterpret_cast < char *>(buffer))) { + reinterpret_cast(buffer))) { ALICE_print_status(status_vector); return; } - ptr = buffer; - flag = true; + UCHAR* ptr = buffer; + bool flag = true; while (flag) { - item = *ptr++; - length = (USHORT) gds__vax_integer(ptr, 2); + const USHORT item = *ptr++; + const USHORT length = (USHORT) gds__vax_integer(ptr, 2); ptr += 2; switch (item) { case gds_info_limbo: @@ -327,7 +321,8 @@ void TDR_list_limbo(FRBRD *handle, TEXT * name, ULONG switches) break; } if (!tdgbl->sw_service_thd) - ALICE_print(71, reinterpret_cast < char *>(id), 0, 0, 0, 0); /* msg 71: Transaction %d is in limbo. */ + ALICE_print(71, reinterpret_cast(id), 0, 0, 0, 0); + // msg 71: Transaction %d is in limbo. if (trans = MET_get_transaction(status_vector, handle, id)) { #ifdef SUPERSERVER SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_multi_tra_id); @@ -355,7 +350,8 @@ void TDR_list_limbo(FRBRD *handle, TEXT * name, ULONG switches) case gds_info_truncated: if (!tdgbl->sw_service_thd) - ALICE_print(72, 0, 0, 0, 0, 0); /* msg 72: More limbo transactions than fit. Try again */ + ALICE_print(72, 0, 0, 0, 0, 0); + // msg 72: More limbo transactions than fit. Try again case gds_info_end: flag = false; @@ -363,7 +359,8 @@ void TDR_list_limbo(FRBRD *handle, TEXT * name, ULONG switches) default: if (!tdgbl->sw_service_thd) - ALICE_print(73, reinterpret_cast < char *>(item), 0, 0, 0, 0); /* msg 73: Unrecognized info item %d */ + ALICE_print(73, reinterpret_cast(item), 0, 0, 0, 0); + // msg 73: Unrecognized info item %d } } } @@ -387,14 +384,13 @@ bool TDR_reconnect_multiple(FRBRD *handle, TEXT * name, ULONG switches) { - TDR trans, ptr; ISC_STATUS_ARRAY status_vector; - USHORT advice; bool error = false; // get the state of all the associated transactions - if (!(trans = MET_get_transaction(status_vector, handle, id))) + TDR trans = MET_get_transaction(status_vector, handle, id); + if (!trans) return reconnect(handle, id, name, switches); reattach_databases(trans); @@ -403,7 +399,7 @@ bool TDR_reconnect_multiple(FRBRD *handle, // analyze what to do with them; if the advice contradicts the user's // desire, make them confirm it; otherwise go with the flow. - advice = TDR_analyze(trans); + USHORT advice = TDR_analyze(trans); if (!advice) { print_description(trans); @@ -413,8 +409,9 @@ bool TDR_reconnect_multiple(FRBRD *handle, switch (advice) { case TRA_rollback: if (switches & sw_commit) { - ALICE_print(74, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 74: "A commit of transaction %ld will violate two-phase commit. */ + ALICE_print(74, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 74: A commit of transaction %ld will violate two-phase commit. print_description(trans); switches = ask(); } @@ -423,8 +420,9 @@ bool TDR_reconnect_multiple(FRBRD *handle, else if (switches & sw_two_phase) switches |= sw_rollback; else if (switches & sw_prompt) { - ALICE_print(75, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 75: A rollback of transaction %ld is needed to preserve two-phase commit. */ + ALICE_print(75, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 75: A rollback of transaction %ld is needed to preserve two-phase commit. print_description(trans); switches = ask(); } @@ -432,9 +430,11 @@ bool TDR_reconnect_multiple(FRBRD *handle, case TRA_commit: if (switches & sw_rollback) { - ALICE_print(76, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 76: Transaction %ld has already been partially committed. */ - ALICE_print(77, 0, 0, 0, 0, 0); /* msg 77: A rollback of this transaction will violate two-phase commit. */ + ALICE_print(76, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 76: Transaction %ld has already been partially committed. + ALICE_print(77, 0, 0, 0, 0, 0); + // msg 77: A rollback of this transaction will violate two-phase commit. print_description(trans); switches = ask(); } @@ -444,18 +444,22 @@ bool TDR_reconnect_multiple(FRBRD *handle, switches |= sw_commit; else if (switches & sw_prompt) { - ALICE_print(78, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 78: Transaction %ld has been partially committed. */ - ALICE_print(79, 0, 0, 0, 0, 0); /* msg 79: A commit is necessary to preserve the two-phase commit. */ + ALICE_print(78, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 78: Transaction %ld has been partially committed. + ALICE_print(79, 0, 0, 0, 0, 0); + // msg 79: A commit is necessary to preserve the two-phase commit. print_description(trans); switches = ask(); } break; case TRA_unknown: - ALICE_print(80, 0, 0, 0, 0, 0); /* msg 80: Insufficient information is available to determine */ - ALICE_print(81, reinterpret_cast < char *>(trans->tdr_id), 0, 0, - 0, 0); /* msg 81: a proper action for transaction %ld. */ + ALICE_print(80, 0, 0, 0, 0, 0); + // msg 80: Insufficient information is available to determine + ALICE_print(81, reinterpret_cast(trans->tdr_id), 0, 0, + 0, 0); + // msg 81: a proper action for transaction %ld. print_description(trans); switches = ask(); break; @@ -463,9 +467,11 @@ bool TDR_reconnect_multiple(FRBRD *handle, default: if (!(switches & (sw_commit | sw_rollback))) { - ALICE_print(82, reinterpret_cast < char *>(trans->tdr_id), 0, - 0, 0, 0); /* msg 82: Transaction %ld: All subtransactions have been prepared. */ - ALICE_print(83, 0, 0, 0, 0, 0); /* msg 83: Either commit or rollback is possible. */ + ALICE_print(82, reinterpret_cast(trans->tdr_id), 0, + 0, 0, 0); + // msg 82: Transaction %ld: All subtransactions have been prepared. + ALICE_print(83, 0, 0, 0, 0, 0); + // msg 83: Either commit or rollback is possible. print_description(trans); switches = ask(); } @@ -474,11 +480,11 @@ bool TDR_reconnect_multiple(FRBRD *handle, if (switches != (ULONG) - 1) { - /* now do the required operation with all the subtransactions */ + // now do the required operation with all the subtransactions if (switches & (sw_commit | sw_rollback)) { - for (ptr = trans; ptr; ptr = ptr->tdr_next) + for (TDR ptr = trans; ptr; ptr = ptr->tdr_next) { if (ptr->tdr_state == TRA_limbo) { @@ -490,7 +496,7 @@ bool TDR_reconnect_multiple(FRBRD *handle, } else { - ALICE_print(84, 0, 0, 0, 0, 0); /* msg 84: unexpected end of input */ + ALICE_print(84, 0, 0, 0, 0, 0); // msg 84: unexpected end of input error = true; } @@ -512,13 +518,6 @@ bool TDR_reconnect_multiple(FRBRD *handle, static void print_description(TDR trans) { - TDR ptr; - bool prepared_seen; - -#ifdef SUPERSERVER - int i; -#endif - TGBL tdgbl = GET_THREAD_DATA; if (!trans) @@ -528,11 +527,11 @@ static void print_description(TDR trans) if (!tdgbl->sw_service_thd) { - ALICE_print(92, 0, 0, 0, 0, 0); /* msg 92: Multidatabase transaction: */ + ALICE_print(92, 0, 0, 0, 0, 0); // msg 92: Multidatabase transaction: } - prepared_seen = false; - for (ptr = trans; ptr; ptr = ptr->tdr_next) + bool prepared_seen = false; + for (TDR ptr = trans; ptr; ptr = ptr->tdr_next) { if (ptr->tdr_host_site) { @@ -540,7 +539,7 @@ static void print_description(TDR trans) reinterpret_cast(ptr->tdr_host_site->str_data); #ifndef SUPERSERVER - /* msg 93: Host Site: %s */ + // msg 93: Host Site: %s ALICE_print(93, pszHostSize, 0, 0, 0, 0); #else const size_t nHostSiteLen = strlen(pszHostSize); @@ -548,7 +547,7 @@ static void print_description(TDR trans) SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_host_site); SVC_putc(tdgbl->service_blk, (UCHAR) nHostSiteLen); SVC_putc(tdgbl->service_blk, (UCHAR) (nHostSiteLen >> 8 )); - for (i = 0; i < (int) nHostSiteLen; i++) + for (int i = 0; i < (int) nHostSiteLen; i++) { SVC_putc(tdgbl->service_blk, (UCHAR) pszHostSize[i]); } @@ -558,7 +557,7 @@ static void print_description(TDR trans) if (ptr->tdr_id) { #ifndef SUPERSERVER - /* msg 94: Transaction %ld */ + // msg 94: Transaction %ld ALICE_print(94, reinterpret_cast(ptr->tdr_id), 0, 0, 0, 0); #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_id); @@ -573,7 +572,7 @@ static void print_description(TDR trans) { case TRA_limbo: #ifndef SUPERSERVER - ALICE_print(95, 0, 0, 0, 0, 0); /* msg 95: has been prepared. */ + ALICE_print(95, 0, 0, 0, 0, 0); // msg 95: has been prepared. #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state); SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state_limbo); @@ -583,7 +582,7 @@ static void print_description(TDR trans) case TRA_commit: #ifndef SUPERSERVER - ALICE_print(96, 0, 0, 0, 0, 0); /* msg 96: has been committed. */ + ALICE_print(96, 0, 0, 0, 0, 0); // msg 96: has been committed. #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state); SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state_commit); @@ -592,7 +591,7 @@ static void print_description(TDR trans) case TRA_rollback: #ifndef SUPERSERVER - ALICE_print(97, 0, 0, 0, 0, 0); /* msg 97: has been rolled back. */ + ALICE_print(97, 0, 0, 0, 0, 0); // msg 97: has been rolled back. #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state); SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state_rollback); @@ -601,7 +600,7 @@ static void print_description(TDR trans) case TRA_unknown: #ifndef SUPERSERVER - ALICE_print(98, 0, 0, 0, 0, 0); /* msg 98: is not available. */ + ALICE_print(98, 0, 0, 0, 0, 0); // msg 98: is not available. #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state); SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_state_unknown); @@ -612,12 +611,12 @@ static void print_description(TDR trans) #ifndef SUPERSERVER if (prepared_seen) { - /* msg 99: is not found, assumed not prepared. */ + // msg 99: is not found, assumed not prepared. ALICE_print(99, 0, 0, 0, 0, 0); } else { - /* msg 100: is not found, assumed to be committed. */ + // msg 100: is not found, assumed to be committed. ALICE_print(100, 0, 0, 0, 0, 0); } #endif @@ -630,7 +629,7 @@ static void print_description(TDR trans) reinterpret_cast(ptr->tdr_remote_site->str_data); #ifndef SUPERSERVER - /*msg 101: Remote Site: %s */ + //msg 101: Remote Site: %s ALICE_print(101, pszRemoteSite, 0, 0, 0, 0); #else const size_t nRemoteSiteLen = strlen(pszRemoteSite); @@ -638,7 +637,7 @@ static void print_description(TDR trans) SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_remote_site); SVC_putc(tdgbl->service_blk, (UCHAR) nRemoteSiteLen); SVC_putc(tdgbl->service_blk, (UCHAR) (nRemoteSiteLen >> 8)); - for (i = 0; i < (int) nRemoteSiteLen; i++) + for (int i = 0; i < (int) nRemoteSiteLen; i++) { SVC_putc(tdgbl->service_blk, (UCHAR) pszRemoteSite[i]); } @@ -651,7 +650,7 @@ static void print_description(TDR trans) reinterpret_cast(ptr->tdr_fullpath->str_data); #ifndef SUPERSERVER - /* msg 102: Database Path: %s */ + // msg 102: Database Path: %s ALICE_print(102, pszFullpath, 0, 0, 0, 0); #else const size_t nFullpathLen = strlen(pszFullpath); @@ -659,7 +658,7 @@ static void print_description(TDR trans) SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_db_path); SVC_putc(tdgbl->service_blk, (UCHAR) nFullpathLen); SVC_putc(tdgbl->service_blk, (UCHAR) (nFullpathLen >> 8)); - for (i = 0; i < (int) nFullpathLen; i++) + for (int i = 0; i < (int) nFullpathLen; i++) { SVC_putc(tdgbl->service_blk, (UCHAR) pszFullpath[i]); } @@ -674,7 +673,7 @@ static void print_description(TDR trans) { case TRA_commit: #ifndef SUPERSERVER - /* msg 103: Automated recovery would commit this transaction. */ + // msg 103: Automated recovery would commit this transaction. ALICE_print(103, 0, 0, 0, 0, 0); #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_advise); @@ -684,7 +683,7 @@ static void print_description(TDR trans) case TRA_rollback: #ifndef SUPERSERVER - /* msg 104: Automated recovery would rollback this transaction. */ + // msg 104: Automated recovery would rollback this transaction. ALICE_print(104, 0, 0, 0, 0, 0); #else SVC_putc(tdgbl->service_blk, (UCHAR) isc_spb_tra_advise); @@ -711,31 +710,31 @@ static void print_description(TDR trans) static ULONG ask(void) { - UCHAR response[32], *p; - int c; - ULONG switches; - TGBL tdgbl; + UCHAR response[32]; + char* const resp_ptr = reinterpret_cast(response); + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - switches = 0; + ULONG switches = 0; while (true) { - ALICE_print(85, 0, 0, 0, 0, 0); /* msg 85: Commit, rollback, or neither (c, r, or n)? */ + ALICE_print(85, 0, 0, 0, 0, 0); + // msg 85: Commit, rollback, or neither (c, r, or n)? if (tdgbl->sw_service) ib_putc('\001', ib_stdout); ib_fflush(ib_stdout); + int c; + UCHAR* p; for (p = response; (c = ib_getchar()) != '\n' && c != EOF;) *p++ = c; if (c == EOF && p == response) return (ULONG) - 1; *p = 0; - ALICE_down_case(reinterpret_cast < char *>(response), - reinterpret_cast < char *>(response)); - if (!strcmp(reinterpret_cast < const char *>(response), "n") - || !strcmp(reinterpret_cast < const char *>(response), "c") - || !strcmp(reinterpret_cast < const char *>(response), "r")) + ALICE_down_case(resp_ptr, resp_ptr, sizeof(response)); + if (!strcmp(resp_ptr, "n") || !strcmp(resp_ptr, "c") + || !strcmp(resp_ptr, "r")) + { break; + } } if (response[0] == 'c') @@ -756,19 +755,16 @@ static ULONG ask(void) static void reattach_database(TDR trans) { ISC_STATUS_ARRAY status_vector; - UCHAR buffer[1024], *p, *q, *start; - STR string; - TGBL tdgbl; + UCHAR buffer[1024], *p, *q; + TGBL tdgbl = GET_THREAD_DATA; - tdgbl = GET_THREAD_DATA; - - ISC_get_host(reinterpret_cast < char *>(buffer), sizeof(buffer)); + ISC_get_host(reinterpret_cast(buffer), sizeof(buffer)); // if this is being run from the same host, // try to reconnect using the same pathname - if (!strcmp(reinterpret_cast < const char *>(buffer), - reinterpret_cast < const char *>(trans->tdr_host_site->str_data))) + if (!strcmp(reinterpret_cast(buffer), + reinterpret_cast(trans->tdr_host_site->str_data))) { if (TDR_attach_database(status_vector, trans, reinterpret_cast @@ -777,8 +773,6 @@ static void reattach_database(TDR trans) return; } } - - // try going through the previous host with all available // protocols, using chaining to try the same method of // attachment originally used from that host @@ -786,15 +780,12 @@ static void reattach_database(TDR trans) else if (trans->tdr_host_site) { for (p = buffer, q = trans->tdr_host_site->str_data; *q;) *p++ = *q++; - start = p; - - p = start; *p++ = ':'; for (q = trans->tdr_fullpath->str_data; *q;) *p++ = *q++; *q = 0; if (TDR_attach_database(status_vector, trans, - reinterpret_cast < char *>(buffer))) + reinterpret_cast(buffer))) { return; } @@ -806,15 +797,12 @@ static void reattach_database(TDR trans) if (trans->tdr_remote_site) { for (p = buffer, q = trans->tdr_remote_site->str_data; *q;) *p++ = *q++; - start = p; - - p = start; *p++ = ':'; for (q = (UCHAR *) trans->tdr_filename; *q;) *p++ = *q++; *q = 0; if (TDR_attach_database (status_vector, trans, - reinterpret_cast < char *>(buffer))) + reinterpret_cast(buffer))) { return; } @@ -823,12 +811,13 @@ static void reattach_database(TDR trans) // we have failed to reattach; notify the user // and let them try to succeed where we have failed - ALICE_print(86, reinterpret_cast < char *>(trans->tdr_id), 0, 0, 0, 0); /* msg 86: Could not reattach to database for transaction %ld. */ - ALICE_print(87, reinterpret_cast < char *>(trans->tdr_fullpath->str_data), - 0, 0, 0, 0); /* msg 87: Original path: %s */ + ALICE_print(86, reinterpret_cast(trans->tdr_id), 0, 0, 0, 0); + // msg 86: Could not reattach to database for transaction %ld. + ALICE_print(87, reinterpret_cast(trans->tdr_fullpath->str_data), + 0, 0, 0, 0); // msg 87: Original path: %s for (;;) { - ALICE_print(88, 0, 0, 0, 0, 0); /* msg 88: Enter a valid path: */ + ALICE_print(88, 0, 0, 0, 0, 0); // msg 88: Enter a valid path: for (p = buffer; (*p = ib_getchar()) != '\n'; p++); *p = 0; if (!buffer[0]) @@ -839,7 +828,7 @@ static void reattach_database(TDR trans) if (TDR_attach_database(status_vector, trans, reinterpret_cast(p))) { - string = FB_NEW_RPT(*tdgbl->ALICE_default_pool, + STR string = FB_NEW_RPT(*tdgbl->ALICE_default_pool, strlen(reinterpret_cast(p)) + 1) str; strcpy(reinterpret_cast(string->str_data), reinterpret_cast(p)); @@ -848,7 +837,7 @@ static void reattach_database(TDR trans) trans->tdr_filename = (TEXT *) string->str_data; return; } - ALICE_print(89, 0, 0, 0, 0, 0); /* msg 89: Attach unsuccessful. */ + ALICE_print(89, 0, 0, 0, 0, 0); // msg 89: Attach unsuccessful. } } @@ -862,9 +851,7 @@ static void reattach_database(TDR trans) static void reattach_databases(TDR trans) { - TDR ptr; - - for (ptr = trans; ptr; ptr = ptr->tdr_next) + for (TDR ptr = trans; ptr; ptr = ptr->tdr_next) reattach_database(ptr); } @@ -880,14 +867,12 @@ static bool reconnect(FRBRD *handle, TEXT * name, ULONG switches) { - FRBRD *transaction; - SLONG id; ISC_STATUS_ARRAY status_vector; - id = gds__vax_integer((UCHAR *) & number, 4); - transaction = NULL; + SLONG id = gds__vax_integer((UCHAR *) & number, 4); + FRBRD* transaction = NULL; if (gds__reconnect_transaction(status_vector, &handle, &transaction, - sizeof(id), reinterpret_cast (&id))) { + sizeof(id), reinterpret_cast(&id))) { ALICE_print(90, name, 0, 0, 0, 0); // msg 90: failed to reconnect to a transaction in database %s ALICE_print_status(status_vector); @@ -895,7 +880,7 @@ static bool reconnect(FRBRD *handle, } if (!(switches & (sw_commit | sw_rollback))) { - ALICE_print(91, reinterpret_cast < char *>(number), 0, 0, 0, 0); + ALICE_print(91, reinterpret_cast(number), 0, 0, 0, 0); // msg 91: Transaction %ld: switches = ask(); if (switches == (ULONG) - 1) { @@ -920,3 +905,4 @@ static bool reconnect(FRBRD *handle, return false; } + diff --git a/src/burp/backup.epp b/src/burp/backup.epp index b6c33f56c6..95f14c921b 100644 --- a/src/burp/backup.epp +++ b/src/burp/backup.epp @@ -37,7 +37,7 @@ */ /* -$Id: backup.epp,v 1.40 2003-09-23 19:47:50 brodsom Exp $ +$Id: backup.epp,v 1.41 2003-09-25 11:48:59 robocop Exp $ */ #include "firebird.h" @@ -158,7 +158,7 @@ enum backup_capabilities }; #ifdef DEBUG -UCHAR debug_on = 0; /* able to turn this on in debug mode */ +UCHAR debug_on = 0; // able to turn this on in debug mode #endif @@ -268,7 +268,7 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) gds_trans = NULL; BURP_verbose(130, NULL, NULL, NULL, NULL, NULL); - /* msg 130 starting transaction */ + // msg 130 starting transaction if (tdgbl->gbl_sw_ignore_limbo) { @@ -296,12 +296,12 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) -/* decide what type of database we've got */ +// decide what type of database we've got set_capabilities(); -/* Write burp record first with other valuable information */ -/* In case of split operation, write a 'split' header first to all the files */ +// Write burp record first with other valuable information +// In case of split operation, write a 'split' header first to all the files if (tdgbl->action->act_action == ACT_backup_split) { @@ -312,7 +312,7 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) { BURP_error(269, tdgbl->action->act_file->fil_name, 0, 0, 0, 0); - /* msg 269 can't write a header record to file %s */ + // msg 269 can't write a header record to file %s } } tdgbl->action->act_file = tdgbl->gbl_sw_files; @@ -322,14 +322,14 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) reinterpret_cast(file_name), &tdgbl->io_cnt, &tdgbl->io_ptr); -/* Write database record */ +// Write database record write_database(dbb_file); -/* Write global fields */ +// Write global fields BURP_verbose(150, NULL, NULL, NULL, NULL, NULL); - /* msg 150 writing global fields */ + // msg 150 writing global fields write_global_fields(); if (tdgbl->BCK_capabilities & BCK_ods6) @@ -337,65 +337,65 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) write_field_dimensions(); BURP_verbose(162, NULL, NULL, NULL, NULL, NULL); - /* msg 162 writing shadow files */ + // msg 162 writing shadow files write_shadow_files(); } -/* Write relations */ +// Write relations BURP_verbose(154, NULL, NULL, NULL, NULL, NULL); - /* msg 154 writing relations */ + // msg 154 writing relations write_relations(); if (tdgbl->BCK_capabilities & BCK_ffmptt) { - /* Write functions */ + // Write functions BURP_verbose(148, NULL, NULL, NULL, NULL, NULL); - /* msg 148 writing functions */ + // msg 148 writing functions write_functions(); - /* Write types */ + // Write types BURP_verbose(161, NULL, NULL, NULL, NULL, NULL); - /* msg 161 writing types */ + // msg 161 writing types write_types(); - /* Write filters */ + // Write filters BURP_verbose(146, NULL, NULL, NULL, NULL, NULL); - /* msg 146 writing filters */ + // msg 146 writing filters write_filters(); - /* Write generators */ + // Write generators BURP_verbose(164, NULL, NULL, NULL, NULL, NULL); - /* msg 164 writing id generators */ + // msg 164 writing id generators write_generators(); } if (tdgbl->BCK_capabilities & BCK_ods8) { - /* Write procedures */ + // Write procedures BURP_verbose(192, NULL, NULL, NULL, NULL, NULL); - /* msg 192 writing stored procedures */ + // msg 192 writing stored procedures write_procedures(); - /* Write exceptions */ + // Write exceptions BURP_verbose(197, NULL, NULL, NULL, NULL, NULL); - /* msg 197 writing exceptions */ + // msg 197 writing exceptions write_exceptions(); - /* Write Character Sets */ + // Write Character Sets BURP_verbose(msgVerbose_write_charsets, NULL, NULL, NULL, NULL, NULL); write_character_sets(); - /* Write Collations */ + // Write Collations BURP_verbose(msgVerbose_write_collations, NULL, NULL, NULL, NULL, NULL); write_collations(); } -/* Now go back and write all data */ +// Now go back and write all data for (BURP_REL relation = tdgbl->relations; relation; relation = relation->rel_next) { put(tdgbl, (UCHAR) (rec_relation_data)); @@ -417,15 +417,15 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) /* now for the new triggers in rdb$triggers */ if (tdgbl->BCK_capabilities & BCK_ffmptt) { BURP_verbose(159, NULL, NULL, NULL, NULL, NULL); - /* msg 159 writing triggers */ + // msg 159 writing triggers write_triggers(); BURP_verbose(158, NULL, NULL, NULL, NULL, NULL); - /* msg 158 writing trigger messages */ + // msg 158 writing trigger messages write_trigger_messages(); write_user_privileges(); } -/* Last, but not least, go back and add any access control lists */ +// Last, but not least, go back and add any access control lists if (tdgbl->BCK_capabilities & BCK_security) { @@ -436,7 +436,7 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) l = PUT_TEXT (att_class_security_class, X.RDB$SECURITY_CLASS); MISC_terminate (X.RDB$SECURITY_CLASS, temp, l, sizeof(temp)); BURP_verbose (155, temp, NULL, NULL, NULL, NULL); - /* msg 155 writing security class %s */ + // msg 155 writing security class %s put_blr_blob (att_class_acl, (ISC_QUAD *)&X.RDB$ACL); put_source_blob (att_class_description2, att_class_description, (ISC_QUAD *)&X.RDB$DESCRIPTION); @@ -451,32 +451,32 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) if (tdgbl->BCK_capabilities & BCK_ods8) { - /* Write relation constraints */ + // Write relation constraints BURP_verbose(206, NULL, NULL, NULL, NULL, NULL); - /* msg 206 writing relation constraints */ + // msg 206 writing relation constraints write_rel_constraints(); - /* Write referential constraints */ + // Write referential constraints BURP_verbose(209, NULL, NULL, NULL, NULL, NULL); - /* msg 209 writing referential constraints */ + // msg 209 writing referential constraints write_ref_constraints(); - /* Write check constraints */ + // Write check constraints BURP_verbose(210, NULL, NULL, NULL, NULL, NULL); - /* msg 210 writing check constraints */ + // msg 210 writing check constraints write_check_constraints(); } if (tdgbl->BCK_capabilities & BCK_ods9) { - /* Write SQL roles */ + // Write SQL roles BURP_verbose(248, NULL, NULL, NULL, NULL, NULL); - /* msg 248 writing SQL roles */ + // msg 248 writing SQL roles write_sql_roles(); } -/* Finish up */ +// Finish up put(tdgbl, (UCHAR) (rec_end)); @@ -484,12 +484,12 @@ int BACKUP_backup(TEXT* dbb_file, const TEXT* file_name) if (cumul_count <= MAX_SLONG) { SLONG tempcount = cumul_count; BURP_verbose(176, (void*) tempcount, NULL, NULL, NULL, NULL); - /* msg 176 closing file, committing, and finishing. %ld bytes written */ + // msg 176 closing file, committing, and finishing. %ld bytes written } else { char psz[64]; ib_sprintf(psz, "%" QUADFORMAT "d", cumul_count); BURP_verbose(283, psz, NULL, NULL, NULL, NULL); - /* msg 283 closing file, committing, and finishing. %s bytes written */ + // msg 283 closing file, committing, and finishing. %s bytes written } COMMIT; ON_ERROR @@ -799,7 +799,7 @@ BURP_FLD get_fields( BURP_REL relation) } blob_id = &Y.RDB$COMPUTED_BLR; if (blob_id->gds_quad_low || blob_id->gds_quad_high) - field->fld_flags |= FLD_computed; + field->fld_flags |= FLD_computed; if (tdgbl->BCK_capabilities & BCK_rfr_sys_flag) { FOR (REQUEST_HANDLE tdgbl->handles_get_fields_req_handle3) @@ -911,7 +911,7 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) * Read id for a generator; * **************************************/ - UCHAR blr_buffer[100]; /* enough to fit blr */ + UCHAR blr_buffer[100]; // enough to fit blr SLONG read_msg0; SINT64 read_msg1; ISC_STATUS_ARRAY status_vector; @@ -927,7 +927,7 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) */ if (tdgbl->BCK_capabilities & BCK_ods10) { - /* build the blr with the right relation name and 64-bit results. */ + // build the blr with the right relation name and 64-bit results. stuff(&blr, blr_version5); stuff(&blr, blr_begin); stuff(&blr, blr_message); @@ -958,7 +958,7 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) } else { - /* build the blr with the right relation name and 32-bit results */ + // build the blr with the right relation name and 32-bit results stuff(&blr, blr_version4); stuff(&blr, blr_begin); stuff(&blr, blr_message); @@ -998,16 +998,16 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) if (isc_compile_request(status_vector, &DB, &gen_id_reqh, blr_length, (char*) blr_buffer)) { - /* if there's no gen_id, never mind ... */ + // if there's no gen_id, never mind ... return 0; } if (isc_start_request(status_vector, &gen_id_reqh, - &gds_trans, /* use the same one generated by gpre */ + &gds_trans, // use the same one generated by gpre 0)) { BURP_error_redirect(status_vector, 25, NULL, NULL); - /* msg 25 Failed in put_blr_gen_id */ + // msg 25 Failed in put_blr_gen_id } if (tdgbl->BCK_capabilities & BCK_ods10) @@ -1016,7 +1016,7 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) &read_msg1, 0)) { BURP_error_redirect(status_vector, 25, NULL, NULL); - /* msg 25 Failed in put_blr_gen_id */ + // msg 25 Failed in put_blr_gen_id } } else @@ -1025,7 +1025,7 @@ SINT64 get_gen_id( const TEXT* name, SSHORT name_len) &read_msg0, 0)) { BURP_error_redirect(status_vector, 25, NULL, NULL); - /* msg 25 Failed in put_blr_gen_id */ + // msg 25 Failed in put_blr_gen_id } read_msg1 = (SINT64) read_msg0; } @@ -1063,7 +1063,7 @@ void get_ranges( BURP_FLD field) if (count != X.RDB$DIMENSION) BURP_error_redirect (NULL, 52, field->fld_name, NULL); - /* msg 52 array dimension for field %s is invalid */ + // msg 52 array dimension for field %s is invalid *rp++ = X.RDB$LOWER_BOUND; *rp++ = X.RDB$UPPER_BOUND; count++; @@ -1075,7 +1075,7 @@ void get_ranges( BURP_FLD field) if (count != field->fld_dimensions) BURP_error_redirect(NULL, 52, field->fld_name, NULL); - /* msg 52 array dimension for field %s is invalid */ + // msg 52 array dimension for field %s is invalid } @@ -1092,12 +1092,12 @@ void put_array( BURP_FLD field, BURP_REL relation, ISC_QUAD * blob_id) * **************************************/ ISC_STATUS_ARRAY status_vector; - SLONG *returned_range, range_buffer[16]; /* enough for 16 dimensions */ - UCHAR blr_buffer[200]; /* enough for a sdl with 16 dimensions */ + SLONG *returned_range, range_buffer[16]; // enough for 16 dimensions + UCHAR blr_buffer[200]; // enough for a sdl with 16 dimensions TGBL tdgbl = GET_THREAD_DATA; -/* If the array is null, don't store it. It will be restored as null. */ +// If the array is null, don't store it. It will be restored as null. if (!blob_id->gds_quad_low && !blob_id->gds_quad_high) return; @@ -1112,7 +1112,7 @@ void put_array( BURP_FLD field, BURP_REL relation, ISC_QUAD * blob_id) if (tdgbl->gbl_sw_transportable) xdr_buffer.lstr_length = field_length + 3; -/* build the sdl */ +// build the sdl stuff(&blr, isc_sdl_version1); @@ -1185,7 +1185,7 @@ void put_array( BURP_FLD field, BURP_REL relation, ISC_QUAD * blob_id) } UCHAR *slice = BURP_alloc(slice_length); -/* allocate space for the XDR representation */ +// allocate space for the XDR representation if (tdgbl->gbl_sw_transportable) { @@ -1201,7 +1201,7 @@ void put_array( BURP_FLD field, BURP_REL relation, ISC_QUAD * blob_id) slice_length, slice, (SLONG*) &return_length)) { BURP_print(81, field->fld_name, NULL, NULL, NULL, NULL); - /* msg 81 error accessing blob field %s -- continuing */ + // msg 81 error accessing blob field %s -- continuing BURP_print_status(status_vector); #ifdef DEBUG PRETTY_print_sdl(blr_buffer, NULL, NULL, 0); @@ -1329,19 +1329,19 @@ void put_blob( BURP_FLD field, ISC_QUAD * blob_id, ULONG count) TGBL tdgbl = GET_THREAD_DATA; -/* If the blob is null, don't store it. It will be restored as null. */ +// If the blob is null, don't store it. It will be restored as null. if (!blob_id->gds_quad_high && !blob_id->gds_quad_low) return; -/* Open the blob and get it's vital statistics */ +// Open the blob and get it's vital statistics FRBRD *blob = NULL; if (isc_open_blob(status_vector, &DB, &gds_trans, &blob, blob_id)) { BURP_print(81, field->fld_name, NULL, NULL, NULL, NULL); - /* msg 81 error accessing blob field %s -- continuing */ + // msg 81 error accessing blob field %s -- continuing BURP_print_status(status_vector); return; } @@ -1351,7 +1351,7 @@ void put_blob( BURP_FLD field, ISC_QUAD * blob_id, ULONG count) (char*) blob_info)) { BURP_error_redirect(status_vector, 20, NULL, NULL); - /* msg 20 isc_blob_info failed */ + // msg 20 isc_blob_info failed } put(tdgbl, (UCHAR) (rec_blob)); @@ -1386,11 +1386,11 @@ void put_blob( BURP_FLD field, ISC_QUAD * blob_id, ULONG count) default: BURP_error_redirect(NULL, 21, (void*) (ULONG) item, NULL); - /* msg 21 don't understand blob info item %ld */ + // msg 21 don't understand blob info item %ld } } -/* Allocate a buffer large enough for the largest segment and start grinding. */ +// Allocate a buffer large enough for the largest segment and start grinding. UCHAR* buffer; if (!max_segment || max_segment <= sizeof(static_buffer)) @@ -1408,7 +1408,7 @@ void put_blob( BURP_FLD field, ISC_QUAD * blob_id, ULONG count) { BURP_error_redirect(status_vector, 22, NULL, NULL); } - /* msg 22 gds__get_segment failed */ + // msg 22 gds__get_segment failed put(tdgbl, (UCHAR) (segment_length)); put(tdgbl, (UCHAR) (segment_length >> 8)); @@ -1421,7 +1421,7 @@ void put_blob( BURP_FLD field, ISC_QUAD * blob_id, ULONG count) if (isc_close_blob(status_vector, &blob)) BURP_error_redirect(status_vector, 23, NULL, NULL); - /* msg 23 isc_close_blob failed */ + // msg 23 isc_close_blob failed if (buffer != static_buffer) BURP_free(buffer); @@ -1446,19 +1446,19 @@ bool put_blr_blob( SCHAR attribute, ISC_QUAD * blob_id) TGBL tdgbl = GET_THREAD_DATA; -/* If the blob is null, don't store it. It will be restored as null. */ +// If the blob is null, don't store it. It will be restored as null. if (!blob_id->gds_quad_high && !blob_id->gds_quad_low) return false; -/* Open the blob and get it's vital statistics */ +// Open the blob and get it's vital statistics FRBRD *blob = NULL; if (isc_open_blob(status_vector, &DB, &gds_trans, &blob, blob_id)) { BURP_error_redirect(status_vector, 24, NULL, NULL); - /* msg 24 isc_open_blob failed */ + // msg 24 isc_open_blob failed } if (isc_blob_info(status_vector, &blob, sizeof(blr_items), @@ -1466,7 +1466,7 @@ bool put_blr_blob( SCHAR attribute, ISC_QUAD * blob_id) (char*) blob_info)) { BURP_error_redirect(status_vector, 20, NULL, NULL); - /* msg 20 isc_blob_info failed */ + // msg 20 isc_blob_info failed } ULONG length = 0; @@ -1492,7 +1492,7 @@ bool put_blr_blob( SCHAR attribute, ISC_QUAD * blob_id) default: BURP_print(79, (void *) (ULONG) item, NULL, NULL, NULL, NULL); - /* msg 79 don't understand blob info item %ld */ + // msg 79 don't understand blob info item %ld return false; } } @@ -1501,18 +1501,18 @@ bool put_blr_blob( SCHAR attribute, ISC_QUAD * blob_id) { if (isc_close_blob(status_vector, &blob)) BURP_error_redirect(status_vector, 23, NULL, NULL); - /* msg 23 isc_close_blob failed */ + // msg 23 isc_close_blob failed return false; } -/* Rdb sometimes gets the length messed up */ +// Rdb sometimes gets the length messed up if (length < max_segment) length = max_segment; put_numeric(attribute, (int) length); -/* Allocate a buffer large enough for the largest segment and start grinding. */ +// Allocate a buffer large enough for the largest segment and start grinding. UCHAR* buffer; if (!max_segment || max_segment <= sizeof(static_buffer)) @@ -1534,7 +1534,7 @@ bool put_blr_blob( SCHAR attribute, ISC_QUAD * blob_id) { BURP_error_redirect(status_vector, 23, NULL, NULL); } - /* msg 23 isc_close_blob failed */ + // msg 23 isc_close_blob failed if (buffer != static_buffer) BURP_free(buffer); @@ -1672,7 +1672,7 @@ void put_data(BURP_REL relation) default: BURP_error_redirect(NULL, 26, (void *) (SLONG) field->fld_type, NULL); - /* msg 26 datatype %ld not understood */ + // msg 26 datatype %ld not understood break; } if (alignment) @@ -1682,7 +1682,7 @@ void put_data(BURP_REL relation) offset += length; } -/* Next, build fields for null flags */ +// Next, build fields for null flags for (field = relation->rel_fields; field; field = field->fld_next) { @@ -1695,24 +1695,24 @@ void put_data(BURP_REL relation) offset += sizeof(SSHORT); } -/* Finally, make up an EOF field */ +// Finally, make up an EOF field - stuff(&blr, blr_short); /* eof field */ - stuff(&blr, 0); /* scale for eof field */ + stuff(&blr, blr_short); // eof field + stuff(&blr, 0); // scale for eof field SSHORT eof_parameter = count++; RCRD_OFFSET record_length = offset; RCRD_OFFSET eof_offset = FB_ALIGN(offset, sizeof(SSHORT)); // To be used later for the buffer size to receive data const FLD_LENGTH length = (USHORT) (eof_offset + sizeof(SSHORT)); -/* Build FOR loop, body, and eof handler */ +// Build FOR loop, body, and eof handler stuff(&blr, blr_for); stuff(&blr, blr_rse); - stuff(&blr, 1); /* count of relations */ + stuff(&blr, 1); // count of relations stuff(&blr, blr_rid); stuff_word(&blr, relation->rel_id); - stuff(&blr, 0); /* context variable */ + stuff(&blr, 0); // context variable stuff(&blr, blr_end); stuff(&blr, blr_send); @@ -1763,7 +1763,7 @@ void put_data(BURP_REL relation) #endif -/* Compile request */ +// Compile request FRBRD *request = NULL; SSHORT blr_length = blr - blr_buffer; @@ -1771,14 +1771,14 @@ void put_data(BURP_REL relation) blr_length, (SCHAR*) blr_buffer)) { BURP_error_redirect(status_vector, 27, NULL, NULL); - /* msg 27 isc_compile_request failed */ + // msg 27 isc_compile_request failed isc_print_blr((char*) blr_buffer, (isc_callback)NULL, NULL, 0); } BURP_free(blr_buffer); BURP_verbose(142, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 142 writing data for relation %s */ + // msg 142 writing data for relation %s if (isc_start_request(status_vector, &request, &gds_trans, 0)) { @@ -1809,12 +1809,12 @@ void put_data(BURP_REL relation) if (isc_receive(status_vector, &request, 0, length, buffer, 0)) { BURP_error_redirect(status_vector, 29, NULL, NULL); - /* msg 29 isc_receive failed */ + // msg 29 isc_receive failed } if (!*eof) break; records++; - /* Verbose records */ + // Verbose records if ((records % BACKUP_VERBOSE_INTERVAL) == 0) BURP_verbose(108, (void *) (SLONG) records, NULL, NULL, NULL, NULL); @@ -1835,7 +1835,7 @@ void put_data(BURP_REL relation) else if (record_length) put_block(tdgbl, p, record_length); - /* Look for any blobs to write */ + // Look for any blobs to write for (field = relation->rel_fields; field; field = field->fld_next) { @@ -1849,8 +1849,8 @@ void put_data(BURP_REL relation) } } - /* Look for any array to write */ - /* we got back the blob_id for the array from isc_receive in the second param. */ + // Look for any array to write + // we got back the blob_id for the array from isc_receive in the second param. for (field = relation->rel_fields; field; field = field->fld_next) { if (field->fld_flags & FLD_array) @@ -1867,11 +1867,11 @@ void put_data(BURP_REL relation) BURP_free(xdr_buffer.lstr_address); BURP_verbose(108, (void *) (SLONG) records, NULL, NULL, NULL, NULL); -/* msg 108 %ld records written */ +// msg 108 %ld records written if (isc_release_request(status_vector, &request)) BURP_error_redirect(status_vector, 30, NULL, NULL); - /* msg 30 isc_release_request failed */ + // msg 30 isc_release_request failed } @@ -1934,7 +1934,7 @@ void put_index( BURP_REL relation) l = PUT_TEXT (att_index_name, X.RDB$INDEX_NAME); MISC_terminate (X.RDB$INDEX_NAME, temp, l, sizeof(temp)); BURP_verbose (151, temp, NULL, NULL, NULL, NULL); - /* msg 151 writing index %s */ + // msg 151 writing index %s put_numeric (att_segment_count, X.RDB$SEGMENT_COUNT); put_numeric (att_index_inactive, X.RDB$INDEX_INACTIVE); put_numeric (att_index_unique_flag, X.RDB$UNIQUE_FLAG); @@ -1963,7 +1963,7 @@ void put_index( BURP_REL relation) (ISC_QUAD *)&X.RDB$EXPRESSION_BLR); if (!X.RDB$FOREIGN_KEY.NULL) PUT_TEXT (att_index_foreign_key, X.RDB$FOREIGN_KEY); - put(tdgbl, att_end); + put(tdgbl, att_end); END_FOR; ON_ERROR @@ -2011,7 +2011,7 @@ void put_index( BURP_REL relation) l = PUT_TEXT (att_index_name, X.RDB$INDEX_NAME); MISC_terminate (X.RDB$INDEX_NAME, temp, l, sizeof(temp)); BURP_verbose (151, temp, NULL, NULL, NULL, NULL); - /* msg 151 writing index %s */ + // msg 151 writing index %s put_numeric (att_segment_count, X.RDB$SEGMENT_COUNT); if (tdgbl->BCK_capabilities & BCK_idx_inactive) FOR (REQUEST_HANDLE tdgbl->handles_put_index_req_handle4) @@ -2237,7 +2237,7 @@ void put_relation( BURP_REL relation) relation->rel_fields = field; } -/* Now write the fields in what will become physical backup order */ +// Now write the fields in what will become physical backup order for (field = relation->rel_fields; field; field = field->fld_next) { @@ -2245,7 +2245,7 @@ void put_relation( BURP_REL relation) l = PUT_TEXT(att_field_name, field->fld_name); MISC_terminate(field->fld_name, temp, l, sizeof(temp)); BURP_verbose(144, temp, NULL, NULL, NULL, NULL); - /* msg 144 writing field %s */ + // msg 144 writing field %s PUT_TEXT(att_field_source, field->fld_source); if (field->fld_query_name[0]) PUT_TEXT(att_field_query_name, field->fld_query_name); @@ -2370,7 +2370,7 @@ bool put_source_blob(SCHAR attribute, if (isc_open_blob(status_vector, &DB, &gds_trans, &blob, blob_id)) { BURP_error_redirect(status_vector, 24, NULL, NULL); - /* msg 24 isc_open_blob failed */ + // msg 24 isc_open_blob failed } if (isc_blob_info(status_vector, &blob, sizeof(source_items), @@ -2378,7 +2378,7 @@ bool put_source_blob(SCHAR attribute, (SCHAR*) blob_info)) { BURP_error_redirect(status_vector, 20, NULL, NULL); - /* msg 20 isc_blob_info failed */ + // msg 20 isc_blob_info failed } SLONG length = 0; @@ -2408,7 +2408,7 @@ bool put_source_blob(SCHAR attribute, default: BURP_print(79, (void *) (ULONG) item, NULL, NULL, NULL, NULL); - /* msg 79 don't understand blob info item %ld */ + // msg 79 don't understand blob info item %ld return false; } } @@ -2418,19 +2418,19 @@ bool put_source_blob(SCHAR attribute, if (isc_close_blob(status_vector, &blob)) { BURP_error_redirect(status_vector, 23, NULL, NULL); - /* msg 23 isc_close_blob failed */ + // msg 23 isc_close_blob failed } return false; } -/* Rdb sometimes gets the length messed up */ +// Rdb sometimes gets the length messed up if (length < max_segment) length = max_segment; put_numeric(attribute, length + num_seg); -/* Allocate a buffer large enough for the largest segment and start grinding. */ +// Allocate a buffer large enough for the largest segment and start grinding. UCHAR* buffer; if (!max_segment || max_segment <= sizeof(static_buffer)) @@ -2451,7 +2451,7 @@ bool put_source_blob(SCHAR attribute, if (isc_close_blob(status_vector, &blob)) BURP_error_redirect(status_vector, 23, NULL, NULL); - /* msg 23 isc_close_blob failed */ + // msg 23 isc_close_blob failed if (buffer != static_buffer) BURP_free(buffer); @@ -2742,7 +2742,7 @@ void write_database( const TEXT * dbb_file) (SCHAR *) db_info_items, sizeof(buffer), buffer)) { BURP_error_redirect(status_vector, 31, NULL, NULL); - /* msg 31 isc_database_info failed */ + // msg 31 isc_database_info failed } USHORT page_size = 0, forced_writes, no_reserve, @@ -2783,8 +2783,8 @@ void write_database( const TEXT * dbb_file) put_numeric(att_page_buffers, page_buffers); break; - case isc_info_error: /* old server does not understand new isc_info */ - break; /* parametere and returns isc_info_error. skip it */ + case isc_info_error: // old server does not understand new isc_info + break; // parametere and returns isc_info_error. skip it case isc_info_db_sql_dialect: SQL_dialect = (USHORT) isc_vax_integer(d, length); @@ -2798,7 +2798,7 @@ void write_database( const TEXT * dbb_file) default: BURP_error_redirect(status_vector, 31, NULL, NULL); - /* msg 31 isc_database_info failed */ + // msg 31 isc_database_info failed break; } } @@ -2806,7 +2806,7 @@ void write_database( const TEXT * dbb_file) put_asciz(att_file_name, dbb_file); BURP_verbose(77, dbb_file, (void *) (ULONG) page_size, NULL, NULL, NULL); -/* msg 77 database %s has a page size of %ld bytes. */ +// msg 77 database %s has a page size of %ld bytes. put(tdgbl, (UCHAR) (att_end)); @@ -3067,7 +3067,7 @@ void write_function_args( GDS_NAME funcptr) SSHORT l = PUT_TEXT (att_functionarg_name, X.RDB$FUNCTION_NAME); MISC_terminate (X.RDB$FUNCTION_NAME, temp, l, sizeof(temp)); BURP_verbose (141, temp, NULL, NULL, NULL, NULL); - /* msg 141 writing argument for function %s */ + // msg 141 writing argument for function %s put_numeric (att_functionarg_position, X.RDB$ARGUMENT_POSITION); put_numeric (att_functionarg_mechanism, X.RDB$MECHANISM); put_numeric (att_functionarg_field_type, X.RDB$FIELD_TYPE); @@ -3082,7 +3082,7 @@ void write_function_args( GDS_NAME funcptr) put(tdgbl, att_end); END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } else @@ -3095,7 +3095,7 @@ void write_function_args( GDS_NAME funcptr) SSHORT l = PUT_TEXT (att_functionarg_name, X.RDB$FUNCTION_NAME); MISC_terminate (X.RDB$FUNCTION_NAME, temp, l, sizeof(temp)); BURP_verbose (141, temp, NULL, NULL, NULL, NULL); - /* msg 141 writing argument for function %s */ + // msg 141 writing argument for function %s put_numeric (att_functionarg_position, X.RDB$ARGUMENT_POSITION); put_numeric (att_functionarg_mechanism, X.RDB$MECHANISM); put_numeric (att_functionarg_field_type, X.RDB$FIELD_TYPE); @@ -3113,12 +3113,12 @@ void write_function_args( GDS_NAME funcptr) if (!(X2.RDB$CHARACTER_SET_ID.NULL)) put_numeric (att_functionarg_character_set, X2.RDB$CHARACTER_SET_ID); /* Note that BCK_ods10 canNOT be set if we're in this - ``else'' branch. Hence there is no need to test that + "else" branch. Hence there is no need to test that bit and store the RDB$FIELD_PRECISION. */ END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } put(tdgbl, att_end); @@ -3259,7 +3259,7 @@ void write_global_fields(void) END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } else @@ -3327,7 +3327,7 @@ void write_global_fields(void) if (!(F.RDB$CHARACTER_SET_ID.NULL)) put_numeric (att_field_character_set, F.RDB$CHARACTER_SET_ID); if (!(F.RDB$COLLATION_ID.NULL)) - put_numeric (att_field_collation_id, F.RDB$COLLATION_ID); + put_numeric (att_field_collation_id, F.RDB$COLLATION_ID); if (tdgbl->BCK_capabilities & BCK_ods10) { @@ -3429,7 +3429,7 @@ void write_procedure_prms( GDS_NAME procptr) SSHORT l = PUT_TEXT (att_procedureprm_name, X.RDB$PARAMETER_NAME); MISC_terminate (X.RDB$PARAMETER_NAME, temp, l, sizeof(temp)); BURP_verbose (194, temp, NULL, NULL, NULL, NULL); - /* msg 194 writing parameter %s for stored procedure */ + // msg 194 writing parameter %s for stored procedure put_numeric (att_procedureprm_number, X.RDB$PARAMETER_NUMBER); put_numeric (att_procedureprm_type, X.RDB$PARAMETER_type); PUT_TEXT (att_procedureprm_field_source, X.RDB$FIELD_SOURCE); @@ -3500,7 +3500,7 @@ void write_rel_constraints(void) SSHORT l = PUT_TEXT (att_rel_constraint_name, X.RDB$CONSTRAINT_NAME); MISC_terminate (X.RDB$CONSTRAINT_NAME, temp, l, sizeof(temp)); BURP_verbose (207, temp, NULL, NULL, NULL, NULL); - /* msg 207 writing constraint %s */ + // msg 207 writing constraint %s PUT_MESSAGE (att_rel_constraint_type, X.RDB$CONSTRAINT_TYPE); PUT_TEXT (att_rel_constraint_rel_name, X.RDB$RELATION_NAME); PUT_TEXT (att_rel_constraint_defer, X.RDB$DEFERRABLE); @@ -3591,7 +3591,7 @@ void write_relations(void) put_relation (relation); END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } else @@ -3623,7 +3623,7 @@ void write_relations(void) put_numeric (att_relation_flags, R.RDB$FLAGS); END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } if (tdgbl->BCK_capabilities & BCK_security) @@ -3746,7 +3746,7 @@ void write_sql_roles(void) put(tdgbl, att_end); MISC_terminate (X.RDB$ROLE_NAME, temp, l, sizeof(temp)); BURP_verbose (249, temp, NULL, NULL, NULL, NULL); - /* msg 249 writing SQL role: %s */ + // msg 249 writing SQL role: %s END_FOR; ON_ERROR @@ -3790,7 +3790,7 @@ void write_triggers(void) SSHORT l = PUT_TEXT (att_trig_name, X.RDB$TRIGGER_NAME); MISC_terminate (X.RDB$TRIGGER_NAME, temp, l, sizeof(temp)); BURP_verbose (156, temp, NULL, NULL, NULL, NULL); - /* msg 156 writing trigger %s */ + // msg 156 writing trigger %s PUT_TEXT (att_trig_relation_name, X.RDB$RELATION_NAME); put_numeric (att_trig_sequence, X.RDB$TRIGGER_SEQUENCE); @@ -3808,7 +3808,7 @@ void write_triggers(void) END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } else @@ -3822,7 +3822,7 @@ void write_triggers(void) SSHORT l = PUT_TEXT (att_trig_name, X.RDB$TRIGGER_NAME); MISC_terminate (X.RDB$TRIGGER_NAME, temp, l, sizeof(temp)); BURP_verbose (156, temp, NULL, NULL, NULL, NULL); - /* msg 156 writing trigger %s */ + // msg 156 writing trigger %s PUT_TEXT (att_trig_relation_name, X.RDB$RELATION_NAME); put_numeric (att_trig_sequence, X.RDB$TRIGGER_SEQUENCE); @@ -3844,7 +3844,7 @@ void write_triggers(void) END_FOR; ON_ERROR - general_on_error(); + general_on_error(); END_ERROR; } @@ -3924,11 +3924,11 @@ void write_types(void) PUT_TEXT (att_type_name, X.RDB$TYPE_NAME); PUT_TEXT (att_type_field_name, X.RDB$FIELD_NAME); BURP_verbose (160, X.RDB$TYPE_NAME, X.RDB$FIELD_NAME, NULL, NULL, NULL); - /* msg 160 writing type %s for field %s */ + // msg 160 writing type %s for field %s put_numeric (att_type_type, X.RDB$TYPE); put_source_blob (att_type_description2, att_type_description, (ISC_QUAD *)&X.RDB$DESCRIPTION); if (X.RDB$SYSTEM_FLAG) - put_numeric (att_type_system_flag, X.RDB$SYSTEM_FLAG); + put_numeric (att_type_system_flag, X.RDB$SYSTEM_FLAG); put(tdgbl, att_end); END_FOR; ON_ERROR diff --git a/src/burp/burp.cpp b/src/burp/burp.cpp index 5cce47f06f..cc4ff2ec9d 100644 --- a/src/burp/burp.cpp +++ b/src/burp/burp.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Backup and Restore Program - * MODULE: burp.c + * MODULE: burp.cpp * DESCRIPTION: Command line interpreter for backup/restore * * The contents of this file are subject to the Interbase Public @@ -106,20 +106,20 @@ tgbl *gdgbl; #endif -const char* FOPEN_WRITE_TYPE = "w"; -const char* FOPEN_READ_TYPE = "r"; +const char* fopen_write_type = "w"; +const char* fopen_read_type = "r"; -const int OPEN_MASK = 0666; +const int open_mask = 0666; #ifdef VMS -const char* SWITCH_CHAR = "/"; +const char* switch_char = "/"; #else -const char* SWITCH_CHAR = "-"; +const char* switch_char = "-"; #endif -const char* output_suppress = "SUPPRESS"; -const int BURP_MSG_FAC = 12; +const char* const output_suppress = "SUPPRESS"; +const int burp_msg_fac = 12; enum gbak_action { @@ -152,12 +152,14 @@ const ULONG GBYTE = MBYTE * KBYTE; #if defined (WIN95) static bool fAnsiCP = false; -static inline void translate_cp(SCHAR *a){ +static inline void translate_cp(SCHAR* a) +{ if (!fAnsiCP) AnsiToOem(a, a); } #else -static inline void translate_cp(SCHAR *a){ +static inline void translate_cp(SCHAR* a) +{ } #endif @@ -221,7 +223,7 @@ void BURP_svc_error(USHORT errcode, ISC_STATUS *status = tdgbl->service_blk->svc_status; - CMD_UTIL_put_svc_status(status, BURP_MSG_FAC, errcode, + CMD_UTIL_put_svc_status(status, burp_msg_fac, errcode, arg1_t, arg1, arg2_t, arg2, arg3_t, arg3, arg4_t, arg4, arg5_t, arg5); @@ -274,10 +276,10 @@ int CLIB_ROUTINE main(int argc, char* argv[]) if (!string[1]) string = "-*NONE*"; const in_sw_tab_t* in_sw_tab = burp_in_sw_table; - const TEXT *q; + const TEXT* q; for (; q = in_sw_tab->in_sw_name; in_sw_tab++) { - TEXT c; + TEXT c; for (const TEXT *p = string + 1; c = *p++;) if (UPPER(c) != *q++) break; @@ -580,7 +582,7 @@ int common_main(int argc, for (in_sw_tab = burp_in_sw_table; in_sw_tab->in_sw; in_sw_tab++) if (in_sw_tab->in_sw_msg) { - BURP_msg_put(in_sw_tab->in_sw_msg, (void*)SWITCH_CHAR, 0, 0, + BURP_msg_put(in_sw_tab->in_sw_msg, (void*)switch_char, 0, 0, 0, 0); } @@ -685,7 +687,7 @@ int common_main(int argc, const TEXT *p = redirect; TEXT c; - const TEXT *q = output_suppress; + const TEXT* q = output_suppress; tdgbl->sw_redirect = NOOUTPUT; while (c = *p++) { if (UPPER(c) != *q++) { @@ -696,7 +698,7 @@ int common_main(int argc, if (tdgbl->sw_redirect == REDIRECT) { // not NOREDIRECT, and not NOOUTPUT // Make sure the status file doesn't already exist - IB_FILE* tmp_outfile = ib_fopen(redirect, FOPEN_READ_TYPE); + IB_FILE* tmp_outfile = ib_fopen(redirect, fopen_read_type); if (tmp_outfile) { BURP_print(66, redirect, 0, 0, 0, 0); // msg 66 can't open status and error output file %s @@ -705,7 +707,7 @@ int common_main(int argc, } if (! (tdgbl->output_file = - ib_fopen(redirect, FOPEN_WRITE_TYPE))) { + ib_fopen(redirect, fopen_write_type))) { BURP_print(66, redirect, 0, 0, 0, 0); // msg 66 can't open status and error output file %s exit_local(FINI_ERROR, const_cast(tdgbl)); @@ -1029,7 +1031,7 @@ int common_main(int argc, if (isc_detach_database(const_cast(tdgbl->status_vector), const_cast(&tdgbl->db_handle))) { - BURP_print_status(const_cast(tdgbl->status_vector)); + BURP_print_status(const_cast(tdgbl->status_vector)); } } @@ -1108,7 +1110,7 @@ void BURP_error(USHORT errcode, TGBL tdgbl = GET_THREAD_DATA; ISC_STATUS *status = tdgbl->service_blk->svc_status; - CMD_UTIL_put_svc_status(status, BURP_MSG_FAC, errcode, + CMD_UTIL_put_svc_status(status, burp_msg_fac, errcode, isc_arg_string, arg1, isc_arg_string, arg2, isc_arg_string, arg3, @@ -1123,7 +1125,7 @@ void BURP_error(USHORT errcode, } -void BURP_error_redirect( ISC_STATUS* status_vector, +void BURP_error_redirect(const ISC_STATUS* status_vector, USHORT errcode, const void* arg1, const void* arg2) @@ -1164,7 +1166,7 @@ void BURP_msg_partial( USHORT number, **************************************/ TEXT buffer[256]; - gds__msg_format(NULL, BURP_MSG_FAC, number, sizeof(buffer), buffer, + gds__msg_format(NULL, burp_msg_fac, number, sizeof(buffer), buffer, static_cast(arg1), static_cast(arg2), static_cast(arg3), @@ -1193,7 +1195,7 @@ void BURP_msg_put( USHORT number, **************************************/ TEXT buffer[256]; - gds__msg_format(NULL, BURP_MSG_FAC, number, sizeof(buffer), buffer, + gds__msg_format(NULL, burp_msg_fac, number, sizeof(buffer), buffer, static_cast(arg1), static_cast(arg2), static_cast(arg3), @@ -1225,7 +1227,7 @@ void BURP_msg_get( USHORT number, TEXT buffer[128]; gds__msg_format(NULL, - BURP_MSG_FAC, + burp_msg_fac, number, sizeof(buffer), buffer, @@ -1282,7 +1284,7 @@ void BURP_print(USHORT number, } -void BURP_print_status( ISC_STATUS * status_vector) +void BURP_print_status(const ISC_STATUS* status_vector) { /************************************** * @@ -1296,7 +1298,7 @@ void BURP_print_status( ISC_STATUS * status_vector) * **************************************/ if (status_vector) { - ISC_STATUS *vector = status_vector; + const ISC_STATUS *vector = status_vector; #ifdef SUPERSERVER TGBL tdgbl = GET_THREAD_DATA; ISC_STATUS *status = tdgbl->service_blk->svc_status; @@ -1324,7 +1326,7 @@ void BURP_print_status( ISC_STATUS * status_vector) } -void BURP_print_warning( ISC_STATUS * status_vector) +void BURP_print_warning(const ISC_STATUS* status_vector) { /************************************** * @@ -1342,7 +1344,7 @@ void BURP_print_warning( ISC_STATUS * status_vector) assert(status_vector[0] == gds_arg_gds); assert(status_vector[1] == 0); // print the warning message - ISC_STATUS* vector = &status_vector[2]; + const ISC_STATUS* vector = &status_vector[2]; SCHAR s[1024]; if (isc_interprete(s, &vector)) { translate_cp(s); @@ -1585,7 +1587,7 @@ static gbak_action open_files(const TEXT * file1, if ((fil->fil_fd = MVOL_open(fil->fil_name, MODE_WRITE, CREATE_ALWAYS)) == INVALID_HANDLE_VALUE) #else - if ((fil->fil_fd = open(fil->fil_name, MODE_WRITE, OPEN_MASK)) == -1) + if ((fil->fil_fd = open(fil->fil_name, MODE_WRITE, open_mask)) == -1) #endif // WIN_NT { diff --git a/src/burp/burp.h b/src/burp/burp.h index 4797bb3c90..4de3b3ecba 100644 --- a/src/burp/burp.h +++ b/src/burp/burp.h @@ -45,15 +45,19 @@ #include #endif -static inline UCHAR* BURP_alloc(ULONG size){ + +static inline UCHAR* BURP_alloc(ULONG size) +{ return MISC_alloc_burp(size); } -static inline UCHAR* BURP_alloc_zero(ULONG size){ +static inline UCHAR* BURP_alloc_zero(ULONG size) +{ return MISC_alloc_burp(size); } -static inline void BURP_free(void *block){ +static inline void BURP_free(void* block) +{ MISC_free_burp(block); } @@ -625,6 +629,8 @@ enum gfld_flags_vals { GFLD_validation_source2 = 4 }; +// CVC: Could use MAXPATHLEN, but what about restoring in a different system? +// I need to review if we tolerate different lengths for different OS's here. const int MAX_FILE_NAME_LENGTH = 256; /* Note that this typedef is also defined in JRD.H and REMOTE.H */ @@ -896,6 +902,8 @@ const int GBAK_IO_BUFFER_SIZE = (16 * (BUFSIZ)); #else const int GBAK_IO_BUFFER_SIZE = (16 * (1024)); #endif +#else +const int GBAK_IO_BUFFER_SIZE = (16 * (IO_BUFFER_SIZE)); #endif /* Burp will always write a backup in multiples of the following number @@ -919,14 +927,12 @@ inline static ULONG BURP_UP_TO_BLOCK(ULONG size) #ifdef WIN_NT static const int MODE_READ = GENERIC_READ; static const int MODE_WRITE = GENERIC_WRITE; -#else -# ifdef VMS +#elif defined(VMS) static const int MODE_READ = O_RDONLY; static const int MODE_WRITE = O_WRONLY | O_CREAT | O_TRUNC; -# else +#else static const int MODE_READ = O_RDONLY; static const int MODE_WRITE = O_WRONLY | O_CREAT; -# endif #endif diff --git a/src/burp/burp_proto.h b/src/burp/burp_proto.h index ea892dd1d4..2aa314cf73 100644 --- a/src/burp/burp_proto.h +++ b/src/burp/burp_proto.h @@ -32,8 +32,8 @@ extern void BURP_abort(void); extern void BURP_svc_error(USHORT, USHORT, const void *, USHORT, const void *, USHORT, const void *, USHORT, const void *, USHORT, const void *); extern void BURP_error(USHORT, const void*, const void*, const void*, const void*, const void*); -extern void BURP_print_status(ISC_STATUS *); -extern void BURP_error_redirect(ISC_STATUS *, USHORT, const void*, const void*); +extern void BURP_print_status(const ISC_STATUS*); +extern void BURP_error_redirect(const ISC_STATUS*, USHORT, const void*, const void*); extern void BURP_msg_partial(USHORT, const void*, const void*, const void*, const void*, const void*); extern void BURP_msg_put(USHORT, const void*, const void*, const void*, @@ -42,7 +42,7 @@ extern void BURP_msg_get(USHORT, TEXT*, const void*, const void*, const void*, const void*, const void*); extern void BURP_output_version(const TEXT *, TEXT *); extern void BURP_print(USHORT, const void*, const void*, const void*, const void*, const void*); -extern void BURP_print_warning(ISC_STATUS*); +extern void BURP_print_warning(const ISC_STATUS*); extern void BURP_verbose(USHORT, const void*, const void*, const void*, const void*, const void*); #endif /* BURP_BURP_PROTO_H */ diff --git a/src/burp/canonical.cpp b/src/burp/canonical.cpp index b64fe4edd3..fa66805075 100644 --- a/src/burp/canonical.cpp +++ b/src/burp/canonical.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Backup and Restore Program - * MODULE: canonical.c + * MODULE: canonical.cpp * DESCRIPTION: * * The contents of this file are subject to the Interbase Public @@ -28,7 +28,7 @@ * */ /* -$Id: canonical.cpp,v 1.27 2003-09-22 14:13:53 brodsom Exp $ +$Id: canonical.cpp,v 1.28 2003-09-25 11:48:59 robocop Exp $ */ #include "firebird.h" @@ -209,7 +209,7 @@ ULONG CAN_encode_decode(BURP_REL relation, } } -/* Next, get null flags */ +// Next, get null flags for (field = relation->rel_fields; field; field = field->fld_next) { @@ -674,7 +674,7 @@ static bool_t xdr_slice(XDR* xdrs, if (!xdr_long(xdrs, reinterpret_cast(&slice->lstr_length))) return FALSE; -/* Handle operation specific stuff, particularly memory allocation/deallocation */ +// Handle operation specific stuff, particularly memory allocation/deallocation switch (xdrs->x_op) { @@ -712,7 +712,7 @@ static bool_t xdr_slice(XDR* xdrs, return FALSE; } -/* Get descriptor of array element */ +// Get descriptor of array element if (SDL_info(status_vector, sdl, &info, 0)) return FALSE; diff --git a/src/burp/misc.cpp b/src/burp/misc.cpp index c1309e8d50..cd5d5c50b7 100644 --- a/src/burp/misc.cpp +++ b/src/burp/misc.cpp @@ -52,7 +52,7 @@ UCHAR *MISC_alloc_burp(ULONG size) TGBL tdgbl = GET_THREAD_DATA; -/* Add some header space to store a list of blocks allocated for this gbak */ +// Add some header space to store a list of blocks allocated for this gbak size += ROUNDUP(sizeof(UCHAR *), ALIGNMENT); UCHAR* block = (UCHAR*)gds__alloc(size); @@ -60,7 +60,7 @@ UCHAR *MISC_alloc_burp(ULONG size) if (!block) /* NOMEM: message & abort FREE: all items freed at gbak exit */ { - BURP_error(238, NULL, NULL, NULL, NULL, NULL); /* msg 238: System memory exhaused */ + BURP_error(238, NULL, NULL, NULL, NULL, NULL); // msg 238: System memory exhaused return NULL; } @@ -92,26 +92,26 @@ void MISC_free_burp( void *free) TGBL tdgbl = GET_THREAD_DATA; if (free != NULL) { - /* Point at the head of the allocated block */ + // Point at the head of the allocated block UCHAR **block = (UCHAR **) ((UCHAR *) free - ROUNDUP(sizeof(UCHAR *), ALIGNMENT)); - /* Scan for this block in the list of blocks */ + // Scan for this block in the list of blocks for (UCHAR **ptr = &tdgbl->head_of_mem_list; *ptr; ptr = (UCHAR **) *ptr) { if (*ptr == (UCHAR *) block) { - /* Found it - remove it from the list */ + // Found it - remove it from the list *ptr = *block; - /* and free it */ + // and free it gds__free((SLONG *) block); return; } } - /* We should always find the block in the list */ - BURP_error(238, NULL, NULL, NULL, NULL, NULL); /* msg 238: System memory exhausted */ - /* (too lazy to add a better message) */ + // We should always find the block in the list + BURP_error(238, NULL, NULL, NULL, NULL, NULL); // msg 238: System memory exhausted + // (too lazy to add a better message) } } @@ -147,9 +147,9 @@ void MISC_terminate(const TEXT* from, TEXT* to, ULONG length, ULONG max_length) if (length) { length = MIN(length, max_length - 1); - do + do { *to++ = *from++; - while (--length); + } while (--length); *to++ = '\0'; } else { diff --git a/src/burp/mvol.cpp b/src/burp/mvol.cpp index 77928d8d98..b4843d34b4 100644 --- a/src/burp/mvol.cpp +++ b/src/burp/mvol.cpp @@ -67,7 +67,7 @@ #include #endif -const int OPEN_MASK = 0666; +const int open_mask = 0666; #ifdef VMS const char* TERM_INPUT = "sys$input"; @@ -84,11 +84,13 @@ const char* TERM_OUTPUT = "/dev/tty"; const int MAX_HEADER_SIZE = 512; -static inline int get(TGBL tdgbl){ +static inline int get(TGBL tdgbl) +{ return (--(tdgbl->mvol_io_cnt) >= 0 ? *(tdgbl->mvol_io_ptr)++ : 255); } -static inline void put(TGBL tdgbl, ULONG c){ +static inline void put(TGBL tdgbl, ULONG c) +{ --(tdgbl->mvol_io_cnt); *(tdgbl->mvol_io_ptr)++ = (UCHAR) (c); } @@ -187,9 +189,6 @@ void MVOL_init_read(const UCHAR* database_name, // unused? int* cnt, UCHAR** ptr) { - ULONG temp_buffer_size; - UCHAR *new_buffer; - TGBL tdgbl = GET_THREAD_DATA; tdgbl->mvol_volume_count = 1; @@ -205,8 +204,8 @@ void MVOL_init_read(const UCHAR* database_name, // unused? tdgbl->mvol_old_file[0] = 0; } - tdgbl->mvol_actual_buffer_size = temp_buffer_size = - tdgbl->mvol_io_buffer_size; + ULONG temp_buffer_size = tdgbl->mvol_io_buffer_size; + tdgbl->mvol_actual_buffer_size = temp_buffer_size; tdgbl->mvol_io_buffer = BURP_alloc(temp_buffer_size); tdgbl->gbl_backup_start_time[0] = 0; @@ -214,7 +213,7 @@ void MVOL_init_read(const UCHAR* database_name, // unused? if (temp_buffer_size > tdgbl->mvol_actual_buffer_size) { - new_buffer = BURP_alloc(temp_buffer_size); + UCHAR* new_buffer = BURP_alloc(temp_buffer_size); memcpy(new_buffer, tdgbl->mvol_io_buffer, tdgbl->mvol_io_buffer_size); BURP_free(tdgbl->mvol_io_buffer); tdgbl->mvol_io_ptr = @@ -811,13 +810,11 @@ static SLONG get_numeric(void) // static int get_text(UCHAR* text, SSHORT length) { - unsigned int l, l2; - TGBL tdgbl = GET_THREAD_DATA; - l = get(tdgbl); + ULONG l = get(tdgbl); length -= l; - l2 = l; + const ULONG l2 = l; if (length < 0) { @@ -844,10 +841,6 @@ static int get_text(UCHAR* text, SSHORT length) // static DESC next_volume( DESC handle, int mode, bool full_buffer) { - SCHAR new_file[MAX_FILE_NAME_LENGTH]; - ULONG temp_buffer_size; - USHORT format; - TGBL tdgbl = GET_THREAD_DATA; /* We must close the old handle before the user inserts @@ -885,6 +878,7 @@ static DESC next_volume( DESC handle, int mode, bool full_buffer) // Loop until we have opened a file successfully + SCHAR new_file[MAX_FILE_NAME_LENGTH]; DESC new_desc = INVALID_HANDLE_VALUE; for (;;) { @@ -903,7 +897,7 @@ static DESC next_volume( DESC handle, int mode, bool full_buffer) new_desc = MVOL_open(new_file, mode, OPEN_ALWAYS); if (new_desc == INVALID_HANDLE_VALUE) #else - new_desc = open(new_file, mode, OPEN_MASK); + new_desc = open(new_file, mode, open_mask); if (new_desc < 0) #endif // WIN_NT { @@ -917,7 +911,7 @@ static DESC next_volume( DESC handle, int mode, bool full_buffer) #ifdef WIN_NT if (mode == MODE_WRITE) #else - if ( (mode = mode & O_WRONLY) || (mode = mode & O_RDWR)) + if ((O_WRONLY == (mode & O_WRONLY)) || (O_RDWR == (mode & O_RDWR))) #endif // WIN_NT { if (!write_header(new_desc, 0L, full_buffer)) @@ -938,6 +932,8 @@ static DESC next_volume( DESC handle, int mode, bool full_buffer) { // File is open for read only. Read the header. + ULONG temp_buffer_size; + USHORT format; if (!read_header(new_desc, &temp_buffer_size, &format, false)) { BURP_print(224, new_file, 0, 0, 0, 0); @@ -1060,7 +1056,7 @@ static void prompt_for_name(SCHAR* name, int length) // // Write an attribute starting with a null terminated string. // -static void put_asciz( SCHAR attribute, const TEXT * string) +static void put_asciz( SCHAR attribute, const TEXT* string) { TGBL tdgbl = GET_THREAD_DATA; @@ -1069,13 +1065,13 @@ static void put_asciz( SCHAR attribute, const TEXT * string) { l++; } + fb_assert(l <= MAX_UCHAR); put(tdgbl, attribute); put(tdgbl, l); if (l) { - do - { + do { put(tdgbl, *string++); } while (--l); } @@ -1092,7 +1088,7 @@ static void put_numeric( SCHAR attribute, int value) TGBL tdgbl = GET_THREAD_DATA; ULONG vax_value = gds__vax_integer((UCHAR *) & value, sizeof(value)); - UCHAR *p = (UCHAR *) & vax_value; + UCHAR* p = (UCHAR *) &vax_value; put(tdgbl, attribute); put(tdgbl, sizeof(value)); @@ -1112,7 +1108,6 @@ static bool read_header(DESC handle, USHORT* format, bool init_flag) { - int attribute, temp; SSHORT l; ULONG temp_buffer_size; TEXT buffer[256], *p, msg[128]; @@ -1132,10 +1127,13 @@ static bool read_header(DESC handle, #endif tdgbl->mvol_io_ptr = tdgbl->mvol_io_buffer; - if ((attribute = (att_type) get(tdgbl)) != rec_burp) - BURP_error_redirect(0, 45, NULL, NULL); // msg 45 expected backup description record + int attribute = get(tdgbl); + if (attribute != rec_burp) + BURP_error_redirect(0, 45, NULL, NULL); + // msg 45 expected backup description record - while ((attribute = (att_type) get(tdgbl)) != att_end) + int temp; + for (attribute = get(tdgbl); attribute != att_end; attribute = get(tdgbl)) { switch (attribute) { @@ -1158,9 +1156,9 @@ static bool read_header(DESC handle, else p = buffer; if (l) - do + do { *p++ = get(tdgbl); - while (--l); + } while (--l); *p = 0; if (!init_flag && strcmp(buffer, tdgbl->gbl_backup_start_time)) { diff --git a/src/burp/restore.epp b/src/burp/restore.epp index c8c909abb9..af86d35009 100644 --- a/src/burp/restore.epp +++ b/src/burp/restore.epp @@ -24,7 +24,7 @@ * 2003.08.17 Claudio Valderrama: Fix SF Bug #750659. */ /* -$Id: restore.epp,v 1.47 2003-09-23 19:47:50 brodsom Exp $ +$Id: restore.epp,v 1.48 2003-09-25 11:48:59 robocop Exp $ */ #include "firebird.h" @@ -67,19 +67,19 @@ namespace // unnamed, private { -const int DB_VERSION_DDL4 = 4; /* ods4 db */ -const int DB_VERSION_DDL5 = 5; /* ods5 db */ -const int DB_VERSION_DDL8 = 8; /* ods8 db */ -const int DB_VERSION_CURRENT = DB_VERSION_DDL8; /* v4.0 is ods8 */ +const int DB_VERSION_DDL4 = 4; // ods4 db +const int DB_VERSION_DDL5 = 5; // ods5 db +const int DB_VERSION_DDL8 = 8; // ods8 db +const int DB_VERSION_CURRENT = DB_VERSION_DDL8; // v4.0 is ods8 const char* FOREIGN_KEY = "FOREIGN KEY"; -const int DEFERRED_ACTIVE = 3; /* RDB$INDEX_INACTIVE setting for Foreign Keys +const int DEFERRED_ACTIVE = 3; /* RDB$INDEX_INACTIVE setting for Foreign Keys * This setting is used temporarily while * restoring a database. This was required * in order to differentiate a partial * "inactive" state of SOME indices from * "inactive" state of ALL indices (gbak -i) - * -bsriram, 11-May-1999 BUG: 10016 + * -bsriram, 11-May-1999 BUG: 10016 */ const int RESTORE_VERBOSE_INTERVAL = 10000; @@ -92,41 +92,41 @@ const struct s_t_cvtbl { /* NOTE: The magic numbers for collation_id come from ordinal * position of the COLLATION() entries in jrd/intlnames.h */ - {101, CS_DOS_437, 1}, /* PDOX_ASCII */ - {102, CS_DOS_437, 2}, /* PDOX_INTL */ - {106, CS_DOS_437, 3}, /* PDOX_SWEDFIN */ - {160, CS_DOS_850, 0}, /* codepoint collation */ - {107, CS_DOS_865, 0}, /* codepoint collation */ - {105, CS_DOS_865, 1}, /* PDOX_NORDAN4 */ - {139, CS_ISO8859_1, 1}, /* DA_DA */ - {140, CS_ISO8859_1, 2}, /* DU_NL */ - {141, CS_ISO8859_1, 3}, /* FI_FI */ - {142, CS_ISO8859_1, 4}, /* FR_FR */ - {143, CS_ISO8859_1, 5}, /* FR_CA */ - {144, CS_ISO8859_1, 6}, /* DE_DE */ - {145, CS_ISO8859_1, 7}, /* IS_IS */ - {146, CS_ISO8859_1, 8}, /* IT_IT */ - {148, CS_ISO8859_1, 9}, /* NO_NO */ - {149, CS_ISO8859_1, 10}, /* ES_ES */ - {151, CS_ISO8859_1, 11}, /* SV_SV */ - {152, CS_ISO8859_1, 12}, /* EN_UK */ - {153, CS_ISO8859_1, 14}, /* EN_US */ - {154, CS_ISO8859_1, 15}, /* PT_PT */ - {160, CS_ISO8859_2, 1}, /* CS_CZ */ - {180, CS_NEXT, 1}, /* NXT_US */ - {181, CS_NEXT, 2}, /* NXT_GERMANY */ - {182, CS_NEXT, 3}, /* NXT_FRANCE */ - {183, CS_NEXT, 4}, /* NXT_ITALY */ - {184, CS_NEXT, 5}, /* NXT_SPAIN */ - {201, CS_UNICODE_FSS, 0}, /* codepoint collation */ - {220, CS_SJIS, 0}, /* codepoint collation */ - {230, CS_EUCJ, 0} /* codepoint collation */ + {101, CS_DOS_437, 1}, // PDOX_ASCII + {102, CS_DOS_437, 2}, // PDOX_INTL + {106, CS_DOS_437, 3}, // PDOX_SWEDFIN + {160, CS_DOS_850, 0}, // codepoint collation + {107, CS_DOS_865, 0}, // codepoint collation + {105, CS_DOS_865, 1}, // PDOX_NORDAN4 + {139, CS_ISO8859_1, 1}, // DA_DA + {140, CS_ISO8859_1, 2}, // DU_NL + {141, CS_ISO8859_1, 3}, // FI_FI + {142, CS_ISO8859_1, 4}, // FR_FR + {143, CS_ISO8859_1, 5}, // FR_CA + {144, CS_ISO8859_1, 6}, // DE_DE + {145, CS_ISO8859_1, 7}, // IS_IS + {146, CS_ISO8859_1, 8}, // IT_IT + {148, CS_ISO8859_1, 9}, // NO_NO + {149, CS_ISO8859_1, 10}, // ES_ES + {151, CS_ISO8859_1, 11}, // SV_SV + {152, CS_ISO8859_1, 12}, // EN_UK + {153, CS_ISO8859_1, 14}, // EN_US + {154, CS_ISO8859_1, 15}, // PT_PT + {160, CS_ISO8859_2, 1}, // CS_CZ + {180, CS_NEXT, 1}, // NXT_US + {181, CS_NEXT, 2}, // NXT_GERMANY + {182, CS_NEXT, 3}, // NXT_FRANCE + {183, CS_NEXT, 4}, // NXT_ITALY + {184, CS_NEXT, 5}, // NXT_SPAIN + {201, CS_UNICODE_FSS, 0}, // codepoint collation + {220, CS_SJIS, 0}, // codepoint collation + {230, CS_EUCJ, 0} // codepoint collation }; enum scan_attr_t { - NO_SKIP = 0, /* Not in skipping and scanning mode */ - BEFORE_SKIP = 1, /* After skipping, before scanning next byte for valid attribute */ - AFTER_SKIP = 2 /* After skipping and after scanning next byte for valid attribute */ + NO_SKIP = 0, // Not in skipping and scanning mode + BEFORE_SKIP = 1, // After skipping, before scanning next byte for valid attribute + AFTER_SKIP = 2 // After skipping and after scanning next byte for valid attribute }; void add_files(const UCHAR *); @@ -191,7 +191,7 @@ void general_on_error (void); bool bug_8183 (TGBL); #endif #ifdef DEBUG -UCHAR debug_on = 0; /* able to turn this on in the debugger */ +UCHAR debug_on = 0; // able to turn this on in the debugger #endif bool flag_on_line = true; /* indicates whether we will bring @@ -201,7 +201,7 @@ bool flag_on_line = true; /* indicates whether we will bring #ifdef sparc const SSHORT old_sparcs[] = {0, 0, 0, 2, 0, 0, 0, 0, 2, 4, 4, 4, 8, 8, 0, 0, 8, 8, 8}; -#endif +#endif //MVOL_read returns int static inline int get(tgbl* tdgbl) @@ -239,21 +239,23 @@ static inline UCHAR* get_block(tgbl* tdgbl, UCHAR* p, ULONG n) // When skipping started, scan_next_attr will be changed from NO_SKIP // to BEFORE_SKIP. When scanning for next valid attribute after skipping, // it will flip-flop between BEFORE_SKIP and AFTER_SKIP. When next valid -// attribute is found, it will be changed back to NO_SKIP by 'SKIP_SCAN' +// attribute is found, it will be changed back to NO_SKIP by 'skip_scan' -static inline void SKIP_INIT(scan_attr_t *scan_next_attr) +static inline void skip_init(scan_attr_t* scan_next_attr) { *scan_next_attr = NO_SKIP; } -static inline bool SKIP_SCAN(scan_attr_t *scan_next_attr) +static inline void skip_scan(scan_attr_t* scan_next_attr) { - return (*scan_next_attr == AFTER_SKIP ? - *scan_next_attr = BEFORE_SKIP : - *scan_next_attr == BEFORE_SKIP ? - *scan_next_attr = NO_SKIP : 0); + if (*scan_next_attr == AFTER_SKIP) + *scan_next_attr = BEFORE_SKIP; + else if (*scan_next_attr == BEFORE_SKIP) + *scan_next_attr = NO_SKIP; + //else 0; => nothing, no change in the original macro } -/* User Privilege Flags */ + +// User Privilege Flags const int USER_PRIV_USER = 1; const int USER_PRIV_GRANTOR = 2; @@ -280,8 +282,8 @@ int RESTORE_restore (TEXT *file_name, * Recreate a database from a backup. * **************************************/ - isc_req_handle req_handle1 = NULL, req_handle2 = NULL, req_handle4 = NULL; - isc_req_handle req_handle3 = NULL; + isc_req_handle req_handle1 = NULL, req_handle2 = NULL, req_handle3 = NULL; + isc_req_handle req_handle4 = NULL; BASED_ON RDB$INDICES.RDB$INDEX_NAME index_name; TGBL tdgbl = GET_THREAD_DATA; @@ -300,11 +302,11 @@ int RESTORE_restore (TEXT *file_name, return FINI_ERROR; BURP_verbose (76, NULL, NULL, NULL, NULL, NULL); - /* msg 76 creating indexes */ + // msg 76 creating indexes COMMIT; ON_ERROR - /* Fix for bug_no 8055: + /* Fix for bug_no 8055: don't throw away the database just because an index could not be made */ long error_code; @@ -327,22 +329,22 @@ int RESTORE_restore (TEXT *file_name, if ( error_code == gds_no_dup ) { BURP_print(241, NULL, NULL, NULL, NULL, NULL); - /* msg 241 The unique index has duplicate values or NULLs */ + // msg 241 The unique index has duplicate values or NULLs BURP_print(242, NULL, NULL, NULL, NULL, NULL); - /* msg 242 Delete or Update duplicate values or NULLs, and activate index with */ + // msg 242 Delete or Update duplicate values or NULLs, and activate index with } else { BURP_print(244, NULL, NULL, NULL, NULL, NULL); - /* msg 244 Not enough disk space to create the sort file for an index */ + // msg 244 Not enough disk space to create the sort file for an index BURP_print(245, NULL, NULL, NULL, NULL, NULL); - /* msg 245 Set the TMP environment variable to a directory on a filesystem that does have enough space, and activate index with */ + // msg 245 Set the TMP environment variable to a directory on a filesystem that does have enough space, and activate index with } BURP_print(243, index_name, NULL, NULL, NULL, NULL); /* msg 243 ALTER INDEX \"%s\" ACTIVE; */ END_MODIFY; END_FOR; - /* don't bring the database on-line */ + // don't bring the database on-line flag_on_line = false; break; default: @@ -355,18 +357,18 @@ int RESTORE_restore (TEXT *file_name, END_ERROR } END_ERROR; - /* Activate the indices for foreign keys and do another commit */ + // Activate the indices for foreign keys and do another commit if (!(tdgbl->gbl_sw_deactivate_indexes)) { - /* Block added to verbose index creation by Toni Martir */ + // Block added to verbose index creation by Toni Martir if (tdgbl->gbl_sw_verbose) { EXEC SQL SET TRANSACTION ISOLATION LEVEL READ COMMITTED NO_AUTO_UNDO; - if (gds_status [1]) + if (gds_status [1]) EXEC SQL SET TRANSACTION; - /* Activate first indexes that are not foreign keys */ + // Activate first indexes that are not foreign keys FOR (REQUEST_HANDLE req_handle1) IDS IN RDB$INDICES WITH IDS.RDB$INDEX_INACTIVE EQ DEFERRED_ACTIVE AND IDS.RDB$FOREIGN_KEY MISSING @@ -375,13 +377,13 @@ int RESTORE_restore (TEXT *file_name, ON_ERROR general_on_error(); END_ERROR; - + SAVE - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (173, IDS.RDB$INDEX_NAME, NULL, NULL, NULL, NULL); - BURP_print_status (isc_status); - MODIFY IDS USING + BURP_print_status(isc_status); + MODIFY IDS USING IDS.RDB$INDEX_INACTIVE = TRUE; END_MODIFY; ON_ERROR @@ -402,22 +404,22 @@ int RESTORE_restore (TEXT *file_name, EXEC SQL SET TRANSACTION ISOLATION LEVEL READ COMMITTED NO_AUTO_UNDO; - if (gds_status [1]) + if (gds_status [1]) EXEC SQL SET TRANSACTION; /* Only activate Foreign keys that have been marked for deferred - * activation. - * -bsriram, 11-May-1999 BUG: 10016 + * activation. + * -bsriram, 11-May-1999 BUG: 10016 */ FOR (REQUEST_HANDLE req_handle1) - CNST IN RDB$RELATION_CONSTRAINTS + CNST IN RDB$RELATION_CONSTRAINTS CROSS IDS IN RDB$INDICES WITH CNST.RDB$CONSTRAINT_TYPE EQ FOREIGN_KEY AND CNST.RDB$INDEX_NAME EQ IDS.RDB$INDEX_NAME AND IDS.RDB$INDEX_INACTIVE EQ DEFERRED_ACTIVE - MODIFY IDS USING + MODIFY IDS USING IDS.RDB$INDEX_INACTIVE = FALSE; END_MODIFY; ON_ERROR @@ -425,11 +427,11 @@ int RESTORE_restore (TEXT *file_name, END_ERROR; SAVE - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (173, IDS.RDB$INDEX_NAME, NULL, NULL, NULL, NULL); - BURP_print_status (isc_status); - MODIFY IDS USING + BURP_print_status(isc_status); + MODIFY IDS USING IDS.RDB$INDEX_INACTIVE = TRUE; END_MODIFY; ON_ERROR @@ -451,15 +453,15 @@ int RESTORE_restore (TEXT *file_name, if (tdgbl->global_trans) { BURP_verbose (68, NULL, NULL, NULL, NULL, NULL); - /* msg 68 committing meta data */ + // msg 68 committing meta data EXEC SQL COMMIT TRANSACTION tdgbl->global_trans; if (gds_status [1]) general_on_error (); - /* Check to see if there is a warning */ - if (gds_status [0] == gds_arg_gds && gds_status [1] == 0 + // Check to see if there is a warning + if (gds_status [0] == gds_arg_gds && gds_status [1] == 0 && gds_status [2] != gds_arg_end) { - BURP_print_warning (gds_status); + BURP_print_warning(gds_status); } } @@ -467,7 +469,7 @@ int RESTORE_restore (TEXT *file_name, if (gds_status [1]) EXEC SQL SET TRANSACTION; /* - ** Change ownership of any procedures necessary + ** Change ownership of any procedures necessary */ for (BURP_PRC procedure = tdgbl->procedures; procedure; @@ -498,7 +500,7 @@ int RESTORE_restore (TEXT *file_name, MISC_release_request_silent(req_handle4); - /* Change ownership of any relations necessary */ + // Change ownership of any relations necessary for (BURP_REL relation = tdgbl->relations; relation; relation = relation->rel_next) { @@ -530,7 +532,7 @@ int RESTORE_restore (TEXT *file_name, /* Now that changing ownership of tables is over, it is safe to update the database security class in RDB$DATABASE */ - if (tdgbl->database_security_class[0]) /* Do it only if it's not NULL */ + if (tdgbl->database_security_class[0]) // Do it only if it's not NULL { FOR (REQUEST_HANDLE req_handle1) X IN RDB$DATABASE @@ -538,10 +540,10 @@ int RESTORE_restore (TEXT *file_name, strncpy(X.RDB$SECURITY_CLASS, tdgbl->database_security_class, sizeof(X.RDB$SECURITY_CLASS)); END_MODIFY; - ON_ERROR - MISC_release_request_silent(req_handle1); - general_on_error (); - END_ERROR; + ON_ERROR + MISC_release_request_silent(req_handle1); + general_on_error (); + END_ERROR; END_FOR; ON_ERROR MISC_release_request_silent(req_handle1); @@ -556,19 +558,19 @@ int RESTORE_restore (TEXT *file_name, general_on_error (); END_ERROR; - /* Check to see if there is a warning */ - if (gds_status [0] == gds_arg_gds && gds_status [1] == 0 + // Check to see if there is a warning + if (gds_status [0] == gds_arg_gds && gds_status [1] == 0 && gds_status [2] != gds_arg_end) { - BURP_print_warning (gds_status); + BURP_print_warning(gds_status); } BURP_verbose (88, NULL, NULL, NULL, NULL, NULL); - /* msg 88 finishing, closing, and going home */ + // msg 88 finishing, closing, and going home UINT64 cumul_count = MVOL_fini_read(); - /* attach database again to put it online */ + // attach database again to put it online UCHAR dpb[128]; UCHAR *d = dpb; @@ -599,10 +601,10 @@ int RESTORE_restore (TEXT *file_name, *d++ = *q++; } - /* set sync writes to engine default */ + // set sync writes to engine default *d++ = (UCHAR) gds_dpb_force_write; *d++ = 1; - *d++ = (UCHAR) tdgbl->hdr_forced_writes; + *d++ = (UCHAR) tdgbl->hdr_forced_writes; // set forced writes to the value which was in the header SSHORT l = d - dpb; @@ -624,9 +626,9 @@ int RESTORE_restore (TEXT *file_name, if (!flag_on_line) { BURP_print(246, NULL, NULL, NULL, NULL, NULL); - /* msg 246 Database is not online due to failure to activate one or more indices. */ + // msg 246 Database is not online due to failure to activate one or more indices. BURP_print(247, NULL, NULL, NULL, NULL, NULL); - /* msg 247 Run gfix -online to bring database online without active indices. */ + // msg 247 Run gfix -online to bring database online without active indices. return FINI_DB_NOT_ONLINE; } @@ -634,7 +636,7 @@ int RESTORE_restore (TEXT *file_name, if (tdgbl->gbl_sw_mode && tdgbl->gbl_sw_mode_val) { BURP_verbose (280, NULL, NULL, NULL, NULL, NULL); - /* msg 280: setting database to read-only access */ + // msg 280: setting database to read-only access d = dpb; *d++ = (UCHAR) gds_dpb_version1; @@ -659,7 +661,7 @@ int RESTORE_restore (TEXT *file_name, *d++ = (UCHAR) isc_dpb_set_db_readonly; *d++ = 1; - *d++ = TRUE; /* set database to readOnly mode */ + *d++ = TRUE; // set database to readOnly mode l = d - dpb; db_handle = 0; if (isc_attach_database (tdgbl->status_vector, 0, database_name, @@ -710,13 +712,13 @@ void add_files (const UCHAR *file_name) X IN RDB$FILES strcpy (X.RDB$FILE_NAME, file->fil_name); X.RDB$FILE_START = start; - END_STORE; + END_STORE; ON_ERROR general_on_error (); END_ERROR; MISC_release_request_silent(req_handle1); BURP_verbose (57, file->fil_name, (void*) start, NULL, NULL, NULL); - /* msg 57 adding file %s, starting at page %ld */ + // msg 57 adding file %s, starting at page %ld } else if (((signed long )file->fil_length) >= start - 1) file->fil_length -= start - 1; @@ -734,12 +736,12 @@ void add_files (const UCHAR *file_name) if (count) { BURP_verbose (70, NULL, NULL, NULL, NULL, NULL); - /* msg 70 committing secondary files */ + // msg 70 committing secondary files COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (174, NULL, NULL, NULL, NULL, NULL); - /* msg 174 cannot commit files */ + // msg 174 cannot commit files BURP_print_status (tdgbl->status_vector); ROLLBACK; ON_ERROR @@ -766,7 +768,7 @@ void bad_attribute (scan_attr_t scan_next_attr, * Functional description * We ran into an unsupported attribute. * but it isn't the end of the world. - * We will try to skip some bad data and + * We will try to skip some bad data and * look for next valid attribute to continue the process. * **************************************/ @@ -782,7 +784,7 @@ void bad_attribute (scan_attr_t scan_next_attr, gds__msg_format(NULL, 12, type, sizeof(t_name), t_name, NULL, NULL, NULL, NULL, NULL); BURP_print (80, t_name, (void*) bad_attr, NULL, NULL, NULL); - /* msg 80 don't recognize %s attribute %ld -- continuing */ + // msg 80 don't recognize %s attribute %ld -- continuing skip_l = get(tdgbl); if (skip_l) get_skip(tdgbl, skip_l); @@ -794,13 +796,13 @@ void bad_attribute (scan_attr_t scan_next_attr, skip_count = tdgbl->gbl_sw_skip_count; get_skip(tdgbl, skip_count); BURP_print (203, (void*) skip_count, (void*) bad_attr, NULL, NULL, NULL); - /*msg 203: skipped %d bytes after reading a bad attribute %d */ + //msg 203: skipped %d bytes after reading a bad attribute %d } else { skip_count ++; BURP_print (205, (void*) skip_count, (void*) bad_attr, NULL, NULL, NULL); - /* msg 205: skipped %d bytes looking for next valid attribute, encountered attribute %d */ + // msg 205: skipped %d bytes looking for next valid attribute, encountered attribute %d } scan_next_attr = AFTER_SKIP; } @@ -876,7 +878,7 @@ void create_database (const TEXT *file_name) sweep_interval = MAX_ULONG; bool no_reserve = false; bool db_read_only = false, SQL_dialect_flag = false; - USHORT forced_writes = 2; /* default for the current platform */ + USHORT forced_writes = 2; // default for the current platform ULONG page_buffers = 0; rec_type record; @@ -927,14 +929,14 @@ void create_database (const TEXT *file_name) if (record != rec_database) BURP_error_redirect (NULL, 32, 0, 0); - /* msg 32 Expected database description record */ + // msg 32 Expected database description record if (tdgbl->gbl_sw_page_size && (tdgbl->gbl_sw_page_size < page_size)) { BURP_print (110, (void*) page_size, (void*) (ULONG) tdgbl->gbl_sw_page_size, NULL, NULL, NULL); - /* msg 110 Reducing the database page size from %ld bytes to %ld bytes */ + // msg 110 Reducing the database page size from %ld bytes to %ld bytes } if (tdgbl->gbl_sw_page_size) @@ -945,7 +947,7 @@ void create_database (const TEXT *file_name) if (tdgbl->gbl_sw_no_reserve) no_reserve = tdgbl->gbl_sw_no_reserve != FALSE; - /* Override attribute setting with user requirement */ + // Override attribute setting with user requirement if (tdgbl->gbl_sw_mode) db_read_only = tdgbl->gbl_sw_mode_val; else @@ -993,17 +995,17 @@ void create_database (const TEXT *file_name) *d++ = (UCHAR) isc_dpb_user_name; *d++ = (UCHAR) strlen (tdgbl->gbl_sw_user); for (q = (UCHAR*) tdgbl->gbl_sw_user; *q;) - *d++ = *q++; + *d++ = *q++; } if (tdgbl->gbl_sw_password) { if (!tdgbl->gbl_sw_service_gbak) - *d++ = (UCHAR) isc_dpb_password; + *d++ = (UCHAR) isc_dpb_password; else - *d++ = (UCHAR) isc_dpb_password_enc; + *d++ = (UCHAR) isc_dpb_password_enc; *d++ = (UCHAR) strlen (tdgbl->gbl_sw_password); for (q = (UCHAR*) tdgbl->gbl_sw_password; *q;) - *d++ = *q++; + *d++ = *q++; } if (page_buffers) { @@ -1015,14 +1017,14 @@ void create_database (const TEXT *file_name) *d++ = (UCHAR) (page_buffers >> 24); } - /* Turn off sync writes during restore */ + // Turn off sync writes during restore *d++ = (UCHAR) isc_dpb_force_write; *d++ = 1; *d++ = 0; - /* - ** - ** which SQL dialect that this database speaks + /* + ** + ** which SQL dialect that this database speaks ** When we restore backup files that came from prior ** to V6, we force the SQL database dialect to 1 ** @@ -1034,8 +1036,8 @@ void create_database (const TEXT *file_name) *d++ = (UCHAR) SQL_dialect; else *d++ = (UCHAR) SQL_DIALECT_V5; - - /* start database up shut down */ + + // start database up shut down *d++ = (UCHAR) isc_dpb_shutdown; *d++ = 1; *d++ = (UCHAR) isc_dpb_shut_attachment; @@ -1047,11 +1049,11 @@ void create_database (const TEXT *file_name) l = d - dpb; // We'll have to fix the API someday, so const params are declared const. - if (isc_create_database (status_vector, 0, (TEXT*) file_name, + if (isc_create_database (status_vector, 0, (TEXT*) file_name, &DB, l, (SCHAR*) dpb, 0)) { BURP_error_redirect (status_vector, 33, file_name, 0); - /* msg 33 failed to create database %s */ + // msg 33 failed to create database %s } if (tdgbl->gbl_sw_version) @@ -1060,9 +1062,9 @@ void create_database (const TEXT *file_name) /* msg 139 Version(s) for database "%s" */ isc_version(&DB, (void (*)()) BURP_output_version, (void*) "\t%s\n"); } - + BURP_verbose (74, file_name, (void*) page_size, NULL, NULL, NULL); - /* msg 74 created database %s, page_size %ld bytes */ + // msg 74 created database %s, page_size %ld bytes } void decompress (UCHAR *buffer, @@ -1088,8 +1090,8 @@ void decompress (UCHAR *buffer, while (p < end) { - /* This change was made to restore National Semi-Conductor's corrupted */ - /* gbak file and it is in the code base now. -Andrew */ + // This change was made to restore National Semi-Conductor's corrupted + // gbak file and it is in the code base now. -Andrew count = (SCHAR) get(tdgbl); if (count > 0) @@ -1098,7 +1100,7 @@ void decompress (UCHAR *buffer, { BURP_print (202, (void*) (SLONG) count, (void*) (ULONG) (end - p), NULL, NULL, NULL); - /* msg 202: adjusting a decompression length error: invalid length %d was adjusted to %d */ + // msg 202: adjusting a decompression length error: invalid length %d was adjusted to %d count = end - p; } p = get_block(tdgbl, p, count); @@ -1109,7 +1111,7 @@ void decompress (UCHAR *buffer, { BURP_print(202, (void*) (SLONG) count, (void*) (ULONG) (p - end), NULL, NULL, NULL); - /* msg 202: adjusting a decompression length error: invalid length %d was adjusted to %d */ + // msg 202: adjusting a decompression length error: invalid length %d was adjusted to %d count = p - end; } c = get(tdgbl); @@ -1120,7 +1122,7 @@ void decompress (UCHAR *buffer, if (p > end) BURP_error_redirect (NULL, 34, 0, 0); - /* msg 34 RESTORE: decompression length error */ + // msg 34 RESTORE: decompression length error } void eat_blob (void) @@ -1166,7 +1168,7 @@ BURP_REL find_relation (const TEXT *name) return relation; BURP_error_redirect (NULL, 35, name, 0); - /* msg 35 can't find relation %s */ + // msg 35 can't find relation %s return NULL; } @@ -1203,14 +1205,14 @@ bool get_acl (const TEXT *owner_nm, * * open the blob that contains the ACL list * get the ACL list of a relation - * replace the owner of the relation in the ACL list with + * replace the owner of the relation in the ACL list with * the creator of the relation * create a new blob * store the new ACL list in the new blob * **************************************/ - static const SCHAR blr_items [] = {isc_info_blob_max_segment, + static const SCHAR blr_items [] = {isc_info_blob_max_segment, isc_info_blob_total_length, isc_info_blob_num_segments}; ISC_STATUS_ARRAY status_vector; @@ -1222,26 +1224,26 @@ bool get_acl (const TEXT *owner_nm, TGBL tdgbl = GET_THREAD_DATA; - /* If the blob is null, don't store it. It will be restored as null. */ + // If the blob is null, don't store it. It will be restored as null. if (!blob_id->gds_quad_high && !blob_id->gds_quad_low) return false; - /* Open the blob and get it's vital statistics */ + // Open the blob and get it's vital statistics FRBRD* blob = NULL; if (isc_open_blob (status_vector, &DB, &gds_trans, &blob, blob_id)) { - /* msg 24 gds__open_blob failed */ - BURP_error_redirect (status_vector, 24, NULL, NULL); + // msg 24 gds__open_blob failed + BURP_error_redirect (status_vector, 24, NULL, NULL); } if (isc_blob_info (status_vector, &blob, sizeof(blr_items), (SCHAR *) blr_items, sizeof(blob_info), (SCHAR*) blob_info)) { - /* msg 20 gds__blob_info failed */ - BURP_error_redirect (status_vector, 20, NULL, NULL); + // msg 20 gds__blob_info failed + BURP_error_redirect (status_vector, 20, NULL, NULL); } SLONG length = 0; @@ -1265,19 +1267,19 @@ bool get_acl (const TEXT *owner_nm, case isc_info_blob_num_segments: num_segments = (USHORT) n; - /* - ** we assume that the ACL list was written out as + /* + ** we assume that the ACL list was written out as ** in one big segment ** */ if (num_segments > 1) { - // CVC: I can't see the effect of assert(true) - assert (num_segments > 1); + // CVC: I can't see the effect of assert(true) + assert (num_segments > 1); } break; default: - /* msg 79 don't understand blob info item %ld */ + // msg 79 don't understand blob info item %ld BURP_print (79, (void*) (ULONG) item, NULL, NULL, NULL, NULL); // CVC: do you return, without closing the blob, dear function??? if (isc_close_blob (status_vector, &blob)) @@ -1290,19 +1292,19 @@ bool get_acl (const TEXT *owner_nm, if (!length) { if (isc_close_blob (status_vector, &blob)) - /* msg 23 gds__close_blob failed */ - BURP_error_redirect (status_vector, 23, NULL, NULL); + BURP_error_redirect (status_vector, 23, NULL, NULL); + // msg 23 gds__close_blob failed return false; } - /* Rdb sometimes gets the length messed up */ + // Rdb sometimes gets the length messed up if (length < max_segment) length = max_segment; - /* - ** Allocate a buffer large enough for the largest segment and start - ** grinding. + /* + ** Allocate a buffer large enough for the largest segment and start + ** grinding. */ if (!max_segment || max_segment <= sizeof(static_buffer)) @@ -1319,12 +1321,12 @@ bool get_acl (const TEXT *owner_nm, if (isc_close_blob (status_vector, &blob)) { if (buffer != static_buffer) - BURP_free (buffer); - /* msg 23 gds__close_blob failed */ - BURP_error_redirect (status_vector, 23, NULL, NULL); + BURP_free (buffer); + // msg 23 gds__close_blob failed + BURP_error_redirect (status_vector, 23, NULL, NULL); } - from = buffer + 3; /* skip ACL_version, ACL_id_list, and id_person */ + from = buffer + 3; // skip ACL_version, ACL_id_list, and id_person id_person_len = (int)*from; c_1 = (UCHAR*) owner_nm; @@ -1334,9 +1336,9 @@ bool get_acl (const TEXT *owner_nm, from = buffer; to = new_buffer; - *to++ = *from++; /* copy ACL_verion */ - *to++ = *from++; /* copy ACL_id_list */ - *to++ = *from++; /* copy id_person */ + *to++ = *from++; // copy ACL_verion + *to++ = *from++; // copy ACL_id_list + *to++ = *from++; // copy id_person *to++ = owner_nm_len; new_len = new_len + 4; from = buffer + id_person_len + 4; @@ -1357,11 +1359,11 @@ bool get_acl (const TEXT *owner_nm, &blob_handle, new_blob_id, 0, NULL)) { if (buffer != static_buffer) - BURP_free (buffer); + BURP_free (buffer); if (new_buffer != NULL) BURP_free (new_buffer); - /* msg 37 gds__create_blob failed */ - BURP_error_redirect (status_vector, 37, 0, 0); + // msg 37 gds__create_blob failed + BURP_error_redirect (status_vector, 37, 0, 0); } if (isc_put_segment (status_vector, &blob_handle, new_len, (SCHAR*) new_buffer)) @@ -1370,8 +1372,8 @@ bool get_acl (const TEXT *owner_nm, BURP_free (buffer); if (new_buffer != NULL) BURP_free (new_buffer); - /* msg 38 gds__put_segment failed */ - BURP_error_redirect (status_vector, 38, 0, 0); + // msg 38 gds__put_segment failed + BURP_error_redirect (status_vector, 38, 0, 0); } if (isc_close_blob (status_vector, &blob_handle)) @@ -1380,8 +1382,8 @@ bool get_acl (const TEXT *owner_nm, BURP_free (buffer); if (new_buffer != NULL) BURP_free (new_buffer); - /* msg 23 gds__close_blob failed */ - BURP_error_redirect (status_vector, 23, 0, 0); + // msg 23 gds__close_blob failed + BURP_error_redirect (status_vector, 23, 0, 0); } if (buffer != static_buffer) @@ -1416,20 +1418,20 @@ void get_array (BURP_REL relation, lcount; USHORT blr_length, count, field_number, field_length; UCHAR *buffer, *p; - UCHAR *blr, blr_buffer [200]; /* enough for a sdl with 16 dimensions */ + UCHAR *blr, blr_buffer [200]; // enough for a sdl with 16 dimensions LSTRING xdr_buffer, xdr_slice; scan_attr_t scan_next_attr; TGBL tdgbl = GET_THREAD_DATA; - /* don't free something you don't allocate */ + // don't free something you don't allocate xdr_buffer.lstr_allocated = 0; - /* Pick up attributes */ + // Pick up attributes - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) { switch (attribute) { @@ -1439,18 +1441,18 @@ void get_array (BURP_REL relation, if (field->fld_number == field_number) break; if (!field) - BURP_error_redirect (NULL, 36, 0, 0); - /* msg 36 Can't find field for blob */ + BURP_error_redirect (NULL, 36, 0, 0); + // msg 36 Can't find field for blob field_length = field->fld_length; if (field->fld_type == blr_varying) - field_length += sizeof(USHORT); + field_length += sizeof(USHORT); slice_length = field_length; - // + // // Copy the ranges onto a buffer and let the program // mess with the copy rather than the original // - memcpy(fld_ranges,field->fld_ranges, sizeof(fld_ranges)); + memcpy(fld_ranges,field->fld_ranges, sizeof(fld_ranges)); break; case att_array_dimensions: @@ -1459,13 +1461,13 @@ void get_array (BURP_REL relation, for (range = fld_ranges; range < end_ranges; range += 2) { if (get_attribute(&attribute, tdgbl) != att_array_range_low) - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array else range [0] = get_numeric(); if (get_attribute(&attribute, tdgbl) != att_array_range_high) - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array else range [1] = get_numeric(); slice_length *= (range [1] - range [0] + 1); @@ -1473,8 +1475,8 @@ void get_array (BURP_REL relation, break; default: - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array break; } } @@ -1486,7 +1488,7 @@ void get_array (BURP_REL relation, blob_id = (SLONG*) ((UCHAR*) record_buffer + field->fld_offset); - if (return_length != slice_length) + if (return_length != slice_length) { int current_dim, divisor, elements_remaining; int data_at, elements_written, upper, lower; @@ -1495,26 +1497,26 @@ void get_array (BURP_REL relation, // Ugh! The full array wasn't returned and versions of gbak prior to // V3.2I don't explicitly signal this. We must recompute the top // element to restore. - // - // Double Ugh! gbak (Versions prior to 5.0) while backing up calculates - // the top dimensions incorrectly So whatever was written as top dimensions + // + // Double Ugh! gbak (Versions prior to 5.0) while backing up calculates + // the top dimensions incorrectly So whatever was written as top dimensions // is useless. 5.0 gbak has written correct dimensions, but what the heck // we'll calculate it again // elements_remaining = return_length / field_length; // - // Backup (versions prior to 5.0) has surely written wrong dimensions. - // Ignore whatever is read in fld_ranges and calculate the dimensions - // of the last element. field->fld_ranges has the max dimensions. + // Backup (versions prior to 5.0) has surely written wrong dimensions. + // Ignore whatever is read in fld_ranges and calculate the dimensions + // of the last element. field->fld_ranges has the max dimensions. // last_element_dim holds only the upper bounds of each dimension. // - for (i1 = 0, i3 = 0; i1 < field->fld_dimensions; i1++) + for (i1 = 0, i3 = 0; i1 < field->fld_dimensions; i1++) { divisor = 1; for (i2 = (2 * (i1 + 1) + 1); i2 <= field->fld_dimensions * 2; i2 += 2) divisor *= (field->fld_ranges[i2] - field->fld_ranges[i2 - 1] + 1); - last_element_dim[i1] = + last_element_dim[i1] = (elements_remaining - 1) / divisor + field->fld_ranges[i3]; elements_remaining -= (last_element_dim[i1] - field->fld_ranges[i3]) * divisor; @@ -1522,15 +1524,15 @@ void get_array (BURP_REL relation, } #ifdef DEBUG ib_fprintf(ib_stderr, "\nLast element upper bounds read from backup file:\n"); - for(current_dim=1;current_dimfld_dimensions*2;current_dim+=2) + for (current_dim = 1; current_dim < field->fld_dimensions * 2; current_dim += 2) ib_fprintf(ib_stderr,"%ld ",fld_ranges[current_dim]); ib_fprintf(ib_stderr, "\nCalculated Last element upper bounds :\n"); - for(current_dim=0;current_dimfld_dimensions;current_dim++) + for (current_dim = 0; current_dim < field->fld_dimensions; current_dim++) ib_fprintf(ib_stderr,"%ld ",last_element_dim[current_dim]); ib_fprintf(ib_stderr,"return_length = %ld\n", return_length); ib_fprintf(ib_stderr,"elements_returned = %ld\n", return_length/field_length); ib_fprintf(ib_stderr,"Max dims["); - for(current_dim=1;current_dimfld_dimensions*2;current_dim+=2) + for (current_dim = 1; current_dim < field->fld_dimensions * 2; current_dim += 2) ib_fprintf(ib_stderr,"%ld ",field->fld_ranges[current_dim]); ib_fprintf(ib_stderr,"]"); #endif @@ -1541,16 +1543,16 @@ void get_array (BURP_REL relation, // to the engine. When the loop cycles through all dimensions, we would // have written the whole of the irregular slice. // - for (current_dim=0; current_dimfld_dimensions; current_dim++) + for (current_dim = 0; current_dim < field->fld_dimensions; current_dim++) { blr = blr_buffer; bool dont_write = false; - /* build the sdl */ + // build the sdl stuff(&blr, gds_sdl_version1); - stuff(&blr, gds_sdl_struct); + stuff(&blr, gds_sdl_struct); stuff(&blr, 1); if (field->fld_type == blr_text || field->fld_type == blr_varying) @@ -1563,7 +1565,7 @@ void get_array (BURP_REL relation, stuff_word(&blr, field->fld_length); } else if (field->fld_type == blr_short || field->fld_type == blr_long || - field->fld_type == blr_quad || field->fld_type == blr_int64) + field->fld_type == blr_quad || field->fld_type == blr_int64) { stuff(&blr, field->fld_type); stuff(&blr, field->fld_scale); @@ -1572,12 +1574,12 @@ void get_array (BURP_REL relation, stuff(&blr, field->fld_type); - stuff(&blr, gds_sdl_relation); + stuff(&blr, gds_sdl_relation); stuff_string(&blr, relation->rel_name); - stuff(&blr, gds_sdl_field); + stuff(&blr, gds_sdl_field); stuff_string(&blr, field->fld_name); - /* each element spec starts here */ + // each element spec starts here #ifdef DEBUG ib_fprintf(ib_stderr,"\nBounds written ["); @@ -1586,7 +1588,7 @@ void get_array (BURP_REL relation, end_ranges = field->fld_ranges + 2 * field->fld_dimensions; // // Here is the important work. Calculate the the bounds to be written - // so that the resulting slice is a rectangular/square slice. + // so that the resulting slice is a rectangular/square slice. // For a 2 dimensional array of size 1..N, 1..M, which is partially // filled, we have already calculated the dims of last element. Say // if this was x,y (x is row, y is column) then we do @@ -1598,7 +1600,7 @@ void get_array (BURP_REL relation, // isc_put_slice(x..x, y..y, 1..z); // This is applicable for any number of dimensions. // Special cases: - // for example in case of a 2D array (10,10) and if the last element + // for example in case of a 2D array (10,10) and if the last element // dims were (1,2), we would just do a isc_put_slice(1..1, 1..2). // This is applied for any number of dimensions. // @@ -1613,7 +1615,7 @@ void get_array (BURP_REL relation, // we blindly put slices without actually figuring out if we // really need to do so. For eg: if we have a 2D array of // size [10,4] and the last element dims are [6,4] then all - // we need to do is is to put one slice as + // we need to do is is to put one slice as // isc_put_slice(1..6,1..4) // rather than looping through the dimensions and putting // isc_put_slice(1..5,1..4) @@ -1623,71 +1625,73 @@ void get_array (BURP_REL relation, // the Special case should optimize the no of isc_put_slice // we perform. // - if( current_dim + 1 == field->fld_dimensions - 1 && + if (current_dim + 1 == field->fld_dimensions - 1 && field->fld_dimensions-count == 2 && - last_element_dim[count + 1] == range[3] ) + last_element_dim[count + 1] == range[3]) { - stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, range [0]); - lower = range [0]; + stuff(&blr, gds_sdl_long_integer); + stuff_long(&blr, range[0]); + lower = range[0]; stuff(&blr, gds_sdl_long_integer); stuff_long(&blr, last_element_dim [count]); - upper = last_element_dim [count]; + upper = last_element_dim[count]; elements_written *= (upper - lower + 1); range += 2; count++; stuff(&blr, gds_sdl_do2); stuff(&blr, count); stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, range [0]); - lower = range [0]; + stuff_long(&blr, range[0]); + lower = range[0]; stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, last_element_dim [count]); - upper=last_element_dim [count]; + stuff_long(&blr, last_element_dim[count]); + upper=last_element_dim[count]; elements_written *= (upper - lower + 1); ++current_dim; break; } - if( current_dim == count) + if (current_dim == count) { stuff(&blr, gds_sdl_long_integer); stuff_long(&blr, range [0]); lower = range [0]; - stuff(&blr, gds_sdl_long_integer); + stuff(&blr, gds_sdl_long_integer); upper = (current_dim == field->fld_dimensions - 1) ? last_element_dim [count] : (last_element_dim [count] - 1); - if( upper < range[0] ) + if (upper < range[0]) { - /** + /** see Special Case above **/ dont_write = true; break; } - stuff_long(&blr, upper); + stuff_long(&blr, upper); } - else if (current_dim < count) + else if (current_dim < count) { stuff(&blr, gds_sdl_long_integer); stuff_long(&blr, range [0]); stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, range [1]); - upper = range[1]; lower = range[0]; + stuff_long(&blr, range [1]); + upper = range[1]; + lower = range[0]; } - else if (current_dim > count) + else if (current_dim > count) { - stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, last_element_dim [count]); - stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, last_element_dim [count]); - upper=lower=last_element_dim [count]; + stuff(&blr, gds_sdl_long_integer); + stuff_long(&blr, last_element_dim [count]); + stuff(&blr, gds_sdl_long_integer); + stuff_long(&blr, last_element_dim [count]); + upper = lower = last_element_dim[count]; } elements_written *= (upper - lower + 1); #ifdef DEBUG ib_fprintf(ib_stderr,"%d..%d ",lower,upper); #endif } - if (dont_write) continue; + if (dont_write) + continue; #ifdef DEBUG ib_fprintf(ib_stderr,"]"); ib_fprintf(ib_stderr,"\n Elements Written=%d ",elements_written); @@ -1701,7 +1705,7 @@ void get_array (BURP_REL relation, for (count = 0; count < field->fld_dimensions; count++) { - stuff(&blr, gds_sdl_variable); + stuff(&blr, gds_sdl_variable); stuff(&blr, count); } @@ -1713,17 +1717,17 @@ void get_array (BURP_REL relation, #endif blr_length = blr - blr_buffer; - - if(data_at == 0) + + if (data_at == 0) { buffer = BURP_alloc (return_length); - if (tdgbl->gbl_sw_transportable) + if (tdgbl->gbl_sw_transportable) { if (get_attribute(&attribute, tdgbl) != att_xdr_array) - /* msg 55 Expected XDR record length */ + // msg 55 Expected XDR record length BURP_error_redirect (NULL, 55, 0, 0); - else + else { xdr_buffer.lstr_allocated = get(tdgbl); xdr_buffer.lstr_allocated |= get(tdgbl) << 8; @@ -1733,13 +1737,13 @@ void get_array (BURP_REL relation, xdr_buffer.lstr_address = BURP_alloc (xdr_buffer.lstr_allocated); xdr_slice.lstr_allocated = xdr_slice.lstr_length = return_length; xdr_slice.lstr_address = buffer; - p = xdr_buffer.lstr_address; + p = xdr_buffer.lstr_address; } } - else + else { p = buffer; - lcount = return_length; + lcount = return_length; } if (lcount) @@ -1749,15 +1753,15 @@ void get_array (BURP_REL relation, CAN_slice (&xdr_buffer, &xdr_slice, FALSE, blr_length, blr_buffer); } - if (isc_put_slice (status_vector, &DB, &gds_trans, + if (isc_put_slice (status_vector, &DB, &gds_trans, (ISC_QUAD*) blob_id, blr_length, reinterpret_cast(blr_buffer), - 0, /* param length for subset of an array handling */ - NULL, /* param for subset of an array handling */ + 0, // param length for subset of an array handling + NULL, // param for subset of an array handling elements_written * field->fld_length, - buffer+data_at)) + buffer + data_at)) { BURP_print (81, field->fld_name, NULL, NULL, NULL, NULL); - /* msg 81 error accessing blob field %s -- continuing */ + // msg 81 error accessing blob field %s -- continuing BURP_print_status (status_vector); #ifdef DEBUG PRETTY_print_sdl (blr_buffer, NULL, NULL, 0); @@ -1770,15 +1774,15 @@ void get_array (BURP_REL relation, #endif } } - else + else { /** This is the regular case we've got the entire array **/ blr = blr_buffer; - /* build the sdl */ + // build the sdl stuff(&blr, gds_sdl_version1); - stuff(&blr, gds_sdl_struct); + stuff(&blr, gds_sdl_struct); stuff(&blr, 1); if (field->fld_type == blr_text || field->fld_type == blr_varying) @@ -1800,12 +1804,12 @@ void get_array (BURP_REL relation, stuff(&blr, field->fld_type); - stuff(&blr, gds_sdl_relation); + stuff(&blr, gds_sdl_relation); stuff_string(&blr, relation->rel_name); - stuff(&blr, gds_sdl_field); + stuff(&blr, gds_sdl_field); stuff_string(&blr, field->fld_name); - /* each element spec starts here */ + // each element spec starts here for (range = fld_ranges, count = 0; range < end_ranges; range += 2, count++) { @@ -1814,7 +1818,7 @@ void get_array (BURP_REL relation, stuff(&blr, gds_sdl_long_integer); stuff_long(&blr, range [0]); stuff(&blr, gds_sdl_long_integer); - stuff_long(&blr, range [1]); + stuff_long(&blr, range [1]); } stuff(&blr, gds_sdl_element); @@ -1844,8 +1848,8 @@ void get_array (BURP_REL relation, { if (get_attribute(&attribute, tdgbl) != att_xdr_array) BURP_error_redirect (NULL, 55, 0, 0); - /* msg 55 Expected XDR record length */ - else + // msg 55 Expected XDR record length + else { xdr_buffer.lstr_allocated = get(tdgbl); xdr_buffer.lstr_allocated |= get(tdgbl) << 8; @@ -1855,13 +1859,13 @@ void get_array (BURP_REL relation, xdr_buffer.lstr_address = BURP_alloc (xdr_buffer.lstr_allocated); xdr_slice.lstr_allocated = xdr_slice.lstr_length = return_length; xdr_slice.lstr_address = buffer; - p = xdr_buffer.lstr_address; + p = xdr_buffer.lstr_address; } } else { p = buffer; - lcount = return_length; + lcount = return_length; } if (lcount) @@ -1871,15 +1875,15 @@ void get_array (BURP_REL relation, CAN_slice (&xdr_buffer, &xdr_slice, FALSE, blr_length, blr_buffer); - if (isc_put_slice (status_vector, &DB, &gds_trans, + if (isc_put_slice (status_vector, &DB, &gds_trans, (ISC_QUAD*) blob_id, blr_length, reinterpret_cast(blr_buffer), - 0, /* param length for subset of an array handling */ - NULL, /* param for subset of an array handling */ + 0, // param length for subset of an array handling + NULL, // param for subset of an array handling return_length, buffer)) { BURP_print (81, field->fld_name, NULL, NULL, NULL, NULL); - /* msg 81 error accessing blob field %s -- continuing */ + // msg 81 error accessing blob field %s -- continuing BURP_print_status (status_vector); #ifdef DEBUG PRETTY_print_sdl (blr_buffer, NULL, NULL, 0); @@ -1916,12 +1920,12 @@ void get_blob (BURP_FLD fields, TGBL tdgbl = GET_THREAD_DATA; - /* Pick up attributes */ + // Pick up attributes ULONG segments = 0; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) { switch (attribute) { @@ -1942,13 +1946,13 @@ void get_blob (BURP_FLD fields, break; default: - bad_attribute (scan_next_attr, attribute, 64); - /* msg 64 blob */ + bad_attribute (scan_next_attr, attribute, 64); + // msg 64 blob break; } } - /* Find the field associated with the blob */ + // Find the field associated with the blob for (field = fields; field; field = field->fld_next) if (field->fld_number == field_number) @@ -1956,28 +1960,28 @@ void get_blob (BURP_FLD fields, if (!field) BURP_error_redirect (NULL, 36, 0, 0); - /* msg 36 Can't find field for blob */ + // msg 36 Can't find field for blob - /* Create new blob */ + // Create new blob ISC_QUAD* blob_id = (ISC_QUAD*) ((UCHAR*) record_buffer + field->fld_offset); FRBRD* blob = NULL; - if (isc_create_blob (status_vector, &DB, &gds_trans, &blob, + if (isc_create_blob (status_vector, &DB, &gds_trans, &blob, (ISC_QUAD*) blob_id)) { - BURP_error_redirect (status_vector, 37, 0, 0); - /* msg 37 gds__create_blob failed */ + BURP_error_redirect (status_vector, 37, 0, 0); + // msg 37 gds__create_blob failed } - /* Allocate blob buffer is static buffer is too short */ + // Allocate blob buffer is static buffer is too short if (!max_segment || max_segment <= sizeof(static_buffer)) buffer = static_buffer; else buffer = BURP_alloc (max_segment); - /* Eat up blob segments */ + // Eat up blob segments for (; segments > 0; --segments ) { @@ -1989,12 +1993,12 @@ void get_blob (BURP_FLD fields, } if (isc_put_segment (status_vector, &blob, length, (SCHAR*) buffer)) BURP_error_redirect (status_vector, 38, 0, 0); - /* msg 38 gds__put_segment failed */ + // msg 38 gds__put_segment failed } if (isc_close_blob (status_vector, &blob)) - BURP_error_redirect (status_vector, 23, 0, 0); - /* msg 23 gds__close_blob failed */ + BURP_error_redirect (status_vector, 23, 0, 0); + // msg 23 gds__close_blob failed if (buffer != static_buffer) BURP_free (buffer); @@ -2016,14 +2020,14 @@ void get_blr_blob (ISC_QUAD *blob_id, * **************************************/ ISC_STATUS_ARRAY status_vector; - UCHAR *buffer, static_buffer [1024], *p; + UCHAR *buffer, static_buffer[1024], *p; isc_tr_handle local_trans; TGBL tdgbl = GET_THREAD_DATA; ULONG length = (ULONG)get_numeric(); - /* Create new blob */ + // Create new blob FRBRD* blob = NULL; @@ -2033,12 +2037,14 @@ void get_blr_blob (ISC_QUAD *blob_id, local_trans = gds_trans; if (isc_create_blob (status_vector, &DB, &local_trans, &blob, blob_id)) - BURP_error_redirect (status_vector, 37, 0, 0); - /* msg 37 gds__create_blob failed */ + { + BURP_error_redirect (status_vector, 37, 0, 0); + // msg 37 gds__create_blob failed + } - /* Allocate blob buffer is static buffer is too short */ + // Allocate blob buffer is static buffer is too short - /* 03 Jun 2003. Nickolay Samofatov. Workaround bug of GCC 3.2.X #11068. + /* 03 Jun 2003. Nickolay Samofatov. Workaround bug of GCC 3.2.X #11068. Original code was: if (!length || length + 1 <= (USHORT)(sizeof(static_buffer)) ) */ @@ -2050,7 +2056,7 @@ void get_blr_blob (ISC_QUAD *blob_id, if (length) { p = get_block(tdgbl, buffer, length); - /* Make sure it has an eoc */ + // Make sure it has an eoc if (p[-1] != blr_eoc) { p[0] = blr_eoc; length++; @@ -2058,12 +2064,12 @@ void get_blr_blob (ISC_QUAD *blob_id, } if (isc_put_segment (status_vector, &blob, length, (SCHAR*) buffer)) - BURP_error_redirect (status_vector, 38, 0, 0); - /* msg 38 gds__put_segment failed */ + BURP_error_redirect (status_vector, 38, 0, 0); + // msg 38 gds__put_segment failed if (isc_close_blob (status_vector, &blob)) - BURP_error_redirect (status_vector, 23, 0, 0); - /* msg 23 gds__close_blob failed */ + BURP_error_redirect (status_vector, 23, 0, 0); + // msg 23 gds__close_blob failed if (buffer != static_buffer) BURP_free (buffer); @@ -2097,9 +2103,9 @@ bool get_character_set (void) X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$FUNCTION_NAME.NULL = TRUE; X.RDB$BYTES_PER_CHARACTER.NULL = TRUE; - - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -2152,7 +2158,7 @@ bool get_character_set (void) break; default: - bad_attribute (scan_next_attr, attribute, msgErr_restore_charset); + bad_attribute (scan_next_attr, attribute, msgErr_restore_charset); /* RDB$CHARSETS */ break; } @@ -2169,7 +2175,7 @@ bool get_chk_constraint (void) { /************************************** * - * g e t _ c h k _ c o n s t r a i n t + * g e t _ c h k _ c o n s t r a i n t * ************************************** * @@ -2186,8 +2192,8 @@ bool get_chk_constraint (void) X IN RDB$CHECK_CONSTRAINTS X.RDB$CONSTRAINT_NAME.NULL = TRUE; X.RDB$TRIGGER_NAME.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -2202,8 +2208,8 @@ bool get_chk_constraint (void) break; default: - bad_attribute (scan_next_attr, attribute, 208); - /* msg 208 relation constraint */ + bad_attribute (scan_next_attr, attribute, 208); + // msg 208 relation constraint break; } } @@ -2242,8 +2248,8 @@ bool get_collation (void) X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$FUNCTION_NAME.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -2270,9 +2276,8 @@ bool get_collation (void) X.RDB$COLLATION_ATTRIBUTES = (USHORT) get_numeric(); break; - case att_coll_subtype: /* No longer used: 93-11-15 DBS */ - /* still present to handle V4 R&D - gbak files */ + case att_coll_subtype: // No longer used: 93-11-15 DBS + // still present to handle V4 R&D gbak files get_numeric(); break; @@ -2330,12 +2335,12 @@ rec_type get_data (BURP_REL relation) TGBL tdgbl = GET_THREAD_DATA; - /* If we're only doing meta-data, ignore data records */ + // If we're only doing meta-data, ignore data records if (tdgbl->gbl_sw_meta) return ignore_data (relation); - /* Start by counting the interesting fields */ + // Start by counting the interesting fields RCRD_OFFSET offset = 0; ULONG length = 0; @@ -2353,7 +2358,7 @@ rec_type get_data (BURP_REL relation) if (tdgbl->RESTORE_format >= 2) count += count; - /* Time to generate blr to store data. Whoppee. */ + // Time to generate blr to store data. Whoppee. UCHAR* const blr_buffer = (UCHAR*) BURP_alloc (200 + length + count * 18); UCHAR* blr = blr_buffer; @@ -2361,8 +2366,8 @@ rec_type get_data (BURP_REL relation) stuff(&blr, blr_version4); stuff(&blr, blr_begin); stuff(&blr, blr_message); - stuff(&blr, 0); /* Message number */ - stuff_word(&blr, count); /* Number of fields, counting eof */ + stuff(&blr, 0); // Message number + stuff_word(&blr, count); // Number of fields, counting eof // Let's reset count. count = 0; @@ -2370,16 +2375,16 @@ rec_type get_data (BURP_REL relation) for (field = relation->rel_fields; field; field = field->fld_next) { if (field->fld_flags & FLD_computed) - continue; + continue; - /* arrays are of various fld_types but are really blobs */ + // arrays are of various fld_types but are really blobs dtype = field->fld_type; length = field->fld_length; alignment = 4; if (field->fld_flags & FLD_array) - dtype = blr_blob; + dtype = blr_blob; if (dtype <= DTYPE_BLR_MAX) { @@ -2400,9 +2405,9 @@ rec_type get_data (BURP_REL relation) stuff_word(&blr, field->fld_character_set_id); stuff_word(&blr, field->fld_length); if (dtype == blr_varying) - length += sizeof(USHORT); + length += sizeof(USHORT); break; - + case blr_short: case blr_long: case blr_quad: @@ -2425,14 +2430,14 @@ rec_type get_data (BURP_REL relation) stuff(&blr, blr_quad); stuff(&blr, 0); break; - - default: + + default: #ifdef SUPERSERVER BURP_svc_error (26, isc_arg_number, (void*) (SLONG) field->fld_type, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (26, (void*) (SLONG) field->fld_type, 0, 0, 0, 0); - /* msg 26 datatype %ld not understood */ + // msg 26 datatype %ld not understood #endif break; } @@ -2443,7 +2448,7 @@ rec_type get_data (BURP_REL relation) offset += length; } - /* If this is format version 2, build fields for null flags */ + // If this is format version 2, build fields for null flags if (tdgbl->RESTORE_format >= 2) for (field = relation->rel_fields; field; field = field->fld_next) @@ -2459,25 +2464,25 @@ rec_type get_data (BURP_REL relation) length = offset; - /* Build STORE statement */ + // Build STORE statement stuff(&blr, blr_receive); stuff(&blr, 0); stuff(&blr, blr_store); stuff(&blr, blr_relation); stuff_string(&blr, relation->rel_name); - stuff(&blr, 0); /* context variable */ + stuff(&blr, 0); // context variable stuff(&blr, blr_begin); for (field = relation->rel_fields; field; field = field->fld_next) { if (field->fld_flags & FLD_computed) - continue; + continue; stuff(&blr, blr_assignment); if (tdgbl->RESTORE_format >= 2) { stuff(&blr, blr_parameter2); - stuff(&blr, 0); + stuff(&blr, 0); stuff_word(&blr, field->fld_parameter); stuff_word(&blr, field->fld_missing_parameter); } @@ -2496,7 +2501,7 @@ rec_type get_data (BURP_REL relation) stuff(&blr, blr_end); stuff(&blr, blr_eoc); - /* Compile request */ + // Compile request #ifdef DEBUG isc_print_blr (blr_buffer, NULL, NULL, 0); @@ -2506,26 +2511,26 @@ rec_type get_data (BURP_REL relation) ISC_STATUS_ARRAY status_vector; USHORT blr_length = blr - blr_buffer; - if (isc_compile_request (status_vector, &DB, &request, + if (isc_compile_request (status_vector, &DB, &request, blr_length, reinterpret_cast(blr_buffer))) { isc_print_blr(reinterpret_cast(blr_buffer), NULL, NULL, 0); if (!tdgbl->gbl_sw_incremental) - BURP_error_redirect (status_vector, 27, 0, 0); - /* msg 27 gds__compile_request failed */ + BURP_error_redirect (status_vector, 27, 0, 0); + // msg 27 gds__compile_request failed else { - BURP_print_status (status_vector); + BURP_print_status (status_vector); BURP_free (blr_buffer); - return ignore_data (relation); + return ignore_data (relation); } } - + BURP_free (blr_buffer); buffer = NULL; BURP_verbose (124, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 124 restoring data for relation %s */ + // msg 124 restoring data for relation %s data.lstr_allocated = 0; data.lstr_address = NULL; @@ -2538,7 +2543,7 @@ rec_type get_data (BURP_REL relation) { if (get(tdgbl) != att_data_length) BURP_error_redirect (NULL, 39, 0, 0); - /* msg 39 expected record length */ + // msg 39 expected record length l = (USHORT) get_numeric(); if (!tdgbl->gbl_sw_transportable && l != length) { @@ -2552,18 +2557,18 @@ rec_type get_data (BURP_REL relation) 0, NULL, 0, NULL, 0, NULL); #else BURP_error (40, (void*) length, (void*)(ULONG) l, 0, 0, 0); - /* msg 40 wrong length record, expected %ld encountered %ld */ + // msg 40 wrong length record, expected %ld encountered %ld #endif } } if (!buffer) buffer = (SSHORT *) BURP_alloc (MAX (length, l)); - if (tdgbl->gbl_sw_transportable) + if (tdgbl->gbl_sw_transportable) { if (get(tdgbl) != att_xdr_length) BURP_error_redirect (NULL, 55, 0, 0); - /* msg 55 Expected XDR record length */ + // msg 55 Expected XDR record length else { data.lstr_length = l = (USHORT) get_numeric(); @@ -2581,7 +2586,7 @@ rec_type get_data (BURP_REL relation) p = (TEXT*) buffer; if (get(tdgbl) != att_data_data) BURP_error_redirect (NULL, 41, 0, 0); - /* msg 41 expected data attribute */ + // msg 41 expected data attribute if (tdgbl->gbl_sw_compress) decompress ((UCHAR*) p, l); @@ -2595,12 +2600,12 @@ rec_type get_data (BURP_REL relation) if (tdgbl->gbl_sw_transportable) CAN_encode_decode (relation, &data, (UCHAR *)buffer, FALSE); - + records++; - + if ((records % RESTORE_VERBOSE_INTERVAL) == 0) BURP_verbose(107, (void*) (SLONG) records, NULL, NULL, NULL, NULL); - + for (field = relation->rel_fields; field; field = field->fld_next) if ((field->fld_type == blr_blob) || (field->fld_flags & FLD_array)) { @@ -2627,23 +2632,23 @@ rec_type get_data (BURP_REL relation) if (tdgbl->gbl_sw_incremental) { BURP_print (138, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 138 validation error on field in relation %s */ + // msg 138 validation error on field in relation %s BURP_print_status (status_vector); } else BURP_error_redirect (status_vector, 47, 0, 0); - /* msg 47 warning -- record could not be restored */ + // msg 47 warning -- record could not be restored } else { if (tdgbl->gbl_sw_incremental) { BURP_print (114, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 114 restore failed for record in relation %s */ + // msg 114 restore failed for record in relation %s BURP_print_status (status_vector); } else BURP_error_redirect (status_vector, 48, 0, 0); - /* msg 48 gds__send failed */ + // msg 48 gds__send failed } } if (record != rec_data) @@ -2658,9 +2663,9 @@ rec_type get_data (BURP_REL relation) if (tdgbl->gbl_sw_incremental) { BURP_verbose (72, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 72 committing data for relation %s */ + // msg 72 committing data for relation %s COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR /* Fix for bug_no 8055: @@ -2683,24 +2688,24 @@ rec_type get_data (BURP_REL relation) if ( error_code == gds_no_dup ) { BURP_print(241, NULL, NULL, NULL, NULL, NULL); - /* msg 241 The unique index has duplicate values or NULLs */ + // msg 241 The unique index has duplicate values or NULLs BURP_print(242, NULL, NULL, NULL, NULL, NULL); - /* msg 242 Delete or Update duplicate values or NULLs, and activate index with */ + // msg 242 Delete or Update duplicate values or NULLs, and activate index with } else { BURP_print(244, NULL, NULL, NULL, NULL, NULL); - /* msg 244 Not enough disk space to create the sort file for an index */ + // msg 244 Not enough disk space to create the sort file for an index BURP_print(245, NULL, NULL, NULL, NULL, NULL); - /* msg 245 Set the TMP environment variable to a directory on a filesystem that does have enough space, and activate index with */ + // msg 245 Set the TMP environment variable to a directory on a filesystem that does have enough space, and activate index with } BURP_print(243, index_name, NULL, NULL, NULL, NULL); /* msg 243 ALTER INDEX \"%s\" ACTIVE; */ END_MODIFY; END_FOR; - /* don't bring the database on-line */ + // don't bring the database on-line flag_on_line = false; - /* commit one more time */ + // commit one more time COMMIT ON_ERROR continue; @@ -2708,15 +2713,15 @@ rec_type get_data (BURP_REL relation) break; default: BURP_print (69, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 69 commit failed on relation %s */ + // msg 69 commit failed on relation %s BURP_print_status (tdgbl->status_vector); ROLLBACK; ON_ERROR general_on_error (); END_ERROR; break; - } /* end of switch */ - } /* end of while */ + } // end of switch + } // end of while END_ERROR; EXEC SQL SET TRANSACTION NO_AUTO_UNDO; @@ -2724,7 +2729,7 @@ rec_type get_data (BURP_REL relation) EXEC SQL SET TRANSACTION; } BURP_verbose (107, (void*) (SLONG) records, NULL, NULL, NULL, NULL); - /* msg 107 %ld records restored */ + // msg 107 %ld records restored return record; } @@ -2752,8 +2757,8 @@ bool get_exception(void) X IN RDB$EXCEPTIONS X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$MESSAGE.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -2761,7 +2766,7 @@ bool get_exception(void) l = GET_TEXT(X.RDB$EXCEPTION_NAME); MISC_terminate (X.RDB$EXCEPTION_NAME, temp, l, sizeof(temp)); BURP_verbose (199, temp, NULL, NULL, NULL, NULL); - /* msg 199 restoring exception %s */ + // msg 199 restoring exception %s break; case att_exception_description: @@ -2780,8 +2785,8 @@ bool get_exception(void) break; default: - bad_attribute (scan_next_attr, attribute, 89); - /* msg 89 function */ + bad_attribute (scan_next_attr, attribute, 89); + // msg 89 function break; } } @@ -2817,7 +2822,7 @@ bool cvt_v3_to_v4_intl (SSHORT dtype, * contain a NULL byte, and can therefore not be represented * using a c-string datatype, always use fixed". * - * Return true if a conversion was performed, FALSE otherwise. + * Return true if a conversion was performed, false otherwise. * **************************************/ SSHORT i; @@ -2827,38 +2832,38 @@ bool cvt_v3_to_v4_intl (SSHORT dtype, case blr_text2: case blr_varying2: case blr_cstring2: - + case blr_text: case blr_varying: case blr_cstring: - /* Japanese V3.2 used SCALE 5 to indicate SJIS text */ + // Japanese V3.2 used SCALE 5 to indicate SJIS text if (*scale == 5 && ((*sub_type == 0) || (*sub_type == 1))) - { + { *character_set_id = CS_JIS_0208; *collation_id = 0; BURP_verbose (237, (void*) (SLONG) *scale, - (void*) (SLONG) *character_set_id, + (void*) (SLONG) *character_set_id, (void*) (SLONG) *collation_id, NULL, NULL); - /* msg 237: Converted V3 scale: %d to + /* msg 237: Converted V3 scale: %d to character_set_id: %d and callate_id: %d. */ *scale = 0; return true; - } + } - /* Japanese V3.2 used SCALE 6 to indicate EUCJ text */ + // Japanese V3.2 used SCALE 6 to indicate EUCJ text if (*scale == 6 && (*sub_type == 0 || *sub_type == 1)) - { + { *character_set_id = CS_EUCJ; *collation_id = 0; BURP_verbose (237, (void*) (SLONG) *scale, - (void*) (SLONG) *character_set_id, + (void*) (SLONG) *character_set_id, (void*) (SLONG) *collation_id, NULL, NULL); - /* msg 237: Converted V3 scale: %d to + /* msg 237: Converted V3 scale: %d to character_set_id: %d and callate_id: %d. */ *scale = 0; return true; - } + } /* V3.3 used SCALE 0 and Subtypes in range 100 - 255 for European text types and collations */ @@ -2867,7 +2872,7 @@ bool cvt_v3_to_v4_intl (SSHORT dtype, return false; if (*sub_type == 0 || *sub_type == 1) - /* Do not process sub_type 0,1 conversion */ + // Do not process sub_type 0,1 conversion return false; for (i = 0; i < cvtbl_len; i ++) @@ -2877,9 +2882,9 @@ bool cvt_v3_to_v4_intl (SSHORT dtype, *collation_id = sub_type_cvtbl [i].collation_id; BURP_verbose (236, (void*) (SLONG) *sub_type, - (void*) (SLONG) *character_set_id, + (void*) (SLONG) *character_set_id, (void*) (SLONG) *collation_id, NULL, NULL); - /* msg 236: Converted V3 sub_type: %d to + /* msg 236: Converted V3 sub_type: %d to character_set_id: %d and callate_id: %d. */ *sub_type = 0; @@ -2888,7 +2893,7 @@ bool cvt_v3_to_v4_intl (SSHORT dtype, return false; default: - /* Do not process sub_type conversion on non-text field */ + // Do not process sub_type conversion on non-text field return false; } @@ -2946,10 +2951,10 @@ BURP_FLD get_field (BURP_REL relation) X.RDB$DEFAULT_VALUE.NULL = TRUE; X.RDB$NULL_FLAG.NULL = TRUE; X.RDB$COLLATION_ID.NULL = TRUE; - SKIP_INIT(&scan_next_attr); + skip_init(&scan_next_attr); while (get_attribute(&attribute, tdgbl) != att_end) { - switch (SKIP_SCAN(&scan_next_attr), attribute) + switch (skip_scan(&scan_next_attr), attribute) { case att_field_name: field->fld_name_length = GET_TEXT(field->fld_name); @@ -3098,14 +3103,14 @@ BURP_FLD get_field (BURP_REL relation) break; default: - bad_attribute (scan_next_attr, attribute, 84); + bad_attribute (scan_next_attr, attribute, 84); // msg 84 field break; } } /* For migration from V3.3 to V4.0 format of International text - * information - search the list of global fields which were + * information - search the list of global fields which were * remapped from V3.3 format into V4.0 format. If we find that * this local field's source is one of those global fields, then * remap the local field's information. This is used to compose @@ -3150,8 +3155,8 @@ bool get_field_dimensions (void) STORE (REQUEST_HANDLE tdgbl->handles_get_field_dimensions_req_handle1) X IN RDB$FIELD_DIMENSIONS - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3172,8 +3177,8 @@ bool get_field_dimensions (void) break; default: - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array break; } } @@ -3206,16 +3211,16 @@ bool get_files (void) STORE (REQUEST_HANDLE tdgbl->handles_get_files_req_handle1) X IN RDB$FILES X.RDB$FILE_FLAGS = 0; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { case att_file_filename: GET_TEXT(X.RDB$FILE_NAME); BURP_verbose (116, - /* msg 116 restoring file %s */ X.RDB$FILE_NAME, NULL, NULL, NULL, NULL); + // msg 116 restoring file %s break; case att_file_sequence: @@ -3241,8 +3246,8 @@ bool get_files (void) break; default: - bad_attribute (scan_next_attr, attribute, 85); - /* msg 85 file */ + bad_attribute (scan_next_attr, attribute, 85); + // msg 85 file break; } } @@ -3274,15 +3279,15 @@ bool get_filter (void) STORE (REQUEST_HANDLE tdgbl->handles_get_filter_req_handle1) X IN RDB$FILTERS X.RDB$DESCRIPTION.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { case att_filter_name: GET_TEXT(X.RDB$FUNCTION_NAME); BURP_verbose (117, X.RDB$FUNCTION_NAME, NULL, NULL, NULL, NULL); - /* msg 117 restoring filter %s */ + // msg 117 restoring filter %s break; case att_filter_description: @@ -3312,8 +3317,8 @@ bool get_filter (void) break; default: - bad_attribute (scan_next_attr, attribute, 87); - /* msg 87 filter */ + bad_attribute (scan_next_attr, attribute, 87); + // msg 87 filter break; } } @@ -3347,8 +3352,8 @@ bool get_function (void) STORE (REQUEST_HANDLE tdgbl->handles_get_function_req_handle1) X IN RDB$FUNCTIONS - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3356,7 +3361,7 @@ bool get_function (void) l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate (X.RDB$FUNCTION_NAME, temp, l, sizeof(temp)); BURP_verbose (118, temp, NULL, NULL, NULL, NULL); - /* msg 118 restoring function %s */ + // msg 118 restoring function %s break; case att_function_description: @@ -3388,8 +3393,8 @@ bool get_function (void) break; default: - bad_attribute (scan_next_attr, attribute, 89); - /* msg 89 function */ + bad_attribute (scan_next_attr, attribute, 89); + // msg 89 function break; } } @@ -3399,7 +3404,7 @@ bool get_function (void) general_on_error (); END_ERROR; - /* at the end of args for a function is the rec_function_end marker */ + // at the end of args for a function is the rec_function_end marker while (get(tdgbl) == rec_function_arg) get_function_arg(); @@ -3434,8 +3439,8 @@ void get_function_arg() X.RDB$CHARACTER_SET_ID.NULL = TRUE; X.RDB$FIELD_PRECISION.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3443,7 +3448,7 @@ void get_function_arg() l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate (X.RDB$FUNCTION_NAME, temp, l, sizeof(temp)); BURP_verbose (119, temp, NULL, NULL, NULL, NULL); - /* msg 119 restoring argument for function %s */ + // msg 119 restoring argument for function %s break; case att_functionarg_position: @@ -3482,14 +3487,14 @@ void get_function_arg() break; default: - bad_attribute (scan_next_attr, attribute, 90); - /* msg 90 function argument */ + bad_attribute (scan_next_attr, attribute, 90); + // msg 90 function argument break; } } END_STORE; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; } else @@ -3500,8 +3505,8 @@ void get_function_arg() X.RDB$FIELD_SUB_TYPE.NULL = TRUE; X.RDB$CHARACTER_SET_ID.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3509,7 +3514,7 @@ void get_function_arg() l = GET_TEXT(X.RDB$FUNCTION_NAME); MISC_terminate (X.RDB$FUNCTION_NAME, temp, l, sizeof(temp)); BURP_verbose (119, temp, NULL, NULL, NULL, NULL); - /* msg 119 restoring argument for function %s */ + // msg 119 restoring argument for function %s break; case att_functionarg_position: @@ -3543,14 +3548,14 @@ void get_function_arg() break; default: - bad_attribute (scan_next_attr, attribute, 90); - /* msg 90 function argument */ + bad_attribute (scan_next_attr, attribute, 90); + // msg 90 function argument break; } } END_STORE; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; } } @@ -3577,8 +3582,8 @@ bool get_generator (void) scan_attr_t scan_next_attr; TGBL tdgbl = GET_THREAD_DATA; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3597,7 +3602,7 @@ bool get_generator (void) break; default: - bad_attribute (scan_next_attr, attribute, 93); + bad_attribute (scan_next_attr, attribute, 93); // msg 93 index break; } @@ -3665,8 +3670,8 @@ bool get_global_field (void) X.RDB$FIELD_PRECISION.NULL = TRUE; memset (X.RDB$QUERY_NAME, ' ', sizeof(X.RDB$QUERY_NAME)); - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3674,7 +3679,7 @@ bool get_global_field (void) l = GET_TEXT(X.RDB$FIELD_NAME); MISC_terminate (X.RDB$FIELD_NAME, temp, l, sizeof(temp)); BURP_verbose (121, temp, NULL, NULL, NULL, NULL); - /* msg 121 restoring global field %s */ + // msg 121 restoring global field %s break; case att_field_query_name: @@ -3713,7 +3718,7 @@ bool get_global_field (void) case att_field_segment_length: X.RDB$SEGMENT_LENGTH = (USHORT) get_numeric(); if (X.RDB$SEGMENT_LENGTH) - X.RDB$SEGMENT_LENGTH.NULL = FALSE; + X.RDB$SEGMENT_LENGTH.NULL = FALSE; break; case att_field_computed_blr: @@ -3733,25 +3738,24 @@ bool get_global_field (void) case att_field_validation_blr: if (tdgbl->gbl_sw_novalidity) - eat_blob(); + eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. - if (tdgbl->global_trans) - { - if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + if (tdgbl->global_trans) + { + if (!gfield) + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); - get_blr_blob (&gfield->gfld_vb, true); - gfield->gfld_flags |= GFLD_validation_blr; - } - else - { - X.RDB$VALIDATION_BLR.NULL = FALSE; - get_blr_blob (&X.RDB$VALIDATION_BLR, false); + get_blr_blob (&gfield->gfld_vb, true); + gfield->gfld_flags |= GFLD_validation_blr; + } + else + { + X.RDB$VALIDATION_BLR.NULL = FALSE; + get_blr_blob (&X.RDB$VALIDATION_BLR, false); } } break; @@ -3761,14 +3765,13 @@ bool get_global_field (void) eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. if (tdgbl->global_trans) { if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); get_misc_blob (&gfield->gfld_vs, 0, true); gfield->gfld_flags |= GFLD_validation_source; @@ -3786,14 +3789,13 @@ bool get_global_field (void) eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. if (tdgbl->global_trans) { if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); get_source_blob (&gfield->gfld_vs2, true); gfield->gfld_flags |= GFLD_validation_source2; @@ -3887,8 +3889,8 @@ bool get_global_field (void) break; default: - bad_attribute (scan_next_attr, attribute, 92); - /* msg 92 global field */ + bad_attribute (scan_next_attr, attribute, 92); + // msg 92 global field break; } } @@ -3901,7 +3903,7 @@ bool get_global_field (void) } if (gfield) - strcpy (gfield->gfld_name, X.RDB$FIELD_NAME); + strcpy (gfield->gfld_name, X.RDB$FIELD_NAME); /* V3.3 used a different method from V4.0 for encoding International * text character set & collation information. Here we are @@ -3911,15 +3913,13 @@ bool get_global_field (void) */ save_subtype = X.RDB$FIELD_SUB_TYPE; if (X.RDB$CHARACTER_SET_ID.NULL && X.RDB$COLLATION_ID.NULL && - cvt_v3_to_v4_intl (X.RDB$FIELD_TYPE, &X.RDB$FIELD_SCALE, - &X.RDB$FIELD_SUB_TYPE, &X.RDB$CHARACTER_SET_ID, + cvt_v3_to_v4_intl (X.RDB$FIELD_TYPE, &X.RDB$FIELD_SCALE, + &X.RDB$FIELD_SUB_TYPE, &X.RDB$CHARACTER_SET_ID, &X.RDB$COLLATION_ID)) { - BURP_FLD f; - - /* If some value was reset, set the NULL flag */ + // If some value was reset, set the NULL flag if (save_subtype && !X.RDB$FIELD_SUB_TYPE) - X.RDB$FIELD_SUB_TYPE.NULL = TRUE; + X.RDB$FIELD_SUB_TYPE.NULL = TRUE; X.RDB$CHARACTER_SET_ID.NULL = FALSE; X.RDB$COLLATION_ID.NULL = FALSE; @@ -3928,7 +3928,7 @@ bool get_global_field (void) * global field */ - f = (BURP_FLD) BURP_alloc_zero (sizeof(burp_fld)); + BURP_FLD f = (BURP_FLD) BURP_alloc_zero (sizeof(burp_fld)); strcpy (f->fld_name, X.RDB$FIELD_NAME); f->fld_sub_type = X.RDB$FIELD_SUB_TYPE; f->fld_scale = X.RDB$FIELD_SCALE; @@ -3940,14 +3940,14 @@ bool get_global_field (void) END_STORE; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; } else /* RESTORE_format < 6 */ { /* without rdb$field_precision */ - + STORE (REQUEST_HANDLE tdgbl->handles_get_global_field_req_handle1) X IN RDB$FIELDS @@ -3979,8 +3979,8 @@ bool get_global_field (void) X.RDB$COLLATION_ID.NULL = TRUE; memset (X.RDB$QUERY_NAME, ' ', sizeof(X.RDB$QUERY_NAME)); - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -3988,7 +3988,7 @@ bool get_global_field (void) l = GET_TEXT(X.RDB$FIELD_NAME); MISC_terminate (X.RDB$FIELD_NAME, temp, l, sizeof(temp)); BURP_verbose (121, temp, NULL, NULL, NULL, NULL); - /* msg 121 restoring global field %s */ + // msg 121 restoring global field %s break; case att_field_query_name: @@ -4027,7 +4027,7 @@ bool get_global_field (void) case att_field_segment_length: X.RDB$SEGMENT_LENGTH = (USHORT) get_numeric(); if (X.RDB$SEGMENT_LENGTH) - X.RDB$SEGMENT_LENGTH.NULL = FALSE; + X.RDB$SEGMENT_LENGTH.NULL = FALSE; break; case att_field_computed_blr: @@ -4047,75 +4047,72 @@ bool get_global_field (void) case att_field_validation_blr: if (tdgbl->gbl_sw_novalidity) - eat_blob(); + eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. - if (tdgbl->global_trans) + if (tdgbl->global_trans) { - if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + if (!gfield) + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); - get_blr_blob (&gfield->gfld_vb, true); - gfield->gfld_flags |= GFLD_validation_blr; + get_blr_blob (&gfield->gfld_vb, true); + gfield->gfld_flags |= GFLD_validation_blr; } - else + else { - X.RDB$VALIDATION_BLR.NULL = FALSE; - get_blr_blob (&X.RDB$VALIDATION_BLR, false); + X.RDB$VALIDATION_BLR.NULL = FALSE; + get_blr_blob (&X.RDB$VALIDATION_BLR, false); } } break; case att_field_validation_source: if (tdgbl->gbl_sw_novalidity) - eat_blob(); + eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. - if (tdgbl->global_trans) + if (tdgbl->global_trans) { - if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + if (!gfield) + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); - get_misc_blob (&gfield->gfld_vs, 0, true); - gfield->gfld_flags |= GFLD_validation_source; + get_misc_blob (&gfield->gfld_vs, 0, true); + gfield->gfld_flags |= GFLD_validation_source; } - else + else { - X.RDB$VALIDATION_SOURCE.NULL = FALSE; - get_misc_blob (&X.RDB$VALIDATION_SOURCE, 0, false); + X.RDB$VALIDATION_SOURCE.NULL = FALSE; + get_misc_blob (&X.RDB$VALIDATION_SOURCE, 0, false); } } break; case att_field_validation_source2: if (tdgbl->gbl_sw_novalidity) - eat_blob(); + eat_blob(); else { - /* if we are going against a V4.0 database, - * restore the global fields in 2 phases. - */ + // if we are going against a V4.0 database, + // restore the global fields in 2 phases. - if (tdgbl->global_trans) + if (tdgbl->global_trans) { - if (!gfield) - gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); + if (!gfield) + gfield = (GFLD)BURP_alloc_zero(sizeof(gfld)); - get_source_blob (&gfield->gfld_vs2, true); - gfield->gfld_flags |= GFLD_validation_source2; + get_source_blob (&gfield->gfld_vs2, true); + gfield->gfld_flags |= GFLD_validation_source2; } - else + else { - X.RDB$VALIDATION_SOURCE.NULL = FALSE; - get_source_blob (&X.RDB$VALIDATION_SOURCE, false); + X.RDB$VALIDATION_SOURCE.NULL = FALSE; + get_source_blob (&X.RDB$VALIDATION_SOURCE, false); } } break; @@ -4197,7 +4194,7 @@ bool get_global_field (void) default: bad_attribute (scan_next_attr, attribute, 92); - /* msg 92 global field */ + // msg 92 global field break; } } @@ -4210,7 +4207,7 @@ bool get_global_field (void) } if (gfield) - strcpy (gfield->gfld_name, X.RDB$FIELD_NAME); + strcpy (gfield->gfld_name, X.RDB$FIELD_NAME); /* V3.3 used a different method from V4.0 for encoding International * text character set & collation information. Here we are @@ -4221,14 +4218,14 @@ bool get_global_field (void) save_subtype = X.RDB$FIELD_SUB_TYPE; if (X.RDB$CHARACTER_SET_ID.NULL && X.RDB$COLLATION_ID.NULL && - cvt_v3_to_v4_intl (X.RDB$FIELD_TYPE, &X.RDB$FIELD_SCALE, - &X.RDB$FIELD_SUB_TYPE, &X.RDB$CHARACTER_SET_ID, + cvt_v3_to_v4_intl (X.RDB$FIELD_TYPE, &X.RDB$FIELD_SCALE, + &X.RDB$FIELD_SUB_TYPE, &X.RDB$CHARACTER_SET_ID, &X.RDB$COLLATION_ID)) { - /* If some value was reset, set the NULL flag */ + // If some value was reset, set the NULL flag if (save_subtype && !X.RDB$FIELD_SUB_TYPE) - X.RDB$FIELD_SUB_TYPE.NULL = TRUE; + X.RDB$FIELD_SUB_TYPE.NULL = TRUE; X.RDB$CHARACTER_SET_ID.NULL = FALSE; X.RDB$COLLATION_ID.NULL = FALSE; @@ -4249,7 +4246,7 @@ bool get_global_field (void) END_STORE; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; } @@ -4292,16 +4289,16 @@ bool get_index (BURP_REL relation) strcpy (X.RDB$RELATION_NAME, relation->rel_name); X.RDB$UNIQUE_FLAG = 0; if (!tdgbl->gbl_sw_deactivate_indexes) - X.RDB$INDEX_INACTIVE = FALSE; + X.RDB$INDEX_INACTIVE = FALSE; else - X.RDB$INDEX_INACTIVE = TRUE; + X.RDB$INDEX_INACTIVE = TRUE; X.RDB$INDEX_TYPE.NULL = TRUE; X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$FOREIGN_KEY.NULL = TRUE; X.RDB$EXPRESSION_SOURCE.NULL = TRUE; X.RDB$EXPRESSION_BLR.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -4321,17 +4318,17 @@ bool get_index (BURP_REL relation) case att_index_inactive: X.RDB$INDEX_INACTIVE = (USHORT) get_numeric(); - /* Defer foreign key index activation */ - /* Modified by Toni Martir, all index deferred when verbose */ + // Defer foreign key index activation + // Modified by Toni Martir, all index deferred when verbose if (tdgbl->gbl_sw_verbose) { - if (X.RDB$INDEX_INACTIVE == FALSE) + if (X.RDB$INDEX_INACTIVE == FALSE) X.RDB$INDEX_INACTIVE = DEFERRED_ACTIVE; - } + } else - { - if (X.RDB$INDEX_INACTIVE == FALSE && foreign_index) - X.RDB$INDEX_INACTIVE = DEFERRED_ACTIVE; + { + if (X.RDB$INDEX_INACTIVE == FALSE && foreign_index) + X.RDB$INDEX_INACTIVE = DEFERRED_ACTIVE; } if (tdgbl->gbl_sw_deactivate_indexes) X.RDB$INDEX_INACTIVE = TRUE; @@ -4376,7 +4373,7 @@ bool get_index (BURP_REL relation) case att_index_foreign_key: foreign_index = true; - /* Defer foreign key index activation */ + // Defer foreign key index activation if (X.RDB$INDEX_INACTIVE == FALSE) X.RDB$INDEX_INACTIVE = DEFERRED_ACTIVE; if (tdgbl->gbl_sw_deactivate_indexes) @@ -4386,15 +4383,15 @@ bool get_index (BURP_REL relation) break; default: - bad_attribute (scan_next_attr, attribute, 93); - /* msg 93 index */ + bad_attribute (scan_next_attr, attribute, 93); + // msg 93 index break; } } count = 0; FOR (REQUEST_HANDLE tdgbl->handles_get_index_req_handle3) - RFR IN RDB$RELATION_FIELDS CROSS I_S IN RDB$INDEX_SEGMENTS + RFR IN RDB$RELATION_FIELDS CROSS I_S IN RDB$INDEX_SEGMENTS OVER RDB$FIELD_NAME WITH I_S.RDB$INDEX_NAME = index_name AND RFR.RDB$RELATION_NAME = relation->rel_name count++; @@ -4460,14 +4457,14 @@ void get_misc_blob (ISC_QUAD *blob_id, else local_trans = gds_trans; - if (isc_create_blob2 (status_vector, &DB, &local_trans, &blob, + if (isc_create_blob2 (status_vector, &DB, &local_trans, &blob, blob_id, bpb_length, (SCHAR*) bpb)) { - BURP_error_redirect (status_vector, 37, 0, 0); - /* msg 37 gds__create_blob failed */ + BURP_error_redirect (status_vector, 37, 0, 0); + // msg 37 gds__create_blob failed } - /* Allocate blob buffer is static buffer is too short */ + // Allocate blob buffer is static buffer is too short UCHAR *buffer; if (!length || length <= (USHORT)(sizeof(static_buffer)) ) @@ -4481,12 +4478,12 @@ void get_misc_blob (ISC_QUAD *blob_id, } if (isc_put_segment (status_vector, &blob, length, (SCHAR*) buffer)) - BURP_error_redirect (status_vector, 38, 0, 0); - /* msg 38 gds__put_segment failed */ + BURP_error_redirect (status_vector, 38, 0, 0); + // msg 38 gds__put_segment failed if (isc_close_blob (status_vector, &blob)) - BURP_error_redirect (status_vector, 23, 0, 0); - /* msg 23 gds__close_blob failed */ + BURP_error_redirect (status_vector, 23, 0, 0); + // msg 23 gds__close_blob failed if (buffer != static_buffer) BURP_free (buffer); @@ -4575,8 +4572,8 @@ bool get_procedure (void) X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$SECURITY_CLASS.NULL = TRUE; X.RDB$OWNER_NAME.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -4586,7 +4583,7 @@ bool get_procedure (void) strcpy (procedure->prc_name, X.RDB$PROCEDURE_NAME); MISC_terminate (X.RDB$PROCEDURE_NAME, temp, l, sizeof(temp)); BURP_verbose (195, temp, NULL, NULL, NULL, NULL); - /* msg 195 restoring stored procedure %s */ + // msg 195 restoring stored procedure %s break; case att_procedure_description: @@ -4635,8 +4632,8 @@ bool get_procedure (void) break; default: - bad_attribute (scan_next_attr, attribute, 89); - /* msg 89 function */ + bad_attribute (scan_next_attr, attribute, 89); + // msg 89 function break; } } @@ -4646,7 +4643,7 @@ bool get_procedure (void) general_on_error (); END_ERROR; - /* at the end of prms for a procedure is the rec_procedure_end marker */ + // at the end of prms for a procedure is the rec_procedure_end marker while (get(tdgbl) == rec_procedure_prm) get_procedure_prm (procedure_name); @@ -4684,8 +4681,8 @@ bool get_procedure_prm (GDS_NAME procptr) X IN RDB$PROCEDURE_PARAMETERS X.RDB$DESCRIPTION.NULL = TRUE; strcpy (X.RDB$PROCEDURE_NAME, procptr); - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -4693,7 +4690,7 @@ bool get_procedure_prm (GDS_NAME procptr) l = GET_TEXT(X.RDB$PARAMETER_NAME); MISC_terminate (X.RDB$PARAMETER_NAME, temp, l, sizeof(temp)); BURP_verbose (196, temp, NULL, NULL, NULL, NULL); - /* msg 196 restoring parameter %s for stored procedure */ + // msg 196 restoring parameter %s for stored procedure break; case att_procedureprm_type: @@ -4719,8 +4716,8 @@ bool get_procedure_prm (GDS_NAME procptr) break; default: - bad_attribute (scan_next_attr, attribute, 90); - /* msg 90 function argument */ + bad_attribute (scan_next_attr, attribute, 90); + // msg 90 function argument break; } } @@ -4736,7 +4733,7 @@ bool get_ref_constraint (void) { /************************************** * - * g e t _ r e f _ c o n s t r a i n t + * g e t _ r e f _ c o n s t r a i n t * ************************************** * @@ -4756,8 +4753,8 @@ bool get_ref_constraint (void) X.RDB$MATCH_OPTION.NULL = TRUE; X.RDB$UPDATE_RULE.NULL = TRUE; X.RDB$DELETE_RULE.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -4787,8 +4784,8 @@ bool get_ref_constraint (void) break; default: - bad_attribute (scan_next_attr, attribute, 208); - /* msg 208 relation constraint */ + bad_attribute (scan_next_attr, attribute, 208); + // msg 208 relation constraint break; } } @@ -4816,7 +4813,7 @@ bool get_relation (void) * with plans. Assume it is a view if it has * RDB$VIEW_BLR, also assume RDB$VIEW_BLR is * the first blob in the backup file. - * + * * **************************************/ TEXT temp [GDS_NAME_LEN]; @@ -4843,7 +4840,7 @@ bool get_relation (void) isc_tr_handle local_trans; TGBL tdgbl = GET_THREAD_DATA; - /* Pick up relation attributes */ + // Pick up relation attributes BURP_REL relation = (BURP_REL) BURP_alloc_zero (sizeof(burp_rel)); relation->rel_next = tdgbl->relations; @@ -4862,8 +4859,8 @@ bool get_relation (void) X.RDB$EXTERNAL_DESCRIPTION.NULL = TRUE; */ - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -4872,7 +4869,7 @@ bool get_relation (void) relation->rel_name_length = l; MISC_terminate (relation->rel_name, temp, l, sizeof(temp)); BURP_verbose (167, temp, NULL, NULL, NULL, NULL); - /* msg 167 restoring relation %s */ + // msg 167 restoring relation %s break; case att_relation_security_class: @@ -4937,12 +4934,12 @@ bool get_relation (void) default: bad_attribute (scan_next_attr, attribute, 111); - /* msg 111 relation */ + // msg 111 relation break; } } - /* If this is a view and there is a global transaction then use it */ + // If this is a view and there is a global transaction then use it if (view_blr_null || !tdgbl->global_trans) local_trans = gds_trans; @@ -4979,7 +4976,7 @@ bool get_relation (void) general_on_error (); END_ERROR; - /* Eat up misc. records */ + // Eat up misc. records BURP_FLD field = NULL; BURP_FLD *ptr = &relation->rel_fields; @@ -4990,22 +4987,22 @@ bool get_relation (void) case rec_relation_end: if (tdgbl->gbl_sw_incremental) { - BURP_verbose (170, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 170: committing metadata for relation %s */ + BURP_verbose (170, relation->rel_name, NULL, NULL, NULL, NULL); + // msg 170: committing metadata for relation %s COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (171, relation->rel_name, NULL, NULL, NULL, NULL); - /* msg 171: error committing metadata for relation %s */ - BURP_print_status (tdgbl->status_vector); - ROLLBACK; - ON_ERROR - general_on_error (); - END_ERROR; + // msg 171: error committing metadata for relation %s + BURP_print_status (tdgbl->status_vector); + ROLLBACK; + ON_ERROR + general_on_error (); + END_ERROR; END_ERROR; EXEC SQL SET TRANSACTION NO_AUTO_UNDO; - if (gds_status [1]) - EXEC SQL SET TRANSACTION; + if (gds_status [1]) + EXEC SQL SET TRANSACTION; } return true; @@ -5015,7 +5012,7 @@ bool get_relation (void) return false; ptr = &field->fld_next; break; - + case rec_view: get_view (relation); break; @@ -5026,19 +5023,19 @@ bool get_relation (void) 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (43, (void*) record, 0, 0, 0, 0); - /* msg 43 don't recognize record type %ld */ + // msg 43 don't recognize record type %ld #endif break; } } - /* If we fall thru, there are data records to be gotten */ + // If we fall thru, there are data records to be gotten /* we can get here only when restoring ancient gbak'ed files where rec_data was once embedded into rec_relation ... otherwise, meta commit happens when we see the first rec_relation_data */ BURP_verbose (68, NULL, NULL, NULL, NULL, NULL); - /* msg 68 committing meta data */ + // msg 68 committing meta data COMMIT; ON_ERROR @@ -5058,7 +5055,7 @@ bool get_rel_constraint (void) { /************************************** * - * g e t _ r e l _ c o n s t r a i n t + * g e t _ r e l _ c o n s t r a i n t * ************************************** * @@ -5079,8 +5076,8 @@ bool get_rel_constraint (void) X.RDB$DEFERRABLE.NULL = TRUE; X.RDB$INITIALLY_DEFERRED.NULL = TRUE; X.RDB$INDEX_NAME.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5115,8 +5112,8 @@ bool get_rel_constraint (void) break; default: - bad_attribute (scan_next_attr, attribute, 208); - /* msg 208 relation constraint */ + bad_attribute (scan_next_attr, attribute, 208); + // msg 208 relation constraint break; } } @@ -5153,8 +5150,8 @@ bool get_relation_data (void) relation = NULL; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5164,31 +5161,31 @@ bool get_relation_data (void) break; default: - bad_attribute (scan_next_attr, attribute, 111); - /* msg 111 relation */ + bad_attribute (scan_next_attr, attribute, 111); + // msg 111 relation break; } } if (!relation) BURP_error_redirect (NULL, 49, 0, 0); - /* msg 49 no relation name for data */ + // msg 49 no relation name for data - /* Eat up misc. records */ + // Eat up misc. records get_record(&record, tdgbl); - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), TRUE) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), true) { switch (record) { case rec_relation_end: return true; - + case rec_data: record = get_data (relation); - /* get_data does a GET_RECORD */ + // get_data does a GET_RECORD break; case rec_gen_id: @@ -5196,20 +5193,20 @@ bool get_relation_data (void) store_blr_gen_id (name, gen_id); get_record(&record, tdgbl); break; - + case rec_index: get_index (relation); get_record(&record, tdgbl); break; - - case rec_trigger: /* old style trigger */ + + case rec_trigger: // old style trigger get_trigger_old (relation); get_record(&record, tdgbl); break; default: - bad_attribute (scan_next_attr, attribute, 111); - /* msg 111 relation */ + bad_attribute (scan_next_attr, attribute, 111); + // msg 111 relation get_record(&record, tdgbl); break; } @@ -5240,9 +5237,9 @@ bool get_sql_roles (void) X.RDB$ROLE_NAME.NULL = TRUE; X.RDB$OWNER_NAME.NULL = TRUE; - SKIP_INIT(&scan_next_attr); + skip_init(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5327,8 +5324,8 @@ bool get_security_class (void) STORE (REQUEST_HANDLE tdgbl->handles_get_security_class_req_handle1) X IN RDB$SECURITY_CLASSES - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { X.RDB$DESCRIPTION.NULL = TRUE; switch (attribute) @@ -5339,28 +5336,28 @@ bool get_security_class (void) /* Bug fix for bug_no 7299: There was a V3 bug that inserted garbage security class entry when doing GBAK. In order to restore the V3 gbak file with this bad security entry to - V4 database. We should check if the security class is a - valid ASCII name. If not, skip this entry by setting - 'is_valid_sec_class' to FALSE. + V4 database. We should check if the security class is a + valid ASCII name. If not, skip this entry by setting + 'is_valid_sec_class' to false. */ is_valid_sec_class = is_ascii_name(X.RDB$SECURITY_CLASS, l); if (!is_valid_sec_class) - { + { MISC_terminate (X.RDB$SECURITY_CLASS, temp, l, sizeof(temp)); BURP_print (234, temp, NULL, NULL, NULL, NULL); - /* msg 234 Skipped bad security class entry: %s */ + // msg 234 Skipped bad security class entry: %s break; - } + } MISC_terminate (X.RDB$SECURITY_CLASS, temp, l, sizeof(temp)); BURP_verbose (125, temp, NULL, NULL, NULL, NULL); - /* msg 125 restoring security class %s */ + // msg 125 restoring security class %s break; case att_class_acl: get_misc_blob (&X.RDB$ACL, 0, false); break; - + case att_class_description: X.RDB$DESCRIPTION.NULL = FALSE; get_misc_blob (&X.RDB$DESCRIPTION, 0, false); @@ -5372,13 +5369,13 @@ bool get_security_class (void) break; default: - bad_attribute (scan_next_attr, attribute, 131); - /* msg 131 security class */ + bad_attribute (scan_next_attr, attribute, 131); + // msg 131 security class break; } } - /* If the security class is not valid ASCII name, don't store it to the */ - /* database. Simply return from here and the entry is discarded. */ + // If the security class is not valid ASCII name, don't store it to the + // database. Simply return from here and the entry is discarded. if (!is_valid_sec_class) { return true; @@ -5425,11 +5422,11 @@ void get_source_blob ( if (isc_create_blob (status_vector, &DB, &local_trans, &blob, blob_id)) { - BURP_error_redirect (status_vector, 37, 0, 0); - /* msg 37 gds__create_blob failed */ + BURP_error_redirect (status_vector, 37, 0, 0); + // msg 37 gds__create_blob failed } - /* Allocate blob buffer is static buffer is too short */ + // Allocate blob buffer is static buffer is too short UCHAR *buffer; if (!length || length <= (USHORT)(sizeof(static_buffer)) ) @@ -5447,13 +5444,13 @@ void get_source_blob ( USHORT seg_len = p - buffer; if (isc_put_segment (status_vector, &blob, seg_len, (SCHAR*) buffer)) - BURP_error_redirect (status_vector, 38, 0, 0); - /* msg 38 gds__put_segment failed */ + BURP_error_redirect (status_vector, 38, 0, 0); + // msg 38 gds__put_segment failed } if (isc_close_blob (status_vector, &blob)) - BURP_error_redirect (status_vector, 23, 0, 0); - /* msg 23 gds__close_blob failed */ + BURP_error_redirect (status_vector, 23, 0, 0); + // msg 23 gds__close_blob failed if (buffer != static_buffer) BURP_free (buffer); @@ -5479,7 +5476,7 @@ USHORT get_text ( if (length <= l) BURP_error_redirect (NULL, 46, 0, 0); - /* msg 46 string truncated */ + // msg 46 string truncated if (l) text = (TEXT*) get_block(tdgbl, (UCHAR*) text, l); @@ -5514,8 +5511,8 @@ bool get_trigger_old ( X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$TRIGGER_BLR.NULL = TRUE; X.RDB$TRIGGER_SOURCE.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5539,13 +5536,13 @@ bool get_trigger_old ( break; default: - bad_attribute (scan_next_attr, attribute, 134); - /* msg 134 trigger */ + bad_attribute (scan_next_attr, attribute, 134); + // msg 134 trigger break; } } - /* fill in rest of attributes unique to new trigger format */ + // fill in rest of attributes unique to new trigger format p = X.RDB$TRIGGER_NAME; end = p + 31; @@ -5570,20 +5567,20 @@ bool get_trigger_old ( } else { - bad_attribute (scan_next_attr, attribute, 136); - /* msg 136 trigger type */ - return 0; + bad_attribute (scan_next_attr, attribute, 136); + // msg 136 trigger type + return 0; } while (*q && p < end) *p++ = *q++; *p = 0; BURP_verbose (126, X.RDB$TRIGGER_NAME, NULL, NULL, NULL, NULL); - /* msg 126 restoring trigger %s */ + // msg 126 restoring trigger %s strncpy (X.RDB$RELATION_NAME, relation->rel_name, GDS_NAME_LEN); strcpy (name, X.RDB$TRIGGER_NAME); X.RDB$TRIGGER_SEQUENCE = TRIGGER_SEQUENCE_DEFAULT; - X.RDB$SYSTEM_FLAG = 0; /* restore as vanilla user type */ + X.RDB$SYSTEM_FLAG = 0; // restore as vanilla user type END_STORE; ON_ERROR @@ -5593,10 +5590,10 @@ bool get_trigger_old ( if (tdgbl->gbl_sw_incremental) { COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (94, name, NULL, NULL, NULL, NULL); - /* msg 94 trigger %s is invalid */ + // msg 94 trigger %s is invalid BURP_print_status (tdgbl->status_vector); ROLLBACK; ON_ERROR @@ -5640,8 +5637,8 @@ bool get_trigger (void) X.RDB$TRIGGER_SOURCE.NULL = TRUE; X.RDB$SYSTEM_FLAG.NULL = TRUE; X.RDB$FLAGS.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5673,7 +5670,7 @@ bool get_trigger (void) GET_TEXT(X.RDB$TRIGGER_NAME); strcpy (name, X.RDB$TRIGGER_NAME); BURP_verbose (126, X.RDB$TRIGGER_NAME, NULL, NULL, NULL, NULL); - /* msg 126 restoring trigger %s */ + // msg 126 restoring trigger %s break; case att_trig_relation_name: @@ -5704,8 +5701,8 @@ bool get_trigger (void) break; default: - bad_attribute (scan_next_attr, attribute, 134); - /* msg 134 trigger */ + bad_attribute (scan_next_attr, attribute, 134); + // msg 134 trigger break; } } @@ -5717,10 +5714,10 @@ bool get_trigger (void) if (tdgbl->gbl_sw_incremental) { COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (94, name, NULL, NULL, NULL, NULL); - /* msg 94 trigger %s is invalid */ + // msg 94 trigger %s is invalid BURP_print_status (tdgbl->status_vector); ROLLBACK; ON_ERROR @@ -5739,7 +5736,7 @@ bool get_trigger_message (void) { /************************************** * - * g e t _ t r i g g e r _ m e s s a g e + * g e t _ t r i g g e r _ m e s s a g e * ************************************** * @@ -5758,8 +5755,8 @@ bool get_trigger_message (void) TGBL tdgbl = GET_THREAD_DATA; bool flag = false; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5771,11 +5768,11 @@ bool get_trigger_message (void) X.RDB$SYSTEM_FLAG EQ 1 AND X.RDB$TRIGGER_NAME EQ name flag = true; END_FOR; - ON_ERROR - general_on_error (); - END_ERROR; + ON_ERROR + general_on_error (); + END_ERROR; BURP_verbose (127, name, NULL, NULL, NULL, NULL); - /* msg 127 restoring trigger message for %s */ + // msg 127 restoring trigger message for %s break; case att_trigmsg_number: @@ -5787,8 +5784,8 @@ bool get_trigger_message (void) break; default: - bad_attribute (scan_next_attr, attribute, 135); - /* msg 135 trigger message */ + bad_attribute (scan_next_attr, attribute, 135); + // msg 135 trigger message break; } } @@ -5812,10 +5809,10 @@ bool get_trigger_message (void) if (tdgbl->gbl_sw_incremental) { COMMIT - /* existing ON_ERROR continues past error, beck */ + // existing ON_ERROR continues past error, beck ON_ERROR BURP_print (94, name, NULL, NULL, NULL, NULL); - /* msg 94 trigger %s is invalid */ + // msg 94 trigger %s is invalid BURP_print_status (tdgbl->status_vector); ROLLBACK; ON_ERROR @@ -5853,8 +5850,8 @@ bool get_type (void) X IN RDB$TYPES X.RDB$DESCRIPTION.NULL = TRUE; X.RDB$SYSTEM_FLAG.NULL = TRUE; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -5886,15 +5883,15 @@ bool get_type (void) break; default: - bad_attribute (scan_next_attr, attribute, 136); - /* msg 136 trigger type */ + bad_attribute (scan_next_attr, attribute, 136); + // msg 136 trigger type break; } } MISC_terminate (X.RDB$TYPE_NAME, temp, l, sizeof(temp)); BURP_verbose (128, temp, X.RDB$FIELD_NAME, NULL, NULL, NULL); - /* msg 128 restoring type %s for field %s */ + // msg 128 restoring type %s for field %s END_STORE; ON_ERROR @@ -5934,18 +5931,18 @@ bool get_user_privilege (void) TGBL tdgbl = GET_THREAD_DATA; user_type = obj_user; object_type = obj_relation; - - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { case att_priv_user: - /* default USER_TYPE to USER */ + // default USER_TYPE to USER flags |= USER_PRIV_USER; GET_TEXT(user); BURP_verbose (123, user, NULL, NULL, NULL, NULL); - /* msg 123 restoring privilege for user %s */ + // msg 123 restoring privilege for user %s break; case att_priv_grantor: @@ -5965,7 +5962,7 @@ bool get_user_privilege (void) case att_priv_object_name: flags |= USER_PRIV_OBJECT_NAME; - /* default OBJECT_TYPE to RELATION */ + // default OBJECT_TYPE to RELATION GET_TEXT(relation_name); break; @@ -5986,12 +5983,12 @@ bool get_user_privilege (void) default: bad_attribute (scan_next_attr, attribute, 105); - /* msg 105 privilege */ + // msg 105 privilege break; } } - - /* Check if object exists */ + + // Check if object exists bool exists = false; switch (object_type) @@ -6001,9 +5998,9 @@ bool get_user_privilege (void) for (BURP_PRC proc = tdgbl->procedures; proc; proc = proc->prc_next) if (!strcmp(proc->prc_name, relation_name)) { - exists = true; - local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; - break; + exists = true; + local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; + break; } } break; @@ -6013,9 +6010,9 @@ bool get_user_privilege (void) for (BURP_REL rel = tdgbl->relations; rel; rel = rel->rel_next) if (!strcmp(rel->rel_name, relation_name)) { - exists = true; - if (rel->rel_flags & REL_view) - local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; + exists = true; + if (rel->rel_flags & REL_view) + local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; break; } } @@ -6029,7 +6026,7 @@ bool get_user_privilege (void) if (exists) { if (!local_trans) - local_trans = gds_trans; + local_trans = gds_trans; STORE (TRANSACTION_HANDLE local_trans REQUEST_HANDLE tdgbl->handles_get_user_privilege_req_handle1) X @@ -6066,9 +6063,9 @@ bool get_user_privilege (void) } /* - * USER_TYPE & OBJECT_TYPE are fields that did not exist before - * V4.0. So, we have to reconstruct them and initialize them to - * reasonable values. If they existed before then user_type and + * USER_TYPE & OBJECT_TYPE are fields that did not exist before + * V4.0. So, we have to reconstruct them and initialize them to + * reasonable values. If they existed before then user_type and * object_type contain the proper values. If they didn't exist * then user_type and object_type contain the reasonable default * values. @@ -6081,13 +6078,13 @@ bool get_user_privilege (void) X.RDB$OBJECT_TYPE = object_type; - /* + /* * If OBJECT_TYPE didn't exist before and we have a field level * user privileges, then use obj_field instead. * - * NOTE: Scanning the V4.0 code base, obj_field has never been - * used at all. The following code should be uncommented - * in case we ever introduce obj_field to the picture. + * NOTE: Scanning the V4.0 code base, obj_field has never been + * used at all. The following code should be uncommented + * in case we ever introduce obj_field to the picture. */ /*********************************************************** if ( !(flags & USER_PRIV_OBJECT_TYPE) ) @@ -6101,7 +6098,7 @@ bool get_user_privilege (void) END_STORE; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; } @@ -6126,7 +6123,7 @@ bool get_view (BURP_REL relation) TGBL tdgbl = GET_THREAD_DATA; - /* If there is a global transaction then use it */ + // If there is a global transaction then use it local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; @@ -6134,8 +6131,8 @@ bool get_view (BURP_REL relation) REQUEST_HANDLE tdgbl->handles_get_view_req_handle1) X IN RDB$VIEW_RELATIONS strcpy (X.RDB$VIEW_NAME, relation->rel_name); - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) { switch (attribute) { @@ -6152,8 +6149,8 @@ bool get_view (BURP_REL relation) break; default: - bad_attribute (scan_next_attr, attribute, 140); - /* msg 140 view */ + bad_attribute (scan_next_attr, attribute, 140); + // msg 140 view break; } } @@ -6187,13 +6184,13 @@ void ignore_array (BURP_REL relation) TGBL tdgbl = GET_THREAD_DATA; - /* don't free something you don't allocate */ + // don't free something you don't allocate xdr_buffer.lstr_allocated = 0; - /* Pick up attributes */ + // Pick up attributes - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) { switch (attribute) { @@ -6203,8 +6200,8 @@ void ignore_array (BURP_REL relation) if (field->fld_number == field_number) break; if (!field) - BURP_error_redirect (NULL, 36, 0, 0); - /* msg 36 Can't find field for blob */ + BURP_error_redirect (NULL, 36, 0, 0); + // msg 36 Can't find field for blob break; case att_array_dimensions: @@ -6213,21 +6210,21 @@ void ignore_array (BURP_REL relation) for (range = field->fld_ranges; range < end_ranges; range += 2) { if (get_attribute(&attribute, tdgbl) != att_array_range_low) - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array else range [0] = get_numeric(); if (get_attribute(&attribute, tdgbl) != att_array_range_high) - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array else range [1] = get_numeric(); } break; default: - bad_attribute (scan_next_attr, attribute, 58); - /* msg 58 array */ + bad_attribute (scan_next_attr, attribute, 58); + // msg 58 array break; } } @@ -6241,8 +6238,8 @@ void ignore_array (BURP_REL relation) { if (get_attribute(&attribute, tdgbl) != att_xdr_array) BURP_error_redirect (NULL, 55, 0, 0); - /* msg 55 Expected XDR record length */ - else + // msg 55 Expected XDR record length + else { xdr_buffer.lstr_allocated = get(tdgbl); xdr_buffer.lstr_allocated |= get(tdgbl) << 8; @@ -6251,9 +6248,9 @@ void ignore_array (BURP_REL relation) lcount = xdr_buffer.lstr_length = xdr_buffer.lstr_allocated; } } - else + else { - lcount = length; + lcount = length; } if (lcount) @@ -6279,12 +6276,12 @@ void ignore_blob (void) TGBL tdgbl = GET_THREAD_DATA; - /* Pick up attributes */ + // Pick up attributes segments = 0; - SKIP_INIT(&scan_next_attr); - while (SKIP_SCAN(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) + skip_init(&scan_next_attr); + while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_blob_data) { switch (attribute) { @@ -6305,13 +6302,13 @@ void ignore_blob (void) break; default: - bad_attribute (scan_next_attr, attribute, 64); - /* msg 64 blob */ + bad_attribute (scan_next_attr, attribute, 64); + // msg 64 blob break; } } - /* Eat up blob segments */ + // Eat up blob segments while (--segments >= 0) { @@ -6343,18 +6340,20 @@ rec_type ignore_data (BURP_REL relation) while (true) { if (get(tdgbl) != att_data_length) - BURP_error_redirect (NULL, 39, 0, 0); - /* msg 39 expected record length */ + BURP_error_redirect (NULL, 39, 0, 0); + // msg 39 expected record length USHORT l = (USHORT) get_numeric(); - if (tdgbl->gbl_sw_transportable) - if (get(tdgbl) != att_xdr_length) - BURP_error_redirect (NULL, 55, 0, 0); - /* msg 55 Expected XDR record length */ - else - l = (USHORT) get_numeric(); + if (tdgbl->gbl_sw_transportable) + { + if (get(tdgbl) != att_xdr_length) + BURP_error_redirect (NULL, 55, 0, 0); + // msg 55 Expected XDR record length + else + l = (USHORT) get_numeric(); + } if (get(tdgbl) != att_data_data) BURP_error_redirect (NULL, 41, 0, 0); - /* msg 41 expected data attribute */ + // msg 41 expected data attribute if (l) { if (tdgbl->gbl_sw_compress) { @@ -6380,7 +6379,7 @@ rec_type ignore_data (BURP_REL relation) } BURP_verbose (106, (void*) records, NULL, NULL, NULL, NULL); - /* msg 106 %ld records ignored */ + // msg 106 %ld records ignored return record; } @@ -6418,8 +6417,8 @@ void realign (UCHAR *buffer, // CVC: This code assumes fld_offset < fld_old_offset, // why not use memmove() instead? - - /* Beware of overlaps here - don't use memcpy */ + + // Beware of overlaps here - don't use memcpy while (l--) *p++ = *q++; @@ -6430,7 +6429,7 @@ void realign (UCHAR *buffer, } } - /* If this is format version 2, build fields for null flags */ + // If this is format version 2, build fields for null flags if (tdgbl->RESTORE_format >= 2) { @@ -6461,7 +6460,7 @@ USHORT recompute_length (BURP_REL relation) * **************************************/ -#ifdef sparc +#ifdef sparc BURP_FLD field; ULONG offset, length, dtype, alignment; const SSHORT *alignments = old_sparcs; @@ -6475,7 +6474,7 @@ USHORT recompute_length (BURP_REL relation) length = field->fld_length; alignment = 4; - /* arrays are of various fld_types but are really blobs */ + // arrays are of various fld_types but are really blobs dtype = field->fld_type; @@ -6487,15 +6486,15 @@ USHORT recompute_length (BURP_REL relation) alignment = alignments [gds_cvt_blr_dtype [field->fld_type]]; if (dtype == blr_varying) - length += sizeof(USHORT); - + length += sizeof(USHORT); + if (alignment) offset = FB_ALIGN(offset, alignment); field->fld_old_offset = offset; offset += length; } - /* If this is format version 2, build fields for null flags */ + // If this is format version 2, build fields for null flags if (tdgbl->RESTORE_format >= 2) { @@ -6509,7 +6508,7 @@ USHORT recompute_length (BURP_REL relation) } return offset; -#else +#else return 0; #endif } @@ -6534,29 +6533,31 @@ bool restore (const TEXT *file_name, TGBL tdgbl = GET_THREAD_DATA; - /* Read burp record first */ + // Read burp record first - MVOL_init_read ((UCHAR*) tdgbl->gbl_database_file_name, (UCHAR*) file_name, + MVOL_init_read ((UCHAR*) tdgbl->gbl_database_file_name, (UCHAR*) file_name, &tdgbl->RESTORE_format, &tdgbl->io_cnt, &tdgbl->io_ptr); if (tdgbl->gbl_sw_transportable) BURP_verbose (133, NULL, NULL, NULL, NULL, NULL); - /* msg 133 transportable backup -- data in XDR format */ + // msg 133 transportable backup -- data in XDR format if (tdgbl->gbl_sw_compress) BURP_verbose (61, NULL, NULL, NULL, NULL, NULL); - /* msg 61 backup file is compressed */ + // msg 61 backup file is compressed // restore only from those backup files created by current or previous GBAK if (tdgbl->RESTORE_format < 1 || tdgbl->RESTORE_format > ATT_BACKUP_FORMAT) - #ifdef SUPERSERVER + { +#ifdef SUPERSERVER BURP_svc_error (44, isc_arg_number, (void*)(ULONG)tdgbl->RESTORE_format, 0, NULL, 0, NULL, 0, NULL, 0, NULL); - #else +#else BURP_error (44, (void*)(ULONG) tdgbl->RESTORE_format, 0, 0, 0, 0); - /* msg 44 Expected backup version 1, 2, or 3. Found %ld */ - #endif + // msg 44 Expected backup version 1, 2, or 3. Found %ld +#endif + } create_database (database_name); @@ -6573,16 +6574,18 @@ bool restore (const TEXT *file_name, USHORT db_version = check_db_version(); if (db_version < DB_VERSION_CURRENT) + { #ifdef SUPERSERVER BURP_svc_error (51, isc_arg_number, (void*) (ULONG) db_version, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (51, (void*) (ULONG) db_version, 0, 0, 0, 0); - /* msg 51 database format %ld is too old to restore to */ + // msg 51 database format %ld is too old to restore to #endif + } BURP_verbose (129, NULL, NULL, NULL, NULL, NULL); - /* msg 129 started transaction */ + // msg 129 started transaction while (get_attribute(&attribute, tdgbl) != att_end) { @@ -6602,7 +6605,7 @@ bool restore (const TEXT *file_name, X IN RDB$DATABASE MODIFY X USING if (attribute == att_database_description2) - get_source_blob (&X.RDB$DESCRIPTION, false); + get_source_blob (&X.RDB$DESCRIPTION, false); else get_misc_blob (&X.RDB$DESCRIPTION, 1, false); END_MODIFY; @@ -6663,19 +6666,19 @@ bool restore (const TEXT *file_name, return false; flag = true; break; - + case rec_collation: if (!get_collation()) return false; flag = true; break; - + case rec_chk_constraint: if (!get_chk_constraint()) return false; flag = true; break; - + case rec_global_field: if (!get_global_field()) return false; @@ -6694,19 +6697,19 @@ bool restore (const TEXT *file_name, flag = true; flag_norel = false; break; - + case rec_ref_constraint: if (!get_ref_constraint()) return false; flag = true; break; - + case rec_rel_constraint: if (!get_rel_constraint()) return false; flag = true; break; - + case rec_function: if (!get_function()) return false; @@ -6747,7 +6750,7 @@ bool restore (const TEXT *file_name, if (flag) { BURP_verbose (68, NULL, NULL, NULL, NULL, NULL); - /* msg 68 committing meta data */ + // msg 68 committing meta data COMMIT; ON_ERROR general_on_error (); @@ -6761,18 +6764,18 @@ bool restore (const TEXT *file_name, return false; break; - case rec_trigger: /* new trigger type */ + case rec_trigger: // new trigger type if (!get_trigger()) return false; flag = true; break; - case rec_trigger_message: + case rec_trigger_message: if (!get_trigger_message()) return false; flag = true; break; - + case rec_user_privilege: if (!get_user_privilege()) return false; @@ -6803,13 +6806,13 @@ bool restore (const TEXT *file_name, 0, NULL, 0, NULL, 0, NULL, 0, NULL); #else BURP_error (43, (void*) record, 0, 0, 0, 0); - /* msg 43 don't recognize record type %ld */ + // msg 43 don't recognize record type %ld #endif break; } } - /* This piece of code is to fix bug 10098: restore of database with + /* This piece of code is to fix bug 10098: restore of database with only domains and no relations aborts with the message ERROR: deadlock This is because insertion of domains into RDB$FIELDS is happening in the default transaction, whereas updation of RDB$FIELDS to add @@ -6823,18 +6826,18 @@ bool restore (const TEXT *file_name, { COMMIT; ON_ERROR - general_on_error (); + general_on_error (); END_ERROR; EXEC SQL SET TRANSACTION NO_AUTO_UNDO; if (gds_status [1]) - EXEC SQL SET TRANSACTION; + EXEC SQL SET TRANSACTION; } - /* put validation clauses for global fields */ + // put validation clauses for global fields update_global_field (); - /* Purge shadow metadata if necessary */ + // Purge shadow metadata if necessary if (tdgbl->gbl_sw_kill) @@ -6917,7 +6920,7 @@ void store_blr_gen_id (const TEXT* gen_name, // TEXT GDS_NAME[GDS_NAME_LEN] ISC_STATUS_ARRAY status_vector; TGBL tdgbl = GET_THREAD_DATA; - + STORE (REQUEST_HANDLE tdgbl->handles_store_blr_gen_id_req_handle1) X IN RDB$GENERATORS strcpy (X.RDB$GENERATOR_NAME, gen_name); @@ -6930,10 +6933,10 @@ void store_blr_gen_id (const TEXT* gen_name, // TEXT GDS_NAME[GDS_NAME_LEN] { #pragma FB_COMPILER_MESSAGE("BRS: casting SINT64 to SLONG") BURP_verbose (185, gen_name, (void*) (SLONG) value, NULL, NULL, NULL); - /* msg 185 restoring generator %s value: %ld */ + // msg 185 restoring generator %s value: %ld return; } - + FRBRD *gen_id_reqh = NULL; UCHAR blr_buffer [100]; // enough to fit blr @@ -6995,21 +6998,21 @@ void store_blr_gen_id (const TEXT* gen_name, // TEXT GDS_NAME[GDS_NAME_LEN] { isc_print_blr ((SCHAR*) blr_buffer, NULL, NULL, 0); BURP_error_redirect (status_vector, 42, 0, 0); - /* msg 42 Failed in store_blr_gen_id */ + // msg 42 Failed in store_blr_gen_id } if (isc_start_request (status_vector, &gen_id_reqh, - &gds_trans, /* use the same one generated by gpre */ + &gds_trans, // use the same one generated by gpre 0)) { isc_print_blr ((SCHAR*) blr_buffer, NULL, NULL, 0); BURP_error_redirect (status_vector, 42, 0, 0); - /* msg 42 Failed in store_blr_gen_id */ + // msg 42 Failed in store_blr_gen_id } #pragma FB_COMPILER_MESSAGE("BRS: casting SINT64 to SLONG") BURP_verbose (185, gen_name, (void*) (SLONG) value, NULL, NULL, NULL); - /* msg 185 restoring generator %s value: %ld */ + // msg 185 restoring generator %s value: %ld isc_release_request (status_vector, &gen_id_reqh); } @@ -7072,7 +7075,7 @@ void update_global_field (void) do *p++ = *q++; while (--length); } } - + if (gfield->gfld_flags & GFLD_validation_source) { X.RDB$VALIDATION_SOURCE.NULL = FALSE; @@ -7085,7 +7088,7 @@ void update_global_field (void) do *p++ = *q++; while (--length); } } - + if (gfield->gfld_flags & GFLD_validation_source2) { X.RDB$VALIDATION_SOURCE.NULL = FALSE; @@ -7098,7 +7101,7 @@ void update_global_field (void) do *p++ = *q++; while (--length); } } - + END_MODIFY; ON_ERROR general_on_error (); @@ -7129,7 +7132,7 @@ bool bug_8183 (TGBL tdgbl) * Name: bug_8183 * * Function: Bug fix for bug_no 8183: It is a migration bug between IB3.3 - * and IB4.0. Gbak v4.0 can't restore database v3.3 if + * and IB4.0. Gbak v4.0 can't restore database v3.3 if * database has an index definition with comment field. * It happens because of att_index_description2 attribute * (which indicates that index contains a comment field @@ -7143,15 +7146,15 @@ bool bug_8183 (TGBL tdgbl) * * This function is trying to recognize the next * data in tdgbl->io_ptr buffer as either name of foreign - * key or comment field. Function returns TRUE in case of - * comment field, otherwise FALSE. + * key or comment field. Function returns true in case of + * comment field, otherwise false. * * Usage: result = bug_8183(tdgbl); * * Parameters: tdgbl - pointer to the structure of global switches * and data * - * Returns: result [TRUE/FALSE] + * Returns: result [true/false] * * Pre: gbak got an index attribute with value "8" from * backup database. @@ -7211,3 +7214,4 @@ bool bug_8183 (TGBL tdgbl) } // namespace + diff --git a/src/burp/spit.cpp b/src/burp/spit.cpp index 21164ce945..f7fe4d6dab 100644 --- a/src/burp/spit.cpp +++ b/src/burp/spit.cpp @@ -1,7 +1,7 @@ /************************************************************************* ** ** PROGRAM: JRD file split utility program -** MODULE: spit.c +** MODULE: spit.cpp ** DESCRIPTION: Command line interpreter for backup file split/join ** utility program ** @@ -60,11 +60,11 @@ #include #endif -static const int MODE_READ = O_RDONLY; -static const int MODE_WRITE = O_WRONLY | O_CREAT; -static const int MASK = 0666; +static const int mode_read = O_RDONLY; +static const int mode_write = O_WRONLY | O_CREAT; +static const int mask = 0666; -/* Definitions for GSPLIT */ +// Definitions for GSPLIT enum gsplit_option { IN_SW_SPIT_0 = 0, // the unknowable switch @@ -214,7 +214,7 @@ int main( int argc, char *argv[]) switch (sw_replace) { case (IN_SW_SPIT_SP): - if (!file_nm_sw) { /* process file name */ + if (!file_nm_sw) { // process file name file_size = 0; file_num = file_num + 1; @@ -298,8 +298,8 @@ int main( int argc, char *argv[]) } /* and of switch (sw_replace) */ argv++; - } /* processing function specific command line options */ - } /* while (argv < end) */ + } // processing function specific command line options + } // while (argv < end) if (!file_list && sw_replace != IN_SW_SPIT_0) { ib_fprintf(ib_stderr, @@ -399,11 +399,11 @@ static int get_function_option(const SCHAR* prog_name, ret_cd = print_clo(prog_name); return FB_FAILURE; } - else /* compatible option */ + else // compatible option break; } - } /* end of if (!c) */ - } /* end of for loop */ + } // end of if (!c) + } // end of for loop if (!in_sw_tab->in_sw) { ib_fprintf(ib_stderr, "%s: invalid option '%s'\n", prog_name, string); @@ -495,7 +495,7 @@ static int get_file_size(const SCHAR* prog_name, const SCHAR* string, double* fi *file_size = *file_size * size_indicator; } - else { /* invalid size indicator */ + else { // invalid size indicator ib_fprintf(ib_stderr, "%s: invalid size indicator '%s'\n", prog_name, @@ -505,7 +505,7 @@ static int get_file_size(const SCHAR* prog_name, const SCHAR* string, double* fi } } } - if (*file_size < MIN_FILE_SIZE) { /* handling user specifies file size 0 */ + if (*file_size < MIN_FILE_SIZE) { // handling user specifies file size 0 ib_fprintf(ib_stderr, "%s: invalid option '%s', minimum file size is 1 megabyte\n", prog_name, string); @@ -650,7 +650,7 @@ static int gen_multy_bakup_files(b_fil* file_list, file_size = fl_ptr->b_fil_size - header_rec_len; file_name = fl_ptr->b_fil_name; - output_fl_desc = open(file_name, MODE_WRITE, MASK); + output_fl_desc = open(file_name, mode_write, mask); if (output_fl_desc == -1) { free(io_buffer); ib_fprintf(ib_stderr, "can not open back up file %s\n", @@ -721,7 +721,7 @@ static int gen_multy_bakup_files(b_fil* file_list, file_name = fl_ptr->b_fil_name; output_fl_desc = - open(file_name, MODE_WRITE, MASK); + open(file_name, mode_write, mask); if (output_fl_desc == -1) { free(io_buffer); ib_fprintf(ib_stderr, @@ -753,7 +753,7 @@ static int gen_multy_bakup_files(b_fil* file_list, return FB_FAILURE; } } - else { /* got a lot of backup files */ + else { // got a lot of backup files ret_cd = flush_io_buff(remaining_io, remaining_io_len, @@ -840,21 +840,21 @@ static int read_and_write(FILE_DESC input_file_desc, read_cnt = read(input_file_desc, *io_buffer, io_size); switch (read_cnt) { - case (0): /* no more data to be read */ + case (0): // no more data to be read close(output_fl_desc); *end_of_input = true; *byte_read = *byte_read + read_cnt; return FB_SUCCESS; break; - case (-1): /* read failed */ + case (-1): // read failed close(output_fl_desc); ib_fprintf(ib_stderr, "fail to read input from ib_stdin, errno = %d\n", errno); return FB_FAILURE; break; - default: /* read ok */ + default: // read ok *byte_read = *byte_read + read_cnt; break; } @@ -862,15 +862,15 @@ static int read_and_write(FILE_DESC input_file_desc, SLONG write_cnt = write(output_fl_desc, *io_buffer, read_cnt); switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(output_fl_desc); return FB_FAILURE; break; default: - if (write_cnt == read_cnt) /* write ok */ + if (write_cnt == read_cnt) // write ok return FB_SUCCESS; - else { /* write less data then it reads in */ + else { // write less data then it reads in close(output_fl_desc); *byte_write = write_cnt; @@ -906,35 +906,35 @@ static int final_read_and_write(FILE_DESC input_file_desc, SLONG read_cnt = read(input_file_desc, *io_buffer, io_size); switch (read_cnt) { - case (0): /* no more data to be read */ + case (0): // no more data to be read close(output_fl_desc); *end_of_input = true; return FB_SUCCESS; break; - case (-1): /* read failed */ + case (-1): // read failed close(output_fl_desc); ib_fprintf(ib_stderr, "problem when reading input file, errno = %d\n", errno); return FB_FAILURE; break; - default: /* read ok */ + default: // read ok break; } SLONG write_cnt = write(output_fl_desc, *io_buffer, read_cnt); switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(output_fl_desc); return FB_FAILURE; break; default: - if (write_cnt == read_cnt) /* write ok */ + if (write_cnt == read_cnt) // write ok return FB_SUCCESS; - else { /* write less data then it reads in */ + else { // write less data then it reads in ib_fprintf(ib_stderr, "There is no enough space to write to back up file %s\n", @@ -995,7 +995,7 @@ static int join_multy_bakup_files( b_fil* file_list) return FB_FAILURE; } - } /* end of for loop */ + } // end of for loop free(io_buffer); return FB_SUCCESS; @@ -1025,7 +1025,7 @@ static int read_and_write_for_join(FILE_DESC output_fl_desc, TEXT num_arr[5], total_arr[5]; header_rec hdr_rec; - FILE_DESC input_fl_desc = open(file_name, MODE_READ); + FILE_DESC input_fl_desc = open(file_name, mode_read); if (input_fl_desc == -1) { ib_fprintf(ib_stderr, "can not open input file %s\n", file_name); @@ -1087,24 +1087,24 @@ static int read_and_write_for_join(FILE_DESC output_fl_desc, while (true) { switch (read_cnt) { - case (0): /* no more data to be read */ + case (0): // no more data to be read close(input_fl_desc); return FB_SUCCESS; break; - case (-1): /* read failed */ + case (-1): // read failed close(input_fl_desc); return FB_FAILURE; break; - default: /* this is the last read */ + default: // this is the last read break; } SLONG write_cnt = write(output_fl_desc, *io_buffer, read_cnt); switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(input_fl_desc); return FB_FAILURE; break; @@ -1241,7 +1241,7 @@ static int write_header(b_fil* fl_ptr, SLONG write_cnt = write(output_fl_desc, header_str, header_rec_len); switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(output_fl_desc); return FB_FAILURE; break; @@ -1301,16 +1301,16 @@ static int flush_io_buff(UCHAR* remaining_io, } switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(output_fl_desc); *flush_done = false; return FB_FAILURE; break; default: - if (write_cnt == remaining_io_len) /* write ok */ + if (write_cnt == remaining_io_len) // write ok *flush_done = true; - else { /* could not write out all remaining data */ + else { // could not write out all remaining data close(output_fl_desc); *flush_done = false; @@ -1342,15 +1342,15 @@ static int final_flush_io_buff(UCHAR * remaining_io, SLONG write_cnt = write(output_fl_desc, remaining_io, remaining_io_len); switch (write_cnt) { - case (-1): /* write failed */ + case (-1): // write failed close(output_fl_desc); return FB_FAILURE; break; default: - if (write_cnt == remaining_io_len) /* write ok */ + if (write_cnt == remaining_io_len) // write ok return FB_SUCCESS; - else { /* could not write out all remaining data */ + else { // could not write out all remaining data close(output_fl_desc); return FB_FAILURE; diff --git a/src/dsql/all.h b/src/dsql/all.h index f074a6f790..bd6b2765df 100644 --- a/src/dsql/all.h +++ b/src/dsql/all.h @@ -42,9 +42,10 @@ public: static void ALLD_push(class blk*, class dsql_lls**); private: - BlockCache lls_cache; /* Was plb_lls */ + BlockCache lls_cache; // Was plb_lls }; extern DsqlMemoryPool *DSQL_permanent_pool; #endif // DSQL_ALL_H + diff --git a/src/dsql/alld_proto.h b/src/dsql/alld_proto.h index 2a73d4ae82..aa2cf36f04 100644 --- a/src/dsql/alld_proto.h +++ b/src/dsql/alld_proto.h @@ -21,10 +21,11 @@ * Contributor(s): ______________________________________. */ -#ifndef _DSQL_ALLD_PROTO_H_ -#define _DSQL_ALLD_PROTO_H_ +#ifndef DSQL_ALLD_PROTO_H +#define DSQL_ALLD_PROTO_H -void ALLD_init(); /* initialize pool system */ -void ALLD_fini(); /* get rid of everything */ +void ALLD_init(); // initialize pool system +void ALLD_fini(); // get rid of everything + +#endif /* DSQL_ALLD_PROTO_H */ -#endif /* _DSQL_ALLD_PROTO_H_ */ diff --git a/src/dsql/dsql.h b/src/dsql/dsql.h index 7cedd5920e..d3a3e8bab5 100644 --- a/src/dsql/dsql.h +++ b/src/dsql/dsql.h @@ -29,8 +29,8 @@ * */ -#ifndef _DSQL_DSQL_H_ -#define _DSQL_DSQL_H_ +#ifndef DSQL_DSQL_H +#define DSQL_DSQL_H #include "../jrd/common.h" #include "../dsql/all.h" @@ -662,4 +662,5 @@ extern unsigned DSQL_debug; (*request->req_blr++ = (UCHAR)(byte)) : GEN_expand_buffer (request, (UCHAR)(byte)) -#endif // _DSQL_DSQL_H_ +#endif // DSQL_DSQL_H + diff --git a/src/extlib/ib_udf.c b/src/extlib/ib_udf.c index 558934bf27..da75db59e5 100644 --- a/src/extlib/ib_udf.c +++ b/src/extlib/ib_udf.c @@ -37,13 +37,17 @@ #include "ib_udf.h" #ifndef SOLARIS - -int MATHERR(struct exception *e) +#ifdef WIN_NT +#define exception_type _exception +#else +#define exception_type exception +#endif +int MATHERR(struct exception_type *e) { return 1; } - -#endif +#undef exception_type +#endif /* SOLARIS */ double EXPORT IB_UDF_abs( double *a) { diff --git a/src/gpre/ada.cpp b/src/gpre/ada.cpp index 9c31d7ba6d..ba69dc13e5 100644 --- a/src/gpre/ada.cpp +++ b/src/gpre/ada.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: ada.cpp,v 1.25 2003-09-16 14:01:56 brodsom Exp $ +// $Id: ada.cpp,v 1.26 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -144,25 +144,25 @@ static int first_flag; #define FLOAT_DCL "interbase.isc_float" #define DOUBLE_DCL "interbase.isc_double" -static inline void endif(int column) +static inline void endif(const int column) { printa(column, "end if;"); } -static inline void begin(int column) +static inline void begin(const int column) { printa(column, "begin"); } -static inline void endp(int column) +static inline void endp(const int column) { printa(column, "end"); } -static inline void set_sqlcode(ACT action, int column) +static inline void set_sqlcode(ACT action, const int column) { if (action->act_flags & ACT_sql) - printa (column, "SQLCODE := interbase.sqlcode (isc_status);"); + printa(column, "SQLCODE := interbase.sqlcode(isc_status);"); } //____________________________________________________________ diff --git a/src/gpre/c_cxx.cpp b/src/gpre/c_cxx.cpp index cc40abcc12..14281ae36c 100644 --- a/src/gpre/c_cxx.cpp +++ b/src/gpre/c_cxx.cpp @@ -27,7 +27,7 @@ // //____________________________________________________________ // -// $Id: c_cxx.cpp,v 1.29 2003-09-16 14:01:56 brodsom Exp $ +// $Id: c_cxx.cpp,v 1.30 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -160,20 +160,20 @@ static TEXT *status_name; #define DCL_QUAD "ISC_QUAD" #endif -static inline void begin(int column) +static inline void begin(const int column) { printa(column, "{"); } -static inline void endp(int column) +static inline void endp(const int column) { printa(column, "}"); } -static inline void set_sqlcode(ACT action, int column) +static inline void set_sqlcode(ACT action, const int column) { if (action->act_flags & ACT_sql) - printa (column, "SQLCODE = isc_sqlcode (%s);", status_name); + printa(column, "SQLCODE = isc_sqlcode(%s);", status_name); } //____________________________________________________________ diff --git a/src/gpre/cme.cpp b/src/gpre/cme.cpp index 748ac10907..0d30616271 100644 --- a/src/gpre/cme.cpp +++ b/src/gpre/cme.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: cme.cpp,v 1.10 2003-09-12 16:35:40 brodsom Exp $ +// $Id: cme.cpp,v 1.11 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -134,7 +134,7 @@ const op_table operators[] = }; -static inline void assign_dtype(gpre_fld *f, gpre_fld *field) +static inline void assign_dtype(gpre_fld* f, const gpre_fld* field) { f->fld_dtype = field->fld_dtype; f->fld_length = field->fld_length; @@ -147,10 +147,10 @@ static inline void assign_dtype(gpre_fld *f, gpre_fld *field) } /* One of d1,d2 is time, the other is date */ -static inline bool is_date_and_time(USHORT d1, USHORT d2) +static inline bool is_date_and_time(const USHORT d1, const USHORT d2) { - return ((((d1)==dtype_sql_time)&&((d2)==dtype_sql_date)) || - (((d2)==dtype_sql_time)&&((d1)==dtype_sql_date))); + return (d1 == dtype_sql_time && d2 == dtype_sql_date) || + (d2 == dtype_sql_time && d1 == dtype_sql_date); } //____________________________________________________________ diff --git a/src/gpre/ftn.cpp b/src/gpre/ftn.cpp index a77181cf36..b1e16b39a0 100644 --- a/src/gpre/ftn.cpp +++ b/src/gpre/ftn.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: ftn.cpp,v 1.26 2003-09-13 12:23:31 brodsom Exp $ +// $Id: ftn.cpp,v 1.27 2003-09-25 11:49:02 robocop Exp $ // // 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port // 2002.10.28 Sean Leyne - Completed removal of obsolete "SGI" port @@ -919,14 +919,14 @@ static void gen_based( ACT action) // print the first variable, then precede the rest with commas - bool first_flag_l = true; + bool first = true; while (based_on->bas_variables) { variable = (TEXT *) POP(&based_on->bas_variables); - if (!first_flag_l) + if (!first) ib_fprintf(out_file, ",\n%s", CONTINUE); ib_fprintf(out_file, "%s", variable); - first_flag_l = false; + first = false; if (field->fld_array_info && !(based_on->bas_flags & BAS_segment)) { /* Print out the dimension part of the declaration */ ib_fprintf(out_file, "("); diff --git a/src/gpre/int.cpp b/src/gpre/int.cpp index dbc0c428cb..02ca569d9e 100644 --- a/src/gpre/int.cpp +++ b/src/gpre/int.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: int.cpp,v 1.15 2003-09-16 14:01:55 brodsom Exp $ +// $Id: int.cpp,v 1.16 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -38,7 +38,7 @@ #include "../gpre/lang_proto.h" #include "../jrd/gds_proto.h" -static void align(int); +static void align(const int); static void asgn_from(REF, int); #ifdef NOT_USED_OR_REPLACED static void asgn_to(REF); @@ -60,12 +60,12 @@ static void gen_routine(ACT, int); static void gen_s_end(ACT, int); static void gen_s_fetch(ACT, int); static void gen_s_start(ACT, int); -static void gen_send(GPRE_REQ, POR, int, bool); -static void gen_start(GPRE_REQ, POR, int, bool); +static void gen_send(GPRE_REQ, const por*, int, bool); +static void gen_start(GPRE_REQ, const por*, int, bool); static void gen_type(ACT, int); static void gen_variable(ACT, int); static void make_port(POR, int); -static void printa(int, TEXT *, ...) ATTRIBUTE_FORMAT(2,3); +static void printa(const int, const TEXT*, ...) ATTRIBUTE_FORMAT(2,3); static int first_flag = 0; @@ -75,12 +75,12 @@ static int first_flag = 0; #define JRD_VTOF "jrd_vtof" #define VTO_CALL "%s ((const char*)%s, (char*)%s, %d);" -static inline void begin(int column) +static inline void begin(const int column) { printa(column, "{"); } -static inline void endp(int column) +static inline void endp(const int column) { printa(column, "}"); } @@ -167,7 +167,7 @@ void INT_action( ACT action, int column) // Align output to a specific column for output. // -static void align( int column) +static void align(const int column) { int i; @@ -261,10 +261,9 @@ static void asgn_to( REF reference) static void gen_at_end( ACT action, int column) { - GPRE_REQ request; TEXT s[20]; - request = action->act_request; + GPRE_REQ request = action->act_request; printa(column, "if (!%s) ", gen_name(s, request->req_eof)); } @@ -290,12 +289,9 @@ static int gen_blr( int *user_arg, int offset, TEXT * string) static void gen_compile( GPRE_REQ request, int column) { - DBB db; - SYM symbol; - column += INDENT; - db = request->req_database; - symbol = db->dbb_name; + DBB db = request->req_database; + SYM symbol = db->dbb_name; ib_fprintf(out_file, "if (!%s)", request->req_handle); align(column); ib_fprintf(out_file, @@ -311,13 +307,11 @@ static void gen_compile( GPRE_REQ request, int column) static void gen_database( ACT action, int column) { - GPRE_REQ request; - if (first_flag++ != 0) return; align(0); - for (request = requests; request; request = request->req_next) + for (GPRE_REQ request = requests; request; request = request->req_next) gen_request(request); } @@ -329,20 +323,17 @@ static void gen_database( ACT action, int column) static void gen_emodify( ACT action, int column) { - UPD modify; - REF reference; - GPRE_FLD field; TEXT s1[20], s2[20]; - modify = (UPD) action->act_object; + UPD modify = (UPD) action->act_object; - for (reference = modify->upd_port->por_references; reference; + for (REF reference = modify->upd_port->por_references; reference; reference = reference->ref_next) { REF source = reference->ref_source; if (!source) continue; - field = reference->ref_field; + GPRE_FLD field = reference->ref_field; align(column); if (field->fld_dtype == dtype_text) @@ -370,9 +361,7 @@ static void gen_emodify( ACT action, int column) static void gen_estore( ACT action, int column, bool special) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; align(column); gen_compile(request, column); gen_start(request, request->req_primary, column, special); @@ -386,9 +375,7 @@ static void gen_estore( ACT action, int column, bool special) static void gen_endfor( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; column += INDENT; if (request->req_sync) @@ -405,9 +392,7 @@ static void gen_endfor( ACT action, int column) static void gen_erase( ACT action, int column) { - UPD erase; - - erase = (UPD) action->act_object; + UPD erase = (UPD) action->act_object; gen_send(erase->upd_request, erase->upd_port, column, false); } @@ -419,13 +404,12 @@ static void gen_erase( ACT action, int column) static void gen_for( ACT action, int column) { - GPRE_REQ request; TEXT s[20]; gen_s_start(action, column); align(column); - request = action->act_request; + GPRE_REQ request = action->act_request; ib_fprintf(out_file, "while (1)"); column += INDENT; begin(column); @@ -459,17 +443,15 @@ static TEXT* gen_name(TEXT* string, const REF reference) static void gen_raw( GPRE_REQ request) { - UCHAR *blr, c; - TEXT buffer[80], *p; - int blr_length; + TEXT buffer[80]; - blr = request->req_blr; - blr_length = request->req_length; - p = buffer; + UCHAR* blr = request->req_blr; + int blr_length = request->req_length; + TEXT* p = buffer; align(0); while (--blr_length) { - c = *blr++; + const UCHAR c = *blr++; if ((c >= 'A' && c <= 'Z') || c == '$' || c == '_') sprintf(p, "'%c',", c); else @@ -536,13 +518,12 @@ static void gen_request( GPRE_REQ request) static void gen_routine( ACT action, int column) { - GPRE_REQ request; - POR port; - - for (request = (GPRE_REQ) action->act_object; request; - request = request->req_routine) for (port = request->req_ports; port; - port = port->por_next) + for (GPRE_REQ request = (GPRE_REQ) action->act_object; request; + request = request->req_routine) + { + for (POR port = request->req_ports; port; port = port->por_next) make_port(port, column + INDENT); + } } @@ -553,9 +534,7 @@ static void gen_routine( ACT action, int column) static void gen_s_end( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; printa(column, "EXE_unwind (tdbb, %s);", request->req_handle); } @@ -567,9 +546,7 @@ static void gen_s_end( ACT action, int column) static void gen_s_fetch( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; if (request->req_sync) gen_send(request, request->req_sync, column, false); @@ -585,13 +562,11 @@ static void gen_s_fetch( ACT action, int column) static void gen_s_start( ACT action, int column) { - GPRE_REQ request; - POR port; - - request = action->act_request; + GPRE_REQ request = action->act_request; gen_compile(request, column); - if (port = request->req_vport) + const por* port = request->req_vport; + if (port) asgn_from(port->por_references, column); gen_start(request, port, column, false); @@ -603,7 +578,7 @@ static void gen_s_start( ACT action, int column) // Generate a send or receive call for a port. // -static void gen_send( GPRE_REQ request, POR port, int column, bool special) +static void gen_send( GPRE_REQ request, const por* port, int column, bool special) { if (special) { @@ -625,7 +600,7 @@ static void gen_send( GPRE_REQ request, POR port, int column, bool special) // Generate a START. // -static void gen_start( GPRE_REQ request, POR port, int column, bool special) +static void gen_start( GPRE_REQ request, const por* port, int column, bool special) { align(column); @@ -644,7 +619,6 @@ static void gen_start( GPRE_REQ request, POR port, int column, bool special) static void gen_type( ACT action, int column) { - printa(column, "%ld", (SLONG) action->act_object); } @@ -671,19 +645,17 @@ static void gen_variable( ACT action, int column) static void make_port( POR port, int column) { - GPRE_FLD field; - REF reference; - SYM symbol; - TEXT *name, s[50]; + TEXT s[50]; printa(column, "struct {"); - for (reference = port->por_references; reference; - reference = reference->ref_next) { + for (REF reference = port->por_references; reference; + reference = reference->ref_next) + { align(column + INDENT); - field = reference->ref_field; - symbol = field->fld_symbol; - name = symbol->sym_string; + GPRE_FLD field = reference->ref_field; + SYM symbol = field->fld_symbol; + TEXT* name = symbol->sym_string; switch (field->fld_dtype) { case dtype_short: ib_fprintf(out_file, " SSHORT jrd_%d;\t/* %s */", @@ -756,7 +728,7 @@ static void make_port( POR port, int column) // Print a fixed string at a particular column. // -static void printa( int column, TEXT * string, ...) +static void printa(const int column, const TEXT* string, ...) { va_list ptr; @@ -764,3 +736,4 @@ static void printa( int column, TEXT * string, ...) align(column); ib_vfprintf(out_file, string, ptr); } + diff --git a/src/gpre/int_cxx.cpp b/src/gpre/int_cxx.cpp index fba458c327..fa54258b19 100644 --- a/src/gpre/int_cxx.cpp +++ b/src/gpre/int_cxx.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: int_cxx.cpp,v 1.14 2003-09-16 14:01:55 brodsom Exp $ +// $Id: int_cxx.cpp,v 1.15 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -38,7 +38,7 @@ #include "../gpre/lang_proto.h" #include "../jrd/gds_proto.h" -static void align(int); +static void align(const int); static void asgn_from(REF, int); #ifdef NOT_USED_OR_REPLACED static void asgn_to(REF); @@ -60,12 +60,12 @@ static void gen_routine(ACT, int); static void gen_s_end(ACT, int); static void gen_s_fetch(ACT, int); static void gen_s_start(ACT, int); -static void gen_send(GPRE_REQ, POR, int, bool); -static void gen_start(GPRE_REQ, POR, int, bool); +static void gen_send(GPRE_REQ, const por*, int, bool); +static void gen_start(GPRE_REQ, const por*, int, bool); static void gen_type(ACT, int); static void gen_variable(ACT, int); static void make_port(POR, int); -static void printa(int, TEXT *, ...); +static void printa(const int, const TEXT*, ...); static int first_flag = 0; @@ -75,12 +75,12 @@ static int first_flag = 0; #define JRD_VTOF "jrd_vtof" #define VTO_CALL "%s ((const char*)%s, (char*)%s, %d);" -static inline void begin(int column) +static inline void begin(const int column) { printa(column, "{"); } -static inline void endp(int column) +static inline void endp(const int column) { printa(column, "}"); } @@ -167,7 +167,7 @@ void INT_CXX_action( ACT action, int column) // Align output to a specific column for output. // -static void align( int column) +static void align(const int column) { int i; @@ -234,12 +234,10 @@ static void asgn_from( REF reference, int column) #ifdef NOT_USED_OR_REPLACED static void asgn_to( REF reference) { - GPRE_FLD field; - REF source; TEXT s[20]; - source = reference->ref_friend; - field = source->ref_field; + REF source = reference->ref_friend; + GPRE_FLD field = source->ref_field; gen_name(s, source); #pragma FB_COMPILER_MESSAGE("BUG: Checking for zero pointer - then using it!") @@ -266,10 +264,9 @@ static void asgn_to( REF reference) static void gen_at_end( ACT action, int column) { - GPRE_REQ request; TEXT s[20]; - request = action->act_request; + GPRE_REQ request = action->act_request; printa(column, "if (!%s) ", gen_name(s, request->req_eof)); } @@ -376,9 +373,7 @@ static void gen_emodify( ACT action, int column) static void gen_estore( ACT action, int column, bool special) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; align(column); gen_compile(request, column); gen_start(request, request->req_primary, column, special); @@ -392,9 +387,7 @@ static void gen_estore( ACT action, int column, bool special) static void gen_endfor( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; column += INDENT; if (request->req_sync) @@ -411,9 +404,7 @@ static void gen_endfor( ACT action, int column) static void gen_erase( ACT action, int column) { - UPD erase; - - erase = (UPD) action->act_object; + UPD erase = (UPD) action->act_object; gen_send(erase->upd_request, erase->upd_port, column, false); } @@ -425,13 +416,12 @@ static void gen_erase( ACT action, int column) static void gen_for( ACT action, int column) { - GPRE_REQ request; TEXT s[20]; gen_s_start(action, column); align(column); - request = action->act_request; + GPRE_REQ request = action->act_request; ib_fprintf(out_file, "while (1)"); column += INDENT; begin(column); @@ -465,17 +455,15 @@ static char* gen_name(char* string, const REF reference) static void gen_raw( GPRE_REQ request) { - UCHAR *blr, c; - TEXT buffer[80], *p; - int blr_length; + TEXT buffer[80]; - blr = request->req_blr; - blr_length = request->req_length; - p = buffer; + const UCHAR* blr = request->req_blr; + int blr_length = request->req_length; + TEXT* p = buffer; align(0); while (--blr_length) { - c = *blr++; + const UCHAR c = *blr++; if ((c >= 'A' && c <= 'Z') || c == '$' || c == '_') sprintf(p, "'%c',", c); else @@ -542,13 +530,12 @@ static void gen_request( GPRE_REQ request) static void gen_routine( ACT action, int column) { - GPRE_REQ request; - POR port; - - for (request = (GPRE_REQ) action->act_object; request; + for (GPRE_REQ request = (GPRE_REQ) action->act_object; request; request = request->req_routine) - for (port = request->req_ports; port; port = port->por_next) + { + for (POR port = request->req_ports; port; port = port->por_next) make_port(port, column + INDENT); + } } @@ -559,9 +546,7 @@ static void gen_routine( ACT action, int column) static void gen_s_end( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; printa(column, "EXE_unwind (tdbb, %s);", request->req_handle); } @@ -573,9 +558,7 @@ static void gen_s_end( ACT action, int column) static void gen_s_fetch( ACT action, int column) { - GPRE_REQ request; - - request = action->act_request; + GPRE_REQ request = action->act_request; if (request->req_sync) gen_send(request, request->req_sync, column, false); @@ -591,13 +574,11 @@ static void gen_s_fetch( ACT action, int column) static void gen_s_start( ACT action, int column) { - GPRE_REQ request; - POR port; - - request = action->act_request; + GPRE_REQ request = action->act_request; gen_compile(request, column); - if (port = request->req_vport) + const por* port = request->req_vport; + if (port) asgn_from(port->por_references, column); gen_start(request, port, column, false); @@ -609,7 +590,7 @@ static void gen_s_start( ACT action, int column) // Generate a send or receive call for a port. // -static void gen_send( GPRE_REQ request, POR port, int column, bool special) +static void gen_send( GPRE_REQ request, const por* port, int column, bool special) { if (special) { align(column); @@ -630,7 +611,7 @@ static void gen_send( GPRE_REQ request, POR port, int column, bool special) // Generate a START. // -static void gen_start( GPRE_REQ request, POR port, int column, bool special) +static void gen_start( GPRE_REQ request, const por* port, int column, bool special) { align(column); @@ -676,19 +657,17 @@ static void gen_variable( ACT action, int column) static void make_port( POR port, int column) { - GPRE_FLD field; - REF reference; - SYM symbol; - TEXT *name, s[50]; + TEXT s[50]; printa(column, "struct {"); - for (reference = port->por_references; reference; - reference = reference->ref_next) { + for (REF reference = port->por_references; reference; + reference = reference->ref_next) + { align(column + INDENT); - field = reference->ref_field; - symbol = field->fld_symbol; - name = symbol->sym_string; + GPRE_FLD field = reference->ref_field; + SYM symbol = field->fld_symbol; + TEXT* name = symbol->sym_string; switch (field->fld_dtype) { case dtype_short: ib_fprintf(out_file, " SSHORT jrd_%d;\t/* %s */", @@ -761,7 +740,7 @@ static void make_port( POR port, int column) // Print a fixed string at a particular column. // -static void printa( int column, TEXT * string, ...) +static void printa(const int column, const TEXT* string, ...) { va_list ptr; @@ -769,3 +748,4 @@ static void printa( int column, TEXT * string, ...) align(column); ib_vfprintf(out_file, string, ptr); } + diff --git a/src/gpre/pas.cpp b/src/gpre/pas.cpp index 9bb8628913..93b885d1c6 100644 --- a/src/gpre/pas.cpp +++ b/src/gpre/pas.cpp @@ -24,7 +24,7 @@ // //____________________________________________________________ // -// $Id: pas.cpp,v 1.21 2003-09-16 14:01:55 brodsom Exp $ +// $Id: pas.cpp,v 1.22 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -49,7 +49,7 @@ // why I rather than trying to use it currently remove it from compilation. -static void align(int); +static void align(const int); static void asgn_from(ACT, REF, int); static void asgn_sqlda_from(REF, int, TEXT *, int); static void asgn_to(ACT, REF, int); @@ -159,25 +159,25 @@ static int first_flag; #define GDS_EVENT_COUNTS "GDS__EVENT_COUNTS" #define GDS_EVENT_WAIT "GDS__EVENT_WAIT" -static inline void begin(int column) +static inline void begin(const int column) { printa(column, "begin"); } -static inline void endp(int column) +static inline void endp(const int column) { printa(column, "end"); } -static inline void ends(int column) +static inline void ends(const int column) { printa(column, "end;"); } -static inline void set_sqlcode(ACT action, int column) +static inline void set_sqlcode(ACT action, const int column) { if (action->act_flags & ACT_sql) - printa (column, "SQLCODE := gds__sqlcode (gds__status);"); + printa(column, "SQLCODE := gds__sqlcode (gds__status);"); } //____________________________________________________________ @@ -522,7 +522,7 @@ void PAS_action( ACT action, int column) // Align output to a specific column for output. // -static void align( int column) +static void align(const int column) { int i; @@ -1303,7 +1303,7 @@ static void gen_database( ACT action, int column) for (reference = port->por_references; reference; reference = reference->ref_next) { - if (reference-> ref_flags & REF_fetch_array) { + if (reference->ref_flags & REF_fetch_array) { make_array_declaration(reference); array_flag = true; } @@ -2659,7 +2659,7 @@ static void gen_request( GPRE_REQ request, int column) sw_volatile = FB_DP_VOLATILE; printa(column, " "); - if (!(request-> req_flags & (REQ_exp_hand | REQ_sql_blob_open | + if (!(request->req_flags & (REQ_exp_hand | REQ_sql_blob_open | REQ_sql_blob_create)) && request->req_type != REQ_slice && request->req_type != REQ_procedure) { @@ -3760,3 +3760,4 @@ static void t_start_auto( ACT action, GPRE_REQ request, TEXT * vector, int colum set_sqlcode(action, column); ends(column); } + diff --git a/src/gpre/sql.cpp b/src/gpre/sql.cpp index acc93ae454..b9100c3539 100644 --- a/src/gpre/sql.cpp +++ b/src/gpre/sql.cpp @@ -25,7 +25,7 @@ // //____________________________________________________________ // -// $Id: sql.cpp,v 1.24 2003-09-13 12:23:31 brodsom Exp $ +// $Id: sql.cpp,v 1.25 2003-09-25 11:49:02 robocop Exp $ // #include "firebird.h" @@ -149,10 +149,10 @@ static SWE whenever[SWE_max], whenever_list; static inline bool end_of_command(void) { - return (((sw_language != lang_cobol) && + return ((sw_language != lang_cobol) && ((int) token.tok_keyword == (int) KW_SEMI_COLON)) || ((sw_language == lang_cobol) && - ((int) token.tok_keyword == (int) KW_END_EXEC))); + ((int) token.tok_keyword == (int) KW_END_EXEC)); } @@ -6291,7 +6291,7 @@ void SQL_resolve_identifier( TEXT * err_mesg, TEXT * str) static void dialect1_bad_type(USHORT field_dtype) { char buffer[200]; - char *s = NULL; + const char *s = NULL; switch (field_dtype) { case dtype_sql_date: diff --git a/src/ipserver/ipserver.cpp b/src/ipserver/ipserver.cpp index 07325cc97c..346a3efbff 100644 --- a/src/ipserver/ipserver.cpp +++ b/src/ipserver/ipserver.cpp @@ -3256,7 +3256,7 @@ static void send_no_wait( ICC icc) } -static void send_response( ICC icc, ISC_STATUS * status_vector) +static void send_response( ICC icc, ISC_STATUS* status_vector) { /************************************** * @@ -3271,7 +3271,6 @@ static void send_response( ICC icc, ISC_STATUS * status_vector) ISC_STATUS *comm_status; USHORT i, length; ULONG to_copy, size_left; - TEXT *p, buffer[1024]; TEXT *acursor, *scursor, *abase; ips_comm_area *comm; TEXT *comm_ptr; @@ -3297,9 +3296,11 @@ static void send_response( ICC icc, ISC_STATUS * status_vector) { /* transfer the status vector, putting strings in the comm area's data area */ + TEXT buffer[1024]; while (*status_vector) { + const TEXT* p; switch (*status_vector) { case isc_arg_interpreted: diff --git a/src/isql/isql.epp b/src/isql/isql.epp index 56ae2d26d0..56a9247a51 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -1,6 +1,6 @@ /* * PROGRAM: Interactive SQL utility - * MODULE: isql.e + * MODULE: isql.epp * DESCRIPTION: Main line routine * * The contents of this file are subject to the Interbase Public @@ -785,7 +785,7 @@ void ISQL_copy_SQL_id(TEXT * in_str, } -void ISQL_errmsg(ISC_STATUS * status) +void ISQL_errmsg(const ISC_STATUS* status) { /************************************** * @@ -798,14 +798,13 @@ void ISQL_errmsg(ISC_STATUS * status) * Simulate isc_print_status exactly, to control ib_stderr **************************************/ TEXT errbuf[MSG_LENGTH]; - ISC_STATUS *vec; #if defined (WIN95) #define TRANSLATE_CP if (!fAnsiCP) AnsiToOem(errbuf, errbuf) #else #define TRANSLATE_CP #endif - vec = status; + const ISC_STATUS* vec = status; if (Quiet) Exit_value = FINI_ERROR; else { @@ -814,7 +813,10 @@ void ISQL_errmsg(ISC_STATUS * status) && vec[2] != gds_arg_warning) || (vec[0] == gds_arg_gds && vec[1] == 0 && vec[2] == gds_arg_warning - && !Warnings)) return; + && !Warnings)) + { + return; + } gds__msg_format(NULL, ISQL_MSG_FAC, 0, sizeof(errbuf), errbuf, (TEXT *) isc_sqlcode(status), NULL, NULL, NULL, NULL); TRANSLATE_CP; @@ -833,7 +835,7 @@ void ISQL_errmsg(ISC_STATUS * status) } -void ISQL_warning(ISC_STATUS * status) +void ISQL_warning(ISC_STATUS* status) { /************************************** * @@ -845,8 +847,6 @@ void ISQL_warning(ISC_STATUS * status) * Report warning * Simulate isc_print_status exactly, to control ib_stderr **************************************/ - ISC_STATUS *vec; - TEXT buf[MSG_LENGTH]; #if defined (WIN95) #define TRANSLATE_CP if (!fAnsiCP) AnsiToOem(buf, buf) #else @@ -854,13 +854,17 @@ void ISQL_warning(ISC_STATUS * status) #endif - vec = status; + const ISC_STATUS* vec = status; fb_assert(vec[1] == 0); /* shouldn't be any errors */ if (!Quiet) { if (vec[0] != gds_arg_gds || vec[2] != gds_arg_warning || - (vec[2] == gds_arg_warning && !Warnings)) return; + (vec[2] == gds_arg_warning && !Warnings)) + { + return; + } + TEXT buf[MSG_LENGTH]; isc_interprete(buf, &vec); TRANSLATE_CP; STDERROUT(buf, 1); diff --git a/src/isql/isql_proto.h b/src/isql/isql_proto.h index 9e6241aaf5..3461bfa420 100644 --- a/src/isql/isql_proto.h +++ b/src/isql/isql_proto.h @@ -36,8 +36,8 @@ extern int ISQL_create_database(TEXT *, SCHAR *, IB_FILE *, IB_FILE *, IB_FILE *); extern bool ISQL_dbcheck(void); extern void ISQL_disconnect_database(bool); -extern void ISQL_errmsg(ISC_STATUS *); -extern void ISQL_warning(ISC_STATUS *); +extern void ISQL_errmsg(const ISC_STATUS*); +extern void ISQL_warning(ISC_STATUS*); extern void ISQL_exit_db(void); extern int ISQL_extract(TEXT *, int, IB_FILE *, IB_FILE *, IB_FILE *); extern int ISQL_frontend_command(TEXT *, IB_FILE *, IB_FILE *, IB_FILE *); @@ -65,3 +65,4 @@ extern void ISQL_truncate_term(TEXT *, USHORT); extern void ISQL_win_err(SCHAR *); #endif /* ISQL_ISQL_PROTO_H */ + diff --git a/src/jrd/alt.cpp b/src/jrd/alt.cpp index ef8219992e..360c3ef262 100644 --- a/src/jrd/alt.cpp +++ b/src/jrd/alt.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: alt.c + * MODULE: alt.cpp * DESCRIPTION: Alternative entrypoints * * The contents of this file are subject to the Interbase Public @@ -665,12 +665,12 @@ void API_ROUTINE isc_qtoq(GDS_QUAD * quad1, GDS_QUAD * quad2) gds__qtoq(quad1, quad2); } -SLONG API_ROUTINE isc_sqlcode(ISC_STATUS * status_vector) +SLONG API_ROUTINE isc_sqlcode(const ISC_STATUS* status_vector) { return gds__sqlcode(status_vector); } -void API_ROUTINE isc_sqlcode_s(ISC_STATUS * status_vector, ULONG * sqlcode) +void API_ROUTINE isc_sqlcode_s(const ISC_STATUS* status_vector, ULONG * sqlcode) { *sqlcode = gds__sqlcode(status_vector); return; @@ -712,7 +712,7 @@ ISC_STATUS API_ROUTINE isc_wait_for_event(ISC_STATUS * status_vector, } #endif -ISC_STATUS API_ROUTINE isc_interprete(SCHAR * buffer, ISC_STATUS ** status_vector_p) +ISC_STATUS API_ROUTINE isc_interprete(SCHAR* buffer, const ISC_STATUS** status_vector_p) { return gds__interprete(buffer, status_vector_p); } diff --git a/src/jrd/gds.cpp b/src/jrd/gds.cpp index 02f852a940..ca54b6649e 100644 --- a/src/jrd/gds.cpp +++ b/src/jrd/gds.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: gds.c + * MODULE: gds.cpp * DESCRIPTION: User callable routines * * The contents of this file are subject to the Interbase Public @@ -782,7 +782,7 @@ void API_ROUTINE gds_alloc_report(ULONG flags, char* filename, int lineno) } #endif // DEBUG_GDS_ALLOC -SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) +SLONG API_ROUTINE gds__interprete(char* s, const ISC_STATUS** vector) { /************************************** * @@ -796,13 +796,6 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) * message is null (end of messages) or invalid, return 0; * **************************************/ - TEXT *p, *q, *temp; - SSHORT l, temp_len; - - TEXT **arg, *args[10]; - ISC_STATUS code, *v; - UCHAR x; - ISC_STATUS decoded; #ifdef VMS ISC_STATUS status; TEXT flags[4]; @@ -812,8 +805,8 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) if (!**vector) return 0; - temp = NULL; - + const ISC_STATUS* v; + ISC_STATUS code; /* handle a case: "no errors, some warning(s)" */ if ((*vector)[1] == 0 && (*vector)[2] == isc_arg_warning) { v = *vector + 4; @@ -824,16 +817,23 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) code = (*vector)[1]; } - arg = args; + TEXT* args[10]; + TEXT** arg = args; /* Parse and collect any arguments that may be present */ + + TEXT* p; + const TEXT* q; + const SSHORT temp_len = (SSHORT) BUFFER_SMALL; + TEXT* temp = NULL; + SSHORT l; for (;;) { - x = (UCHAR) * v++; + const UCHAR x = (UCHAR) *v++; switch (x) { case gds_arg_string: case gds_arg_number: - *arg++ = (TEXT *) * v++; + *arg++ = (TEXT*) *v++; continue; case gds_arg_cstring: @@ -842,21 +842,20 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) Give up if we can't get one. */ p = temp = (TEXT*) gds__alloc((SLONG) BUFFER_SMALL); - temp_len = (SSHORT) BUFFER_SMALL; /* FREE: at procedure exit */ if (!temp) /* NOMEM: */ return 0; } - l = (SSHORT) * v++; - q = (TEXT *) * v++; + l = (SSHORT) *v++; + q = (const TEXT*) *v++; *arg++ = p; /* ensure that we do not overflow the buffer allocated */ l = (temp_len < l) ? temp_len : l; if (l) - do + do { *p++ = *q++; - while (--l); + } while (--l); *p++ = 0; continue; @@ -874,10 +873,11 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) case gds_arg_gds: { USHORT fac = 0, class_ = 0; - decoded = gds__decode(code, &fac, &class_); + const ISC_STATUS decoded = gds__decode(code, &fac, &class_); if (gds__msg_format(0, fac, (USHORT) decoded, 128, s, args[0], args[1], args[2], args[3], - args[4]) < 0) { + args[4]) < 0) + { if ((decoded < FB_NELEM(messages) - 1) && (decoded >= 0)) sprintf(s, messages[decoded], args[0], args[1], args[2], args[3], args[4]); @@ -889,14 +889,14 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) case gds_arg_interpreted: p = s; - q = (TEXT *) (*vector)[1]; + q = (const TEXT*) (*vector)[1]; while ((*p++ = *q++) /*!= NULL*/); break; case gds_arg_unix: /* The strerror() function returns the appropriate description string, or an unknown error message if the error code is unknown. */ - p = (TEXT*)strerror(code); + p = (TEXT*) strerror(code); break; case gds_arg_dos: @@ -949,18 +949,18 @@ SLONG API_ROUTINE gds__interprete(char *s, ISC_STATUS ** vector) gds__free((SLONG *) temp); *vector = v; - p = s; - while (*p) - p++; + const TEXT* end = s; + while (*end) + end++; - return p - s; + return end - s; } void API_ROUTINE gds__interprete_a( SCHAR * s, SSHORT * length, - ISC_STATUS * vector, SSHORT * offset) + const ISC_STATUS* vector, SSHORT * offset) { /************************************** * @@ -976,9 +976,7 @@ void API_ROUTINE gds__interprete_a( * the concept of indexing into the vector. * **************************************/ - ISC_STATUS *v; - - v = vector + *offset; + const ISC_STATUS *v = vector + *offset; *length = (SSHORT) gds__interprete(s, &v); *offset = v - vector; } @@ -1155,7 +1153,7 @@ void API_ROUTINE gds__log(const TEXT * text, ...) } -void API_ROUTINE gds__log_status(TEXT * database, ISC_STATUS * status_vector) +void API_ROUTINE gds__log_status(TEXT * database, const ISC_STATUS* status_vector) { /************************************** * @@ -1853,7 +1851,7 @@ void API_ROUTINE gds__prefix_msg(TEXT * string, const TEXT * root) #endif -ISC_STATUS API_ROUTINE gds__print_status(ISC_STATUS * vec) +ISC_STATUS API_ROUTINE gds__print_status(const ISC_STATUS* vec) { /************************************** * @@ -1865,18 +1863,15 @@ ISC_STATUS API_ROUTINE gds__print_status(ISC_STATUS * vec) * Interprete a status vector. * **************************************/ - ISC_STATUS *vector; - TEXT *s; - if (!vec || (!vec[1] && vec[2] == gds_arg_end)) return FB_SUCCESS; - s = (TEXT *) gds__alloc((SLONG) BUFFER_LARGE); + TEXT* s = (TEXT *) gds__alloc((SLONG) BUFFER_LARGE); /* FREE: at procedure return */ if (!s) /* NOMEM: */ return vec[1]; - vector = vec; + const ISC_STATUS* vector = vec; if (!gds__interprete(s, &vector)) { gds__free((SLONG *) s); @@ -2180,7 +2175,7 @@ void API_ROUTINE gds__register_cleanup(FPTR_VOID_PTR routine, void *arg) } -SLONG API_ROUTINE gds__sqlcode(ISC_STATUS * status_vector) +SLONG API_ROUTINE gds__sqlcode(const ISC_STATUS* status_vector) { /************************************** * @@ -2199,18 +2194,13 @@ SLONG API_ROUTINE gds__sqlcode(ISC_STATUS * status_vector) * first code for which there is a non-generic SQLCODE, return it. * **************************************/ - USHORT code; - SLONG sqlcode; - ISC_STATUS *s; - USHORT have_sqlcode; - if (!status_vector) { DEV_REPORT("gds__sqlcode: NULL status vector"); return GENERIC_SQLCODE; } - have_sqlcode = FALSE; - sqlcode = GENERIC_SQLCODE; /* error of last resort */ + bool have_sqlcode = false; + SLONG sqlcode = GENERIC_SQLCODE; /* error of last resort */ /* SQL code -999 (GENERIC_SQLCODE) is generic, meaning "no other sql code * known". Now scan the status vector, seeing if there is ANY sqlcode @@ -2219,7 +2209,7 @@ SLONG API_ROUTINE gds__sqlcode(ISC_STATUS * status_vector) * sqlerr reported. */ - s = status_vector; + const ISC_STATUS* s = status_vector; while (*s != gds_arg_end) { if (*s == gds_arg_gds) @@ -2235,13 +2225,13 @@ SLONG API_ROUTINE gds__sqlcode(ISC_STATUS * status_vector) sql_codes */ USHORT fac = 0, class_ = 0; - code = (USHORT) gds__decode(status_vector[1], &fac, &class_); + USHORT code = (USHORT) gds__decode(status_vector[1], &fac, &class_); if ((code < FB_NELEM(gds__sql_code)) && (gds__sql_code[code] != GENERIC_SQLCODE)) { sqlcode = gds__sql_code[code]; - have_sqlcode = TRUE; + have_sqlcode = true; } } s++; @@ -2256,7 +2246,7 @@ SLONG API_ROUTINE gds__sqlcode(ISC_STATUS * status_vector) } -void API_ROUTINE gds__sqlcode_s(ISC_STATUS * status_vector, ULONG * sqlcode) +void API_ROUTINE gds__sqlcode_s(const ISC_STATUS* status_vector, ULONG* sqlcode) { /************************************** * @@ -2268,7 +2258,7 @@ void API_ROUTINE gds__sqlcode_s(ISC_STATUS * status_vector, ULONG * sqlcode) * Translate GDS error code to SQL error code. This is a little * imprecise (to say the least) because we don't know the proper * SQL codes. One must do what what can; stiff upper lip, and all - * that. THIS IS THE COBOL VERSION. (Some cobols son't have + * that. THIS IS THE COBOL VERSION. (Some cobols don't have * return values for calls... * **************************************/ diff --git a/src/jrd/gds_proto.h b/src/jrd/gds_proto.h index 7a421fa871..d2b65c97bc 100644 --- a/src/jrd/gds_proto.h +++ b/src/jrd/gds_proto.h @@ -79,11 +79,11 @@ void API_ROUTINE isc_encode_sql_date(void*, GDS_DATE*); void API_ROUTINE isc_encode_sql_time(void*, GDS_TIME*); void API_ROUTINE isc_encode_timestamp(void*, GDS_TIMESTAMP*); ULONG API_ROUTINE gds__free(void*); -SLONG API_ROUTINE gds__interprete(char*, ISC_STATUS**); -void API_ROUTINE gds__interprete_a(SCHAR*, SSHORT*, ISC_STATUS*, SSHORT*); +SLONG API_ROUTINE gds__interprete(char*, const ISC_STATUS**); +void API_ROUTINE gds__interprete_a(SCHAR*, SSHORT*, const ISC_STATUS*, SSHORT*); void API_ROUTINE gds__log(const TEXT*, ...); void API_ROUTINE gds__trace(const TEXT*); -void API_ROUTINE gds__log_status(TEXT*, ISC_STATUS*); +void API_ROUTINE gds__log_status(TEXT*, const ISC_STATUS*); int API_ROUTINE gds__msg_close(void*); SSHORT API_ROUTINE gds__msg_format(void* handle, USHORT facility, @@ -105,7 +105,7 @@ void API_ROUTINE gds__prefix_lock(TEXT*, const TEXT*); void API_ROUTINE gds__prefix_msg(TEXT*, const TEXT*); SLONG API_ROUTINE gds__get_prefix(SSHORT, TEXT*); -ISC_STATUS API_ROUTINE gds__print_status(ISC_STATUS*); +ISC_STATUS API_ROUTINE gds__print_status(const ISC_STATUS*); USHORT API_ROUTINE gds__parse_bpb(USHORT, UCHAR*, USHORT*, USHORT*); USHORT API_ROUTINE gds__parse_bpb2(USHORT, UCHAR*, SSHORT*, SSHORT*, USHORT*, USHORT*); @@ -115,8 +115,8 @@ int API_ROUTINE gds__print_blr(UCHAR*, FPTR_VOID, SCHAR*, SSHORT); void API_ROUTINE gds__put_error(TEXT*); void API_ROUTINE gds__qtoq(void*, void*); void API_ROUTINE gds__register_cleanup(FPTR_VOID_PTR, void*); -SLONG API_ROUTINE gds__sqlcode(ISC_STATUS*); -void API_ROUTINE gds__sqlcode_s(ISC_STATUS*, ULONG*); +SLONG API_ROUTINE gds__sqlcode(const ISC_STATUS*); +void API_ROUTINE gds__sqlcode_s(const ISC_STATUS*, ULONG*); void API_ROUTINE gds__temp_dir(TEXT*); void* API_ROUTINE gds__temp_file(BOOLEAN, TEXT*, TEXT*, TEXT* = NULL, BOOLEAN = FALSE); void API_ROUTINE gds__unregister_cleanup(FPTR_VOID_PTR, void*); diff --git a/src/jrd/gdsold.h b/src/jrd/gdsold.h index 175383638e..8c7accd258 100644 --- a/src/jrd/gdsold.h +++ b/src/jrd/gdsold.h @@ -263,9 +263,9 @@ int GDS_EXPORT gds__disable_subsystem(char *); int GDS_EXPORT gds__enable_subsystem(char *); -ISC_STATUS GDS_EXPORT gds__print_status(ISC_STATUS *); +ISC_STATUS GDS_EXPORT gds__print_status(const ISC_STATUS*); -ISC_STATUS GDS_EXPORT gds__sqlcode(ISC_STATUS *); +ISC_STATUS GDS_EXPORT gds__sqlcode(const ISC_STATUS*); ISC_STATUS GDS_EXPORT gds__ddl(ISC_STATUS *, FRBRD **, diff --git a/src/jrd/ibase.h b/src/jrd/ibase.h index 22249f7e55..9c195b38ae 100644 --- a/src/jrd/ibase.h +++ b/src/jrd/ibase.h @@ -33,7 +33,7 @@ * */ /* -$Id: ibase.h,v 1.45 2003-09-21 13:33:45 skidder Exp $ +$Id: ibase.h,v 1.46 2003-09-25 11:49:06 robocop Exp $ */ #ifndef JRD_IBASE_H @@ -636,8 +636,8 @@ ISC_STATUS ISC_EXPORT isc_get_slice(ISC_STATUS *, void *, ISC_LONG *); -ISC_STATUS ISC_EXPORT isc_interprete(char *, - ISC_STATUS * *); +ISC_STATUS ISC_EXPORT isc_interprete(char*, + const ISC_STATUS**); ISC_STATUS ISC_EXPORT isc_open_blob(ISC_STATUS *, isc_db_handle *, @@ -702,7 +702,7 @@ ISC_STATUS ISC_EXPORT_VARARG isc_start_transaction(ISC_STATUS *, isc_tr_handle *, short, ...); -ISC_LONG ISC_EXPORT isc_sqlcode(ISC_STATUS *); +ISC_LONG ISC_EXPORT isc_sqlcode(const ISC_STATUS*); void ISC_EXPORT isc_sql_interprete(short, char *, diff --git a/src/jrd/intlobj.h b/src/jrd/intlobj.h index 8761776586..fefb1e6254 100644 --- a/src/jrd/intlobj.h +++ b/src/jrd/intlobj.h @@ -24,8 +24,8 @@ * in the texttype struct so we remain compatible with any IB WRT intl module. */ -#ifndef _JRD_INTLOBJ_H_ -#define _JRD_INTLOBJ_H_ +#ifndef JRD_INTLOBJ_H +#define JRD_INTLOBJ_H #ifdef __cplusplus extern "C" { @@ -69,7 +69,7 @@ typedef struct intl_blk { USHORT blk_length; } intl_blk; -typedef unsigned short(*pfn_INTL_init)(struct texttype *,short,short); +typedef unsigned short(*pfn_INTL_init)(struct texttype*, short, short); typedef struct texttype { struct intl_blk texttype_blk; @@ -184,4 +184,5 @@ typedef struct charset } /* extern "C" */ #endif -#endif /* _JRD_INTLOBJ_H_ */ +#endif /* JRD_INTLOBJ_H */ + diff --git a/src/jrd/isc.cpp b/src/jrd/isc.cpp index fc47c7102a..dd9b1335aa 100644 --- a/src/jrd/isc.cpp +++ b/src/jrd/isc.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: isc.c + * MODULE: isc.cpp * DESCRIPTION: General purpose but non-user routines. * * The contents of this file are subject to the Interbase Public @@ -36,7 +36,7 @@ * */ /* -$Id: isc.cpp,v 1.38 2003-09-22 17:52:27 brodsom Exp $ +$Id: isc.cpp,v 1.39 2003-09-25 11:49:06 robocop Exp $ */ #ifdef DARWIN #define _STLP_CCTYPE @@ -229,9 +229,7 @@ int DLL_EXPORT ISC_check_process_existence(SLONG pid, #ifdef VMS #define CHECK_EXIST - ULONG item; - - item = JPI$_PID; + ULONG item = JPI$_PID; return (lib$getjpi(&item, &pid, NULL, NULL, NULL, NULL) == SS$_NONEXPR) ? FALSE : TRUE; #endif @@ -270,9 +268,7 @@ int ISC_expand_logical_once( * Expand a logical name. If it doesn't exist, return 0. * **************************************/ - int attr; USHORT l; - TEXT *p; ITM items[2]; struct dsc$descriptor_s desc1, desc2; @@ -290,7 +286,7 @@ int ISC_expand_logical_once( items[1].itm_length = 0; items[1].itm_code = 0; - attr = LNM$M_CASE_BLIND; + int attr = LNM$M_CASE_BLIND; if (!(sys$trnlnm(&attr, &desc2, &desc1, NULL, items) & 1)) { while (file_length--) @@ -346,12 +342,10 @@ TEXT *INTERNAL_API_ROUTINE ISC_get_host(TEXT * string, USHORT length) * Get host name. * **************************************/ - TEXT *p; - if (!ISC_expand_logical_once("SYS$NODE", sizeof("SYS$NODE") - 1, string)) strcpy(string, "local"); else { - p = string; + TEXT* p = string; if (*p == '_') ++p; @@ -494,11 +488,13 @@ int INTERNAL_API_ROUTINE ISC_get_user(TEXT* name, #ifdef VMS int INTERNAL_API_ROUTINE ISC_get_user( - TEXT * name, - int *id, - int *group, - TEXT * project, -TEXT * organization, int *node, TEXT * user_string) + TEXT* name, + int* id, + int* group, + TEXT* project, + TEXT* organization, + int* node, + TEXT* user_string) { /************************************** * @@ -510,10 +506,9 @@ TEXT * organization, int *node, TEXT * user_string) * Find out who the user is. * **************************************/ - SLONG status, privileges[2]; + SLONG privileges[2]; USHORT uic[2], len0, len1, len2; TEXT *p, *q, *end, user_name[256]; - ITM items[4]; if (user_string && *user_string) { for (p = user_name, q = user_string; (*p = *q++) && *p != '.'; p++); @@ -537,6 +532,7 @@ TEXT * organization, int *node, TEXT * user_string) } } else { + ITM items[4]; items[0].itm_code = JPI$_UIC; items[0].itm_length = sizeof(uic); items[0].itm_buffer = uic; @@ -555,7 +551,7 @@ TEXT * organization, int *node, TEXT * user_string) items[3].itm_code = 0; items[3].itm_length = 0; - status = sys$getjpiw(NULL, NULL, NULL, items, NULL, NULL, NULL); + SLONG status = sys$getjpiw(NULL, NULL, NULL, items, NULL, NULL, NULL); if (!(status & 1)) { len1 = 0; @@ -694,7 +690,7 @@ static BOOLEAN check_user_privilege(void) TOKEN_GROUPS* ptg = NULL; DWORD token_len = 0; - while (TRUE) + while (true) { /* Then we must query the size of the group information associated with the token. This is guarenteed to fail the first time through @@ -955,14 +951,10 @@ void ISC_wake(SLONG process_id) * remote (but on the same CPU). * **************************************/ - int status; - POKE poke; - TEXT string[32]; - struct dsc$descriptor_s desc; /* Try to do a simple wake. If this succeeds, we're done. */ - status = sys$wake(&process_id, 0); + int status = sys$wake(&process_id, 0); #ifdef __ALPHA THREAD_wakeup(); #endif @@ -974,6 +966,7 @@ void ISC_wake(SLONG process_id) /* Find a free poke block to use */ + POKE poke; for (poke = pokes; poke; poke = poke->poke_next) if (!poke->poke_use_count) break; @@ -991,6 +984,8 @@ void ISC_wake(SLONG process_id) ++poke->poke_use_count; + TEXT string[32]; + struct dsc$descriptor_s desc; sprintf(string, WAKE_LOCK, process_id); ISC_make_desc(string, &desc, 0); @@ -1022,9 +1017,7 @@ void ISC_wake_init(void) * Set up to be awakened by another process thru a blocking AST. * **************************************/ - int status; TEXT string[32]; - FPTR_INT master; struct dsc$descriptor_s desc; /* If we already have lock, we're done */ @@ -1035,7 +1028,7 @@ void ISC_wake_init(void) sprintf(string, WAKE_LOCK, getpid()); ISC_make_desc(string, &desc, 0); - status = sys$enqw(0, /* event flag */ + int status = sys$enqw(0, /* event flag */ LCK$K_PWMODE, /* lock mode */ &wake_lock, /* Lock status block */ LCK$M_SYSTEM, /* flags */ @@ -1063,11 +1056,10 @@ static void blocking_ast(void) * Somebody else is trying to post a lock. * **************************************/ - int status; /* Initially down grade the lock to let the other guy complete */ - status = sys$enqw(0, /* event flag */ + int status = sys$enqw(0, /* event flag */ LCK$K_NLMODE, /* lock mode */ &wake_lock, /* Lock status block */ LCK$M_CONVERT, /* flags */ @@ -1114,11 +1106,8 @@ static void poke_ast(POKE poke) * and deque the lock. * **************************************/ - int status; - LKSB *lksb; - - lksb = &poke->poke_lksb; - status = sys$deq(lksb->lksb_lock_id, 0, 0, 0); + LKSB* lksb = &poke->poke_lksb; + int status = sys$deq(lksb->lksb_lock_id, 0, 0, 0); --poke->poke_use_count; } #endif @@ -1170,9 +1159,7 @@ SLONG ISC_get_user_group_id(TEXT * user_group_name) **************************************/ struct group *user_group; - SLONG n; - - n = 0; + SLONG n = 0; if ( (user_group = getgrnam(user_group_name)) ) @@ -1199,9 +1186,7 @@ SLONG ISC_get_user_group_id(TEXT * user_group_name) * **************************************/ - SLONG n; - - n = 0; + SLONG n = 0; return (n); } #endif /* end of ifdef UNIX */ @@ -1214,6 +1199,7 @@ BOOLEAN ISC_is_WinNT() { OSVERSIONINFO OsVersionInfo; + // thread safe??? :-) if (!os_type) { os_type = 1; /* Default to NT */ @@ -1271,3 +1257,4 @@ LPSECURITY_ATTRIBUTES ISC_get_security_desc() } #endif + diff --git a/src/jrd/isc_file.cpp b/src/jrd/isc_file.cpp index 51ccebf161..754923869a 100644 --- a/src/jrd/isc_file.cpp +++ b/src/jrd/isc_file.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: isc_file.c + * MODULE: isc_file.cpp * DESCRIPTION: General purpose but non-user routines. * * The contents of this file are subject to the Interbase Public @@ -1770,3 +1770,4 @@ bool ISC_verify_database_access(TEXT *name) { #endif return true; } + diff --git a/src/jrd/isc_sync.cpp b/src/jrd/isc_sync.cpp index af409ba269..14bcd62767 100644 --- a/src/jrd/isc_sync.cpp +++ b/src/jrd/isc_sync.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: isc_sync.c + * MODULE: isc_sync.cpp * DESCRIPTION: General purpose but non-user routines. * * The contents of this file are subject to the Interbase Public diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index c45926c08f..8d11aa52ce 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: jrd.c + * MODULE: jrd.cpp * DESCRIPTION: User visible entrypoints * * The contents of this file are subject to the Interbase Public @@ -6645,3 +6645,4 @@ static bool verify_database_name(TEXT *name, ISC_STATUS *status) } } // extern "C" + diff --git a/src/jrd/jrn.cpp b/src/jrd/jrn.cpp index e466c706f9..9b07c13de4 100644 --- a/src/jrd/jrn.cpp +++ b/src/jrd/jrn.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: jrn.c + * MODULE: jrn.cpp * DESCRIPTION: Journalling interface for database system. * * The contents of this file are subject to the Interbase Public diff --git a/src/jrd/met.epp b/src/jrd/met.epp index c18794b358..13f0c0cd25 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: met.e + * MODULE: met.epp * DESCRIPTION: Meta data handler * * The contents of this file are subject to the Interbase Public @@ -37,7 +37,7 @@ * */ /* -$Id: met.epp,v 1.69 2003-09-22 17:52:27 brodsom Exp $ +$Id: met.epp,v 1.70 2003-09-25 11:49:06 robocop Exp $ */ // This MUST be at the top of the file #ifdef DARWIN diff --git a/src/jrd/perf.cpp b/src/jrd/perf.cpp index e67ffd9b02..15770c2414 100644 --- a/src/jrd/perf.cpp +++ b/src/jrd/perf.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: perf.c + * MODULE: perf.cpp * DESCRIPTION: Performance monitoring routines * * The contents of this file are subject to the Interbase Public diff --git a/src/jrd/scl.epp b/src/jrd/scl.epp index 8530842302..9551ae8718 100644 --- a/src/jrd/scl.epp +++ b/src/jrd/scl.epp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: scl.e + * MODULE: scl.epp * DESCRIPTION: Security class handler * * The contents of this file are subject to the Interbase Public @@ -135,9 +135,6 @@ void SCL_check_access(SCL s_class, * object in question. * **************************************/ - const P_NAMES* names; - SCL att_class; - TDBB tdbb = GET_THREAD_DATA; if (s_class && (s_class->scl_flags & SCL_corrupt)) @@ -150,8 +147,8 @@ void SCL_check_access(SCL s_class, ATT attachment = tdbb->tdbb_attachment; - if ((att_class = attachment->att_security_class) && - !(att_class->scl_flags & mask)) + SCL att_class = attachment->att_security_class; + if (att_class && !(att_class->scl_flags & mask)) { type = "DATABASE"; name = ""; @@ -179,6 +176,7 @@ void SCL_check_access(SCL s_class, return; } + const P_NAMES* names; for (names = p_names; names->p_names_priv; names++) { if (names->p_names_priv & mask) @@ -214,7 +212,6 @@ void SCL_check_index(TDBB tdbb, TEXT* index_name, UCHAR index_id, USHORT mask) * becomes relation_name since index ids are relative to tables. * *******************************************************/ - volatile BLK request; SCL s_class, default_s_class; TEXT reln_name[32], aux_idx_name[32]; TEXT *idx_name_ptr = index_name, *relation_name_ptr = index_name; @@ -231,7 +228,7 @@ void SCL_check_index(TDBB tdbb, TEXT* index_name, UCHAR index_id, USHORT mask) reln_name[0] = aux_idx_name[0] = 0; - request = NULL; + volatile BLK request = NULL; // No need to cache this request handle, it's only used when // new constraints are created @@ -335,9 +332,7 @@ void SCL_check_procedure(DSC* dsc_name, USHORT mask) * scanned. This is used exclusively for meta-data operations. * **************************************/ - BLK request; - SCL s_class; - TEXT *p, *q, *endp, *endq, name[32]; + TEXT name[32]; TDBB tdbb = GET_THREAD_DATA; @@ -345,18 +340,22 @@ void SCL_check_procedure(DSC* dsc_name, USHORT mask) assert(dsc_name->dsc_dtype == dtype_text); - for (p = name, endp = name + sizeof(name) - 1, - q = (TEXT*)dsc_name->dsc_address, endq = q + dsc_name->dsc_length; - q < endq && p < endp && *q;) + { // scope only block + TEXT* p = name; + const TEXT* const endp = name + sizeof(name) - 1; + const TEXT* q = (TEXT*) dsc_name->dsc_address; + const TEXT* const endq = q + dsc_name->dsc_length; + while (q < endq && p < endp && *q) *p++ = *q++; *p = 0; + } // end scope block MET_exact_name(name); DBB dbb = tdbb->tdbb_database; - s_class = NULL; + SCL s_class = NULL; - request = (BLK) CMP_find_request(tdbb, irq_p_security, IRQ_REQUESTS); + BLK request = (BLK) CMP_find_request(tdbb, irq_p_security, IRQ_REQUESTS); FOR(REQUEST_HANDLE request) JRD_PRC IN RDB$PROCEDURES WITH JRD_PRC.RDB$PROCEDURE_NAME EQ name @@ -389,9 +388,7 @@ void SCL_check_relation(DSC* dsc_name, USHORT mask) * scanned. This is used exclusively for meta-data operations. * **************************************/ - BLK request; - SCL s_class; - TEXT *p, *q, *endp, *endq, name[32]; + TEXT name[32]; TDBB tdbb = GET_THREAD_DATA; @@ -399,18 +396,22 @@ void SCL_check_relation(DSC* dsc_name, USHORT mask) assert(dsc_name->dsc_dtype == dtype_text); - for (p = name, endp = name + sizeof(name) - 1, - q = (TEXT*)dsc_name->dsc_address, endq = q + dsc_name->dsc_length; - q < endq && p < endp && *q;) + { // scope only block + TEXT* p = name; + const TEXT* const endp = name + sizeof(name) - 1; + const TEXT* q = (TEXT*) dsc_name->dsc_address; + const TEXT* const endq = q + dsc_name->dsc_length; + while (q < endq && p < endp && *q) *p++ = *q++; *p = 0; + } // end scope block MET_exact_name(name); DBB dbb = tdbb->tdbb_database; - s_class = NULL; + SCL s_class = NULL; - request = (BLK) CMP_find_request(tdbb, irq_v_security, IRQ_REQUESTS); + BLK request = (BLK) CMP_find_request(tdbb, irq_v_security, IRQ_REQUESTS); FOR(REQUEST_HANDLE request) REL IN RDB$RELATIONS WITH REL.RDB$RELATION_NAME EQ name @@ -443,9 +444,6 @@ SCL SCL_get_class(/* INOUT */ TEXT* string) * class block. * **************************************/ - SCL s_class; - ATT attachment; - TDBB tdbb = GET_THREAD_DATA; DBB dbb = tdbb->tdbb_database; @@ -459,10 +457,11 @@ SCL SCL_get_class(/* INOUT */ TEXT* string) if (!string[0]) return NULL; - attachment = tdbb->tdbb_attachment; + ATT attachment = tdbb->tdbb_attachment; // Look for the class already known + SCL s_class; for (s_class = attachment->att_security_classes; s_class; s_class = s_class->scl_next) @@ -507,18 +506,14 @@ int SCL_get_mask(const TEXT* relation_name, const TEXT* field_name) * **************************************/ JRD_REL relation; - JRD_FLD field; - SSHORT id; - USHORT access; - SCL s_class; TDBB tdbb = GET_THREAD_DATA; ATT attachment = tdbb->tdbb_attachment; // Start with database security class - access = - (s_class = attachment->att_security_class) ? s_class->scl_flags : -1; + SCL s_class = attachment->att_security_class; + USHORT access = (s_class) ? s_class->scl_flags : -1; // If there's a relation, track it down @@ -530,6 +525,9 @@ int SCL_get_mask(const TEXT* relation_name, const TEXT* field_name) { access &= s_class->scl_flags; } + + JRD_FLD field; + SSHORT id; if (field_name && (id = MET_lookup_field(tdbb, relation, field_name, 0)) >= 0 && (field = MET_get_field(relation, id)) && @@ -570,32 +568,27 @@ void SCL_init(bool create, * in, encrypting if necessary. * **************************************/ - DBB dbb; - BLK handle, handle1; volatile BLK request; - USR user; TEXT name[129], project[33], organization[33], *p; - USHORT length; - int id, group, wheel, node_id; TEXT role_name[33], login_name[129], *q; - USHORT major_version, minor_original; bool preODS9; SET_TDBB(tdbb); - dbb = tdbb->tdbb_database; - major_version = (SSHORT) dbb->dbb_ods_version; - minor_original = (SSHORT) dbb->dbb_minor_original; + DBB dbb = tdbb->tdbb_database; + USHORT major_version = dbb->dbb_ods_version; + USHORT minor_original = dbb->dbb_minor_original; *project = *organization = *name = *role_name = *login_name = '\0'; - node_id = 0; - id = group = -1; // CVC: This var contained trash + int node_id = 0; + int id = -1, group = -1; // CVC: This var contained trash #ifdef NO_SECURITY - wheel = 1; + bool wheel = true; #else + bool wheel = false; if (!user_name) { - wheel = ISC_get_user(name, + wheel = (bool) ISC_get_user(name, &id, &group, project, @@ -603,10 +596,6 @@ void SCL_init(bool create, &node_id, sys_user_name); } - else - { - wheel = 0; - } if (user_name || (id == -1)) { @@ -626,7 +615,7 @@ void SCL_init(bool create, if (!strcmp(name, SYSDBA_USER_NAME)) { - wheel = 1; + wheel = true; } } #endif // NO_SECURITY @@ -738,9 +727,10 @@ void SCL_init(bool create, strcpy(role_name, "NONE"); } - length = strlen(name) + strlen(role_name) + strlen(project) + + USHORT length = strlen(name) + strlen(role_name) + strlen(project) + strlen(organization) + 4; /* for the terminating nulls */ - tdbb->tdbb_attachment->att_user = user = FB_NEW_RPT(*dbb->dbb_permanent, length) usr(); + usr* user = FB_NEW_RPT(*dbb->dbb_permanent, length) usr(); + tdbb->tdbb_attachment->att_user = user; p = user->usr_data; user->usr_user_name = save_string(name, &p); user->usr_project_name = save_string(project, &p); @@ -752,7 +742,7 @@ void SCL_init(bool create, if (wheel) user->usr_flags |= USR_locksmith; - handle = handle1 = NULL; + BLK handle = NULL, handle1 = NULL; if (!create) { FOR(REQUEST_HANDLE handle) X IN RDB$DATABASE @@ -1034,11 +1024,10 @@ static bool check_string(const TEXT* acl, const TEXT* string) * * Functional description * Check a string against and acl string. If they don't match, - * return TRUE. + * return true. * **************************************/ USHORT l; - TEXT c1, c2; // Add these asserts to catch calls to this function with NULL, // the caller to this function must check to ensure that the arguments are not @@ -1052,8 +1041,8 @@ static bool check_string(const TEXT* acl, const TEXT* string) if ( (l = *acl++) ) { do { - c1 = *acl++; - c2 = *string++; + TEXT c1 = *acl++; + TEXT c2 = *string++; if (UPPER7(c1) != UPPER7(c2)) return true; } while (--l); @@ -1088,10 +1077,7 @@ static SLONG compute_access(TDBB tdbb, * access permissions. Return a flag word of recognized privileges. * **************************************/ - BLK request; - BLB blob; - TEXT *acl; - TEXT *buffer; + BLB blob = NULL; volatile STR str_buffer = NULL; SLONG length = BLOB_BUFFER_SIZE, *length_ptr = &length; @@ -1106,9 +1092,9 @@ static SLONG compute_access(TDBB tdbb, str_buffer = FB_NEW_RPT(*dbb->dbb_permanent, BLOB_BUFFER_SIZE) str(); str_buffer->str_length = BLOB_BUFFER_SIZE - 1; - buffer = (TEXT*) str_buffer->str_data; + TEXT* buffer = (TEXT*) str_buffer->str_data; - request = (BLK) CMP_find_request(tdbb, irq_l_security, IRQ_REQUESTS); + BLK request = (BLK) CMP_find_request(tdbb, irq_l_security, IRQ_REQUESTS); FOR(REQUEST_HANDLE request) X IN RDB$SECURITY_CLASSES WITH X.RDB$SECURITY_CLASS EQ s_class->scl_name @@ -1118,8 +1104,8 @@ static SLONG compute_access(TDBB tdbb, privileges |= SCL_exists; blob = BLB_open(tdbb, dbb->dbb_sys_trans, (BID) & X.RDB$ACL); - acl = buffer; - while (TRUE) + TEXT* acl = buffer; + while (true) { acl += BLB_get_segment(tdbb, blob, (UCHAR*)acl, (USHORT) (length - @@ -1141,6 +1127,7 @@ static SLONG compute_access(TDBB tdbb, } } BLB_close(tdbb, blob); + blob = NULL; if (acl != buffer) { // TMN: The cast is really a const_cast to @@ -1163,6 +1150,7 @@ static SLONG compute_access(TDBB tdbb, } catch (const std::exception&) { delete str_buffer; + // CVC: we may need to call BLB_close here Firebird::status_exception::raise(tdbb->tdbb_status_vector[1]); } @@ -1183,12 +1171,11 @@ static TEXT *save_string(TEXT* string, TEXT** ptr) * pointer. * **************************************/ - TEXT *p, *start; - if (!*string) return NULL; - start = p = *ptr; + TEXT* p = *ptr; + TEXT* const start = p; while ( (*p++ = *string++) ) ; @@ -1443,3 +1430,4 @@ static SLONG walk_acl(TDBB tdbb, return privilege; } + diff --git a/src/jrd/scl_proto.h b/src/jrd/scl_proto.h index 19f4547a95..39f20fae74 100644 --- a/src/jrd/scl_proto.h +++ b/src/jrd/scl_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _JRD_SCL_PROTO_H_ -#define _JRD_SCL_PROTO_H_ +#ifndef JRD_SCL_PROTO_H +#define JRD_SCL_PROTO_H #ifdef __cplusplus extern "C" { @@ -44,4 +44,5 @@ void SCL_check_index(TDBB, TEXT*, UCHAR, USHORT); } /* extern "C" */ #endif -#endif /* _JRD_SCL_PROTO_H_ */ +#endif /* JRD_SCL_PROTO_H */ + diff --git a/src/jrd/svc.cpp b/src/jrd/svc.cpp index eba115c26a..23c7105003 100644 --- a/src/jrd/svc.cpp +++ b/src/jrd/svc.cpp @@ -152,16 +152,16 @@ static inline void is_service_running(SVC service) if (!(service->svc_flags & SVC_forked)) { THREAD_ENTER; ERR_post (isc_svcnoexe, isc_arg_string, - service->svc_service->serv_name, 0); + service->svc_service->serv_name, 0); } } -static inline void need_admin_privs(ISC_STATUS **status, char* message) +static inline void need_admin_privs(ISC_STATUS** status, const char* message) { - ISC_STATUS *stat = *status; + ISC_STATUS* stat = *status; *stat++ = isc_insufficient_svc_privileges; *stat++ = isc_arg_string; - *stat++ = (ISC_STATUS) ERR_string(message,strlen(message)); + *stat++ = (ISC_STATUS) ERR_string(message, strlen(message)); *stat++ = isc_arg_end; *status = stat; } diff --git a/src/jrd/utl.cpp b/src/jrd/utl.cpp index 5dce41b1bc..68c4ea9c24 100644 --- a/src/jrd/utl.cpp +++ b/src/jrd/utl.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Access Method - * MODULE: utl.c + * MODULE: utl.cpp * DESCRIPTION: User callable routines * * The contents of this file are subject to the Interbase Public diff --git a/src/qli/all.cpp b/src/qli/all.cpp index d0c9a2a8e2..56a5587964 100644 --- a/src/qli/all.cpp +++ b/src/qli/all.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: all.c + * MODULE: all.cpp * DESCRIPTION: Internal block allocator * * The contents of this file are subject to the Interbase Public @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: all.cpp,v 1.20 2003-09-19 10:26:46 aafemt Exp $ +$Id: all.cpp,v 1.21 2003-09-25 11:49:07 robocop Exp $ */ /*************************************************** @@ -68,7 +68,7 @@ static struct { static void extend_pool(PLB, USHORT); -static VEC pools; +static VEC global_pools; #define MIN_ALLOCATION 1024 @@ -86,18 +86,15 @@ BLK ALLQ_alloc( PLB pool, UCHAR type, int count) * This is the primary block allocation routine. * **************************************/ - FRB block; FRB free, *best, *ptr; - USHORT l; - USHORT size; SLONG best_tail, tail; if (type <= (SCHAR) type_MIN || type >= (SCHAR) type_MAX) - BUGCHECK(1); // Msg1 bad block type + BUGCHECK(1); // Msg1 bad block type -// Compute block length +// Compute block length - size = block_sizes[type].typ_root_length; + USHORT size = block_sizes[type].typ_root_length; if (tail = block_sizes[type].typ_tail_length) size += count * tail; @@ -109,7 +106,7 @@ BLK ALLQ_alloc( PLB pool, UCHAR type, int count) #endif if (size <= 4 || size > 65535) - BUGCHECK(2); // Msg2 bad block size + BUGCHECK(2); // Msg2 bad block size /* Find best fit. Best fit is defined to be the free block of SHORTest tail. If there isn't a fit, extend the pool and try, try again. */ @@ -118,11 +115,11 @@ BLK ALLQ_alloc( PLB pool, UCHAR type, int count) best = NULL; best_tail = 32767; for (ptr = &pool->plb_free; (free = *ptr); ptr = &free->frb_next) - if (free->frb_next - && (SCHAR *) free >= - (SCHAR *) free->frb_next) BUGCHECK(434); // memory pool free list is incorrect + if (free->frb_next && (SCHAR *) free >= (SCHAR *) free->frb_next) + BUGCHECK(434); // memory pool free list is incorrect else if ((tail = free->frb_header.blk_length - size) >= 0 - && tail < best_tail) { + && tail < best_tail) + { best = ptr; best_tail = tail; if (tail == 0) @@ -138,8 +135,9 @@ BLK ALLQ_alloc( PLB pool, UCHAR type, int count) the entire free block as our block (a little extra won't hurt). */ free = *best; + FRB block; if (best_tail > sizeof(frb)) { - l = free->frb_header.blk_length - size; + USHORT l = free->frb_header.blk_length - size; block = (FRB) ((SCHAR *) free + l); free->frb_header.blk_length -= size; } @@ -172,15 +170,12 @@ BLK ALLQ_extend(BLK * pointer, int size) * Extend a repeating block, copying the constant part. * **************************************/ - BLK block, new_blk; - int length; - - block = *pointer; - new_blk = (BLK) ALLQ_alloc((PLB) pools->vec_object[block->blk_pool_id], + BLK block = *pointer; + BLK new_blk = (BLK) ALLQ_alloc((PLB) global_pools->vec_object[block->blk_pool_id], block->blk_type, size); - length = MIN(block->blk_length, new_blk->blk_length) - sizeof(blk); - MOVQ_fast((SCHAR *) block + sizeof(blk), - (SCHAR *) new_blk + sizeof(blk), length); + const int length = MIN(block->blk_length, new_blk->blk_length) - sizeof(blk); + MOVQ_fast((SCHAR*) block + sizeof(blk), + (SCHAR*) new_blk + sizeof(blk), length); ALLQ_release((FRB) block); if (new_blk->blk_type == (SCHAR) type_vec) @@ -206,16 +201,20 @@ void ALLQ_fini(void) * Get rid of everything. * **************************************/ - PLB pool, *vector, *until; - HNK hunks, hunk; - - for (vector = (PLB *) pools->vec_object + pools->vec_count, - until = (PLB *) pools->vec_object; --vector >= until;) - if (pool = *vector) + PLB* vector = (PLB*) global_pools->vec_object + global_pools->vec_count; + PLB* until = (PLB*) global_pools->vec_object; + while (--vector >= until) + { + PLB pool = *vector; + if (pool) + { + HNK hunks, hunk; for (hunks = pool->plb_hunks; hunk = hunks;) { hunks = hunk->hnk_next; ALLQ_free(hunk->hnk_address); } + } + } } @@ -249,16 +248,16 @@ void ALLQ_init(void) * **************************************/ ISC_STATUS_ARRAY temp_vector; - PLB pool; - pools = (VEC) temp_vector; - pools->vec_count = 1; - pools->vec_object[0] = NULL; + global_pools = (VEC) temp_vector; + global_pools->vec_count = 1; + global_pools->vec_object[0] = NULL; - QLI_default_pool = QLI_permanent_pool = pool = ALLQ_pool(); - pools = (VEC) ALLQ_alloc(pool, type_vec, 10); - pools->vec_count = 10; - pools->vec_object[0] = (BLK) pool; + PLB pool = ALLQ_pool(); + QLI_default_pool = QLI_permanent_pool = pool; + global_pools = (VEC) ALLQ_alloc(pool, type_vec, 10); + global_pools->vec_count = 10; + global_pools->vec_object[0] = (BLK) pool; } @@ -274,16 +273,16 @@ SCHAR *ALLQ_malloc(SLONG size) * Get memory from system. * **************************************/ - SCHAR *memory; + SCHAR *memory = (SCHAR*) gds__alloc(size); - if (memory = (SCHAR *) gds__alloc(size)) { + if (memory) { #ifdef DEBUG_GDS_ALLOC - gds_alloc_flag_unfreed((void *) memory); /* Don't care about QLI leaks */ + gds_alloc_flag_unfreed((void *) memory); // Don't care about QLI leaks #endif return memory; } - IBERROR(5); /* Msg5 "memory gonzo" */ + IBERROR(5); // Msg5 "memory gonzo" return 0; } @@ -302,31 +301,30 @@ PLB ALLQ_pool(void) * In SHORT, by mirrors. * **************************************/ - plb temp_pool; - PLB pool; int pool_id; -// Start by assigning a pool id +// Start by assigning a pool id - for (pool_id = 0; pool_id < pools->vec_count; pool_id++) - if (!(pools->vec_object[pool_id])) + for (pool_id = 0; pool_id < global_pools->vec_count; pool_id++) + if (!(global_pools->vec_object[pool_id])) break; - if (pool_id >= pools->vec_count) - ALLQ_extend((BLK*) &pools, pool_id + 10); + if (pool_id >= global_pools->vec_count) + ALLQ_extend((BLK*) &global_pools, pool_id + 10); - pools->vec_object[pool_id] = (BLK) & temp_pool; + plb temp_pool; + global_pools->vec_object[pool_id] = (BLK) &temp_pool; temp_pool.plb_free = NULL; temp_pool.plb_hunks = NULL; temp_pool.plb_pool_id = pool_id; if (pool_id == 0) QLI_permanent_pool = &temp_pool; - pool = (PLB) ALLQ_alloc(&temp_pool, type_plb, 0); + PLB pool = (PLB) ALLQ_alloc(&temp_pool, type_plb, 0); pool->plb_pool_id = pool_id; pool->plb_free = temp_pool.plb_free; pool->plb_hunks = temp_pool.plb_hunks; - pools->vec_object[pool_id] = (BLK) pool; + global_pools->vec_object[pool_id] = (BLK) pool; if (pool_id == 0) QLI_permanent_pool = pool; @@ -347,12 +345,10 @@ void ALLQ_push( BLK object, LLS * stack) * Push an object on an LLS stack. * **************************************/ - LLS node; - PLB pool; + PLB pool = QLI_default_pool; - pool = QLI_default_pool; - - if (node = pool->plb_lls) + LLS node = pool->plb_lls; + if (node) pool->plb_lls = node->lls_next; else node = (LLS) ALLQ_alloc(pool, type_lls, 0); @@ -376,11 +372,8 @@ BLK ALLQ_pop(LLS * stack) * further use. * **************************************/ - LLS node; - PLB pool; - - node = *stack; - pool = (PLB) pools->vec_object[node->lls_header.blk_pool_id]; + LLS node = *stack; + PLB pool = (PLB) global_pools->vec_object[node->lls_header.blk_pool_id]; *stack = node->lls_next; node->lls_next = pool->plb_lls; pool->plb_lls = node; @@ -404,18 +397,21 @@ void ALLQ_release( FRB block) * of addresses). * **************************************/ - FRB prior, free; - FRB *ptr; PLB pool; - int pool_id; block->frb_header.blk_type = (SCHAR) type_frb; - pool_id = block->frb_header.blk_pool_id; + int pool_id = block->frb_header.blk_pool_id; - if (pool_id >= pools->vec_count || - !(pool = (PLB) pools->vec_object[pool_id])) BUGCHECK(4); // Msg4 bad pool id + if (pool_id >= global_pools->vec_count || + !(pool = (PLB) global_pools->vec_object[pool_id])) + { + BUGCHECK(4); + // Msg4 bad pool id + } - prior = NULL; + FRB prior = NULL; + FRB free; + FRB* ptr; for (ptr = &pool->plb_free; free = *ptr; prior = free, ptr = &free->frb_next) { @@ -424,14 +420,14 @@ void ALLQ_release( FRB block) } if ((SCHAR *) block == (SCHAR *) free) - BUGCHECK(435); // block released twice + BUGCHECK(435); // block released twice -// Merge block into list first, then try to combine blocks +// Merge block into list first, then try to combine blocks block->frb_next = free; *ptr = block; -// Try to merge the free block with the next one down. +// Try to merge the free block with the next one down. if (free) { if ((SCHAR *) block + block->frb_header.blk_length == @@ -441,10 +437,10 @@ void ALLQ_release( FRB block) } else if ((SCHAR *) block + block->frb_header.blk_length > (SCHAR *) free) - BUGCHECK(436); // released block overlaps following free block + BUGCHECK(436); // released block overlaps following free block } -// Try and merge the block with the prior free block +// Try and merge the block with the prior free block if (prior) { if ((SCHAR *) prior + prior->frb_header.blk_length == @@ -454,7 +450,7 @@ void ALLQ_release( FRB block) } else if ((SCHAR *) prior + prior->frb_header.blk_length > (SCHAR *) block) - BUGCHECK(437); // released block overlaps prior free block + BUGCHECK(437); // released block overlaps prior free block } } @@ -474,7 +470,7 @@ void ALLQ_rlpool( PLB pool) **************************************/ HNK hunk, hunks; - pools->vec_object[pool->plb_pool_id] = NULL; + global_pools->vec_object[pool->plb_pool_id] = NULL; for (hunks = pool->plb_hunks; hunk = hunks;) { hunks = hunk->hnk_next; @@ -496,24 +492,23 @@ static void extend_pool( PLB pool, USHORT count) * of given size. * **************************************/ - HNK hunk; - BLK block; - SLONG size; - - size = (count + sizeof(hnk) + MIN_ALLOCATION - 1) & ~(MIN_ALLOCATION - 1); + SLONG size = + (count + sizeof(hnk) + MIN_ALLOCATION - 1) & ~(MIN_ALLOCATION - 1); if ((USHORT) size < count) - IBERROR(481); // msg 481 unsuccessful attempt to extend pool beyond 64KB + IBERROR(481); // msg 481 unsuccessful attempt to extend pool beyond 64KB - block = (BLK) ALLQ_malloc(size); + BLK block = (BLK) ALLQ_malloc(size); block->blk_length = size; block->blk_type = (SCHAR) type_frb; block->blk_pool_id = pool->plb_pool_id; ALLQ_release((FRB) block); - hunk = (HNK) ALLQ_alloc(pool, type_hnk, 0); + HNK hunk = (HNK) ALLQ_alloc(pool, type_hnk, 0); hunk->hnk_address = (SCHAR *) block; hunk->hnk_length = size; hunk->hnk_next = pool->plb_hunks; pool->plb_hunks = hunk; } + + diff --git a/src/qli/all_proto.h b/src/qli/all_proto.h index 94d0bf986a..8bc21ac272 100644 --- a/src/qli/all_proto.h +++ b/src/qli/all_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_ALL_PROTO_H_ -#define _QLI_ALL_PROTO_H_ +#ifndef QLI_ALL_PROTO_H +#define QLI_ALL_PROTO_H extern blk* ALLQ_alloc(plb*, UCHAR, int); extern blk* ALLQ_extend(blk**, int); @@ -36,4 +36,5 @@ extern blk* ALLQ_pop(lls**); extern void ALLQ_release(frb*); extern void ALLQ_rlpool(plb*); -#endif /* _QLI_ALL_PROTO_H_ */ +#endif /* QLI_ALL_PROTO_H */ + diff --git a/src/qli/blk.h b/src/qli/blk.h index bcafaaa766..14db54c12a 100644 --- a/src/qli/blk.h +++ b/src/qli/blk.h @@ -47,7 +47,7 @@ BLKDEF (type_brk, brk, 0) BLKDEF (type_rpt, rpt, 0) BLKDEF (type_pic, pics, 0) BLKDEF (type_prt, prt, 0) -BLKDEF (type_map, map, 0) +BLKDEF (type_map, qli_map, 0) BLKDEF (type_qpr, qpr, 0) BLKDEF (type_qfn, qfn, 0) BLKDEF (type_qfl, qfl, 0) diff --git a/src/qli/comma_proto.h b/src/qli/comma_proto.h index 20263f1f3e..36aeff4cd5 100644 --- a/src/qli/comma_proto.h +++ b/src/qli/comma_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_COMMA_PROTO_H_ -#define _QLI_COMMA_PROTO_H_ +#ifndef QLI_COMMA_PROTO_H +#define QLI_COMMA_PROTO_H extern int CMD_check_ready(void); extern void CMD_copy_procedure(syn*); @@ -36,4 +36,4 @@ extern void CMD_set(syn*); extern void CMD_shell(syn*); extern void CMD_transaction(syn*); -#endif /* _QLI_COMMA_PROTO_H_ */ +#endif /* QLI_COMMA_PROTO_H */ diff --git a/src/qli/command.cpp b/src/qli/command.cpp index bbb1d7c30a..404ab7ae7c 100644 --- a/src/qli/command.cpp +++ b/src/qli/command.cpp @@ -60,7 +60,7 @@ int CMD_check_ready(void) ************************************** * * Functional description - * Make sure at least one database is ready. If not, give a + * Make sure at least one database is ready. If not, give a * message. * **************************************/ @@ -68,7 +68,7 @@ int CMD_check_ready(void) if (QLI_databases) return FALSE; - ERRQ_msg_put(95, NULL, NULL, NULL, NULL, NULL); // Msg95 No databases are currently ready + ERRQ_msg_put(95, NULL, NULL, NULL, NULL, NULL); // Msg95 No databases are currently ready return TRUE; } @@ -83,7 +83,7 @@ void CMD_copy_procedure( SYN node) ************************************** * * Functional description - * Copy one procedure to another, possibly + * Copy one procedure to another, possibly * across databases * **************************************/ @@ -140,7 +140,7 @@ void CMD_delete_proc( SYN node) if (PRO_delete_procedure(proc->qpr_database, proc->qpr_name->nam_string)) return; - ERRQ_msg_put(88, proc->qpr_name->nam_string, /* Msg88 Procedure %s not found in database %s */ + ERRQ_msg_put(88, proc->qpr_name->nam_string, // Msg88 Procedure %s not found in database %s proc->qpr_database->dbb_symbol->sym_string, NULL, NULL, NULL); } @@ -194,7 +194,7 @@ void CMD_extract( SYN node) database = QLI_databases; name = proc->qpr_name; if (!(blob = PRO_fetch_procedure(database, name->nam_string))) { - ERRQ_msg_put(89, /* Msg89 Procedure %s not found in database %s */ + ERRQ_msg_put(89, // Msg89 Procedure %s not found in database %s name->nam_string, database->dbb_symbol->sym_string, NULL, NULL, NULL); @@ -264,14 +264,14 @@ void CMD_rename_proc( SYN node) database = QLI_databases; if (new_proc->qpr_database && (new_proc->qpr_database != database)) - IBERROR(84); // Msg84 Procedures can not be renamed across databases. Try COPY + IBERROR(84); // Msg84 Procedures can not be renamed across databases. Try COPY NAM old_name = old_proc->qpr_name; NAM new_name = new_proc->qpr_name; if (PRO_rename_procedure (database, old_name->nam_string, new_name->nam_string)) return; - ERRQ_error(85, /* Msg85 Procedure %s not found in database %s */ + ERRQ_error(85, // Msg85 Procedure %s not found in database %s old_name->nam_string, database->dbb_symbol->sym_string, NULL, NULL, NULL); } @@ -325,7 +325,7 @@ void CMD_set( SYN node) break; case set_form: - IBERROR(484); // FORMs not supported + IBERROR(484); // FORMs not supported break; case set_password: @@ -340,7 +340,7 @@ void CMD_set( SYN node) case set_prompt: string = (CON) value; if (string->con_desc.dsc_length > sizeof(QLI_prompt_string)) - ERRQ_error(86, NULL, NULL, NULL, NULL, NULL); // Msg86 substitute prompt string too long + ERRQ_error(86, NULL, NULL, NULL, NULL, NULL); // Msg86 substitute prompt string too long strncpy(QLI_prompt_string, (char*) string->con_data, string->con_desc.dsc_length); QLI_prompt_string[string->con_desc.dsc_length] = 0; @@ -349,7 +349,7 @@ void CMD_set( SYN node) case set_continuation: string = (CON) value; if (string->con_desc.dsc_length > sizeof(QLI_cont_string)) - ERRQ_error(87, NULL, NULL, NULL, NULL, NULL); // Msg87 substitute prompt string too long + ERRQ_error(87, NULL, NULL, NULL, NULL, NULL); // Msg87 substitute prompt string too long strncpy(QLI_cont_string, (char*) string->con_data, string->con_desc.dsc_length); QLI_cont_string[string->con_desc.dsc_length] = 0; @@ -409,7 +409,7 @@ void CMD_set( SYN node) #endif default: - BUGCHECK(6); // Msg6 set option not implemented + BUGCHECK(6); // Msg6 set option not implemented } } } @@ -431,16 +431,16 @@ void CMD_shell( SYN node) USHORT l; CON constant; -// Copy command, inserting extra blank at end. +// Copy command, inserting extra blank at end. TEXT* p = buffer; if (constant = (CON) node->syn_arg[0]) { const TEXT* q = (TEXT*) constant->con_data; if (l = constant->con_desc.dsc_length) - do + do { *p++ = *q++; - while (--l); + } while (--l); *p++ = ' '; *p = 0; } @@ -465,13 +465,13 @@ void CMD_shell( SYN node) int return_status = 0; int mask = 1; int status = lib$spawn(ptr, // Command to be executed - NULL, // Command file - NULL, // Output file + NULL, // Command file + NULL, // Output file &mask, // sub-process characteristics mask NULL, // sub-process name - NULL, // returned process id - &return_status, // completion status - &15); // event flag for completion + NULL, // returned process id + &return_status, // completion status + &15); // event flag for completion if (status & 1) while (!return_status) sys$waitfr(15); @@ -602,3 +602,4 @@ static void extract_procedure( dump_procedure(database, file, name, length, blob); } + diff --git a/src/qli/compile.cpp b/src/qli/compile.cpp index 3f28b1d751..0a0d17069d 100644 --- a/src/qli/compile.cpp +++ b/src/qli/compile.cpp @@ -132,7 +132,7 @@ int CMP_node_match( QLI_NOD node1, QLI_NOD node2) * **************************************/ QLI_NOD *ptr1, *ptr2, *end; - MAP map1, map2; + QLI_MAP map1, map2; USHORT l; UCHAR *p1, *p2; @@ -158,17 +158,17 @@ int CMP_node_match( QLI_NOD node1, QLI_NOD node2) p1 = node1->nod_desc.dsc_address; p2 = node2->nod_desc.dsc_address; if (l = node1->nod_desc.dsc_length) - do + do { if (*p1++ != *p2++) return FALSE; - while (--l); + } while (--l); return TRUE; } case nod_map: { - map1 = (MAP) node1->nod_arg[e_map_map]; - map2 = (MAP) node2->nod_arg[e_map_map]; + map1 = (QLI_MAP) node1->nod_arg[e_map_map]; + map2 = (QLI_MAP) node2->nod_arg[e_map_map]; return CMP_node_match(map1->map_node, map2->map_node); } @@ -238,7 +238,7 @@ static QLI_NOD compile_any( QLI_NOD node, QLI_REQ old_request, int internal_flag } if (old_request && request->req_database != old_request->req_database) - IBERROR(357); // Msg357 relations from multiple databases in single rse + IBERROR(357); // Msg357 relations from multiple databases in single rse if (old_request && (!receive || !receive->msg_parameters)) { if (receive) @@ -275,7 +275,7 @@ static QLI_NOD compile_assignment( QLI_NOD node, QLI_REQ request, int statement_ * the logic of such things, the 'internal' flags * mean external to qli, but internal to jrd. * As is well known, the seat of the soul is the - * dbms). + * dbms). * **************************************/ QLI_NOD target, initial; @@ -310,7 +310,7 @@ static QLI_NOD compile_assignment( QLI_NOD node, QLI_REQ request, int statement_ compile_expression(initial, request, FALSE); if (statement_internal) { - node->nod_arg[e_asn_valid] = NULL; // Memory reclaimed in the main loop + node->nod_arg[e_asn_valid] = NULL; // Memory reclaimed in the main loop node->nod_flags |= NOD_remote; node = NULL; } @@ -412,14 +412,14 @@ static QLI_NOD compile_edit( QLI_NOD node, QLI_REQ request) can't find the target database. */ if (!request) - BUGCHECK(358); /* Msg358 can't find database for blob edit */ + BUGCHECK(358); // Msg358 can't find database for blob edit -// If there is an input blob, get it now. +// If there is an input blob, get it now. if (value = node->nod_arg[e_edt_input]) { QLI_FLD field = (QLI_FLD) value->nod_arg[e_fld_field]; if (value->nod_type != nod_field || field->fld_dtype != dtype_blob) - IBERROR(356); // Msg356 EDIT argument must be a blob field + IBERROR(356); // Msg356 EDIT argument must be a blob field node->nod_arg[e_edt_input] = compile_expression(value, request, FALSE); } @@ -475,11 +475,11 @@ static QLI_NOD compile_expression( QLI_NOD node, QLI_REQ request, int internal_f * Functional description * Compile a value. The value may be used internally as part of * another expression (internal_flag == TRUE) or may be referenced - * in the QLI context (internal_flag == FALSE). + * in the QLI context (internal_flag == FALSE). * **************************************/ QLI_NOD *ptr, *end, value; - MAP map; + QLI_MAP map; PAR parm; QLI_FLD field; @@ -544,7 +544,7 @@ static QLI_NOD compile_expression( QLI_NOD node, QLI_REQ request, int internal_f return node; case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + map = (QLI_MAP) node->nod_arg[e_map_map]; map->map_node = value = compile_expression(map->map_node, request, TRUE); make_descriptor(value, &node->nod_desc); @@ -664,7 +664,7 @@ static QLI_NOD compile_expression( QLI_NOD node, QLI_REQ request, int internal_f return node; default: - BUGCHECK(359); // Msg359 compile_expression: not yet implemented + BUGCHECK(359); // Msg359 compile_expression: not yet implemented return NULL; } } @@ -832,7 +832,7 @@ static QLI_NOD compile_function( QLI_NOD node, QLI_REQ old_request, int internal else request = old_request; -// If there is a value, compile it here +// If there is a value, compile it here if (!internal_flag) { node->nod_import = parameter = @@ -1058,7 +1058,7 @@ static QLI_NOD compile_prompt( QLI_NOD node) QLI_FLD field; USHORT prompt_length; -// Make up a plausible prompt length +// Make up a plausible prompt length if (!(field = (QLI_FLD) node->nod_arg[e_prm_field])) prompt_length = PROMPT_LENGTH; @@ -1086,7 +1086,7 @@ static QLI_NOD compile_prompt( QLI_NOD node) break; } -/* Allocate string buffer to hold data, a two byte count, +/* Allocate string buffer to hold data, a two byte count, a possible carriage return, and a null */ prompt_length += 2 + sizeof(SSHORT); @@ -1202,7 +1202,7 @@ static QLI_REQ compile_rse( database = &local_dbb; } -// Loop thru relations to make sure only a single database is presented +// Loop thru relations to make sure only a single database is presented QLI_CTX* ctx_ptr = (QLI_CTX*) node->nod_arg + e_rse_count; QLI_CTX* ctx_end = ctx_ptr + node->nod_count; @@ -1220,7 +1220,7 @@ static QLI_REQ compile_rse( if (!*database) *database = relation->rel_database; else if (*database != relation->rel_database) - IBERROR(357); // Msg357 relations from multiple databases in single rse + IBERROR(357); // Msg357 relations from multiple databases in single rse } } @@ -1240,7 +1240,7 @@ static QLI_REQ compile_rse( compile_context(node, request, internal_flag); -// Process various clauses +// Process various clauses if (node->nod_arg[e_rse_first]) compile_expression(node->nod_arg[e_rse_first], request, TRUE); @@ -1266,7 +1266,7 @@ static QLI_REQ compile_rse( if (node->nod_arg[e_rse_having]) compile_expression(node->nod_arg[e_rse_having], request, TRUE); -/* If we didn't allocate a new request block, say so by returning NULL */ +// If we didn't allocate a new request block, say so by returning NULL if (request == original_request) return NULL; @@ -1393,7 +1393,7 @@ static QLI_NOD compile_statistical( QLI_NOD node, QLI_REQ old_request, int inter else request = old_request; -// If there is a value, compile it here +// If there is a value, compile it here if (!internal_flag) { node->nod_import = parameter = @@ -1440,7 +1440,7 @@ static QLI_NOD compile_store( QLI_NOD node, QLI_REQ request, int internal_flag) **************************************/ QLI_MSG send; -// Find or make up request for statement +// Find or make up request for statement QLI_CTX context = (QLI_CTX) node->nod_arg[e_sto_context]; QLI_REL relation = context->ctx_relation; @@ -1491,7 +1491,7 @@ static int computable( QLI_NOD node, QLI_REQ request) **************************************/ QLI_NOD *ptr, *end, sub; QLI_CTX context; - MAP map; + QLI_MAP map; switch (node->nod_type) { case nod_max: @@ -1538,7 +1538,7 @@ static int computable( QLI_NOD node, QLI_REQ request) return (request == context->ctx_request); case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + map = (QLI_MAP) node->nod_arg[e_map_map]; return computable(map->map_node, request); case nod_print: @@ -1608,7 +1608,7 @@ static int computable( QLI_NOD node, QLI_REQ request) if (node->nod_arg[e_asn_valid]) { sub = node->nod_arg[e_asn_from]; if (sub->nod_type == nod_prompt) - /* Try to do validation in QLI as soon as + /* Try to do validation in QLI as soon as the user responds to the prompt */ return FALSE; } @@ -1646,7 +1646,7 @@ static int computable( QLI_NOD node, QLI_REQ request) return TRUE; default: - BUGCHECK(361); // Msg361 computable: not yet implemented + BUGCHECK(361); // Msg361 computable: not yet implemented return FALSE; } } @@ -1667,7 +1667,7 @@ static void make_descriptor( QLI_NOD node, DSC * desc) DSC desc1, desc2; QLI_FLD field; PAR parameter; - MAP map; + QLI_MAP map; FUN function; USHORT dtype; @@ -1695,7 +1695,7 @@ static void make_descriptor( QLI_NOD node, DSC * desc) return; case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + map = (QLI_MAP) node->nod_arg[e_map_map]; make_descriptor(map->map_node, desc); return; @@ -1846,7 +1846,7 @@ static void make_descriptor( QLI_NOD node, DSC * desc) case nod_substr: default: - BUGCHECK(362); // Msg362 make_descriptor: not yet implemented + BUGCHECK(362); // Msg362 make_descriptor: not yet implemented } } @@ -1933,11 +1933,11 @@ static QLI_NOD make_reference( QLI_NOD node, QLI_MSG message) ************************************** * * Functional description - * Make a reference to a value to be computed in the + * Make a reference to a value to be computed in the * database context. Since a field can be referenced * several times, construct reference blocks linking * the single field to the single parameter. (I think.) - * In any event, if a parameter for a field exists, + * In any event, if a parameter for a field exists, * use it rather than generating an new one. Make it * parameter2 style if necessary. * @@ -1945,15 +1945,15 @@ static QLI_NOD make_reference( QLI_NOD node, QLI_MSG message) PAR parm; if (!message) - BUGCHECK(363); // Msg363 missing message + BUGCHECK(363); // Msg363 missing message -// Look for an existing field reference +// Look for an existing field reference for (parm = message->msg_parameters; parm; parm = parm->par_next) if (CMP_node_match(parm->par_value, node)) break; -/* Parameter doesn't exits -- make a new one. */ +// Parameter doesn't exits -- make a new one. if (!parm) { parm = make_parameter(message, node); @@ -2019,7 +2019,7 @@ static void release_message( QLI_MSG message) break; if (!*ptr) - BUGCHECK(364); // Msg 364 lost message + BUGCHECK(364); // Msg 364 lost message *ptr = message->msg_next; ALL_release((FRB) message); @@ -2042,3 +2042,4 @@ static int string_length(const dsc* desc) return DSC_string_length(desc); } + diff --git a/src/qli/compile.h b/src/qli/compile.h index c1c9e8abf3..d37f828925 100644 --- a/src/qli/compile.h +++ b/src/qli/compile.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_COMPILE_H_ -#define _QLI_COMPILE_H_ +#ifndef QLI_COMPILE_H +#define QLI_COMPILE_H /* Name nodes -- used to hold names between parse and compilation */ @@ -252,4 +252,4 @@ enum set_t { #define s_dfi_flag_order 32 #define s_dfi_flag_statistics 64 -#endif /* _QLI_COMPILE_H_ */ +#endif /* QLI_COMPILE_H */ diff --git a/src/qli/dtr.cpp b/src/qli/dtr.cpp index 2686240093..b35253bdf0 100644 --- a/src/qli/dtr.cpp +++ b/src/qli/dtr.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: dtr.c + * MODULE: dtr.cpp * DESCRIPTION: Top level driving module * * The contents of this file are subject to the Interbase Public @@ -77,7 +77,7 @@ bool sw_trace; USHORT sw_buffers; USHORT QLI_lines = 60, QLI_prompt_count, QLI_reprompt, QLI_name_columns = 0; -/* Let's define the default number of columns on a machine by machine basis */ +// Let's define the default number of columns on a machine by machine basis #ifdef VMS USHORT QLI_columns = 80; @@ -252,7 +252,7 @@ int CLIB_ROUTINE main( int argc, char **argv) break; default: - ERRQ_msg_put(469, (TEXT *) c, NULL, NULL, NULL, NULL); /* Msg469 qli: ignoring unknown switch %c */ + ERRQ_msg_put(469, (TEXT *) c, NULL, NULL, NULL, NULL); // Msg469 qli: ignoring unknown switch %c break; } } @@ -263,7 +263,7 @@ int CLIB_ROUTINE main( int argc, char **argv) ERRQ_msg_put(24, NULL, NULL, NULL, NULL, NULL); // Msg24 Welcome to QLI Query Language Interpreter if (version_flag) - ERRQ_msg_put(25, GDS_VERSION, NULL, NULL, NULL, NULL); /* Msg25 qli version %s */ + ERRQ_msg_put(25, GDS_VERSION, NULL, NULL, NULL, NULL); // Msg25 qli version %s if (application_file) LEX_push_file(application_file, true); @@ -476,8 +476,8 @@ static bool process_statement(bool flush_flag) dbb->dbb_statistics = (int *) gds__alloc((SLONG) sizeof(PERF)); #ifdef DEBUG_GDS_ALLOC - /* We don't care about QLI specific memory leaks for V4.0 */ - gds_alloc_flag_unfreed((void *) dbb->dbb_statistics); /* QLI: don't care */ + // We don't care about QLI specific memory leaks for V4.0 + gds_alloc_flag_unfreed((void *) dbb->dbb_statistics); // QLI: don't care #endif } perf_get_info(&dbb->dbb_handle, (perf *)dbb->dbb_statistics); @@ -500,7 +500,7 @@ static bool process_statement(bool flush_flag) perf_get_info(&dbb->dbb_handle, &statistics); perf_format((perf*) dbb->dbb_statistics, &statistics, report, buffer, 0); - ERRQ_msg_put(26, dbb->dbb_filename, buffer, NULL, NULL, NULL); /* Msg26 Statistics for database %s %s */ + ERRQ_msg_put(26, dbb->dbb_filename, buffer, NULL, NULL, NULL); // Msg26 Statistics for database %s %s QLI_skip_line = TRUE; } } @@ -534,6 +534,11 @@ static void CLIB_ROUTINE signal_arith_excp(USHORT sig, USHORT code, USHORT scp) **************************************/ USHORT msg_number; +#if defined(FPE_INOVF_TRAP) || defined(FPE_INTDIV_TRAP) + || defined(FPE_FLTOVF_TRAP) || defined(FPE_FLTDIV_TRAP) + || defined(FPE_FLTUND_TRAP) || defined(FPE_FLTOVF_FAULT) + || defined(FPE_FLTUND_FAULT) + switch (code) { #ifdef FPE_INOVF_TRAP case FPE_INTOVF_TRAP: @@ -580,6 +585,9 @@ static void CLIB_ROUTINE signal_arith_excp(USHORT sig, USHORT code, USHORT scp) default: msg_number = 21; // Msg21 arithmetic exception } +#else + msg_number = 21; +#endif signal(SIGFPE, (void(*)(int)) signal_arith_excp); diff --git a/src/qli/dtr.h b/src/qli/dtr.h index 9f0e8fe984..8fff5a9949 100644 --- a/src/qli/dtr.h +++ b/src/qli/dtr.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_DTR_H_ -#define _QLI_DTR_H_ +#ifndef QLI_DTR_H +#define QLI_DTR_H #include "../jrd/common.h" #include "../jrd/dsc.h" @@ -501,4 +501,4 @@ EXTERN USHORT QLI_interp; #include "../qli/all_proto.h" -#endif /* _QLI_DTR_H_ */ +#endif /* QLI_DTR_H */ diff --git a/src/qli/err.cpp b/src/qli/err.cpp index 2fd731a44a..862659eb9e 100644 --- a/src/qli/err.cpp +++ b/src/qli/err.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: err.c + * MODULE: err.cpp * DESCRIPTION: Error handlers * * The contents of this file are subject to the Interbase Public @@ -58,11 +58,11 @@ void ERRQ_bugcheck( USHORT number) TEXT s[256]; ERRQ_msg_format(number, sizeof(s), s, NULL, NULL, NULL, NULL, NULL); - ERRQ_error(9, s, NULL, NULL, NULL, NULL); /* Msg9 INTERNAL: %s */ + ERRQ_error(9, s, NULL, NULL, NULL, NULL); // Msg9 INTERNAL: %s } -void ERRQ_database_error( DBB dbb, ISC_STATUS * status_vector) +void ERRQ_database_error( DBB dbb, ISC_STATUS* status_vector) { /************************************** * @@ -101,8 +101,11 @@ void ERRQ_database_error( DBB dbb, ISC_STATUS * status_vector) void ERRQ_error( USHORT number, - TEXT * arg1, - TEXT * arg2, TEXT * arg3, TEXT * arg4, TEXT * arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -131,8 +134,11 @@ void ERRQ_error( void ERRQ_error_format( USHORT number, - TEXT * arg1, - TEXT * arg2, TEXT * arg3, TEXT * arg4, TEXT * arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -150,7 +156,8 @@ void ERRQ_error_format( gds__msg_format(0, QLI_MSG_FAC, number, sizeof(s), s, arg1, arg2, arg3, arg4, arg5); gds__msg_format(0, QLI_MSG_FAC, 12, sizeof(ERRQ_message), - ERRQ_message, s, NULL, NULL, NULL, NULL); /* Msg12 ** QLI error: %s ** */ + ERRQ_message, s, NULL, NULL, NULL, NULL); + /* Msg12 ** QLI error: %s ** */ QLI_error = (TEXT*) ERRQ_message; QLI_skip_line = TRUE; } @@ -178,9 +185,12 @@ void ERRQ_exit( int status) void ERRQ_msg_format( USHORT number, USHORT length, - TEXT * string, - TEXT * arg1, - TEXT * arg2, TEXT * arg3, TEXT * arg4, TEXT * arg5) + TEXT* output_string, + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -193,18 +203,18 @@ void ERRQ_msg_format( * **************************************/ - gds__msg_format(0, QLI_MSG_FAC, number, length, string, arg1, arg2, arg3, - arg4, arg5); + gds__msg_format(0, QLI_MSG_FAC, number, length, output_string, + arg1, arg2, arg3, arg4, arg5); } void ERRQ_msg_partial( USHORT number, - const TEXT * arg1, - const TEXT * arg2, - const TEXT * arg3, - const TEXT * arg4, - const TEXT * arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -225,11 +235,11 @@ void ERRQ_msg_partial( void ERRQ_msg_put( USHORT number, - const TEXT * arg1, - const TEXT * arg2, - const TEXT * arg3, - const TEXT * arg4, - const TEXT * arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -249,7 +259,7 @@ void ERRQ_msg_put( } -int ERRQ_msg_get( USHORT number, TEXT * msg) +int ERRQ_msg_get( USHORT number, TEXT* output_msg) { /************************************** * @@ -261,12 +271,12 @@ int ERRQ_msg_get( USHORT number, TEXT * msg) * Retrieve a message from the error file * **************************************/ - SSHORT l; TEXT buffer[128]; - l = gds__msg_format(0, QLI_MSG_FAC, number, sizeof(buffer), buffer, + const SSHORT l = gds__msg_format(0, QLI_MSG_FAC, number, + sizeof(buffer), buffer, NULL, NULL, NULL, NULL, NULL); - strcpy(msg, buffer); + strcpy(output_msg, buffer); return (l >= 0); } @@ -294,8 +304,11 @@ void ERRQ_pending(void) void ERRQ_print_error( USHORT number, - TEXT * arg1, - TEXT * arg2, TEXT * arg3, TEXT * arg4, TEXT * arg5) + const TEXT* arg1, + const TEXT* arg2, + const TEXT* arg3, + const TEXT* arg4, + const TEXT* arg5) { /************************************** * @@ -329,5 +342,8 @@ void ERRQ_syntax( USHORT number) TEXT s[256]; ERRQ_msg_format(number, sizeof(s), s, NULL, NULL, NULL, NULL, NULL); - ERRQ_error(13, s, QLI_token->tok_string, NULL, NULL, NULL); /* Msg13 expected %s, encountered %s */ + ERRQ_error(13, s, QLI_token->tok_string, NULL, NULL, NULL); + // Msg13 expected %s, encountered %s } + + diff --git a/src/qli/err_proto.h b/src/qli/err_proto.h index 8a152ff574..2e417f2960 100644 --- a/src/qli/err_proto.h +++ b/src/qli/err_proto.h @@ -1,7 +1,7 @@ /* * PROGRAM: JRD Command Oriented Query Language * MODULE: err_proto.h - * DESCRIPTION: Prototype header file for err.c + * DESCRIPTION: Prototype header file for err.cpp * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file @@ -26,17 +26,21 @@ extern void ERRQ_bugcheck (USHORT); extern void ERRQ_database_error(dbb*, ISC_STATUS*); -extern void ERRQ_error (USHORT, TEXT *, TEXT *, TEXT *, TEXT *, TEXT *); -extern void ERRQ_error_format (USHORT, TEXT *, TEXT *, TEXT *, TEXT *, TEXT *); +extern void ERRQ_error (USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); +extern void ERRQ_error_format (USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); extern void ERRQ_exit (int); -extern void ERRQ_msg_format (USHORT, USHORT, TEXT *, TEXT *, TEXT *, TEXT *, TEXT *, TEXT *); -extern int ERRQ_msg_get (USHORT, TEXT *); -extern void ERRQ_msg_partial (USHORT, const TEXT *, const TEXT *, const TEXT *, - const TEXT *, const TEXT *); -extern void ERRQ_msg_put (USHORT, const TEXT *, const TEXT *, const TEXT *, - const TEXT *, const TEXT *); +extern void ERRQ_msg_format (USHORT, USHORT, TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*, const TEXT*); +extern int ERRQ_msg_get (USHORT, TEXT*); +extern void ERRQ_msg_partial (USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); +extern void ERRQ_msg_put (USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); extern void ERRQ_pending (void); -extern void ERRQ_print_error (USHORT, TEXT *, TEXT *, TEXT *, TEXT *, TEXT *); +extern void ERRQ_print_error (USHORT, const TEXT*, const TEXT*, const TEXT*, + const TEXT*, const TEXT*); extern void ERRQ_syntax (USHORT); #endif /* QLI_ERR_PROTO_H */ diff --git a/src/qli/eval.cpp b/src/qli/eval.cpp index c84bf29d21..eca23b2fd7 100644 --- a/src/qli/eval.cpp +++ b/src/qli/eval.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: eval.c + * MODULE: eval.cpp * DESCRIPTION: Value and boolean expression evaluator * * The contents of this file are subject to the Interbase Public @@ -177,7 +177,7 @@ int EVAL_boolean( QLI_NOD node) return result; default: - BUGCHECK(28); // Msg28 EVAL_boolean: not finished + BUGCHECK(28); // Msg28 EVAL_boolean: not finished return FALSE; } } @@ -223,7 +223,7 @@ void EVAL_break_increment( QLI_NOD node) DSC* desc1 = &node->nod_desc; -// Knock off count as trivial +// Knock off count as trivial if (node->nod_type == nod_rpt_count) { *(SLONG *) node->nod_desc.dsc_address += 1; @@ -236,7 +236,7 @@ void EVAL_break_increment( QLI_NOD node) if (!(desc2 = EVAL_value(node->nod_arg[e_stt_value]))) return; -// If this is the first value, just move it in. +// If this is the first value, just move it in. SLONG count = (SLONG) node->nod_arg[e_stt_default] + 1; if (count == 1) { @@ -255,10 +255,10 @@ void EVAL_break_increment( QLI_NOD node) node->nod_arg[e_stt_default] = (QLI_NOD) (SLONG) count; desc1->dsc_missing = FALSE; -// Finish off as per operator +// Finish off as per operator SSHORT comparison; - + switch (node->nod_type) { case nod_rpt_min: case nod_rpt_max: @@ -485,14 +485,14 @@ DSC *EVAL_value(QLI_NOD node) break; default: - IBERROR(30); // Msg30 data type not supported for arithmetic + IBERROR(30); // Msg30 data type not supported for arithmetic } return desc; case nod_prompt: if (!prompt[0][0]) { - ERRQ_msg_get(499, prompt[0]); // Msg499 Re-enter - ERRQ_msg_get(500, prompt[1]); // Msg500 Enter + ERRQ_msg_get(499, prompt[0]); // Msg499 Re-enter + ERRQ_msg_get(500, prompt[1]); // Msg500 Enter } return execute_prompt(node); @@ -533,7 +533,7 @@ DSC *EVAL_value(QLI_NOD node) desc->dsc_length = p - desc->dsc_address; return desc; case nod_user_name: - IBERROR(31); // Msg31 user name is supported only in RSEs temporarily + IBERROR(31); // Msg31 user name is supported only in RSEs temporarily case nod_parameter: case nod_position: @@ -543,7 +543,7 @@ DSC *EVAL_value(QLI_NOD node) case nod_via: default: - BUGCHECK(29); // Msg29 EVAL_value: not finished + BUGCHECK(29); // Msg29 EVAL_value: not finished return NULL; } } @@ -605,14 +605,14 @@ static DSC *execute_concatenate( QLI_NOD node, DSC * value1, DSC * value2) length2 = MAX(MIN(length2, desc->dsc_length - 2 - length1), 0); if (length1) - do + do { *p++ = *address1++; - while (--length1); + } while (--length1); if (length2) - do + do { *p++ = *address2++; - while (--length2); + } while (--length2); vary->vary_length = p - vary->vary_string; @@ -725,9 +725,9 @@ static DSC *execute_prompt( QLI_NOD node) } else { if (reprompt) - sprintf(string, "\07%s: ", prompt[0]); // Msg497 Re-enter + sprintf(string, "\07%s: ", prompt[0]); // Msg497 Re-enter else - sprintf(string, "%s: ", prompt[1]); // Msg498 Enter + sprintf(string, "%s: ", prompt[1]); // Msg498 Enter } if (!LEX_get_line(string, value, length)) { @@ -742,7 +742,7 @@ static DSC *execute_prompt( QLI_NOD node) if (p > value && p[-1] == '\n') *--p = 0; - // Get rid of trailing blanks on non-text data types + // Get rid of trailing blanks on non-text data types if (desc->dsc_dtype > dtype_varying) { while (p > value && p[-1] == ' ') @@ -759,7 +759,7 @@ static DSC *execute_prompt( QLI_NOD node) return desc; } - ERRQ_msg_put(32, NULL, NULL, NULL, NULL, NULL); // Msg32 Input value is too long + ERRQ_msg_put(32, NULL, NULL, NULL, NULL, NULL); // Msg32 Input value is too long reprompt = TRUE; } } @@ -861,8 +861,8 @@ static TEXT *make_blob_buffer( FRBRD * blob, USHORT * length) *length = max_segment; buffer = (TEXT *) gds__alloc((SLONG) * length); #ifdef DEBUG_GDS_ALLOC - /* We don't care about QLI specific memory leaks for V4.0 */ - gds_alloc_flag_unfreed((void *) buffer); /* QLI: don't care */ + // We don't care about QLI specific memory leaks for V4.0 + gds_alloc_flag_unfreed((void *) buffer); // QLI: don't care #endif return buffer; } @@ -934,22 +934,22 @@ static int sleuth( QLI_NOD node, DSC * desc1, DSC * desc2, DSC * desc3) l1 = MOVQ_get_string(desc3, &p1, (VARY*) temp1, TEMP_LENGTH); -// Get address and length of search string +// Get address and length of search string l2 = MOVQ_get_string(desc2, &p2, (VARY*) temp2, TEMP_LENGTH); -// Merge search and control strings +// Merge search and control strings l2 = sleuth_merge((UCHAR*) p2, (UCHAR*) (p2 + l2), (UCHAR*) p1, (UCHAR*) (p1 + l1), (UCHAR*) control); -// If source is not a blob, do a simple search +// If source is not a blob, do a simple search if (desc1->dsc_dtype != dtype_blob) { l1 = MOVQ_get_string(desc1, &p1, (VARY*) temp1, TEMP_LENGTH); return sleuth_check(0, (UCHAR*) p1, (UCHAR*) (p1 + l1), (UCHAR*) control, (UCHAR*) (control + l2)); } -// Source string is a blob, things get interesting +// Source string is a blob, things get interesting result = FALSE; @@ -1142,9 +1142,9 @@ static int sleuth_merge( * * Functional description * Merge the matching pattern and control strings to give a cannonical - * matching pattern. Return the length of the combined string. + * matching pattern. Return the length of the combined string. * - * What this routine does is to take the language template, strip off + * What this routine does is to take the language template, strip off * the prefix and put it in the output string, then parse the definitions * into an array of character pointers. The index array is the defined * character. The routine then takes the actual match pattern and uses @@ -1163,7 +1163,7 @@ static int sleuth_merge( v = vector; t = temp; -// Parse control string into substitution strings and initializing string +// Parse control string into substitution strings and initializing string while (control < end_control) { c = *control++; @@ -1192,19 +1192,19 @@ static int sleuth_merge( max_op = v - vector; -// Interpret matching string, substituting where appropriate +// Interpret matching string, substituting where appropriate while (c = *match++) { - /* if we've got a defined character, slurp the definition */ + // if we've got a defined character, slurp the definition if (c <= max_op && (p = vector[c])) { while (*p) *comb++ = *p++; - /* if we've got the definition of a quote character, slurp the next character too */ + // if we've got the definition of a quote character, slurp the next character too if (comb[-1] == '@' && *match) *comb++ = *match++; } - /* at this point we've got a non-match, but as it might be one of ours, quote it. */ + // at this point we've got a non-match, but as it might be one of ours, quote it. else { if (special[c] && comb[-1] != '@') *comb++ = '@'; @@ -1212,7 +1212,7 @@ static int sleuth_merge( } } -// Put in trailing stuff +// Put in trailing stuff while (control < end_control) *comb++ = *control++; @@ -1258,18 +1258,18 @@ static int string_boolean( QLI_NOD node) if (node->nod_type == nod_sleuth) return sleuth(node, desc1, desc2, desc3); -// Get address and length of strings +// Get address and length of strings l2 = MOVQ_get_string(desc2, &p2, (VARY*) temp2, TEMP_LENGTH); -// If source is not a blob, do a simple search +// If source is not a blob, do a simple search if (desc1->dsc_dtype != dtype_blob) { l1 = MOVQ_get_string(desc1, &p1, (VARY*) temp1, TEMP_LENGTH); return string_function(node, l1, p1, l2, p2) ? TRUE : FALSE; } -// Source string is a blob, things get interesting +// Source string is a blob, things get interesting result = FALSE; blob = EXEC_open_blob(node->nod_arg[0]); @@ -1279,7 +1279,7 @@ static int string_boolean( QLI_NOD node) if (!(buffer = make_blob_buffer( blob, &buffer_length))) buffer = fixed_buffer; - while (!gds__get_segment(status_vector, &blob, (USHORT*) &l1, + while (!gds__get_segment(status_vector, &blob, (USHORT*) &l1, buffer_length, buffer)) { if (string_function(node, l1, buffer, l2, p2)) { @@ -1320,7 +1320,7 @@ static bool string_function( TEXT *q1, *q2, c1, c2, temp[16]; SSHORT l; -/* Handle "STARTS WITH" */ +// Handle "STARTS WITH" if (node->nod_type == nod_starts) { if (l1 < l2) @@ -1331,7 +1331,7 @@ static bool string_function( return true; } -// Handle CONTAINS +// Handle CONTAINS if (node->nod_type == nod_containing) { while (l1 >= l2) { @@ -1349,7 +1349,7 @@ static bool string_function( return false; } -// Handle LIKE +// Handle LIKE if (node->nod_type == nod_like) { c1 = 0; @@ -1364,7 +1364,7 @@ static bool string_function( return false; } -// Handle MATCHES +// Handle MATCHES if (node->nod_type == nod_matches) if (matches(p1, l1, p2, l2)) @@ -1373,3 +1373,4 @@ static bool string_function( return false; } + diff --git a/src/qli/eval_proto.h b/src/qli/eval_proto.h index f78e0a173c..a3399809cc 100644 --- a/src/qli/eval_proto.h +++ b/src/qli/eval_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_EVAL_PROTO_H_ -#define _QLI_EVAL_PROTO_H_ +#ifndef QLI_EVAL_PROTO_H +#define QLI_EVAL_PROTO_H extern int EVAL_boolean (struct qli_nod *); extern void EVAL_break_compute (struct qli_nod *); @@ -31,4 +31,4 @@ extern void EVAL_break_init (struct qli_nod *); extern struct dsc *EVAL_parameter (struct par *); extern struct dsc *EVAL_value (struct qli_nod *); -#endif /* _QLI_EVAL_PROTO_H_ */ +#endif /* QLI_EVAL_PROTO_H */ diff --git a/src/qli/exe.cpp b/src/qli/exe.cpp index 06e53699e7..54cba63d13 100644 --- a/src/qli/exe.cpp +++ b/src/qli/exe.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: exe.c + * MODULE: exe.cpp * DESCRIPTION: Execution phase * * The contents of this file are subject to the Interbase Public @@ -64,7 +64,7 @@ extern USHORT QLI_prompt_count, QLI_reprompt; static DSC *assignment(QLI_NOD, DSC *, QLI_NOD, QLI_NOD, PAR); static void commit_retaining(QLI_NOD); -static int copy_blob(QLI_NOD, PAR); +static bool copy_blob(QLI_NOD, PAR); static void db_error(QLI_REQ, ISC_STATUS *); static void execute_abort(QLI_NOD); static void execute_assignment(QLI_NOD); @@ -79,7 +79,7 @@ static void print_counts(QLI_REQ); static void set_null(QLI_MSG); static void transaction_state(QLI_NOD, DBB); -// definitions for SET COUNT +// definitions for SET COUNT #define COUNT_ITEMS 4 @@ -105,9 +105,8 @@ void EXEC_abort(void) * **************************************/ ISC_STATUS_ARRAY status_vector; - QLI_REQ request; - for (request = QLI_requests; request; request = request->req_next) + for (QLI_REQ request = QLI_requests; request; request = request->req_next) if (request->req_handle) gds__unwind_request(status_vector, &request->req_handle, 0); @@ -197,7 +196,7 @@ void EXEC_execute( QLI_NOD node) return; default: - BUGCHECK(33); // Msg33 EXEC_execute: not implemented + BUGCHECK(33); // Msg33 EXEC_execute: not implemented } } @@ -214,35 +213,26 @@ FRBRD *EXEC_open_blob( QLI_NOD node) * Given a blob field node, open and return the blob. * **************************************/ - QLI_CTX context; - QLI_REQ request; - DBB dbb; - DSC *desc; - UCHAR bpb[20], *p; - USHORT bpb_length; - FRBRD *blob; - ISC_STATUS_ARRAY status_vector; - - desc = EVAL_value(node); + dsc* desc = EVAL_value(node); if (!desc) return FALSE; -// Starting from the print item, work our way back to the database block +// Starting from the print item, work our way back to the database block if (node->nod_type == nod_reference) node = node->nod_arg[0]; if (node->nod_type != nod_field) - BUGCHECK(34); // Msg34 print_blob: expected field node + BUGCHECK(34); // Msg34 print_blob: expected field node - context = (QLI_CTX) node->nod_arg[e_fld_context]; - request = context->ctx_request; - dbb = request->req_database; - blob = NULL; + QLI_CTX context = (QLI_CTX) node->nod_arg[e_fld_context]; + QLI_REQ request = context->ctx_request; + DBB dbb = request->req_database; + FRBRD* blob = NULL; -// Format blob parameter block - - p = bpb; +// Format blob parameter block + UCHAR bpb[20]; + UCHAR* p = bpb; *p++ = gds_bpb_version1; *p++ = gds_bpb_source_type; *p++ = 2; @@ -252,11 +242,12 @@ FRBRD *EXEC_open_blob( QLI_NOD node) *p++ = 1; *p++ = 1; - bpb_length = p - bpb; + const USHORT bpb_length = p - bpb; + ISC_STATUS_ARRAY status_vector; if (gds__open_blob2(status_vector, &dbb->dbb_handle, &dbb->dbb_transaction, &blob, (GDS_QUAD*) desc->dsc_address, bpb_length, - (char*) bpb)) + (char*) bpb)) ERRQ_database_error(dbb, status_vector); return blob; @@ -275,47 +266,45 @@ file* EXEC_open_output(QLI_NOD node) * Open output stream to re-direct output. * **************************************/ - IB_FILE *out_file; - DSC *desc; - TEXT filename[256], temp[64], *p, *q; -#ifndef WIN_NT - TEXT *argv[20], **arg; - int pair[2]; -#endif - SSHORT l; +// Evaluate filename and copy to a null terminated string -// Evaluate filename and copy to a null terminated string + dsc* desc = EVAL_value(node->nod_arg[e_out_file]); + TEXT* p = NULL; + TEXT temp[64]; + SSHORT l = MOVQ_get_string(desc, &p, (VARY*) temp, sizeof(temp)); - desc = EVAL_value(node->nod_arg[e_out_file]); - l = MOVQ_get_string(desc, &p, (VARY*) temp, sizeof(temp)); - q = filename; + TEXT filename[256]; + TEXT* q = filename; if (l) - do + do { *q++ = *p++; - while (--l); + } while (--l); *q = 0; -// If output is to a file, just do it +// If output is to a file, just do it if (!node->nod_arg[e_out_pipe]) { - if (out_file = ib_fopen(filename, FOPEN_WRITE_TYPE)) - return (file*)out_file; + IB_FILE* out_file = ib_fopen(filename, FOPEN_WRITE_TYPE); + if (out_file) + return (file*) out_file; ERRQ_print_error(42, filename, NULL, NULL, NULL, NULL); - /* Msg42 Can't open output file %s */ + // Msg42 Can't open output file %s } -// Output is to a file. Setup file and fork process +// Output is to a file. Setup file and fork process #ifdef VMS - IBERROR(35); // Msg35 output pipe is not supported on VMS + IBERROR(35); // Msg35 output pipe is not supported on VMS #else #ifdef WIN_NT - if (out_file = _popen(filename, "w")) - return (file*)out_file; + IB_FILE* out_file = _popen(filename, "w"); + if (out_file) + return (file*) out_file; #else - arg = argv; + TEXT* argv[20]; + TEXT** arg = argv; p = filename; while (*p) { *arg++ = p; @@ -329,8 +318,9 @@ file* EXEC_open_output(QLI_NOD node) } *arg = NULL; + int pair[2]; if (pipe(pair) < 0) - IBERROR(36); /* Msg36 couldn't create pipe */ + IBERROR(36); // Msg36 couldn't create pipe if (!vfork()) { close(pair[1]); @@ -338,17 +328,17 @@ file* EXEC_open_output(QLI_NOD node) dup(pair[0]); close(pair[0]); execvp(argv[0], argv); - ERRQ_msg_put(43, filename, NULL, NULL, NULL, NULL); /* Msg43 Couldn't run %s */ + ERRQ_msg_put(43, filename, NULL, NULL, NULL, NULL); // Msg43 Couldn't run %s _exit(-1); } close(pair[0]); if (out_file = ib_fdopen(pair[1], "w")) - return (file*)out_file; + return (file*) out_file; #endif - IBERROR(37); // Msg37 ib_fdopen failed + IBERROR(37); // Msg37 ib_fdopen failed #endif return NULL; } @@ -371,7 +361,7 @@ void EXEC_poll_abort(void) if (!QLI_abort) return; - IBERROR(38); // Msg38 execution terminated by signal + IBERROR(38); // Msg38 execution terminated by signal } @@ -387,13 +377,12 @@ DSC *EXEC_receive(QLI_MSG message, PAR parameter) * Receive a message from a running request. * **************************************/ - QLI_REQ request; ISC_STATUS_ARRAY status_vector; - request = message->msg_request; + QLI_REQ request = message->msg_request; if (gds__receive(status_vector, &request->req_handle, message->msg_number, - message->msg_length, message->msg_buffer, 0)) + message->msg_length, message->msg_buffer, 0)) db_error(request, status_vector); if (!parameter) @@ -416,10 +405,9 @@ void EXEC_send( QLI_MSG message) * any data to the message. * **************************************/ - QLI_REQ request; ISC_STATUS_ARRAY status_vector; - request = message->msg_request; + QLI_REQ request = message->msg_request; map_data(message); if (gds__send(status_vector, &request->req_handle, message->msg_number, @@ -448,12 +436,12 @@ void EXEC_start_request( QLI_REQ request, QLI_MSG message) if (!gds__start_and_send(status_vector, &request->req_handle, &request->req_database-> dbb_transaction, message->msg_number, message->msg_length, - message->msg_buffer, 0)) + message->msg_buffer, 0)) return; } else if (!gds__start_request(status_vector, &request->req_handle, - &request->req_database-> dbb_transaction, 0)) + &request->req_database-> dbb_transaction, 0)) return; db_error(request, status_vector); @@ -494,17 +482,15 @@ static DSC *assignment( QLI_NOD from_node, * goes wrong and there was a prompt, try again. * **************************************/ - DSC *from_desc; - UCHAR *p; - QLI_MSG message; - USHORT l, *missing_flag, trash; jmp_buf old_env; memcpy(old_env, QLI_env, sizeof(QLI_env)); QLI_reprompt = FALSE; QLI_prompt_count = 0; - missing_flag = &trash; + USHORT trash; + USHORT* missing_flag = &trash; + QLI_MSG message = NULL; if (parameter) { message = parameter->par_message; missing_flag = @@ -514,7 +500,7 @@ static DSC *assignment( QLI_NOD from_node, try { memcpy(QLI_env, old_env, sizeof(QLI_env)); - from_desc = EVAL_value(from_node); + dsc* from_desc = EVAL_value(from_node); if (from_desc->dsc_missing & DSC_initial) { from_desc = EVAL_value(initial); @@ -523,8 +509,9 @@ static DSC *assignment( QLI_NOD from_node, /* If there is a value present, do any assignment; otherwise null fill */ if (*missing_flag = to_desc->dsc_missing = from_desc->dsc_missing) { - p = from_desc->dsc_address; - if (l = from_desc->dsc_length) { + UCHAR* p = from_desc->dsc_address; + USHORT l = from_desc->dsc_length; + if (l) { do { *p++ = 0; } while (--l); @@ -535,7 +522,7 @@ static DSC *assignment( QLI_NOD from_node, } if (validation && EVAL_boolean(validation) <= 0) { - IBERROR(39); // Msg39 field validation error + IBERROR(39); // Msg39 field validation error } QLI_reprompt = FALSE; @@ -567,12 +554,11 @@ static void commit_retaining( QLI_NOD node) * * Functional description * Execute commit retaining statement for - * one or more named databases or all databases. + * one or more named databases or all databases. * If there's more than one, prepare it. * **************************************/ DBB database; - QLI_NOD *ptr, *end; /* If there aren't any open databases then obviously there isn't anything to commit. */ @@ -582,7 +568,8 @@ static void commit_retaining( QLI_NOD node) if (node->nod_type == nod_commit_retaining && ((node->nod_count > 1) || - (node->nod_count == 0 && QLI_databases->dbb_next))) { + (node->nod_count == 0 && QLI_databases->dbb_next))) + { node->nod_type = nod_prepare; commit_retaining(node); node->nod_type = nod_commit_retaining; @@ -600,8 +587,10 @@ static void commit_retaining( QLI_NOD node) database = database->dbb_next) { if ((node->nod_type == nod_commit_retaining) && !(database->dbb_flags & DBB_prepared)) + { ERRQ_msg_put(465, database->dbb_symbol->sym_string, NULL, NULL, NULL, NULL); + } else if (node->nod_type == nod_prepare) database->dbb_flags |= DBB_prepared; if (database->dbb_transaction) @@ -610,12 +599,15 @@ static void commit_retaining( QLI_NOD node) return; } - for (ptr = node->nod_arg, end = ptr + node->nod_count; ptr < end; ptr++) { - database = (DBB) * ptr; + QLI_NOD* ptr = node->nod_arg; + for (QLI_NOD* const end = ptr + node->nod_count; ptr < end; ptr++) { + database = (DBB) *ptr; if ((node->nod_type == nod_commit_retaining) && !(database->dbb_flags & DBB_prepared)) + { ERRQ_msg_put(465, database->dbb_symbol->sym_string, NULL, NULL, NULL, NULL); + } else if (node->nod_type == nod_prepare) database->dbb_flags |= DBB_prepared; if (database->dbb_transaction) @@ -625,7 +617,7 @@ static void commit_retaining( QLI_NOD node) -static int copy_blob( QLI_NOD value, PAR parameter) +static bool copy_blob( QLI_NOD value, PAR parameter) { /************************************** * @@ -639,52 +631,47 @@ static int copy_blob( QLI_NOD value, PAR parameter) * copy the blob ids. * **************************************/ - QLI_CTX context; - QLI_MSG message; - QLI_REQ from_request, to_request; - DBB to_dbb, from_dbb; - DSC *from_desc, *to_desc; - FRBRD *from_blob, *to_blob; - SLONG size, segment_count, max_segment; - ISC_STATUS_ARRAY status_vector; - USHORT bpb_length, length, buffer_length; - UCHAR bpb[20], *p, fixed_buffer[4096], *buffer; /* If assignment isn't from a field, there isn't a blob copy, so do a dumb assignment. */ if (value->nod_type != nod_field) - return FALSE; + return false; /* Find the sending and receiving requests. If they are the same and no filtering is necessary, a simple assignment will suffice. */ - context = (QLI_CTX) value->nod_arg[e_fld_context]; - from_request = context->ctx_request; - from_dbb = from_request->req_database; - message = parameter->par_message; - to_request = message->msg_request; - to_dbb = to_request->req_database; + QLI_CTX context = (QLI_CTX) value->nod_arg[e_fld_context]; + QLI_REQ from_request = context->ctx_request; + DBB from_dbb = from_request->req_database; + QLI_MSG message = parameter->par_message; + QLI_REQ to_request = message->msg_request; + DBB to_dbb = to_request->req_database; - from_desc = EVAL_value(value); - to_desc = EVAL_parameter(parameter); + dsc* from_desc = EVAL_value(value); + dsc* to_desc = EVAL_parameter(parameter); if (to_dbb == from_dbb && (!to_desc->dsc_sub_type || - from_desc->dsc_sub_type == to_desc->dsc_sub_type)) return FALSE; + from_desc->dsc_sub_type == to_desc->dsc_sub_type)) + { + return false; + } -/* We've got a blob copy on our hands. */ +// We've got a blob copy on our hands. if (!from_desc) { *to_desc->dsc_address = 0; - return TRUE; + return true; } - to_blob = from_blob = NULL; + FRBRD* to_blob = NULL; + FRBRD* from_blob = NULL; -// Format blob parameter block for the existing blob +// Format blob parameter block for the existing blob - p = bpb; + UCHAR bpb[20]; + UCHAR* p = bpb; *p++ = gds_bpb_version1; *p++ = gds_bpb_source_type; *p++ = 2; @@ -694,40 +681,51 @@ static int copy_blob( QLI_NOD value, PAR parameter) *p++ = 2; *p++ = to_desc->dsc_sub_type; *p++ = to_desc->dsc_sub_type >> 8; - bpb_length = p - bpb; + const USHORT bpb_length = p - bpb; + ISC_STATUS_ARRAY status_vector; if (gds__create_blob(status_vector, &to_dbb->dbb_handle, &to_dbb->dbb_transaction, &to_blob, (GDS__QUAD*) to_desc->dsc_address)) + { ERRQ_database_error(to_dbb, status_vector); + } if (gds__open_blob2(status_vector, &from_dbb->dbb_handle, &from_dbb->dbb_transaction, &from_blob, (GDS__QUAD*) from_desc->dsc_address, bpb_length, - (char*) bpb)) + (char*) bpb)) + { ERRQ_database_error(from_dbb, status_vector); + } + SLONG size, segment_count, max_segment; gds__blob_size(&from_blob, &size, &segment_count, &max_segment); + UCHAR fixed_buffer[4096]; + UCHAR* buffer; + USHORT buffer_length; if (max_segment < (SLONG) sizeof(fixed_buffer)) { buffer_length = sizeof(fixed_buffer); buffer = fixed_buffer; } - else { + else + { buffer_length = max_segment; buffer = (UCHAR*) gds__alloc(buffer_length); #ifdef DEBUG_GDS_ALLOC - /* We don't care about QLI specific memory leaks for V4.0 */ - gds_alloc_flag_unfreed((void *) buffer); /* QLI: don't care */ + // We don't care about QLI specific memory leaks for V4.0 + gds_alloc_flag_unfreed((void *) buffer); // QLI: don't care #endif - } + USHORT length; while (!gds__get_segment(status_vector, &from_blob, &length, buffer_length, (char*) buffer)) - if (gds__put_segment(status_vector, &to_blob, length, - (char*) buffer)) - ERRQ_database_error(to_dbb, status_vector); + { + if (gds__put_segment(status_vector, &to_blob, length, (char*) buffer)) + ERRQ_database_error(to_dbb, status_vector); + } if (buffer != fixed_buffer) gds__free(buffer); @@ -738,7 +736,7 @@ static int copy_blob( QLI_NOD value, PAR parameter) if (gds__close_blob(status_vector, &to_blob)) ERRQ_database_error(to_dbb, status_vector); - return TRUE; + return true; } @@ -773,19 +771,20 @@ static void execute_abort( QLI_NOD node) * Abort a statement. * **************************************/ - USHORT l; - UCHAR *ptr, temp[80], msg[128]; - if (node->nod_count) { - l = - MOVQ_get_string(EVAL_value(node->nod_arg[0]), (TEXT**) &ptr, (VARY*) temp, - sizeof(temp)); + UCHAR* ptr = NULL; + UCHAR temp[80]; + USHORT l = + MOVQ_get_string(EVAL_value(node->nod_arg[0]), (TEXT**) &ptr, + (VARY*) temp, sizeof(temp)); + + UCHAR msg[128]; MOVQ_terminate((SCHAR*) ptr, (SCHAR*) msg, l, sizeof(msg)); ERRQ_error(40, (TEXT*) msg, NULL, NULL, NULL, NULL); - /* Msg40 Request terminated by statement: %s */ + // Msg40 Request terminated by statement: %s } - IBERROR(41); // Msg41 Request terminated by statement + IBERROR(41); // Msg41 Request terminated by statement } @@ -800,23 +799,23 @@ static void execute_assignment( QLI_NOD node) * Functional description * **************************************/ - QLI_NOD to, from, reference, initial; - QLI_FLD field; - PAR parameter; - if (node->nod_flags & NOD_remote) return; - to = node->nod_arg[e_asn_to]; - from = node->nod_arg[e_asn_from]; - initial = node->nod_arg[e_asn_initial]; + QLI_NOD to = node->nod_arg[e_asn_to]; + QLI_NOD from = node->nod_arg[e_asn_from]; + QLI_NOD initial = node->nod_arg[e_asn_initial]; + PAR parameter; if (to->nod_type == nod_field) { - reference = to->nod_arg[e_fld_reference]; + QLI_NOD reference = to->nod_arg[e_fld_reference]; parameter = reference->nod_import; if (to->nod_desc.dsc_dtype == dtype_blob && from->nod_desc.dsc_dtype == dtype_blob && - copy_blob(from, parameter)) return; + copy_blob(from, parameter)) + { + return; + } } else parameter = node->nod_import; @@ -827,10 +826,10 @@ static void execute_assignment( QLI_NOD node) assignment(from, EVAL_value(to), node->nod_arg[e_asn_valid], initial, parameter); -// propagate the missing flag in variable assignments +// propagate the missing flag in variable assignments if (to->nod_type == nod_variable) { - field = (QLI_FLD) to->nod_arg[e_fld_field]; + QLI_FLD field = (QLI_FLD) to->nod_arg[e_fld_field]; if (to->nod_desc.dsc_missing & DSC_missing) field->fld_flags |= FLD_missing; else @@ -854,29 +853,31 @@ static void execute_for( QLI_NOD node) * absolutely nothing to do. * **************************************/ - QLI_REQ request; - QLI_MSG message; - DSC *desc; /* If there is a request associated with the node, start it and possibly send a message along with it. */ - if (request = (QLI_REQ) node->nod_arg[e_for_request]) + QLI_REQ request = (QLI_REQ) node->nod_arg[e_for_request]; + if (request) EXEC_start_request(request, (QLI_MSG) node->nod_arg[e_for_send]); - else if (message = (QLI_MSG) node->nod_arg[e_for_send]) - EXEC_send(message); + else { + QLI_MSG amessage = (QLI_MSG) node->nod_arg[e_for_send]; + if (amessage) + EXEC_send(amessage); + } /* If there isn't a receive message, the body of the loop has been optimized out of existance. So skip it. */ - if (!(message = (QLI_MSG) node->nod_arg[e_for_receive])) + QLI_MSG message = (QLI_MSG) node->nod_arg[e_for_receive]; + if (!message) goto count; /* Receive messages in a loop until the end of file field comes up true. */ while (true) { - desc = EXEC_receive(message, (PAR) node->nod_arg[e_for_eof]); + dsc* desc = EXEC_receive(message, (PAR) node->nod_arg[e_for_eof]); if (*(USHORT *) desc->dsc_address) break; EXEC_execute(node->nod_arg[e_for_statement]); @@ -903,13 +904,11 @@ static void execute_modify( QLI_NOD node) * message to the running request and executing a sub-statement. * **************************************/ - QLI_MSG message; - - if (node->nod_flags & NOD_remote) return; - if (message = (QLI_MSG) node->nod_arg[e_mod_send]) + QLI_MSG message = (QLI_MSG) node->nod_arg[e_mod_send]; + if (message) set_null(message); EXEC_execute(node->nod_arg[e_mod_statement]); @@ -931,21 +930,20 @@ static void execute_output( QLI_NOD node) * Open output stream to re-direct output. * **************************************/ - PRT print; jmp_buf old_env; jmp_buf env; - print = (PRT) node->nod_arg[e_out_print]; + PRT print = (PRT) node->nod_arg[e_out_print]; print->prt_file = EXEC_open_output(node); -// Set up error handling +// Set up error handling memcpy(old_env, QLI_env, sizeof(QLI_env)); memcpy(QLI_env, env, sizeof(QLI_env)); try { -// Finally, execute the query +// Finally, execute the query EXEC_execute(node->nod_arg[e_out_statement]); memcpy(QLI_env, old_env, sizeof(QLI_env)); @@ -989,7 +987,7 @@ static void execute_repeat( QLI_NOD node) { /************************************** * - * e x e c u t e _ r e p e a t + * e x e c u t e _ r e p e a t * ************************************** * @@ -997,9 +995,7 @@ static void execute_repeat( QLI_NOD node) * Execute a REPEAT statement. In short, loop. * **************************************/ - SLONG count; - - count = MOVQ_get_long(EVAL_value(node->nod_arg[e_rpt_value]), 0); + SLONG count = MOVQ_get_long(EVAL_value(node->nod_arg[e_rpt_value]), 0); while (--count >= 0) EXEC_execute(node->nod_arg[e_rpt_statement]); @@ -1022,10 +1018,8 @@ static void execute_store( QLI_NOD node) * here. * **************************************/ - QLI_REQ request; - QLI_MSG message; - - if (message = (QLI_MSG) node->nod_arg[e_sto_send]) + QLI_MSG message = (QLI_MSG) node->nod_arg[e_sto_send]; + if (message) set_null(message); if (!(node->nod_flags & NOD_remote)) @@ -1034,7 +1028,8 @@ static void execute_store( QLI_NOD node) /* If there is a request associated with the node, start it and possibly send a message along with it. */ - if (request = (QLI_REQ) node->nod_arg[e_sto_request]) + QLI_REQ request = (QLI_REQ) node->nod_arg[e_sto_request]; + if (request) EXEC_start_request(request, (QLI_MSG) node->nod_arg[e_sto_send]); else if (message) EXEC_send(message); @@ -1056,22 +1051,19 @@ static void map_data( QLI_MSG message) * Map data to a message in preparation for sending. * **************************************/ - PAR parameter, missing_parameter; - QLI_NOD from; - DSC *desc; - USHORT *missing_flag; - - for (parameter = message->msg_parameters; parameter; - parameter = parameter->par_next) { - desc = ¶meter->par_desc; + for (PAR parameter = message->msg_parameters; parameter; + parameter = parameter->par_next) + { + dsc* desc = ¶meter->par_desc; desc->dsc_address = message->msg_buffer + parameter->par_offset; - if (missing_parameter = parameter->par_missing) { - missing_flag = (USHORT *) (message->msg_buffer + + PAR missing_parameter = parameter->par_missing; + if (missing_parameter) { + USHORT* missing_flag = (USHORT*) (message->msg_buffer + missing_parameter->par_offset); *missing_flag = (desc->dsc_missing & DSC_missing) ? DSC_missing : 0; } - from = parameter->par_value; + QLI_NOD from = parameter->par_value; if (desc->dsc_dtype == dtype_blob && copy_blob(from, parameter)) continue; assignment(from, desc, 0, 0, parameter->par_missing); @@ -1088,28 +1080,28 @@ static void print_counts( QLI_REQ request) ************************************** * * Functional description - * Print out the count of records affected + * Print out the count of records affected * by the last statement. * **************************************/ - UCHAR item; - int length; - ULONG number; ISC_STATUS_ARRAY status_vector; - SCHAR count_buffer[COUNT_ITEMS * 7 + 1], *c; + SCHAR count_buffer[COUNT_ITEMS * 7 + 1]; if (gds__request_info(status_vector, &request->req_handle, 0, sizeof(count_info), count_info, - sizeof(count_buffer), count_buffer)) + sizeof(count_buffer), count_buffer)) + { return; + } -// print out the counts of any records affected +// print out the counts of any records affected - for (c = count_buffer; *c != gds_info_end; c += length) { - item = *c++; + int length = 0; + for (SCHAR* c = count_buffer; *c != gds_info_end; c += length) { + UCHAR item = *c++; length = gds__vax_integer((UCHAR*) c, 2); c += 2; - number = gds__vax_integer((UCHAR*) c, length); + const ULONG number = gds__vax_integer((UCHAR*) c, length); if (number) switch (item) { @@ -1151,15 +1143,12 @@ static void set_null( QLI_MSG message) * statements. * **************************************/ - PAR parameter; - QLI_NOD from; - DSC *desc; - - for (parameter = message->msg_parameters; parameter; - parameter = parameter->par_next) { - from = parameter->par_value; + for (PAR parameter = message->msg_parameters; parameter; + parameter = parameter->par_next) + { + QLI_NOD from = parameter->par_value; if (from->nod_type == nod_field) { - desc = EVAL_value(from); + dsc* desc = EVAL_value(from); desc->dsc_missing |= DSC_missing; } else @@ -1178,7 +1167,7 @@ static void transaction_state( QLI_NOD node, DBB database) ************************************** * * Functional description - * + * * set the state of the working transaction * in a particular database to prepared or * committed. @@ -1197,3 +1186,5 @@ static void transaction_state( QLI_NOD node, DBB database) } } } + + diff --git a/src/qli/exe.h b/src/qli/exe.h index 55111a5f9a..508e7abccb 100644 --- a/src/qli/exe.h +++ b/src/qli/exe.h @@ -90,18 +90,18 @@ typedef struct qli_ctx { struct qli_nod* ctx_rse; /* RSE node for root context */ struct qli_nod* ctx_sub_rse; /* RSE node aggregate */ qli_ctx* ctx_parent; /* Parent context for map */ - struct map *ctx_map; /* Map items, if any */ + struct qli_map *ctx_map; /* Map items, if any */ USHORT ctx_context; /* Context in request */ } *QLI_CTX; /* Aggregate/union map block */ -typedef struct map { +typedef struct qli_map { blk map_header; - map* map_next; /* Next map in item */ + qli_map* map_next; /* Next map in item */ struct qli_nod* map_node; /* Value for map item */ USHORT map_position; /* Position in map */ -} *MAP; +} *QLI_MAP; /* Message block */ diff --git a/src/qli/exe_proto.h b/src/qli/exe_proto.h index e651286a29..c60ea80ca3 100644 --- a/src/qli/exe_proto.h +++ b/src/qli/exe_proto.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_EXE_PROTO_H_ -#define _QLI_EXE_PROTO_H_ +#ifndef QLI_EXE_PROTO_H +#define QLI_EXE_PROTO_H extern void EXEC_abort (void); extern void EXEC_execute(qli_nod*); @@ -34,4 +34,4 @@ extern void EXEC_send(qli_msg*); extern void EXEC_start_request(qli_req*, qli_msg*); extern void EXEC_top(qli_nod*); -#endif /* _QLI_EXE_PROTO_H_ */ +#endif /* QLI_EXE_PROTO_H */ diff --git a/src/qli/expan_proto.h b/src/qli/expan_proto.h index f6fcc93b3b..ee9ddde977 100644 --- a/src/qli/expan_proto.h +++ b/src/qli/expan_proto.h @@ -21,9 +21,9 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_EXPAN_PROTO_H_ -#define _QLI_EXPAN_PROTO_H_ +#ifndef QLI_EXPAN_PROTO_H +#define QLI_EXPAN_PROTO_H extern qli_nod* EXP_expand(syn*); -#endif /* _QLI_EXPAN_PROTO_H_ */ +#endif /* QLI_EXPAN_PROTO_H */ diff --git a/src/qli/expand.cpp b/src/qli/expand.cpp index d53d7a8cf0..9d9d19c417 100644 --- a/src/qli/expand.cpp +++ b/src/qli/expand.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: expand.c + * MODULE: expand.cpp * DESCRIPTION: Expand syntax tree -- first phase of compiler * * The contents of this file are subject to the Interbase Public @@ -39,7 +39,7 @@ extern USHORT QLI_columns, QLI_lines; -#define MAKE_NODE(type,count) make_node (type, count) +#define MAKE_NODE(type, count) make_node (type, count) static bool compare_names(NAM, SYM); static bool compare_symbols(SYM, SYM); @@ -88,7 +88,7 @@ static QLI_NOD post_map(QLI_NOD, QLI_CTX); static QLI_FLD resolve(SYN, LLS, QLI_CTX *); static void resolve_really(QLI_FLD, SYN); -static LLS output_stack; +static LLS global_output_stack; QLI_NOD EXP_expand( SYN node) @@ -103,10 +103,6 @@ QLI_NOD EXP_expand( SYN node) * Expand a syntax tree into something richer and more complete. * **************************************/ - QLI_NOD expanded, output; - QLI_CTX context; - LLS right, left; - switch (node->syn_type) { case nod_commit: case nod_prepare: @@ -233,25 +229,27 @@ QLI_NOD EXP_expand( SYN node) case nod_sql_al_table: MET_sql_alter_table((QLI_REL) node->syn_arg[0], (QLI_FLD) node->syn_arg[1]); return NULL; - } + } // end switch, no default case for error -// If there are any variables, make up a context now +// If there are any variables, make up a context now - output_stack = right = left = NULL; + LLS right, left; + global_output_stack = right = left = NULL; if (QLI_variables) { - context = (QLI_CTX) ALLOCD(type_ctx); + QLI_CTX context = (QLI_CTX) ALLOCD(type_ctx); context->ctx_type = CTX_VARIABLE; context->ctx_variable = QLI_variables; LLS_PUSH(context, &right); LLS_PUSH(context, &left); } - if (!(expanded = expand_statement(node, right, left))) + QLI_NOD expanded = expand_statement(node, right, left); + if (!expanded) return NULL; - while (output_stack) { - output = (QLI_NOD) LLS_POP(&output_stack); + while (global_output_stack) { + QLI_NOD output = (QLI_NOD) LLS_POP(&global_output_stack); output->nod_arg[e_out_statement] = expanded; expanded = output; } @@ -273,19 +271,20 @@ static bool compare_names( NAM name, SYM symbol) * **************************************/ USHORT l; - TEXT *p, *q; if (!symbol || (l = name->nam_length) != symbol->sym_length) return false; - p = symbol->sym_string; - q = name->nam_string; - if (l) - do + { + const TEXT* p = symbol->sym_string; + const TEXT* q = name->nam_string; + + do { if (*p++ != *q++) return false; - while (--l); + } while (--l); + } return true; } @@ -303,23 +302,23 @@ static bool compare_symbols( SYM symbol1, SYM symbol2) * Compare two symbols (either may be 0). * **************************************/ - USHORT l; - TEXT *p, *q; - if (!symbol1 || !symbol2) return false; - if ((l = symbol1->sym_length) != symbol2->sym_length) + USHORT l = symbol1->sym_length; + if (l != symbol2->sym_length) return false; - p = symbol1->sym_string; - q = symbol2->sym_string; - if (l) - do + { + const TEXT* p = symbol1->sym_string; + const TEXT* q = symbol2->sym_string; + + do { if (*p++ != *q++) return false; - while (--l); + } while (--l); + } return true; } @@ -337,9 +336,7 @@ static SYM copy_symbol( SYM old) * Copy a symbol into the permanent pool. * **************************************/ - SYM new_sym; - - new_sym = (SYM) ALLOCPV(type_sym, old->sym_length); + SYM new_sym = (SYM) ALLOCPV(type_sym, old->sym_length); new_sym->sym_length = old->sym_length; new_sym->sym_type = old->sym_type; new_sym->sym_string = new_sym->sym_name; @@ -358,30 +355,29 @@ static void declare_global( QLI_FLD variable, SYN field_node) ************************************** * * Functional description - * Copy a variable block into the permanent pool as a field. - * Resolve BASED_ON references. + * Copy a variable block into the permanent pool as a field. + * Resolve BASED_ON references. * Allocate all strings off the field block. * **************************************/ - TEXT *p, *q; - USHORT l; - QLI_FLD new_fld, field, *ptr; + QLI_FLD field, *ptr; -/* If it's based_on, flesh it out & check datatype. */ +// If it's based_on, flesh it out & check datatype. if (field_node) { if (field_node->syn_type == nod_index) field_node = field_node->syn_arg[s_idx_field]; resolve_really(variable, field_node); if (variable->fld_dtype == dtype_blob) - IBERROR(137); // Msg137 variables may not be based on blob fields. + IBERROR(137); // Msg137 variables may not be based on blob fields. } -// Get rid of any other variables of the same name +// Get rid of any other variables of the same name for (ptr = &QLI_variables; field = *ptr; ptr = &field->fld_next) if (!strcmp - (field->fld_name->sym_string, variable->fld_name->sym_string)) { + (field->fld_name->sym_string, variable->fld_name->sym_string)) + { *ptr = field->fld_next; ALLQ_release((FRB) field->fld_name); if (field->fld_query_name) @@ -390,16 +386,17 @@ static void declare_global( QLI_FLD variable, SYN field_node) break; } -/* Next, copy temporary field block into permanent pool. Fold edit_string - query_header into main block to save space and complexity. */ +// Next, copy temporary field block into permanent pool. Fold edit_string +// query_header into main block to save space and complexity. - l = variable->fld_length; + const TEXT* q; + USHORT l = variable->fld_length; if (q = variable->fld_edit_string) l += strlen(q); if (q = variable->fld_query_header) l += strlen(q); - new_fld = (QLI_FLD) ALLOCPV(type_fld, l); + QLI_FLD new_fld = (QLI_FLD) ALLOCPV(type_fld, l); new_fld->fld_name = copy_symbol(variable->fld_name); new_fld->fld_dtype = variable->fld_dtype; new_fld->fld_length = variable->fld_length; @@ -408,9 +405,9 @@ static void declare_global( QLI_FLD variable, SYN field_node) new_fld->fld_sub_type_missing = variable->fld_sub_type_missing; new_fld->fld_flags = variable->fld_flags | FLD_missing; -// Copy query_name, edit string, query header +// Copy query_name, edit string, query header - p = (TEXT *) new_fld->fld_data + new_fld->fld_length; + TEXT* p = (TEXT*) new_fld->fld_data + new_fld->fld_length; if (q = variable->fld_edit_string) { new_fld->fld_edit_string = p; while (*p++ = *q++); @@ -422,7 +419,7 @@ static void declare_global( QLI_FLD variable, SYN field_node) while (*p++ = *q++); } -// Link new variable into variable chain +// Link new variable into variable chain new_fld->fld_next = QLI_variables; QLI_variables = new_fld; @@ -440,21 +437,17 @@ static SYN decompile_field( QLI_FLD field, QLI_CTX context) * Functional description * Take a perfectly good, completely compiled * field block and regress to a SYN node and - * and a NAM block. + * and a NAM block. * (Needed to support SQL idiocies) * **************************************/ - SYN node; - NAM name; - int args; + int args = (context) ? 2 : 1; - args = (context) ? 2 : 1; - - node = (SYN) ALLOCDV(type_syn, args); + SYN node = (SYN) ALLOCDV(type_syn, args); node->syn_type = nod_field; node->syn_count = args; - name = decompile_symbol(field->fld_name); + NAM name = decompile_symbol(field->fld_name); node->syn_arg[0] = (SYN) name; if (context) { @@ -519,20 +512,20 @@ static QLI_NOD expand_assignment( SYN input, LLS right, LLS left) * Expand an assigment statement. All in all, not too tough. * **************************************/ - QLI_NOD node, from, to; - QLI_FLD field; + QLI_NOD from, to; - node = MAKE_NODE(input->syn_type, e_asn_count); + QLI_NOD node = MAKE_NODE(input->syn_type, e_asn_count); node->nod_arg[e_asn_to] = to = expand_expression(input->syn_arg[s_asn_to], left); node->nod_arg[e_asn_from] = from = expand_expression(input->syn_arg[s_asn_from], right); if (to->nod_type == nod_field || to->nod_type == nod_variable) { - field = (QLI_FLD) to->nod_arg[e_fld_field]; + QLI_FLD field = (QLI_FLD) to->nod_arg[e_fld_field]; if (field->fld_flags & FLD_computed) { ERRQ_print_error(138, field->fld_name->sym_string, NULL, NULL, - NULL, NULL); /* Msg138 can't do assignment to computed field */ + NULL, NULL); + // Msg138 can't do assignment to computed field } if (from->nod_type == nod_prompt) from->nod_arg[e_prm_field] = to->nod_arg[e_fld_field]; @@ -562,16 +555,16 @@ static QLI_NOD expand_any( SYN input, LLS stack) * for existence. * **************************************/ - QLI_NOD rse, node, negation, boolean; + QLI_NOD rse; - node = MAKE_NODE(input->syn_type, e_any_count); + QLI_NOD node = MAKE_NODE(input->syn_type, e_any_count); node->nod_count = 0; node->nod_arg[e_any_rse] = rse = expand_rse(input->syn_arg[0], &stack); if (input->syn_count >= 2 && input->syn_arg[1]) { - boolean = MAKE_NODE(nod_missing, 1); + QLI_NOD boolean = MAKE_NODE(nod_missing, 1); boolean->nod_arg[0] = expand_expression(input->syn_arg[1], stack); - negation = MAKE_NODE(nod_not, 1); + QLI_NOD negation = MAKE_NODE(nod_not, 1); negation->nod_arg[0] = boolean; rse->nod_arg[e_rse_boolean] = make_and(rse->nod_arg[e_rse_boolean], negation); @@ -593,26 +586,25 @@ static QLI_NOD expand_boolean( SYN input, LLS stack) * Expand a statement. * **************************************/ - QLI_NOD node, *ptr, value; - QLI_FLD field; + QLI_NOD value; SSHORT i; -// Make node and process arguments +// Make node and process arguments - node = MAKE_NODE(input->syn_type, input->syn_count); - ptr = node->nod_arg; + QLI_NOD node = MAKE_NODE(input->syn_type, input->syn_count); + QLI_NOD* ptr = node->nod_arg; *ptr++ = value = expand_expression(input->syn_arg[0], stack); for (i = 1; i < input->syn_count; i++, ptr++) if (!(*ptr = possible_literal(input->syn_arg[i], stack, true))) *ptr = expand_expression(input->syn_arg[i], stack); -// Try to match any prompts against fields to determine prompt length +// Try to match any prompts against fields to determine prompt length if (value->nod_type != nod_field) return node; - field = (QLI_FLD) value->nod_arg[e_fld_field]; + QLI_FLD field = (QLI_FLD) value->nod_arg[e_fld_field]; ptr = &node->nod_arg[1]; for (i = 1; i < node->nod_count; i++, ptr++) @@ -623,7 +615,7 @@ static QLI_NOD expand_boolean( SYN input, LLS stack) } -static void expand_control_break( BRK * ptr, LLS right) +static void expand_control_break( BRK* ptr, LLS right) { /************************************** * @@ -636,9 +628,9 @@ static void expand_control_break( BRK * ptr, LLS right) * to handle multiple breaks. * **************************************/ - BRK control, list; + BRK control; - list = NULL; + BRK list = NULL; while (control = *ptr) { *ptr = control->brk_next; @@ -670,12 +662,11 @@ static void expand_distinct( QLI_NOD rse, QLI_NOD node) * **************************************/ QLI_NOD list; - LLS stack; if (rse->nod_arg[e_rse_reduced]) return; - stack = NULL; + LLS stack = NULL; LLS_PUSH(node, &stack); LLS_PUSH(0, &stack); rse->nod_arg[e_rse_reduced] = list = make_list(stack); @@ -695,9 +686,8 @@ static void expand_edit_string( QLI_NOD node, ITM item) * Default edit_string and query_header. * **************************************/ - QLI_FLD field; FUN function; - MAP map; + QLI_MAP map; switch (node->nod_type) { case nod_min: @@ -738,7 +728,7 @@ static void expand_edit_string( QLI_NOD node, ITM item) break; case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + map = (QLI_MAP) node->nod_arg[e_map_map]; expand_edit_string(map->map_node, item); return; @@ -756,9 +746,9 @@ static void expand_edit_string( QLI_NOD node, ITM item) return; } -// Handle fields +// Handle fields - field = (QLI_FLD) node->nod_arg[e_fld_field]; + QLI_FLD field = (QLI_FLD) node->nod_arg[e_fld_field]; if (!item->itm_edit_string) item->itm_edit_string = field->fld_edit_string; @@ -781,15 +771,10 @@ static QLI_NOD expand_erase( SYN input, LLS right, LLS left) * Expand a statement. * **************************************/ - QLI_NOD node, loop; - LLS contexts; - QLI_CTX context; - USHORT count; + QLI_NOD loop = NULL; + USHORT count = 0; - loop = NULL; - count = 0; - -// If there is an rse, make up a FOR loop +// If there is an rse, make up a FOR loop if (input->syn_arg[s_era_rse]) { loop = MAKE_NODE(nod_for, e_for_count); @@ -797,9 +782,10 @@ static QLI_NOD expand_erase( SYN input, LLS right, LLS left) &right); } -// Loop thru contexts counting them. +// Loop thru contexts counting them. - for (contexts = right; contexts; contexts = contexts->lls_next) { + QLI_CTX context = NULL; + for (LLS contexts = right; contexts; contexts = contexts->lls_next) { context = (QLI_CTX) contexts->lls_object; if (context->ctx_variable) continue; @@ -809,13 +795,13 @@ static QLI_NOD expand_erase( SYN input, LLS right, LLS left) } if (count == 0) - IBERROR(139); // Msg139 no context for ERASE + IBERROR(139); // Msg139 no context for ERASE else if (count > 1) - IBERROR(140); /* Msg140 can't erase from a join */ + IBERROR(140); // Msg140 can't erase from a join -// Make up node big enough to hold fixed fields plus all contexts +// Make up node big enough to hold fixed fields plus all contexts - node = MAKE_NODE(nod_erase, e_era_count); + QLI_NOD node = MAKE_NODE(nod_erase, e_era_count); node->nod_arg[e_era_context] = (QLI_NOD) context; if (!loop) @@ -839,12 +825,11 @@ static QLI_NOD expand_expression( SYN input, LLS stack) * Expand an expression. * **************************************/ - QLI_NOD *ptr, node; + QLI_NOD node; CON constant; QLI_CTX context; NAM name; SYN value; - SSHORT i; switch (input->syn_type) { case nod_field: @@ -884,7 +869,7 @@ static QLI_NOD expand_expression( SYN input, LLS stack) && node->nod_arg[e_stt_value]) expand_distinct(node->nod_arg[e_stt_rse], node->nod_arg[e_stt_value]); -// count2 next 2 lines go +// count2 next 2 lines go if (input->syn_type == nod_count) node->nod_arg[e_stt_value] = 0; return node; @@ -901,7 +886,8 @@ static QLI_NOD expand_expression( SYN input, LLS stack) break; } if (!stack) - ERRQ_print_error(454, NULL, NULL, NULL, NULL, NULL); // could not resolve context for aggregate + ERRQ_print_error(454, NULL, NULL, NULL, NULL, NULL); + // could not resolve context for aggregate /* count2 if (value = input->syn_arg [s_stt_value]) { @@ -925,7 +911,7 @@ static QLI_NOD expand_expression( SYN input, LLS stack) case nod_index: value = input->syn_arg[s_idx_field]; if (value->syn_type != nod_field) - IBERROR(466); // Msg466 Only fields may be subscripted + IBERROR(466); // Msg466 Only fields may be subscripted return expand_field(value, stack, input->syn_arg[s_idx_subs]); case nod_list: @@ -991,16 +977,17 @@ static QLI_NOD expand_expression( SYN input, LLS stack) case nod_star: name = (NAM) input->syn_arg[0]; - ERRQ_print_error(141, name->nam_string, NULL, NULL, NULL, NULL); /* Msg141 can't be used when a single element is required */ + ERRQ_print_error(141, name->nam_string, NULL, NULL, NULL, NULL); + // Msg141 can't be used when a single element is required default: - BUGCHECK(135); // Msg135 expand_expression: not yet implemented + BUGCHECK(135); // Msg135 expand_expression: not yet implemented } node = MAKE_NODE(input->syn_type, input->syn_count); - ptr = node->nod_arg; + QLI_NOD* ptr = node->nod_arg; - for (i = 0; i < input->syn_count; i++) + for (SSHORT i = 0; i < input->syn_count; i++) *ptr++ = expand_expression(input->syn_arg[i], stack); return node; @@ -1021,37 +1008,41 @@ static QLI_NOD expand_field( SYN input, LLS stack, SYN subs) * sure it goes there. * **************************************/ - QLI_NOD node; - QLI_FLD field; - QLI_CTX context, parent, stream_context, *ptr, *end; - NAM name; - USHORT i, l; - TEXT *p, *q, s[160]; - LLS save_stack; + QLI_CTX context; - if (!(field = resolve(input, stack, &context)) || - (subs && (context->ctx_variable))) + QLI_FLD field = resolve(input, stack, &context); + if (!field || (subs && (context->ctx_variable))) { - p = s; - for (i = 0; i < input->syn_count; i++) { - name = (NAM) input->syn_arg[i]; - q = name->nam_string; - if (l = name->nam_length) - do - *p++ = *q++; - while (--l); - *p++ = '.'; + TEXT s[160]; + TEXT* p = s; + const TEXT* const limit = p + sizeof(s) - 1; + for (USHORT i = 0; i < input->syn_count; i++) { + NAM name = (NAM) input->syn_arg[i]; + const TEXT* q = name->nam_string; + USHORT l = name->nam_length; + if (p < limit) { + if (l) + do { + *p++ = *q++; + } while (--l && p < limit); + *p++ = '.'; + } } *--p = 0; if (field) - ERRQ_print_error(467, s, NULL, NULL, NULL, NULL); /* Msg467 "%s" is not a field and so may not be subscripted */ + ERRQ_print_error(467, s, NULL, NULL, NULL, NULL); + // Msg467 "%s" is not a field and so may not be subscripted else - ERRQ_print_error(142, s, NULL, NULL, NULL, NULL); /* Msg142 "%s" is undefined or used out of context */ + ERRQ_print_error(142, s, NULL, NULL, NULL, NULL); + // Msg142 "%s" is undefined or used out of context } - node = make_field(field, context); + + QLI_NOD node = make_field(field, context); if (subs) node->nod_arg[e_fld_subs] = expand_expression(subs, stack); + QLI_CTX parent = NULL; + LLS save_stack; for (save_stack = stack; stack; stack = stack->lls_next) { parent = (QLI_CTX) stack->lls_object; if (parent->ctx_type == CTX_AGGREGATE) @@ -1065,13 +1056,14 @@ static QLI_NOD expand_field( SYN input, LLS stack, SYN subs) a stream context. Check out this possibility. */ for (; save_stack; save_stack = save_stack->lls_next) { - stream_context = (QLI_CTX) save_stack->lls_object; + QLI_CTX stream_context = (QLI_CTX) save_stack->lls_object; if (stream_context->ctx_type != CTX_STREAM || stream_context->ctx_stream->nod_type != nod_rse) continue; - ptr = (QLI_CTX*) stream_context->ctx_stream->nod_arg + e_rse_count; - end = ptr + stream_context->ctx_stream->nod_count; + QLI_CTX* ptr = + (QLI_CTX*) stream_context->ctx_stream->nod_arg + e_rse_count; + QLI_CTX* const end = ptr + stream_context->ctx_stream->nod_count; for (; ptr < end; ptr++) if (*ptr == context) break; @@ -1099,9 +1091,7 @@ static QLI_NOD expand_for( SYN input, LLS right, LLS left) * Expand a statement. * **************************************/ - QLI_NOD node; - - node = MAKE_NODE(input->syn_type, e_for_count); + QLI_NOD node = MAKE_NODE(input->syn_type, e_for_count); node->nod_arg[e_for_rse] = expand_rse(input->syn_arg[s_for_rse], &right); node->nod_arg[e_for_statement] = expand_statement(input->syn_arg[s_for_statement], right, left); @@ -1126,13 +1116,12 @@ static QLI_NOD expand_function( SYN input, LLS stack) * reference, use any database that matches. * **************************************/ - QLI_NOD node; SYM symbol; FUN function; QLI_CTX context; DBB database; - node = MAKE_NODE(input->syn_type, e_fun_count); + QLI_NOD node = MAKE_NODE(input->syn_type, e_fun_count); node->nod_count = 1; if (stack && (context = (QLI_CTX) stack->lls_object) && (context->ctx_type == CTX_RELATION)) { @@ -1151,14 +1140,17 @@ static QLI_NOD expand_function( SYN input, LLS stack) } else for (database = QLI_databases; database; - database = database->dbb_next) { + database = database->dbb_next) + { for (symbol = (SYM) input->syn_arg[s_fun_function]; symbol; symbol = symbol->sym_homonym) + { if (symbol->sym_type == SYM_function) { function = (FUN) symbol->sym_object; if (function->fun_database == database) break; } + } if (symbol) break; } @@ -1192,13 +1184,13 @@ static QLI_NOD expand_group_by( SYN input, LLS stack, QLI_CTX context) * **************************************/ SYN *ptr, *end; - QLI_NOD node, *ptr2; - node = MAKE_NODE(input->syn_type, input->syn_count); - ptr2 = node->nod_arg; + QLI_NOD node = MAKE_NODE(input->syn_type, input->syn_count); + QLI_NOD* ptr2 = node->nod_arg; for (ptr = input->syn_arg, end = ptr + input->syn_count; ptr < end; - ptr++, ptr2++) { + ptr++, ptr2++) + { *ptr2 = expand_expression(*ptr, stack); post_map(*ptr2, context); } @@ -1219,16 +1211,12 @@ static QLI_NOD expand_modify( SYN input, LLS right, LLS left) * Expand a statement. * **************************************/ - QLI_NOD node, loop, list, *ptr; - SYN syn_list, *syn_ptr; LLS contexts; - QLI_CTX new_context, context; - USHORT count, i; - loop = NULL; - count = 0; + QLI_NOD loop = NULL; + USHORT count = 0; -// If there is an rse, make up a FOR loop +// If there is an rse, make up a FOR loop if (input->syn_arg[s_mod_rse]) { loop = MAKE_NODE(nod_for, e_for_count); @@ -1236,10 +1224,10 @@ static QLI_NOD expand_modify( SYN input, LLS right, LLS left) &right); } -// Loop thru contexts counting them. +// Loop thru contexts counting them. for (contexts = right; contexts; contexts = contexts->lls_next) { - context = (QLI_CTX) contexts->lls_object; + QLI_CTX context = (QLI_CTX) contexts->lls_object; if (context->ctx_variable) continue; count++; @@ -1248,21 +1236,21 @@ static QLI_NOD expand_modify( SYN input, LLS right, LLS left) } if (!count) - IBERROR(148); // Msg148 no context for modify + IBERROR(148); // Msg148 no context for modify -// Make up node big enough to hold fixed fields plus all contexts +// Make up node big enough to hold fixed fields plus all contexts - node = MAKE_NODE(nod_modify, (int) e_mod_count + count); + QLI_NOD node = MAKE_NODE(nod_modify, (int) e_mod_count + count); node->nod_count = count; - ptr = &node->nod_arg[e_mod_count]; + QLI_NOD* ptr = &node->nod_arg[e_mod_count]; -// Loop thru contexts augmenting left context +// Loop thru contexts augmenting left context for (contexts = right; contexts; contexts = contexts->lls_next) { - context = (QLI_CTX) contexts->lls_object; + QLI_CTX context = (QLI_CTX) contexts->lls_object; if (context->ctx_variable) continue; - new_context = (QLI_CTX) ALLOCD(type_ctx); + QLI_CTX new_context = (QLI_CTX) ALLOCD(type_ctx); *ptr++ = (QLI_NOD) new_context; new_context->ctx_type = CTX_RELATION; new_context->ctx_source = context; @@ -1273,23 +1261,26 @@ static QLI_NOD expand_modify( SYN input, LLS right, LLS left) break; } -// Process sub-statement, list of fields, or, sigh, none of the above +// Process sub-statement, list of fields, or, sigh, none of the above + SYN syn_list; if (input->syn_arg[s_mod_statement]) node->nod_arg[e_mod_statement] = expand_statement(input->syn_arg[s_mod_statement], right, left); else if (syn_list = input->syn_arg[s_mod_list]) { - node->nod_arg[e_mod_statement] = list = - MAKE_NODE(nod_list, syn_list->syn_count); + QLI_NOD list = MAKE_NODE(nod_list, syn_list->syn_count); + node->nod_arg[e_mod_statement] = list; + ptr = list->nod_arg; - syn_ptr = syn_list->syn_arg; - for (i = 0; i < syn_list->syn_count; i++, syn_ptr++) - *ptr++ = - make_assignment(expand_expression((SYN) *syn_ptr, left), (QLI_NOD) *syn_ptr, - right); + SYN* syn_ptr = syn_list->syn_arg; + for (USHORT i = 0; i < syn_list->syn_count; i++, syn_ptr++) + { + *ptr++ = make_assignment(expand_expression((SYN) *syn_ptr, left), + (QLI_NOD) *syn_ptr, right); + } } else - IBERROR(149); // Msg149 field list required for modify + IBERROR(149); // Msg149 field list required for modify if (!loop) return node; @@ -1312,18 +1303,17 @@ static QLI_NOD expand_output( SYN input, LLS right, PRT * print) * Handle the presence (or absence) of an output specification clause. * **************************************/ - QLI_NOD output, node; - if (print) *print = (PRT) ALLOCD(type_prt); if (!input) return NULL; - output = MAKE_NODE(nod_output, e_out_count); - LLS_PUSH(output, &output_stack); + QLI_NOD output = MAKE_NODE(nod_output, e_out_count); + LLS_PUSH(output, &global_output_stack); - if (!(node = possible_literal(input->syn_arg[s_out_file], right, false))) + QLI_NOD node = possible_literal(input->syn_arg[s_out_file], right, false); + if (!node) node = expand_expression(input->syn_arg[s_out_file], right); output->nod_arg[e_out_file] = node; @@ -1348,31 +1338,21 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) * Expand a statement. * **************************************/ - SYN syn_list, syn_item, syn_rse, *sub, *end; - ITM item; - QLI_NOD node, loop, list, *ptr, rse; - QLI_NOD reduced; - LLS items, new_right; - QLI_CTX context; - QLI_REL relation; - QLI_FLD field; + SYN syn_rse = input->syn_arg[s_prt_rse]; + + QLI_NOD loop = NULL; + LLS items = NULL; + QLI_NOD rse = NULL; + USHORT count = 0; + LLS new_right = right; + +// If an output file or pipe is present, make up an output node + PRT print; - USHORT i, count; - - syn_rse = input->syn_arg[s_prt_rse]; - - loop = NULL; - items = NULL; - rse = NULL; - count = 0; - new_right = right; - -// If an output file or pipe is present, make up an output node - expand_output(input->syn_arg[s_prt_output], right, &print); -/* If a record select expression is present, expand it and build a FOR - statement. */ +// If a record select expression is present, expand it and build a FOR +// statement. if (syn_rse) { loop = MAKE_NODE(nod_for, e_for_count); @@ -1383,13 +1363,18 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) look like items, but are actually lists. If there aren't items of any kind, pick up all fields in the relations from the record selection expression. */ - if (syn_list = input->syn_arg[s_prt_list]) + SYN syn_item, *sub, *end; + SYN syn_list = input->syn_arg[s_prt_list]; + if (syn_list) for (sub = syn_list->syn_arg, end = sub + syn_list->syn_count; - sub < end; sub++) { + sub < end; sub++) + { if (((*sub)->syn_type == nod_print_item) && (syn_item = (*sub)->syn_arg[s_itm_value]) && (syn_item->syn_type == nod_star)) + { count += generate_items(syn_item, new_right, (LLS) &items, rse); + } else { LLS_PUSH(expand_print_item(*sub, new_right), &items); count++; @@ -1397,8 +1382,9 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) } else if (syn_rse && (syn_list = syn_rse->syn_arg[s_rse_reduced])) for (sub = syn_list->syn_arg, end = sub + syn_list->syn_count; - sub < end; sub += 2) { - item = (ITM) ALLOCD(type_itm); + sub < end; sub += 2) + { + ITM item = (ITM) ALLOCD(type_itm); item->itm_type = item_value; item->itm_value = expand_expression(*sub, new_right); expand_edit_string(item->itm_value, item); @@ -1407,21 +1393,25 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) } else for (; new_right; new_right = new_right->lls_next) { - context = (QLI_CTX) new_right->lls_object; - relation = context->ctx_relation; + QLI_CTX context = (QLI_CTX) new_right->lls_object; + QLI_REL relation = context->ctx_relation; if (!relation || context->ctx_sub_rse) continue; - for (field = relation->rel_fields; field; field = field->fld_next) { + for (QLI_FLD field = relation->rel_fields; field; + field = field->fld_next) + { if ( (field->fld_system_flag && field->fld_system_flag != relation->rel_system_flag) || field->fld_flags & FLD_array) + { continue; - node = make_field(field, context); + } + QLI_NOD node = make_field(field, context); if (rse && rse->nod_arg[e_rse_group_by] && invalid_nod_field(node, rse->nod_arg[e_rse_group_by])) continue; - item = (ITM) ALLOCD(type_itm); + ITM item = (ITM) ALLOCD(type_itm); item->itm_type = item_value; item->itm_value = make_field(field, context); expand_edit_string(item->itm_value, item); @@ -1435,22 +1425,24 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) /* If no print object showed up, complain! */ if (!count) - IBERROR(150); // Msg150 No items in print list + IBERROR(150); // Msg150 No items in print list /* Build new print statement. Unlike the syntax node, the print statement has only print items in it. */ - node = MAKE_NODE(input->syn_type, e_prt_count); - node->nod_arg[e_prt_list] = list = make_list(items); + QLI_NOD node = MAKE_NODE(input->syn_type, e_prt_count); + QLI_NOD list = make_list(items); + node->nod_arg[e_prt_list] = list; node->nod_arg[e_prt_output] = (QLI_NOD) print; -// If DISTINCT was requested, make up a reduced list. +// If DISTINCT was requested, make up a reduced list. if (rse && input->syn_arg[s_prt_distinct]) { - reduced = MAKE_NODE(nod_list, list->nod_count * 2); + QLI_NOD reduced = MAKE_NODE(nod_list, list->nod_count * 2); reduced->nod_count = 0; - for (i = 0, ptr = reduced->nod_arg; i < list->nod_count; i++) { - item = (ITM) list->nod_arg[i]; + QLI_NOD* ptr = reduced->nod_arg; + for (USHORT i = 0; i < list->nod_count; i++) { + ITM item = (ITM) list->nod_arg[i]; if (item->itm_value) { *ptr++ = item->itm_value; ptr++; @@ -1461,7 +1453,7 @@ static QLI_NOD expand_print( SYN input, LLS right, LLS left) rse->nod_arg[e_rse_reduced] = reduced; } -// If a FOR loop was generated, splice it in here. +// If a FOR loop was generated, splice it in here. if (loop) { loop->nod_arg[e_for_statement] = node; @@ -1488,11 +1480,10 @@ static ITM expand_print_item( SYN syn_item, LLS right) * specifier. * **************************************/ - ITM item; SYN syn_expr; QLI_NOD node; - item = (ITM) ALLOCD(type_itm); + ITM item = (ITM) ALLOCD(type_itm); switch (syn_item->syn_type) { case nod_print_item: @@ -1551,11 +1542,9 @@ static QLI_NOD expand_print_list( SYN input, LLS stack) * Expand a print list. * **************************************/ - LLS items; + LLS items = NULL; SYN *ptr, *end; - items = NULL; - for (ptr = input->syn_arg, end = ptr + input->syn_count; ptr < end; ptr++) LLS_PUSH(expand_print_item(*ptr, stack), &items); @@ -1575,15 +1564,12 @@ static QLI_NOD expand_report( SYN input, LLS right, LLS left) * Expand a report specification. * **************************************/ - RPT report; - SYN sub; - QLI_NOD node, loop; PRT print; -// Start by processing record selection expression +// Start by processing record selection expression expand_output(input->syn_arg[s_prt_output], right, &print); - report = print->prt_report = (RPT) input->syn_arg[s_prt_list]; + RPT report = print->prt_report = (RPT) input->syn_arg[s_prt_list]; if (!(print->prt_lines_per_page = report->rpt_lines)) print->prt_lines_per_page = QLI_lines; @@ -1591,20 +1577,22 @@ static QLI_NOD expand_report( SYN input, LLS right, LLS left) if (!report->rpt_columns) report->rpt_columns = QLI_columns; - loop = MAKE_NODE(nod_report_loop, e_for_count); + QLI_NOD loop = MAKE_NODE(nod_report_loop, e_for_count); loop->nod_arg[e_for_rse] = expand_rse(input->syn_arg[s_prt_rse], &right); - loop->nod_arg[e_for_statement] = node = - MAKE_NODE(nod_report, e_prt_count); + QLI_NOD node = MAKE_NODE(nod_report, e_prt_count); + loop->nod_arg[e_for_statement] = node; + node->nod_arg[e_prt_list] = (QLI_NOD) report; node->nod_arg[e_prt_output] = (QLI_NOD) print; -// Process clauses where they exist +// Process clauses where they exist expand_control_break(&report->rpt_top_rpt, right); expand_control_break(&report->rpt_top_page, right); expand_control_break(&report->rpt_top_breaks, right); - if (sub = (SYN) report->rpt_detail_line) + SYN sub = (SYN) report->rpt_detail_line; + if (sub) report->rpt_detail_line = expand_print_list(sub, right); expand_control_break(&report->rpt_bottom_breaks, right); @@ -1627,30 +1615,25 @@ static QLI_NOD expand_restructure( SYN input, LLS right, LLS left) * Transform a restructure statement into a FOR STORE. * **************************************/ - QLI_NOD node, assignment, loop; - SYN rel_node; - QLI_REL relation; - QLI_FLD field, fld; - QLI_CTX context, ctx; - LLS stack, search; -// Make a FOR loop to drive the restructure +// Make a FOR loop to drive the restructure - loop = MAKE_NODE(nod_for, e_for_count); + QLI_NOD loop = MAKE_NODE(nod_for, e_for_count); loop->nod_arg[e_for_rse] = expand_rse(input->syn_arg[s_asn_from], &right); -// Make a STORE node. +// Make a STORE node. - loop->nod_arg[e_for_statement] = node = MAKE_NODE(nod_store, e_sto_count); - rel_node = input->syn_arg[s_asn_to]; - context = (QLI_CTX) ALLOCD(type_ctx); + QLI_NOD node = MAKE_NODE(nod_store, e_sto_count); + loop->nod_arg[e_for_statement] = node; + SYN rel_node = input->syn_arg[s_asn_to]; + QLI_CTX context = (QLI_CTX) ALLOCD(type_ctx); node->nod_arg[e_sto_context] = (QLI_NOD) context; context->ctx_type = CTX_RELATION; context->ctx_rse = (QLI_NOD) - 1; - relation = context->ctx_relation = + QLI_REL relation = context->ctx_relation = (QLI_REL) rel_node->syn_arg[s_rel_relation]; -/* If we don't already know about the relation, find out now. */ +// If we don't already know about the relation, find out now. if (!(relation->rel_flags & REL_fields)) MET_fields(relation); @@ -1658,22 +1641,24 @@ static QLI_NOD expand_restructure( SYN input, LLS right, LLS left) /* Match fields in target relation against fields in the input rse. Fields may match on either name or query name. */ - stack = NULL; + LLS stack = NULL; - for (field = relation->rel_fields; field; field = field->fld_next) - if (!(field->fld_flags & FLD_computed)) { - for (search = right; search; search = search->lls_next) { - ctx = (QLI_CTX) search->lls_object; + for (QLI_FLD field = relation->rel_fields; field; field = field->fld_next) + if (!(field->fld_flags & FLD_computed)) + { + for (LLS search = right; search; search = search->lls_next) { + QLI_CTX ctx = (QLI_CTX) search->lls_object; - // First look for an exact field name match + // First look for an exact field name match + QLI_FLD fld; for (fld = ctx->ctx_relation->rel_fields; fld; - fld = fld->fld_next) + fld = fld->fld_next) { if (compare_symbols(field->fld_name, fld->fld_name)) break; } - // Next try, target field name matching source query name + // Next try, target field name matching source query name if (!fld) for (fld = ctx->ctx_relation->rel_fields; fld; @@ -1682,7 +1667,7 @@ static QLI_NOD expand_restructure( SYN input, LLS right, LLS left) if (compare_symbols(field->fld_name, fld->fld_query_name)) break; } - // If nothing yet, look for any old match + // If nothing yet, look for any old match if (!fld) for (fld = ctx->ctx_relation->rel_fields; fld; @@ -1698,7 +1683,7 @@ static QLI_NOD expand_restructure( SYN input, LLS right, LLS left) } if (fld) { - assignment = MAKE_NODE(nod_assign, e_asn_count); + QLI_NOD assignment = MAKE_NODE(nod_assign, e_asn_count); assignment->nod_count = e_asn_count - 1; assignment->nod_arg[e_asn_to] = make_field(field, context); @@ -1710,7 +1695,7 @@ static QLI_NOD expand_restructure( SYN input, LLS right, LLS left) if (ctx->ctx_rse) break; } - found_field:; + found_field:; } node->nod_arg[e_sto_statement] = make_list(stack); @@ -1732,32 +1717,27 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) * stack. * **************************************/ - QLI_NOD node, boolean, eql_node, *ptr2, *end, parent_rse, temp; - QLI_CTX context, parent_context; - SYN *ptr, over, field, rel_node, list, value; - SYM symbol; - QLI_REL relation; - LLS old_stack, new_stack, short_stack; - USHORT i, j; - + LLS old_stack, new_stack; old_stack = new_stack = *stack; - boolean = NULL; - node = MAKE_NODE(input->syn_type, (int) e_rse_count + input->syn_count); + QLI_NOD boolean = NULL; + QLI_NOD node = MAKE_NODE(input->syn_type, (int) e_rse_count + input->syn_count); node->nod_count = input->syn_count; - ptr2 = &node->nod_arg[e_rse_count]; + QLI_NOD* ptr2 = &node->nod_arg[e_rse_count]; /* Decide whether or not this is a GROUP BY, real or imagined If it is, disallow normal field type references */ - parent_context = NULL; - parent_rse = NULL; + QLI_CTX parent_context = NULL; + QLI_NOD parent_rse = NULL; if (input->syn_arg[s_rse_group_by] || input->syn_arg[s_rse_having]) parent_context = (QLI_CTX) ALLOCD(type_ctx); - if (list = input->syn_arg[s_rse_list]) { - for (i = 0; i < list->syn_count; i++) { - value = list->syn_arg[i]; - if (!(field = value->syn_arg[e_itm_value])) + SYN list = input->syn_arg[s_rse_list]; + if (list) { + for (USHORT i = 0; i < list->syn_count; i++) { + SYN value = list->syn_arg[i]; + SYN field = value->syn_arg[e_itm_value]; + if (!field) continue; if (global_agg(field, input->syn_arg[s_rse_group_by])) { if (!parent_context) @@ -1777,20 +1757,20 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) parent_context->ctx_sub_rse = node; } -// Process the FIRST clause before the context gets augmented +// Process the FIRST clause before the context gets augmented if (input->syn_arg[s_rse_first]) node->nod_arg[e_rse_first] = expand_expression(input->syn_arg[e_rse_first], old_stack); -// Process relations +// Process relations - ptr = input->syn_arg + s_rse_count; + SYN* ptr = input->syn_arg + s_rse_count; - for (i = 0; i < input->syn_count; i++) { - rel_node = *ptr++; - over = *ptr++; - context = (QLI_CTX) ALLOCD(type_ctx); + for (USHORT i = 0; i < input->syn_count; i++) { + SYN rel_node = *ptr++; + SYN over = *ptr++; + QLI_CTX context = (QLI_CTX) ALLOCD(type_ctx); *ptr2++ = (QLI_NOD) context; if (i == 0) context->ctx_rse = node; @@ -1800,20 +1780,20 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) } else { context->ctx_type = CTX_RELATION; - relation = context->ctx_relation = + QLI_REL relation = context->ctx_relation = (QLI_REL) rel_node->syn_arg[s_rel_relation]; if (!(relation->rel_flags & REL_fields)) MET_fields(relation); - symbol = context->ctx_symbol = + SYM symbol = context->ctx_symbol = (SYM) rel_node->syn_arg[s_rel_context]; if (symbol) symbol->sym_object = (BLK) context; if (over) { - short_stack = NULL; + LLS short_stack = NULL; LLS_PUSH(context, &short_stack); - for (j = 0; j < over->syn_count; j++) { - field = over->syn_arg[j]; - eql_node = MAKE_NODE(nod_eql, 2); + for (USHORT j = 0; j < over->syn_count; j++) { + syn* field = over->syn_arg[j]; + QLI_NOD eql_node = MAKE_NODE(nod_eql, 2); eql_node->nod_arg[0] = expand_expression(field, short_stack); eql_node->nod_arg[1] = @@ -1826,7 +1806,7 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) LLS_PUSH(context, &new_stack); } -// Handle explicit boolean +// Handle explicit boolean if (input->syn_arg[e_rse_boolean]) boolean = make_and(boolean, @@ -1836,7 +1816,7 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) /* Handle implicit boolean from SQL xxx IN (yyy FROM relation) */ if (input->syn_arg[s_rse_outer]) { - eql_node = MAKE_NODE((enum nod_t)(int)input->syn_arg[s_rse_op], 2); + QLI_NOD eql_node = MAKE_NODE((enum nod_t)(int)input->syn_arg[s_rse_op], 2); eql_node->nod_arg[0] = expand_expression(input->syn_arg[s_rse_outer], old_stack); eql_node->nod_arg[1] = @@ -1849,7 +1829,7 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) node->nod_arg[e_rse_boolean] = boolean; if (input->syn_arg[s_rse_sort]) { - temp = expand_sort(input->syn_arg[e_rse_sort], new_stack, 0); + QLI_NOD temp = expand_sort(input->syn_arg[e_rse_sort], new_stack, 0); if (parent_rse) parent_rse->nod_arg[e_rse_sort] = temp; else @@ -1871,16 +1851,19 @@ static QLI_NOD expand_rse( SYN input, LLS * stack) node->nod_arg[e_rse_join_type] = (QLI_NOD) input->syn_arg[s_rse_join_type]; -// If there is a parent context, set it up here +// If there is a parent context, set it up here *stack = new_stack; if (!parent_context) return node; + QLI_NOD *end; + QLI_CTX context = NULL; for (ptr2 = node->nod_arg + e_rse_count, end = ptr2 + node->nod_count; - ptr2 < end; ptr2++) { - context = (QLI_CTX) * ptr2; + ptr2 < end; ptr2++) + { + context = (QLI_CTX) *ptr2; context->ctx_parent = parent_context; } @@ -1912,25 +1895,20 @@ static QLI_NOD expand_sort( SYN input, LLS stack, QLI_NOD list) * number of keys. So be careful. * **************************************/ - ITM item; - SYN *syn_ptr, expr; - QLI_NOD node, *ptr; - USHORT i; - - node = MAKE_NODE(nod_list, input->syn_count); + QLI_NOD node = MAKE_NODE(nod_list, input->syn_count); node->nod_count = input->syn_count / 2; - ptr = node->nod_arg; - syn_ptr = input->syn_arg; + QLI_NOD* ptr = node->nod_arg; + SYN* syn_ptr = input->syn_arg; - for (i = 0; i < node->nod_count; i++) { - expr = *syn_ptr++; - if (expr->syn_type == nod_position) - { // FIXME: isn't plain 'unsigned long' better here? + for (USHORT i = 0; i < node->nod_count; i++) { + SYN expr = *syn_ptr++; + if (expr->syn_type == nod_position) { + // FIXME: isn't plain 'unsigned long' better here? // On 64bit platforms long is 64bit as well as pointer - ULONG position = (ULONG) expr->syn_arg[0]; + const ULONG position = (ULONG) expr->syn_arg[0]; if (!list || !position || position > list->nod_count) - IBERROR(152); // Msg152 invalid ORDER BY ordinal - item = (ITM) list->nod_arg[position - 1]; + IBERROR(152); // Msg152 invalid ORDER BY ordinal + ITM item = (ITM) list->nod_arg[position - 1]; *ptr++ = item->itm_value; } else @@ -2052,7 +2030,7 @@ static QLI_NOD expand_statement( SYN input, LLS right, LLS left) return NULL; default: - BUGCHECK(136); // Msg136 expand_statement: not yet implemented + BUGCHECK(136); // Msg136 expand_statement: not yet implemented } return (*routine) (input, right, left); @@ -2072,17 +2050,9 @@ static QLI_NOD expand_store( SYN input, LLS right, LLS left) * something neat if nothing looks obvious. * **************************************/ - QLI_NOD node, assignment, loop; - SYN rel_node; - QLI_REL relation; - QLI_FLD field; - SYM symbol; - QLI_CTX context, secondary; - LLS stack; + QLI_NOD loop = NULL; - loop = NULL; - -// If there is an rse, make up a FOR loop +// If there is an rse, make up a FOR loop if (input->syn_arg[s_sto_rse]) { loop = MAKE_NODE(nod_for, e_for_count); @@ -2090,31 +2060,35 @@ static QLI_NOD expand_store( SYN input, LLS right, LLS left) &right); } - node = MAKE_NODE(input->syn_type, e_sto_count); + QLI_NOD node = MAKE_NODE(input->syn_type, e_sto_count); - rel_node = input->syn_arg[s_sto_relation]; - context = (QLI_CTX) ALLOCD(type_ctx); + SYN rel_node = input->syn_arg[s_sto_relation]; + QLI_CTX context = (QLI_CTX) ALLOCD(type_ctx); node->nod_arg[e_sto_context] = (QLI_NOD) context; context->ctx_type = CTX_RELATION; context->ctx_rse = (QLI_NOD) - 1; - relation = context->ctx_relation = + QLI_REL relation = context->ctx_relation = (QLI_REL) rel_node->syn_arg[s_rel_relation]; if (!(relation->rel_flags & REL_fields)) MET_fields(relation); - if (symbol = context->ctx_symbol = (SYM) rel_node->syn_arg[s_rel_context]) + SYM symbol = context->ctx_symbol = (SYM) rel_node->syn_arg[s_rel_context]; + if (symbol) symbol->sym_object = (BLK) context; LLS_PUSH(context, &left); -// If there are field and value lists, process them +// If there are field and value lists, process them if (input->syn_arg[s_sto_values]) { if (!input->syn_arg[s_sto_fields]) { - stack = NULL; - for (field = relation->rel_fields; field; field = field->fld_next) + LLS stack = NULL; + for (QLI_FLD field = relation->rel_fields; field; + field = field->fld_next) + { LLS_PUSH(decompile_field(field, 0), &stack); + } input->syn_arg[s_sto_fields] = (SYN) stack; } expand_values(input, right); @@ -2124,7 +2098,7 @@ static QLI_NOD expand_store( SYN input, LLS right, LLS left) assignments. */ if (input->syn_arg[s_sto_statement]) { - secondary = (QLI_CTX) ALLOCD(type_ctx); + QLI_CTX secondary = (QLI_CTX) ALLOCD(type_ctx); secondary->ctx_type = CTX_RELATION; secondary->ctx_primary = context; LLS_PUSH(secondary, &right); @@ -2132,8 +2106,10 @@ static QLI_NOD expand_store( SYN input, LLS right, LLS left) expand_statement(input->syn_arg[s_sto_statement], right, left); } else { - stack = NULL; - for (field = relation->rel_fields; field; field = field->fld_next) { + LLS stack = NULL; + for (QLI_FLD field = relation->rel_fields; field; + field = field->fld_next) + { if (field->fld_flags & FLD_computed) continue; if ( @@ -2141,7 +2117,7 @@ static QLI_NOD expand_store( SYN input, LLS right, LLS left) && field->fld_system_flag != relation->rel_system_flag) || field->fld_flags & FLD_array) continue; - assignment = make_assignment(make_field(field, context), 0, 0); + QLI_NOD assignment = make_assignment(make_field(field, context), 0, 0); LLS_PUSH(assignment, &stack); } node->nod_arg[e_sto_statement] = make_list(stack); @@ -2167,9 +2143,9 @@ static void expand_values( SYN input, LLS right) * Functional description * We've got a grungy SQL insert, and we have * to make the value list match the field list. - * On the way in, we got the right number of + * On the way in, we got the right number of * fields. Now all that's needed is the values - * and matching the two lists, and generating + * and matching the two lists, and generating * assignments. If the input is from a select, * things may be harder, and if there are wild cards * things will be harder still. Wild cards come in @@ -2177,46 +2153,43 @@ static void expand_values( SYN input, LLS right) * a nod_prompt, the second a nod_star. * **************************************/ - SSHORT field_count, value_count; - SYN value, *ptr, list, assignment; - QLI_CTX context; - LLS stack, fields, values, temp; + SSHORT field_count = 0, value_count = 0; - field_count = value_count = 0; +// fields have already been checked and expanded. Just count them -// fields have already been checked and expanded. Just count them - - fields = (LLS) input->syn_arg[s_sto_fields]; + LLS fields = (LLS) input->syn_arg[s_sto_fields]; + LLS stack; for (stack = fields; stack; stack = stack->lls_next) field_count++; -/* We're going to want the values in the order listed in the command */ +// We're going to want the values in the order listed in the command - values = (LLS) input->syn_arg[s_sto_values]; + LLS values = (LLS) input->syn_arg[s_sto_values]; for (; values; LLS_PUSH(LLS_POP(&values), &stack)); -// now go through, count, and expand where needed +// now go through, count, and expand where needed while (stack) { - value = (SYN) LLS_POP(&stack); + SYN value = (SYN) LLS_POP(&stack); if (input->syn_arg[s_sto_rse] && value->syn_type == nod_prompt) { if (value->syn_arg[0] == 0) { - temp = NULL; + LLS temp = NULL; for (; right; right = right->lls_next) LLS_PUSH(right->lls_object, &temp); while (temp) { - context = (QLI_CTX) LLS_POP(&temp); + QLI_CTX context = (QLI_CTX) LLS_POP(&temp); value_count += generate_fields(context, (LLS) &values, input->syn_arg[s_sto_rse]); } } else - IBERROR(542); /* this was a prompting expression. won't do at all */ + IBERROR(542); // this was a prompting expression. won't do at all } else if (input->syn_arg[s_sto_rse] && (value->syn_type == nod_star)) { - if (!(context = find_context((NAM) value->syn_arg[0], right))) - IBERROR(154); // Msg154 unrecognized context + QLI_CTX context = find_context((NAM) value->syn_arg[0], right); + if (!context) + IBERROR(154); // Msg154 unrecognized context value_count += generate_fields(context, (LLS) &values, input->syn_arg[s_sto_rse]); } @@ -2226,19 +2199,21 @@ static void expand_values( SYN input, LLS right) } } -// Make assignments from values to fields +// Make assignments from values to fields if (field_count != value_count) - IBERROR(189); // Msg189 the number of values do not match the number of fields + IBERROR(189); + // Msg189 the number of values do not match the number of fields - list = (SYN) ALLOCDV(type_syn, value_count); + SYN list = (SYN) ALLOCDV(type_syn, value_count); list->syn_type = nod_list; list->syn_count = value_count; input->syn_arg[s_sto_statement] = list; - ptr = list->syn_arg + value_count; + SYN* ptr = list->syn_arg + value_count; while (values) { - *--ptr = assignment = (SYN) ALLOCDV(type_syn, s_asn_count); + SYN assignment = (SYN) ALLOCDV(type_syn, s_asn_count); + *--ptr = assignment; assignment->syn_type = nod_assign; assignment->syn_count = s_asn_count; assignment->syn_arg[s_asn_to] = (SYN) LLS_POP(&fields); @@ -2260,12 +2235,11 @@ static QLI_CTX find_context( NAM name, LLS contexts) * the context block implicated. * **************************************/ - QLI_REL relation; QLI_CTX context; for (; contexts; contexts = contexts->lls_next) { context = (QLI_CTX) contexts->lls_object; - relation = context->ctx_relation; + QLI_REL relation = context->ctx_relation; if (compare_names(name, relation->rel_symbol)) break; if (compare_names(name, context->ctx_symbol)) @@ -2290,24 +2264,21 @@ static int generate_fields( QLI_CTX context, LLS values, SYN rse) * input to a store or update. * **************************************/ - int count; - QLI_REL relation; - QLI_FLD field; - SYN value, group_list; - if (context->ctx_type == CTX_AGGREGATE) return 0; - group_list = rse->syn_arg[s_rse_group_by]; - relation = context->ctx_relation; - count = 0; + SYN group_list = rse->syn_arg[s_rse_group_by]; + QLI_REL relation = context->ctx_relation; + int count = 0; - for (field = relation->rel_fields; field; field = field->fld_next) { + for (QLI_FLD field = relation->rel_fields; field; field = field->fld_next) { if ( (field->fld_system_flag && field->fld_system_flag != relation->rel_system_flag) || field->fld_flags & FLD_array) + { continue; - value = decompile_field(field, context); + } + SYN value = decompile_field(field, context); if (group_list && invalid_syn_field(value, group_list)) continue; LLS_PUSH(value, (LLS*) values); @@ -2329,45 +2300,40 @@ static int generate_items( SYN symbol, LLS right, LLS items, QLI_NOD rse) * Functional description * Expand an asterisk expression, which * could be .* or .* or .* - * into a list of reasonable print items. + * into a list of reasonable print items. * * If the original request included a group by, * include only the grouping fields. * **************************************/ - int count; - QLI_REL relation; - QLI_CTX context; + int count = 0; + QLI_NOD group_list = (rse) ? rse->nod_arg[e_rse_group_by] : NULL; + +// first identify the relation or context + NAM name; - ITM item; - QLI_FLD field; - QLI_NOD node, group_list; - - count = 0; - group_list = (rse) ? rse->nod_arg[e_rse_group_by] : NULL; - -// first identify the relation or context - if (symbol->syn_count == 1) name = (NAM) symbol->syn_arg[0]; else - IBERROR(153); // Msg153 asterisk expressions require exactly one qualifying context + IBERROR(153); + // Msg153 asterisk expressions require exactly one qualifying context - if (!(context = find_context(name, right))) - IBERROR(154); // Msg154 unrecognized context + QLI_CTX context = find_context(name, right); + if (!context) + IBERROR(154); // Msg154 unrecognized context - relation = context->ctx_relation; + QLI_REL relation = context->ctx_relation; - for (field = relation->rel_fields; field; field = field->fld_next) { + for (QLI_FLD field = relation->rel_fields; field; field = field->fld_next) { if ( (field->fld_system_flag && field->fld_system_flag != relation->rel_system_flag) || field->fld_flags & FLD_array) continue; - node = make_field(field, context); + QLI_NOD node = make_field(field, context); if (group_list && invalid_nod_field(node, group_list)) continue; - item = (ITM) ALLOCD(type_itm); + ITM item = (ITM) ALLOCD(type_itm); item->itm_type = item_value; item->itm_value = make_field(field, context); expand_edit_string(item->itm_value, item); @@ -2392,7 +2358,7 @@ static bool global_agg( SYN item, SYN group_list) * a sql global aggregate. If it does, we're * going to make the whole thing a degenerate * group by. Anyway. Look for aggregates buried - * deep within printable things. + * deep within printable things. * * This recurses. If it finds a mixture of normal * and aggregates it complains. @@ -2422,7 +2388,8 @@ static bool global_agg( SYN item, SYN group_list) case nod_substr: { for (ptr = item->syn_arg, end = ptr + item->syn_count; ptr < end; - ptr++) { + ptr++) + { if ((*ptr)->syn_type == nod_constant) continue; if (global_agg(*ptr, group_list)) @@ -2455,22 +2422,20 @@ static bool invalid_nod_field( QLI_NOD node, QLI_NOD list) * * Validate that an expanded field / context * pair is in a specified list. Thus is used - * in one instance to check that a simple field selected - * through a grouping rse is a grouping field - + * in one instance to check that a simple field selected + * through a grouping rse is a grouping field - * thus a valid field reference. * **************************************/ - QLI_FLD field; - QLI_CTX context; - bool invalid = false; QLI_NOD *ptr, *end; + bool invalid = false; if (!list) return true; if (node->nod_type == nod_field) { - field = (QLI_FLD) node->nod_arg[e_fld_field]; - context = (QLI_CTX) node->nod_arg[e_fld_context]; + QLI_FLD field = (QLI_FLD) node->nod_arg[e_fld_field]; + QLI_CTX context = (QLI_CTX) node->nod_arg[e_fld_context]; for (ptr = list->nod_arg, end = ptr + list->nod_count; ptr < end; ptr++) if (field == (QLI_FLD) (*ptr)->nod_arg[e_fld_field] && context == (QLI_CTX) (*ptr)->nod_arg[e_fld_context]) @@ -2482,6 +2447,7 @@ static bool invalid_nod_field( QLI_NOD node, QLI_NOD list) else for (ptr = node->nod_arg, end = ptr + node->nod_count; ptr < end; ptr++) + { switch ((*ptr)->nod_type) { case nod_field: case nod_add: @@ -2497,6 +2463,7 @@ static bool invalid_nod_field( QLI_NOD node, QLI_NOD list) case nod_upcase: invalid |= invalid_nod_field(*ptr, list); } + } return invalid; } @@ -2511,21 +2478,19 @@ static bool invalid_syn_field( SYN syn_node, SYN list) ************************************** * * Functional description - * Make sure an unexpanded simple field selected - * through a grouping rse is a grouping field - + * Make sure an unexpanded simple field selected + * through a grouping rse is a grouping field - * thus a valid field reference. For the sake of * argument, we'll match qualified to unqualified * reference, but qualified reference must match - * completely. + * completely. * * One more thought. If this miserable thing is - * a wild card, let it through and expand it + * a wild card, let it through and expand it * correctly later. * **************************************/ - SYN element, *ptr, *end; - NAM gname, fname, gctx, fctx; - SSHORT count; + SYN *ptr, *end; bool invalid = false; if (syn_node->syn_type == nod_star) @@ -2535,24 +2500,24 @@ static bool invalid_syn_field( SYN syn_node, SYN list) return true; if (syn_node->syn_type == nod_field) { - fctx = NULL; - fname = (NAM) syn_node->syn_arg[0]; + NAM fctx = NULL; + NAM fname = (NAM) syn_node->syn_arg[0]; if (syn_node->syn_count == 2) { fctx = fname; fname = (NAM) syn_node->syn_arg[1]; } - for (count = list->syn_count; count;) { - gctx = NULL; - element = list->syn_arg[--count]; - gname = (NAM) element->syn_arg[0]; + for (SSHORT count = list->syn_count; count;) { + NAM gctx = NULL; + SYN element = list->syn_arg[--count]; + NAM gname = (NAM) element->syn_arg[0]; if (element->syn_count == 2) { gctx = gname; gname = (NAM) element->syn_arg[1]; } if (!strcmp(fname->nam_string, gname->nam_string)) if (!gctx || !fctx - || (!strcmp(fctx->nam_string, gctx->nam_string))) + || !strcmp(fctx->nam_string, gctx->nam_string)) { return false; } @@ -2562,6 +2527,7 @@ static bool invalid_syn_field( SYN syn_node, SYN list) else for (ptr = syn_node->syn_arg, end = ptr + syn_node->syn_count; ptr < end; ptr++) + { switch ((*ptr)->syn_type) { case nod_field: case nod_add: @@ -2577,6 +2543,7 @@ static bool invalid_syn_field( SYN syn_node, SYN list) case nod_upcase: invalid |= invalid_syn_field(*ptr, list); } + } return invalid; } @@ -2586,7 +2553,7 @@ static QLI_NOD make_and( QLI_NOD expr1, QLI_NOD expr2) { /************************************** * - * m a k e _ a n d + * m a k e _ a n d * ************************************** * @@ -2595,15 +2562,13 @@ static QLI_NOD make_and( QLI_NOD expr1, QLI_NOD expr2) * a single boolean. * **************************************/ - QLI_NOD node; - if (!expr1) return expr2; if (!expr2) return expr1; - node = MAKE_NODE(nod_and, 2); + QLI_NOD node = MAKE_NODE(nod_and, 2); node->nod_arg[0] = expr1; node->nod_arg[1] = expr2; @@ -2623,12 +2588,10 @@ static QLI_NOD make_assignment( QLI_NOD target, QLI_NOD initial, LLS right) * Generate a prompt and assignment to a field. * **************************************/ - QLI_NOD assignment, prompt; - QLI_FLD field; - LLS stack; + QLI_NOD prompt; - field = (QLI_FLD) target->nod_arg[e_fld_field]; - stack = NULL; + QLI_FLD field = (QLI_FLD) target->nod_arg[e_fld_field]; + LLS stack = NULL; LLS_PUSH(target->nod_arg[e_fld_context], &stack); if (field->fld_dtype == dtype_blob) { @@ -2646,7 +2609,7 @@ static QLI_NOD make_assignment( QLI_NOD target, QLI_NOD initial, LLS right) prompt->nod_arg[e_prm_field] = (QLI_NOD) field; } - assignment = MAKE_NODE(nod_assign, e_asn_count); + QLI_NOD assignment = MAKE_NODE(nod_assign, e_asn_count); assignment->nod_arg[e_asn_to] = target; assignment->nod_arg[e_asn_from] = prompt; @@ -2674,9 +2637,7 @@ static QLI_NOD make_field( QLI_FLD field, QLI_CTX context) * Make a field block. Not too tough. * **************************************/ - QLI_NOD node; - - node = MAKE_NODE(nod_field, e_fld_count); + QLI_NOD node = MAKE_NODE(nod_field, e_fld_count); node->nod_count = 0; node->nod_arg[e_fld_field] = (QLI_NOD) field; node->nod_arg[e_fld_context] = (QLI_NOD) context; @@ -2701,20 +2662,16 @@ static QLI_NOD make_list( LLS stack) * them first. * **************************************/ - QLI_NOD node, *ptr; - LLS temp; - USHORT count; - - temp = stack; - count = 0; + LLS temp = stack; + USHORT count = 0; while (temp) { count++; temp = temp->lls_next; } - node = MAKE_NODE(nod_list, count); - ptr = &node->nod_arg[count]; + QLI_NOD node = MAKE_NODE(nod_list, count); + QLI_NOD* ptr = &node->nod_arg[count]; while (stack) *--ptr = (QLI_NOD) LLS_POP(&stack); @@ -2735,9 +2692,7 @@ static QLI_NOD make_node( NOD_T type, USHORT count) * Allocate a node and fill in some basic stuff. * **************************************/ - QLI_NOD node; - - node = (QLI_NOD) ALLOCDV(type_nod, count); + QLI_NOD node = (QLI_NOD) ALLOCDV(type_nod, count); node->nod_type = type; node->nod_count = count; @@ -2757,9 +2712,7 @@ static QLI_NOD negate( QLI_NOD expr) * Build negation of expression. * **************************************/ - QLI_NOD node; - - node = MAKE_NODE(nod_not, 1); + QLI_NOD node = MAKE_NODE(nod_not, 1); node->nod_arg[0] = expr; return node; @@ -2782,12 +2735,7 @@ static QLI_NOD possible_literal(SYN input, * correct "informalities" in relational expressions. * **************************************/ - NAM name; - CON constant; - QLI_NOD node; QLI_CTX context; - USHORT l; - TEXT *p, *q, c; /* If the value isn't a field, is qualified, or can be resolved, it doesn't qualify for conversion. Return NULL. */ @@ -2796,30 +2744,30 @@ static QLI_NOD possible_literal(SYN input, input->syn_count != 1 || resolve(input, stack, &context)) return NULL; - name = (NAM) input->syn_arg[0]; - l = name->nam_length; - constant = (CON) ALLOCDV(type_con, l); + NAM name = (NAM) input->syn_arg[0]; + USHORT l = name->nam_length; + CON constant = (CON) ALLOCDV(type_con, l); constant->con_desc.dsc_dtype = dtype_text; constant->con_desc.dsc_length = l; - p = (TEXT *) constant->con_data; + TEXT* p = (TEXT *) constant->con_data; constant->con_desc.dsc_address = (UCHAR *) p; - q = name->nam_string; + const TEXT* q = name->nam_string; if (upper_flag) { if (l) do { - c = *q++; + const TEXT c = *q++; *p++ = UPPER(c); } while (--l); } else if (l) do { - c = *q++; + const TEXT c = *q++; *p++ = (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } while (--l); - node = MAKE_NODE(nod_constant, 0); + QLI_NOD node = MAKE_NODE(nod_constant, 0); node->nod_desc = constant->con_desc; return node; @@ -2838,23 +2786,22 @@ static QLI_NOD post_map( QLI_NOD node, QLI_CTX context) * Post an item to a map for a context. * **************************************/ - QLI_NOD new_node; - MAP map; + QLI_MAP map; -// Check to see if the item has already been posted +// Check to see if the item has already been posted for (map = context->ctx_map; map; map = map->map_next) if (CMP_node_match(node, map->map_node)) break; if (!map) { - map = (MAP) ALLOCD(type_map); + map = (QLI_MAP) ALLOCD(type_map); map->map_next = context->ctx_map; context->ctx_map = map; map->map_node = node; } - new_node = MAKE_NODE(nod_map, e_map_count); + QLI_NOD new_node = MAKE_NODE(nod_map, e_map_count); new_node->nod_count = 0; new_node->nod_arg[e_map_context] = (QLI_NOD) context; new_node->nod_arg[e_map_map] = (QLI_NOD) map; @@ -2878,8 +2825,6 @@ static QLI_FLD resolve( SYN node, LLS stack, QLI_CTX * out_context) * reference). Return NULL if field can't be resolved. * **************************************/ - NAM name, *base, *ptr; - QLI_CTX context; QLI_REL relation; QLI_FLD field; @@ -2888,18 +2833,19 @@ static QLI_FLD resolve( SYN node, LLS stack, QLI_CTX * out_context) that the context name be given explicitly (used for special STORE context). */ - base = (NAM *) node->syn_arg; + NAM* base = (NAM *) node->syn_arg; for (; stack; stack = stack->lls_next) { - *out_context = context = (QLI_CTX) stack->lls_object; - ptr = base + node->syn_count; - name = *--ptr; + QLI_CTX context = (QLI_CTX) stack->lls_object; + *out_context = context; + NAM* ptr = base + node->syn_count; + NAM name = *--ptr; switch (context->ctx_type) { case CTX_VARIABLE: if (ptr == base) for (field = context->ctx_variable; field; - field = field->fld_next) + field = field->fld_next) { if (compare_names(name, field->fld_name) || compare_names(name, field->fld_query_name)) @@ -2919,7 +2865,7 @@ static QLI_FLD resolve( SYN node, LLS stack, QLI_CTX * out_context) for (field = relation->rel_fields; field; field = field->fld_next) if (compare_names(name, field->fld_name) || - compare_names(name, field->fld_query_name)) + compare_names(name, field->fld_query_name)) { if (ptr == base) return field; @@ -2940,7 +2886,7 @@ static QLI_FLD resolve( SYN node, LLS stack, QLI_CTX * out_context) } } -/* We didn't resolve all name segments. Let somebody else worry about it. */ +// We didn't resolve all name segments. Let somebody else worry about it. return NULL; } @@ -2956,33 +2902,31 @@ static void resolve_really( QLI_FLD variable, SYN field_node) ************************************** * * Functional description - * Resolve a field reference entirely. + * Resolve a field reference entirely. * **************************************/ - USHORT offset; - bool resolved = false; - bool local = false; - NAM fld_name = NULL; - NAM rel_name = NULL; - NAM db_name = NULL; SYM symbol; - QLI_FLD field = NULL; QLI_REL relation; - DBB dbb; /* For ease, break down the syntax block. It should contain at least one name; two names are a potential ambiguity: check for a dbb (.), then for a rel (.). */ - offset = field_node->syn_count; - fld_name = (NAM) field_node->syn_arg[--offset]; + USHORT offset = field_node->syn_count; + NAM fld_name = (NAM) field_node->syn_arg[--offset]; + NAM rel_name = NULL; + NAM db_name = NULL; if (offset) { rel_name = (NAM) field_node->syn_arg[--offset]; if (offset) db_name = (NAM) field_node->syn_arg[--offset]; } + bool resolved = false; + bool local = false; + QLI_FLD field = NULL; + if (field_node->syn_count == 1) resolved = (MET_declare(0, variable, fld_name)); else if (field_node->syn_count == 2) { @@ -2990,31 +2934,30 @@ static void resolve_really( QLI_FLD variable, SYN field_node) symbol = symbol->sym_homonym) { if (symbol->sym_type == SYM_database) { - dbb = (DBB) symbol->sym_object; + DBB dbb = (DBB) symbol->sym_object; resolved = (MET_declare(dbb, variable, fld_name)); break; // should be only one db in homonym list } } if (!resolved) { - for (dbb = QLI_databases; dbb && !resolved; dbb = dbb->dbb_next) + for (DBB dbb = QLI_databases; dbb && !resolved; dbb = dbb->dbb_next) for (symbol = rel_name->nam_symbol; symbol; - symbol = symbol->sym_homonym) + symbol = symbol->sym_homonym) { if (symbol->sym_type == SYM_relation && (relation = (QLI_REL) symbol->sym_object) - && relation->rel_database == dbb) + && relation->rel_database == dbb) { if (!relation->rel_fields) MET_fields(relation); for (field = relation->rel_fields; field; - field = field->fld_next) + field = field->fld_next) { - if (resolved = local = compare_names (fld_name, - field->fld_name)) - { + resolved = local = compare_names(fld_name, + field->fld_name); + if (resolved) break; - } } break; // should be only one rel in homonym list for each db } @@ -3026,12 +2969,16 @@ static void resolve_really( QLI_FLD variable, SYN field_node) if (!relation->rel_fields) MET_fields(relation); for (field = relation->rel_fields; field; field = field->fld_next) - if (resolved = local = compare_names(fld_name, field->fld_name)) + { + resolved = local = compare_names(fld_name, field->fld_name); + if (resolved) break; + } } if (!resolved) - IBERROR(155); // Msg155 field referenced in BASED ON can not be resolved against readied databases + IBERROR(155); + // Msg155 field referenced in BASED ON can not be resolved against readied databases if (local) { variable->fld_dtype = field->fld_dtype; @@ -3047,3 +2994,6 @@ static void resolve_really( QLI_FLD variable, SYN field_node) variable->fld_query_name = field->fld_query_name; } } + + + diff --git a/src/qli/format.cpp b/src/qli/format.cpp index b29e716329..029454af4c 100644 --- a/src/qli/format.cpp +++ b/src/qli/format.cpp @@ -127,7 +127,7 @@ TEXT *FMT_format(LLS stack) USHORT j, l, n, lengths[10], *ptr; TEXT *p, *q, *segments[10]; -// Start by inverting the item stack into an item que +// Start by inverting the item stack into an item que LLS temp = stack; stack = NULL; @@ -191,7 +191,7 @@ TEXT *FMT_format(LLS stack) format_value(item, 0); - // If the item would overflow the line, reset to beginning of line + // If the item would overflow the line, reset to beginning of line if (offset + MAX(item->itm_print_length, item->itm_header_length) > QLI_columns) offset = 0; @@ -220,9 +220,9 @@ TEXT *FMT_format(LLS stack) } if (flag && (l = n)) { BOTTOM_CHECK(bottom, bottom - BOTTOM_LINE + n); - do + do { *bottom++ = '='; - while (--l); + } while (--l); } else { item->itm_query_header = NULL; @@ -240,7 +240,7 @@ TEXT *FMT_format(LLS stack) max_offset = MAX(max_offset, offset); } -// Make another pass checking for overlapping fields +// Make another pass checking for overlapping fields for (temp = stack; temp; temp = temp->lls_next) { item = (ITM) temp->lls_object; @@ -261,7 +261,7 @@ TEXT *FMT_format(LLS stack) if (number_segments == 0) return NULL; -// Allocate a string block big enough to hold all lines of the print header +// Allocate a string block big enough to hold all lines of the print header const ULONG size = (max_offset + 1) * (number_segments + 1) + 2; @@ -272,7 +272,7 @@ TEXT *FMT_format(LLS stack) STR header = (STR) ALLOCDV(type_str, size); p = header->str_data; -// Generate the various lines of the header line at a time. +// Generate the various lines of the header line at a time. for (j = 0; j < number_segments; j++) { *p++ = '\n'; @@ -292,20 +292,20 @@ TEXT *FMT_format(LLS stack) *p++ = ' '; q = segments[segment]; if (l) - do + do { *p++ = *q++; - while (--l); + } while (--l); } } -// Make one last pass to put in underlining of headers +// Make one last pass to put in underlining of headers if (l = bottom - BOTTOM_LINE) { *p++ = '\n'; bottom = BOTTOM_LINE; - do + do { *p++ = *bottom++; - while (--l); + } while (--l); } *p++ = '\n'; @@ -444,11 +444,11 @@ void FMT_print( QLI_NOD list, PRT print) RPT report; ISC_STATUS_ARRAY status_vector; -// Now go thru and make up the first line +// Now go thru and make up the first line if (!list) return; - + TEXT* buffer = NULL; TEXT* p = BUFFER_INIT; qli_nod** const end = list->nod_arg + list->nod_count; @@ -514,7 +514,7 @@ void FMT_print( QLI_NOD list, PRT print) while (p < q) *p++ = ' '; - // Next, handle simple formated values + // Next, handle simple formated values if (item->itm_dtype != dtype_blob) { desc = EVAL_value(item->itm_value); @@ -526,7 +526,7 @@ void FMT_print( QLI_NOD list, PRT print) continue; } - // Finally, handle blobs + // Finally, handle blobs if (!(item->itm_stream = EXEC_open_blob(item->itm_value))) continue; @@ -544,11 +544,11 @@ void FMT_print( QLI_NOD list, PRT print) put_line(print, &p, buffer, '\n'); -// Now go back until all blobs have been fetched +// Now go back until all blobs have been fetched print_blobs(print, (ITM*) list->nod_arg, (ITM*) end); -// Finish by closing all blobs +// Finish by closing all blobs for (ptr = list->nod_arg; ptr < end; ptr++) { ITM item = (ITM) *ptr; @@ -581,7 +581,7 @@ void FMT_put(const TEXT* line, PRT print) TEXT* const end = buffer + sizeof(buffer) - 1; const TEXT* q = line; TEXT* p; - + if (print && print->prt_file) while (*q) { for (p = buffer; p < end && *q;) @@ -596,7 +596,7 @@ void FMT_put(const TEXT* line, PRT print) *p = 0; #ifdef DEV_BUILD if (QLI_hex_output) { - // Hex mode output to assist debugging of multicharset work + // Hex mode output to assist debugging of multicharset work for (p = buffer; p < end && *p; p++) if (is_printable(*p)) @@ -652,7 +652,7 @@ void FMT_report( RPT report) report->rpt_column_header = format_report(columns_vec, width, &width); -// Handle report name, if any +// Handle report name, if any if (report->rpt_name) { const USHORT n = @@ -660,16 +660,16 @@ void FMT_report( RPT report) USHORT i; for (i = 0; i < n; i++) width = MAX(width, lengths[i] + 15); - + STR string = (STR) ALLOCDV(type_str, width * n); TEXT* p = string->str_data; report->rpt_header = p; for (i = 0; i < n; i++) { USHORT column = (width - lengths[i]) / 2; if (column > 0) - do + do { *p++ = ' '; - while (--column); + } while (--column); const TEXT* q = segments[i]; const TEXT* const end = q + lengths[i]; while (q < end) @@ -703,7 +703,7 @@ static int decompose_header(SCHAR* string, SSHORT n = 0; -// Handle simple name first +// Handle simple name first if (*string != '"' && *string != '\'') while (*string) { @@ -752,7 +752,7 @@ static void format_index( ITM item, QLI_NOD field, const bool print_flag) return; } -// Start the label with the current query header, if any +// Start the label with the current query header, if any USHORT l; const TEXT* q; @@ -771,7 +771,7 @@ static void format_index( ITM item, QLI_NOD field, const bool print_flag) while (l--) *p++ = *q++; -// Loop through the subscripts, adding to the label +// Loop through the subscripts, adding to the label const TEXT* r; if (print_flag) { @@ -780,7 +780,7 @@ static void format_index( ITM item, QLI_NOD field, const bool print_flag) } else r = "["; - + TEXT s[32]; QLI_NOD *ptr, *end; for (ptr = args->nod_arg, end = ptr + args->nod_count; ptr < end; ptr++) { @@ -799,7 +799,7 @@ static void format_index( ITM item, QLI_NOD field, const bool print_flag) break; default: - // Punt on anything but constants, fields, and variables + // Punt on anything but constants, fields, and variables ALL_release((FRB) str); return; @@ -956,14 +956,14 @@ static TEXT *format_report( VEC columns_vec, USHORT width, USHORT * max_width) if (number_segments == 0) return NULL; -// Allocate a string block big enough to hold all lines of the print header +// Allocate a string block big enough to hold all lines of the print header l = bottom - BOTTOM_LINE; STR header = (STR) ALLOCDV(type_str, (max_offset + 1) * (number_segments + 1) + 2 + l); p = header->str_data; -// Generate the various lines of the header line at a time. +// Generate the various lines of the header line at a time. for (j = 0; j < number_segments; j++) { *p++ = '\n'; @@ -988,21 +988,21 @@ static TEXT *format_report( VEC columns_vec, USHORT width, USHORT * max_width) *p++ = ' '; q = segments[segment]; if (l) - do + do { *p++ = *q++; - while (--l); + } while (--l); } } } -// Make one last pass to put in underlining of headers +// Make one last pass to put in underlining of headers if (l = bottom - BOTTOM_LINE) { *p++ = '\n'; bottom = BOTTOM_LINE; - do + do { *p++ = *bottom++; - while (--l); + } while (--l); } *p++ = '\n'; @@ -1055,7 +1055,7 @@ static void format_value( ITM item, int flags) field = (QLI_FLD) node->nod_arg[e_fld_field]; if ((field->fld_flags & FLD_array) && !node->nod_arg[e_fld_subs]) ERRQ_print_error(480, field->fld_name->sym_string, NULL, NULL, - NULL, NULL); /* msg 480 can not format unsubscripted array %s */ + NULL, NULL); // msg 480 can not format unsubscripted array %s } if (!(item->itm_picture->pic_missing) && @@ -1099,9 +1099,9 @@ static TEXT* get_buffer(STR* str, TEXT* ptr, USHORT length) const TEXT* q = (*str)->str_data; if (ptr && (l = ptr - q)) - do + do { *p++ = *q++; - while (--l); + } while (--l); ALL_release((FRB) *str); *str = temp_str; @@ -1124,7 +1124,7 @@ static int match_expr( QLI_NOD node1, QLI_NOD node2) **************************************/ QLI_NOD *ptr1, *ptr2, *end; -/* If either is missing, they can't match. */ +// If either is missing, they can't match. if (!node1 || !node2) return FALSE; @@ -1135,12 +1135,12 @@ static int match_expr( QLI_NOD node1, QLI_NOD node2) if (node2->nod_type == nod_reference) node2 = node2->nod_arg[0]; -// A constant more or less matches anything +// A constant more or less matches anything if (node1->nod_type == nod_constant) return TRUE; -/* Hasn't matched yet. Check for statistical expression */ +// Hasn't matched yet. Check for statistical expression switch (node1->nod_type) { case nod_average: @@ -1273,7 +1273,7 @@ static int print_line( ITM item, TEXT ** ptr) EXEC_poll_abort(); -/* If we're already at end of stream, there's nothing to do */ +// If we're already at end of stream, there's nothing to do if (!item->itm_stream) return EOF; @@ -1383,7 +1383,7 @@ static void report_item( ITM item, VEC * columns_vec, USHORT * col_ndx) if (item->itm_query_header && *item->itm_query_header == '-') item->itm_query_header = NULL; -/* If it's a constant, dump it in the next logical column */ +// If it's a constant, dump it in the next logical column columns = *columns_vec; if (columns->vec_object[*col_ndx] && @@ -1408,7 +1408,7 @@ static void report_item( ITM item, VEC * columns_vec, USHORT * col_ndx) } } -/* Didn't fit -- make a new logical column */ +// Didn't fit -- make a new logical column *col_ndx = new_index = col - (LLS *) columns->vec_object; if (new_index >= columns->vec_count) { @@ -1449,3 +1449,4 @@ static void report_line( QLI_NOD list, VEC * columns_vec) } } + diff --git a/src/qli/format.h b/src/qli/format.h index 8391f3361b..c5eabda77a 100644 --- a/src/qli/format.h +++ b/src/qli/format.h @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_FORMAT_H_ -#define _QLI_FORMAT_H_ +#ifndef QLI_FORMAT_H +#define QLI_FORMAT_H /* Logical column block */ @@ -116,4 +116,4 @@ typedef struct pics { #define PIC_literal 2 /* We're in a quoted string */ #define PIC_signed 4 /* This numeric edit string has a sign indicator */ -#endif /* _QLI_FORMAT_H_ */ +#endif /* QLI_FORMAT_H */ diff --git a/src/qli/gener.cpp b/src/qli/gener.cpp index 855ecf6397..fe32d0466b 100644 --- a/src/qli/gener.cpp +++ b/src/qli/gener.cpp @@ -21,7 +21,7 @@ * Contributor(s): ______________________________________. */ /* -$Id: gener.cpp,v 1.22 2003-09-15 12:30:28 robocop Exp $ +$Id: gener.cpp,v 1.23 2003-09-25 11:49:07 robocop Exp $ */ #include "firebird.h" @@ -56,7 +56,7 @@ static void gen_for(QLI_NOD, QLI_REQ); static void gen_function(QLI_NOD, QLI_REQ); static void gen_if(QLI_NOD, QLI_REQ); static void gen_literal(const dsc*, QLI_REQ); -static void gen_map(MAP, QLI_REQ); +static void gen_map(QLI_MAP, QLI_REQ); static void gen_modify(QLI_NOD, QLI_REQ); static void gen_parameter(PAR, QLI_REQ); static void gen_print_list(QLI_NOD, QLI_REQ); @@ -128,7 +128,7 @@ RLB GEN_rlb_extend(RLB rlb) ************************************** * * Functional description - * + * * Allocate a new larger request language buffer * and copy generated request language into it * @@ -161,7 +161,7 @@ void GEN_rlb_release( RLB rlb) ************************************** * * Functional description - * + * * Release the request language buffer * contents. The buffer itself will go away * with the default pool. @@ -191,7 +191,7 @@ static void explain(const UCHAR* explain_buffer) ************************************** * * Functional description - * Print out the access path for a blr + * Print out the access path for a blr * request in pretty-printed form. * **************************************/ @@ -243,7 +243,7 @@ static void explain(const UCHAR* explain_buffer) case gds_info_rsb_indexed: ib_printf("gds_info_rsb_indexed,\n"); level++; - explain_index_tree(level, relation_name, + explain_index_tree(level, relation_name, reinterpret_cast(&explain_buffer), &buffer_length); level--; @@ -521,14 +521,14 @@ static void gen_assignment( QLI_NOD node, QLI_REQ request) **************************************/ qli_nod* from = node->nod_arg[e_asn_from]; -// Handle a local expression locally +// Handle a local expression locally if (node->nod_flags & NOD_local) { gen_expression(from, 0); return; } -// Generate a remote assignment +// Generate a remote assignment RLB rlb = CHECK_RLB(request->req_blr); @@ -603,7 +603,7 @@ static void gen_compile( QLI_REQ request) DBB dbb = request->req_database; if (gds__compile_request(status_vector, &dbb->dbb_handle, - &request->req_handle, length, + &request->req_handle, length, (char*) rlb->rlb_base)) { RELEASE_RLB; ERRQ_database_error(dbb, status_vector); @@ -698,7 +698,7 @@ static void gen_descriptor(const dsc* desc, QLI_REQ request) break; default: - BUGCHECK(352); // Msg352 gen_descriptor: dtype not recognized + BUGCHECK(352); // Msg352 gen_descriptor: dtype not recognized } } @@ -743,7 +743,7 @@ static void gen_expression( QLI_NOD node, QLI_REQ request) **************************************/ QLI_NOD *ptr, *end; QLI_CTX context; - MAP map; + QLI_MAP map; USHORT operatr; RLB rlb; @@ -779,7 +779,7 @@ static void gen_expression( QLI_NOD node, QLI_REQ request) return; case nod_map: - map = (MAP) node->nod_arg[e_map_map]; + map = (QLI_MAP) node->nod_arg[e_map_map]; context = (QLI_CTX) node->nod_arg[e_map_context]; if (context->ctx_request != request && map->map_node->nod_type == nod_field) { @@ -944,7 +944,7 @@ static void gen_expression( QLI_NOD node, QLI_REQ request) gen_parameter(node->nod_export, request); return; } - BUGCHECK(353); // Msg353 gen_expression: not understood + BUGCHECK(353); // Msg353 gen_expression: not understood } if (request) { @@ -974,7 +974,7 @@ static void gen_field( QLI_NOD node, QLI_REQ request) * requests or not. * **************************************/ -/* If there isn't a request specified, this is a reference. */ +// If there isn't a request specified, this is a reference. if (!request) return; @@ -1042,12 +1042,12 @@ static void gen_for( QLI_NOD node, QLI_REQ request) if (message = (QLI_MSG) node->nod_arg[e_for_receive]) STUFF(blr_begin); -// If there is a message to be sent, build a receive for it +// If there is a message to be sent, build a receive for it if (node->nod_arg[e_for_send]) gen_send_receive((QLI_MSG) node->nod_arg[e_for_send], blr_receive); -// Generate the FOR loop proper. +// Generate the FOR loop proper. STUFF(blr_for); gen_rse(node->nod_arg[e_for_rse], request); @@ -1062,7 +1062,7 @@ static void gen_for( QLI_NOD node, QLI_REQ request) gen_send_receive(message, blr_send); STUFF(blr_begin); - // Build assigments for all values referenced. + // Build assigments for all values referenced. for (PAR parameter = message->msg_parameters; parameter; parameter = parameter->par_next) @@ -1074,7 +1074,7 @@ static void gen_for( QLI_NOD node, QLI_REQ request) } } - // Next, make a FALSE for the end of file parameter + // Next, make a FALSE for the end of file parameter eof = (PAR) node->nod_arg[e_for_eof]; desc.dsc_dtype = dtype_short; @@ -1091,7 +1091,7 @@ static void gen_for( QLI_NOD node, QLI_REQ request) STUFF(blr_end); } -// Build the body of the loop. +// Build the body of the loop. QLI_MSG continuation = request->req_continue; if (continuation) { @@ -1113,7 +1113,7 @@ static void gen_for( QLI_NOD node, QLI_REQ request) if (continuation) STUFF(blr_end); -// Finish off by building a SEND to indicate end of file +// Finish off by building a SEND to indicate end of file if (message) { gen_send_receive(message, blr_send); @@ -1124,7 +1124,7 @@ static void gen_for( QLI_NOD node, QLI_REQ request) STUFF(blr_end); } -// If this is our request, compile it. +// If this is our request, compile it. if (node->nod_arg[e_for_request]) gen_compile(request); @@ -1167,7 +1167,7 @@ static void gen_function( QLI_NOD node, QLI_REQ request) else rlb = CHECK_RLB(request->req_blr); -// Generate function body +// Generate function body STUFF(blr_function); FUN function = (FUN) node->nod_arg[e_fun_function]; @@ -1176,7 +1176,7 @@ static void gen_function( QLI_NOD node, QLI_REQ request) for (const UCHAR* p = (UCHAR *) symbol->sym_string; *p;) STUFF(*p++); -// Generate function arguments +// Generate function arguments QLI_NOD args = node->nod_arg[e_fun_args]; STUFF(args->nod_count); @@ -1284,14 +1284,14 @@ static void gen_literal(const dsc* desc, QLI_REQ request) default: if (l) - do + do { STUFF(*p++); - while (--l); + } while (--l); } } -static void gen_map( MAP map, QLI_REQ request) +static void gen_map(QLI_MAP map, QLI_REQ request) { /************************************** * @@ -1303,7 +1303,7 @@ static void gen_map( MAP map, QLI_REQ request) * Generate a value map for a record selection expression. * **************************************/ - MAP temp; + QLI_MAP temp; RLB rlb = CHECK_RLB(request->req_blr); @@ -1332,7 +1332,7 @@ static void gen_modify( QLI_NOD node, QLI_REQ org_request) ************************************** * * Functional description - * Generate a MODIFY statement. + * Generate a MODIFY statement. * **************************************/ QLI_NOD *ptr, *end; @@ -1459,7 +1459,7 @@ static void gen_request( QLI_REQ request) STUFF(blr_version4); STUFF(blr_begin); -// Build declarations for all messages. +// Build declarations for all messages. for (QLI_MSG message = request->req_messages; message; message = message->msg_next) @@ -1523,7 +1523,7 @@ static void gen_rse( QLI_NOD node, QLI_REQ request) STUFF(blr_rs_stream); STUFF(node->nod_count); -// Check for aggregate case +// Check for aggregate case QLI_CTX context = (QLI_CTX) node->nod_arg[e_rse_count]; @@ -1553,7 +1553,7 @@ static void gen_rse( QLI_NOD node, QLI_REQ request) return; } -// Make relation clauses for all relations +// Make relation clauses for all relations for (ptr = &node->nod_arg[e_rse_count], end = ptr + node->nod_count; ptr < end; ptr++) @@ -1569,7 +1569,7 @@ static void gen_rse( QLI_NOD node, QLI_REQ request) } } -// Handle various clauses +// Handle various clauses if (list = node->nod_arg[e_rse_first]) { STUFF(blr_first); @@ -1726,7 +1726,7 @@ static void gen_statement( QLI_NOD node, QLI_REQ request) return; default: - BUGCHECK(354); // Msg354 gen_statement: not yet implemented + BUGCHECK(354); // Msg354 gen_statement: not yet implemented } } @@ -1800,7 +1800,7 @@ static void gen_statistical( QLI_NOD node, QLI_REQ request) break; default: - BUGCHECK(355); // Msg355 gen_statistical: not understood + BUGCHECK(355); // Msg355 gen_statistical: not understood } /* If there is a request associated with the statement, prepare to @@ -1863,12 +1863,12 @@ static void gen_store( QLI_NOD node, QLI_REQ request) RLB rlb = CHECK_RLB(request->req_blr); -// If there is a message to be sent, build a receive for it +// If there is a message to be sent, build a receive for it if (node->nod_arg[e_sto_send]) gen_send_receive((QLI_MSG) node->nod_arg[e_sto_send], blr_receive); -// Generate the STORE statement proper. +// Generate the STORE statement proper. STUFF(blr_store); QLI_CTX context = (QLI_CTX) node->nod_arg[e_sto_context]; @@ -1877,15 +1877,16 @@ static void gen_store( QLI_NOD node, QLI_REQ request) STUFF_WORD(relation->rel_id); STUFF(context->ctx_context); -// Build the body of the loop. +// Build the body of the loop. STUFF(blr_begin); gen_statement(node->nod_arg[e_sto_statement], request); STUFF(blr_end); -// If this is our request, compile it. +// If this is our request, compile it. if (node->nod_arg[e_sto_request]) gen_compile(request); } + diff --git a/src/qli/help.epp b/src/qli/help.epp index e87527f14a..e57c71b2a1 100644 --- a/src/qli/help.epp +++ b/src/qli/help.epp @@ -133,7 +133,7 @@ static int additional_topics( TEXT * parent, TEXT * banner, TEXT * string) **************************************/ TEXT line[256]; -/* Print list of know topics. When we find the first, +/* Print list of know topics. When we find the first, print the banner, if any */ TEXT* ptr = line; @@ -161,9 +161,9 @@ static int additional_topics( TEXT * parent, TEXT * banner, TEXT * string) while (ptr < p) *ptr++ = ' '; p = X.TOPIC; - do + do { *ptr++ = *p++; - while (--l); + } while (--l); *ptr++ = ' '; END_FOR; @@ -199,12 +199,12 @@ static void print_more( ERRQ_msg_get(502, prompt); /* Msg502 "Subtopic? " */ -// Prompt the user for a line +// Prompt the user for a line if (!LEX_get_line(prompt, buffer, sizeof(buffer))) return; -// Upcase the response and zap the blanks +// Upcase the response and zap the blanks topics[1] = p = topic; @@ -213,7 +213,7 @@ static void print_more( *p++ = UPPER(*q); *p = 0; -// If we got anything, print the new topic +// If we got anything, print the new topic if (p != topic) print_topic(level + 1, depth + 1, topics + 1, max_level, parent, @@ -244,7 +244,7 @@ static void print_topic( TEXT string[128], banner[128], *next, *p, *q, *path, buffer[128], prompt[80]; -// Copy the parent string inserting a blank at the end +// Copy the parent string inserting a blank at the end p = string; @@ -272,7 +272,7 @@ static void print_topic( FOR(LEVEL level) X IN TOPICS WITH X.FACILITY EQ "QLI" AND (X.TOPIC STARTING WITH * topics AND X.PARENT EQ parent) OR (X.TOPIC = X.FACILITY AND X.TOPIC = *topics AND X.TOPIC = X.PARENT) - SORTED BY X.TOPIC + SORTED BY X.TOPIC if (QLI_abort) return; @@ -303,7 +303,7 @@ static void print_topic( ib_printf("%s%s", INDENT, B.SEGMENT); END_FOR; ERRQ_msg_format(81, sizeof(banner), banner, INDENT, NULL, NULL, - NULL, NULL); /* Msg81 %sSub-topics available: */ + NULL, NULL); // Msg81 %sSub-topics available: if (additional_topics(string, banner, INDENT)) print_more(level, depth, topics, max_level, string, error_flag); @@ -312,8 +312,8 @@ static void print_topic( if (!count && error_flag && level > *max_level) { path = strip(parent); - ERRQ_msg_put(82, path, *topics, NULL, NULL, NULL); /* Msg82 No help is available for %s %s */ - ERRQ_msg_format(83, sizeof(banner), banner, path, NULL, NULL, NULL, NULL); /* Msg83 Sub-topics available for %s are: */ + ERRQ_msg_put(82, path, *topics, NULL, NULL, NULL); // Msg82 No help is available for %s %s + ERRQ_msg_format(83, sizeof(banner), banner, path, NULL, NULL, NULL, NULL); // Msg83 Sub-topics available for %s are: additional_topics(parent, banner, path); } } @@ -345,3 +345,4 @@ static TEXT *strip( TEXT * string) return p; } + diff --git a/src/qli/help_proto.h b/src/qli/help_proto.h index 0ad72d9748..35e60f9e10 100644 --- a/src/qli/help_proto.h +++ b/src/qli/help_proto.h @@ -21,10 +21,10 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_HELP_PROTO_H_ -#define _QLI_HELP_PROTO_H_ +#ifndef QLI_HELP_PROTO_H +#define QLI_HELP_PROTO_H extern void HELP_fini (void); extern void HELP_help(syn*); -#endif /* _QLI_HELP_PROTO_H_ */ +#endif /* QLI_HELP_PROTO_H */ diff --git a/src/qli/hsh.cpp b/src/qli/hsh.cpp index a45a993db1..a47ea2b419 100644 --- a/src/qli/hsh.cpp +++ b/src/qli/hsh.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: hsh.c + * MODULE: hsh.cpp * DESCRIPTION: Hash table and symbol manager * * The contents of this file are subject to the Interbase Public @@ -28,18 +28,20 @@ #include "../qli/err_proto.h" #include "../qli/hsh_proto.h" -#define HASH_SIZE 224 - -static int hash(SCHAR *, int); -static bool scompare(SCHAR *, int, SCHAR *, int); +static int hash(const SCHAR*, int); +static bool scompare(const SCHAR*, int, const SCHAR*, int); +const int HASH_SIZE = 224; static SYM hash_table[HASH_SIZE]; static SYM key_symbols; -struct word_t { +struct qli_kword { KWWORDS id; SCHAR *keyword; -} keywords[] = { +}; + +const qli_kword keywords[] = +{ #include "../qli/words.h" {KW_continuation, "-\n"} }; @@ -57,10 +59,8 @@ void HSH_fini(void) * Release space used by keywords. * **************************************/ - SYM symbol; - while (key_symbols) { - symbol = key_symbols; + SYM symbol = key_symbols; key_symbols = (SYM) key_symbols->sym_object; HSH_remove(symbol); ALL_release((FRB) symbol); @@ -81,18 +81,17 @@ void HSH_init(void) * inserting all known keywords. * **************************************/ - SCHAR *string; - SYM symbol; - int i; - word_t* word; + const qli_kword* qword = keywords; - for (i = 0, word = keywords; i < FB_NELEM(keywords); i++, word++) { - for (string = word->keyword; *string; string++); - symbol = (SYM) ALLOCPV(type_sym, 0); + for (int i = 0; i < FB_NELEM(keywords); i++, qword++) { + const SCHAR* string = qword->keyword; + while (*string) + ++string; + SYM symbol = (SYM) ALLOCPV(type_sym, 0); symbol->sym_type = SYM_keyword; - symbol->sym_length = string - word->keyword; - symbol->sym_string = word->keyword; - symbol->sym_keyword = (int) word->id; + symbol->sym_length = string - qword->keyword; + symbol->sym_string = qword->keyword; + symbol->sym_keyword = (int) qword->id; HSH_insert(symbol); symbol->sym_object = (BLK) key_symbols; key_symbols = symbol; @@ -112,14 +111,12 @@ void HSH_insert( SYM symbol) * Insert a symbol into the hash table. * **************************************/ - int h; - SYM old; + const int h = hash(symbol->sym_string, symbol->sym_length); - h = hash(symbol->sym_string, symbol->sym_length); - - for (old = hash_table[h]; old; old = old->sym_collision) + for (SYM old = hash_table[h]; old; old = old->sym_collision) if (scompare(symbol->sym_string, symbol->sym_length, - old->sym_string, old->sym_length)) { + old->sym_string, old->sym_length)) + { symbol->sym_homonym = old->sym_homonym; old->sym_homonym = symbol; return; @@ -130,7 +127,7 @@ void HSH_insert( SYM symbol) } -SYM HSH_lookup(SCHAR * string, int length) +SYM HSH_lookup(const SCHAR* string, int length) { /************************************** * @@ -142,13 +139,12 @@ SYM HSH_lookup(SCHAR * string, int length) * Perform a string lookup against hash table. * **************************************/ - SYM symbol; - - for (symbol = hash_table[hash(string, length)]; symbol; + for (SYM symbol = hash_table[hash(string, length)]; symbol; symbol = symbol->sym_collision) - if (scompare - (string, length, symbol->sym_string, - symbol->sym_length)) return symbol; + { + if (scompare(string, length, symbol->sym_string, symbol->sym_length)) + return symbol; + } return NULL; } @@ -158,7 +154,7 @@ void HSH_remove( SYM symbol) { /************************************** * - * H S H _ r e m o v e + * H S H _ r e m o v e * ************************************** * @@ -166,12 +162,11 @@ void HSH_remove( SYM symbol) * Remove a symbol from the hash table. * **************************************/ - int h; - SYM *next, *ptr, homonym; + SYM *ptr, homonym; - h = hash(symbol->sym_string, symbol->sym_length); + const int h = hash(symbol->sym_string, symbol->sym_length); - for (next = &hash_table[h]; *next; next = &(*next)->sym_collision) + for (SYM* next = &hash_table[h]; *next; next = &(*next)->sym_collision) if (symbol == *next) if (homonym = symbol->sym_homonym) { homonym->sym_collision = symbol->sym_collision; @@ -189,11 +184,11 @@ void HSH_remove( SYM symbol) return; } - ERRQ_error(27, NULL, NULL, NULL, NULL, NULL); // Msg 27 HSH_remove failed + ERRQ_error(27, NULL, NULL, NULL, NULL, NULL); // Msg 27 HSH_remove failed } -static int hash( SCHAR * string, int length) +static int hash(const SCHAR* string, int length) { /************************************** * @@ -205,13 +200,10 @@ static int hash( SCHAR * string, int length) * Returns the hash function of a string. * **************************************/ - int value; - SCHAR c; - - value = 0; + int value = 0; while (length--) { - c = *string++; + const SCHAR c = *string++; value = (value << 1) + UPPER(c); } @@ -219,9 +211,9 @@ static int hash( SCHAR * string, int length) } -static bool scompare(SCHAR * string1, +static bool scompare(const SCHAR* string1, int length1, - SCHAR * string2, + const SCHAR* string2, int length2) { /************************************** @@ -234,14 +226,18 @@ static bool scompare(SCHAR * string1, * Compare two strings * **************************************/ - SCHAR c1, c2; - if (length1 != length2) return false; while (length1--) - if ((c1 = *string1++) != (c2 = *string2++) && UPPER(c1) != UPPER(c2)) + { + const SCHAR c1 = *string1++; + const SCHAR c2 = *string2++; + if (c1 != c2 && UPPER(c1) != UPPER(c2)) return false; + } return true; } + + diff --git a/src/qli/hsh_proto.h b/src/qli/hsh_proto.h index 56a8729e52..9c4e40fd31 100644 --- a/src/qli/hsh_proto.h +++ b/src/qli/hsh_proto.h @@ -1,7 +1,7 @@ /* * PROGRAM: JRD Command Oriented Query Language * MODULE: hsh_proto.h - * DESCRIPTION: Prototype header file for hsh.c + * DESCRIPTION: Prototype header file for hsh.cpp * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file @@ -27,7 +27,8 @@ extern void HSH_fini (void); extern void HSH_init (void); extern void HSH_insert(sym*); -extern sym* HSH_lookup(SCHAR*, int); +extern sym* HSH_lookup(const SCHAR*, int); extern void HSH_remove(sym*); #endif /* QLI_HSH_PROTO_H */ + diff --git a/src/qli/lex.cpp b/src/qli/lex.cpp index ef9bcdfadd..ca90c80b8e 100644 --- a/src/qli/lex.cpp +++ b/src/qli/lex.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: lex.c + * MODULE: lex.cpp * DESCRIPTION: Lexical analyser * * The contents of this file are subject to the Interbase Public @@ -39,6 +39,7 @@ #include "../qli/proc_proto.h" #include "../jrd/gds_proto.h" #include "../jrd/utl_proto.h" +#include "../jrd/gdsassert.h" #ifdef HAVE_UNISTD_H #include @@ -77,40 +78,39 @@ extern bool sw_verify; extern bool sw_trace; static bool get_line(IB_FILE *, TEXT *, USHORT); -static int nextchar(bool); -static void next_line(bool); -static void retchar(SSHORT); +static int nextchar(const bool); +static void next_line(const bool); +static void retchar(const SSHORT); static bool scan_number(SSHORT, TEXT **); static int skip_white(void); static LLS QLI_statements; static int QLI_position; static IB_FILE *input_file = NULL, *trace_file = NULL; -static UCHAR trace_file_name[128]; +static char trace_file_name[MAXPATHLEN]; static SLONG trans_limit; #define TRANS_LIMIT 10 -#define CHR_ident 1 -#define CHR_letter 2 -#define CHR_digit 4 -#define CHR_quote 8 -#define CHR_white 16 -#define CHR_eol 32 +const char CHR_ident = char(1); +const char CHR_letter = char(2); +const char CHR_digit = char(4); +const char CHR_quote = char(8); +const char CHR_white = char(16); +const char CHR_eol = char(32); -#define CHR_IDENT CHR_ident -#define CHR_LETTER CHR_letter + CHR_ident -#define CHR_DIGIT CHR_digit + CHR_ident -#define CHR_QUOTE CHR_quote -#define CHR_WHITE CHR_white -#define CHR_EOL CHR_eol +const char CHR_IDENT = CHR_ident; +const char CHR_LETTER = CHR_letter + CHR_ident; +const char CHR_DIGIT = CHR_digit + CHR_ident; +const char CHR_QUOTE = CHR_quote; +const char CHR_WHITE = CHR_white; +const char CHR_EOL = CHR_eol; -#ifdef NOT_USED_OR_REPLACED -static SCHAR *eol_string = "*end_of_line*"; -#endif -static SCHAR *eof_string = "*end_of_file*"; +static const char* const eol_string = "end of line"; +static const char* const eof_string = "*end_of_file*"; -static SCHAR classes[256] = { +static const char classes[256] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 0, CHR_WHITE, CHR_EOL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -170,24 +170,22 @@ void LEX_edit( SLONG start, SLONG stop) * push the scratch file on the input stack. * **************************************/ - IB_FILE *scratch; - TEXT filename[128]; - SSHORT c; + TEXT filename[MAXPATHLEN]; - scratch = (IB_FILE *) gds__temp_file(TRUE, SCRATCH, filename); + IB_FILE* scratch = (IB_FILE*) gds__temp_file(TRUE, SCRATCH, filename); if (scratch == (IB_FILE *) - 1) - IBERROR(61); /* Msg 61 couldn't open scratch file */ + IBERROR(61); // Msg 61 couldn't open scratch file #ifdef WIN_NT stop--; #endif if (ib_fseek(trace_file, start, 0)) { ib_fseek(trace_file, (SLONG) 0, 2); - IBERROR(59); // Msg 59 ib_fseek failed + IBERROR(59); // Msg 59 ib_fseek failed } while (++start <= stop) { - c = ib_getc(trace_file); + const SSHORT c = ib_getc(trace_file); if (c == EOF) break; ib_putc(c, scratch); @@ -216,16 +214,13 @@ TOK LEX_edit_string(void) * Parse the next token as an edit_string. * **************************************/ - TOK token; - SSHORT c, d; - TEXT *p; + SSHORT c; + TOK token = QLI_token; - token = QLI_token; - - do + do { c = skip_white(); - while (c == '\n'); - p = token->tok_string; + } while (c == '\n'); + TEXT* p = token->tok_string; *p = c; if (!QLI_line) { @@ -238,7 +233,8 @@ TOK LEX_edit_string(void) *p++ = c; if (classes[c] & CHR_quote) for (;;) { - if ((d = nextchar(false)) == '\n') { + const SSHORT d = nextchar(false); + if (d == '\n') { retchar(d); break; } @@ -278,20 +274,17 @@ TOK LEX_filename(void) * Parse the next token as a filename. * **************************************/ - TOK token; - SSHORT c, save; - USHORT class_; - TEXT *p; + SSHORT c; - token = QLI_token; + TOK token = QLI_token; - do + do { c = skip_white(); - while (c == '\n'); - p = token->tok_string; + } while (c == '\n'); + TEXT* p = token->tok_string; *p++ = c; -/* If there isn't a line, we're all done */ +// If there isn't a line, we're all done if (!QLI_line) { token->tok_symbol = NULL; @@ -299,49 +292,48 @@ TOK LEX_filename(void) return NULL; } -// notice if this looks like a quoted file name +// notice if this looks like a quoted file name + SSHORT save = 0; if (classes[c] & CHR_quote) { token->tok_type = tok_quoted; save = c; } - else - save = 0; -// Look for white space or end of line, allowing embedded quoted strings. +// Look for white space or end of line, allowing embedded quoted strings. for (;;) { c = nextchar(true); - class_ = classes[c]; + char char_class = classes[c]; if (c == '"' && c != save) { *p++ = c; for (;;) { c = nextchar(true); - class_ = classes[c]; - if ((class_ & CHR_eol) || c == '"') + char_class = classes[c]; + if ((char_class & CHR_eol) || c == '"') break; *p++ = c; } } - if (class_ & (CHR_white | CHR_eol)) + if (char_class & (CHR_white | CHR_eol)) break; *p++ = c; } retchar(c); -// Drop trailing semi-colon to avoid confusion +// Drop trailing semi-colon to avoid confusion if (p[-1] == ';') { retchar(c); --p; } -// complain on unterminated quoted string +// complain on unterminated quoted string if ((token->tok_type == tok_quoted) && (p[-1] != save)) - IBERROR(60); // Msg 60 unterminated quoted string + IBERROR(60); // Msg 60 unterminated quoted string token->tok_length = p - token->tok_string; *p = 0; @@ -370,7 +362,7 @@ void LEX_fini(void) if (trace_file && (trace_file != (IB_FILE *) - 1)) { ib_fclose(trace_file); - unlink((char*) trace_file_name); + unlink(trace_file_name); } } @@ -384,7 +376,7 @@ void LEX_flush(void) ************************************** * * Functional description - * Flush the input stream after an error. + * Flush the input stream after an error. * **************************************/ @@ -393,12 +385,12 @@ void LEX_flush(void) if (!QLI_line) return; -/* Pop off line sources until we're down to the last one. */ +// Pop off line sources until we're down to the last one. while (QLI_line->line_next) LEX_pop_line(); -// Look for a semi-colon +// Look for a semi-colon if (QLI_semi) while (QLI_line && QLI_token->tok_keyword != KW_SEMI) @@ -427,18 +419,17 @@ bool LEX_get_line(TEXT * prompt, * return false. Regardless, a null terminated string is returned. * **************************************/ - TEXT *p; - bool overflow_flag = false; SSHORT c; -// UNIX flavor +// UNIX flavor if (prompt) ib_printf(prompt); errno = 0; - p = buffer; + TEXT* p = buffer; + bool overflow_flag = false; while (true) { c = ib_getc(input_file); if (c == EOF) { @@ -447,9 +438,9 @@ bool LEX_get_line(TEXT * prompt, continue; } - /* The check for this actually being a terminal that is at - end of file is to prevent looping through a redirected - ib_stdin (e.g., a script file). */ + // The check for this actually being a terminal that is at + // end of file is to prevent looping through a redirected + // ib_stdin (e.g., a script file). if (prompt && isatty(ib_fileno(ib_stdin))) { ib_rewind(ib_stdin); @@ -474,7 +465,7 @@ bool LEX_get_line(TEXT * prompt, if (overflow_flag) { buffer[0] = 0; - IBERROR(476); // Msg 476 input line too long + IBERROR(476); // Msg 476 input line too long } if (sw_verify) @@ -506,9 +497,8 @@ bool LEX_get_line(TEXT * prompt, struct dsc$descriptor_s line_desc, prompt_desc; SLONG status; SSHORT length; - SCHAR *p; -/* We're going to add a null to the end, so don't read too much */ +// We're going to add a null to the end, so don't read too much --size; @@ -527,13 +517,13 @@ bool LEX_get_line(TEXT * prompt, else status = lib$get_input(&line_desc, NULL, &length); - p = buffer + length; + SCHAR* p = buffer + length; if (!(status & 1)) { if (status != LIB$_INPSTRTRU) return false; buffer[0] = 0; - IBERROR(476); // Msg 476 input line too long + IBERROR(476); // Msg 476 input line too long } else if (length < size) *p++ = '\n'; @@ -564,9 +554,9 @@ void LEX_init(void) * **************************************/ - trace_file = (IB_FILE*) gds__temp_file(TRUE, SCRATCH, (TEXT*) trace_file_name); + trace_file = (IB_FILE*) gds__temp_file(TRUE, SCRATCH, trace_file_name); if (trace_file == (IB_FILE *) - 1) - IBERROR(61); /* Msg 61 couldn't open scratch file */ + IBERROR(61); // Msg 61 couldn't open scratch file QLI_token = (TOK) ALLOCPV(type_tok, MAXSYMLEN); @@ -595,15 +585,17 @@ void LEX_mark_statement(void) * the statement stack. * **************************************/ - LLS statement; LINE temp; for (temp = QLI_line; temp->line_next && QLI_statements; temp = temp->line_next) -if (temp->line_next->line_position == (SLONG) QLI_statements->lls_object) return; + { + if (temp->line_next->line_position == (SLONG) QLI_statements->lls_object) + return; + } - statement = (LLS) ALLOCP(type_lls); + LLS statement = (LLS) ALLOCP(type_lls); statement->lls_object = (BLK) temp->line_position; statement->lls_next = QLI_statements; QLI_statements = statement; @@ -623,9 +615,7 @@ void LEX_pop_line(void) * and release the line block. * **************************************/ - LINE temp; - - temp = QLI_line; + LINE temp = QLI_line; QLI_line = temp->line_next; if (temp->line_type == line_blob) @@ -650,9 +640,7 @@ void LEX_procedure( DBB database, FRBRD *blob) * stack; * **************************************/ - LINE temp; - - temp = (LINE) ALLOCPV(type_line, QLI_token->tok_length); + LINE temp = (LINE) ALLOCPV(type_line, QLI_token->tok_length); temp->line_source = blob; strncpy(temp->line_source_name, QLI_token->tok_string, QLI_token->tok_length); @@ -666,12 +654,12 @@ void LEX_procedure( DBB database, FRBRD *blob) } -bool LEX_push_file(TEXT * filename, - bool error_flag) +bool LEX_push_file(const TEXT* filename, + const bool error_flag) { /************************************** * - * L E X _ p u s h _ f i l e + * L E X _ p u s h _ f i l e * ************************************** * @@ -681,20 +669,20 @@ bool LEX_push_file(TEXT * filename, * if the error flag is set, otherwise return quietly. * **************************************/ - TEXT buffer[64]; IB_FILE *file; - LINE line; if (!(file = ib_fopen(filename, FOPEN_INPUT_TYPE))) { + TEXT buffer[64]; sprintf(buffer, "%s.com", filename); if (!(file = ib_fopen(buffer, FOPEN_INPUT_TYPE))) { if (error_flag) - ERRQ_msg_put(67, filename, NULL, NULL, NULL, NULL); /* Msg 67 can't open command file \"%s\"\n */ + ERRQ_msg_put(67, filename, NULL, NULL, NULL, NULL); + // Msg 67 can't open command file \"%s\"\n return false; } } - line = (LINE) ALLOCPV(type_line, strlen(filename)); + LINE line = (LINE) ALLOCPV(type_line, strlen(filename)); line->line_type = line_file; line->line_source = (FRBRD *) file; line->line_size = sizeof(line->line_data); @@ -708,7 +696,7 @@ bool LEX_push_file(TEXT * filename, } -bool LEX_push_string( TEXT * string) +bool LEX_push_string(const TEXT* const string) { /************************************** * @@ -720,9 +708,7 @@ bool LEX_push_string( TEXT * string) * Push a simple string on as an input source. * **************************************/ - LINE line; - - line = (LINE) ALLOCPV(type_line, 0); + LINE line = (LINE) ALLOCPV(type_line, 0); line->line_type = line_string; line->line_size = strlen(string); line->line_ptr = line->line_data; @@ -748,25 +734,25 @@ void LEX_put_procedure( FRBRD *blob, SLONG start, SLONG stop) * **************************************/ ISC_STATUS_ARRAY status_vector; - int length; - SSHORT l, c; - TEXT buffer[1024], *p; if (ib_fseek(trace_file, start, 0)) { ib_fseek(trace_file, (SLONG) 0, 2); - IBERROR(62); // Msg 62 ib_fseek failed + IBERROR(62); // Msg 62 ib_fseek failed } - length = stop - start; + int length = stop - start; + + TEXT buffer[1024]; while (length) { - p = buffer; + TEXT* p = buffer; while (length) { --length; - *p++ = c = ib_getc(trace_file); + const SSHORT c = ib_getc(trace_file); + *p++ = c; if (c == '\n') { #ifdef PC_FILE_SEEK - // account for the extra line-feed on OS/2 and Windows NT + // account for the extra line-feed on OS/2 and Windows NT if (length) --length; @@ -774,9 +760,10 @@ void LEX_put_procedure( FRBRD *blob, SLONG start, SLONG stop) break; } } - if (l = p - buffer) + const SSHORT l = p - buffer; + if (l) if (gds__put_segment(status_vector, &blob, l, buffer)) - BUGCHECK(58); // Msg 58 gds__put_segment failed + BUGCHECK(58); // Msg 58 gds__put_segment failed } ib_fseek(trace_file, (SLONG) 0, 2); @@ -832,32 +819,27 @@ TOK LEX_token(void) * Parse and return the next token. * **************************************/ - TOK token; - SSHORT c, next, peek; - TEXT class_, *p, *q; - SYM symbol; - LINE prior; + SSHORT c; - token = QLI_token; - p = token->tok_string; + TOK token = QLI_token; + TEXT* p = token->tok_string; -/* Get next significant byte. If it's the last EOL of a blob, throw it - away */ +// Get next significant byte. If it's the last EOL of a blob, throw it away for (;;) { c = skip_white(); if (c != '\n' || QLI_line->line_type != line_blob) break; - prior = QLI_line; + LINE prior = QLI_line; next_line(true); if (prior == QLI_line) break; } -// If we hit end of file, make up a phoney token +// If we hit end of file, make up a phoney token if (!QLI_line) { - q = eof_string; + const TEXT* q = eof_string; while (*p++ = *q++); token->tok_type = tok_eof; token->tok_keyword = KW_none; @@ -868,34 +850,35 @@ TOK LEX_token(void) QLI_token->tok_position = QLI_line->line_position + QLI_line->line_ptr - QLI_line->line_data - 1; -// On end of file, generate furious but phone end of line tokens +// On end of file, generate furious but phone end of line tokens - class_ = classes[c]; + char char_class = classes[c]; - if (class_ & CHR_letter) { - while (classes[c = nextchar(true)] & CHR_ident) + if (char_class & CHR_letter) { + for (c = nextchar(true); classes[c] & CHR_ident; c = nextchar(true)) *p++ = c; retchar(c); token->tok_type = tok_ident; } - else if (((class_ & CHR_digit) || c == '.') && scan_number(c, &p)) + else if (((char_class & CHR_digit) || c == '.') && scan_number(c, &p)) token->tok_type = tok_number; - else if (class_ & CHR_quote) { + else if (char_class & CHR_quote) { token->tok_type = tok_quoted; + SSHORT next; while (true) { if (!(next = nextchar(false)) || next == '\n') { retchar(next); - IBERROR(63); // Msg 63 unterminated quoted string + IBERROR(63); // Msg 63 unterminated quoted string break; } *p++ = next; if ((p - token->tok_string) >= MAXSYMLEN) - ERRQ_msg_put(470, (TEXT *) MAXSYMLEN, NULL, NULL, NULL, NULL); // Msg 470 literal too long + ERRQ_msg_put(470, (TEXT *) MAXSYMLEN, NULL, NULL, NULL, NULL); // Msg 470 literal too long - // If there are 2 quotes in a row, interpret 2nd as a literal + // If there are 2 quotes in a row, interpret 2nd as a literal if (next == c) { - peek = nextchar(false); + const SSHORT peek = nextchar(false); retchar(peek); if (peek != c) break; @@ -904,9 +887,10 @@ TOK LEX_token(void) } } else if (c == '\n') { + // end of line, signal it properly with a phoney token. token->tok_type = tok_eol; --p; - q = "end of line"; + const TEXT* q = eol_string; while (*q) *p++ = *q++; } @@ -921,7 +905,8 @@ TOK LEX_token(void) *p = '\0'; if (token->tok_string[0] == '$' && - trans_limit < TRANS_LIMIT && (p = getenv(token->tok_string + 1))) { + trans_limit < TRANS_LIMIT && (p = getenv(token->tok_string + 1))) + { LEX_push_string(p); ++trans_limit; token = LEX_token(); @@ -929,8 +914,8 @@ TOK LEX_token(void) return token; } - token->tok_symbol = symbol = - HSH_lookup(token->tok_string, token->tok_length); + SYM symbol = HSH_lookup(token->tok_string, token->tok_length); + token->tok_symbol = symbol; if (symbol && symbol->sym_type == SYM_keyword) token->tok_keyword = (KWWORDS) symbol->sym_keyword; else @@ -960,14 +945,12 @@ static bool get_line(IB_FILE * file, * return false. Regardless, a null terminated string is returned. * **************************************/ - TEXT *p; - SLONG length; bool overflow_flag = false; SSHORT c; errno = 0; - p = buffer; - length = size; + TEXT* p = buffer; + SLONG length = size; while (true) { c = ib_getc(file); @@ -994,7 +977,7 @@ static bool get_line(IB_FILE * file, return false; if (overflow_flag) - IBERROR(477); // Msg 477 input line too long + IBERROR(477); // Msg 477 input line too long if (sw_verify) ib_fputs(buffer, ib_stdout); @@ -1003,7 +986,7 @@ static bool get_line(IB_FILE * file, } -static int nextchar(bool eof_ok) +static int nextchar(const bool eof_ok) { /************************************** * @@ -1017,10 +1000,10 @@ static int nextchar(bool eof_ok) **************************************/ SSHORT c; -/* Get the next character in the current line. If we run out, - get the next line. If the line source runs out, pop the - line source. If we run out of line sources, we are distinctly - at end of file. */ +// Get the next character in the current line. If we run out, +// get the next line. If the line source runs out, pop the +// line source. If we run out of line sources, we are distinctly +// at end of file. while (QLI_line) { if (c = *QLI_line->line_ptr++) @@ -1032,7 +1015,7 @@ static int nextchar(bool eof_ok) } -static void next_line(bool eof_ok) +static void next_line(const bool eof_ok) { /************************************** * @@ -1044,23 +1027,22 @@ static void next_line(bool eof_ok) * Get the next line from the input stream. * **************************************/ - TEXT *p, *q, filename[256]; - bool flag; + TEXT *p, *q; while (QLI_line) { - flag = false; + bool flag = false; - /* Get next line from where ever. If it comes from either the terminal - or command file, check for another command file. */ + // Get next line from where ever. If it comes from either the terminal + // or command file, check for another command file. if (QLI_line->line_type == line_blob) { - // If the current blob segment contains another line, use it + // If the current blob segment contains another line, use it if ((p = QLI_line->line_ptr) != QLI_line->line_data && p[-1] == '\n' && *p) flag = true; else { - // Initialize line block for retrieval + // Initialize line block for retrieval p = QLI_line->line_data; QLI_line->line_ptr = QLI_line->line_data; @@ -1072,7 +1054,7 @@ static void next_line(bool eof_ok) } } else { - // Initialize line block for retrieval + // Initialize line block for retrieval QLI_line->line_ptr = QLI_line->line_data; p = QLI_line->line_data; @@ -1087,45 +1069,46 @@ static void next_line(bool eof_ok) if (flag) { for (q = p; classes[*q] & CHR_white; q++); if (*q == '@') { + TEXT filename[MAXPATHLEN]; for (p = q + 1, q = filename; *p && *p != '\n';) *q++ = *p++; *q = 0; - QLI_line->line_ptr = (TEXT *) p; + QLI_line->line_ptr = p; LEX_push_file(filename, true); continue; } } } - /* If get got a line, we're almost done */ + // If get got a line, we're almost done if (flag) break; - /* We hit end of file. Either complain about the circumstances - or just close out the current input source. Don't close the - input source if it's the terminal and we're at a continuation - prompt. */ + // We hit end of file. Either complain about the circumstances + // or just close out the current input source. Don't close the + // input source if it's the terminal and we're at a continuation + // prompt. if (eof_ok && (QLI_line->line_next || QLI_prompt != QLI_cont_string)) { LEX_pop_line(); return; } - // this is an unexpected end of file + // this is an unexpected end of file if (QLI_line->line_type == line_blob) ERRQ_print_error(64, QLI_line->line_source_name, NULL, NULL, NULL, NULL); - /* Msg 64 unexpected end of procedure in procedure %s */ + // Msg 64 unexpected end of procedure in procedure %s else if (QLI_line->line_type == line_file) ERRQ_print_error(65, QLI_line->line_source_name, NULL, NULL, NULL, NULL); - /* Msg 65 unexpected end of file in file %s */ + // Msg 65 unexpected end of file in file %s else { if (QLI_line->line_type == line_string) LEX_pop_line(); - IBERROR(66); // Msg 66 unexpected eof + IBERROR(66); // Msg 66 unexpected eof } } @@ -1134,7 +1117,7 @@ static void next_line(bool eof_ok) QLI_line->line_position = QLI_position; -// Dump output to the trace file +// Dump output to the trace file if (QLI_line->line_type == line_blob) while (*p) @@ -1144,8 +1127,8 @@ static void next_line(bool eof_ok) ib_putc(*p++, trace_file); QLI_position += (TEXT *) p - QLI_line->line_data; #ifdef PC_FILE_SEEK - /* account for the extra line-feed on OS/2 and Windows NT - to determine file position */ + // account for the extra line-feed on OS/2 and Windows NT + // to determine file position QLI_position++; #endif @@ -1155,7 +1138,7 @@ static void next_line(bool eof_ok) } -static void retchar( SSHORT c) +static void retchar(const SSHORT c) // unused, now checked in DEBUG mode. { /************************************** * @@ -1168,6 +1151,9 @@ static void retchar( SSHORT c) * **************************************/ +// CVC: Too naive implementation: what if the pointer is at the beginning? +// What if the character being returned isn't the character that was gotten? + fb_assert(QLI_line && QLI_line->line_ptr[-1] == c); --QLI_line->line_ptr; } @@ -1185,13 +1171,12 @@ static bool scan_number(SSHORT c, * Pass on a possible numeric literal. * **************************************/ - TEXT *p; bool dot = false; - p = *ptr; + TEXT* p = *ptr; -/* If this is a leading decimal point, check that the next - character is really a digit, otherwise backout */ +// If this is a leading decimal point, check that the next +// character is really a digit, otherwise backout if (c == '.') { retchar(c = nextchar(true)); @@ -1200,7 +1185,7 @@ static bool scan_number(SSHORT c, dot = true; } -// Gobble up digits up to a single decimal point +// Gobble up digits up to a single decimal point for (;;) { c = nextchar(true); @@ -1214,7 +1199,7 @@ static bool scan_number(SSHORT c, break; } -// If this is an exponential, eat the exponent sign and digits +// If this is an exponential, eat the exponent sign and digits if (UPPER(c) == 'E') { *p++ = c; @@ -1248,14 +1233,15 @@ static int skip_white(void) * Skip over while space and comments in input stream * **************************************/ - SSHORT c, next, class_; + SSHORT c; while (true) { c = nextchar(true); - class_ = classes[c]; - if (class_ & CHR_white) + const char char_class = classes[c]; + if (char_class & CHR_white) continue; if (c == '/') { + SSHORT next; if ((next = nextchar(true)) != '*') { retchar(next); return c; @@ -1270,3 +1256,5 @@ static int skip_white(void) return c; } + + diff --git a/src/qli/lex_proto.h b/src/qli/lex_proto.h index ea592135cd..c0906ccc70 100644 --- a/src/qli/lex_proto.h +++ b/src/qli/lex_proto.h @@ -1,7 +1,7 @@ /* * PROGRAM: JRD Command Oriented Query Language * MODULE: lex_proto.h - * DESCRIPTION: Prototype header file for lex.c + * DESCRIPTION: Prototype header file for lex.cpp * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file @@ -21,8 +21,8 @@ * Contributor(s): ______________________________________. */ -#ifndef _QLI_LEX_PROTO_H_ -#define _QLI_LEX_PROTO_H_ +#ifndef QLI_LEX_PROTO_H +#define QLI_LEX_PROTO_H extern bool LEX_active_procedure (void); extern void LEX_edit (SLONG, SLONG); @@ -35,11 +35,12 @@ extern void LEX_init (void); extern void LEX_mark_statement (void); extern void LEX_pop_line (void); extern void LEX_procedure(dbb*, FRBRD*); -extern bool LEX_push_file (TEXT *, bool); -extern bool LEX_push_string (TEXT *); +extern bool LEX_push_file (const TEXT*, const bool); +extern bool LEX_push_string (const TEXT* const); extern void LEX_put_procedure (FRBRD *, SLONG, SLONG); extern void LEX_real (void); extern lls* LEX_statement_list(void); extern tok* LEX_token(void); -#endif /* _QLI_LEX_PROTO_H_ */ +#endif /* QLI_LEX_PROTO_H */ + diff --git a/src/qli/meta.epp b/src/qli/meta.epp index 3887f50304..0d8c5c57f4 100644 --- a/src/qli/meta.epp +++ b/src/qli/meta.epp @@ -82,18 +82,18 @@ static CON missing_value(SLONG *, SYM); static SYN parse_blr(UCHAR **, SYM); static SYN parse_blr_blob(SLONG *, SYM); static void purge_relation(QLI_REL); -static void put_dyn_string(RLB, TEXT *); +static void put_dyn_string(RLB, const TEXT*); static void rollback_update(DBB); static void set_capabilities(DBB); static DBB setup_update(DBB); static void sql_grant_revoke(SYN, USHORT); -static void stuff_priv(RLB, USHORT, TEXT *, USHORT, TEXT *, TEXT *); +static void stuff_priv(RLB, USHORT, const TEXT*, USHORT, const TEXT*, const TEXT*); static int truncate_string(TEXT *); static void wal_info(UCHAR *, SLONG *, SCHAR *, SLONG *); static const UCHAR tpb[] = { gds_tpb_version1, gds_tpb_write }; static const UCHAR db_info[] = { gds_info_implementation, gds_info_end }; -static UCHAR parm_buffer[256]; +static UCHAR global_parm_buffer[256]; static const UCHAR db_log_info[] = { gds_info_logfile, gds_info_cur_logfile_name, @@ -131,20 +131,20 @@ static const USHORT blr_dtypes[] = { }; -/* - table used to determine capabilities, checking for specific - fields in system relations +/* + table used to determine capabilities, checking for specific + fields in system relations */ -typedef struct rfr_tab_t { +struct rfr_tab_t { const TEXT *relation; const TEXT *field; int bit_mask; -} *RFR_TAB; +}; static const rfr_tab_t rfr_table[] = { { "RDB$INDICES", "RDB$INDEX_INACTIVE", DBB_cap_idx_inactive }, -/* OBSOLETE - 1996-Aug-06 David Schnepper +/* OBSOLETE - 1996-Aug-06 David Schnepper { "RDB$RELATIONS", "RDB$STORE_TRIGGER", DBB_cap_triggers }, */ { "RDB$RELATIONS", "RDB$EXTERNAL_FILE", DBB_cap_extern_file }, @@ -207,7 +207,7 @@ void MET_define_field( DBB database, QLI_FLD field) if (check_global_field(database, NULL, field->fld_name->sym_string)) { rollback_update(database); - ERRQ_print_error(233, field->fld_name->sym_string, NULL, NULL, NULL, NULL); /* Msg233 global field %s already exists */ + ERRQ_print_error(233, field->fld_name->sym_string, NULL, NULL, NULL, NULL); // Msg233 global field %s already exists } define_global_field(database, field, field->fld_name); @@ -228,25 +228,18 @@ void MET_define_index( SYN node) * Define a new index. * **************************************/ - DBB database; - QLI_REL relation; - SYN fields; - QLI_FLD field; - NAM *ptr; - SYM symbol; - int position, present; - - symbol = (SYM) node->syn_arg[s_dfi_name]; - relation = (QLI_REL) node->syn_arg[s_dfi_relation]; - fields = node->syn_arg[s_dfi_fields]; - database = setup_update(relation->rel_database); + SYM symbol = (SYM) node->syn_arg[s_dfi_name]; + QLI_REL relation = (QLI_REL) node->syn_arg[s_dfi_relation]; + SYN fields = node->syn_arg[s_dfi_fields]; + DBB database = setup_update(relation->rel_database); if (relation->rel_flags & REL_view) - IBERROR(234); /* Msg234 Can't define an index in a view */ + IBERROR(234); // Msg234 Can't define an index in a view FOR(REQUEST_HANDLE database->dbb_requests[REQ_def_index1]) X IN DB.RDB$INDICES WITH X.RDB$INDEX_NAME EQ symbol->sym_string - ERRQ_print_error(235, symbol->sym_string, NULL, NULL, NULL, NULL); /* Msg235 Index %s already exists */ + ERRQ_print_error(235, symbol->sym_string, NULL, NULL, NULL, NULL); + // Msg235 Index %s already exists END_FOR ON_ERROR ERRQ_database_error(database, gds_status); @@ -288,24 +281,26 @@ void MET_define_index( SYN node) ERRQ_database_error(database, gds_status); END_ERROR; - - for (ptr = (NAM *) fields->syn_arg, position = 0; - position < fields->syn_count; ptr++, position++) { + NAM* ptr = (NAM*) fields->syn_arg; + for (int position = 0; position < fields->syn_count; ptr++, position++) + { MET_fields(relation); - for (present = FALSE, field = relation->rel_fields; field; - field = - field-> - fld_next) - if (!(strcmp((*ptr)->nam_string, field->fld_name->sym_string))) { - present = TRUE; + bool present = false; + for (QLI_FLD field = relation->rel_fields; field; + field = field->fld_next) + { + if (!(strcmp((*ptr)->nam_string, field->fld_name->sym_string))) { + present = true; break; } + } if (!present) { rollback_update(database); ERRQ_print_error(236, (*ptr)->nam_string, - relation->rel_symbol->sym_string, NULL, NULL, NULL); /* Msg236 Field %s does not occur in relation %s */ + relation->rel_symbol->sym_string, NULL, NULL, NULL); + // Msg236 Field %s does not occur in relation %s } setup_update(database); @@ -342,29 +337,24 @@ void MET_define_relation( QLI_REL relation, QLI_REL source) * else. * **************************************/ - DBB database; - SYM symbol; - QLI_FLD field; - USHORT position; - - symbol = relation->rel_symbol; + SYM symbol = relation->rel_symbol; if (source) { source->rel_database = setup_update(source->rel_database); if (!(check_relation(source))) ERRQ_print_error(483, source->rel_symbol->sym_string, NULL, NULL, - NULL, NULL); /* Msg 483 Relation %s does not exist */ + NULL, NULL); // Msg 483 Relation %s does not exist } - - relation->rel_database = database = setup_update(relation->rel_database); + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; if (check_relation(relation)) - ERRQ_print_error(237, symbol->sym_string, NULL, NULL, NULL, NULL); /* Msg237 Relation %s already exists */ + ERRQ_print_error(237, symbol->sym_string, NULL, NULL, NULL, NULL); // Msg237 Relation %s already exists STORE(REQUEST_HANDLE database->dbb_requests[REQ_store_relation]) - X IN DB.RDB$RELATIONS + X IN DB.RDB$RELATIONS strcpy(X.RDB$RELATION_NAME, symbol->sym_string); END_STORE ON_ERROR @@ -374,10 +364,14 @@ void MET_define_relation( QLI_REL relation, QLI_REL source) if (source) clone_fields(relation, source); - else - for (field = relation->rel_fields, position = 1; field; - field = field->fld_next, position++) + else { + USHORT position = 1; + for (QLI_FLD field = relation->rel_fields; field; + field = field->fld_next, position++) + { add_field(relation, field, position); + } + } MET_meta_commit(database); @@ -386,13 +380,13 @@ void MET_define_relation( QLI_REL relation, QLI_REL source) database->dbb_relations = relation; relation->rel_database = database; -// Go back and pick up relation id +// Go back and pick up relation id setup_update(database); FOR(REQUEST_HANDLE database->dbb_requests[REQ_relation_id]) X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ symbol->sym_string - relation->rel_id = X.RDB$RELATION_ID; + relation->rel_id = X.RDB$RELATION_ID; symbol = make_symbol(X.RDB$RELATION_NAME, sizeof(X.RDB$RELATION_NAME)); symbol->sym_type = SYM_relation; symbol->sym_object = (BLK) relation; @@ -420,24 +414,20 @@ void MET_define_sql_relation( QLI_REL relation) * Define a new SQL relation, using dynamic ddl. * **************************************/ - DBB database; - SYM symbol; - QLI_FLD field; - USHORT position; - RLB rlb; - - symbol = relation->rel_symbol; - relation->rel_database = database = setup_update(relation->rel_database); + SYM symbol = relation->rel_symbol; + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; FOR(REQUEST_HANDLE database->dbb_requests[REQ_relation_def]) X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ symbol->sym_string - ERRQ_print_error(237, symbol->sym_string, NULL, NULL, NULL, NULL); /* Msg237 Relation %s already exists */ + ERRQ_print_error(237, symbol->sym_string, NULL, NULL, NULL, NULL); + // Msg237 Relation %s already exists END_FOR ON_ERROR ERRQ_database_error(database, gds_status); END_ERROR; - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); @@ -448,9 +438,12 @@ void MET_define_sql_relation( QLI_REL relation) STUFF_WORD(2); STUFF_WORD(1); - for (field = relation->rel_fields, position = 1; field; + USHORT position = 1; + for (QLI_FLD field = relation->rel_fields; field; field = field->fld_next, position++) + { add_sql_field(relation, field, position, rlb); + } STUFF(gds_dyn_end); STUFF(gds_dyn_end); @@ -464,13 +457,13 @@ void MET_define_sql_relation( QLI_REL relation) database->dbb_relations = relation; relation->rel_database = database; -// Go back and pick up relation id +// Go back and pick up relation id setup_update(database); FOR(REQUEST_HANDLE database->dbb_requests[REQ_relation_id]) X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ symbol->sym_string - relation->rel_id = X.RDB$RELATION_ID; + relation->rel_id = X.RDB$RELATION_ID; symbol = make_symbol(X.RDB$RELATION_NAME, sizeof(X.RDB$RELATION_NAME)); symbol->sym_type = SYM_relation; @@ -500,19 +493,12 @@ void MET_delete_database( DBB dbb) * and finish any copies we have active. * **************************************/ - ISC_STATUS_ARRAY status_vector; - LLS log_stack, stack; - STR string; - DBB database, next; - UCHAR *dpb = NULL, *p; - TEXT *user, *password; - USHORT dpb_length = 0, user_length, password_length; - SCHAR db_info_buffer[512], cur_log[512], db_name[512]; - SLONG part_offset, log; -/* generate a database parameter block to +/* generate a database parameter block to include the user/password, if necessary */ + TEXT* user; + USHORT user_length; if (dbb->dbb_user) { user = (TEXT *) dbb->dbb_user->con_data; user_length = dbb->dbb_user->con_desc.dsc_length; @@ -522,6 +508,8 @@ void MET_delete_database( DBB dbb) user_length = strlen(QLI_default_user); } + TEXT* password; + USHORT password_length; if (dbb->dbb_password) { password = (TEXT *) dbb->dbb_password->con_data; password_length = dbb->dbb_user->con_desc.dsc_length; @@ -531,7 +519,8 @@ void MET_delete_database( DBB dbb) password_length = strlen(QLI_default_password); } - dpb = p = parm_buffer; + UCHAR* p = global_parm_buffer; + UCHAR* const dpb = p; *p++ = gds_dpb_version1; if (user_length) { @@ -548,38 +537,42 @@ void MET_delete_database( DBB dbb) *p++ = *password++; } - dpb_length = p - parm_buffer; + USHORT dpb_length = p - global_parm_buffer; if (dpb_length == 1) dpb_length = 0; + ISC_STATUS_ARRAY status_vector; if (gds__attach_database(status_vector, 0, dbb->dbb_filename, &dbb->dbb_handle, dpb_length, (char*) dpb)) ERRQ_database_error(dbb, status_vector); - log_stack = stack = NULL; + LLS log_stack = NULL, stack = NULL; gds_trans = MET_transaction(nod_start_trans, dbb); DB = dbb->dbb_handle; FOR F IN DB.RDB$FILES SORTED BY F.RDB$FILE_START - string = (STR) ALLOCDV(type_str, strlen(F.RDB$FILE_NAME)); - LLS_PUSH(string, &stack); - strcpy(string->str_data, F.RDB$FILE_NAME); + STR astring = (STR) ALLOCDV(type_str, strlen(F.RDB$FILE_NAME)); + strcpy(astring->str_data, F.RDB$FILE_NAME); + LLS_PUSH(astring, &stack); END_FOR ON_ERROR ERRQ_database_error(dbb, gds_status); END_ERROR; -// Get write ahead log information +// Get write ahead log information + TEXT db_info_buffer[512]; if (gds__database_info(status_vector, &DB, sizeof(db_log_info), (char*) db_log_info, sizeof(db_info_buffer), - db_info_buffer)) + db_info_buffer)) ERRQ_database_error(dbb, status_vector); -// extract info from buffer +// extract info from buffer + TEXT cur_log[512]; + SLONG part_offset, log = 0; wal_info((UCHAR*) db_info_buffer, &log, cur_log, &part_offset); if (log) @@ -590,30 +583,34 @@ void MET_delete_database( DBB dbb) if (gds__detach_database(gds_status, &dbb->dbb_handle)) gds__print_status(gds_status); - for (database = QLI_databases; database; database = next) { + DBB next = NULL; + for (DBB database = QLI_databases; database; database = next) { next = database->dbb_next; if (!strcmp(database->dbb_filename, dbb->dbb_filename)) MET_finish(database); } if (log) { + TEXT db_name[512]; ISC_expand_filename(dbb->dbb_filename, 0, db_name); get_log_names(dbb, db_name, &log_stack, cur_log, part_offset, 0, 1); } while (stack) { - string = (STR) LLS_POP(&stack); - if (unlink(string->str_data)) - ERRQ_print_error(431, string->str_data, NULL, NULL, NULL, NULL); /* Msg431 Could not drop database file "%s" */ + STR sstring = (STR) LLS_POP(&stack); + if (unlink(sstring->str_data)) + ERRQ_print_error(431, sstring->str_data, NULL, NULL, NULL, NULL); + // Msg431 Could not drop database file "%s" } while (log_stack) { - string = (STR) LLS_POP(&log_stack); - unlink(string->str_data); // do not check for error + STR lstring = (STR) LLS_POP(&log_stack); + unlink(lstring->str_data); // do not check for error } if (unlink(dbb->dbb_filename)) - ERRQ_print_error(431, dbb->dbb_filename, NULL, NULL, NULL, NULL); /* Msg431 Could not drop database file "%s" */ + ERRQ_print_error(431, dbb->dbb_filename, NULL, NULL, NULL, NULL); + // Msg431 Could not drop database file "%s" } @@ -629,17 +626,15 @@ void MET_delete_field( DBB database, NAM name) * Delete a global field. * **************************************/ - USHORT count; - RLB rlb; - database = setup_update(database); - count = 0; + USHORT count = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_check_fld]) - RFR IN DB.RDB$RELATION_FIELDS WITH RFR.RDB$FIELD_SOURCE EQ name-> - nam_string REDUCED TO RFR.RDB$RELATION_NAME + RFR IN DB.RDB$RELATION_FIELDS + WITH RFR.RDB$FIELD_SOURCE EQ name->nam_string + REDUCED TO RFR.RDB$RELATION_NAME if (!count) - ERRQ_msg_put(238, name->nam_string, NULL, NULL, NULL, NULL); /* Msg238 Field %s is in use in the following relations: */ + ERRQ_msg_put(238, name->nam_string, NULL, NULL, NULL, NULL); // Msg238 Field %s is in use in the following relations: ib_printf("\t%s\n", RFR.RDB$RELATION_NAME); count++; END_FOR @@ -649,12 +644,12 @@ void MET_delete_field( DBB database, NAM name) if (count) ERRQ_print_error(239, name->nam_string, database->dbb_filename, NULL, - NULL, NULL); /* Msg239 Field %s is in use in database %s */ + NULL, NULL); // Msg239 Field %s is in use in database %s FOR(REQUEST_HANDLE database->dbb_requests[REQ_erase_fld]) FLD IN DB.RDB$FIELDS WITH FLD.RDB$FIELD_NAME EQ name->nam_string - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); STUFF(gds_dyn_delete_dimensions); @@ -676,7 +671,7 @@ void MET_delete_field( DBB database, NAM name) if (!count) ERRQ_print_error(240, name->nam_string, database->dbb_filename, NULL, - NULL, NULL); /* Msg240 Field %s is not defined in database %s */ + NULL, NULL); // Msg240 Field %s is not defined in database %s MET_meta_commit(database); } @@ -694,10 +689,8 @@ void MET_delete_index( DBB database, NAM name) * Delete an index. * **************************************/ - USHORT count; - database = setup_update(database); - count = 0; + USHORT count = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_erase_index]) IDX IN DB.RDB$INDICES WITH IDX.RDB$INDEX_NAME EQ name->nam_string @@ -715,7 +708,7 @@ void MET_delete_index( DBB database, NAM name) if (!count) ERRQ_print_error(241, name->nam_string, database->dbb_filename, NULL, - NULL, NULL); /* Msg241 Index %s is not defined in database %s */ + NULL, NULL); // Msg241 Index %s is not defined in database %s FOR(REQUEST_HANDLE database->dbb_requests[REQ_erase_segments]) SEG IN DB.RDB$INDEX_SEGMENTS WITH SEG.RDB$INDEX_NAME EQ name->nam_string @@ -746,13 +739,10 @@ void MET_delete_relation( QLI_REL relation) * Delete a relation. * **************************************/ - SYM symbol; - RLB rlb; +// Pass the mess off to dynamic DDL and let it worry -// Pass the mess off to dynamic DDL and let it worry - - symbol = relation->rel_symbol; - rlb = NULL; + SYM symbol = relation->rel_symbol; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); STUFF(gds_dyn_delete_rel); @@ -764,7 +754,7 @@ void MET_delete_relation( QLI_REL relation) execute_dynamic_ddl(relation->rel_database, rlb); MET_meta_commit(relation->rel_database); -// Unlink and release various blocks +// Unlink and release various blocks purge_relation(relation); } @@ -782,12 +772,10 @@ int MET_dimensions( DBB database, TEXT * field_name) * Determine if the field has any dimensions. * **************************************/ - USHORT dimensions; - if (!(database->dbb_capabilities & DBB_cap_dimensions)) return 0; - dimensions = 0; + USHORT dimensions = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_fld_dimensions]) F IN DB.RDB$FIELDS WITH F.RDB$FIELD_NAME = field_name @@ -813,21 +801,17 @@ void MET_fields( QLI_REL relation) * Get all fields for a relation. * **************************************/ - DBB database; - QLI_FLD field, *ptr; - SYM symbol; - SLONG *blob; -/* If we already have fetched the fields for the relation, +/* If we already have fetched the fields for the relation, don't do it again. */ if (relation->rel_flags & REL_fields) return; - database = relation->rel_database; + DBB database = relation->rel_database; MET_meta_transaction(database, FALSE); relation->rel_flags |= REL_fields; - ptr = &relation->rel_fields; + QLI_FLD* ptr = &relation->rel_fields; FOR(REQUEST_HANDLE database->dbb_field_request) RFR IN DB.RDB$RELATION_FIELDS CROSS @@ -838,10 +822,12 @@ void MET_fields( QLI_REL relation) if (RFR.RDB$FIELD_POSITION > relation->rel_max_field_pos) relation->rel_max_field_pos = RFR.RDB$FIELD_POSITION; - *ptr = field = (QLI_FLD) ALLOCPV(type_fld, 0); + QLI_FLD field = (QLI_FLD) ALLOCPV(type_fld, 0); + *ptr = field; ptr = &field->fld_next; field->fld_relation = relation; - if (symbol = make_symbol(RFR.RDB$FIELD_NAME, sizeof(RFR.RDB$FIELD_NAME))) { + SYM symbol = make_symbol(RFR.RDB$FIELD_NAME, sizeof(RFR.RDB$FIELD_NAME)); + if (symbol) { symbol->sym_object = (BLK) field; symbol->sym_type = SYM_field; field->fld_name = symbol; @@ -857,13 +843,14 @@ void MET_fields( QLI_REL relation) if (RFL.RDB$SEGMENT_LENGTH.NULL) field->fld_segment_length = 80; - else + else { field->fld_segment_length = ((RFL.RDB$SEGMENT_LENGTH) < 256 && (RFL.RDB$SEGMENT_LENGTH > 0)) ? RFL.RDB$SEGMENT_LENGTH : 255; + } - blob = (SLONG *) & RFR.RDB$QUERY_HEADER; + SLONG* blob = (SLONG*) & RFR.RDB$QUERY_HEADER; if (!blob[0] && !blob[1]) blob = (SLONG *) & RFL.RDB$QUERY_HEADER; if (blob[0] || blob[1]) @@ -912,20 +899,16 @@ void MET_finish( DBB dbb) * Finish a database and release all associated blocks. * **************************************/ - ISC_STATUS_ARRAY status_vector; - DBB *ptr; +// Get rid of relation and field blocks. + QLI_REL relation; - FUN function; - SCHAR count; - -// Get rid of relation and field blocks. - while (relation = dbb->dbb_relations) { purge_relation(relation); } -// Get rid of any functions +// Get rid of any functions + FUN function; while (function = dbb->dbb_functions) { dbb->dbb_functions = function->fun_next; HSH_remove(function->fun_symbol); @@ -933,8 +916,9 @@ void MET_finish( DBB dbb) ALL_release((FRB) function); } -// Finally, actually close down database connection. +// Finally, actually close down database connection. + ISC_STATUS_ARRAY status_vector; detach(status_vector, dbb); if (dbb->dbb_symbol) { @@ -942,7 +926,8 @@ void MET_finish( DBB dbb) ALL_release((FRB) dbb->dbb_symbol); } - for (count = 0, ptr = &QLI_databases; *ptr; ptr = &(*ptr)->dbb_next) + int count = 0; + for (DBB* ptr = &QLI_databases; *ptr; ptr = &(*ptr)->dbb_next) { if (*ptr == dbb) { @@ -956,7 +941,7 @@ void MET_finish( DBB dbb) } if (!count) - BUGCHECK(231); // Msg231 database block not found for removal + BUGCHECK(231); // Msg231 database block not found for removal if (status_vector[1]) ERRQ_database_error(NULL, status_vector); @@ -977,34 +962,51 @@ int MET_get_datatype( USHORT blr_datatype) **************************************/ USHORT retvalue; - if (blr_datatype == blr_text) + switch (blr_datatype) + { + case blr_text: retvalue = dtype_text; - else if (blr_datatype == blr_varying) + break; + case blr_varying: retvalue = dtype_varying; - else if (blr_datatype == blr_cstring) + break; + case blr_cstring: retvalue = dtype_cstring; - else if (blr_datatype == blr_short) + break; + case blr_short: retvalue = dtype_short; - else if (blr_datatype == blr_long) + break; + case blr_long: retvalue = dtype_long; - else if (blr_datatype == blr_quad) + break; + case blr_quad: retvalue = dtype_quad; - else if (blr_datatype == blr_float) + break; + case blr_float: retvalue = dtype_real; - else if (blr_datatype == blr_double) + break; + case blr_double: retvalue = dtype_double; - else if (blr_datatype == blr_timestamp) + break; + case blr_timestamp: retvalue = dtype_timestamp; - else if (blr_datatype == blr_sql_date) + break; + case blr_sql_date: retvalue = dtype_sql_date; - else if (blr_datatype == blr_sql_time) + break; + case blr_sql_time: retvalue = dtype_sql_time; - else if (blr_datatype == blr_blob) + break; + case blr_blob: retvalue = dtype_blob; - else if (blr_datatype == blr_int64) + break; + case blr_int64: retvalue = dtype_int64; - else + break; + default: retvalue = dtype_null; + break; + } return retvalue; } @@ -1026,8 +1028,7 @@ void MET_index_info(const SCHAR* relation_name, * Get info about a particular index. * **************************************/ - FRBRD *request_handle = NULL; - SCHAR *p; + FRBRD* request_handle = NULL; SCHAR* b = buffer; FOR(REQUEST_HANDLE request_handle) @@ -1036,15 +1037,18 @@ void MET_index_info(const SCHAR* relation_name, RDB$INDEX_NAME WITH IDX.RDB$INDEX_NAME EQ index_name AND IDX.RDB$RELATION_NAME EQ relation_name - SORTED BY SEG.RDB$FIELD_POSITION + SORTED BY SEG.RDB$FIELD_POSITION + const SCHAR* p; if (b == buffer) { + // CVC: warning: not dialect 3 aware. for (p = IDX.RDB$INDEX_NAME; *p && *p != ' ';) { *b++ = *p++; } *b++ = ' '; *b++ = '('; - } + } + // CVC: warning: not dialect 3 aware. for (p = SEG.RDB$FIELD_NAME; *p && *p != ' ';) { *b++ = *p++; } @@ -1060,7 +1064,7 @@ void MET_index_info(const SCHAR* relation_name, if (gds__release_request(gds_status, &request_handle)) ERRQ_database_error(NULL, gds_status); -// back up over the last space and finish off +// back up over the last space and finish off b--; *b++ = ')'; @@ -1082,13 +1086,14 @@ void MET_meta_commit( DBB database) * transaction. * **************************************/ - ISC_STATUS_ARRAY status_vector; - if (database->dbb_capabilities & DBB_cap_multi_trans) + { + ISC_STATUS_ARRAY status_vector; if (gds__commit_transaction(status_vector, &database->dbb_meta_trans)) { rollback_update(database); ERRQ_database_error(database, status_vector); } + } } @@ -1123,10 +1128,10 @@ FRBRD *MET_meta_transaction(DBB database, int update_flag) * Setup transaction for meta-data operation. Set up * DB and gds_trans, and return meta-data transaction * handle for yucks. If we're doing metadata updates, - * and lookups we'll use the metadat date transaction, - * unless this is an rdb database or gateway in which + * and lookups we'll use the metadat date transaction, + * unless this is an rdb database or gateway in which * case, we'll use the only transacti. - * + * * In any event, we will set up the met_transaction because * it's widely used and somebody is going to forget to test * that the database is multi_transaction before using it. @@ -1135,12 +1140,11 @@ FRBRD *MET_meta_transaction(DBB database, int update_flag) * **************************************/ ISC_STATUS_ARRAY status_vector; - FRBRD *transaction; if (!database) - IBERROR(243); // Msg243 no active database for operation + IBERROR(243); // Msg243 no active database for operation - transaction = (database->dbb_capabilities & DBB_cap_multi_trans) ? + FRBRD* transaction = (database->dbb_capabilities & DBB_cap_multi_trans) ? database->dbb_meta_trans : NULL; DB = database->dbb_handle; @@ -1163,21 +1167,21 @@ FRBRD *MET_meta_transaction(DBB database, int update_flag) } } -/* If we already have a meta-data transaction, there's more nothing to do */ +// If we already have a meta-data transaction, there's more nothing to do gds_trans = transaction; -// If we only support a single transaction, use the data transaction +// If we only support a single transaction, use the data transaction if (!gds_trans && (database->dbb_capabilities & DBB_cap_single_trans)) { if (update_flag) - IBERROR(244); // Msg244 Interactive metadata updates are not available on Rdb + IBERROR(244); // Msg244 Interactive metadata updates are not available on Rdb if (!(gds_trans = database->dbb_transaction)) gds_trans = MET_transaction(nod_start_trans, database); } -// otherwise make one more effort to start the transaction +// otherwise make one more effort to start the transaction else if (!gds_trans) { @@ -1204,14 +1208,11 @@ void MET_modify_field( DBB database, QLI_FLD field) * Modify an existing global field. * **************************************/ - SYM symbol, field_name; - QLI_REL relation; TEXT *p; - SSHORT flag; database = setup_update(database); - field_name = field->fld_name; - flag = 0; + SYM field_name = field->fld_name; + SSHORT flag = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_modify_fld]) X IN DB.RDB$FIELDS WITH X.RDB$FIELD_NAME EQ field_name->sym_string @@ -1236,9 +1237,10 @@ void MET_modify_field( DBB database, QLI_FLD field) X.RDB$FIELD_SUB_TYPE.NULL = FALSE; X.RDB$FIELD_SUB_TYPE = field->fld_sub_type; } - if (symbol = field->fld_query_name) { + SYM asymbol = field->fld_query_name; + if (asymbol) { X.RDB$QUERY_NAME.NULL = FALSE; - strcpy(X.RDB$QUERY_NAME, symbol->sym_string); + strcpy(X.RDB$QUERY_NAME, asymbol->sym_string); } if (field->fld_edit_string) { X.RDB$EDIT_STRING.NULL = FALSE; @@ -1259,15 +1261,15 @@ void MET_modify_field( DBB database, QLI_FLD field) if (flag <= 0) { rollback_update(database); - /* Msg245 global field %s is not defined */ - /* Msg468 Datatype of field %s may not be changed to or from blob */ + // Msg245 global field %s is not defined + // Msg468 Datatype of field %s may not be changed to or from blob const USHORT nErr = flag ? 468 : 245; ERRQ_print_error(flag, field_name->sym_string, NULL, NULL, NULL, NULL); } MET_meta_commit(database); -// Now go back and re-fetch fields for affected databases +// Now go back and re-fetch fields for affected databases setup_update(database); @@ -1275,14 +1277,15 @@ void MET_modify_field( DBB database, QLI_FLD field) X IN DB.RDB$RELATION_FIELDS WITH X.RDB$FIELD_SOURCE EQ field_name->sym_string REDUCED TO X.RDB$RELATION_NAME - p = X.RDB$RELATION_NAME; + p = X.RDB$RELATION_NAME; while (*p && *p != ' ') { p++; } - symbol = HSH_lookup(X.RDB$RELATION_NAME, p - X.RDB$RELATION_NAME); + SYM symbol = HSH_lookup(X.RDB$RELATION_NAME, p - X.RDB$RELATION_NAME); for (; symbol; symbol = symbol->sym_homonym) { + QLI_REL relation; if (symbol->sym_type == SYM_relation && (relation = (QLI_REL) symbol->sym_object) && relation->rel_database == database) @@ -1311,15 +1314,11 @@ void MET_modify_index( SYN node) * of an index. * **************************************/ - DBB database; - NAM name; - USHORT count; - - name = (NAM) node->syn_arg[s_mfi_name]; - database = (DBB) node->syn_arg[s_mfi_database]; + NAM name = (NAM) node->syn_arg[s_mfi_name]; + DBB database = (DBB) node->syn_arg[s_mfi_database]; database = setup_update(database); - count = 0; + USHORT count = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_mdf_index]) X IN DB.RDB$INDICES WITH X.RDB$INDEX_NAME = name->nam_string @@ -1348,7 +1347,7 @@ void MET_modify_index( SYN node) if (!count) ERRQ_print_error(246, name->nam_string, database->dbb_filename, NULL, - NULL, NULL); /* Msg246 Index %s does not exist */ + NULL, NULL); // Msg246 Index %s does not exist MET_meta_commit(database); } @@ -1366,22 +1365,19 @@ void MET_modify_relation( QLI_REL relation, QLI_FLD fields) * Modify an existing relation. * **************************************/ - DBB database; - SYM relation_name, field_name; - QLI_FLD field; - USHORT count; + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; + SYM relation_name = relation->rel_symbol; - relation->rel_database = database = setup_update(relation->rel_database); - relation_name = relation->rel_symbol; - - for (field = fields; field; field = field->fld_next) + for (QLI_FLD field = fields; field; field = field->fld_next) + { if (field->fld_flags & FLD_drop) { - count = 0; - field_name = field->fld_name; + USHORT count = 0; + SYM field_name = field->fld_name; FOR(REQUEST_HANDLE database->dbb_requests[REQ_modify_rel]) X IN DB.RDB$RELATION_FIELDS WITH X.RDB$FIELD_NAME EQ field_name->sym_string AND - X.RDB$RELATION_NAME EQ relation_name->sym_string + X.RDB$RELATION_NAME EQ relation_name->sym_string count++; ERASE X ON_ERROR @@ -1396,13 +1392,14 @@ void MET_modify_relation( QLI_REL relation, QLI_FLD fields) if (!count) { rollback_update(database); ERRQ_print_error(247, field_name->sym_string, NULL, NULL, - NULL, NULL); /* Msg247 field %s doesn't exist */ + NULL, NULL); // Msg247 field %s doesn't exist } } else if (field->fld_flags & FLD_modify) change_field(relation, field); else add_field(relation, field, 0); + } MET_meta_commit(database); setup_update(database); @@ -1424,23 +1421,17 @@ void MET_ready( SYN node, USHORT create_flag) * fail, all fail. Fair enough? * **************************************/ - DBB temp, dbb; - SYN *ptr, *ptr2, *end; - ISC_STATUS_ARRAY status_vector; - SSHORT dpb_length, length; - UCHAR *dpb, *p; - TEXT *q; - TEXT *lc_ctype; - - p = parm_buffer; - temp = (DBB) node->syn_arg[0]; + UCHAR* p = global_parm_buffer; + DBB temp = (DBB) node->syn_arg[0]; /* Only a SQL CREATE DATABASE will have a pagesize parameter, so only looking at the first pointer is justified. */ *p++ = gds_dpb_version1; - if ((lc_ctype = QLI_charset) && (length = strlen(lc_ctype))) { + SSHORT length; + const TEXT* lc_ctype = QLI_charset; + if (lc_ctype && (length = strlen(lc_ctype))) { *p++ = gds_dpb_lc_ctype; *p++ = length; while (*lc_ctype) @@ -1470,6 +1461,7 @@ void MET_ready( SYN node, USHORT create_flag) /* get a username, if specified globally or on the command line */ + const TEXT* q; if (temp->dbb_user) { q = (TEXT *) temp->dbb_user->con_data; length = temp->dbb_user->con_desc.dsc_length; @@ -1485,7 +1477,7 @@ void MET_ready( SYN node, USHORT create_flag) *p++ = *q++; } -// get a password, if specified +// get a password, if specified if (temp->dbb_password) { q = (TEXT *) temp->dbb_password->con_data; @@ -1502,20 +1494,24 @@ void MET_ready( SYN node, USHORT create_flag) *p++ = *q++; } - dpb_length = p - parm_buffer; + USHORT dpb_length = p - global_parm_buffer; + UCHAR* dpb; if (dpb_length == 1) { dpb = NULL; dpb_length = 0; } else - dpb = parm_buffer; + dpb = global_parm_buffer; - end = node->syn_arg + node->syn_count; + SYN* const end = node->syn_arg + node->syn_count; -// Start by attaching all databases +// Start by attaching all databases + ISC_STATUS_ARRAY status_vector; + SYN* ptr; + DBB dbb; for (ptr = node->syn_arg; ptr < end; ptr++) { - dbb = (DBB) * ptr; + dbb = (DBB) *ptr; if (create_flag) gds__create_database(status_vector, 0, dbb->dbb_filename, &dbb->dbb_handle, dpb_length, (char*) dpb, 0); @@ -1526,16 +1522,16 @@ void MET_ready( SYN node, USHORT create_flag) break; } -// If any attach failed, cleanup and give up +// If any attach failed, cleanup and give up if (ptr < end) { - for (ptr2 = node->syn_arg; ptr2 < ptr; ptr2++) + for (SYN* ptr2 = node->syn_arg; ptr2 < ptr; ptr2++) detach(gds_status, (DBB) *ptr2); ERRQ_database_error(dbb, status_vector); } -// Databases are up and running. Install each. +// Databases are up and running. Install each. for (ptr = node->syn_arg; ptr < end; ptr++) install((DBB) *ptr); @@ -1555,9 +1551,8 @@ void MET_shutdown(void) * **************************************/ ISC_STATUS_ARRAY status_vector; - DBB dbb; - for (dbb = QLI_databases; dbb; dbb = dbb->dbb_next) + for (DBB dbb = QLI_databases; dbb; dbb = dbb->dbb_next) if (detach(status_vector, dbb)) gds__print_status(status_vector); } @@ -1575,15 +1570,10 @@ void MET_sql_alter_table( QLI_REL relation, QLI_FLD fields) * Alter table data based on a SQL metadata request * **************************************/ - DBB database; - SYM symbol; - QLI_FLD field; - RLB rlb; - USHORT count; - - symbol = relation->rel_symbol; - relation->rel_database = database = setup_update(relation->rel_database); - count = 0; + SYM symbol = relation->rel_symbol; + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; + USHORT count = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_relation_def]) X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ symbol->sym_string @@ -1593,10 +1583,10 @@ void MET_sql_alter_table( QLI_REL relation, QLI_FLD fields) ERRQ_database_error(database, gds_status); END_ERROR; if (!count) - ERRQ_print_error(414, symbol->sym_string, NULL, NULL, NULL, NULL); /* Msg237 Relation %s is lost */ + ERRQ_print_error(414, symbol->sym_string, NULL, NULL, NULL, NULL); // Msg237 Relation %s is lost - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); @@ -1604,7 +1594,7 @@ void MET_sql_alter_table( QLI_REL relation, QLI_FLD fields) STUFF(gds_dyn_mod_rel); STUFF_STRING(symbol->sym_string); - for (field = fields; field; field = field->fld_next) { + for (QLI_FLD field = fields; field; field = field->fld_next) { if (field->fld_flags & FLD_add) add_sql_field(relation, field, 0, rlb); else if (field->fld_flags & FLD_drop) { @@ -1639,16 +1629,12 @@ void MET_sql_cr_view( SYN node) * Create a view from a SQL metadata request * **************************************/ - QLI_REL relation; - DBB database; - SYM symbol; - RLB rlb; + QLI_REL relation = (QLI_REL) node->syn_arg[s_crv_name]; + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; + SYM symbol = relation->rel_symbol; - relation = (QLI_REL) node->syn_arg[s_crv_name]; - relation->rel_database = database = setup_update(relation->rel_database); - symbol = relation->rel_symbol; - - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); STUFF(gds_dyn_begin); @@ -1656,7 +1642,7 @@ void MET_sql_cr_view( SYN node) STUFF(gds_dyn_def_view); STUFF_STRING(symbol->sym_string); -// The meat of the blr generation will go here +// The meat of the blr generation will go here STUFF(gds_dyn_end); STUFF(gds_dyn_eoc); @@ -1758,17 +1744,14 @@ static void add_field( QLI_REL relation, QLI_FLD field, USHORT position) * Add a field to a relation. Do all sorts of sanity checks. * **************************************/ - DBB database; - SYM relation_name, field_name, symbol, global_field; - bool global_flag; - - database = relation->rel_database; - relation_name = relation->rel_symbol; - field_name = field->fld_name; - if (!(global_field = field->fld_based)) + DBB database = relation->rel_database; + SYM relation_name = relation->rel_symbol; + SYM field_name = field->fld_name; + SYM global_field = field->fld_based; + if (!global_field) global_field = field_name; -// Check to see if it already exits in relation +// Check to see if it already exits in relation FOR(REQUEST_HANDLE database->dbb_requests[REQ_rfr_def]) X IN DB.RDB$RELATION_FIELDS WITH @@ -1776,15 +1759,15 @@ static void add_field( QLI_REL relation, QLI_FLD field, USHORT position) X.RDB$FIELD_NAME EQ field_name->sym_string rollback_update(relation->rel_database); ERRQ_print_error(251, field_name->sym_string, - relation_name->sym_string, NULL, NULL, NULL); /* Msg251 Field %s already exists in relation %s */ + relation_name->sym_string, NULL, NULL, NULL); // Msg251 Field %s already exists in relation %s END_FOR ON_ERROR ERRQ_database_error(database, gds_status); END_ERROR; -/* Check global field. Define it if it doesn't exist. */ +// Check global field. Define it if it doesn't exist. - global_flag = false; + bool global_flag = false; if (!check_global_field(database, field, global_field->sym_string)) { global_flag = true; define_global_field(database, field, global_field); @@ -1806,6 +1789,7 @@ static void add_field( QLI_REL relation, QLI_FLD field, USHORT position) } else X.RDB$FIELD_POSITION.NULL = TRUE; + SYM symbol; if (!global_flag && (symbol = field->fld_query_name)) { X.RDB$QUERY_NAME.NULL = FALSE; strcpy(X.RDB$QUERY_NAME, symbol->sym_string); @@ -1839,16 +1823,12 @@ static void add_sql_field( QLI_REL relation, QLI_FLD field, USHORT position, RLB * Add a SQL field to a relation via dyn. * **************************************/ - DBB database; - SYM relation_name, field_name; - USHORT l; - rlb = CHECK_RLB(rlb); - database = relation->rel_database; - relation_name = relation->rel_symbol; - field_name = field->fld_name; + DBB database = relation->rel_database; + SYM relation_name = relation->rel_symbol; + SYM field_name = field->fld_name; -// Check to see if it already exits in relation +// Check to see if it already exits in relation FOR(REQUEST_HANDLE database->dbb_requests[REQ_rfr_def]) X IN DB.RDB$RELATION_FIELDS WITH @@ -1856,7 +1836,7 @@ static void add_sql_field( QLI_REL relation, QLI_FLD field, USHORT position, RLB X.RDB$FIELD_NAME EQ field_name->sym_string rollback_update(relation->rel_database); ERRQ_print_error(251, field_name->sym_string, - relation_name->sym_string, NULL, NULL, NULL); /* Msg251 Field %s already exists in relation %s */ + relation_name->sym_string, NULL, NULL, NULL); // Msg251 Field %s already exists in relation %s END_FOR ON_ERROR ERRQ_database_error(database, gds_status); @@ -1872,10 +1852,8 @@ static void add_sql_field( QLI_REL relation, QLI_FLD field, USHORT position, RLB STUFF(gds_dyn_fld_length); STUFF_WORD(2); - l = - (field->fld_dtype == - dtype_varying) ? field->fld_length - - sizeof(SSHORT) : field->fld_length; + const USHORT l = (field->fld_dtype == dtype_varying) + ? field->fld_length - sizeof(SSHORT) : field->fld_length; STUFF_WORD(l); STUFF(gds_dyn_fld_scale); @@ -1920,17 +1898,12 @@ static int blob_copy( RLB rlb, QLI_REL source, SLONG * source_blob_id) * language block to stick it into a new definition. * **************************************/ - DBB source_dbb; - FRBRD *source_blob; - SLONG size, segment_count, max_segment; ISC_STATUS_ARRAY status_vector; - USHORT length, buffer_length; - TEXT *buffer, fixed_buffer[4096], *p; - source_dbb = + DBB source_dbb = (source->rel_database) ? source->rel_database : QLI_databases; DB = source_dbb->dbb_handle; - source_blob = NULL; + FRBRD* source_blob = NULL; if (gds__open_blob(status_vector, &DB, &source_dbb->dbb_meta_trans, &source_blob, (GDS__QUAD*) source_blob_id)) { @@ -1938,8 +1911,12 @@ static int blob_copy( RLB rlb, QLI_REL source, SLONG * source_blob_id) ERRQ_database_error(source_dbb, status_vector); } + SLONG size, segment_count, max_segment; gds__blob_size(&source_blob, (SLONG*) &size, &segment_count, &max_segment); + TEXT fixed_buffer[4096]; + TEXT* buffer; + USHORT buffer_length; if (max_segment < sizeof(fixed_buffer)) { buffer_length = sizeof(fixed_buffer); buffer = fixed_buffer; @@ -1951,11 +1928,13 @@ static int blob_copy( RLB rlb, QLI_REL source, SLONG * source_blob_id) STUFF_WORD((USHORT) size); + USHORT length; while (!gds__get_segment(status_vector, &source_blob, &length, - buffer_length, buffer)) { + buffer_length, buffer)) + { while (rlb->rlb_limit - rlb->rlb_data < length) rlb = GEN_rlb_extend(rlb); - p = buffer; + const TEXT* p = buffer; while (length--) STUFF(*p++); } @@ -1991,39 +1970,39 @@ static void change_field( QLI_REL relation, QLI_FLD field) * Change optional attributes of a field. * **************************************/ - DBB database; - SYM relation_name, field_name, symbol, global_field; - USHORT count; - - database = relation->rel_database; - relation_name = relation->rel_symbol; - field_name = field->fld_name; - global_field = field->fld_based; + DBB database = relation->rel_database; + SYM relation_name = relation->rel_symbol; + SYM field_name = field->fld_name; + SYM global_field = field->fld_based; if (field->fld_dtype) { rollback_update(database); - ERRQ_print_error(252, NULL, NULL, NULL, NULL, NULL); // Msg252 datatype can not be changed locally + ERRQ_print_error(252, NULL, NULL, NULL, NULL, NULL); + // Msg252 datatype can not be changed locally } if (global_field && - !(check_global_field(database, NULL, global_field->sym_string))) { + !(check_global_field(database, NULL, global_field->sym_string))) + { rollback_update(database); - ERRQ_print_error(253, global_field->sym_string, NULL, NULL, NULL, NULL); /* Msg253 global field %s does not exist */ + ERRQ_print_error(253, global_field->sym_string, NULL, NULL, NULL, NULL); + // Msg253 global field %s does not exist } -// Modify RFR - count = 0; +// Modify RFR + USHORT count = 0; FOR(REQUEST_HANDLE database->dbb_requests[REQ_mdf_rfr]) X IN DB.RDB$RELATION_FIELDS WITH X.RDB$RELATION_NAME = relation_name->sym_string AND - X.RDB$FIELD_NAME = field_name->sym_string + X.RDB$FIELD_NAME = field_name->sym_string count++; MODIFY X USING if (global_field) strcpy(X.RDB$FIELD_SOURCE, global_field->sym_string); - if (symbol = field->fld_query_name) + SYM symbol = field->fld_query_name; + if (symbol) strcpy(X.RDB$QUERY_NAME, symbol->sym_string); if (field->fld_edit_string) strcpy(X.RDB$EDIT_STRING, field->fld_edit_string); @@ -2041,7 +2020,7 @@ static void change_field( QLI_REL relation, QLI_FLD field) if (!count) { rollback_update(database); ERRQ_print_error(254, field_name->sym_string, - relation_name->sym_string, NULL, NULL, NULL); /* Msg254 field %s not found in relation %s */ + relation_name->sym_string, NULL, NULL, NULL); // Msg254 field %s not found in relation %s } } @@ -2052,7 +2031,7 @@ static bool check_global_field(DBB database, { /************************************** * - * c h e c k _ g l o b a l _ f i e l d + * c h e c k _ g l o b a l _ f i e l d * ************************************** * @@ -2064,10 +2043,9 @@ static bool check_global_field(DBB database, * **************************************/ bool previously_defined = false; - SLONG *blob; FOR(REQUEST_HANDLE database->dbb_requests[REQ_field_def]) - X IN DB.RDB$FIELDS WITH X.RDB$FIELD_NAME EQ name + X IN DB.RDB$FIELDS WITH X.RDB$FIELD_NAME EQ name if (field) { @@ -2079,7 +2057,7 @@ static bool check_global_field(DBB database, X.RDB$FIELD_SCALE != field->fld_scale)) { rollback_update(database); - ERRQ_print_error(255, name, NULL, NULL, NULL, NULL); /* Msg255 Datatype conflict with existing global field %s */ + ERRQ_print_error(255, name, NULL, NULL, NULL, NULL); // Msg255 Datatype conflict with existing global field %s } field->fld_dtype = MET_get_datatype(X.RDB$FIELD_TYPE); field->fld_length = @@ -2102,7 +2080,7 @@ static bool check_global_field(DBB database, } if (!field->fld_query_header) { - blob = (SLONG *) & X.RDB$QUERY_HEADER; + SLONG* blob = (SLONG *) &X.RDB$QUERY_HEADER; if (blob[0] || blob[1]) { field->fld_query_header = @@ -2124,7 +2102,7 @@ static bool check_relation( QLI_REL relation) { /************************************** * - * c h e c k _ r e l a t i o n + * c h e c k _ r e l a t i o n * ************************************** * @@ -2133,14 +2111,12 @@ static bool check_relation( QLI_REL relation) * **************************************/ bool previously_defined = false; - FRBRD *spare; - - spare = DB; + FRBRD* spare = DB; DB = relation->rel_database->dbb_handle; FOR(REQUEST_HANDLE relation->rel_database->dbb_requests[REQ_relation_def] TRANSACTION_HANDLE relation->rel_database->dbb_meta_trans) - X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ relation->rel_symbol->sym_string + X IN DB.RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ relation->rel_symbol->sym_string previously_defined = true; END_FOR ON_ERROR @@ -2156,7 +2132,7 @@ static int clone_fields( QLI_REL target, QLI_REL source) { /************************************** * - * c l o n e _ f i e l d s + * c l o n e _ f i e l d s * ************************************** * @@ -2169,14 +2145,13 @@ static int clone_fields( QLI_REL target, QLI_REL source) * * If it's two different databases, create the global * fields that are missing in the target (except those - * that support computed fields), then create the local + * that support computed fields), then create the local * fields and during that pass create the computed * fields and the SQL fields. * **************************************/ FRBRD *req1, *req2; FRBRD *t_trans, *s_trans; - RLB rlb; req1 = req2 = NULL; s_trans = t_trans = gds_trans; @@ -2190,7 +2165,7 @@ static int clone_fields( QLI_REL target, QLI_REL source) if (target->rel_database != source->rel_database) clone_global_fields(target, source); - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); @@ -2202,7 +2177,7 @@ static int clone_fields( QLI_REL target, QLI_REL source) CROSS F IN DB.RDB$FIELDS WITH Y.RDB$RELATION_NAME = source->rel_symbol->sym_string AND Y.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME - // If SQL made this field, create a new global field for it + // If SQL made this field, create a new global field for it if (F.RDB$COMPUTED_BLR.NULL && (strncmp("RDB$", Y.RDB$FIELD_NAME, 4)) && (!(strncmp("RDB$", F.RDB$FIELD_NAME, 4)))) @@ -2345,7 +2320,7 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) { /************************************** * - * c l o n e _ g l o b a l _ f i e l d s + * c l o n e _ g l o b a l _ f i e l d s * ************************************** * @@ -2353,7 +2328,7 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) * Copy the global field definitions required by a relation * from one database into another. Both databases are * setup correctly. (Set up the handles again just because - * we're compulsive.) + * we're compulsive.) * * In this routine, as in clone fields, be careful to probe * for our extensions rather than just using them so we @@ -2368,32 +2343,28 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) * **************************************/ FRBRD *req1, *req2, *req3; - FRBRD *t_trans, *s_trans; - TEXT *name; - SSHORT first_field, first_dimension, predefined; - RLB rlb; - req1 = req2 = req3 = NULL; - s_trans = source->rel_database->dbb_meta_trans; - t_trans = target->rel_database->dbb_meta_trans; + + FRBRD* s_trans = source->rel_database->dbb_meta_trans; + FRBRD* t_trans = target->rel_database->dbb_meta_trans; DB = source->rel_database->dbb_handle; DB1 = target->rel_database->dbb_handle; - rlb = NULL; - first_field = TRUE; + RLB rlb = NULL; + bool first_field = true; FOR(REQUEST_HANDLE req1 TRANSACTION_HANDLE s_trans) RFR IN DB.RDB$RELATION_FIELDS CROSS Y IN DB.RDB$FIELDS - WITH RFR.RDB$RELATION_NAME = source->rel_symbol->sym_string AND - Y.RDB$FIELD_NAME = RFR.RDB$FIELD_SOURCE REDUCED TO Y.RDB$FIELD_NAME + WITH RFR.RDB$RELATION_NAME = source->rel_symbol->sym_string AND + Y.RDB$FIELD_NAME = RFR.RDB$FIELD_SOURCE REDUCED TO Y.RDB$FIELD_NAME if (!Y.RDB$COMPUTED_BLR.NULL || ((strncmp("RDB$",RFR.RDB$FIELD_NAME,4)) && (!(strncmp("RDB$", Y.RDB$FIELD_NAME,4))))) continue; - predefined = FALSE; + bool predefined = false; FOR(REQUEST_HANDLE req2 TRANSACTION_HANDLE t_trans) A IN DB1.RDB$FIELDS WITH A.RDB$FIELD_NAME = Y.RDB$FIELD_NAME @@ -2404,15 +2375,18 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) (A.RDB$FIELD_SCALE != Y.RDB$FIELD_SCALE)) || (A.RDB$FIELD_SUB_TYPE.NULL != Y.RDB$FIELD_SUB_TYPE.NULL) || ((!Y.RDB$FIELD_SUB_TYPE.NULL) - && (A.RDB$FIELD_SUB_TYPE != Y.RDB$FIELD_SUB_TYPE))) { + && (A.RDB$FIELD_SUB_TYPE != Y.RDB$FIELD_SUB_TYPE))) + { - name = (TEXT *) ALLQ_malloc((SLONG) sizeof(Y.RDB$FIELD_NAME)); - strcpy(name, Y.RDB$FIELD_NAME); - rollback_update(target->rel_database); - ERRQ_error(413, name, NULL, NULL, NULL, NULL); // conflicting previous definition - } + TEXT* name = (TEXT*) ALLQ_malloc((SLONG) sizeof(Y.RDB$FIELD_NAME)); + strcpy(name, Y.RDB$FIELD_NAME); + rollback_update(target->rel_database); + // CVC: When is this memory deallocated? + ERRQ_error(413, name, NULL, NULL, NULL, NULL); + // conflicting previous definition + } else - predefined = TRUE; + predefined = true; END_FOR ON_ERROR ERRQ_database_error(target->rel_database, gds_status); @@ -2425,7 +2399,7 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); STUFF(gds_dyn_begin); - first_field = FALSE; + first_field = false; } STUFF(gds_dyn_def_global_fld); STUFF_STRING(Y.RDB$FIELD_NAME); @@ -2504,19 +2478,19 @@ static int clone_global_fields( QLI_REL target, QLI_REL source) if ((target->rel_database->dbb_capabilities & DBB_cap_dimensions) && (source->rel_database->dbb_capabilities & DBB_cap_dimensions)) { - first_dimension = TRUE; + bool first_dimension = true; FOR(REQUEST_HANDLE req3 TRANSACTION_HANDLE s_trans) F IN DB.RDB$FIELDS CROSS D IN DB.RDB$FIELD_DIMENSIONS WITH F.RDB$FIELD_NAME = D.RDB$FIELD_NAME AND - F.RDB$FIELD_NAME = Y.RDB$FIELD_NAME + F.RDB$FIELD_NAME = Y.RDB$FIELD_NAME if (first_dimension) { - first_dimension = FALSE; + first_dimension = false; STUFF(gds_dyn_fld_dimensions); STUFF_WORD(2); STUFF_WORD(F.RDB$DIMENSIONS); - } + } STUFF(gds_dyn_def_dimension); STUFF_WORD(2); @@ -2574,7 +2548,7 @@ static void define_global_field( DBB database, QLI_FLD field, SYM name) { /************************************** * - * d e f i n e _ g l o b a l _ f i e l d + * d e f i n e _ g l o b a l _ f i e l d * ************************************** * @@ -2584,15 +2558,13 @@ static void define_global_field( DBB database, QLI_FLD field, SYM name) * information. * **************************************/ - SYM symbol; - - if (!field->fld_dtype) { rollback_update(database); - ERRQ_print_error(256, name->sym_string, NULL, NULL, NULL, NULL); /* Msg256 No datatype specified for field %s */ + ERRQ_print_error(256, name->sym_string, NULL, NULL, NULL, NULL); // Msg256 No datatype specified for field %s } + STORE(REQUEST_HANDLE database->dbb_requests[REQ_store_field]) - X IN DB.RDB$FIELDS + X IN DB.RDB$FIELDS strcpy(X.RDB$FIELD_NAME, name->sym_string); X.RDB$FIELD_TYPE = blr_dtypes[field->fld_dtype]; X.RDB$FIELD_SCALE = field->fld_scale; @@ -2604,7 +2576,8 @@ static void define_global_field( DBB database, QLI_FLD field, SYM name) } else X.RDB$FIELD_SUB_TYPE.NULL = TRUE; - if (symbol = field->fld_query_name) { + SYM symbol = field->fld_query_name; + if (symbol) { X.RDB$QUERY_NAME.NULL = FALSE; strcpy(X.RDB$QUERY_NAME, symbol->sym_string); } @@ -2636,9 +2609,7 @@ static void delete_fields( QLI_REL relation) * Delete field definitions. * **************************************/ - QLI_FLD field; - - while (field = relation->rel_fields) { + while (QLI_FLD field = relation->rel_fields) { relation->rel_fields = field->fld_next; ALL_release((FRB) field->fld_name); if (field->fld_query_name) @@ -2664,13 +2635,11 @@ static ISC_STATUS detach(ISC_STATUS * status_vector, * first failing call, if any. * **************************************/ - ISC_STATUS *status; - ISC_STATUS_ARRAY alt_vector; - if (!dbb->dbb_handle) return FB_SUCCESS; - status = status_vector; + ISC_STATUS_ARRAY alt_vector; + ISC_STATUS* status = status_vector; if (dbb->dbb_transaction) if (gds__commit_transaction(status, &dbb->dbb_transaction)) @@ -2702,9 +2671,7 @@ static void execute_dynamic_ddl( DBB database, RLB rlb) * Execute a ddl command, for better or for worse. * **************************************/ - USHORT length; - - length = (UCHAR *) rlb->rlb_data - (UCHAR *) rlb->rlb_base; + const USHORT length = (UCHAR *) rlb->rlb_data - (UCHAR *) rlb->rlb_base; if (QLI_blr) PRETTY_print_dyn((SCHAR*) rlb->rlb_base, (FPTR_INT) ib_printf, "%4d %s\n", 0); @@ -2766,13 +2733,11 @@ static void get_database_type( DBB new_dbb) ************************************** * * Functional description - * Ask what type of database this is. + * Ask what type of database this is. * **************************************/ ISC_STATUS_ARRAY status_vector; - int count; - USHORT l; - UCHAR item, buffer[1024], *p, *q; + UCHAR buffer[1024]; gds__database_info(status_vector, &new_dbb->dbb_handle, sizeof(db_info), (char*) db_info, sizeof(buffer), (char*) buffer); @@ -2780,25 +2745,28 @@ static void get_database_type( DBB new_dbb) if (status_vector[1]) ERRQ_database_error(new_dbb, gds_status); - p = buffer; + UCHAR* p = buffer; while (*p != gds_info_end && p < buffer + sizeof(buffer)) { - item = *p++; - l = gds__vax_integer(p, 2); + UCHAR item = *p++; + USHORT l = gds__vax_integer(p, 2); p += 2; switch (item) { case gds_info_implementation: - q = p; - count = *q++; + { + const UCHAR* q = p; + int count = *q++; while (count--) { new_dbb->dbb_type = *q++; if (*q++ == gds_info_db_class_access) break; } break; + } default: - ERRQ_error(257, NULL, NULL, NULL, NULL, NULL); // Msg257 database info call failed + ERRQ_error(257, NULL, NULL, NULL, NULL, NULL); + // Msg257 database info call failed } p += l; } @@ -2823,18 +2791,13 @@ static void get_log_names( * **************************************/ SCHAR next_log[512]; - SCHAR *cl, *nl; int log_count; - int ret_val; bool not_archived; SLONG last_log_flag, next_offset; - SLONG log_seqno, log_length; - SSHORT loop; - STR string; - loop = 0; + SSHORT loop = 0; -// loop up to 10 times to allow the file to be archived +// loop up to 10 times to allow the file to be archived while (true) { loop++; @@ -2857,6 +2820,7 @@ static void get_log_names( ERRQ_print_error(431, dbb->dbb_filename, NULL, NULL, NULL, NULL); } + STR string; if (log_count) { string = (STR) ALLOCDV(type_str, strlen(next_log)); LLS_PUSH(string, log_stack); @@ -2868,12 +2832,13 @@ static void get_log_names( strcpy(string->str_data, cur_log); } - cl = next_log; - nl = cur_log; + SCHAR* cl = next_log; + SCHAR* nl = cur_log; part_offset = next_offset; + SLONG log_seqno, log_length; while (log_count) { - ret_val = WALF_get_next_log_info(gds_status, + int ret_val = WALF_get_next_log_info(gds_status, db_name, cl, part_offset, nl, &next_offset, @@ -2890,7 +2855,7 @@ static void get_log_names( LLS_PUSH(string, log_stack); strcpy(string->str_data, nl); - // switch files + // switch files if (cl == next_log) { cl = cur_log; @@ -2918,20 +2883,18 @@ static void get_log_names_serial( LLS * log_stack) * **************************************/ SCHAR next_log[512]; - STR string; -/* - * for round robin log files, some of the log files may not have been used - * when the database is dropped or log is dropped. Add them to the list - */ +// for round robin log files, some of the log files may not have been used +// when the database is dropped or log is dropped. Add them to the list + FOR L IN DB.RDB$LOG_FILES if (L.RDB$FILE_FLAGS & LOG_serial) continue; ISC_expand_filename(L.RDB$FILE_NAME, 0, next_log); - string = (STR) ALLOCDV(type_str, strlen(next_log)); - LLS_PUSH(string, log_stack); + STR string = (STR) ALLOCDV(type_str, strlen(next_log)); strcpy(string->str_data, next_log); + LLS_PUSH(string, log_stack); END_FOR ON_ERROR END_ERROR; @@ -2950,33 +2913,34 @@ static TEXT *get_query_header( DBB database, SLONG blob_id[2]) * Pick up a query header for a field. * **************************************/ - FRBRD *blob; - ISC_STATUS status; ISC_STATUS_ARRAY status_vector; - USHORT length; - TEXT header[1024], buffer[1024], *p, *q; - blob = NULL; - + TEXT header[1024], buffer[1024]; + FRBRD* blob = NULL; if (gds__open_blob(status_vector, &database->dbb_handle, &gds_trans, &blob, (GDS__QUAD*) blob_id)) + { ERRQ_database_error(database, status_vector); + } - p = header; + TEXT* p = header; + // CVC: No bounds check here: it's assumed that 1024 is enough, but "p" + // might overflow "header" eventually. for (;;) { - status = gds__get_segment(status_vector, &blob, &length, + USHORT length; + ISC_STATUS status = gds__get_segment(status_vector, &blob, &length, sizeof(buffer), buffer); if (status && status != gds_segment) break; if (length && buffer[length - 1] == '\n') --length; buffer[length] = 0; - q = buffer; + const TEXT* q = buffer; if (*q == '"') - do + do { *p++ = *q++; - while (*q); + } while (*q); else { *p++ = '"'; while (*q) @@ -2995,8 +2959,9 @@ static TEXT *get_query_header( DBB database, SLONG blob_id[2]) p = header + 1; } - if (length = p - header) - return make_string(header, length); + const USHORT len = p - header; + if (len) + return make_string(header, len); return NULL; } @@ -3016,39 +2981,32 @@ static void install( DBB old_dbb) * permanent. * **************************************/ - DBB new_dbb; - QLI_REL relation; - NAM name; - SYM symbol, symbol2; - FRBRD *request, *request2; - SSHORT l; - FUN function; - TEXT *p, *q; -// Copy the database block to one out of the permanent pool +// Copy the database block to one out of the permanent pool - l = old_dbb->dbb_filename_length; - new_dbb = (DBB) ALLOCPV(type_dbb, l); + SSHORT l = old_dbb->dbb_filename_length; + DBB new_dbb = (DBB) ALLOCPV(type_dbb, l); new_dbb->dbb_filename_length = l; - p = new_dbb->dbb_filename; - q = old_dbb->dbb_filename; - do + TEXT* p = new_dbb->dbb_filename; + const TEXT* q = old_dbb->dbb_filename; + do { *p++ = *q++; - while (--l); + } while (--l); DB = new_dbb->dbb_handle = old_dbb->dbb_handle; new_dbb->dbb_capabilities = old_dbb->dbb_capabilities; new_dbb->dbb_next = QLI_databases; QLI_databases = new_dbb; -// If a name was given, make up a symbol for the database. +// If a name was given, make up a symbol for the database. - if (name = (NAM) old_dbb->dbb_symbol) { - new_dbb->dbb_symbol = symbol = - make_symbol(name->nam_string, name->nam_length); - symbol->sym_type = SYM_database; - symbol->sym_object = (BLK) new_dbb; - HSH_insert(symbol); + NAM name = (NAM) old_dbb->dbb_symbol; + if (name) { + SYM asymbol = make_symbol(name->nam_string, name->nam_length); + new_dbb->dbb_symbol = asymbol; + asymbol->sym_type = SYM_database; + asymbol->sym_object = (BLK) new_dbb; + HSH_insert(asymbol); } gds_trans = MET_transaction(nod_start_trans, new_dbb); @@ -3061,24 +3019,25 @@ static void install( DBB old_dbb) set_capabilities(new_dbb); /* Get all relations in database. For each relation make up a - relation block, make up a symbol block, and insert the symbol + relation block, make up a symbol block, and insert the symbol into the hash table. */ - request = NULL; + FRBRD* request = NULL; - FOR(REQUEST_HANDLE request) X IN DB.RDB$RELATIONS SORTED BY DESCENDING - X.RDB$RELATION_NAME relation = (QLI_REL) ALLOCP(type_rel); + FOR(REQUEST_HANDLE request) X IN DB.RDB$RELATIONS + SORTED BY DESCENDING X.RDB$RELATION_NAME + QLI_REL relation = (QLI_REL) ALLOCP(type_rel); relation->rel_next = new_dbb->dbb_relations; new_dbb->dbb_relations = relation; relation->rel_database = new_dbb; relation->rel_id = X.RDB$RELATION_ID; - symbol = make_symbol(X.RDB$RELATION_NAME, sizeof(X.RDB$RELATION_NAME)); - symbol->sym_type = SYM_relation; - symbol->sym_object = (BLK) relation; - relation->rel_symbol = symbol; - HSH_insert(symbol); - if (strcmp(symbol->sym_string, "QLI$PROCEDURES") == 0) + SYM rsymbol = make_symbol(X.RDB$RELATION_NAME, sizeof(X.RDB$RELATION_NAME)); + rsymbol->sym_type = SYM_relation; + rsymbol->sym_object = (BLK) relation; + relation->rel_symbol = rsymbol; + HSH_insert(rsymbol); + if (strcmp(rsymbol->sym_string, "QLI$PROCEDURES") == 0) new_dbb->dbb_flags |= DBB_procedures; if (relation->rel_system_flag = X.RDB$SYSTEM_FLAG) relation->rel_flags |= REL_system; @@ -3093,22 +3052,23 @@ static void install( DBB old_dbb) if (gds__release_request(gds_status, &request)) ERRQ_database_error(new_dbb, gds_status); -// Pick up functions, if appropriate +// Pick up functions, if appropriate if (new_dbb->dbb_capabilities & DBB_cap_functions) { - request2 = NULL; + FRBRD* request2 = NULL; FOR(REQUEST_HANDLE request) X IN DB.RDB$FUNCTIONS - if (!(symbol = make_symbol(X.RDB$FUNCTION_NAME, sizeof(X.RDB$FUNCTION_NAME)))) + SYM fsymbol = make_symbol(X.RDB$FUNCTION_NAME, sizeof(X.RDB$FUNCTION_NAME)); + if (!fsymbol) continue; - function = (FUN) ALLOCPV(type_fun, 0); + FUN function = (FUN) ALLOCPV(type_fun, 0); function->fun_next = new_dbb->dbb_functions; new_dbb->dbb_functions = function; - function->fun_symbol = symbol; + function->fun_symbol = fsymbol; function->fun_database = new_dbb; FOR(REQUEST_HANDLE request2) Y IN DB.RDB$FUNCTION_ARGUMENTS WITH Y.RDB$FUNCTION_NAME EQ X.RDB$FUNCTION_NAME AND Y.RDB$ARGUMENT_POSITION EQ X.RDB$RETURN_ARGUMENT - function->fun_return.dsc_dtype = MET_get_datatype(Y.RDB$FIELD_TYPE); + function->fun_return.dsc_dtype = MET_get_datatype(Y.RDB$FIELD_TYPE); function->fun_return.dsc_length = field_length(function->fun_return.dsc_dtype, Y.RDB$FIELD_LENGTH); @@ -3121,14 +3081,14 @@ static void install( DBB old_dbb) function->fun_return.dsc_dtype = dtype_text; function->fun_return.dsc_length = 20; } - symbol->sym_type = SYM_function; - symbol->sym_object = (BLK) function; - HSH_insert(symbol); + fsymbol->sym_type = SYM_function; + fsymbol->sym_object = (BLK) function; + HSH_insert(fsymbol); - // Insert another symbol if there is a function query name + // Insert another symbol if there is a function query name - if (symbol2 = - make_symbol(X.RDB$QUERY_NAME, sizeof(X.RDB$QUERY_NAME))) { + SYM symbol2 = make_symbol(X.RDB$QUERY_NAME, sizeof(X.RDB$QUERY_NAME)); + if (symbol2) { function->fun_query_name = symbol2; symbol2->sym_type = SYM_function; symbol2->sym_object = (BLK) function; @@ -3160,9 +3120,7 @@ static SYN make_node( NOD_T type, USHORT count) * Generate a syntax node. * **************************************/ - SYN node; - - node = (SYN) ALLOCPV(type_syn, count); + SYN node = (SYN) ALLOCPV(type_syn, count); node->syn_count = count; node->syn_type = type; @@ -3183,19 +3141,16 @@ static TEXT *make_string( TEXT * string, SSHORT length) * trailing blanks. If there's nothing left, return NULL. * **************************************/ - STR str; - TEXT *p; - string[length] = 0; if (!(length = truncate_string(string))) return NULL; - str = (STR) ALLOCPV(type_str, length + 1); - p = str->str_data; - do + STR str = (STR) ALLOCPV(type_str, length + 1); + TEXT* p = str->str_data; + do { *p++ = *string++; - while (--length); + } while (--length); *p = 0; return str->str_data; @@ -3211,24 +3166,22 @@ static SYM make_symbol( TEXT * string, SSHORT length) ************************************** * * Functional description - * Make up a symbol from a string. If the string is all blanks, + * Make up a symbol from a string. If the string is all blanks, * don't make up a symbol. Phooey. * **************************************/ - SYM symbol; - TEXT *p; - if (!(length = truncate_string(string))) return NULL; - symbol = (SYM) ALLOCPV(type_sym, length); + SYM symbol = (SYM) ALLOCPV(type_sym, length); symbol->sym_type = SYM_relation; symbol->sym_length = length; - symbol->sym_string = p = symbol->sym_name; - do + TEXT* p = symbol->sym_name; + symbol->sym_string = p; + do { *p++ = *string++; - while (--length); + } while (--length); return symbol; } @@ -3244,12 +3197,10 @@ static CON missing_value( SLONG * blob_id, SYM symbol) * * Functional description * Get a missing value into a constant - * block for later reference. + * block for later reference. * **************************************/ - SYN element; - - element = parse_blr_blob(blob_id, symbol); + SYN element = parse_blr_blob(blob_id, symbol); if (element) return ((CON) element->syn_arg[0]); else @@ -3269,16 +3220,16 @@ static SYN parse_blr( UCHAR ** ptr, SYM symbol) * Parse a BLR expression. * **************************************/ - SYN node, *arg; + SYN *arg; CON constant; NOD_T operatr; NAM name; - UCHAR *p, *blr; - SSHORT args, dtype, scale, length, l, op; + UCHAR *p; + SSHORT dtype, scale, length, l, op; - blr = *ptr; - args = 2; - node = NULL; + UCHAR* blr = *ptr; + SSHORT args = 2; + SYN node = NULL; switch (op = BLR_BYTE) { case blr_any: @@ -3382,9 +3333,9 @@ static SYN parse_blr( UCHAR ** ptr, SYM symbol) node->syn_arg[0] = (SYN) name; name->nam_length = length; p = (UCHAR *) name->nam_string; - do + do { *p++ = BLR_BYTE; - while (--length); + } while (--length); break; case blr_function: @@ -3500,7 +3451,7 @@ static SYN parse_blr( UCHAR ** ptr, SYM symbol) break; default: - ERRQ_print_error(258, (TEXT *) op, NULL, NULL, NULL, NULL); /* Msg258 don't understand BLR operatr %d */ + ERRQ_print_error(258, (TEXT *) op, NULL, NULL, NULL, NULL); // Msg258 don't understand BLR operatr %d } if (!node) { @@ -3526,31 +3477,29 @@ static SYN parse_blr_blob( SLONG * blob_id, SYM symbol) ************************************** * * Functional description - * Gobble up a BLR blob, if possible. + * Gobble up a BLR blob, if possible. * **************************************/ - FRBRD *handle; ISC_STATUS_ARRAY status_vector; - SYN node; - USHORT length; - UCHAR buffer[1024], *ptr; if (!blob_id[0] && !blob_id[1]) return NULL; - handle = NULL; + FRBRD* handle = NULL; - if (gds__open_blob(status_vector, &DB, &gds_trans, &handle, - (GDS__QUAD*) blob_id)) + if (gds__open_blob(status_vector, &DB, &gds_trans, &handle, + (GDS__QUAD*) blob_id)) return NULL; - ptr = buffer; + UCHAR buffer[1024]; + UCHAR* ptr = buffer; for (;;) { - if (!(length = buffer + sizeof(buffer) - ptr)) + USHORT length = buffer + sizeof(buffer) - ptr; + if (!length) break; - if (gds__get_segment(status_vector, &handle, &length, length, - (char*) ptr)) + if (gds__get_segment(status_vector, &handle, &length, length, + (char*) ptr)) break; ptr += length; } @@ -3566,7 +3515,7 @@ static SYN parse_blr_blob( SLONG * blob_id, SYM symbol) if (*ptr++ != blr_version4) return NULL; - node = parse_blr(&ptr, symbol); + SYN node = parse_blr(&ptr, symbol); if (*ptr != blr_eoc) return NULL; @@ -3587,22 +3536,19 @@ static void purge_relation(QLI_REL relation) * Purge a relation out of internal data structures. * **************************************/ - SYM symbol; - QLI_REL *ptr; - QLI_FLD field; - DBB database; - - symbol = relation->rel_symbol; - database = relation->rel_database; + SYM symbol = relation->rel_symbol; + DBB database = relation->rel_database; HSH_remove(symbol); - for (ptr = &database->dbb_relations; *ptr; ptr = &(*ptr)->rel_next) { + for (QLI_REL* ptr = &database->dbb_relations; *ptr; ptr = &(*ptr)->rel_next) + { if (*ptr == relation) { *ptr = relation->rel_next; break; } } + QLI_FLD field; while (field = relation->rel_fields) { relation->rel_fields = field->fld_next; ALLQ_release((FRB) field->fld_name); @@ -3616,7 +3562,7 @@ static void purge_relation(QLI_REL relation) } -static void put_dyn_string( RLB rlb, TEXT * string) +static void put_dyn_string( RLB rlb, const TEXT* string) { /************************************** * @@ -3629,7 +3575,7 @@ static void put_dyn_string( RLB rlb, TEXT * string) * **************************************/ - SSHORT l = strlen(string); + const SSHORT l = strlen(string); while ((SSHORT) (rlb->rlb_limit - rlb->rlb_data) < l) { rlb = GEN_rlb_extend(rlb); @@ -3656,12 +3602,13 @@ static void rollback_update( DBB database) * Roll back a meta-data update. * **************************************/ - ISC_STATUS_ARRAY alt_vector; - if (gds_trans == database->dbb_meta_trans && (database->dbb_capabilities & DBB_cap_multi_trans)) + { + ISC_STATUS_ARRAY alt_vector; gds__rollback_transaction(alt_vector, &database->dbb_meta_trans); - // Note: No message given if rollback fails + // Note: No message given if rollback fails + } gds_trans = NULL; } @@ -3684,15 +3631,13 @@ static void set_capabilities( DBB database) * capabilities bits. * **************************************/ - FRBRD *req; - RFR_TAB rel_field_table; + FRBRD* req = NULL; - req = NULL; +// Look for desireable fields in system relations -// Look for desireable fields in system relations - - for (rel_field_table = const_cast(rfr_table); rel_field_table->relation; - rel_field_table++) { + for (const rfr_tab_t* rel_field_table = rfr_table; rel_field_table->relation; + rel_field_table++) + { FOR(REQUEST_HANDLE req) x IN DB.RDB$RELATION_FIELDS WITH x.RDB$RELATION_NAME = rel_field_table->relation AND x.RDB$FIELD_NAME = rel_field_table->field @@ -3722,7 +3667,7 @@ static DBB setup_update( DBB database) * Functional description * Get ready to do a meta data update. * If no database was specified, use the - * most recently readied one. + * most recently readied one. * **************************************/ @@ -3746,43 +3691,41 @@ static void sql_grant_revoke( SYN node, USHORT type) * Build a DYN string for a SQL GRANT or REVOKE statement * *****************************************************/ - DBB database; - QLI_REL relation; - NAM *name, *end, *field, *end_field; - SYN names, fields; - USHORT privileges; - TEXT *relation_name; - RLB rlb; + const USHORT privileges = (USHORT) node->syn_arg[s_grant_privileges]; + QLI_REL relation = (QLI_REL) node->syn_arg[s_grant_relation]; + DBB database = setup_update(relation->rel_database); + relation->rel_database = database; + const TEXT* relation_name = relation->rel_symbol->sym_string; - - privileges = (USHORT) node->syn_arg[s_grant_privileges]; - relation = (QLI_REL) node->syn_arg[s_grant_relation]; - relation->rel_database = database = setup_update(relation->rel_database); - relation_name = relation->rel_symbol->sym_string; - - rlb = NULL; + RLB rlb = NULL; rlb = CHECK_RLB(rlb); STUFF(gds_dyn_version_1); STUFF(gds_dyn_begin); -// For each user create a separate grant string -// For each specified field create a separate grant string +// For each user create a separate grant string +// For each specified field create a separate grant string - names = node->syn_arg[s_grant_users]; - fields = node->syn_arg[s_grant_fields]; + SYN names = node->syn_arg[s_grant_users]; + SYN fields = node->syn_arg[s_grant_fields]; + NAM *name, *end; for (name = (NAM *) names->syn_arg, end = name + names->syn_count; name < end; name++) + { if (fields->syn_count) { - for (field = (NAM *) fields->syn_arg, end_field = - field + fields->syn_count; field < end_field; field++) + NAM* field = (NAM *) fields->syn_arg; + NAM* const end_field = field + fields->syn_count; + for (; field < end_field; field++) + { stuff_priv(rlb, type, relation_name, privileges, (*name)->nam_string, (*field)->nam_string); + } } else stuff_priv(rlb, type, relation_name, privileges, (*name)->nam_string, NULL); + } STUFF(gds_dyn_end); STUFF(gds_dyn_eoc); @@ -3826,8 +3769,8 @@ static int truncate_string( TEXT * string) static void stuff_priv( RLB rlb, USHORT type, - TEXT * relation, - USHORT privileges, TEXT * user, TEXT * field) + const TEXT* relation, + USHORT privileges, const TEXT* user, const TEXT* field) { /************************************** * @@ -3839,14 +3782,12 @@ static void stuff_priv( * Stuff a privilege for grant/revoke. * **************************************/ - USHORT priv_count; - rlb = CHECK_RLB(rlb); STUFF(type); -// Stuff privileges first +// Stuff privileges first - priv_count = 0; + USHORT priv_count = 0; if (privileges & PRV_select) priv_count++; if (privileges & PRV_insert) @@ -3905,17 +3846,15 @@ static void wal_info( * Extract wal name and log offset * **************************************/ - UCHAR item; - UCHAR *d, *p; - SLONG length; - - p = db_info_buffer; *log = 0; *part_offset = 0; cur_log[0] = 0; + UCHAR* p = db_info_buffer; + UCHAR item; + UCHAR* d; while ((item = *p++) != gds_info_end) { - length = gds__vax_integer(p, 2); + SLONG length = gds__vax_integer(p, 2); p += 2; switch (item) { case gds_info_logfile: @@ -3941,3 +3880,5 @@ static void wal_info( } } } + + diff --git a/src/qli/mov.cpp b/src/qli/mov.cpp index 74847eaa76..c6624df603 100644 --- a/src/qli/mov.cpp +++ b/src/qli/mov.cpp @@ -169,44 +169,44 @@ int MOVQ_compare( DSC * arg1, DSC * arg2) case dtype_text: if (arg1->dsc_length >= arg2->dsc_length) { if (length = arg2->dsc_length) - do + do { if (*p1++ != *p2++) if (p1[-1] > p2[-1]) return 1; else return -1; - while (--length); + } while (--length); if (length = arg1->dsc_length - arg2->dsc_length) - do + do { if (*p1++ != ' ') if (p1[-1] > ' ') return 1; else return -1; - while (--length); + } while (--length); return 0; } if (length = arg1->dsc_length) - do + do { if (*p1++ != *p2++) if (p1[-1] > p2[-1]) return 1; else return -1; - while (--length); + } while (--length); length = arg2->dsc_length - arg1->dsc_length; - do + do { if (*p2++ != ' ') if (' ' > p2[-1]) return 1; else return -1; - while (--length); + } while (--length); return 0; } } -// Handle mixed string comparisons +// Handle mixed string comparisons if (arg1->dsc_dtype <= dtype_varying && arg2->dsc_dtype <= dtype_varying) { length = MOVQ_get_string(arg1, (TEXT**) &p1, 0, 0); @@ -214,42 +214,43 @@ int MOVQ_compare( DSC * arg1, DSC * arg2) fill = length - length2; if (length >= length2) { if (length2) - do + do { if (*p1++ != *p2++) if (p1[-1] > p2[-1]) return 1; else return -1; - while (--length2); + } while (--length2); if (fill > 0) - do + do { if (*p1++ != ' ') if (p1[-1] > ' ') return 1; else return -1; - while (--fill); + } while (--fill); return 0; } - if (length) - do + if (length) { + do { if (*p1++ != *p2++) if (p1[-1] > p2[-1]) return 1; else return -1; - while (--length); - do + } while (--length); + } + do { if (*p2++ != ' ') if (' ' > p2[-1]) return 1; else return -1; - while (++fill); + } while (++fill); return 0; } -// Handle hetergeneous compares +// Handle hetergeneous compares if (arg1->dsc_dtype < arg2->dsc_dtype) return (-MOVQ_compare(arg2, arg1)); @@ -326,7 +327,7 @@ int MOVQ_compare( DSC * arg1, DSC * arg2) } case dtype_blob: - IBERROR(48); // Msg 48 Blob conversion is not supported + IBERROR(48); // Msg 48 Blob conversion is not supported default: mover_error(410, arg1->dsc_dtype, arg2->dsc_dtype); @@ -349,14 +350,14 @@ double MOVQ_date_to_double(const dsc* desc) * date arithmetic routines. * **************************************/ - DSC temp_desc; SLONG temp[2], *date; -// If the input descriptor is not in date form, convert it. +// If the input descriptor is not in date form, convert it. if (desc->dsc_dtype == dtype_timestamp) date = (SLONG *) desc->dsc_address; else { + dsc temp_desc; temp_desc.dsc_dtype = dtype_timestamp; temp_desc.dsc_length = sizeof(temp); temp_desc.dsc_scale = 0; @@ -382,11 +383,10 @@ int MOVQ_decompose(const TEXT* string, USHORT length, SLONG* return_value) * Decompose a numeric string in mantissa and exponent. * **************************************/ - SSHORT scale; - SLONG value; + SSHORT scale = 0; + SLONG value = 0; SCHAR temp[128]; - scale = value = 0; bool sign = false; bool fraction = false; @@ -473,7 +473,7 @@ void MOVQ_double_to_date( double real, SLONG fixed[2]) void MOVQ_fast(const SCHAR* from, - SCHAR* to, + SCHAR* to, ULONG length) { /************************************** @@ -488,9 +488,9 @@ void MOVQ_fast(const SCHAR* from, **************************************/ if (length) - do + do { *to++ = *from++; - while (--length); + } while (--length); } @@ -504,7 +504,7 @@ double MOVQ_get_double(const dsc* desc) * * Functional description * Convert something arbitrary to a - * double_precision representation. + * double_precision representation. * **************************************/ double value; @@ -541,7 +541,7 @@ double MOVQ_get_double(const dsc* desc) } else if (*p == '.') if (fraction) - IBERROR(52); // Msg 52 conversion error + IBERROR(52); // Msg 52 conversion error else fraction = 1; else if (!value && *p == '-') @@ -551,7 +551,7 @@ double MOVQ_get_double(const dsc* desc) else if (*p == 'e' || *p == 'E') break; else if (*p != ' ') - IBERROR(53); // Msg 53 conversion error + IBERROR(53); // Msg 53 conversion error } if (sign) @@ -569,7 +569,7 @@ double MOVQ_get_double(const dsc* desc) sign = TRUE; else if (*p == '+' && !exp); else if (*p != ' ') - IBERROR(54); // Msg 54 conversion error + IBERROR(54); // Msg 54 conversion error } if (sign) scale += exp; @@ -578,13 +578,13 @@ double MOVQ_get_double(const dsc* desc) } if (scale > 0) - do + do { value /= 10.; - while (--scale); + } while (--scale); else if (scale) - do + do { value *= 10.; - while (++scale); + } while (++scale); return value; @@ -592,19 +592,19 @@ double MOVQ_get_double(const dsc* desc) mover_error(410, desc->dsc_dtype, dtype_double); } -// Last, but not least, adjust for scale +// Last, but not least, adjust for scale if ((scale = desc->dsc_scale) == 0) return value; if (scale > 0) - do + do { value *= 10.; - while (--scale); + } while (--scale); else - do + do { value /= 10.; - while (++scale); + } while (++scale); return value; } @@ -625,12 +625,11 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) **************************************/ SLONG value; double d; - SSHORT fraction, length; - TEXT *p; + SSHORT length; scale -= (SSHORT) desc->dsc_scale; - p = (TEXT *) desc->dsc_address; + TEXT* p = (TEXT *) desc->dsc_address; switch (desc->dsc_dtype) { case dtype_short: value = *((SSHORT *) p); @@ -643,13 +642,13 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) case dtype_real: d = *((float *) p); if (scale > 0) - do + do { d /= 10.; - while (--scale); + } while (--scale); else if (scale < 0) - do + do { d *= 10.; - while (++scale); + } while (++scale); if (d > 0) d += 0.5; else @@ -659,13 +658,13 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) case dtype_double: d = *((double *) p); if (scale > 0) - do + do { d /= 10.; - while (--scale); + } while (--scale); else if (scale < 0) - do + do { d *= 10.; - while (++scale); + } while (++scale); if (d > 0) d += 0.5; else @@ -683,7 +682,7 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) mover_error(410, desc->dsc_dtype, dtype_long); } -// Last, but not least, adjust for scale +// Last, but not least, adjust for scale if (scale == 0) return value; @@ -691,7 +690,7 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) if (scale > 0) { if ((desc->dsc_dtype == dtype_short) || (desc->dsc_dtype == dtype_long)) { - fraction = 0; + SSHORT fraction = 0; do { if (scale == 1) fraction = value % 10; @@ -701,14 +700,14 @@ SLONG MOVQ_get_long(const dsc* desc, SSHORT scale) value++; } else - do + do { value /= 10; - while (--scale); + } while (--scale); } else - do + do { value *= 10; - while (++scale); + } while (++scale); return value; } @@ -732,8 +731,6 @@ int MOVQ_get_string(const dsc* desc, TEXT ** address, VARY * temp, USHORT length * argument (temp buffer) may be omitted. * **************************************/ - VARY *varying; - DSC temp_desc; /* If the value is already a string (fixed or varying), just return the address and length. */ @@ -743,21 +740,22 @@ int MOVQ_get_string(const dsc* desc, TEXT ** address, VARY * temp, USHORT length return desc->dsc_length; } -/* Perhaps it a "C" type string? */ +// Perhaps it a "C" type string? if (desc->dsc_dtype == dtype_cstring) { *address = (TEXT *) desc->dsc_address; return MIN(strlen((char*)desc->dsc_address), desc->dsc_length - 1); } -// No luck -- convert value to varying string. +// No luck -- convert value to varying string. if (desc->dsc_dtype == dtype_varying) { - varying = (VARY *) desc->dsc_address; + VARY* varying = (VARY*) desc->dsc_address; *address = varying->vary_string; return varying->vary_length; } + dsc temp_desc; temp_desc.dsc_length = length; temp_desc.dsc_address = (UCHAR *) temp; temp_desc.dsc_scale = 0; @@ -785,14 +783,14 @@ void MOVQ_move(const dsc* from, dsc* to) SSHORT fill; SLONG l; UCHAR *ptr; - + // This is USHORT!! SSHORT length = from->dsc_length; UCHAR* p = to->dsc_address; const UCHAR* q = from->dsc_address; /* If the datatypes and lengths are identical, just move the - stuff byte by byte. Although this may seem slower than + stuff byte by byte. Although this may seem slower than optimal, it would cost more to find the fast move than the fast move would gain. */ @@ -802,9 +800,9 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) */ { if (length) - do + do { *p++ = *q++; - while (--length); + } while (--length); return; } @@ -847,7 +845,7 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) ((SLONG *) to->dsc_address)[0] = ((SLONG *) from->dsc_address)[0]; return; case dtype_sql_time: - // Error situation + // Error situation break; } break; @@ -868,7 +866,7 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) ((SLONG *) to->dsc_address)[0] = ((SLONG *) from->dsc_address)[1]; return; case dtype_sql_date: - // Error situation + // Error situation break; } break; @@ -887,21 +885,21 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) length = MIN(length, to->dsc_length); fill = to->dsc_length - length; if (length) - do + do { *p++ = *q++; - while (--length); + } while (--length); if (fill > 0) - do + do { *p++ = ' '; - while (--fill); + } while (--fill); return; case dtype_cstring: length = MIN(length, to->dsc_length - 1); if (length) - do + do { *p++ = *q++; - while (--length); + } while (--length); *p = 0; return; @@ -910,9 +908,9 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) ((VARY *) p)->vary_length = length; p = (UCHAR *) ((VARY *) p)->vary_string; if (length) - do + do { *p++ = *q++; - while (--length); + } while (--length); return; } @@ -954,7 +952,7 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) case dtype_short: *(SSHORT *) p = l = MOVQ_get_long(from, to->dsc_scale); if (*(SSHORT *) p != l) - IBERROR(14); // Msg14 integer overflow + IBERROR(14); // Msg14 integer overflow return; case dtype_long: @@ -971,7 +969,7 @@ if (((ALT_DSC*) from)->dsc_combined_type == ((ALT_DSC*) to)->dsc_combined_type) } if (to->dsc_dtype == dtype_blob || from->dsc_dtype == dtype_blob) - IBERROR(55); // Msg 55 Blob conversion is not supported + IBERROR(55); // Msg 55 Blob conversion is not supported mover_error(410, from->dsc_dtype, to->dsc_dtype); } @@ -997,9 +995,9 @@ void MOVQ_terminate(const SCHAR* from, if (length) { length = MIN(length, max_length - 1); - do + do { *to++ = *from++; - while (--length); + } while (--length); *to++ = '\0'; } else { @@ -1024,7 +1022,8 @@ static void date_error(const TEXT* string, const USHORT length) SCHAR temp[128]; MOVQ_terminate(string, temp, length, sizeof(temp)); - ERRQ_error(56, temp, NULL, NULL, NULL, NULL); /* Msg 56 Error converting string \"%s\" to date */ + ERRQ_error(56, temp, NULL, NULL, NULL, NULL); + // Msg 56 Error converting string \"%s\" to date } @@ -1040,19 +1039,21 @@ static void sql_date_to_text( SLONG date[1], DSC * to) * Convert date to text. * **************************************/ - DSC desc; - TEXT *p, temp[35]; tm times; SLONG date2[2]; date2[0] = date[0]; date2[1] = 0; isc_decode_date((GDS_QUAD*) date2, ×); + + TEXT temp[35]; sprintf(temp, "%2d-%.3s-%04d", times.tm_mday, months[times.tm_mon], times.tm_year + 1900); + TEXT* p; for (p = temp; *p; p++); + dsc desc; desc.dsc_length = p - temp; desc.dsc_address = (UCHAR *) temp; desc.dsc_dtype = dtype_text; @@ -1075,8 +1076,6 @@ static void sql_time_to_text( ULONG date[1], DSC * to) * Convert sql time to text. * **************************************/ - DSC desc; - TEXT *p, temp[35]; tm times; SLONG date2[2]; @@ -1085,11 +1084,14 @@ static void sql_time_to_text( ULONG date[1], DSC * to) isc_decode_date((GDS_QUAD*) date2, ×); + TEXT temp[35]; sprintf(temp, " %2d:%.2d:%.2d.%.4"SLONGFORMAT, times.tm_hour, times.tm_min, times.tm_sec, date2[1] % PRECISION); + TEXT* p; for (p = temp; *p; p++); + dsc desc; desc.dsc_length = p - temp; desc.dsc_address = (UCHAR *) temp; desc.dsc_dtype = dtype_text; @@ -1112,23 +1114,24 @@ static void timestamp_to_text( SLONG date[2], DSC * to) * Convert date to text. * **************************************/ - DSC desc; - TEXT *p, temp[35], time[15]; tm times; - isc_decode_date((GDS_QUAD*)date, ×); + TEXT temp[35]; sprintf(temp, "%2d-%.3s-%04d", times.tm_mday, months[times.tm_mon], times.tm_year + 1900); if (times.tm_hour || times.tm_min || times.tm_sec || date[1]) { + TEXT time[15]; sprintf(time, " %2d:%.2d:%.2d.%.4"SLONGFORMAT, times.tm_hour, times.tm_min, times.tm_sec, date[1] % PRECISION); strcat(temp, time); } + TEXT* p; for (p = temp; *p; p++); + dsc desc; desc.dsc_length = p - temp; desc.dsc_address = (UCHAR *) temp; desc.dsc_dtype = dtype_text; @@ -1143,7 +1146,7 @@ static void mover_error( int pattern, USHORT in_type, USHORT out_type) { /************************************** * - * m o v e r _ e r r o r + * m o v e r _ e r r o r * ************************************** * @@ -1153,16 +1156,18 @@ static void mover_error( int pattern, USHORT in_type, USHORT out_type) * comparisons. * **************************************/ - TEXT *in, *out, in_name[25], out_name[25], msg_unknown[40]; + TEXT in_name[25], out_name[25], msg_unknown[40]; - ERRQ_msg_get(504, msg_unknown); /* Msg504 unknown datatype %d */ + ERRQ_msg_get(504, msg_unknown); // Msg504 unknown datatype %d - if (!(in = type_name(in_type))) { + TEXT* in = type_name(in_type); + if (!in) { in = in_name; sprintf(in_name, msg_unknown, in_type); } - if (!(out = type_name(out_type))) { + TEXT* out = type_name(out_type); + if (!out) { out = out_name; sprintf(out, msg_unknown, out_type); } @@ -1204,39 +1209,38 @@ static void numeric_to_text(const dsc* from, dsc* to) * Convert your basic number to nice, formatted text. * **************************************/ - DSC intermediate; - SLONG n; - TEXT temp[32], *p, *q; - SSHORT l, scale, neg, pad, decimal, length; - - pad = decimal = neg = 0; /* Save (or compute) scale of source. Then convert source to ordinary longword. */ - scale = from->dsc_scale; + SSHORT scale = from->dsc_scale; + SSHORT pad = 0, decimal = 0; if (scale > 0) pad = scale; else if (scale < 0) decimal = 1; + SLONG n; + dsc intermediate; intermediate.dsc_dtype = dtype_long; intermediate.dsc_length = sizeof(SLONG); intermediate.dsc_scale = scale; intermediate.dsc_sub_type = 0; - intermediate.dsc_address = (UCHAR *) & n; + intermediate.dsc_address = (UCHAR *) &n; MOVQ_move(from, &intermediate); -// Check for negation, then convert the number to a string of digits +// Check for negation, then convert the number to a string of digits + SSHORT neg = 0; if (n < 0) { neg = 1; n = -n; } - p = temp; + TEXT temp[32]; + TEXT* p = temp; do { *p++ = n % 10 + '0'; @@ -1247,20 +1251,23 @@ static void numeric_to_text(const dsc* from, dsc* to) fits. Keep in mind that routine handles both string and varying string fields. */ - l = p - temp; - length = l + neg + decimal + pad; + SSHORT l = p - temp; + const SSHORT length = l + neg + decimal + pad; if ((to->dsc_dtype == dtype_text && length > to->dsc_length) || (to->dsc_dtype == dtype_cstring && length >= to->dsc_length) || (to->dsc_dtype == dtype_varying && length > to->dsc_length - sizeof(SSHORT))) - IBERROR(57); // Msg 57 overflow during conversion + { + IBERROR(57); // Msg 57 overflow during conversion + } - q = + // Hopefully a cstring never reached this point. + TEXT* q = (TEXT *) ((to->dsc_dtype == dtype_text) ? to->dsc_address : to-> dsc_address + sizeof(SSHORT)); -// If negative, put in minus sign +// If negative, put in minus sign if (neg) *q++ = '-'; @@ -1270,34 +1277,34 @@ static void numeric_to_text(const dsc* from, dsc* to) if (scale < 0) { if ((l += scale) > 0) - do + do { *q++ = *--p; - while (--l); + } while (--l); *q++ = '.'; - do + do { *q++ = *--p; - while (++scale); + } while (++scale); } else - do + do { *q++ = *--p; - while (--l); + } while (--l); -// If padding is required, do it now. +// If padding is required, do it now. if (pad) - do + do { *q++ = '0'; - while (--pad); + } while (--pad); /* Finish up by padding (if fixed) or computing the actual length (varying string) */ if (to->dsc_dtype == dtype_text) { if (l = to->dsc_length - length) - do + do { *q++ = ' '; - while (--l); + } while (--l); return; } @@ -1323,11 +1330,6 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) * Convert an arbitrary string to a date. * **************************************/ - TEXT c, temp[15], *t; - USHORT n, month_position, i, components[7], precision, year; - tm times, times2; - tm* today; - if (!length) { date[0] = date[1] = 0; return; @@ -1336,15 +1338,21 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) const TEXT* p = string; const TEXT* const end = p + length; - year = month_position = 0; + USHORT month_position = 0; time_t clock = time(0); - today = localtime(&clock); + tm* today = localtime(&clock); + USHORT i; + USHORT components[7]; for (i = 0; i < 7; i++) components[i] = 0; -// Parse components +// Parse components + + TEXT temp[15]; + USHORT n, precision; + bool year = false; for (i = 0; i < 7; i++) { @@ -1356,9 +1364,9 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) if (p == end) break; - // Handle digit or character strings + // Handle digit or character strings - c = UPPER(*p); + TEXT c = UPPER(*p); if (DIGIT(c)) { precision = n = 0; while (p < end && DIGIT(*p)) { @@ -1366,10 +1374,10 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) precision++; } if (i == 2) - year = TRUE; + year = true; } else if (LETTER(c)) { - t = temp; + TEXT* t = temp; while (p < end && LETTER(c)) { c = UPPER(*p); if (!LETTER(c)) @@ -1431,8 +1439,9 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) } } -// Slide things into day, month, year form +// Slide things into day, month, year form + tm times; if (month_position) { times.tm_mon = components[1]; times.tm_mday = components[0]; @@ -1442,7 +1451,7 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) times.tm_mday = components[1]; } -// Handle defaulting of year +// Handle defaulting of year if (((times.tm_year = components[2]) == 0) && !year) times.tm_year = today->tm_year + 1900; @@ -1459,9 +1468,10 @@ static void string_to_date(const TEXT* string, USHORT length, SLONG date[2]) times.tm_min = components[4]; times.tm_sec = components[5]; -// convert day/month/year to Julian and validate result +// convert day/month/year to Julian and validate result isc_encode_date(×, (GDS_QUAD*)date); + tm times2; isc_decode_date((GDS_QUAD*)date, ×2); if (times.tm_year != times2.tm_year || @@ -1488,27 +1498,26 @@ static void string_to_time( TEXT * string, USHORT length, SLONG date[2]) * Convert an arbitrary string to a t i m e. * **************************************/ - TEXT c, *p, temp[15], *t, *end; - USHORT n, i, components[7], precision; - time_t clock; - tm times; - tm* today; if (!length) { date[0] = date[1] = 0; return; } - p = string; + const TEXT* p = string; + const TEXT* const end = p + length; - end = p + length; - - clock = time(0); - today = localtime(&clock); + time_t clock = time(0); + tm* today = localtime(&clock); + USHORT i; + USHORT components[7]; for (i = 0; i < 7; i++) components[i] = 0; -// Parse components +// Parse components + + TEXT temp[15]; + USHORT n, precision; for (i = 3; i < 7; i++) { @@ -1520,9 +1529,9 @@ static void string_to_time( TEXT * string, USHORT length, SLONG date[2]) if (p == end) break; - // Handle digit or character strings + // Handle digit or character strings - c = UPPER(*p); + TEXT c = UPPER(*p); if (DIGIT(c)) { precision = n = 0; while (p < end && DIGIT(*p)) { @@ -1531,7 +1540,7 @@ static void string_to_time( TEXT * string, USHORT length, SLONG date[2]) } } else if (LETTER(c)) { - t = temp; + TEXT* t = temp; while (p < end && LETTER(c)) { c = UPPER(*p); if (!LETTER(c)) @@ -1565,11 +1574,12 @@ static void string_to_time( TEXT * string, USHORT length, SLONG date[2]) } + tm times; times.tm_hour = components[3]; times.tm_min = components[4]; times.tm_sec = components[5]; -// convert day/month/year to Julian and validate result +// convert day/month/year to Julian and validate result isc_encode_date(×, (GDS_QUAD*)date); @@ -1599,3 +1609,4 @@ static TEXT *type_name( USHORT dtype) return NULL; } + diff --git a/src/qli/mov_proto.h b/src/qli/mov_proto.h index 27b7d3fd7f..472bdbf374 100644 --- a/src/qli/mov_proto.h +++ b/src/qli/mov_proto.h @@ -1,7 +1,7 @@ /* * PROGRAM: JRD Command Oriented Query Language * MODULE: mov_proto.h - * DESCRIPTION: Prototype header file for mov.c + * DESCRIPTION: Prototype header file for mov.cpp * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file diff --git a/src/qli/nounix.cpp b/src/qli/nounix.cpp index 2638ab8d4a..f3f373396f 100644 --- a/src/qli/nounix.cpp +++ b/src/qli/nounix.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: nounix.c + * MODULE: nounix.cpp * DESCRIPTION: Dummy routines * * The contents of this file are subject to the Interbase Public @@ -32,3 +32,4 @@ int vfork(void) { return -1; } + diff --git a/src/qli/parse.cpp b/src/qli/parse.cpp index 5144081254..a4d38ec29e 100644 --- a/src/qli/parse.cpp +++ b/src/qli/parse.cpp @@ -1,6 +1,6 @@ /* * PROGRAM: JRD Command Oriented Query Language - * MODULE: parse.c + * MODULE: parse.cpp * DESCRIPTION: Statement parser * * The contents of this file are subject to the Interbase Public @@ -27,7 +27,7 @@ #include #define PARSER_MAIN #include "../qli/dtr.h" -#include "../qli/exe.h" // This is only included to suppress a compiler warning +#include "../qli/exe.h" // This is only included to suppress a compiler warning #include "../qli/parse.h" #include "../qli/compile.h" #include "../qli/report.h" @@ -38,6 +38,7 @@ #include "../qli/mov_proto.h" #include "../qli/parse_proto.h" #include "../qli/proc_proto.h" +#include "../jrd/gdsassert.h" #define SYNTAX_NODE(type,count) syntax_node (type, count) #define KEYWORD(kw) (QLI_token->tok_keyword == kw) @@ -48,8 +49,8 @@ static void command_end(void); static DBB get_dbb(SYM); static SYN make_list(LLS); static NAM make_name(void); -static CON make_numeric_constant(TEXT *, USHORT); -static TEXT *make_string(TEXT *, USHORT); +static CON make_numeric_constant(const TEXT*, USHORT); +static TEXT* make_string(const TEXT*, USHORT); static SYN negate(SYN); static KWWORDS next_keyword(void); static SYN parse_abort(void); @@ -120,7 +121,7 @@ static SYN parse_sql_create(void); static int parse_sql_dtype(USHORT *, USHORT *); static QLI_FLD parse_sql_field(void); static SYN parse_sql_grant_revoke(USHORT); -static SYN parse_sql_index_create(USHORT, USHORT); +static SYN parse_sql_index_create(const bool, const bool); static SYN parse_sql_joined_relation(SYN); static SYN parse_sql_join_clause(SYN); static SYN parse_sql_table_create(void); @@ -151,10 +152,10 @@ typedef struct { ULONG gds_quad_low; } gds_quad; -/* -The following flags are: +/* +The following flags are: - sql_flag indicates whether we are parsing in a SQL environment. + sql_flag indicates whether we are parsing in a SQL environment. The flag is used to turn off automatic end-of-command recognition. @@ -168,14 +169,16 @@ The following flags are: */ static USHORT sql_flag, else_count, sw_report, sw_statement, sw_sql_view; -static SSHORT function_count; // indicates the depth of UDF calls +static SSHORT function_count; // indicates the depth of UDF calls -static struct nod_types { +struct nod_types { KWWORDS nod_t_keyword; NOD_T nod_t_node; NOD_T nod_t_rpt_node; NOD_T nod_t_sql_node; -} statisticals[] = { +}; + +static const nod_types statisticals[] = { { KW_MAX, nod_max, nod_rpt_max, nod_agg_max }, { KW_MIN, nod_min, nod_rpt_min, nod_agg_min }, { KW_COUNT, nod_count, nod_rpt_count, nod_agg_count }, @@ -184,7 +187,7 @@ static struct nod_types { { KW_none, nod_any, nod_any, nod_any } }; -static NOD_T relationals[] = { +static const NOD_T relationals[] = { nod_eql, nod_neq, nod_leq, nod_lss, nod_gtr, nod_geq, nod_containing, nod_like, nod_starts, nod_missing, nod_between, nod_sleuth, nod_matches, nod_and, nod_or, nod_not, nod_any, nod_unique, (NOD_T) 0 @@ -301,16 +304,15 @@ int PAR_match( KWWORDS keyword) * If so, advance the token stream. * **************************************/ - SYM symbol; - if (KEYWORD(keyword)) { PAR_token(); return TRUE; } - for (symbol = QLI_token->tok_symbol; symbol; symbol = symbol->sym_homonym) + for (SYM symbol = QLI_token->tok_symbol; symbol; symbol = symbol->sym_homonym) if (symbol->sym_type == SYM_keyword && - symbol->sym_keyword == (int) keyword) { + symbol->sym_keyword == (int) keyword) + { PAR_token(); return TRUE; } @@ -335,13 +337,11 @@ void PAR_real(void) * procedure. * **************************************/ - DBB database; - while ((QLI_token->tok_type == tok_eol) || KEYWORD(KW_continuation)) LEX_token(); if (MATCH(KW_COLON)) { - database = parse_database(); + DBB database = parse_database(); PRO_invoke(database, QLI_token->tok_string); } } @@ -374,13 +374,11 @@ void PAR_token(void) ************************************** * * Functional description - * Get the next token. + * Get the next token. * If it's a procedure invocation, handle it * or complain and get rid of the evidence. * **************************************/ - DBB database; - for (;;) { LEX_token(); if (!(KEYWORD(KW_continuation)) && @@ -390,12 +388,12 @@ void PAR_token(void) if (MATCH(KW_COLON)) { if (!QLI_databases) { - ERRQ_error_format(159, NULL, NULL, NULL, NULL, NULL); // Msg159 no databases are ready + ERRQ_error_format(159, NULL, NULL, NULL, NULL, NULL); // Msg159 no databases are ready ERRQ_pending(); LEX_token(); } else { - database = parse_database(); + DBB database = parse_database(); PRO_invoke(database, QLI_token->tok_string); } } @@ -417,12 +415,13 @@ static void check_end(void) if (QLI_token->tok_type == tok_eol || KEYWORD(KW_SEMI) || - KEYWORD(KW_THEN) || (else_count && KEYWORD(KW_ELSE))) { + KEYWORD(KW_THEN) || (else_count && KEYWORD(KW_ELSE))) + { sw_statement = FALSE; return; } - SYNTAX_ERROR(161); // Msg161 end of statement + SYNTAX_ERROR(161); // Msg161 end of statement } @@ -444,7 +443,7 @@ static void command_end(void) return; } - SYNTAX_ERROR(162); // Msg162 end of command + SYNTAX_ERROR(162); // Msg162 end of command } @@ -483,20 +482,16 @@ static SYN make_list( LLS stack) * them first. * **************************************/ - SYN node, *ptr; - LLS temp; - USHORT count; - - temp = stack; - count = 0; + LLS temp = stack; + USHORT count = 0; while (temp) { count++; temp = temp->lls_next; } - node = SYNTAX_NODE(nod_list, count); - ptr = &node->syn_arg[count]; + SYN node = SYNTAX_NODE(nod_list, count); + SYN* ptr = &node->syn_arg[count]; while (stack) *--ptr = (SYN) LLS_POP(&stack); @@ -518,11 +513,10 @@ static NAM make_name(void) * (like a database) that needs one. * **************************************/ - NAM name; - SSHORT l, i; - TEXT c, *p, *q, string[32]; + SSHORT l; + TEXT string[32]; - for (i = 0; i < 1000; i++) { + for (SSHORT i = 0; i < 1000; i++) { sprintf(string, "QLI_%d", i); if (i < 10) l = 5; @@ -532,14 +526,14 @@ static NAM make_name(void) break; } - name = (NAM) ALLOCDV(type_nam, l); + NAM name = (NAM) ALLOCDV(type_nam, l); name->nam_length = l; - p = name->nam_string; - q = string; + TEXT* p = name->nam_string; + const TEXT* q = string; if (l) do { - c = *q++; + const TEXT c = *q++; *p++ = UPPER(c); } while (--l); @@ -547,7 +541,7 @@ static NAM make_name(void) } -static CON make_numeric_constant( TEXT * string, USHORT length) +static CON make_numeric_constant(const TEXT* string, USHORT length) { /************************************** * @@ -566,13 +560,8 @@ static CON make_numeric_constant( TEXT * string, USHORT length) * **************************************/ CON constant; - TEXT *p; - USHORT l; - p = string; - l = length; - -// If there are a reasonable number of digits, convert to binary +// If there are a reasonable number of digits, convert to binary if (length < 9) { constant = (CON) ALLOCDV(type_con, sizeof(SLONG)); @@ -588,7 +577,7 @@ static CON make_numeric_constant( TEXT * string, USHORT length) constant->con_desc.dsc_dtype = dtype_text; constant->con_desc.dsc_length = length; constant->con_desc.dsc_address = constant->con_data; - p = (TEXT *) constant->con_desc.dsc_address; + TEXT* p = (TEXT *) constant->con_desc.dsc_address; *p++ = '0'; while (--length) *p++ = *string++; @@ -598,7 +587,7 @@ static CON make_numeric_constant( TEXT * string, USHORT length) } -static TEXT *make_string( TEXT * address, USHORT length) +static TEXT* make_string(const TEXT* address, USHORT length) { /************************************** * @@ -610,15 +599,12 @@ static TEXT *make_string( TEXT * address, USHORT length) * Copy a string into a temporary string block. * **************************************/ - STR string; - TEXT *p; - - string = (STR) ALLOCDV(type_str, length); - p = string->str_data; + STR string = (STR) ALLOCDV(type_str, length); + TEXT* p = string->str_data; if (length) - do + do { *p++ = *address++; - while (--length); + } while (--length); return string->str_data; } @@ -636,9 +622,7 @@ static SYN negate( SYN expr) * Build negation of expression. * **************************************/ - SYN node; - - node = SYNTAX_NODE(nod_not, 1); + SYN node = SYNTAX_NODE(nod_not, 1); node->syn_arg[0] = expr; return node; @@ -657,11 +641,9 @@ static KWWORDS next_keyword(void) * Get a real token and return the keyword number. * **************************************/ - SYM symbol; - PAR_real(); - for (symbol = QLI_token->tok_symbol; symbol; symbol = symbol->sym_homonym) + for (SYM symbol = QLI_token->tok_symbol; symbol; symbol = symbol->sym_homonym) if (symbol->sym_type == SYM_keyword) return (KWWORDS) symbol->sym_keyword; @@ -681,10 +663,8 @@ static SYN parse_abort(void) * Parse an ABORT statement. * **************************************/ - SYN node; - PAR_token(); - node = SYNTAX_NODE(nod_abort, 1); + SYN node = SYNTAX_NODE(nod_abort, 1); if (KEYWORD(KW_SEMI)) node->syn_count = 0; @@ -707,7 +687,7 @@ static SYN parse_accept(void) * Parse form update statement. * **************************************/ - IBERROR(484); // FORMs not supported + IBERROR(484); // FORMs not supported return 0; } @@ -724,10 +704,9 @@ static SYN parse_add( USHORT * paren_count, USHORT * bool_flag) * Parse the lowest precedence operatrs, ADD and SUBTRACT. * **************************************/ - SYN node, arg; NOD_T operatr; - node = parse_multiply(paren_count, bool_flag); + SYN node = parse_multiply(paren_count, bool_flag); while (true) { if (MATCH(KW_PLUS)) @@ -736,7 +715,7 @@ static SYN parse_add( USHORT * paren_count, USHORT * bool_flag) operatr = nod_subtract; else return node; - arg = node; + SYN arg = node; node = SYNTAX_NODE(operatr, 2); node->syn_arg[0] = arg; node->syn_arg[1] = parse_multiply(paren_count, bool_flag); @@ -756,9 +735,7 @@ static SYN parse_and( USHORT * paren_count) * Parse an AND expression. * **************************************/ - SYN expr, node; - - expr = parse_not(paren_count); + SYN expr = parse_not(paren_count); /* while (*paren_count && KEYWORD (KW_RIGHT_PAREN)) @@ -771,7 +748,7 @@ while (*paren_count && KEYWORD (KW_RIGHT_PAREN)) if (!MATCH(KW_AND)) return expr; - node = SYNTAX_NODE(nod_and, 2); + SYN node = SYNTAX_NODE(nod_and, 2); node->syn_arg[0] = expr; node->syn_arg[1] = parse_and(paren_count); @@ -790,36 +767,33 @@ static SYN parse_assignment(void) * Functional description * Parse an assignment statement (or give an error). The * assignment statement can be either a simple assignment - * (field = value) or a restructure (relation = rse). - * If the assignment operatr is missing, + * (field = value) or a restructure (relation = rse). + * If the assignment operatr is missing, * generate an "expected statement" error. * **************************************/ - SYN node, field; - QLI_REL relation; - NAM name, name2; + SYN field; - node = SYNTAX_NODE(nod_assign, s_asn_count); + SYN node = SYNTAX_NODE(nod_assign, s_asn_count); node->syn_arg[s_asn_to] = parse_field_name(&field); - name = (NAM) field->syn_arg[0]; + NAM name = (NAM) field->syn_arg[0]; /* If the next token is an equals sign, the statement really is an assignment, and we're off the hook. */ if (!MATCH(KW_EQUALS)) - ERRQ_print_error(156, name->nam_string, NULL, NULL, NULL, NULL); /* Msg156 expected statement, encountered %s */ + ERRQ_print_error(156, name->nam_string, NULL, NULL, NULL, NULL); // Msg156 expected statement, encountered %s /* See if the "field name" is really a relation reference. If so, turn the assignment into a restructure. */ + QLI_REL relation = NULL; if (field->syn_count == 1) relation = resolve_relation(0, name->nam_symbol); else if (field->syn_count == 2 && name->nam_symbol) { - name2 = (NAM) field->syn_arg[1]; + NAM name2 = (NAM) field->syn_arg[1]; relation = resolve_relation(name->nam_symbol, name2->nam_symbol); } - else - relation = NULL; if (relation) { ALL_release((FRB) field); @@ -849,7 +823,6 @@ static SYN parse_boolean( USHORT * paren_count) * here. * **************************************/ - SYN expr, node; USHORT local_count; if (!paren_count) { @@ -857,7 +830,7 @@ static SYN parse_boolean( USHORT * paren_count) paren_count = &local_count; } - expr = parse_and(paren_count); + SYN expr = parse_and(paren_count); /* while (*paren_count && KEYWORD (KW_RIGHT_PAREN)) @@ -872,7 +845,7 @@ while (*paren_count && KEYWORD (KW_RIGHT_PAREN)) return expr; } - node = SYNTAX_NODE(nod_or, 2); + SYN node = SYNTAX_NODE(nod_or, 2); node->syn_arg[0] = expr; node->syn_arg[1] = parse_boolean(paren_count); parse_terminating_parens(paren_count, &local_count); @@ -894,19 +867,17 @@ static SYN parse_copy(void) * one procedure to another. * **************************************/ - SYN node; - PAR_real_token(); if (MATCH(KW_PROCEDURE)) { - node = SYNTAX_NODE(nod_copy_proc, 2); + SYN node = SYNTAX_NODE(nod_copy_proc, 2); node->syn_arg[0] = (SYN) parse_qualified_procedure(); MATCH(KW_TO); node->syn_arg[1] = (SYN) parse_qualified_procedure(); return node; } - ERRQ_print_error(157, QLI_token->tok_string, NULL, NULL, NULL, NULL); /* Msg157 Expected PROCEDURE encountered %s */ + ERRQ_print_error(157, QLI_token->tok_string, NULL, NULL, NULL, NULL); // Msg157 Expected PROCEDURE encountered %s return NULL; } @@ -925,22 +896,20 @@ static DBB parse_database(void) * token is not a database name. * **************************************/ - DBB database; - SYM db_symbol; + SYM db_symbol = QLI_token->tok_symbol; - - if ((db_symbol = QLI_token->tok_symbol) - && db_symbol->sym_type == SYM_database) { - database = (DBB) db_symbol->sym_object; + if (db_symbol && db_symbol->sym_type == SYM_database) + { + DBB database = (DBB) db_symbol->sym_object; PAR_real_token(); if (!MATCH(KW_DOT)) - SYNTAX_ERROR(158); // Msg158 period in qualified name + SYNTAX_ERROR(158); // Msg158 period in qualified name PAR_real(); return database; } if (!QLI_databases) - IBERROR(159); // Msg159 no databases are ready + IBERROR(159); // Msg159 no databases are ready return NULL; } @@ -958,26 +927,18 @@ static SYN parse_declare(void) * Parse a variable declaration. * **************************************/ - SYN node, field_node; - SYM name, query_name; - QLI_FLD global_variable; - USHORT dtype, length, scale; - SSHORT sub_type, sub_type_missing; - TEXT *edit_string, *query_header; - QLI_REL relation; - NAM db_name, rel_name; - PAR_token(); PAR_real(); - dtype = length = scale = 0; - sub_type = 0; - sub_type_missing = 1; - field_node = NULL; - relation = NULL; - query_name = NULL; - edit_string = query_header = NULL; - name = parse_symbol(); + USHORT dtype = 0, length = 0, scale = 0; + SSHORT sub_type = 0; + SSHORT sub_type_missing = 1; + SYN field_node = NULL; + SYM query_name = NULL; + TEXT* edit_string = NULL; + TEXT* query_header = NULL; + + SYM name = parse_symbol(); /*if (global_flag) PAR_real();*/ @@ -992,12 +953,12 @@ static SYN parse_declare(void) case KW_CHAR: case KW_VARYING: if (dtype) - SYNTAX_ERROR(164); // Msg164 variable definition clause + SYNTAX_ERROR(164); // Msg164 variable definition clause dtype = parse_dtype(&length, &scale); break; case KW_BLOB: - IBERROR(160); // Msg160 blob variables are not supported + IBERROR(160); // Msg160 blob variables are not supported break; case KW_SUB_TYPE: @@ -1008,7 +969,7 @@ static SYN parse_declare(void) case KW_EDIT_STRING: PAR_token(); if (QLI_token->tok_type != tok_quoted) - SYNTAX_ERROR(163); // Msg163 quoted edit string + SYNTAX_ERROR(163); // Msg163 quoted edit string edit_string = make_string(QLI_token->tok_string + 1, QLI_token->tok_length - 2); @@ -1019,7 +980,7 @@ static SYN parse_declare(void) PAR_token(); MATCH(KW_IS); if (QLI_token->tok_type != tok_ident) - SYNTAX_ERROR(199); // Msg199 identifier + SYNTAX_ERROR(199); // Msg199 identifier query_name = parse_symbol(); break; @@ -1035,33 +996,36 @@ static SYN parse_declare(void) break; default: - SYNTAX_ERROR(164); // Msg164 variable definition clause + SYNTAX_ERROR(164); // Msg164 variable definition clause break; } } + QLI_REL relation = NULL; if (field_node && field_node->syn_count == 3) { - db_name = (NAM) field_node->syn_arg[0]; - rel_name = (NAM) field_node->syn_arg[1]; + NAM db_name = (NAM) field_node->syn_arg[0]; + NAM rel_name = (NAM) field_node->syn_arg[1]; if (!db_name->nam_symbol) - ERRQ_print_error(165, db_name->nam_string, NULL, NULL, NULL, NULL); /* Msg165 %s is not a database */ - if (! - (relation = - resolve_relation(db_name->nam_symbol, - rel_name->nam_symbol))) ERRQ_print_error(166, - rel_name-> - nam_string, - db_name-> - nam_string, NULL, NULL, NULL); /* Msg166 %s is not a relation in database %s */ + ERRQ_print_error(165, db_name->nam_string, NULL, NULL, NULL, NULL); + // Msg165 %s is not a database + + relation = resolve_relation(db_name->nam_symbol, rel_name->nam_symbol); + if (!relation) + { + ERRQ_print_error(166, rel_name->nam_string, + db_name->nam_string, NULL, NULL, NULL); + // Msg166 %s is not a relation in database %s + } } if (!dtype && !field_node) - SYNTAX_ERROR(167); // Msg167 variable data type + SYNTAX_ERROR(167); // Msg167 variable data type if (field_node && (dtype || length || scale)) - IBERROR(168); // Msg168 no datatype may be specified for a variable based on a field + IBERROR(168); // Msg168 no datatype may be specified for a variable based on a field - node = SYNTAX_NODE(nod_declare, 2); - global_variable = (QLI_FLD) ALLOCDV(type_fld, length); + SYN node = SYNTAX_NODE(nod_declare, 2); + // Not global to this unit, misleading name "global..." + QLI_FLD global_variable = (QLI_FLD) ALLOCDV(type_fld, length); node->syn_arg[0] = (SYN) global_variable; global_variable->fld_name = name; global_variable->fld_dtype = dtype; @@ -1091,24 +1055,22 @@ static SYN parse_define(void) ************************************** * * Functional description - * Parse a DEFINE command. - * There are, of course, a whole class of define commands. + * Parse a DEFINE command. + * There are, of course, a whole class of define commands. * **************************************/ - SYN node; - PAR_real_token(); if (MATCH(KW_PROCEDURE)) { PAR_real(); - node = SYNTAX_NODE(nod_define, 1); - node->syn_arg[0] = (SYN) parse_qualified_procedure(); - return node; + SYN anode = SYNTAX_NODE(nod_define, 1); + anode->syn_arg[0] = (SYN) parse_qualified_procedure(); + return anode; } if (MATCH(KW_FIELD)) { PAR_real(); - node = SYNTAX_NODE(nod_def_field, 2); + SYN node = SYNTAX_NODE(nod_def_field, 2); node->syn_arg[0] = (SYN) parse_database(); node->syn_arg[1] = (SYN) parse_field(TRUE); return node; @@ -1123,7 +1085,7 @@ static SYN parse_define(void) if (MATCH(KW_INDEX)) return parse_def_index(); - SYNTAX_ERROR(169); // Msg169 object type for DEFINE + SYNTAX_ERROR(169); // Msg169 object type for DEFINE return NULL; } @@ -1137,20 +1099,17 @@ static SYN parse_def_index(void) ************************************** * * Functional description - * Parse a DEFINE INDEX command. + * Parse a DEFINE INDEX command. * **************************************/ - LLS stack; - SYN node; - PAR_real(); - node = SYNTAX_NODE(nod_def_index, s_dfi_count); + SYN node = SYNTAX_NODE(nod_def_index, s_dfi_count); node->syn_arg[s_dfi_name] = (SYN) parse_symbol(); PAR_real(); MATCH(KW_FOR); if (!(node->syn_arg[s_dfi_relation] = (SYN) parse_qualified_relation())) - SYNTAX_ERROR(170); // Msg170 relation name + SYNTAX_ERROR(170); // Msg170 relation name PAR_real(); @@ -1172,7 +1131,7 @@ static SYN parse_def_index(void) break; } - stack = NULL; + LLS stack = NULL; for (;;) { LLS_PUSH(parse_name(), &stack); if (!MATCH(KW_COMMA)) @@ -1189,25 +1148,21 @@ static SYN parse_def_relation(void) { /************************************** * - * p a r s e _ d e f _ r e l a t i o n + * p a r s e _ d e f _ r e l a t i o n * ************************************** * - * Functional description + * Functional description * Parse a DEFINE RELATION command, * which include the field definitions * for a primitive relation definition * or it may just reference another relatio - * whose field definitions we will copy. + * whose field definitions we will copy. * **************************************/ - QLI_REL relation; - QLI_FLD field, *ptr; - SYN node; - PAR_real(); - node = SYNTAX_NODE(nod_def_relation, 2); - relation = (QLI_REL) ALLOCD(type_rel); + SYN node = SYNTAX_NODE(nod_def_relation, 2); + QLI_REL relation = (QLI_REL) ALLOCD(type_rel); node->syn_arg[0] = (SYN) relation; relation->rel_database = parse_database(); relation->rel_symbol = parse_symbol(); @@ -1226,17 +1181,18 @@ static SYN parse_def_relation(void) } else { node->syn_arg[1] = NULL; - ptr = &relation->rel_fields; + QLI_FLD* ptr = &relation->rel_fields; for (;;) { MATCH(KW_ADD); PAR_real(); MATCH(KW_FIELD); - *ptr = field = parse_field(FALSE); + QLI_FLD field = parse_field(FALSE); + *ptr = field; ptr = &field->fld_next; if (KEYWORD(KW_SEMI)) break; if (!MATCH(KW_COMMA)) - SYNTAX_ERROR(171); // Msg171 comma between field definitions + SYNTAX_ERROR(171); // Msg171 comma between field definitions } } @@ -1254,24 +1210,23 @@ static SYN parse_delete(void) ************************************** * * Functional description - * Parse a SQL DELETE statement. + * Parse a SQL DELETE statement. * (DELETE PROCEDURE is parsed in parse_drop) * **************************************/ - SYN node, rse; - ++sql_flag; if (!MATCH(KW_FROM)) - SYNTAX_ERROR(172); // Msg172 FROM + SYNTAX_ERROR(172); // Msg172 FROM + + SYN node = SYNTAX_NODE(nod_erase, s_era_count); + SYN rse = SYNTAX_NODE(nod_rse, (int) s_rse_count + 2); + node->syn_arg[s_era_rse] = rse; - node = SYNTAX_NODE(nod_erase, s_era_count); - node->syn_arg[s_era_rse] = rse = - SYNTAX_NODE(nod_rse, (int) s_rse_count + 2); rse->syn_count = 1; rse->syn_arg[s_rse_count] = parse_sql_relation(); -// Pick up boolean, if present +// Pick up boolean, if present if (MATCH(KW_WITH)) rse->syn_arg[s_rse_boolean] = parse_boolean(0); @@ -1306,7 +1261,7 @@ static SYN parse_drop(void) if (MATCH(KW_RELATION) || MATCH(KW_VIEW) || MATCH(KW_TABLE)) { node = SYNTAX_NODE(nod_del_relation, 1); if (!(node->syn_arg[0] = (SYN) parse_qualified_relation())) - SYNTAX_ERROR(173); // Msg173 relation or view name + SYNTAX_ERROR(173); // Msg173 relation or view name return node; } @@ -1326,7 +1281,7 @@ static SYN parse_drop(void) case KW_DATABASE: LEX_filename(); if (!(l = QLI_token->tok_length)) - ERRQ_error(429, NULL, NULL, NULL, NULL, NULL); // Msg429 database file name required on DROP DATABASE + ERRQ_error(429, NULL, NULL, NULL, NULL, NULL); // Msg429 database file name required on DROP DATABASE q = QLI_token->tok_string; if (QLI_token->tok_type == tok_quoted) { l -= 2; @@ -1335,12 +1290,12 @@ static SYN parse_drop(void) database = (DBB) ALLOCDV(type_dbb, l); database->dbb_filename_length = l; p = database->dbb_filename; - do + do { *p++ = *q++; - while (--l); + } while (--l); PAR_token(); - // parse an optional user name and password if given + // parse an optional user name and password if given for (;;) { if (MATCH(KW_USER)) @@ -1386,10 +1341,9 @@ static int parse_dtype( USHORT * length, USHORT * scale) * Parse a datatype clause. * **************************************/ - KWWORDS keyword; USHORT dtype, l; - keyword = QLI_token->tok_keyword; + KWWORDS keyword = QLI_token->tok_keyword; PAR_token(); *scale = 0; @@ -1470,16 +1424,14 @@ static int parse_dtype_subtype(void) * Returns the numeric subtype value, * **************************************/ - int sign; - -// grab KW_SUB_TYPE +// grab KW_SUB_TYPE PAR_token(); MATCH(KW_IS); if (MATCH(KW_TEXT) || MATCH(KW_FIXED)) return 1; - sign = (MATCH(KW_MINUS)) ? -1 : 1; + int sign = (MATCH(KW_MINUS)) ? -1 : 1; return (sign * parse_ordinal()); } @@ -1489,24 +1441,19 @@ static SYN parse_edit(void) { /************************************** * - * p a r s e _ e d i t + * p a r s e _ e d i t * ************************************** * * Functional description * Parse an edit statement which can * be any of EDIT - * EDIT + * EDIT * EDIT <*> - * EDIT + * EDIT * * **************************************/ - SYN node; - NOD_T type; - int l; - LLS start, stop, statement_list; - LEX_token(); /* @@ -1515,27 +1462,34 @@ static SYN parse_edit(void) */ if (KEYWORD(KW_SEMI) || - (QLI_token->tok_type == tok_number) || (KEYWORD(KW_ASTERISK))) { - if (!(statement_list = LEX_statement_list())) - IBERROR(176); // Msg176 No statements issued yet + (QLI_token->tok_type == tok_number) || (KEYWORD(KW_ASTERISK))) + { + LLS statement_list = LEX_statement_list(); + if (!statement_list) + IBERROR(176); // Msg176 No statements issued yet if (MATCH(KW_ASTERISK)) LEX_edit((SLONG) 0, (SLONG) statement_list->lls_object); else { + int l = 0; // initialize, will catch changes in logic here. if (KEYWORD(KW_SEMI)) l = 1; - else if (QLI_token->tok_type == tok_number) + else if (QLI_token->tok_type == tok_number) // redundant for now l = parse_ordinal(); - for (start = stop = statement_list; - l && start->lls_next; l--, start = start->lls_next); + LLS start = statement_list, stop = start; + while (l && start->lls_next) + { + --l; + start = start->lls_next; + } command_end(); LEX_edit((SLONG) start->lls_object, (SLONG) stop->lls_object); } } else { - type = nod_edit_proc; - node = SYNTAX_NODE(type, 2); + NOD_T type = nod_edit_proc; + SYN node = SYNTAX_NODE(type, 2); node->syn_arg[0] = (SYN) parse_qualified_procedure(); command_end(); return node; @@ -1583,12 +1537,10 @@ static SYN parse_erase(void) * ERASE [ALL] [OF ] * **************************************/ - SYN node; - PAR_token(); MATCH(KW_ALL); MATCH(KW_OF); - node = SYNTAX_NODE(nod_erase, s_era_count); + SYN node = SYNTAX_NODE(nod_erase, s_era_count); if (MATCH(KW_ALL) || potential_rse()) { MATCH(KW_OF); @@ -1613,15 +1565,12 @@ static SYN parse_extract(void) * EXTRACT [ON ] proc [, ...] [ON ] * **************************************/ - LLS stack; - SYN node; - PAR_real_token(); - node = SYNTAX_NODE(nod_extract, 2); + SYN node = SYNTAX_NODE(nod_extract, 2); node->syn_arg[1] = parse_output(); if (!MATCH(KW_ALL)) { - stack = NULL; + LLS stack = NULL; for (;;) { LLS_PUSH(parse_qualified_procedure(), &stack); if (!MATCH(KW_COMMA)) @@ -1631,7 +1580,7 @@ static SYN parse_extract(void) } if (!node->syn_arg[1] && !(node->syn_arg[1] = parse_output())) - SYNTAX_ERROR(177); /* Msg177 "ON or TO" */ + SYNTAX_ERROR(177); // Msg177 "ON or TO" return node; } @@ -1649,20 +1598,16 @@ static QLI_FLD parse_field( int global_flag) * Parse a field description. * **************************************/ - QLI_FLD field; - SYM name, query_name, based_on; - USHORT dtype, length, scale; - SSHORT sub_type, sub_type_missing; - TEXT *edit_string, *query_header; - PAR_real(); - dtype = length = scale = 0; - sub_type = 0; - sub_type_missing = 1; - query_name = based_on = NULL; - edit_string = query_header = NULL; - name = parse_symbol(); + USHORT dtype = 0, length = 0, scale = 0; + SSHORT sub_type = 0; + SSHORT sub_type_missing = 1; + SYM query_name = NULL; + SYM based_on = NULL; + TEXT* edit_string = NULL; + TEXT* query_header = NULL; + SYM name = parse_symbol(); if (global_flag) PAR_real(); @@ -1679,7 +1624,7 @@ static QLI_FLD parse_field( int global_flag) case KW_VARYING: case KW_BLOB: if (dtype) - SYNTAX_ERROR(179); // Msg179 field definition clause + SYNTAX_ERROR(179); // Msg179 field definition clause dtype = parse_dtype(&length, &scale); break; @@ -1691,7 +1636,7 @@ static QLI_FLD parse_field( int global_flag) case KW_EDIT_STRING: PAR_token(); if (QLI_token->tok_type != tok_quoted) - SYNTAX_ERROR(178); // Msg178 quoted edit string + SYNTAX_ERROR(178); // Msg178 quoted edit string edit_string = make_string(QLI_token->tok_string + 1, QLI_token->tok_length - 2); @@ -1702,7 +1647,7 @@ static QLI_FLD parse_field( int global_flag) PAR_token(); MATCH(KW_IS); if (QLI_token->tok_type != tok_ident) - SYNTAX_ERROR(199); // Msg199 identifier + SYNTAX_ERROR(199); // Msg199 identifier query_name = parse_symbol(); break; @@ -1713,12 +1658,12 @@ static QLI_FLD parse_field( int global_flag) break; default: - SYNTAX_ERROR(179); // Msg179 field definition clause + SYNTAX_ERROR(179); // Msg179 field definition clause break; } } - field = (QLI_FLD) ALLOCDV(type_fld, length); + QLI_FLD field = (QLI_FLD) ALLOCDV(type_fld, length); field->fld_name = name; field->fld_dtype = dtype; field->fld_scale = scale; @@ -1731,7 +1676,7 @@ static QLI_FLD parse_field( int global_flag) if (!global_flag) field->fld_based = based_on; else if (based_on) - IBERROR(180); // Msg180 global fields may not be based on other fields + IBERROR(180); // Msg180 global fields may not be based on other fields return field; } @@ -1750,32 +1695,29 @@ static SYN parse_field_name( SYN * fld_ptr) * qualified * expression. * **************************************/ - SYN field, node; - LLS stack; - - stack = NULL; + LLS stack = NULL; while (true) { if (MATCH(KW_ASTERISK)) { if (!stack) - SYNTAX_ERROR(181); // Msg181 field name or asterisk expression - field = make_list(stack); - field->syn_type = nod_star; - return field; + SYNTAX_ERROR(181); // Msg181 field name or asterisk expression + SYN afield = make_list(stack); + afield->syn_type = nod_star; + return afield; } LLS_PUSH(parse_name(), &stack); if (!MATCH(KW_DOT)) break; } - field = make_list(stack); + SYN field = make_list(stack); field->syn_type = nod_field; if (fld_ptr) *fld_ptr = field; if (!(MATCH(KW_L_BRCKET))) return field; -// Parse an array reference +// Parse an array reference stack = NULL; for (;;) { @@ -1783,10 +1725,10 @@ static SYN parse_field_name( SYN * fld_ptr) if (MATCH(KW_R_BRCKET)) break; if (!MATCH(KW_COMMA)) - SYNTAX_ERROR(183); // Msg183 comma + SYNTAX_ERROR(183); // Msg183 comma } - node = SYNTAX_NODE(nod_index, s_idx_count); + SYN node = SYNTAX_NODE(nod_index, s_idx_count); node->syn_arg[s_idx_field] = field; node->syn_arg[s_idx_subs] = make_list(stack); @@ -1806,10 +1748,8 @@ static SYN parse_for(void) * Parse a FOR statement. * **************************************/ - SYN node; - PAR_token(); - node = SYNTAX_NODE(nod_for, s_for_count); + SYN node = SYNTAX_NODE(nod_for, s_for_count); node->syn_arg[s_for_rse] = parse_rse(); node->syn_arg[s_for_statement] = parse_statement(); @@ -1829,7 +1769,7 @@ static SYN parse_from( USHORT * paren_count, USHORT * bool_flag) * Parse either an explicit or implicit FIRST ... FROM statement. * **************************************/ - SYN node, value; + SYN value; PAR_real(); @@ -1837,7 +1777,7 @@ static SYN parse_from( USHORT * paren_count, USHORT * bool_flag) value = parse_primitive_value(0, 0); PAR_real(); if (!MATCH(KW_FROM)) - SYNTAX_ERROR(182); // Msg182 FROM rse clause + SYNTAX_ERROR(182); // Msg182 FROM rse clause } else { value = parse_primitive_value(paren_count, bool_flag); @@ -1845,7 +1785,7 @@ static SYN parse_from( USHORT * paren_count, USHORT * bool_flag) return value; } - node = SYNTAX_NODE(nod_from, s_stt_count); + SYN node = SYNTAX_NODE(nod_from, s_stt_count); node->syn_arg[s_stt_value] = value; node->syn_arg[s_stt_rse] = parse_rse(); @@ -1868,15 +1808,12 @@ static SYN parse_function(void) * Parse a function reference. * **************************************/ - SYN node; - LLS stack; - function_count++; - node = SYNTAX_NODE(nod_function, s_fun_count); + SYN node = SYNTAX_NODE(nod_function, s_fun_count); node->syn_arg[s_fun_function] = (SYN) QLI_token->tok_symbol; node->syn_count = 1; PAR_token(); - stack = NULL; + LLS stack = NULL; if (MATCH(KW_LEFT_PAREN)) for (;;) { @@ -1884,7 +1821,7 @@ static SYN parse_function(void) if (MATCH(KW_RIGHT_PAREN)) break; if (!MATCH(KW_COMMA)) - SYNTAX_ERROR(183); // Msg183 comma + SYNTAX_ERROR(183); // Msg183 comma } node->syn_arg[s_fun_args] = make_list(stack); @@ -1908,15 +1845,15 @@ static TEXT *parse_header(void) * or even the non-header - * **************************************/ - TEXT *p, *q, header[1024]; + TEXT header[1024]; - p = header; + TEXT* p = header; while (true) { PAR_real(); if ((QLI_token->tok_keyword != KW_MINUS) && - (QLI_token->tok_type != tok_quoted)) SYNTAX_ERROR(184); // Msg184 quoted header segment - q = QLI_token->tok_string; + (QLI_token->tok_type != tok_quoted)) SYNTAX_ERROR(184); // Msg184 quoted header segment + const TEXT* q = QLI_token->tok_string; while (*q) *p++ = *q++; PAR_real_token(); @@ -1941,10 +1878,7 @@ static SYN parse_help(void) * must be appeased. Bread, circuses, help. * **************************************/ - SYN node; - LLS stack; - - stack = NULL; + LLS stack = NULL; PAR_token(); while (!KEYWORD(KW_SEMI)) { @@ -1952,7 +1886,7 @@ static SYN parse_help(void) MATCH(KW_COMMA); } - node = make_list(stack); + SYN node = make_list(stack); node->syn_type = nod_help; command_end(); @@ -1972,10 +1906,8 @@ static SYN parse_if(void) * Parse an IF THEN ELSE statement. * **************************************/ - SYN node; - PAR_token(); - node = SYNTAX_NODE(nod_if, s_if_count); + SYN node = SYNTAX_NODE(nod_if, s_if_count); node->syn_arg[s_if_boolean] = parse_boolean(0); PAR_real(); MATCH(KW_THEN); @@ -2006,36 +1938,34 @@ static SYN parse_in( SYN value, NOD_T operatr, USHORT all_flag) * value IN (column