Debian Codegraph @

src/intl/utils/dtest.c

raw
1 /*
2 * Test tool for Language Drivers.
3 *
4 * This tool loads up a language driver using the dynamic link
5 * (or shared object) method and interrogates it's ID function.
6 * This tool is used to quickly verify the dynamic load ability
7 * of a newly created language driver.
8 * The contents of this file are subject to the Interbase Public
9 * License Version 1.0 (the "License"); you may not use this file
10 * except in compliance with the License. You may obtain a copy
11 * of the License at http://www.Inprise.com/IPL.html
12 *
13 * Software distributed under the License is distributed on an
14 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
15 * or implied. See the License for the specific language governing
16 * rights and limitations under the License.
17 *
18 * The Original Code was created by Inprise Corporation
19 * and its predecessors. Portions created by Inprise Corporation are
20 * Copyright (C) Inprise Corporation.
21 *
22 * All Rights Reserved.
23 * Contributor(s): ______________________________________.
24 */
25
26 /* define LIKE_JRD to have the lookup follow exactly the syntax
27 * used by intl.c in JRD.
28 * Set the static full_debug to 1 to turn on printf debugging.
29 *
30 * 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete "Apollo" port
31 *
32 */
33
34 #include "firebird.h"
35 #include <stdio.h>
36 #define DEBUG
37
38 static int full_debug = 0;
39 #define FULL_DEBUG if (full_debug) printf
40
41
42
43 typedef unsigned short SHORT;
44
45 #include "../jrd/intl.h"
46
47 /* Following defines are duplicates of those in intl.c */
48 /* Name of module that implements text-type (n) */
49
50 #ifndef INTL_MODULE
51 #define INTL_MODULE "IBLD_%03d"
52 #endif
53
54 #ifndef INTL_INIT_ENTRY
55 #define INTL_INIT_ENTRY "ld_init"
56 #endif
57
58
59 void try_fc(char* c, FPTR_INT f)
60 {
61 unsigned char buffer[200];
62 const int res = (*f) (strlen(c), c, sizeof(buffer), buffer);
63 printf("%s => ", c);
64 for (int i = 0; i < res; i++)
65 printf("%d ", buffer[i]);
66 printf("\n");
67 }
68
69 int main(int argc, char** argv)
70 {
71 char buffer[200];
72 struct texttype this_textobj;
73
74 if (argc <= 1)
75 {
76 printf("usage: dtest Intl_module_name\n");
77 return (1);
78 }
79 char** vector = argv;
80
81 FPTR_INT func = 0;
82
83 for (int i = 1; i < argc; i++)
84 {
85
86 #ifdef LIKE_JRD
87 {
88 char module[200];
89 Firebird::PathName path;
90 char entry[200];
91 const int t_type = atoi(vector[i]);
92 sprintf(module, INTL_MODULE, t_type);
93 path = fb_utils::getPrefix(Firebird::IConfigManager::FB_DIR_LIB, module);
94 sprintf(entry, INTL_INIT_ENTRY, t_type);
95 printf("path=%s entry=%s\n", path.c_str(), entry);
96 func = (FPTR_INT) ISC_lookup_entrypoint(path.c_str(), entry, NULL);
97 }
98 #else
99 if (strcmp(vector[i], "ask") == 0)
100 {
101 gets(buffer);
102 func = (FPTR_INT) ISC_lookup_entrypoint(buffer, "ld_init", NULL);
103 }
104 else
105 func = (FPTR_INT) ISC_lookup_entrypoint(vector[i], "ld_init", NULL);
106 #endif
107 if (func == NULL)
108 printf("Cannot find %s.init\n", vector[i]);
109 else
110 {
111 FULL_DEBUG("This testobj %ld\n", &this_textobj);
112 FULL_DEBUG("size of %d\n", sizeof(this_textobj));
113 if ((*func) (99, &this_textobj) != 99)
114 printf("%s.Init returned bad result\n", vector[i]);
115 else
116 {
117 FULL_DEBUG("Called init ok\n");
118 FULL_DEBUG("ld_init is %ld %ld\n",
119 this_textobj.
120 texttype_functions[(int) intl_fn_init], func);
121 func = this_textobj.texttype_functions[intl_fn_NULL];
122 FULL_DEBUG("ld_id is %ld %ld\n",
123 this_textobj.
124 texttype_functions[(int) intl_fn_NULL], func);
125 if (func == NULL)
126 printf("%s.Init OK can't find ID\n", vector[i]);
127 else
128 {
129 FULL_DEBUG("About to call ID fn\n");
130 (*func) (sizeof(buffer), buffer);
131 FULL_DEBUG("Back from ID fn \n");
132 printf("%s.id => %s\n", vector[i], buffer);
133 }
134
135 func = this_textobj.texttype_functions[intl_fn_string_to_key];
136
137 FULL_DEBUG("ld_to_key is %ld\n", func);
138 if (func == NULL)
139 printf("%s: Can't find str_to_key\n", vector[i]);
140 else
141 {
142 try_fc("cote", func);
143 try_fc("COTE", func);
144 try_fc("co-te", func);
145 try_fc("CO-TE", func);
146 }
147 }
148 }
149 }
150 return (0);
151 }
152