home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / x / volume13 / xdtm / part10 < prev    next >
Internet Message Format  |  1991-05-18  |  52KB

  1. Path: uunet!olivea!apple!sun-barr!newstop!exodus!cogs.sussex.ac.uk
  2. From: eddyg@cogs.sussex.ac.uk (EdwardJ. Groenendaal)
  3. Newsgroups: comp.sources.x
  4. Subject: v13i015: xdtm - X Desktop Manager for the X Window System, Part10/11
  5. Message-ID: <13579@exodus.Eng.Sun.COM>
  6. Date: 19 May 91 00:03:55 GMT
  7. References: <csx-13i006:xdtm@uunet.UU.NET>
  8. Sender: news@exodus.Eng.Sun.COM
  9. Lines: 1613
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: Edward "J." Groenendaal <eddyg@cogs.sussex.ac.uk>
  13. Posting-number: Volume 13, Issue 15
  14. Archive-name: xdtm/part10
  15.  
  16. Submitted-by: eddyg@cste
  17. Archive-name: xdtm/part10
  18.  
  19. ---- Cut Here and feed the following to sh ----
  20. #!/bin/sh
  21. # This is part 10 of xdtm
  22. # ============= xdtm/parse.c ==============
  23. if test ! -d 'xdtm'; then
  24.     echo 'x - creating directory xdtm'
  25.     mkdir 'xdtm'
  26. fi
  27. if test -f 'xdtm/parse.c' -a X"$1" != X"-c"; then
  28.     echo 'x - skipping xdtm/parse.c (File already exists)'
  29. else
  30. echo 'x - extracting xdtm/parse.c (Text)'
  31. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/parse.c' &&
  32. X/*****************************************************************************
  33. X ** File          : parse.c                                                 **
  34. X ** Purpose       : Parse setup file, select icon to be used.               **
  35. X ** Author        : Edward Groenendaal                                      **
  36. X ** Date          : 19th Feb 1991                                           **
  37. X ** Documentation : Xdtm Design Folder                                      **
  38. X *****************************************************************************/
  39. X
  40. X#include "xdtm.h"
  41. X
  42. X#include <sys/types.h>
  43. X#include <sys/stat.h>
  44. X#include <sys/param.h>
  45. X
  46. X#ifndef TRUE_SYSV
  47. X#include <sys/file.h>
  48. X#endif
  49. X
  50. X#include <pwd.h>
  51. X#include <grp.h>
  52. X#include "parse.h"
  53. X#include "menus.h"
  54. X
  55. X#include "Xedw/XedwList.h"
  56. X
  57. X#include "bitmaps/Grey.Mask"
  58. X#include "bitmaps/folder.icon"
  59. X#include "bitmaps/file.icon"
  60. X
  61. Xtypedef struct _BTree {
  62. X  Pixmap icon;
  63. X  Pixmap grey;
  64. X  struct _BTree *left;
  65. X  struct _BTree *right;
  66. X} BTree;
  67. X
  68. Xextern FILE *yyin;
  69. Xextern int step(char*, char*);
  70. Xextern int circf;
  71. Xextern typePrefs *prefs ;
  72. X
  73. X#ifdef ESIX
  74. Xtypedef long uid_t    /* jcc */
  75. X#endif
  76. X
  77. Xpublic uid_t user;
  78. Xpublic uid_t group;
  79. Xprivate BTree *grey_tree;
  80. X
  81. Xprivate Pixmap applyprefs(typePrefs*, String, String, struct stat*);
  82. Xprivate Pixmap do_iconprefs(iconPrefs*, String, String, struct stat*);
  83. X
  84. Xpublic GC xdtmgc;
  85. Xpublic Pixmap foldericon, fileicon, grey_mask; /* default icons */
  86. X
  87. X/*****************************************************************************
  88. X *                               getIconType                                 *
  89. X *****************************************************************************/
  90. Xpublic Boolean getIconType(String filename, String path, XedwList *element)
  91. X{
  92. X  /* Return True if file should be displayed, otherwise False. 
  93. X   * if long listing is on, expand the filename to contain the extra
  94. X   * data as well.
  95. X   */
  96. X
  97. X  private Pixmap grey_icon(Pixmap);
  98. X
  99. X  extern Icon_mode current_mode;
  100. X  struct stat *filestatus;
  101. X  typePrefs *myprefs = prefs;
  102. X  String fullname;
  103. X  Pixmap icon;
  104. X  
  105. X  element->string = XtNewString(filename);
  106. X
  107. X  if (current_mode.mode != Short) {
  108. X    filestatus = (struct stat*) XtMalloc (sizeof(struct stat));
  109. X    fullname=(String) XtMalloc((strlen(filename)+strlen(path)+4) * 
  110. X                   sizeof(char));
  111. X    strcpy(fullname, path);
  112. X    strcat(fullname, "/");
  113. X    strcat(fullname, filename);
  114. X#ifdef TRUE_SYSV
  115. X    if (stat(fullname, filestatus) == -1) {    /* jcc, no symbolic links */
  116. X#else
  117. X    if (lstat(fullname, filestatus) == -1) {
  118. X#endif
  119. X      /* maybe a link to a nonexistent file? */
  120. X      return(False);
  121. X    } else {
  122. X      if (current_mode.mode == Icons) {
  123. X    element->icon = fileicon;
  124. X    if ((filestatus->st_mode & S_IFMT) == S_IFDIR) /* stat(5) for details */
  125. X      element->icon = foldericon;
  126. X      
  127. X    /* try all rules in prefs */
  128. X    if ((icon = applyprefs(myprefs, fullname, filename, filestatus)) != NULL) {
  129. X    
  130. X      /* If the file is a directory but is not readable AND executable by the user
  131. X       * then grey it. If the file is not readable then grey it.
  132. X       */
  133. X    
  134. X      /* if not readable then grey it */
  135. X      if (icon != DUMMY) 
  136. X        if (!(((filestatus->st_mode & S_IRUSR) != 0 &&
  137. X           user == filestatus->st_uid)           ||
  138. X          ((filestatus->st_mode & S_IRGRP) != 0 &&
  139. X           group == filestatus->st_gid)          ||
  140. X          ((filestatus->st_mode & S_IROTH) != 0))) {
  141. X          icon = grey_icon(icon);
  142. X        } else {
  143. X          if ((filestatus->st_mode & S_IFMT) == S_IFDIR) 
  144. X        if (!(((filestatus->st_mode & S_IXUSR) != 0 &&
  145. X               user == filestatus->st_uid)           ||
  146. X              ((filestatus->st_mode & S_IXGRP) != 0 &&
  147. X               group == filestatus->st_gid)          ||
  148. X              ((filestatus->st_mode & S_IXOTH) != 0))) {
  149. X          icon = grey_icon(icon);
  150. X        } 
  151. X        }
  152. X      element->icon = icon;
  153. X    }
  154. X      } else {
  155. X    /* Long Listing, construct the line*/
  156. X    Cardinal length;
  157. X    char cm = current_mode.options;
  158. X    String output_line;
  159. X
  160. X    element->icon = NULL;
  161. X    length = 0;
  162. X    output_line = XtNewString("");
  163. X    if (cm & PERMS) {
  164. X      char type;
  165. X      char xusr, xgrp, xoth;
  166. X      unsigned short mode = (filestatus->st_mode);
  167. X
  168. X      output_line = (String) XtMalloc (sizeof(char) * 12);
  169. X
  170. X      /* I could use the S_IS* macros here but I prefer to see what's
  171. X       * going on.
  172. X       */
  173. X      if ((mode & S_IFMT) == S_IFDIR) type = 'd';      /* Directory */
  174. X      else if ((mode & S_IFMT) == S_IFBLK) type = 'b'; /* Block device */
  175. X      else if ((mode & S_IFMT) == S_IFCHR) type = 'c'; /* Character device */
  176. X      else if ((mode & S_IFMT) == S_IFREG) type = ' '; /* Plain file */
  177. X      else if ((mode & S_IFMT) == S_IFIFO) type = 'f'; /* Fifo */
  178. X#ifndef TRUE_SYSV                       /* jcc */
  179. X      else if ((mode & S_IFMT) == S_IFLNK) type = 'l'; /* Symbolic link */ 
  180. X      else if ((mode & S_IFMT) == S_IFSOCK) type = 's'; /* Socket */
  181. X#endif
  182. X      else type = '?';
  183. X      
  184. X      if (mode & S_ISUID)     /* Set User Id */
  185. X        xusr = 's';
  186. X      else if (mode & S_IXUSR)
  187. X        xusr = 'x';
  188. X      else 
  189. X        xusr = '-';
  190. X
  191. X      if (mode & S_ISGID)    /* Set Group Id */
  192. X        xgrp = 's';
  193. X      else if (mode & S_IXGRP)
  194. X        xgrp = 'x';
  195. X      else
  196. X        xgrp = '-';
  197. X
  198. X      if (mode & S_ISVTX)    /* Save Text */
  199. X        xoth = 't';
  200. X      else if (mode & S_IXOTH)
  201. X        xoth = 'x';
  202. X      else 
  203. X        xoth = '-';
  204. X
  205. X      sprintf(output_line, 
  206. X          "%c%c%c%c%c%c%c%c%c%c ",
  207. X          type,
  208. X          (mode & S_IRUSR) ? 'r' : '-',
  209. X          (mode & S_IWUSR) ? 'w' : '-',
  210. X          xusr,
  211. X          (mode & S_IRGRP) ? 'r' : '-',
  212. X          (mode & S_IWGRP) ? 'w' : '-',
  213. X          xgrp,
  214. X          (mode & S_IROTH) ? 'r' : '-',
  215. X          (mode & S_IWOTH) ? 'w' : '-',
  216. X          xoth);
  217. X    } 
  218. X
  219. X    if (cm & NLINKS) {
  220. X      output_line = XtRealloc (output_line, 
  221. X                   sizeof(char) *
  222. X                   (strlen(output_line) + 3 + 4));
  223. X      
  224. X      sprintf(output_line, "%s%3d ", output_line, 
  225. X          filestatus->st_nlink);
  226. X    }
  227. X    if (cm & OWNER) {
  228. X      struct passwd *pw;
  229. X
  230. X      output_line = XtRealloc (output_line,
  231. X                   sizeof(char) *
  232. X                  (strlen(output_line) + 8 + 4));
  233. X      
  234. X      if ((pw = getpwuid(filestatus->st_uid)) == NULL)
  235. X        sprintf(output_line, "%s%-8d ", output_line, filestatus->st_uid);
  236. X      else
  237. X        sprintf(output_line, "%s%-8s ", output_line, pw->pw_name);
  238. X
  239. X    }
  240. X    if (cm & GROUP) {
  241. X      struct group *gr;
  242. X      
  243. X      output_line = XtRealloc (output_line,
  244. X                   sizeof(char) *
  245. X                  (strlen(output_line) + 8 + 4));
  246. X      
  247. X      if ((gr = getgrgid(filestatus->st_gid)) == NULL)
  248. X        sprintf(output_line, "%s%-8d ", output_line, filestatus->st_gid);
  249. X      else
  250. X        sprintf(output_line, "%s%-8s ", output_line, gr->gr_name);
  251. X
  252. X    }
  253. X    if (cm & SIZE)  {
  254. X      unsigned short mode = (filestatus->st_mode);
  255. X
  256. X      output_line = XtRealloc (output_line, 
  257. X                   sizeof(char) *
  258. X                  (strlen(output_line) + 9 + 4));
  259. X      if ((mode & S_IFMT) == S_IFBLK || (mode & S_IFMT) == S_IFCHR)
  260. X        sprintf(output_line, "%s%5d,%3d ", output_line, 
  261. X            (filestatus->st_rdev >> 8) & 0377,
  262. X            (filestatus->st_rdev) & 0377);
  263. X      else
  264. X        sprintf(output_line, "%s%9d ", output_line, filestatus->st_size);
  265. X    }
  266. X    if (cm & MODTM) {
  267. X      String time;
  268. X      output_line = XtRealloc (output_line,
  269. X                   sizeof(char) *
  270. X                   (strlen(output_line) + 35 + 4));
  271. X
  272. X      time = ctime(&(filestatus->st_mtime));
  273. X      *(time + (strlen(time) - 1)) = '\0';
  274. X      sprintf(output_line, "%s%s ", output_line, time);
  275. X    }
  276. X    if (cm & ACCTM) {
  277. X      String time;
  278. X      output_line = XtRealloc (output_line,
  279. X                   sizeof(char) *
  280. X                   (strlen(output_line) + 35 + 4));
  281. X
  282. X      time = ctime(&(filestatus->st_atime));
  283. X      *(time + (strlen(time) - 1)) = '\0';
  284. X      sprintf(output_line, "%s%s ", output_line, time);
  285. X    }
  286. X    current_mode.length = strlen(output_line); /* length of data */
  287. X    output_line = XtRealloc (output_line,
  288. X                 sizeof(char) * 
  289. X                (strlen(output_line) + strlen(filename) + 4));
  290. X    sprintf(output_line, "%s%s", output_line, filename);
  291. X    element->string = output_line;
  292. X      }
  293. X    }
  294. X    XtFree(filestatus);
  295. X    XtFree(fullname);
  296. X  }
  297. X
  298. X  if (element->icon == DUMMY)
  299. X    return(False);
  300. X  else
  301. X    return(True);
  302. X}
  303. X
  304. X/*****************************************************************************
  305. X *                                applyprefs                                 *
  306. X *****************************************************************************/
  307. Xprivate Pixmap applyprefs(typePrefs *tp, String fullname, String filename, 
  308. X              struct stat *filestatus)
  309. X{
  310. X  /* Recursively traverse the prefs structure until a match is found.
  311. X   * Jump out as soon as a match is found, try special files first */
  312. X
  313. X  static Boolean insymlink = False;
  314. X  Pixmap icon = NULL;
  315. X  struct stat *newfilestatus;
  316. X  
  317. X  /* Try directories */
  318. X  if (icon == NULL && 
  319. X      tp->dir != NULL &&
  320. X      (filestatus->st_mode & S_IFMT) == S_IFDIR) {
  321. X    icon = applyprefs(tp->dir, fullname, filename, filestatus);
  322. X  }
  323. X
  324. X  /* Try plain files */
  325. X  if (icon == NULL &&
  326. X      tp->file != NULL &&
  327. X      (filestatus->st_mode & S_IFMT) == S_IFREG) {
  328. X    icon = applyprefs(tp->file, fullname, filename, filestatus);
  329. X  }
  330. X
  331. X  /* Try Block special devices */
  332. X  if (icon == NULL &&
  333. X      tp->block != NULL &&
  334. X      (filestatus->st_mode & S_IFMT) == S_IFBLK) {
  335. X    icon = applyprefs(tp->block, fullname, filename, filestatus);
  336. X  }
  337. X
  338. X  /* Try Character special devices */
  339. X  if (icon == NULL &&
  340. X      tp->character != NULL &&
  341. X      (filestatus->st_mode & S_IFMT) == S_IFCHR) {
  342. X    icon = applyprefs(tp->character, fullname, filename, filestatus);
  343. X  }
  344. X
  345. X  /* Try Fifo's */
  346. X  if (icon == NULL &&
  347. X      tp->fifo != NULL &&
  348. X      (filestatus->st_mode & S_IFMT) == S_IFIFO) {
  349. X    icon = applyprefs(tp->fifo, fullname, filename, filestatus);
  350. X  }
  351. X
  352. X  /* Try Symbolic Links */
  353. X  if (icon == NULL &&
  354. X      tp->slink != NULL &&
  355. X      insymlink == False &&
  356. X      (filestatus->st_mode & S_IFMT) == S_IFLNK) {
  357. X    insymlink = True;
  358. X    newfilestatus = (struct stat*) XtMalloc (sizeof(struct stat));
  359. X    if (stat(fullname, newfilestatus) != -1) {
  360. X      icon = applyprefs(tp->slink, fullname, filename, newfilestatus);
  361. X      XtFree(newfilestatus);
  362. X    }
  363. X    insymlink = False;
  364. X  }
  365. X
  366. X  /* Try Sockets */
  367. X  if (icon == NULL &&
  368. X      tp->socket != NULL &&
  369. X      (filestatus->st_mode & S_IFMT) == S_IFSOCK) {
  370. X    icon = applyprefs(tp->socket, fullname, filename, filestatus);
  371. X  }
  372. X
  373. X  /* Try executable files */
  374. X  if (icon == NULL &&
  375. X      tp->exe != NULL &&
  376. X      (filestatus->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0) {
  377. X    icon = applyprefs(tp->exe, fullname, filename, filestatus);
  378. X  }
  379. X
  380. X  /* Try Readable files */
  381. X  if (icon == NULL && 
  382. X      tp->read != NULL &&
  383. X      (filestatus->st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) {
  384. X    icon = applyprefs(tp->read, fullname, filename, filestatus);
  385. X  }
  386. X  
  387. X  /* Try Writable files */
  388. X  if (icon == NULL && 
  389. X      tp->write != NULL &&
  390. X      (filestatus->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) {
  391. X    icon = applyprefs(tp->write, fullname, filename, filestatus);
  392. X  }
  393. X
  394. X  /* defaults */
  395. X  if (icon == NULL && tp->iconprefs != NULL) {
  396. X    icon = do_iconprefs(tp->iconprefs, fullname, filename, filestatus);
  397. X  }
  398. X
  399. X  return(icon);
  400. X}
  401. X
  402. X/*****************************************************************************
  403. X *                                  grey_icon                                *
  404. X *****************************************************************************/
  405. Xprivate Pixmap grey_icon(Pixmap icon)
  406. X{
  407. X  /* Get a greyed icon for the icon 'icon'. */
  408. X
  409. X  private BTree *grey_search(Pixmap, Pixmap*, BTree*);
  410. X  Pixmap result;
  411. X  
  412. X  grey_tree = grey_search(icon, &result, grey_tree);
  413. X  
  414. X  return(result);
  415. X}
  416. X
  417. X/*****************************************************************************
  418. X *                                grey_search                                *
  419. X *****************************************************************************/
  420. Xprivate BTree *grey_search(Pixmap icon, Pixmap *new, BTree *tree)
  421. X{
  422. X  /* Search through the grey pixmap tree for a pixmap with the same id,
  423. X   * if none is found, make a new one by And'ing the original icon
  424. X   * with a stippled pixmap, put this into the tree, and also return it.
  425. X   * This procedure should still work even if the representation of a
  426. X   * Pixmap changes.
  427. X   */
  428. X
  429. X  Pixmap newpixmap;
  430. X  Widget w;
  431. X  BTree *result;
  432. X  extern Widget topLevel;
  433. X
  434. X  if (tree == NULL) {
  435. X    /* Create Pixmap */
  436. X    result = (BTree*) XtMalloc (sizeof(BTree));
  437. X    result->icon = icon;
  438. X    result->left = NULL;
  439. X    result->right = NULL;
  440. X    newpixmap = XCreatePixmap(XtDisplay(topLevel),
  441. X                  RootWindowOfScreen(XtScreen(topLevel)), 
  442. X                  32, 32, DefaultDepthOfScreen(XtScreen(topLevel)));
  443. X    XSetFunction(XtDisplay(topLevel), xdtmgc, GXcopy);
  444. X    XCopyPlane(XtDisplay(topLevel),
  445. X           icon, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1);  
  446. X    XSetFunction(XtDisplay(topLevel), xdtmgc, GXand);
  447. X    XCopyPlane(XtDisplay(topLevel),
  448. X           grey_mask, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1); 
  449. X    result->grey = newpixmap; 
  450. X    *new = newpixmap;
  451. X  } else 
  452. X    if (tree->icon == icon) {
  453. X      /* Found it */
  454. X      *new = tree->grey;
  455. X      result = tree;
  456. X    } else
  457. X      if (tree->icon < icon) 
  458. X    /* Try left hand side */
  459. X    result = grey_search(icon, new, tree->left);
  460. X      else
  461. X    /* Try right hand side */
  462. X    result = grey_search(icon, new, tree->right);
  463. X
  464. X  return(result);
  465. X}
  466. X
  467. X/*****************************************************************************
  468. X *                                do_iconprefs                               *
  469. X *****************************************************************************/
  470. Xprivate Pixmap do_iconprefs(iconPrefs *ip, String fullname, String filename, 
  471. X                struct stat *filestatus)
  472. X{
  473. X  /* traverse linked list trying to match regular expressions against 
  474. X   * the current filename 
  475. X   */
  476. X  Pixmap icon = NULL;
  477. X  String string;
  478. X
  479. X  if (ip != NULL) 
  480. X    if (ip->expbuf == NULL) {
  481. X      /* default value */
  482. X      icon = ip->icon;
  483. X    } else {
  484. X      /* try to match regular expression,
  485. X       */
  486. X      if (ip->checkpath == True) 
  487. X    string = fullname;
  488. X      else
  489. X    string = filename;
  490. X      circf = ip->circf;
  491. X      if (step(string, ip->expbuf) != 0) {
  492. X    if (ip->extra != NULL) {
  493. X      icon = applyprefs((typePrefs*)ip->extra, fullname, filename, filestatus);
  494. X    }
  495. X    if (icon == NULL) 
  496. X      icon = ip->icon;
  497. X      } else {
  498. X    icon = do_iconprefs(ip->next, fullname, filename, filestatus);
  499. X      }
  500. X    }
  501. X  return(icon);
  502. X}
  503. X
  504. X/*****************************************************************************
  505. X *                             parsePreferences                              *
  506. X *****************************************************************************/
  507. Xpublic Boolean parsePreferences(Widget w)
  508. X{
  509. X  /* Call the parser on the config file */
  510. X
  511. X  private void initBitmaps(Widget);
  512. X  extern int yyparse(void);
  513. X  extern void selectionChange(Widget, Cardinal, caddr_t);
  514. X  extern typePrefs *newTypePref(void);
  515. X  extern AppSelection **appselections;
  516. X  extern Cardinal selectionindex;
  517. X  extern String home;
  518. X  extern Widget selectionMenu;
  519. X  MenuContents *selectionmenu;
  520. X  String setupfile;
  521. X  Cardinal i;
  522. X  int n;
  523. X
  524. X  /* Initialise default pixmaps */
  525. X  initBitmaps(w);
  526. X
  527. X  /* check to see it there is an .xdtmrc in the users home directory. 
  528. X   * If not use the system one.. or command line argument one.
  529. X   */
  530. X  
  531. X  setupfile = (String) XtMalloc ((strlen(home) + 10) * sizeof(char));
  532. X
  533. X  user = geteuid();
  534. X  group = getegid();
  535. X
  536. X  strcpy(setupfile, home);
  537. X  strcat(setupfile, "/.xdtmrc");
  538. X  if (((yyin = fopen(app_data.cffile, "r")) == NULL) &&  /* try appdefaults */
  539. X      ((yyin = fopen(setupfile,        "r")) == NULL) && /* try home dir */
  540. X      ((yyin = fopen(SYSTEM_XDTMRC,    "r")) == NULL)) { /* try system dir */
  541. X    fprintf(stderr, "Error: No user or system xdtmrc found\n");
  542. X    fprintf(stderr, "       either install an xdtmrc or specify one on the\n");
  543. X    fprintf(stderr, "       command line using the -cf option\n");
  544. X    exit(2);
  545. X  } else {
  546. X    /* parse the file */
  547. X    (void) yyparse();
  548. X  }
  549. X  XtFree(setupfile);
  550. X  
  551. X  /* Create selection menu */
  552. X  selectionmenu = (MenuContents*) XtMalloc (sizeof(MenuContents) *
  553. X                        selectionindex);
  554. X  for(i = 0; i < selectionindex; i++) {
  555. X    selectionmenu[i].paneName   = appselections[i]->name;
  556. X    selectionmenu[i].paneLabel  = appselections[i]->name;
  557. X    selectionmenu[i].paneNumber = i;
  558. X    selectionmenu[i].set        = noflag;
  559. X  }
  560. X  
  561. X  createMenu(selectionMenu, selectionmenu, i, selectionChange);
  562. X
  563. X}
  564. X
  565. X/*****************************************************************************
  566. X *                               initBitmaps                                 *
  567. X *****************************************************************************/
  568. Xprivate void initBitmaps(Widget w)
  569. X{
  570. X  /* Get default icon pixmaps + the stippled pixmap for greying icons */
  571. X
  572. X  XGCValues values;
  573. X
  574. X  foldericon  = XCreateBitmapFromData(    XtDisplay(w),
  575. X                          RootWindowOfScreen(XtScreen(w)),
  576. X                          folder_bits,
  577. X                         IconBitmapWidth, IconBitmapHeight);
  578. X  fileicon    = XCreateBitmapFromData(  XtDisplay(w),
  579. X                                          RootWindowOfScreen(XtScreen(w)),
  580. X                          file_bits,
  581. X                          IconBitmapWidth, IconBitmapHeight);
  582. X  grey_mask   = XCreateBitmapFromData(  XtDisplay(w),
  583. X                                          RootWindowOfScreen(XtScreen(w)),
  584. X                          Grey_bits,
  585. X                          IconBitmapWidth, IconBitmapHeight);
  586. X  
  587. X  /* GC for copying pixmaps */
  588. X  if ((BlackPixelOfScreen(XtScreen(w))) == 1) {
  589. X    values.background = WhitePixelOfScreen(XtScreen(w));
  590. X    values.foreground = BlackPixelOfScreen(XtScreen(w));
  591. X  } else {
  592. X    values.background = BlackPixelOfScreen(XtScreen(w));
  593. X    values.foreground = WhitePixelOfScreen(XtScreen(w));
  594. X  }
  595. X
  596. X  xdtmgc = XtGetGC(w, (unsigned) GCBackground | GCForeground, &values);
  597. X         
  598. X  grey_tree = NULL;
  599. X}
  600. X
  601. X/*****************************************************************************
  602. X *                            highlight_by_re                                *
  603. X *****************************************************************************/
  604. Xpublic void highlight_by_re(String re)
  605. X{
  606. X  /* This procedure is called by selectQueryResult in map.c, it should be in
  607. X   * map.c but can't because <regexp.h> can only be accessable from within
  608. X   * one file.
  609. X   */
  610. X  extern void selection_made(Widget, caddr_t, caddr_t);
  611. X  extern XedwList **icon_list;
  612. X  extern Cardinal icon_list_size;
  613. X  extern Widget directoryManager;
  614. X  String buffer;
  615. X  Cardinal i;
  616. X
  617. X  buffer = (char*) XtMalloc (sizeof(char) * ESIZE);
  618. X  compile(re, buffer, &(buffer[ESIZE]), '\0');
  619. X
  620. X  /* traverse icon_list calling XedwListHighlight on every filename
  621. X   * matched.
  622. X   */
  623. X  for (i = 0; i < icon_list_size; i++) {
  624. X    if (step(icon_list[i]->string, buffer) != 0) 
  625. X      XedwListHighlight(directoryManager, i);
  626. X  }
  627. X
  628. X  selection_made(directoryManager, 0, 0);
  629. X
  630. X  XtFree(buffer);
  631. X
  632. X}
  633. X
  634. X
  635. X
  636. X
  637. X
  638. X
  639. X
  640. X
  641. X
  642. X
  643. X
  644. X
  645. X
  646. SHAR_EOF
  647. chmod 0644 xdtm/parse.c ||
  648. echo 'restore of xdtm/parse.c failed'
  649. Wc_c="`wc -c < 'xdtm/parse.c'`"
  650. test 18463 -eq "$Wc_c" ||
  651.     echo 'xdtm/parse.c: original size 18463, current size' "$Wc_c"
  652. fi
  653. # ============= xdtm/parse.h ==============
  654. if test -f 'xdtm/parse.h' -a X"$1" != X"-c"; then
  655.     echo 'x - skipping xdtm/parse.h (File already exists)'
  656. else
  657. echo 'x - extracting xdtm/parse.h (Text)'
  658. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/parse.h' &&
  659. X/*****************************************************************************
  660. X ** File          : parse.h                                                 **
  661. X ** Purpose       :                                                         **
  662. X ** Author        : Edward Groenendaal                                      **
  663. X ** Date          : 18th Feb 1991                                           **
  664. X ** Documentation : Xdtm Design Folder                                      **
  665. X ** Related Files : parse.c, lexical.h, parser.y                            **
  666. X *****************************************************************************/
  667. X
  668. X#ifndef _parse_h
  669. X#define _parse_h
  670. X
  671. X/* Directory Manager Structures */
  672. X
  673. Xtypedef struct _iconPrefs {
  674. X  char *expbuf;
  675. X  int circf; 
  676. X  Boolean checkpath;
  677. X  XtPointer extra;
  678. X  Pixmap icon;
  679. X  struct _iconPrefs *next;
  680. X} iconPrefs;
  681. X
  682. Xtypedef struct _typePrefs {
  683. X  iconPrefs *iconprefs;
  684. X  struct _typePrefs *dir;
  685. X  struct _typePrefs *file;
  686. X  struct _typePrefs *block;    /* Added in v1.2 */
  687. X  struct _typePrefs *character;    /* Added in v1.2 */
  688. X  struct _typePrefs *fifo;    /* Added in v1.2 */
  689. X  struct _typePrefs *slink;    /* Added in v1.2 */
  690. X  struct _typePrefs *socket;    /* Added in v1.2 */
  691. X  struct _typePrefs *exe;
  692. X  struct _typePrefs *read;
  693. X  struct _typePrefs *write;
  694. X} typePrefs;
  695. X
  696. X/* Application Manager Structure */
  697. X
  698. X#define APPPSIZE 10 /* Initial size of an AppProgram Array */
  699. X#define APPPINC  5  /* Increment by which to increase AppProgram Array on overflow */
  700. X
  701. Xtypedef enum {M_SEL, O_SEL, N_SEL} SelOptions;
  702. X
  703. Xtypedef struct {
  704. X  String string;
  705. X  Pixmap icon;
  706. X  String program;
  707. X  SelOptions options;
  708. X} AppProgram;
  709. X
  710. Xtypedef struct {
  711. X  String name;
  712. X  Cardinal number;
  713. X  AppProgram **list;
  714. X} AppSelection;
  715. X
  716. X/* Regular Expression macros */
  717. X
  718. X#define ESIZE 1024            /* maximum size of an expression */
  719. X
  720. X#define INIT register String sp = instring;
  721. X#define GETC() (*sp++)
  722. X#define PEEKC() (*sp)
  723. X#define UNGETC(c) (--sp)
  724. X#define RETURN(c) return;
  725. X#define ERROR(c)  {fprintf(stderr,"regexp error %d\n", c); exit(1);};
  726. X
  727. X#endif /* _parse_h */
  728. SHAR_EOF
  729. chmod 0644 xdtm/parse.h ||
  730. echo 'restore of xdtm/parse.h failed'
  731. Wc_c="`wc -c < 'xdtm/parse.h'`"
  732. test 2063 -eq "$Wc_c" ||
  733.     echo 'xdtm/parse.h: original size 2063, current size' "$Wc_c"
  734. fi
  735. # ============= xdtm/parser.y ==============
  736. if test -f 'xdtm/parser.y' -a X"$1" != X"-c"; then
  737.     echo 'x - skipping xdtm/parser.y (File already exists)'
  738. else
  739. echo 'x - extracting xdtm/parser.y (Text)'
  740. sed 's/^X//' << 'SHAR_EOF' > 'xdtm/parser.y' &&
  741. X%{ /*-*- Mode: C -*-*/
  742. X/**************************************************************************
  743. X ** Filename :       parser.y                                            **
  744. X ** Author   :       Edward Groenendaal                                  **
  745. X ** Date     :       31/1/91                                             **
  746. X ** Purpose  :       Parse the xdtm config file, build the data          **
  747. X **                  structures.                                         **
  748. X **************************************************************************/
  749. X
  750. X#define YYDEBUG     1    /* allow yacc debugging */
  751. X#include "xdtm.h"
  752. X#include "parse.h"
  753. X
  754. X#if defined(sco386) && defined(M_INTERNAT)   /* jcc */
  755. X#undef M_INTERNAT
  756. X#endif
  757. X
  758. X#include <regexp.h>     /* Needed for regular expression compilation */
  759. X
  760. X/* structure used to hold loaded bitmaps (pixmaps), the pixmaps referenced
  761. X * in the icon list are pointing into this structure.
  762. X */
  763. Xtypedef struct _iconTree {
  764. X  String fullname;       /* index on this */
  765. X  Pixmap icon;
  766. X  struct _iconTree *left;
  767. X  struct _iconTree *right;
  768. X} iconTree;
  769. X
  770. X/* The variable stack frame, this stack holds the stack frames for use in 
  771. X * calculating the scope of local variables in the config language.
  772. X */
  773. Xtypedef struct _varStack {
  774. X  String *defpath;        /* path in this stack */
  775. X  Cardinal dirinpath;        /* Number of dirs in path */
  776. X  Boolean checkpath;        /* Whether to match over the whole path */
  777. X  iconPrefs *iconpref;        /* The point into the main icon structure 
  778. X                 * at which this frame's results will be
  779. X                 * inserted. 
  780. X                 */
  781. X  typePrefs *current;        /* The level at which the new iconprefs
  782. X                 * will be inserted.
  783. X                 */
  784. X  struct _varStack *next;    /* Next link in stack */
  785. X} varStack;
  786. X
  787. X/* Declarations of procedures defined after they have been referenced */
  788. Xpublic  typePrefs *newTypePref(void);
  789. Xprivate void       start_block(typePrefs*,iconPrefs*);
  790. Xprivate void       end_block(void);
  791. Xprivate String    *stringtopath(String, Cardinal*);
  792. Xprivate Pixmap     lookupicon(String);
  793. Xprivate iconPrefs *getlast(iconPrefs*);
  794. Xprivate iconPrefs *inserticonpref(iconPrefs*, iconPrefs*);
  795. Xprivate String     strip_quotes(String);
  796. Xprivate iconTree  *get_pixmap(iconTree*,iconTree*);
  797. Xprivate void       set_path(String);
  798. Xprivate void       set_icon(String, Boolean);
  799. Xprivate void       set_deficon(String);
  800. Xprivate void       set_ignore(void);
  801. Xprivate void       newselection(String);
  802. Xprivate void       setapp(int, String);
  803. X
  804. X/* imported variables/procedures */
  805. Xextern int parseerror;            /* quantity of parse errors so far */
  806. Xextern int yylineno;              /* line number being parsed */
  807. Xextern void yyerror(char *, ...); /* normal error printing routine */
  808. X
  809. X#ifndef DEBUG_YACC
  810. Xextern Widget topLevel;
  811. X#endif
  812. X
  813. X/* Variable declarations */
  814. Xpublic  AppSelection **appselections;
  815. Xpublic  typePrefs     *prefs;          /* preferneces */
  816. Xprivate varStack      *varframe;       /* stack frames */
  817. Xprivate iconTree      *icontable;      /* table of pixmaps */
  818. Xprivate char          *ptr;            /* general use pointer */
  819. Xprivate AppSelection  *current_selection;
  820. Xprivate Cardinal       listindex;      /* index into current appprogram list */
  821. Xprivate Cardinal       currentlistmax; /* current list appprogram size */
  822. Xpublic  Cardinal       selectionindex; /* index into appselections */
  823. X
  824. X%} /* Start of YACC declarations */
  825. X
  826. X%start xdtmrc    
  827. X
  828. X%union                              /* valid types */
  829. X{
  830. X    int  number;                     /* number */
  831. X    char *string;                    /* string */
  832. X}
  833. X
  834. X/* declare terminals with their types */
  835. X
  836. X%token <string> STRING_T
  837. X%token <number> IF_T SET_T ICON_T NAME_T PATH_T DEFICON_T TYPE_T CHECKPATH_T
  838. X%token <number> TRUE_T FALSE_T IGNORE_T
  839. X%token <number> DIR_T FILE_T READ_T WRITE_T EXE_T BLOCK_T CHARACTER_T SLINK_T
  840. X%token <number> SOCKET_T FIFO_T
  841. X%token <number> MSEL_T OSEL_T NSEL_T DEFINE_T PROG_T OPTIONS_T
  842. X%token <number> ASSIGN_T EQUAL_T SEMIC_T COMMA_T
  843. X%token <number> O_PAR_T C_PAR_T O_BRACE_T C_BRACE_T
  844. X%token <value>  EOFTOKEN ERRORTOKEN
  845. X
  846. X/* types of non-terminals */
  847. X%type <string> identifier
  848. X%type <number> block type var option xdtmrc
  849. X
  850. X%%    /* Beginning of rule section */
  851. X
  852. Xxdtmrc       :   { init_structs(); } 
  853. X                 statements 
  854. X                 { free_structs(); }
  855. X             ;
  856. Xstatements   :   /* Empty */
  857. X             |   statements statement 
  858. X             ;
  859. Xstatement    :   ifstatement
  860. X             |   setstatement SEMIC_T
  861. X             |   define
  862. X             ;
  863. Xifstatement  :   IF_T O_PAR_T expression C_PAR_T block
  864. X             ;
  865. Xsetstatement :   SET_T var ASSIGN_T identifier { switch ($2) {
  866. X                                                 case PATH_T:
  867. X                                                   set_path($4);
  868. X                           break;
  869. X                         case ICON_T:
  870. X                           set_icon($4, False);
  871. X                           break;
  872. X                         case DEFICON_T:
  873. X                           set_deficon($4);
  874. X                           break;
  875. X                         }
  876. X                           }
  877. X             |   SET_T CHECKPATH_T ASSIGN_T TRUE_T 
  878. X                       { varframe->checkpath = True; }
  879. X             |   SET_T CHECKPATH_T ASSIGN_T FALSE_T 
  880. X                       { varframe->checkpath = False; }
  881. X             |   SET_T IGNORE_T
  882. X                       { set_icon("", True);}
  883. X             ;
  884. Xdefine       :   DEFINE_T identifier {newselection($2);} ASSIGN_T defineblock
  885. X             ;
  886. Xblock        :   O_BRACE_T
  887. X                 statements {end_block();} 
  888. X                 C_BRACE_T
  889. X             ;
  890. Xdefineblock  :   O_BRACE_T descriptions C_BRACE_T 
  891. X                 {current_selection->number = listindex;}
  892. X             ;
  893. Xdescriptions :   /* Empty */
  894. X             |   descriptions description 
  895. X             ;
  896. Xdescription  :   O_BRACE_T 
  897. X
  898. X                 { /* Allocate a new AppProgram */
  899. X           
  900. X           current_selection->list[listindex] = 
  901. X             (AppProgram*) XtMalloc (sizeof(AppProgram));
  902. X         }
  903. X
  904. X                 NAME_T ASSIGN_T identifier SEMIC_T {setapp($3, $5);}
  905. X         ICON_T ASSIGN_T identifier SEMIC_T {setapp($8, $10);}
  906. X                 PROG_T ASSIGN_T identifier SEMIC_T {setapp($13, $15);}
  907. X                 OPTIONS_T ASSIGN_T option SEMIC_T  
  908. X                 {
  909. X           setapp($18, (String)$20);
  910. X
  911. X                  /* Increment listindex, Thanks to Johan Widen for catching
  912. X           * a bug here in version 1.0.
  913. X           */
  914. X           if (++listindex == currentlistmax) {
  915. X             currentlistmax += APPPINC;
  916. X             current_selection->list = 
  917. X               (AppProgram**) XtRealloc (current_selection->list,
  918. X                        sizeof(AppProgram*) *
  919. X                        currentlistmax);
  920. X           }
  921. X         }
  922. X
  923. X                 C_BRACE_T
  924. X             ;
  925. Xoption       :   MSEL_T | OSEL_T | NSEL_T
  926. X             ;
  927. Xexpression   :   NAME_T EQUAL_T identifier { new_re($3); }
  928. X             |   TYPE_T EQUAL_T type       { new_type($3); }
  929. X             ;
  930. Xidentifier   :   STRING_T      {  $$=strip_quotes($1);
  931. X                   }
  932. X             ;
  933. Xtype         :   DIR_T   | READ_T      | WRITE_T | EXE_T   | FILE_T   |
  934. X                 BLOCK_T | CHARACTER_T | FIFO_T  | SLINK_T | SOCKET_T
  935. X             ;
  936. Xvar          :   PATH_T | ICON_T | DEFICON_T
  937. X             ;
  938. X%%  
  939. X
  940. X/*****************************************************************************
  941. X *                               init_structs                                *
  942. X *****************************************************************************/
  943. Xprivate void init_structs(void)
  944. X{
  945. X  /* Initialise structures.. wow what a suprise :-) */
  946. X
  947. X  Cardinal n;
  948. X  
  949. X  /* Icon prefs = an empty type pref */
  950. X  prefs = newTypePref();
  951. X  
  952. X  /* Icon table is empty, no icons loaded yet */
  953. X  icontable = NULL;
  954. X
  955. X  /* Default top level stack frame */
  956. X  varframe = (varStack*) XtMalloc (sizeof(varStack));
  957. X  varframe->defpath = stringtopath("/usr/lib/X11/bitmaps", &n);
  958. X  varframe->dirinpath = n;
  959. X  varframe->current = prefs;
  960. X  varframe->checkpath = False;
  961. X  varframe->iconpref = NULL;
  962. X  varframe->next = NULL;
  963. X
  964. X  /* initialise the Application Selection Lists Array */
  965. X  listindex = 0;    /* First entry in the new selection list */
  966. X  selectionindex = -1;  /* First selection list is 0 in the array */
  967. X  appselections = (AppSelection**) XtMalloc (sizeof(AppSelection*) * APPPSIZE);
  968. X}
  969. X
  970. X/*****************************************************************************
  971. X *                              free_structs                                 *
  972. X *****************************************************************************/
  973. Xprivate void free_structs(void)
  974. X{
  975. X  /* This procedure is called just before the parsing finishes, it free's
  976. X   * the memory allocated to the internal structures used by the parser.
  977. X   * Note: Doesn't get all of them.. but let's not get petty, what's a few
  978. X   *       bytes once only in a program of this size?
  979. X   */
  980. X
  981. X  /* Free varstack (Should be only one level left) */
  982. X  XtFree(varframe);
  983. X
  984. X  selectionindex++; /* So that we know the correct number of selections */
  985. X}
  986. X
  987. X/*****************************************************************************
  988. X *                                newTypePref                                *
  989. X *****************************************************************************/
  990. Xpublic typePrefs *newTypePref(void)
  991. X{
  992. X  /* Allocate the memory for a new empty typePref, I suppose this 
  993. X   * procedure is not really needed on most machines, but what if
  994. X   * a machine doesn't automatically fill all entries in a structure
  995. X   * with NULL's ?
  996. X   */
  997. X
  998. X  typePrefs *tp;
  999. X
  1000. X  tp = (typePrefs*) XtMalloc (sizeof(typePrefs));
  1001. X  tp->iconprefs = NULL;
  1002. X  tp->dir = NULL;
  1003. X  tp->file = NULL;
  1004. X  tp->block = NULL;
  1005. X  tp->character = NULL;
  1006. X  tp->fifo = NULL;
  1007. X  tp->slink = NULL;
  1008. X  tp->socket = NULL;
  1009. X  tp->exe = NULL;
  1010. X  tp->read = NULL;
  1011. X  tp->write = NULL;
  1012. X  
  1013. X  return(tp);
  1014. X}
  1015. X
  1016. X/*****************************************************************************
  1017. X *                                start_block                                *
  1018. X *****************************************************************************/
  1019. Xprivate void start_block(typePrefs *newpref, iconPrefs *iconpref)
  1020. X{
  1021. X  /* A new block has been entered, create a new stack frame, inherit most
  1022. X   * stuff from the previous stack frame.
  1023. X   */
  1024. X
  1025. X  /* Push new stack frame */
  1026. X  varStack *newframe;
  1027. X  
  1028. X  newframe = (varStack*) XtMalloc (sizeof(varStack));
  1029. X  newframe->defpath = varframe->defpath;
  1030. X  newframe->dirinpath = varframe->dirinpath;
  1031. X  newframe->current = newpref;
  1032. X  newframe->checkpath = varframe->checkpath;
  1033. X  newframe->iconpref = iconpref;
  1034. X  newframe->next = varframe;
  1035. X  varframe = newframe;
  1036. X}
  1037. X
  1038. X/*****************************************************************************
  1039. X *                                    end_block                              *
  1040. X *****************************************************************************/
  1041. Xprivate void end_block(void)
  1042. X{
  1043. X  /* End the current stack frame, check to see if the extra part of
  1044. X   * the iconPref has been used, if not free it.
  1045. X   * Pop the current stack from off the stack.
  1046. X   */
  1047. X
  1048. X  iconPrefs *tmpIconPref;
  1049. X  typePrefs *tmp = varframe->current;
  1050. X  varStack *tmpframe = varframe->next;
  1051. X
  1052. X  if (tmp->iconprefs == NULL && tmp->dir == NULL &&
  1053. X      tmp->file == NULL      && tmp->exe == NULL &&
  1054. X      tmp->read == NULL      && tmp->write == NULL) {
  1055. X    XtFree(tmp);
  1056. X    tmp = NULL;
  1057. X    tmpIconPref = varframe->iconpref;
  1058. X    tmpIconPref->extra = NULL;
  1059. X  }
  1060. X  XtFree(varframe);
  1061. X  varframe = tmpframe;
  1062. X}
  1063. X
  1064. X/*****************************************************************************
  1065. X *                                     new_re                                *
  1066. X *****************************************************************************/
  1067. Xprivate void new_re(String re)
  1068. X{
  1069. X  /* Create a new iconpref, put the compiled regular expression in it then
  1070. X   * insert it into the current iconprefs.
  1071. X   *
  1072. X   * - Takes a regular expression in the original string format. eg. "\.c$"
  1073. X   */
  1074. X
  1075. X  iconPrefs *new, *tmp = varframe->current->iconprefs;
  1076. X
  1077. X  new = (iconPrefs*) XtMalloc (sizeof(iconPrefs));
  1078. X  new->next = NULL;
  1079. X  new->expbuf = (char*) XtMalloc (sizeof(char) * ESIZE);
  1080. X  new->extra = (XtPointer) newTypePref();
  1081. X  compile(re, new->expbuf, &(new->expbuf[ESIZE]), '\0');
  1082. X  new->circf = circf;
  1083. X  new->checkpath = varframe->checkpath;
  1084. X  new->icon = NULL;
  1085. X  varframe->current->iconprefs = inserticonpref(tmp, new);
  1086. X  start_block((typePrefs*)new->extra, (iconPrefs*)new);
  1087. X}
  1088. X
  1089. X/*****************************************************************************
  1090. X *                               new_type                                    *
  1091. X *****************************************************************************/
  1092. Xprivate void new_type(int n)
  1093. X{
  1094. X  /* Allocate a typePref on dir, write etc. if neadbe, otherwise ignore 
  1095. X   *
  1096. X   * - Takes a number representing which file feature to insert the typePref
  1097. X   *   on.
  1098. X   */
  1099. X
  1100. X  typePrefs *typeprefs = varframe->current;
  1101. X  typePrefs *newpref;
  1102. X
  1103. X  switch(n) {
  1104. X  case DIR_T:
  1105. X    if (typeprefs->dir == NULL) 
  1106. X      typeprefs->dir = newTypePref();
  1107. X    newpref = typeprefs->dir;
  1108. X    break;
  1109. X  case FILE_T:
  1110. X    if (typeprefs->file == NULL) 
  1111. X      typeprefs->file = newTypePref();
  1112. X    newpref = typeprefs->file;
  1113. X    break;
  1114. X  case BLOCK_T:
  1115. X    if (typeprefs->block == NULL) 
  1116. X      typeprefs->block = newTypePref();
  1117. X    newpref = typeprefs->block;
  1118. X    break;
  1119. X  case CHARACTER_T:
  1120. X    if (typeprefs->character == NULL) 
  1121. X      typeprefs->character = newTypePref();
  1122. X    newpref = typeprefs->character;
  1123. X    break;
  1124. X  case FIFO_T:
  1125. X    if (typeprefs->fifo == NULL) 
  1126. X      typeprefs->fifo = newTypePref();
  1127. X    newpref = typeprefs->fifo;
  1128. X    break;
  1129. X  case SLINK_T:
  1130. X    if (typeprefs->slink == NULL) 
  1131. X      typeprefs->slink = newTypePref();
  1132. X    newpref = typeprefs->slink;
  1133. X    break;
  1134. X  case SOCKET_T:
  1135. X    if (typeprefs->socket == NULL) 
  1136. X      typeprefs->socket = newTypePref();
  1137. X    newpref = typeprefs->socket;
  1138. X    break;
  1139. X  case EXE_T:
  1140. X    if (typeprefs->exe == NULL) 
  1141. X      typeprefs->exe = newTypePref();
  1142. X    newpref = typeprefs->exe;
  1143. X    break;
  1144. X  case READ_T:
  1145. X    if (typeprefs->read == NULL) 
  1146. X      typeprefs->read = newTypePref();
  1147. X    newpref = typeprefs->read;
  1148. X    break;
  1149. X  case WRITE_T:
  1150. X    if (typeprefs->write == NULL) 
  1151. X      typeprefs->write = newTypePref();
  1152. X    newpref = typeprefs->write;
  1153. X    break;
  1154. X  }
  1155. X  start_block(newpref, NULL);
  1156. X}
  1157. X
  1158. X/*****************************************************************************
  1159. X *                                   count_chr                               *
  1160. X *****************************************************************************/
  1161. Xpublic Cardinal count_chr(String s, char c)
  1162. X{
  1163. X  /* Given a String and a character this function counts the number of
  1164. X   * occurences of that character in the string and returns the result.
  1165. X   *
  1166. X   * - Takes a string s within which to check for character c.
  1167. X   */
  1168. X
  1169. X  Cardinal count=0;
  1170. X
  1171. X  while(*s != '\0') {
  1172. X    if (*s == c) count++;
  1173. X    s++;
  1174. X  }
  1175. X  return count;
  1176. X}
  1177. X
  1178. X/*****************************************************************************
  1179. X *                                  stringtopath                             *
  1180. X *****************************************************************************/
  1181. Xprivate String *stringtopath(String s, Cardinal *n)
  1182. X{
  1183. X  /* Split a path into directories, put these into a linked list
  1184. X   * only directories starting with / or ~/ are allowed.
  1185. X   *
  1186. X   * - Takes a string containing the path delimited by colons, and 
  1187. X   *   a pointer within which the number of directories in the
  1188. X   *   path is left.
  1189. X   * + Returns an array of directories.
  1190. X   */
  1191. X  String *result;
  1192. X  String p, tmp;
  1193. X#ifdef DEBUG_YACC
  1194. X  String home;
  1195. X#else
  1196. X  extern String home;
  1197. X#endif
  1198. X
  1199. X  *n = 0;
  1200. X
  1201. X#ifdef DEBUG_YACC
  1202. X    if ((home = (String) getenv("HOME")) == NULL) {
  1203. X    fprintf(stderr, "can\'t get environment variable HOME\n");
  1204. X    home = XtNewString("/");
  1205. X  } else 
  1206. X    home = XtNewString(home);
  1207. X#endif
  1208. X
  1209. X  result = (String*) XtMalloc ((count_chr(s, ':')+3) * sizeof(String));
  1210. X  s = XtNewString(s);
  1211. X
  1212. X  /* extract the directories from path 's' */
  1213. X
  1214. X  p = strtok(s, ":");
  1215. X  while ( p != NULL) {
  1216. X    if (*p == '/')
  1217. X      result[(*n)++] = p;
  1218. X    else 
  1219. X      if (*p == '~' && *(p+1) == '/') {
  1220. X    tmp = (String) XtMalloc ((strlen(home) + strlen(p) + 2) * sizeof(char));
  1221. X    strcpy(tmp, home);
  1222. X    strcat(tmp, p+1);
  1223. X    result[(*n)++] = tmp;
  1224. X      } else
  1225. X    fprintf(stderr, "Warning: Directory \'%s\' not fully qualified,"
  1226. X        " ignoring.\n"
  1227. X        "         Must start with either / or ~/ .\n", p);
  1228. X    p = strtok(NULL, ":");
  1229. X  }
  1230. X#ifdef DEBUG_YACC
  1231. X  XtFree(home);
  1232. X#endif
  1233. X  return(result);
  1234. X}
  1235. X
  1236. X/*****************************************************************************
  1237. X *                             inserticonpref                                *
  1238. X *****************************************************************************/
  1239. Xprivate iconPrefs *inserticonpref(iconPrefs *head, iconPrefs *item)
  1240. X{
  1241. X  /* Insert item into list starting with head, insert into the last 
  1242. X   * position before the default.
  1243. X   *
  1244. X   * - Takes the head of the iconpref list and the iconpref list entry to 
  1245. X   *   be inserted.
  1246. X   * + Returns the new iconpref list with the item inserted.
  1247. X   */
  1248. X
  1249. X  iconPrefs *sec = NULL, *tmp = head;
  1250. X
  1251. X  if (head == NULL) {
  1252. X    /* first element */
  1253. X    head=item;
  1254. X    head->next=NULL;
  1255. X  } else {
  1256. X    while (tmp->next != NULL) {
  1257. X      sec = tmp;
  1258. X      tmp = tmp->next;
  1259. X    }
  1260. X    if (tmp->expbuf == NULL) {
  1261. X      /* Already got a default */
  1262. X      if (item->expbuf != NULL) {
  1263. X    /* Item is not a new default */
  1264. X    item->next = tmp;
  1265. X    if (sec != NULL)
  1266. X      sec->next = item;
  1267. X    else 
  1268. X      head = item;
  1269. X      } else 
  1270. X    XtFree(item);
  1271. X    } else {
  1272. X      /* No default */
  1273. X      tmp->next = item;
  1274. X      item->next = NULL;
  1275. X    }
  1276. X  }
  1277. X  return(head);
  1278. X}
  1279. X
  1280. X/*****************************************************************************
  1281. X *                                    getlast                                *
  1282. X *****************************************************************************/
  1283. Xprivate iconPrefs *getlast(iconPrefs *head)
  1284. X{
  1285. X  /* return the last non-default iconpref in the frame 
  1286. X   *
  1287. X   * - Takes the head of the iconpref list
  1288. X   * + Returns the last non-default iconpref in that iconpref list
  1289. X   */
  1290. X
  1291. X  iconPrefs *tmp = head;
  1292. X  
  1293. X  if (tmp != NULL)
  1294. X    while (tmp->next != NULL || tmp->next->expbuf == NULL) 
  1295. X      tmp = tmp->next;
  1296. X
  1297. X  return(tmp);
  1298. X}
  1299. X
  1300. X/*****************************************************************************
  1301. X *                              strip_quotes                                 *
  1302. X *****************************************************************************/
  1303. Xprivate String strip_quotes(String s)
  1304. X{
  1305. X  /* This function is for stripping the first and last characters from a 
  1306. X   * string. It is used for stripping the quotes off strings.
  1307. X   *
  1308. X   * - Takes a String with quotes.
  1309. X   * - Returns the String with quotes missing.
  1310. X   */
  1311. X  String new;
  1312. X  
  1313. X  *(s + (strlen(s)-1)) = '\0';
  1314. X  s=s+1;
  1315. X  new = XtNewString(s);
  1316. X
  1317. X  /* s is NOT free'd because it was supplied from the lexical analyzer,
  1318. X   * it's up to that to free it.
  1319. X   */
  1320. X  return(new);
  1321. X}
  1322. X
  1323. X/*****************************************************************************
  1324. X *                                 set_path                                  *
  1325. X *****************************************************************************/
  1326. Xprivate void set_path(String s)
  1327. X{
  1328. X  /* Given a string containing a list of directories delimited by colons
  1329. X   * this procedure inserts these directories in teh form of an array of
  1330. X   * strings into the current stack frame.
  1331. X   */
  1332. X  Cardinal n;
  1333. X
  1334. X  varframe->defpath = stringtopath(s, &n);
  1335. X  varframe->dirinpath = n;
  1336. X}
  1337. X
  1338. X/*****************************************************************************
  1339. X *                                set_icon                                   *
  1340. X *****************************************************************************/
  1341. Xprivate void set_icon(String s, Boolean ignore)
  1342. X{
  1343. X  /* varframe->iconpref points to the iconpref into which this
  1344. X   * icon should be inserted. If it is NULL, then create a new
  1345. X   * one at varframe->current->iconprefs.
  1346. X   *
  1347. X   * - Takes an icon filename and/or a flag saying whether the current
  1348. X   *   iconpref should be ignored.
  1349. X   */
  1350. X
  1351. X  typePrefs *frame = varframe->current;
  1352. X  iconPrefs *iconpref = varframe->iconpref, 
  1353. X            *head = frame->iconprefs,
  1354. X            *new =  NULL;
  1355. X
  1356. X  if (iconpref == NULL) {
  1357. X    new = (iconPrefs*) XtMalloc (sizeof(iconPrefs));
  1358. X    new->expbuf = NULL;  /* default icon */
  1359. X    new->extra = NULL;
  1360. X    if (ignore==True) {
  1361. X      new->icon = DUMMY;
  1362. X    } else {
  1363. X      new->icon = lookupicon(s);
  1364. X    }
  1365. X    new->next = NULL;
  1366. X    frame->iconprefs = inserticonpref(head, new);
  1367. X  } else 
  1368. X    if (ignore==True)
  1369. X      iconpref->icon = DUMMY;
  1370. X    else
  1371. X      iconpref->icon = lookupicon(s);
  1372. X
  1373. X}
  1374. X
  1375. X/*****************************************************************************
  1376. X *                                set_deficon                                *
  1377. X *****************************************************************************/
  1378. Xprivate void set_deficon(String s)
  1379. X{
  1380. X  /* Set the default icon in the current iconprefs list.
  1381. X   *
  1382. X   * - Takes the filename of the icon to be used.
  1383. X   */
  1384. X
  1385. X  typePrefs *frame = varframe->current;
  1386. X  iconPrefs *iconpref, *head = frame->iconprefs;
  1387. X
  1388. X  iconpref = (iconPrefs*) XtMalloc (sizeof(iconPrefs));
  1389. X  iconpref->expbuf = NULL;  /* default icon */
  1390. X  iconpref->extra = NULL;
  1391. X  iconpref->icon = lookupicon(s);
  1392. X  iconpref->next = NULL;
  1393. X  frame->iconprefs = inserticonpref(head, iconpref);
  1394. X
  1395. X}
  1396. X
  1397. X/*****************************************************************************
  1398. X *                             lookupicon                                    *
  1399. X *****************************************************************************/
  1400. Xprivate Pixmap lookupicon(String icon)
  1401. X{
  1402. X  /* Return the pixmap associated with the name 'icon' if none 
  1403. X   * found NULL is returned.
  1404. X   */
  1405. X
  1406. X  typePrefs *frame = varframe->current;
  1407. X  String *path = varframe->defpath;
  1408. X  Cardinal pathsize = varframe->dirinpath;
  1409. X  Cardinal n;
  1410. X  iconTree *item;
  1411. X  Pixmap pixmap = NULL;
  1412. X  String fullname = NULL;
  1413. X  String tmp;
  1414. X  FILE *result;
  1415. X
  1416. X  /* Append 'icon' to each filename in current path, and check to see 
  1417. X   * whether that file exists.
  1418. X   */
  1419. X  
  1420. X  n = 0;
  1421. X  do {
  1422. X    tmp = (String) XtMalloc ((strlen(icon) + strlen(path[n]) + 4) * sizeof(char));
  1423. X    tmp = strcpy(tmp, path[n]);
  1424. X    tmp = strcat(tmp, "/");
  1425. X    tmp = strcat(tmp, icon);
  1426. X    if ((result = fopen(tmp, "r")) != NULL) {
  1427. X      fullname = XtNewString(tmp);
  1428. X      fclose(result);
  1429. X    } 
  1430. X    XtFree(tmp);
  1431. X  } while (++n < pathsize && fullname == NULL);
  1432. X
  1433. X  if (fullname == NULL) 
  1434. X    fprintf(stderr, "Warning: could not find icon %s,"
  1435. X        " default icon will be used instead.\n", icon);
  1436. X  else {
  1437. X    item = (iconTree*) XtMalloc (sizeof(iconTree));
  1438. X    item->fullname = fullname;
  1439. X    item->icon = NULL;
  1440. X    icontable = get_pixmap(item, icontable);
  1441. X    pixmap = item->icon;
  1442. X  }
  1443. X  return(pixmap);
  1444. X}
  1445. X
  1446. X/*****************************************************************************
  1447. X *                               get_pixmap                                  *
  1448. X *****************************************************************************/
  1449. Xprivate iconTree *get_pixmap(iconTree *item, iconTree *tree)
  1450. X{
  1451. X  /* If the item is found in the tree, then item's contents are filled 
  1452. X   * with that items, otherwise the Pixmap is created and the item is 
  1453. X   * inserted into the tree.
  1454. X   */
  1455. X
  1456. X  int cmp, value;
  1457. X  unsigned int width, height;
  1458. X  int x_hot, y_hot;
  1459. X
  1460. X  if (tree == NULL) {
  1461. X    /* At a leaf, insert item */
  1462. X#ifndef DEBUG_YACC
  1463. X    value = XReadBitmapFile(XtDisplay(topLevel), 
  1464. X                RootWindowOfScreen(XtScreen(topLevel)),
  1465. X                item->fullname,
  1466. X                &width, &height,
  1467. X                &item->icon,
  1468. X                &x_hot, &y_hot);
  1469. X    if (value == BitmapFileInvalid)
  1470. X      fprintf(stderr, "Filename \'%s\' contains invalid bitmap data\n", 
  1471. X          item->fullname);
  1472. X    else if (value == BitmapOpenFailed)
  1473. X      fprintf(stderr, "Filename \'%s\' could not be opened\n", 
  1474. X          item->fullname);
  1475. X    else if (value == BitmapNoMemory)
  1476. X      fprintf(stderr, "Not enough memory to allocate pixmap\n");
  1477. X#else
  1478. X    item->icon = (Pixmap) DUMMY;
  1479. X    printf("DEBUG: Loaded bitmap for %s\n", item->fullname);
  1480. X#endif
  1481. X    item->left = NULL;
  1482. X    item->right = NULL;
  1483. X    tree = item;
  1484. X  } else {
  1485. X    if ((cmp = strcmp(tree->fullname, item->fullname)) == 0) {
  1486. X      /* Found it !!! */
  1487. X      item->icon = tree->icon;
  1488. X    } else 
  1489. X      if (cmp < 0)
  1490. X    tree->left = get_pixmap(item, tree->left);
  1491. X      else 
  1492. X    tree->right = get_pixmap(item, tree->right);
  1493. X  }
  1494. X  return(tree);
  1495. X}
  1496. X
  1497. X/*****************************************************************************
  1498. X *                              newselection                                 *
  1499. X *****************************************************************************/
  1500. Xprivate void newselection(String selection)
  1501. X{
  1502. X  /* increment selectionindex, put selection string into next 
  1503. X   * appselection, increase size if appselections array if needed.
  1504. X   * 
  1505. X   * - Takes the name of the new selection
  1506. X   */
  1507. X
  1508. X  static selectionmax = APPPSIZE;
  1509. X  
  1510. X  if (++selectionindex == selectionmax) {
  1511. X    selectionmax += APPPINC;
  1512. X    appselections = (AppSelection **) XtRealloc (appselections, 
  1513. X                         sizeof(AppSelection*) *
  1514. X                         selectionmax);
  1515. X  }
  1516. X
  1517. X#ifdef DEBUG_YACC
  1518. X  printf("DEBUG: New selection %s\n", selection);
  1519. X#endif
  1520. X  
  1521. X  listindex = 0;
  1522. X  current_selection = appselections[selectionindex] =
  1523. X    (AppSelection*) XtMalloc (sizeof(AppSelection));
  1524. X  current_selection->name = XtNewString(selection);
  1525. X  current_selection->number = listindex;
  1526. X  current_selection->list = (AppProgram**) XtMalloc (sizeof(AppProgram*) * 
  1527. X                             APPPSIZE);
  1528. X  currentlistmax = APPPSIZE;
  1529. X}
  1530. X
  1531. X/*****************************************************************************
  1532. X *                               setapp                                      *
  1533. X *****************************************************************************/
  1534. Xprivate void setapp(int type, String argument)
  1535. X{
  1536. X  /* Set part of the current program in the current selection list,
  1537. X   * the part to be set is contained in type, the value it is to be set
  1538. X   * to contained within argument.
  1539. X   */
  1540. X
  1541. X  AppProgram **proglist = current_selection->list;
  1542. X  AppProgram *node = proglist[listindex];
  1543. X  
  1544. X  switch(type) {
  1545. X  case NAME_T:
  1546. X    node->string = XtNewString(argument);
  1547. X#ifdef DEBUG_YACC
  1548. X    printf("String: %s\n", argument);
  1549. X#endif
  1550. X    break;
  1551. X  case ICON_T:
  1552. X    node->icon = lookupicon(argument);
  1553. X    break;
  1554. X  case PROG_T:
  1555. X    node->program = XtNewString(argument);
  1556. X#ifdef DEBUG_YACC
  1557. X    printf("Program: %s\n", argument);
  1558. X#endif
  1559. X    break;
  1560. X  case OPTIONS_T:
  1561. X    switch((int)argument) {
  1562. X    case MSEL_T:
  1563. X      node->options = M_SEL;
  1564. X#ifdef DEBUG_YACC
  1565. X      printf("MSEL\n");
  1566. X#endif
  1567. X      break;
  1568. X    case OSEL_T:
  1569. X      node->options = O_SEL;
  1570. X#ifdef DEBUG_YACC
  1571. X      printf("OSEL\n");
  1572. X#endif      
  1573. X      break;
  1574. X    case NSEL_T:
  1575. X      node->options = N_SEL;
  1576. X#ifdef DEBUG_YACC
  1577. X      printf("NSEL\n");
  1578. X#endif
  1579. X      break;
  1580. X    default:
  1581. X      fprintf(stderr, "Programmer Error: Bad argument to setapp.\n");
  1582. X      break;
  1583. X    }
  1584. X    break;
  1585. X  default:
  1586. X    fprintf(stderr, "Programmer Error: Bad argument to setapp.\n");
  1587. X    break;
  1588. X  }
  1589. X}
  1590. X
  1591. X#ifdef DEBUG_YACC
  1592. X
  1593. X/*****************************************************************************
  1594. X *                                 main                                      *
  1595. X *****************************************************************************/
  1596. Xmain()
  1597. X{
  1598. X  /* main for use when the real main is not linked, because we in debug mode.
  1599. X   */
  1600. X
  1601. X  yyparse();   /* Parse the stdin */
  1602. X  return(0);   /* Hey, it probably worked */
  1603. X}
  1604. X#endif
  1605. X
  1606. X
  1607. X
  1608. X
  1609. SHAR_EOF
  1610. chmod 0644 xdtm/parser.y ||
  1611. echo 'restore of xdtm/parser.y failed'
  1612. Wc_c="`wc -c < 'xdtm/parser.y'`"
  1613. test 27319 -eq "$Wc_c" ||
  1614.     echo 'xdtm/parser.y: original size 27319, current size' "$Wc_c"
  1615. fi
  1616. true || echo 'restore of xdtm/patchlevel.h failed'
  1617. echo End of part 10, continue with part 11
  1618. exit 0
  1619.  
  1620. --
  1621. Dan Heller
  1622. O'Reilly && Associates       Z-Code Software    Comp-sources-x:
  1623. Senior Writer                President          comp-sources-x@uunet.uu.net
  1624. argv@ora.com                 argv@zipcode.com
  1625.