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: ab_bil.c /main/3 1995/11/06 17:12:37 rswiston $
27 * @(#)ab_bil.c 1.85 22 May 1995
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement between
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel without
35 * Sun's specific written approval. This document and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 * File: ab_bil.c - functions dealing with bil files
47 #include <sys/times.h>
49 #include <sys/param.h> /* MAXPATHLEN */
51 #include <ab_private/obj.h>
52 #include <ab_private/trav.h>
53 #include <ab_private/bil.h>
54 #include <ab_private/objxm.h>
55 #include <ab_private/abobj.h>
56 #include <ab_private/abobj_set.h>
57 #include <ab_private/brws.h>
58 #include <ab_private/proj.h>
59 #include <ab_private/conn.h>
60 #include <ab_private/ui_util.h>
61 #include <ab_private/ab.h>
62 #include <ab_private/ab_bil.h>
63 #include "../libABobj/objP.h"
64 #include "palette_ui.h"
66 /* REMIND: #ifdef DEBUG */
71 double elapsedSeconds;
72 } ABTimedIntervalRec, *ABTimedInterval;
76 ABTimedIntervalRec realTime;
77 ABTimedIntervalRec CPUTime;
78 } ABProfiledIntervalRec, *ABProfiledInterval;
80 static int get_cur_times(double *realTimeOut, double *cpuTimeOut);
81 static int get_start_times(ABProfiledInterval);
82 static int get_end_times(ABProfiledInterval);
83 static int calc_elapsed_times(ABProfiledInterval);
84 static int print_load_stats(
86 ABProfiledInterval totalTime,
87 ABProfiledInterval loadTime,
88 ABProfiledInterval configTime
91 char Buf[MAXPATHLEN]; /* Work buffer */
94 * Loads in a new project, replacing the current project.
95 * Chdirs to the directory where the project is. Called
96 * from the 'File->Open Project' and 'Project->Open'
97 * (Project Organizer) menus, and the cmd-line (dtbuilder.c).
106 int rc = 0; /* return code */
107 ABObj newProject = NULL;
109 STRING init_msg = NULL;
110 STRING modfile = NULL;
112 ABProfiledIntervalRec totalTime;
113 ABProfiledIntervalRec loadTime;
114 ABProfiledIntervalRec configTime;
115 XmString xm_buf = (XmString) NULL;
118 STRING errmsg = NULL;
119 BOOL read_OK, write_OK;
122 get_start_times(&totalTime);
124 get_start_times(&loadTime);
125 rc = bil_load_file_and_resolve_all(fileName, inFile, &newProject);
126 if (newProject == NULL)
131 /* If BufferDrop is TRUE, then that means that
132 * ab_load_bil_file() is being called due to
133 * a buffer drop (i.e. a .bix dtmail attachment).
134 * In that case, we don't need to check whether
135 * the modules are read-only, since there aren't
136 * .bil files associated with the modules.
140 /* Check if any of the modules are read-only. If so, post
143 for (trav_open(&trav, newProject, AB_TRAV_MODULES);
144 (mod = trav_next(&trav)) != NULL; )
146 if (!obj_is_defined(mod))
151 modfile = obj_get_file(mod);
152 abio_access_file(modfile, &read_OK, &write_OK);
153 if (!write_OK && !util_strempty(modfile))
155 obj_set_read_only(mod, TRUE);
157 len = len + strlen(modfile) + 2;
159 ** Is this the first read-only file we've encountered?
160 ** If so, initialize the notice message.
164 /* The first thing in the message is
167 init_msg = catgets(Dtb_project_catd, 100, 38, "The following modules are read-only.\nIf you edit these modules, you\nwill not be able to save your edits.");
169 /* If we have an old buffer lying around, free it */
170 if (errmsg != (STRING) NULL)
173 /* Now create a new buffer of the proper size */
174 len = strlen(init_msg) + strlen(modfile) + 3;
175 errmsg = (STRING) util_malloc(len);
178 ** Put the general text plus name of the first
179 ** read-only file into the notice message.
181 sprintf(errmsg, "%s\n\n%s", init_msg, modfile);
185 errmsg = (STRING) realloc(errmsg, len);
186 strcat(errmsg, "\n");
187 strcat(errmsg, modfile);
194 if (!util_strempty(errmsg))
196 util_set_help_data(catgets(Dtb_project_catd, 100, 92,
197 "Any changes made to a read-only module cannot be saved,\nunless you save the module to a different file name."),
202 get_end_times(&loadTime);
204 if( obj_get_num_children(newProject) == 0 )
206 sprintf(Buf, catgets(Dtb_project_catd, 100, 23,
207 "%s: Empty project file loaded."), fileName);
208 xm_buf = XmStringCreateLocalized(Buf);
209 dtb_palette_empty_proj_msg_initialize(&dtb_palette_empty_proj_msg);
210 (void)dtb_show_modal_message(dtb_get_toplevel_widget(),
211 &dtb_palette_empty_proj_msg, xm_buf, NULL, NULL);
212 XmStringFree(xm_buf);
215 if (util_get_verbosity() >= 5)
216 obj_tree_print(newProject);
218 /* Destroy the old project, first. Then initialize
219 * the project to be the one just created. This
220 * also sets the current module to NULL, since a
221 * module has not been shown yet.
223 proj_destroy_project(proj_get_project());
224 proj_set_project(newProject);
226 /* REMIND: Check this out later */
228 get_start_times(&configTime);
229 objxm_tree_configure(newProject, OBJXM_CONFIG_BUILD);
230 get_end_times(&configTime);
232 abobj_update_proj_name(newProject);
233 abobj_update_palette_title(newProject);
234 obj_tree_update_clients(newProject);
237 get_end_times(&totalTime);
238 print_load_stats(newProject, &totalTime, &loadTime, &configTime);
253 int return_value = 0;
255 ABObj project = proj_get_project();
257 ABObjList loaded_comp_objs = NULL;
258 ABObj loaded_module = NULL;
262 * XmConfigured flags is not getting set properly. If it's already
263 * here, we'll assume it's configured.
265 for (trav_open(&trav, project, AB_TRAV_MODULES);
266 (module= trav_next(&trav)) != NULL; )
268 obj_set_flag(module, XmConfiguredFlag);
272 if (bil_load_file(fileName, inFile, project, &loaded_comp_objs)
279 /* loaded_module will point to the module that was
282 loaded_module = NULL;
283 if (objlist_get_num_objs(loaded_comp_objs) >= 1)
285 loaded_module = objlist_get_obj(loaded_comp_objs, 0, NULL);
288 if (loaded_module != NULL)
292 obj_set_file(loaded_module, (String) NULL);
294 else /* Import by reference */
296 /* Convert the imported module's file field to a
297 * path that is relative to the directory in which
298 * the project is stored.
300 file = proj_cvt_mod_file_to_rel_path(fileName,
301 obj_get_file(project));
302 obj_set_file(loaded_module, file);
307 * configure anything that's not marked as configured
309 abobj_show_tree(loaded_module, TRUE);
310 obj_tree_update_clients(loaded_module);
311 proj_set_cur_module(loaded_module);
315 objlist_destroy(loaded_comp_objs);
321 get_start_times(ABProfiledInterval interval)
323 return get_cur_times(&(interval->realTime.startSeconds),
324 &(interval->CPUTime.startSeconds));
329 get_end_times(ABProfiledInterval interval)
331 return get_cur_times(&(interval->realTime.endSeconds),
332 &(interval->CPUTime.endSeconds));
337 calc_elapsed_times(ABProfiledInterval interval)
339 interval->realTime.elapsedSeconds =
340 interval->realTime.endSeconds - interval->realTime.startSeconds;
341 interval->CPUTime.elapsedSeconds =
342 interval->CPUTime.endSeconds - interval->CPUTime.startSeconds;
347 /* REMIND: #ifdef DEBUG */
351 ABProfiledInterval totalTime,
352 ABProfiledInterval loadTime,
353 ABProfiledInterval configTime
356 ABProfiledIntervalRec otherTimeRec;
357 ABProfiledInterval otherTime = &otherTimeRec;
360 * Print out statistics about load
362 calc_elapsed_times(totalTime);
363 calc_elapsed_times(loadTime);
364 calc_elapsed_times(configTime);
365 otherTime->realTime.elapsedSeconds =
366 (totalTime->realTime.elapsedSeconds
367 - loadTime->realTime.elapsedSeconds
368 - configTime->realTime.elapsedSeconds);
369 otherTime->CPUTime.elapsedSeconds =
370 (totalTime->CPUTime.elapsedSeconds
371 - loadTime->CPUTime.elapsedSeconds
372 - configTime->CPUTime.elapsedSeconds);
374 fprintf(stderr, "\nLoad Times (Real/CPU) seconds:\n");
375 fprintf(stderr, " Total: (%lg/%lg)\n",
376 totalTime->realTime.elapsedSeconds,
377 totalTime->CPUTime.elapsedSeconds);
378 fprintf(stderr, " Actual load: (%lg/%lg)\n",
379 loadTime->realTime.elapsedSeconds,
380 loadTime->CPUTime.elapsedSeconds);
381 fprintf(stderr, " Config: (%lg/%lg)\n",
382 configTime->realTime.elapsedSeconds,
383 configTime->CPUTime.elapsedSeconds);
384 fprintf(stderr, " Other: (%lg/%lg)\n",
385 otherTime->realTime.elapsedSeconds,
386 otherTime->CPUTime.elapsedSeconds);
388 fprintf(stderr, "Number of objects loaded - salient:%d total:%d\n",
389 trav_count(tree, AB_TRAV_SALIENT),
390 trav_count(tree, AB_TRAV_ALL));
394 /* REMIND: #endif DEBUG */
398 get_cur_times(double *realTimeOut, double *cpuTimeOut)
400 static BOOL initialized = FALSE;
401 static long ticks_per_second = 1;
408 ticks_per_second = sysconf(_SC_CLK_TCK);
411 realTime = times(&timeInfo);
412 cpuTime = timeInfo.tms_utime + timeInfo.tms_stime
413 + timeInfo.tms_cutime + timeInfo.tms_cstime;
414 *realTimeOut = realTime / ticks_per_second;
415 *cpuTimeOut = cpuTime / ticks_per_second;
421 /* Called by the 'File->Open Project' callback and the
422 * 'Project->Open' callback. NOT called when a project
423 * is loaded from the command-line.
426 ab_check_and_open_bip(
430 DTB_MODAL_ANSWER answer = DTB_ANSWER_NONE;
431 BOOL read_OK, write_OK;
433 XmString xm_buf = (XmString) NULL;
434 DtbObjectHelpData help_data = NULL;
436 abio_access_file(fileName, &read_OK, &write_OK);
441 iRet = ab_load_project(fileName, NULL, FALSE);
443 else /* Read-only file */
445 /* You can read it but you can't write to it. */
446 sprintf(Buf, catgets(Dtb_project_catd, 100, 17,
447 "The file %s is a read-only file.\nYou may open the project\nor cancel the operation."), fileName);
448 xm_buf = XmStringCreateLocalized(Buf);
449 dtb_palette_open_ro_proj_msg_initialize(
450 &dtb_palette_open_ro_proj_msg);
452 help_data = (DtbObjectHelpData) util_malloc(sizeof(DtbObjectHelpDataRec));
453 help_data->help_text = catgets(Dtb_project_catd, 100, 90,
454 "Opening a read-only project means that any changes that\naffect the project (.bip) file, such as creation of a\nnew module or creation of a cross-module connection,\ncannot be saved, unless you save the project to a\ndifferent file name. You have the option of continuing\nwith the open operation or cancelling it.");
455 help_data->help_volume = "";
456 help_data->help_locationID = "";
458 answer = dtb_show_modal_message(dtb_get_toplevel_widget(),
459 &dtb_palette_open_ro_proj_msg, xm_buf, help_data, NULL);
461 util_free(help_data);
462 XmStringFree(xm_buf);
465 case DTB_ANSWER_ACTION1:
466 iRet = ab_load_project(fileName, NULL, FALSE);
469 case DTB_ANSWER_CANCEL:
472 case DTB_ANSWER_HELP:
479 sprintf(Buf, catgets(Dtb_project_catd, 100, 20,
480 "%s does not have read permission."), fileName);
481 xm_buf = XmStringCreateLocalized(Buf);
482 dtb_palette_error_msg_initialize(&dtb_palette_error_msg);
483 (void)dtb_show_modal_message(dtb_get_toplevel_widget(),
484 &dtb_palette_error_msg, xm_buf, NULL, NULL);
485 XmStringFree(xm_buf);
501 ab_set_busy_cursor(TRUE);
502 ui_sync_display_of_widget(AB_toplevel);
504 if ((ret = ab_load_bil_file(fileName, inFile, BufferDrop)) != -1)
506 proj_show_proj_dir();
507 objxm_tree_configure(proj_get_project(), OBJXM_CONFIG_BUILD);
508 /* Popup the Project Organizer */
512 ab_set_busy_cursor(FALSE);
517 /* Calls ab_import_bil_file(). Called by the File->Import->Module
518 * callback and the Module->Import callback. NOT called when
519 * a project is loaded from the command-line.
522 ab_check_and_import_bil(
527 BOOL read_OK, write_OK;
528 DTB_MODAL_ANSWER answer = DTB_ANSWER_NONE;
529 ABObj project = proj_get_project();
531 XmString xm_buf = (XmString) NULL;
532 DtbObjectHelpData help_data = NULL;
534 abio_access_file(fileName, &read_OK, &write_OK);
539 iRet = ab_import_module(fileName, NULL, TRUE);
541 else /* Importing by Reference. Have to check permissions. */
545 /* The file is readable and writable, can be opened,
546 * and is a valid module file, so import it.
548 iRet = ab_import_module(fileName, NULL, FALSE);
552 /* You can read it but you can't write to it. */
553 sprintf(Buf, catgets(Dtb_project_catd, 100, 21,
554 "The file %s is a read-only file.\n\
555 You may import the module or cancel\n\
556 the operation."), fileName);
557 xm_buf = XmStringCreateLocalized(Buf);
558 dtb_palette_import_ro_msg_initialize(
559 &dtb_palette_import_ro_msg);
561 help_data = (DtbObjectHelpData) util_malloc(sizeof(DtbObjectHelpDataRec));
562 help_data->help_text = catgets(Dtb_project_catd, 100, 91,
563 "Importing a read-only module means that any changes\nthat affect the module cannot be saved, unless you\nsave the module to a different file name. You have\nthe option of continuing with the import operation\nor cancelling it.");
565 help_data->help_volume = "";
566 help_data->help_locationID = "";
568 answer = dtb_show_modal_message(dtb_get_toplevel_widget(),
569 &dtb_palette_import_ro_msg, xm_buf, help_data, NULL);
571 util_free(help_data);
572 XmStringFree(xm_buf);
575 case DTB_ANSWER_ACTION1:
576 iRet = ab_import_module(fileName, NULL, ImportByCopy);
579 case DTB_ANSWER_CANCEL:
580 case DTB_ANSWER_HELP:
588 sprintf(Buf, catgets(Dtb_project_catd, 100, 9,
589 "%s does not have read permission."), fileName);
590 xm_buf = XmStringCreateLocalized(Buf);
591 dtb_palette_error_msg_initialize(&dtb_palette_error_msg);
592 (void)dtb_show_modal_message(dtb_get_toplevel_widget(),
593 &dtb_palette_error_msg, xm_buf, NULL, NULL);
594 XmStringFree(xm_buf);
610 ab_set_busy_cursor(TRUE);
611 ui_sync_display_of_widget(AB_toplevel);
613 iRet = ab_import_bil_file(fileName, inFile, ImportByCopy);
616 abobj_set_save_needed(proj_get_project(), TRUE);
618 ab_set_busy_cursor(FALSE);