v13i014: xdtm - X Desktop Manager for the X Window System, Part09/11

EdwardJ. Groenendaal eddyg at cogs.sussex.ac.uk
Sun May 19 10:03:55 AEST 1991


Submitted-by: Edward "J." Groenendaal <eddyg at cogs.sussex.ac.uk>
Posting-number: Volume 13, Issue 14
Archive-name: xdtm/part09

Submitted-by: eddyg at cste
Archive-name: xdtm/part09

---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is part 09 of xdtm
# ============= xdtm/main.c ==============
if test ! -d 'xdtm'; then
    echo 'x - creating directory xdtm'
    mkdir 'xdtm'
fi
if test -f 'xdtm/main.c' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/main.c (File already exists)'
else
echo 'x - extracting xdtm/main.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/main.c' &&
X/*****************************************************************************
X ** File          : main.c                                                  **
X ** Purpose       : Initialise and Realise xdtm                             **
X ** Author        : Edward Groenendaal                                      **
X ** Date          : 18th Feb 1991                                           **
X ** Documentation : Xdtm Design Folder                                      **
X ** Related Files : All other xdtm files                                    **
X *****************************************************************************/
X
X#include "xdtm.h"
X#include "menus.h"
X
X/* local headers */
X
X#include <X11/Shell.h>
X#include "Xedw/XedwForm.h"
X
X#include "bitmaps/xdtm.xbm"
X
Xpublic Widget topLevel;
Xpublic String home;
Xpublic AppData app_data;
X
Xstatic XtResource resources[] = {
X  {   
X    XtNviewWidth, 
X    XtCViewWidth,
X    XtRInt,
X    sizeof(int),
X    XtOffset(AppDataPtr, view_width),
X    XtRImmediate,
X    (caddr_t) 85,
X  },
X  { 
X    XtNviewHeight,
X    XtCViewHeight,
X    XtRInt,
X    sizeof(int),
X    XtOffset(AppDataPtr, view_height),
X    XtRImmediate,
X    (caddr_t) 25,
X  },
X  {
X    XtNmode,
X    XtCMode,
X    XtRString,
X    sizeof(String),
X    XtOffset(AppDataPtr, mode),
X    XtRImmediate,
X    (caddr_t) "icons",
X  },
X  {
X    XtNdelay,
X    XtCDelay,
X    XtRInt,
X    sizeof(int),
X    XtOffset(AppDataPtr, delay),
X    XtRImmediate,
X    (caddr_t) 0,
X  },
X  {
X    XtNdirOnExit,
X    XtCDirOnExit,
X    XtRBoolean,
X    sizeof(Boolean),
X    XtOffset(AppDataPtr, dironexit),
X    XtRImmediate,
X    (caddr_t) False,
X  },
X  {
X    XtNconfigFile,
X    XtCConfigFile,
X    XtRString,
X    sizeof(String),
X    XtOffset(AppDataPtr, cffile),
X    XtRImmediate,
X    (caddr_t) NULL,
X  },
X  {
X    XtNviewFont,
X    XtCFont,
X    XtRFontStruct,
X    sizeof(XFontStruct*),
X    XtOffset(AppDataPtr, view_font),
X    XtRString,
X    (caddr_t) "6x10",
X  },
X  {
X    XtNdmFont,
X    XtCFont,
X    XtRFontStruct,
X    sizeof(XFontStruct*),
X    XtOffset(AppDataPtr, dm_font),
X    XtRString,
X    (caddr_t) "*-courier-bold-r-*-120-*",
X  },
X};
X      
X/*****************************************************************************
X *                                main                                       *
X *****************************************************************************/
Xpublic void main(int argc, char *argv[])
X{
X  /* Parse the command line arguments, initialise the toplevel form, call
X   * other initialising procedures, enter the X Main Loop.
X   */
X
X  private void initialiseXdtm(void);
X  extern void createMenuWidgets(Widget);          /* menus.c */
X  extern void createAppManagerWidgets(Widget);    /* appman.c */
X  extern void createFileManagerWidgets(Widget);   /* fileman.c */
X  extern void createDialogWidgets(Widget);        /* dialogs.c */
X
X  extern Icon_mode current_mode;
X  Widget topForm;
X  Arg arglist[6];
X  Cardinal i;
X  static String Title = "X DeskTop Manager";
X
X  /* Command Line Arguments */
X
X  static XrmOptionDescRec options[] = {
X    {"-dmfont",    "*directoryManager.font", XrmoptionSepArg, NULL},
X    {"-cf", 	   ".configFile",            XrmoptionSepArg, NULL},
X    {"-delay",     ".delay",                 XrmoptionSepArg, NULL}
X  };
X
X  /* Initialise Program */
X  if ((home = (String) getenv("HOME")) == NULL) {
X    fprintf(stderr, "Warning: can't get environment variable HOME\n");
X    home = XtNewString("/");
X  } else 
X    home = XtNewString(home);
X
X  /* Initialise the user interface */
X
X  topLevel = XtInitialize(argv[0], 
X			  "Xdtm", 
X			  options, 
X			  XtNumber(options),
X			  &argc, argv);
X
X  /* Check left over command line arguments */
X  if (argc > 1) {
X    /* incorrect command line arguments */
X    int i;
X    static int errs = False;
X    
X    for (i = 1; i < argc; i++) {
X      if (!errs++)
X	fprintf(stderr, "%s: command line option unknown:\n", argv[0]);
X      fprintf(stderr, "option: %s\n\n", argv[i]);
X    }
X    fprintf(stderr, "%s understands all standard Xt "
X	    "command-line options.\n", argv[0]);
X    fprintf(stderr, "Additional options are as follows:\n");
X    fprintf(stderr, "Option              Valid Range\n");
X    fprintf(stderr, "-dmfont             Any font, should be fixed width\n");
X    fprintf(stderr, "-cf                 config filename\n");
X    fprintf(stderr, "-delay              delay after copying, for NFS\n");
X    exit(2);
X  }
X    
X  /* get application resources */
X  XtGetApplicationResources(topLevel,
X			    &app_data,
X			    resources,
X			    XtNumber(resources),
X			    NULL, 0);
X
X  /* check values of application resources */
X  if (app_data.view_width < 1 || app_data.view_height < 1) {
X    fprintf(stderr, "%s: error in resource settings:\n"
X	    "view window must be greater than 1x1 characters\n",
X	    argv[0]);
X    exit(2);
X  }
X  
X  if (strcmp(app_data.mode, "icons") == 0) 
X    current_mode.mode = Icons;
X  else if (strcmp(app_data.mode, "short") == 0)
X    current_mode.mode = Short;
X  else if (strcmp(app_data.mode,  "long") == 0)
X    current_mode.mode = Long;
X  else {
X    fprintf(stderr, "%s: error in resource settings:\n"
X	    "mode must be one of either:\n"
X	    "'icons'     Show icons\n"
X	    "'short'     Just display file names\n"
X	    "'long'      Display file names with additional data.\n",
X	    argv[0]);
X    exit(2);
X  }
X
X  if (app_data.delay < 0 || app_data.delay > 5) {
X    fprintf(stderr, "%s: error in resource settings:\n"
X	    "delay must be between 0 and 5\n", argv[0]);
X    exit(2);
X  }
X
X  i = 0;
X  XtSetArg(arglist[i], XtNbottom, XtChainBottom); i++;
X  XtSetArg(arglist[i], XtNtop,       XtChainTop); i++;
X  XtSetArg(arglist[i], XtNleft,     XtChainLeft); i++;
X  XtSetArg(arglist[i], XtNright,   XtChainRight); i++;
X  XtSetArg(arglist[i], XtNhorizDistance,      5); i++;
X  XtSetArg(arglist[i], XtNvertDistance,       5); i++;
X  topForm = XtCreateManagedWidget("topForm",
X				  xedwFormWidgetClass,
X				  topLevel,
X				  arglist, i);
X
X  /* Create Widgets in rest of program.
X   * These must be called in this order, top left -> bottom right 
X   */
X  createMenuWidgets        (topForm);
X  createAppManagerWidgets  (topForm);
X  createFileManagerWidgets (topForm);
X  createDialogWidgets      (topForm); 
X
X  i = 0;
X  XtSetArg(arglist[i], XtNiconPixmap,
X	   XCreateBitmapFromData(XtDisplay(topLevel),       /* jcc */
X				 XtScreen(topLevel)->root,
X				 xdtm_bits, xdtm_width,
X				 xdtm_height)); i++;
X  XtSetArg(arglist[i], XtNtitle,   Title); i++;
X  XtSetArg(arglist[i], XtNminWidth,  400); i++;
X  XtSetArg(arglist[i], XtNminHeight, 200); i++;
X  XtSetValues(topLevel, arglist, i);
X
X  tzset(); /* Make sure we have the time zone info so that the date 
X	    * functions work, probably don't *need* this.. */
X
X  /* Realize the widgets, (display program) then loop waiting for events */
X
X  XtRealizeWidget(topLevel);
X
X  initialiseXdtm();
X
X  XtMainLoop();
X
X}
X
X/*****************************************************************************
X *                              quitQueryResult                              *
X *****************************************************************************/
Xpublic void quitQueryResult(Widget w, Boolean quit, caddr_t call_data)
X{
X  /* Action procedure called when a button is pressed in a quit dialog,
X   *
X   * - Takes a widget, quit - whether to quit, call_data - ignored.
X   */
X
X  extern void destroy_quit_dialog(void);
X
X  /* Quit selected */
X  if (quit == True)
X    exit(0);
X
X  /* Cancel selected */
X  destroy_quit_dialog();
X}
X
X/*****************************************************************************
X *                              initialiseXdtm                               *
X *****************************************************************************/
Xprivate void initialiseXdtm(void)
X{
X  /* initialise the program */
X
X  extern void initAppManager(Widget);               /* appman.c */
X  extern void initFileManager(Widget);              /* fileman.c */
X  extern void parsePreferences(Widget);           /* parse.c */
X
X  parsePreferences(topLevel);
X  initAppManager(topLevel);
X  initFileManager(topLevel);
X}
SHAR_EOF
chmod 0644 xdtm/main.c ||
echo 'restore of xdtm/main.c failed'
Wc_c="`wc -c < 'xdtm/main.c'`"
test 8048 -eq "$Wc_c" ||
	echo 'xdtm/main.c: original size 8048, current size' "$Wc_c"
fi
# ============= xdtm/map.c ==============
if test -f 'xdtm/map.c' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/map.c (File already exists)'
else
echo 'x - extracting xdtm/map.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/map.c' &&
X/*****************************************************************************
X ** File          : map.c                                                   **
X ** Purpose       : Initialise and Realise map dialog                       **
X ** Author        : Edward Groenendaal                                      **
X ** Date          : April 1991                                              **
X ** Documentation : Xdtm Design Folder                                      **
X ** Related Files :                                                         **
X *****************************************************************************/
X
X#include "xdtm.h"
X#include "parse.h"		/* For SelOptions, ESIZE */
X#include <X11/Shell.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/AsciiText.h>
X#include "Xedw/XedwForm.h"
X#include "Xedw/XedwList.h"
X
Xextern void realize_dialog(Widget);
X
X/* Widgets */
X
Xprivate Widget mappopup;        /* For mapping prog over files */
Xprivate Widget mapform;
Xprivate Widget maplabel;
Xprivate Widget mappromptlabel;
Xprivate Widget maptext;
Xprivate Widget mapCancel;
Xprivate Widget mapOK;
X
X/*****************************************************************************
X *                                init_map                                   *
X *****************************************************************************/
Xpublic void init_map(Widget top)
X{
X  /* Initialise the map and select dialog Widgets, they actually shar the
X   * same ones.
X   */
X
X  Arg arglist[7];
X  Cardinal i;
X  XtTranslations mapTranslations;
X
X  /* Translations for the text widget */
X  static char defaultTranslations[] = 
X    "Ctrl<Key>A:        beginning-of-line() \n\
X     Ctrl<Key>E:        end-of-line() \n\
X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
X     <Key>Right: 	forward-character() \n\
X     <Key>Left:         backward-character() \n\
X     <Key>Delete:       delete-previous-character() \n\
X     <Key>BackSpace:    delete-previous-character() \n\
X     <Key>:             insert-char() \n\
X     <FocusIn>:         focus-in() \n\
X     <FocusOut>:        focus-out() \n\
X     <BtnDown>:         select-start()";
X
X
X  mappopup       = XtCreatePopupShell("mappopup",
X				      transientShellWidgetClass,
X				      top,
X				      NULL, 0);
X
X  mapform        = XtCreateManagedWidget("mapform",
X					 xedwFormWidgetClass,
X					 mappopup,
X					 NULL, 0);
X
X  i = 0;
X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X  maplabel       = XtCreateManagedWidget("maplabel",
X					 labelWidgetClass,
X					 mapform,
X					 arglist, i);
X
X  i = 1;
X  XtSetArg(arglist[i], XtNfromVert, maplabel); i++;
X  mappromptlabel = XtCreateManagedWidget("mappromptlabel",
X					 labelWidgetClass,
X					 mapform,
X					 arglist, i);
X  
X  i = 2;
X  XtSetArg(arglist[i], XtNfromHoriz, mappromptlabel); i++;
X  XtSetArg(arglist[i], XtNfullWidth,           True); i++;
X  XtSetArg(arglist[i], XtNeditType,     XawtextEdit); i++;
X  maptext        = XtCreateManagedWidget("maptext",
X					 asciiTextWidgetClass,
X					 mapform,
X					 arglist, i);
X  
X  i = 0;
X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X  XtSetArg(arglist[i], XtNfromVert,        maptext); i++;
X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
X  mapCancel      = XtCreateManagedWidget("mapCancel",
X					 commandWidgetClass,
X					 mapform,
X					 arglist, i);
X
X  i = 2;
X  XtSetArg(arglist[i], XtNfromHoriz,   mapCancel); i++;
X  XtSetArg(arglist[i], XtNwidthLinked, mapCancel); i++;
X  XtSetArg(arglist[i], XtNlabel,            "OK"); i++;
X  mapOK          = XtCreateManagedWidget("mapOK",
X					 commandWidgetClass,
X					 mapform,
X					 arglist, i);
X
X
X  XtUninstallTranslations(maptext);
X  mapTranslations = XtParseTranslationTable(defaultTranslations);
X  XtOverrideTranslations(maptext, mapTranslations);
X
X}
X
X/*****************************************************************************
X *                                 map_dialog                                *
X *****************************************************************************/
Xpublic void map_dialog(Boolean map)
X{
X  /* if map is true then put map dialog up, otherwise use the 
X   * select dialog.
X   */
X
X  private void mapQueryResult(Widget, Boolean, caddr_t);
X  private void selectQueryResult(Widget, Boolean, caddr_t);
X  Arg arglist[1];
X
X  XtSetArg(arglist[0], XtNstring, "");
X  XtSetValues(maptext, arglist, 1);
X
X  if (map == True) {
X    XtSetArg(arglist[0], XtNlabel, " Map Program over Selected Files ");
X    XtSetValues(maplabel, arglist, 1);
X
X    XtSetArg(arglist[0], XtNlabel, "Program:");
X    XtSetValues(mappromptlabel, arglist, 1);
X
X    XtAddCallback(mapCancel, XtNcallback, mapQueryResult, False);
X    XtAddCallback(mapOK,     XtNcallback, mapQueryResult, True);
X  } else {
X    XtSetArg(arglist[0], XtNlabel, "Select Files by Regular Expression"); 
X    XtSetValues(maplabel, arglist, 1);
X
X    XtSetArg(arglist[0], XtNlabel, "RegExp: ");
X    XtSetValues(mappromptlabel, arglist, 1);
X
X    XtAddCallback(mapCancel, XtNcallback, selectQueryResult, False);
X    XtAddCallback(mapOK,     XtNcallback, selectQueryResult, True);
X  }
X
X  realize_dialog(mappopup);
X}
X
X/*****************************************************************************
X *                         destroy_map_dialog                                *
X *****************************************************************************/
Xprivate void destroy_map_dialog(void)
X{
X  /* Popdown the map dialog, remove the callbacks on the buttons so that
X   * they can be reset next time map_dialog is called, in case the select
X   * dialog is required.
X   */
X
X  Arg arglist[1];
X
X  XtPopdown(mappopup);
X
X  XtRemoveAllCallbacks(mapCancel, XtNcallback);
X  XtRemoveAllCallbacks(mapOK,     XtNcallback);
X}
X
X/*****************************************************************************
X *                             mapQueryResult                                *
X *****************************************************************************/
Xprivate void mapQueryResult(Widget w, Boolean ok, caddr_t call_data)
X{
X  /* Either map a program over the selected files if OK was pressed,
X   * otherwise do nothing.
X   */
X
X  extern String build_arguments(String, SelOptions);
X  extern int execute(String, String, String, Boolean);
X  extern void setCursor(Cursor);
X  extern Cursor busy;
X  String mapprogram, program, filename;
X  Arg arglist[1];
X
X  destroy_map_dialog();
X
X  if (ok == True) {
X    setCursor(busy);
X    /* get program name from text widget */
X    XtSetArg(arglist[0], XtNstring, &mapprogram);
X    XtGetValues(maptext, arglist, 1);
X
X    program = XtNewString(mapprogram);
X
X    /* extract filename from program */
X    filename = XtNewString(program);
X    filename = strtok(filename, " ");
X    
X    /* Get list of files */
X    if ((program = build_arguments(program, M_SEL)) == NULL) 
X      fprintf(stderr, "Programmer Error: map was selected without files\n");
X    else
X      execute(NULL, filename, program, False);
X
X    setCursor(NULL);
X  }
X}
X
X/*****************************************************************************
X *                             selectQueryResult                             *
X *****************************************************************************/
Xprivate void selectQueryResult(Widget w, Boolean ok, caddr_t call_data)
X{
X  /* If Ok was pressed then select files using the regular expression
X   * contained within the text widget.
X   */
X
X  extern void highlight_by_re(String);
X  extern void setCursor(Cursor);
X  extern Cursor busy;
X  String re;
X  Arg arglist[1];
X
X  destroy_map_dialog();
X
X  if (ok == True) {
X    /* Get regular expression */
X    setCursor(busy);
X    XtSetArg(arglist[0], XtNstring, &re);
X    XtGetValues(maptext, arglist, 1);
X    
X    highlight_by_re(re);
X
X    setCursor(NULL);
X  }
X}
SHAR_EOF
chmod 0644 xdtm/map.c ||
echo 'restore of xdtm/map.c failed'
Wc_c="`wc -c < 'xdtm/map.c'`"
test 7904 -eq "$Wc_c" ||
	echo 'xdtm/map.c: original size 7904, current size' "$Wc_c"
fi
# ============= xdtm/menus.c ==============
if test -f 'xdtm/menus.c' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/menus.c (File already exists)'
else
echo 'x - extracting xdtm/menus.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/menus.c' &&
X/*****************************************************************************
X ** File          : menus.c                                                 **
X ** Purpose       : Create, and handle the pull down menus                  **
X ** Author        : Edward Groenendaal                                      **
X ** Date          : 18th Feb 1991                                           **
X ** Documentation : Xdtm Design Folder                                      **
X ** Related Files :                                                         **
X *****************************************************************************/
X
X#include "xdtm.h"
X#include "menus.h"
X#include <sys/stat.h>
X#include <X11/Xaw/MenuButton.h>
X#include <X11/Xaw/SimpleMenu.h>
X#include <X11/Xaw/SmeBSB.h>
X#include <X11/Xaw/SmeLine.h>
X
X#include "Xedw/XedwList.h"
X#include "Xedw/XedwForm.h"
X#include "bitmaps/Tick"
X#include "bitmaps/EmptyTick"
X
Xstatic MenuContents fileMenuStrings[] = {
X  { "about",     "About Xdtm...",  About,     noflag },
X  { "help",      "Help",           Help,      noflag },
X  {  LINE,        NULL,            0,         noflag },
X  { "new",       "New File",       New,       noflag },
X  { "duplicate", "Duplicate File", Duplicate, noflag },
X  {  LINE,        NULL,            0,         noflag },
X  { "copy",      "Copy files",     Copy,      noflag },
X  { "move",      "Move files",     Move,      noflag },
X  { "trash",     "Delete files",   Trash,     noflag },
X  {  LINE,        NULL,            0,         noflag },
X  { "quit",      "Quit Program",   Quit,      noflag },
X};
X
Xstatic MenuContents optionMenuStrings[] = {
X  { "map",      "Map Program over Files",     Map,    noflag },
X  { "select",   "Select Files by Template",   Select, noflag },
X};
X
Xstatic MenuContents viewMenuStrings[] = {
X  { "icons",    "Show Icons",     Icons,   flagged },
X  { "short",    "No Icons",       Short,   flagged },
X  {  LINE,       NULL,            0,       flagged },
X  { "long",     "Long Listing",   Long,    flagged },
X  { "options",  "Options",        Options, flagged },
X};
X
XCardinal fileMenuSize   = sizeof(fileMenuStrings)   /
X                                sizeof(fileMenuStrings[0]);
XCardinal optionMenuSize = sizeof(optionMenuStrings) /
X                                sizeof(optionMenuStrings[0]);
XCardinal viewMenuSize   = sizeof(viewMenuStrings)   /
X                                sizeof(viewMenuStrings[0]);
X
Xpublic Arg chain_position[] = {  XtNtop,     XtChainTop,
X				 XtNbottom,  XtChainBottom,
X				 XtNleft,    XtChainLeft,
X				 XtNright,   XtChainRight,
X				 NULL,       NULL
X			      };
X
XCardinal chain_size = sizeof(chain_position)/sizeof(chain_position[0]);
X
Xpublic Pixmap tick, emptytick;
Xpublic Widget menuBar;
X
Xpublic Icon_mode current_mode;
X
X/*****************************************************************************
X *                        createManuWidgets                                  *
X *****************************************************************************/
Xpublic void createMenuWidgets(Widget w)
X{
X  /* This procedure creates the widgets for the menu bar. 
X   * It's 4:41 in the morning, I'm tired, but the work must go on..
X   * so it's time to smile :-) Always look on the bright side of life... 
X   */
X   
X  private void menuSelect(Widget, Cardinal, caddr_t);
X  public  void createMenu(Widget, MenuContents[], Cardinal, 
X			  void (*)(Widget, Cardinal, caddr_t) );
X
X  Widget fileMenuButton, optionMenuButton, viewMenuButton, selectionMenuButton;
X  Widget fileMenu, optionMenu, viewMenu;
X  Arg arglist[7], *newlist;
X  Cardinal i;
X
X  i = 0;
X  XtSetArg(arglist[i], XtNrubberWidth,  False);    i++;
X  XtSetArg(arglist[i], XtNrubberHeight, False);    i++;
X  XtSetArg(arglist[i], XtNborderWidth,      0);    i++;
X  newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
X  menuBar          =   XtCreateManagedWidget("menuBar",
X					     xedwFormWidgetClass,
X					     w,
X					     newlist, i + chain_size);
X  XtFree(newlist);
X
X  i = 0;
X  XtSetArg(arglist[i], XtNhighlightThickness, 0); i++;
X  XtSetArg(arglist[i], XtNborderWidth,        0); i++;
X  XtSetArg(arglist[i], XtNmenuName,  "fileMenu"); i++;
X  XtSetArg(arglist[i], XtNlabel,         "File"); i++;
X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
X  fileMenuButton   =   XtCreateManagedWidget("fileMenuButton",
X					     menuButtonWidgetClass,
X					     menuBar,
X					     arglist, i);
X
X  i = 2;
X  XtSetArg(arglist[i], XtNmenuName,         "optionMenu"); i++;
X  XtSetArg(arglist[i], XtNlabel,               "Options"); i++;
X  XtSetArg(arglist[i], XtNfromHoriz,      fileMenuButton); i++;
X  XtSetArg(arglist[i], XtNvertDistance,                0); i++;
X  optionMenuButton =   XtCreateManagedWidget("optionMenuButton",
X					     menuButtonWidgetClass,
X					     menuBar,
X					     arglist, i);
X
X  i = 2;
X  XtSetArg(arglist[i], XtNmenuName,        "viewMenu"); i++;
X  XtSetArg(arglist[i], XtNlabel,               "View"); i++;
X  XtSetArg(arglist[i], XtNfromHoriz, optionMenuButton); i++;
X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
X  viewMenuButton   =   XtCreateManagedWidget("viewMenuButton",
X					     menuButtonWidgetClass,
X					     menuBar,
X					     arglist, i);
X
X  fileMenu         =   XtCreatePopupShell("fileMenu",
X					  simpleMenuWidgetClass,
X					  fileMenuButton,
X					  NULL, 0);
X  
X  optionMenu       =   XtCreatePopupShell("optionMenu",
X					  simpleMenuWidgetClass,
X					  optionMenuButton,
X					  NULL, 0);
X  
X  viewMenu         =   XtCreatePopupShell("viewMenu",
X					  simpleMenuWidgetClass,
X					  viewMenuButton,
X					  NULL, 0);
X
X  tick             =   XCreateBitmapFromData(XtDisplay(w), 
X					     RootWindowOfScreen(XtScreen(w)),
X					     tick_bits, tick_width, 
X					     tick_height);
X
X  emptytick        =   XCreateBitmapFromData(XtDisplay(w), 
X					     RootWindowOfScreen(XtScreen(w)),
X					     EmptyTick_bits, 
X					     EmptyTick_width, 
X					     EmptyTick_height);
X
X  /* create the menu panes from the arrays defined at the top of this 
X   * file. 
X   */
X  createMenu(fileMenu, fileMenuStrings, fileMenuSize, menuSelect);
X  
X  createMenu(optionMenu, optionMenuStrings, optionMenuSize, menuSelect);
X  
X  createMenu(viewMenu, viewMenuStrings, viewMenuSize, menuSelect);
X
X  /* Default long listing options */
X  current_mode.options = (PERMS | NLINKS | OWNER | GROUP | SIZE);
X  
X}
X
X
X/*****************************************************************************
X *                                createMenu                                 *
X *****************************************************************************/
Xpublic void createMenu(Widget menu, MenuContents menuStrings[], 
X		       Cardinal menuSize, void (*function)())
X{
X  /* Given a MenuContents stucture, the number of entries and a function
X   * that should be called when that pane is pressed, this procedure
X   * creates the menu panes for the menu widget 'menu'
X   */
X
X  Widget menuEntry;
X  Cardinal i, n;
X  Arg arglist[3];
X
X  for(n=0; n < menuSize; n++) {
X    MenuContents entry = menuStrings[n];
X    String widgetname = entry.paneName;
X    if (!strcmp(LINE, widgetname))
X      menuEntry = XtCreateManagedWidget(widgetname, smeLineObjectClass,
X					menu, NULL, 0);
X    else {
X      i = 0;
X      XtSetArg(arglist[i], XtNlabel, entry.paneLabel); i++;
X      if (entry.set == flagged) {
X	XtSetArg(arglist[i], XtNleftMargin, (tick_width*1.5)); i++;
X	if (entry.paneNumber == current_mode.mode) {
X	  XtSetArg(arglist[i], XtNleftBitmap, tick); i++; 
X	} else {
X	  XtSetArg(arglist[i], XtNleftBitmap,           None); i++; 
X	}
X      }
X	  
X      menuEntry = XtCreateManagedWidget(widgetname, smeBSBObjectClass,
X					menu, arglist, i);
X      if (entry.paneNumber == current_mode.mode && entry.set == flagged) 
X	current_mode.w = menuEntry;
X
X      XtAddCallback(menuEntry, XtNcallback, function,
X		    (caddr_t) entry.paneNumber);
X    }
X  }
X}
X
X/*****************************************************************************
X *                              menuSelect                                   *
X *****************************************************************************/
Xprivate void menuSelect(Widget w, Cardinal paneNumber, caddr_t rubbish)
X{
X  /* This procedure is called when a pane is pressed in any of the main
X   * three pull down menus.
X   *
X   * - Takes the paneNumber of the pane selected. Rest is discarded.
X   */
X
X  extern void map_dialog(Boolean);
X  extern void quit_dialog(void);
X  extern void query_dialog(String, Boolean);
X  extern void displayfile(String);
X  extern void newfile_dialog(Boolean, String, Boolean);
X  extern void button_selected(Widget, Cardinal, caddr_t);
X  extern void listoption_dialog(void);
X  extern Boolean directoryManagerNewDirectory(String);
X  extern String getfilename(String);
X  extern void setCursor(Cursor);
X  extern Cursor busy;
X  extern String cwd;
X  extern Widget directoryManager;
X  XedwListReturnStruct *highlighted;
X  String filename, fullname, level;
X  struct stat filestatus;
X  Arg arglist[6];
X  Cardinal i;
X
X  /* Which pane was selected */
X  switch (paneNumber) {
X  case About:
X    /* display about dialog */
X
X    level = XtMalloc (sizeof(char) * 25);
X    sprintf(level, "   Xdtm v%d.%d   ", RELEASE, PATCHLEVEL);
X    query_dialog(level, False);
X    break;
X  case Help:
X    /* If help file is readable show it */
X
X    if (access(SYSTEM_HELP, R_OK) == 0) 
X      displayfile(SYSTEM_HELP);
X    else
X      query_dialog("Help not found!", False); /* Error dialog */
X    break;
X
X  case New:
X    /* Create a newfile */
X
X    newfile_dialog(False, NULL, False);
X    break;
X
X  case Duplicate:
X    /* Find out whether highlighted file is a regular file or a directory */
X
X    highlighted = XedwListShowCurrent(directoryManager);
X    if (highlighted->xedwList_index != XDTM_LIST_NONE) {
X      if (highlighted->next != NULL) 
X	query_dialog("Only one file!", False);
X      else {
X	filename = getfilename(highlighted->string);
X	fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+3) * 
X				   sizeof(char));
X	strcpy(fullname, cwd);
X	if (strcmp(cwd, "/") != 0)
X	  strcat(fullname, "/");
X	strcat(fullname, filename);
X	if (stat(fullname, &filestatus) == -1) {
X	  fprintf(stderr,"xdtm: ARRRGGHHH stat error\n");
X	} else {
X	  if ((filestatus.st_mode & S_IFMT) == S_IFDIR) 
X	    /* Is a directory */
X	    newfile_dialog(True, filename, True);
X	  else if ((filestatus.st_mode & S_IFMT) == S_IFREG) 
X	    newfile_dialog(True, filename, False);
X	  else 
X	    query_dialog("Wrong file type!", False);
X	}
X	XtFree(fullname);
X      }
X    } else
X      fprintf(stderr, "Error: Duplicate selected when should have been"
X	      " disabled\n");
X    break;
X
X  case Getinfo:
X    /* Maybe I'll get round to doing this one sometime, it should display
X     * a popup with the filename and permissions in, then allow you to
X     * change them. 
X     */
X    query_dialog("Not implemented!", False);
X    break;
X
X  case Copy:
X  case Move:
X  case Trash:
X    /* Call button press with it */
X    button_selected(w, paneNumber, 0);
X    break;
X
X  case Quit:
X    /* Quit the program.. maybe */
X    quit_dialog();
X    break;
X
X  case Map:
X    /* Map program over files */
X    map_dialog(True);
X    break;
X
X  case Select:
X    /* Select files via RE template, uses same dilaog as map, except 
X     * with different resources.
X     */
X    map_dialog(False);
X    break;
X
X  case Icons:
X    /* Change to icon mode */
X    if (current_mode.mode != Icons) {
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X      XtSetValues(current_mode.w, arglist, i);
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X      XtSetValues(w, arglist, i);
X      current_mode.w = w;
X      current_mode.mode = Icons;
X      XtSetArg(arglist[i], XtNshowIcons,     True); i++;
X      XtSetArg(arglist[i], XtNrowSpacing,      10); i++; 
X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
X      XtSetValues(directoryManager, arglist, i);
X      directoryManagerNewDirectory(cwd);
X    } 
X    break;
X
X  case Short:
X    /* Change to short listing mode */
X    if (current_mode.mode != Short) {
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X      XtSetValues(current_mode.w, arglist, i);
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X      XtSetValues(w, arglist, i);
X      current_mode.w = w;
X      current_mode.mode = Short;
X      i = 0;
X      XtSetArg(arglist[i], XtNshowIcons,    False); i++;
X      XtSetArg(arglist[i], XtNrowSpacing,       5); i++;
X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
X      XtSetValues(directoryManager, arglist, i);
X      directoryManagerNewDirectory(cwd);	/* To be consistent */
X    } 
X    break;
X
X  case Long:
X    /* change to long listing mode */
X    if (current_mode.mode != Long) {
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X      XtSetValues(current_mode.w, arglist, i);
X      i = 0;
X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X      XtSetValues(w, arglist, i);
X      current_mode.w = w;
X      current_mode.mode = Long;
X      i = 0;
X      XtSetArg(arglist[i], XtNshowIcons,   False); i++;
X      XtSetArg(arglist[i], XtNrowSpacing,      5); i++;
X      XtSetArg(arglist[i], XtNforceColumns, True); i++;
X      XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;
X      XtSetValues(directoryManager, arglist, i);
X      directoryManagerNewDirectory(cwd);	   /* To be consistent */
X    }
X    break;
X
X  case Options:
X    /* allow changes to long listing format. */
X    listoption_dialog();
X    break;
X
X  default:
X    fprintf(stderr, "Menu option number %d not supported\n", paneNumber);
X    break;
X  }
X    
X  
X}
X
SHAR_EOF
chmod 0644 xdtm/menus.c ||
echo 'restore of xdtm/menus.c failed'
Wc_c="`wc -c < 'xdtm/menus.c'`"
test 13682 -eq "$Wc_c" ||
	echo 'xdtm/menus.c: original size 13682, current size' "$Wc_c"
fi
# ============= xdtm/menus.h ==============
if test -f 'xdtm/menus.h' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/menus.h (File already exists)'
else
echo 'x - extracting xdtm/menus.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/menus.h' &&
X/***********************************************************************************
X ** File          : menus.h                                                       **
X ** Purpose       :                                                               **
X ** Author        : Edward Groenendaal                                            **
X ** Date          : 18th Feb 1990                                                 **
X ** Documentation : Xedw Design Folder                                            **
X ** Related Files : menus.c                                                       **
X ***********************************************************************************/
X
X#ifndef _EG_menus_h
X#define _EG_menus_h
X
X#include <X11/Intrinsic.h>
X
X#define LINE    "line"
X
X#define PERMS   (1 << 1)
X#define NLINKS  (1 << 2)
X#define OWNER   (1 << 3)
X#define GROUP   (1 << 4)
X#define SIZE    (1 << 5)
X#define MODTM   (1 << 6)
X#define ACCTM   (1 << 7)
X
Xtypedef enum {flagged, noflag} Flags;
X
Xtypedef enum {
X  About,
X  Help,
X  New,
X  Duplicate,
X  Getinfo,
X  Copy,
X  Move,
X  Trash,
X  Quit,
X  Map,
X  Select,
X  Icons,
X  Short,
X  Long,
X  Options
X} MenuValue;
X
Xtypedef struct {
X  String paneName;
X  String paneLabel;
X  MenuValue paneNumber;
X  Flags set;
X} MenuContents;
X
Xtypedef struct {
X  Widget w;
X  MenuValue mode;
X  /* long listing options */
X  Cardinal length;
X  char options;
X} Icon_mode;
X
Xextern Widget menuBar;
Xextern Icon_mode current_mode;
Xextern Pixmap tick;
Xextern Pixmap emptytick;
X
X#endif /* _EG_menus_h */
SHAR_EOF
chmod 0644 xdtm/menus.h ||
echo 'restore of xdtm/menus.h failed'
Wc_c="`wc -c < 'xdtm/menus.h'`"
test 1513 -eq "$Wc_c" ||
	echo 'xdtm/menus.h: original size 1513, current size' "$Wc_c"
fi
# ============= xdtm/mystrstr.c ==============
if test -f 'xdtm/mystrstr.c' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/mystrstr.c (File already exists)'
else
echo 'x - extracting xdtm/mystrstr.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/mystrstr.c' &&
X/*****************************************************************************
X ** File          : mystrstr.c                                              **
X ** Purpose       : Return pointer to first occurence of second string in   **
X **                 first string, else NULL                                 **
X ** Author        : Edward Groenendaal                                      **
X ** Date          : 11th April 1991                                         **
X ** Documentation : Xdtm Design Folder                                      **
X ** Related Files : appman.c                                                **
X *****************************************************************************/
X
X#ifndef HAS_STRSTR
X
X#include <stdio.h>  /* For NULL */
X
Xchar *mystrstr(char *cs, char *ct)
X{
X  char *csi, *cti, *result;
X  
X  result = NULL;
X  cti = ct;
X  csi = cs;
X  
X  /* search for first letter, on finding it set result to that point */
X
X  while (*csi != '\0' && *cti != '\0') {
X    if (result == NULL) {
X      /* searching for start of substring */
X      if (*csi == *cti) {
X	result = csi;
X	cti++;
X      }
X    } else 
X      /* trying to match rest */
X      if (*csi == *cti) 
X	cti++;
X      else {
X	cti = ct;
X	csi = result;
X	result = NULL;
X      }
X    csi++;
X  }
X
X  if (*cti == '\0')
X    return(result);
X  else 
X    return((char*) NULL);
X}
X
X#endif /* HAS_STRSTR */
X
X
X
X
SHAR_EOF
chmod 0644 xdtm/mystrstr.c ||
echo 'restore of xdtm/mystrstr.c failed'
Wc_c="`wc -c < 'xdtm/mystrstr.c'`"
test 1385 -eq "$Wc_c" ||
	echo 'xdtm/mystrstr.c: original size 1385, current size' "$Wc_c"
fi
# ============= xdtm/newfile.c ==============
if test -f 'xdtm/newfile.c' -a X"$1" != X"-c"; then
	echo 'x - skipping xdtm/newfile.c (File already exists)'
else
echo 'x - extracting xdtm/newfile.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xdtm/newfile.c' &&
X/*****************************************************************************
X ** File          : newfile.c                                               **
X ** Purpose       : Initialise and Realise newfile dialog                   **
X ** Author        : Edward Groenendaal                                      **
X ** Date          : April 1991                                              **
X ** Documentation : Xdtm Design Folder                                      **
X ** Related Files :                                                         **
X *****************************************************************************/
X
X#include "xdtm.h"
X
X#include <X11/Shell.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/AsciiText.h>
X#include "Xedw/XedwForm.h"
X
Xextern void realize_dialog(Widget);
X
X/* Widgets */
X
Xprivate Widget newfilepopup;
Xprivate Widget newfileform;
Xprivate Widget newfilelabel;
Xprivate Widget newfiletext;
Xprivate Widget newfilefile;
Xprivate Widget newfiledir;
Xprivate Widget newfilecancel;
X
Xtypedef struct {
X  String filename;
X  Boolean isdir;
X} Filetype;
X
X/*****************************************************************************
X *                             init_newfile                                  *
X *****************************************************************************/
Xpublic void init_newfile(Widget top)
X{
X  /* Create Widgets for newfile dialog */
X
X  private void destroy_newfile_dialog(Widget, caddr_t, caddr_t);
X
X  Arg arglist[5];
X  Cardinal i;
X  XtTranslations newfileTranslations;
X
X  /* Translations for text widget */
X  static char defaultTranslations[] = 
X    "Ctrl<Key>A:        beginning-of-line() \n\
X     Ctrl<Key>E:        end-of-line() \n\
X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
X     <Key>Right: 	forward-character() \n\
X     <Key>Left:         backward-character() \n\
X     <Key>Delete:       delete-previous-character() \n\
X     <Key>BackSpace:    delete-previous-character() \n\
X     <Key>:             insert-char() \n\
X     <FocusIn>:         focus-in() \n\
X     <FocusOut>:        focus-out() \n\
X     <BtnDown>:         select-start()";
X	
X
X  newfilepopup  = XtCreatePopupShell("newfilepopup",
X				     transientShellWidgetClass,
X				     top,
X				     NULL, 0);
X
X  newfileform   = XtCreateManagedWidget("newfileform",
X					xedwFormWidgetClass,
X					newfilepopup,
X					NULL, 0);
X
X  /* label widget to prompt for new filename */
X
X  i = 0;
X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X  newfilelabel  = XtCreateManagedWidget("newfilelabel",
X					labelWidgetClass,
X					newfileform,
X					arglist, i);
X  
X  /* new filename text input widget */
X
X  i = 1;
X  XtSetArg(arglist[i], XtNfromVert, newfilelabel); i++;
X  XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
X  newfiletext   = XtCreateManagedWidget("newfiletext",
X					asciiTextWidgetClass,
X					newfileform,
X					arglist, i);
X
X  i = 0;
X  XtSetArg(arglist[i], XtNfromVert, newfiletext); i++;
X  XtSetArg(arglist[i], XtNlabel,    "Directory"); i++;
X  newfiledir    = XtCreateManagedWidget("newfiledir",
X					commandWidgetClass,
X					newfileform,
X					arglist, i);
X  i = 1;
X  XtSetArg(arglist[i], XtNfromHoriz,   newfiledir); i++;
X  XtSetArg(arglist[i], XtNwidthLinked, newfiledir); i++;
X  XtSetArg(arglist[i], XtNlabel,           "File"); i++;
X  newfilefile   = XtCreateManagedWidget("newfilefile",
X					commandWidgetClass,
X					newfileform,
X					arglist, i);
X
X  i = 1;
X  XtSetArg(arglist[i], XtNfromHoriz,   newfilefile); i++;
X  XtSetArg(arglist[i], XtNwidthLinked, newfilefile); i++;
X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
X  newfilecancel = XtCreateManagedWidget("newfilecancel",
X					commandWidgetClass,
X					newfileform,
X					arglist, i);
X
X  /* Add callbacks for buttons */
X  XtAddCallback(newfilecancel, XtNcallback,  destroy_newfile_dialog, 0); 
X
X  /* Do the translations on the text widget */
X  XtUninstallTranslations(newfiletext);
X  newfileTranslations = XtParseTranslationTable(defaultTranslations);
X  XtOverrideTranslations(newfiletext, newfileTranslations);
X}
X
X/*****************************************************************************
X *                             newfile_dialog                                *
X *****************************************************************************/
Xpublic void newfile_dialog(Boolean rename, String newname, Boolean isdir)
X{
X  /* Popup the newfile dialog on screen with the correct data 
X   *
X   * - Takes a flag saying whether this is a duplication of a file, or the
X   *   creation of a new file or directory.
X   *   newname - The name of the file to be duplicated.
X   *   isdir   - Whether the file is a directory 
X   */
X
X  private void newfileQueryReturn(Widget, Boolean, caddr_t);
X  private void duplicateQueryReturn(Widget, Filetype*, caddr_t);
X  Arg arglist[1];
X  String filename;
X  Filetype *filetype;
X
X  static String defaultfilename = "untitled";
X
X  filetype = (Filetype*) XtMalloc (sizeof(Filetype));
X
X  if (newname == NULL) 
X    filename = defaultfilename;
X  else
X    filename = newname;
X
X  if (rename == False) {
X    /* Create a new file */
X
X    XtSetArg(arglist[0], XtNlabel, "Create a new file"); 
X    XtSetValues(newfilelabel, arglist, 1);
X
X    XtSetArg(arglist[0], XtNstring, filename);
X    XtSetValues(newfiletext, arglist, 1);
X
X    /* Add callbacks for buttons */
X    XtAddCallback(newfiledir,    XtNcallback,  newfileQueryReturn,  True);
X    XtAddCallback(newfilefile,   XtNcallback,  newfileQueryReturn, False);
X  } else {
X    /* rename an existing file */
X    filetype->filename = filename;
X    filetype->isdir    = isdir;
X
X    XtSetArg(arglist[0], XtNlabel, "Duplicate file"); 
X    XtSetValues(newfilelabel, arglist, 1);
X
X    XtSetArg(arglist[0], XtNstring, filename);
X    XtSetValues(newfiletext, arglist, 1);
X
X    if (isdir == True) 
X      XtSetSensitive(newfilefile, False);
X    else
X      XtSetSensitive(newfiledir, False);
X    XtAddCallback(newfiledir,  XtNcallback, duplicateQueryReturn, filetype);
X    XtAddCallback(newfilefile, XtNcallback, duplicateQueryReturn, filetype);
X  }
X
X  realize_dialog(newfilepopup);
X
X}
X
X/*****************************************************************************
X *                        destroy_newfile_dialog                             *
X *****************************************************************************/
Xprivate void destroy_newfile_dialog(Widget w, caddr_t dummy1, caddr_t dummy2)
X{
X  /* Popdown and destroy callbacks for the newfile dialog. Also back sure
X   * that both buttons are sensitive.
X   */
X
X  XtPopdown(newfilepopup);
X  
X  XtSetSensitive(newfilefile, True);
X  XtSetSensitive(newfiledir,  True);
X  XtRemoveAllCallbacks(newfilefile, XtNcallback);
X  XtRemoveAllCallbacks(newfiledir,  XtNcallback);
X}
X
X/*****************************************************************************
X *                            newfileQueryReturn                             *
X *****************************************************************************/
Xprivate void newfileQueryReturn(Widget w, Boolean isdir, caddr_t dummy)
X{
X  /* This procedure creates a new empty directory or file with the filename
X   * in the text widget newfiletext.
X   *
X   * - Takes a flag isdir, is the new file a directory?
X   */
X
X  extern void query_dialog(String, Boolean);
X  extern String cwd;
X  String filename, fullname;
X  Arg arglist[1];
X  int fd;
X  
X  destroy_newfile_dialog(w, 0, 0);
X  
X  XtSetArg(arglist[0], XtNstring, &filename);
X  XtGetValues(newfiletext, arglist, 1);
X
X  fullname = (String) XtMalloc (sizeof(char) * (strlen(cwd) + 
X						strlen(filename) + 4));
X  sprintf(fullname, "%s/%s", cwd, filename);
X
X  if (isdir == True) {
X    /* Create a directory with the name 'filename' */
X    if ((fd = mkdir(fullname, 0777)) == -1) 
X      query_dialog("Can't create dir", False);
X    else
X      directoryManagerNewDirectory(cwd);
X  } else {
X    /* Create a file with the name 'filename' */
X    if ((fd = creat(fullname, 0666)) == -1) {
X      /* Can't create fullname, maybe should look in errno to see why? */
X      query_dialog("Can't create file", False);
X    } else {
X      close(fd);
X      directoryManagerNewDirectory(cwd);
X    }
X  }
X
X  XtFree(fullname);
X}
X
X/*****************************************************************************
X *                            duplicateQueryReturn                           *
X *****************************************************************************/
Xprivate void duplicateQueryReturn(Widget w, Filetype *filetype, caddr_t dummy)
X{
X  /* This procedure copies a file in the current directory to a file with
X   * the name as specified within the text widget newfiletext. The orignal
X   * filename and type are passed as arguments to this procedure in the
X   * structure filetype.
X   */
X
X  extern void query_dialog(String, Boolean);
X  extern String cwd;
X  String filename, command;
X  Arg arglist[1];
X  int fd;
X  
X  destroy_newfile_dialog(w, 0, 0);
X  
X  XtSetArg(arglist[0], XtNstring, &filename);
X  XtGetValues(newfiletext, arglist, 1);
X
X  command = XtMalloc (sizeof(char) * (strlen(filetype->filename) + 
X				      strlen(filename) + 24));
X
X  if (filetype->isdir == True) {
X    /* make new directory, copy contents of old one into it */
X    if ((fd = mkdir(filename, 0777)) == -1) 
X      query_dialog("Can't create dir", False);
X    sprintf(command, "sh -c 'cp -r \"%s\"/ \"%s\"'", filetype->filename, 
X	    filename);
X
X    if (execute(NULL, "sh", command, True) != 0) 
X      query_dialog("Can't copy files!", False);
X    else
X      directoryManagerNewDirectory(cwd);
X  } else {
X    sprintf(command, "cp '%s' '%s'", filetype->filename, filename);
X
X    if (execute(NULL, "cp", command, True) != 0) 
X      query_dialog("Can't create file!", False);
X    else
X      directoryManagerNewDirectory(cwd);
X  }
X
X  XtFree(command);
X}
SHAR_EOF
chmod 0644 xdtm/newfile.c ||
echo 'restore of xdtm/newfile.c failed'
Wc_c="`wc -c < 'xdtm/newfile.c'`"
test 9922 -eq "$Wc_c" ||
	echo 'xdtm/newfile.c: original size 9922, current size' "$Wc_c"
fi
true || echo 'restore of xdtm/parse.c failed'
echo End of part 9, continue with part 10
exit 0

--
Dan Heller
O'Reilly && Associates       Z-Code Software    Comp-sources-x:
Senior Writer                President          comp-sources-x at uunet.uu.net
argv at ora.com                 argv at zipcode.com



More information about the Comp.sources.x mailing list