8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 22:43:04 +01:00
firebird-mirror/src/msgs/modify_msgs.epp

202 lines
4.0 KiB
Plaintext
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: Firebird Message file modify for escape chars
* MODULE: modify_messages.epp
2001-05-23 15:26:42 +02:00
* DESCRIPTION: Allow modification of messages with translatation of escape sequences
*
* 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>
2003-11-08 17:40:17 +01:00
#include "../jrd/ibase.h"
2001-05-23 15:26:42 +02:00
#include "../jrd/common.h"
#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 explicit_print(const TEXT*);
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
2008-12-18 02:31:26 +01:00
* Top level routine.
2001-05-23 15:26:42 +02:00
*
**************************************/
2002-12-10 12:53:53 +01:00
SCHAR facility[20], newtext[256];
2001-05-23 15:26:42 +02:00
SCHAR innumber[4];
SSHORT number;
2004-04-29 00:36:29 +02:00
printf("\nHit Ctrl-D (or Ctrl-Z) at prompt to exit level\n");
printf("You will be prompted for fac_code and message number\n");
printf("Escape sequences will be translated to single bytes\n");
2001-05-23 15:26:42 +02:00
READY;
START_TRANSACTION;
for (;;) {
2004-04-29 00:36:29 +02:00
printf("Facility: ");
if (!gets(facility))
2001-05-23 15:26:42 +02:00
break;
FOR Y IN FACILITIES WITH Y.FACILITY CONTAINING facility
2004-04-29 00:36:29 +02:00
printf("Message number: ");
if (!gets(innumber))
2001-05-23 15:26:42 +02:00
break;
number = atoi(innumber);
FOR X IN MESSAGES WITH X.FAC_CODE = Y.FAC_CODE AND X.NUMBER = number
2004-04-29 00:36:29 +02:00
printf(" Current text:");
2001-05-23 15:26:42 +02:00
explicit_print(X.TEXT);
2004-04-29 00:36:29 +02:00
printf("\n New text: ");
if (!gets(newtext))
2001-05-23 15:26:42 +02:00
break;
MODIFY X USING
SCHAR* p = X.TEXT;
const SCHAR* q = newtext;
2001-05-23 15:26:42 +02:00
/* translate scape sequences to single bytes */
while (*q) {
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;
break;
}
*q++;
}
else
*p++ = *q++;
}
*p = 0;
END_MODIFY;
END_FOR;
END_FOR;
}
COMMIT;
FINISH;
exit(FINI_OK);
}
static void explicit_print( const TEXT* string)
2001-05-23 15:26:42 +02:00
{
/**************************************
*
* e x p l i c i t _ p r i n t
*
**************************************
*
* Functional description
* Let it all hang out: print line
* with explicit \n \b \t \f etc.
* to make changing messages easy
*
**************************************/
const TEXT* p = string;
2001-05-23 15:26:42 +02:00
while (*p) {
switch (*p) {
case '\n':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('n');
2001-05-23 15:26:42 +02:00
break;
case '\t':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('t');
2001-05-23 15:26:42 +02:00
break;
case '\f':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('f');
2001-05-23 15:26:42 +02:00
break;
case '\b':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('b');
2001-05-23 15:26:42 +02:00
break;
case '\r':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('r');
2001-05-23 15:26:42 +02:00
break;
case '\v':
2004-04-29 00:36:29 +02:00
putchar('\\');
2001-05-23 15:26:42 +02:00
break;
case '\\':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('\\');
2001-05-23 15:26:42 +02:00
break;
case '\"':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('\"');
2001-05-23 15:26:42 +02:00
break;
case '\'':
2004-04-29 00:36:29 +02:00
putchar('\\');
putchar('\'');
2001-05-23 15:26:42 +02:00
break;
default:
2004-04-29 00:36:29 +02:00
putchar(*p);
2001-05-23 15:26:42 +02:00
}
*p++;
}
}