2
* @OPENGROUP_COPYRIGHT@
4
* Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
5
* Copyright (c) 1996, 1997, 1998, 1999, 2000 The Open Group
6
* ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
7
* the full copyright text.
9
* This software is subject to an open license. It may only be
10
* used on, with or for operating systems which are themselves open
11
* source systems. You must contact The Open Group for a license
12
* allowing distribution and sublicensing of this software on, with,
13
* or for operating systems which are not Open Source programs.
15
* See http://www.opengroup.org/openmotif/license for full
16
* details of the license agreement. Any use, reproduction, or
17
* distribution of the program constitutes recipient's acceptance of
20
* EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
21
* PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
* KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
23
* WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
24
* OR FITNESS FOR A PARTICULAR PURPOSE
26
* EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
27
* NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT,
28
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED
30
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
* ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
33
* EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
34
* POSSIBILITY OF SUCH DAMAGES.
41
static char rcsid[] = "$TOG: wmldbcreate.c /main/8 1997/04/14 12:55:30 dbl $"
51
* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
54
* This is the program creates binary databases from WML output.
59
#ifndef X_NOT_STDC_ENV
63
#include <Mrm/MrmWidget.h>
65
#include <Xm/MwmUtil.h>
67
#include <Dt/Editor.h>
69
#include <Dt/HelpDialog.h>
70
#include <Dt/HelpQuickD.h>
71
#include <Dt/MenuButton.h>
73
#include <Dt/TermPrim.h>
79
* User supplied widget public.h and/or private.h files are to be added here
80
* #ifdef for automatic use in uilwmdcreate script file
85
* End of User supplied widget files
90
#include "UilLexPars.h"
92
#include "UilSymGen.h" /* from WML */
93
#include "UilSymArTy.h" /* from WML */
94
#include "UilSymRArg.h" /* from WML */
95
#include "UilSymArTa.h" /* from WML */
96
#include "UilSymReas.h" /* from WML */
97
#include "UilSymCtl.h" /* from WML */
98
#include "UilConst.h" /* from WML */
99
#include "UilSymNam.h" /* from WML */
100
#include "UilSymEnum.h" /* from WML */
101
#include "UilSymCSet.h" /* from WML */
102
#include "UilUrmClas.h" /* from WML */
103
#include "UilKeyTab.h" /* from WML */
104
#include "UilSymChCl.h" /* from WML */
105
#include "UilSymChTa.h" /* from WML */
108
void emit_header(_db_header_ptr header);
109
void emit_chars(int table_id);
110
void emit_ints_and_string( int table_id);
111
void emit_char_table( int table_id);
112
void emit_length_and_string( int table_id);
113
void emit_shorts( int table_id);
114
void emit_int_and_table_shorts( int table_id);
115
void emit_ints( int table_id);
119
char outfilename[80];
120
char debugfilename[80];
128
strcpy(outfilename, "motif.wmd");
129
strcpy(debugfilename, "motif.dbg");
131
for (argc--, argv++; argc; argc--, argv++)
133
if (strcmp("-debug", *argv) == 0)
137
else if ((strcmp("-o", *argv) == 0))
139
strcpy(outfilename, argv[1]);
143
bfile = fopen(outfilename, "w");
144
if (bfile == (FILE *) NULL)
146
printf("\nCouldnt't open %s", outfilename);
151
afile = fopen(debugfilename, "w");
152
if (afile == (FILE *) NULL)
154
printf("\nCouldn't open %s", debugfilename);
164
* UilSymCset - parts of it
167
emit_chars(Constraint_Tab);
168
emit_chars(Argument_Type_Table_Value);
169
emit_chars(Charset_Wrdirection_Table);
170
emit_chars(Charset_Parsdirection_Table);
171
emit_chars(Charset_Charsize_Table);
172
emit_chars(Child_Class_Table);
176
emit_ints_and_string (Key_Table);
177
emit_ints_and_string (Key_Table_Case_Ins);
184
emit_char_table (Allowed_Argument_Table);
185
emit_char_table (Allowed_Control_Table);
186
emit_char_table (Allowed_Reason_Table);
187
emit_char_table (Allowed_Child_Table);
193
emit_length_and_string (Charset_Xmstring_Names_Table);
194
emit_length_and_string (Charset_Lang_Names_Table);
195
emit_length_and_string (Uil_Widget_Names);
196
emit_length_and_string (Uil_Argument_Names);
197
emit_length_and_string (Uil_Reason_Names);
198
emit_length_and_string (Uil_Enumval_names);
199
emit_length_and_string (Uil_Charset_Names);
200
emit_length_and_string (Uil_Widget_Funcs);
201
emit_length_and_string (Uil_Argument_Toolkit_Names);
202
emit_length_and_string (Uil_Reason_Toolkit_Names);
203
emit_length_and_string (Uil_Children_Names);
210
emit_shorts (Charset_Lang_Codes_Table);
211
emit_shorts (Argument_Enum_Set_Table);
212
emit_shorts (Related_Argument_Table);
213
emit_shorts (Uil_Gadget_Funcs);
214
emit_shorts (Uil_Urm_Nondialog_Class);
215
emit_shorts (Uil_Urm_Subtree_Resource);
219
emit_int_and_table_shorts(Enum_Set_Table);
223
emit_ints (Enumval_Values_Table);
227
return 0; /* make compiler happy */
235
globals.version = DB_Compiled_Version;
236
globals.uil_max_arg = uil_max_arg;
237
globals.uil_max_charset = uil_max_charset;
238
globals.charset_lang_table_max = charset_lang_table_max;
239
globals.uil_max_object = uil_max_object;
240
globals.uil_max_reason = uil_max_reason;
241
globals.uil_max_enumval = uil_max_enumval;
242
globals.uil_max_enumset = uil_max_enumset;
243
globals.key_k_keyword_count = key_k_keyword_count;
244
globals.key_k_keyword_max_length = key_k_keyword_max_length;
245
globals.uil_max_child = uil_max_child;
247
fwrite (&globals, sizeof (_db_globals), 1, bfile);
249
fprintf(afile, "%d %d %d %d %d %d %d %d %d %d ", globals.version,
250
globals.uil_max_arg, globals.uil_max_charset,
251
globals.charset_lang_table_max, globals.uil_max_object,
252
globals.uil_max_reason, globals.uil_max_enumval,
253
globals.uil_max_enumset, globals.key_k_keyword_count,
254
globals.key_k_keyword_max_length);
259
void emit_header(header)
260
_db_header_ptr header;
263
fwrite (header, sizeof(_db_header), 1, bfile);
266
"\n\nTableId=%d, NumEntries=%d, TableSize=%d \n",
267
header->table_id, header->num_items, header->table_size);
272
void emit_chars(table_id)
283
* NOTE: The first entry is not used but we copy it anyway
285
header.table_size = sizeof(constraint_tab_vec);
286
header.num_items = header.table_size;
287
header.table_id = Constraint_Tab;
288
ptr = constraint_tab;
290
case Argument_Type_Table_Value:
292
* NOTE: The first entry is not used but we copy it anyway
294
header.table_size = sizeof(argument_type_table_vec);
295
header.num_items = header.table_size;
296
header.table_id = Argument_Type_Table_Value;
297
ptr = argument_type_table;
299
case Charset_Wrdirection_Table:
301
* NOTE: The first entry is not used but we copy it anyway
303
header.table_size = sizeof(charset_wrdirection_table_vec);
304
header.num_items = header.table_size;
305
header.table_id = Charset_Wrdirection_Table;
306
ptr = charset_writing_direction_table;
308
case Charset_Parsdirection_Table:
310
* NOTE: The first entry is not used but we copy it anyway
312
header.table_size = sizeof(charset_parsdirection_table_vec);
313
header.num_items = header.table_size;
314
header.table_id = Charset_Parsdirection_Table;
315
ptr = charset_parsing_direction_table;
317
case Charset_Charsize_Table:
319
* NOTE: The first entry is not used but we copy it anyway
321
header.table_size = sizeof(charset_charsize_table_vec);
322
header.num_items = header.table_size;
323
header.table_id = Charset_Charsize_Table;
324
ptr = charset_character_size_table;
326
case Child_Class_Table:
328
* NOTE: The first entry is not used but we copy it anyway
330
header.table_size = sizeof(child_class_table_vec);
331
header.num_items = header.table_size;
332
header.table_id = Child_Class_Table;
333
ptr = child_class_table;
337
emit_header(&header);
339
fwrite (ptr, header.table_size, 1, bfile);
342
for (i=0; i<=header.num_items; i++)
344
fprintf(afile, "%d ", ptr[i]);
350
void emit_ints_and_string(table_id)
354
key_keytable_entry_type *table;
360
* All tables are zero based unless otherwise noted
363
header.table_size = sizeof(key_table_vec);
364
header.num_items = key_k_keyword_count;
365
header.table_id = Key_Table;
368
case Key_Table_Case_Ins:
369
header.table_size = sizeof(key_table_case_ins_vec);
370
header.num_items = key_k_keyword_count;
371
header.table_id = Key_Table_Case_Ins;
372
table = key_table_case_ins;
375
emit_header(&header);
377
fwrite (table, header.table_size, 1, bfile);
378
for (i=0; i<header.num_items; i++)
380
fwrite (table[i].at_name, table[i].b_length + 1, 1, bfile);
382
fprintf (afile, "%d %d %d %d %s", table[i].b_class, table[i].b_subclass,
383
table[i].b_length, table[i].b_token, table[i].at_name);
389
void emit_char_table(table_id)
392
unsigned char **table;
394
unsigned char *entry_vec;
396
int num_bits = (uil_max_object + 7) / 8;
401
* All tables are 1 based unless otherwise specified
403
case Allowed_Argument_Table:
404
header.table_size = sizeof(allowed_argument_table_vec);
405
header.num_items = uil_max_arg;
406
header.table_id = Allowed_Argument_Table;
407
table = allowed_argument_table;
409
case Allowed_Control_Table:
410
header.table_size = sizeof(allowed_control_table_vec);
411
header.num_items = uil_max_object;
412
header.table_id = Allowed_Control_Table;
413
table = allowed_control_table;
415
case Allowed_Reason_Table:
416
header.table_size = sizeof(allowed_reason_table_vec);
417
header.num_items = uil_max_reason;
418
header.table_id = Allowed_Reason_Table;
419
table = allowed_reason_table;
421
case Allowed_Child_Table:
422
header.table_size = sizeof(allowed_child_table_vec);
423
header.num_items = uil_max_child;
424
header.table_id = Allowed_Child_Table;
425
table = allowed_child_table;
429
emit_header(&header);
431
for (i=1; i<=header.num_items; i++) /* First not used */
433
entry_vec = table[i];
434
fwrite (entry_vec, sizeof (char) * num_bits, 1, bfile);
437
for (j=0; j<num_bits; j++)
439
fprintf (afile, "%d, ", entry_vec[j]);
441
fprintf (afile, "\n");
447
void emit_length_and_string(table_id)
459
* all the tables are 1 based unless otherwise documented
461
case Charset_Xmstring_Names_Table:
462
header.table_size = sizeof(charset_xmstring_names_table_vec);
463
header.num_items = uil_max_charset;
464
header.table_id = Charset_Xmstring_Names_Table;
465
table = charset_xmstring_names_table;
467
case Charset_Lang_Names_Table:
469
* This table is 0 based
471
header.table_size = sizeof(charset_lang_names_table_vec);
472
header.num_items = charset_lang_table_max - 1;
473
header.table_id = Charset_Lang_Names_Table;
474
table = charset_lang_names_table;
476
case Uil_Widget_Names:
477
header.table_size = sizeof(uil_widget_names_vec);
478
header.num_items = uil_max_object;
479
header.table_id = Uil_Widget_Names;
480
table = uil_widget_names ;
482
case Uil_Argument_Names:
483
header.table_size = sizeof(uil_argument_names_vec);
484
header.num_items = uil_max_arg;
485
header.table_id = Uil_Argument_Names;
486
table = uil_argument_names;
488
case Uil_Reason_Names:
489
header.table_size = sizeof(uil_reason_names_vec);
490
header.num_items = uil_max_reason;
491
header.table_id = Uil_Reason_Names;
492
table = uil_reason_names;
494
case Uil_Enumval_names:
495
header.table_size = sizeof(uil_enumval_names_vec);
496
header.num_items = uil_max_enumval;
497
header.table_id = Uil_Enumval_names;
498
table = uil_enumval_names;
500
case Uil_Charset_Names:
501
header.table_size = sizeof(uil_charset_names_vec);
502
header.num_items = uil_max_charset;
503
header.table_id = Uil_Charset_Names;
504
table = uil_charset_names;
506
case Uil_Widget_Funcs:
507
header.table_size = sizeof(uil_widget_funcs_vec);
508
header.num_items = uil_max_object;
509
header.table_id = Uil_Widget_Funcs;
510
table = uil_widget_funcs;
512
case Uil_Argument_Toolkit_Names:
513
header.table_size = sizeof(uil_argument_toolkit_names_vec);
514
header.num_items = uil_max_arg;
515
header.table_id = Uil_Argument_Toolkit_Names;
516
table = uil_argument_toolkit_names;
518
case Uil_Reason_Toolkit_Names:
519
header.table_size = sizeof(uil_reason_toolkit_names_vec);
520
header.num_items = uil_max_reason;
521
header.table_id = Uil_Reason_Toolkit_Names;
522
table = uil_reason_toolkit_names;
524
case Uil_Children_Names:
525
header.table_size = sizeof(uil_child_names_vec);
526
header.num_items = uil_max_child;
527
header.table_id = Uil_Children_Names;
528
table = uil_child_names ;
532
emit_header(&header);
534
lengths = (int *) malloc (sizeof (int) * (header.num_items + 1));
536
for (i=0; i<=header.num_items; i++)
538
if (table[i] != NULL)
541
* Add one to the length for the null terminator
543
lengths[i] = strlen(table[i]) + 1;
550
fprintf (afile, "%d ", lengths[i]);
552
fwrite (lengths, sizeof (int) * (header.num_items + 1), 1, bfile);
553
for (i=0; i<=header.num_items; i++)
558
* assumed lengths[i] = lengths[i] * sizeof(char)
559
* Add one for the null terminator
561
fwrite (table[i], lengths[i] + 1, 1, bfile);
563
fprintf (afile, "%s ", table[i]);
570
void emit_shorts(table_id)
574
unsigned short int *ptr;
580
* All tables are 1 based unless otherwise noted
582
case Charset_Lang_Codes_Table:
586
header.table_size = sizeof(charset_lang_codes_table_vec);
587
header.num_items = charset_lang_table_max - 1;
588
header.table_id = Charset_Lang_Codes_Table;
589
ptr = charset_lang_codes_table;
591
case Argument_Enum_Set_Table:
592
header.table_size = sizeof(argument_enumset_table_vec);
593
header.num_items = uil_max_arg;
594
header.table_id = Argument_Enum_Set_Table;
595
ptr = argument_enumset_table;
597
case Related_Argument_Table:
598
header.table_size = sizeof(related_argument_table_vec);
599
header.num_items = uil_max_arg;
600
header.table_id = Related_Argument_Table;
601
ptr = related_argument_table;
603
case Uil_Gadget_Funcs:
604
header.table_size = sizeof(uil_gadget_variants_vec);
605
header.num_items = uil_max_object;
606
header.table_id = Uil_Gadget_Funcs;
607
ptr = uil_gadget_variants;
609
case Uil_Urm_Nondialog_Class:
610
header.table_size = sizeof(uil_urm_nondialog_class_vec);
611
header.num_items = uil_max_object;
612
header.table_id = Uil_Urm_Nondialog_Class;
613
ptr = uil_urm_nondialog_class;
615
case Uil_Urm_Subtree_Resource:
616
header.table_size = sizeof(uil_urm_subtree_resource_vec);
617
header.num_items = uil_max_object;
618
header.table_id = Uil_Urm_Subtree_Resource;
619
ptr = uil_urm_subtree_resource;
623
emit_header(&header);
625
fwrite (ptr, header.table_size, 1, bfile);
628
for (i=0; i<header.num_items; i++)
630
fprintf(afile, "%d ", ptr[i]);
636
void emit_int_and_table_shorts(table_id)
640
UilEnumSetDescDef *table;
642
unsigned short int *value_vec;
647
* All tables are 1 based unless otherwise noted
650
header.table_size = sizeof(enum_set_table_vec);
651
header.num_items = uil_max_enumset;
652
header.table_id = Enum_Set_Table;
653
table = enum_set_table;
657
emit_header(&header);
658
fwrite (table, header.table_size, 1, bfile);
659
for (i=0; i<=header.num_items; i++) /* first is not used */
661
if (table[i].values_cnt)
663
fwrite (table[i].values, sizeof (short) * table[i].values_cnt, 1, bfile);
669
void emit_ints(table_id)
678
* all tables are 1 based unless otherwise noted
681
case Enumval_Values_Table:
682
header.table_size = sizeof(enumval_values_table_vec);
683
header.num_items = uil_max_enumval;
684
header.table_id = Enumval_Values_Table;
685
ptr = enumval_values_table;
689
emit_header(&header);
691
fwrite (ptr, header.table_size, 1, bfile);
694
for (i=0; i<header.num_items; i++)
696
fprintf(afile, "%d ", ptr[i]);