8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-25 00:43:03 +01:00
firebird-mirror/src/alice/alice.cpp

849 lines
20 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// PROGRAM: Alice (All Else) Utility
// MODULE: alice.cpp
// DESCRIPTION: Neo-Debe (does everything but eat)
//
2001-05-23 15:26:42 +02:00
// The contents of this file are subject to the Interbase Public
// License Version 1.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.Inprise.com/IPL.html
//
2001-05-23 15:26:42 +02:00
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
// or implied. See the License for the specific language governing
// rights and limitations under the License.
//
2001-05-23 15:26:42 +02:00
// The Original Code was created by Inprise Corporation
// and its predecessors. Portions created by Inprise Corporation are
// Copyright (C) Inprise Corporation.
//
2001-05-23 15:26:42 +02:00
// All Rights Reserved.
// Contributor(s): ______________________________________.
//
2001-05-23 15:26:42 +02:00
//
//____________________________________________________________
//
2002-10-30 07:40:58 +01:00
// $Id: alice.cpp,v 1.17 2002-10-30 06:40:44 seanleyne Exp $
//
// 2001.07.06 Sean Leyne - Code Cleanup, removed "#ifdef READONLY_DATABASE"
// conditionals, as the engine now fully supports
// readonly databases.
2001-05-23 15:26:42 +02:00
//
2002-10-30 07:40:58 +01:00
// 2002.10.29 Sean Leyne - Removed support for obsolete "Netware" port
//
//
2001-05-23 15:26:42 +02:00
#include "firebird.h"
2001-05-23 15:26:42 +02:00
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#define FB_FROM_ALICE_CPP
#include "../alice/alice.h"
#include "../alice/aliceswi.h"
#include "../alice/all.h"
#include "../alice/alice_proto.h"
#include "../alice/all_proto.h"
#include "../alice/exe_proto.h"
2001-12-28 06:16:31 +01:00
#include "../jrd/ib_stdio.h"
#include "../jrd/gds.h"
#include "../jrd/common.h"
#include "../jrd/license.h"
#include "../jrd/ibsetjmp.h"
#include "../jrd/msg_encode.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/gds_proto.h"
#include "../jrd/svc.h"
#include "../jrd/svc_proto.h"
#include "../jrd/thd_proto.h"
2001-07-12 07:46:06 +02:00
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
2001-05-23 15:26:42 +02:00
#ifdef SUPERSERVER
#include "../utilities/cmd_util_proto.h"
#endif
#ifdef WIN_NT
#include <windows.h>
#endif
#if (defined WIN_NT || defined PC_PLATFORM)
#include <io.h>
#endif
2001-12-25 05:53:56 +01:00
static const USHORT val_err_table[] = {
2001-05-23 15:26:42 +02:00
0,
2001-12-25 05:53:56 +01:00
55, // msg 55: \n\tNumber of record level errors\t: %ld
56, // msg 56: \tNumber of Blob page errors\t: %ld
57, // msg 57: \tNumber of data page errors\t: %ld
58, // msg 58: \tNumber of index page errors\t: %ld
59, // msg 59: \tNumber of pointer page errors\t: %ld
60, // msg 60: \tNumber of transaction page errors\t: %ld
61 // msg 61: \tNumber of database page errors\t: %ld
2001-05-23 15:26:42 +02:00
};
// The following structure in only needed if we are building a local exe
// I've commented it out to make it clear since this global variable is
// defined in burp.cpp as well, and is not relevant for SUPERSERVER
#ifndef SUPERSERVER
2001-05-23 15:26:42 +02:00
struct tgbl *gdgbl;
#endif
#define ALICE_MSG_FAC 3
2001-12-25 05:53:56 +01:00
#define EXIT(code) { tdgbl->exit_code = (code); \
2001-12-29 12:41:29 +01:00
Firebird::status_exception::raise(1); }
2001-12-25 05:53:56 +01:00
2001-05-23 15:26:42 +02:00
#if defined (WIN95) && !defined (GUI_TOOLS)
2001-12-25 08:57:04 +01:00
static bool fAnsiCP = false;
2001-05-23 15:26:42 +02:00
#endif
2001-12-25 08:57:04 +01:00
static void ALICE_error(USHORT number); // overloaded to keep down param count
static inline void translate_cp(TEXT* sz);
2001-12-25 05:53:56 +01:00
static void expand_filename(TEXT*, TEXT*);
static int output_thread(SLONG, UCHAR*);
static int output_main(SLONG, UCHAR*);
static int output_svc(SLONG, UCHAR*);
#ifdef __GNUC__
static void alice_output(CONST SCHAR*, ...) __attribute__ ((format(printf,1,2)));
#else
2001-12-25 05:53:56 +01:00
static void alice_output(CONST SCHAR*, ...);
#endif
2001-05-23 15:26:42 +02:00
#ifdef SUPERSERVER
//____________________________________________________________
//
2001-12-25 05:53:56 +01:00
// Entry point for GFIX in case of service manager.
//
2001-05-23 15:26:42 +02:00
int main_gfix(SVC service)
{
2001-12-25 05:53:56 +01:00
int exit_code =
ALICE_gfix( service->svc_argc,
service->svc_argv,
output_thread,
(SLONG) service);
2001-05-23 15:26:42 +02:00
service->svc_handle = 0;
2001-12-25 05:53:56 +01:00
if (service->svc_service->in_use != NULL) {
2001-05-23 15:26:42 +02:00
*(service->svc_service->in_use) = FALSE;
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
// Mark service thread as finished.
// If service is detached, cleanup memory being used by service.
2001-05-23 15:26:42 +02:00
SVC_finish(service, SVC_finished);
return exit_code;
}
//____________________________________________________________
//
2001-12-25 05:53:56 +01:00
// Routine which is passed to GFIX for calling back when there is output.
//
2001-05-23 15:26:42 +02:00
static int output_thread(SLONG output_data, UCHAR * output_buf)
{
SVC_fprintf((SVC) output_data, "%s", output_buf);
return 0;
}
2001-12-25 05:53:56 +01:00
#else // SUPERSERVER
2001-05-23 15:26:42 +02:00
#ifndef GUI_TOOLS
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Call the 'real' main.
//
2001-05-23 15:26:42 +02:00
int CLIB_ROUTINE main(int argc, char *argv[])
{
2001-12-25 05:53:56 +01:00
int exit_code = ALICE_gfix(argc, argv, output_main, (SLONG) NULL);
2001-05-23 15:26:42 +02:00
return exit_code;
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Routine which is passed to GFIX for calling back when there is output.
//
2001-05-23 15:26:42 +02:00
static int output_main(SLONG output_data, UCHAR * output_buf)
{
ib_fprintf(ib_stderr, "%s", output_buf);
return 0;
}
2001-12-25 05:53:56 +01:00
#endif // !GUI_TOOLS
#endif // SUPERSERVER
2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Routine which is passed to GFIX for calling back when there is output
// if gfix is run as a service
//
2001-05-23 15:26:42 +02:00
static int output_svc(SLONG output_data, UCHAR * output_buf)
{
ib_fprintf(ib_stdout, "%s", output_buf);
return 0;
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Routine called by command line utility, and server manager
// Parse switches and do work
//
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
int DLL_EXPORT ALICE_gfix( int argc,
char* argv[],
OUTPUTPROC output_proc,
SLONG output_data)
2001-05-23 15:26:42 +02:00
{
IN_SW_TAB table = alice_in_sw_table;
2001-12-25 05:53:56 +01:00
USHORT error;
TEXT* database;
TEXT string[512];
ULONG switches;
SLONG redir_in;
SLONG redir_out;
SLONG redir_err;
2001-05-23 15:26:42 +02:00
#if defined (WIN95) && !defined (GUI_TOOLS)
2001-12-25 08:57:04 +01:00
fAnsiCP = (GetConsoleCP() == GetACP());
2001-05-23 15:26:42 +02:00
#endif
volatile tgbl* tdgbl = (struct tgbl*) gds__alloc(sizeof(*tdgbl));
2001-12-25 05:53:56 +01:00
if (!tdgbl) {
// NOMEM: return error, FREE: during function exit in the SETJMP
2001-05-23 15:26:42 +02:00
return FINI_ERROR;
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
SET_THREAD_DATA;
SVC_PUTSPECIFIC_DATA;
memset((void *) tdgbl, 0, sizeof(*tdgbl));
tdgbl->output_proc = output_proc;
tdgbl->output_data = output_data;
tdgbl->ALICE_permanent_pool = NULL;
tdgbl->ALICE_default_pool = NULL;
2001-12-24 03:51:06 +01:00
try {
2001-05-23 15:26:42 +02:00
#ifdef VMS
argc = VMS_parse(&argv, argc);
#endif
// Perform some special handling when run as an Interbase service. The
// first switch can be "-svc" (lower case!) or it can be "-svc_re" followed
// by 3 file descriptors to use in re-directing ib_stdin, ib_stdout, and ib_stderr.
2001-05-23 15:26:42 +02:00
tdgbl->sw_service = FALSE;
tdgbl->sw_service_thd = FALSE;
tdgbl->service_blk = NULL;
tdgbl->status =
/* TMN: cast away volatile */
(long *) tdgbl->status_vector;
if (argc > 1 && !strcmp(argv[1], "-svc")) {
tdgbl->sw_service = TRUE;
argv++;
argc--;
}
else if (argc > 1 && !strcmp(argv[1], "-svc_thd")) {
tdgbl->sw_service = TRUE;
tdgbl->sw_service_thd = TRUE;
tdgbl->service_blk = (SVC) output_data;
tdgbl->status = tdgbl->service_blk->svc_status;
argv++;
argc--;
}
else if (argc > 4 && !strcmp(argv[1], "-svc_re")) {
tdgbl->sw_service = TRUE;
tdgbl->output_proc = output_svc;
redir_in = atol(argv[2]);
redir_out = atol(argv[3]);
redir_err = atol(argv[4]);
#ifdef WIN_NT
#if defined (WIN95) && !defined (GUI_TOOLS)
2001-12-25 08:57:04 +01:00
fAnsiCP = true;
2001-05-23 15:26:42 +02:00
#endif
redir_in = _open_osfhandle(redir_in, 0);
redir_out = _open_osfhandle(redir_out, 0);
redir_err = _open_osfhandle(redir_err, 0);
#endif
2001-12-25 08:57:04 +01:00
if (redir_in != 0) {
if (dup2((int) redir_in, 0)) {
2001-05-23 15:26:42 +02:00
close((int) redir_in);
2001-12-25 08:57:04 +01:00
}
}
if (redir_out != 1) {
if (dup2((int) redir_out, 1)) {
2001-05-23 15:26:42 +02:00
close((int) redir_out);
2001-12-25 08:57:04 +01:00
}
}
if (redir_err != 2) {
if (dup2((int) redir_err, 2)) {
2001-05-23 15:26:42 +02:00
close((int) redir_err);
2001-12-25 08:57:04 +01:00
}
}
2001-05-23 15:26:42 +02:00
argv += 4;
argc -= 4;
}
tdgbl->ALICE_data.ua_user = NULL;
tdgbl->ALICE_data.ua_password = NULL;
// Start by parsing switches
2001-05-23 15:26:42 +02:00
error = 0;
switches = 0;
tdgbl->ALICE_data.ua_shutdown_delay = 0;
database = NULL;
argv++;
2001-12-24 03:51:06 +01:00
while (--argc > 0)
{
if ((*argv)[0] != '-')
{
if (database) {
2001-05-23 15:26:42 +02:00
ALICE_error(1, database, 0, 0, 0, 0); /* msg 1: "data base file name (%s) already given", */
2001-12-24 03:51:06 +01:00
}
2001-05-23 15:26:42 +02:00
database = *argv++;
#if defined (WIN95) && !defined (GUI_TOOLS)
// There is a small problem with SuperServer on NT, since it is a
// Windows app, it uses the ANSI character set. All the console
2001-12-25 08:57:04 +01:00
// apps use the OEM character set. We need to pass the database
2001-05-23 15:26:42 +02:00
// name in the correct character set.
// if (GetConsoleCP != GetACP())
// OemToAnsi(database, database);
//
2001-05-23 15:26:42 +02:00
#else
#endif
continue;
}
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (!string[1]) {
2001-05-23 15:26:42 +02:00
continue;
2001-12-25 05:53:56 +01:00
}
for (table = alice_in_sw_table; TRUE; ++table)
{
const TEXT* p = (TEXT*) table->in_sw_name;
if (!p) {
2001-05-23 15:26:42 +02:00
ALICE_print(2, *--argv, 0, 0, 0, 0); /* msg 2: invalid switch %s */
error = TRUE;
break;
}
2001-12-25 05:53:56 +01:00
TEXT* q = &string[1];
while (*q && *p++ == *q) {
2001-05-23 15:26:42 +02:00
q++;
2001-12-25 05:53:56 +01:00
}
if (!*q) {
2001-05-23 15:26:42 +02:00
break;
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
2001-12-25 05:53:56 +01:00
if (error) {
2001-05-23 15:26:42 +02:00
break;
2001-12-25 05:53:56 +01:00
}
if (*table->in_sw_name == 'x') {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_debug++;
2001-12-25 05:53:56 +01:00
}
if (table->in_sw_value == sw_z) {
2001-05-23 15:26:42 +02:00
ALICE_print(3, GDS_VERSION, 0, 0, 0, 0); /* msg 3: gfix version %s */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
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 */
error = TRUE;
break;
}
switches |= table->in_sw_value;
if (table->in_sw_value & sw_begin_log) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(5); /* msg 5: replay log pathname required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
expand_filename(*argv++, /* TMN: cast away volatile */
(TEXT *) tdgbl->ALICE_data.ua_log_file);
}
if (table->in_sw_value & (sw_buffers)) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(6); /* msg 6: number of page buffers for cache required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
if ((!(tdgbl->ALICE_data.ua_page_buffers = atoi(string)))
&& (strcmp(string, "0")))
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(7); /* msg 7: numeric value required */
2001-12-25 05:53:56 +01:00
}
if (tdgbl->ALICE_data.ua_page_buffers < 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(8); /* msg 8: positive numeric value required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & (sw_housekeeping)) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2002-06-29 07:33:02 +02:00
ALICE_error(113); /* msg 113: dialect number required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
if ((!(tdgbl->ALICE_data.ua_sweep_interval = atoi(string)))
&& (strcmp(string, "0")))
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(7); /* msg 7: numeric value required */
2001-12-25 05:53:56 +01:00
}
if (tdgbl->ALICE_data.ua_sweep_interval < 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(8); /* msg 8: positive numeric value required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & (sw_set_db_dialect)) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(113); /* msg 113: dialect info is required XXX */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
if ((!(tdgbl->ALICE_data.ua_db_SQL_dialect = atoi(string))) &&
(strcmp(string, "0")))
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(7); /* msg 7: numeric value required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
2002-04-04 07:31:13 +02:00
// JMB: Removed because tdgbl->ALICE_data.ua_db_SQL_dialect is
// an unsigned number. Therefore this check is useless.
// if (tdgbl->ALICE_data.ua_db_SQL_dialect < 0)
// {
// ALICE_error(8); /* msg 8: positive numeric value
// required */
// }
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & (sw_commit | sw_rollback | sw_two_phase)) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(10); /* msg 10: transaction number or "all" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (!(tdgbl->ALICE_data.ua_transaction = atoi(string))) {
if (strcmp(string, "all")) {
2001-12-25 08:57:04 +01:00
ALICE_error(10); /* msg 10: transaction number or "all" required */
2001-12-25 05:53:56 +01:00
} else {
2001-05-23 15:26:42 +02:00
switches |= sw_list;
2001-12-25 05:53:56 +01:00
}
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_write) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(11); /* msg 11: "sync" or "async" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (!strcmp(string, ALICE_SW_SYNC)) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_force = TRUE;
2001-12-25 05:53:56 +01:00
} else if (!strcmp(string, ALICE_SW_ASYNC)) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_force = FALSE;
2001-12-25 05:53:56 +01:00
} else {
2001-12-25 08:57:04 +01:00
ALICE_error(11); /* msg 11: "sync" or "async" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_use) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(12); /* msg 12: "full" or "reserve" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (!strcmp(string, "full")) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_use = TRUE;
2001-12-25 05:53:56 +01:00
} else if (!strcmp(string, "reserve")) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_use = FALSE;
2001-12-25 05:53:56 +01:00
} else {
2001-12-25 08:57:04 +01:00
ALICE_error(12); /* msg 12: "full" or "reserve" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_user) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(13); /* msg 13: user name required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_user =
2001-12-25 05:53:56 +01:00
const_cast<UCHAR* volatile>(reinterpret_cast<UCHAR*>(*argv++));
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_password) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(14); /* msg 14: password required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_password =
2001-12-25 05:53:56 +01:00
const_cast<UCHAR* volatile>(reinterpret_cast<UCHAR*>(*argv++));
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_disable) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(15); /* msg 15: subsystem name */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (strcmp(string, "wal")) {
2001-12-25 08:57:04 +01:00
ALICE_error(16); /* msg 16: "wal" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & (sw_attach | sw_force | sw_tran | sw_cache)) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(17); /* msg 17: number of seconds required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
if ((!(tdgbl->ALICE_data.ua_shutdown_delay = atoi(string)))
&& (strcmp(string, "0")))
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(7); /* msg 7: numeric value required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
if (tdgbl->ALICE_data.ua_shutdown_delay < 0
|| tdgbl->ALICE_data.ua_shutdown_delay > 32767)
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(18); /* msg 18: numeric value between 0 and 32767 inclusive required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
if (table->in_sw_value & sw_mode) {
2001-12-25 05:53:56 +01:00
if (--argc <= 0) {
2001-12-25 08:57:04 +01:00
ALICE_error(110); /* msg 110: "read_only" or "read_write" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
ALICE_down_case(*argv++, string);
2001-12-25 05:53:56 +01:00
if (!strcmp(string, ALICE_SW_MODE_RO)) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_read_only = TRUE;
2001-12-25 05:53:56 +01:00
} else if (!strcmp(string, ALICE_SW_MODE_RW)) {
2001-05-23 15:26:42 +02:00
tdgbl->ALICE_data.ua_read_only = FALSE;
2001-12-25 05:53:56 +01:00
} else {
2001-12-25 08:57:04 +01:00
ALICE_error(110); /* msg 110: "read_only" or "read_write" required */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
}
// put this here since to put it above overly complicates the parsing
// can't use tbl_requires since it only looks backwards on command line
2001-05-23 15:26:42 +02:00
if ((switches & sw_shut)
&& !(switches & ((sw_attach | sw_force | sw_tran | sw_cache))))
2001-12-25 05:53:56 +01:00
{
2001-12-25 08:57:04 +01:00
ALICE_error(19); /* msg 19: must specify type of shutdown */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
// catch the case where -z is only command line option
// switches is unset since sw_z == 0
2001-12-25 05:53:56 +01:00
if (!switches && !error && table->in_sw_value == sw_z) {
2001-05-23 15:26:42 +02:00
EXIT(FINI_OK);
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
if (!switches || !(switches & ~(sw_user | sw_password))) {
#ifndef SUPERSERVER
ALICE_print(20, 0, 0, 0, 0, 0); /* msg 20: please retry, specifying an option */
#endif
error = TRUE;
}
if (error) {
#ifdef SUPERSERVER
CMD_UTIL_put_svc_status(tdgbl->service_blk->svc_status, ALICE_MSG_FAC,
20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
SVC_STARTED(tdgbl->service_blk);
#else
ALICE_print(21, 0, 0, 0, 0, 0); /* msg 21: plausible options are:\n */
for (table = alice_in_sw_table; table->in_sw_msg; table++)
ALICE_print(table->in_sw_msg, 0, 0, 0, 0, 0);
ALICE_print(22, 0, 0, 0, 0, 0); /* msg 22: \n qualifiers show the major option in parenthesis */
#endif
EXIT(FINI_ERROR);
}
2001-12-25 05:53:56 +01:00
if (!database) {
2001-12-25 08:57:04 +01:00
ALICE_error(23); /* msg 23: please retry, giving a database name */
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
// generate the database parameter block for the attach,
// based on the various switches
USHORT ret;
2001-05-23 15:26:42 +02:00
if (switches & (sw_list | sw_commit | sw_rollback | sw_two_phase))
2001-12-25 05:53:56 +01:00
{
2001-05-23 15:26:42 +02:00
ret = EXE_two_phase(database, switches);
2001-12-25 05:53:56 +01:00
}
else
{
2001-05-23 15:26:42 +02:00
ret = EXE_action(database, switches);
2001-12-25 08:57:04 +01:00
// cast away volatile
const SLONG* ua_val_errors =
const_cast<SLONG*>(tdgbl->ALICE_data.ua_val_errors);
if (!ua_val_errors[VAL_INVALID_DB_VERSION])
{
bool any_error = false;
2001-05-23 15:26:42 +02:00
2001-12-25 08:57:04 +01:00
for (int i = 0; i < MAX_VAL_ERRORS; ++i) {
if (ua_val_errors[i]) {
any_error = true;
break;
}
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
2001-12-25 08:57:04 +01:00
if (any_error) {
ALICE_print(24, 0, 0, 0, 0, 0); /* msg 24: Summary of validation errors\n */
2001-05-23 15:26:42 +02:00
2001-12-25 08:57:04 +01:00
for (int i = 0; i < MAX_VAL_ERRORS; ++i) {
if (ua_val_errors[i]) {
TEXT* szErr = reinterpret_cast<TEXT*>(ua_val_errors[i]);
ALICE_print(val_err_table[i], szErr, 0, 0, 0, 0);
}
2001-12-25 05:53:56 +01:00
}
}
2001-05-23 15:26:42 +02:00
}
}
2001-12-25 05:53:56 +01:00
if (ret == FINI_ERROR) {
2001-05-23 15:26:42 +02:00
ALICE_print_status(tdgbl->status);
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
EXIT(FINI_OK);
2001-12-24 03:51:06 +01:00
} // try
catch (...)
{
2001-12-25 05:53:56 +01:00
/* All "calls" to EXIT(), normal and error exits, wind up here */
2001-12-24 03:51:06 +01:00
SVC_STARTED(tdgbl->service_blk);
2001-12-25 05:53:56 +01:00
int exit_code = tdgbl->exit_code;
2001-12-24 03:51:06 +01:00
/* Close the status output file */
if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) {
ib_fclose(tdgbl->output_file);
tdgbl->output_file = NULL;
}
/* Free all unfreed memory used by Gfix itself */
ALLA_fini();
RESTORE_THREAD_DATA;
2001-12-25 05:53:56 +01:00
// cast away volatile
gds__free((void*)tdgbl);
2001-12-24 03:51:06 +01:00
#if defined(DEBUG_GDS_ALLOC) && !defined(SUPERSERVER)
gds_alloc_report(0, __FILE__, __LINE__);
#endif
/* All returns occur from this point - even normal returns */
return exit_code;
} // catch
2001-05-23 15:26:42 +02:00
return 0; // compiler silencer
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Copy a string, down casing as we go.
//
2001-05-23 15:26:42 +02:00
void ALICE_down_case(TEXT * in, TEXT * out)
{
TEXT c;
2001-12-25 05:53:56 +01:00
while (c = *in++) {
2001-05-23 15:26:42 +02:00
*out++ = (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c;
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
*out = 0;
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Display a formatted error message
//
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
void ALICE_print(USHORT number,
TEXT* arg1,
TEXT* arg2,
TEXT* arg3,
TEXT* arg4,
TEXT* arg5)
2001-05-23 15:26:42 +02:00
{
TEXT buffer[256];
gds__msg_format(0, ALICE_MSG_FAC, number, sizeof(buffer), buffer, arg1,
arg2, arg3, arg4, arg5);
2001-12-25 08:57:04 +01:00
translate_cp(buffer);
2001-05-23 15:26:42 +02:00
alice_output("%s\n", buffer);
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Print error message. Use isc_interprete
// to allow redirecting output.
//
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
void ALICE_print_status(STATUS* status_vector)
2001-05-23 15:26:42 +02:00
{
2001-12-25 05:53:56 +01:00
STATUS* vector;
SCHAR s[1024];
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
if (status_vector)
{
2001-05-23 15:26:42 +02:00
vector = status_vector;
#ifdef SUPERSERVER
2001-12-25 05:53:56 +01:00
int i = 0, j;
TGBL tdgbl = GET_THREAD_DATA;
STATUS* status = tdgbl->service_blk->svc_status;
2001-05-23 15:26:42 +02:00
if (status != status_vector) {
2001-12-25 05:53:56 +01:00
while (*status && (++i < ISC_STATUS_LENGTH)) {
2001-05-23 15:26:42 +02:00
status++;
2001-12-25 05:53:56 +01:00
}
for (j = 0; status_vector[j] && (i < ISC_STATUS_LENGTH); j++, i++) {
2001-05-23 15:26:42 +02:00
*status++ = status_vector[j];
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
#endif
isc_interprete(s, &vector);
2001-12-25 08:57:04 +01:00
translate_cp(s);
2001-05-23 15:26:42 +02:00
alice_output("%s\n", s);
/* Continuation of error */
s[0] = '-';
while (isc_interprete(s + 1, &vector)) {
2001-12-25 08:57:04 +01:00
translate_cp(s);
2001-05-23 15:26:42 +02:00
alice_output("%s\n", s);
}
}
}
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Format and print an error message, then punt.
//
2001-05-23 15:26:42 +02:00
2001-12-25 05:53:56 +01:00
void ALICE_error(USHORT number,
TEXT* arg1,
TEXT* arg2,
TEXT* arg3,
TEXT* arg4,
TEXT* arg5)
2001-05-23 15:26:42 +02:00
{
2001-12-25 05:53:56 +01:00
TGBL tdgbl = GET_THREAD_DATA;
2001-05-23 15:26:42 +02:00
TEXT buffer[256];
#ifdef SUPERSERVER
2001-12-25 05:53:56 +01:00
STATUS* status = tdgbl->service_blk->svc_status;
2001-05-23 15:26:42 +02:00
CMD_UTIL_put_svc_status(status, ALICE_MSG_FAC, number,
isc_arg_string, arg1,
isc_arg_string, arg2,
isc_arg_string, arg3,
2001-12-25 05:53:56 +01:00
isc_arg_string, arg4,
isc_arg_string, arg5);
2001-05-23 15:26:42 +02:00
#endif
gds__msg_format(0, ALICE_MSG_FAC, number, sizeof(buffer), buffer, arg1,
arg2, arg3, arg4, arg5);
2001-12-25 08:57:04 +01:00
translate_cp(buffer);
2001-05-23 15:26:42 +02:00
alice_output("%s\n", buffer);
EXIT(FINI_ERROR);
}
2001-12-25 08:57:04 +01:00
//
// Overload of ALICE_error to keep down parameter count.
//
static void ALICE_error(USHORT number)
{
ALICE_error(number, 0, 0, 0, 0, 0);
}
2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Platform independent output routine.
//
2001-05-23 15:26:42 +02:00
static void alice_output(CONST SCHAR * format, ...)
{
va_list arglist;
UCHAR buf[1000];
int exit_code;
2001-12-25 05:53:56 +01:00
TGBL tdgbl = GET_THREAD_DATA;
2001-05-23 15:26:42 +02:00
if (tdgbl->sw_redirect == NOOUTPUT || format[0] == '\0') {
exit_code =
tdgbl->output_proc(tdgbl->output_data,
2001-07-12 07:46:06 +02:00
(UCHAR *)(""));
2001-05-23 15:26:42 +02:00
}
else if (tdgbl->sw_redirect == TRUE && tdgbl->output_file != NULL) {
VA_START(arglist, format);
ib_vfprintf(tdgbl->output_file, format, arglist);
va_end(arglist);
exit_code =
tdgbl->output_proc(tdgbl->output_data,
2001-07-12 07:46:06 +02:00
(UCHAR *)(""));
2001-05-23 15:26:42 +02:00
}
else {
VA_START(arglist, format);
vsprintf((char *) buf, format, arglist);
va_end(arglist);
exit_code = tdgbl->output_proc(tdgbl->output_data, buf);
}
2001-12-25 05:53:56 +01:00
if (exit_code != 0) {
2001-05-23 15:26:42 +02:00
EXIT(exit_code);
2001-12-25 05:53:56 +01:00
}
2001-05-23 15:26:42 +02:00
}
2001-12-25 08:57:04 +01:00
//
// Translate the given string from Windows ANSI charset to the
// to the current OEM charset iff:
// 1. The macro WIN95 is defined AND
// 2. The macro GUI_TOOLS is NOT defined AND
// 3. The static variable fAnsiCP is false.
//
static inline void translate_cp(TEXT* sz)
2001-12-25 08:57:04 +01:00
{
#if defined (WIN95) && !defined (GUI_TOOLS)
if (!fAnsiCP) {
CharToOem(sz, sz);
}
#endif
}
2001-05-23 15:26:42 +02:00
//____________________________________________________________
//
2001-05-23 15:26:42 +02:00
// Fully expand a file name. If the file doesn't exist, do something
// intelligent.
//
2001-05-23 15:26:42 +02:00
static void expand_filename(TEXT * filename, TEXT * expanded_name)
{
strcpy(expanded_name, filename);
}