2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
25 * $XConsortium: abmf.c /main/6 1996/11/21 12:31:02 mustafa $
27 * @(#)abmf.c 3.53 16 Feb 1994 cde_app_builder/src/abmf
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special restrictions in a
32 * confidential disclosure agreement between HP, IBM, Sun, USL, SCO and
33 * Univel. Do not distribute this document outside HP, IBM, Sun, USL, SCO,
34 * or Univel without Sun's specific written approval. This document and all
35 * copies and derivative works thereof must be returned or destroyed at Sun's
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
47 #include <sys/times.h>
52 #include <ab_private/util.h>
53 #include <ab_private/obj.h>
54 #include <ab_private/objxm.h>
55 #include <ab_private/bil.h>
56 #include "dtb_utils.h"
57 #include "write_codeP.h"
58 #include "motifdefsP.h"
60 #include "lib_func_stringsP.h"
61 #include "instancesP.h"
62 #include "ui_header_fileP.h"
69 extern long _sysconf(int name); /* CLK_TCK uses this */
76 ABMF_PROFILE_UNDEF = 0,
79 ABMF_PROFILE_TRAVERSALS,
80 ABMF_PROFILE_WHAT_NUM_VALUES
87 ABMF_PROFILE_WHAT debug_profile_what;
88 ABMF_CGEN_RESTRICTION cgen_restriction;
93 BOOL show_all_windows;
94 BOOL show_all_windows_set;
99 BOOL use_default_project;
101 BOOL write_all_resources;
102 BOOL write_i18n_resources;
103 } CmdlineArgsRec, *CmdlineArgs;
105 BOOL freshenUnchangedFiles = TRUE;
110 static int abmf_init(void);
111 static int abmf_usage(void);
112 static int parse_args(int argc, char *argv[], CmdlineArgs args);
113 static int find_proj_file(CmdlineArgs args);
114 static int mark_modules_to_load_and_write(
121 static int load_marked_modules(ABObj project);
122 static int load_module(ABObj module);
123 static BOOL write_required(ABObj tree);
124 static int examine_tree(ABObj project);
125 static int munge_ensure_win_parent(ABObj win);
126 static int munge_liberate_menu(ABObj menu);
127 static int dup_all_menu_refs(ABObj project);
128 static int abmfP_dup_menu_ref_tree(ABObj obj);
129 static int abmfP_do_dup_menu_ref_tree(ABObj obj);
130 static int dump_tree(ABObj tree);
131 static int print_tree(ABObj root, int indent);
132 static int abmfP_prepare_tree(ABObj project);
133 static int abmfP_create_obj_data_for_project(ABObj project);
134 static int abmfP_create_obj_data_for_module(ABObj objInModule);
135 static int ensure_data_for_module_obj(ABObj module);
136 static BOOL proj_file_has_modules(
140 static int replace_string_shorter(
152 static int dump_callbacks(ABObj project);
153 static int debug_verify_tree(ABObj root);
156 #ifdef DEBUG /* performance testing */
157 static int time_traversal(ABObj root);
158 static int get_cur_time(double *realTimeOut, double *cpuTimeOut);
162 /* Internationalization defines */
163 nl_catd Dtb_project_catd;
165 /* Workaround for XPG4 API compatibility */
166 #if !defined(NL_CAT_LOCALE)
167 #define NL_CAT_LOCALE 0
172 main(int argc, STRING *argv)
175 int iRC= 0; /* int return code */
176 CmdlineArgsRec cmdlineRec;
177 CmdlineArgs cmdline = &cmdlineRec;
178 ABObj project = NULL;
180 int num_modules_processed = 0;
181 BOOL genAllFiles = FALSE;
182 BOOL genMain = FALSE;
183 BOOL genMainOnly = FALSE;
184 BOOL useDefaultProject = FALSE;
185 BOOL showAllWindows = FALSE;
186 STRING errmsg = NULL;
188 #ifdef DEBUG /* performance testing */
189 double progStartSeconds = 0.0;
190 double progEndSeconds = 0.0;
191 double progSeconds = 0.0;
192 double progStartCPUSeconds = 0.0;
193 double progEndCPUSeconds = 0.0;
194 double progCPUSeconds = 0.0;
195 double configStartSeconds = 0.0;
196 double configEndSeconds = 0.0;
197 double configSeconds = 0.0;
198 double configStartCPUSeconds = 0.0;
199 double configEndCPUSeconds = 0.0;
200 double configCPUSeconds = 0.0;
201 double loadStartSeconds = 0.0;
202 double loadEndSeconds = 0.0;
203 double loadSeconds = 0.0;
204 double loadStartCPUSeconds = 0.0;
205 double loadEndCPUSeconds = 0.0;
206 double loadCPUSeconds = 0.0;
207 double startupStartSeconds = 0.0;
208 double startupEndSeconds = 0.0;
209 double startupSeconds = 0.0;
210 double startupStartCPUSeconds = 0.0;
211 double startupEndCPUSeconds = 0.0;
212 double startupCPUSeconds = 0.0;
213 get_cur_time(&progStartSeconds, &progStartCPUSeconds);
214 startupStartSeconds = loadStartSeconds = configStartSeconds
216 startupStartCPUSeconds = loadStartCPUSeconds = configStartCPUSeconds
217 = progStartCPUSeconds;
221 * Open the standard message catalog for the project.
223 Dtb_project_catd = catopen("dtcodegen", NL_CAT_LOCALE);
224 if (Dtb_project_catd == (nl_catd)-1)
227 "WARNING: Could not open message catalog: dtcodegen.cat\n");
230 util_init(&argc, &argv);
231 dtb_save_command(argv[0]);
235 if ((iRC = parse_args(argc, argv, cmdline)) < 0)
239 util_set_verbosity(cmdline->verbosity);
241 /*********************************************************************
243 ** Figure out what the user wants **
245 *********************************************************************/
248 * Find the project file
250 if (cmdline->use_default_project)
252 useDefaultProject = TRUE;
254 else if (cmdline->proj_file == NULL)
256 int numProjFiles = find_proj_file(cmdline);
257 if (cmdline->proj_file == NULL)
259 if (!strlist_is_empty(cmdline->files))
261 useDefaultProject = TRUE;
262 if (!util_be_silent())
265 catgets(Dtb_project_catd, 1, 1,
266 "No project file that references module(s) - using defaults\n"));
269 else if (numProjFiles == 0)
272 catgets(Dtb_project_catd, 1, 2,
273 "No files specified, and no project file found\n"));
278 /* assume find_proj_file() complained sufficiently */
287 if (strlist_is_empty(cmdline->files))
289 if (cmdline->write_main)
291 /* only -main was specified */
297 /* no specific files requested - gen them all */
304 /* files specified */
305 if (cmdline->write_main)
308 if (useDefaultProject)
310 /* dtcodegen -np module.bil -main : only gen main */
316 if (useDefaultProject)
324 if (cmdline->show_all_windows_set)
326 showAllWindows = cmdline->show_all_windows;
328 else if (useDefaultProject)
330 /* user did not override, so we're going to set show_all_windows */
331 showAllWindows = TRUE;
334 util_dprintf(1, "main:%d mainonly:%d all:%d defaultproj:%d showall:%d\n",
335 genMain, genMainOnly, genAllFiles, useDefaultProject, showAllWindows);
337 if ((!util_be_silent()) && (cmdline->proj_file != NULL))
339 char *proj_file_name = istr_string_safe(cmdline->proj_file);
341 catgets(Dtb_project_catd, 1, 3, "Reading project %s.\n"),
345 #ifdef DEBUG /* performance testing */
346 get_cur_time(&loadStartSeconds, &loadStartCPUSeconds);
349 /*********************************************************************
351 ** Load or create the project **
353 *********************************************************************/
355 if (cmdline->proj_file != NULL)
357 /* project = bil_load_file(istr_string(cmdline->proj_file), NULL, project);
358 assert(project != NULL); */
360 iRC = bil_load_file_and_resolve_all(
361 istr_string(cmdline->proj_file), NULL, &project);
369 if (useDefaultProject)
372 int numModuleFiles = 0;
373 STRING moduleFileName = NULL;
374 ABObj fileObj = NULL;
376 char projNameBuf[1024];
380 * Create the default project
384 ABObj oldProject = project;
385 project = obj_create(AB_TYPE_PROJECT, NULL);
386 obj_move_children(project, oldProject);
387 obj_destroy(oldProject);
391 project = obj_create(AB_TYPE_PROJECT, NULL);
393 util_strncpy(projNameBuf,
394 strlist_get_str(cmdline->files, 0, NULL), 1024);
395 dotPtr = strrchr(projNameBuf, '.');
400 obj_set_name(project, projNameBuf);
401 obj_set_file(project, strlist_get_str(cmdline->files, 0, NULL));
402 obj_set_is_default(project, TRUE);
405 * Create "files" to get converted to undefined modules
407 numModuleFiles = strlist_get_num_strs(cmdline->files);
408 for (i = 0; i < numModuleFiles; ++i)
410 moduleFileName = strlist_get_str(cmdline->files, i, NULL);
411 fileObj = obj_create(AB_TYPE_FILE, project);
412 obj_set_file(fileObj, moduleFileName);
417 * Load the appropriate files
421 mfobj_set_flags(project, CGenFlagLoadMe|CGenFlagIsReferenced);
422 obj_set_write_me(project, TRUE);
424 mark_modules_to_load_and_write(
425 project, cmdline->force_load_all, genAllFiles, genMainOnly, cmdline->files);
426 load_marked_modules(project);
428 #ifdef DEBUG /* performance testing */
429 get_cur_time(&loadEndSeconds, &loadEndCPUSeconds);
430 loadSeconds = loadEndSeconds - loadStartSeconds;
431 loadCPUSeconds = loadEndCPUSeconds - loadStartCPUSeconds;
432 printf("load real:%lg CPU:%lg\n", loadSeconds, loadCPUSeconds);
437 char *prog_name_string = util_get_program_name();
440 catgets(Dtb_project_catd, 1, 4,
441 "%s: exiting due to error loading project.\n"),
445 if (cmdline->debug_profile_what == ABMF_PROFILE_LOAD)
451 * See if we actually have anything to write
453 if (!write_required(project))
455 char *prog_name_string = util_get_program_name();
458 catgets(Dtb_project_catd, 1, 5,
459 "%s: Nothing to do!\n"), prog_name_string);
464 * Configure the raw objects into AB objects
470 for (trav_open(&trav, project, AB_TRAV_WINDOWS);
471 (window = trav_next(&trav)) != NULL; )
473 obj_set_is_initially_visible(window, TRUE);
478 #ifdef DEBUG /* performance testing */
479 get_cur_time(&configStartSeconds, &configStartCPUSeconds);
482 examine_tree(project);
484 #ifdef DEBUG /* performance testing */
485 get_cur_time(&configEndSeconds, &configEndCPUSeconds);
486 configSeconds = configEndSeconds - configStartSeconds;
487 configCPUSeconds = configEndCPUSeconds - configStartCPUSeconds;
488 get_cur_time(&startupEndSeconds, &startupEndCPUSeconds);
489 startupSeconds = startupEndSeconds - startupStartSeconds;
490 startupCPUSeconds = startupEndCPUSeconds - startupStartCPUSeconds;
493 * Print out startup stats (if debugging build)
495 util_printf("Startup real time: %lg s (%lg s load, %lg s config)\n",
496 startupSeconds, loadSeconds, configSeconds);
497 util_printf("Startup CPU time: %lg s (%lg s load, %lg s config)\n",
498 startupCPUSeconds, loadCPUSeconds, configCPUSeconds);
502 util_dprintf(1, "after configure_tree\n");
503 debug_verify_tree(project);
507 * The tree has been loaded, examined, mangled, and generally messed with.
508 * Now, do what the user has requested.
512 /* make sure we didn't muss anything up */
515 int numObjs = trav_count(project, AB_TRAV_ALL);
516 obj_tree_verify(project);
517 if ( ((debug_level() >= 10) || ((25*debug_level()) >= numObjs))
518 && (!cmdline->dump_tree))
520 objxm_tree_print(project);
525 if (cmdline->dump_tree)
531 AB_ARG_CLASS_FLAGS dumpedRes = obj_get_res_file_arg_classes(project);
532 ABMF_I18N_METHOD i18n_method = ABMF_I18N_NONE;
534 if (obj_get_i18n_enabled(project))
535 i18n_method = ABMF_I18N_XPG4_API;
540 iRC = abmf_generate_code(
542 cmdline->cgen_restriction,
543 cmdline->merge_files,
545 cmdline->prototype_funcs,
554 #ifdef DEBUG /* performance testing */
555 get_cur_time(&progEndSeconds, &progEndCPUSeconds);
556 progSeconds = progEndSeconds - progStartSeconds;
557 progCPUSeconds = progEndCPUSeconds - progStartCPUSeconds;
558 util_printf("Total real time: %lg s CPU time: %lg s\n",
559 progSeconds, progCPUSeconds);
564 debug_verify_tree(project);
572 parse_args(int argc, char *argv[], CmdlineArgs cmdline)
580 cmdline->force_load_all = TRUE;
581 cmdline->debug_profile_what = ABMF_PROFILE_UNDEF;
582 cmdline->cgen_restriction = ABMF_CGEN_ALL;
583 cmdline->dump_tree = FALSE;
584 cmdline->files = strlist_create();
585 cmdline->i18n = FALSE;
586 cmdline->show_all_windows = FALSE;
587 cmdline->show_all_windows_set = FALSE;
588 cmdline->write_main = FALSE;
589 cmdline->merge_files = TRUE;
590 cmdline->proj_file = NULL;
591 cmdline->prototype_funcs = TRUE;
592 cmdline->source_browser = FALSE;
593 cmdline->use_default_project = FALSE;
594 cmdline->verbosity = util_get_verbosity();
595 cmdline->write_all_resources = FALSE;
596 cmdline->write_i18n_resources = FALSE;
598 for (argCount = 1; argCount < argc; ++argCount)
600 char *arg = argv[argCount];
603 if (strcmp(arg, "-s") == 0 ||
604 strcmp(arg, "-silent") == 0)
606 cmdline->verbosity = 0;
608 else if (strcmp(arg, "-a") == 0 ||
609 strcmp(arg, "-ansi") == 0)
611 cmdline->prototype_funcs = TRUE;
613 else if (util_streq(arg, "-freshen"))
615 freshenUnchangedFiles = TRUE;
617 else if (util_streq(arg, "-nofreshen"))
619 freshenUnchangedFiles = FALSE;
622 else if (util_streq(arg, "-tree"))
624 cmdline->dump_tree = TRUE;
627 else if (util_streq(arg, "-changed"))
629 cmdline->cgen_restriction = ABMF_CGEN_BY_DATE;
631 else if (strcmp(arg, "-k") == 0 ||
632 strcmp(arg, "-kandr") == 0)
634 cmdline->prototype_funcs = FALSE;
636 else if (strcmp(arg, "-main") == 0)
638 cmdline->write_main = TRUE;
640 else if (util_streq(arg, "-showall"))
642 cmdline->show_all_windows = TRUE;
643 cmdline->show_all_windows_set = TRUE;
645 else if (util_streq(arg, "-noshowall"))
647 cmdline->show_all_windows = FALSE;
648 cmdline->show_all_windows_set = TRUE;
650 else if (util_streq(arg, "-merge"))
652 cmdline->merge_files = TRUE;
654 else if (util_streq(arg, "-nomerge"))
656 cmdline->merge_files = FALSE;
658 else if (strcmp(arg, "-P") == 0 ||
659 strcmp(arg, "-p") == 0 ||
660 strcmp(arg, "-project") == 0)
662 if ((argCount + 1) >= argc)
664 util_error( catgets(Dtb_project_catd, 1, 6,
665 "Missing project name for -p option"));
672 * get the project file name
676 projArg= argv[argCount];
677 if ( util_file_name_has_extension(projArg, "bip")
678 || util_file_name_has_extension(projArg, "bix"))
680 cmdline->proj_file = istr_const(projArg);
684 char projFile[MAX_PATH_SIZE];
685 sprintf(projFile, "%s.bip", projArg);
686 if (!util_file_exists(projFile))
688 char encapsFile[MAXPATHLEN];
689 sprintf(encapsFile, "%s.bix", projArg);
690 if (util_file_exists(encapsFile))
692 strcpy(projFile, encapsFile);
695 cmdline->proj_file = istr_create(projFile);
699 else if ( util_streq(arg, "-np")
700 || util_streq(arg, "-noproject"))
702 cmdline->use_default_project = TRUE;
704 else if (strcmp(arg, "-help") == 0)
708 else if (strcmp(arg, "-i") == 0 ||
709 strcmp(arg, "-i18n") == 0)
711 cmdline->i18n = TRUE;
713 else if (strcmp(arg, "-r") == 0 ||
714 strcmp(arg, "-resources") == 0)
716 cmdline->write_all_resources = TRUE;
718 else if (strcmp(arg, "-sb") == 0)
720 cmdline->source_browser = TRUE;
722 else if (strncmp(arg, "-v", 2) == 0)
724 cmdline->verbosity = 2;
731 else if (strncmp(arg, "-V", 2) == 0)
734 for (i = 1; arg[i] == 'V'; ++i)
737 cmdline->verbosity = i;
739 else if (strncmp(arg, "-time", 5) == 0)
741 if (argCount < (argc-1))
743 arg = argv[++argCount];
744 if (util_streq(arg, "load"))
746 cmdline->debug_profile_what = ABMF_PROFILE_LOAD;
750 else if (strncmp(arg, "-loadall", 8) == 0)
752 cmdline->force_load_all = TRUE;
757 char *prog_name_string = util_get_program_name();
759 fprintf(stderr, catgets(Dtb_project_catd, 1, 7,
760 "%s: Illegal option \"%s\"\n\n"), prog_name_string, arg);
771 if ( util_file_name_has_extension(arg, "bip")
772 || util_file_name_has_extension(arg, "bix") )
774 if (cmdline->proj_file != NULL)
777 catgets(Dtb_project_catd, 1, 8,
778 "Only one project file may be specified."));
783 cmdline->proj_file = istr_const(arg);
788 ISTRING newFile = NULL;
790 if (util_file_name_has_ab_extension(arg))
792 newFile = istr_const(arg);
796 char fileName[MAX_PATH_SIZE];
797 strcpy(fileName, arg);
798 strcat(fileName, ".bil");
799 newFile = istr_create(fileName);
802 strlist_add_istr(cmdline->files, newFile, NULL);
803 } /* not project file */
809 * Make the comand-line args consistent
811 if (cmdline->use_default_project && (cmdline->proj_file != NULL))
813 char *proj_file_name = istr_string_safe(cmdline->proj_file);
816 catgets(Dtb_project_catd, 1, 9,
817 "ignoring -noproject (-np) because project file was specified: %s\n"),
819 cmdline->use_default_project = FALSE;
827 mark_modules_to_load_and_write(
835 int return_value = 0;
836 AB_TRAVERSAL fileTrav;
838 ISTRING fileName = NULL;
839 char newModuleName[1024];
840 STRING dotPtr = NULL;
841 AB_TRAVERSAL allTrav;
845 AB_TRAVERSAL moduleTrav;
847 ABObj winParent = NULL;
851 * Convert remaining files into undefined modules
853 for (trav_open(&fileTrav, project, AB_TRAV_FILES | AB_TRAV_MOD_SAFE);
854 (file = trav_next(&fileTrav)) != NULL; )
856 fileName = istr_create(obj_get_file(file));
857 util_get_file_name_from_path(
858 istr_string(fileName), newModuleName, 1024);
859 dotPtr = strrchr(newModuleName, '.');
865 module = obj_find_module_by_name(project, newModuleName);
868 /* this module already exists, probably because of a forward */
874 obj_set_type(file, AB_TYPE_MODULE);
875 module = file; file = NULL;
876 obj_set_name(module, newModuleName);
877 obj_set_is_defined(module, FALSE);
878 mfobj_set_flags(module, CGenFlagLoadMe|CGenFlagIsReferenced);
882 * Objects/modules created as a forward reference will
883 * not have their file names set, so we're going to
886 if (obj_get_file(module) == NULL)
888 obj_set_file(module, istr_string(fileName));
890 istr_destroy(fileName);
894 trav_close(&fileTrav);
898 * Mark the modules that are to be written
901 char explodedModuleFile[MAXPATHLEN+1];
902 *explodedModuleFile = 0;
904 for (trav_open(&moduleTrav, project, AB_TRAV_MODULES|AB_TRAV_MOD_SAFE);
905 (module = trav_next(&moduleTrav)) != NULL; )
907 sprintf(explodedModuleFile, "%s.bil", obj_get_name(module));
909 if ((genAllModules && obj_is_defined(module)) ||
910 (strlist_str_exists(fileNames, explodedModuleFile) && (!genNoModules)))
912 if (obj_is_defined(module)) /* must be defined!! */
914 strlist_set_str_data(fileNames, explodedModuleFile, (void*)TRUE);
915 obj_set_write_me(module, TRUE);
920 trav_close(&moduleTrav);
924 * Make sure all the modules on the command line were found
928 int numFiles = strlist_get_num_strs(fileNames);
929 STRING fileName = NULL;
930 BOOL wasFound = FALSE;
931 void *wasFoundVoidPtr;
932 BOOL errOccurred = FALSE;
933 for (i = 0; i < numFiles; ++i)
935 fileName = strlist_get_str(fileNames, i, &wasFoundVoidPtr);
936 assert(fileName != NULL);
937 wasFound = (BOOL)(unsigned)wasFoundVoidPtr;
940 util_printf_err("module not found in project: %s\n", fileName);
951 * Determine dependencies necessary to write the requested modules
955 for (trav_open(&allTrav, project, AB_TRAV_ALL | AB_TRAV_MOD_SAFE);
956 (obj = trav_next(&allTrav)) != NULL; )
958 switch (obj_get_type(obj))
961 if (obj_get_write_me(obj))
963 mfobj_set_flags(obj, CGenFlagIsReferenced);
968 * win-parent can be in another module
971 case AB_TYPE_BASE_WINDOW:
972 if ( obj_is_defined(obj)
974 && obj_get_write_me(obj_get_module(obj)))
976 if ((winParent = obj_get_win_parent(obj)) != NULL)
978 mfobj_set_flags(obj_get_module(winParent),
979 CGenFlagIsReferenced);
983 /* visible windows must be loaded to write main */
984 if ( obj_get_write_me(project)
985 && obj_is_defined(obj) && obj_is_initially_visible(obj))
987 mfobj_set_flags(obj_get_module(obj),
988 CGenFlagIsReferenced);
996 obj1 = obj_get_from(obj);
997 if (obj_is_project(obj1))
999 obj2 = obj_get_to(obj);
1000 if ( ( (obj1 != NULL)
1001 && obj_is_defined(obj1)
1002 && obj_get_write_me(obj_get_module(obj1)))
1004 && obj_is_defined(obj2)
1005 && obj_get_write_me(obj_get_module(obj2)))
1009 * At least one object will be written, make sure
1014 mfobj_set_flags((obj_get_module(obj1)),
1015 CGenFlagIsReferenced);
1019 mfobj_set_flags((obj_get_module(obj2)),
1020 CGenFlagIsReferenced);
1025 * to/from of cross-module conns must be available to write
1028 if ( obj_get_write_me(project)
1029 && obj_is_defined(obj)
1030 && obj_is_cross_module(obj))
1032 if ((obj1 != NULL) && obj_is_defined(obj1))
1034 mfobj_set_flags((obj_get_module(obj1)),
1035 CGenFlagIsReferenced);
1037 if ((obj2 != NULL) && obj_is_defined(obj2))
1039 mfobj_set_flags((obj_get_module(obj2)),
1040 CGenFlagIsReferenced);
1046 trav_close(&allTrav);
1054 load_marked_modules(ABObj project)
1056 ABObj module = NULL;
1057 AB_TRAVERSAL moduleTrav;
1058 char fileName[MAXPATHLEN+1] = "";
1060 for (trav_open(&moduleTrav, project, AB_TRAV_MODULES|AB_TRAV_MOD_SAFE);
1061 (module = trav_next(&moduleTrav)) != NULL; )
1063 if ( mfobj_has_flags(module, CGenFlagLoadMe)
1064 && (!obj_is_defined(module)))
1066 load_module(module);
1069 trav_close(&moduleTrav);
1076 load_module(ABObj module)
1078 char fileName[MAXPATHLEN+1];
1079 ABObj newProject = NULL;
1080 ABObj project = obj_get_project(module);
1083 if (obj_get_file(module) != NULL)
1085 strcpy(fileName, obj_get_file(module));
1089 strcpy(fileName, obj_get_name(module));
1090 if (!util_file_name_has_ab_extension(fileName))
1092 strcat(fileName, ".bil");
1096 newProject = bil_load_file(fileName, NULL, project, NULL);
1097 if (newProject == NULL)
1099 /* a failure ocurred. The error has already been reported */
1102 else if (newProject != project)
1105 catgets(Dtb_project_catd, 1, 10,
1106 "Unexpected project in file %s. Aborting\n"), fileName);
1109 if (!obj_is_defined(module))
1111 char *module_name_string = obj_get_name(module);
1114 catgets(Dtb_project_catd, 1, 11,
1115 "Module %s not found in file %s. Aborting\n"),
1116 module_name_string, fileName);
1125 * Print usage message
1130 char *program_name_string = util_get_program_name();
1132 fprintf(stderr,"\n");
1134 catgets(Dtb_project_catd, 1, 12,
1135 "Usage: %s [options] [project-file] [module-file [module-file] ...]\n\n"),
1136 program_name_string);
1138 fprintf(stderr, catgets(Dtb_project_catd, 1, 13,
1139 "Code is generated for each module specified on the command line, or for\n"));
1140 fprintf(stderr, catgets(Dtb_project_catd, 1, 14,
1141 "all modules in the project, if no modules are specified. If no project\n"));
1142 fprintf(stderr, catgets(Dtb_project_catd, 1, 15,
1143 "file is specified, a project file containing the specified module(s) is\n"));
1144 fprintf(stderr, catgets(Dtb_project_catd, 1, 16,
1145 "searched for in the current directory.\n\n"));
1147 fprintf(stderr, catgets(Dtb_project_catd, 1, 17,
1148 "Files with extension .bip are assumend to be BIL project files, files with\n"));
1149 fprintf(stderr, catgets(Dtb_project_catd, 1, 18,
1150 ".bix extenstion are assumed to be encapsulated BIL files, and files\n"));
1151 fprintf(stderr, catgets(Dtb_project_catd, 1, 19,
1152 "With a .bil extension are assumed to be BIL module files.\n\n"));
1154 fprintf(stderr, catgets(Dtb_project_catd, 1, 20,
1155 "Options (* = default, + = default with no project file):\n"));
1156 fprintf(stderr, catgets(Dtb_project_catd, 1, 21,
1157 " -help (-h) Print out this help message\n"));
1158 fprintf(stderr, catgets(Dtb_project_catd, 1, 22,
1159 " -main Write file containing main()\n"));
1160 fprintf(stderr, catgets(Dtb_project_catd, 1, 23,
1161 " -changed Only generate files that have changed\n"));
1162 fprintf(stderr, catgets(Dtb_project_catd, 1, 24,
1163 "* -merge Merge generated _stubs.c files with previous version\n"));
1164 fprintf(stderr, catgets(Dtb_project_catd, 1, 25,
1165 " -nomerge Don't merge existing and new stubs file\n"));
1166 fprintf(stderr, catgets(Dtb_project_catd, 1, 26,
1167 "* -project (-p) Specify a project to generate code for\n"));
1168 fprintf(stderr, catgets(Dtb_project_catd, 1, 27,
1169 " -noproject (-np) Use default project settings, ignore project file\n"));
1170 fprintf(stderr, catgets(Dtb_project_catd, 1, 28,
1171 "+ -showall Application shows (maps) all windows at startup\n"));
1172 fprintf(stderr, catgets(Dtb_project_catd, 1, 29,
1173 "* -noshowall Application shows (maps) only initially-visible windows\n"));
1174 fprintf(stderr, catgets(Dtb_project_catd, 1, 30,
1175 " -silent (-s) Silent mode, no messages written\n"));
1176 fprintf(stderr, catgets(Dtb_project_catd, 1, 31,
1177 " -verbose (-v) Verbose mode, detailed progress messages\n\n"));
1180 /* "-a (-ansi) Write ANSI C code\n" */
1181 /* "-k (-kandr) Write K&R C code, no function prototypes\n" */
1182 /* "-i (-i18n) Create resource file for I18N\n" */
1183 /* "-r (-resources) Write all resources into a resource file\n" */
1186 return ERR_INTERNAL;
1191 * Searches the current directory for a project file
1192 * Sets the cmdline->proj_file member
1194 * Returns the total number of project files found
1198 find_proj_file(CmdlineArgs cmdline)
1201 struct dirent *dirEntry= NULL;
1202 int numProjectFiles = 0;
1203 StringListRec projFiles;
1204 strlist_construct(&projFiles);
1209 perror(catgets(Dtb_project_catd,1,32,"Couldn't open '.'"));
1213 while ((dirEntry= readdir(dir)) != NULL)
1215 if (util_file_name_has_extension(dirEntry->d_name, "bip"))
1217 /* found a project file! */
1218 strlist_add_str(&projFiles, dirEntry->d_name, NULL);
1222 numProjectFiles = strlist_get_num_strs(&projFiles);
1223 if (numProjectFiles > 0)
1225 int num_strings = strlist_get_num_strs(&projFiles);
1227 STRING fileName = NULL;
1229 for (i = 0; i < strlist_get_num_strs(&projFiles); ++i)
1231 fileName = strlist_get_str(&projFiles, i, NULL);
1232 if (!proj_file_has_modules(fileName, cmdline->files))
1234 strlist_remove_index(&projFiles, i);
1240 if (strlist_get_num_strs(&projFiles) == 1)
1242 cmdline->proj_file = istr_create(strlist_get_str(&projFiles, 0, NULL));
1244 else if (strlist_get_num_strs(&projFiles) > 1)
1247 char *prog_name_string = util_get_program_name();
1249 fprintf(stderr, catgets(Dtb_project_catd, 1, 33,
1250 "%s: Please specify project file (e.g."), prog_name_string);
1251 for (i = 0; i < strlist_get_num_strs(&projFiles); ++i)
1253 fprintf(stderr, ", %s", strlist_get_str(&projFiles, i, NULL));
1255 fprintf(stderr, catgets(Dtb_project_catd, 1, 34, ")\n"));
1256 if (!strlist_is_empty(cmdline->files))
1259 catgets(Dtb_project_catd, 1, 35,
1260 "%s: More than one project contains specified module(s)\n"),
1265 closedir(dir); dir= NULL;
1267 strlist_destruct(&projFiles);
1268 return numProjectFiles;
1273 proj_file_has_modules(STRING projFileName, StringList moduleFileNames)
1275 BOOL hasModules = FALSE;
1276 char word[1024] = "";
1277 int modulesFound = 0;
1282 int numFiles = strlist_get_num_strs(moduleFileNames);
1289 file = util_fopen_locked(projFileName, "r");
1292 perror(projFileName);
1296 while ((c = fgetc(file)) != EOF)
1300 fgetpos(file, &fpos);
1302 if ( (fgets(word, 6, file) != NULL)
1303 && (strncmp(word, "files", 5) == 0))
1305 /* :files <file-list> */
1306 BOOL filesDone = FALSE;
1307 while (((c = fgetc(file)) != EOF) && (c != '(')) {}
1308 filesDone = (c == EOF);
1311 while (((c = fgetc(file)) != EOF) && isspace(c)) {}
1315 while (((c = fgetc(file)) != EOF) && (!isspace(c)))
1322 word[wordLen++] = c;
1333 ISTRING temp_istr = istr_create(word);
1334 for (i = 0; i < numFiles; ++i)
1336 if (istr_equal(temp_istr,
1337 strlist_get_istr(moduleFileNames, i, NULL)))
1343 istr_destroy(temp_istr);
1347 else if ( (strncmp(word, "modul", 5) == 0)
1348 && (fgets(word, 2, file) != NULL)
1349 && (strncmp(word, "e", 1) == 0) )
1351 /* :module <module-name */
1352 /* REMIND: we need to have this for .bix files to work! */
1356 fsetpos(file, &fpos);
1359 } /* while c != EOF */
1362 hasModules = (modulesFound >= numFiles);
1369 write_required(ABObj tree)
1371 BOOL writeSomething= FALSE;
1373 if (obj_get_write_me(tree))
1375 writeSomething= TRUE;
1382 for(trav_open(&trav, tree, AB_TRAV_MODULES);
1383 (module= trav_next(&trav)) != NULL; )
1385 if (obj_get_write_me(module))
1387 writeSomething= TRUE;
1394 return writeSomething;
1399 * Initializes everything in abmf.
1404 STRING templateFuncName = NULL;
1406 abmfP_motifdefs_init();
1407 abmfP_ui_header_file_init();
1411 * Turn "template" library functions into printf format strings
1413 templateFuncName = "dtb_default_dragCB";
1414 replace_string_shorter(abmfP_lib_default_dragCB->proto,
1415 templateFuncName, "%s");
1416 replace_string_shorter(abmfP_lib_default_dragCB->def,
1417 templateFuncName, "%s");
1419 templateFuncName = "dtb_default_dropCB";
1420 replace_string_shorter(abmfP_lib_default_dropCB->proto,
1421 templateFuncName, "%s");
1422 replace_string_shorter(abmfP_lib_default_dropCB->def,
1423 templateFuncName, "%s");
1430 * Replaces all occurences of substr with replacestr.
1431 * replaceStr *must* be shorter than or the same length as subStr
1434 replace_string_shorter(STRING buf, STRING subStr, STRING replaceStr)
1436 int numReplaced = 0;
1438 char *bufEnd = buf + strlen(buf);
1439 int subStrLen = strlen(subStr);
1440 char *subStrPtr = subStr;
1441 int replaceStrLen = strlen(replaceStr);
1442 int replaceDiffLen = subStrLen - replaceStrLen;
1444 assert(strlen(subStr) >= (size_t)strlen(replaceStr));
1446 while ((subStrPtr = strstr(bufPtr, subStr)) != NULL)
1448 memmove(subStrPtr+replaceStrLen,
1449 subStrPtr+subStrLen,
1450 ((int)(bufEnd - (subStrPtr+subStrLen))) + 1);
1451 strncpy(subStrPtr, replaceStr, replaceStrLen); /* no NULL! */
1452 bufPtr = subStrPtr+replaceStrLen;
1453 bufEnd -= replaceDiffLen;
1464 examine_tree(ABObj project)
1466 int returnValue = 0;
1467 AB_TRAVERSAL moduleTrav;
1468 AB_TRAVERSAL uiTrav;
1469 ABObj module = NULL;
1471 ABObj parent = NULL;
1472 StringList proj_callbacks = NULL;
1473 ABObj callbackScopeObj = NULL;
1474 STRING funcName = NULL;
1476 objxm_obj_configure(project, OBJXM_CONFIG_CODEGEN, TRUE);
1478 for (trav_open(&moduleTrav, project, AB_TRAV_MODULES);
1479 (module = trav_next(&moduleTrav)) != NULL; )
1481 if (!mfobj_has_flags(module, CGenFlagIsReferenced))
1490 util_dprintf(1, "Configuring %s\n",
1491 obj_get_safe_name(module, name, 256));
1494 objxm_tree_configure(module, OBJXM_CONFIG_CODEGEN);
1495 dup_all_menu_refs(module); /* this can create new objs */
1497 for (trav_open(&uiTrav, module,
1498 AB_TRAV_UI | AB_TRAV_MOD_PARENTS_FIRST | AB_TRAV_MOD_SAFE);
1499 (obj = trav_next(&uiTrav)) != NULL; )
1501 if ( (obj_get_class_name(obj) == NULL)
1502 && (!obj_has_flag(obj, NoCodeGenFlag)) )
1507 if (!(obj_is_item(obj) || obj_is_menu(obj) || obj_is_message(obj)))
1509 char name[256] = "";
1512 "Object has no class name (NoCodeGenFlag not set): %s\n",
1513 obj_get_safe_name(obj, name, 256));
1519 munge_ensure_win_parent(obj);
1520 munge_liberate_menu(obj);
1522 trav_close(&uiTrav);
1523 } /* trav modules */
1524 trav_close(&moduleTrav);
1526 abmfP_prepare_tree(project); /* creates extra data for each obj */
1533 munge_ensure_win_parent(ABObj win)
1535 ABObj root_window = abmfP_get_root_window(obj_get_project(win));
1536 if (!obj_is_window(win))
1541 if ((obj_get_win_parent(win) == NULL) && (win != root_window))
1543 obj_set_win_parent(win, root_window);
1551 munge_liberate_menu(ABObj menu)
1553 if (!obj_is_menu(menu))
1558 ABObj compRoot = obj_get_root(menu);
1559 AB_OBJECT_TYPE compType = AB_TYPE_UNDEF;
1561 if (compRoot != NULL)
1563 compType = obj_get_type(compRoot);
1565 if ( (compRoot != menu)
1566 && ( (compType == AB_TYPE_ITEM)
1567 || (compType == AB_TYPE_BUTTON)) )
1569 menu->part_of = NULL;
1578 dup_all_menu_refs(ABObj project)
1580 AB_TRAVERSAL moduleTrav;
1581 AB_TRAVERSAL menuTrav;
1582 ABObj module = NULL;
1585 for (trav_open(&moduleTrav, project, AB_TRAV_MODULES);
1586 (module = trav_next(&moduleTrav)) != NULL; )
1588 if (!obj_get_write_me(module))
1592 for (trav_open(&menuTrav, module, AB_TRAV_MENUS);
1593 (menu = trav_next(&menuTrav)) != NULL; )
1595 if (obj_is_ref(menu))
1597 abmfP_dup_menu_ref_tree(menu);
1598 if (obj_is_popup(menu))
1600 STRING title = obj_get_menu_title(obj_get_parent(menu));
1601 if (!util_strempty(title))
1602 objxm_create_popup_menu_title(menu, OBJXM_CONFIG_CODEGEN,
1607 trav_close(&menuTrav);
1609 trav_close(&moduleTrav);
1616 abmfP_dup_menu_ref_tree(ABObj obj)
1618 int rc = 0; /* return code */
1619 int return_value = 0;
1620 ABObj refObj = NULL;
1623 if (!obj_is_menu_ref(obj))
1627 rc = abmfP_do_dup_menu_ref_tree(obj);
1634 * We can't handle multi-layered references, so we are going to collapse
1635 * any reference lists to only reference the final (actual) object.
1637 for (trav_open(&trav, obj, AB_TRAV_UI);
1638 (obj = trav_next(&trav)) != NULL; )
1640 refObj = obj_get_actual_obj(obj);
1643 while (obj_is_ref(refObj))
1645 refObj = obj_get_actual_obj(refObj);
1647 obj_cvt_to_ref(obj, refObj);
1651 return return_value;
1656 abmfP_do_dup_menu_ref_tree(ABObj obj)
1658 int return_value = 0;
1660 ABObj actualMenu = NULL;
1661 if (!obj_is_menu_ref(obj))
1665 actualMenu = obj_get_actual_obj(obj);
1666 if (actualMenu == NULL)
1671 if (obj_get_num_items(obj) != obj_get_num_items(actualMenu))
1673 ABObj dupTree = obj_tree_create_ref(actualMenu);
1674 if (dupTree == NULL)
1679 rc = obj_move_children(obj, dupTree);
1684 obj_destroy(dupTree);
1688 ABObj descendant = NULL;
1690 for (trav_open(&trav, obj,
1691 AB_TRAV_UI|AB_TRAV_MOD_PARENTS_FIRST|AB_TRAV_MOD_SAFE);
1692 (descendant = trav_next(&trav)) != NULL; )
1694 if (descendant == obj)
1698 if (obj_is_menu_ref(descendant))
1700 abmfP_do_dup_menu_ref_tree(descendant);
1707 return return_value;
1712 dump_tree(ABObj tree)
1714 int return_value = 0;
1715 int old_verbosity = util_get_verbosity();
1717 switch (old_verbosity)
1719 case 0: /* FALLTHROUGH */
1720 case 1: util_set_verbosity(3);
1723 case 2: util_set_verbosity(4);
1727 print_tree(tree, 0);
1730 util_set_verbosity(old_verbosity);
1731 return return_value;
1736 print_tree(ABObj root, int indent)
1741 int travType = AB_TRAV_SALIENT_CHILDREN;
1743 if (util_get_verbosity() >= 4)
1745 travType = AB_TRAV_CHILDREN;
1748 if ( (travType == AB_TRAV_CHILDREN)
1749 || (obj_is_salient(root)) )
1751 objxm_print_indented(root, indent, util_get_verbosity());
1755 if (obj_is_module(root) && (!obj_get_write_me(root)))
1759 for (trav_open(&trav, root, travType);
1760 (child = trav_next(&trav)) != NULL; )
1762 numPrinted += print_tree(child, indent+4);
1767 * Look for non-salient children that need their children printed
1769 if (travType == AB_TRAV_SALIENT_CHILDREN)
1771 for (trav_open(&trav, root, AB_TRAV_CHILDREN);
1772 (child = trav_next(&trav)) != NULL; )
1774 if ((!obj_is_salient(child)) && (obj_get_root(child) != root))
1776 numPrinted += print_tree(child, indent);
1788 time_traversal(ABObj root)
1790 int return_value = 0;
1794 double startTime = 0;
1796 double totalTravTime = 0;
1797 double oneTravTime = 0;
1798 int numTravs = 1000;
1800 long ticks_per_second = sysconf(_SC_CLK_TCK);
1801 int oldVerbosity = util_get_verbosity();
1803 if (ticks_per_second <= 0)
1805 util_dprintf(0, "Couldn't get the value of _SC_CLK_TCK!\n");
1806 return_code(ERR_INTERNAL);
1809 util_set_verbosity(0); /* no expensive error-checking */
1814 util_printf("Beginning trav test\n");
1815 startTime = (times(&timeBuf) *1.0) / ticks_per_second;
1816 for (i = 0; i < numTravs; ++i)
1818 for (trav_open(&trav, root, AB_TRAV_ALL);
1819 (obj = trav_next(&trav)) != NULL; )
1824 endTime = (times(&timeBuf) *1.0) / ticks_per_second;
1825 util_printf("end of trav test\n");
1826 totalTravTime = (endTime - startTime);
1827 oneTravTime = totalTravTime/numTravs;
1828 util_printf("one ALL traversal time: %g\n", oneTravTime);
1833 startTime = (times(&timeBuf) *1.0) / ticks_per_second;
1834 for (i = 0; i < numTravs; ++i)
1836 for (trav_open(&trav, root, AB_TRAV_SALIENT);
1837 (obj = trav_next(&trav)) != NULL; )
1842 endTime = (times(&timeBuf) *1.0) / ticks_per_second;
1843 util_printf("end of trav test\n");
1844 totalTravTime = (endTime - startTime);
1845 oneTravTime = totalTravTime/numTravs;
1846 util_printf("one SALIENT traversal time: %lg\n", oneTravTime);
1849 util_set_verbosity(oldVerbosity);
1850 return return_value;
1856 * Actually sets the tree up for code generation.
1859 abmfP_prepare_tree(ABObj project)
1861 ABObj module = NULL;
1863 StringList proj_callbacks = NULL;
1865 AB_TRAVERSAL allTrav;
1866 ABObj callbackScopeObj;
1867 STRING funcName = NULL;
1868 ABObj parent = NULL;
1871 * Create extra cgen data for each object
1873 abmfP_create_obj_data_for_project(project);
1874 for(trav_open(&trav, project, AB_TRAV_MODULES);
1875 (module = trav_next(&trav)) != NULL; )
1877 abmfP_create_obj_data_for_module(module);
1881 proj_callbacks = mfobj_get_proj_data(project)->callbacks;
1883 for (trav_open(&allTrav, project,
1884 AB_TRAV_ALL | AB_TRAV_MOD_PARENTS_FIRST | AB_TRAV_MOD_SAFE);
1885 (obj = trav_next(&allTrav)) != NULL; )
1887 module = obj_get_module(obj);
1889 if (obj_is_action(obj) && (obj_get_func_type(obj) == AB_FUNC_USER_DEF))
1892 * we have a user-defined callback. decide where to put it
1894 funcName = obj_get_func_name(obj);
1895 callbackScopeObj = abmfP_find_callback_scope(project, funcName);
1896 if (callbackScopeObj == NULL)
1899 if (obj_is_intra_module(obj) &&
1900 !obj_is_project(obj_get_from(obj)))
1902 strlist_add_str(mfobj_get_module_data(module)->callbacks,
1903 funcName, (void *)obj);
1907 strlist_add_str(mfobj_get_proj_data(project)->callbacks,
1908 funcName, (void *)obj);
1910 if (obj_is_project(obj_get_from(obj)))
1911 mfobj_set_flags(obj, CGenFlagWriteDefToProjFile);
1917 * It exists - see if it's in the right place...
1919 if ( obj_is_module(callbackScopeObj)
1920 && (callbackScopeObj != module))
1923 * it's in more than one module - put it in the project
1926 ABObj originalConn = NULL;
1927 StringList moduleCallbacks =
1928 mfobj_get_module_data(callbackScopeObj)
1932 strlist_get_str_index(moduleCallbacks, funcName);
1933 strlist_get_str(moduleCallbacks, str_index,
1934 (void **)&originalConn);
1935 if (originalConn != NULL)
1937 mfobj_set_flags(originalConn,
1938 CGenFlagWriteDefToProjFile);
1940 strlist_remove_index(moduleCallbacks, str_index);
1942 mfobj_get_proj_data(project)->callbacks,
1943 funcName, (void *)originalConn);
1944 mfobj_set_flags(obj, CGenFlagWriteDefToProjFile);
1948 * Mark this as a duplicate, so we only write it once
1950 mfobj_set_flags(obj, CGenFlagIsDuplicateDef);
1953 else if ((module != NULL) && (obj_get_write_me(module)))
1956 * For some reason, menu titles are of type menu and not label
1958 if (ObjWClassIsLabel(obj))
1960 obj->type = AB_TYPE_LABEL;
1961 parent = abmfP_parent(obj);
1962 if ( obj_is_menu(parent)
1963 || obj_is_menu_ref(parent))
1965 obj->part_of = abmfP_parent(obj);
1966 parent->part_of = parent;
1970 if ( (obj_is_menu(obj) || (obj_is_menu_ref(obj)))
1971 && (obj_get_class_name(obj) == NULL))
1973 obj_set_class_name(obj, istr_string(abmfP_xmMenuShell));
1975 } /* obj_get_write_me() */
1976 if ((!(mfobj_get_proj_data(project)->has_ui_obj)) && obj_is_ui(obj))
1978 mfobj_get_proj_data(project)->has_ui_obj = TRUE;
1980 if (obj_get_type(obj) == AB_TYPE_TERM_PANE)
1982 mfobj_get_proj_data(project)->has_terminal = TRUE;
1984 } /* trav modules */
1985 trav_close(&allTrav);
1992 abmfP_obj_has_no_module(ABObj obj)
1994 return ((obj == NULL) || (obj_get_module(obj) == NULL));
1999 * Creates data ONLY for project-specific things that are not covered
2000 * by the individual modules.
2002 * Assumes: project is a project
2005 abmfP_create_obj_data_for_project(ABObj project)
2009 CGenProjData projData = NULL;
2010 CGenData objData = NULL;
2011 size_t objDataNumBytes = 0;
2016 for (trav_open_cond(&trav, project, AB_TRAV_ALL|AB_TRAV_MOD_SAFE,
2017 abmfP_obj_has_no_module);
2018 (obj = trav_next(&trav)) != NULL; )
2022 /* don't close trav, yet */
2025 * Create data space for all children
2027 objDataNumBytes = numObjects * sizeof(CGenDataRec);
2028 objData= (CGenData)util_malloc(objDataNumBytes);
2029 memset(objData, 0, objDataNumBytes);
2032 * Assign each obj it's own struct
2034 for (trav_reset(&trav), objCount = 0;
2035 (obj = trav_next(&trav)) != NULL; )
2037 obj->cgen_data = (CGenData)&(objData[objCount++]);
2038 mfobj_set_flags(obj, CGenFlagDataIsObj);
2040 trav_close(&trav); /* close it, now */
2041 assert(objCount == numObjects);
2044 * Create project-specific data
2046 projData = (CGenProjData)calloc(1, sizeof(CGenProjDataRec));
2047 projData->callbacks = strlist_create();
2048 projData->children_data = objData;
2049 mfobj_set_proj_data(project, projData);
2055 * Accepts any value (NULL, obj w/o module, ...)
2058 abmfP_create_obj_data_for_module(ABObj objInModule)
2060 ABObj module = NULL;
2062 CGenData objData = NULL;
2063 size_t objDataBytes = 0;
2068 if ( (objInModule == NULL)
2069 || (mfobj_has_data(objInModule))
2070 || ((module = obj_get_module(objInModule)) == NULL)
2078 * object data is an array of all data for the module.
2080 numObjects = trav_count(module, AB_TRAV_ALL);
2081 objDataBytes = numObjects * sizeof(CGenDataRec);
2082 objData = (CGenData)util_malloc(objDataBytes);
2083 memset(objData, 0, objDataBytes);
2084 if (objData == NULL)
2086 util_printf_err(catgets(Dtb_project_catd, 1, 36,
2087 "Could not allocate cgen data\n"));
2092 * Assign a structure to each object
2094 for (trav_open(&trav, module, AB_TRAV_ALL), objCount = 0;
2095 (obj = trav_next(&trav)) != NULL; )
2097 if (obj->cgen_data == NULL)
2099 obj->cgen_data = (CGenData)&(objData[objCount++]);
2100 mfobj_set_flags(obj, CGenFlagDataIsObj);
2104 assert(objCount <= numObjects);
2107 * Create module-specific data
2109 ensure_data_for_module_obj(module);
2110 mfobj_get_module_data(module)->children_data = objData;
2117 * Makes sure the module has a cgen data associated with it. Will load
2118 * the objects in the module if necessary, if loadFile is TRUE.
2121 ensure_data_for_module_obj(ABObj module)
2123 CGenModuleData moduleData = NULL;
2124 ABObj project = NULL;
2125 ABObj newProject = NULL;
2127 if (!obj_is_module(module))
2131 project = obj_get_project(module);
2132 if (module->cgen_data == NULL)
2134 module->cgen_data = (CGenData)calloc(sizeof(CGenDataRec), 1);
2137 if (mfobj_get_module_data(module) == NULL)
2139 moduleData = (CGenModuleData)calloc(sizeof(CGenModuleDataRec), 1);
2140 moduleData->callbacks = strlist_create();
2141 mfobj_set_module_data(module, moduleData);
2151 dump_callbacks(ABObj project)
2153 ABObj module = NULL;
2154 AB_TRAVERSAL moduleTrav;
2155 StringList callbacks = NULL;
2157 util_dprintf(0, "\n***** CALLBACKS *****\n");
2158 util_dprintf(0, "project callbacks\n");
2159 callbacks = mfobj_get_proj_data(project)->callbacks;
2160 if (callbacks != NULL)
2162 strlist_dump(callbacks);
2164 for (trav_open(&moduleTrav, project, AB_TRAV_MODULES);
2165 (module = trav_next(&moduleTrav)) != NULL; )
2167 util_dprintf(0, "module '%s' callbacks\n", util_strsafe(obj_get_name(module)));
2168 callbacks = mfobj_get_module_data(module)->callbacks;
2169 if (callbacks != NULL)
2171 strlist_dump(callbacks);
2174 trav_close(&moduleTrav);
2175 util_dprintf(0,"\n");
2180 * Checks tree and aborts if an error is found.
2183 debug_verify_tree(ABObj root)
2195 util_dprintf(1, "Examining tree for defects.\n");
2198 * Do the standard verification
2200 if (obj_tree_verify(root) < 0)
2202 util_dprintf(1, "Project tree is corrupt! Aborting.\n");
2207 * Perform more code-generator specific checks
2209 for (trav_open(&trav, root, AB_TRAV_ALL);
2210 (obj = trav_next(&trav)) != NULL; )
2214 if ( (obj_get_write_me(obj_get_module(obj)))
2215 && (obj_get_name(obj) == NULL) )
2217 util_dprintf(1, "Object has no name: %s\n",
2218 obj_get_safe_name(obj, name, 256));
2231 #ifdef DEBUG /* performance testing */
2233 get_cur_time(double *realTimeOut, double *cpuTimeOut)
2235 long ticks_per_second = sysconf(_SC_CLK_TCK);
2236 struct tms timeInfo;
2237 double realTime = times(&timeInfo);
2238 double cpuTime = timeInfo.tms_utime + timeInfo.tms_stime
2239 + timeInfo.tms_cutime + timeInfo.tms_cstime;
2240 *realTimeOut = realTime / CLK_TCK;
2241 *cpuTimeOut = cpuTime / CLK_TCK;