8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-27 18:03:04 +01:00
firebird-mirror/src/msgs/enter_msgs.epp

539 lines
12 KiB
Plaintext
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: Interbase Message file entry program
2003-11-10 10:16:38 +01:00
* MODULE: enter_messages.epp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Allow entry of messages to database
*
* 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
*
* 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.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
2004-04-29 00:36:29 +02:00
#include <stdio.h>
2002-11-25 17:14:13 +01:00
2003-11-08 17:40:17 +01:00
#include "../jrd/ibase.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/common.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_CTYPE_H
#include <ctype.h>
#endif
#include <stdlib.h>
2002-11-25 17:14:13 +01:00
DATABASE DB = "msg.fdb";
2001-05-23 15:26:42 +02:00
static void ascii_str_upper(UCHAR*);
2003-08-29 02:37:25 +02:00
static bool get_sql_class(UCHAR *);
static bool get_sql_code(SSHORT *);
static bool get_sql_subclass(UCHAR *);
static bool store_sql_msg(void);
static bool translate(const UCHAR*, UCHAR*, SSHORT);
2003-08-29 02:37:25 +02:00
static bool get_symbol( UCHAR *);
2001-05-23 15:26:42 +02:00
2004-05-18 18:32:07 +02:00
const int FAC_SQL_POSITIVE = 14;
const int FAC_SQL_NEGATIVE = 13;
2001-05-23 15:26:42 +02:00
2004-05-18 18:32:07 +02:00
const char LOWER_A = 'a';
const char UPPER_A = 'A';
const char LOWER_Z = 'z';
const char UPPER_Z = 'Z';
2001-05-23 15:26:42 +02:00
int main( int argc, char **argv)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* Top level routine.
*
**************************************/
/* Note that the lengths of these variables are based on the lengths of the
* fields in the message database */
UCHAR facility[20], text[256], module[32], routine[32];
UCHAR sql_class[32], sql_sub_class[32];
UCHAR symbol[30], pub[1];
UCHAR nstring[32];
SSHORT count;
2002-12-10 12:53:53 +01:00
SSHORT sql_num;
2003-08-29 02:37:25 +02:00
bool public_msg;
2001-05-23 15:26:42 +02:00
/* Setup the 'strings' so that element 0 is really 0 */
memset(facility, 0, sizeof(facility));
memset(text, 0, sizeof(text));
memset(module, 0, sizeof(module));
memset(routine, 0, sizeof(routine));
memset(sql_class, 0, sizeof(sql_class));
memset(sql_sub_class, 0, sizeof(sql_sub_class));
memset(symbol, 0, sizeof(symbol));
memset(pub, 0, sizeof(pub));
memset(nstring, 0, sizeof(nstring));
2004-04-29 00:36:29 +02:00
printf("\nHit Ctrl-D (or Ctrl-Z) at prompt to exit level\n");
printf
2001-05-23 15:26:42 +02:00
("You will be prompted for facility, module, routine and message text\n");
2004-04-29 00:36:29 +02:00
printf
2001-05-23 15:26:42 +02:00
("You *must* enter module and routine names for each message; be prepared\n");
2004-04-29 00:36:29 +02:00
printf("You will be returned a message number for the message\n");
printf("You may assign an optional symbol for the message\n");
printf
2001-05-23 15:26:42 +02:00
("Escape sequences may be entered and will be translated to single bytes\n");
READY;
START_TRANSACTION;
for (;;) {
2004-04-29 00:36:29 +02:00
printf("Facility: ");
2004-11-30 07:18:39 +01:00
if (gets((char*) facility) == NULL)
2001-05-23 15:26:42 +02:00
break;
ascii_str_upper(facility);
count = 0;
FOR X IN FACILITIES WITH X.FACILITY = facility
count++;
if (X.FAC_CODE == FAC_SQL_POSITIVE
|| X.FAC_CODE == FAC_SQL_NEGATIVE)
{
2001-05-23 15:26:42 +02:00
if (!store_sql_msg())
break;
}
else {
MODIFY X USING
for (;;) {
2004-04-29 00:36:29 +02:00
printf(" Module: ");
if (!gets((char*) module))
2001-05-23 15:26:42 +02:00
break;
2004-04-29 00:36:29 +02:00
printf(" Routine: ");
if (!gets((char*) routine))
2001-05-23 15:26:42 +02:00
break;
2004-04-29 00:36:29 +02:00
printf(" Text: ");
if (!gets((char*) text))
2001-05-23 15:26:42 +02:00
break;
symbol[0] = 0;
/* All JRD messages are public. Only ask if entering messages
* in a component other than JRD */
if (X.FAC_CODE != 0) {
2004-04-29 00:36:29 +02:00
printf("Public [y/n]: ");
gets((char*) pub);
2001-05-23 15:26:42 +02:00
if (*pub == 'Y' || *pub == 'y')
2003-08-29 02:37:25 +02:00
public_msg = true;
2001-05-23 15:26:42 +02:00
else
2003-08-29 02:37:25 +02:00
public_msg = false;
2001-05-23 15:26:42 +02:00
}
else
2003-08-29 02:37:25 +02:00
public_msg = true;
2001-05-23 15:26:42 +02:00
2004-04-29 00:36:29 +02:00
printf(" Symbol: ");
if (!gets((char*) symbol))
2001-05-23 15:26:42 +02:00
break;
if (public_msg) {
2001-05-23 15:26:42 +02:00
if (!symbol[0])
if (!get_symbol(symbol))
break;
if (!get_sql_code(&sql_num))
break;
if (!get_sql_class(sql_class))
/* continue */ ;
if (!get_sql_subclass(sql_sub_class))
/* continue */ ;
STORE S IN SYSTEM_ERRORS USING
S.FAC_CODE = X.FAC_CODE;
S.NUMBER = X.MAX_NUMBER;
S.SQL_CODE = sql_num;
strcpy(S.GDS_SYMBOL, (char*) symbol);
2001-05-23 15:26:42 +02:00
if (sql_class[0]) {
strcpy(S.SQL_CLASS, (char*) sql_class);
2001-05-23 15:26:42 +02:00
S.SQL_CLASS.NULL = FALSE;
}
else
S.SQL_CLASS.NULL = TRUE;
if (sql_sub_class[0]) {
strcpy(S.SQL_SUBCLASS, (char*) sql_sub_class);
2001-05-23 15:26:42 +02:00
S.SQL_SUBCLASS.NULL = FALSE;
}
else
S.SQL_SUBCLASS.NULL = TRUE;
END_STORE;
}
STORE Y IN MESSAGES USING
Y.FAC_CODE = X.FAC_CODE;
Y.NUMBER = X.MAX_NUMBER;
strcpy(Y.MODULE, (char*) module);
strcpy(Y.ROUTINE, (char*) routine);
strcpy(Y.SYMBOL, (char*) symbol);
if (!translate(text, (UCHAR*) Y.TEXT, sizeof(Y.TEXT))) {
2004-04-29 00:36:29 +02:00
printf
2001-05-23 15:26:42 +02:00
("Message too long: max length: %d\n",
sizeof(Y.TEXT));
break;
}
2004-04-29 00:36:29 +02:00
printf("Message number: %d\n", X.MAX_NUMBER);
2001-05-23 15:26:42 +02:00
X.MAX_NUMBER = X.MAX_NUMBER + 1;
END_STORE;
}
END_MODIFY;
}
END_FOR;
if (!count) {
2004-04-29 00:36:29 +02:00
printf("Facilty %s not found\n Known facilities are:\n",
2001-05-23 15:26:42 +02:00
facility);
FOR F IN FACILITIES SORTED BY F.FACILITY
2004-04-29 00:36:29 +02:00
printf(" %s\n", F.FACILITY);
2001-05-23 15:26:42 +02:00
END_FOR;
}
}
COMMIT;
FINISH;
exit(FINI_OK);
}
static void ascii_str_upper( UCHAR * str)
{
/**************************************
*
* a s c i i _ s t r _ u p p e r
*
**************************************
*
* Functional description
* change a string to all upper case
*
**************************************/
while (*str) {
/* subtract 32 if necessary */
if (*str >= LOWER_A && *str <= LOWER_Z)
*str += (UPPER_A - LOWER_A);
str++;
}
}
2003-08-29 02:37:25 +02:00
static bool get_sql_class( UCHAR * sql_class)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* g e t _ s q l _ c l a s s
*
**************************************
*
* Functional description
* get a two character sql_class string
2003-08-29 02:37:25 +02:00
* return true if we get one, otherwise false
2001-05-23 15:26:42 +02:00
*
**************************************/
while (true) {
2004-04-29 00:36:29 +02:00
printf(" SQLCLASS: ");
gets((char*) sql_class);
const SSHORT length = strlen((char*) sql_class);
2001-05-23 15:26:42 +02:00
if (length == 0 || !isalnum(sql_class[0]))
break;
if (length == 2)
2003-08-29 02:37:25 +02:00
return true;
2001-05-23 15:26:42 +02:00
else
2004-04-29 00:36:29 +02:00
fprintf(stderr, "Sqlclass is two characters!\n");
2001-05-23 15:26:42 +02:00
}
2003-08-29 02:37:25 +02:00
return false;
2001-05-23 15:26:42 +02:00
}
2003-08-29 02:37:25 +02:00
static bool get_sql_code( SSHORT * sql_code)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* g e t _ s q l _ c o d e
*
**************************************
*
* Functional description
* prompt for sql_code and convert it to a number
2003-08-29 02:37:25 +02:00
* return true on success, otherwise false
2001-05-23 15:26:42 +02:00
* Issue a warning if the SQL code is not in the SQLERR facility
*
**************************************/
UCHAR nstring[32];
SSHORT sign;
SSHORT sql_num;
SSHORT srch_num;
2003-08-29 02:37:25 +02:00
bool ret = false;
2001-05-23 15:26:42 +02:00
while (true) {
2004-04-29 00:36:29 +02:00
printf(" SQLCODE: ");
if (!gets((char*) nstring))
2001-05-23 15:26:42 +02:00
break;
const UCHAR* p = nstring;
2001-05-23 15:26:42 +02:00
sign = 1;
sql_num = 0;
/* skip spaces */
while (*p && *p == ' ')
p++;
/* Allow for leading sign */
if (*p == '+')
p++;
else if (*p == '-') {
p++;
sign = -1;
}
/* skip spaces again */
while (*p && *p == ' ')
p++;
/* and if anything is left, convert to a number .. */
if (*p && isdigit(*p)) {
sql_num = sign * atoi((char*) p);
2001-05-23 15:26:42 +02:00
*sql_code = sql_num;
2003-08-29 02:37:25 +02:00
ret = true;
2001-05-23 15:26:42 +02:00
break;
}
else {
2004-04-29 00:36:29 +02:00
fprintf(stderr, "SQLCode is now required!\n");
2001-05-23 15:26:42 +02:00
}
}
/* make sure that the SQL code is in the SQLERR facility */
if (ret) {
bool got_it = false;
2001-05-23 15:26:42 +02:00
if (sql_num < 0) {
srch_num = 1000 + sql_num;
FOR M IN MESSAGES WITH M.FAC_CODE = FAC_SQL_NEGATIVE
AND M.NUMBER = srch_num
got_it = true;
2001-05-23 15:26:42 +02:00
END_FOR;
}
else {
srch_num = sql_num;
FOR M IN MESSAGES WITH M.FAC_CODE = FAC_SQL_POSITIVE
AND M.NUMBER = srch_num
got_it = true;
2001-05-23 15:26:42 +02:00
END_FOR;
}
if (!got_it) {
2004-04-29 00:36:29 +02:00
printf("Warning: SQL code %d is not in the SQLERR facility.\n",
2001-05-23 15:26:42 +02:00
sql_num);
2004-04-29 00:36:29 +02:00
printf("You will need to add it there too.\n");
2001-05-23 15:26:42 +02:00
}
}
return ret;
}
2003-08-29 02:37:25 +02:00
static bool get_sql_subclass( UCHAR * sql_sub_class)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* g e t _ s q l _ s u b c l a s s
*
**************************************
*
* Functional description
* get a three character sql_subclass string
2003-08-29 02:37:25 +02:00
* return true if we get one, otherwise false
2001-05-23 15:26:42 +02:00
*
**************************************/
while (true) {
2004-04-29 00:36:29 +02:00
printf(" SQLSUBCLASS: ");
gets((char*) sql_sub_class);
const SSHORT length = strlen((char*) sql_sub_class);
2001-05-23 15:26:42 +02:00
if (length == 0 || !isalnum(sql_sub_class[0]))
break;
if (length == 3)
2003-08-29 02:37:25 +02:00
return true;
2001-05-23 15:26:42 +02:00
else {
2004-04-29 00:36:29 +02:00
fprintf(stderr, "Sqlsubclass is three characters!\n");
2001-05-23 15:26:42 +02:00
continue;
}
}
2003-08-29 02:37:25 +02:00
return false;
2001-05-23 15:26:42 +02:00
}
2003-08-29 02:37:25 +02:00
static bool get_symbol( UCHAR * symbol)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* g e t _ s y m b o l
*
**************************************
*
* Functional description
* insist on getting the symbol
2003-08-29 02:37:25 +02:00
* return true when we get one
* or false if user breaks out
2001-05-23 15:26:42 +02:00
*
**************************************/
2003-08-29 02:37:25 +02:00
while (true) {
2004-04-29 00:36:29 +02:00
fprintf(stderr, "Symbols are required for system errors!\n");
printf(" Symbol: ");
gets((char*) symbol);
if (!strlen((char*) symbol) || !isalnum(symbol[0]))
2003-08-29 02:37:25 +02:00
return false;
2001-05-23 15:26:42 +02:00
else
2003-08-29 02:37:25 +02:00
return true;
2001-05-23 15:26:42 +02:00
}
}
static bool store_sql_msg(void)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* s t o r e _ s q l _ m s g
*
**************************************
*
* Functional description
* sql messages key off the sql code. The
* compound message number works out to
* the offset from 1400.
*
**************************************/
UCHAR text[256], nstring[32];
SSHORT sql_num;
for (;;) {
2004-04-29 00:36:29 +02:00
printf("Enter the sqlcode: ");
if (!gets((char*) nstring))
2001-05-23 15:26:42 +02:00
break;;
sql_num = atoi((char*) nstring);
2004-04-29 00:36:29 +02:00
printf(" Text: ");
if (!gets((char*) text))
2001-05-23 15:26:42 +02:00
break;
STORE Y IN MESSAGES USING
if (sql_num < 0) {
Y.NUMBER = 1000 + sql_num;
Y.FAC_CODE = FAC_SQL_NEGATIVE;
}
else {
Y.NUMBER = sql_num;
Y.FAC_CODE = FAC_SQL_POSITIVE;
}
/* translate escape sequences to single bytes */
if (!translate(text, (UCHAR*) Y.TEXT, sizeof(Y.TEXT))) {
2004-04-29 00:36:29 +02:00
printf("Message too long: max length: %d\n",
2001-05-23 15:26:42 +02:00
sizeof(Y.TEXT));
return false;
2001-05-23 15:26:42 +02:00
}
END_STORE;
}
return true;
2001-05-23 15:26:42 +02:00
}
static bool translate( const UCHAR* source, UCHAR* target, SSHORT length)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* t r a n s l a t e
*
**************************************
*
* Functional description
* make explicit escape sequences into
* ascii, returns length ok?
**************************************/
UCHAR* p = target;
const UCHAR* q = source;
2001-05-23 15:26:42 +02:00
while (*q) {
if (!--length)
return false;
2001-05-23 15:26:42 +02:00
if (*q == '\\') {
*q++;
switch (*q) {
case 'n':
*p++ = '\n';
break;
case 't':
*p++ = '\t';
break;
case 'f':
*p++ = '\f';
break;
case 'a':
*p++ = '\a';
break;
case 'b':
*p++ = '\b';
break;
case 'r':
*p++ = '\r';
break;
case 'v':
*p++ = '\v';
break;
case '\\':
*p++ = '\\';
break;
case '\"':
*p++ = '\"';
break;
case '\'':
*p++ = '\'';
break;
default:
2004-04-29 00:36:29 +02:00
printf
2001-05-23 15:26:42 +02:00
("\n\n*** Escape sequence not understood; being copied unchanged ***\n\n");
*p++ = '\\';
*p++ = *q;
}
*q++;
}
else
*p++ = *q++;
}
*p = 0;
return true;
2001-05-23 15:26:42 +02:00
}