home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / xmps / part02 < prev    next >
Encoding:
Text File  |  1993-06-14  |  54.3 KB  |  2,154 lines

  1. Newsgroups: comp.sources.x
  2. From: jjm@hplb.hpl.hp.com (Jean-Jacques Moreau)
  3. Subject: v20i027:  xmps - Motif process monitor, Part02/03
  4. Message-ID: <1993Jun15.140923.17040@sparky.imd.sterling.com>
  5. X-Md4-Signature: 8d9d13712f857f833b108e8d209c12f3
  6. Sender: chris@sparky.imd.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 15 Jun 1993 14:09:23 GMT
  9. Approved: chris@sparky.imd.sterling.com
  10.  
  11. Submitted-by: jjm@hplb.hpl.hp.com (Jean-Jacques Moreau)
  12. Posting-number: Volume 20, Issue 27
  13. Archive-name: xmps/part02
  14. Environment: HP-UX, X11. OSF/Motif
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  command.c format.c process.c search.c snapshot.c status.c
  21. #   xmps.h
  22. # Wrapped by chris@sparky on Tue Jun 15 08:52:05 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 2 (of 3)."'
  26. if test -f 'command.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'command.c'\"
  28. else
  29.   echo shar: Extracting \"'command.c'\" \(5589 characters\)
  30.   sed "s/^X//" >'command.c' <<'END_OF_FILE'
  31. X#include <Xm/Xm.h>
  32. X
  33. X#include <stdio.h>
  34. X#include <unistd.h>
  35. X#include <string.h>
  36. X#include <sys/ioctl.h>
  37. X#include <sys/fcntl.h>
  38. X#include <sys/signal.h>
  39. X#include <sys/wait.h>
  40. X#include <errno.h>
  41. X
  42. X#include "xmps.h"
  43. X
  44. X
  45. Xtypedef struct _BufferRec {
  46. X     String data;
  47. X     int len;
  48. X} BufferStruct, *BufferRec;
  49. X
  50. X
  51. Xtypedef struct _CommandRec {
  52. X     XtInputId outputId;
  53. X     int outputPipe[2];
  54. X     BufferStruct outputBuffer;
  55. X     XtInputId errorId;
  56. X     int errorPipe[2];
  57. X     BufferStruct errorBuffer;
  58. X} CommandStruct, *CommandRec;
  59. X
  60. X
  61. XBoolean childDied (clientData)
  62. X     XtPointer clientData;
  63. X{
  64. X     int *pid = (int *) clientData;
  65. X     
  66. X     /*
  67. X      * This function just prevents XtProcessEvent() to hang if
  68. X      * our child dies when it is being executed and there is no
  69. X      * data left in the pipes : XtProcessEvent() will exit after
  70. X      * calling that function, instead of blocking on select().
  71. X      */
  72. X
  73. X     return (waitpid (*pid, NULL, WNOHANG));
  74. X}
  75. X
  76. X      
  77. Xvoid readInput (pipe, buffer)
  78. X     int pipe;
  79. X     BufferRec buffer;
  80. X{
  81. X     char tempbuf[BUFSIZ];
  82. X     long charsCount;
  83. X     int oldPipeMode;
  84. X
  85. X     /*
  86. X      * Set the read mode of the pipe to non-blocking.
  87. X      */
  88. X     if ((oldPipeMode = fcntl (pipe, F_GETFL)) == -1) {
  89. X      error ("Cannot get ouput of command", (char *) 0);
  90. X      return;
  91. X     }
  92. X     if (fcntl (pipe, F_SETFL, (oldPipeMode | O_NONBLOCK)) == -1) {
  93. X      error ("Cannot get output of command", (char *) 0);
  94. X      return;
  95. X     }
  96. X     
  97. X     /*
  98. X      * Read as many characters as are available.
  99. X      */
  100. X     charsCount = read (pipe, tempbuf, BUFSIZ);
  101. X     while ((charsCount != 0) && (charsCount != -1)) {
  102. X      buffer->data = XtRealloc (buffer->data,
  103. X                    (Cardinal) (buffer->len + charsCount + 1));
  104. X      bcopy (tempbuf, buffer->data + buffer->len, charsCount);
  105. X      buffer->len = buffer->len + charsCount;
  106. X
  107. X      charsCount = read (pipe, tempbuf, BUFSIZ);
  108. X     }
  109. X
  110. X     /*
  111. X      * Restore the old pipe's mode, and return the output of ps.
  112. X      */
  113. X     (void) fcntl (pipe, F_SETFL, oldPipeMode);
  114. X
  115. X     if ((charsCount == -1) && (errno != EAGAIN)) {
  116. X      error ("Cannot read output of command", (char *) 0);
  117. X      return;
  118. X     }
  119. X
  120. X     if (buffer->data != NULL)
  121. X      buffer->data[buffer->len] = '\0';
  122. X     return;
  123. X}
  124. X
  125. X
  126. XXtInputCallbackProc inputReady (clientData, pipe, unused)
  127. X     XtPointer clientData;
  128. X     int *pipe;
  129. X     XtInputId *unused;
  130. X{
  131. X     BufferRec buffer = (BufferRec) clientData;
  132. X
  133. X     readInput (*pipe, buffer);
  134. X}
  135. X
  136. X
  137. XString executeCommand (argv)
  138. X     String *argv;
  139. X{
  140. X     CommandStruct command;
  141. X     int oldStdout, oldStderr;
  142. X     int pid;
  143. X     
  144. X     command.outputBuffer.data = NULL;
  145. X     command.outputBuffer.len = 0;
  146. X     command.errorBuffer.data = NULL;
  147. X     command.errorBuffer.len = 0;
  148. X
  149. X     /*
  150. X      * Redirect stdout to a pipe.
  151. X      */
  152. X     if (pipe (command.outputPipe) != -1) {
  153. X      oldStdout = dup (fileno (stdout));
  154. X      (void) dup2 (command.outputPipe[1], fileno (stdout));
  155. X     } else {
  156. X      error ("Cannot redirect standard output", (char *) 0);
  157. X      return (XtNewString (" \n"));
  158. X     }
  159. X     
  160. X     /*
  161. X      * Redirect stderr to a pipe too.
  162. X      */
  163. X     if (pipe (command.errorPipe) != -1) {
  164. X      oldStderr = dup (fileno (stderr));
  165. X      (void) dup2 (command.errorPipe[1], fileno (stderr));
  166. X     } else {
  167. X      error ("Cannot redirect standard error", (char *) 0);
  168. X      return (XtNewString (" \n"));
  169. X     }
  170. X     
  171. X     /*
  172. X      * Create a sub-process that will run ps.
  173. X      */
  174. X     if ((pid = fork ()) == -1) {
  175. X      error ("Cannot fork", (char *) 0);
  176. X      return (XtNewString (" \n"));
  177. X
  178. X     } else if (pid == 0) {
  179. X      /*
  180. X       * Close unused file descriptors.
  181. X       */
  182. X      close (fileno (stdin));
  183. X      close (oldStdout);
  184. X      close (oldStderr);
  185. X      close (command.outputPipe[0]);
  186. X      close (command.errorPipe[0]);
  187. X
  188. X      /*
  189. X       * Execute ps.
  190. X       */
  191. X      (void) execv (argv[0], argv);
  192. X
  193. X      /*
  194. X       * If we ever reach this point, then exec failed.
  195. X       */
  196. X      error ("Cannot run command", (char *) 0);
  197. X      return (XtNewString (" \n"));
  198. X
  199. X     } else {
  200. X      /*
  201. X       * Restore the original stdout and stderr.
  202. X       */
  203. X      dup2 (oldStdout, fileno (stdout));
  204. X      dup2 (oldStderr, fileno (stderr));
  205. X
  206. X      /*
  207. X       * Close unused file descriptors.
  208. X       */
  209. X      close (oldStdout);
  210. X      close (oldStderr);
  211. X      close (command.outputPipe[1]);
  212. X      close (command.errorPipe[1]);
  213. X
  214. X      /*
  215. X       * Install handlers to take care of pipes overflow.
  216. X       */
  217. X      command.outputId = XtAddInput (command.outputPipe[0],
  218. X                     (XtPointer) XtInputReadMask,
  219. X                     (XtInputCallbackProc) inputReady,
  220. X                     (XtPointer) &command.outputBuffer);
  221. X      command.errorId = XtAddInput (command.errorPipe[0],
  222. X                    (XtPointer) XtInputReadMask,
  223. X                    (XtInputCallbackProc) inputReady,
  224. X                    (XtPointer) &command.errorBuffer);
  225. X
  226. X      /*
  227. X       * Install a handlers to take care of dead locks.
  228. X       */
  229. X      XtAddWorkProc ((XtWorkProc) childDied, &pid);
  230. X
  231. X      /*
  232. X       * Read as much as we can to prevent pipe overflows
  233. X       * whilst our child is still alive.
  234. X       */
  235. X      while (!waitpid (pid, NULL, WNOHANG))
  236. X           XtProcessEvent (XtIMAlternateInput);
  237. X
  238. X      (void) waitpid (pid, NULL, 0);
  239. X      
  240. X      /*
  241. X       * Get the output of ps, if any.
  242. X       */
  243. X      readInput (command.outputPipe[0], &command.outputBuffer);
  244. X
  245. X      (void) close (command.outputPipe[0]);
  246. X      XtRemoveInput (command.outputId);
  247. X
  248. X      /*
  249. X       * Check for any errors.
  250. X       */
  251. X      readInput (command.errorPipe[0], &command.errorBuffer);
  252. X
  253. X      (void) close (command.errorPipe[0]);
  254. X      XtRemoveInput (command.errorId);
  255. X
  256. X      if (command.errorBuffer.data != NULL) {
  257. X           error (command.errorBuffer.data, (char *) 0);
  258. X           XtFree (command.errorBuffer.data);
  259. X      }
  260. X
  261. X      /*
  262. X       * Return the output of ps.
  263. X       */
  264. X      return (command.outputBuffer.data);
  265. X     }
  266. X}
  267. END_OF_FILE
  268.   if test 5589 -ne `wc -c <'command.c'`; then
  269.     echo shar: \"'command.c'\" unpacked with wrong size!
  270.   fi
  271.   # end of 'command.c'
  272. fi
  273. if test -f 'format.c' -a "${1}" != "-c" ; then 
  274.   echo shar: Will not clobber existing file \"'format.c'\"
  275. else
  276.   echo shar: Extracting \"'format.c'\" \(10822 characters\)
  277.   sed "s/^X//" >'format.c' <<'END_OF_FILE'
  278. X#include <Xm/Xm.h>
  279. X#include <Xm/XmStrDefs.h>
  280. X
  281. X#include <stdio.h>
  282. X#include <stdlib.h>
  283. X
  284. X#include "xmps.h"
  285. X
  286. X
  287. Xtypedef struct _Process {
  288. X     int pid;
  289. X     int ppid;
  290. X     String data;
  291. X     struct _Process *child;
  292. X     int childCount;
  293. X     struct _Process *brother;
  294. X     struct _Process *next;
  295. X     struct _Process *nexthash;
  296. X} *Process;
  297. X
  298. Xtypedef struct _ProcessList {
  299. X     Process first;
  300. X     Process *hashtable;
  301. X     Process root;
  302. X} *ProcessList;
  303. X
  304. Xtypedef struct _Field {
  305. X     int start;
  306. X     int end;
  307. X} *Field;
  308. X
  309. X
  310. XField pidField;
  311. XField ppidField;
  312. XField commandField;
  313. X
  314. Xint indentation = 2;
  315. Xint hashvalue = 97;
  316. X
  317. X
  318. XField newField (x, y)
  319. X     int x;
  320. X     int y;
  321. X{
  322. X     Field result;
  323. X
  324. X     result = (Field) XtMalloc (sizeof (*result));
  325. X
  326. X     result->start = x;
  327. X     result->end = y;
  328. X
  329. X     return (result);
  330. X}
  331. X
  332. X
  333. Xvoid deleteField (field)
  334. X     Field field;
  335. X{
  336. X     if (field != NULL) 
  337. X      XtFree ((char *) field);
  338. X}
  339. X
  340. X
  341. XField fieldPosition (string, name)
  342. X     String string;
  343. X     String name;
  344. X{
  345. X     Field field = newField (0, 0);
  346. X     String origin = string;
  347. X     String endOfString = string + strlen (string);
  348. X
  349. X     /*
  350. X      * Move to which'th field.
  351. X      */
  352. X     field->start = string - origin;
  353. X     string = string + strspn (string, " ");        /* Skip blank(s) */
  354. X     while (string < endOfString) {
  355. X      if (!strncmp (string, name, strlen (name))) {
  356. X           if ((string = strchr (string, ' ')) != NULL)
  357. X            field->end = string - origin;    /* To next blank(s) */
  358. X           else
  359. X            field->end = endOfString - origin;
  360. X           return (field);
  361. X      }
  362. X      if ((string = strchr (string, ' ')) == NULL)
  363. X           return (NULL);                /* To next blank(s) */
  364. X      field->start = string - origin;
  365. X      string = string + strspn (string, " ");    /* Skip them */
  366. X     }
  367. X
  368. X     return (NULL);
  369. X}
  370. X
  371. X
  372. Xint intFieldValue (string, field)
  373. X     String string;
  374. X     Field field;
  375. X{
  376. X     char value[32];
  377. X     int length = field->end - field->start;
  378. X     int i;
  379. X
  380. X     string = string + field->start;
  381. X     strncpy (value, string, length);
  382. X     value[length] = '\0';
  383. X
  384. X     return (atoi (value));
  385. X}
  386. X
  387. X
  388. Xint pid (string)
  389. X     String string;
  390. X{
  391. X     return (intFieldValue (string, pidField));
  392. X}
  393. X
  394. X
  395. Xint ppid (string)
  396. X     String string;
  397. X{
  398. X     return (intFieldValue (string, ppidField));
  399. X}
  400. X
  401. X
  402. Xvoid parseHeader (string)
  403. X     String string;
  404. X{
  405. X     deleteField (pidField);
  406. X     deleteField (ppidField);
  407. X     deleteField (commandField);
  408. X     
  409. X     pidField = fieldPosition (string, "PID");
  410. X     ppidField = fieldPosition (string, "PPID");
  411. X     if (ppidField == NULL)
  412. X      ppidField = pidField;
  413. X     commandField = fieldPosition (string, "COM");
  414. X}
  415. X
  416. X
  417. XProcess newRootProcess ()
  418. X{
  419. X     Process root;
  420. X     
  421. X     root = (Process) XtMalloc (sizeof (*root));
  422. X     root->pid = -1;
  423. X     root->ppid = -1;
  424. X     root->child = NULL;
  425. X     root->brother = NULL;
  426. X     root->next = NULL;
  427. X     root->nexthash = NULL;
  428. X     
  429. X     return (root);
  430. X}
  431. X
  432. X
  433. XProcess newProcess (string)
  434. X     String string;
  435. X{
  436. X     Process result;
  437. X
  438. X     result = (Process) XtMalloc (sizeof (*result));
  439. X     result->data = string;
  440. X     result->pid = pid (string);
  441. X     result->ppid = ppid (string);
  442. X     result->child = NULL;
  443. X     result->brother = NULL;
  444. X     result->next = NULL;
  445. X     result->nexthash = NULL;
  446. X
  447. X     return (result);
  448. X}
  449. X
  450. X
  451. Xvoid deleteProcess (process)
  452. X     Process process;
  453. X{
  454. X     if (process != NULL) 
  455. X      XtFree ((char *) process);
  456. X}
  457. X
  458. X
  459. Xint hash (id)
  460. X     int id;
  461. X{
  462. X     return (id % hashvalue);
  463. X}
  464. X
  465. X
  466. XProcessList newProcessList ()
  467. X{
  468. X     ProcessList result;
  469. X     int i;
  470. X
  471. X     result = (ProcessList) XtMalloc (sizeof (*result));
  472. X     result->first = NULL;
  473. X     result->root = newRootProcess ();
  474. X     result->hashtable = (Process) XtMalloc (sizeof (Process) *
  475. X                         (hashvalue + 1));
  476. X     for (i = 0; i < hashvalue; i++)
  477. X      result->hashtable[i] = NULL;
  478. X
  479. X     return (result);
  480. X}
  481. X
  482. X
  483. Xvoid deleteProcessList (list)
  484. X     ProcessList list;
  485. X{
  486. X     Process current = list->first;
  487. X     Process next;
  488. X
  489. X     deleteProcess (list->root);
  490. X     while (current != NULL) {
  491. X      next = current->next;
  492. X      deleteProcess (current);
  493. X      current = next;
  494. X     }
  495. X
  496. X     XtFree ((char *) (list->hashtable));
  497. X     XtFree ((char *) list);
  498. X}
  499. X
  500. X
  501. Xvoid addProcess (list, process)
  502. X     ProcessList list;
  503. X     Process process;
  504. X{
  505. X     Process current;
  506. X     
  507. X     /*
  508. X      * Add process to list.
  509. X      */
  510. X     process->next = list->first;
  511. X     list->first = process;
  512. X}
  513. X
  514. X
  515. Xvoid hashAddProcess (list, process)
  516. X     ProcessList list;
  517. X     Process process;
  518. X{
  519. X     Process current;
  520. X     
  521. X     /*
  522. X      * Add process to list.
  523. X      */
  524. X     addProcess (list, process);
  525. X
  526. X     /*
  527. X      * Setup the hashtable for this process
  528. X      * for a faster access.
  529. X      */
  530. X     current = list->hashtable[hash (process->pid)];
  531. X     if (current == NULL)
  532. X      list->hashtable[hash (process->pid)] = process;
  533. X     else {
  534. X      Process previous;
  535. X
  536. X      while (current != NULL) {
  537. X           previous = current;
  538. X           current = current->nexthash;
  539. X      }
  540. X      process->nexthash = current;
  541. X      previous->nexthash = process;
  542. X     }
  543. X}
  544. X
  545. X
  546. Xvoid addChild (parent, child)
  547. X     Process parent;
  548. X     Process child;
  549. X{
  550. X     /*
  551. X      * Add child as a child of parent.
  552. X      * Sort childs by pid.
  553. X      */
  554. X     if (parent->child == NULL)
  555. X      parent->child = child;
  556. X     else if (parent->child->pid > child->pid) {
  557. X      child->brother = parent->child;
  558. X      parent->child = child;
  559. X     } else {
  560. X      Process current;
  561. X      Process previous;
  562. X
  563. X      current = parent->child;
  564. X      while ((current != NULL) && (child->pid >= current->pid)) {
  565. X           previous = current;
  566. X           current = current->brother;
  567. X      }
  568. X      
  569. X      child->brother = current;
  570. X      previous->brother = child;
  571. X     }
  572. X}
  573. X
  574. X
  575. Xvoid sortAddChild (parent, child)
  576. X     Process parent;
  577. X     Process child;
  578. X{
  579. X     /*
  580. X      * Add child as a child of parent.
  581. X      * Sort childs by number of number of children.
  582. X      */
  583. X     if (parent->child == NULL)
  584. X      parent->child = child;
  585. X     else if (parent->child->childCount > child->childCount) {
  586. X      child->brother = parent->child;
  587. X      parent->child = child;
  588. X     } else {
  589. X      Process current;
  590. X      Process previous;
  591. X
  592. X      current = parent->child;
  593. X      while ((current != NULL) &&
  594. X         (child->childCount >= current->childCount)) {
  595. X           previous = current;
  596. X           current = current->brother;
  597. X      }
  598. X      
  599. X      child->brother = current;
  600. X      previous->brother = child;
  601. X     }
  602. X}
  603. X
  604. X
  605. XProcess parentProcess (list, process)
  606. X     ProcessList list;
  607. X     Process process;
  608. X{
  609. X     Process current = NULL;
  610. X
  611. X     /*
  612. X      * Only look for the parent of process if the process is not
  613. X      * its own parent.
  614. X      */
  615. X     if (process->pid != process->ppid) {
  616. X          current = list->hashtable[hash (process->ppid)];
  617. X          while ((current != NULL) && (current->pid != process->ppid))
  618. X           current = current->nexthash;
  619. X     }
  620. X
  621. X     /*
  622. X      * If no parent could be found, return the dummy
  623. X      * head of the process tree.
  624. X      */
  625. X     if (current == NULL)
  626. X          current = list->root;
  627. X
  628. X     return (current);
  629. X}
  630. X
  631. X
  632. Xint countChilds (parent)
  633. X     Process parent;
  634. X{
  635. X     Process child = parent->child;
  636. X     int childCount = 0;
  637. X
  638. X     while (child != NULL) {
  639. X      childCount = childCount + countChilds (child);
  640. X      child = child->brother;
  641. X     }
  642. X     parent->childCount = childCount;
  643. X
  644. X     return (childCount + 1);
  645. X}
  646. X
  647. X
  648. Xvoid sort (parent)
  649. X     Process parent;
  650. X{
  651. X     Process child = parent->child;
  652. X     Process next;
  653. X
  654. X     parent->child = NULL;
  655. X     while (child != NULL) {
  656. X      next = child->brother;
  657. X      child->brother = NULL;
  658. X      sortAddChild (parent, child);
  659. X      sort (child);
  660. X      child = next;
  661. X     }
  662. X}
  663. X
  664. X
  665. XString indent (string, level)
  666. X     String string;
  667. X     int level;
  668. X{
  669. X     String result = (String) XtMalloc (strlen (string)
  670. X                    + indentation * level
  671. X                    + 2);
  672. X     int separation = commandField->start;
  673. X
  674. X     /*
  675. X      * Some fields overrun, so we need to go to the real start of
  676. X      * the command (if any).
  677. X      */
  678. X     if (string[separation] && (string [separation] != ' ')) {
  679. X      separation = strchr (string + separation, ' ') - string;
  680. X      separation = separation + strspn (string + separation, " ");
  681. X     }
  682. X
  683. X     /*
  684. X      * Use printf to indent the command within string.
  685. X      */
  686. X     sprintf (result,
  687. X          "%.*s%*s%-s\n",
  688. X          separation, string,
  689. X          indentation * level, "",
  690. X          string + separation);
  691. X
  692. X     return (result);
  693. X}
  694. X
  695. X
  696. XString indentHierarchy (current, level)
  697. X     Process current;
  698. X     int level;
  699. X{
  700. X     String result = XtNewString ("");
  701. X     String partialResult;
  702. X
  703. X     /*
  704. X      * Do me first, if I am not the dummy root.
  705. X      */
  706. X     if (current->pid != -1) {
  707. X          partialResult = indent (current->data, level);
  708. X          result = XtRealloc (result,
  709. X                  strlen (result) + strlen (partialResult) + 1);
  710. X          strcat (result, partialResult);
  711. X          XtFree (partialResult);
  712. X     }
  713. X
  714. X     /*
  715. X      * Do all my childs.
  716. X      */
  717. X     if (current->child != NULL) {
  718. X      partialResult = indentHierarchy (current->child, level + 1);
  719. X      result = XtRealloc (result,
  720. X                  strlen (result) + strlen (partialResult) + 1);
  721. X      strcat (result, partialResult);
  722. X      XtFree (partialResult);
  723. X     }
  724. X
  725. X     /*
  726. X      * Finally, do all my brothers.
  727. X      */
  728. X     if (current->brother != NULL) {
  729. X      partialResult = indentHierarchy (current->brother, level);
  730. X      result = XtRealloc (result,
  731. X                  strlen (result) + strlen (partialResult) + 1);
  732. X      strcat (result, partialResult);
  733. X      XtFree (partialResult);
  734. X     }
  735. X
  736. X     return (result);
  737. X}
  738. X
  739. X
  740. XString format (lines)
  741. X     String lines;
  742. X{
  743. X     String line;
  744. X     String result;
  745. X     String partialResult;
  746. X     Process process;
  747. X     ProcessList processList = newProcessList ();
  748. X
  749. X     if ((line = strtok (lines, "\n")) == NULL)
  750. X      return (lines);
  751. X
  752. X     parseHeader (line);
  753. X     
  754. X     /*
  755. X      * Store the header first.
  756. X      */
  757. X     result = XtNewString (line);
  758. X     result = XtRealloc (result, strlen (result) + 1);
  759. X     strcat (result, "\n");
  760. X
  761. X     /*
  762. X      * Transform the input string into a linked list of processes.
  763. X      */
  764. X     while ((line = strtok (NULL, "\n")) != NULL) {
  765. X      process = newProcess (line);
  766. X      hashAddProcess (processList, process);
  767. X     }
  768. X
  769. X     /*
  770. X      * For each process, find its parent.
  771. X      */
  772. X     process = processList->first;
  773. X     while (process != NULL) {
  774. X      addChild (parentProcess (processList, process), process);
  775. X      process = process->next;
  776. X     }
  777. X     
  778. X     /*
  779. X      * Sort the process list based on the number of children
  780. X      * per process.
  781. X      */
  782. X     (void) countChilds (processList->root);
  783. X     sort (processList->root);
  784. X     
  785. X     /*
  786. X      * Display the process list according to a parent-child relationship.
  787. X      */
  788. X     partialResult = indentHierarchy (processList->root, -1);
  789. X     result = XtRealloc (result,
  790. X             strlen (result) + strlen (partialResult) + 1);
  791. X     strcat (result, partialResult);
  792. X     XtFree (partialResult);
  793. X     
  794. X     /*
  795. X      * Free all the garbage we have generated.
  796. X      */
  797. X     deleteProcessList (processList);
  798. X     
  799. X     return (result);
  800. X}
  801. END_OF_FILE
  802.   if test 10822 -ne `wc -c <'format.c'`; then
  803.     echo shar: \"'format.c'\" unpacked with wrong size!
  804.   fi
  805.   # end of 'format.c'
  806. fi
  807. if test -f 'process.c' -a "${1}" != "-c" ; then 
  808.   echo shar: Will not clobber existing file \"'process.c'\"
  809. else
  810.   echo shar: Extracting \"'process.c'\" \(8922 characters\)
  811.   sed "s/^X//" >'process.c' <<'END_OF_FILE'
  812. X#include <Xm/Xm.h>
  813. X#include <Xm/XmStrDefs.h>
  814. X#include <Xm/List.h>
  815. X#include <Xm/Text.h>
  816. X
  817. X#include <stdio.h>
  818. X#include <stdlib.h>
  819. X#include <sys/types.h>
  820. X#include <sys/stat.h>
  821. X#include <errno.h>
  822. X#include <pwd.h>
  823. X#include <grp.h>
  824. X#include <sys/utsname.h>
  825. X
  826. X#include "xmps.h"
  827. X
  828. X
  829. Xint selectAllProcesses (widget, clientData, callData)
  830. X     Widget widget;
  831. X     caddr_t clientData;
  832. X     caddr_t callData;
  833. X{
  834. X     int itemCount;
  835. X     int current;
  836. X
  837. X     Arg arglist[2];
  838. X     Cardinal i;
  839. X     
  840. X     i = 0;
  841. X     XtSetArg (arglist[i], XmNitemCount, &itemCount); i++;
  842. X     XtGetValues (listArea, arglist, i);
  843. X     
  844. X     XtUnmapWidget (processArea);
  845. X     XmListDeselectAllItems (listArea);
  846. X     for (current = 1; current <= itemCount; current++)
  847. X      XmListSelectPos (listArea, current, True);
  848. X     XtMapWidget (processArea);
  849. X}
  850. X
  851. X
  852. Xint unselectAllProcesses (widget, clientData, callData)
  853. X     Widget widget;
  854. X     caddr_t clientData;
  855. X     caddr_t callData;
  856. X{
  857. X     XtUnmapWidget (processArea);
  858. X     XmListDeselectAllItems (listArea);
  859. X     XtMapWidget (processArea);
  860. X}
  861. X
  862. X
  863. Xvoid highlightProcess (processPosition)
  864. X     int processPosition;
  865. X{
  866. X     XmListSelectPos (listArea, processPosition, True);
  867. X}
  868. X
  869. X
  870. Xvoid centerProcess (processPosition, topProcessPosition, visibleProcessCount)
  871. X     int processPosition;
  872. X     int topProcessPosition;
  873. X     int visibleProcessCount;
  874. X{
  875. X     /*
  876. X      * Center the requested process.
  877. X      */
  878. X     if (! ((processPosition >= topProcessPosition) &&
  879. X        (processPosition <= (topProcessPosition +
  880. X                 visibleProcessCount - 1)))) {
  881. X      if (processPosition > visibleProcessCount/2) {
  882. X           XmListSetPos (listArea, processPosition - visibleProcessCount/2);
  883. X      } else {
  884. X           XmListSetPos (listArea, processPosition);
  885. X      }
  886. X     }
  887. X}
  888. X
  889. X
  890. Xvoid reDisplayProcessesIfNecessary ()
  891. X{
  892. X     if (resources.automaticRefresh)
  893. X      reDisplayProcesses ();
  894. X}
  895. X
  896. X
  897. Xint reDisplayProcesses (widget, clientData, callData)
  898. X     Widget widget;
  899. X     caddr_t clientData;
  900. X     caddr_t callData;
  901. X{
  902. X     int oldTopItemPosition;
  903. X     int oldItemCount;
  904. X     int itemCount;
  905. X     int topItemPosition;
  906. X
  907. X     Arg arglist[4];
  908. X     Cardinal i;
  909. X     
  910. X     extern void displayProcesses ();
  911. X
  912. X     /*
  913. X      * Disable alarms while we refresh the display.
  914. X      */
  915. X     if (resources.periodicRefresh)
  916. X      setTimer (False);
  917. X     
  918. X     /*
  919. X      * Hide the list while we update it.
  920. X      */
  921. X     setBusyIndicator ();
  922. X     XtUnmapWidget (processArea);
  923. X
  924. X     /*
  925. X      * Remember where the top of the list is.
  926. X      */
  927. X     i = 0;
  928. X     XtSetArg (arglist[i], XmNtopItemPosition, &oldTopItemPosition); i++;
  929. X     XtSetArg (arglist[i], XmNitemCount, &oldItemCount); i++;
  930. X     XtGetValues (listArea, arglist, i);
  931. X     
  932. X     /*
  933. X      * Xm bug fix.
  934. X      * Go to the beginning of the list.
  935. X      */
  936. X     XmListSetPos (listArea, 1);
  937. X     XmListSetHorizPos (listArea, 1);
  938. X
  939. X     /*
  940. X      * Recreate the processes information.
  941. X      */
  942. X     XmListDeleteAllItems (listArea);
  943. X     displayProcesses ();
  944. X
  945. X     /*
  946. X      * Go back we were.
  947. X      */
  948. X     i = 0;
  949. X     XtSetArg (arglist[i], XmNitemCount, &itemCount); i++;
  950. X     XtGetValues (listArea, arglist, i);
  951. X     
  952. X     i = 0;
  953. X     if (itemCount >= oldItemCount)
  954. X      topItemPosition = oldTopItemPosition;
  955. X     else {
  956. X      topItemPosition = oldTopItemPosition - (oldItemCount - itemCount);
  957. X      if (topItemPosition <= 0)
  958. X           topItemPosition = 1;
  959. X     }
  960. X     XtSetArg (arglist[i], XmNtopItemPosition, topItemPosition); i++;
  961. X     XtSetValues (listArea, arglist, i);
  962. X
  963. X     /*
  964. X      * Make the list visible again.
  965. X      */
  966. X     XtMapWidget (processArea);
  967. X     unsetBusyIndicator ();
  968. X
  969. X     /*
  970. X      * Reenable alarms.
  971. X      */
  972. X     if (resources.periodicRefresh)
  973. X      setTimer (True);
  974. X}
  975. X
  976. X
  977. Xint applyAction ()
  978. X{
  979. X     XmStringTable selectedItems;
  980. X     int selectedItemCount;
  981. X     int current;
  982. X     String line;
  983. X     char command[512];
  984. X     char *argv[4];
  985. X     Boolean remote;
  986. X     struct utsname name;
  987. X
  988. X     Arg arglist[4];
  989. X     Cardinal i;
  990. X     
  991. X     /*
  992. X      * Find out whether or not we need to use remsh.
  993. X      */
  994. X     if ((strcmp (currentHost, "localhost") == 0) ||
  995. X     ((uname (&name) != -1) && (strcmp (currentHost, name.nodename) == 0)))
  996. X      remote = False;
  997. X     else
  998. X      remote = True;
  999. X
  1000. X     /*
  1001. X      * Get the selected processes.
  1002. X      */
  1003. X     i = 0;
  1004. X     XtSetArg (arglist[i], XmNselectedItems, &selectedItems); i++;
  1005. X     XtSetArg (arglist[i], XmNselectedItemCount, &selectedItemCount); i++;
  1006. X     XtGetValues (listArea, arglist, i);
  1007. X     
  1008. X     /*
  1009. X      * Apply the current action on them.
  1010. X      */
  1011. X     setBusyIndicator ();
  1012. X     for (current = 1; current <= selectedItemCount; current++) {
  1013. X      
  1014. X      XmStringGetLtoR (selectedItems[current-1],
  1015. X               XmSTRING_DEFAULT_CHARSET,
  1016. X               &line);
  1017. X      if (remote)
  1018. X           sprintf (command, "%s %s -n %s %d",
  1019. X            resources.rshCommand, currentHost,
  1020. X            currentAction, pid (line));
  1021. X      else
  1022. X           sprintf (command, "%s %d", currentAction, pid (line));
  1023. X
  1024. X      argv[0] = "/bin/sh";
  1025. X      argv[1] = "-c";
  1026. X      argv[2] = command;
  1027. X      argv[3] = 0;
  1028. X      (void) executeCommand (argv);
  1029. X
  1030. X          XtFree (line);
  1031. X     }
  1032. X     unsetBusyIndicator ();
  1033. X}
  1034. X
  1035. X
  1036. XString buildCommandLine ()
  1037. X{
  1038. X     String command;
  1039. X     struct utsname name;
  1040. X
  1041. X     command = (char *) XtMalloc (sizeof (char) * 512);
  1042. X
  1043. X     /*
  1044. X      * Store the process command first.
  1045. X      */
  1046. X     if ((strcmp (currentHost, "localhost") == 0) ||
  1047. X     ((uname (&name) != -1) && (strcmp (currentHost, name.nodename) == 0)))
  1048. X      strcpy (command, resources.psCommand);
  1049. X     else
  1050. X      sprintf (command,"%s %s -n %s",
  1051. X           resources.rshCommand, currentHost, resources.psCommand);
  1052. X     
  1053. X     /*
  1054. X      * Add a hyphen now for eventual options and do not bother any more.
  1055. X      */
  1056. X     strcat (command, " -");
  1057. X     
  1058. X     /*
  1059. X      * Add the process type options.
  1060. X      */
  1061. X     if (resources.allProcesses)
  1062. X      strcat (command, resources.allProcessesOption);
  1063. X     else if (resources.noNonTerminal)
  1064. X      strcat (command, resources.noNonTerminalOption);
  1065. X     else if (resources.noGroupLeader)
  1066. X      strcat (command, resources.noGroupLeaderOption);
  1067. X
  1068. X     /*
  1069. X      * Add the listing options.
  1070. X      */
  1071. X     if (resources.fullListing)
  1072. X      strcat (command, resources.fullListingOption);
  1073. X     else if (resources.longListing)
  1074. X      strcat (command, resources.longListingOption);
  1075. X
  1076. X     /*
  1077. X      * Add the user name to look for.
  1078. X      */
  1079. X     if (strcmp (currentUser, "all") != 0) {
  1080. X#ifdef notdef
  1081. X      struct passwd *passwd = getpwnam (currentUser);
  1082. X      if (passwd != NULL) {
  1083. X           sprintf (command, "%s -%s %d",
  1084. X            command, resources.usersOption, passwd->pw_uid);
  1085. X      } else
  1086. X           error ("Cannot find selected user :\n%s",
  1087. X              currentUser, (char *) 0);
  1088. X#else
  1089. X      sprintf (command, "%s -%s %s",
  1090. X           command, resources.usersOption, currentUser);
  1091. X#endif
  1092. X     }
  1093. X
  1094. X     /*
  1095. X      * Add the group name to look for.
  1096. X      */
  1097. X     if (strcmp (currentGroup, "all") != 0) {
  1098. X#ifdef notdef
  1099. X      struct group *group = getgrnam (currentGroup);
  1100. X      if (group != NULL) {
  1101. X           sprintf (command, "%s -%s %d",
  1102. X            command, resources.groupsOption, group->gr_gid);
  1103. X      } else
  1104. X           error ("Cannot find selected group :\n%s",
  1105. X              currentGroup, (char *) 0);
  1106. X#else
  1107. X      sprintf (command, "%s -%s %s",
  1108. X           command, resources.groupsOption, currentGroup);
  1109. X#endif
  1110. X     }
  1111. X
  1112. X     /*
  1113. X      * Add the terminal to look for.
  1114. X      */
  1115. X     if (strcmp (currentTerminal, "") != 0)
  1116. X      sprintf (command, "%s -%s %s",
  1117. X           command, resources.terminalsOption, currentTerminal);
  1118. X
  1119. X     /*
  1120. X      * Add the beautifier.
  1121. X      */
  1122. X     if (resources.beautify && !internalBeautifier)
  1123. X      sprintf (command, "%s | %s",
  1124. X           command, resources.beautifyCommand);
  1125. X
  1126. X     return (command);
  1127. X}
  1128. X
  1129. X
  1130. Xvoid displayProcesses ()
  1131. X{
  1132. X     char *argv[4];
  1133. X     String command;
  1134. X     String line;
  1135. X     String lines;
  1136. X     String oldLines;
  1137. X     XmString label;
  1138. X     int processCount = 0;
  1139. X
  1140. X     Arg arglist[4];
  1141. X     Cardinal i;
  1142. X
  1143. X     extern void infoLineUpdate ();
  1144. X     
  1145. X     /*
  1146. X      * Construct the appropriate command line.
  1147. X      */
  1148. X     command = buildCommandLine ();
  1149. X     
  1150. X     /*
  1151. X      * Get processes information.
  1152. X      */
  1153. X     argv[0] = "/bin/sh";
  1154. X     argv[1] = "-c";
  1155. X     argv[2] = command;
  1156. X     argv[3] = 0;
  1157. X     lines = executeCommand (argv);
  1158. X
  1159. X     /*
  1160. X      * Format it eventually.
  1161. X      */
  1162. X     if (resources.beautify && internalBeautifier)
  1163. X      lines = format (lines);
  1164. X     oldLines = lines;
  1165. X
  1166. X     /*
  1167. X      * Print the title line.
  1168. X      */
  1169. X     if ((line = strtok (lines, "\n")) != NULL) {
  1170. X      parseHeader (line);
  1171. X
  1172. X      label = XmStringCreateLtoR (line, XmSTRING_DEFAULT_CHARSET);
  1173. X      
  1174. X      i = 0;
  1175. X      XtSetArg (arglist[i], XmNlabelString, label); i++;
  1176. X      XtSetValues (headerArea, arglist, i);
  1177. X      XmStringFree (label);
  1178. X
  1179. X      /*
  1180. X       * Print each process information.
  1181. X       */
  1182. X      while ((line = strtok (NULL, "\n")) != NULL) {
  1183. X           label = XmStringCreateLtoR (line, XmSTRING_DEFAULT_CHARSET);
  1184. X           XmListAddItemUnselected (listArea, label, 0);
  1185. X           XmStringFree (label);
  1186. X           processCount = processCount + 1;
  1187. X      }
  1188. X     }
  1189. X
  1190. X     XtFree (oldLines);
  1191. X
  1192. X     infoLineUpdate (processCount);
  1193. X}
  1194. X
  1195. X
  1196. END_OF_FILE
  1197.   if test 8922 -ne `wc -c <'process.c'`; then
  1198.     echo shar: \"'process.c'\" unpacked with wrong size!
  1199.   fi
  1200.   # end of 'process.c'
  1201. fi
  1202. if test -f 'search.c' -a "${1}" != "-c" ; then 
  1203.   echo shar: Will not clobber existing file \"'search.c'\"
  1204. else
  1205.   echo shar: Extracting \"'search.c'\" \(5315 characters\)
  1206.   sed "s/^X//" >'search.c' <<'END_OF_FILE'
  1207. X#include <Xm/Xm.h>
  1208. X#include <Xm/XmStrDefs.h>
  1209. X#include <Xm/List.h>
  1210. X
  1211. X#include <stdio.h>
  1212. X#include <regex.h>
  1213. X
  1214. X#include "xmps.h"
  1215. X
  1216. X
  1217. Xvoid setSearch (state)
  1218. X     Boolean state;
  1219. X{
  1220. X     Arg arglist[2];
  1221. X     Cardinal i;
  1222. X     
  1223. X     i = 0;
  1224. X     XtSetArg (arglist[i], XmNsensitive, state); i++;
  1225. X     XtSetValues (XtNameToWidget (processPane, "previous"), arglist, i);
  1226. X     XtSetValues (XtNameToWidget (processPane, "next"), arglist, i);
  1227. X}
  1228. X
  1229. X
  1230. Xvoid enableSearch ()
  1231. X{
  1232. X     setSearch (True);
  1233. X}
  1234. X
  1235. X
  1236. Xvoid disableSearch ()
  1237. X{
  1238. X     setSearch (False);
  1239. X}
  1240. X
  1241. X
  1242. Xint searchProcessPrompt (widget, clientData, callData)
  1243. X     Widget widget;
  1244. X     caddr_t clientData;
  1245. X     caddr_t callData;
  1246. X{
  1247. X     extern int searchProcess ();
  1248. X     
  1249. X     if (! searchDialog) {
  1250. X      XmString title, label;
  1251. X      
  1252. X      Arg arglist[4];
  1253. X      Cardinal i;
  1254. X      
  1255. X      title = XmStringCreateLtoR ("Search Dialog",
  1256. X                      XmSTRING_DEFAULT_CHARSET);
  1257. X      label = XmStringCreateLtoR ("Search For...",
  1258. X                      XmSTRING_DEFAULT_CHARSET);
  1259. X
  1260. X      i = 0;
  1261. X      XtSetArg (arglist[i], XmNdialogTitle, title); i++;
  1262. X      XtSetArg (arglist[i], XmNselectionLabelString, label); i++;
  1263. X      searchDialog = (Widget) XmCreatePromptDialog (topLevel,
  1264. X                            "searchDialog",
  1265. X                            arglist,i);
  1266. X
  1267. X      XtUnmanageChild ((Widget) XmMessageBoxGetChild (searchDialog,
  1268. X                              XmDIALOG_HELP_BUTTON));
  1269. X      XtAddCallback (searchDialog,
  1270. X             XmNokCallback,
  1271. X             (XtCallbackProc) searchProcess,
  1272. X             (XtPointer) ACTION_SEARCH);
  1273. X
  1274. X      XmStringFree (title);
  1275. X      XmStringFree (label);
  1276. X     }
  1277. X     
  1278. X     XtManageChild (searchDialog);
  1279. X}
  1280. X
  1281. X
  1282. Xint searchProcess (widget, typeOfSearch, callData)
  1283. X     Widget widget;
  1284. X     int typeOfSearch;
  1285. X     caddr_t callData;
  1286. X{
  1287. X     XmStringTable items;
  1288. X     XmString currentItem;
  1289. X     String pattern;
  1290. X     regex_t compiledPattern;
  1291. X     int flag;
  1292. X     String line;
  1293. X     Boolean foundItem = False;
  1294. X     int itemCount;
  1295. X     int topItemPosition;
  1296. X     int visibleItemCount;
  1297. X     int current;
  1298. X     enum {forward, backward} direction;
  1299. X     static int lastSearchPosition = 1;
  1300. X     int endOfSearchPosition;
  1301. X     Boolean firstOccurrence = True;
  1302. X     int regErrorCode;
  1303. X
  1304. X     Arg arglist[5];
  1305. X     Cardinal i;
  1306. X     
  1307. X     i = 0;
  1308. X     XtSetArg (arglist[i], XmNitemCount, &itemCount); i++;
  1309. X     XtSetArg (arglist[i], XmNtopItemPosition, &topItemPosition); i++;
  1310. X     XtSetArg (arglist[i], XmNvisibleItemCount, &visibleItemCount); i++;
  1311. X     XtSetArg (arglist[i], XmNitems, &items); i++;
  1312. X     XtGetValues (listArea, arglist, i);
  1313. X     
  1314. X     /*
  1315. X      * Disable temporarily the Next and Previous buttons.
  1316. X      */
  1317. X     disableSearch ();
  1318. X
  1319. X     /*
  1320. X      * Get the process name to search for.
  1321. X      */
  1322. X     i = 0;
  1323. X     XtSetArg (arglist[i], XmNtextString, ¤tItem); i++;
  1324. X     XtGetValues (searchDialog, arglist, i);
  1325. X     XmStringGetLtoR (currentItem, XmSTRING_DEFAULT_CHARSET, &pattern);
  1326. X
  1327. X     if (strcmp (pattern, "") == 0) {
  1328. X      XtFree (pattern);
  1329. X      return;
  1330. X     }
  1331. X
  1332. X     flag = REG_EXTENDED | REG_NEWLINE | REG_NOSUB;
  1333. X     if (resources.ignoreCase)
  1334. X      flag |= REG_ICASE;
  1335. X     regErrorCode = regcomp (&compiledPattern, pattern, flag);
  1336. X     if (regErrorCode != 0) {
  1337. X      char regErrorMsg[256];
  1338. X
  1339. X      (void) regerror (regErrorCode, &compiledPattern,
  1340. X               regErrorMsg, sizeof (regErrorMsg));
  1341. X      error ("Malformed regular expression :\n%s",
  1342. X         regErrorMsg, (char *) 0);
  1343. X      XtFree (pattern);
  1344. X      return;
  1345. X     }
  1346. X
  1347. X     /*
  1348. X      * Find where to search.
  1349. X      */
  1350. X     if (typeOfSearch == ACTION_SEARCH) {
  1351. X      current = lastSearchPosition;
  1352. X      endOfSearchPosition = current;
  1353. X      direction = forward;
  1354. X     } else if (typeOfSearch == ACTION_SEARCH_NEXT) {
  1355. X      if (lastSearchPosition != itemCount)
  1356. X           current = lastSearchPosition + 1;
  1357. X      else
  1358. X           current = 1;
  1359. X      endOfSearchPosition = current;
  1360. X      direction = forward;
  1361. X     } else if (typeOfSearch == ACTION_SEARCH_PREVIOUS) {
  1362. X      if (lastSearchPosition != 1)
  1363. X           current = lastSearchPosition - 1;
  1364. X      else
  1365. X           current = itemCount;
  1366. X      endOfSearchPosition = current;
  1367. X      direction = backward;
  1368. X     } else {
  1369. X      error ("Invalid type of search :\ninternal error", (char *) 0);
  1370. X          regfree (&compiledPattern);
  1371. X          XtFree (pattern);
  1372. X      return;
  1373. X     }
  1374. X     
  1375. X     /*
  1376. X      * Search now.
  1377. X      */
  1378. X     XmListDeselectAllItems (listArea);
  1379. X     XmListSetAddMode (listArea, True);
  1380. X     do {
  1381. X      XmStringGetLtoR (items[current-1],
  1382. X               XmSTRING_DEFAULT_CHARSET,
  1383. X               &line);
  1384. X      if (regexec (&compiledPattern, line, (size_t) 0, NULL, 0) == 0) {
  1385. X           if (firstOccurrence)
  1386. X            centerProcess (current, topItemPosition, visibleItemCount);
  1387. X           highlightProcess (current);
  1388. X           foundItem = True;
  1389. X           if (! resources.multipleOccurrences)
  1390. X            break;
  1391. X           firstOccurrence = False;
  1392. X      }
  1393. X      if (((direction == forward) && (current < itemCount)) ||
  1394. X          ((direction == backward) && (current > 1)))
  1395. X           current += (direction == forward) ? 1 : -1;
  1396. X      else
  1397. X           current = (direction == forward) ? 1 : itemCount;
  1398. X      XtFree (line);
  1399. X     } while (current != endOfSearchPosition);
  1400. X     XmListSetAddMode (listArea, False);
  1401. X     regfree (&compiledPattern);
  1402. X
  1403. X     /*
  1404. X      * Remember the position of the found item.
  1405. X      */
  1406. X     if (foundItem) {
  1407. X      lastSearchPosition = current;
  1408. X
  1409. X      if (! resources.multipleOccurrences)
  1410. X           enableSearch ();
  1411. X     } else {
  1412. X      XmListDeselectAllItems (listArea);
  1413. X      error ("No such string :\n%s", pattern, (char *) 0);
  1414. X     }
  1415. X     XtFree (pattern);
  1416. X}
  1417. END_OF_FILE
  1418.   if test 5315 -ne `wc -c <'search.c'`; then
  1419.     echo shar: \"'search.c'\" unpacked with wrong size!
  1420.   fi
  1421.   # end of 'search.c'
  1422. fi
  1423. if test -f 'snapshot.c' -a "${1}" != "-c" ; then 
  1424.   echo shar: Will not clobber existing file \"'snapshot.c'\"
  1425. else
  1426.   echo shar: Extracting \"'snapshot.c'\" \(8857 characters\)
  1427.   sed "s/^X//" >'snapshot.c' <<'END_OF_FILE'
  1428. X#include <Xm/Xm.h>
  1429. X#include <Xm/XmStrDefs.h>
  1430. X#include <Xm/Frame.h>
  1431. X#include <Xm/MainW.h>
  1432. X#include <Xm/List.h>
  1433. X#include <Xm/PushBG.h>
  1434. X#include <Xm/RowColumn.h>
  1435. X#include <Xm/ScrolledW.h>
  1436. X#include <Xm/SeparatoG.h>
  1437. X#include <Xm/Text.h>
  1438. X#include <Xm/ToggleBG.h>
  1439. X
  1440. X#include <stdio.h>
  1441. X
  1442. X#include "xmps.h"
  1443. X
  1444. X
  1445. Xint closeSnapshot (widget, clientData, callData)
  1446. X     Widget widget;
  1447. X     XtPointer clientData;
  1448. X     caddr_t callData;
  1449. X{
  1450. X     Widget snapshotTopLevel = (Widget) clientData;
  1451. X     
  1452. X     XtPopdown (snapshotTopLevel);
  1453. X     XtDestroyWidget (snapshotTopLevel);
  1454. X}
  1455. X
  1456. X
  1457. Xint printSnapshotProcesses (widget, clientData, callData)
  1458. X     Widget widget;
  1459. X     XtPointer clientData;
  1460. X     caddr_t callData;
  1461. X{
  1462. X     Widget listArea = (Widget) clientData;
  1463. X
  1464. X     printProcessesFrom (listArea);
  1465. X}
  1466. X
  1467. X
  1468. Xint takeSnapshot (widget, clientData, callData)
  1469. X     Widget widget;
  1470. X     caddr_t clientData;
  1471. X     caddr_t callData;
  1472. X{
  1473. X     extern void createSnapshot ();
  1474. X
  1475. X     setBusyIndicator ();
  1476. X     createSnapshot (topLevel);
  1477. X     unsetBusyIndicator ();
  1478. X}
  1479. X
  1480. X
  1481. Xvoid duplicateList (parent, status, header, list)
  1482. X     Widget parent;
  1483. X     Widget status;
  1484. X     Widget header;
  1485. X     Widget list;
  1486. X{
  1487. X     Widget snapshotTopWindow;
  1488. X     Widget snapshotStatusArea;
  1489. X     Widget snapshotSeparator;
  1490. X     Widget snapshotHeaderArea;
  1491. X     Widget snapshotProcessArea;
  1492. X     Widget snapshotButtonArea;
  1493. X     Widget snapshotCloseArea;
  1494. X     Widget snapshotPrintArea;
  1495. X     
  1496. X     XmFontList fontList;
  1497. X     XmString label;
  1498. X     Dimension height;
  1499. X     XmStringTable items;
  1500. X     int itemCount;
  1501. X     int current;
  1502. X
  1503. X     Arg arglist[15];
  1504. X     Cardinal i;
  1505. X     
  1506. X     /*
  1507. X      * Create a form.
  1508. X      */
  1509. X     i = 0;
  1510. X     XtSetArg (arglist[i], XmNorientation, XmVERTICAL); i++;
  1511. X     XtSetArg (arglist[i], XmNpacking, XmPACK_NONE); i++;
  1512. X     snapshotTopWindow = (Widget) XmCreateForm (parent,
  1513. X                        "snapshotTopWindow",
  1514. X                        arglist, i);
  1515. X     XtManageChild (snapshotTopWindow);
  1516. X
  1517. X     /*
  1518. X      * Add a status line.
  1519. X      */
  1520. X     i = 0;
  1521. X     XtSetArg (arglist[i], XmNlabelString, &label); i++;
  1522. X     XtSetArg (arglist[i], XmNfontList, &fontList); i++;
  1523. X     XtSetArg (arglist[i], XmNheight, &height); i++;
  1524. X     XtGetValues (status, arglist, i);
  1525. X
  1526. X     i = 0;
  1527. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1528. X     XtSetArg (arglist[i], XmNfontList, fontList); i++;
  1529. X     XtSetArg (arglist[i], XmNalignment, XmALIGNMENT_BEGINNING); i++;
  1530. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_FORM); i++;
  1531. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1532. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_NONE); i++;
  1533. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1534. X     snapshotStatusArea = (Widget) XmCreateLabelGadget (snapshotTopWindow,
  1535. X                            "snapshotStatusArea",
  1536. X                            arglist, i);
  1537. X     XtManageChild (snapshotStatusArea);
  1538. X     
  1539. X     /*
  1540. X      * Add a separator.
  1541. X      */
  1542. X     i = 0;
  1543. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1544. X     XtSetArg (arglist[i], XmNtopWidget, snapshotStatusArea); i++;
  1545. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1546. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_NONE); i++;
  1547. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1548. X     snapshotSeparator = XmCreateSeparatorGadget (snapshotTopWindow,
  1549. X                          "snapshotSeparator",
  1550. X                          arglist, i);
  1551. X
  1552. X     XtManageChild (snapshotSeparator);
  1553. X
  1554. X     /*
  1555. X      * Add a header.
  1556. X      */
  1557. X     i = 0;
  1558. X     XtSetArg (arglist[i], XmNlabelString, &label); i++;
  1559. X     XtSetArg (arglist[i], XmNfontList, &fontList); i++;
  1560. X     XtGetValues (header, arglist, i);
  1561. X
  1562. X     i = 0;
  1563. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1564. X     XtSetArg (arglist[i], XmNfontList, fontList); i++;
  1565. X     XtSetArg (arglist[i], XmNalignment, XmALIGNMENT_BEGINNING); i++;
  1566. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1567. X     XtSetArg (arglist[i], XmNtopWidget, snapshotSeparator); i++;
  1568. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1569. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_NONE); i++;
  1570. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1571. X     snapshotHeaderArea = (Widget) XmCreateLabelGadget (snapshotTopWindow,
  1572. X                            "snapshotHeaderArea",
  1573. X                            arglist, i);
  1574. X     XtManageChild (snapshotHeaderArea);
  1575. X     
  1576. X     /*
  1577. X      * Add a scrolledList.
  1578. X      */
  1579. X     i = 0;
  1580. X     XtSetArg (arglist[i], XmNfontList, &fontList); i++;
  1581. X     XtSetArg (arglist[i], XmNitems, &items); i++;
  1582. X     XtSetArg (arglist[i], XmNitemCount, &itemCount); i++;
  1583. X     XtGetValues (list, arglist, i);
  1584. X
  1585. X     i = 0;
  1586. X     XtSetArg (arglist[i], XmNfontList, fontList); i++;
  1587. X
  1588. X     XtSetArg (arglist[i], XmNlistSizePolicy, XmCONSTANT); i++;
  1589. X     XtSetArg (arglist[i], XmNselectionPolicy, XmSINGLE_SELECT); i++;
  1590. X
  1591. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1592. X     XtSetArg (arglist[i], XmNtopWidget, snapshotHeaderArea); i++;
  1593. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1594. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  1595. X     XtSetArg (arglist[i], XmNbottomOffset, height); i++;
  1596. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1597. X
  1598. X     snapshotProcessArea = XmCreateScrolledList (snapshotTopWindow, 
  1599. X                         "snapshotProcessArea",
  1600. X                         arglist, i);
  1601. X     XtManageChild (snapshotProcessArea);
  1602. X
  1603. X     /*
  1604. X      * Add the items of the current list to the new list.
  1605. X      */
  1606. X     for (current = 0; current < itemCount; current++)
  1607. X      XmListAddItemUnselected (snapshotProcessArea, items[current], 0);
  1608. X
  1609. X     /*
  1610. X      * Add a form to enclose buttons.
  1611. X      */
  1612. X     i = 0;
  1613. X     XtSetArg (arglist[i], XmNheight, height); i++;
  1614. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_NONE); i++;
  1615. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1616. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  1617. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1618. X     
  1619. X     snapshotButtonArea = XmCreateForm (snapshotTopWindow,
  1620. X                    "snapshotButtonArea",
  1621. X                    arglist, i);
  1622. X     XtManageChild (snapshotButtonArea);
  1623. X
  1624. X     /*
  1625. X      * Add a print button.
  1626. X      */
  1627. X     label = XmStringCreateLtoR ("Print", XmSTRING_DEFAULT_CHARSET);
  1628. X
  1629. X     i = 0;
  1630. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1631. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_FORM); i++;
  1632. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1633. X     XtSetArg (arglist[i], XmNleftOffset, 50); i++;
  1634. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  1635. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_NONE); i++;
  1636. X     
  1637. X     snapshotPrintArea = XmCreatePushButtonGadget (snapshotButtonArea,
  1638. X                           "snapshotPrintArea",
  1639. X                           arglist, i);
  1640. X     XtManageChild (snapshotPrintArea);
  1641. X     XmStringFree (label);
  1642. X
  1643. X     XtAddCallback (snapshotPrintArea,
  1644. X            XmNactivateCallback,
  1645. X            (XtCallbackProc) printSnapshotProcesses,
  1646. X            (XtPointer) snapshotProcessArea);
  1647. X
  1648. X     /*
  1649. X      * Add a close button.
  1650. X      */
  1651. X     label = XmStringCreateLtoR ("Close", XmSTRING_DEFAULT_CHARSET);
  1652. X
  1653. X     i = 0;
  1654. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1655. X     XtSetArg (arglist[i], XmNtopAttachment, XmATTACH_FORM); i++;
  1656. X     XtSetArg (arglist[i], XmNleftAttachment, XmATTACH_NONE); i++;
  1657. X     XtSetArg (arglist[i], XmNbottomAttachment, XmATTACH_FORM); i++;
  1658. X     XtSetArg (arglist[i], XmNrightAttachment, XmATTACH_FORM); i++;
  1659. X     XtSetArg (arglist[i], XmNrightOffset, 50); i++;
  1660. X     
  1661. X     snapshotCloseArea = XmCreatePushButtonGadget (snapshotButtonArea,
  1662. X                           "snapshotCloseArea",
  1663. X                           arglist, i);
  1664. X     XtManageChild (snapshotCloseArea);
  1665. X     XmStringFree (label);
  1666. X
  1667. X     XtAddCallback (snapshotCloseArea,
  1668. X            XmNactivateCallback,
  1669. X            (XtCallbackProc) closeSnapshot,
  1670. X            (XtPointer) parent);
  1671. X}
  1672. X
  1673. X
  1674. Xvoid createSnapshot (parent)
  1675. X     Widget parent;
  1676. X{
  1677. X     Widget snapshotTopLevel;
  1678. X     Widget statusArea = XtNameToWidget (topLevel,
  1679. X                     "topWindow.selectionArea.statusArea");
  1680. X     Dimension width, height;
  1681. X
  1682. X     Arg arglist[3];
  1683. X     Cardinal i;
  1684. X
  1685. X     /*
  1686. X      * Create a shell to have a separate window and interact directly with
  1687. X      * the window manager.
  1688. X      */
  1689. X     i = 0;
  1690. X     XtSetArg (arglist[i], XmNwidth, &width); i++;
  1691. X     XtSetArg (arglist[i], XmNheight, &height); i++;
  1692. X     XtGetValues (topLevel, arglist, i);
  1693. X
  1694. X     i = 0;
  1695. X     XtSetArg (arglist[i], XmNwidth, width); i++;
  1696. X     XtSetArg (arglist[i], XmNheight, height); i++;
  1697. X     snapshotTopLevel = XtCreatePopupShell ("Process Browser",
  1698. X                        topLevelShellWidgetClass,
  1699. X                        parent,
  1700. X                        arglist, i);
  1701. X     
  1702. X     /*
  1703. X      * Replicate the current window.
  1704. X      */
  1705. X     (void) duplicateList (snapshotTopLevel, statusArea, headerArea, listArea);
  1706. X     
  1707. X     /*
  1708. X      * Display the new window.
  1709. X      */
  1710. X     XtRealizeWidget (snapshotTopLevel);
  1711. X     XtMapWidget (snapshotTopLevel);
  1712. X     XRaiseWindow (XtDisplay (snapshotTopLevel), XtWindow (snapshotTopLevel));
  1713. X}
  1714. X
  1715. X
  1716. END_OF_FILE
  1717.   if test 8857 -ne `wc -c <'snapshot.c'`; then
  1718.     echo shar: \"'snapshot.c'\" unpacked with wrong size!
  1719.   fi
  1720.   # end of 'snapshot.c'
  1721. fi
  1722. if test -f 'status.c' -a "${1}" != "-c" ; then 
  1723.   echo shar: Will not clobber existing file \"'status.c'\"
  1724. else
  1725.   echo shar: Extracting \"'status.c'\" \(5378 characters\)
  1726.   sed "s/^X//" >'status.c' <<'END_OF_FILE'
  1727. X#include <Xm/Xm.h>
  1728. X#include <Xm/XmStrDefs.h>
  1729. X#include <Xm/Text.h>
  1730. X
  1731. X#include <stdio.h>
  1732. X#include <stdlib.h>
  1733. X#include <string.h>
  1734. X
  1735. X#include "xmps.h"
  1736. X
  1737. X
  1738. Xint menuParameterChange (widget, newValue, callData)
  1739. X     Widget widget;
  1740. X     String newValue;
  1741. X     caddr_t callData;
  1742. X{
  1743. X     String widgetName = XtName (XtParent (widget));
  1744. X     
  1745. X     if (strcmp (widgetName, "hostPane") == 0) {
  1746. X      strcpy (currentHost, newValue);
  1747. X      reDisplayProcessesIfNecessary ();
  1748. X
  1749. X     } else if (strcmp (widgetName, "userPane") == 0) {
  1750. X      strcpy (currentUser, newValue);
  1751. X      reDisplayProcessesIfNecessary ();
  1752. X
  1753. X     } else if (strcmp (widgetName, "groupPane") == 0) {
  1754. X      strcpy (currentGroup, newValue);
  1755. X      reDisplayProcessesIfNecessary ();
  1756. X
  1757. X     } else if (strcmp (widgetName, "terminalPane") == 0) {
  1758. X      strcpy (currentTerminal, newValue);
  1759. X      reDisplayProcessesIfNecessary ();
  1760. X
  1761. X     } else if (strcmp (widgetName, "actionPane") == 0) {
  1762. X      strcpy (currentAction, newValue);
  1763. X      if (resources.automaticRefresh)
  1764. X           applyAction ();
  1765. X
  1766. X     } else
  1767. X      error ("Invalid option menu selection :\ninternal error", (char *) 0);
  1768. X
  1769. X     noInputMode ();
  1770. X}
  1771. X
  1772. X
  1773. Xvoid textParameterUpdate (currentValue, newValue, menuPane)
  1774. X     String currentValue;
  1775. X     String newValue;
  1776. X     Widget menuPane;
  1777. X{
  1778. X     if (! strcmp (currentValue, newValue))
  1779. X      return;
  1780. X     
  1781. X     strcpy (currentValue, newValue);
  1782. X     
  1783. X     if (resources.automaticMemory) {
  1784. X      Widget menuElement;
  1785. X      XmString label;
  1786. X      
  1787. X      Arg arglist[3];
  1788. X      Cardinal i;
  1789. X      
  1790. X      label = XmStringCreateLtoR (newValue, XmSTRING_DEFAULT_CHARSET);
  1791. X
  1792. X      i = 0;
  1793. X      XtSetArg (arglist[i], XmNlabelString, label); i++;
  1794. X      menuElement = (Widget) XmCreatePushButtonGadget (menuPane,
  1795. X                               newValue,
  1796. X                               arglist, i);
  1797. X      XtManageChild (menuElement);
  1798. X      XtAddCallback (menuElement,
  1799. X             XmNactivateCallback,
  1800. X             (XtCallbackProc) menuParameterChange, newValue);
  1801. X      
  1802. X      XmStringFree (label);
  1803. X     }
  1804. X}
  1805. X
  1806. X
  1807. Xvoid textParameterChange (widget, event, parameters, parameterCount)
  1808. X     Widget widget;
  1809. X     XEvent *event;
  1810. X     String *parameters;
  1811. X     Cardinal *parameterCount;
  1812. X{
  1813. X     String newValue = XmTextGetString (widget);
  1814. X     Boolean error = False;
  1815. X     Boolean noTerminal = False;
  1816. X
  1817. X     String newUser;
  1818. X     String newGroup;
  1819. X     String newTerminal = "";
  1820. X     String newHost;
  1821. X     String newAction;
  1822. X
  1823. X     extern void statusLineUpdate ();
  1824. X
  1825. X     if (strstr (newValue, "()") != NULL)
  1826. X      noTerminal = True;
  1827. X     
  1828. X     if ((newUser = strtok (newValue, ":")) == NULL)
  1829. X      error = True;
  1830. X
  1831. X     if ((newGroup = strtok (NULL, "(")) == NULL)
  1832. X      error = True;
  1833. X
  1834. X     if (! noTerminal)
  1835. X      newTerminal = strtok (NULL, ")");
  1836. X
  1837. X     if ((newHost = strtok (NULL, " ")) == NULL)
  1838. X      error = True;
  1839. X     else
  1840. X      newHost = newHost + (noTerminal ? 2 : 1);
  1841. X
  1842. X     if ((newAction = strtok (NULL, ")")) == NULL)
  1843. X      error = True;
  1844. X     else
  1845. X      newAction = newAction + 2;
  1846. X
  1847. X     if (!error) {
  1848. X      textParameterUpdate (currentUser, newUser, userPane);
  1849. X      textParameterUpdate (currentGroup, newGroup, groupPane);
  1850. X      textParameterUpdate (currentTerminal, newTerminal, terminalPane);
  1851. X      textParameterUpdate (currentHost, newHost, hostPane);
  1852. X      textParameterUpdate (currentAction, newAction, actionPane);
  1853. X
  1854. X      reDisplayProcessesIfNecessary ();
  1855. X     }
  1856. X     noInputMode ();
  1857. X
  1858. X     XtFree (newValue);
  1859. X}
  1860. X
  1861. X
  1862. Xvoid inputMode ()
  1863. X{
  1864. X     Widget statusArea = XtNameToWidget (topLevel,
  1865. X                     "topWindow.selectionArea.statusArea");
  1866. X     Widget textArea = XtNameToWidget (topLevel,
  1867. X                       "topWindow.selectionArea.textArea");
  1868. X
  1869. X     extern void textLineUpdate ();
  1870. X
  1871. X     XtUnmanageChild (statusArea);
  1872. X     textLineUpdate ();
  1873. X     XtManageChild (textArea);
  1874. X}
  1875. X
  1876. X
  1877. Xvoid noInputMode ()
  1878. X{
  1879. X     Widget statusArea = XtNameToWidget (topLevel,
  1880. X                     "topWindow.selectionArea.statusArea");
  1881. X     Widget textArea = XtNameToWidget (topLevel,
  1882. X                       "topWindow.selectionArea.textArea");
  1883. X
  1884. X     extern void statusLineUpdate ();
  1885. X
  1886. X     XtUnmanageChild (textArea);
  1887. X     statusLineUpdate ();
  1888. X     XtManageChild (statusArea);
  1889. X}
  1890. X
  1891. X
  1892. Xvoid infoLineUpdate (processCount)
  1893. X     int processCount;
  1894. X{
  1895. X     Widget infoArea = XtNameToWidget (topLevel,
  1896. X                       "topWindow.selectionArea.infoArea");
  1897. X     XmString label;
  1898. X     char infoLine[512];
  1899. X
  1900. X     Arg arglist[2];
  1901. X     Cardinal i;
  1902. X     
  1903. X     sprintf (infoLine, "%d Processes", processCount);
  1904. X
  1905. X     label = XmStringCreateLtoR (infoLine, XmSTRING_DEFAULT_CHARSET);
  1906. X
  1907. X     i = 0;
  1908. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1909. X     XtSetValues (infoArea, arglist, i);
  1910. X
  1911. X     XmStringFree (label);
  1912. X}
  1913. X
  1914. X
  1915. Xvoid statusLineUpdate ()
  1916. X{
  1917. X     Widget statusArea = XtNameToWidget (topLevel,
  1918. X                     "topWindow.selectionArea.statusArea");
  1919. X     XmString label;
  1920. X     char statusLine[512];
  1921. X
  1922. X     Arg arglist[2];
  1923. X     Cardinal i;
  1924. X     
  1925. X     sprintf (statusLine,
  1926. X          "%s:%s(%s)@%s  (%s)",
  1927. X          currentUser, currentGroup, currentTerminal, currentHost,
  1928. X          currentAction);
  1929. X
  1930. X     label = XmStringCreateLtoR (statusLine, XmSTRING_DEFAULT_CHARSET);
  1931. X
  1932. X     i = 0;
  1933. X     XtSetArg (arglist[i], XmNlabelString, label); i++;
  1934. X     XtSetValues (statusArea, arglist, i);
  1935. X
  1936. X     XmStringFree (label);
  1937. X}
  1938. X
  1939. X
  1940. Xvoid textLineUpdate ()
  1941. X{
  1942. X     Widget textArea = XtNameToWidget (topLevel,
  1943. X                       "topWindow.selectionArea.textArea");
  1944. X     char statusLine[512];
  1945. X     
  1946. X     sprintf (statusLine,
  1947. X          "%s:%s(%s)@%s  (%s)",
  1948. X          currentUser, currentGroup, currentTerminal, currentHost,
  1949. X          currentAction);
  1950. X
  1951. X     XmTextSetString (textArea, statusLine);
  1952. X}
  1953. END_OF_FILE
  1954.   if test 5378 -ne `wc -c <'status.c'`; then
  1955.     echo shar: \"'status.c'\" unpacked with wrong size!
  1956.   fi
  1957.   # end of 'status.c'
  1958. fi
  1959. if test -f 'xmps.h' -a "${1}" != "-c" ; then 
  1960.   echo shar: Will not clobber existing file \"'xmps.h'\"
  1961. else
  1962.   echo shar: Extracting \"'xmps.h'\" \(4496 characters\)
  1963.   sed "s/^X//" >'xmps.h' <<'END_OF_FILE'
  1964. X/*
  1965. X * Copyright (C) 1991, 1992 Jean-Jacques Moreau.
  1966. X *
  1967. X * Permission to use, copy, modify and distribute this software
  1968. X * and its documentation for any purpose is hereby granted without fee,
  1969. X * provided that the above copyright notice appear in all copies and
  1970. X * that both that copyright notice and this permission notice appear
  1971. X * in supporting documentation.  The author makes no representations
  1972. X * about the suitability of this software for any purpose.  It is
  1973. X * provided "as is" without express or implied warranty.
  1974. X *
  1975. X * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  1976. X * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
  1977. X * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  1978. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  1979. X * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1980. X * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
  1981. X * USE OR PERFORMANCE OF THIS SOFTWARE.
  1982. X */
  1983. X
  1984. X
  1985. X#ifdef GLOBAL
  1986. X#define EXTERN
  1987. X#else
  1988. X#define EXTERN extern
  1989. X#endif
  1990. X
  1991. X
  1992. XEXTERN Widget topLevel;
  1993. XEXTERN Widget processArea;
  1994. XEXTERN Widget headerArea;
  1995. XEXTERN Widget listArea;
  1996. X
  1997. XEXTERN Widget searchDialog;
  1998. X
  1999. XEXTERN Widget processPane;
  2000. XEXTERN Widget hostPane;
  2001. XEXTERN Widget userPane;
  2002. XEXTERN Widget groupPane;
  2003. XEXTERN Widget terminalPane;
  2004. XEXTERN Widget actionPane;
  2005. XEXTERN Widget viewPane;
  2006. XEXTERN Widget optionPane;
  2007. XEXTERN Widget helpPane;
  2008. X
  2009. X#ifdef GLOBAL
  2010. Xchar currentHost[512];
  2011. Xchar currentUser[512];
  2012. Xchar currentGroup[512];
  2013. Xchar currentTerminal[512];
  2014. Xchar currentAction[512];
  2015. X#else
  2016. Xextern char currentHost[];
  2017. Xextern char currentUser[];
  2018. Xextern char currentGroup[];
  2019. Xextern char currentTerminal[];
  2020. Xextern char currentAction[];
  2021. X#endif
  2022. X
  2023. XBoolean internalBeautifier;
  2024. X
  2025. XEXTERN Cursor busyCursor;
  2026. X
  2027. X
  2028. X#define ACTION_SEARCH        101
  2029. X#define ACTION_SEARCH_NEXT    102
  2030. X#define ACTION_SEARCH_PREVIOUS    103
  2031. X#define ACTION_NEW_VIEW        104
  2032. X
  2033. X#define MENU_AUTOMATIC_REFRESH    201
  2034. X#define MENU_FULL_LISTING    202
  2035. X#define MENU_LONG_LISTING    203
  2036. X#define MENU_ALL_PROCESSES    205
  2037. X#define MENU_NO_GROUP_LEADER    206
  2038. X#define MENU_NO_NON_TERMINAL    207
  2039. X#define MENU_AUTOMATIC_MEMORY    208
  2040. X#define MENU_BEAUTIFY        209
  2041. X#define MENU_MULTIPLE_OCCURRENCES 210
  2042. X#define MENU_PERIODIC_REFRESH    211
  2043. X#define MENU_IGNORE_CASE    212
  2044. X#define MENU_PRINT_SELECTED    213
  2045. X
  2046. X
  2047. Xextern void textParameterChange ();
  2048. Xextern int menuParameterChange ();
  2049. Xextern void reDisplayProcessesIfNecessary ();
  2050. Xextern int reDisplayProcesses ();
  2051. Xextern int selectAllProcesses ();
  2052. Xextern int unselectAllProcesses ();
  2053. Xextern int applyAction ();
  2054. Xextern int searchProcessPrompt ();
  2055. Xextern int searchProcess ();
  2056. Xextern int exitXmPs ();
  2057. Xextern int createNewView ();
  2058. Xextern int takeSnapshot ();
  2059. Xextern int changeOption ();
  2060. Xextern int versionXmPs ();
  2061. Xextern int printProcesses ();
  2062. Xextern int printSnapshotProcesses ();
  2063. Xextern void printProcessesFrom ();
  2064. Xextern String executeCommand ();
  2065. Xextern int pid ();
  2066. Xextern int ppid ();
  2067. Xextern String format ();
  2068. Xextern void inputMode ();
  2069. Xextern void noInputMode ();
  2070. Xextern String concat ();
  2071. Xextern void parseHeader ();
  2072. Xextern void error ();
  2073. X
  2074. X
  2075. Xtypedef struct _ResourceRec {
  2076. X     String hosts;
  2077. X     String actions;
  2078. X     String users;
  2079. X     String usersOption;
  2080. X     String groups;
  2081. X     String groupsOption;
  2082. X     String terminals;
  2083. X     String terminalsOption;
  2084. X
  2085. X     String psCommand;
  2086. X     String rshCommand;
  2087. X     String printCommand;
  2088. X     String beautifyCommand;
  2089. X
  2090. X     int refreshPeriod;
  2091. X
  2092. X     Boolean automaticRefresh;
  2093. X     Boolean periodicRefresh;
  2094. X     Boolean automaticMemory;
  2095. X     Boolean beautify;
  2096. X     Boolean multipleOccurrences;
  2097. X     Boolean ignoreCase;
  2098. X     Boolean printSelected;
  2099. X
  2100. X     Boolean allProcesses;
  2101. X     Boolean noGroupLeader;
  2102. X     Boolean noNonTerminal;
  2103. X     String allProcessesOption;
  2104. X     String noGroupLeaderOption;
  2105. X     String noNonTerminalOption;
  2106. X
  2107. X     Boolean fullListing;
  2108. X     Boolean longListing;
  2109. X     String fullListingOption;
  2110. X     String longListingOption;
  2111. X} ResourceStruct, *ResourceRec;
  2112. X
  2113. Xtypedef struct _MenuDescRec {
  2114. X     String label;        /* button label ("[-^]Label") */
  2115. X     String id;            /* button internal identifier */
  2116. X     char mnemonic;        /* button mnemonic */
  2117. X     String acceleratorText;    /* button accelerator label */
  2118. X     String accelerator;    /* button accelerator */
  2119. X     int (*callback) ();    /* activateCallback or valueChangedCallback */
  2120. X     XtPointer callbackData;    /* data passed to callback when called */
  2121. X     Boolean *state;        /* initial state if toggle button ("^Label") */
  2122. X} MenuDescStruct, *MenuDescRec;
  2123. X
  2124. X
  2125. XEXTERN ResourceStruct resources;
  2126. END_OF_FILE
  2127.   if test 4496 -ne `wc -c <'xmps.h'`; then
  2128.     echo shar: \"'xmps.h'\" unpacked with wrong size!
  2129.   fi
  2130.   # end of 'xmps.h'
  2131. fi
  2132. echo shar: End of archive 2 \(of 3\).
  2133. cp /dev/null ark2isdone
  2134. MISSING=""
  2135. for I in 1 2 3 ; do
  2136.     if test ! -f ark${I}isdone ; then
  2137.     MISSING="${MISSING} ${I}"
  2138.     fi
  2139. done
  2140. if test "${MISSING}" = "" ; then
  2141.     echo You have unpacked all 3 archives.
  2142.     rm -f ark[1-9]isdone
  2143. else
  2144.     echo You still must unpack the following archives:
  2145.     echo "        " ${MISSING}
  2146. fi
  2147. exit 0
  2148. exit 0 # Just in case...
  2149. -- 
  2150.   // chris@IMD.Sterling.COM       | Send comp.sources.x submissions to:
  2151. \X/  Amiga - The only way to fly! |    sources-x@imd.sterling.com
  2152.  "It's intuitively obvious to the |
  2153.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  2154.