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

  1. From: eddyg@syma.sussex.ac.uk (Edward J. Groenendaal)
  2. Newsgroups: alt.sources
  3. Subject: X Desktop Manager
  4. Message-ID: <4866@syma.sussex.ac.uk>
  5. Date: 17 Apr 91 20:49:06 GMT
  6.  
  7. ---- Cut Here and unpack ----
  8. #!/bin/sh
  9. # this is part 3 of a multipart archive
  10. # do not concatenate these parts, unpack them in order with /bin/sh
  11. # file code/map.c continued
  12. #
  13. CurArch=3
  14. if test ! -r s2_seq_.tmp
  15. then echo "Please unpack part 1 first!"
  16.      exit 1; fi
  17. ( read Scheck
  18.   if test "$Scheck" != $CurArch
  19.   then echo "Please unpack part $Scheck next!"
  20.        exit 1;
  21.   else exit 0; fi
  22. ) < s2_seq_.tmp || exit 1
  23. echo "x - Continuing file code/map.c"
  24. sed 's/^X//' << 'SHAR_EOF' >> code/map.c
  25. X#include <X11/Shell.h>
  26. X#include <X11/Xaw/Label.h>
  27. X#include <X11/Xaw/Command.h>
  28. X#include <X11/Xaw/AsciiText.h>
  29. X#include "Xedw/XedwForm.h"
  30. X#include "Xedw/XedwList.h"
  31. X
  32. Xextern void realize_dialog(Widget);
  33. X
  34. X/* Widgets */
  35. X
  36. Xprivate Widget mappopup;        /* For mapping prog over files */
  37. Xprivate Widget mapform;
  38. Xprivate Widget maplabel;
  39. Xprivate Widget mappromptlabel;
  40. Xprivate Widget maptext;
  41. Xprivate Widget mapCancel;
  42. Xprivate Widget mapOK;
  43. X
  44. Xpublic void init_map(Widget top)
  45. X{
  46. X  Arg arglist[5];
  47. X  Cardinal i;
  48. X  XtTranslations mapTranslations;
  49. X
  50. X  static char defaultTranslations[] = 
  51. X    "Ctrl<Key>A:        beginning-of-line() \n\
  52. X     Ctrl<Key>E:        end-of-line() \n\
  53. X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
  54. X     <Key>Right:     forward-character() \n\
  55. X     <Key>Left:         backward-character() \n\
  56. X     <Key>Delete:       delete-previous-character() \n\
  57. X     <Key>BackSpace:    delete-previous-character() \n\
  58. X     <Key>:             insert-char() \n\
  59. X     <FocusIn>:         focus-in() \n\
  60. X     <FocusOut>:        focus-out() \n\
  61. X     <BtnDown>:         select-start()";
  62. X
  63. X
  64. X  mappopup       = XtCreatePopupShell("mappopup",
  65. X                      transientShellWidgetClass,
  66. X                      top,
  67. X                      NULL, 0);
  68. X
  69. X  mapform        = XtCreateManagedWidget("mapform",
  70. X                     xedwFormWidgetClass,
  71. X                     mappopup,
  72. X                     NULL, 0);
  73. X
  74. X  i = 0;
  75. X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
  76. X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
  77. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  78. X  maplabel       = XtCreateManagedWidget("maplabel",
  79. X                     labelWidgetClass,
  80. X                     mapform,
  81. X                     arglist, i);
  82. X
  83. X  i = 1;
  84. X  XtSetArg(arglist[i], XtNfromVert, maplabel); i++;
  85. X  mappromptlabel = XtCreateManagedWidget("mappromptlabel",
  86. X                     labelWidgetClass,
  87. X                     mapform,
  88. X                     arglist, i);
  89. X  
  90. X  i = 2;
  91. X  XtSetArg(arglist[i], XtNfromHoriz, mappromptlabel); i++;
  92. X  XtSetArg(arglist[i], XtNfullWidth,           True); i++;
  93. X  XtSetArg(arglist[i], XtNeditType,     XawtextEdit); i++;
  94. X  maptext        = XtCreateManagedWidget("maptext",
  95. X                     asciiTextWidgetClass,
  96. X                     mapform,
  97. X                     arglist, i);
  98. X  
  99. X  i = 0;
  100. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  101. X  XtSetArg(arglist[i], XtNfromVert,        maptext); i++;
  102. X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
  103. X  mapCancel      = XtCreateManagedWidget("mapCancel",
  104. X                     commandWidgetClass,
  105. X                     mapform,
  106. X                     arglist, i);
  107. X
  108. X  i = 2;
  109. X  XtSetArg(arglist[i], XtNfromHoriz,   mapCancel); i++;
  110. X  XtSetArg(arglist[i], XtNwidthLinked, mapCancel); i++;
  111. X  XtSetArg(arglist[i], XtNlabel,            "OK"); i++;
  112. X  mapOK          = XtCreateManagedWidget("mapOK",
  113. X                     commandWidgetClass,
  114. X                     mapform,
  115. X                     arglist, i);
  116. X
  117. X
  118. X  XtUninstallTranslations(maptext);
  119. X  mapTranslations = XtParseTranslationTable(defaultTranslations);
  120. X  XtOverrideTranslations(maptext, mapTranslations);
  121. X
  122. X}
  123. X
  124. Xpublic void map_dialog(Boolean map)
  125. X{
  126. X  /* if map is true then put map dialog up, otherwise use the 
  127. X   * select dialog.
  128. X   */
  129. X  private void mapQueryResult(Widget, Boolean, caddr_t);
  130. X  private void selectQueryResult(Widget, Boolean, caddr_t);
  131. X  Arg arglist[1];
  132. X
  133. X  XtSetArg(arglist[0], XtNstring, "");
  134. X  XtSetValues(maptext, arglist, 1);
  135. X
  136. X  if (map == True) {
  137. X    XtSetArg(arglist[0], XtNlabel, " Map Program over Selected Files ");
  138. X    XtSetValues(maplabel, arglist, 1);
  139. X
  140. X    XtSetArg(arglist[0], XtNlabel, "Program:");
  141. X    XtSetValues(mappromptlabel, arglist, 1);
  142. X
  143. X    XtAddCallback(mapCancel, XtNcallback, mapQueryResult, False);
  144. X    XtAddCallback(mapOK,     XtNcallback, mapQueryResult, True);
  145. X  } else {
  146. X    XtSetArg(arglist[0], XtNlabel, "Select Files by Regular Expression"); 
  147. X    XtSetValues(maplabel, arglist, 1);
  148. X
  149. X    XtSetArg(arglist[0], XtNlabel, "RegExp: ");
  150. X    XtSetValues(mappromptlabel, arglist, 1);
  151. X
  152. X    XtAddCallback(mapCancel, XtNcallback, selectQueryResult, False);
  153. X    XtAddCallback(mapOK,     XtNcallback, selectQueryResult, True);
  154. X  }
  155. X
  156. X  realize_dialog(mappopup);
  157. X}
  158. X
  159. Xprivate void destroy_map_dialog(void)
  160. X{
  161. X  Arg arglist[1];
  162. X
  163. X  XtPopdown(mappopup);
  164. X
  165. X  XtRemoveAllCallbacks(mapCancel, XtNcallback);
  166. X  XtRemoveAllCallbacks(mapOK,     XtNcallback);
  167. X}
  168. X
  169. Xprivate void mapQueryResult(Widget w, Boolean ok, caddr_t call_data)
  170. X{
  171. X  extern String build_arguments(String, SelOptions);
  172. X  extern int execute(String, String, String, Boolean);
  173. X  extern void setCursor(Cursor);
  174. X  extern Cursor busy;
  175. X  String mapprogram, program, filename;
  176. X  Arg arglist[1];
  177. X
  178. X  destroy_map_dialog();
  179. X
  180. X  if (ok == True) {
  181. X    setCursor(busy);
  182. X    /* get program name from text widget */
  183. X    XtSetArg(arglist[0], XtNstring, &mapprogram);
  184. X    XtGetValues(maptext, arglist, 1);
  185. X
  186. X    program = XtNewString(mapprogram);
  187. X
  188. X    /* extract filename from program */
  189. X    filename = XtNewString(program);
  190. X    filename = strtok(filename, " ");
  191. X    
  192. X    /* Get list of files */
  193. X    program = build_arguments(program, M_SEL);
  194. X
  195. X    execute(NULL, filename, program, False);
  196. X    setCursor(NULL);
  197. X  }
  198. X}
  199. X
  200. Xprivate void selectQueryResult(Widget w, Boolean ok, caddr_t call_data)
  201. X{
  202. X  extern void highlight_by_re(String);
  203. X  extern void setCursor(Cursor);
  204. X  extern Cursor busy;
  205. X  String re;
  206. X  Arg arglist[1];
  207. X
  208. X  destroy_map_dialog();
  209. X
  210. X  if (ok == True) {
  211. X    /* Get regular expression */
  212. X    setCursor(busy);
  213. X    XtSetArg(arglist[0], XtNstring, &re);
  214. X    XtGetValues(maptext, arglist, 1);
  215. X    
  216. X    highlight_by_re(re);
  217. X
  218. X    setCursor(NULL);
  219. X  }
  220. X}
  221. SHAR_EOF
  222. echo "File code/map.c is complete"
  223. chmod 0644 code/map.c || echo "restore of code/map.c fails"
  224. echo "x - extracting code/menus.c (Text)"
  225. sed 's/^X//' << 'SHAR_EOF' > code/menus.c &&
  226. X/*****************************************************************************
  227. X ** File          : menus.c                                                 **
  228. X ** Purpose       : Create, and handle the pull down menus                  **
  229. X ** Author        : Edward Groenendaal                                      **
  230. X ** Date          : 18th Feb 1991                                           **
  231. X ** Documentation : Xdtm Design Folder                                      **
  232. X ** Related Files :                                                         **
  233. X *****************************************************************************/
  234. X
  235. X#include "xdtm.h"
  236. X#include "menus.h"
  237. X#include <sys/stat.h>
  238. X#include <X11/Xaw/MenuButton.h>
  239. X#include <X11/Xaw/SimpleMenu.h>
  240. X#include <X11/Xaw/SmeBSB.h>
  241. X#include <X11/Xaw/SmeLine.h>
  242. X
  243. X#include "Xedw/XedwList.c"
  244. X#include "Xedw/XedwForm.h"
  245. X#include "bitmaps/Tick"
  246. X#include "bitmaps/EmptyTick"
  247. X
  248. Xstatic MenuContents fileMenuStrings[] = {
  249. X  { "about",     "About Xdtm...",  About,     noflag },
  250. X  { "help",      "Help",           Help,      noflag },
  251. X  {  LINE,        NULL,            0,         noflag },
  252. X  { "new",       "New File",       New,       noflag },
  253. X  { "duplicate", "Duplicate File", Duplicate, noflag },
  254. X  {  LINE,        NULL,            0,         noflag },
  255. X  { "getinfo",   "Get Info",       Getinfo,   noflag }, 
  256. X  { "copy",      "Copy files",     Copy,      noflag },
  257. X  { "move",      "Move files",     Move,      noflag },
  258. X  { "trash",     "Delete files",   Trash,     noflag },
  259. X  {  LINE,        NULL,            0,         noflag },
  260. X  { "quit",      "Quit Program",   Quit,      noflag },
  261. X};
  262. X
  263. Xstatic MenuContents optionMenuStrings[] = {
  264. X  { "map",      "Map Program over Files",     Map,    noflag },
  265. X  { "select",   "Select Files by Template",   Select, noflag },
  266. X};
  267. X
  268. Xstatic MenuContents viewMenuStrings[] = {
  269. X  { "icons",    "Show Icons",     Icons,   flagged },
  270. X  { "short",    "No Icons",       Short,   flagged },
  271. X  {  LINE,       NULL,            0,       flagged },
  272. X  { "long",     "Long Listing",   Long,    flagged },
  273. X  { "options",  "Options",        Options, flagged },
  274. X};
  275. X
  276. XCardinal fileMenuSize   = sizeof(fileMenuStrings)   /
  277. X                                sizeof(fileMenuStrings[0]);
  278. XCardinal optionMenuSize = sizeof(optionMenuStrings) /
  279. X                                sizeof(optionMenuStrings[0]);
  280. XCardinal viewMenuSize   = sizeof(viewMenuStrings)   /
  281. X                                sizeof(viewMenuStrings[0]);
  282. X
  283. Xpublic Arg chain_position[] = {  XtNtop,     XtChainTop,
  284. X                 XtNbottom,  XtChainBottom,
  285. X                 XtNleft,    XtChainLeft,
  286. X                 XtNright,   XtChainRight,
  287. X                 NULL,       NULL
  288. X                  };
  289. X
  290. XCardinal chain_size = sizeof(chain_position)/sizeof(chain_position[0]);
  291. X
  292. Xpublic Pixmap tick, emptytick;
  293. Xpublic Widget menuBar;
  294. X
  295. Xpublic Icon_mode current_mode;
  296. X
  297. X
  298. Xpublic void createMenuWidgets(Widget w)
  299. X{
  300. X  private void menuSelect(Widget, Cardinal, caddr_t);
  301. X  public  void createMenu(Widget, MenuContents[], Cardinal, 
  302. X              void (*)(Widget, Cardinal, caddr_t) );
  303. X
  304. X  Widget fileMenuButton, optionMenuButton, viewMenuButton, selectionMenuButton;
  305. X  Widget fileMenu, optionMenu, viewMenu;
  306. X  Arg arglist[5], *newlist;
  307. X  Cardinal i;
  308. X
  309. X  i = 0;
  310. X  XtSetArg(arglist[i], XtNrubberWidth,  False);    i++;
  311. X  XtSetArg(arglist[i], XtNrubberHeight, False);    i++;
  312. X  XtSetArg(arglist[i], XtNborderWidth,      0);    i++;
  313. X  newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
  314. X  menuBar          =   XtCreateManagedWidget("menuBar",
  315. X                         xedwFormWidgetClass,
  316. X                         w,
  317. X                         newlist, i + chain_size);
  318. X  XtFree(newlist);
  319. X
  320. X  i = 0;
  321. X  XtSetArg(arglist[i], XtNhighlightThickness, 0); i++;
  322. X  XtSetArg(arglist[i], XtNborderWidth,        0); i++;
  323. X  XtSetArg(arglist[i], XtNmenuName,  "fileMenu"); i++;
  324. X  XtSetArg(arglist[i], XtNlabel,         "File"); i++;
  325. X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
  326. X  fileMenuButton   =   XtCreateManagedWidget("fileMenuButton",
  327. X                         menuButtonWidgetClass,
  328. X                         menuBar,
  329. X                         arglist, i);
  330. X
  331. X  i = 2;
  332. X  XtSetArg(arglist[i], XtNmenuName,         "optionMenu"); i++;
  333. X  XtSetArg(arglist[i], XtNlabel,               "Options"); i++;
  334. X  XtSetArg(arglist[i], XtNfromHoriz,      fileMenuButton); i++;
  335. X  XtSetArg(arglist[i], XtNvertDistance,                0); i++;
  336. X  optionMenuButton =   XtCreateManagedWidget("optionMenuButton",
  337. X                         menuButtonWidgetClass,
  338. X                         menuBar,
  339. X                         arglist, i);
  340. X
  341. X  i = 2;
  342. X  XtSetArg(arglist[i], XtNmenuName,        "viewMenu"); i++;
  343. X  XtSetArg(arglist[i], XtNlabel,               "View"); i++;
  344. X  XtSetArg(arglist[i], XtNfromHoriz, optionMenuButton); i++;
  345. X  XtSetArg(arglist[i], XtNvertDistance,       0); i++;
  346. X  viewMenuButton   =   XtCreateManagedWidget("viewMenuButton",
  347. X                         menuButtonWidgetClass,
  348. X                         menuBar,
  349. X                         arglist, i);
  350. X
  351. X  fileMenu         =   XtCreatePopupShell("fileMenu",
  352. X                      simpleMenuWidgetClass,
  353. X                      fileMenuButton,
  354. X                      NULL, 0);
  355. X  
  356. X  optionMenu       =   XtCreatePopupShell("optionMenu",
  357. X                      simpleMenuWidgetClass,
  358. X                      optionMenuButton,
  359. X                      NULL, 0);
  360. X  
  361. X  viewMenu         =   XtCreatePopupShell("viewMenu",
  362. X                      simpleMenuWidgetClass,
  363. X                      viewMenuButton,
  364. X                      NULL, 0);
  365. X
  366. X  tick             =   XCreateBitmapFromData(XtDisplay(w), 
  367. X                         RootWindowOfScreen(XtScreen(w)),
  368. X                         tick_bits, tick_width, 
  369. X                         tick_height);
  370. X
  371. X  emptytick        =   XCreateBitmapFromData(XtDisplay(w), 
  372. X                         RootWindowOfScreen(XtScreen(w)),
  373. X                         EmptyTick_bits, 
  374. X                         EmptyTick_width, 
  375. X                         EmptyTick_height);
  376. X  
  377. X  createMenu(fileMenu, fileMenuStrings, fileMenuSize, menuSelect);
  378. X  
  379. X  createMenu(optionMenu, optionMenuStrings, optionMenuSize, menuSelect);
  380. X  
  381. X  createMenu(viewMenu, viewMenuStrings, viewMenuSize, menuSelect);
  382. X
  383. X  current_mode.options = (PERMS | NLINKS | OWNER | GROUP | SIZE);
  384. X  
  385. X}
  386. X
  387. X
  388. X
  389. Xpublic void createMenu(Widget menu, MenuContents menuStrings[], 
  390. X               Cardinal menuSize, void (*function)())
  391. X{
  392. X  Widget menuEntry;
  393. X  Cardinal i, n;
  394. X  Arg arglist[3];
  395. X
  396. X  for(n=0; n < menuSize; n++) {
  397. X    MenuContents entry = menuStrings[n];
  398. X    String widgetname = entry.paneName;
  399. X    if (!strcmp(LINE, widgetname))
  400. X      menuEntry = XtCreateManagedWidget(widgetname, smeLineObjectClass,
  401. X                    menu, NULL, 0);
  402. X    else {
  403. X      i = 0;
  404. X      XtSetArg(arglist[i], XtNlabel, entry.paneLabel); i++;
  405. X      if (entry.set == flagged) {
  406. X    XtSetArg(arglist[i], XtNleftMargin, (tick_width*1.5)); i++;
  407. X    if (entry.paneNumber == current_mode.mode) {
  408. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++; 
  409. X    } else {
  410. X      XtSetArg(arglist[i], XtNleftBitmap,           None); i++; 
  411. X    }
  412. X      }
  413. X      
  414. X      menuEntry = XtCreateManagedWidget(widgetname, smeBSBObjectClass,
  415. X                    menu, arglist, i);
  416. X      if (entry.paneNumber == current_mode.mode && entry.set == flagged) 
  417. X    current_mode.w = menuEntry;
  418. X
  419. X      XtAddCallback(menuEntry, XtNcallback, function,
  420. X            (caddr_t) entry.paneNumber);
  421. X    }
  422. X  }
  423. X}
  424. X
  425. X
  426. Xprivate void menuSelect(Widget w, Cardinal paneNumber, caddr_t rubbish)
  427. X{
  428. X  extern void map_dialog(Boolean);
  429. X  extern void quit_dialog(void);
  430. X  extern void query_dialog(String, Boolean);
  431. X  extern void displayfile(String);
  432. X  extern void newfile_dialog(Boolean, String, Boolean);
  433. X  extern void button_selected(Widget, Cardinal, caddr_t);
  434. X  extern void listoption_dialog(void);
  435. X  extern Boolean directoryManagerNewDirectory(String);
  436. X  extern String getfilename(String);
  437. X  extern void setCursor(Cursor);
  438. X  extern Cursor busy;
  439. X  extern String cwd;
  440. X  extern Widget directoryManager;
  441. X  XedwListReturnStruct *highlighted;
  442. X  String filename, fullname, level;
  443. X  struct stat filestatus;
  444. X  Arg arglist[6];
  445. X  Cardinal i;
  446. X
  447. X  switch (paneNumber) {
  448. X  case About:
  449. X    level = XtMalloc (sizeof(char) * 25);
  450. X    sprintf(level, "   Xdtm v%d.%d   ", RELEASE, PATCHLEVEL);
  451. X    query_dialog(level, False);
  452. X    break;
  453. X  case Help:
  454. X    if (access(SYSTEM_HELP, R_OK) == 0) 
  455. X      displayfile(SYSTEM_HELP);
  456. X    else
  457. X      query_dialog("Help not found!", False);
  458. X    break;
  459. X
  460. X  case New:
  461. X    newfile_dialog(False, NULL, False);
  462. X    break;
  463. X
  464. X  case Duplicate:
  465. X    /* Find out whether highlighted file is a regular file or a directory */
  466. X    highlighted = XedwListShowCurrent(directoryManager);
  467. X    if (highlighted->xedwList_index != XDTM_LIST_NONE) {
  468. X      if (highlighted->next != NULL) 
  469. X    query_dialog("Only one file!", False);
  470. X      else {
  471. X    filename = getfilename(highlighted->string);
  472. X    fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+1) * sizeof(char));
  473. X    strcpy(fullname, cwd);
  474. X    if (strcmp(cwd, "/") != 0)
  475. X      strcat(fullname, "/");
  476. X    strcat(fullname, filename);
  477. X    if (stat(fullname, &filestatus) == -1) {
  478. X      fprintf(stderr,"xdtm: ARRRGGHHH stat error\n");
  479. X    } else {
  480. X      if ((filestatus.st_mode & S_IFMT) == S_IFDIR) 
  481. X        /* Is a directory */
  482. X        newfile_dialog(True, filename, True);
  483. X      else if ((filestatus.st_mode & S_IFMT) == S_IFREG) 
  484. X        newfile_dialog(True, filename, False);
  485. X      else 
  486. X        query_dialog("Wrong file type!", False);
  487. X    }
  488. X    XtFree(fullname);
  489. X      }
  490. X    } else
  491. X      fprintf(stderr, "Error: Duplicate selected when should have been"
  492. X          " disabled\n");
  493. X    break;
  494. X
  495. X  case Getinfo:
  496. X    query_dialog("Not implemented!", False);
  497. X    break;
  498. X
  499. X  case Copy:
  500. X  case Move:
  501. X  case Trash:
  502. X    /* Call button press with it */
  503. X    button_selected(w, paneNumber, 0);
  504. X    break;
  505. X
  506. X  case Quit:
  507. X    quit_dialog();
  508. X    break;
  509. X
  510. X  case Map:
  511. X    map_dialog(True);
  512. X    break;
  513. X
  514. X  case Select:
  515. X    map_dialog(False);
  516. X    break;
  517. X
  518. X  case Icons:
  519. X    if (current_mode.mode != Icons) {
  520. X      i = 0;
  521. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  522. X      XtSetValues(current_mode.w, arglist, i);
  523. X      i = 0;
  524. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  525. X      XtSetValues(w, arglist, i);
  526. X      current_mode.w = w;
  527. X      current_mode.mode = Icons;
  528. X      XtSetArg(arglist[i], XtNshowIcons,     True); i++;
  529. X      XtSetArg(arglist[i], XtNrowSpacing,      10); i++;
  530. X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
  531. X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
  532. X      XtSetValues(directoryManager, arglist, i);
  533. X      directoryManagerNewDirectory(cwd);
  534. X    } 
  535. X    break;
  536. X
  537. X  case Short:
  538. X    if (current_mode.mode != Short) {
  539. X      i = 0;
  540. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  541. X      XtSetValues(current_mode.w, arglist, i);
  542. X      i = 0;
  543. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  544. X      XtSetValues(w, arglist, i);
  545. X      current_mode.w = w;
  546. X      current_mode.mode = Short;
  547. X      i = 0;
  548. X      XtSetArg(arglist[i], XtNshowIcons,    False); i++;
  549. X      XtSetArg(arglist[i], XtNrowSpacing,       5); i++;
  550. X      XtSetArg(arglist[i], XtNforceColumns, False); i++;
  551. X      XtSetArg(arglist[i], XtNdefaultColumns,   2); i++;
  552. X      XtSetValues(directoryManager, arglist, i);
  553. X      directoryManagerNewDirectory(cwd);    /* To be consistent */
  554. X    } 
  555. X    break;
  556. X
  557. X  case Long:
  558. X    if (current_mode.mode != Long) {
  559. X      i = 0;
  560. X      XtSetArg(arglist[i], XtNleftBitmap, None); i++;
  561. X      XtSetValues(current_mode.w, arglist, i);
  562. X      i = 0;
  563. X      XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
  564. X      XtSetValues(w, arglist, i);
  565. X      current_mode.w = w;
  566. X      current_mode.mode = Long;
  567. X      i = 0;
  568. X      XtSetArg(arglist[i], XtNshowIcons,   False); i++;
  569. X      XtSetArg(arglist[i], XtNrowSpacing,      5); i++;
  570. X      XtSetArg(arglist[i], XtNforceColumns, True); i++;
  571. X      XtSetArg(arglist[i], XtNdefaultColumns,  1); i++;
  572. X      XtSetValues(directoryManager, arglist, i);
  573. X      directoryManagerNewDirectory(cwd);       /* To be consistent */
  574. X    }
  575. X    break;
  576. X
  577. X  case Options:
  578. X    listoption_dialog();
  579. X    break;
  580. X
  581. X  default:
  582. X    fprintf(stderr, "Menu option number %d not supported\n", paneNumber);
  583. X    break;
  584. X  }
  585. X    
  586. X  
  587. X}
  588. X
  589. SHAR_EOF
  590. chmod 0644 code/menus.c || echo "restore of code/menus.c fails"
  591. echo "x - extracting code/menus.h (Text)"
  592. sed 's/^X//' << 'SHAR_EOF' > code/menus.h &&
  593. X/***********************************************************************************
  594. X ** File          : menus.h                                                       **
  595. X ** Purpose       :                                                               **
  596. X ** Author        : Edward Groenendaal                                            **
  597. X ** Date          : 18th Feb 1990                                                 **
  598. X ** Documentation : Xedw Design Folder                                            **
  599. X ** Related Files : menus.c                                                       **
  600. X ***********************************************************************************/
  601. X
  602. X#ifndef _EG_menus_h
  603. X#define _EG_menus_h
  604. X
  605. X#include <X11/Intrinsic.h>
  606. X
  607. X#define LINE    "line"
  608. X
  609. X#define PERMS   (1 << 1)
  610. X#define NLINKS  (1 << 2)
  611. X#define OWNER   (1 << 3)
  612. X#define GROUP   (1 << 4)
  613. X#define SIZE    (1 << 5)
  614. X#define MODTM   (1 << 6)
  615. X#define ACCTM   (1 << 7)
  616. X
  617. Xtypedef enum {flagged, noflag} Flags;
  618. X
  619. Xtypedef enum {
  620. X  About,
  621. X  Help,
  622. X  New,
  623. X  Duplicate,
  624. X  Getinfo,
  625. X  Copy,
  626. X  Move,
  627. X  Trash,
  628. X  Quit,
  629. X  Map,
  630. X  Select,
  631. X  Icons,
  632. X  Short,
  633. X  Long,
  634. X  Options
  635. X} MenuValue;
  636. X
  637. Xtypedef struct {
  638. X  String paneName;
  639. X  String paneLabel;
  640. X  MenuValue paneNumber;
  641. X  Flags set;
  642. X} MenuContents;
  643. X
  644. Xtypedef struct {
  645. X  Widget w;
  646. X  MenuValue mode;
  647. X  /* long listing options */
  648. X  Cardinal length;
  649. X  char options;
  650. X} Icon_mode;
  651. X
  652. Xextern Widget menuBar;
  653. Xextern Icon_mode current_mode;
  654. Xextern Pixmap tick;
  655. Xextern Pixmap emptytick;
  656. X
  657. X#endif /* _EG_menus_h */
  658. SHAR_EOF
  659. chmod 0644 code/menus.h || echo "restore of code/menus.h fails"
  660. echo "x - extracting code/newfile.c (Text)"
  661. sed 's/^X//' << 'SHAR_EOF' > code/newfile.c &&
  662. X/*****************************************************************************
  663. X ** File          : newfile.c                                               **
  664. X ** Purpose       : Initialise and Realise newfile dialog                   **
  665. X ** Author        : Edward Groenendaal                                      **
  666. X ** Date          : April 1991                                              **
  667. X ** Documentation : Xdtm Design Folder                                      **
  668. X ** Related Files :                                                         **
  669. X *****************************************************************************/
  670. X
  671. X#include "xdtm.h"
  672. X
  673. X#include <X11/Shell.h>
  674. X#include <X11/Xaw/Label.h>
  675. X#include <X11/Xaw/Command.h>
  676. X#include <X11/Xaw/AsciiText.h>
  677. X#include "Xedw/XedwForm.h"
  678. X
  679. Xextern void realize_dialog(Widget);
  680. X
  681. X/* Widgets */
  682. X
  683. Xprivate Widget newfilepopup;
  684. Xprivate Widget newfileform;
  685. Xprivate Widget newfilelabel;
  686. Xprivate Widget newfiletext;
  687. Xprivate Widget newfilefile;
  688. Xprivate Widget newfiledir;
  689. Xprivate Widget newfilecancel;
  690. X
  691. Xtypedef struct {
  692. X  String filename;
  693. X  Boolean isdir;
  694. X} Filetype;
  695. X
  696. Xpublic void init_newfile(Widget top)
  697. X{
  698. X  /* Create Widgets for newfile dialog */
  699. X  private void destroy_newfile_dialog(Widget, caddr_t, caddr_t);
  700. X
  701. X  Arg arglist[5];
  702. X  Cardinal i;
  703. X  XtTranslations newfileTranslations;
  704. X
  705. X  static char defaultTranslations[] = 
  706. X    "Ctrl<Key>A:        beginning-of-line() \n\
  707. X     Ctrl<Key>E:        end-of-line() \n\
  708. X     <Key>Escape:       beginning-of-line() kill-to-end-of-line() \n\
  709. X     <Key>Right:     forward-character() \n\
  710. X     <Key>Left:         backward-character() \n\
  711. X     <Key>Delete:       delete-previous-character() \n\
  712. X     <Key>BackSpace:    delete-previous-character() \n\
  713. X     <Key>:             insert-char() \n\
  714. X     <FocusIn>:         focus-in() \n\
  715. X     <FocusOut>:        focus-out() \n\
  716. X     <BtnDown>:         select-start()";
  717. X    
  718. X
  719. X  newfilepopup  = XtCreatePopupShell("newfilepopup",
  720. X                     transientShellWidgetClass,
  721. X                     top,
  722. X                     NULL, 0);
  723. X
  724. X  newfileform   = XtCreateManagedWidget("newfileform",
  725. X                    xedwFormWidgetClass,
  726. X                    newfilepopup,
  727. X                    NULL, 0);
  728. X
  729. X  /* label widget to prompt for new filename */
  730. X
  731. X  i = 0;
  732. X  XtSetArg(arglist[i], XtNfullWidth,          True); i++;
  733. X  XtSetArg(arglist[i], XtNborderWidth,           0); i++;
  734. X  XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
  735. X  newfilelabel  = XtCreateManagedWidget("newfilelabel",
  736. X                    labelWidgetClass,
  737. X                    newfileform,
  738. X                    arglist, i);
  739. X  
  740. X  /* new filename text input widget */
  741. X
  742. X  i = 1;
  743. X  XtSetArg(arglist[i], XtNfromVert, newfilelabel); i++;
  744. X  XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
  745. X  newfiletext   = XtCreateManagedWidget("newfiletext",
  746. X                    asciiTextWidgetClass,
  747. X                    newfileform,
  748. X                    arglist, i);
  749. X
  750. X  i = 0;
  751. X  XtSetArg(arglist[i], XtNfromVert, newfiletext); i++;
  752. X  XtSetArg(arglist[i], XtNlabel,    "Directory"); i++;
  753. X  newfiledir    = XtCreateManagedWidget("newfiledir",
  754. X                    commandWidgetClass,
  755. X                    newfileform,
  756. X                    arglist, i);
  757. X  i = 1;
  758. X  XtSetArg(arglist[i], XtNfromHoriz,   newfiledir); i++;
  759. X  XtSetArg(arglist[i], XtNwidthLinked, newfiledir); i++;
  760. X  XtSetArg(arglist[i], XtNlabel,           "File"); i++;
  761. X  newfilefile   = XtCreateManagedWidget("newfilefile",
  762. X                    commandWidgetClass,
  763. X                    newfileform,
  764. X                    arglist, i);
  765. X
  766. X  i = 1;
  767. X  XtSetArg(arglist[i], XtNfromHoriz,   newfilefile); i++;
  768. X  XtSetArg(arglist[i], XtNwidthLinked, newfilefile); i++;
  769. X  XtSetArg(arglist[i], XtNlabel,          "Cancel"); i++;
  770. X  newfilecancel = XtCreateManagedWidget("newfilecancel",
  771. X                    commandWidgetClass,
  772. X                    newfileform,
  773. X                    arglist, i);
  774. X
  775. X  /* Add callbacks for buttons */
  776. X  XtAddCallback(newfilecancel, XtNcallback,  destroy_newfile_dialog, 0); 
  777. X
  778. X  /* Do the translations on the text widget */
  779. X  XtUninstallTranslations(newfiletext);
  780. X  newfileTranslations = XtParseTranslationTable(defaultTranslations);
  781. X  XtOverrideTranslations(newfiletext, newfileTranslations);
  782. X}
  783. X
  784. Xpublic void newfile_dialog(Boolean rename, String newname, Boolean isdir)
  785. X{
  786. X  /* Popup the newfile dialog on screen with the correct data */
  787. X  private void newfileQueryReturn(Widget, Boolean, caddr_t);
  788. X  private void duplicateQueryReturn(Widget, Filetype*, caddr_t);
  789. X  Arg arglist[1];
  790. X  String filename;
  791. X  Filetype *filetype;
  792. X
  793. X  static String defaultfilename = "untitled";
  794. X
  795. X  filetype = (Filetype*) XtMalloc (sizeof(Filetype));
  796. X
  797. X  if (newname == NULL) 
  798. X    filename = defaultfilename;
  799. X  else
  800. X    filename = newname;
  801. X
  802. X  if (rename == False) {
  803. X    /* Create a new file */
  804. X
  805. X    XtSetArg(arglist[0], XtNlabel, "Create a new file"); 
  806. X    XtSetValues(newfilelabel, arglist, 1);
  807. X
  808. X    XtSetArg(arglist[0], XtNstring, filename);
  809. X    XtSetValues(newfiletext, arglist, 1);
  810. X
  811. X    /* Add callbacks for buttons */
  812. X    XtAddCallback(newfiledir,    XtNcallback,  newfileQueryReturn,  True);
  813. X    XtAddCallback(newfilefile,   XtNcallback,  newfileQueryReturn, False);
  814. X  } else {
  815. X    /* rename an existing file */
  816. X    filetype->filename = filename;
  817. X    filetype->isdir    = isdir;
  818. X
  819. X    XtSetArg(arglist[0], XtNlabel, "Duplicate file"); 
  820. X    XtSetValues(newfilelabel, arglist, 1);
  821. X
  822. X    XtSetArg(arglist[0], XtNstring, filename);
  823. X    XtSetValues(newfiletext, arglist, 1);
  824. X
  825. X    if (isdir == True) 
  826. X      XtSetSensitive(newfilefile, False);
  827. X    else
  828. X      XtSetSensitive(newfiledir, False);
  829. X    XtAddCallback(newfiledir,    XtNcallback,  duplicateQueryReturn,  filetype);
  830. X    XtAddCallback(newfilefile,   XtNcallback,  duplicateQueryReturn,  filetype);
  831. X  }
  832. X
  833. X  realize_dialog(newfilepopup);
  834. X
  835. X}
  836. X
  837. Xprivate void destroy_newfile_dialog(Widget w, caddr_t dummy1, caddr_t dummy2)
  838. X{
  839. X
  840. X  XtPopdown(newfilepopup);
  841. X  
  842. X  XtSetSensitive(newfilefile, True);
  843. X  XtSetSensitive(newfiledir,  True);
  844. X  XtRemoveAllCallbacks(newfilefile, XtNcallback);
  845. X  XtRemoveAllCallbacks(newfiledir,  XtNcallback);
  846. X}
  847. X
  848. Xprivate void newfileQueryReturn(Widget w, Boolean isdir, caddr_t dummy)
  849. X{
  850. X  extern void query_dialog(String, Boolean);
  851. X  extern String cwd;
  852. X  String filename, fullname;
  853. X  Arg arglist[1];
  854. X  int fd;
  855. X  
  856. X  destroy_newfile_dialog(w, 0, 0);
  857. X  
  858. X  XtSetArg(arglist[0], XtNstring, &filename);
  859. X  XtGetValues(newfiletext, arglist, 1);
  860. X
  861. X  fullname = (String) XtMalloc (sizeof(char) * (strlen(cwd) + 
  862. X                        strlen(filename) + 2));
  863. X  sprintf(fullname, "%s/%s", cwd, filename);
  864. X
  865. X  if (isdir == True) {
  866. X    /* Create a directory with the name 'filename' */
  867. X    if ((fd = mkdir(fullname, 0777)) == -1) 
  868. X      query_dialog("Can't create dir", False);
  869. X    else
  870. X      directoryManagerNewDirectory(cwd);
  871. X  } else {
  872. X    /* Create a file with the name 'filename' */
  873. X    if ((fd = creat(fullname, 0666)) == -1) {
  874. X      /* Can't create fullname, maybe should look in errno to see why? */
  875. X      query_dialog("Can't create file", False);
  876. X    } else {
  877. X      close(fd);
  878. X      directoryManagerNewDirectory(cwd);
  879. X    }
  880. X  }
  881. X
  882. X  XtFree(fullname);
  883. X}
  884. X
  885. X
  886. Xprivate void duplicateQueryReturn(Widget w, Filetype *filetype, caddr_t dummy)
  887. X{
  888. X  extern void query_dialog(String, Boolean);
  889. X  extern String cwd;
  890. X  String filename, command;
  891. X  Arg arglist[1];
  892. X  int fd;
  893. X  
  894. X  destroy_newfile_dialog(w, 0, 0);
  895. X  
  896. X  XtSetArg(arglist[0], XtNstring, &filename);
  897. X  XtGetValues(newfiletext, arglist, 1);
  898. X
  899. X  command = XtMalloc (sizeof(char) * (strlen(filetype->filename) + 
  900. X                      strlen(filename) + 20));
  901. X
  902. X  if (filetype->isdir == True) {
  903. X    /* make new directory, copy contents of old one into it */
  904. X    if ((fd = mkdir(filename, 0777)) == -1) 
  905. X      query_dialog("Can't create dir", False);
  906. X    sprintf(command, "sh -c 'cp -r \"%s\"/ \"%s\"'", filetype->filename, 
  907. X        filename);
  908. X
  909. X    if (execute(NULL, "sh", command, True) != 0) 
  910. X      query_dialog("Can't copy files!", False);
  911. X    else
  912. X      directoryManagerNewDirectory(cwd);
  913. X  } else {
  914. X    sprintf(command, "cp '%s' '%s'", filetype->filename, filename);
  915. X
  916. X    if (execute(NULL, "cp", command, True) != 0) 
  917. X      query_dialog("Can't create file!", False);
  918. X    else
  919. X      directoryManagerNewDirectory(cwd);
  920. X  }
  921. X
  922. X  XtFree(command);
  923. X}
  924. SHAR_EOF
  925. chmod 0644 code/newfile.c || echo "restore of code/newfile.c fails"
  926. echo "x - extracting code/parse.c (Text)"
  927. sed 's/^X//' << 'SHAR_EOF' > code/parse.c &&
  928. X/*****************************************************************************
  929. X ** File          : parse.c                                                 **
  930. X ** Purpose       : Parse setup file, select icon to be used.               **
  931. X ** Author        : Edward Groenendaal                                      **
  932. X ** Date          : 19th Feb 1990                                           **
  933. X ** Documentation : Xdtm Design Folder                                      **
  934. X ** Related Files :                                                         **
  935. X *****************************************************************************/
  936. X
  937. X#include "xdtm.h"
  938. X
  939. X#include <sys/types.h>
  940. X#include <sys/stat.h>
  941. X#include <sys/param.h>
  942. X#include <sys/file.h>
  943. X#include <pwd.h>
  944. X#include <grp.h>
  945. X#include "parse.h"
  946. X#include "menus.h"
  947. X
  948. X#include "Xedw/XedwList.h"
  949. X
  950. X#include "bitmaps/Grey.Mask"
  951. X#include "bitmaps/folder.icon"
  952. X#include "bitmaps/file.icon"
  953. X
  954. Xtypedef struct _BTree {
  955. X  Pixmap icon;
  956. X  Pixmap grey;
  957. X  struct _BTree *left;
  958. X  struct _BTree *right;
  959. X} BTree;
  960. X
  961. Xextern FILE *yyin;
  962. Xextern int step(char*, char*);
  963. Xextern int circf;
  964. Xextern typePrefs *prefs ;
  965. X
  966. Xpublic uid_t user;
  967. Xpublic uid_t group;
  968. Xprivate BTree *grey_tree;
  969. X
  970. Xprivate Pixmap applyprefs(typePrefs*, String, String, struct stat*);
  971. Xprivate Pixmap do_iconprefs(iconPrefs*, String, String, struct stat*);
  972. X
  973. Xpublic GC xdtmgc;
  974. Xpublic Pixmap foldericon, fileicon, grey_mask; /* default icons */
  975. X
  976. Xpublic Boolean getIconType(String filename, String path, XedwList *element)
  977. X{
  978. X  /* Return True if file should be displayed, otherwise False.
  979. X   * If long listing is on, element should be DUMMY, and this
  980. X   * routine should fill the entries into the icon_list.
  981. X   */
  982. X
  983. X  private Pixmap grey_icon(Pixmap);
  984. X
  985. X  extern Icon_mode current_mode;
  986. X  struct stat *filestatus;
  987. X  typePrefs *myprefs = prefs;
  988. X  String fullname;
  989. X  Pixmap icon;
  990. X  
  991. X  element->string = XtNewString(filename);
  992. X
  993. X  if (current_mode.mode != Short) {
  994. X    filestatus = (struct stat*) XtMalloc (sizeof(struct stat));
  995. X    fullname=(String) XtMalloc((strlen(filename)+strlen(path)+1) * sizeof(char));
  996. X    strcpy(fullname, path);
  997. X    strcat(fullname, "/");
  998. X    strcat(fullname, filename);
  999. X    if (lstat(fullname, filestatus) == -1) {
  1000. X      /* maybe a link to a nonexistent file? */
  1001. X      return(False);
  1002. X    } else {
  1003. X      if (current_mode.mode == Icons) {
  1004. X    element->icon = fileicon;
  1005. X    if ((filestatus->st_mode & S_IFMT) == S_IFDIR) /* stat(5) for details */
  1006. X      element->icon = foldericon;
  1007. X      
  1008. X    /* try all rules in prefs */
  1009. X    if ((icon = applyprefs(myprefs, fullname, filename, filestatus)) != NULL) {
  1010. X    
  1011. X      /* If the file is a directory but is not readable AND executable by the user
  1012. X       * then grey it. If the file is not readable then grey it.
  1013. X       */
  1014. X    
  1015. X      /* if not readable then grey it */
  1016. X      if (icon != DUMMY) 
  1017. X        if (!(((filestatus->st_mode & S_IRUSR) != 0 &&
  1018. X           user == filestatus->st_uid)           ||
  1019. X          ((filestatus->st_mode & S_IRGRP) != 0 &&
  1020. X           group == filestatus->st_gid)          ||
  1021. X          ((filestatus->st_mode & S_IROTH) != 0))) {
  1022. X          icon = grey_icon(icon);
  1023. X        } else {
  1024. X          if ((filestatus->st_mode & S_IFMT) == S_IFDIR) 
  1025. X        if (!(((filestatus->st_mode & S_IXUSR) != 0 &&
  1026. X               user == filestatus->st_uid)           ||
  1027. X              ((filestatus->st_mode & S_IXGRP) != 0 &&
  1028. X               group == filestatus->st_gid)          ||
  1029. X              ((filestatus->st_mode & S_IXOTH) != 0))) {
  1030. X          icon = grey_icon(icon);
  1031. X        } 
  1032. X        }
  1033. X      element->icon = icon;
  1034. X    }
  1035. X      } else {
  1036. X    /* Long Listing */
  1037. X    Cardinal length;
  1038. X    char cm = current_mode.options;
  1039. X    String output_line = "";
  1040. X
  1041. X    element->icon = NULL;
  1042. X    length = 0;
  1043. X    if (cm & PERMS) {
  1044. X      char type;
  1045. X      char xusr, xgrp, xoth;
  1046. X      unsigned short mode = (filestatus->st_mode);
  1047. X
  1048. X      output_line = (String) XtMalloc (sizeof(char) * 12);
  1049. X
  1050. X      /* I could use the S_IS* macros here but I prefer to see what's
  1051. X       * going on.
  1052. X       */
  1053. X      if ((mode & S_IFMT) == S_IFDIR) type = 'd';      /* Directory */
  1054. X      else if ((mode & S_IFMT) == S_IFBLK) type = 'b'; /* Block device */
  1055. X      else if ((mode & S_IFMT) == S_IFCHR) type = 'c'; /* Character device */
  1056. X      else if ((mode & S_IFMT) == S_IFREG) type = ' '; /* Plain file */
  1057. X      else if ((mode & S_IFMT) == S_IFIFO) type = 'f'; /* Fifo */
  1058. X      else if ((mode & S_IFMT) == S_IFLNK) type = 'l'; /* Symbolic link */
  1059. X      else if ((mode & S_IFMT) == S_IFSOCK) type = 's'; /* Socket */
  1060. X      else type = '?';
  1061. X      
  1062. X      if (mode & S_ISUID)     /* Set User Id */
  1063. X        xusr = 's';
  1064. X      else if (mode & S_IXUSR)
  1065. X        xusr = 'x';
  1066. X      else 
  1067. X        xusr = '-';
  1068. X
  1069. X      if (mode & S_ISGID)    /* Set Group Id */
  1070. X        xgrp = 's';
  1071. X      else if (mode & S_IXGRP)
  1072. X        xgrp = 'x';
  1073. X      else
  1074. X        xgrp = '-';
  1075. X
  1076. X      if (mode & S_ISVTX)    /* Save Text */
  1077. X        xoth = 't';
  1078. X      else if (mode & S_IXOTH)
  1079. X        xoth = 'x';
  1080. X      else 
  1081. X        xoth = '-';
  1082. X
  1083. X      sprintf(output_line, 
  1084. X          "%c%c%c%c%c%c%c%c%c%c ",
  1085. X          type,
  1086. X          (mode & S_IRUSR) ? 'r' : '-',
  1087. X          (mode & S_IWUSR) ? 'w' : '-',
  1088. X          xusr,
  1089. X          (mode & S_IRGRP) ? 'r' : '-',
  1090. X          (mode & S_IWGRP) ? 'w' : '-',
  1091. X          xgrp,
  1092. X          (mode & S_IROTH) ? 'r' : '-',
  1093. X          (mode & S_IWOTH) ? 'w' : '-',
  1094. X          xoth);
  1095. X    }
  1096. X
  1097. X    if (cm & NLINKS) {
  1098. X      output_line = XtRealloc (output_line, 
  1099. X                   sizeof(char) *
  1100. X                   (strlen(output_line) + 3 + 2));
  1101. X      
  1102. X      sprintf(output_line, "%s%3d ", output_line, 
  1103. X          filestatus->st_nlink);
  1104. X    }
  1105. X    if (cm & OWNER) {
  1106. X      struct passwd *pw;
  1107. X
  1108. X      output_line = XtRealloc (output_line,
  1109. X                   sizeof(char) *
  1110. X                  (strlen(output_line) + 8 + 2));
  1111. X      
  1112. X      if ((pw = getpwuid(filestatus->st_uid)) == NULL)
  1113. X        sprintf(output_line, "%s%-8d ", output_line, filestatus->st_uid);
  1114. X      else
  1115. X        sprintf(output_line, "%s%-8s ", output_line, pw->pw_name);
  1116. X
  1117. X    }
  1118. X    if (cm & GROUP) {
  1119. X      struct group *gr;
  1120. X      
  1121. X      output_line = XtRealloc (output_line,
  1122. X                   sizeof(char) *
  1123. X                  (strlen(output_line) + 8 + 2));
  1124. X      
  1125. X      if ((gr = getgrgid(filestatus->st_gid)) == NULL)
  1126. X        sprintf(output_line, "%s%-8d ", output_line, filestatus->st_gid);
  1127. X      else
  1128. X        sprintf(output_line, "%s%-8s ", output_line, gr->gr_name);
  1129. X
  1130. X    }
  1131. X    if (cm & SIZE)  {
  1132. X      unsigned short mode = (filestatus->st_mode);
  1133. X
  1134. X      output_line = XtRealloc (output_line, 
  1135. X                   sizeof(char) *
  1136. X                  (strlen(output_line) + 9 + 2));
  1137. X      if ((mode & S_IFMT) == S_IFBLK || (mode & S_IFMT) == S_IFCHR)
  1138. X        sprintf(output_line, "%s%5d,%3d ", output_line, 
  1139. X            (filestatus->st_rdev >> 8) & 0377,
  1140. X            (filestatus->st_rdev) & 0377);
  1141. X      else
  1142. X        sprintf(output_line, "%s%9d ", output_line, filestatus->st_size);
  1143. X    }
  1144. X    if (cm & MODTM) {
  1145. X      String time;
  1146. X      output_line = XtRealloc (output_line,
  1147. X                   sizeof(char) *
  1148. X                   (strlen(output_line) + 35 + 2));
  1149. X
  1150. X      time = ctime(&(filestatus->st_mtime));
  1151. X      *(time + (strlen(time) - 1)) = '\0';
  1152. X      sprintf(output_line, "%s%s ", output_line, time);
  1153. X    }
  1154. X    if (cm & ACCTM) {
  1155. X      String time;
  1156. X      output_line = XtRealloc (output_line,
  1157. X                   sizeof(char) *
  1158. X                   (strlen(output_line) + 35 + 2));
  1159. X
  1160. X      time = ctime(&(filestatus->st_atime));
  1161. X      *(time + (strlen(time) - 1)) = '\0';
  1162. X      sprintf(output_line, "%s%s ", output_line, time);
  1163. X    }
  1164. X    current_mode.length = strlen(output_line); /* length of data */
  1165. X    output_line = XtRealloc (output_line,
  1166. X                 sizeof(char) * 
  1167. X                (strlen(output_line) + strlen(filename) + 2));
  1168. X    sprintf(output_line, "%s%s", output_line, filename);
  1169. X    element->string = output_line;
  1170. X      }
  1171. X    }
  1172. X    XtFree(filestatus);
  1173. X    XtFree(fullname);
  1174. X  }
  1175. X
  1176. X  if (element->icon == DUMMY)
  1177. X    return(False);
  1178. X  else
  1179. X    return(True);
  1180. X}
  1181. X
  1182. Xprivate Pixmap applyprefs(typePrefs *tp, String fullname, String filename, 
  1183. X              struct stat *filestatus)
  1184. X{
  1185. X  /* Recursively traverse the prefs structure until a match is found.
  1186. X   * Jump out as soon as a match is found, try special files first */
  1187. X
  1188. X  Pixmap icon = NULL;
  1189. X  
  1190. X  /* Try directories */
  1191. X  if (icon == NULL && 
  1192. X      tp->dir != NULL &&
  1193. X      (filestatus->st_mode & S_IFMT) == S_IFDIR) {
  1194. X    icon = applyprefs(tp->dir, fullname, filename, filestatus);
  1195. X  }
  1196. X
  1197. X  /* Try plain files */
  1198. X  if (icon == NULL &&
  1199. X      tp->file != NULL &&
  1200. X      (filestatus->st_mode & S_IFMT) == S_IFREG) {
  1201. X    icon = applyprefs(tp->file, fullname, filename, filestatus);
  1202. X  }
  1203. X
  1204. X  /* Try executable files */
  1205. X  if (icon == NULL &&
  1206. X      tp->exe != NULL &&
  1207. X      (filestatus->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0) {
  1208. X    icon = applyprefs(tp->exe, fullname, filename, filestatus);
  1209. X  }
  1210. X  /* Try Readable files */
  1211. X  if (icon == NULL && 
  1212. X      tp->read != NULL &&
  1213. X      (filestatus->st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) {
  1214. X    icon = applyprefs(tp->read, fullname, filename, filestatus);
  1215. X  }
  1216. X  
  1217. X  /* Try Writable files */
  1218. X  if (icon == NULL && 
  1219. X      tp->write != NULL &&
  1220. X      (filestatus->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) {
  1221. X    icon = applyprefs(tp->write, fullname, filename, filestatus);
  1222. X  }
  1223. X
  1224. X  /* defaults */
  1225. X  if (icon == NULL && tp->iconprefs != NULL) {
  1226. X    icon = do_iconprefs(tp->iconprefs, fullname, filename, filestatus);
  1227. X  }
  1228. X
  1229. X  return(icon);
  1230. X}
  1231. X
  1232. Xprivate Pixmap grey_icon(Pixmap icon)
  1233. X{
  1234. X  private BTree *grey_search(Pixmap, Pixmap*, BTree*);
  1235. X  Pixmap result;
  1236. X  
  1237. X  grey_tree = grey_search(icon, &result, grey_tree);
  1238. X  
  1239. X  return(result);
  1240. X}
  1241. X
  1242. Xprivate BTree *grey_search(Pixmap icon, Pixmap *new, BTree *tree)
  1243. X{
  1244. X  Pixmap newpixmap;
  1245. X  Widget w;
  1246. X  BTree *result;
  1247. X  extern Widget topLevel;
  1248. X
  1249. X  if (tree == NULL) {
  1250. X    /* Create Pixmap */
  1251. X    result = (BTree*) XtMalloc (sizeof(BTree));
  1252. X    result->icon = icon;
  1253. X    result->left = NULL;
  1254. X    result->right = NULL;
  1255. X    newpixmap = XCreatePixmap(XtDisplay(topLevel),
  1256. X                  RootWindowOfScreen(XtScreen(topLevel)), 
  1257. X                  32, 32, DefaultDepthOfScreen(XtScreen(topLevel)));
  1258. X    XSetFunction(XtDisplay(topLevel), xdtmgc, GXcopy);
  1259. X    XCopyPlane(XtDisplay(topLevel),
  1260. X           icon, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1);  
  1261. X    XSetFunction(XtDisplay(topLevel), xdtmgc, GXand);
  1262. X    XCopyPlane(XtDisplay(topLevel),
  1263. X           grey_mask, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1); 
  1264. X    result->grey = newpixmap; 
  1265. X    *new = newpixmap;
  1266. X  } else 
  1267. X    if (tree->icon == icon) {
  1268. X      *new = tree->grey;
  1269. X      result = tree;
  1270. X    } else
  1271. X      if (tree->icon < icon) 
  1272. X    result = grey_search(icon, new, tree->left);
  1273. X      else
  1274. X    result = grey_search(icon, new, tree->right);
  1275. X
  1276. X  return(result);
  1277. X}
  1278. X
  1279. Xprivate Pixmap do_iconprefs(iconPrefs *ip, String fullname, String filename, 
  1280. X                struct stat *filestatus)
  1281. X{
  1282. X  /* traverse linked list trying to match regular expressions against 
  1283. X   * the current filename 
  1284. X   */
  1285. X  Pixmap icon = NULL;
  1286. X  String string;
  1287. X
  1288. X  if (ip != NULL) 
  1289. X    if (ip->expbuf == NULL) {
  1290. X      /* default value */
  1291. X      icon = ip->icon;
  1292. X    } else {
  1293. X      /* try to match regular expression,
  1294. X       * Add stuff here to check for whether to use fullname or filename.
  1295. X       */
  1296. X      if (ip->checkpath == True) 
  1297. X    string = fullname;
  1298. X      else
  1299. X    string = filename;
  1300. X      circf = ip->circf;
  1301. X      if (step(string, ip->expbuf) != 0) {
  1302. X    if (ip->extra != NULL) {
  1303. X      icon = applyprefs((typePrefs*)ip->extra, fullname, filename, filestatus);
  1304. X    }
  1305. X    if (icon == NULL) 
  1306. X      icon = ip->icon;
  1307. X      } else {
  1308. X    icon = do_iconprefs(ip->next, fullname, filename, filestatus);
  1309. X      }
  1310. X    }
  1311. X  return(icon);
  1312. X}
  1313. X
  1314. Xpublic Boolean parsePreferences(Widget w)
  1315. X{
  1316. X  private void initBitmaps(Widget);
  1317. X  extern int yyparse(void);
  1318. X  extern void selectionChange(Widget, Cardinal, caddr_t);
  1319. X  extern typePrefs *newTypePref(void);
  1320. X  extern AppSelection **appselections;
  1321. X  extern Cardinal selectionindex;
  1322. X  extern String home;
  1323. X  extern Widget selectionMenu;
  1324. X  MenuContents *selectionmenu;
  1325. X  String setupfile;
  1326. X  Cardinal i;
  1327. X  int n;
  1328. X  
  1329. X  initBitmaps(w);
  1330. X
  1331. X  /* check to see it there is an .xdtmrc in the users home directory. 
  1332. X   * If not use the system one.. or the command line argument one.
  1333. X   */
  1334. X  
  1335. X  setupfile = (String) XtMalloc ((strlen(home) + 8) * sizeof(char));
  1336. X
  1337. X  user = geteuid();
  1338. X  group = getegid();
  1339. X
  1340. X  strcpy(setupfile, home);
  1341. X  strcat(setupfile, "/.xdtmrc");
  1342. X  if (((yyin = fopen(setupfile, "r")) == NULL) &&
  1343. X      ((yyin = fopen(SYSTEM_XDTMRC, "r")) == NULL)) {
  1344. X    fprintf(stderr, "Warning: No user or system xdtmrc found\n");
  1345. X    prefs = newTypePref();
  1346. X  } else {
  1347. X    /* parse the file */
  1348. X    (void) yyparse();
  1349. X  }
  1350. X  XtFree(setupfile);
  1351. X  
  1352. X  /* Create selection menu */
  1353. X  selectionmenu = (MenuContents*) XtMalloc (sizeof(MenuContents) * selectionindex);
  1354. X  for(i = 0; i < selectionindex; i++) {
  1355. X    selectionmenu[i].paneName   = appselections[i]->name;
  1356. X    selectionmenu[i].paneLabel  = appselections[i]->name;
  1357. X    selectionmenu[i].paneNumber = i;
  1358. X    selectionmenu[i].set        = noflag;
  1359. X  }
  1360. X  
  1361. X  createMenu(selectionMenu, selectionmenu, i, selectionChange);
  1362. X
  1363. X}
  1364. X
  1365. Xprivate void initBitmaps(Widget w)
  1366. X{
  1367. X  XGCValues values;
  1368. X
  1369. X  foldericon  = XCreateBitmapFromData(    XtDisplay(w),
  1370. X                          RootWindowOfScreen(XtScreen(w)),
  1371. X                          folder_bits,
  1372. X                         IconBitmapWidth, IconBitmapHeight);
  1373. X  fileicon    = XCreateBitmapFromData(  XtDisplay(w),
  1374. X                                          RootWindowOfScreen(XtScreen(w)),
  1375. X                          file_bits,
  1376. X                          IconBitmapWidth, IconBitmapHeight);
  1377. X  grey_mask   = XCreateBitmapFromData(  XtDisplay(w),
  1378. X                                          RootWindowOfScreen(XtScreen(w)),
  1379. X                          Grey_bits,
  1380. X                          IconBitmapWidth, IconBitmapHeight);
  1381. X  
  1382. X  if ((BlackPixelOfScreen(XtScreen(w))) == 1) {
  1383. X    values.background = WhitePixelOfScreen(XtScreen(w));
  1384. X    values.foreground = BlackPixelOfScreen(XtScreen(w));
  1385. X  } else {
  1386. X    values.background = BlackPixelOfScreen(XtScreen(w));
  1387. X    values.foreground = WhitePixelOfScreen(XtScreen(w));
  1388. X  }
  1389. X
  1390. X  xdtmgc = XtGetGC(w, (unsigned) GCBackground | GCForeground, &values);
  1391. X         
  1392. X  grey_tree = NULL;
  1393. X}
  1394. X
  1395. X
  1396. Xpublic void highlight_by_re(String re)
  1397. X{
  1398. X  /* This procedure is called by selectQueryResult in map.c, it should be in
  1399. X   * map.c but can't because <regexp.h> can only be accessable from within
  1400. X   * one file.
  1401. X   */
  1402. X  extern void selection_made(Widget, caddr_t, caddr_t);
  1403. X  extern XedwList **icon_list;
  1404. X  extern Cardinal icon_list_size;
  1405. X  extern Widget directoryManager;
  1406. X  String buffer;
  1407. X  Cardinal i;
  1408. X
  1409. X  buffer = (char*) XtMalloc (sizeof(char) * ESIZE);
  1410. X  compile(re, buffer, &(buffer[ESIZE]), '\0');
  1411. X
  1412. X  /* traverse icon_list calling XedwListHighlight on every filename
  1413. X   * matched.
  1414. X   */
  1415. X  for (i = 0; i < icon_list_size; i++) {
  1416. X    if (step(icon_list[i]->string, buffer) != 0) 
  1417. X      XedwListHighlight(directoryManager, i);
  1418. X  }
  1419. X
  1420. X  selection_made(directoryManager, 0, 0);
  1421. X
  1422. X  XtFree(buffer);
  1423. X
  1424. X}
  1425. X
  1426. X
  1427. X
  1428. X
  1429. X
  1430. X
  1431. X
  1432. X
  1433. X
  1434. X
  1435. X
  1436. X
  1437. X
  1438. SHAR_EOF
  1439. chmod 0644 code/parse.c || echo "restore of code/parse.c fails"
  1440. echo "x - extracting code/parse.h (Text)"
  1441. sed 's/^X//' << 'SHAR_EOF' > code/parse.h &&
  1442. X/*****************************************************************************
  1443. X ** File          : parse.h                                                 **
  1444. X ** Purpose       :                                                         **
  1445. X ** Author        : Edward Groenendaal                                      **
  1446. X ** Date          : 18th Feb 1990                                           **
  1447. X ** Documentation : Xdtm Design Folder                                      **
  1448. X ** Related Files : parse.c, lexical.h, parser.y                            **
  1449. X *****************************************************************************/
  1450. X
  1451. X#ifndef _parse_h
  1452. X#define _parse_h
  1453. X
  1454. X/* Directory Manager Structures */
  1455. X
  1456. Xtypedef struct _iconPrefs {
  1457. X  char *expbuf;
  1458. X  int circf; 
  1459. X  Boolean checkpath;
  1460. X  XtPointer extra;
  1461. X  Pixmap icon;
  1462. X  struct _iconPrefs *next;
  1463. X} iconPrefs;
  1464. X
  1465. Xtypedef struct _typePrefs {
  1466. X  iconPrefs *iconprefs;
  1467. X  struct _typePrefs *dir;
  1468. X  struct _typePrefs *file;
  1469. X  struct _typePrefs *exe;
  1470. X  struct _typePrefs *read;
  1471. X  struct _typePrefs *write;
  1472. X} typePrefs;
  1473. X
  1474. X/* Application Manager Structure */
  1475. X
  1476. X#define APPPSIZE 10 /* Initial size of an AppProgram Array */
  1477. X#define APPPINC  5  /* Increment by which to increase AppProgram Array on overflow */
  1478. X
  1479. Xtypedef enum {M_SEL, O_SEL, N_SEL} SelOptions;
  1480. X
  1481. Xtypedef struct {
  1482. X  String string;
  1483. X  Pixmap icon;
  1484. X  String program;
  1485. X  SelOptions options;
  1486. X} AppProgram;
  1487. X
  1488. Xtypedef struct {
  1489. X  String name;
  1490. X  Cardinal number;
  1491. X  AppProgram **list;
  1492. X} AppSelection;
  1493. X
  1494. X/* Regular Expression macros */
  1495. X
  1496. X#define ESIZE 1024            /* maximum size of an expression */
  1497. X
  1498. X#define INIT register String sp = instring;
  1499. X#define GETC() (*sp++)
  1500. X#define PEEKC() (*sp)
  1501. X#define UNGETC(c) (--sp)
  1502. X#define RETURN(c) return;
  1503. X#define ERROR(c)  {fprintf(stderr,"regexp error %d\n", c); exit(1);};
  1504. X
  1505. X#endif /* _parse_h */
  1506. SHAR_EOF
  1507. chmod 0644 code/parse.h || echo "restore of code/parse.h fails"
  1508. echo "x - extracting code/parser.y (Text)"
  1509. sed 's/^X//' << 'SHAR_EOF' > code/parser.y &&
  1510. X%{ /*-*- Mode: C -*-*/
  1511. X/**************************************************************************
  1512. X * Filename :       parser.y
  1513. X * Author   :       Edward Groenendaal
  1514. X * Date     :       31/1/91
  1515. X * Purpose  :       
  1516. X *                  
  1517. X **************************************************************************/
  1518. X
  1519. X#define YYDEBUG     1
  1520. X#include "xdtm.h"
  1521. X#include "parse.h"
  1522. X#include <regexp.h>
  1523. X
  1524. Xtypedef struct _iconTree {
  1525. X  String fullname;       /* index on this */
  1526. X  Pixmap icon;
  1527. X  struct _iconTree *left;
  1528. X  struct _iconTree *right;
  1529. X} iconTree;
  1530. X
  1531. Xtypedef struct _varStack {
  1532. X  String *defpath;
  1533. X  Cardinal dirinpath;
  1534. X  Boolean checkpath;
  1535. X  iconPrefs *iconpref;
  1536. X  typePrefs *current;
  1537. X  struct _varStack *next;
  1538. X} varStack;
  1539. X
  1540. Xpublic  typePrefs *newTypePref(void);
  1541. Xprivate void       start_block(typePrefs*,iconPrefs*);
  1542. Xprivate void       end_block(void);
  1543. Xprivate String    *stringtopath(String, Cardinal*);
  1544. Xprivate Pixmap     lookupicon(String);
  1545. Xprivate iconPrefs *getlast(iconPrefs*);
  1546. Xprivate iconPrefs *inserticonpref(iconPrefs*, iconPrefs*);
  1547. Xprivate String     strip_quotes(String);
  1548. Xprivate iconTree  *get_pixmap(iconTree*,iconTree*);
  1549. Xprivate void       set_path(String);
  1550. Xprivate void       set_icon(String, Boolean);
  1551. Xprivate void       set_deficon(String);
  1552. Xprivate void       set_ignore(void);
  1553. Xprivate void       newselection(String);
  1554. Xprivate void       setapp(int, String);
  1555. X
  1556. X/* imported variables/procedures */
  1557. Xextern int parseerror;            /* quantity of parse errors so far */
  1558. Xextern int yylineno;              /* line number being parsed */
  1559. Xextern void yyerror(char *, ...); /* normal error printing routine */
  1560. X
  1561. X#ifndef DEBUG_YACC
  1562. Xextern Widget topLevel;
  1563. X#endif
  1564. X
  1565. Xpublic  AppSelection **appselections;
  1566. Xpublic  typePrefs     *prefs;          /* preferneces */
  1567. Xprivate varStack      *varframe;       /* stack frames */
  1568. Xprivate iconTree      *icontable;      /* table of pixmaps */
  1569. Xprivate char          *ptr;            /* general use pointer */
  1570. Xprivate AppSelection  *current_selection;
  1571. Xprivate Cardinal       listindex;      /* index into current appprogram list */
  1572. Xprivate Cardinal       currentlistmax; /* current list appprogram size */
  1573. Xpublic  Cardinal       selectionindex; /* index into appselections */
  1574. X
  1575. X%} /* Start of YACC declarations */
  1576. X
  1577. X%start xdtmrc
  1578. X
  1579. X%union                              /* valid types */
  1580. X{
  1581. X    int  number;                     /* number */
  1582. X    char *string;                    /* string */
  1583. X}
  1584. X
  1585. X/* declare terminals with their types */
  1586. X
  1587. X%token <string> STRING_T
  1588. X%token <number> IF_T SET_T ICON_T NAME_T PATH_T DEFICON_T TYPE_T CHECKPATH_T
  1589. X%token <number> TRUE_T FALSE_T IGNORE_T
  1590. X%token <number> DIR_T FILE_T READ_T WRITE_T EXE_T PROG_T OPTIONS_T
  1591. X%token <number> MSEL_T OSEL_T NSEL_T DEFINE_T
  1592. X%token <number> ASSIGN_T EQUAL_T SEMIC_T COMMA_T
  1593. X%token <number> O_PAR_T C_PAR_T O_BRACE_T C_BRACE_T
  1594. X%token <value>  EOFTOKEN ERRORTOKEN
  1595. X
  1596. X%type <string> identifier
  1597. X%type <number> block type var option
  1598. X
  1599. X%%    /* Beginning of rule section */
  1600. X
  1601. Xxdtmrc       :   { init_structs(); } 
  1602. X                 statements 
  1603. X                 { free_structs(); }
  1604. X             ;
  1605. Xstatements   :   /* Empty */
  1606. X             |   statements statement 
  1607. X             ;
  1608. Xstatement    :   ifstatement
  1609. X             |   setstatement SEMIC_T
  1610. X             |   define
  1611. X             ;
  1612. Xifstatement  :   IF_T O_PAR_T expression C_PAR_T block
  1613. X             ;
  1614. Xsetstatement :   SET_T var ASSIGN_T identifier { switch ($2) {
  1615. X                                                 case PATH_T:
  1616. X                                                   set_path($4);
  1617. X                           break;
  1618. X                         case ICON_T:
  1619. X                           set_icon($4, False);
  1620. X                           break;
  1621. X                         case DEFICON_T:
  1622. X                           set_deficon($4);
  1623. X                           break;
  1624. X                         }
  1625. X                           }
  1626. X             |   SET_T CHECKPATH_T ASSIGN_T TRUE_T 
  1627. X                       { varframe->checkpath = True; }
  1628. X             |   SET_T CHECKPATH_T ASSIGN_T FALSE_T 
  1629. X                       { varframe->checkpath = False; }
  1630. X             |   SET_T IGNORE_T
  1631. X                       { set_icon("", True);}
  1632. X             ;
  1633. Xdefine       :   DEFINE_T identifier {newselection($2);} ASSIGN_T defineblock
  1634. X             ;
  1635. Xblock        :   O_BRACE_T
  1636. X                 statements {end_block();} 
  1637. X                 C_BRACE_T
  1638. X             ;
  1639. Xdefineblock  :   O_BRACE_T descriptions C_BRACE_T 
  1640. X                 {current_selection->number = listindex;}
  1641. X             ;
  1642. Xdescriptions :   /* Empty */
  1643. X             |   descriptions description 
  1644. X             ;
  1645. Xdescription  :   O_BRACE_T 
  1646. X
  1647. X                 { /* Allocate a new AppProgram */
  1648. SHAR_EOF
  1649. echo "End of part 3"
  1650. echo "File code/parser.y is continued in part 4"
  1651. echo "4" > s2_seq_.tmp
  1652. exit 0
  1653.