home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3642 < prev    next >
Encoding:
Text File  |  1991-07-17  |  40.1 KB  |  1,383 lines

  1. Newsgroups: alt.sources
  2. From: jtsillas@sprite.ma30.bull.com (James Tsillas)
  3. Subject: mxgdb Part 4/9
  4. Date: 16 Jul 91 13:05:20
  5. Message-ID: <JTSILLAS.91Jul16130520@sprite.ma30.bull.com>
  6.  
  7.  
  8.  
  9. ---- Cut Here and feed the following to sh ----
  10. #!/bin/sh
  11. # this is mxgdb.04 (part 4 of a multipart archive)
  12. # do not concatenate these parts, unpack them in order with /bin/sh
  13. # file mxgdb/regex.c continued
  14. #
  15. if test ! -r _shar_seq_.tmp; then
  16.     echo 'Please unpack part 1 first!'
  17.     exit 1
  18. fi
  19. (read Scheck
  20.  if test "$Scheck" != 4; then
  21.     echo Please unpack part "$Scheck" next!
  22.     exit 1
  23.  else
  24.     exit 0
  25.  fi
  26. ) < _shar_seq_.tmp || exit 1
  27. if test ! -f _shar_wnt_.tmp; then
  28.     echo 'x - still skipping mxgdb/regex.c'
  29. else
  30. echo 'x - continuing file mxgdb/regex.c'
  31. sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/regex.c' &&
  32. X        break;
  33. X      goto fail;
  34. X
  35. X    case exactn:
  36. X      /* Match the next few pattern characters exactly.
  37. X         mcnt is how many characters to match. */
  38. X      mcnt = *p++;
  39. X      if (translate)
  40. X        {
  41. X          do
  42. X        {
  43. X          PREFETCH;
  44. X          if (translate[*(unsigned char *)d++] != *p++) goto fail;
  45. X        }
  46. X          while (--mcnt);
  47. X        }
  48. X      else
  49. X        {
  50. X          do
  51. X        {
  52. X          PREFETCH;
  53. X          if (*d++ != *p++) goto fail;
  54. X        }
  55. X          while (--mcnt);
  56. X        }
  57. X      break;
  58. X    }
  59. X      continue;    /* Successfully matched one pattern command; keep matching */
  60. X
  61. X      /* Jump here if any matching operation fails. */
  62. X    fail:
  63. X      if (stackp != stackb)
  64. X    /* A restart point is known.  Restart there and pop it. */
  65. X    {
  66. X      if (!stackp[-2])
  67. X        {   /* If innermost failure point is dormant, flush it and keep looking */
  68. X          stackp -= 2;
  69. X          goto fail;
  70. X        }
  71. X      d = *--stackp;
  72. X      p = *--stackp;
  73. X      if (d >= string1 && d <= end1)
  74. X        dend = end_match_1;
  75. X    }
  76. X      else break;   /* Matching at this starting point really fails! */
  77. X    }
  78. X  return -1;         /* Failure to match */
  79. }
  80. X
  81. int
  82. bcmp_translate (s1, s2, len, translate)
  83. X     unsigned char *s1, *s2;
  84. X     register int len;
  85. X     unsigned char *translate;
  86. {
  87. X  register unsigned char *p1 = s1, *p2 = s2;
  88. X  while (len)
  89. X    {
  90. X      if (translate [*p1++] != translate [*p2++]) return 1;
  91. X      len--;
  92. X    }
  93. X  return 0;
  94. }
  95. X
  96. /* Entry points compatible with bsd4.2 regex library */
  97. X
  98. #ifndef emacs
  99. X
  100. static struct re_pattern_buffer re_comp_buf;
  101. X
  102. char *
  103. re_comp (s)
  104. X     char *s;
  105. {
  106. X  if (!s)
  107. X    {
  108. X      if (!re_comp_buf.buffer)
  109. X    return "No previous regular expression";
  110. X      return 0;
  111. X    }
  112. X
  113. X  if (!re_comp_buf.buffer)
  114. X    {
  115. X      if (!(re_comp_buf.buffer = (char *) malloc (200)))
  116. X    return "Memory exhausted";
  117. X      re_comp_buf.allocated = 200;
  118. X      if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH)))
  119. X    return "Memory exhausted";
  120. X    }
  121. X  return re_compile_pattern (s, strlen (s), &re_comp_buf);
  122. }
  123. X
  124. int
  125. re_exec (s)
  126. X     char *s;
  127. {
  128. X  int len = strlen (s);
  129. X  return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0);
  130. }
  131. X
  132. #endif /* emacs */
  133. X
  134. #ifdef test
  135. X
  136. #include <stdio.h>
  137. X
  138. /* Indexed by a character, gives the upper case equivalent of the character */
  139. X
  140. static char upcase[0400] = 
  141. X  { 000, 001, 002, 003, 004, 005, 006, 007,
  142. X    010, 011, 012, 013, 014, 015, 016, 017,
  143. X    020, 021, 022, 023, 024, 025, 026, 027,
  144. X    030, 031, 032, 033, 034, 035, 036, 037,
  145. X    040, 041, 042, 043, 044, 045, 046, 047,
  146. X    050, 051, 052, 053, 054, 055, 056, 057,
  147. X    060, 061, 062, 063, 064, 065, 066, 067,
  148. X    070, 071, 072, 073, 074, 075, 076, 077,
  149. X    0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  150. X    0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  151. X    0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  152. X    0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
  153. X    0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  154. X    0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  155. X    0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  156. X    0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
  157. X    0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
  158. X    0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
  159. X    0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
  160. X    0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
  161. X    0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
  162. X    0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
  163. X    0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
  164. X    0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
  165. X    0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
  166. X    0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
  167. X    0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
  168. X    0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
  169. X    0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
  170. X    0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
  171. X    0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
  172. X    0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  173. X  };
  174. X
  175. main ()
  176. {
  177. X  char pat[80];
  178. X  struct re_pattern_buffer buf;
  179. X  int i;
  180. X  char c;
  181. X  char fastmap[(1 << BYTEWIDTH)];
  182. X
  183. X  buf.allocated = 40;
  184. X  buf.buffer = (char *) malloc (buf.allocated);
  185. X  buf.fastmap = fastmap;
  186. X  buf.translate = upcase;
  187. X
  188. X  while (1)
  189. X    {
  190. X      gets (pat);
  191. X
  192. X      if (*pat)
  193. X    {
  194. X          re_compile_pattern (pat, strlen(pat), &buf);
  195. X
  196. X      for (i = 0; i < buf.used; i++)
  197. X        printchar (buf.buffer[i]);
  198. X
  199. X      putchar ('\n');
  200. X
  201. X      printf ("%d allocated, %d used.\n", buf.allocated, buf.used);
  202. X
  203. X      re_compile_fastmap (&buf);
  204. X      printf ("Allowed by fastmap: ");
  205. X      for (i = 0; i < (1 << BYTEWIDTH); i++)
  206. X        if (fastmap[i]) printchar (i);
  207. X      putchar ('\n');
  208. X    }
  209. X
  210. X      gets (pat);    /* Now read the string to match against */
  211. X
  212. X      i = re_match (&buf, pat, strlen (pat), 0, 0);
  213. X      printf ("Match value %d.\n", i);
  214. X    }
  215. }
  216. X
  217. #ifdef NOTDEF
  218. print_buf (bufp)
  219. X     struct re_pattern_buffer *bufp;
  220. {
  221. X  int i;
  222. X
  223. X  printf ("buf is :\n----------------\n");
  224. X  for (i = 0; i < bufp->used; i++)
  225. X    printchar (bufp->buffer[i]);
  226. X  
  227. X  printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  228. X  
  229. X  printf ("Allowed by fastmap: ");
  230. X  for (i = 0; i < (1 << BYTEWIDTH); i++)
  231. X    if (bufp->fastmap[i])
  232. X      printchar (i);
  233. X  printf ("\nAllowed by translate: ");
  234. X  if (bufp->translate)
  235. X    for (i = 0; i < (1 << BYTEWIDTH); i++)
  236. X      if (bufp->translate[i])
  237. X    printchar (i);
  238. X  printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  239. X  printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  240. }
  241. #endif
  242. X
  243. printchar (c)
  244. X     char c;
  245. {
  246. X  if (c < 041 || c >= 0177)
  247. X    {
  248. X      putchar ('\\');
  249. X      putchar (((c >> 6) & 3) + '0');
  250. X      putchar (((c >> 3) & 7) + '0');
  251. X      putchar ((c & 7) + '0');
  252. X    }
  253. X  else
  254. X    putchar (c);
  255. }
  256. X
  257. error (string)
  258. X     char *string;
  259. {
  260. X  puts (string);
  261. X  exit (1);
  262. }
  263. X
  264. #endif test
  265. SHAR_EOF
  266. echo 'File mxgdb/regex.c is complete' &&
  267. chmod 0664 mxgdb/regex.c ||
  268. echo 'restore of mxgdb/regex.c failed'
  269. Wc_c="`wc -c < 'mxgdb/regex.c'`"
  270. test 46422 -eq "$Wc_c" ||
  271.     echo 'mxgdb/regex.c: original size 46422, current size' "$Wc_c"
  272. rm -f _shar_wnt_.tmp
  273. fi
  274. # ============= mxgdb/command.c ==============
  275. if test -f 'mxgdb/command.c' -a X"$1" != X"-c"; then
  276.     echo 'x - skipping mxgdb/command.c (File already exists)'
  277.     rm -f _shar_wnt_.tmp
  278. else
  279. > _shar_wnt_.tmp
  280. echo 'x - extracting mxgdb/command.c (Text)'
  281. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/command.c' &&
  282. static char rcsid[] = "$Id: command.c,v 1.5 1991/07/01 20:57:19 jtsillas Exp $";
  283. X
  284. /*****************************************************************************
  285. X *
  286. X *  xdbx - X Window System interface to the dbx debugger
  287. X *
  288. X *  Copyright 1989 The University of Texas at Austin
  289. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  290. X *
  291. X *  Permission to use, copy, modify, and contribute this software and its
  292. X *  documentation for any purpose and without fee is hereby granted,
  293. X *  provided that the above copyright notice appear in all copies and that
  294. X *  both that copyright notice and this permission notice appear in
  295. X *  supporting documentation, and that the name of The University of Texas
  296. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  297. X *  used in advertising or publicity pertaining to distribution of
  298. X *  the software without specific, written prior permission.  The
  299. X *  University of Texas and MCC makes no representations about the 
  300. X *  suitability of this software for any purpose.  It is provided "as is" 
  301. X *  without express or implied warranty.
  302. X *
  303. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  304. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  305. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  306. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  307. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  308. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  309. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  310. X *
  311. X *  Author:      Po Cheung
  312. X *  Created:       March 10, 1989
  313. X * 
  314. X *****************************************************************************
  315. X * 
  316. X *  xxgdb - X Window System interface to the gdb debugger
  317. X *  
  318. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  319. X *  
  320. X *  Permission to use, copy, modify, and distribute this software and its
  321. X *  documentation for any purpose and without fee is hereby granted,
  322. X *  provided that the above copyright notice appear in all copies and that
  323. X *  both that copyright notice and this permission notice appear in
  324. X *  supporting documentation, and that the name of Thomson Consumer
  325. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  326. X *  to distribution of the software without specific, written prior
  327. X *  permission.  TCE makes no representations about the suitability of
  328. X *  this software for any purpose.  It is provided "as is" without express
  329. X *  or implied warranty.
  330. X *
  331. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  332. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  333. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  334. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  335. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  336. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  337. X *  SOFTWARE.
  338. X *
  339. X *  Adaptation to GDB:  Pierre Willard
  340. X *  XXGDB Created:       December, 1990
  341. X *
  342. X *****************************************************************************
  343. X
  344. /*  command.c
  345. X *
  346. X *    Create the command window, the command buttons and their callbacks.
  347. X *
  348. X *    CreateCommandPanel() :     Create a window with command buttons
  349. X *    CreateButtons() :        Create command buttons in panel
  350. X *    AddButton() :        Add a command button into the command window
  351. X *    ButtonSet() :        Action proc for command button translation
  352. X *
  353. X *    Command callbacks for the command buttons:
  354. X *
  355. X *    forwardSearch() :        forward string search
  356. X *    reverseSearch() :        reverse string search
  357. X *    Search() :        call either forwardSearch() or reverseSearch()
  358. X *    PopupSearch() :        command callback for search button
  359. X *    DoneSearch() :        command callback for DONE button in search panel
  360. X *    CreateSearchPopup() :    create search panel
  361. X *
  362. X *    Command queue manipulation routines:
  363. X *    send_command():        send a command to dbx and record in the queue
  364. X *    get_command():        read command off head of queue
  365. X *    insert_command():    insert command at the head of queue
  366. X *    delete_command():    delete command from head of queue
  367. X */
  368. #include <signal.h>
  369. #include <ctype.h>
  370. #include <sys/wait.h>
  371. #include "global.h"
  372. #include <Xm/Xm.h>
  373. #include <Xm/RowColumn.h>
  374. #include <Xm/PushB.h>
  375. #include <Xm/ArrowB.h>
  376. #include <Xm/Text.h>
  377. #include <Xm/Form.h>
  378. #include <Xm/DialogS.h>
  379. X
  380. #define     REVERSE    0
  381. #define     FORWARD    1
  382. X
  383. Widget        commandWindow,        /* command panel with buttons */
  384. X                arrowL, arrowR, cancelButton, helpButton, searchText, 
  385. X                searchLabel;
  386. static Widget    searchPopupShell;
  387. static Widget    AddButton();
  388. /* static Widget    button[30]; */
  389. static char    SearchString[BUFSIZ] = "";    /* search string buffer */
  390. static char    command[LINESIZ];
  391. static CommandRec *commandQueue = NULL;
  392. X
  393. /* ARGSUSED */
  394. /*  Execute the dbx command specifed in client_data
  395. X */
  396. void DoIt (w, command, call_data)
  397. X    Widget w;
  398. X    XtPointer command;
  399. X    XtPointer call_data;
  400. {
  401. X    /* run, cont, next, step, where, up, down, status */
  402. X    send_command(command);
  403. X    AppendDialogText(command);
  404. }
  405. X
  406. /*
  407. X    here client_data is "break" or "tbreak"
  408. X
  409. */
  410. void Break(w, client_data, call_data)
  411. X     Widget w;
  412. X     char * client_data;
  413. X     XtPointer call_data;
  414. {
  415. X    XmTextPosition pos;
  416. X    int line;
  417. X    char *string1;
  418. X    char *string2;
  419. X    char *s;
  420. X
  421. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  422. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  423. X
  424. X    if(string2 && !string1)
  425. X      {
  426. X        string1 = string2;
  427. X        string2 = NULL;
  428. X      }
  429. X
  430. X    if(string2) XtFree(string2);
  431. X
  432. X    if (string1 && *string1) 
  433. X      {
  434. X    s = string1;
  435. X    while (*s == ' ') s++;    /* skip leading spaces (if any) */
  436. X    if ((*s >= '0') && (*s <= '9'))
  437. X      sprintf(command, "%s *%s\n",client_data,string1);
  438. X    else
  439. X      sprintf(command, "%s %s\n",client_data,string1);
  440. X      }
  441. X    else
  442. X      {
  443. X    if (displayedFile != NULL)
  444. X      {
  445. X        pos = XmTextGetInsertionPosition(sourceWindow);
  446. X        line = TextPositionToLine(pos);
  447. X        sprintf(command, "%s %d\n",client_data,line);
  448. X      }
  449. X    else
  450. X      {
  451. X        UpdateMessageWindow(BREAK_HELP, NULL);
  452. X        bell(0);
  453. X        if(string1) XtFree(string1);
  454. X        return;
  455. X      }
  456. X      }
  457. X    
  458. X    if(string1) XtFree(string1);
  459. X    send_command(command);
  460. X    AppendDialogText(command);
  461. X  }
  462. X
  463. /*  Clear removes the stop_no associated with a given line number.
  464. X *  RemoveStop() is called to undisplay the stop sign only when there
  465. X *  are no more stop_no's associated with that line number.
  466. X */
  467. X                /* A modification to this would allow selecting
  468. X                 a function name which has a break associated 
  469. X                 with it. A shift-Btn1Down should give a
  470. X                 selection-box of all available break points
  471. X                 - Jim (5-4-91)*/
  472. /* ARGSUSED */
  473. void Clear(w, client_data, call_data)
  474. X    Widget w;
  475. X    XtPointer client_data;
  476. X    XtPointer call_data;
  477. {
  478. X    XmTextPosition pos;
  479. X    int            line;
  480. X    char           *string1, *string2;
  481. X
  482. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  483. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  484. X
  485. X    if(string2 && !string1)
  486. X      {
  487. X    string1 = string2;
  488. X    string2 = NULL;
  489. X      }
  490. X
  491. X    if(string2) XtFree(string2);
  492. X
  493. X    if(string1 && *string1 != '\0')
  494. X      {
  495. X    sprintf(command, "clear %s\n", string1);
  496. X    send_command(command);
  497. X    AppendDialogText(command);
  498. X    XtFree(string1);
  499. X    return;
  500. X      }
  501. X    if(string1) XtFree(string1);
  502. X
  503. X    if (displayedFile) {
  504. X      pos = XmTextGetInsertionPosition(sourceWindow);
  505. X      line = TextPositionToLine(pos);
  506. X      if (LineToStop_no(line)) {
  507. X    sprintf(command, "clear %d\n", line);
  508. X    send_command(command);
  509. X    AppendDialogText(command);
  510. X    return;
  511. X      }
  512. X    }
  513. X    UpdateMessageWindow(CLEAR_HELP, NULL);
  514. X    bell(0);
  515. }
  516. X
  517. /* ARGSUSED */
  518. void Print(w, client_data, call_data)
  519. X    Widget w;
  520. X    XtPointer client_data;
  521. X    XtPointer call_data;
  522. {
  523. X    char *string1, *string2;
  524. X    int nbytes;
  525. X
  526. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  527. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  528. X
  529. X    if(string2 && !string1)
  530. X      {
  531. X    string1 = string2;
  532. X    string2 = NULL;
  533. X      }
  534. X
  535. X    if(string2) XtFree(string2);
  536. X
  537. X    if(!string1 || *string1 == '\0')
  538. X      {
  539. X    UpdateMessageWindow(PRINT_HELP, NULL);
  540. X    bell(0);
  541. X    if(string1) XtFree(string1);
  542. X    return;
  543. X      }
  544. X    if (client_data == (XtPointer)0)
  545. X    sprintf(command, "print %s\n", string1);
  546. X    else if (client_data == (XtPointer)1)
  547. X    sprintf(command, "print *%s\n", string1);
  548. X    send_command(command);
  549. X    AppendDialogText(command);
  550. X    if(string1) XtFree(string1);
  551. }
  552. X
  553. /* ARGSUSED */
  554. void Quit(w, client_data, call_data)
  555. X    Widget w;
  556. X    XtPointer client_data;
  557. X    XtPointer call_data;
  558. {
  559. X
  560. X    int status;
  561. X
  562. X    write_dbx("quit\n");
  563. X    XtDestroyApplicationContext(app_context);
  564. X    kill(dbxpid, SIGKILL);
  565. X
  566. X    waitpid(&status, NULL, WNOHANG);
  567. X
  568. X    exit(0);
  569. }
  570. X
  571. extern int helpstackidx;
  572. X
  573. void Help(w, client_data, call_data)
  574. X     Widget w;
  575. X     XtPointer client_data;
  576. X     XtPointer call_data;
  577. {
  578. X  helpstackidx = 0;
  579. X  query_dbx("help\n");
  580. }
  581. X
  582. /* ARGSUSED */
  583. void Display_(w, client_data, call_data)
  584. X    Widget w;
  585. X    XtPointer client_data;
  586. X    XtPointer call_data;
  587. {
  588. X    char *string1, *string2;
  589. X    int nbytes;
  590. X
  591. X    if(!XtIsManaged(displayFD)) XtManageChild(displayFD);
  592. X
  593. X    string1 = (char *)XmTextGetSelection(sourceWindow);
  594. X    string2 = (char *)XmTextGetSelection(dialogWindow);
  595. X
  596. X    if(string2 && !string1)
  597. X      {
  598. X    string1 = string2;
  599. X    string2 = NULL;
  600. X      }
  601. X
  602. X    if(string2) XtFree(string2);
  603. X
  604. X    if(string1 && *string1 != '\0')
  605. X      {
  606. X    sprintf(command, "display %s\n", string1);
  607. X    send_command(command);
  608. X    AppendDialogText(command);
  609. X    XtFree(string1);
  610. X    return;
  611. X      }
  612. X    if(string1) XtFree(string1);
  613. X
  614. }
  615. X
  616. /* ARGSUSED */
  617. void Undisplay(w, client_data, call_data)
  618. X    Widget w;
  619. X    XtPointer client_data;
  620. X    XtPointer call_data;
  621. {
  622. X  char *string1, s[5], *st1, *st2;
  623. X  int     stop_no, nbytes;
  624. X  
  625. X  string1 = XmTextGetSelection(displayWindow);
  626. X  
  627. X  if (string1 && *string1)
  628. X    {
  629. X      st1 = s;
  630. X      st2 = string1;
  631. X      while((*st1++ = *st2++)!=':' && *st1);
  632. X      *(st1-1) = '\0';
  633. X      XtFree(string1);
  634. X      if ((stop_no = atoi(s)) > 0)
  635. X    {
  636. X      sprintf(command, "undisplay %d\n", stop_no);
  637. X      send_command(command);
  638. X      AppendDialogText(command);
  639. X    }
  640. X      else
  641. X    {
  642. X      UpdateMessageWindow(UNDISPLAY_HELP, NULL);
  643. X      bell(0);
  644. X      return;
  645. X    }
  646. X  }
  647. X  else
  648. X    {
  649. X      if(XtIsManaged(displayFD))
  650. X    XtUnmanageChild(displayFD);
  651. X      if(string1) XtFree(string1);
  652. X      return;
  653. X    }
  654. }
  655. X
  656. /*  Beginning from startpos, this routine searches text forward for 
  657. X *  searchstring, and returns 1 if searchstring is found, also returning 
  658. X *  the left and right positions of the matched string in left and right; 
  659. X *  else 0 is returned.
  660. X *  It also does wrap-around search.
  661. X */
  662. static forwardSearch(text, startpos, searchstring, left, right)
  663. X    char *text;
  664. X    int  startpos;
  665. X    char *searchstring;
  666. X    XmTextPosition  *left, *right;
  667. {
  668. X    int  searchlength, searchsize, i, n=0;
  669. X    char *s1, *s2;
  670. X
  671. X    searchlength = strlen(searchstring);
  672. X    searchsize = strlen(text) - searchlength;
  673. X    for (i=startpos; i < searchsize; i++) {
  674. X    n = searchlength;
  675. X    s1 = &text[i];
  676. X    s2 = searchstring;
  677. X    while (--n >= 0 && *++s1 == *s2++);
  678. X    if (n < 0) break;
  679. X    }
  680. X    if (n < 0) {
  681. X        *left = i+1;
  682. X        *right = i+1+searchlength;
  683. X        return 1;
  684. X    }
  685. X    else {
  686. X    for (i=0; i < startpos; i++) {
  687. X        n = searchlength;
  688. X        s1 = &text[i];
  689. X        s2 = searchstring;
  690. X        while (--n >= 0 && *++s1 == *s2++);
  691. X        if (n < 0) break;
  692. X    }
  693. X    if (n < 0) {
  694. X        *left = i+1;
  695. X        *right = i+1+searchlength;
  696. X        return 1;
  697. X    }
  698. X    return 0;
  699. X    }
  700. }
  701. X    
  702. X
  703. /*  Similar to forwardSearch(), except that it does a reverse search
  704. X */
  705. static reverseSearch(text, startpos, searchstring, left, right)
  706. X    char         *text;
  707. X    XmTextPosition  startpos;
  708. X    char         *searchstring;
  709. X    XmTextPosition  *left, *right;
  710. {
  711. X    int  searchlength, i, n=0;
  712. X    char *s1, *s2;
  713. X
  714. X    searchlength = strlen(searchstring);
  715. X    for (i=startpos; i > searchlength; i--) {
  716. X    n = searchlength;
  717. X    s1 = &text[i];
  718. X    s2 = &searchstring[searchlength-1];
  719. X    while (--n >= 0 && *--s1 == *s2--);
  720. X    if (n < 0) break;
  721. X    }
  722. X    if (n < 0) {
  723. X        *right = i;
  724. X        *left = *right-searchlength;
  725. X        return 1;
  726. X    }
  727. X    else {
  728. X    for (i=strlen(text)-1; i > startpos; i--) {
  729. X        n = searchlength;
  730. X        s1 = &text[i];
  731. X        s2 = &searchstring[searchlength-1];
  732. X        while (--n >= 0 && *--s1 == *s2--);
  733. X        if (n < 0) break;
  734. X    }
  735. X    if (n < 0) {
  736. X            *right = i;
  737. X            *left = *right-searchlength;
  738. X        return 1;
  739. X    }
  740. X    return 0;
  741. X    }
  742. }
  743. X
  744. /* ARGSUSED */
  745. void PopupSearch(w, client_data, call_data)
  746. X    Widget w;
  747. X    XtPointer client_data;
  748. X    XtPointer call_data;
  749. {
  750. X    if (!displayedFile) {
  751. X    UpdateMessageWindow(SEARCH_HELP, NULL);
  752. X    bell(0);
  753. X    }
  754. X    else {
  755. X    XtManageChild(searchPopupShell);
  756. X    }
  757. }
  758. X
  759. X
  760. /* ARGSUSED */
  761. /*  This routine handles both forward and reverse text search.
  762. X *  If no text has been entered, the contents of the cut buffer are used
  763. X *  for searching.
  764. X */ 
  765. static void Search(w, direction, call_data)
  766. X     Widget w;
  767. X     XtPointer direction;
  768. X     XtPointer call_data;
  769. {
  770. X  XmTextPosition    pos, left, right;
  771. X  char        *searchString;
  772. X  
  773. X  searchString = XmTextGetString(searchText);
  774. X  if(searchString && *searchString)
  775. X    {
  776. X      pos = XmTextGetInsertionPosition(sourceWindow);
  777. X      if ((direction == (XtPointer)FORWARD && 
  778. X       forwardSearch(displayedFile->buf, pos, searchString, &left, &right)) ||
  779. X      (direction == (XtPointer)REVERSE && 
  780. X       reverseSearch(displayedFile->buf, pos, searchString, &left, &right))) {
  781. X    AdjustText(TextPositionToLine(left));
  782. X    XmTextSetSelection(sourceWindow, left, right, 0);
  783. X    XmTextSetInsertionPosition(sourceWindow, left);
  784. X      }
  785. X      else {
  786. X    if (direction == (XtPointer)FORWARD)
  787. X      UpdateMessageWindow("String not found", NULL);
  788. X    else if (direction == (XtPointer)REVERSE)
  789. X      UpdateMessageWindow("String not found", NULL);
  790. X    else
  791. X      UpdateMessageWindow("xxgdb error: illegal search direction", NULL);
  792. X    bell(0);
  793. X      }
  794. X    }
  795. X  if(searchString) XtFree(searchString);
  796. }
  797. X
  798. void CreateSearchPopup(parent)
  799. Widget parent;
  800. {
  801. X    Arg     args[MAXARGS];
  802. X
  803. X    XtSetArg(args[0], XmNdialogTitle, 
  804. X             XmStringCreateLtoR("String Search", XmSTRING_DEFAULT_CHARSET));
  805. X
  806. X    searchPopupShell = XmCreateFormDialog(parent, "searchPopupShell", args, 1);
  807. X
  808. X    XtSetArg(args[0], XmNkeyboardFocusPolicy, XmPOINTER);
  809. X    XtSetValues(XtParent(searchPopupShell), args, 1);
  810. X
  811. X    XtSetArg(args[0], XmNleftAttachment, XmATTACH_POSITION);
  812. X    XtSetArg(args[1], XmNtopAttachment, XmATTACH_POSITION);
  813. X    XtSetArg(args[2], XmNlabelString, 
  814. X         XmStringCreateLtoR("Selection", XmSTRING_DEFAULT_CHARSET));
  815. X    searchLabel = XtCreateManagedWidget("searchLabel", xmLabelWidgetClass,
  816. X                       searchPopupShell, args, 3);
  817. X    XtSetArg(args[0], XmNleftAttachment, XmATTACH_POSITION);
  818. X    XtSetArg(args[1], XmNtopAttachment, XmATTACH_POSITION);
  819. X    XtSetArg(args[2], XmNrightAttachment, XmATTACH_POSITION);
  820. X    searchText = XtCreateManagedWidget("searchText", xmTextWidgetClass,
  821. X                       searchPopupShell, args, 3);
  822. X    XtSetArg(args[0], XmNarrowDirection, XmARROW_LEFT);
  823. X    XtSetArg(args[1], XmNbottomAttachment, XmATTACH_POSITION);
  824. X    XtSetArg(args[2], XmNleftAttachment, XmATTACH_POSITION);
  825. X    arrowL = XtCreateManagedWidget("arrowL", xmArrowButtonWidgetClass, 
  826. X                   searchPopupShell, args, 3);
  827. X
  828. X    XtAddCallback(arrowL, XmNactivateCallback, Search, (XtPointer)REVERSE);
  829. X
  830. X    XtSetArg(args[0], XmNarrowDirection, XmARROW_RIGHT);
  831. X    XtSetArg(args[1], XmNbottomAttachment, XmATTACH_POSITION);
  832. X    XtSetArg(args[2], XmNleftAttachment, XmATTACH_POSITION);
  833. X    arrowR = XtCreateManagedWidget("arrowR", xmArrowButtonWidgetClass, 
  834. X                   searchPopupShell, args, 3);
  835. X
  836. X    XtAddCallback(arrowR, XmNactivateCallback, Search, (XtPointer)FORWARD);
  837. X
  838. X    XtSetArg(args[0], XmNlabelString, 
  839. X         XmStringCreateLtoR("Cancel", XmSTRING_DEFAULT_CHARSET));
  840. X    XtSetArg(args[1], XmNbottomAttachment, XmATTACH_POSITION);
  841. X    XtSetArg(args[2], XmNrightAttachment, XmATTACH_POSITION);
  842. X    cancelButton = XtCreateManagedWidget("cancelButton", 
  843. X                     xmPushButtonWidgetClass, 
  844. X                     searchPopupShell, args, 3);
  845. X    XtSetArg(args[0], XmNlabelString, 
  846. X         XmStringCreateLtoR("Help", XmSTRING_DEFAULT_CHARSET));
  847. X    XtSetArg(args[1], XmNbottomAttachment, XmATTACH_POSITION);
  848. X    XtSetArg(args[2], XmNrightAttachment, XmATTACH_POSITION);
  849. X    helpButton = XtCreateManagedWidget("helpButton", 
  850. X                     xmPushButtonWidgetClass, 
  851. X                     searchPopupShell, args, 3);
  852. X    
  853. }
  854. X
  855. /**************************************************************************
  856. X *
  857. X *  Command queue functions
  858. X *
  859. X **************************************************************************/
  860. X
  861. /*  Append command to end of the command queue and send the command to dbx */
  862. X
  863. void send_command(command)
  864. char *command;
  865. {
  866. X    CommandRec *p, *q, *r;
  867. X
  868. #ifdef BSD 
  869. X    /* Save the command if it is not a blank command; else use the 
  870. X       last saved command instead */
  871. X    if (strcspn(command, " \n"))
  872. X    strcpy(savedCommand, command);
  873. X    else
  874. X    strcpy(command, savedCommand);
  875. #endif
  876. X
  877. X    p = (CommandRec *)XtNew(CommandRec);
  878. X    p->command = XtNewString(command);
  879. X    p->next = NULL;
  880. X    if (!commandQueue)
  881. X    commandQueue = p;
  882. X    else {
  883. X    q = commandQueue;
  884. X    while (r = q->next)
  885. X        q = r;
  886. X    q->next = p;
  887. X    }
  888. X    write_dbx(command);
  889. }
  890. X
  891. /*  Read command at the head of the command queue */
  892. X
  893. char *get_command()
  894. {
  895. X    if (commandQueue) {
  896. X    return (commandQueue->command);
  897. X    }
  898. X    else
  899. X    return NULL;
  900. }
  901. X
  902. /*  Delete command from the head of the command queue */
  903. X
  904. void delete_command()
  905. {
  906. X    CommandRec *p;
  907. X
  908. X    if (p = commandQueue) {
  909. X    commandQueue = p->next;
  910. X    XtFree(p->command);
  911. X    XtFree(p);
  912. X    }
  913. }
  914. X
  915. /*  Insert command into head of queue */
  916. X
  917. void insert_command(command)
  918. char *command;
  919. {
  920. X    CommandRec *p;
  921. X
  922. X    p = (CommandRec *)XtNew(CommandRec);
  923. X    p->command = XtNewString(command);
  924. X    p->next = NULL;
  925. X    if (!commandQueue)
  926. X    commandQueue = p;
  927. X    else {
  928. X    p->next = commandQueue;
  929. X    commandQueue = p;
  930. X    }
  931. }
  932. SHAR_EOF
  933. chmod 0664 mxgdb/command.c ||
  934. echo 'restore of mxgdb/command.c failed'
  935. Wc_c="`wc -c < 'mxgdb/command.c'`"
  936. test 17899 -eq "$Wc_c" ||
  937.     echo 'mxgdb/command.c: original size 17899, current size' "$Wc_c"
  938. rm -f _shar_wnt_.tmp
  939. fi
  940. # ============= mxgdb/source.c ==============
  941. if test -f 'mxgdb/source.c' -a X"$1" != X"-c"; then
  942.     echo 'x - skipping mxgdb/source.c (File already exists)'
  943.     rm -f _shar_wnt_.tmp
  944. else
  945. > _shar_wnt_.tmp
  946. echo 'x - extracting mxgdb/source.c (Text)'
  947. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/source.c' &&
  948. static char rcsid[] = "$Id: source.c,v 1.7 1991/07/16 14:20:30 jtsillas Exp $";
  949. X
  950. /*****************************************************************************
  951. X *
  952. X *  xdbx - X Window System interface to the dbx debugger
  953. X *
  954. X *  Copyright 1989 The University of Texas at Austin
  955. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  956. X *
  957. X *  Permission to use, copy, modify, and distribute this software and its
  958. X *  documentation for any purpose and without fee is hereby granted,
  959. X *  provided that the above copyright notice appear in all copies and that
  960. X *  both that copyright notice and this permission notice appear in
  961. X *  supporting documentation, and that the name of The University of Texas
  962. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  963. X *  used in advertising or publicity pertaining to distribution of
  964. X *  the software without specific, written prior permission.  The
  965. X *  University of Texas and MCC makes no representations about the 
  966. X *  suitability of this software for any purpose.  It is provided "as is" 
  967. X *  without express or implied warranty.
  968. X *
  969. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  970. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  971. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  972. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  973. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  974. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  975. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  976. X *
  977. X *  Author:      Po Cheung
  978. X *  Created:       March 10, 1989
  979. X * 
  980. X *****************************************************************************
  981. X * 
  982. X *  xxgdb - X Window System interface to the gdb debugger
  983. X *  
  984. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  985. X *  
  986. X *  Permission to use, copy, modify, and distribute this software and its
  987. X *  documentation for any purpose and without fee is hereby granted,
  988. X *  provided that the above copyright notice appear in all copies and that
  989. X *  both that copyright notice and this permission notice appear in
  990. X *  supporting documentation, and that the name of Thomson Consumer
  991. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  992. X *  to distribution of the software without specific, written prior
  993. X *  permission.  TCE makes no representations about the suitability of
  994. X *  this software for any purpose.  It is provided "as is" without express
  995. X *  or implied warranty.
  996. X *
  997. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  998. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  999. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  1000. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1001. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1002. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1003. X *  SOFTWARE.
  1004. X *
  1005. X *  Adaptation to GDB:  Pierre Willard
  1006. X *  XXGDB Created:       December, 1990
  1007. X *
  1008. X *****************************************************************************/
  1009. X
  1010. /*  source.c
  1011. X *
  1012. X *    Create the source window and handle display of file.
  1013. X *
  1014. X *    source_init():     Initialization routine.
  1015. X *    Update():        Action proc to update source window on scrollbar action.
  1016. X *    NotifyResize():    Action proc to update source window on resize.
  1017. X *    CreateSourceWindow(): Create the source window.
  1018. X *    BuildLinePos():    Build an array of starting text position of each line.
  1019. X *    LookUpFileTable():Check out source file info from a file table.
  1020. X *    SaveDisplayedFileInfo(): records displayed file info into file table.
  1021. X *    DisplayFile():    Display a file on the source window
  1022. X *    LoadFile():    Search for a file and open it for display.
  1023. X */
  1024. X
  1025. #include <X11/Xos.h>
  1026. #include <sys/stat.h>
  1027. #include <pwd.h>
  1028. #include "global.h"
  1029. #include "bitmaps.h"
  1030. #include "bitmaps2.h"
  1031. #ifdef SYSV 
  1032. #ifdef SCO
  1033. #   include <fcntl.h>
  1034. #endif
  1035. #endif /* SYSV */
  1036. X
  1037. #include <Xm/Xm.h>
  1038. #include <Xm/Form.h>
  1039. #include <Xm/Text.h>
  1040. #include <Xm/ScrolledW.h>
  1041. #include <Xm/ScrollBar.h>
  1042. #include <Xm/ArrowB.h>
  1043. #include <Xm/PushB.h>
  1044. X
  1045. #define    MAXDIRS    256            /* max number of dirs in dirList */
  1046. X
  1047. char        CurrentFile[MAXNAME];    /* current contents of file variable */
  1048. Widget        sourceWindow,        /* text window for source file */
  1049. X                sourceScroll,
  1050. X                scrollV,
  1051. X                sourceForm,
  1052. X                pageRbutton, pageLbutton,
  1053. X                breakbutton, stepbutton, nextbutton, printbutton,
  1054. X                downbutton, upbutton, stackbutton, contbutton, finishbutton,
  1055. X                runbutton, dispbutton, undispbutton, clearbutton, printsbutton,
  1056. X                argsbutton, localsbutton;
  1057. X
  1058. FileRec      *displayedFile;        /* pointer to table entry of currently
  1059. X                       displayed file */
  1060. X
  1061. static FileRec    **fileTable;        /* table of file records */
  1062. static int    fileTableSize;        /* size of file table */
  1063. static char     *dirList[MAXDIRS];    /* list of dirs for searching files */
  1064. static short    maxcol;
  1065. static short    currvalue;
  1066. X
  1067. void source_init()
  1068. {
  1069. X    dirList[0] = NULL;
  1070. }
  1071. X
  1072. /*
  1073. X *  Update topline, bottomline, arrow sign, updown sign, stop signs, and
  1074. X *  line label.
  1075. X */
  1076. /* ARGSUSED */
  1077. void Update(w, event, params, num_params)
  1078. X    Widget w;
  1079. X    XEvent *event;
  1080. X    String *params;
  1081. X    Cardinal *num_params;
  1082. {
  1083. X    XmTextPosition     pos;
  1084. X    int            topline;
  1085. X    FileRec         *file;
  1086. X    int Py;
  1087. X    Arg args[5];
  1088. X
  1089. X    if (displayedFile) {
  1090. X        file = displayedFile;
  1091. X    pos = XmTextGetTopCharacter(sourceWindow);
  1092. X    file->topPosition = pos;
  1093. X    topline = TextPositionToLine(pos);
  1094. X    /* Update the symbols only if the text scrolls */
  1095. X    if (file->topline != topline) {
  1096. X        file->topline = topline;
  1097. X        file->bottomline = MIN (file->topline + file->lines - 1, 
  1098. X                    file->lastline);
  1099. X        if (*num_params == 1 && strcmp(params[0], "warp") == 0)
  1100. X          {
  1101. X        XmTextSetInsertionPosition(sourceWindow, 
  1102. X                       file->linepos[file->topline]);
  1103. X          }
  1104. X
  1105. X        UpdateLineLabel(file->topline);
  1106. X            UpdateStops(file, -1);
  1107. X            UpdateArrow(file);
  1108. X            UpdateUpdown(file);
  1109. X            UpdateBomb(file);
  1110. X        Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
  1111. X        XtSetArg(args[0], XmNvalue, Py);
  1112. X        XtSetValues(scrollV, args, 1);
  1113. X
  1114. X    }
  1115. X    else {/* Update caret position only */
  1116. X        pos = XmTextGetInsertionPosition(sourceWindow);
  1117. X        UpdateLineLabel(TextPositionToLine(pos));
  1118. X    }
  1119. X    }
  1120. }
  1121. X
  1122. void UpdateSigns(reason)
  1123. {
  1124. X  int pos;
  1125. X  FileRec *file;
  1126. X
  1127. X  file = displayedFile;
  1128. X  pos = XmTextGetTopCharacter(sourceWindow);
  1129. X  file->topline = TextPositionToLine(pos);
  1130. X  file->bottomline = MIN (file->topline + file->lines - 1, 
  1131. X              file->lastline);
  1132. X  UpdateStops(file, reason);
  1133. X  UpdateArrow(file);
  1134. X  UpdateUpdown(file);
  1135. X  UpdateBomb(file);
  1136. X
  1137. }  
  1138. X
  1139. X
  1140. /*  Update the position of the caret */
  1141. /*  ARGSUSED */
  1142. void UpdateLine(w, event, params, num_params)
  1143. X    Widget w;
  1144. X    XEvent *event;
  1145. X    String *params;
  1146. X    Cardinal *num_params;
  1147. {
  1148. X    XmTextPosition pos;
  1149. X    int    line;
  1150. X
  1151. X    pos = XmTextGetInsertionPosition(w);
  1152. X    line = TextPositionToLine(pos);
  1153. X    UpdateLineLabel(line);
  1154. }
  1155. X
  1156. X
  1157. /*  My select-start routine that cancels the effect of automatic scrolling
  1158. X *  near the bottom of an Athena text widget window.
  1159. X */
  1160. /*  ARGSUSED */
  1161. void SelectStart(w, event, params, num_params)
  1162. X    Widget w;
  1163. X    XEvent *event;
  1164. X    String *params;
  1165. X    Cardinal *num_params;
  1166. {
  1167. X    XtCallActionProc(w, "set-insertion-point", event, params, num_params);
  1168. X    XtCallActionProc(w, "grab-focus", event, params, num_params);
  1169. }
  1170. X
  1171. /*  My select-end routine to store the text selection into both the PRIMARY
  1172. X *  selection and cut buffer 0. 
  1173. X */
  1174. /*  ARGSUSED */
  1175. void SelectEnd(w, event, params, num_params)
  1176. X    Widget w;
  1177. X    XEvent *event;
  1178. X    String *params;
  1179. X    Cardinal *num_params;
  1180. {
  1181. X    XtCallActionProc(w, "extend-end", event, params, num_params);
  1182. }
  1183. X
  1184. /*  This is my own select word routine to replace the standard action
  1185. X *  procedure provided by the Text widget.
  1186. X *  It selects a word delimited by DELIMITERS, not whitespace.
  1187. X */
  1188. /* ARGSUSED */
  1189. void SelectWord(w, event, params, num_params)
  1190. X    Widget w;
  1191. X    XEvent *event;
  1192. X    String *params;
  1193. X    Cardinal *num_params;
  1194. {
  1195. X    XmTextPosition left, right, center, last;
  1196. X    char *valuestring;
  1197. X
  1198. X    XtCallActionProc(w, "set-insertion-point", event, params, num_params);
  1199. X    center = XmTextGetInsertionPosition(w);
  1200. X    valuestring = XmTextGetString(w);
  1201. X    last = XmTextGetLastPosition(w);
  1202. X
  1203. X    if(strchr(DELIMITERS, valuestring[center])) return;
  1204. X    left = center;
  1205. X    right = center;
  1206. X    
  1207. X    while(left>0 && !strchr(DELIMITERS, valuestring[left-1])) left--;
  1208. X    while(right<last && !strchr(DELIMITERS, valuestring[right])) right++;
  1209. X
  1210. X    XmTextSetSelection(w, left, right, 0);
  1211. X    XtFree(valuestring);
  1212. }
  1213. X
  1214. void SelectAdjust(w, event, params, num_params)
  1215. X    Widget w;
  1216. X    XEvent *event;
  1217. X    String *params;
  1218. X    Cardinal *num_params;
  1219. {
  1220. X    XtCallActionProc(w, "extend-adjust", event, params, num_params);
  1221. }
  1222. X
  1223. void ScrollTxt(w, client_data, call_data)
  1224. X     Widget w;
  1225. X     XtPointer client_data;
  1226. X     XmScrollBarCallbackStruct *call_data;
  1227. {
  1228. X  Arg args[5];
  1229. X  int Py;
  1230. X
  1231. X  if(!displayedFile) return;
  1232. X
  1233. X  if(client_data == _PAGERIGHT)
  1234. X    {
  1235. X
  1236. X      XtCallActionProc(sourceWindow, "page-right", call_data->event, 
  1237. X               NULL, 0);
  1238. X    }
  1239. X  else
  1240. X  if(client_data == _PAGELEFT)
  1241. X    {
  1242. X      XtCallActionProc(sourceWindow, "page-left", call_data->event, 
  1243. X               NULL, 0);
  1244. X    }
  1245. X  else
  1246. X  if(client_data == _SCROLLUPPAGE)
  1247. X    {
  1248. X      XtCallActionProc(sourceWindow, "next-page", call_data->event, NULL, 0);
  1249. X      Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
  1250. X      XtSetArg(args[0], XmNvalue, Py);
  1251. X      XtSetValues(scrollV, args, 1);
  1252. X    }
  1253. X  else
  1254. X  if(client_data == _SCROLLDOWNPAGE)
  1255. X    {
  1256. X      XtCallActionProc(sourceWindow, "previous-page", call_data->event, NULL, 0);
  1257. X      Py = TextPositionToLine(XmTextGetTopCharacter(sourceWindow));
  1258. X      XtSetArg(args[0], XmNvalue, Py);
  1259. X      XtSetValues(scrollV, args, 1);
  1260. X    }
  1261. X  else
  1262. X      XmTextSetTopCharacter(sourceWindow, displayedFile->linepos[call_data->value]); 
  1263. X  UpdateSigns(call_data->reason);
  1264. }
  1265. X
  1266. /* 
  1267. X *  On top of a form widget, we have a text widget with scrollbar, label
  1268. X *  widgets for the stop sign, arrow sign, and updown signs.
  1269. X */
  1270. void CreateSourceWindow(parent)
  1271. Widget parent;
  1272. {
  1273. X    Arg args[10];
  1274. X    Pixel bg;
  1275. X    int screen;
  1276. X    Display *topdisplay;
  1277. X    
  1278. X    static XtActionsRec command_actions[] = {
  1279. X        {"SelectStart", (XtActionProc) SelectStart},
  1280. X    {"SelectWord", (XtActionProc) SelectWord},
  1281. X    {"SelectEnd", (XtActionProc) SelectEnd},
  1282. X    {"SelectAdjust", (XtActionProc) SelectAdjust},
  1283. X    {"Update", (XtActionProc) Update},
  1284. X        {NULL, NULL}
  1285. X    };
  1286. X
  1287. X    XtSetArg(args[0], XmNscrollingPolicy, XmAPPLICATION_DEFINED);
  1288. X    XtSetArg(args[1], XmNscrollBarPlacement, XmBOTTOM_LEFT);
  1289. X    sourceScroll = XtCreateManagedWidget("sourceScroll", 
  1290. X                     xmScrolledWindowWidgetClass,
  1291. X                     parent, args, 2);   
  1292. X
  1293. X    scrollV = XtCreateWidget("scrollV", xmScrollBarWidgetClass, sourceScroll,
  1294. X                 args, 0);
  1295. X
  1296. X    sourceForm = XtCreateManagedWidget("sourceForm", xmFormWidgetClass,
  1297. X                       sourceScroll, args, 1);
  1298. X
  1299. X    XmScrolledWindowSetAreas(sourceScroll, NULL, scrollV, sourceForm);
  1300. X
  1301. X    XtAddCallback(scrollV, XmNdecrementCallback, ScrollTxt, _SCROLLDOWN);
  1302. X    XtAddCallback(scrollV, XmNincrementCallback, ScrollTxt, _SCROLLUP);
  1303. X    XtAddCallback(scrollV, XmNpageIncrementCallback, ScrollTxt, _SCROLLUPPAGE);
  1304. X    XtAddCallback(scrollV, XmNpageDecrementCallback, 
  1305. X          ScrollTxt, _SCROLLDOWNPAGE);
  1306. X    XtAddCallback(scrollV, XmNdragCallback, ScrollTxt, _SCROLLDRAG);
  1307. X
  1308. X    XtSetArg(args[0], XmNeditMode, XmMULTI_LINE_EDIT);
  1309. X    XtSetArg(args[1], XmNrightAttachment, XmATTACH_FORM);
  1310. X    XtSetArg(args[2], XmNbottomAttachment, XmATTACH_FORM);
  1311. X    XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM);
  1312. X    XtSetArg(args[4], XmNleftAttachment, XmATTACH_FORM);
  1313. X    XtSetArg(args[5], XmNeditable, False);
  1314. X    XtSetArg(args[6], XmNhighlightOnEnter, True);
  1315. X
  1316. X    sourceWindow = XtCreateManagedWidget("sourceWindow", xmTextWidgetClass,
  1317. X                     sourceForm, args, 7);
  1318. X
  1319. X    XtSetArg(args[0], XmNbottomAttachment, XmATTACH_POSITION);
  1320. X    XtSetArg(args[1], XmNtopAttachment, XmATTACH_POSITION);
  1321. X    XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
  1322. X    XtSetArg(args[3], XmNwidth, 32);
  1323. X    XtSetArg(args[4], XmNarrowDirection, XmARROW_LEFT);
  1324. X    XtSetArg(args[5], XmNhighlightOnEnter, True);
  1325. X    
  1326. X    pageLbutton = XtCreateManagedWidget("pageLbutton", 
  1327. X                    xmArrowButtonWidgetClass, sourceForm,
  1328. X                    args, 6);
  1329. X    XtAddCallback(pageLbutton, XmNactivateCallback, ScrollTxt, 
  1330. X          _PAGELEFT);
  1331. X
  1332. X    XtSetArg(args[4], XmNarrowDirection, XmARROW_RIGHT);
  1333. X    pageRbutton = XtCreateManagedWidget("pageRbutton", 
  1334. X                    xmArrowButtonWidgetClass, sourceForm,
  1335. X                    args, 6);
  1336. X    XtAddCallback(pageRbutton, XmNactivateCallback, ScrollTxt, 
  1337. X          _PAGERIGHT);
  1338. X
  1339. X
  1340. X    XtSetArg(args[0], XmNbackground, &bg);
  1341. X    XtGetValues(sourceForm, args, 1);
  1342. X
  1343. X    topdisplay = XtDisplay(toplevel);
  1344. X    screen = DefaultScreen(topdisplay);
  1345. X    XtSetArg(args[0], XmNbottomAttachment, XmATTACH_POSITION);
  1346. X
  1347. X    XtSetArg(args[4], XmNlabelType, XmPIXMAP);
  1348. X    XtSetArg(args[5], XmNhighlightOnEnter, True);
  1349. X    XtSetArg(args[6], XmNlabelPixmap, XCreatePixmapFromBitmapData (
  1350. X    topdisplay, DefaultRootWindow(topdisplay), stop_bits, stop_width, 
  1351. X    stop_height, app_resources.stop_color, bg, 
  1352. X    DefaultDepth(topdisplay, screen)));
  1353. X    breakbutton = XtCreateManagedWidget("breakbutton",
  1354. X                    xmPushButtonWidgetClass, sourceForm,
  1355. X                    args, 7);
  1356. X    XtAddCallback(breakbutton, XmNactivateCallback, Break, "break");
  1357. X
  1358. X    XtSetArg(args[6], XmNlabelPixmap, XCreatePixmapFromBitmapData (
  1359. X    topdisplay, DefaultRootWindow(topdisplay), step_bits, step_width, 
  1360. X    step_height, app_resources.stop_color, bg, 
  1361. X    DefaultDepth(topdisplay, screen)));
  1362. X    stepbutton = XtCreateManagedWidget("stepbutton",
  1363. X                    xmPushButtonWidgetClass, sourceForm,
  1364. X                    args, 7);
  1365. X    XtAddCallback(stepbutton, XmNactivateCallback, DoIt, "step\n");
  1366. SHAR_EOF
  1367. true || echo 'restore of mxgdb/source.c failed'
  1368. fi
  1369. echo 'End of  part 4'
  1370. echo 'File mxgdb/source.c is continued in part 5'
  1371. echo 5 > _shar_seq_.tmp
  1372. exit 0
  1373. --
  1374.  == James Tsillas                    Bull HN Information Systems Inc. ==
  1375.  == (508) 294-2937                   300 Concord Road   826A          ==
  1376.  == jtsillas@bubba.ma30.bull.com     Billerica, MA 01821              ==
  1377.  ==                                                                   ==
  1378.  == The opinions expressed above are solely my own and do not reflect ==
  1379.  == those of my employer.                                             ==
  1380.             -== no solicitations please ==-
  1381.