4943a5f65305fbdabea037933158644df5fc5f62
[oweals/cde.git] / cde / programs / dtfile / Main.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: Main.c /main/29 1999/09/17 13:35:04 mgreess $ */
24 /************************************<+>*************************************
25  ****************************************************************************
26  *
27  *   FILE:           Main.c
28  *
29  *   COMPONENT_NAME: Desktop File Manager (dtfile)
30  *
31  *   Description:    This file contains the main program for dtfile.
32  *                   It also contains functions for session management and
33  *                   directory view control.
34  *
35  *   FUNCTIONS: BlackPixelOfScreen
36  *              BuildAndShowIconName
37  *              CheckForOpenDirectory
38  *              CheckOpenDir
39  *              CleanUp
40  *              CloseView
41  *              DirectoryChanged
42  *              DisplayHeight
43  *              DisplayWidth
44  *              DtfileCvtStringToDTIcon
45  *              DtfileCvtStringToDirection
46  *              DtfileCvtStringToGrid
47  *              DtfileCvtStringToObjPlace
48  *              DtfileCvtStringToOpenDir
49  *              DtfileCvtStringToOrder
50  *              DtfileCvtStringToTree
51  *              DtfileCvtStringToTreeFiles
52  *              DtfileCvtStringToView
53  *              DtfileStringToDirection
54  *              DtfileStringToGrid
55  *              DtfileStringToOrder
56  *              DtfileStringToTree
57  *              DtfileStringToTreeFiles
58  *              DtfileStringToView
59  *              ErrorHandler
60  *              ExitApp
61  *              ExitHandler
62  *              ForceMyIconClosed
63  *              ForceMyIconOpen
64  *              GetNewView
65  *              GetPWD
66  *              GetRestrictedDirectory
67  *              HandleTtRequest
68  *              LoadViews
69  *              MarqueeSelect
70  *              MoveDefaultSettings
71  *              ObserveTtNotice
72  *              OpenDirectories
73  *              ReloadDatabases
74  *              RemoveTextFields
75  *              RestoreSession
76  *              RestoreSettingsFile
77  *              RestrictModeUsage
78  *              ReturnDesktopPtr
79  *              RootWindowOfScreen
80  *              SaveDefaultCancelCB
81  *              SaveDefaultOkCB
82  *              SaveSession
83  *              SaveSessionCallback
84  *              SaveSettingsCB
85  *              SetupSendRequestArgs
86  *              Stop
87  *              ToolkitErrorHandler
88  *              Usage
89  *              ViewAccept
90  *              ViewDirectoryHandler
91  *              ViewDirectoryProc
92  *              ViewHomeDirectoryHandler
93  *              ViewSessionHandler
94  *              ViewToolsDirectoryHandler
95  *              WaitForResponseAndExit
96  *              WhitePixelOfScreen
97  *              XtMalloc
98  *              _DtNextToken
99  *              _DtWsmAddMarqueeSelectionCallback
100  *              if
101  *              main
102  *              strcmp
103  *              strlen
104  *
105  *   (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
106  *   (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
107  *   (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
108  *   (c) Copyright 1993, 1994, 1995 Novell, Inc.
109  *
110  ****************************************************************************
111  ************************************<+>*************************************/
112
113 #include <sys/types.h>
114 #include <stdio.h>
115 #include <stdlib.h>
116 #include <sys/stat.h>
117 #include <signal.h>
118
119 #if defined(CSRG_BASED)
120 #include <sys/wait.h>
121 #endif /* CSRG_BASED */
122
123 #include <errno.h>
124 #include <pwd.h>
125 #include <stdlib.h>
126 #include <ctype.h>
127
128 #ifndef sun /* don't need the nl_types.h file */
129 #include <nl_types.h>
130 #endif /* !sun */
131
132 #include <locale.h>
133
134 #include <Xm/XmP.h>
135 #include <Xm/DrawingA.h>
136 #include <Xm/DrawingAP.h>
137 #include <Xm/MessageB.h>
138 #include <Xm/RowColumn.h>
139 #include <Xm/MwmUtil.h>
140
141 #include <Xm/IconFileP.h>
142 #include <Dt/Icon.h>
143 #include <Dt/IconP.h>
144 #include <Dt/IconFile.h>
145
146 #include <Dt/HelpDialog.h>
147
148 #ifdef SHAPE
149 #include <X11/extensions/shape.h>
150 #endif
151
152 #include <X11/Shell.h>
153 #include <X11/Xatom.h>
154 #include <Xm/Protocols.h>
155 #ifdef HAVE_EDITRES
156 #include <X11/Xmu/Editres.h>
157 #endif
158 #include <Dt/Session.h>
159 #include <Dt/Dt.h>
160 #include <Dt/DtP.h>
161 #include <Dt/Connect.h>
162 #include <Dt/FileM.h>
163 #include <Dt/Indicator.h>
164 #include <Dt/Lock.h>
165 #include <Dt/UserMsg.h>
166 #include <Dt/Wsm.h>
167 #include <Dt/WsmP.h>
168 #include <Dt/DtNlUtils.h>
169 #include <Dt/CommandM.h>
170 #include <Dt/EnvControlP.h>
171 #include <Dt/Dts.h>
172 #include <Dt/SharedProcs.h>
173
174 #include "Encaps.h"
175 #include "SharedProcs.h"
176
177 #include <Tt/tttk.h>
178
179 #include "Help.h"
180 #include "FileMgr.h"
181 #include "Desktop.h"
182 #include "Main.h"
183 #include "ChangeDir.h"
184 #include "Prefs.h"
185 #include "Common.h"
186 #include "Filter.h"
187 #include "Find.h"
188 #include "ModAttr.h"
189
190 /* From Command.c */
191 extern void MoveCopyLinkHandler(Tt_message ttMsg, int opType);
192
193 /* From Desktop.c */
194 extern void PutOnWorkspaceHandler(Tt_message ttMsg);
195
196 /* From Filter.c */
197 extern void UpdateFilterAfterDBReread (DialogData * dialog_data);
198
199 /* From ToolTalk.c */
200 extern int InitializeToolTalkSession( Widget topLevel, int ttFd );
201 extern Tt_status InitializeToolTalkProcid( int *ttFd, Widget topLevel, Boolean sendStarted );
202 extern void FinalizeToolTalkSession();
203 /* From Trash.c */
204 void CloseTrash(Widget w, XtPointer client_data, XtPointer call_data) ;
205
206
207
208 /* When openDir resource is set to NEW
209    File Manager will use this prefix to find for a different icon
210    to display.
211 */
212 #define ICON_OPEN_PREFIX "OPEN_"
213
214 /* THESE ARE ONLY STRINGS WHICH DO NOT NEED TO BE LOCALIZED */
215 /* Don't use '#define' since you end up with multiple copies */
216 char DTFILE_CLASS_NAME[] = "Dtfile";
217 char DTFILE_HELP_NAME[] = "Filemgr";
218 char DESKTOP_DIR[] = ".dt/Desktop";
219
220 static char WS_RES_HEADER[] = ".Workspace.";
221 static char SEC_HELP_RES_HEADER[] = ".secondaryHelpDialogCount: ";
222 static char WS_LOAD_RES_HEADER[] = "Workspace";
223 static char SEC_LOAD_HELP_RES_HEADER[] = "secondaryHelpDialogCount";
224 static char RESTRICTED_HEADER[] = "-restricted";
225 static char VIEW_HEADER[] = "-view";
226
227
228 /*  Structure, resource definitions, for View's optional parameters.  */
229
230 typedef struct
231 {
232    char * no_view;
233    char * session;
234    char * directories;
235    int tree_view;
236    int tree_files;
237    int view;
238    int order;
239    int direction;
240    int grid;
241    int instanceIconWidth;
242    int instanceIconHeight;
243    XmFontList user_font;
244    Dimension tool_width;
245    Dimension tool_height;
246    Dimension dir_width;
247    Dimension dir_height;
248    Boolean prompt_user;
249    char * root_title;
250    char * title;
251    char * help_volume;
252    char * restricted;
253    int dragThreshold;
254    int rereadTime;
255    int checkBrokenLink;
256    int maxDirectoryProcesses;
257    int maxRereadProcesses;
258    int maxRereadProcsPerTick;
259    int trashWait;
260    int desktopIconType;
261    Boolean showFilesystem;
262    Boolean showDropZone;
263    Boolean showEmptySet;
264    Boolean showEmptyMsg;
265    int openDirType;
266    Boolean restrictMode;
267    int desktopPlacement;
268    Boolean freezeOnConfig;
269 #if defined(__hpux) || defined(sun)
270    Boolean follow_links;
271 #endif
272    char * fileMgrIcon;
273    char * appMgrIcon;
274    char * trashIcon;
275    int retryLoadDesktop;
276    int smallIconWidth;
277    int smallIconHeight;
278    int largeIconWidth;
279    int largeIconHeight;
280    Boolean emptyTrashOnExit;
281 } ApplicationArgs, *ApplicationArgsPtr;
282
283 static ApplicationArgs application_args;
284
285 /********    Static Function Declarations    ********/
286
287 static void ErrorHandler(
288                         Display *disp,
289                         XErrorEvent *event) ;
290 static void ToolkitErrorHandler(
291                         char *message) ;
292 static void Usage(
293                         char **argv) ;
294 static void RestrictModeUsage(
295                         char **argv) ;
296 static void Stop( void ) ;
297 static void RestoreSettingsFile( void ) ;
298 static void MoveDefaultSettings(
299                         int mode) ;
300 static void SaveDefaultCancelCB(
301                         Widget w,
302                         XtPointer client_data,
303                         XtPointer call_data) ;
304 static void SaveDefaultOkCB(
305                         Widget w,
306                         XtPointer client_data,
307                         XtPointer call_data) ;
308 static void SaveSession(
309                         char *path) ;
310 static int RestoreSession(
311                         char *path,
312                         int type_of_restore,
313                         char *directory) ;
314 static void GetPWD(
315                         char current_directory[]) ;
316 static void OpenDirectories(
317                         char *directory_set,
318                         char *type) ;
319 static Tt_callback_action ObserveTtNotice(
320                         Tt_message msg,
321                         Tt_pattern pat) ;
322 static void ViewSessionHandler(
323                         Tt_message msg);
324 static void ViewDirectoryHandler(
325                         Tt_message msg);
326 static void ViewHomeDirectoryHandler(
327                         Tt_message msg);
328 static void ViewToolsDirectoryHandler(
329                         Tt_message msg);
330 static void ExitHandler(
331                         Tt_message msg,
332                         XtPointer clientData,
333                         String * messageFields,
334                         int numFields);
335 static void ReloadDatabases( void );
336 static void ViewAccept(
337                         View *view,
338                         Tt_message msg);
339 static void LoadViews (
340                         int num_views,
341                         XrmDatabase db,
342                         char *host_name,
343                         char *directory_name,
344                         char *type,
345                         Tt_message msg);
346 static void RemoveTextFields (
347                         XtPointer client_data,
348                         DialogData * old_dialog_data,
349                         DialogData * new_dialog_data) ;
350 static void DtfileCvtStringToObjPlace (
351                         XrmValue *args,
352                         Cardinal numArgs,
353                         XrmValue *fromVal,
354                         XrmValue *toVal) ;
355 static unsigned char *_DtNextToken (
356                         unsigned char *pchIn,
357                         int *pLen,
358                         unsigned char **ppchNext) ;
359 static void DtfileCvtStringToOpenDir (
360                         XrmValue *args,
361                         Cardinal numArgs,
362                         XrmValue *fromVal,
363                         XrmValue *toVal) ;
364 static void DtfileCvtStringToDTIcon (
365                         XrmValue *args,
366                         Cardinal numArgs,
367                         XrmValue *fromVal,
368                         XrmValue *toVal) ;
369 static void DtfileCvtStringToTree (
370                         XrmValue *args,
371                         Cardinal numArgs,
372                         XrmValue *fromVal,
373                         XrmValue *toVal) ;
374 static void DtfileCvtStringToTreeFiles (
375                         XrmValue *args,
376                         Cardinal numArgs,
377                         XrmValue *fromVal,
378                         XrmValue *toVal) ;
379 static void DtfileCvtStringToView (
380                         XrmValue *args,
381                         Cardinal numArgs,
382                         XrmValue *fromVal,
383                         XrmValue *toVal) ;
384 static void DtfileCvtStringToOrder (
385                         XrmValue *args,
386                         Cardinal numArgs,
387                         XrmValue *fromVal,
388                         XrmValue *toVal) ;
389 static void DtfileCvtStringToDirection (
390                         XrmValue *args,
391                         Cardinal numArgs,
392                         XrmValue *fromVal,
393                         XrmValue *toVal) ;
394 static void DtfileCvtStringToGrid (
395                         XrmValue *args,
396                         Cardinal numArgs,
397                         XrmValue *fromVal,
398                         XrmValue *toVal) ;
399 static void DtfileStringToTree(
400                         char *str,
401                         int *type) ;
402 static void DtfileStringToTreeFiles(
403                         char *str,
404                         int *type) ;
405 static void DtfileStringToView(
406                         char *str,
407                         int *type) ;
408 static void DtfileStringToOrder(
409                         char *str,
410                         int *type) ;
411 static void DtfileStringToDirection(
412                         char *str,
413                         int *type) ;
414 static void DtfileStringToGrid(
415                         char *str,
416                         int *type) ;
417 static void SetupSendRequestArgs(
418                         ApplicationArgs application_args,
419                         Tt_message msg) ;
420 static void BuildAndShowIconName(
421                         char *file_type_name,
422                         unsigned char view,
423                         unsigned char show_type,
424                         Widget widget) ;
425 static void MarqueeSelect (
426                         Widget w,
427                         int type,
428                         Position x,
429                         Position y,
430                         Dimension width,
431                         Dimension height,
432                         XtPointer client_data);
433 static void WaitForResponseAndExit( void ) ;
434 static void ExitApp(
435                         XtPointer clientData,
436                         String *words,
437                         int num_fields) ;
438 static Widget post_dialog(
439                         Widget parent,
440                         char *title,
441                         char *msg,
442                         void (*callback)());
443 static void DtErrExitCB(
444                         Widget widget,
445                         XtPointer client_data,
446                         XtPointer call_data);
447
448 /********    End Static Function Declarations    ********/
449
450 /*  debugging flag  */
451 #ifdef DEBUG
452 int debug = 0;
453 #endif
454
455 /*  performance flag  */
456 #ifdef DT_PERFORMANCE
457 int perform = 0;
458 #endif
459
460 /*  The id's of the dialogs registered by main  */
461
462 int file_mgr_dialog;
463 int change_dir_dialog;
464 int preferences_dialog;
465 int filter_dialog;
466 int find_dialog;
467 int mod_attr_dialog;
468 int help_dialog;
469
470 /* The shared menu button and pane Id's */
471
472 Widget * create_dataBtn;
473 Widget * renameBtn;
474 Widget * moveBtn;
475 Widget * duplicateBtn;
476 Widget * linkBtn;
477 Widget * findBtn;
478 Widget * create_directoryBtn;
479 Widget * change_directoryBtn;
480 Widget * showHiddenMenu;
481 Widget * preferencesBtn;
482 Widget * filterBtn;
483 Widget * defaultEnvBtn;
484 Widget * homeBarBtn;
485 Widget * upBarBtn;
486 Widget * newViewBtn;
487 Widget * cleanUpBtn;
488 Widget * separator1;
489 Widget * separator2;
490 Widget * terminalBtn;
491 Widget * usingHelp = NULL;
492 Widget * fileManagerHelp = NULL;
493 Widget * applicationManagerHelp = NULL;
494 Widget * usingHelpTrash = NULL;
495
496
497 /* Bitmask used to indicate the current sensitivity state of shared menu btns */
498
499 unsigned int currentMenuStates = ( RENAME | MOVE | DUPLICATE | LINK | TRASH |
500                                  MODIFY | CHANGEDIR | PREFERENCES | FILTER |
501                                  FIND | CREATE_DIR | CREATE_FILE |
502                                  PUT_ON_DESKTOP | PUTBACK |
503                                  CLEAN_UP | MOVE_UP |
504                                  HOME | CHANGE_DIR | TERMINAL);
505
506 /* Drag manager globals */
507 Boolean b1Drag;
508 Boolean dragActive = False;
509
510 /* Desktop Globals */
511 int numColumns;
512 int numRows;
513
514 /*  Globally referenced application name.  Set to argv[0] in main  */
515
516 char * application_name = NULL;
517
518
519 /*  uid for root user; used when we are checking access permissions  */
520
521 long root_user = -1;
522
523
524 /*  Home host name  */
525
526 char home_host_name[MAX_PATH];
527 char users_home_dir[MAX_PATH];
528
529
530 /*  Toolbox directory  */
531
532 char * desktop_dir = NULL;
533 char * trash_dir = NULL;
534 char * remote_sys_dir = NULL;
535
536 /* Restor type */
537
538 int restoreType = NORMAL_RESTORE;
539
540
541 /*  Black and White pixels  */
542
543 Pixel black_pixel;
544 Pixel white_pixel;
545
546
547 /*  File manager view set before a new view is created and   */
548 /*  used to propagate visual attributes from the initiating  */
549 /*  view to the new view.                                    */
550
551 XtPointer initiating_view = NULL;
552 Boolean special_view = False;
553 Boolean TrashView = False;
554
555
556 /*  system wide user font  */
557
558 XmFontList user_font;
559
560
561 /* Global localizable strings */
562
563 String openInPlace;
564 String openNewView;
565
566
567 /* Global dialog button labels, as XmStrings */
568
569 XmString okXmString;
570 XmString cancelXmString;
571 XmString helpXmString;
572 XmString applyXmString;
573 XmString closeXmString;
574
575
576 /* Global top level widget  */
577
578 Widget toplevel;
579
580 /* Global Application resources */
581 Boolean showFilesystem;
582 Boolean showDropZone;
583 Boolean showEmptySet;
584 Boolean showEmptyMsg;
585 Boolean restrictMode;
586 int openDirType;
587 char *root_title;
588 char *fileMgrTitle;
589 char *fileMgrHelpVol;
590 int desktopIconType;
591 int rereadTime;
592 int checkBrokenLink;
593 int trashWait;
594 int desktopPlacement;
595 Boolean freezeOnConfig;
596 #if defined(__hpux) || defined(sun)
597 Boolean follow_links;
598 #endif
599 int treeType;
600 int treeFiles;
601 int viewType;
602 int orderType;
603 int directionType;
604 int randomType;
605 int instanceWidth;
606 int instanceHeight;
607 unsigned char keybdFocusPolicy;
608 int special_treeType;
609 int special_treeFiles;
610 int special_viewType;
611 int special_orderType;
612 int special_directionType;
613 int special_randomType;
614 char *special_restricted;
615 char *special_title;
616 char *special_helpVol;
617 char *fileMgrIcon;
618 char *appMgrIcon;
619 char *trashIcon;
620 int retryLoadDesktopInfo;
621
622 int smallIconWidth;
623 int smallIconHeight;
624 int largeIconWidth;
625 int largeIconHeight;
626
627 Boolean emptyTrashOnExit;
628
629 #ifdef SHAPE
630 Boolean shapeExtension;
631 #endif
632
633 /* Drag state variables */
634 Boolean B1DragPossible = False;
635 Boolean B2DragPossible = False;
636 Boolean ProcessBtnUp = False;
637 Boolean ProcessBtnUpCD = True;
638 int initialDragX;
639 int initialDragY;
640 int dragThreshold;
641 int xErrorDetected = False;
642
643 /* BMenu button binding */
644 int bMenuButton;
645
646 View ** view_set = NULL;
647 int view_count = 0;
648 int view_set_size = 0;
649
650 /*  Globals used within this file.  */
651
652 static Display * display;
653 char * dt_path = NULL;
654 static Boolean message_display_enabled = True;
655
656
657 static Atom save_yourself_atom;
658 static Atom command_atom;
659 static Atom wm_state_atom;
660 static Atom save_mode;
661
662 /*  Structure used on a save session to see if a dt is iconic  */
663
664 typedef struct
665 {
666    int state;
667    Window icon;
668 } WM_STATE;
669
670
671 /*  Application resource list definition  */
672
673 static XrmOptionDescRec option_list[] =
674 {
675    {  "-noview",            "noView",          XrmoptionIsArg,   NULL  },
676    {  "-session",           "session",         XrmoptionSepArg,  NULL  },
677    {  "-dir",               "folder",          XrmoptionSepArg,  NULL  },
678    {  "-folder",            "folder",          XrmoptionSepArg,  NULL  },
679    {  "-tree",              "treeView",        XrmoptionSepArg,  NULL  },
680    {  "-tree_files",        "treeFiles",       XrmoptionSepArg,  NULL  },
681    {  VIEW_HEADER,          "view",            XrmoptionSepArg,  NULL  },
682    {  "-order",             "order",           XrmoptionSepArg,  NULL  },
683    {  "-direction",         "direction",       XrmoptionSepArg,  NULL  },
684    {  "-grid",              "grid",            XrmoptionSepArg,  NULL  },
685    {  RESTRICTED_HEADER,    "restricted",      XrmoptionIsArg,   NULL  },
686    {  "-title",             "title",           XrmoptionSepArg,  NULL  },
687    {  "-help_volume",       "help_volume",     XrmoptionSepArg,  NULL  },
688    {  "-noprompt",          "promptUser",      XrmoptionNoArg,  "False"  },
689    {  "-small_icon_width",  "smallIconWidth",  XrmoptionSepArg,  NULL  },
690    {  "-small_icon_height", "smallIconHeight", XrmoptionSepArg,  NULL  },
691    {  "-large_icon_width",  "largeIconWidth",  XrmoptionSepArg,  NULL  },
692    {  "-large_icon_height", "largeIconHeight", XrmoptionSepArg,  NULL  },
693 };
694
695
696 static XtResource resources[] =
697 {
698    {
699      "noView", "NoView", XmRString, sizeof (char *),
700      XtOffset (ApplicationArgsPtr, no_view), XmRImmediate, (XtPointer) NULL,
701    },
702
703    {
704      "session", "Session", XmRString, sizeof (char *),
705      XtOffset (ApplicationArgsPtr, session), XmRImmediate, (XtPointer) NULL,
706    },
707
708    {
709      "folder", "Folder", XmRString, sizeof (char *),
710      XtOffset (ApplicationArgsPtr, directories), XmRImmediate, (XtPointer) NULL,
711    },
712
713    {
714      "treeView", "TreeView", "Tree", sizeof (int),
715      XtOffset (ApplicationArgsPtr, tree_view), XmRImmediate,
716      (XtPointer) UNSET_VALUE,
717    },
718
719    {
720      "treeFiles", "TreeFiles", "TreeFiles", sizeof (int),
721      XtOffset (ApplicationArgsPtr, tree_files), XmRImmediate,
722      (XtPointer) UNSET_VALUE,
723    },
724
725    {
726      "view", "View", "View", sizeof (int),
727      XtOffset (ApplicationArgsPtr, view), XmRImmediate, (XtPointer) UNSET_VALUE,
728    },
729
730    {
731      "order", "Order", "Order", sizeof (int),
732      XtOffset (ApplicationArgsPtr, order), XmRImmediate, (XtPointer) UNSET_VALUE,
733    },
734
735    {
736      "direction", "Direction", "Direction", sizeof (int),
737      XtOffset (ApplicationArgsPtr, direction), XmRImmediate,
738      (XtPointer) UNSET_VALUE,
739    },
740
741    {
742      "grid", "Grid", "Grid", sizeof (int),
743      XtOffset (ApplicationArgsPtr, grid), XmRImmediate, (XtPointer) UNSET_VALUE,
744    },
745
746    {
747      "instanceIconWidth", "InstanceIconWidth", XmRInt, sizeof (int),
748      XtOffset (ApplicationArgsPtr, instanceIconWidth), XmRImmediate,
749      (XtPointer) 256,
750    },
751
752    {
753      "instanceIconHeight", "InstanceIconHeight", XmRInt, sizeof (int),
754      XtOffset (ApplicationArgsPtr, instanceIconHeight), XmRImmediate,
755      (XtPointer) 256,
756    },
757
758    {
759      "restricted", "Restricted", XmRString, sizeof (char *),
760      XtOffset (ApplicationArgsPtr, restricted), XmRImmediate, (XtPointer) NULL,
761    },
762
763    {
764      "title", "Title", XmRString, sizeof (char *),
765      XtOffset (ApplicationArgsPtr, title), XmRImmediate, (XtPointer)NULL,
766    },
767
768    {
769      "help_volume", "Help_volume", XmRString, sizeof (char *),
770      XtOffset (ApplicationArgsPtr, help_volume), XmRImmediate, (XtPointer)NULL,
771    },
772
773    {
774      "userFont", "XmCFontList", XmRFontList, sizeof (XmFontList),
775      XtOffset (ApplicationArgsPtr, user_font), XmRString, (XtPointer) "Fixed",
776    },
777
778    {
779      "toolWidth", "ToolWidth", XmRHorizontalDimension, sizeof (Dimension),
780      XtOffset (ApplicationArgsPtr, tool_width), XmRImmediate, (XtPointer) 700,
781    },
782
783    {
784      "toolHeight", "ToolHeight", XmRVerticalDimension, sizeof (Dimension),
785      XtOffset (ApplicationArgsPtr, tool_height), XmRImmediate, (XtPointer) 250,
786    },
787
788    {
789      "dirWidth", "DirWidth", XmRHorizontalDimension, sizeof (Dimension),
790      XtOffset (ApplicationArgsPtr, dir_width), XmRImmediate, (XtPointer) 555,
791    },
792
793    {
794      "dirHeight", "DirHeight", XmRVerticalDimension, sizeof (Dimension),
795      XtOffset (ApplicationArgsPtr, dir_height), XmRImmediate, (XtPointer) 400,
796    },
797
798    {
799      "promptUser", "PromptUser", XmRBoolean, sizeof (Boolean),
800      XtOffset (ApplicationArgsPtr, prompt_user), XmRImmediate, (XtPointer) True,
801    },
802
803    {
804      "rootTitle", "RootTitle", XmRString, sizeof (char *),
805      XtOffset (ApplicationArgsPtr, root_title), XmRImmediate, (XtPointer)"ROOT",
806    },
807
808    {
809      "moveThreshold", "MoveThreshold", XmRInt, sizeof (int),
810      XtOffset (ApplicationArgsPtr, dragThreshold), XmRImmediate, (XtPointer) 4,
811    },
812
813    {
814      "rereadTime", "RereadTime", XmRInt, sizeof (int),
815      XtOffset (ApplicationArgsPtr, rereadTime), XmRImmediate, (XtPointer) 3,
816    },
817
818    {
819      "checkBrokenLink", "CheckBrokenLink", XmRInt, sizeof (int),
820      XtOffset (ApplicationArgsPtr, checkBrokenLink), XmRImmediate,
821      (XtPointer) 180,
822    },
823
824    {
825      "maxDirectoryProcesses", "MaxDirectoryProcesses", XmRInt, sizeof (int),
826      XtOffset (ApplicationArgsPtr, maxDirectoryProcesses), XmRImmediate,
827      (XtPointer) 10,
828    },
829
830    {
831      "maxRereadProcesses", "MaxRereadProcesses", XmRInt, sizeof (int),
832      XtOffset (ApplicationArgsPtr, maxRereadProcesses), XmRImmediate,
833      (XtPointer) 5,
834    },
835
836    {
837      "maxRereadProcsPerTick", "MaxRereadProcsPerTick", XmRInt, sizeof (int),
838      XtOffset (ApplicationArgsPtr, maxRereadProcsPerTick), XmRImmediate,
839      (XtPointer) 1,
840    },
841
842    {
843      "trashWait", "TrashWait", XmRInt, sizeof (int),
844      XtOffset (ApplicationArgsPtr, trashWait), XmRImmediate, (XtPointer) 1,
845    },
846
847    {
848      "desktopIcon", "DesktopIcon", "DesktopIcon", sizeof (int),
849      XtOffset (ApplicationArgsPtr, desktopIconType), XmRImmediate,
850      (XtPointer)LARGE,
851    },
852
853    {
854      "showFilesystem", "ShowFilesystem", XmRBoolean, sizeof (Boolean),
855      XtOffset (ApplicationArgsPtr, showFilesystem), XmRImmediate,
856      (XtPointer)True,
857    },
858
859    {
860      "showDropZone", "ShowDropZone", XmRBoolean, sizeof (Boolean),
861      XtOffset (ApplicationArgsPtr, showDropZone), XmRImmediate,
862      (XtPointer)False,
863    },
864
865    {
866      "showEmptySet", "ShowEmptySet", XmRBoolean, sizeof (Boolean),
867      XtOffset (ApplicationArgsPtr, showEmptySet), XmRImmediate,
868      (XtPointer)False,
869    },
870
871    {
872      "showEmptyMsg", "ShowEmptyMsg", XmRBoolean, sizeof (Boolean),
873      XtOffset (ApplicationArgsPtr, showEmptyMsg), XmRImmediate,
874      (XtPointer)False,
875    },
876
877    {
878      "openFolder", "OpenFolder", "OpenFolder", sizeof (int),
879      XtOffset (ApplicationArgsPtr, openDirType), XmRImmediate,
880      (XtPointer)CURRENT,
881    },
882
883    {
884      "restrictMode", "RestrictMode", XmRBoolean, sizeof (Boolean),
885      XtOffset (ApplicationArgsPtr, restrictMode), XmRImmediate,
886      (XtPointer)False,
887    },
888
889    {
890      "objectPlacement", "ObjectPlacement", "ObjectPlacement", sizeof (int),
891      XtOffset (ApplicationArgsPtr, desktopPlacement), XmRImmediate,
892      (XtPointer)(OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_RIGHT_SECONDARY),
893    },
894
895    {
896      "freezeOnConfig", "FreezeOnConfig", XmRBoolean, sizeof (Boolean),
897      XtOffset (ApplicationArgsPtr, freezeOnConfig), XmRImmediate,
898      (XtPointer)True,
899    },
900
901    {
902      "fileManagerIcon", "FileManagerIcon", XmRString, sizeof (char *),
903      XtOffset (ApplicationArgsPtr, fileMgrIcon), XmRImmediate,
904      (XtPointer) HOME_ICON_NAME,
905    },
906
907    {
908      "appManagerIcon", "AppManagerIcon", XmRString, sizeof (char *),
909      XtOffset (ApplicationArgsPtr, appMgrIcon), XmRImmediate,
910      (XtPointer) TOOL_ICON_NAME,
911    },
912
913    {
914      "trashIcon", "TrashIcon", XmRString, sizeof (char *),
915      XtOffset (ApplicationArgsPtr, trashIcon), XmRImmediate,
916      (XtPointer) TRASH_ICON_NAME,
917    },
918
919    {
920      "retryLoadDesktop", "RetryLoadDesktop", XmRInt, sizeof (int),
921      XtOffset (ApplicationArgsPtr, retryLoadDesktop), XmRImmediate,
922      (XtPointer) 10,
923    },
924
925    {
926      "smallIconWidth", "SmallIconWidth", XmRInt, sizeof (int),
927      XtOffset (ApplicationArgsPtr, smallIconWidth), XmRImmediate,
928      (XtPointer) 24,
929    },
930
931    {
932      "smallIconHeight", "SmallIconHeight", XmRInt, sizeof (int),
933      XtOffset (ApplicationArgsPtr, smallIconHeight), XmRImmediate,
934      (XtPointer) 24,
935    },
936
937    {
938      "largeIconWidth", "LargeIconWidth", XmRInt, sizeof (int),
939      XtOffset (ApplicationArgsPtr, largeIconWidth), XmRImmediate,
940      (XtPointer) 38,
941    },
942
943    {
944      "largeIconHeight", "LargeIconHeight", XmRInt, sizeof (int),
945      XtOffset (ApplicationArgsPtr, largeIconHeight), XmRImmediate,
946      (XtPointer) 38,
947    },
948
949    {
950      "emptyTrashOnExit", "EmptyTrashOnExit", XmRBoolean, sizeof (Boolean),
951      XtOffset (ApplicationArgsPtr, emptyTrashOnExit), XmRImmediate,
952      (XtPointer)False,
953    },
954
955 #if defined(__hpux) || defined(sun)
956    { "followLinks", "FollowLinks", XmRBoolean, sizeof(Boolean),
957      XtOffset(ApplicationArgsPtr, follow_links), XmRImmediate,
958      (XtPointer) False,
959    },
960 #endif
961
962 };
963
964 XtActionsRec actionTable[] = {
965    {"Space", (XtActionProc)VFTextChangeSpace},
966    {"EscapeFM", (XtActionProc)CancelOut},
967 };
968
969 /************************************************************************
970  *
971  *  DT File
972  *      The main program for the file manager.
973  *
974  ************************************************************************/
975
976 extern XtInputId ProcessToolTalkInputId;
977
978 #if defined(CSRG_BASED)
979 extern void sigchld_handler(int);
980 #endif /* CSRG_BASED */
981
982 int
983 main(
984         int argc,
985         char **argv )
986 {
987 #ifdef DT_PERFORMANCE
988    struct timeval update_time_s;
989    struct timeval update_time_f;
990    struct timeval update_time_ss;
991    struct timeval update_time_fs;
992 #endif
993    struct passwd * pw;
994    char current_directory[MAX_PATH] = {0};
995    struct passwd * pwInfo;
996    char * homeDir;
997    XEvent event;
998    XtInputMask pending;
999    Boolean eventDebugging;
1000    int offset;
1001    int displayHeight;
1002    int displayWidth;
1003    Arg args[10];
1004    int n;
1005    char * tmpStr;
1006    XSetWindowAttributes sAttributes;
1007    Window root;
1008 #ifdef SHAPE
1009    int base1, base2;
1010 #endif
1011    XrmValue resource_value;
1012    XrmDatabase db;
1013    char *rep_type;
1014    char *string, *str;
1015    int i;
1016    int ttFd;    /* ToolTalk file descriptor */
1017    char *sessId;
1018    Tt_pattern events2Watch;
1019    Tt_pattern requests2Handle;
1020    Tt_message msg;
1021    Tt_status status;
1022 #if defined(CSRG_BASED)
1023    struct sigaction sa, osa;
1024 #endif /* CSRG_BASED */
1025    int session_flag = 0;
1026
1027 #ifdef DT_PERFORMANCE
1028    printf("  Start\n");
1029    gettimeofday(&update_time_ss, NULL);
1030 #endif
1031    (void) signal (SIGINT, (void (*)())Stop);
1032
1033    /* We don't want any zombie children, do we? */
1034 #if defined(CSRG_BASED)
1035     sa.sa_handler = sigchld_handler;
1036     sigemptyset(&sa.sa_mask);
1037     sa.sa_flags   =  0;
1038
1039     if (sigaction(SIGCHLD, &sa, &osa) < 0)
1040     /* error handling follows, none for now */
1041         ;
1042 #else
1043    (void) signal (SIGCHLD, SIG_IGN);
1044 #endif /* CSRG_BASED */
1045    XtSetLanguageProc( NULL, NULL, NULL );
1046
1047 #ifdef DT_PERFORMANCE
1048 { /* Initialize the checkpoint protocol  - Aloke Gupta */
1049 Display *display;
1050 display = XOpenDisplay("");
1051 _DtPerfChkpntInit(display, RootWindow(display, DefaultScreen(display)),
1052                     argv[0], True);
1053 }
1054 #endif
1055
1056
1057    _DtEnvControl(DT_ENV_SET);
1058
1059 #ifdef DT_PERFORMANCE
1060    printf("  XtInitalize\n");
1061    gettimeofday(&update_time_s, NULL);
1062
1063    /* Added by Aloke Gupta */
1064 _DtPerfChkpntMsgSend("Begin XtInitialize");
1065 #endif
1066
1067    /*  Initialize the toolkit and open the display  */
1068    toplevel = XtInitialize (argv[0], DTFILE_CLASS_NAME,
1069                             option_list, XtNumber(option_list),
1070                             (int *)&argc, argv);
1071
1072 #ifdef DT_PERFORMANCE
1073    gettimeofday(&update_time_f, NULL);
1074    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1075       update_time_f.tv_usec += 1000000;
1076       update_time_f.tv_sec--;
1077    }
1078    printf("    done XtInitialize, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1079
1080    /* Added by Aloke Gupta */
1081    _DtPerfChkpntMsgSend("Done  XtInitialize");
1082 #endif
1083
1084    /* Initialize the function ptr for alphabetic sorting */
1085    FMStrcoll = GetStrcollProc();
1086
1087    /* Open the message catalog - DO NOT PERFORM until after XtInitialize! */
1088    {
1089       char * foo = ((char *)GETMESSAGE(18, 1, ""));
1090    }
1091
1092    /* set application name for later */
1093    str = strrchr(argv[0], '/');
1094    if(str != NULL)
1095       application_name = XtNewString (str + 1);
1096    else
1097       application_name = XtNewString (argv[0]);
1098
1099    n = 0;
1100    XtSetArg(args[n], XmNallowShellResize, True); n++;
1101    XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
1102    XtSetArg(args[n], XmNheight, 1); n++;
1103    XtSetArg(args[n], XmNwidth, 1); n++;
1104    XtSetValues(toplevel, args, n);
1105    XtRealizeWidget(toplevel);
1106    display = XtDisplay (toplevel);
1107 #ifdef HAVE_EDITRES
1108     XtAddEventHandler(toplevel, 0, True,
1109                       (XtEventHandler) _XEditResCheckMessages,
1110                       (XtPointer) NULL);
1111 #endif
1112
1113    /* Initialize BMenu button binding */
1114    {
1115         int numMouseButtons = XGetPointerMapping(display,
1116                                         (unsigned char *)NULL, 0);
1117         bMenuButton = (numMouseButtons < 3) ? Button2 : Button3;
1118    }
1119
1120    /* initialize debugging flag */
1121 #ifdef DEBUG
1122    if ((tmpStr = getenv("DTFILE_DEBUG")) != NULL)
1123    {
1124       debug = atoi(tmpStr);
1125       if (debug <= 0)
1126          debug = 1;
1127    }
1128    if (getenv("DTFILE_XSYNC") != NULL)
1129    {
1130       XSynchronize(display, True);
1131    }
1132 #endif
1133
1134    /* initialize performance flag */
1135 #ifdef DT_PERFORMANCE
1136    if ((tmpStr = getenv("DTFILE_PERFORM")) != NULL)
1137    {
1138       perform = atoi(tmpStr);
1139       if (perform <= 0)
1140          perform = 1;
1141    }
1142    if (getenv("DTFILE_XSYNC") != NULL)
1143    {
1144       XSynchronize(display, True);
1145    }
1146 #endif
1147
1148    /*  Create the atom set used by save and restore session  */
1149    save_yourself_atom = XmInternAtom (display, "WM_SAVE_YOURSELF", False);
1150    wm_state_atom = XmInternAtom (display, "WM_STATE", False);
1151    command_atom = XA_WM_COMMAND;
1152    save_mode = XmInternAtom (display, _XA_DT_RESTORE_MODE, False);
1153
1154    root = RootWindowOfScreen(XtScreen(toplevel));
1155
1156    /* Set session property on the top level window */
1157    XmAddWMProtocols(toplevel, &save_yourself_atom, 1);
1158    XmAddWMProtocolCallback(toplevel, save_yourself_atom, SaveSessionCallback,
1159                            NULL);
1160
1161    XSetErrorHandler ((int (*)())ErrorHandler);
1162    XtAppSetErrorHandler (XtWidgetToApplicationContext(toplevel),
1163                          ToolkitErrorHandler);
1164
1165    /* get the keyboard focus policy so we know how we want to set up the */
1166    /*  Icon gadgets */
1167    XtSetArg(args[0], XmNkeyboardFocusPolicy, &keybdFocusPolicy);
1168    XtGetValues(toplevel, args, 1);
1169
1170    /*  If all of the command line parameters were not processed  */
1171    /*  out, print out a usage message set and exit.              */
1172
1173    if (argc != 1) Usage (argv);
1174
1175    displayWidth = DisplayWidth(display, DefaultScreen(display));
1176    displayHeight = DisplayHeight(display, DefaultScreen(display));
1177
1178    /*  Get Dt initialized  */
1179
1180    if (DtInitialize (display, toplevel, argv[0], FILE_MANAGER_TOOL_CLASS) == False)
1181    {
1182       /* Fatal Error: could not connect to the messaging system. */
1183       /* DtInitialize() has already logged an appropriate error msg */
1184       exit(-1);
1185    }
1186
1187 #ifdef DT_PERFORMANCE
1188    printf("  Setup Converters and get resources\n");
1189    gettimeofday(&update_time_s, NULL);
1190
1191    /* Added by Aloke Gupta */
1192    _DtPerfChkpntMsgSend("Begin Setup Converters");
1193
1194 #endif
1195
1196    /* First lets add the resource converters needed */
1197    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1198                        XtRString, "ObjectPlacement",
1199                        (XtConverter)DtfileCvtStringToObjPlace, NULL, 0);
1200    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1201                        XtRString, "OpenFolder",
1202                        (XtConverter)DtfileCvtStringToOpenDir, NULL, 0);
1203    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1204                        XtRString, "DesktopIcon",
1205                        (XtConverter)DtfileCvtStringToDTIcon, NULL, 0);
1206    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1207                        XtRString, "Tree",
1208                        (XtConverter)DtfileCvtStringToTree, NULL, 0);
1209    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1210                        XtRString, "TreeFiles",
1211                        (XtConverter)DtfileCvtStringToTreeFiles, NULL, 0);
1212    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1213                        XtRString, "View",
1214                        (XtConverter)DtfileCvtStringToView, NULL, 0);
1215    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1216                        XtRString, "Order",
1217                        (XtConverter)DtfileCvtStringToOrder, NULL, 0);
1218    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1219                        XtRString, "Direction",
1220                        (XtConverter)DtfileCvtStringToDirection, NULL, 0);
1221    XtAppAddConverter (XtWidgetToApplicationContext (toplevel),
1222                        XtRString, "Grid",
1223                        (XtConverter)DtfileCvtStringToGrid, NULL, 0);
1224
1225    /*  Get the application defined resources of session and  */
1226    /*  directory, and get the processes host.                */
1227
1228    XtGetApplicationResources(toplevel, &application_args,
1229                              resources, XtNumber(resources), NULL,0);
1230
1231 #ifdef DT_PERFORMANCE
1232    gettimeofday(&update_time_f, NULL);
1233    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1234       update_time_f.tv_usec += 1000000;
1235       update_time_f.tv_sec--;
1236    }
1237    printf("    done Setting up Converters and got resources, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1238
1239    /* Added by Aloke Gupta */
1240    _DtPerfChkpntMsgSend("Done  Setup Converters");
1241 #endif
1242
1243 #ifdef DT_PERFORMANCE
1244    printf("  DtDbLoad\n");
1245    gettimeofday(&update_time_s, NULL);
1246    /* Added by Aloke Gupta */
1247    _DtPerfChkpntMsgSend("Begin DtDbLoad");
1248
1249 #endif
1250
1251    /*  Set up the messaging and file types  */
1252
1253    DtDbLoad();
1254 #ifdef DT_PERFORMANCE
1255    gettimeofday(&update_time_f, NULL);
1256    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1257       update_time_f.tv_usec += 1000000;
1258       update_time_f.tv_sec--;
1259    }
1260    printf("    done DtDbLoad, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1261
1262    /* Added by Aloke Gupta */
1263    _DtPerfChkpntMsgSend("Done  DtDbLoad");
1264
1265 #endif
1266
1267
1268    /* Create some global strings */
1269    db = XtDatabase(display);
1270    if (XrmGetResource (db, "dttypes.defaultActions",
1271                        "Dttypes.DefaultActions", &rep_type,
1272                        &resource_value))
1273    {
1274      string = XtNewString(resource_value.addr);
1275      for(str = DtStrtok(string, ",") ,i = 0; str != NULL && i < 2 ;
1276      str = DtStrtok(NULL, ","), i++) {
1277        if(i == 0)
1278          openInPlace = XtNewString(str);
1279        else
1280          openNewView = XtNewString(str);
1281      }
1282      XtFree(string);
1283    }
1284    if(openInPlace == NULL || strlen(openInPlace) == 0)
1285        openInPlace = XtNewString("OpenInPlace");
1286    if(openNewView == NULL || strlen(openNewView) == 0)
1287        openNewView = XtNewString("OpenNewView");
1288
1289    DtGetShortHostname (home_host_name, MAX_PATH);
1290
1291    /*  Get the lock established to ensure only one dtfile process  */
1292    /*  is running.                                                  */
1293    if (_DtGetLock (display, DTFILE_CLASS_NAME) == 0)
1294    {
1295       status = InitializeToolTalkProcid( &ttFd, toplevel, False );
1296       if (TT_OK != status)
1297       {
1298           char *errfmt, *errmsg, *title, *statmsg;
1299           title = GETMESSAGE(21,38,"File Manager Error");
1300           errfmt = GETMESSAGE(18, 40,
1301                    "Could not connect to ToolTalk:\n%s\nExiting ...");
1302           statmsg = tt_status_message(status);
1303
1304           errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1305           fprintf(stderr, errfmt, statmsg);
1306           sprintf(errmsg, errfmt, statmsg);
1307
1308           /* put up error dialog and loop,
1309            * application will exit in dialog callback
1310            */
1311           post_dialog(toplevel, title, errmsg, DtErrExitCB); 
1312       }
1313
1314       if (application_args.session != NULL)
1315       {
1316          msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1317                                     "DtFileSession_Run",
1318                                     (Tt_message_callback)ExitApp );
1319          tt_message_file_set( msg, application_args.session );
1320          tt_message_send( msg );
1321       }
1322       else if (application_args.directories != NULL)
1323       {
1324          msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1325                                     "DtFolder_Show",
1326                                     (Tt_message_callback)ExitApp );
1327          tt_message_file_set( msg, application_args.directories );
1328          SetupSendRequestArgs( application_args, msg );
1329          tt_message_send( msg );
1330       }
1331       else
1332       {
1333          /* Default action: Open up pwd or home dir */
1334          GetPWD(current_directory);
1335
1336          if (current_directory[0] != '\0')
1337          {
1338             msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1339                                        "DtFolder_Show",
1340                                        (Tt_message_callback)ExitApp );
1341             tt_message_file_set( msg, current_directory );
1342          }
1343          else
1344          {
1345             msg = tttk_message_create( 0, TT_REQUEST, TT_SESSION, 0,
1346                                        "DtHome_Show",
1347                                        (Tt_message_callback)ExitApp );
1348          }
1349          SetupSendRequestArgs( application_args, msg );
1350          tt_message_send( msg );
1351       }
1352       WaitForResponseAndExit();
1353    }
1354
1355    /*  Initialize the encapsulation mechanism and install the dialogs  */
1356    /*  used by the file manager.                                       */
1357
1358    _DtInitializeEncapsulation (display, argv[0], DTFILE_CLASS_NAME);
1359    topPositionOffset = -8;
1360
1361    status = InitializeToolTalkProcid( &ttFd, toplevel, True );
1362    if (TT_OK != status)
1363    {
1364        char *errfmt, *errmsg, *title, *statmsg;
1365        title = GETMESSAGE(21,38,"File Manager Error");
1366        errfmt = GETMESSAGE(18, 40,
1367                 "Could not connect to ToolTalk:\n%s\nExiting ...");
1368        statmsg = tt_status_message(status);
1369
1370        errmsg = XtMalloc(strlen(errfmt) + strlen(statmsg) + 2);
1371        fprintf(stderr, errfmt, statmsg);
1372        sprintf(errmsg, errfmt, statmsg);
1373
1374        /* put up error dialog and loop,
1375         * application will exit in dialog callback
1376         */
1377        post_dialog(toplevel, title, errmsg, DtErrExitCB); 
1378    }
1379
1380
1381 #ifdef DT_PERFORMANCE
1382    printf("  Setup Callbacks (messaging)\n");
1383    gettimeofday(&update_time_s, NULL);
1384
1385    /* Added by Aloke Gupta */
1386    _DtPerfChkpntMsgSend("Begin Setup Callbacks");
1387
1388 #endif
1389    events2Watch = tt_pattern_create();
1390    tt_pattern_category_set( events2Watch, TT_OBSERVE );
1391    tt_pattern_class_add( events2Watch, TT_NOTICE );
1392    tt_pattern_scope_add( events2Watch, TT_SESSION );
1393    sessId = tt_default_session();
1394    tt_pattern_session_add( events2Watch, sessId );
1395    tt_free( sessId );
1396    tt_pattern_op_add( events2Watch, "DtTypes_Reloaded" );
1397    tt_pattern_op_add( events2Watch, "XSession_Ending" );
1398    tt_pattern_callback_add( events2Watch, ObserveTtNotice );
1399    tt_pattern_register( events2Watch );
1400
1401    requests2Handle = tt_pattern_create();
1402    tt_pattern_category_set( requests2Handle, TT_HANDLE );
1403    tt_pattern_class_add( requests2Handle, TT_REQUEST );
1404    tt_pattern_scope_add( requests2Handle, TT_SESSION );
1405    sessId = tt_default_session();
1406    tt_pattern_session_add( requests2Handle, sessId );
1407    tt_free( sessId );
1408    tt_pattern_op_add( requests2Handle, "DtFileSession_Run" );
1409    tt_pattern_op_add( requests2Handle, "DtFolder_Show" );
1410    tt_pattern_op_add( requests2Handle, "DtHome_Show" );
1411    tt_pattern_op_add( requests2Handle, "DtTools_Show" );
1412    tt_pattern_op_add( requests2Handle, "DtTrash_Show" );
1413    tt_pattern_op_add( requests2Handle, "DtTrash_Remove" );
1414    tt_pattern_op_add( requests2Handle, "DtTrash_Empty" );
1415    tt_pattern_op_add( requests2Handle, "DtTrash_File" );
1416    tt_pattern_op_add( requests2Handle, "DtTrash_Restore" );
1417    tt_pattern_op_add( requests2Handle, "DtFile_PutOnWorkspace" );
1418    tt_pattern_op_add( requests2Handle, "DtFile_Move" );
1419    tt_pattern_op_add( requests2Handle, "DtFile_Copy" );
1420    tt_pattern_op_add( requests2Handle, "DtFile_Link" );
1421    tt_pattern_callback_add( requests2Handle, HandleTtRequest );
1422    tt_pattern_register( requests2Handle );
1423
1424    /* Setup the settings file if any to setup */
1425
1426    _DtWsmAddMarqueeSelectionCallback(toplevel,
1427                                      (DtWsmMarqueeSelectionProc) MarqueeSelect,
1428                                      NULL);
1429
1430 #ifdef DT_PERFORMANCE
1431    gettimeofday(&update_time_f, NULL);
1432    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1433       update_time_f.tv_usec += 1000000;
1434       update_time_f.tv_sec--;
1435    }
1436    printf("    done Setting Callbacks (messaging), time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1437
1438     /* Added by Aloke Gupta */
1439    _DtPerfChkpntMsgSend("Done  Setup Callbacks");
1440
1441 #endif
1442
1443    smallIconWidth = application_args.smallIconWidth;
1444    smallIconHeight = application_args.smallIconHeight;
1445    largeIconWidth = application_args.largeIconWidth;
1446    largeIconHeight = application_args.largeIconHeight;
1447    user_font = application_args.user_font;
1448    dragThreshold = application_args.dragThreshold;
1449    rereadTime = application_args.rereadTime;
1450    checkBrokenLink = application_args.checkBrokenLink;
1451    maxDirectoryProcesses = application_args.maxDirectoryProcesses;
1452    maxRereadProcesses = application_args.maxRereadProcesses;
1453    maxRereadProcsPerTick = application_args.maxRereadProcsPerTick;
1454    trashWait = application_args.trashWait;
1455    showFilesystem = application_args.showFilesystem;
1456    showDropZone = application_args.showDropZone;
1457    showEmptySet = application_args.showEmptySet;
1458    showEmptyMsg = application_args.showEmptyMsg;
1459    restrictMode = application_args.restrictMode;
1460    openDirType = application_args.openDirType;
1461    desktopIconType = application_args.desktopIconType;
1462    desktopPlacement = application_args.desktopPlacement;
1463    freezeOnConfig = application_args.freezeOnConfig;
1464    emptyTrashOnExit = application_args.emptyTrashOnExit;
1465 #if defined(__hpux) || defined(sun)
1466    follow_links = application_args.follow_links;
1467 #endif
1468    instanceWidth = application_args.instanceIconWidth;
1469    instanceHeight = application_args.instanceIconHeight;
1470    fileMgrIcon = application_args.fileMgrIcon;
1471    appMgrIcon = application_args.appMgrIcon;
1472    trashIcon = application_args.trashIcon;
1473    retryLoadDesktopInfo = application_args.retryLoadDesktop;
1474    if( application_args.directories != NULL
1475        || (strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1476        || restrictMode )
1477    {
1478       special_view = True;
1479       if(strcmp (application_args.restricted, RESTRICTED_HEADER) == 0)
1480       {
1481          if(application_args.directories != NULL)
1482             special_restricted = XtNewString(application_args.directories);
1483          else
1484          {
1485             /* Get users pwd so we can set the restricted dir to it */
1486             GetPWD(current_directory);
1487
1488             if (current_directory[0] != '\0')
1489                special_restricted = XtNewString(current_directory);
1490             else
1491                special_restricted = XtNewString("~");
1492          }
1493       }
1494       else if( restrictMode )
1495          special_restricted = XtNewString("~");
1496       else
1497          special_restricted = NULL;
1498       special_treeType = treeType = application_args.tree_view;
1499       special_treeFiles = treeFiles = application_args.tree_files;
1500       special_viewType = viewType = application_args.view;
1501       special_orderType = orderType = application_args.order;
1502       special_directionType = directionType = application_args.direction;
1503       special_randomType = randomType = application_args.grid;
1504       special_title = XtNewString(application_args.title);
1505       if(application_args.help_volume == NULL)
1506       {
1507          special_helpVol = XtNewString(DTFILE_HELP_NAME);
1508          fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1509       }
1510       else
1511       {
1512          special_helpVol = XtNewString(application_args.help_volume);
1513          fileMgrHelpVol = XtNewString(application_args.help_volume);
1514       }
1515       fileMgrTitle = application_args.title;
1516    }
1517    else
1518    {
1519       special_view = False;
1520       treeType = application_args.tree_view;
1521       treeFiles = application_args.tree_files;
1522       viewType = application_args.view;
1523       orderType = application_args.order;
1524       directionType = application_args.direction;
1525       randomType = application_args.grid;
1526       fileMgrTitle = application_args.title;
1527       if(application_args.help_volume == NULL)
1528          fileMgrHelpVol = XtNewString(DTFILE_HELP_NAME);
1529       else
1530          fileMgrHelpVol = XtNewString(application_args.help_volume);
1531    }
1532
1533
1534    if(desktopIconType == LARGE)
1535    {
1536       numRows = displayHeight / PIXELS_PER_ROW_LARGE;
1537       numColumns = displayWidth / PIXELS_PER_COLUMN_LARGE;
1538    }
1539    else /* small */
1540    {
1541       numRows = displayHeight / PIXELS_PER_ROW_SMALL;
1542       numColumns = displayWidth / PIXELS_PER_COLUMN_SMALL;
1543    }
1544
1545 #ifdef SHAPE
1546    /* determine whether the Server has the shape extension */
1547    if(XShapeQueryExtension(display, &base1, &base2) == True)
1548       shapeExtension = True;
1549    else
1550       shapeExtension = False;
1551 #endif
1552
1553    /* get the name for the root directory */
1554    root_title = (char *)XtMalloc(strlen(application_args.root_title) + 1);
1555    strcpy(root_title, application_args.root_title);
1556
1557    if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
1558    {
1559       pwInfo = getpwuid (getuid());
1560       homeDir = pwInfo->pw_dir;
1561    }
1562    strncpy(users_home_dir, homeDir, MAX_PATH - 1);
1563    if(restrictMode)
1564    {
1565       if(application_args.directories != NULL &&
1566                            strncmp(application_args.directories, "~", 1) != 0 )
1567       {
1568          if(strncmp(application_args.directories, users_home_dir,
1569                                                   strlen(users_home_dir)) != 0)
1570             RestrictModeUsage (argv);
1571       }
1572       else if (application_args.directories == NULL)
1573           application_args.directories = XtNewString("~");
1574    }
1575    if (strcmp(users_home_dir, "/") != 0)
1576       strcat(users_home_dir, "/");
1577
1578    XtAppAddActions(XtWidgetToApplicationContext (toplevel), actionTable, 2);
1579
1580    /* Create some global Xm strings for our dialog buttons */
1581
1582    okXmString = XmStringCreateLocalized((char*)_DtOkString);
1583    cancelXmString = XmStringCreateLocalized((char*)_DtCancelString);
1584    helpXmString = XmStringCreateLocalized((char*)_DtHelpString);
1585    applyXmString = XmStringCreateLocalized((char*)_DtApplyString);
1586    closeXmString = XmStringCreateLocalized((char*)_DtCloseString);
1587
1588    /*  Get the dt path created and initialized  */
1589
1590    dt_path = _DtCreateDtDirs (display);
1591
1592    if (dt_path == NULL)
1593    {
1594       Widget dialog;
1595       char *msg, *title;
1596       title = XtNewString((GETMESSAGE(21,38,"File Manager Error")));
1597       tmpStr = GETMESSAGE(18, 2, "Could not create the ~/.dt folder or sub folders.");
1598       msg = XtNewString(tmpStr);
1599
1600       /* put up error dialog and loop, application will exit in 
1601          dialog callback */
1602
1603       dialog = post_dialog(toplevel, title, msg, DtErrExitCB); 
1604       XtFree(msg);
1605       XtFree(title);
1606
1607       while (TRUE)
1608       {
1609         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
1610       }
1611     }
1612
1613    /*  Set the black and white pixel globals.  */
1614
1615    black_pixel = BlackPixelOfScreen (XtScreen (toplevel));
1616    white_pixel = WhitePixelOfScreen (XtScreen (toplevel));
1617
1618    /*
1619     * Take over the drawing area's redisplay functions, so that we can get
1620     * the dtfile views to redraw according to stacking order, using our own
1621     * redraw function.
1622     */
1623    xmDrawingAreaWidgetClass->core_class.expose = DrawingAreaRedisplay;
1624
1625
1626    /* Get the root user id */
1627
1628    if ((pw = getpwnam("root")) == NULL)
1629       root_user = 0;          /* Assume root is uid 0 */
1630    else
1631       root_user = pw->pw_uid;
1632
1633
1634    file_mgr_dialog = _DtInstallDialog (fileMgrClass, True, True);
1635    change_dir_dialog = _DtInstallDialog (changeDirClass, True, True);
1636    preferences_dialog = _DtInstallDialog (preferencesClass, True, True);
1637    filter_dialog = _DtInstallDialog (filterClass, True, True);
1638    find_dialog = _DtInstallDialog (findClass, True, True);
1639    mod_attr_dialog = _DtInstallDialog (modAttrClass, True, True);
1640    help_dialog = _DtInstallDialog (helpClass, False, False);
1641
1642    if(special_view == True && special_restricted != NULL) {
1643       if(strncmp(special_restricted, "~", 1) == 0)
1644       {
1645          char *ptr, *ptr1;
1646
1647          special_restricted = _DtChangeTildeToHome(special_restricted);
1648          ptr = strrchr(special_restricted, '/');
1649          ptr1 = ptr + 1;
1650          if(ptr1[0] == '\0')
1651             *ptr = '\0';
1652       }
1653    }
1654
1655    /* Setup the settings file if any to setup */
1656    RestoreSettingsFile();
1657
1658 #ifdef DT_PERFORMANCE
1659    printf("  TrashCreateDialog\n");
1660    gettimeofday(&update_time_s, NULL);
1661
1662    /* Added by Aloke Gupta */
1663    _DtPerfChkpntMsgSend("Begin TrashCreateDialog");
1664
1665 #endif
1666    if( InitializeTrash( application_args.prompt_user ) )
1667
1668 #ifdef DEFER_TRASH_CREATION
1669 ;
1670 #else
1671      TrashCreateDialog (display);
1672 #endif
1673
1674 #ifdef DT_PERFORMANCE
1675    gettimeofday(&update_time_f, NULL);
1676    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1677       update_time_f.tv_usec += 1000000;
1678       update_time_f.tv_sec--;
1679    }
1680    printf("    done TrashCreateDialog, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1681
1682    /* Added by Aloke Gupta */
1683    _DtPerfChkpntMsgSend("Done  TrashCreateDialog");
1684 #endif
1685
1686    /* lets go empty the trash if there is any */
1687 /*
1688    TrashEmpty();
1689 */
1690
1691 #ifdef DT_PERFORMANCE
1692    printf("  Setup Desktop\n");
1693    gettimeofday(&update_time_s, NULL);
1694    /* Added by Aloke Gupta */
1695    _DtPerfChkpntMsgSend("Begin Setup Desktop");
1696
1697 #endif
1698    /* go build 10 desktop windows */
1699    desktop_data = NULL;
1700    InitializeDesktopWindows(10, display);
1701    InitializeDesktopGrid(displayWidth, displayHeight);
1702
1703    LoadDesktopInfo(application_args.session);
1704
1705    /* Install WorkSpaceRemoved handler.
1706       This handler will be called when a workspace is being removed
1707       so File Manager can go through its desktop icons and clean up.
1708    */
1709    DtWsmAddWorkspaceModifiedCallback( toplevel, WorkSpaceRemoved, NULL );
1710
1711 #ifdef DT_PERFORMANCE
1712    gettimeofday(&update_time_f, NULL);
1713    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1714       update_time_f.tv_usec += 1000000;
1715       update_time_f.tv_sec--;
1716    }
1717    printf("    done Setting up Desktop, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1718
1719    /* Added by Aloke Gupta */
1720    _DtPerfChkpntMsgSend("Done  Setup Desktop");
1721 #endif
1722
1723
1724    /*  Process the application resources to restore a session, dt  */
1725    /*  a directory set or display the users home directory.         */
1726
1727 #ifdef DT_PERFORMANCE
1728    printf("  Bring up View\n");
1729    gettimeofday(&update_time_s, NULL);
1730
1731    /* Added by Aloke Gupta */
1732    _DtPerfChkpntMsgSend("Begin Bring up View");
1733
1734 #endif
1735
1736    if (strcmp (application_args.no_view, "-noview") != 0)
1737    {
1738      if (application_args.session != NULL)
1739         session_flag =
1740           RestoreSession (application_args.session, NORMAL_RESTORE, NULL);
1741      else if (application_args.directories != NULL)
1742      {
1743         restoreType = CURRENT_DIR_RESTORE;
1744         OpenDirectories (application_args.directories, NULL);
1745      }
1746    }
1747
1748 #ifdef DT_PERFORMANCE
1749    gettimeofday(&update_time_f, NULL);
1750    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1751       update_time_f.tv_usec += 1000000;
1752       update_time_f.tv_sec--;
1753    }
1754    printf("    done Bringing up view, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);  fflush(stdout);
1755
1756    /* Added by Aloke Gupta */
1757     _DtPerfChkpntMsgSend("Done  Bring up View");
1758 #endif
1759
1760
1761    /*  If no views were opened upon invocation, display the  */
1762    /*  current directory.                                    */
1763
1764    if ( (strcmp (application_args.no_view, "-noview") != 0) &&
1765         ((application_args.session == NULL) ||
1766          (session_flag != 0)) )
1767    {
1768       if (view_count == 0)
1769       {
1770          /* Get users pwd so we can create a fileviewer window of it */
1771          GetPWD(current_directory);
1772
1773          if (current_directory[0] != '\0')
1774          {
1775            if (!GetNewView (home_host_name, current_directory, NULL, NULL, 0))
1776               ViewHomeDirectoryHandler (0);
1777          }
1778          else
1779          {
1780            ViewHomeDirectoryHandler (0);
1781          }
1782       }
1783    }
1784
1785
1786    /*  Set up the timer based directory reading.      */
1787    InitializeDirectoryRead (toplevel);
1788
1789    /* Process and dispatch incoming events */
1790    eventDebugging = getenv("EVENT_DEBUGGING") != NULL;
1791
1792 #ifdef DT_PERFORMANCE
1793    printf("  InitializeToolTalkSession\n");
1794    gettimeofday(&update_time_s, NULL);
1795 #endif
1796    (void) InitializeToolTalkSession( toplevel, ttFd );
1797 #ifdef DT_PERFORMANCE
1798    gettimeofday(&update_time_f, NULL);
1799    if (update_time_s.tv_usec > update_time_f.tv_usec) {
1800       update_time_f.tv_usec += 1000000;
1801       update_time_f.tv_sec--;
1802    }
1803    printf("    done InitializeToolTalkSession, time: %ld.%ld\n\n", update_time_f.tv_sec - update_time_s.tv_sec, update_time_f.tv_usec - update_time_s .tv_usec);
1804 #endif
1805
1806  #ifdef DT_PERFORMANCE
1807    gettimeofday(&update_time_fs, NULL);
1808    if (update_time_ss.tv_usec > update_time_fs.tv_usec) {
1809       update_time_fs.tv_usec += 1000000;
1810       update_time_fs.tv_sec--;
1811    }
1812    printf("    Finish, time: %ld.%ld\n\n", update_time_fs.tv_sec - update_time_ss.tv_sec, update_time_fs.tv_usec - update_time_ss .tv_usec);
1813 #endif
1814
1815    while (1)
1816    {
1817       XtNextEvent(&event);
1818
1819       if (event.type != 0)
1820          XtDispatchEvent(&event);
1821    }
1822
1823    return EXIT_SUCCESS;
1824 }
1825
1826
1827
1828 /************************************************************************
1829  *
1830  *  ErrorHandler
1831  *
1832  ************************************************************************/
1833
1834 static void
1835 ErrorHandler(
1836         Display *disp,
1837         XErrorEvent *event )
1838 {
1839   #define _DTFILE_BUFSIZE 1024
1840   char errmsg[_DTFILE_BUFSIZE];
1841
1842   _DtPrintDefaultErrorSafe (disp, event, errmsg, _DTFILE_BUFSIZE);
1843   _DtSimpleError(application_name, DtWarning, NULL, errmsg, NULL);
1844   xErrorDetected = True;
1845
1846   /* We do not want to exit here lets try to continue... */
1847
1848 }
1849
1850 static void
1851 ToolkitErrorHandler(
1852         char *message )
1853 {
1854     char * msg;
1855     char * tmpStr;
1856
1857     tmpStr = GETMESSAGE(18, 6, "An X Toolkit error occurred... Exiting.\n");
1858     msg = (char *)malloc(strlen(tmpStr) + strlen(message) + 3);
1859     strcpy(msg, message);
1860     strcat(msg, "\n");
1861     strcat(msg, tmpStr);
1862     _DtSimpleError (application_name, DtError, NULL, msg);
1863     printf ("%s",msg);
1864     XtFree(msg);
1865     FinalizeToolTalkSession( );
1866     exit (1);
1867 }
1868
1869
1870
1871
1872 /************************************************************************
1873  *
1874  *  Usage
1875  *      When incorrect parameters have been specified on the command
1876  *      line, print out a set of messages detailing the correct use
1877  *      and exit.
1878  *
1879  ************************************************************************/
1880
1881 static void
1882 Usage(
1883         char **argv )
1884 {
1885    char * template;
1886    char * message_string1 = "\nUsage: %s...\n\n"
1887                          "   -noview\n\n\t"
1888                          "Dtfile runs in server mode.\n\n"
1889                          "   -session SessionFile\n\n\t"
1890                          "Dtfile runs with the session file specified in the SessionFile\n\t"
1891                          "parameter.\n\n"
1892                          "   -folder Folder[,Folder,Folder]\n"
1893                          "   -dir Folder[,Folder,Folder]\n\n\t"
1894                          "Dtfile displays a window for each folder specified in the\n\t"
1895                          "Folder parameter.  The Folder parameter may contain many\n\t"
1896                          "folders separated by commas.  Folders may be in the form\n\t"
1897                          "'path'.\n\n"
1898                          "   -title Title\n\n\t"
1899                          "Dtfile uses the string specified in the Title parameter as the\n\t"
1900                          "title for its windows.\n\n"
1901                          "   -help_volume HelpVolume\n\n\t"
1902                          "Dtfile uses the help volume specified in the HelpVolume parameter.\n\n"
1903                          "   -restricted\n\n\t"
1904                          "Dtfile will not display folders above the restricted folder.\n\t"
1905                          "If the -dir option is used, the folder specified in that option\n\t"
1906                          "is the restricted folder.  If the -dir option is not used, the\n\t"
1907                          "user's current folder is the restricted folder.\n\n"
1908                          "   -grid on/off\n\n\t"
1909                          "on     = Files are displayed in a grid pattern.\n\t"
1910                          "off    = Files are displayed as placed.\n\n"
1911                          "   -tree on/off\n\n\t"
1912                          "on     = Files are displayed in single folder mode.\n";
1913
1914    char * message_string2 = "\toff    = Files are displayed in folder tree mode.\n\n"
1915                          "   -tree_files never/always/choose\n\n\t"
1916                          "never  = Tree mode has two states: partially expanded or collapsed.\n\t"
1917                          "always = Tree mode has two states: fully expanded or collapsed.\n\t"
1918                          "choose = Tree mode has three states: partially expanded, fully\n\t"
1919                          "         expanded, or collapsed.\n\n"
1920                          "   -order alphabetical/file_type/date/size\n\n\t"
1921                          "Files are displayed in the specified order: alphabetical, by file\n\t"
1922                          "type, by date, or by size.\n\n"
1923                          "   -view no_icon/large_icon/small_icon/attributes\n\n\t"
1924                          "Files are displayed in the specified format: text only, text and\n\t"
1925                          "large icons, text and small icons, with attributes.\n\n"
1926                          "   -direction ascending/descending\n\n\t"
1927                          "Files are displayed in the specified direction: ascending or\n\t"
1928                          "descending.\n\n"
1929                          "   -large_icon_width  <size>\n\n"
1930                          "   -large_icon_height <size>\n\n"
1931                          "   -small_icon_width  <size>\n\n"
1932                          "   -small_icon_height <size>\n\n"
1933                          "        The display area size for the icon images in File Manager\n"
1934                          "        Icon images larger than this size will be clipped to this size\n"
1935                          "        The default display area size for large is 38 and small is 24\n\n"
1936                          "\n"
1937 ;
1938
1939    template = (GETMESSAGE(18,23, message_string1));
1940    fprintf (stderr, template, argv[0]);
1941    template = (GETMESSAGE(18,24, message_string2));
1942    fprintf (stderr, "%s", template);
1943
1944    exit (0);
1945 }
1946
1947 static void
1948 RestrictModeUsage(
1949         char **argv )
1950 {
1951    char * template;
1952    char * message_string = "\nRestricted Mode Usage: %s...\n\n"
1953                          "   -folder Folder[,Folder,Folder]\n"
1954                          "   -dir Folder[,Folder,Folder]\n\n\t"
1955                          "Where Folder is a Folder below and/or including\n\t"
1956                          "the user's Home Folder.\n\n";
1957
1958    template = (GETMESSAGE(18,26, message_string));
1959
1960    fprintf (stderr, template, argv[0]);
1961
1962    FinalizeToolTalkSession( );
1963    exit (0);
1964 }
1965
1966
1967
1968
1969 /************************************************************************
1970  *
1971  *  Stop
1972  *      Catches Ctrl C's and exits.
1973  *
1974  ************************************************************************/
1975
1976 static void
1977 Stop( void )
1978 {
1979   FinalizeToolTalkSession( );
1980   exit(0);
1981 }
1982
1983
1984
1985
1986
1987
1988
1989 /***********************************************************************
1990  *
1991  * RestoreSettingsFile
1992  *         Used to restore the save settings files from
1993  *         either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
1994  *
1995  ***********************************************************************/
1996 static void
1997 RestoreSettingsFile( void )
1998 {
1999    int             status, fd;
2000    char            *dtPath=NULL;
2001    char            *homeSavePath=NULL;
2002    char            *homeHomePath=NULL;
2003    char            *toolSavePath=NULL;
2004    char            *toolHomePath=NULL;
2005    char            *dirName=NULL;
2006    Atom            actualType;
2007    int             actualFormat;
2008    unsigned long   nitems;
2009    unsigned long   leftover;
2010    unsigned char   *data = NULL;
2011
2012
2013   /* go get the dt path */
2014   /* _DtCreateDtDirs returs a path of MaxPath Length */
2015    dtPath = (char *)_DtCreateDtDirs(display);
2016
2017   /* Determin which type of session we are running HOME or CURRENT */
2018
2019   /* get the root window property of SaveMode */
2020   XGetWindowProperty(display, RootWindow(display,0),
2021                          save_mode, 0L, (long)BUFSIZ,False,
2022                          XA_STRING, &actualType,
2023                          &actualFormat,&nitems,&leftover,
2024                          &data);
2025
2026   if(strcmp((char *)data, "home") == 0)
2027     dirName = XtNewString("home");
2028   else if(strcmp((char *)data, "current") == 0)
2029     dirName = XtNewString("current");
2030   else
2031   {
2032     XtFree(dtPath);
2033     return;  /* we are coming up in a system mode (e.g. default) */
2034   }
2035
2036
2037   /* Build the paths to read the files from */
2038
2039   toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2040                   strlen(TOOL_SETTINGS_FILENAME) +
2041                   strlen(dirName) + 4);
2042
2043   homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2044                   strlen(HOME_SETTINGS_FILENAME) +
2045                   strlen(dirName) + 4);
2046
2047   sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2048   sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2049
2050   /* open the home settings file to see if its there */
2051   if((fd = open(homeSavePath, O_RDONLY)) != -1)
2052   {
2053       close(fd);
2054      /* create where the saved file is going to go */
2055
2056       homeHomePath = (char *)XtMalloc(strlen(dtPath) +
2057                      strlen(HOME_SETTINGS_FILENAME) + 2);
2058
2059       sprintf( homeHomePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2060
2061      /* remove any existing dtfile.home (e.g. HOME_SETTINGS_FILENAME) */
2062       unlink(homeHomePath);
2063
2064      /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2065       * will be used by the dtfile
2066       */
2067       status = link(homeSavePath, homeHomePath);
2068       if(status != 0)
2069       {
2070         char *tmpStr, *msg;
2071
2072         tmpStr = GETMESSAGE(18,27, "Unable to recover the saved default home settings file, will use default.\n");
2073         msg = XtNewString(tmpStr);
2074         _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2075         XtFree(msg);
2076       }
2077
2078    }
2079
2080  /* open the tool settings file to see if its there */
2081   if((fd = open(toolSavePath, O_RDONLY)) != -1)
2082   {
2083       close(fd);
2084      /* create where the saved file is going to go */
2085       toolHomePath = (char *)XtMalloc(strlen(dtPath) +
2086                      strlen(TOOL_SETTINGS_FILENAME) + 2);
2087
2088       sprintf( toolHomePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2089
2090      /* remove any existing dtfile.tool (e.g. TOOL_SETTINGS_FILENAME) */
2091       unlink(toolHomePath);
2092
2093      /* copy the saved one into $HOME/.dt/$DISPLAY ... this is the one that
2094       * will be used by the dtfile
2095       */
2096       status = link(toolSavePath, toolHomePath);
2097       if(status != 0)
2098       {
2099         char *tmpStr, *msg;
2100
2101         tmpStr = GETMESSAGE(18,28, "Unable to recover the saved default tool settings file, will use default.\n");
2102         msg = XtNewString(tmpStr);
2103         _DtSimpleErrnoError(application_name, DtWarning, NULL, msg, NULL);
2104         XtFree(msg);
2105       }
2106    }
2107
2108
2109   /* free up space */
2110    XFree(data);
2111    XtFree(dtPath);
2112    XtFree(dirName);
2113    XtFree(homeSavePath);
2114    XtFree(toolSavePath);
2115    XtFree(toolHomePath);
2116    XtFree(homeHomePath);
2117
2118
2119 }
2120
2121
2122
2123
2124
2125 /***********************************************************************
2126  *
2127  * MoveDefaultSettings
2128  *         Used to save the dtfile.tool and dtfile.home settings files to
2129  *         either $HOME/.dt/$DISPLAY/current or $HOME/.dt/$DISPLAY/home.
2130  *         The parameter mode determines whether it is home or
2131  *         current.
2132  *
2133  ***********************************************************************/
2134 static void
2135 MoveDefaultSettings(
2136         int mode )
2137 {
2138    int status;
2139    char *toolSavePath=NULL;
2140    char *homeSavePath=NULL;
2141    char *dirName=NULL;
2142    char *toolMovePath=NULL;
2143    char *homeMovePath=NULL;
2144    char *dtPath;
2145
2146    /* determine whether home or current */
2147    if(mode == HOME_DIR_RESTORE)
2148      dirName = XtNewString("home");
2149    else
2150      dirName = XtNewString("current");
2151
2152   /* go get the dt path */
2153   /* _DtCreateDtDirs returs a path of MaxPath Length */
2154   dtPath = (char *)_DtCreateDtDirs(display);
2155
2156
2157   /* Build the paths to save the files to */
2158
2159   toolSavePath = (char *)XtMalloc(strlen(dtPath) +
2160                   strlen(TOOL_SETTINGS_FILENAME) +
2161                   strlen(dirName) + 4);
2162
2163   homeSavePath = (char *)XtMalloc(strlen(dtPath) +
2164                   strlen(HOME_SETTINGS_FILENAME) +
2165                   strlen(dirName) + 4);
2166
2167
2168    /* create the directory and filename of where its going to be saved */
2169   sprintf( homeSavePath, "%s/%s/%s", dtPath, dirName, HOME_SETTINGS_FILENAME );
2170   sprintf( toolSavePath, "%s/%s/%s", dtPath, dirName, TOOL_SETTINGS_FILENAME );
2171
2172    /* Setup the paths used to GET the old files */
2173
2174    toolMovePath= (char *)XtMalloc(strlen(dtPath) +
2175                    strlen(TOOL_SETTINGS_FILENAME) + 3);
2176
2177    homeMovePath= (char *)XtMalloc(strlen(dtPath) +
2178                    strlen(HOME_SETTINGS_FILENAME) + 3);
2179
2180    /* create the filename of where its going to be saved from */
2181
2182    /* Tool File location */
2183    sprintf( toolMovePath, "%s/%s", dtPath, TOOL_SETTINGS_FILENAME );
2184
2185    /* Home File location */
2186    sprintf( homeMovePath, "%s/%s", dtPath, HOME_SETTINGS_FILENAME );
2187
2188
2189   /* get rid of the tool settings file that is already in home or current */
2190    status = unlink(toolSavePath);
2191
2192   /* get rid of the home settings file that is already in home or current */
2193    status = unlink(homeSavePath);
2194
2195
2196   /* now save tool settings file in home or current determined by savePath */
2197    status = link(toolMovePath, toolSavePath);
2198
2199   /* now save home settings file in home or current determined by savePath */
2200    status = link(homeMovePath, homeSavePath);
2201
2202    /* free up space */
2203    XtFree(homeMovePath);
2204    XtFree(toolMovePath);
2205    XtFree(homeSavePath);
2206    XtFree(toolSavePath);
2207    XtFree(dirName);
2208    XtFree(dtPath);
2209 }
2210
2211
2212 /************************************************************************
2213  *
2214  *  SaveSettingsCB
2215  *      Callback for the Save Settings menupick.
2216  *
2217  ************************************************************************/
2218 void
2219 SaveSettingsCB(
2220         Widget w,
2221         XtPointer client_data,
2222         XtPointer call_data )
2223 {
2224    Widget dlog;
2225    Widget mbar;
2226    Arg args[1];
2227    char * message;
2228    char * title;
2229    FileMgrRec * file_mgr_rec;
2230    DialogData * dialog_data;
2231    FileMgrData * file_mgr_data;
2232    char * tmpStr;
2233
2234    /* Strip the file_mgr_rec from the current widget
2235    * and attach it to the ok callback button
2236    */
2237
2238
2239    /* Get the file_mgr_rec hanging off the menubar */
2240    mbar = XmGetPostedFromWidget(XtParent(w));
2241    XmUpdateDisplay (w);
2242    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2243    XtGetValues(mbar, args, 1);
2244
2245
2246    /* Ignore accelerators when we're insensitive */
2247    if ((file_mgr_rec->menuStates & SETTINGS) == 0)
2248    {
2249      XSetInputFocus(XtDisplay(w),
2250                     XtWindow(file_mgr_rec->defaultEnvBtn_child),
2251                     RevertToParent, CurrentTime);
2252      return;
2253    }
2254
2255    /* Desensatize the save settings menu pick here */
2256    file_mgr_rec->menuStates &= ~SETTINGS;
2257
2258
2259    /* Get the file_mgr_rec dialog data info */
2260    if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
2261      return;
2262    file_mgr_data = (FileMgrData *) dialog_data->data;
2263
2264
2265    /* Based on the path we must determine if we are saving a Tools or
2266     * HomeDir dtfile view.
2267     */
2268    if (file_mgr_data->restricted_directory != NULL && file_mgr_data->toolbox)
2269      file_mgr_data->restoreKind = TOOL_RESTORE;
2270    else
2271      file_mgr_data->restoreKind = HOME_RESTORE;
2272
2273
2274    /* Setup and call the _DtMessageDialog procedure to post the dialog */
2275
2276    if (file_mgr_data->restoreKind == HOME_RESTORE)
2277    {
2278      tmpStr = (GETMESSAGE(18,29, "Save the current File Manager View window size,\npreferences, and filter settings?\n\nThey will be used for any new File Manager View windows\nstarted from the Front Panel."));
2279    }
2280    else
2281    {
2282      tmpStr = (GETMESSAGE(18,35, "Save the current Application Manager\nView window size, preferences, and filter settings?\n\nThey will be used for any new Application Manager\nwindows started from the Front Panel."));
2283    }
2284    message = XtNewString(tmpStr);
2285
2286    if(file_mgr_data->title != NULL &&
2287                strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
2288    {
2289       tmpStr = GETMESSAGE(18, 16, "Save As Default Options");
2290       title = (char *)XtMalloc(strlen(tmpStr) +
2291                                  strlen(file_mgr_data->title) + 5);
2292       sprintf(title, "%s - %s", file_mgr_data->title, tmpStr);
2293    }
2294    else
2295    {
2296       tmpStr = GETMESSAGE(18, 32, "File Manager - Save As Default Options");
2297       title = XtNewString(tmpStr);
2298    }
2299    dlog = (Widget)_DtMessageDialog(mbar, title, message, NULL, TRUE,
2300                                    SaveDefaultCancelCB, SaveDefaultOkCB, NULL,
2301                                    HelpRequestCB, False, QUESTION_DIALOG);
2302    file_mgr_rec->defaultEnvBtn_child=dlog;
2303    XtFree (message);
2304    XtFree (title);
2305
2306
2307    /* Add array as userdata on the dialog. */
2308
2309    XtSetArg(args[0], XmNuserData, file_mgr_rec);
2310    XtSetValues(dlog, args, 1);
2311
2312 }
2313
2314 /************************************************************************
2315  *
2316  *  SaveDefaultCancelCB
2317  *      Cleanup and unmanage the save settings dialog.
2318  *
2319  ************************************************************************/
2320 static void
2321 SaveDefaultCancelCB(
2322         Widget w,
2323         XtPointer client_data,
2324         XtPointer call_data )
2325 {
2326   FileMgrRec * file_mgr_rec;
2327   Arg args[1];
2328
2329     /* Update the display, and un-post the dialog */
2330     XtUnmanageChild((Widget)client_data);
2331     XmUpdateDisplay((Widget)client_data);
2332     XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2333     XtGetValues((Widget)client_data, args, 1);
2334
2335
2336     /* Re-sensatize the save settings menu pick */
2337     file_mgr_rec->menuStates |= SETTINGS;
2338
2339
2340     XtDestroyWidget((Widget)client_data);
2341
2342 }
2343
2344
2345 /************************************************************************
2346  *
2347  *  SaveDefaultOkCB
2348  *      Save the current dtfile view as the default environment for
2349  *      new dtfiles created.
2350  *
2351  ************************************************************************/
2352 static void
2353 SaveDefaultOkCB(
2354         Widget w,
2355         XtPointer client_data,
2356         XtPointer call_data )
2357 {
2358
2359    FileMgrRec * file_mgr_rec;
2360    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
2361    char view_number[5];
2362    int fd;
2363    Arg args[1];
2364
2365    DialogData * dialog_data;
2366    FileMgrData * file_mgr_data;
2367    char * msg;
2368    char * tmp_path;
2369    char full_path[MAX_PATH + 1];
2370    char * tmpStr;
2371    char * save_host;
2372    char * save_directory;
2373    char ** save_branch_list;
2374    FileViewData ** save_selection_list;
2375    int save_selected_file_count;
2376
2377
2378    /* Get the file_mgr_rec hanging off the dialog */
2379    XtUnmanageChild((Widget)client_data);
2380    XmUpdateDisplay ((Widget)client_data);
2381    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
2382    XtGetValues((Widget)client_data, args, 1);
2383
2384
2385    /* Re-sensatize the save settings menu pick */
2386    file_mgr_rec->menuStates |= SETTINGS;
2387
2388
2389    /* Get the file_mgr_rec dialog data info */
2390
2391    dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
2392    file_mgr_data = (FileMgrData *) dialog_data->data;
2393
2394
2395    /* Build the path for our env file */
2396
2397    tmp_path = _DtCreateDtDirs(display);
2398    if (tmp_path == NULL)
2399      {
2400        XtDestroyWidget(client_data);
2401        return;
2402      }
2403
2404
2405    /* Look and see what type of restore we are doing */
2406    if (file_mgr_data->restoreKind == TOOL_RESTORE)
2407    {
2408       sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
2409       application_args.tool_width = file_mgr_data->width;
2410       application_args.tool_height = file_mgr_data->height;
2411    }
2412    else
2413    {
2414       sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
2415       application_args.dir_width = file_mgr_data->width;
2416       application_args.dir_height = file_mgr_data->height;
2417    }
2418
2419    XtFree(tmp_path);
2420
2421
2422    /*  Create the Environment session file  */
2423
2424    if ((fd = creat(full_path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2425    {
2426       char *title;
2427       tmpStr = GETMESSAGE(18, 17, "Unable to create a file to store the default options.");
2428       title = XtNewString((GETMESSAGE(21,38,"Object Create Error")));
2429       msg = XtNewString(tmpStr);
2430       _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
2431       XtFree(msg);
2432       XtFree(title);
2433       return;
2434    }
2435
2436
2437    /*  Write out the general information  */
2438
2439    (void) write (fd, "*", strlen ("*"));
2440    (void) write (fd, DTFILE_CLASS_NAME,strlen (DTFILE_CLASS_NAME));
2441    (void) write (fd, "*view_count:      ", strlen ("*view_count:      "));
2442
2443    (void) sprintf (view_number, "%d", 1);
2444    (void) write (fd, view_number, strlen (view_number));
2445    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2446
2447    name_list[1] = view_number;
2448
2449    /* Temporarily remove data that we don't need or want saved */
2450
2451    save_host = file_mgr_data->host;
2452    save_directory = file_mgr_data->current_directory;
2453    save_branch_list = file_mgr_data->branch_list;
2454    save_selection_list = file_mgr_data->selection_list;
2455    save_selected_file_count = file_mgr_data->selected_file_count;
2456    file_mgr_data->host = NULL;
2457    file_mgr_data->current_directory = NULL;
2458    file_mgr_data->branch_list = NULL;
2459    file_mgr_data->selection_list = NULL;
2460    file_mgr_data->selected_file_count = 0;
2461
2462    /*  Call the encapsulation mechanism to write each dialog  */
2463
2464    (void) sprintf (view_number, "%d", 0);
2465    _DtWriteDialogData (dialog_data, fd, name_list);
2466    (void) write (fd, "#\n", strlen ("#\n"));
2467
2468    /* Restore the data that was temporarily removed */
2469
2470    file_mgr_data->host = save_host;
2471    file_mgr_data->current_directory = save_directory;
2472    file_mgr_data->branch_list = save_branch_list;
2473    file_mgr_data->selection_list = save_selection_list;
2474    file_mgr_data->selected_file_count = save_selected_file_count;
2475
2476    (void) close (fd);
2477
2478    XtDestroyWidget(client_data);
2479
2480 }
2481
2482
2483
2484 /************************************************************************
2485  *
2486  *  SaveSessionCallback
2487  *      Get the session name and call the function to save the session.
2488  *
2489  ************************************************************************/
2490
2491 void
2492 SaveSessionCallback(
2493         Widget w,
2494         XtPointer client_data,
2495         XtPointer call_data )
2496 {
2497    char * full_path=NULL;
2498    char * file_name=NULL;
2499    char * strPtr;
2500    int restore=NORMAL_RESTORE;
2501    Boolean status=FALSE;
2502    char * sessionFileName;
2503    char ** argv;
2504
2505    if(view_count == 0 && desktop_data->numIconsUsed == 0)
2506    {
2507       XChangeProperty (display, XtWindow (toplevel), command_atom,
2508                     XA_STRING, 8, PropModeReplace, (unsigned char *)NULL, 0);
2509       XSync(display, False);
2510       FinalizeToolTalkSession( );
2511       exit(0);
2512    }
2513
2514    status = DtSessionSavePath(w, &full_path, &file_name);
2515
2516    if (status)
2517      sessionFileName = file_name;
2518    else
2519    {
2520      XtFree( (char *)full_path);
2521      full_path = (char *) XtMalloc (sizeof (char) * MAX_PATH);
2522      sprintf( full_path, "%s/%s", dt_path, DTFILE_CLASS_NAME );
2523      sessionFileName = full_path;
2524    }
2525    SaveSession( full_path );
2526
2527    /* skip to the /.dt/ portion of the sessionFileName */
2528    strPtr = strstr(full_path, "/.dt/");
2529    (void)strcpy(full_path, strPtr);
2530
2531    /* Save off the settings files for both tool and home views */
2532    do {
2533         strPtr = DtStrrchr(full_path, '/');
2534         if ( !strPtr )
2535            continue;
2536         if ((strncmp(strPtr, "/home", 5) == 0))
2537            restore = HOME_DIR_RESTORE;
2538         else if ((strncmp(strPtr, "/current", 8) == 0))
2539            restore = CURRENT_DIR_RESTORE;
2540
2541         if (strPtr != NULL)
2542           *strPtr = '\0';
2543    } while ((strPtr != NULL) && (restore == NORMAL_RESTORE));
2544
2545    SaveDesktopInfo(restore);
2546
2547    /* Cop the settings files to the proper dir */
2548    MoveDefaultSettings(restore);
2549
2550    /*  Generate the reinvoking command and add it as the property value */
2551    argv = (char **) XtMalloc(3 * sizeof(char *));
2552    argv[0] = XtNewString(application_name);
2553    argv[1] = XtNewString("-session");
2554    argv[2] = XtNewString(sessionFileName);
2555    XSetCommand(XtDisplay(toplevel), XtWindow(toplevel), argv, 3);
2556
2557    XtFree ((char *) argv[0]);
2558    XtFree ((char *) argv[1]);
2559    XtFree ((char *) argv[2]);
2560    XtFree ((char *) argv);
2561
2562    XtFree ((char *) full_path);
2563    XtFree ((char *) file_name);
2564 }
2565
2566 /************************************************************************
2567  *
2568  *  SaveSession
2569  *      Save the current File Manager session as a set of resources
2570  *      within the file denoted by path.
2571  *
2572  ************************************************************************/
2573
2574 static void
2575 SaveSession(
2576         char *path
2577         )
2578 {
2579    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2580                                  NULL, NULL};
2581    char view_number[11];
2582    char number[5];
2583    char workspaceNumber[11];
2584    int fd;
2585    Atom * ws_presence = NULL;
2586    char * workspace_name=NULL;
2587    unsigned long num_workspaces = 0;
2588
2589    Atom actual_type;
2590    int  actual_format;
2591    unsigned long nitems;
2592    unsigned long leftover;
2593    WM_STATE * wm_state;
2594
2595    DialogData * dialog_data;
2596    FileMgrData * file_mgr_data;
2597    FileMgrRec  * file_mgr_rec;
2598    int i;
2599    int j;
2600    char * msg;
2601    int view_index;
2602    WorkspaceRec * workspaceInfo;
2603    char * tmpStr;
2604    Boolean saveTitle;
2605    char *actualSavedTitle;
2606
2607    /* This needs to be done because name_list is static and the values
2608       can be changed during the routine.  This means that they need to be
2609       NULL'd out each pass */
2610    name_list[1] = NULL;
2611    name_list[2] = NULL;
2612    name_list[3] = NULL;
2613    name_list[4] = NULL;
2614    name_list[5] = NULL;
2615
2616    /*  Disable any message box display during save session  */
2617
2618    message_display_enabled = False;
2619
2620
2621    /*  Create the session file  */
2622
2623    if ((fd = creat (path, S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP)) == -1)
2624    {
2625       tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
2626       msg = XtNewString(tmpStr);
2627       _DtSimpleError (application_name, DtError, NULL, msg);
2628       XtFree(msg);
2629       message_display_enabled = True;
2630
2631       return;
2632    }
2633
2634
2635    /*  Write out the general information  */
2636
2637    /* Number of dtfile views */
2638    (void) write (fd, "*", strlen ("*"));
2639    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2640    (void) write (fd, "*view_count:      ", strlen ("*view_count:        "));
2641
2642    if (trashFileMgrData)
2643    {
2644       if (trashFileMgrData->file_mgr_rec)
2645          (void) sprintf (view_number, "%d", view_count + 1);
2646       else
2647          (void) sprintf (view_number, "%d", view_count);
2648    }
2649    else
2650    {
2651       (void) sprintf (view_number, "%d", view_count);
2652    }
2653    (void) write (fd, view_number, strlen (view_number));
2654    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2655
2656    (void) write (fd, "*", strlen ("*"));
2657    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2658    (void) write (fd, "*showFilesystem:  ", strlen ("*showFilesystem:    "));
2659
2660    if(showFilesystem)
2661       (void) write (fd, "True", strlen ("True"));
2662    else
2663       (void) write (fd, "False", strlen ("False"));
2664    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2665
2666    (void) write (fd, "*", strlen ("*"));
2667    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2668    (void) write (fd, "*restrictMode:    ", strlen ("*restrictMode:      "));
2669
2670    if(restrictMode)
2671       (void) write (fd, "True", strlen ("True"));
2672    else
2673       (void) write (fd, "False", strlen ("False"));
2674    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2675
2676    (void) write (fd, "*", strlen ("*"));
2677    (void) write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2678    (void) write (fd, "*openFolder:      ", strlen ("*openFolder:        "));
2679
2680    if(openDirType == NEW)
2681       (void) write (fd, "NEW", strlen ("NEW"));
2682    else
2683       (void) write (fd, "CURRENT", strlen ("CURRENT"));
2684    (void) write (fd, "\n#\n", strlen ("\n#\n"));
2685
2686    view_index = 0;
2687    name_list[1] = view_number;
2688    saveTitle = False;
2689
2690
2691    /*  Write out each of the view's resources  */
2692    /*  start with -1 so we can include the trash dialog */
2693    for (i = -1; i < view_count; i++)
2694    {
2695       if(i == -1)
2696       {
2697          if(trashDialogData)
2698             dialog_data = (DialogData *) trashDialogData;
2699          else
2700             continue;
2701       }
2702       else
2703       {
2704          dialog_data = (DialogData *) view_set[i]->dialog_data;
2705       }
2706
2707       file_mgr_data = (FileMgrData *) dialog_data->data;
2708       if(i == -1 && trashDialogData)
2709           file_mgr_data->IsTrashCan = True;
2710       file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
2711       if(file_mgr_rec == NULL)
2712          continue;
2713
2714       /* This is a bug fix ... We don't want to save the title if the
2715          View is the Trash Can of if it is an Application Manager.  This
2716          is because if the user saves a session in one Locale, then logs
2717          in in another, the Title will be in the locale that the session was
2718          saved in rather then the new local.  So let's save the Title,
2719          Null it out, Save the session info, and finally restore the Title.
2720       */
2721       if(i == -1 || file_mgr_data->toolbox)
2722       {
2723          /* the Trash Can or toolbox (i.e. Application Manager) */
2724          actualSavedTitle = file_mgr_data->title;
2725          file_mgr_data->title = NULL;
2726          saveTitle = True;
2727       }
2728
2729       /*  Getting the WM_STATE property to see if iconified or not */
2730       XGetWindowProperty (display, XtWindow (file_mgr_rec->shell),
2731                              wm_state_atom, 0L, (long) BUFSIZ, False,
2732                              wm_state_atom, &actual_type, &actual_format,
2733                              &nitems, &leftover, (unsigned char **) &wm_state);
2734
2735       /* Write out if iconified our not */
2736
2737       write (fd, "*", strlen ("*"));
2738       write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2739       sprintf (view_number, "%d", view_index);
2740       write (fd, ".", strlen ("."));
2741       write (fd, view_number, strlen (view_number));
2742
2743       (void) write (fd, ".iconify:      ", strlen (".iconify:   "));
2744
2745       if (wm_state->state == IconicState)
2746         write (fd, "True\n", strlen ("True\n"));
2747       else
2748         write (fd, "False\n", strlen ("False\n"));
2749
2750
2751       /*  Get the workspaces for this dt by accessing the property.  */
2752
2753       if (DtWsmGetWorkspacesOccupied (display, XtWindow (file_mgr_rec->shell),
2754                                   &ws_presence, &num_workspaces) == Success)
2755       {
2756          write (fd, "*", strlen ("*"));
2757          write (fd, DTFILE_CLASS_NAME, strlen (DTFILE_CLASS_NAME));
2758          (void) write (fd, ".", strlen ("."));
2759          (void) write (fd, view_number, strlen (view_number));
2760          (void) write (fd, ".workspace: ", strlen (".workspace: "));
2761
2762
2763          for (j = 0; j < num_workspaces; j++)
2764          {
2765             if (j != 0) (void) write (fd, "*", strlen ("*"));
2766             workspace_name = XGetAtomName (display, ws_presence[j]);
2767             (void) write (fd, workspace_name, strlen (workspace_name));
2768             XtFree ((char *) workspace_name);
2769          }
2770
2771
2772          (void) write (fd, "\n", strlen ("\n"));
2773          XFree((char *)ws_presence);
2774       }
2775
2776
2777       /*  Call the encapsulation mechanism to write each dialog  */
2778
2779       if(i == -1)
2780          _DtWriteDialogData (trashDialogData, fd, name_list);
2781       else
2782          _DtWriteDialogData ((DialogData *)view_set[i]->dialog_data,
2783                              fd, name_list);
2784       (void) write (fd, "#\n", strlen ("#\n"));
2785
2786       view_index++;
2787       if(saveTitle)
2788       {
2789          file_mgr_data->title = actualSavedTitle;
2790          saveTitle = False;
2791       }
2792    }
2793
2794    /*
2795     * Save off help dialog information for each workspace.
2796     * These are the help dialogs used for the desktop objects.
2797     */
2798    name_list[1] = WS_LOAD_RES_HEADER;
2799    name_list[2] = workspaceNumber;
2800    name_list[3] = number;
2801
2802    for (i = 0; i < desktop_data->numWorkspaces; i++)
2803    {
2804       workspaceInfo = desktop_data->workspaceData[i];
2805
2806       /*
2807        * Save number of secondary help dialogs in format:
2808        *     *Dtfile.Workspace.<WS#>.secondaryHelpDialogCount:  <#>
2809        */
2810       write(fd, "*", strlen("*"));
2811       write(fd, DTFILE_CLASS_NAME, strlen(DTFILE_CLASS_NAME));
2812       write(fd, WS_RES_HEADER, strlen(WS_RES_HEADER));
2813       sprintf(workspaceNumber, "%d", i);
2814       write(fd, workspaceNumber, strlen(workspaceNumber));
2815       write(fd, SEC_HELP_RES_HEADER, strlen(SEC_HELP_RES_HEADER));
2816       sprintf(view_number, "%d", workspaceInfo->secondaryHelpDialogCount);
2817       write(fd, view_number, strlen(view_number));
2818       write (fd, "\n#\n", strlen ("\n#\n"));
2819
2820       /* Save each of the secondary help dialogs */
2821       for (j = 0; j < workspaceInfo->secondaryHelpDialogCount; j++)
2822       {
2823          sprintf(number, "%d", j + 1);
2824          _DtWriteDialogData(workspaceInfo->secondaryHelpDialogList[j],
2825                            fd, name_list);
2826       }
2827
2828       /* Save the primary help dialog window */
2829       if (workspaceInfo->primaryHelpDialog)
2830       {
2831          sprintf(number, "%d", 0);
2832          _DtWriteDialogData(workspaceInfo->primaryHelpDialog,
2833                            fd, name_list);
2834       }
2835       write (fd, "#\n", strlen ("#\n"));
2836    }
2837    (void) close (fd);
2838
2839    /*  Re-able message box display flag after save session  */
2840    message_display_enabled = True;
2841
2842
2843 }
2844
2845
2846
2847 /*
2848  * Given a directory name, this function will see if a view of the parent
2849  * directory is open; if so, then it will update the icon representing
2850  * this icon, in the parent view, so that it is drawn as 'open'.  This
2851  * function must only be called if openDirType == NEW.
2852  */
2853
2854 void
2855 ForceMyIconOpen (
2856    char * host_name,
2857    char * directory_name)
2858 {
2859    FileViewData * file_view_data = NULL;
2860    DesktopRec *desktopWindow;
2861    DialogData * dd;
2862    FileMgrData * fmd;
2863    char * parent;
2864    char * fname;
2865    char * ptr;
2866    char * full_path;
2867    int i, j, k;
2868    char *icon_name, *new_file_type_name, *file_type_name;
2869    Arg args[5];
2870
2871    /* if directory_name is passed in a NULL, we want to go through all
2872       existing open directories and check to see if there are any open
2873       directories in each of them. This is used at the end of OpenNewView
2874       and the end of ShowNewDirectory */
2875    if (directory_name == NULL)
2876    {
2877       for (i = 0; i < view_count; i++)
2878       {
2879          dd = (DialogData *) view_set[i]->dialog_data;
2880          fmd = (FileMgrData *) dd->data;
2881
2882          for(j = 0; j < fmd->directory_count; j++)
2883          {
2884             ForceMyIconOpen(view_set[i]->host_name,
2885                             fmd->directory_set[j]->name);
2886          }
2887       }
2888       return;
2889    }
2890
2891    parent = _DtPName(directory_name);
2892    fname =  DName(directory_name);
2893
2894    /* first lets check to see if the directory is open in one of the
2895       open file manager views */
2896    for (i = 0; i < view_count; i++)
2897    {
2898       dd = (DialogData *) view_set[i]->dialog_data;
2899       fmd = (FileMgrData *) dd->data;
2900
2901       /* loop through until we find the file_view_data structure for the
2902          directory to force open */
2903       if (strcmp(host_name, view_set[i]->host_name) == 0)
2904       {
2905          for(j = 0; j < fmd->directory_count; j++)
2906          {
2907             if (strcmp(parent, fmd->directory_set[j]->name) == 0)
2908             {
2909                for (k = 0; k < fmd->directory_set[j]->file_count; k++)
2910                {
2911                   file_view_data = fmd->directory_set[j]->file_view_data[k];
2912                   if (strcmp(file_view_data->file_data->file_name, fname) == 0)
2913                      break;
2914                   file_view_data = NULL;
2915                }
2916                break;
2917             }
2918          }
2919       }
2920
2921       if (file_view_data)
2922       {
2923          fmd = (FileMgrData *)(((DirectorySet *)file_view_data->directory_set)->
2924                            file_mgr_data);
2925
2926          file_type_name = file_view_data->file_data->logical_type;
2927
2928          if(fmd->view != BY_NAME)
2929             BuildAndShowIconName(file_type_name, fmd->view,
2930                                  fmd->show_type, file_view_data->widget);
2931       }
2932    }
2933
2934    /* now we need to check to see if the directory being opened has a
2935       representation on the Desktop */
2936    for(i = 0; i < desktop_data->numIconsUsed; i++)
2937    {
2938       char buf[MAX_PATH];
2939
2940       desktopWindow = desktop_data->desktopWindows[i];
2941       file_view_data = desktopWindow->file_view_data;
2942
2943       sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
2944                             desktopWindow->file_name);
2945       DtEliminateDots (buf);
2946
2947       if (strcmp(buf, directory_name) == 0 &&
2948                                     strcmp(desktopWindow->host, host_name) == 0)
2949       {
2950          file_type_name = file_view_data->file_data->logical_type;
2951          if(desktopIconType == LARGE)
2952              BuildAndShowIconName(file_type_name, BY_NAME_AND_ICON,
2953                                  SINGLE_DIRECTORY, desktopWindow->iconGadget);
2954          else /* SMALL */
2955              BuildAndShowIconName(file_type_name, BY_NAME_AND_SMALL_ICON,
2956                                  SINGLE_DIRECTORY, desktopWindow->iconGadget);
2957       }
2958    }
2959 }
2960
2961
2962
2963
2964 /************************************************************************
2965  *
2966  *  RestoreSession
2967  *      Open the file as a resource data base, and use the data to
2968  *      create a set of File Manager views.
2969  *
2970  ************************************************************************/
2971
2972 static int
2973 RestoreSession(
2974         char *path,
2975         int type_of_restore,
2976         char *directory)
2977 {
2978    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL,
2979                                  NULL, NULL };
2980    XrmDatabase db;
2981    XrmName xrm_name[10];
2982    XrmRepresentation rep_type;
2983    XrmValue value;
2984    int num_views = 0;
2985    char * full_path = NULL;
2986    Boolean status=False;
2987    char * temp = NULL;
2988    char wsNum[11];
2989    char dialogNum[11];
2990    int num_sec_help_dialogs;
2991    int i;
2992    int j;
2993    DialogData * dialogData;
2994    struct stat stat_buf;
2995
2996
2997    /* Build the session path if we need to.
2998     * (e.g. When using the -session option)
2999     */
3000     if (type_of_restore == NORMAL_RESTORE)
3001     {
3002       status = DtSessionRestorePath(toplevel, &full_path, path);
3003
3004       if (!status)
3005          return(-1);
3006
3007       if (stat(full_path, &stat_buf) != 0)
3008       {
3009         char *tmpStr, *msg, *title;
3010
3011         tmpStr = GETMESSAGE(18, 18, "Could not open the session file.");
3012         msg = XtNewString(tmpStr);
3013         title = XtNewString((GETMESSAGE(21,39,"File Open Error")));
3014         _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
3015         XtFree(msg);
3016         XtFree(title);
3017         XtFree(full_path);
3018         full_path = NULL;
3019         return(-1);
3020       }
3021
3022       path = XtNewString(full_path);
3023     }
3024
3025    /* This prevents the encapsulator from placing the dialogs */
3026    disableDialogAutoPlacement = True;
3027
3028    /*  Open the file as a resource database and query it to  */
3029    /*  get the previously saved view count.                  */
3030
3031    db = XrmGetFileDatabase (path);
3032
3033    if (type_of_restore == NORMAL_RESTORE)
3034    {
3035       /* first find out if it should show the file system */
3036       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3037       xrm_name [1] = XrmStringToQuark ("showFilesystem");
3038       xrm_name [2] = 0;
3039       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3040       {
3041          if ((temp = (char *) value.addr) != NULL &&
3042                  strcmp (temp, "True") == 0)
3043          {
3044             showFilesystem = True;
3045          }
3046          else
3047             showFilesystem = False;
3048       }
3049       else
3050          showFilesystem = True;
3051
3052       /* find out if it should be in restricted mode */
3053       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3054       xrm_name [1] = XrmStringToQuark ("restrictMode");
3055       xrm_name [2] = 0;
3056       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3057       {
3058          if ((temp = (char *) value.addr) != NULL &&
3059                  strcmp (temp, "True") == 0)
3060          {
3061             restrictMode = True;
3062          }
3063          else
3064             restrictMode = False;
3065       }
3066       else
3067          restrictMode = False;
3068
3069       /* find out openFolder mode */
3070       xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3071       xrm_name [1] = XrmStringToQuark ("openFolder");
3072       xrm_name [2] = 0;
3073       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3074       {
3075          if ((temp = (char *) value.addr) != NULL &&
3076                  strcmp (temp, "NEW") == 0)
3077          {
3078             openDirType = NEW;
3079          }
3080          else
3081             openDirType = CURRENT;
3082       }
3083       else
3084          openDirType = CURRENT;
3085    }
3086
3087    xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3088    xrm_name [1] = XrmStringToQuark ("view_count");
3089    xrm_name [2] = 0;
3090
3091    /* Load standard dtfile views */
3092    if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3093    {
3094       num_views = atoi (value.addr);
3095       if (num_views > 0)
3096          LoadViews(num_views, db, NULL, directory, special_restricted, 0);
3097    }
3098
3099    /* Restore any desktop help dialogs */
3100    if (type_of_restore == NORMAL_RESTORE)
3101    {
3102       for (i = 0; i < desktop_data->numWorkspaces; i++)
3103       {
3104          sprintf(wsNum, "%d", i);
3105          xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3106          xrm_name [1] = XrmStringToQuark (WS_LOAD_RES_HEADER);
3107          xrm_name [2] = XrmStringToQuark (wsNum);
3108          xrm_name [3] = XrmStringToQuark (SEC_LOAD_HELP_RES_HEADER);
3109          xrm_name [4] = 0;
3110
3111          /* Load standard dtfile views */
3112          if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3113          {
3114             num_sec_help_dialogs = atoi (value.addr);
3115             if (num_sec_help_dialogs > 0)
3116             {
3117                desktop_data->workspaceData[i]->secondaryHelpDialogCount =
3118                   num_sec_help_dialogs;
3119                desktop_data->workspaceData[i]->secondaryHelpDialogList =
3120                 (DialogData **) XtMalloc(sizeof(DialogData *) *
3121                    num_sec_help_dialogs);
3122
3123                for (j = 0; j < num_sec_help_dialogs; j++)
3124                {
3125                   name_list[0] = DTFILE_CLASS_NAME;
3126                   name_list[1] = WS_LOAD_RES_HEADER;
3127                   name_list[2] = wsNum;
3128                   name_list[3] = dialogNum;
3129                   name_list[4] = NULL;
3130                   sprintf(dialogNum, "%d", j + 1);
3131                   dialogData =
3132                        _DtGetResourceDialogData(help_dialog, db, name_list);
3133                   desktop_data->workspaceData[i]->secondaryHelpDialogList[j]=
3134                      dialogData;
3135                   ShowDTHelpDialog(NULL, i, HYPER_HELP_DIALOG,
3136                                    dialogData, NULL, NULL, NULL, NULL,
3137                                    DtHELP_TYPE_TOPIC);
3138                }
3139             }
3140          }
3141
3142          /* Load the primary help dialog */
3143          name_list[0] = DTFILE_CLASS_NAME;
3144          name_list[1] = WS_LOAD_RES_HEADER;
3145          name_list[2] = wsNum;
3146          name_list[3] = dialogNum;
3147          name_list[4] = NULL;
3148          sprintf(dialogNum, "%d", 0);
3149          dialogData = _DtGetResourceDialogData(help_dialog, db, name_list);
3150
3151          /* Keep only if currently posted */
3152          if (!(((HelpData *)dialogData->data)->displayed))
3153          {
3154             /* Not currently displayed */
3155             _DtFreeDialogData(dialogData);
3156             dialogData = NULL;
3157          }
3158          desktop_data->workspaceData[i]->primaryHelpDialog = dialogData;
3159          if (dialogData)
3160          {
3161             ShowDTHelpDialog(NULL, i, MAIN_HELP_DIALOG,
3162                              dialogData, NULL, DTFILE_HELP_NAME,
3163                              NULL, NULL, 0);
3164          }
3165       }
3166    }
3167
3168    XtFree(full_path);
3169    full_path = NULL;
3170
3171    /* Free the Xrm Database */
3172    XrmDestroyDatabase(db);
3173    disableDialogAutoPlacement = False;
3174
3175    return(0);
3176 }
3177
3178
3179 static void
3180 ViewAccept(
3181    View *view,
3182    Tt_message msg)
3183 {
3184    extern Tt_message FileCallback();
3185    extern Tt_message SessionCallback();
3186
3187    if ((msg == 0) || tt_is_err( tt_ptr_error( msg ))) {
3188       return;
3189    }
3190    view->msg = msg;
3191    /*
3192     * Register for notifications on the directory viewed.
3193     * This is done so that requesting apps can notify the
3194     * view if the directory name is changed.
3195     */
3196    view->pats = ttdt_file_join( view->directory_name, TT_SESSION, 0,
3197                                 FileCallback, view );
3198    if (tt_is_err( tt_ptr_error( view->pats ))) {
3199       view->pats = 0;
3200    }
3201
3202    /* Returned patterns automatically get destroyed when msg is destroyed */
3203    ttdt_message_accept( msg, SessionCallback,
3204                         _DtGetDialogShell( (DialogData *)view->dialog_data ),
3205                         view, 1, 1 );
3206 }
3207
3208
3209 static void
3210 LoadViews (
3211    int num_views,
3212    XrmDatabase db,
3213    char *host_name,
3214    char *directory_name,
3215    char *type,
3216    Tt_message msg)
3217
3218 {
3219    XrmName xrm_name[5];
3220    XrmRepresentation rep_type;
3221    XrmValue value;
3222    static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL };
3223    char view_number[11];
3224    DialogData * dialog_data;
3225    FileMgrData * file_mgr_data;
3226    char * workspaces;
3227    XClassHint classHints;
3228    char * iconify = NULL;
3229    Boolean iconify_window;
3230    int i;
3231    char *title, *tmpTitle;
3232
3233    name_list[1] = view_number;
3234    xrm_name [0] = XrmStringToQuark (DTFILE_CLASS_NAME);
3235
3236
3237    /*  Get and display view_count views.  */
3238
3239    for (i = 0; i < num_views; i++)
3240    {
3241       struct stat stat_buf;
3242
3243       (void) sprintf (view_number, "%d", i);
3244       xrm_name [1] = XrmStringToQuark (view_number);
3245
3246       /* Get the main dialog data and set up the view  */
3247
3248       dialog_data = _DtGetResourceDialogData (file_mgr_dialog, db, name_list);
3249       file_mgr_data = (FileMgrData *) dialog_data->data;
3250
3251       if(file_mgr_data->toolbox && file_mgr_data->title == NULL)
3252          file_mgr_data->title = DtActionLabel("Dtappmgr");
3253
3254       if (stat(file_mgr_data->current_directory, &stat_buf) != 0)
3255       {
3256          _DtFreeDialogData(dialog_data);
3257          continue;
3258       }
3259
3260       if (trashFileMgrData
3261           && (file_mgr_data->IsTrashCan == True)
3262           && strcmp(file_mgr_data->current_directory, trash_dir) == 0)
3263       {
3264          trashFileMgrData->view = file_mgr_data->view;
3265          trashFileMgrData->order = file_mgr_data->order;
3266          trashFileMgrData->direction = file_mgr_data->direction;
3267          trashFileMgrData->positionEnabled = file_mgr_data->positionEnabled;
3268          trashFileMgrData->preferences = file_mgr_data->preferences;
3269          file_mgr_data->preferences = NULL;
3270          _DtFreeDialogData(dialog_data);
3271          continue;
3272       }
3273
3274       /* Increment the view list size if necessary and add directory to list */
3275
3276       if (view_count == view_set_size)
3277       {
3278          view_set_size += 10;
3279          view_set =
3280             (View **) XtRealloc ((char *)view_set,
3281                                      sizeof (View **) * view_set_size);
3282       }
3283       view_set[view_count] = (View *) XtMalloc (sizeof (View));
3284       view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3285       view_set[view_count]->msg = 0;
3286       view_set[view_count]->pats = 0;
3287
3288       if(restoreType == TOOL_RESTORE)
3289          file_mgr_data->toolbox = True;
3290
3291       if(directory_name == NULL)
3292       {
3293          view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3294          view_set[view_count]->directory_name =
3295             XtNewString (file_mgr_data->current_directory);
3296       }
3297       else
3298       {
3299          XtFree(file_mgr_data->current_directory);
3300          file_mgr_data->current_directory = NULL;
3301          XtFree(file_mgr_data->restricted_directory);
3302          file_mgr_data->restricted_directory = NULL;
3303
3304          view_set[view_count]->directory_name = XtNewString(directory_name);
3305          XtFree((char *)file_mgr_data->selection_list);
3306          file_mgr_data->selection_list = NULL;
3307          if(host_name == NULL)
3308          {
3309             view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3310             file_mgr_data->current_directory = XtNewString(directory_name);
3311             if(type == NULL)
3312               file_mgr_data->restricted_directory =
3313                                               XtNewString(directory_name);
3314             else
3315               file_mgr_data->restricted_directory =
3316                                               XtNewString(type);
3317          }
3318          else
3319          {
3320             view_set[view_count]->host_name = XtNewString (host_name);
3321             XtFree(file_mgr_data->host);
3322             file_mgr_data->host = XtNewString(host_name);
3323             file_mgr_data->current_directory = XtNewString(directory_name);
3324             if(special_view && special_restricted != NULL)
3325                file_mgr_data->restricted_directory =
3326                                      XtNewString(special_restricted);
3327             else
3328                file_mgr_data->restricted_directory = NULL;
3329          }
3330          FileMgrBuildDirectories (file_mgr_data,
3331                           view_set[view_count]->host_name, directory_name);
3332       }
3333
3334       /*  Get the workspace set the view is contained in  */
3335       /*  and set the property for the view just created  */
3336
3337       xrm_name [2] = XrmStringToQuark ("workspace");
3338       xrm_name [3] = 0;
3339
3340       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3341       {
3342          /*  Make sure we have some valid workspaces names to work with */
3343
3344          /* value.addr should = NULL if no workspace names */
3345          workspaces = (char *) value.addr;
3346       }
3347       else
3348         /* we have no workspace resource so use default */
3349         workspaces = NULL;
3350
3351       /*  Get and set whether the view is iconic  */
3352
3353       xrm_name [2] = XrmStringToQuark ("iconify");
3354       xrm_name [3] = 0;
3355
3356       if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value))
3357       {
3358          /*  If there is an iconify resource and its value is True,  */
3359          /*  then mark the window as iconified.                      */
3360
3361          if ((iconify = (char *) value.addr) != NULL &&
3362               strcmp (iconify, "True") == 0)
3363          {
3364            iconify_window = True;
3365
3366          }
3367          else
3368           iconify_window = False;
3369       }
3370       else
3371          iconify_window = False;
3372
3373      if(file_mgr_data->positionEnabled == RANDOM_ON &&
3374                         (file_mgr_data->object_positions == NULL))
3375         LoadPositionInfo(file_mgr_data);
3376
3377       /* Call _DtShowDialog to create and manage the new window */
3378
3379      tmpTitle = file_mgr_data->title;
3380      title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3381      if (special_title)
3382         XtFree(special_title);
3383      special_title = XtNewString(title);
3384
3385      classHints.res_name = title;
3386      classHints.res_class = DTFILE_CLASS_NAME;
3387
3388      _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL,
3389                     RemoveTextFields, NULL, workspaces, iconify_window,
3390                     special_view, title, &classHints);
3391
3392      XtFree(title);
3393      file_mgr_data->title = tmpTitle;
3394
3395      if (msg != 0) {
3396         ViewAccept( view_set[view_count], msg );
3397         msg = 0;
3398      }
3399
3400      view_count++;
3401    }
3402
3403    if (openDirType == NEW)
3404       ForceMyIconOpen(file_mgr_data->host, NULL);
3405 }
3406
3407
3408 /************************************************************************
3409  *
3410  *  GetPWD
3411  *
3412  ************************************************************************/
3413 static void
3414 GetPWD(
3415         char current_directory[] )
3416 {
3417    FILE * pwd_file = NULL;
3418    int i = 0;
3419
3420     /*  Open a pwd process and read the current working directory  */
3421     /*  from it.  If the open fails or a read fails, then display  */
3422     /*  the users home directory.                                  */
3423
3424       pwd_file = popen ("pwd", "r");
3425
3426       if (pwd_file)
3427       {
3428          while (1)
3429          {
3430             errno = 0;
3431             if (fread (&current_directory[i], sizeof(char), 1, pwd_file) != 1)
3432             {
3433                if (errno == EINTR)
3434                   continue;
3435                else
3436                   break;
3437             }
3438
3439             if (current_directory[i] == '\n')
3440                break;
3441
3442             i++;
3443          }
3444       }
3445
3446       if (pwd_file)
3447           pclose (pwd_file);
3448
3449       current_directory[i] = '\0';
3450 }
3451
3452 /************************************************************************
3453  *
3454  *  OpenDirectories
3455  *      Given a string that contains a single or set of host:path
3456  *      specifications, parse out each host:path, validate it as
3457  *      a accessible directory, and call a function to create a
3458  *      file manager view of the directory.
3459  *
3460  ************************************************************************/
3461
3462 static void
3463 OpenDirectories(
3464         char *directory_set,
3465         char *type)
3466 {
3467    char * separator;
3468    char * host;
3469    char * path;
3470
3471    /*  Loop the the directory set string until all of  */
3472    /*  the path specifications have be parsed.    */
3473
3474    while (1)
3475    {
3476       separator = DtStrchr (directory_set, ',');
3477       if (separator != NULL)
3478          *separator = '\0';
3479
3480       _DtPathFromInput(directory_set, NULL, &host, &path);
3481
3482       if (path)
3483       {
3484          GetNewView (host, path, type, NULL, 0);
3485       }
3486       else
3487       {
3488          char *tmpStr, *errTitle, *errMsg, *dmsg;
3489
3490          tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3491          errTitle = XtNewString(tmpStr);
3492          tmpStr = GETMESSAGE(18, 38, "Invalid folder specification, %s");
3493          errMsg = XtNewString(tmpStr);
3494          dmsg = XtMalloc(strlen(errMsg)+strlen(directory_set)+1);
3495          sprintf(dmsg, errMsg, directory_set);
3496          _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
3497
3498          XtFree(errTitle);
3499          XtFree(errMsg);
3500          XtFree(dmsg);
3501       }
3502
3503       /*  Free up the unique host and directory names  */
3504       /*  that were allocated.                         */
3505
3506       XtFree ((char *) host);
3507       XtFree ((char *) path);
3508
3509       /*  Set the starting position of the next host:path  */
3510
3511       if (separator != NULL)
3512          directory_set = separator + 1;
3513       else
3514          break;
3515    }
3516 }
3517
3518
3519
3520
3521 /************************************************************************
3522  *
3523  *  GetNewView
3524  *      Given a directory name, generate a new view for the directory.
3525  *
3526  ************************************************************************/
3527 DialogData *
3528 GetNewView(
3529         char *host_name,
3530         char *directory_name,
3531         char *type,
3532         WindowPosition *position,
3533         Tt_message msg)
3534 {
3535    DialogData * dialog_data;
3536    DialogInstanceData * instance_data;
3537    FileMgrData * file_mgr_data;
3538    FileMgrData * fmd;
3539    FileMgrRec * file_mgr_rec;
3540    char * real_directory_name;
3541    int i;
3542    XClassHint classHints;
3543    char *title, *tmpTitle;
3544    struct stat stat_buf;
3545    char *tmpStr;
3546    char *errMsg = NULL;
3547
3548    DtEliminateDots( directory_name );
3549
3550    if (stat(directory_name, &stat_buf) == 0)
3551    {
3552       if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
3553       {
3554          tmpStr = GETMESSAGE(18, 19,
3555                   "The folder specification,\n%s\nis not a folder.");
3556          errMsg = XtNewString(tmpStr);
3557       }
3558    }
3559    else
3560    {
3561       tmpStr = GETMESSAGE(18, 20,
3562                "The folder specification,\n%s\ndoes not exist.");
3563       errMsg = XtNewString(tmpStr);
3564    }
3565
3566    if (errMsg)
3567    {
3568       char *title, *dmsg;
3569
3570       tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
3571       title = XtNewString(tmpStr);
3572       dmsg = XtMalloc(strlen(errMsg) +
3573                       strlen(directory_name) + 1);
3574       sprintf(dmsg, errMsg, directory_name);
3575       _DtMessage(toplevel, title, dmsg, NULL, HelpRequestCB);
3576
3577       XtFree(errMsg);
3578       XtFree(title);
3579       XtFree(dmsg);
3580       return(NULL);
3581    }
3582
3583    /*
3584     * Special case: When opening any of the special desktop directory
3585     * icons (Home, Remote Systems, etc), we want to display the correct
3586     * path (i.e. $HOME instead of $HOME/.dt/Desktop/Home).  So ... we'll
3587     * do the remap here.
3588     */
3589    real_directory_name = directory_name;
3590
3591    if(openDirType == NEW || (strcmp(real_directory_name, desktop_dir) == 0))
3592    {
3593       for(i = 0; i < view_count; i++)
3594       {
3595          if((strcmp(real_directory_name, view_set[i]->directory_name) == 0 &&
3596             (strcmp(host_name, view_set[i]->host_name) == 0))
3597                                   )
3598          {
3599              Window   rootWindow;
3600              Atom     pCurrent;
3601              Screen   *currentScreen;
3602              int      screen;
3603
3604              dialog_data = (DialogData *) view_set[i]->dialog_data;
3605              file_mgr_data = (FileMgrData *) dialog_data->data;
3606              file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
3607
3608              screen = XDefaultScreen(display);
3609              currentScreen = XScreenOfDisplay(display, screen);
3610              rootWindow = RootWindowOfScreen(currentScreen);
3611
3612              /* Get the current Workspace */
3613              if (DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
3614                                                                    == Success)
3615              {
3616                 Atom * ws_presence = NULL;
3617                 unsigned long num_workspaces = 0;
3618                 int k;
3619
3620                 if (DtWsmGetWorkspacesOccupied(display,
3621                      XtWindow(file_mgr_rec->shell), &ws_presence,
3622                      &num_workspaces) == Success)
3623                 {
3624                    /* Already in this workspace? */
3625                    for (k = 0; k < num_workspaces; k++)
3626                    {
3627                       if (ws_presence[k] == pCurrent)
3628                          break;
3629                    }
3630
3631                    if (k >= num_workspaces)
3632                    {
3633                       /* Add to the workspace */
3634                       ws_presence = (Atom *) XtRealloc((char *)ws_presence,
3635                            sizeof (Atom) * (num_workspaces + 1));
3636
3637                       ws_presence[num_workspaces] = pCurrent;
3638                       DtWsmSetWorkspacesOccupied(display,
3639                                           XtWindow(file_mgr_rec->shell),
3640                                           ws_presence, num_workspaces + 1);
3641                    }
3642                    XFree((char *)ws_presence);
3643                 }
3644                 else
3645                 {
3646                    /* Change the hints to reflect the current workspace */
3647                    DtWsmSetWorkspacesOccupied(display,
3648                                            XtWindow(file_mgr_rec->shell),
3649                                            &pCurrent, 1);
3650                 }
3651              }
3652
3653              /* must map the window to catch iconified windows */
3654              /* a XtPopup will not catch it */
3655              XtMapWidget(file_mgr_rec->shell);
3656              XRaiseWindow(display, XtWindow(file_mgr_rec->shell));
3657
3658              /* announce activity */
3659              {
3660                 Tt_message msg;
3661                 msg = tt_pnotice_create(TT_SESSION, "DtActivity_Began");
3662                 tt_message_send(msg);
3663                 tttk_message_destroy(msg);
3664              }
3665
3666              return(NULL);
3667          }
3668       }
3669    }
3670
3671    /* If in novice mode, force the icon for this dir to the 'Open' state */
3672    if (openDirType == NEW)
3673       ForceMyIconOpen(host_name, directory_name);
3674
3675    /*  Increment the list size if necessary.  */
3676
3677    if (view_count == view_set_size)
3678    {
3679       view_set_size += 10;
3680       view_set =
3681          (View **) XtRealloc ((char *)view_set,
3682                                     sizeof (View **) * view_set_size);
3683    }
3684
3685    view_set[view_count] = (View *) XtMalloc (sizeof (View));
3686    view_set[view_count]->msg = 0;
3687    view_set[view_count]->pats = 0;
3688
3689    if (initiating_view != NULL)
3690       dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3691    else
3692    {
3693       char * tmp_path;
3694       char full_path[MAX_PATH + 1];
3695       XrmDatabase db;
3696
3697       tmp_path = _DtCreateDtDirs(display);
3698       if(type != NULL)
3699          sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
3700       else
3701          sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
3702       XtFree(tmp_path);
3703       db = XrmGetFileDatabase (full_path);
3704       if(db != NULL)
3705       {
3706          if(type != NULL)
3707          {
3708             restoreType = TOOL_RESTORE;
3709             LoadViews(1, db, NULL, directory_name, type, msg);
3710          }
3711          else
3712          {
3713             restoreType = HOME_RESTORE;
3714             LoadViews(1, db, host_name, directory_name, NULL, msg);
3715          }
3716
3717          /*
3718           * Free the Xrm Database
3719           */
3720          XrmDestroyDatabase(db);
3721          dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
3722          file_mgr_data = (FileMgrData *) dialog_data->data;
3723          if(type != NULL)
3724          {
3725             application_args.tool_width = file_mgr_data->width;
3726             application_args.tool_height = file_mgr_data->height;
3727          }
3728          else
3729          {
3730             application_args.dir_width = file_mgr_data->width;
3731             application_args.dir_height = file_mgr_data->height;
3732          }
3733          if(file_mgr_data->find != NULL &&
3734                                 file_mgr_data->current_directory != NULL)
3735          {
3736             DialogData * dialog_data;
3737             FindData * find_data;
3738
3739             dialog_data = (DialogData *)file_mgr_data->find;
3740             find_data = (FindData *)dialog_data->data;
3741
3742             XtFree(find_data->directories);
3743             if(file_mgr_data->restricted_directory == NULL)
3744             {
3745                if(restrictMode)
3746                   find_data->directories = XtNewString(users_home_dir);
3747                else
3748                   find_data->directories =
3749                             XtNewString(file_mgr_data->current_directory);
3750             }
3751             else
3752             {
3753                if(strcmp(file_mgr_data->current_directory,
3754                          file_mgr_data->restricted_directory) == 0)
3755                   find_data->directories = XtNewString("/");
3756                else
3757                   find_data->directories =
3758                         XtNewString(file_mgr_data->current_directory +
3759                         strlen(file_mgr_data->restricted_directory));
3760             }
3761          }
3762
3763          /* If in novice mode, force the icon for all the dir's to the
3764             'Open' state */
3765          if (openDirType == NEW)
3766             ForceMyIconOpen(host_name, NULL);
3767
3768          return((DialogData *)view_set[view_count - 1]->dialog_data);
3769       }
3770       else
3771          dialog_data = _DtGetDefaultDialogData (file_mgr_dialog);
3772    }
3773    view_set[view_count]->dialog_data = (XtPointer) dialog_data;
3774    file_mgr_data = (FileMgrData *) dialog_data->data;
3775
3776    /*  Adjust the view settings if this new view was created  */
3777    /*  because of an action on a previous view.               */
3778
3779    if (initiating_view != NULL)
3780    {
3781       FileMgrPropagateSettings ((FileMgrData *)initiating_view, file_mgr_data);
3782       /* force new window to come up in flat mode */
3783       file_mgr_data->show_type =
3784         ((PreferencesData *)file_mgr_data->preferences->data)->show_type =
3785                                                               SINGLE_DIRECTORY;
3786       file_mgr_data->view = file_mgr_data->view_single;
3787    }
3788
3789       /*  Call the FileMgr dialog to build up its directory set for  */
3790       /*  the directory name.                                        */
3791    FileMgrBuildDirectories (file_mgr_data, host_name, real_directory_name);
3792
3793    if(type != NULL)
3794    {
3795       PreferencesData *preferences_data;
3796
3797       file_mgr_data->toolbox = True;
3798       file_mgr_data->width = application_args.tool_width;
3799       file_mgr_data->height = application_args.tool_height;
3800
3801       /* we want to default for the toolboxes (i.e. Application Manager) to
3802        * look different from a normal File Manager view.  Let's turn off
3803        * the iconic_path, current_directory, and status_line.
3804        */
3805       file_mgr_data->show_iconic_path = False;
3806       file_mgr_data->show_current_dir = False;
3807 /*
3808       file_mgr_data->show_status_line = True;
3809 */
3810
3811       preferences_data = (PreferencesData *)file_mgr_data->preferences->data;
3812       preferences_data->show_iconic_path = file_mgr_data->show_iconic_path;
3813       preferences_data->show_current_dir = file_mgr_data->show_current_dir;
3814       preferences_data->show_status_line = file_mgr_data->show_status_line;
3815    }
3816    else
3817    {
3818       file_mgr_data->toolbox = False;
3819       file_mgr_data->width = application_args.dir_width;
3820       file_mgr_data->height = application_args.dir_height;
3821    }
3822
3823
3824    if(file_mgr_data->find != NULL && file_mgr_data->current_directory != NULL)
3825    {
3826       DialogData * dialog_data;
3827       FindData * find_data;
3828
3829       dialog_data = (DialogData *)file_mgr_data->find;
3830       find_data = (FindData *)dialog_data->data;
3831
3832       XtFree(find_data->directories);
3833       if(file_mgr_data->restricted_directory == NULL)
3834       {
3835          if(restrictMode)
3836             find_data->directories = XtNewString(users_home_dir);
3837          else
3838             find_data->directories =
3839                             XtNewString(file_mgr_data->current_directory);
3840       }
3841       else
3842       {
3843          if(strcmp(file_mgr_data->current_directory,
3844                    file_mgr_data->restricted_directory) == 0)
3845             find_data->directories = XtNewString("/");
3846          else
3847             find_data->directories =
3848                    XtNewString(file_mgr_data->current_directory +
3849                    strlen(file_mgr_data->restricted_directory));
3850       }
3851    }
3852
3853    view_set[view_count]->host_name = XtNewString (file_mgr_data->host);
3854    view_set[view_count]->directory_name =
3855          XtNewString (file_mgr_data->current_directory);
3856
3857    /* Load default position info, or inherit, if appropriate */
3858    if ((fmd = (FileMgrData *)initiating_view) &&
3859        (strcmp(fmd->host, host_name) == 0) &&
3860        (strcmp(fmd->current_directory, real_directory_name) == 0))
3861    {
3862       InheritPositionInfo(fmd, file_mgr_data);
3863    }
3864    else
3865       LoadPositionInfo(file_mgr_data);
3866
3867
3868    /*  Get the dialog displayed.  */
3869    if (position)
3870    {
3871       instance_data = (DialogInstanceData *) dialog_data->data;
3872       instance_data->x = position->x;
3873       instance_data->y = position->y;
3874       instance_data->displayed = True;  /* @@@ Hack! without this,
3875                                           _DtShowDialog will ignore
3876                                            our position info */
3877    }
3878
3879    tmpTitle = file_mgr_data->title;
3880    title = file_mgr_data->title = _DtBuildFMTitle(file_mgr_data);
3881    if (special_title)
3882       XtFree(special_title);
3883    special_title = XtNewString(title);
3884
3885    classHints.res_name = title;
3886    classHints.res_class = DTFILE_CLASS_NAME;
3887    initiating_view = NULL;
3888
3889    _DtShowDialog (NULL, NULL, NULL, dialog_data, NULL, NULL, RemoveTextFields,
3890                NULL, NULL, False, special_view, title, &classHints);
3891
3892    XtFree(title);
3893    file_mgr_data->title = tmpTitle;
3894
3895    if (msg != 0) {
3896       ViewAccept( view_set[view_count], msg );
3897       msg = 0;
3898    }
3899
3900    view_count++;
3901
3902    /* If in novice mode, force the icon for all the dir's to the 'Open' state */
3903    if (openDirType == NEW)
3904       ForceMyIconOpen(host_name, NULL);
3905
3906    return(dialog_data);
3907 }
3908
3909
3910
3911
3912 /************************************************************************
3913  *
3914  *  CloseView
3915  *      Update the view set array when a view is closed.
3916  *
3917  ************************************************************************/
3918
3919 void
3920 CloseView(
3921         DialogData *dialog_data )
3922 {
3923    int i;
3924    int j;
3925    FileMgrData * file_mgr_data;
3926    DialogData * tmpDialog_data;
3927    FileMgrRec * file_mgr_rec;
3928    XmManagerWidget file_window;
3929    char *directory_name = NULL;
3930    char *host_name = NULL;
3931
3932    if(dialog_data == trashDialogData)
3933    {
3934       CloseTrash(NULL, NULL, NULL);
3935       return;
3936    }
3937
3938    for (i = 0; i < view_count; i++)
3939    {
3940       if (dialog_data == (DialogData *) (view_set[i]->dialog_data))
3941       {
3942          tmpDialog_data = (DialogData *) (view_set[i]->dialog_data);
3943          file_mgr_data = (FileMgrData *)tmpDialog_data->data;
3944
3945          directory_name = (char *)XtMalloc( strlen(view_set[i]->directory_name) + 1);
3946          strcpy(directory_name, view_set[i]->directory_name);
3947          host_name = (char *)XtMalloc( strlen(view_set[i]->host_name) + 1);
3948          strcpy(host_name, view_set[i]->host_name);
3949
3950          if (view_set[i]->msg != 0) {
3951             if (view_set[i]->pats != 0) {
3952                ttdt_file_quit( view_set[i]->pats, 0 );
3953                view_set[i]->pats = 0;
3954             }
3955             tt_message_reply( view_set[i]->msg );
3956             tttk_message_destroy( view_set[i]->msg );
3957             view_set[i]->msg = 0;
3958          }
3959
3960          XtFree ((char *) view_set[i]->directory_name);
3961          XtFree ((char *) view_set[i]->host_name);
3962          XtFree ((char *) view_set[i]);
3963          view_set[i] = NULL;
3964
3965          for (j = i; j < view_count - 1; j++)
3966             view_set[j] = view_set[j + 1];
3967
3968          view_count--;
3969
3970          _DtHideDialog (dialog_data, True);
3971
3972          file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
3973          file_window = (XmManagerWidget)file_mgr_rec->file_window;
3974          /* For next time, unmanage all the icons */
3975          XtUnmanageChildren(file_window->composite.children,
3976                             file_window->composite.num_children);
3977
3978          if(PositionFlagSet(file_mgr_data))
3979             SavePositionInfo(file_mgr_data);
3980
3981          /* If it is an Application Manager view, then no point in
3982           caching this dialog, so free it */
3983
3984          if(file_mgr_data->toolbox)
3985             _DtFreeDialog(dialog_data);
3986
3987          _DtFreeDialogData (dialog_data);
3988
3989          break;
3990       }
3991    }
3992
3993
3994    /*  Update the directory cache list to remove unneeded directories.  */
3995
3996    UpdateCachedDirectories (view_set, view_count);
3997
3998    if (openDirType == NEW)
3999       ForceMyIconClosed(host_name, directory_name);
4000
4001    XtFree(directory_name);
4002    XtFree(host_name);
4003 }
4004
4005
4006
4007
4008 /************************************************************************
4009  *
4010  *  DirectoryChanged
4011  *      This function is called when a view may be changing its
4012  *      current directory.  It updates the view_set list to the
4013  *      new host and directory.
4014  *
4015  ************************************************************************/
4016
4017 void
4018 DirectoryChanged(
4019         XtPointer file_mgr_data,
4020         char *old_host_name,
4021         char *new_host_name,
4022         char *old_directory_name,
4023         char *new_directory_name )
4024 {
4025    int i;
4026
4027
4028    /*  See if the directory is one being viewed  */
4029
4030    for (i = 0; i < view_count; i++)
4031    {
4032       if (((DialogData *) (view_set[i]->dialog_data))->data == file_mgr_data)
4033       {
4034          if (strcmp (old_host_name, view_set[i]->host_name) == 0              &&
4035              strcmp (old_directory_name, view_set[i]->directory_name) == 0)
4036          {
4037             XtFree ((char *) view_set[i]->host_name);
4038             view_set[i]->host_name = XtNewString (new_host_name);
4039
4040             XtFree ((char *) view_set[i]->directory_name);
4041             view_set[i]->directory_name = XtNewString (new_directory_name);
4042          }
4043       }
4044    }
4045
4046
4047    /*  Update the directory cache list to remove unneeded directories.  */
4048
4049    UpdateCachedDirectories (view_set, view_count);
4050 }
4051
4052
4053
4054 /************************************************************************
4055  *
4056  *  ObserveTtNotice
4057  *      Dispatch ToolTalk events to internal handlers.
4058  *
4059  ************************************************************************/
4060
4061 static Tt_callback_action
4062 ObserveTtNotice(
4063         Tt_message msg,
4064         Tt_pattern pat
4065 )
4066 {
4067    char *op;
4068    Tt_status status;
4069
4070    op = tt_message_op( msg );
4071    status = tt_ptr_error( op );
4072    if ((status != TT_OK) || (op == 0)) {
4073       /* Let tttk_Xt_input_handler() Do The Right Thing */
4074       return TT_CALLBACK_CONTINUE;
4075    }
4076    if (strcmp( op, "DtTypes_Reloaded" ) == 0) {
4077       ReloadDatabases();
4078    } else if (strcmp( op, "XSession_Ending" ) == 0) {
4079       if( emptyTrashOnExit )
4080          TrashEmpty();
4081    } else {
4082       tt_free( op );
4083       return TT_CALLBACK_CONTINUE;
4084    }
4085    tt_free( op );
4086    tttk_message_destroy( msg );
4087    return TT_CALLBACK_PROCESSED;
4088 }
4089
4090 /************************************************************************
4091  *
4092  *  HandleTtRequest
4093  *      Dispatch ToolTalk requests to internal handlers.
4094  *
4095  ************************************************************************/
4096
4097 Tt_callback_action
4098 HandleTtRequest(
4099         Tt_message msg,
4100         Tt_pattern pat
4101 )
4102 {
4103         char *op;
4104         Tt_status status;
4105
4106         op = tt_message_op( msg );
4107         status = tt_ptr_error( op );
4108         if ((status != TT_OK) || (op == 0)) {
4109                 /* Let tttk_Xt_input_handler() Do The Right Thing */
4110                 return TT_CALLBACK_CONTINUE;
4111         }
4112         if (strcmp( op, "DtFileSession_Run" ) == 0) {
4113                 ViewSessionHandler( msg );
4114         } else if (strcmp( op, "DtFolder_Show" ) == 0) {
4115                 ViewDirectoryHandler( msg );
4116         } else if (strcmp( op, "DtHome_Show" ) == 0) {
4117                 ViewHomeDirectoryHandler( msg );
4118         } else if (strcmp( op, "DtTools_Show" ) == 0) {
4119                 ViewToolsDirectoryHandler( msg );
4120         } else if (strcmp( op, "DtTrash_Show" ) == 0) {
4121                 TrashDisplayHandler( msg );
4122         } else if (strcmp( op, "DtTrash_Remove" ) == 0) {
4123                 TrashRemoveHandler( msg );
4124         } else if (strcmp( op, "DtTrash_Empty" ) == 0) {
4125                 TrashEmptyHandler( msg );
4126         } else if (strcmp( op, "DtTrash_File" ) == 0) {
4127                 TrashRemoveNoConfirmHandler( msg );
4128     } else if (strcmp( op, "DtTrash_Restore" ) == 0) {
4129          TrashRestoreHandler( msg );
4130     } else if (strcmp( op, "DtFile_PutOnWorkspace" ) == 0) {
4131          PutOnWorkspaceHandler( msg );
4132     } else if (strcmp( op, "DtFile_Move" ) == 0) {
4133          MoveCopyLinkHandler( msg, MOVE_FILE );
4134     } else if (strcmp( op, "DtFile_Copy" ) == 0) {
4135          MoveCopyLinkHandler( msg, COPY_FILE );
4136     } else if (strcmp( op, "DtFile_Link" ) == 0) {
4137          MoveCopyLinkHandler( msg, LINK_FILE );
4138     } else {
4139          tt_free( op );
4140          return TT_CALLBACK_CONTINUE;
4141     }
4142     tt_free( op );
4143     return TT_CALLBACK_PROCESSED;
4144 }
4145
4146
4147
4148
4149 /************************************************************************
4150  *
4151  *  ViewSessionHandler
4152  *      This function is called upon the dt session  message
4153  *      being received.  The name of the session file is extracted
4154  *      out of the message and a function is called to create
4155  *      a view or set of views described by the file.
4156  *
4157  ************************************************************************/
4158
4159 static void
4160 ViewSessionHandler(
4161    Tt_message msg)
4162 {
4163    char *file = tt_message_file( msg );
4164    tt_message_reply( msg );
4165    tttk_message_destroy( msg );
4166
4167    if (! tt_is_err( tt_ptr_error( file )))
4168    {
4169       if (view_count == 0 && desktop_data->numIconsUsed == 0)
4170       {
4171            int session_flag = 0;
4172            char *session_name;
4173
4174            session_name = strrchr(file, '/');
4175            session_name++;
4176            LoadDesktopInfo(session_name);
4177            session_flag = RestoreSession (session_name, NORMAL_RESTORE, NULL);
4178            if ((session_flag != 0) && (view_count == 0))
4179            {
4180               char current_directory[MAX_PATH];
4181
4182               GetPWD(current_directory);
4183               if (current_directory[0] != '\0')
4184               {
4185                  if (!GetNewView
4186                       (home_host_name, current_directory, NULL, NULL, 0))
4187                     ViewHomeDirectoryHandler (0);
4188               }
4189               else
4190               {
4191                  ViewHomeDirectoryHandler (0);
4192               }
4193            }
4194       }
4195       else
4196       {
4197            char *tmpStr, *msg, *title;
4198
4199            tmpStr = GETMESSAGE(18, 39, "Cannot start a second File Manager session because a File Manager\nsession is already open on the desktop.  If you want to start a new File\nManager session, you must first close all current File Manager windows\nand remove all File Manager objects from the workspaces.");
4200            msg = XtNewString(tmpStr);
4201            title = XtNewString((GETMESSAGE(18,40,"Session Error")));
4202            _DtMessage (toplevel, title, msg, NULL, HelpRequestCB);
4203            XtFree(msg);
4204            XtFree(title);
4205       }
4206    }
4207    tt_free( file );
4208 }
4209
4210
4211
4212
4213 /************************************************************************
4214  *
4215  *  ViewDirectoryHandler
4216  *      This function is called upon the dt directory message
4217  *      being received.  The name of the directory is extracted
4218  *      out of the message and a function is called to create
4219  *      a view of the directory.
4220  *
4221  ************************************************************************/
4222
4223 static void
4224 ViewDirectoryHandler(
4225    Tt_message msg)
4226 {
4227    int i, j, k;
4228    char *msgFile;
4229    int numArgs;
4230
4231    initiating_view = NULL;
4232    msgFile = tt_message_file( msg );
4233    if (tt_is_err( tt_ptr_error( msgFile ))) msgFile = 0;
4234
4235    if(restrictMode)
4236    {
4237       if(msgFile && strncmp(msgFile, "~", 1) != 0 )
4238       {
4239          if((strcmp(users_home_dir, "/") != 0) &&
4240             (strncmp(msgFile, users_home_dir, strlen(users_home_dir)-1) != 0))
4241          {
4242             char *tmpStr, *errTitle, *errMsg, *dmsg;
4243
4244             tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4245             errTitle = XtNewString(tmpStr);
4246             tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4247             errMsg = XtNewString(tmpStr);
4248             dmsg = XtMalloc(strlen(errMsg)+strlen(msgFile)+1);
4249             sprintf(dmsg, errMsg, msgFile);
4250             _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4251
4252             XtFree(errTitle);
4253             XtFree(errMsg);
4254             XtFree(dmsg);
4255
4256             tt_free( msgFile );
4257             tt_message_reply( msg );
4258             tttk_message_destroy( msg );
4259             return;
4260          }
4261       }
4262    }
4263
4264    numArgs = tt_message_args_count( msg );
4265    if (tt_is_err( tt_int_error( numArgs ))) numArgs = 0;
4266    if (numArgs > 0)
4267    {
4268       special_view = True;
4269       special_treeType = UNSET_VALUE;
4270       special_treeFiles = UNSET_VALUE;
4271       special_viewType = UNSET_VALUE;
4272       special_orderType = UNSET_VALUE;
4273       special_directionType = UNSET_VALUE;
4274       special_randomType = UNSET_VALUE;
4275       special_restricted = NULL;
4276       special_title = NULL;
4277       special_helpVol = XtNewString(DTFILE_HELP_NAME);
4278       for(i = 0; i < numArgs; i++)
4279       {
4280          char *vtype;
4281          char *val;
4282          vtype = tt_message_arg_type( msg, i );
4283          if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4284             continue;
4285          }
4286          val = tt_message_arg_val( msg, i );
4287          if(strcmp(vtype, "-title") == 0)
4288          {
4289             special_title = XtNewString(val);
4290          }
4291          else if(strcmp(vtype, "-help_volume") == 0)
4292          {
4293             special_helpVol = XtNewString(val);
4294          }
4295          if(strcmp(vtype, "-tree") == 0)
4296          {
4297             DtfileStringToTree(val, &special_treeType);
4298          }
4299          else if(strcmp(vtype, "-tree_files") == 0)
4300          {
4301             DtfileStringToTreeFiles(val, &special_treeFiles);
4302          }
4303          else if(strcmp(vtype, VIEW_HEADER) == 0)
4304          {
4305             DtfileStringToView(val, &special_viewType);
4306          }
4307          else if(strcmp(vtype, "-order") == 0)
4308          {
4309             DtfileStringToOrder(val, &special_orderType);
4310          }
4311          else if(strcmp(vtype, "-direction") == 0)
4312          {
4313             DtfileStringToDirection(val, &special_directionType);
4314          }
4315          else if(strcmp(vtype, "-grid") == 0)
4316          {
4317             DtfileStringToGrid(val, &special_randomType);
4318          }
4319          else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4320          {
4321             special_restricted = XtNewString(msgFile);
4322          }
4323          tt_free( val );
4324          tt_free( vtype );
4325
4326          if ((restrictMode) && (!special_restricted))
4327          {
4328             char *ptr;
4329
4330             ptr = strrchr(users_home_dir, '/');
4331             *ptr = '\0';
4332             special_restricted = XtNewString(users_home_dir);
4333             *ptr = '/';
4334          }
4335       }
4336    }
4337    else if (restrictMode)
4338    {
4339      char *ptr;
4340
4341      special_view = True;
4342      special_treeType = treeType;
4343      special_treeFiles = treeFiles;
4344      special_viewType = viewType;
4345      special_orderType = orderType;
4346      special_directionType = directionType;
4347      special_randomType = randomType;
4348
4349      ptr = strrchr(users_home_dir, '/');
4350      *ptr = '\0';
4351      special_restricted = XtNewString(users_home_dir);
4352      *ptr = '/';
4353
4354      special_title = NULL;
4355      special_helpVol = XtNewString(DTFILE_HELP_NAME);
4356
4357    }
4358    else
4359       special_view = False;
4360
4361    OpenDirectories (msgFile, NULL);
4362
4363    tt_free( msgFile );
4364    tt_message_reply( msg );
4365    tttk_message_destroy( msg );
4366 }
4367
4368
4369
4370
4371 /************************************************************************
4372  *
4373  *  ViewDirectoryProc
4374  *      This function is called upon the dt directory message
4375  *      being received.  The name of the directory is extracted
4376  *      out of the message and a function is called to create
4377  *      a view of the directory.  This function is passed directly
4378  *      to DtActionInvoke to be used as a callback.
4379  *
4380  ************************************************************************/
4381
4382 DialogData *
4383 ViewDirectoryProc(
4384    char* root_dir,
4385    int restricted,
4386    Tt_message msg
4387 )
4388 {
4389    DialogData *return_data;
4390
4391    if(restrictMode)
4392    {
4393       if(root_dir && strncmp(root_dir, "~", 1) != 0 )
4394       {
4395          if((strcmp(users_home_dir, "/") != 0) &&
4396             (strncmp(root_dir, users_home_dir, strlen(users_home_dir)-1) != 0))
4397          {
4398             char *tmpStr, *errTitle, *errMsg, *dmsg;
4399
4400             tmpStr = GETMESSAGE(32, 2, "File Manager Open Directory Error");
4401             errTitle = XtNewString(tmpStr);
4402             tmpStr = GETMESSAGE(2,20,"You cannot switch to folder:\n\n%s\n\nYou are not allowed to view this folder\nbecause it is a restricted folder.");
4403             errMsg = XtNewString(tmpStr);
4404             dmsg = XtMalloc(strlen(errMsg)+strlen(root_dir)+1);
4405             sprintf(dmsg, errMsg, root_dir);
4406             _DtMessage(toplevel, errTitle, dmsg, NULL, HelpRequestCB);
4407
4408             XtFree(errTitle);
4409             XtFree(errMsg);
4410             XtFree(dmsg);
4411             return NULL;
4412          }
4413       }
4414    }
4415
4416    initiating_view = NULL;
4417    special_view = True;
4418    special_treeType = treeType;
4419    special_treeFiles = treeFiles;
4420    special_viewType = viewType;
4421    special_orderType = orderType;
4422    special_directionType = directionType;
4423    special_randomType = randomType;
4424
4425    if (restricted) {
4426      special_restricted = XtNewString(root_dir);
4427    }
4428    else {
4429      special_restricted = NULL;
4430    }
4431
4432    if ((restrictMode) && (!special_restricted))
4433    {
4434       char *ptr;
4435
4436       ptr = strrchr(users_home_dir, '/');
4437       *ptr = '\0';
4438       special_restricted = XtNewString(users_home_dir);
4439       *ptr = '/';
4440    }
4441
4442    special_title = NULL;
4443    special_helpVol = XtNewString(DTFILE_HELP_NAME);
4444
4445    return_data = GetNewView (home_host_name, root_dir, NULL, NULL, msg);
4446
4447    if ((!return_data) && msg)
4448    {
4449       tt_message_reply(msg);
4450       tttk_message_destroy( msg );
4451    }
4452
4453    return(return_data);
4454 }
4455
4456
4457
4458 /************************************************************************
4459  *
4460  *  ViewHomeDirectoryHandler
4461  *      This function is called upon the dt home directory message
4462  *      being received.  The home directory is extracted from the
4463  *      users uid and used to open the directory.
4464  *
4465  ************************************************************************/
4466
4467
4468 static void
4469 ViewHomeDirectoryHandler(
4470    Tt_message msg)
4471 {
4472    int i, j, k;
4473    struct passwd * pwInfo;
4474    char * homeDir;
4475    char * tmp_path;
4476    char full_path[MAX_PATH + 1];
4477    struct stat stat_buf;
4478    int numArgs;
4479
4480    /* We have a new view so set initiating_view to null */
4481    initiating_view = NULL;
4482
4483    if ((homeDir = getenv("HOME")) == NULL || strlen (homeDir) == 0)
4484    {
4485       pwInfo = getpwuid (getuid());
4486       homeDir = pwInfo->pw_dir;
4487    }
4488
4489    /* Look and see if we have a default environment file present */
4490    tmp_path = _DtCreateDtDirs(display);
4491
4492    numArgs = 0;
4493    if (msg) numArgs = tt_message_args_count(msg);
4494    if (tt_is_err(tt_int_error(numArgs))) numArgs = 0;
4495    if (numArgs > 0)
4496    {
4497       special_view = True;
4498       special_treeType = UNSET_VALUE;
4499       special_treeFiles = UNSET_VALUE;
4500       special_viewType = UNSET_VALUE;
4501       special_orderType = UNSET_VALUE;
4502       special_directionType = UNSET_VALUE;
4503       special_randomType = UNSET_VALUE;
4504       special_restricted = NULL;
4505       special_title = NULL;
4506       special_helpVol = XtNewString(DTFILE_HELP_NAME);
4507       for(i = 0; i < numArgs; i++)
4508       {
4509          char *vtype;
4510          char *val;
4511          vtype = tt_message_arg_type( msg, i );
4512          if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4513             continue;
4514          }
4515          val = tt_message_arg_val(msg, i);
4516          if(strcmp(vtype, "-title") == 0)
4517          {
4518             special_title = XtNewString(val);
4519          }
4520          else if(strcmp(vtype, "-help_volume") == 0)
4521          {
4522             special_helpVol = XtNewString(val);
4523          }
4524          if(strcmp(vtype, "-tree") == 0)
4525          {
4526             DtfileStringToTree(val, &special_treeType);
4527          }
4528          else if(strcmp(vtype, "-tree_files") == 0)
4529          {
4530             DtfileStringToTreeFiles(val, &special_treeFiles);
4531          }
4532          else if(strcmp(vtype, VIEW_HEADER) == 0)
4533          {
4534             DtfileStringToView(val, &special_viewType);
4535          }
4536          else if(strcmp(vtype, "-order") == 0)
4537          {
4538             DtfileStringToOrder(val, &special_orderType);
4539          }
4540          else if(strcmp(vtype, "-direction") == 0)
4541          {
4542             DtfileStringToDirection(val, &special_directionType);
4543          }
4544          else if(strcmp(vtype, "-grid") == 0)
4545          {
4546             DtfileStringToGrid(val, &special_randomType);
4547          }
4548          else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4549          {
4550             special_restricted = XtNewString(val);
4551          }
4552          tt_free( val );
4553          tt_free( vtype );
4554       }
4555    }
4556    else if (restrictMode)
4557    {
4558      char *ptr;
4559
4560      special_view = True;
4561      special_treeType = treeType;
4562      special_treeFiles = treeFiles;
4563      special_viewType = viewType;
4564      special_orderType = orderType;
4565      special_directionType = directionType;
4566      special_randomType = randomType;
4567
4568      ptr = strrchr(users_home_dir, '/');
4569      *ptr = '\0';
4570      special_restricted = XtNewString(users_home_dir);
4571      *ptr = '/';
4572
4573      special_title = NULL;
4574      special_helpVol = XtNewString(DTFILE_HELP_NAME);
4575    }
4576    else
4577       special_view = False;
4578
4579    if (tmp_path == NULL)
4580       OpenDirectories (homeDir, NULL);
4581    else
4582    {
4583      sprintf(full_path, "%s/%s", tmp_path, HOME_SETTINGS_FILENAME);
4584      XtFree(tmp_path);
4585
4586      /* Stat the file and make sure its there */
4587      if(numArgs > 0)
4588      {
4589         if (stat (full_path, &stat_buf) == 0 && numArgs < 1)
4590         {
4591            restoreType = HOME_RESTORE;
4592            RestoreSession(full_path, HOME_RESTORE, NULL);
4593            restoreType = NORMAL_RESTORE;
4594         }
4595         else
4596         {
4597            char *ptr;
4598
4599            ptr = strrchr(users_home_dir, '/');
4600            *ptr = '\0';
4601            strcpy(full_path, users_home_dir);
4602            *ptr = '/';
4603            OpenDirectories (full_path, NULL);
4604         }
4605      }
4606      else if (numArgs < 1 && stat (full_path, &stat_buf) == 0)
4607      {
4608         restoreType = HOME_RESTORE;
4609         RestoreSession(full_path, HOME_RESTORE, NULL);
4610         restoreType = NORMAL_RESTORE;
4611      }
4612      else
4613      {
4614        char *ptr;
4615
4616        ptr = strrchr(users_home_dir, '/');
4617
4618        if( ptr != users_home_dir )
4619          *ptr = '\0';
4620
4621        strcpy(full_path, users_home_dir);
4622        *ptr = '/';
4623
4624        OpenDirectories (full_path, NULL);
4625      }
4626    }
4627
4628    if(msg)
4629    {
4630      tt_message_reply(msg);
4631      tttk_message_destroy(msg);
4632    }
4633 }
4634
4635 /************************************************************************
4636  *
4637  *  ViewToolsDirectroyHandler
4638  *      This function is called upon the dt tools message
4639  *      being received.  The names of the tools directories are
4640  *      retrieved from libXue, a view is created and the change
4641  *      directory dialog for the view is displayed with the
4642  *      set of directories contained in the list.
4643  *
4644  ************************************************************************/
4645
4646 static void
4647 ViewToolsDirectoryHandler(
4648    Tt_message msg)
4649 {
4650    int i;
4651    char * tmp_path = NULL;
4652    char * tool_dir = NULL;
4653    char * msgFile = NULL;
4654    int numArgs = 0;
4655
4656    /* We have a new view so set initiating_view to null */
4657    initiating_view = NULL;
4658
4659    /* Look and see if we have a default environment file present */
4660    tmp_path = _DtCreateDtDirs(display);
4661
4662    if (msg) msgFile = tt_message_file(msg);
4663    if (tt_is_err(tt_ptr_error(msgFile))) msgFile = 0;
4664
4665    if (msg) numArgs = tt_message_args_count(msg);
4666    if (tt_is_err(tt_int_error( numArgs ))) numArgs = 0;
4667
4668    if(msgFile != NULL)
4669    {
4670       if(numArgs > 0)
4671       {
4672          char *link_point = NULL;
4673          char *root_toolbox = NULL;
4674          char *user_install_point = NULL;
4675
4676          special_view = True;
4677          special_treeType = treeType;
4678          special_treeFiles = treeFiles;
4679          special_viewType = viewType;
4680          special_orderType = orderType;
4681          special_directionType = directionType;
4682          special_randomType = randomType;
4683          special_restricted = XtNewString(msgFile);
4684          special_title = NULL;
4685          special_helpVol = XtNewString(DTFILE_HELP_NAME);
4686          for(i = 0; i < numArgs; i++)
4687          {
4688             char *vtype;
4689             char *val;
4690             vtype = tt_message_arg_type( msg, i );
4691             if ((vtype == 0) || (tt_is_err( tt_ptr_error( vtype )))) {
4692                continue;
4693             }
4694             val = tt_message_arg_val( msg, i );
4695             if(strcmp(vtype, "-title") == 0)
4696             {
4697                special_title = XtNewString(val);
4698             }
4699             else if(strcmp(vtype, "-help_volume") == 0)
4700             {
4701                special_helpVol = XtNewString(val);
4702             }
4703             else if(strcmp(vtype, "-root") == 0)
4704             {
4705                root_toolbox = XtNewString(val);
4706             }
4707             else if(strcmp(vtype, "-common_link_point") == 0)
4708             {
4709                link_point = XtNewString(val);
4710             }
4711             else if(strcmp(vtype, "-user_install_point") == 0)
4712             {
4713                user_install_point = XtNewString(val);
4714             }
4715             if(strcmp(vtype, "-tree") == 0)
4716             {
4717                DtfileStringToTree(val, &special_treeType);
4718             }
4719             else if(strcmp(vtype, "-tree_files") == 0)
4720             {
4721                DtfileStringToTreeFiles(val, &special_treeFiles);
4722             }
4723             else if(strcmp(vtype, VIEW_HEADER) == 0)
4724             {
4725                DtfileStringToView(val, &special_viewType);
4726             }
4727             else if(strcmp(vtype, "-order") == 0)
4728             {
4729                DtfileStringToOrder(val, &special_orderType);
4730             }
4731             else if(strcmp(vtype, "-direction") == 0)
4732             {
4733                DtfileStringToDirection(val, &special_directionType);
4734             }
4735             else if(strcmp(vtype, "-grid") == 0)
4736             {
4737                DtfileStringToGrid(val, &special_randomType);
4738             }
4739             else if(strcmp(vtype, RESTRICTED_HEADER) == 0)
4740             {
4741                ;
4742             }
4743             tt_free( val );
4744             tt_free( vtype );
4745          }
4746          /* Due to the use of tooltalk messaging, app manager objects
4747             that are dragged either to the desktop or to the front
4748             panel are identified by their fully resolved names (ie.
4749             /usr/dt/appconfig/appmanager/$LANG/.... as opposed to
4750             /var/dt/appconfig/appmanager/$DTUSERSESSION/....).  In order
4751             for the File Manager to treat these objects as links existing
4752             in the /var/.... directory, we use the following ugly code:
4753
4754               1. Search the incoming path for $LANG (if you can't find
4755                  $LANG, try C since this is the default).
4756               2. Concatenate the path following $LANG to the path for the
4757                  root toolbox (this comes in with the tooltalk message
4758                  so that we don't have to hardcode it).
4759               3. Call OpenDirectories with the new path that you have
4760                  created and with the root toolbox path as the restricted
4761                  directory.
4762
4763             This problem is further complicated by:
4764               1. Users traversing into APPGROUPs.
4765               2. Users opening the parent folders for workspace APPGROUPs.
4766
4767             For situation 1, File Manager kicks the user into the App Manager
4768             if he/she traverses into an APPGROUP.  BUT we don't want to
4769             make modifications to the path as we do above.
4770             So, if there is nothing following $LANG or if we can't find
4771             $LANG in the path,
4772             (ie. /var/dt/appconfig/appmanager/$DTUSERSESSION), call
4773             OpenDirectories with no parameter changes.
4774
4775             For situation 2, File Manager is unable to distinguish between
4776             workspace objects dragged from /usr/.... or /var/...., so
4777             the parent folder for all workspace APPGROUPS is considered to
4778             be in the /var path.  In addition to the OpenAppGroup action,
4779             there is an OpenParentAppGroup action which also triggers
4780             ViewToolsDirectoryHandler but sends in an additional
4781             parameter (user_install_point).
4782             If we know that this msg was generated by the OpenParentAppGroup
4783             action
4784             AND nothing follows $LANG.
4785               Modify the parameters as above.
4786             OR we can't find $LANG but we can find the user_install_point
4787               (user's personal appgroup path).
4788               Concatenate the path following .dt/appmanager to the path for the
4789               root toolbox. Call OpenDirectories with the new path and the
4790               root toolbox as the restricted directory.
4791          */
4792          if( root_toolbox )
4793          {
4794             if( link_point )
4795             {
4796                char *ptr;
4797
4798                if ((user_install_point) &&
4799                    (ptr = strstr(msgFile, user_install_point)))
4800                {
4801                   ptr += strlen(user_install_point);
4802                   tool_dir = XtMalloc(strlen(root_toolbox) + strlen(ptr) + 1);
4803                   sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4804                   XtFree(special_restricted);
4805                   special_restricted = XtNewString(root_toolbox);
4806                }
4807                else
4808                {
4809                   ptr = strstr(msgFile, link_point);
4810
4811                   if (!ptr)
4812                   {
4813                      XtFree(link_point);
4814                      link_point = XtNewString("C");
4815                      ptr = strstr(msgFile, link_point);
4816                   }
4817
4818                   if (ptr)
4819                   {
4820                      ptr += strlen(link_point);
4821                      if (strcmp(ptr, "") != 0)
4822                      {
4823                         tool_dir = XtMalloc(strlen(root_toolbox) +
4824                                             strlen(ptr) + 1);
4825                         sprintf(tool_dir, "%s%s", root_toolbox, ptr);
4826                         XtFree(special_restricted);
4827                         special_restricted = XtNewString(root_toolbox);
4828                      }
4829                      else if (user_install_point)
4830                      {
4831                         tool_dir = XtNewString(root_toolbox);
4832                         XtFree(special_restricted);
4833                         special_restricted = XtNewString(root_toolbox);
4834                      }
4835                   }
4836                }
4837             }
4838          }
4839          XtFree(link_point);
4840          XtFree(root_toolbox);
4841          XtFree(user_install_point);
4842       }
4843       else if (restrictMode)
4844       {
4845          char *ptr;
4846
4847          special_view = True;
4848          ptr = strrchr(users_home_dir, '/');
4849          *ptr = '\0';
4850          special_restricted = XtNewString(users_home_dir);
4851          *ptr = '/';
4852       }
4853       else
4854          special_view = False;
4855    }
4856
4857    if (tmp_path == NULL)
4858    {
4859       if (tool_dir)
4860          OpenDirectories (tool_dir, special_restricted);
4861       else if (msgFile != NULL)
4862          OpenDirectories (msgFile, special_restricted);
4863    }
4864    else
4865    {
4866       char full_path[MAX_PATH + 1];
4867       struct stat stat_buf;
4868
4869       sprintf(full_path, "%s/%s", tmp_path, TOOL_SETTINGS_FILENAME);
4870       XtFree(tmp_path);
4871
4872       /* Stat the file and make sure its there */
4873       if (stat (full_path, &stat_buf) == 0 && numArgs > 0)
4874       {
4875          DialogData * dialog_data;
4876          FileMgrData * file_mgr_data;
4877
4878          restoreType = TOOL_RESTORE;
4879          if (tool_dir)
4880             RestoreSession(full_path, TOOL_RESTORE, tool_dir);
4881          else
4882             RestoreSession(full_path, TOOL_RESTORE, msgFile);
4883          dialog_data = (DialogData *)view_set[view_count - 1]->dialog_data;
4884          file_mgr_data = (FileMgrData *) dialog_data->data;
4885          application_args.tool_width = file_mgr_data->width;
4886          application_args.tool_height = file_mgr_data->height;
4887          restoreType = NORMAL_RESTORE;
4888       }
4889       else
4890       {
4891          if (tool_dir)
4892             OpenDirectories (tool_dir, special_restricted);
4893          else if (msgFile != NULL)
4894             OpenDirectories (msgFile, special_restricted);
4895       }
4896    }
4897
4898    if( msgFile )
4899      tt_free( msgFile );
4900
4901    if( msg )
4902    {
4903      tt_message_reply( msg );
4904      tttk_message_destroy( msg );
4905    }
4906
4907    if (tool_dir)
4908       XtFree(tool_dir);
4909 }
4910
4911
4912 /************************************************************************
4913  *
4914  *  ExitHandler
4915  *      This function is called upon the DtSTOP message.
4916  *
4917  ************************************************************************/
4918
4919 static void
4920 ExitHandler(
4921    Tt_message msg,
4922    XtPointer clientData,
4923    String * messageFields,
4924    int numFields)
4925 {
4926    tt_message_reply( msg );
4927    tttk_message_destroy( msg );
4928    FinalizeToolTalkSession( );
4929    exit(0);
4930 }
4931
4932
4933 /*
4934  * This is the message handling function responsible for reloading
4935  * the filetype and action databases, and then updating our collection
4936  * of action menu items, and updating all open views.
4937  */
4938
4939 static void
4940 ReloadDatabases(void)
4941 {
4942    int i;
4943    DialogData * dialog_data;
4944    FileMgrData * file_mgr_data;
4945    FileMgrRec  * file_mgr_rec;
4946    FileViewData *file_view_data;
4947    DesktopRec *desktopWindow;
4948
4949    DtDbLoad();
4950
4951    XmeFlushIconFileCache ( NULL );
4952
4953    /* Update each directory_set view, both mapped and not */
4954    UpdateDirectorySet();
4955
4956    /* Force action menus to update the next time they're posted */
4957    XtFree(fileMgrPopup.action_pane_file_type);
4958    fileMgrPopup.action_pane_file_type = NULL;
4959    XtFree(desktop_data->popupMenu->action_pane_file_type);
4960    desktop_data->popupMenu->action_pane_file_type = NULL;
4961
4962    /* Update each view */
4963    for (i = 0; i < view_count; i++)
4964    {
4965       dialog_data = (DialogData *)view_set[i]->dialog_data;
4966       file_mgr_data = (FileMgrData *) dialog_data->data;
4967       file_mgr_rec = (FileMgrRec *) file_mgr_data->file_mgr_rec;
4968       XtFree(file_mgr_rec->action_pane_file_type);
4969       file_mgr_rec->action_pane_file_type = NULL;
4970       UpdateFilterAfterDBReread(file_mgr_data->filter_active);
4971       UpdateFilterAfterDBReread(file_mgr_data->filter_edit);
4972       FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
4973    }
4974
4975    /* go through the desktop objects to make sure the icons change
4976     * Do this by setting the logical_type to -l, CheckDesktop will
4977     * then update the logical type and the icon
4978     */
4979    for(i = 0; i < desktop_data->numIconsUsed; i++)
4980    {
4981       desktopWindow = desktop_data->desktopWindows[i];
4982       file_view_data = desktopWindow->file_view_data;
4983
4984       file_view_data->file_data->logical_type = NULL;
4985    }
4986    CheckDesktop();
4987 }
4988
4989
4990 /*
4991  * Whenever a directory view or drawer view is closed, we need to remove
4992  * any of its text field children, so that they will not magically reappear
4993  * should this view be reused from the cache to view the same directory later.
4994  */
4995
4996 static void
4997 RemoveTextFields (
4998    XtPointer client_data,
4999    DialogData * old_dialog_data,
5000    DialogData * new_dialog_data)
5001 {
5002    FileMgrRec * file_mgr_rec;
5003    XmManagerWidget file_window;
5004    int i;
5005    int num_children;
5006
5007    file_mgr_rec = (FileMgrRec *) _DtGetDialogInstance(old_dialog_data);
5008    file_window = (XmManagerWidget) file_mgr_rec->file_window;
5009    num_children = file_window->composite.num_children;
5010
5011    for (i = 0; i < num_children; i++)
5012    {
5013       if (XmIsTextField(file_window->composite.children[i]))
5014          XtDestroyWidget(file_window->composite.children[i]);
5015    }
5016
5017    _DtFreeDialogData (new_dialog_data);
5018 }
5019
5020
5021 /*
5022  * This function searches the view list, and returns the file_mgr_data
5023  * associated with the passed-in widget.
5024  */
5025
5026 FileMgrData *
5027 ReturnDesktopPtr (
5028    Widget w)
5029 {
5030    int i;
5031    DialogData * dialog_data;
5032    FileMgrData * file_mgr_data;
5033
5034    for (i = 0; i < view_count; i++)
5035    {
5036       dialog_data = (DialogData *) view_set[i]->dialog_data;
5037       file_mgr_data = (FileMgrData *) dialog_data->data;
5038
5039       if (w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->file_window ||
5040           w == ((FileMgrRec *)file_mgr_data->file_mgr_rec)->shell)
5041          return(file_mgr_data);
5042    }
5043
5044    return(NULL);
5045 }
5046
5047
5048 PixmapData *
5049 CheckForOpenDirectory(
5050      FileViewData *order_list,
5051      DirectorySet *directory_set,
5052      FileMgrData *file_mgr_data,
5053      char * logical_type)
5054 {
5055    int i;
5056    char *ptr;
5057    char *file_type_name, *new_file_type_name;
5058    char directory_name[MAX_PATH];
5059    char * real_dir_name;
5060    FileMgrRec *file_mgr_rec;
5061    int icon_size;
5062    PixmapData *pixmapData = NULL;
5063
5064    if (file_mgr_data->view == BY_NAME_AND_ICON)
5065      icon_size = LARGE;
5066    else
5067      icon_size = SMALL;
5068
5069    file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5070
5071    if (strcmp (directory_set->name, "/") != 0)
5072      sprintf( directory_name, "%s/%s", directory_set->name, order_list->file_data->file_name);
5073    else
5074      sprintf( directory_name, "%s%s", directory_set->name, order_list->file_data->file_name );
5075
5076    (void) DtEliminateDots (directory_name);
5077
5078    real_dir_name = XtNewString(directory_name);
5079
5080    for(i = 0; i < view_count; i++)
5081    {
5082       if(strcmp(real_dir_name, view_set[i]->directory_name) == 0)
5083       {
5084          file_type_name = order_list->file_data->logical_type;
5085          new_file_type_name = (char *)XtMalloc(strlen(file_type_name)
5086                                                + strlen(ICON_OPEN_PREFIX) + 1);
5087          sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5088          pixmapData = _DtRetrievePixmapData(new_file_type_name,
5089                                             NULL,
5090                                             NULL,
5091                                             file_mgr_rec->file_window,
5092                                             icon_size);
5093          XtFree(new_file_type_name);
5094          break;
5095       }
5096    }
5097    XtFree(real_dir_name);
5098
5099    if(pixmapData == NULL || pixmapData->iconFileName == NULL)
5100    {
5101      if( pixmapData != NULL )
5102      {
5103        DtDtsFreeAttributeValue(pixmapData->hostPrefix);
5104        DtDtsFreeAttributeValue(pixmapData->instanceIconName);
5105        DtDtsFreeAttributeValue(pixmapData->iconName);
5106        XtFree((char *)pixmapData);
5107      }
5108
5109        pixmapData = _DtRetrievePixmapData(logical_type,
5110                                           NULL,
5111                                           NULL,
5112                                           file_mgr_rec->file_window,
5113                                           icon_size);
5114    }
5115
5116    return(pixmapData);
5117 }
5118
5119
5120 /*
5121  * The is the menu callback function for cleaning up a view.
5122  */
5123
5124 void
5125 CleanUp (
5126    Widget w,
5127    XtPointer client_data,
5128    XtPointer call_data)
5129 {
5130    Widget mbar;
5131    Arg args[2];
5132    FileMgrRec * file_mgr_rec;
5133    DialogData * dialog_data;
5134    FileMgrData * file_mgr_data;
5135    int i, j;
5136    XmManagerWidget file_window;
5137    char * name;
5138    FileViewData * file_view_data;
5139    XRectangle textExtent;
5140    Position x, y;
5141
5142    if ((int)(XtArgVal) client_data == FM_POPUP)
5143      mbar = XtParent(w);
5144    else
5145      mbar = XmGetPostedFromWidget(XtParent(w));
5146
5147    XmUpdateDisplay(w);
5148    XtSetArg(args[0], XmNuserData, &file_mgr_rec);
5149    XtGetValues(mbar, args, 1);
5150
5151    /* Ignore accelerators when we're insensitive */
5152    if ((file_mgr_rec->menuStates & CLEAN_UP) == 0)
5153       return;
5154
5155    /* Ignore accelerators received after we're unposted */
5156    if ((dialog_data = _DtGetInstanceData((XtPointer)file_mgr_rec)) == NULL)
5157       return;
5158
5159    file_mgr_data = (FileMgrData *)dialog_data->data;
5160
5161    /* Reset the grid size, so it will be recalculated later. */
5162    file_mgr_data->grid_height = 0;
5163    file_mgr_data->grid_width = 0;
5164
5165    if(file_mgr_data->object_positions)
5166       FreePositionInfo(file_mgr_data);
5167
5168    /* CLEAN_UP_OP is not really a menu state.
5169       It's a flag to let GetFileData in FileMgr.c (call when the directory
5170       is being reread) not to reload icon positions from the .!dt<userid> file.
5171    */
5172    file_mgr_rec->menuStates |= CLEAN_UP_OP;
5173
5174    /* Re-layout the view */
5175    FileMgrRedisplayFiles(file_mgr_rec, file_mgr_data, False);
5176
5177    if ((file_mgr_data->show_type == SINGLE_DIRECTORY) &&
5178         (file_mgr_data->view != BY_ATTRIBUTES) &&
5179         (file_mgr_data->positionEnabled == RANDOM_ON))
5180    {
5181       ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5182           RANDOM_ON;
5183    }
5184    else
5185    {
5186       /* Update the preferences dialog */
5187       ((PreferencesData *)(file_mgr_data->preferences->data))->positionEnabled =
5188           RANDOM_OFF;
5189    }
5190
5191    /* Move any text widget, to keep them in sync with their icons */
5192    file_window = (XmManagerWidget)file_mgr_rec->file_window;
5193
5194    for (j = 0; j < file_window->composite.num_children; j++)
5195    {
5196       if (XmIsTextField(file_window->composite.children[j]) &&
5197           !file_window->composite.children[j]->core.being_destroyed)
5198       {
5199          XtSetArg(args[0], XmNuserData, &name);
5200          XtGetValues(file_window->composite.children[j], args, 1);
5201
5202          /* Find the associated icon data */
5203          /* @@@ this won't work for tree mode! */
5204          for (i = 0; i < file_mgr_data->directory_set[0]->file_count; i++)
5205          {
5206             file_view_data = file_mgr_data->directory_set[0]->file_view_data[i];
5207             if (strcmp(name, file_view_data->file_data->file_name) == 0)
5208             {
5209                _DtIconGetTextExtent_r(file_view_data->widget, &textExtent);
5210                x = textExtent.x;
5211                y = textExtent.y -
5212                    (Dimension)(file_window->composite.children[j]->core.height -
5213                     textExtent.height)/(Dimension)2;
5214                XtSetArg (args[0], XmNx, x);
5215                XtSetArg (args[1], XmNy, y);
5216                XtSetValues (file_window->composite.children[j], args, 2);
5217                break;
5218             }
5219          }
5220       }
5221    }
5222
5223    if ((file_mgr_rec->menuStates & CLEAN_UP_OP))
5224      file_mgr_rec->menuStates  &= ~CLEAN_UP_OP;
5225 }
5226
5227 /*************************************<->*************************************
5228  *
5229  *  DtfileCvtStringToObjPlace (args, numArgs, fromVal, toVal)
5230  *
5231  *
5232  *  Description:
5233  *  -----------
5234  *  This function converts a string to an desktop placement scheme description.
5235  *
5236  *
5237  *  Inputs:
5238  *  ------
5239  *  args = NULL (don't care)
5240  *
5241  *  numArgs = 0 (don't care)
5242  *
5243  *  fromVal = resource value to convert
5244  *
5245  *
5246  *  Outputs:
5247  *  -------
5248  *  toVal = descriptor to use to return converted value
5249  *
5250  *************************************<->***********************************/
5251
5252 static void
5253 DtfileCvtStringToObjPlace (
5254           XrmValue *args,
5255           Cardinal numArgs,
5256           XrmValue *fromVal,
5257           XrmValue *toVal)
5258 {
5259     unsigned char       *pch = (unsigned char *) (fromVal->addr);
5260     unsigned char       *pchNext;
5261     int         len;
5262     static long cval;
5263     char tmp[2];
5264     Boolean     fPrimarySet = False;
5265     Boolean     fSecondarySet = False;
5266
5267 /*
5268  * Icon placement layout values:
5269  */
5270
5271 #define OBJ_PLACE_BOTTOM_STR           (unsigned char *)"bottom"
5272 #define OBJ_PLACE_LEFT_STR             (unsigned char *)"left"
5273 #define OBJ_PLACE_RIGHT_STR            (unsigned char *)"right"
5274 #define OBJ_PLACE_TOP_STR              (unsigned char *)"top"
5275
5276
5277     /*
5278      * Convert the icon placement resource value:
5279      */
5280
5281     cval = 0;
5282
5283     while (*pch && _DtNextToken (pch, &len, &pchNext))
5284     {
5285         tmp[0] = pch[len];
5286         pch[len] = '\0';
5287         switch( *pch )
5288         {
5289             case 'B':
5290             case 'b':
5291                 if (_DtStringsAreEquivalent((char *)pch, (char *)OBJ_PLACE_BOTTOM_STR))
5292                 {
5293                   if (!fPrimarySet)
5294                   {
5295                     cval |= OBJ_PLACE_BOTTOM_PRIMARY;
5296                     fPrimarySet = True;
5297                   }
5298                   else if (!fSecondarySet)
5299                   {
5300                     if (!(cval &
5301                           (OBJ_PLACE_BOTTOM_PRIMARY | OBJ_PLACE_TOP_PRIMARY)))
5302                     {
5303                       cval |= OBJ_PLACE_BOTTOM_SECONDARY;
5304                       fSecondarySet = True;
5305                     }
5306                   }
5307                 }
5308                 break;
5309
5310
5311             case 'L':
5312             case 'l':
5313                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_LEFT_STR))
5314                 {
5315                   if (!fPrimarySet)
5316                   {
5317                     cval |= OBJ_PLACE_LEFT_PRIMARY;
5318                     fPrimarySet = True;
5319                   }
5320                   else if (!fSecondarySet)
5321                   {
5322                     if (!(cval &
5323                           (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY)))
5324                     {
5325                       cval |= OBJ_PLACE_LEFT_SECONDARY;
5326                       fSecondarySet = True;
5327                     }
5328                   }
5329                 }
5330                 break;
5331
5332             case 'R':
5333             case 'r':
5334                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_RIGHT_STR))
5335                 {
5336                   if (!fPrimarySet)
5337                   {
5338                     cval |= OBJ_PLACE_RIGHT_PRIMARY;
5339                     fPrimarySet = True;
5340                   }
5341                   else if (!fSecondarySet)
5342                   {
5343                     if (!(cval &
5344                           (OBJ_PLACE_RIGHT_PRIMARY | OBJ_PLACE_LEFT_PRIMARY)))
5345                     {
5346                       cval |= OBJ_PLACE_RIGHT_SECONDARY;
5347                       fSecondarySet = True;
5348                     }
5349                   }
5350                 }
5351                 break;
5352
5353             case 'T':
5354             case 't':
5355                 if (_DtStringsAreEquivalent ((char *)pch, (char *)OBJ_PLACE_TOP_STR))
5356                 {
5357                   if (!fPrimarySet)
5358                   {
5359                     cval |= OBJ_PLACE_TOP_PRIMARY;
5360                     fPrimarySet = True;
5361                   }
5362                   else if (!fSecondarySet)
5363                   {
5364                     if (!(cval &
5365                           (OBJ_PLACE_TOP_PRIMARY | OBJ_PLACE_BOTTOM_PRIMARY)))
5366                     {
5367                       cval |= OBJ_PLACE_TOP_SECONDARY;
5368                       fSecondarySet = True;
5369                     }
5370                   }
5371                 }
5372
5373                 break;
5374         }
5375         pch[len] = tmp[0];
5376         pch = pchNext;
5377     }
5378
5379     if (!fPrimarySet)
5380     {
5381         cval =  OBJ_PLACE_TOP_PRIMARY;
5382     }
5383     if (!fSecondarySet)
5384     {
5385         if (cval & (OBJ_PLACE_LEFT_PRIMARY | OBJ_PLACE_RIGHT_PRIMARY))
5386         {
5387             cval |= OBJ_PLACE_TOP_SECONDARY;
5388         }
5389         else        {
5390             cval |= OBJ_PLACE_RIGHT_SECONDARY;
5391         }
5392     }
5393
5394
5395     (*toVal).size = sizeof (long);
5396     (*toVal).addr = (XtPointer) &cval;
5397
5398 } /* END OF FUNCTION DtfileCvtStringToObjPlace */
5399
5400 /*************************************<->*************************************
5401  *
5402  *  _DtNextToken (pchIn, pLen, ppchNext)
5403  *
5404  *
5405  *  Description:
5406  *  -----------
5407  *  XXDescription ...
5408  *
5409  *
5410  *  Inputs:
5411  *  ------
5412  *  pchIn = pointer to start of next token
5413  *
5414  *
5415  *  Outputs:
5416  *  -------
5417  *  pLen  =    pointer to integer containing number of characters in next token
5418  *  ppchNext = address of pointer to following token
5419  *
5420  *  Return =   next token or NULL
5421  *
5422  *
5423  *  Comments:
5424  *  --------
5425  *  None.
5426  *
5427  *************************************<->***********************************/
5428
5429 static unsigned char
5430 *_DtNextToken (
5431         unsigned char *pchIn,
5432         int *pLen,
5433         unsigned char **ppchNext)
5434 {
5435     unsigned char *pchR = pchIn;
5436     int   i;
5437     int   chlen;
5438
5439     for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
5440     /* find end of word: requires singlebyte whitespace terminator */
5441     {
5442         if ((chlen == 1) && isspace (*pchIn))
5443         {
5444             break;
5445         }
5446         pchIn += chlen;
5447     }
5448
5449     /* skip to next word */
5450     while (pchIn && (mblen ((char *)pchIn, MB_CUR_MAX) == 1) && isspace (*pchIn))
5451     {
5452         *pchIn++;
5453     }
5454
5455     *ppchNext = pchIn;
5456     *pLen = i;
5457     if (i)
5458     {
5459         return(pchR);
5460     }
5461     else
5462     {
5463        return(NULL);
5464     }
5465
5466 } /* END OF FUNCTION _DtNextToken */
5467
5468 /*************************************<->*************************************
5469  *
5470  *  DtfileCvtStringToOpenDir (args, numArgs, fromVal, toVal)
5471  *
5472  *
5473  *  Description:
5474  *  -----------
5475  *  This function converts a string to an desktop placement scheme description.
5476  *
5477  *
5478  *  Inputs:
5479  *  ------
5480  *  args = NULL (don't care)
5481  *
5482  *  numArgs = 0 (don't care)
5483  *
5484  *  fromVal = resource value to convert
5485  *
5486  *
5487  *  Outputs:
5488  *  -------
5489  *  toVal = descriptor to use to return converted value
5490  *
5491  *************************************<->***********************************/
5492
5493 static void
5494 DtfileCvtStringToOpenDir (
5495           XrmValue *args,
5496           Cardinal numArgs,
5497           XrmValue *fromVal,
5498           XrmValue *toVal)
5499 {
5500    char * in_str = (char *) (fromVal->addr);
5501    static int i;
5502
5503    toVal->size = sizeof (int);
5504    toVal->addr = (XtPointer) &i;
5505
5506    if (_DtStringsAreEquivalent (in_str, "current"))
5507       i = CURRENT;
5508    else if (_DtStringsAreEquivalent (in_str, "new"))
5509       i = NEW;
5510    else
5511       i = CURRENT;
5512 /*
5513    else
5514    {
5515       toVal->size = 0;
5516       toVal->addr = NULL;
5517       XtStringConversionWarning ((char *)fromVal->addr, "OpenDir");
5518    }
5519 */
5520 }
5521
5522 /*************************************<->*************************************
5523  *
5524  *  DtfileCvtStringToDTIcon (args, numArgs, fromVal, toVal)
5525  *
5526  *
5527  *  Description:
5528  *  -----------
5529  *  This function converts a string to an desktop placement scheme description.
5530  *
5531  *
5532  *  Inputs:
5533  *  ------
5534  *  args = NULL (don't care)
5535  *
5536  *  numArgs = 0 (don't care)
5537  *
5538  *  fromVal = resource value to convert
5539  *
5540  *
5541  *  Outputs:
5542  *  -------
5543  *  toVal = descriptor to use to return converted value
5544  *
5545  *************************************<->***********************************/
5546
5547 static void
5548 DtfileCvtStringToDTIcon (
5549           XrmValue *args,
5550           Cardinal numArgs,
5551           XrmValue *fromVal,
5552           XrmValue *toVal)
5553 {
5554    char * in_str = (char *) (fromVal->addr);
5555    static int i;
5556
5557    toVal->size = sizeof (int);
5558    toVal->addr = (XtPointer) &i;
5559
5560    if (_DtStringsAreEquivalent (in_str, "large"))
5561       i = LARGE;
5562    else if (_DtStringsAreEquivalent (in_str, "small"))
5563       i = SMALL;
5564    else if (_DtStringsAreEquivalent (in_str, "default"))
5565       i = LARGE;  /* for now, eventually want to look at screen width/height*/
5566    else
5567       i = LARGE;
5568 /*
5569    else
5570    {
5571       toVal->size = 0;
5572       toVal->addr = NULL;
5573       XtStringConversionWarning ((char *)fromVal->addr, "DesktopIcon");
5574    }
5575 */
5576 }
5577
5578 static void
5579 DtfileCvtStringToTree (
5580           XrmValue *args,
5581           Cardinal numArgs,
5582           XrmValue *fromVal,
5583           XrmValue *toVal)
5584 {
5585    char * in_str = (char *) (fromVal->addr);
5586    static int i;
5587
5588    toVal->size = sizeof (int);
5589    toVal->addr = (XtPointer) &i;
5590
5591    DtfileStringToTree(in_str, &i);
5592 }
5593
5594 static void
5595 DtfileCvtStringToTreeFiles (
5596           XrmValue *args,
5597           Cardinal numArgs,
5598           XrmValue *fromVal,
5599           XrmValue *toVal)
5600 {
5601    char * in_str = (char *) (fromVal->addr);
5602    static int i;
5603
5604    toVal->size = sizeof (int);
5605    toVal->addr = (XtPointer) &i;
5606
5607    DtfileStringToTreeFiles(in_str, &i);
5608 }
5609
5610 static void
5611 DtfileCvtStringToView (
5612           XrmValue *args,
5613           Cardinal numArgs,
5614           XrmValue *fromVal,
5615           XrmValue *toVal)
5616 {
5617    char * in_str = (char *) (fromVal->addr);
5618    static int i;
5619
5620    toVal->size = sizeof (int);
5621    toVal->addr = (XtPointer) &i;
5622
5623    DtfileStringToView(in_str, &i);
5624 }
5625
5626 static void
5627 DtfileCvtStringToOrder (
5628           XrmValue *args,
5629           Cardinal numArgs,
5630           XrmValue *fromVal,
5631           XrmValue *toVal)
5632 {
5633    char * in_str = (char *) (fromVal->addr);
5634    static int i;
5635
5636    toVal->size = sizeof (int);
5637    toVal->addr = (XtPointer) &i;
5638
5639    DtfileStringToOrder(in_str, &i);
5640 }
5641
5642 static void
5643 DtfileCvtStringToDirection (
5644           XrmValue *args,
5645           Cardinal numArgs,
5646           XrmValue *fromVal,
5647           XrmValue *toVal)
5648 {
5649    char * in_str = (char *) (fromVal->addr);
5650    static int i;
5651
5652    toVal->size = sizeof (int);
5653    toVal->addr = (XtPointer) &i;
5654
5655    DtfileStringToDirection(in_str, &i);
5656 }
5657
5658 static void
5659 DtfileCvtStringToGrid (
5660           XrmValue *args,
5661           Cardinal numArgs,
5662           XrmValue *fromVal,
5663           XrmValue *toVal)
5664 {
5665    char * in_str = (char *) (fromVal->addr);
5666    static int i;
5667
5668    toVal->size = sizeof (int);
5669    toVal->addr = (XtPointer) &i;
5670
5671    DtfileStringToGrid(in_str, &i);
5672 }
5673
5674 FileMgrData *
5675 CheckOpenDir (
5676           char * directory,
5677           char * host)
5678 {
5679    int i;
5680    FileMgrData *file_mgr_data;
5681    DialogData *dialog_data;
5682
5683    for(i = 0; i < view_count; i++)
5684    {
5685       if(strcmp(directory, view_set[i]->directory_name) == 0 &&
5686                             strcmp(host, view_set[i]->host_name) == 0)
5687       {
5688          dialog_data = (DialogData *) view_set[i]->dialog_data;
5689          file_mgr_data = (FileMgrData *) dialog_data->data;
5690          return(file_mgr_data);
5691       }
5692    }
5693    return(NULL);
5694 }
5695
5696 char *
5697 GetRestrictedDirectory (
5698           Widget widget)
5699 {
5700    int i;
5701    FileMgrData *file_mgr_data;
5702    FileMgrRec *file_mgr_rec;
5703    DialogData *dialog_data;
5704
5705    for(i = 0; i < view_count; i++)
5706    {
5707       dialog_data = (DialogData *) view_set[i]->dialog_data;
5708       file_mgr_data = (FileMgrData *) dialog_data->data;
5709       file_mgr_rec = (FileMgrRec *)file_mgr_data->file_mgr_rec;
5710       if(file_mgr_rec->current_directory_text == widget &&
5711                                           file_mgr_data->fast_cd_enabled)
5712       {
5713          return(file_mgr_data->restricted_directory);
5714       }
5715    }
5716    return((char *)NULL);
5717 }
5718
5719 static void
5720 DtfileStringToTree(
5721    char *str,
5722    int *type)
5723 {
5724    if (_DtStringsAreEquivalent (str, "on"))
5725       *type = MULTIPLE_DIRECTORY;
5726    else if (_DtStringsAreEquivalent (str, "off"))
5727       *type = SINGLE_DIRECTORY;
5728    else
5729       *type = UNSET_VALUE;
5730 }
5731
5732 static void
5733 DtfileStringToTreeFiles(
5734    char *str,
5735    int *type)
5736 {
5737    if (_DtStringsAreEquivalent (str, "never"))
5738       *type = TREE_FILES_NEVER;
5739    else if (_DtStringsAreEquivalent (str, "choose"))
5740       *type = TREE_FILES_CHOOSE;
5741    else if (_DtStringsAreEquivalent (str, "always"))
5742       *type = TREE_FILES_ALWAYS;
5743    else
5744       *type = UNSET_VALUE;
5745 }
5746
5747 static void
5748 DtfileStringToView(
5749    char *str,
5750    int *type)
5751 {
5752    if (_DtStringsAreEquivalent (str, "no_icon") ||
5753                             _DtStringsAreEquivalent (str, "no_icons"))
5754       *type = BY_NAME;
5755    else if (_DtStringsAreEquivalent (str, "large_icon") ||
5756                             _DtStringsAreEquivalent (str, "large_icons"))
5757       *type = BY_NAME_AND_ICON;
5758    else if (_DtStringsAreEquivalent (str, "small_icon") ||
5759                             _DtStringsAreEquivalent (str, "small_icons"))
5760       *type = BY_NAME_AND_SMALL_ICON;
5761    else if (_DtStringsAreEquivalent (str, "attributes"))
5762       *type = BY_ATTRIBUTES;
5763    else
5764       *type = UNSET_VALUE;
5765 }
5766
5767 static void
5768 DtfileStringToOrder(
5769    char *str,
5770    int *type)
5771 {
5772    if (_DtStringsAreEquivalent (str, "file_type"))
5773       *type = ORDER_BY_FILE_TYPE;
5774    else if (_DtStringsAreEquivalent (str, "alphabetical"))
5775       *type = ORDER_BY_ALPHABETICAL;
5776    else if (_DtStringsAreEquivalent (str, "date"))
5777       *type = ORDER_BY_DATE;
5778    else if (_DtStringsAreEquivalent (str, "size"))
5779       *type = ORDER_BY_SIZE;
5780    else
5781       *type = UNSET_VALUE;
5782 }
5783
5784
5785 static void
5786 DtfileStringToDirection(
5787    char *str,
5788    int *type)
5789 {
5790    if (_DtStringsAreEquivalent (str, "ascending"))
5791       *type = DIRECTION_ASCENDING;
5792    else if (_DtStringsAreEquivalent (str, "descending"))
5793       *type = DIRECTION_DESCENDING;
5794    else
5795       *type = UNSET_VALUE;
5796 }
5797
5798 static void
5799 DtfileStringToGrid(
5800    char *str,
5801    int *type)
5802 {
5803    if (_DtStringsAreEquivalent (str, "on"))
5804       *type = RANDOM_OFF;
5805    else if (_DtStringsAreEquivalent (str, "off"))
5806       *type = RANDOM_ON;
5807    else
5808       *type = UNSET_VALUE;
5809 }
5810
5811 static void
5812 SetupSendRequestArgs(
5813    ApplicationArgs application_args,
5814    Tt_message msg)
5815 {
5816    char *vtype;
5817    if(application_args.title != NULL)
5818    {
5819       tt_message_arg_add( msg, TT_IN, "-title", application_args.title );
5820    }
5821    if(application_args.restricted != NULL)
5822    {
5823       tt_message_arg_add( msg, TT_IN, RESTRICTED_HEADER, 0 );
5824    }
5825    vtype = VIEW_HEADER;
5826    switch( application_args.view )
5827    {
5828        case BY_NAME:
5829            tt_message_arg_add( msg, TT_IN, vtype, "no_icon" );
5830            break;
5831        case BY_NAME_AND_ICON:
5832            tt_message_arg_add( msg, TT_IN, vtype, "large_icon" );
5833            break;
5834        case BY_NAME_AND_SMALL_ICON:
5835            tt_message_arg_add( msg, TT_IN, vtype, "small_icon" );
5836            break;
5837        case BY_ATTRIBUTES:
5838            tt_message_arg_add( msg, TT_IN, vtype, "attributes" );
5839            break;
5840        default:
5841            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5842            break;
5843    }
5844
5845    vtype = "-order";
5846    switch( application_args.order )
5847    {
5848        case ORDER_BY_FILE_TYPE:
5849            tt_message_arg_add( msg, TT_IN, vtype, "file_type" );
5850            break;
5851        case ORDER_BY_ALPHABETICAL:
5852            tt_message_arg_add( msg, TT_IN, vtype, "alphabetical" );
5853            break;
5854        case ORDER_BY_DATE:
5855            tt_message_arg_add( msg, TT_IN, vtype, "date" );
5856            break;
5857        case ORDER_BY_SIZE:
5858            tt_message_arg_add( msg, TT_IN, vtype, "size" );
5859            break;
5860        default:
5861            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5862            break;
5863    }
5864
5865    vtype = "-direction";
5866    switch( application_args.direction )
5867    {
5868        case DIRECTION_ASCENDING:
5869            tt_message_arg_add( msg, TT_IN, vtype, "ascending" );
5870            break;
5871        case DIRECTION_DESCENDING:
5872            tt_message_arg_add( msg, TT_IN, vtype, "descending" );
5873            break;
5874        default:
5875            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5876            break;
5877    }
5878
5879    vtype = "-grid";
5880    switch( application_args.grid )
5881    {
5882        case RANDOM_OFF:
5883            tt_message_arg_add( msg, TT_IN, vtype, "on" );
5884            break;
5885        case RANDOM_ON:
5886            tt_message_arg_add( msg, TT_IN, vtype, "off" );
5887            break;
5888        default:
5889            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5890            break;
5891    }
5892    vtype = "-tree";
5893    switch( application_args.tree_view )
5894    {
5895        case MULTIPLE_DIRECTORY:
5896            tt_message_arg_add( msg, TT_IN, vtype, "on" );
5897            break;
5898        case SINGLE_DIRECTORY:
5899            tt_message_arg_add( msg, TT_IN, vtype, "off" );
5900            break;
5901        default:
5902            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5903            break;
5904    }
5905
5906    vtype = "-tree_files";
5907    switch( application_args.tree_files )
5908    {
5909        case TREE_FILES_NEVER:
5910            tt_message_arg_add( msg, TT_IN, vtype, "never" );
5911            break;
5912        case TREE_FILES_CHOOSE:
5913            tt_message_arg_add( msg, TT_IN, vtype, "choose" );
5914            break;
5915        case TREE_FILES_ALWAYS:
5916            tt_message_arg_add( msg, TT_IN, vtype, "always" );
5917            break;
5918        default:
5919            tt_message_arg_add( msg, TT_IN, vtype, "none" );
5920            break;
5921    }
5922
5923    if(application_args.help_volume != NULL)
5924    {
5925       tt_message_arg_add( msg, TT_IN, "-help_volume",
5926                           application_args.help_volume );
5927    }
5928 }
5929
5930 /*
5931  * This routine is used by ForceMyIconOpen to get the "Open" filetype and
5932  * find out what the new icon is.  It then places that icon in the
5933  * correct icon gadget.
5934  */
5935 static void
5936 BuildAndShowIconName(
5937    char *file_type_name,
5938    unsigned char view,
5939    unsigned char show_type,
5940    Widget widget)
5941 {
5942    char *new_file_type_name;
5943    char *ptr;
5944    Arg args[1];
5945    PixmapData *pixmapData;
5946
5947    new_file_type_name = (char *)XtMalloc(strlen(file_type_name) +
5948                                          strlen(ICON_OPEN_PREFIX) + 1);
5949    sprintf(new_file_type_name, "%s%s", ICON_OPEN_PREFIX, file_type_name);
5950
5951    if (view == BY_NAME_AND_ICON && show_type != MULTIPLE_DIRECTORY)
5952      pixmapData = _DtRetrievePixmapData(new_file_type_name,
5953                                         NULL,
5954                                         NULL,
5955                                         widget,
5956                                         LARGE);
5957    else
5958      pixmapData = _DtRetrievePixmapData(new_file_type_name,
5959                                         NULL,
5960                                         NULL,
5961                                         widget,
5962                                         SMALL);
5963
5964    if(pixmapData && pixmapData->iconFileName)
5965    {
5966      XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
5967      XtSetValues(widget, args, 1);
5968    }
5969 /*
5970    else
5971    {
5972      XtSetArg (args[0], XmNimageName, NULL);
5973      XtSetValues(widget, args, 1);
5974    }
5975 */
5976
5977    _DtCheckAndFreePixmapData(new_file_type_name,
5978                              widget,
5979                              (DtIconGadget) widget,
5980                              pixmapData);
5981
5982    XtFree(new_file_type_name);
5983 }
5984
5985
5986 /*
5987  * Given a directory name, this function will see if a view of the parent
5988  * directory is open; if so, then it will update the icon representing
5989  * this icon, in the parent view, so that it is drawn as 'closed'.  This
5990  * function must only be called if openDirType == NEW.
5991  */
5992
5993 void
5994 ForceMyIconClosed (
5995    char * host_name,
5996    char * directory_name)
5997 {
5998    int i;
5999    int j;
6000    int k;
6001    Arg args[1];
6002    FileViewData * file_view_data = NULL;
6003    DialogData *dialog_data;
6004    FileMgrData *file_mgr_data;
6005    DesktopRec *desktopWindow;
6006    char * parent;
6007    char * fname;
6008    PixmapData *pixmapData;
6009
6010    /* find the parent directory of the one just removed */
6011    parent = _DtPName(directory_name);
6012    fname =  DName(directory_name);
6013
6014    /* first check to see if any File Manager views have this directory */
6015    for (i = 0; i < view_count; i++)
6016    {
6017       dialog_data = (DialogData *) view_set[i]->dialog_data;
6018       file_mgr_data = (FileMgrData *) dialog_data->data;
6019
6020       /* loop through until we find the file_view_data structure for
6021        * the directory to force open */
6022
6023       for(j = 0; j < file_mgr_data->directory_count; j++)
6024       {
6025          if (strcmp(parent, file_mgr_data->directory_set[j]->name) == 0)
6026          {
6027             for (k = 0; k < file_mgr_data->directory_set[j]->file_count; k++)
6028             {
6029                file_view_data =
6030                        file_mgr_data->directory_set[j]->file_view_data[k];
6031                if (strcmp(file_view_data->file_data->file_name, fname) == 0)
6032                   goto search_done;
6033             }
6034             break;
6035          }
6036       }
6037    }
6038
6039    search_done:
6040
6041    if( (file_view_data) && (file_mgr_data->view != BY_NAME) )
6042    {
6043       if (file_mgr_data->view == BY_NAME_AND_ICON  &&
6044                        file_mgr_data->show_type != MULTIPLE_DIRECTORY)
6045          pixmapData = _DtRetrievePixmapData(
6046                                  file_view_data->file_data->logical_type,
6047                                  fname,
6048                                  parent,
6049                                  file_view_data->widget,
6050                                  LARGE);
6051       else
6052          pixmapData = _DtRetrievePixmapData(
6053                                  file_view_data->file_data->logical_type,
6054                                  fname,
6055                                  parent,
6056                                  file_view_data->widget,
6057                                  SMALL);
6058
6059       if (pixmapData)
6060         XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6061       else
6062         XtSetArg (args[0], XmNimageName, NULL);
6063       XtSetValues (file_view_data->widget, args, 1);
6064
6065       _DtCheckAndFreePixmapData(file_view_data->file_data->logical_type,
6066                                 file_view_data->widget,
6067                                 (DtIconGadget) file_view_data->widget,
6068                                 pixmapData);
6069    }
6070
6071    /* now check to see if any desktop objects are this directory */
6072    for(j = 0; j < desktop_data->numIconsUsed; j++)
6073    {
6074       char buf[MAX_PATH];
6075
6076       desktopWindow = desktop_data->desktopWindows[j];
6077       file_view_data = desktopWindow->file_view_data;
6078
6079       sprintf(buf, "%s/%s", desktopWindow->dir_linked_to,
6080                             desktopWindow->file_name);
6081       DtEliminateDots (buf);
6082
6083       if( (strcmp(buf, directory_name) == 0) &&
6084           (strcmp(desktopWindow->host, host_name) == 0) )
6085       {
6086          pixmapData = _DtRetrievePixmapData(
6087               file_view_data->file_data->logical_type,
6088               fname,
6089               NULL,
6090               desktopWindow->shell,
6091               desktopIconType);
6092
6093          if(pixmapData)
6094            XtSetArg (args[0], XmNimageName, pixmapData->iconFileName);
6095          else
6096            XtSetArg (args[0], XmNimageName, NULL);
6097          XtSetValues (desktopWindow->iconGadget, args, 1);
6098
6099          _DtCheckAndFreePixmapData(
6100                  desktopWindow->file_view_data->file_data->logical_type,
6101                  desktopWindow->shell,
6102                  (DtIconGadget) desktopWindow->iconGadget,
6103                  pixmapData);
6104       }
6105    }
6106 }
6107
6108
6109 /*************************************************************************
6110  *
6111  * MarqueeSelect - this is the callback which gets called when there is
6112  *    a marquee event happening on the root window.
6113  *
6114  ************************************************************************/
6115 static void
6116 MarqueeSelect (
6117       Widget w,
6118       int type,
6119       Position x,
6120       Position y,
6121       Dimension width,
6122       Dimension height,
6123       XtPointer client_data)
6124 {
6125    int i;
6126    Window   rootWindow;
6127    Atom     pCurrent;
6128    Screen   *currentScreen;
6129    int      screen;
6130    char     *workspace_name=NULL;
6131    Display *display;
6132
6133
6134    switch (type)
6135    {
6136        case DT_WSM_MARQUEE_SELECTION_TYPE_BEGIN:
6137             display = XtDisplay(desktop_data->desktopWindows[0]->shell);
6138             screen = XDefaultScreen(display);
6139             currentScreen = XScreenOfDisplay(display, screen);
6140             rootWindow = RootWindowOfScreen(currentScreen);
6141
6142             if(DtWsmGetCurrentWorkspace(display, rootWindow, &pCurrent)
6143                                                             == Success)
6144             {
6145                workspace_name = XGetAtomName (display, pCurrent);
6146                CleanUpWSName(workspace_name);
6147             }
6148             else
6149                workspace_name =
6150                   XtNewString(desktop_data->workspaceData[0]->name);
6151
6152             for(i = 0; i < desktop_data->numWorkspaces; i++)
6153             {
6154                if(strcmp(workspace_name,
6155                            desktop_data->workspaceData[i]->name) == 0)
6156                {
6157                   DeselectAllDTFiles(desktop_data->workspaceData[i]);
6158                   break;
6159                }
6160             }
6161             XtFree(workspace_name);
6162             break;
6163
6164        case DT_WSM_MARQUEE_SELECTION_TYPE_END:
6165             CheckDesktopMarquee(x, y, width, height);
6166             break;
6167
6168        case DT_WSM_MARQUEE_SELECTION_TYPE_CANCEL:
6169             break;
6170
6171        case DT_WSM_MARQUEE_SELECTION_TYPE_CONTINUE:
6172             CheckDesktopMarquee(x, y, width, height);
6173             break;
6174
6175        default:
6176             break;
6177    }
6178 }
6179
6180
6181 /*
6182  * We must wait for the message response, before exiting
6183  */
6184
6185 static void
6186 WaitForResponseAndExit( void )
6187
6188 {
6189    XtMainLoop();
6190 }
6191
6192 static void
6193 ExitApp(
6194         XtPointer clientData,
6195         DtString words[],
6196         int num_fields )
6197
6198 {
6199   FinalizeToolTalkSession( );
6200   exit(0);
6201 }
6202
6203
6204 /*
6205  * Puts up an Error dialog with Cancel and Help unmapped in the
6206  * center of the screen. The last argument is the OK callback
6207  */
6208
6209 static Widget
6210 post_dialog(Widget parent, char *title, char *msg, void (*DtErrExitCB)())
6211 {
6212    Widget dialog, dialogShell;
6213    XmString message_text, ok;
6214    Arg args[10];
6215    Dimension dialogWd, dialogHt;
6216    int n = 0;
6217
6218    ok = XmStringCreateLocalized ((char*)_DtOkString);
6219    message_text = XmStringCreateLocalized (msg);
6220
6221    XtSetArg(args[n], XmNautoUnmanage, False); n++;
6222    XtSetArg(args[n], XmNokLabelString, ok); n++;
6223    XtSetArg(args[n], XmNtitle, title); n++;
6224    XtSetArg(args[n], XmNmessageString, message_text); n++;
6225    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
6226    XtSetArg (args[n], XmNdefaultPosition, False); n++;
6227    XtSetArg(args[n], XmNuseAsyncGeometry, True); n++;
6228
6229    dialog = XmCreateErrorDialog (parent, title, args, n);
6230    XtAddCallback (dialog, XmNokCallback, DtErrExitCB, NULL);
6231    XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_CANCEL_BUTTON));
6232    XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
6233
6234    /* Disable the frame menu from dialog since we don't want the user
6235       to be able to close dialogs with the frame menu */
6236
6237    dialogShell = XtParent(dialog);
6238    XtSetArg(args[0], XmNmappedWhenManaged, False);
6239    XtSetArg(args[1], XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU);
6240    XtSetValues(dialogShell, args, 2);
6241    XtManageChild (dialog);
6242    XtRealizeWidget (dialogShell);
6243
6244    /* Center the dialog */
6245
6246    XtSetArg(args[0], XmNwidth, &dialogWd);
6247    XtSetArg(args[1], XmNheight, &dialogHt);
6248    XtGetValues(dialog, args, 2);
6249    XtSetArg (args[0], XmNx,
6250                 (WidthOfScreen(XtScreen(dialog)) - dialogWd) / 2);
6251    XtSetArg (args[1], XmNy,
6252                 (HeightOfScreen(XtScreen(dialog)) - dialogHt) / 2);
6253    XtSetArg (args[2], XmNmappedWhenManaged, True); 
6254    XtSetValues (dialog, args, 3);
6255
6256    XtSetArg(args[0], XmNmappedWhenManaged, True);
6257    XtSetValues(dialogShell, args, 1);
6258
6259    XtManageChild (dialog);
6260    XmStringFree(message_text);
6261
6262    return (dialog);
6263 }
6264
6265 /*  
6266  * This is the Callback when an error occurs while trying to create 
6267  * the .dt folder or sub-folders. Application exits.
6268  */
6269
6270 static void 
6271 DtErrExitCB (Widget dialog, XtPointer client_data, XtPointer call_data)
6272 {
6273 XtPopdown (XtParent (dialog));
6274 FinalizeToolTalkSession();
6275 exit (1);
6276 }
6277
6278 #if defined(CSRG_BASED)
6279 extern void
6280 sigchld_handler(int signo)      /* Do not use the arg signo at the moment */
6281 {
6282     pid_t   pid;
6283     int     stat_loc;
6284
6285     /*
6286       On DUX, the process remains in the ZOMBIE
6287       state untill parent invokes wait or waitpid.
6288     */
6289
6290     pid = waitpid(-1, &stat_loc, WNOHANG);
6291     /* Child exit handling code follows, if any */
6292 }
6293 #endif /* CSRG_BASED */