~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/msgs/change_msgs.epp

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      PROGRAM:                Firebird Message file edit program
 
3
 *      MODULE:                 change_msgs.epp
 
4
 *      DESCRIPTION:    Allow limited change of messages in database
 
5
 *
 
6
 * The contents of this file are subject to the Interbase Public
 
7
 * License Version 1.0 (the "License"); you may not use this file
 
8
 * except in compliance with the License. You may obtain a copy
 
9
 * of the License at http://www.Inprise.com/IPL.html
 
10
 *
 
11
 * Software distributed under the License is distributed on an
 
12
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
 
13
 * or implied. See the License for the specific language governing
 
14
 * rights and limitations under the License.
 
15
 *
 
16
 * The Original Code was created by Inprise Corporation
 
17
 * and its predecessors. Portions created by Inprise Corporation are
 
18
 * Copyright (C) Inprise Corporation.
 
19
 *
 
20
 * All Rights Reserved.
 
21
 * Contributor(s): ______________________________________.
 
22
 */
 
23
 
 
24
#include "firebird.h"
 
25
#include <stdio.h>
 
26
#include "../jrd/ibase.h"
 
27
#include "../jrd/common.h"
 
28
 
 
29
#include <stdlib.h>
 
30
 
 
31
#ifdef HAVE_STRING_H
 
32
#include <string.h>
 
33
#endif
 
34
 
 
35
 
 
36
 
 
37
DATABASE DB = "msg.fdb";
 
38
 
 
39
//#define FAC_SQL_POSITIVE      14
 
40
//#define FAC_SQL_NEGATIVE      13
 
41
 
 
42
const char LOWER_A      = 'a';
 
43
const char UPPER_A      = 'A';
 
44
const char LOWER_Z      = 'z';
 
45
const char UPPER_Z      = 'Z';
 
46
 
 
47
static void ascii_str_upper(char*);
 
48
static void explicit_print(const TEXT*);
 
49
static bool get_sql_class(UCHAR *);
 
50
static bool get_sql_subclass(UCHAR *);
 
51
#ifdef NOT_USED_OR_REPLACED
 
52
static bool get_symbol(UCHAR *);
 
53
#endif
 
54
static bool mustget(SCHAR *);
 
55
static bool translate(const SCHAR*, SCHAR*, SSHORT);
 
56
 
 
57
 
 
58
int main( int argc, char **argv)
 
59
{
 
60
/**************************************
 
61
 *
 
62
 *      m a i n
 
63
 *
 
64
 **************************************
 
65
 *
 
66
 * Functional description
 
67
 *      Top level routine.  
 
68
 *
 
69
 **************************************/
 
70
        char facility[20], text[256], module[32], routine[32];
 
71
        UCHAR sql_class[32], sql_sub_class[32];
 
72
        SCHAR input[200], yesno[100];
 
73
        char symbol[30];
 
74
        SCHAR nstring[32];
 
75
        SSHORT count;
 
76
        SSHORT sql_number;
 
77
        SSHORT msg_number;
 
78
 
 
79
        printf("\nHit Ctrl-D (or Ctrl-Z) at prompt to exit level\n");
 
80
        printf
 
81
                ("You will be prompted for facility, module, routine and message text\n");
 
82
        printf
 
83
                ("You *must* enter module and routine names for each message; be prepared\n");
 
84
        printf("You may assign an optional symbol for the message\n");
 
85
        printf
 
86
                ("Escape sequences may be entered and will be translated to single bytes\n");
 
87
 
 
88
        READY;
 
89
        START_TRANSACTION;
 
90
 
 
91
        for (;;) {
 
92
                printf("Facility: ");
 
93
                if (!gets(facility))
 
94
                        break;
 
95
                count = 0;
 
96
                msg_number = 0;
 
97
                ascii_str_upper(facility);
 
98
                FOR X IN FACILITIES WITH X.FACILITY = facility
 
99
                        count++;
 
100
                        for (;;) {
 
101
                                bool sys_error = false;
 
102
 
 
103
                                printf("Message number (%d) ? ", msg_number + 1);
 
104
                                if (!gets(input))
 
105
                                        break;
 
106
                                if (!input[0])
 
107
                                        msg_number++;
 
108
                                else
 
109
                                        msg_number = atoi(input);
 
110
                                if (msg_number <= 0)
 
111
                                        break;
 
112
                                printf("Facility: %s\n", X.FACILITY);
 
113
                                FOR Y IN MESSAGES WITH
 
114
                                        Y.FAC_CODE EQ X.FAC_CODE AND Y.NUMBER EQ msg_number;
 
115
 
 
116
                                        printf(" Message: %d\n", Y.NUMBER);
 
117
                                        printf("  Module: %s\n", Y.MODULE);
 
118
                                        printf(" Routine: %s\n", Y.ROUTINE);
 
119
                                        printf("    Text: ");
 
120
                                        explicit_print(Y.TEXT);
 
121
                                        printf("\n");
 
122
                                        printf("  Symbol: %s\n", Y.SYMBOL);
 
123
                                END_FOR
 
124
 
 
125
                                FOR Z IN SYSTEM_ERRORS WITH X.FAC_CODE EQ Z.FAC_CODE AND
 
126
                                        Z.NUMBER EQ msg_number;
 
127
                                        printf("SQLCODE: %d\n", Z.SQL_CODE);
 
128
                                        printf("   SQL_CLASS:    %s\n", Z.SQL_CLASS);
 
129
                                        printf("SQL_SUBCLASS: %s\n", Z.SQL_SUBCLASS);
 
130
                                        sys_error = true;
 
131
                                END_FOR
 
132
 
 
133
                                printf(" Modify? ");
 
134
                                if (mustget(yesno) && (yesno[0] == 'y' || yesno[0] == 'Y')) {
 
135
                                        module[0] = 0;
 
136
                                        printf(" Module: ");
 
137
                                        if (!gets(module))
 
138
                                                break;
 
139
                                        routine[0] = 0;
 
140
                                        printf("Routine: ");
 
141
                                        if (!gets(routine))
 
142
                                                break;
 
143
                                        text[0] = 0;
 
144
                                        printf("   Text: ");
 
145
                                        if (!gets(text))
 
146
                                                break;
 
147
                                        symbol[0] = 0;
 
148
                                        printf(" Symbol: ");
 
149
                                        if (!gets(symbol))
 
150
                                                break;
 
151
                                        if (sys_error || X.FAC_CODE == 0) {
 
152
                                                printf("SQLCODE: ");
 
153
                                                if (mustget(nstring))
 
154
                                                        sql_number = atoi(nstring);
 
155
                                                if (!get_sql_class(sql_class))
 
156
                                                        /* continue */ ;
 
157
                                                if (!get_sql_subclass(sql_sub_class))
 
158
                                                        /* continue */ ;
 
159
                                        }
 
160
 
 
161
                                        FOR Y IN MESSAGES WITH
 
162
                                                Y.FAC_CODE EQ X.FAC_CODE AND Y.NUMBER EQ msg_number;
 
163
                                                MODIFY Y USING
 
164
                                                        if (module[0])
 
165
                                                                strcpy(Y.MODULE, module);
 
166
                                                        if (routine[0])
 
167
                                                                strcpy(Y.ROUTINE, routine);
 
168
                                                        if (text[0])
 
169
                                                                while (!translate
 
170
                                                                           (text, Y.TEXT, sizeof(Y.TEXT)))
 
171
                                                                {
 
172
                                                                        printf
 
173
                                                                                ("Message too long: max length: %d\n",
 
174
                                                                                 sizeof(Y.TEXT));
 
175
                                                                        mustget(text);
 
176
                                                                }
 
177
                                                        if (symbol[0])
 
178
                                                                strcpy(Y.SYMBOL, symbol);
 
179
                                                END_MODIFY;
 
180
                                        END_FOR;
 
181
 
 
182
                                        FOR Z IN SYSTEM_ERRORS WITH
 
183
                                                Z.FAC_CODE EQ X.FAC_CODE AND Z.NUMBER EQ msg_number;
 
184
                                                MODIFY Z USING
 
185
                                                        if (symbol[0])
 
186
                                                                strcpy(Z.GDS_SYMBOL, symbol);
 
187
                                                        if (sql_number != 0)
 
188
                                                                Z.SQL_CODE = sql_number;
 
189
                                                        if (sql_class[0])
 
190
                                                                strcpy(Z.SQL_CLASS, (char*) sql_class);
 
191
                                                        if (sql_sub_class[0])
 
192
                                                                strcpy(Z.SQL_SUBCLASS, (char*) sql_sub_class);
 
193
                                                END_MODIFY;
 
194
                                        END_FOR;
 
195
                                }
 
196
                        }
 
197
                END_FOR;
 
198
                if (!count) {
 
199
                        printf("Facilty %s not found\n  Known facilities are:\n",
 
200
                                          facility);
 
201
                        FOR F IN FACILITIES SORTED BY F.FACILITY
 
202
                                printf("    %s\n", F.FACILITY);
 
203
                        END_FOR;
 
204
                }
 
205
        }
 
206
 
 
207
        printf("\n\nCommitting changes...");
 
208
        COMMIT;
 
209
        FINISH;
 
210
        printf("done.\n");
 
211
 
 
212
        exit(FINI_OK);
 
213
}
 
214
 
 
215
 
 
216
static void ascii_str_upper( char* str)
 
217
{
 
218
/**************************************
 
219
 *
 
220
 *      a s c i i _ s t r _ u p p e r
 
221
 *
 
222
 **************************************
 
223
 *
 
224
 * Functional description
 
225
 *      change a string to all upper case
 
226
 *
 
227
 **************************************/
 
228
 
 
229
        while (*str) {
 
230
                /* subtract 32 if necessary */
 
231
 
 
232
                if (*str >= LOWER_A && *str <= LOWER_Z)
 
233
                        *str += (UPPER_A - LOWER_A);
 
234
                str++;
 
235
        }
 
236
}
 
237
 
 
238
 
 
239
static void explicit_print( const TEXT* string)
 
240
{
 
241
/**************************************
 
242
 *
 
243
 *      e x p l i c i t _ p r i n t
 
244
 *
 
245
 **************************************
 
246
 *
 
247
 * Functional description
 
248
 *      Let it all hang out: print line
 
249
 *      with explicit \n \b \t \f etc.
 
250
 *      to make changing messages easy
 
251
 *
 
252
 **************************************/
 
253
        const TEXT* p = string;
 
254
 
 
255
        while (*p) {
 
256
                switch (*p) {
 
257
                case '\n':
 
258
                        putchar('\\');
 
259
                        putchar('n');
 
260
                        break;
 
261
                case '\t':
 
262
                        putchar('\\');
 
263
                        putchar('t');
 
264
                        break;
 
265
                case '\f':
 
266
                        putchar('\\');
 
267
                        putchar('f');
 
268
                        break;
 
269
                case '\b':
 
270
                        putchar('\\');
 
271
                        putchar('b');
 
272
                        break;
 
273
                case '\r':
 
274
                        putchar('\\');
 
275
                        putchar('r');
 
276
                        break;
 
277
                case '\v':
 
278
                        putchar('\\');
 
279
                        break;
 
280
                case '\\':
 
281
                        putchar('\\');
 
282
                        putchar('\\');
 
283
                        break;
 
284
                case '\"':
 
285
                        putchar('\\');
 
286
                        putchar('\"');
 
287
                        break;
 
288
                case '\'':
 
289
                        putchar('\\');
 
290
                        putchar('\'');
 
291
                        break;
 
292
                default:
 
293
                        putchar(*p);
 
294
                }
 
295
                *p++;
 
296
        }
 
297
}
 
298
 
 
299
 
 
300
static bool get_sql_class( UCHAR * sql_class)
 
301
{
 
302
/**************************************
 
303
 *
 
304
 *      g e t _ s q l _ c l a s s
 
305
 *
 
306
 **************************************
 
307
 *
 
308
 * Functional description
 
309
 *      get a two character sql_class string
 
310
 *      return true if we get one, otherwise false
 
311
 *
 
312
 **************************************/
 
313
        while (true) {
 
314
                printf("   SQLCLASS: ");
 
315
                gets((char*) sql_class);
 
316
                const SSHORT length = strlen((char*) sql_class);
 
317
                if (!length)
 
318
                        break;
 
319
 
 
320
                if (length == 2)
 
321
                        return true;
 
322
                else
 
323
                        fprintf(stderr, "Sqlclass is two characters!\n");
 
324
        }
 
325
 
 
326
        return false;
 
327
}
 
328
 
 
329
 
 
330
static bool get_sql_subclass( UCHAR * sql_sub_class)
 
331
{
 
332
/**************************************
 
333
 *
 
334
 *      g e t _ s q l _ s u b c l a s s
 
335
 *
 
336
 **************************************
 
337
 *
 
338
 * Functional description
 
339
 *      get a three character sql_subclass string
 
340
 *      return true if we get one, otherwise false
 
341
 *
 
342
 **************************************/
 
343
        while (true) {
 
344
                printf("SQLSUBCLASS: ");
 
345
                gets((char*) sql_sub_class);
 
346
                const SSHORT length = strlen((char*) sql_sub_class);
 
347
                if (!length)
 
348
                        break;
 
349
 
 
350
                if (length == 3)
 
351
                        return true;
 
352
                else
 
353
                        fprintf(stderr, "Sqlsubclass is three characters!\n");
 
354
        }
 
355
        return false;
 
356
}
 
357
 
 
358
#ifdef NOT_USED_OR_REPLACED
 
359
static bool get_symbol( UCHAR * symbol)
 
360
{
 
361
/**************************************
 
362
 *
 
363
 *      g e t _ s y m b o l
 
364
 *
 
365
 **************************************
 
366
 *
 
367
 * Functional description
 
368
 *      insist on getting the symbol
 
369
 *      return true when we get one
 
370
 *
 
371
 **************************************/
 
372
        while (true) {
 
373
                fprintf(stderr, "Symbols are required for system errors!\n");
 
374
                printf(" Symbol: ");
 
375
                gets((char*) symbol);
 
376
                if (strlen((char*) symbol))
 
377
                        return true;
 
378
        }
 
379
}
 
380
#endif
 
381
 
 
382
static bool mustget( SCHAR * s)
 
383
{
 
384
/**************************************
 
385
 *
 
386
 *      m u s t g e t
 
387
 *
 
388
 **************************************
 
389
 *
 
390
 * Functional description
 
391
 *      gets & returns a string.  Returns false
 
392
 *      if string is empty.
 
393
 *
 
394
 **************************************/
 
395
 
 
396
        if (!gets((char*) s))
 
397
                return false;
 
398
 
 
399
        return (s[0] != 0);
 
400
}
 
401
 
 
402
 
 
403
static bool translate( const SCHAR* source, SCHAR* target, SSHORT length)
 
404
{
 
405
/**************************************
 
406
 *
 
407
 *      t r a n s l a t e
 
408
 *
 
409
 **************************************
 
410
 *
 
411
 * Functional description
 
412
 *      make explicit escape sequences into
 
413
 *      ascii, returns length ok?
 
414
 *
 
415
 **************************************/
 
416
        SCHAR* p = target;
 
417
        const SCHAR* q = source;
 
418
 
 
419
        while (*q) {
 
420
                if (!--length)
 
421
                        return false;
 
422
                if (*q == '\\') {
 
423
                        *q++;
 
424
                        switch (*q) {
 
425
                        case 'n':
 
426
                                *p++ = '\n';
 
427
                                break;
 
428
                        case 't':
 
429
                                *p++ = '\t';
 
430
                                break;
 
431
                        case 'f':
 
432
                                *p++ = '\f';
 
433
                                break;
 
434
                        case 'a':
 
435
                                *p++ = '\a';
 
436
                                break;
 
437
                        case 'b':
 
438
                                *p++ = '\b';
 
439
                                break;
 
440
                        case 'r':
 
441
                                *p++ = '\r';
 
442
                                break;
 
443
                        case 'v':
 
444
                                *p++ = '\v';
 
445
                                break;
 
446
                        case '\\':
 
447
                                *p++ = '\\';
 
448
                                break;
 
449
                        case '\"':
 
450
                                *p++ = '\"';
 
451
                                break;
 
452
                        case '\'':
 
453
                                *p++ = '\'';
 
454
                                break;
 
455
                        default:
 
456
                                printf
 
457
                                        ("\n\n*** Escape sequence not understood; being copied unchanged ***\n\n");
 
458
                                *p++ = '\\';
 
459
                                *p++ = *q;
 
460
                        }
 
461
                        *q++;
 
462
                }
 
463
                else
 
464
                        *p++ = *q++;
 
465
        }
 
466
        *p = 0;
 
467
 
 
468
        return true;
 
469
}
 
470