home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3213 < prev    next >
Internet Message Format  |  1991-04-19  |  50KB

  1. From: eddyg@syma.sussex.ac.uk (Edward J. Groenendaal)
  2. Newsgroups: alt.sources
  3. Subject: X Desktop Manager
  4. Message-ID: <4864@syma.sussex.ac.uk>
  5. Date: 17 Apr 91 20:47:32 GMT
  6.  
  7. ---- Cut Here and unpack ----
  8. #!/bin/sh
  9. # shar:    Shell Archiver  (v1.22)
  10. #    Packed Wed Apr 17 21:39:53 BST 1991 by tsuna!eddyg
  11. #    from directory /tsuna/home/ug/cs88/eddyg/usr/xdtm
  12. #
  13. # This is part 1 of a multipart archive                                    
  14. # do not concatenate these parts, unpack them in order with /bin/sh        
  15. #
  16. #    Run the following text with /bin/sh to create:
  17. #      code/appman.c
  18. #      code/buttons.c
  19. #      code/dialogs.c
  20. #      code/dirman.c
  21. #      code/display.c
  22. #      code/fileman.c
  23. #      code/info.c
  24. #      code/lexical.l
  25. #      code/listoption.c
  26. #      code/main.c
  27. #      code/map.c
  28. #      code/menus.c
  29. #      code/menus.h
  30. #      code/newfile.c
  31. #      code/parse.c
  32. #      code/parse.h
  33. #      code/parser.y
  34. #      code/patchlevel.h
  35. #      code/quit.c
  36. #      code/scroll_hack.c
  37. #      code/strstr.c
  38. #      code/xdtm.h
  39. #      code/README
  40. #      code/Imakefile
  41. #      code/Makefile
  42. #      code/help
  43. #      code/Xdtm
  44. #      icons/eddy/ccode.icon
  45. #      icons/eddy/core.icon
  46. #      icons/eddy/dotdot.icon
  47. #      icons/eddy/elisp.icon
  48. #      icons/eddy/elispc.icon
  49. #      icons/eddy/file.icon
  50. #      icons/eddy/folder.icon
  51. #      icons/eddy/hcode.icon
  52. #      icons/eddy/icon.icon
  53. #      icons/eddy/lcode.icon
  54. #      icons/eddy/lib.icon
  55. #      icons/eddy/make.icon
  56. #      icons/eddy/makefile.icon
  57. #      icons/eddy/manpage.icon
  58. #      icons/eddy/ocode.icon
  59. #      icons/eddy/prog.icon
  60. #      icons/eddy/text.icon
  61. #      icons/eddy/x.icon
  62. #      icons/eddy/xdtm.icon
  63. #      icons/eddy/ycode.icon
  64. #      icons/eddy/z.icon
  65. #      icons/alix/airballoon.icon
  66. #      icons/alix/alien.icon
  67. #      icons/alix/bat.icon
  68. #      icons/alix/candle.icon
  69. #      icons/alix/clock.icon
  70. #      icons/alix/cup.icon
  71. #      icons/alix/dragon.icon
  72. #      icons/alix/drawingA.icon
  73. #      icons/alix/drawingB.icon
  74. #      icons/alix/emacs.icon
  75. #      icons/alix/fish.icon
  76. #      icons/alix/flower.icon
  77. #      icons/alix/ghost.icon
  78. #      icons/alix/gun.icon
  79. #      icons/alix/hat.icon
  80. #      icons/alix/hedgehog.icon
  81. #      icons/alix/mermaid.icon
  82. #      icons/alix/monster.icon
  83. #      icons/alix/piccy.icon
  84. #      icons/alix/snail.icon
  85. #      icons/alix/wordc.icon
  86. #      xdtmrc
  87. #      code/bitmaps/Copy.Button
  88. #      code/bitmaps/Copy.Cursor
  89. #      code/bitmaps/Copy.Mask
  90. #      code/bitmaps/EmptyTick
  91. #      code/bitmaps/Grey.Mask
  92. #      code/bitmaps/Move.Button
  93. #      code/bitmaps/Move.Cursor
  94. #      code/bitmaps/Move.Mask
  95. #      code/bitmaps/Tick
  96. #      code/bitmaps/Trash.Button
  97. #      code/bitmaps/file.icon
  98. #      code/bitmaps/folder.icon
  99. #      code/Xedw/DefIcon.icon
  100. #      code/Xedw/Imakefile
  101. #      code/Xedw/Makefile
  102. #      code/Xedw/XedwForm.c
  103. #      code/Xedw/XedwForm.h
  104. #      code/Xedw/XedwFormP.h
  105. #      code/Xedw/XedwList.c
  106. #      code/Xedw/XedwList.h
  107. #      code/Xedw/XedwListP.h
  108. #      code/Xedw/XedwTree.c
  109. #      code/Xedw/XedwTree.h
  110. #      code/Xedw/XedwTreeP.h
  111. #
  112. if test -r s2_seq_.tmp
  113. then echo "Must unpack archives in sequence!"
  114.      next=`cat s2_seq_.tmp`; echo "Please unpack part $next next"
  115.      exit 1; fi
  116. echo "creating directories"
  117. mkdir code
  118. mkdir code/bitmaps
  119. mkdir code/Xedw
  120. mkdir icons
  121. mkdir icons/eddy
  122. mkdir icons/alix
  123. echo "x - extracting code/appman.c (Text)"
  124. sed 's/^X//' << 'SHAR_EOF' > code/appman.c &&
  125. X/*****************************************************************************
  126. X ** File          : appman.c                                                **
  127. X ** Purpose       : Application Manager                                     **
  128. X ** Author        : Edward Groenendaal                                      **
  129. X ** Date          : 19th Feb 1991                                           **
  130. X ** Documentation : Xedw Design Folder                                      **
  131. X ** Related Files : menus.c                                                 **
  132. X *****************************************************************************/
  133. X
  134. X#include "xdtm.h"
  135. X
  136. X#include <X11/Xaw/MenuButton.h> /* Needed for selection menu */
  137. X#include <X11/Xaw/SimpleMenu.h>
  138. X#include <X11/Xaw/Viewport.h>
  139. X#include <X11/Xaw/Command.h>
  140. X#include <X11/Xaw/Label.h>
  141. X#include <sys/types.h>        /* For opening and closing file descriptors */
  142. X#include <sys/stat.h>        /* For opening and closing file descriptors */
  143. X/* #include <fcntl.h>        For opening and closing file descriptors */
  144. X#include <sys/file.h>        /* For access(2) */
  145. X#include <string.h>
  146. X#include "menus.h"        /* For the use of Trash, Copy, and Move */
  147. X#include "parse.h"              /* For access to AppSelection */
  148. X#include "Xedw/XedwList.h"
  149. X#include "Xedw/XedwForm.h"
  150. X
  151. X/* Include button bitmaps */
  152. X#include "bitmaps/Trash.Button"
  153. X#include "bitmaps/Copy.Button"
  154. X#include "bitmaps/Move.Button"
  155. X
  156. X/* Include Cursor bitmaps */
  157. X#include "bitmaps/Copy.Cursor"
  158. X#include "bitmaps/Copy.Mask"
  159. X#include "bitmaps/Move.Cursor"
  160. X#include "bitmaps/Move.Mask"
  161. X
  162. Xpublic  Mode     mode;
  163. Xpublic  Boolean  buttonSensitive;
  164. Xpublic  Widget   trashButton, copyButton, moveButton;
  165. Xprivate XedwListReturnStruct *return_list;
  166. Xpublic  Widget   appManager;
  167. Xpublic  Widget   selectionMenu;
  168. Xprivate Widget   appManagerView;
  169. Xprivate Widget   appManagerButton;
  170. Xprivate Widget   buttonForm;
  171. Xprivate Cursor   copyCursor, moveCursor;
  172. Xpublic  Cardinal appman_selection;
  173. Xprivate String   srcdir, dstdir;
  174. Xprivate String  *patharray;
  175. Xprivate String   path;
  176. Xprivate Cardinal pathsize; 
  177. X
  178. X#ifdef SYSV
  179. Xextern char *strstr(char *, char *);
  180. X#endif
  181. X
  182. X
  183. Xvoid createAppManagerWidgets(Widget topForm)
  184. X{
  185. X  private void button_selected(Widget, Cardinal, caddr_t);
  186. X  private void program_selected(Widget, caddr_t, caddr_t);
  187. X  Arg arglist[8], *newlist;
  188. X  Pixmap trash, copy, move;
  189. X  Cardinal i, t;
  190. X  XtTranslations appManTranslations;
  191. X
  192. X  static char defaultTranslations[] =
  193. X            "<Btn1Down>:    Set()\n\
  194. X         <Btn1Up>:      Unset()\n\
  195. X             <Btn1Up>(2):   Notify() Unset()";
  196. X  
  197. X  /* Application Manager Selector */
  198. X
  199. X  i = 0;
  200. X  XtSetArg(arglist[i], XtNfromVert,         menuBar); i++;
  201. X  XtSetArg(arglist[i], XtNrubberWidth,        False); i++;
  202. X  XtSetArg(arglist[i], XtNrubberHeight,       False); i++;
  203. X  XtSetArg(arglist[i], XtNmenuName, "selectionMenu"); i++;
  204. X  newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
  205. X  appManagerButton  =   XtCreateManagedWidget("appManagerButton",
  206. X                          menuButtonWidgetClass,
  207. X                          topForm,
  208. X                          newlist, i + chain_size);
  209. X  XtFree(newlist);
  210. X
  211. X
  212. X  selectionMenu    =   XtCreatePopupShell("selectionMenu",
  213. X                      simpleMenuWidgetClass,
  214. X                      appManagerButton,
  215. X                      NULL, 0);
  216. X
  217. X
  218. X  /* Application Manager */
  219. X  
  220. X  i = 0;
  221. X  XtSetArg(arglist[i], XtNfromVert,      appManagerButton);   i++;
  222. X  XtSetArg(arglist[i], XtNforceBars,                 True);   i++;
  223. X  XtSetArg(arglist[i], XtNallowVert,                 True);   i++;
  224. X  XtSetArg(arglist[i], XtNrubberWidth,              False);   i++;
  225. X  XtSetArg(arglist[i], XtNwidthLinked,   appManagerButton);   i++;
  226. X  newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
  227. X  appManagerView      =   XtCreateManagedWidget("appManagerView",
  228. X                        viewportWidgetClass,
  229. X                        topForm,
  230. X                        newlist, i + chain_size);
  231. X  XtFree(newlist);
  232. X  
  233. X  i = 0;
  234. X  XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;
  235. X  XtSetArg(arglist[i], XtNforceColumns, True); i++;
  236. X  XtSetArg(arglist[i], XtNshowIcons,    True); i++;
  237. X  appManager          =   XtCreateManagedWidget("appManager",
  238. X                        xedwListWidgetClass,
  239. X                        appManagerView,
  240. X                        arglist, i);
  241. X
  242. X  /* Action Buttons */
  243. X
  244. X  buttonSensitive = False;
  245. X
  246. X  i = 0;
  247. X  XtSetArg(arglist[i], XtNfromVert,    appManagerView);   i++;
  248. X  XtSetArg(arglist[i], XtNrubberWidth,          False);   i++;
  249. X  XtSetArg(arglist[i], XtNrubberHeight,         False);   i++;
  250. X  XtSetArg(arglist[i], XtNtop,          XtChainBottom);   i++;
  251. X  XtSetArg(arglist[i], XtNwidthLinked, appManagerView);   i++;
  252. X  XtSetArg(arglist[i], XtNborderWidth,              0);   i++;
  253. X  XtSetArg(arglist[i], XtNdefaultDistance,          0);   i++;
  254. X  buttonForm          =   XtCreateManagedWidget("buttonForm",
  255. X                        xedwFormWidgetClass,
  256. X                        topForm,
  257. X                        arglist, i);
  258. X
  259. X  trash = XCreateBitmapFromData(XtDisplay(topForm),
  260. X                RootWindowOfScreen(XtScreen(topForm)),
  261. X                trash_bits,
  262. X                trash_width, trash_height);
  263. X
  264. X  i = 0;
  265. X  XtSetArg(arglist[i], XtNhighlightThickness,       1);   i++;  
  266. X  XtSetArg(arglist[i], XtNsensitive,            False);   i++;
  267. X  XtSetArg(arglist[i], XtNbitmap,               trash);   i++;
  268. X  trashButton          =      XtCreateManagedWidget("trashButton",
  269. X                        commandWidgetClass,
  270. X                        buttonForm,
  271. X                        arglist, i);
  272. X
  273. X
  274. X  move = XCreateBitmapFromData(XtDisplay(topForm),
  275. X                RootWindowOfScreen(XtScreen(topForm)),
  276. X                move_bits,
  277. X                move_width, move_height);
  278. X
  279. X  i = t = i-1;
  280. X  XtSetArg(arglist[i], XtNfromHoriz,      trashButton);   i++;
  281. X  XtSetArg(arglist[i], XtNhorizDistance,            6);   i++;
  282. X  XtSetArg(arglist[i], XtNbitmap,                move);   i++;
  283. X  moveButton          =   XtCreateManagedWidget("moveButton",
  284. X                        commandWidgetClass,
  285. X                        buttonForm,
  286. X                        arglist, i);
  287. X
  288. X  copy = XCreateBitmapFromData(XtDisplay(topForm),
  289. X                RootWindowOfScreen(XtScreen(topForm)),
  290. X                copy_bits,
  291. X                copy_width, copy_height);
  292. X
  293. X  i = t;
  294. X  XtSetArg(arglist[i], XtNfromHoriz,        moveButton);   i++;
  295. X  XtSetArg(arglist[i], XtNhorizDistance,             6);   i++;
  296. X  XtSetArg(arglist[i], XtNbitmap,                 copy);   i++;
  297. X  copyButton          =   XtCreateManagedWidget("copyButton",
  298. X                        commandWidgetClass,
  299. X                        buttonForm,
  300. X                        arglist, i);
  301. X
  302. X
  303. X  XtAddCallback(trashButton, XtNcallback, button_selected, Trash);
  304. X  XtAddCallback(copyButton, XtNcallback, button_selected, Copy);
  305. X  XtAddCallback(moveButton, XtNcallback, button_selected, Move);
  306. X  
  307. X  XtAddCallback(appManager, XtNcallback, program_selected, 0);
  308. X  appManTranslations = XtParseTranslationTable(defaultTranslations);
  309. X  XtUninstallTranslations(appManager);
  310. X  XtOverrideTranslations(appManager, appManTranslations);
  311. X}
  312. X
  313. Xpublic void initAppManager(Widget w)
  314. X{
  315. X  extern int count_chr(String, char);
  316. X  public void selectionChange(Widget, Cardinal, caddr_t);
  317. X  Pixmap cursor, mask;
  318. X  XColor foreground, background;
  319. X  Colormap def_cmap;
  320. X  String pathptr;
  321. X  Cardinal n;
  322. X
  323. X  /* set selection in label */
  324. X  selectionChange(w, 0, NULL);
  325. X
  326. X  /* get the copy and move cursors */
  327. X
  328. X  def_cmap = DefaultColormapOfScreen(XtScreen(w));
  329. X
  330. X  XParseColor(XtDisplay(w), def_cmap, "Black", &foreground);
  331. X  XParseColor(XtDisplay(w), def_cmap, "White", &background);
  332. X  XAllocColor(XtDisplay(w), def_cmap, &foreground);
  333. X  XAllocColor(XtDisplay(w), def_cmap, &background);
  334. X
  335. X  cursor = XCreateBitmapFromData(XtDisplay(w),
  336. X                 RootWindowOfScreen(XtScreen(w)),
  337. X                 CopyC_bits,
  338. X                 CopyC_width, CopyC_height);
  339. X
  340. X  mask   = XCreateBitmapFromData(XtDisplay(w),
  341. X                 RootWindowOfScreen(XtScreen(w)),
  342. X                 CopyM_bits,
  343. X                 CopyM_width, CopyM_height);
  344. X
  345. X  copyCursor = XCreatePixmapCursor(XtDisplay(w), 
  346. X                   cursor, mask,
  347. X                   &foreground, &background,
  348. X                   CopyC_x_hot, CopyC_y_hot);
  349. X
  350. X  XFreePixmap(XtDisplay(w), cursor);
  351. X  XFreePixmap(XtDisplay(w), mask);
  352. X
  353. X
  354. X  cursor = XCreateBitmapFromData(XtDisplay(w),
  355. X                       RootWindowOfScreen(XtScreen(w)),
  356. X                       MoveC_bits,
  357. X                       MoveC_width, MoveC_height);
  358. X
  359. X  mask   = XCreateBitmapFromData(XtDisplay(w),
  360. X                       RootWindowOfScreen(XtScreen(w)),
  361. X                       MoveM_bits,
  362. X                       MoveM_width, MoveM_height);
  363. X
  364. X  moveCursor = XCreatePixmapCursor(XtDisplay(w), 
  365. X                   cursor, mask,
  366. X                   &foreground, &background,
  367. X                   MoveC_x_hot, MoveC_y_hot);
  368. X
  369. X  XFreePixmap(XtDisplay(w), cursor);
  370. X  XFreePixmap(XtDisplay(w), mask);
  371. X
  372. X  mode = NormalMode;
  373. X
  374. X  /* Get path and put it into patharray */
  375. X  if ((path = (String) getenv("PATH")) == NULL) {
  376. X    fprintf(stderr, "Warning: PATH environment variable not set\n");
  377. X  } else path = XtNewString(path);
  378. X  
  379. X  patharray = (String*) XtMalloc ((count_chr(path, ':')+1) * sizeof(String));
  380. X
  381. X  /* Extract the directories from the path into the path array */
  382. X  
  383. X  n = 0;
  384. X
  385. X  pathptr = strtok(path, ":");
  386. X  while (pathptr != NULL) {
  387. X    if (*pathptr == '/')
  388. X      patharray[n++] = pathptr;
  389. X    else 
  390. X      fprintf(stderr, "Warning: Directory '%s' in PATH not fully qualified\n",
  391. X          pathptr);
  392. X    pathptr = strtok(NULL, ":");
  393. X  }
  394. X  
  395. X  pathsize = n;
  396. X}
  397. X
  398. Xpublic void button_selected(Widget w, Cardinal type, caddr_t call_data)
  399. X{
  400. X  extern void button_dialog(Cardinal, XedwListReturnStruct *);
  401. X  extern void changestate(Boolean);
  402. X  extern void setCursor(Cursor);
  403. X  extern String getfilename(String);
  404. X  extern String cwd;
  405. X  extern Cursor left_ptr;
  406. X  extern Widget directoryManager;
  407. X  extern Boolean buttonSensitive;
  408. X  static Boolean copyfirst = True;
  409. X  static Boolean movefirst = True;
  410. X  XedwListReturnStruct *tmp;
  411. X
  412. X  /* Get list of currently highlighted items */
  413. X  if (movefirst == True && copyfirst == True) {
  414. X    return_list = XedwListShowCurrent(directoryManager);
  415. X    /* extract filenames from rest of data */
  416. X    tmp = return_list;
  417. X    while (tmp != NULL) {
  418. X      tmp->string = getfilename(tmp->string);
  419. X      tmp = tmp->next;
  420. X    }
  421. X  }
  422. X  
  423. X  /* if non empty call dialog */
  424. X  if (!(return_list->xedwList_index == XDTM_LIST_NONE &&
  425. X      movefirst == True && copyfirst == True)) {
  426. X    switch(type) {
  427. X    case Trash:
  428. X      changestate(False);
  429. X      button_dialog(type, return_list);
  430. X      break;
  431. X    case Copy:
  432. X      if (copyfirst == True) {
  433. X    /* deselect all */
  434. X    XedwListUnhighlight(directoryManager, XedwAll);
  435. X    setCursor(copyCursor);
  436. X    mode = CopyMode;
  437. X    changestate(False);
  438. X    srcdir = XtNewString(cwd);
  439. X    copyfirst = False;
  440. X      } else {
  441. X    setCursor(left_ptr);
  442. X    mode = NormalMode;
  443. X    buttonSensitive = True; /* hack to force buttons insensitive */
  444. X    changestate(False);
  445. X    dstdir = XtNewString(cwd);
  446. X    button_dialog(type, return_list);
  447. X    copyfirst = True;
  448. X      }
  449. X      break;
  450. X    case Move:
  451. X      if (movefirst == True) {
  452. X    /* deselect all */
  453. X    XedwListUnhighlight(directoryManager, XedwAll);
  454. X    setCursor(moveCursor);
  455. X    mode = MoveMode;
  456. X    changestate(False);
  457. X    srcdir = XtNewString(cwd);
  458. X    movefirst = False;
  459. X      } else {
  460. X    setCursor(left_ptr);
  461. X    mode = NormalMode;
  462. X    buttonSensitive = True; /* hack to force buttons insensitive */
  463. X    changestate(False);
  464. X    dstdir = XtNewString(cwd);
  465. X    button_dialog(type, return_list);
  466. X    movefirst = True;
  467. X      }
  468. X      break;
  469. X    }
  470. X  }
  471. X  else
  472. X    XBell(XtDisplay(w), 100);
  473. X
  474. X}
  475. X
  476. Xpublic void trashQueryResult(Widget w, Boolean delete, caddr_t call_data)
  477. X{
  478. X  public int  execute(String, String, String, Boolean);
  479. X  extern void destroy_button_dialog(void);
  480. X  extern void changestate(Boolean);
  481. X  extern void setCursor(Cursor);
  482. X  extern Boolean directoryManagerNewDirectory(String);
  483. X  extern void query_dialog(String, Boolean);
  484. X  extern Cursor busy, left_ptr;
  485. X  extern String cwd;
  486. X  private void freeReturnStruct(void);
  487. X  String rmstring;
  488. X  int status;
  489. X  XedwListReturnStruct *tmp;
  490. X
  491. X  setCursor(busy);
  492. X
  493. X  /* destroy dialog */
  494. X  destroy_button_dialog();
  495. X
  496. X  if (delete == True) {
  497. X    /* delete files */
  498. X
  499. X    /* I can't be bothered writing my own remove routine so I'll call
  500. X     * 'rm(1)' via execute instead.
  501. X     */
  502. X    rmstring = XtNewString("rm -fr");
  503. X    tmp = return_list;
  504. X    while (tmp != NULL) {
  505. X      rmstring = (String) XtRealloc (rmstring, sizeof(char) * 
  506. X                     (strlen(rmstring) +
  507. X                      strlen(tmp->string) + 4));
  508. X      sprintf(rmstring, "%s '%s'", rmstring, tmp->string);
  509. X      tmp = tmp->next;
  510. X    }
  511. X    if ((status = execute(NULL, "rm", rmstring, True)) != 0) {
  512. X      XBell(XtDisplay(w), 100);
  513. X      query_dialog("Can't remove file", False);
  514. X    }
  515. X    XtFree(rmstring);
  516. X    /* refresh directory (clear highlights as a side effect) */
  517. X    directoryManagerNewDirectory(cwd);
  518. X  } else {
  519. X    /* leave list highlighted, make buttons sensitive again */
  520. X    changestate(True);
  521. X  }
  522. X
  523. X  /* free memory for list */
  524. X  setCursor(left_ptr);
  525. X  freeReturnStruct();
  526. X
  527. X}
  528. X
  529. Xpublic void copyQueryResult(Widget w, Boolean copy, caddr_t call_data)
  530. X{
  531. X  extern void destroy_button_dialog(void);
  532. X  extern void changestate(Boolean);
  533. X  extern void setCursor(Cursor);
  534. X  extern void query_dialog(String, Boolean);
  535. X  extern Boolean directoryManagerNewDirectory(String);
  536. X  extern Cursor busy, left_ptr;
  537. X  private void freeReturnStruct(void);
  538. X  public int execute(String, String, String, Boolean);
  539. X  extern String cwd;
  540. X  String copystring;
  541. X  int status;
  542. X  Cardinal srclen, dstlen;
  543. X  XedwListReturnStruct *tmp;
  544. X
  545. X  destroy_button_dialog();
  546. X
  547. X  setCursor(busy);
  548. X
  549. X  if (copy == True) {
  550. X    /* copy files */
  551. X    
  552. X    /* I can't be bothered writing my own copy routine so I'll call
  553. X     * 'cp(1)' via execute instead.
  554. X     */
  555. X    srclen = strlen(srcdir);
  556. X    dstlen = strlen(dstdir);
  557. X    copystring = XtNewString("cp -r");
  558. X    tmp = return_list;
  559. X    while (tmp != NULL) {
  560. X      copystring = (String) XtRealloc (copystring, sizeof(char) * 
  561. X                       (strlen(copystring) +
  562. X                    strlen(tmp->string) +
  563. X                    srclen + 4));
  564. X      sprintf(copystring, "%s '%s/%s'", copystring, srcdir, tmp->string);
  565. X      tmp = tmp->next;
  566. X    }
  567. X    copystring = (String) XtRealloc (copystring, sizeof(char) *
  568. X                     (strlen(copystring) +
  569. X                      dstlen + 4));
  570. X
  571. X    sprintf(copystring, "%s '%s'", copystring, dstdir);
  572. X    if ((status = execute(NULL, "cp", copystring, True)) != 0) {
  573. X      XBell(XtDisplay(w), 100);
  574. X      query_dialog("Can't copy file!", False);
  575. X    }
  576. X    XtFree(copystring);
  577. X    /* refresh directory (clear highlights as a side effect) */
  578. X    directoryManagerNewDirectory(cwd);
  579. X  } else {
  580. X    changestate(True);
  581. X  }
  582. X
  583. X    
  584. X  XtFree(srcdir);
  585. X  XtFree(dstdir);
  586. X  setCursor(left_ptr);
  587. X  freeReturnStruct();
  588. X}
  589. X
  590. Xpublic void moveQueryResult(Widget w, Boolean move, caddr_t call_data)
  591. X{
  592. X  extern void destroy_button_dialog(void);
  593. X  extern void changestate(Boolean);
  594. X  extern void setCursor(Cursor);
  595. X  extern Boolean directoryManagerNewDirectory(String);
  596. X  extern void query_dialog(String, Boolean);
  597. X  extern Cursor busy, left_ptr;
  598. X  private void freeReturnStruct(void);
  599. X  public int execute(String, String, String, Boolean);
  600. X  extern String cwd;
  601. X  String movestring;
  602. X  Cardinal srclen, dstlen;
  603. X  int status;
  604. X  XedwListReturnStruct *tmp;
  605. X
  606. X  destroy_button_dialog();
  607. X
  608. X  setCursor(busy);
  609. X
  610. X  if (move == True) {
  611. X    /* move files */
  612. X    
  613. X    /* I can't be bothered writing my own move routine so I'll call
  614. X     * 'mv(1)' via execute instead.
  615. X     */
  616. X    srclen = strlen(srcdir);
  617. X    dstlen = strlen(dstdir);
  618. X    movestring = XtNewString("mv -f - ");
  619. X    tmp = return_list;
  620. X    while (tmp != NULL) {
  621. X      movestring = (String) XtRealloc (movestring, sizeof(char) * 
  622. X                       (strlen(movestring) +
  623. X                    strlen(tmp->string) +
  624. X                    srclen + 4));
  625. X      sprintf(movestring, "%s '%s/%s'", movestring, srcdir, tmp->string);
  626. X      tmp = tmp->next;
  627. X    }
  628. X    movestring = (String) XtRealloc (movestring, sizeof(char) *
  629. X                     (strlen(movestring) +
  630. X                      dstlen + 4));
  631. X
  632. X    sprintf(movestring, "%s '%s'", movestring, dstdir);
  633. X    if ((status = execute(NULL, "mv", movestring, True)) != 0) {
  634. X      XBell(XtDisplay(w), 100);
  635. X      query_dialog("Can't move file!", False);
  636. X    }
  637. X    XtFree(movestring);
  638. X    /* refresh directory (clear highlights as a side effect) */
  639. X    directoryManagerNewDirectory(cwd);
  640. X  } else {
  641. X    changestate(True);
  642. X  }
  643. X    
  644. X  XtFree(srcdir);
  645. X  XtFree(dstdir);
  646. X  setCursor(left_ptr);
  647. X  freeReturnStruct();
  648. X}
  649. X
  650. Xprivate void freeReturnStruct(void)
  651. X{
  652. X  /* Deallocate memory for the current list return structure.
  653. X   */
  654. X
  655. X  XedwListReturnStruct *tmp;
  656. X
  657. X  while(return_list != NULL) {
  658. X    tmp = return_list;
  659. X    return_list = return_list->next;
  660. X    XtFree(tmp->string);
  661. X    XtFree(tmp);
  662. X  }
  663. X}
  664. X  
  665. Xpublic void selectionChange(Widget w, Cardinal selection, caddr_t crap)
  666. X{
  667. X  extern AppSelection **appselections;
  668. X  extern Cardinal selectionindex;
  669. X  XedwList **list;
  670. X  Arg arglist[1];
  671. X  Cardinal i;
  672. X
  673. X  appman_selection = selection;
  674. X  i = 0;
  675. X  XtSetArg(arglist[i], XtNlabel, appselections[appman_selection]->name); i++;
  676. X  XtSetValues(appManagerButton, arglist, i);
  677. X
  678. X  /* Change contents of AppManager to that of the new selection */
  679. X  list = (XedwList**) appselections[appman_selection]->list;
  680. X
  681. X  XedwListChange(appManager, list, appselections[appman_selection]->number,
  682. X         0, True);
  683. X
  684. X  /* Reset scrollbar to top */
  685. X  setscroll(appManagerView, 0.0);
  686. X}
  687. X
  688. Xprivate void program_selected(Widget w, caddr_t client, caddr_t call)
  689. X{
  690. X  public int execute(String, String, String, Boolean);
  691. X  public String build_arguments(String, SelOptions);
  692. X  extern void setCursor(Cursor);
  693. X  extern Cursor busy;
  694. X  extern AppSelection **appselections;
  695. X  XedwListReturnStruct *list;
  696. X  AppProgram *node;
  697. X  String program, filename;
  698. X  Cardinal index;
  699. X
  700. X  setCursor(busy);
  701. X  /* Get the index of the program double clicked */
  702. X  list = XedwListShowCurrent(w);
  703. X  index = list->xedwList_index;
  704. X  node = appselections[appman_selection]->list[index];
  705. X  program = XtNewString(node->program);
  706. X  
  707. X  /* extract filename from program */
  708. X  filename = XtNewString(program);
  709. X  filename = strtok(filename, " ");
  710. X  
  711. X  XtFree(list);
  712. X  
  713. X  /* check to see if there are any highlighted files to add as arguments, 
  714. X   * if so check to see where the insertion point is, if no insertion 
  715. X   * point then append arguments.
  716. X   */
  717. X
  718. X  program = build_arguments(program, node->options);
  719. X
  720. X  
  721. X  /* execute program */
  722. X
  723. X  execute(NULL, filename, program, False);
  724. X  setCursor(NULL);
  725. X
  726. X}
  727. X
  728. Xpublic int execute(String fullname, String filename, 
  729. X            String args, Boolean cwait)
  730. X{
  731. X  typedef enum {ready, quote, normal, quoteready} QModes;
  732. X
  733. X  QModes mode;
  734. X  Cardinal i, n, arglen;
  735. X  int result, pid, fd;
  736. X  int status = 0;
  737. X  String newargs[MAXARGS], strptr;
  738. X  
  739. X  if (fullname == NULL) {
  740. X    /* Find program */
  741. X    result = -1;
  742. X    for (i = 0; i < pathsize && result != 0; i++) {
  743. X      /* append filename to path */
  744. X      fullname = (String) XtRealloc (fullname, ((strlen(patharray[i])+
  745. X                         strlen(filename) + 3)
  746. X                        * sizeof(char)));
  747. X      strcpy(fullname, patharray[i]);
  748. X      strcat(fullname, "/");
  749. X      strcat(fullname, filename);
  750. X
  751. X      result = access(fullname, X_OK); /* Does file exist, Is file executable ? */
  752. X    }
  753. X    
  754. X    if (result != 0) {
  755. X      fprintf(stderr, "Warning: Command '%s' not found in PATH\n", filename);
  756. X      return;
  757. X    }
  758. X  } 
  759. X
  760. X  /* split the args string into a NULL terminated array of strings .
  761. X   * If a string of characters is enclosed within quotes, it is counted
  762. X   * as a single argument.
  763. X   */
  764. X
  765. X  n = 0;
  766. X  mode = ready;
  767. X  arglen = strlen(args);
  768. X  for (i = 0; i < arglen; i++) {
  769. X    switch (*(args+i)) {
  770. X    case '\'':
  771. X      if (mode == normal || mode == ready) {
  772. X    /* start a new arg on the next normal chr */
  773. X    mode = quoteready;
  774. X      } else if (mode == quote || mode == quoteready) {
  775. X    /* close current quote */
  776. X    *(args+i) = '\0';
  777. X    mode = ready;
  778. X      }
  779. X      break;
  780. X    case ' ':
  781. X    case '\t':
  782. X      if (mode == normal) {
  783. X    /* terminate current arg */
  784. X    *(args+i) = '\0';
  785. X    mode = ready;
  786. X      }
  787. X      break;
  788. X    default:
  789. X      if (mode == ready || mode == quoteready) {
  790. X    /* start a new arg */
  791. X    if (n == MAXARGS-1) {
  792. X      fprintf(stderr, "Error: Only %d arguments allowed"
  793. X          " to a command.\n", MAXARGS);
  794. X    } else {
  795. X      newargs[n++] = args+i;
  796. X      if (mode == ready)
  797. X        mode = normal;
  798. X      else
  799. X        mode = quote;
  800. X    }
  801. X      }
  802. X      break;
  803. X    }
  804. X  }
  805. X    
  806. X  newargs[n] = NULL;
  807. X
  808. X  if ((pid = fork()) == -1) 
  809. X    fprintf(stderr, "Warning: unable to fork\n");
  810. X  else 
  811. X    if (pid == 0) {
  812. X      /* Child */
  813. X
  814. X      /* Take standard input from /dev/null. This presents any child process
  815. X       * with an immediate end-of-file when read.
  816. X       * Also redirect standard output to /dev/null, but leave standard error
  817. X       * associated with xdtm so we can see error messages on the console.
  818. X       * (unless cwait is set, in whiich case stderr is redirected as well)
  819. X       */
  820. X      
  821. X      if (close(0) == -1) 
  822. X    fprintf(stderr, "Warning: can't close childs file descriptors\n");
  823. X      else 
  824. X    if (open("/dev/null", O_RDONLY, 0) == -1)
  825. X      fprintf(stderr, "Warning: can't open /dev/null as new input"
  826. X          " for child\n");
  827. X      
  828. X      if (close(1) == -1) 
  829. X    fprintf(stderr, "Warning: can't close childs file descriptors\n");
  830. X      else 
  831. X    if (open("/dev/null", O_WRONLY, 0) == -1)
  832. X      fprintf(stderr, "Warning: can't open /dev/null as new output"
  833. X          " for child\n");
  834. X
  835. X      if (cwait) 
  836. X    if (close(2) == -1) 
  837. X      fprintf(stderr, "Warning: can't close childs file descriptors\n");
  838. X    else 
  839. X      if (open("/dev/null", O_WRONLY, 0) == -1)
  840. X        fprintf(stderr, "Warning: can't open /dev/null as new error output"
  841. X            " for child\n");
  842. X
  843. X      /* close all opened file descriptors (except stdin, stderr, stdout) */
  844. X      for (fd = 3; fd < 20; fd++)
  845. X    (void) close(fd); 
  846. X
  847. X      execv(fullname, newargs);
  848. X
  849. X      fprintf(stderr, "Warning: Exec on '%s' failed.\n", fullname);
  850. X      exit(0);
  851. X    } else {
  852. X      /* Parent */
  853. X      
  854. X      /* If cwait is True then wait for the child to finish, then
  855. X       * set status to it's return value.
  856. X       */
  857. X      if (cwait) {
  858. X    wait(&status);
  859. X    status = (status >> 8);
  860. X      }
  861. X    }
  862. X
  863. X  return(status);
  864. X}
  865. X
  866. Xpublic String build_arguments(String program, SelOptions options)
  867. X{
  868. X  extern void changestate(Boolean);
  869. X  extern String getfilename(String);
  870. X  extern Widget directoryManager;
  871. X  XedwListReturnStruct *list, *tmplist;
  872. X  String ptr, tmpptr, arguments;
  873. X
  874. X  list = XedwListShowCurrent(directoryManager);
  875. X
  876. X  arguments = NULL;
  877. X  if (options != N_SEL) {
  878. X    while (list != NULL) {
  879. X      arguments = XtRealloc (arguments, sizeof(char) * 
  880. X                 (((arguments == NULL) ? 0 : strlen(arguments)) + 
  881. X                  strlen(getfilename(list->string)) + 4));
  882. X      strcat(arguments, " ");
  883. X      strcat(arguments, getfilename(list->string));
  884. X      tmplist = list;
  885. X      list = list->next;
  886. X      XtFree(tmplist);
  887. X    }
  888. X    /* insert the arguments into the program string */
  889. X    program = XtRealloc (program, sizeof(char) * (strlen(program) + 
  890. X                          strlen(arguments) + 4));
  891. X    
  892. X    if ((ptr = strstr(program, "!@")) != NULL) {
  893. X      /* replace !@ with arguments */
  894. X      tmpptr = XtNewString(ptr+2);
  895. X      *ptr = '\0';
  896. X      strcat(program, arguments);
  897. X      strcat(program, tmpptr);
  898. X      XtFree(tmpptr);
  899. X    } else {
  900. X      /* append arguments to program */
  901. X      strcat(program, arguments);
  902. X    }
  903. X    XtFree(arguments);
  904. X  } 
  905. X
  906. X  XedwListUnhighlight(directoryManager, XedwAll);
  907. X  changestate(False); 
  908. X
  909. X  return(program);
  910. X}
  911. SHAR_EOF
  912. chmod 0644 code/appman.c || echo "restore of code/appman.c fails"
  913. echo "x - extracting code/buttons.c (Text)"
  914. sed 's/^X//' << 'SHAR_EOF' > code/buttons.c &&
  915. X/*****************************************************************************
  916. X ** File          : buttons.c                                               **
  917. X ** Purpose       : Initialise and Realise button dialogs                   **
  918. X ** Author        : Edward Groenendaal                                      **
  919. X ** Date          : April 1991                                              **
  920. X ** Documentation : Xdtm Design Folder                                      **
  921. X ** Related Files :                                                         **
  922. X *****************************************************************************/
  923. X
  924. X#include "xdtm.h"
  925. X#include "menus.h"
  926. X
  927. X#include <X11/Shell.h>
  928. X#include <X11/Xaw/Label.h>
  929. X#include <X11/Xaw/Command.h>
  930. X#include <X11/Xaw/Viewport.h>
  931. X#include "Xedw/XedwForm.h"
  932. X#include "Xedw/XedwList.h"
  933. X
  934. Xextern void realize_dialog(Widget);
  935. X
  936. X/* Widgets */
  937. X
  938. Xprivate Widget buttonpopup;     /* For conformation of move/copy/trash buttons */
  939. Xprivate Widget buttonform;
  940. Xprivate Widget buttonlabel1;
  941. Xprivate Widget buttonlabel2;
  942. Xprivate Widget buttonyes;
  943. Xprivate Widget buttonno;
  944. Xprivate Widget fileview;
  945. Xprivate Widget filelist;
  946. X
  947. Xpublic void init_button(Widget top)
  948. X{
  949. X  Arg arglist[5];
  950. X  Cardinal i;
  951. X  XtTranslations translations;
  952. X  Dimension height, space;
  953. X  XFontStruct *font;
  954. X
  955. X  buttonpopup  =   XtCreatePopupShell("buttonpopup",
  956. X                      transientShellWidgetClass,
  957. X                      top,
  958. X                      NULL, 0);
  959. X
  960. X
  961. X  buttonform    =   XtCreateManagedWidget("buttonform",
  962. X                      xedwFormWidgetClass,
  963. X                      buttonpopup,
  964. X                      NULL, 0);
  965. X
  966. X  i = 0;
  967. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter);  i++;
  968. X  XtSetArg(arglist[i], XtNfullWidth,          True);  i++;
  969. X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
  970. X  buttonlabel1  =   XtCreateManagedWidget("buttonlabel1",
  971. X                      labelWidgetClass,
  972. X                      buttonform,
  973. X                      arglist, i);
  974. X
  975. X  i = 3;
  976. X  XtSetArg(arglist[i], XtNfromVert,   buttonlabel1);  i++; 
  977. X  buttonlabel2  =   XtCreateManagedWidget("buttonlabel2",
  978. X                      labelWidgetClass,
  979. X                      buttonform,
  980. X                      arglist, i);
  981. X
  982. X  i = 0;
  983. X  XtSetArg(arglist[i], XtNfromVert, buttonlabel2);  i++; 
  984. X  XtSetArg(arglist[i], XtNfullWidth,        True);  i++;
  985. X  XtSetArg(arglist[i], XtNforceBars,        True);  i++;
  986. X  XtSetArg(arglist[i], XtNallowVert,        True);  i++;
  987. X  fileview = XtCreateManagedWidget("fileview",
  988. X                   viewportWidgetClass,
  989. X                   buttonform,
  990. X                   arglist, i);
  991. X
  992. X  translations = XtParseTranslationTable("");
  993. X  i = 0;
  994. X  XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;
  995. X  XtSetArg(arglist[i], XtNforceColumns, True); i++;
  996. X  XtSetArg(arglist[i], XtNrowSpacing,      4); i++;
  997. X  XtSetArg(arglist[i], XtNtranslations, translations); i++;
  998. X  filelist = XtCreateManagedWidget("filelist",
  999. X                   xedwListWidgetClass,
  1000. X                   fileview,
  1001. X                   arglist, i);
  1002. X
  1003. X
  1004. X  /* Get font height from filelist, then set fileview to be 5 times that
  1005. X   * size.
  1006. X   */
  1007. X
  1008. X  i = 0;
  1009. X  XtSetArg(arglist[i], XtNfont, &font); i++;
  1010. X  XtSetArg(arglist[i], XtNrowSpacing, &space); i++;
  1011. X  XtGetValues(filelist, arglist, i);
  1012. X
  1013. X  height = (font->max_bounds.ascent +
  1014. X           font->max_bounds.descent +
  1015. X       space) * 5;
  1016. X
  1017. X  i = 0;
  1018. X  XtSetArg(arglist[i], XtNheight, height); i++;
  1019. X  XtSetValues(fileview, arglist, i);
  1020. X
  1021. X
  1022. X  i = 0;
  1023. X  XtSetArg(arglist[i], XtNfromVert,       fileview);  i++; 
  1024. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter);  i++;
  1025. X  buttonno   =   XtCreateManagedWidget("buttonyes",
  1026. X                       commandWidgetClass,
  1027. X                       buttonform,
  1028. X                       arglist, i);
  1029. X  i = 2;
  1030. X  XtSetArg(arglist[i], XtNfromHoriz,   buttonno);  i++;
  1031. X  XtSetArg(arglist[i], XtNwidthLinked, buttonno);  i++;
  1032. X  buttonyes  =   XtCreateManagedWidget("buttonyes",
  1033. X                       commandWidgetClass,
  1034. X                       buttonform,
  1035. X                       arglist, i);
  1036. X
  1037. X}
  1038. X
  1039. X
  1040. Xpublic void button_dialog(Cardinal type, XedwListReturnStruct *list)
  1041. X{
  1042. X  private int buttoniconcmp(XedwList **, XedwList **);
  1043. X  extern String getfilename(String);
  1044. X  extern void setscroll(Widget, float);
  1045. X
  1046. X  XedwListReturnStruct *tmp;
  1047. X  XedwList **buttonlist;
  1048. X  Arg arglist[5];
  1049. X  Cardinal i, n;
  1050. X  private String CancelButtonLabel = "Cancel";
  1051. X
  1052. X  /* Count items in linked list */
  1053. X  n = 0;
  1054. X  tmp = list;
  1055. X  while (tmp != NULL) {
  1056. X    tmp = tmp->next;
  1057. X    n++;
  1058. X  }
  1059. X
  1060. X  /* Allocate an array of XedwList* of that size */
  1061. X  buttonlist = (XedwList**) XtMalloc (sizeof(XedwList*) * (n+1));
  1062. X
  1063. X  /* Put Strings from linked list into array, using NULL icons */
  1064. X  for (i = 0; i < n; i++) {
  1065. X    buttonlist[i] = XtNew(XedwList);
  1066. X    buttonlist[i]->string = list->string;
  1067. X    list = list->next;
  1068. X  }
  1069. X  buttonlist[i] = NULL;
  1070. X
  1071. X  /* Sort the list */
  1072. X  qsort((char*)buttonlist, n, sizeof(buttonlist[0]), buttoniconcmp);
  1073. X
  1074. X  /* Reset view to top */
  1075. X
  1076. X  setscroll(fileview, 0.0);
  1077. X
  1078. X  switch (type) {
  1079. X  case Trash:
  1080. X    {
  1081. X      extern void trashQueryResult(Widget, Boolean, caddr_t);
  1082. X      private String TrashLabel1       = "Delete these files";
  1083. X      private String TrashLabel2       = "from current directory?";
  1084. X      private String TrashButtonLabel  = "Delete";
  1085. X
  1086. X      /* label */
  1087. X      i = 0;
  1088. X      XtSetArg(arglist[i], XtNlabel, TrashLabel1);  i++;
  1089. X      XtSetValues(buttonlabel1, arglist, i);
  1090. X    
  1091. X      /* label2 */
  1092. X      i = 0;
  1093. X      XtSetArg(arglist[i], XtNlabel,       TrashLabel2);  i++; 
  1094. X      XtSetValues(buttonlabel2, arglist, i);
  1095. X      
  1096. X      /* file list */
  1097. X      i = 0;
  1098. X      XtSetArg(arglist[i], XtNlongest,           0); i++;
  1099. X      XtSetArg(arglist[i], XtNnumberStrings,     0); i++;
  1100. X      XtSetArg(arglist[i], XtNxedwList, buttonlist); i++;
  1101. X      XtSetValues(filelist, arglist, i);
  1102. X
  1103. X      /* button1 */
  1104. X      i = 0;
  1105. X      XtSetArg(arglist[i], XtNlabel, CancelButtonLabel);  i++;
  1106. X      XtSetValues(buttonno, arglist, i);
  1107. X      
  1108. X      /* button2 */
  1109. X      i = 0;
  1110. X      XtSetArg(arglist[i], XtNlabel,   TrashButtonLabel);  i++;
  1111. X      XtSetValues(buttonyes, arglist, i);
  1112. X      
  1113. X      XtAddCallback(buttonno, XtNcallback, trashQueryResult, False);
  1114. X      XtAddCallback(buttonyes, XtNcallback, trashQueryResult, True);
  1115. X      realize_dialog(buttonpopup);
  1116. X      break;
  1117. X    }
  1118. X  case Copy:
  1119. X    {
  1120. X      extern void copyQueryResult(Widget, Boolean, caddr_t);
  1121. X      private String CopyLabel1       = "Copy these files";
  1122. X      private String CopyLabel2       = "to current directory?";
  1123. X      private String CopyButtonLabel  = "Copy";
  1124. X
  1125. X      /* label */
  1126. X      i = 0;
  1127. X      XtSetArg(arglist[i], XtNlabel, CopyLabel1);  i++;
  1128. X      XtSetValues(buttonlabel1, arglist, i);
  1129. X    
  1130. X      /* label2 */
  1131. X      i = 0;
  1132. X      XtSetArg(arglist[i], XtNlabel, CopyLabel2);  i++; 
  1133. X      XtSetValues(buttonlabel2, arglist, i);
  1134. X      
  1135. X      /* file list */
  1136. X      i = 0;
  1137. X      XtSetArg(arglist[i], XtNlongest,           0); i++;
  1138. X      XtSetArg(arglist[i], XtNnumberStrings,     0); i++;
  1139. X      XtSetArg(arglist[i], XtNxedwList, buttonlist); i++;
  1140. X      XtSetValues(filelist, arglist, i);
  1141. X
  1142. X      /* button1 */
  1143. X      i = 0;
  1144. X      XtSetArg(arglist[i], XtNlabel, CancelButtonLabel);  i++;
  1145. X      XtSetValues(buttonno, arglist, i);
  1146. X      
  1147. X      /* button2 */
  1148. X      i = 0;
  1149. X      XtSetArg(arglist[i], XtNlabel, CopyButtonLabel);  i++;
  1150. X      XtSetValues(buttonyes, arglist, i);
  1151. X      
  1152. X      XtAddCallback(buttonno, XtNcallback,  copyQueryResult, False);
  1153. X      XtAddCallback(buttonyes, XtNcallback, copyQueryResult, True);
  1154. X      realize_dialog(buttonpopup);
  1155. X      break;
  1156. X    }
  1157. X  case Move:
  1158. X    {
  1159. X      extern void moveQueryResult(Widget, Boolean, caddr_t);
  1160. X      private String MoveLabel1       = "Move these files";
  1161. X      private String MoveLabel2       = "to current directory?";
  1162. X      private String MoveButtonLabel  = "Move";
  1163. X
  1164. X      /* label */
  1165. X      i = 0;
  1166. X      XtSetArg(arglist[i], XtNlabel, MoveLabel1);  i++;
  1167. X      XtSetValues(buttonlabel1, arglist, i);
  1168. X    
  1169. X      /* label2 */
  1170. X      i = 0;
  1171. X      XtSetArg(arglist[i], XtNlabel, MoveLabel2);  i++; 
  1172. X      XtSetValues(buttonlabel2, arglist, i);
  1173. X      
  1174. X      /* file list */
  1175. X      i = 0;
  1176. X      XtSetArg(arglist[i], XtNlongest,           0); i++;
  1177. X      XtSetArg(arglist[i], XtNnumberStrings,     0); i++;
  1178. X      XtSetArg(arglist[i], XtNxedwList, buttonlist); i++;
  1179. X      XtSetValues(filelist, arglist, i);
  1180. X
  1181. X      /* button1 */
  1182. X      i = 0;
  1183. X      XtSetArg(arglist[i], XtNlabel, CancelButtonLabel);  i++;
  1184. X      XtSetValues(buttonno, arglist, i);
  1185. X      
  1186. X      /* button2 */
  1187. X      i = 0;
  1188. X      XtSetArg(arglist[i], XtNlabel, MoveButtonLabel);  i++;
  1189. X      XtSetValues(buttonyes, arglist, i);
  1190. X      
  1191. X      XtAddCallback(buttonno, XtNcallback,  moveQueryResult, False);
  1192. X      XtAddCallback(buttonyes, XtNcallback, moveQueryResult, True);
  1193. X      realize_dialog(buttonpopup);
  1194. X      break;
  1195. X    }
  1196. X
  1197. X  default:
  1198. X    fprintf(stderr, "Unrecognised button dialog request\n");
  1199. X    break;
  1200. X  }
  1201. X
  1202. X  /* deallocate memory for newlist */
  1203. X
  1204. X}
  1205. X
  1206. Xpublic void destroy_button_dialog(void)
  1207. X{
  1208. X  XtPopdown(buttonpopup);
  1209. X  
  1210. X  XtRemoveAllCallbacks(buttonyes, XtNcallback);
  1211. X  XtRemoveAllCallbacks(buttonno, XtNcallback);
  1212. X
  1213. X}
  1214. X
  1215. Xprivate int buttoniconcmp(XedwList **ip1, XedwList **ip2)
  1216. X{
  1217. X  /* compare the strings of 2 XedwList's */
  1218. X
  1219. X  return (strcmp((*ip1)->string, 
  1220. X         (*ip2)->string));
  1221. X}
  1222. SHAR_EOF
  1223. chmod 0644 code/buttons.c || echo "restore of code/buttons.c fails"
  1224. echo "x - extracting code/dialogs.c (Text)"
  1225. sed 's/^X//' << 'SHAR_EOF' > code/dialogs.c &&
  1226. X/* v0.2 */
  1227. X/***********************************************************************************
  1228. X ** File          : dialogs.c                                                     **
  1229. X ** Purpose       : Initialise and Realise dialogs                                **
  1230. X ** Author        : Edward Groenendaal                                            **
  1231. X ** Date          : 18th Feb 1991                                                 **
  1232. X ** Documentation : Xdtm Design Folder                                            **
  1233. X ** Related Files : quit.c buttons.c listoption.c map.c select.c display.c        **
  1234. X **                 newfile.c                              **
  1235. X ***********************************************************************************/
  1236. X
  1237. X/* dialog box's provided: Quit    - Quit (yes/no)
  1238. X *              Button  - Do action to these files (yes/no)
  1239. X *                        Longl   - Select options on Long Listing
  1240. X *                        Map     - Map program x over selected files OR
  1241. X *                        Select  - Select files using RE x.
  1242. X *              Query   - Display file?
  1243. X *               Display - Display a file.
  1244. X *                     Newfile - Ask for filename, create empty file. 
  1245. X *              Info    - Give info about a file.
  1246. X *
  1247. X * Create instances of popup shells and forms, plus one of each of the 'core' dialog
  1248. X */
  1249. X
  1250. X#include "xdtm.h"
  1251. X
  1252. Xpublic void createDialogWidgets(Widget top)
  1253. X{
  1254. X
  1255. X  extern void init_quit(Widget);
  1256. X  extern void init_button(Widget);
  1257. X  extern void init_listoption(Widget);
  1258. X  extern void init_map(Widget);
  1259. X  extern void init_query(Widget);
  1260. X  extern void init_display(Widget);
  1261. X  extern void init_newfile(Widget);
  1262. X  extern void init_info(Widget);
  1263. X
  1264. X  init_quit(top);
  1265. X  init_button(top);
  1266. X  init_listoption(top);
  1267. X  init_map(top);
  1268. X  init_query(top);
  1269. X  init_display(top);
  1270. X  init_newfile(top);
  1271. X  init_info(top);
  1272. X                  
  1273. X}
  1274. X
  1275. Xpublic void realize_dialog(Widget popup)
  1276. X{
  1277. X  extern Widget topLevel;
  1278. X  Position x,y;
  1279. X  Dimension appWidth, appHeight, qWidth, qHeight;
  1280. X  XtGeometryResult result;
  1281. X  XtWidgetGeometry answer, question;
  1282. X  Arg arglist[2];
  1283. X  Cardinal i;
  1284. X  
  1285. X  /* You dont know the dimensions of a widget for certain until it is
  1286. X   * realized, therefore realize the dialog.
  1287. X   * NOTE: XtRealizeWidget returns without an error if widget is already
  1288. X   *       realized, hence no check via XtIsRealized.
  1289. X   */
  1290. X
  1291. X  XtRealizeWidget(popup);
  1292. X
  1293. X  /* Get dimensions of application */
  1294. X  i = 0;
  1295. X  XtSetArg(arglist[i], XtNwidth,  &appWidth);    i++;
  1296. X  XtSetArg(arglist[i], XtNheight, &appHeight);   i++;
  1297. X  XtGetValues(topLevel, arglist, i);
  1298. X
  1299. X  /* Get dimensions of quit popup */
  1300. X  i = 0;
  1301. X  XtSetArg(arglist[i], XtNwidth,  &qWidth);    i++;
  1302. X  XtSetArg(arglist[i], XtNheight, &qHeight);   i++;
  1303. X  XtGetValues(popup, arglist, i);
  1304. X
  1305. X  /* Translate application coordinates to screen coordinates */
  1306. X  XtTranslateCoords(topLevel,
  1307. X            (Position) ((appWidth/2)-(qWidth/2)),
  1308. X            (Position) ((appHeight/2)-(qHeight/2)),
  1309. X            &x, &y);
  1310. X
  1311. X  /* move popup shell to that position */
  1312. X  i = 0;
  1313. X  XtSetArg(arglist[i], XtNx, x);  i++;
  1314. X  XtSetArg(arglist[i], XtNy, y);  i++;
  1315. X  XtSetValues(popup, arglist, i);
  1316. X
  1317. X  XtPopup(popup, XtGrabNonexclusive);
  1318. X  
  1319. X}
  1320. SHAR_EOF
  1321. chmod 0644 code/dialogs.c || echo "restore of code/dialogs.c fails"
  1322. echo "x - extracting code/dirman.c (Text)"
  1323. sed 's/^X//' << 'SHAR_EOF' > code/dirman.c &&
  1324. X/* v0.3 */
  1325. X/*****************************************************************************
  1326. X ** File          : dirman.c                                                **
  1327. X ** Purpose       : Directory Manager                                       **
  1328. X ** Author        : Edward Groenendaal                                      **
  1329. X ** Date          : 18th Feb 1990                                           **
  1330. X ** Documentation : Xedw Design Folder                                      **
  1331. X ** Related Files :                                                         **
  1332. X *****************************************************************************/
  1333. X
  1334. X/* Include the application header file */
  1335. X#include "xdtm.h"
  1336. X
  1337. X/* Include the local header files */
  1338. X#include <sys/types.h>
  1339. X#include <dirent.h>
  1340. X#include <sys/stat.h>
  1341. X#include <sys/param.h>
  1342. X#include <X11/Xaw/AsciiText.h>
  1343. X
  1344. X#include "menus.h"
  1345. X#include "Xedw/XedwList.h"
  1346. X#include "Xedw/XedwForm.h"
  1347. X
  1348. X#define LISTSIZE    128
  1349. X#define LISTINCR    64
  1350. X
  1351. Xpublic void   changestate(Boolean);        /* Change sensitivity */
  1352. Xpublic String getfilename(String);       /* extract filename */
  1353. X
  1354. Xpublic Widget directoryManager;
  1355. Xpublic String cwd;             /* current working directory */
  1356. Xpublic Cardinal icon_list_size = 0;
  1357. Xpublic Cardinal icon_list_max_size = LISTSIZE;
  1358. Xpublic XedwList **icon_list;
  1359. X
  1360. X/* local copies of the menu panes which are to be made insensitive when
  1361. X * no there is no current selection.
  1362. X */
  1363. Xprivate Widget duplicatemenu, getinfomenu, trashmenu, 
  1364. X               copymenu, movemenu, mapmenu;
  1365. X
  1366. Xpublic void createDirectoryManagerWidgets(Widget view)
  1367. X{
  1368. X  public  void selection_made(Widget, caddr_t, caddr_t);
  1369. X  private void DoubleClick(Widget, XButtonEvent*);
  1370. X  private void GoUp(Widget, XButtonEvent*);
  1371. X  private void SelectAll(Widget, XButtonEvent*);
  1372. X  private void Refresh(Widget, XButtonEvent*);
  1373. X
  1374. X  extern AppData app_data;
  1375. X  extern Icon_mode current_mode;
  1376. X  Cardinal i;
  1377. X  Arg arglist[6];
  1378. X  XtTranslations dirManTranslations;
  1379. X
  1380. X  static XtActionsRec actions[] = {
  1381. X    {"DoubleClick", DoubleClick},
  1382. X    {"GoUp",        GoUp},
  1383. X    {"SelectAll",   SelectAll},
  1384. X    {"Refresh",     Refresh},
  1385. X    {NULL, NULL}
  1386. X  };
  1387. X
  1388. X  static char defaultTranslations[] =
  1389. X             "<Btn1Up>(2):     DoubleClick()\n\
  1390. X              <Key>u:          GoUp()\n\
  1391. X              <Key>a:          SelectAll()\n\
  1392. X          Ctrl<Key>L:      Refresh()";
  1393. X  
  1394. X  i = 0;
  1395. X  switch (current_mode.mode) {
  1396. X  case Icons:
  1397. X    XtSetArg(arglist[i], XtNshowIcons, True); i++;
  1398. X    break;
  1399. X  case Short:
  1400. X    XtSetArg(arglist[i], XtNshowIcons,   False); i++;
  1401. X    XtSetArg(arglist[i], XtNrowSpacing, 5); i++;
  1402. X    break;
  1403. X  case Long:
  1404. X    XtSetArg(arglist[i], XtNshowIcons,   False); i++;
  1405. X    XtSetArg(arglist[i], XtNrowSpacing,      5); i++;
  1406. X    XtSetArg(arglist[i], XtNforceColumns, True); i++;
  1407. X    XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;    
  1408. X  }
  1409. X  XtSetArg(arglist[i], XtNfont, app_data.dm_font); i++;    
  1410. X  XtSetArg(arglist[i], XtNmSelections,      True); i++;
  1411. X  directoryManager    =   XtCreateManagedWidget("directoryManager",
  1412. X                        xedwListWidgetClass,
  1413. X                        view,
  1414. X                        arglist, i);
  1415. X
  1416. X  XtAddCallback(directoryManager, XtNcallback, selection_made, 0);
  1417. X  XtAddActions(actions, XtNumber(actions));
  1418. X  dirManTranslations = XtParseTranslationTable(defaultTranslations);
  1419. X  XtAugmentTranslations(directoryManager, dirManTranslations);
  1420. X}
  1421. X
  1422. Xpublic Boolean directoryManagerNewDirectory(String newpath)
  1423. X{
  1424. X  extern Boolean getIconType(String, String, XedwList*);
  1425. X  extern void setCursor(Cursor);
  1426. X  extern void setscroll(Widget, float);
  1427. X  private int iconcmp(XedwList*, XedwList*);
  1428. X
  1429. X  extern Icon_mode current_mode;
  1430. X  extern Cursor busy;
  1431. X  extern Widget dirSelector;
  1432. X  extern Widget directoryManagerView;
  1433. X  Arg args[1];
  1434. X  XedwList temp;
  1435. X  DIR *dirp;
  1436. X  struct dirent *dp;
  1437. X  Cardinal i = 0, n;
  1438. X  Boolean result = False;
  1439. X
  1440. X  /* create a new one */
  1441. X  if ((dirp = opendir(newpath)) != NULL && chdir(newpath) == 0) {
  1442. X
  1443. X    /* set cursor to busy */
  1444. X    setCursor(busy);
  1445. X
  1446. X    /* Trash old list */
  1447. X    for(i=0; i < icon_list_size; i++) {
  1448. X      XtFree(icon_list[i]->string);
  1449. X      XtFree(icon_list[i]);
  1450. X    }
  1451. X
  1452. X    i = 0;
  1453. X    while ((dp = readdir(dirp)) != NULL) {
  1454. X      if (i == icon_list_max_size) {
  1455. X    icon_list_max_size += LISTINCR;
  1456. X    icon_list = (XedwList**) XtRealloc(icon_list,
  1457. X                       sizeof(XedwList*) * 
  1458. X                       icon_list_max_size);
  1459. X      } else 
  1460. X    if (getIconType(dp->d_name, newpath, &temp)) {
  1461. X      icon_list[i] = XtNew(XedwList);
  1462. X      icon_list[i]->string = temp.string;
  1463. X      icon_list[i]->icon   = temp.icon;
  1464. X      i++;
  1465. X    }
  1466. X    }
  1467. X    icon_list[i] = NULL;
  1468. X    icon_list_size = i;
  1469. X    qsort((char*)icon_list, icon_list_size, sizeof(icon_list[0]), iconcmp);
  1470. X    XedwListChange(directoryManager, icon_list, icon_list_size, 0, True);
  1471. X    setscroll(directoryManagerView, 0.0);
  1472. X    closedir(dirp);
  1473. X    result = True;
  1474. X    /* Change entry in the directory selector */
  1475. X    XtSetArg(args[0], XtNstring, newpath); 
  1476. X    XtSetValues(dirSelector, args, 1);
  1477. X    /* reset cursor */
  1478. X    setCursor(NULL);
  1479. X  } else XBell(XtDisplay(directoryManager), 100);
  1480. X  return(result);
  1481. X}
  1482. X
  1483. X
  1484. Xprivate int iconcmp(XedwList **ip1, XedwList **ip2)
  1485. X{
  1486. X  /* compare the strings of 2 XedwList's */
  1487. X
  1488. X  return (strcmp(getfilename((*ip1)->string), 
  1489. X         getfilename((*ip2)->string)));
  1490. X}
  1491. X
  1492. Xpublic void initDirectoryManager(void)
  1493. X{
  1494. X  extern Boolean buttonSensitive;
  1495. X  extern Widget menuBar;
  1496. X  char tmpcwd[MAXPATHLEN];
  1497. X
  1498. X  /* Initialise the icon list */
  1499. X  icon_list = (XedwList**) XtMalloc(sizeof(XedwList*) * LISTSIZE);
  1500. X
  1501. X  /* Set the starting directory */
  1502. X  if (getwd(tmpcwd) != NULL) 
  1503. X    cwd = XtNewString(tmpcwd);
  1504. X  else
  1505. X    if ((cwd = (char*) getenv("HOME")) == NULL) 
  1506. X      cwd = XtNewString("/");
  1507. X    else
  1508. X      cwd = XtNewString(cwd);
  1509. X
  1510. X  /* Get the id's of the menu widgets which are to be toggled with the
  1511. X   * buttons. Note: This relies on the menus being created first, which
  1512. X   * they are.
  1513. X   */
  1514. X  if ((duplicatemenu = 
  1515. X       XtNameToWidget(menuBar, "fileMenuButton.fileMenu.duplicate")) == NULL) {
  1516. X    fprintf(stderr, "Directorymanager: Can't find duplicate menu widget\n");
  1517. X    exit(2);
  1518. X  }
  1519. X  if ((getinfomenu = 
  1520. X       XtNameToWidget(menuBar, "fileMenuButton.fileMenu.getinfo")) == NULL) {
  1521. X    fprintf(stderr, "Directorymanager: Can't find getinfo menu widget\n");
  1522. X    exit(2);
  1523. X  }
  1524. X  if ((trashmenu   = 
  1525. X       XtNameToWidget(menuBar, "fileMenuButton.fileMenu.trash")) == NULL) {
  1526. X    fprintf(stderr, "Directorymanager: Can't find trash menu widget\n");
  1527. X    exit(2);
  1528. X  }
  1529. X  if ((copymenu    = 
  1530. X       XtNameToWidget(menuBar, "fileMenuButton.fileMenu.copy")) == NULL) {
  1531. X    fprintf(stderr, "Directorymanager: Can't find copy menu widget\n");
  1532. X    exit(2);
  1533. X  }
  1534. X  if ((movemenu    = 
  1535. X       XtNameToWidget(menuBar, "fileMenuButton.fileMenu.move")) == NULL) {
  1536. X    fprintf(stderr, "Directorymanager: Can't find move menu widget\n");
  1537. X    exit(2);
  1538. X  }
  1539. X  if ((mapmenu     = 
  1540. X       XtNameToWidget(menuBar, "optionMenuButton.optionMenu.map")) == NULL) {
  1541. X    fprintf(stderr, "Directorymanager: Can't find map menu widget\n");
  1542. X    exit(2);
  1543. X  }
  1544. X  (void) directoryManagerNewDirectory(cwd);
  1545. X  buttonSensitive = True;
  1546. X  changestate(False);        /* Insure that menus are insensitive */
  1547. X}
  1548. X
  1549. Xpublic void selection_made(Widget w, caddr_t client_data, caddr_t call_data)
  1550. X{
  1551. X  /* Someone has either selected or deselected an item.
  1552. X   * If there's nothing selected then buttons are changed to 
  1553. X   * not sensitive.
  1554. X   */
  1555. X
  1556. X  extern Boolean buttonSensitive;
  1557. X  extern Widget trashButton, copyButton, moveButton;
  1558. X  Arg arglist[1];
  1559. X  Cardinal i;
  1560. X
  1561. X
  1562. X  if (XedwListSelection(w) != buttonSensitive)
  1563. X    if (buttonSensitive == False) {
  1564. X      changestate(True);
  1565. X    } else {
  1566. X      changestate(False);
  1567. X    }
  1568. X}
  1569. X
  1570. Xprivate void DoubleClick(Widget w, XButtonEvent *event)
  1571. X{
  1572. X  /* Either Start a program, View a file or change directory.
  1573. X   * executable = try to exec it.
  1574. X   * directory  = try to enter it.
  1575. X   * otherwise offer to view it.
  1576. X   */
  1577. X  extern void query_dialog(String, Boolean);
  1578. X  extern int execute(String, String, String, Boolean);
  1579. X
  1580. X  extern Boolean buttonSensitive;
  1581. X  extern Widget trashButton, moveButton, copyButton;
  1582. X
  1583. X  struct stat filestatus;
  1584. X  String fullname, filename, temp;
  1585. X  XedwListReturnStruct *highlighted;
  1586. X  Arg arglist[1];
  1587. X  Cardinal i;
  1588. X
  1589. X  selection_made(w, (caddr_t)0, (caddr_t)0);
  1590. X  highlighted = XedwListShowCurrent(w);
  1591. X
  1592. X  if (highlighted->xedwList_index != XDTM_LIST_NONE) {
  1593. X    filename = getfilename(highlighted->string);
  1594. X    fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+1) * sizeof(char));
  1595. X    strcpy(fullname, cwd);
  1596. X    if (strcmp(cwd, "/") != 0)
  1597. X      strcat(fullname, "/");
  1598. X    strcat(fullname, filename);
  1599. X    if (stat(fullname, &filestatus) == -1) {
  1600. X      fprintf(stderr,"xdtm: ARRRGGHHH stat error\n");
  1601. X    } else {
  1602. X      if ((filestatus.st_mode & S_IFMT) == S_IFDIR) {
  1603. X    if (strcmp(filename, "..") == 0) {
  1604. X      strcpy(fullname, cwd);
  1605. X      if ((temp = (char*) strrchr(fullname, '/')) == NULL) 
  1606. X        fprintf(stderr, "xdtm: impossible error\n");
  1607. X      if (temp == fullname)
  1608. X        *(temp+1) = '\0';
  1609. X      else
  1610. X        *temp = '\0';
  1611. X    }  
  1612. X    if (strcmp(filename, ".") == 0) {
  1613. X      XtFree(fullname);
  1614. X      fullname=XtNewString(cwd);
  1615. X    }
  1616. X    if (directoryManagerNewDirectory(fullname) == True) {
  1617. X      XtFree(cwd);
  1618. X      cwd=fullname;
  1619. X      changestate(False);
  1620. X    } else XBell(XtDisplay(w), 100);
  1621. X      } else {
  1622. X    /* Not a directory, is it executable */
  1623. X    if ((filestatus.st_mode & S_IXUSR) != 0 ||
  1624. X        (filestatus.st_mode & S_IXGRP) != 0 ||
  1625. X        (filestatus.st_mode & S_IXOTH) != 0) {
  1626. X      extern void setCursor(Cursor);
  1627. X      extern Cursor busy;
  1628. X
  1629. X      setCursor(busy);
  1630. X      execute(fullname, filename, filename, False);
  1631. X      setCursor(NULL);
  1632. X    } else
  1633. X      if ((filestatus.st_mode & S_IFMT) == S_IFREG) {
  1634. X        /* Display dialog box to ask whether to display file */
  1635. X        query_dialog(fullname, True);
  1636. X      } else XBell(XtDisplay(w), 100);
  1637. X    XtFree(fullname);
  1638. X      }
  1639. X    }
  1640. X    XtFree(highlighted);
  1641. X  }
  1642. X}
  1643. X
  1644. Xprivate void GoUp(Widget w, XButtonEvent *event)
  1645. X{
  1646. X  Cardinal i;
  1647. X  /* Find entry with .. */
  1648. X  for (i=0; i < icon_list_size && 
  1649. X       (strcmp(getfilename(icon_list[i]->string), "..") != 0); i++); 
  1650. X
  1651. X  XedwListUnhighlight(w, XedwAll);
  1652. X  /* Call XedwListHighlight with item number */
  1653. X  XedwListHighlight(w, i);
  1654. X
  1655. X  /* Call double click */
  1656. X
  1657. X  DoubleClick(w, (XButtonEvent*) NULL);
  1658. X
  1659. X}
  1660. X
  1661. Xprivate void SelectAll(Widget w, XButtonEvent *event)
  1662. SHAR_EOF
  1663. echo "End of part 1"
  1664. echo "File code/dirman.c is continued in part 2"
  1665. echo "2" > s2_seq_.tmp
  1666. exit 0
  1667.