home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 4 / 4004 < prev    next >
Text File  |  1991-09-08  |  41KB  |  1,411 lines

  1. Newsgroups: alt.sources
  2. Path: wupost!zaphod.mps.ohio-state.edu!think.com!news.bbn.com!mips2!bubba!jtsillas
  3. From: jtsillas@bubba.ma30.bull.com (James Tsillas)
  4. Subject: mxgdb 1.0.3 (part 2/10)
  5. Organization: Bull HN, Worldwide Information Systems, Billerica, Mass., USA
  6. Distribution: alt
  7. Date: 6 Sep 91 14:20:39
  8. Message-ID: <JTSILLAS.91Sep6142039@bubba.ma30.bull.com>
  9. Sender: news@mips2.ma30.bull.com (Usenet News Manager)
  10.  
  11. ---- Cut Here and feed the following to sh ----
  12. #!/bin/sh
  13. # this is mxgdb.02 (part 2 of a multipart archive)
  14. # do not concatenate these parts, unpack them in order with /bin/sh
  15. # file mxgdb/Makefile continued
  16. #
  17. if test ! -r _shar_seq_.tmp; then
  18.     echo 'Please unpack part 1 first!'
  19.     exit 1
  20. fi
  21. (read Scheck
  22.  if test "$Scheck" != 2; then
  23.     echo Please unpack part "$Scheck" next!
  24.     exit 1
  25.  else
  26.     exit 0
  27.  fi
  28. ) < _shar_seq_.tmp || exit 1
  29. if test ! -f _shar_wnt_.tmp; then
  30.     echo 'x - still skipping mxgdb/Makefile'
  31. else
  32. echo 'x - continuing file mxgdb/Makefile'
  33. sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/Makefile' &&
  34. X
  35. X          DEPLIBS = $(LOCAL_LIBRARIES)
  36. X
  37. X         DEPLIBS1 = $(DEPLIBS)
  38. X         DEPLIBS2 = $(DEPLIBS)
  39. X         DEPLIBS3 = $(DEPLIBS)
  40. X
  41. ###########################################################################
  42. # Imake rules for building libraries, programs, scripts, and data files
  43. # rules:  $XConsortium: Imake.rules,v 1.70 90/05/04 16:57:30 keith Exp $
  44. X
  45. ###########################################################################
  46. # start of Imakefile
  47. X
  48. # $Id: Imakefile,v 1.3 1991/08/23 16:34:24 jtsillas Exp $
  49. X
  50. #
  51. # Read the README file for a list of options to include for your system
  52. #
  53. LOCAL_LIBRARIES = $(XMLIB) $(XTLIB) $(XLIB)
  54. X
  55. X           SRCS1 = callgdb.c command.c gdb.c dialog.c filemenu.c \
  56. X          handler.c parser.c regex.c signs.c signals.c source.c \
  57. X          utils.c windows.c mxgdb.c malloc.c bitmaps.c
  58. X
  59. X           OBJS1 = callgdb.o command.o gdb.o dialog.o filemenu.o \
  60. X          handler.o parser.o regex.o signs.o signals.o source.o \
  61. X          utils.o windows.o mxgdb.o malloc.o bitmaps.o
  62. X
  63. PROGRAMS = mxgdb
  64. X
  65. ..c.o:
  66. X    $(RM) $@
  67. X    $(CC) -c $(CFLAGS) $*.c
  68. X
  69. X            OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
  70. X            SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
  71. X
  72. all:: $(PROGRAMS)
  73. X
  74. mxgdb: $(OBJS1) $(DEPLIBS1)
  75. X     $(RM) $@
  76. X    $(CC) -o $@ $(LDOPTIONS) $(OBJS1) $(LOCAL_LIBRARIES) $(LDLIBS)  $(SYSLIBS) $(EXTRA_LOAD_FLAGS)
  77. X
  78. install:: mxgdb
  79. X    $(INSTALL) -c -s $(INSTPGMFLAGS)   mxgdb $(BINDIR)
  80. X
  81. mxgdb.1:: mxgdb.man
  82. X    nroff -man $? > $@
  83. X
  84. all:: mxgdb.1
  85. X
  86. clean::
  87. X    rm -f mxgdb.1
  88. X
  89. install.man:: mxgdb.1
  90. X    $(INSTALL) -c $(INSTMANFLAGS) -f mxgdb.1 $(MANDIR)/mxgdb.1
  91. X
  92. depend::
  93. X    $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  94. X
  95. lint:
  96. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  97. lint1:
  98. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  99. X
  100. clean::
  101. X    $(RM) $(PROGRAMS)
  102. X
  103. install:: Mxgdb.ad
  104. X    $(INSTALL) -c -f $(INSTAPPFLAGS) Mxgdb.ad $(XAPPLOADDIR)/Mxgdb
  105. X
  106. handler.o: gdb_handler.c
  107. parser.o: gdb_parser.c gdb_regex.h
  108. X
  109. ###########################################################################
  110. # common rules for all Makefiles - do not edit
  111. X
  112. emptyrule::
  113. X
  114. clean::
  115. X    $(RM_CMD) \#*
  116. X
  117. Makefile::
  118. X    -@if [ -f Makefile ]; then \
  119. X        echo "    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
  120. X        $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  121. X    else exit 0; fi
  122. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  123. X
  124. tags::
  125. X    $(TAGS) -w *.[ch]
  126. X    $(TAGS) -xw *.[ch] > TAGS
  127. X
  128. ###########################################################################
  129. # empty rules for directories that do not have SUBDIRS - do not edit
  130. X
  131. install::
  132. X    @echo "install in $(CURRENT_DIR) done"
  133. X
  134. install.man::
  135. X    @echo "install.man in $(CURRENT_DIR) done"
  136. X
  137. Makefiles::
  138. X
  139. includes::
  140. X
  141. ###########################################################################
  142. # dependencies generated by makedepend
  143. X
  144. SHAR_EOF
  145. echo 'File mxgdb/Makefile is complete' &&
  146. chmod 0644 mxgdb/Makefile ||
  147. echo 'restore of mxgdb/Makefile failed'
  148. Wc_c="`wc -c < 'mxgdb/Makefile'`"
  149. test 12188 -eq "$Wc_c" ||
  150.     echo 'mxgdb/Makefile: original size 12188, current size' "$Wc_c"
  151. rm -f _shar_wnt_.tmp
  152. fi
  153. # ============= mxgdb/command.c ==============
  154. if test -f 'mxgdb/command.c' -a X"$1" != X"-c"; then
  155.     echo 'x - skipping mxgdb/command.c (File already exists)'
  156.     rm -f _shar_wnt_.tmp
  157. else
  158. > _shar_wnt_.tmp
  159. echo 'x - extracting mxgdb/command.c (Text)'
  160. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/command.c' &&
  161. static char rcsid[] = "$Id: command.c,v 1.10 1991/08/23 16:34:30 jtsillas Exp $";
  162. X
  163. /*****************************************************************************
  164. X *
  165. X *  xdbx - X Window System interface to the dbx debugger
  166. X *
  167. X *  Copyright 1989 The University of Texas at Austin
  168. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  169. X *
  170. X *  Permission to use, copy, modify, and contribute this software and its
  171. X *  documentation for any purpose and without fee is hereby granted,
  172. X *  provided that the above copyright notice appear in all copies and that
  173. X *  both that copyright notice and this permission notice appear in
  174. X *  supporting documentation, and that the name of The University of Texas
  175. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  176. X *  used in advertising or publicity pertaining to distribution of
  177. X *  the software without specific, written prior permission.  The
  178. X *  University of Texas and MCC makes no representations about the 
  179. X *  suitability of this software for any purpose.  It is provided "as is" 
  180. X *  without express or implied warranty.
  181. X *
  182. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  183. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  184. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  185. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  186. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  187. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  188. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  189. X *
  190. X *  Author:      Po Cheung
  191. X *  Created:       March 10, 1989
  192. X * 
  193. X *****************************************************************************
  194. X * 
  195. X *  xxgdb - X Window System interface to the gdb debugger
  196. X *  
  197. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  198. X *  
  199. X *  Permission to use, copy, modify, and distribute this software and its
  200. X *  documentation for any purpose and without fee is hereby granted,
  201. X *  provided that the above copyright notice appear in all copies and that
  202. X *  both that copyright notice and this permission notice appear in
  203. X *  supporting documentation, and that the name of Thomson Consumer
  204. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  205. X *  to distribution of the software without specific, written prior
  206. X *  permission.  TCE makes no representations about the suitability of
  207. X *  this software for any purpose.  It is provided "as is" without express
  208. X *  or implied warranty.
  209. X *
  210. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  211. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  212. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  213. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  214. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  215. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  216. X *  SOFTWARE.
  217. X *
  218. X *  Adaptation to GDB:  Pierre Willard
  219. X *  XXGDB Created:       December, 1990
  220. X *
  221. X *****************************************************************************
  222. X
  223. /*  command.c
  224. X *
  225. X *    Create the command window, the command buttons and their callbacks.
  226. X *
  227. X *    CreateCommandPanel() :     Create a window with command buttons
  228. X *    CreateButtons() :        Create command buttons in panel
  229. X *    AddButton() :        Add a command button into the command window
  230. X *    ButtonSet() :        Action proc for command button translation
  231. X *
  232. X *    Command callbacks for the command buttons:
  233. X *
  234. X *    forwardSearch() :        forward string search
  235. X *    reverseSearch() :        reverse string search
  236. X *    Search() :        call either forwardSearch() or reverseSearch()
  237. X *    PopupSearch() :        command callback for search button
  238. X *    DoneSearch() :        command callback for DONE button in search panel
  239. X *    CreateSearchPopup() :    create search panel
  240. X *
  241. X *    Command queue manipulation routines:
  242. X *    send_command():        send a command to dbx and record in the queue
  243. X *    get_command():        read command off head of queue
  244. X *    insert_command():    insert command at the head of queue
  245. X *    delete_command():    delete command from head of queue
  246. X */
  247. #include <signal.h>
  248. #include <ctype.h>
  249. #include <sys/types.h>
  250. #include <sys/wait.h>
  251. #include "global.h"
  252. #include "arrows.h"
  253. #include <Xm/Xm.h>
  254. #include <Xm/SelectioB.h>
  255. X
  256. #define     REVERSE    0
  257. #define     FORWARD    1
  258. X
  259. static Widget    searchPopupShell;
  260. static Widget    AddButton();
  261. /* static Widget    button[30]; */
  262. static char    SearchString[BUFSIZ] = "";    /* search string buffer */
  263. static char    command[LINESIZ];
  264. static CommandRec *commandQueue = NULL;
  265. X
  266. /* ARGSUSED */
  267. /*  Execute the dbx command specifed in client_data
  268. X */
  269. void DoIt (w, command, call_data)
  270. X    Widget w;
  271. X    XtPointer command;
  272. X    XtPointer call_data;
  273. {
  274. X    /* run, cont, next, step, where, up, down, status */
  275. X    send_command(command);
  276. X    AppendDialogText(command);
  277. }
  278. X
  279. /*
  280. X    here client_data is "break" or "tbreak"
  281. X
  282. */
  283. void Break(w, client_data, call_data)
  284. X     Widget w;
  285. X     char * client_data;
  286. X     XtPointer call_data;
  287. {
  288. X    XmTextPosition pos;
  289. X    int line;
  290. X    char *string1;
  291. X    char *string2;
  292. X    char *s;
  293. X
  294. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  295. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  296. X
  297. X    if(string2 && !string1)
  298. X      {
  299. X        string1 = string2;
  300. X        string2 = NULL;
  301. X      }
  302. X
  303. X    if(string2) XtFree(string2);
  304. X
  305. X    if (string1 && *string1) 
  306. X      {
  307. X    s = string1;
  308. X    while (*s == ' ') s++;    /* skip leading spaces (if any) */
  309. X    if ((*s >= '0') && (*s <= '9'))
  310. X      sprintf(command, "%s *%s\n",client_data,string1);
  311. X    else
  312. X      sprintf(command, "%s %s\n",client_data,string1);
  313. X      }
  314. X    else
  315. X      {
  316. X    if (displayedFile != NULL)
  317. X      {
  318. X        pos = XmTextGetInsertionPosition(sourceWindow);
  319. X        line = TextPositionToLine(pos);
  320. X        sprintf(command, "%s %d\n",client_data,line);
  321. X      }
  322. X    else
  323. X      {
  324. X        UpdateMessageWindow(BREAK_HELP, NULL);
  325. X        bell(0);
  326. X        if(string1) XtFree(string1);
  327. X        return;
  328. X      }
  329. X      }
  330. X    
  331. X    if(string1) XtFree(string1);
  332. X    send_command(command);
  333. X    AppendDialogText(command);
  334. X  }
  335. X
  336. /*  Clear removes the stop_no associated with a given line number.
  337. X *  RemoveStop() is called to undisplay the stop sign only when there
  338. X *  are no more stop_no's associated with that line number.
  339. X */
  340. X                /* A modification to this would allow selecting
  341. X                 a function name which has a break associated 
  342. X                 with it. A shift-Btn1Down should give a
  343. X                 selection-box of all available break points
  344. X                 - Jim (5-4-91)*/
  345. /* ARGSUSED */
  346. void Clear(w, client_data, call_data)
  347. X    Widget w;
  348. X    XtPointer client_data;
  349. X    XtPointer call_data;
  350. {
  351. X    XmTextPosition pos;
  352. X    int            line;
  353. X    char           *string1, *string2;
  354. X
  355. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  356. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  357. X
  358. X    if(string2 && !string1)
  359. X      {
  360. X    string1 = string2;
  361. X    string2 = NULL;
  362. X      }
  363. X
  364. X    if(string2) XtFree(string2);
  365. X
  366. X    if(string1 && *string1 != '\0')
  367. X      {
  368. X    sprintf(command, "clear %s\n", string1);
  369. X    send_command(command);
  370. X    AppendDialogText(command);
  371. X    XtFree(string1);
  372. X    return;
  373. X      }
  374. X    if(string1) XtFree(string1);
  375. X
  376. X    if (displayedFile) {
  377. X      pos = XmTextGetInsertionPosition(sourceWindow);
  378. X      line = TextPositionToLine(pos);
  379. X      if (LineToStop_no(line)) {
  380. X    sprintf(command, "clear %d\n", line);
  381. X    send_command(command);
  382. X    AppendDialogText(command);
  383. X    return;
  384. X      }
  385. X    }
  386. X    UpdateMessageWindow(CLEAR_HELP, NULL);
  387. X    bell(0);
  388. }
  389. X
  390. /* ARGSUSED */
  391. void Print(w, client_data, call_data)
  392. X    Widget w;
  393. X    XtPointer client_data;
  394. X    XtPointer call_data;
  395. {
  396. X    char *string1, *string2;
  397. X    int nbytes;
  398. X
  399. X    string1 = (char *) XmTextGetSelection(sourceWindow);
  400. X    string2 = (char *) XmTextGetSelection(dialogWindow);
  401. X
  402. X    if(string2 && !string1)
  403. X      {
  404. X    string1 = string2;
  405. X    string2 = NULL;
  406. X      }
  407. X
  408. X    if(string2) XtFree(string2);
  409. X
  410. X    if(!string1 || *string1 == '\0')
  411. X      {
  412. X    UpdateMessageWindow(PRINT_HELP, NULL);
  413. X    bell(0);
  414. X    if(string1) XtFree(string1);
  415. X    return;
  416. X      }
  417. X    if (client_data == (XtPointer)0)
  418. X    sprintf(command, "print %s\n", string1);
  419. X    else if (client_data == (XtPointer)1)
  420. X    sprintf(command, "print *%s\n", string1);
  421. X    send_command(command);
  422. X    AppendDialogText(command);
  423. X    if(string1) XtFree(string1);
  424. }
  425. X
  426. /* ARGSUSED */
  427. void Quit(w, client_data, call_data)
  428. X    Widget w;
  429. X    XtPointer client_data;
  430. X    XtPointer call_data;
  431. {
  432. X
  433. X    int status;
  434. X
  435. X    write_dbx("quit\n");
  436. X    XtDestroyApplicationContext(app_context);
  437. X    kill(dbxpid, SIGKILL);
  438. X
  439. #if defined(SYSV) && !defined(SUNOS4)
  440. X    waitpid(&status, NULL, WNOHANG);
  441. #else
  442. X    wait3(&status, WNOHANG, NULL);
  443. #endif
  444. X
  445. X    exit(0);
  446. }
  447. X
  448. extern int helpstackidx;
  449. X
  450. void Help(w, client_data, call_data)
  451. X     Widget w;
  452. X     XtPointer client_data;
  453. X     XtPointer call_data;
  454. {
  455. X  helpstackidx = 0;
  456. X  query_dbx("help\n");
  457. }
  458. X
  459. /* ARGSUSED */
  460. void Display_(w, client_data, call_data)
  461. X    Widget w;
  462. X    XtPointer client_data;
  463. X    XtPointer call_data;
  464. {
  465. X    char *string1, *string2;
  466. X    int nbytes;
  467. X
  468. X    if(!XtIsManaged(displayFD)) XtManageChild(displayFD);
  469. X
  470. X    string1 = (char *)XmTextGetSelection(sourceWindow);
  471. X    string2 = (char *)XmTextGetSelection(dialogWindow);
  472. X
  473. X    if(string2 && !string1)
  474. X      {
  475. X    string1 = string2;
  476. X    string2 = NULL;
  477. X      }
  478. X
  479. X    if(string2) XtFree(string2);
  480. X
  481. X    if(string1 && *string1 != '\0')
  482. X      {
  483. X    sprintf(command, "display %s\n", string1);
  484. X    send_command(command);
  485. X    AppendDialogText(command);
  486. X    XtFree(string1);
  487. X    return;
  488. X      }
  489. X    if(string1) XtFree(string1);
  490. X
  491. }
  492. X
  493. /* ARGSUSED */
  494. void Undisplay(w, client_data, call_data)
  495. X    Widget w;
  496. X    XtPointer client_data;
  497. X    XtPointer call_data;
  498. {
  499. X  char *string1, s[5], *st1, *st2;
  500. X  int     stop_no, nbytes;
  501. X  
  502. X  string1 = XmTextGetSelection(displayWindow);
  503. X  
  504. X  if (string1 && *string1)
  505. X    {
  506. X      st1 = s;
  507. X      st2 = string1;
  508. X      while((*st1++ = *st2++)!=':' && *st1);
  509. X      *(st1-1) = '\0';
  510. X      XtFree(string1);
  511. X      if ((stop_no = atoi(s)) > 0)
  512. X    {
  513. X      sprintf(command, "undisplay %d\n", stop_no);
  514. X      send_command(command);
  515. X      AppendDialogText(command);
  516. X    }
  517. X      else
  518. X    {
  519. X      UpdateMessageWindow(UNDISPLAY_HELP, NULL);
  520. X      bell(0);
  521. X      return;
  522. X    }
  523. X  }
  524. X  else
  525. X    {
  526. X      if(XtIsManaged(displayFD))
  527. X    XtUnmanageChild(displayFD);
  528. X      if(string1) XtFree(string1);
  529. X      return;
  530. X    }
  531. }
  532. X
  533. /*  Beginning from startpos, this routine searches text forward for 
  534. X *  searchstring, and returns 1 if searchstring is found, also returning 
  535. X *  the left and right positions of the matched string in left and right; 
  536. X *  else 0 is returned.
  537. X *  It also does wrap-around search. 
  538. X */
  539. X    
  540. static forwardSearch(text, startpos, searchstring, left, right)
  541. X    char *text;
  542. X    XmTextPosition  startpos;
  543. X    char *searchstring;
  544. X    XmTextPosition  *left, *right;
  545. {
  546. X    int  searchlength, searchsize, i, n=0;
  547. X    char *s1, *s2;
  548. X
  549. X    searchlength = strlen(searchstring);
  550. X    searchsize = strlen(text) - searchlength;
  551. X    for (i=startpos+1; i < searchsize; i++) {
  552. X    n = searchlength;
  553. X    s1 = &text[i];
  554. X    s2 = searchstring;
  555. X    while (--n >= 0 && *s1++ == *s2++);
  556. X    if (n < 0) break;
  557. X    }
  558. X    if (n < 0) {
  559. X        *left = i;
  560. X        *right = i+searchlength;
  561. X        return 1;
  562. X    }
  563. X    else {
  564. X    for (i=0; i <= startpos; i++) {
  565. X        n = searchlength;
  566. X        s1 = &text[i];
  567. X        s2 = searchstring;
  568. X        while (--n >= 0 && *s1++ == *s2++);
  569. X        if (n < 0) break;
  570. X    }
  571. X    if (n < 0) {
  572. X        *left = i;
  573. X        *right = i+searchlength;
  574. X        return 1;
  575. X    }
  576. X    return 0;
  577. X    }
  578. }
  579. X    
  580. X
  581. /*  Similar to forwardSearch(), except that it does a reverse search
  582. X */
  583. static reverseSearch(text, startpos, searchstring, left, right)
  584. X    char         *text;
  585. X    XmTextPosition  startpos;
  586. X    char         *searchstring;
  587. X    XmTextPosition  *left, *right;
  588. {
  589. X    int  searchlength, i, n=0;
  590. X    char *s1, *s2;
  591. X
  592. X    searchlength = strlen(searchstring);
  593. X    for (i=startpos; i >= searchlength; i--) {
  594. X    n = searchlength;
  595. X    s1 = &text[i];
  596. X    s2 = &searchstring[searchlength-1];
  597. X    while (--n >= 0 && *--s1 == *s2--);
  598. X    if (n < 0) break;
  599. X    }
  600. X    if (n < 0) {
  601. X        *right = i;
  602. X        *left = *right-searchlength;
  603. X        return 1;
  604. X    }
  605. X    else {
  606. X    for (i=strlen(text); i > startpos; i--) {
  607. X        n = searchlength;
  608. X        s1 = &text[i];
  609. X        s2 = &searchstring[searchlength-1];
  610. X        while (--n >= 0 && *--s1 == *s2--);
  611. X        if (n < 0) break;
  612. X    }
  613. X    if (n < 0) {
  614. X            *right = i;
  615. X            *left = *right-searchlength;
  616. X        return 1;
  617. X    }
  618. X    return 0;
  619. X    }
  620. }
  621. X
  622. static XmTextPosition last_pos_before_search;
  623. X
  624. /* ARGSUSED */
  625. void PopupSearch(w, client_data, call_data)
  626. X    Widget w;
  627. X    XtPointer client_data;
  628. X    XtPointer call_data;
  629. {
  630. X    if (!displayedFile) {
  631. X    UpdateMessageWindow(SEARCH_HELP, NULL);
  632. X    bell(0);
  633. X    }
  634. X    else {
  635. X        last_pos_before_search = XmTextGetInsertionPosition(sourceWindow);
  636. X    XtManageChild(searchPopupShell);
  637. X    }
  638. }
  639. X
  640. /* This callback is used by the Cancel button to return to the saved text
  641. X * position after a search.
  642. X */
  643. static void StopSearch(w, client_data, call_data)
  644. X     Widget w;
  645. X     XtPointer client_data;
  646. X     XtPointer call_data;
  647. {
  648. X  XtUnmanageChild(searchPopupShell);
  649. }
  650. X
  651. /* This callback is used by the Cancel button to return to the saved text
  652. X * position after a search.
  653. X */
  654. static void CancelSearch(w, client_data, call_data)
  655. X     Widget w;
  656. X     XtPointer client_data;
  657. X     XtPointer call_data;
  658. {
  659. X        AdjustText(TextPositionToLine(last_pos_before_search));
  660. X    XmTextSetInsertionPosition(sourceWindow, last_pos_before_search);
  661. }
  662. X
  663. /* ARGSUSED */
  664. /*  This routine handles both forward and reverse text search.
  665. X *  If no text has been entered, the contents of the cut buffer are used
  666. X *  for searching.
  667. X */ 
  668. static void Search(w, direction, call_data)
  669. X     Widget w;
  670. X     XtPointer direction;
  671. X     XtPointer call_data;
  672. {
  673. X  XmTextPosition    pos, left, right;
  674. X  char        *searchString;
  675. X  
  676. X  searchString = XmTextGetString(XmSelectionBoxGetChild(searchPopupShell,
  677. X                            XmDIALOG_TEXT));
  678. X  if(searchString && *searchString)
  679. X    {
  680. X      pos = XmTextGetInsertionPosition(sourceWindow);
  681. X      if ((direction == (XtPointer)FORWARD && 
  682. X       forwardSearch(displayedFile->buf, pos, searchString, &left, &right)) ||
  683. X      (direction == (XtPointer)REVERSE && 
  684. X       reverseSearch(displayedFile->buf, pos, searchString, &left, &right))) {
  685. X    AdjustText(TextPositionToLine(left));
  686. X    XmTextSetSelection(sourceWindow, left, right, 0);
  687. X    XmTextSetInsertionPosition(sourceWindow, left);
  688. X      }
  689. X      else {
  690. X    if (direction == (XtPointer)FORWARD)
  691. X      UpdateMessageWindow("String not found", NULL);
  692. X    else if (direction == (XtPointer)REVERSE)
  693. X      UpdateMessageWindow("String not found", NULL);
  694. X    else
  695. X      abort();
  696. X    bell(0);
  697. X      }
  698. X    }
  699. X  if(searchString) XtFree(searchString);
  700. }
  701. X
  702. void CreateSearchPopup(parent)
  703. Widget parent;
  704. {
  705. X    Arg     args[MAXARGS];
  706. X    Display     *topdisplay;
  707. X    Pixel       bg;
  708. X    Widget      applybutton, okbutton, cancelbutton, helpbutton;
  709. X
  710. X    XtSetArg(args[0], XmNdialogTitle, 
  711. X             XmStringCreateLtoR("String Search", XmSTRING_DEFAULT_CHARSET));
  712. X    searchPopupShell = XmCreatePromptDialog(parent, "searchPopupSelection", 
  713. X                        args, 2);
  714. X    applybutton = XmSelectionBoxGetChild(searchPopupShell, 
  715. X                     XmDIALOG_APPLY_BUTTON);
  716. X    okbutton = XmSelectionBoxGetChild(searchPopupShell, 
  717. X                      XmDIALOG_OK_BUTTON);
  718. X    cancelbutton = XmSelectionBoxGetChild(searchPopupShell, 
  719. X                      XmDIALOG_CANCEL_BUTTON);
  720. X    helpbutton = XmSelectionBoxGetChild(searchPopupShell, 
  721. X                    XmDIALOG_HELP_BUTTON);
  722. X    XtManageChild(applybutton);
  723. X
  724. X    XtSetArg(args[0], XmNkeyboardFocusPolicy, XmPOINTER);
  725. X    XtSetValues(XtParent(searchPopupShell), args, 1);
  726. X    
  727. X    topdisplay = XtDisplay(toplevel);
  728. X    XtSetArg(args[0], XmNbackground, &bg);
  729. X    XtGetValues(searchPopupShell, args, 1);
  730. X
  731. X    XtSetArg(args[0], XmNlabelType, XmPIXMAP);
  732. X    XtSetArg(args[1], XmNlabelPixmap, XCreatePixmapFromBitmapData (
  733. X    topdisplay, DefaultRootWindow(topdisplay), 
  734. X    arrowup_bits, arrowup_width, 
  735. X    arrowup_height, app_resources.stop_color, bg, 
  736. X    DefaultDepth(topdisplay, 
  737. X             DefaultScreen(topdisplay))));
  738. X    XtSetValues(applybutton, args, 2);
  739. X
  740. X    XtSetArg(args[1], XmNlabelPixmap, XCreatePixmapFromBitmapData (
  741. X    topdisplay, DefaultRootWindow(topdisplay), 
  742. X    arrowdown_bits, arrowdown_width, 
  743. X    arrowdown_height, app_resources.stop_color, bg, 
  744. X    DefaultDepth(topdisplay, 
  745. X             DefaultScreen(topdisplay))));
  746. X    XtSetValues(okbutton, args, 2);
  747. X    XtSetArg(args[0],  XmNlabelString,
  748. X             XmStringCreateLtoR("Stop", XmSTRING_DEFAULT_CHARSET));
  749. X    XtSetValues(helpbutton, args, 1);
  750. X    XtRemoveAllCallbacks(applybutton, XmNactivateCallback);
  751. X    XtRemoveAllCallbacks(okbutton, XmNactivateCallback);
  752. X    XtAddCallback(applybutton, XmNactivateCallback, 
  753. X          Search, (XtPointer)REVERSE);
  754. X    XtAddCallback(okbutton, XmNactivateCallback, 
  755. X          Search, (XtPointer)FORWARD);
  756. X    XtAddCallback(cancelbutton, XmNactivateCallback, CancelSearch, NULL);
  757. X    XtAddCallback(helpbutton, XmNactivateCallback, StopSearch, NULL);
  758. X
  759. }
  760. X
  761. /**************************************************************************
  762. X *
  763. X *  Command queue functions
  764. X *
  765. X **************************************************************************/
  766. X
  767. /*  Append command to end of the command queue and send the command to gdb */
  768. X
  769. void send_command(command)
  770. char *command;
  771. {
  772. X    CommandRec *p, *q, *r;
  773. X
  774. X    p = (CommandRec *)XtNew(CommandRec);
  775. X    p->command = XtNewString(command);
  776. X    p->next = NULL;
  777. X    if (!commandQueue)
  778. X    commandQueue = p;
  779. X    else {
  780. X    q = commandQueue;
  781. X    while (r = q->next)
  782. X        q = r;
  783. X    q->next = p;
  784. X    }
  785. X    write_dbx(command);
  786. }
  787. X
  788. /*  Read command at the head of the command queue */
  789. X
  790. char *get_command()
  791. {
  792. X    if (commandQueue) {
  793. X    return (commandQueue->command);
  794. X    }
  795. X    else
  796. X    return NULL;
  797. }
  798. X
  799. /*  Delete command from the head of the command queue */
  800. X
  801. void delete_command()
  802. {
  803. X    CommandRec *p;
  804. X
  805. X    if (p = commandQueue) {
  806. X    commandQueue = p->next;
  807. X    XtFree(p->command);
  808. X    XtFree(p);
  809. X    }
  810. }
  811. X
  812. /*  Insert command into head of queue */
  813. X
  814. void insert_command(command)
  815. char *command;
  816. {
  817. X    CommandRec *p;
  818. X
  819. X    p = (CommandRec *)XtNew(CommandRec);
  820. X    p->command = XtNewString(command);
  821. X    p->next = NULL;
  822. X    if (!commandQueue)
  823. X    commandQueue = p;
  824. X    else {
  825. X    p->next = commandQueue;
  826. X    commandQueue = p;
  827. X    }
  828. }
  829. SHAR_EOF
  830. chmod 0664 mxgdb/command.c ||
  831. echo 'restore of mxgdb/command.c failed'
  832. Wc_c="`wc -c < 'mxgdb/command.c'`"
  833. test 18082 -eq "$Wc_c" ||
  834.     echo 'mxgdb/command.c: original size 18082, current size' "$Wc_c"
  835. rm -f _shar_wnt_.tmp
  836. fi
  837. # ============= mxgdb/Mxgdb.ad ==============
  838. if test -f 'mxgdb/Mxgdb.ad' -a X"$1" != X"-c"; then
  839.     echo 'x - skipping mxgdb/Mxgdb.ad (File already exists)'
  840.     rm -f _shar_wnt_.tmp
  841. else
  842. > _shar_wnt_.tmp
  843. echo 'x - extracting mxgdb/Mxgdb.ad (Text)'
  844. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/Mxgdb.ad' &&
  845. !
  846. ! $Id: Mxgdb.ad,v 1.13 1991/08/23 16:34:25 jtsillas Exp $
  847. !
  848. Mxgdb*fontList:-adobe-helvetica-bold-r-normal--12-120-75-75-p-70-iso8859-1
  849. !
  850. ! useCommandDialog (false by default) creates a popup dialog to contain your
  851. ! command buttons rather than putting them beside the source window.
  852. !
  853. Mxgdb*useCommandDialog:    false
  854. !
  855. !    fileWindow - contains the filename and linenumber labels.
  856. !        fileLabel - the label for the current file.
  857. !        lineLabel - the laebl for the current line-number.
  858. !
  859. Mxgdb*fileWindow.height:    15
  860. Mxgdb*fileWindow*fileLabel.borderWidth:    0
  861. Mxgdb*fileWindow*lineLabel.borderWidth:    0
  862. !
  863. ! sourceScroll - the scrolled window containing the sourceForm.
  864. !
  865. Mxgdb*sourceScroll.paneMinimum:    100
  866. !
  867. ! The source form is the FormWidget containing the sourceWindow, the
  868. ! command buttons and the arrow/stopsign/etc. labels.
  869. !
  870. Mxgdb*sourceForm.borderWidth:    0
  871. Mxgdb*sourceForm.shadowThickness:    0
  872. Mxgdb*sourceForm.width:        500
  873. !
  874. ! The source window is the TextWidget with the source text.
  875. !
  876. Mxgdb*sourceWindow.borderWidth:    0
  877. Mxgdb*sourceWindow.highlightThickness:    0
  878. Mxgdb*sourceWindow.shadowThickness:    0
  879. Mxgdb*sourceWindow.rows:        19
  880. Mxgdb*sourceWindow.marginWidth:    5
  881. Mxgdb*sourceWindow.fontList:    6x13
  882. Mxgdb*sourceWindow.translations: #override \
  883. X    Shift<Btn1Down>,Shift<Btn1Up>: SelectWord() Update(warp) \n\
  884. X    <Btn1Down>: SelectStart() \n\
  885. X    <Btn1Motion>: SelectAdjust() \n\
  886. X    <Btn1Up>: SelectEnd() Update(warp) \n\
  887. X    <Key>osfUp: process-up() Update() \n\
  888. X    <Key>osfDown: process-down() Update() \n\
  889. X    <Key>osfLeft: backward-character() Update() \n\
  890. X    <Key>osfRight: forward-character() Update() \n\
  891. X    <Key>osfPageDown: next-page() Update(warp) \n\
  892. X    <Key>osfPageUp:    previous-page() Update(warp) \n\
  893. X    Ctrl<Key>osfPageUp:    page-left() Update(warp) \n\
  894. X    Ctrl<Key>osfPageDown:    page-right() Update(warp) \n\
  895. X    Ctrl<Key>osfBeginLine:    beginning-of-file() Update() \n\
  896. X    Ctrl<Key>osfEndLine:    end-of-file() Update()
  897. !
  898. ! These translations reset the bounds for the sign placement
  899. ! vpane is the paned window widget.
  900. !
  901. Mxgdb*vpane*sash.translations: #override \
  902. X    <Btn1Up>:    SashAction(Commit) resetLineBounds() \n\
  903. X    <Btn2Up>:    SashAction(Commit) resetLineBounds()
  904. !
  905. ! The message window echoes the gdb result lines.
  906. !
  907. Mxgdb*messageWindow.height:    25
  908. !
  909. ! The dialog Window is the text command line window. dialogWindowSW is the
  910. ! Scrolled Window parent of the TextWidget.
  911. !
  912. Mxgdb*dialogWindowSW.paneMinimum:    50
  913. Mxgdb*dialogWindow.height:    200
  914. Mxgdb*dialogWindow.fontList:    6x13
  915. Mxgdb*dialogWindow.translations:    #override \
  916. X    Shift<Btn1Down>,Shift<Btn1Up>: SelectWord() \n\
  917. X    <Btn1Down>:    SelectStart() \n\
  918. X    <Btn1Motion>: SelectAdjust() \n\
  919. X    <Btn1Up>:    SelectEnd()\n\
  920. X    <Btn2Down>:    InsertSelection() copy-primary() \n\
  921. X     Ctrl<Key>C:    SigInt()\n\
  922. X     Ctrl<Key>D:    SigEof()\n\
  923. X     Ctrl<Key>|:    SigQuit()\n\
  924. X    <Key>osfBackSpace: InsertSpace() delete-previous-character() \n\
  925. X     <Key>Return:    end-of-file() newline() Dispatch() \n\
  926. X    <Key>:        end-of-file() self-insert()
  927. !
  928. | The displayWindow is the scrolled text wigdet within displayWindowFD
  929. ! which is the FormDialog widget.
  930. !
  931. Mxgdb*displayWindow.translations:    #override \n\
  932. X        <Btn1Up>:    set-insertion-point() SelectVar()
  933. Mxgdb*displayWindowFD.height:        150
  934. Mxgdb*displayWindowFD.width:        100
  935. Mxgdb*displayWindow.fontList:        6x13
  936. !
  937. ! File Selector Box Settings
  938. !
  939. !Mxgdb*fileSelectorBox
  940. !
  941. ! End
  942. X
  943. SHAR_EOF
  944. chmod 0664 mxgdb/Mxgdb.ad ||
  945. echo 'restore of mxgdb/Mxgdb.ad failed'
  946. Wc_c="`wc -c < 'mxgdb/Mxgdb.ad'`"
  947. test 3289 -eq "$Wc_c" ||
  948.     echo 'mxgdb/Mxgdb.ad: original size 3289, current size' "$Wc_c"
  949. rm -f _shar_wnt_.tmp
  950. fi
  951. # ============= mxgdb/bitmaps.h ==============
  952. if test -f 'mxgdb/bitmaps.h' -a X"$1" != X"-c"; then
  953.     echo 'x - skipping mxgdb/bitmaps.h (File already exists)'
  954.     rm -f _shar_wnt_.tmp
  955. else
  956. > _shar_wnt_.tmp
  957. echo 'x - extracting mxgdb/bitmaps.h (Text)'
  958. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/bitmaps.h' &&
  959. /* $Id: bitmaps.h,v 1.3 1991/08/23 16:34:28 jtsillas Exp $ */
  960. X
  961. #define mxgdb48_width 48
  962. #define mxgdb48_height 48
  963. extern char mxgdb48_bits[];
  964. X
  965. #define mxgdb64_width 64
  966. #define mxgdb64_height 64
  967. extern char mxgdb64_bits[];
  968. X
  969. #define stop_width 16
  970. #define stop_height 16
  971. #define stop_x_hot -1
  972. #define stop_y_hot -1
  973. extern char stop_bits[];
  974. X
  975. #define arrow_width 16
  976. #define arrow_height 16
  977. #define arrow_x_hot -1
  978. #define arrow_y_hot -1
  979. extern char arrow_bits[];
  980. X
  981. #define updown_width 16
  982. #define updown_height 16
  983. #define updown_x_hot -1
  984. #define updown_y_hot -1
  985. extern char updown_bits[];
  986. X
  987. #define bomb_width 16
  988. #define bomb_height 16
  989. extern char bomb_bits[];
  990. X
  991. #define pageR_width 24
  992. #define pageR_height 24
  993. extern char pageR_bits[];
  994. X
  995. #define pageL_width 24
  996. #define pageL_height 24
  997. extern char pageL_bits[];
  998. X
  999. #define step_width 24
  1000. #define step_height 24
  1001. extern char step_bits[];
  1002. X
  1003. #define next_width 24
  1004. #define next_height 24
  1005. extern char next_bits[];
  1006. X
  1007. #define print_width 24
  1008. #define print_height 24
  1009. extern char print_bits[];
  1010. X
  1011. #define down_width 16
  1012. #define down_height 16
  1013. extern char down_bits[];
  1014. X
  1015. #define up_width 16
  1016. #define up_height 16
  1017. extern char up_bits[];
  1018. X
  1019. #define stack_width 24
  1020. #define stack_height 24
  1021. extern char stack_bits[];
  1022. X
  1023. #define cont_width 24
  1024. #define cont_height 24
  1025. extern char cont_bits[];
  1026. X
  1027. #define finish_width 24
  1028. #define finish_height 24
  1029. extern char finish_bits[];
  1030. X
  1031. #define run_width 24
  1032. #define run_height 24
  1033. extern char run_bits[];
  1034. X
  1035. #define disp_width 24
  1036. #define disp_height 24
  1037. extern char disp_bits[];
  1038. X
  1039. #define undisp_width 24
  1040. #define undisp_height 24
  1041. extern char undisp_bits[];
  1042. X
  1043. #define clear_width 24
  1044. #define clear_height 24
  1045. extern char clear_bits[];
  1046. X
  1047. #define prints_width 24
  1048. #define prints_height 24
  1049. extern char prints_bits[];
  1050. X
  1051. #define args_width 24
  1052. #define args_height 24
  1053. extern char args_bits[];
  1054. X
  1055. #define locals_width 24
  1056. #define locals_height 24
  1057. extern char locals_bits[];
  1058. X
  1059. #define triton_width 64
  1060. #define triton_height 64
  1061. extern char triton_bits[];
  1062. SHAR_EOF
  1063. chmod 0664 mxgdb/bitmaps.h ||
  1064. echo 'restore of mxgdb/bitmaps.h failed'
  1065. Wc_c="`wc -c < 'mxgdb/bitmaps.h'`"
  1066. test 1967 -eq "$Wc_c" ||
  1067.     echo 'mxgdb/bitmaps.h: original size 1967, current size' "$Wc_c"
  1068. rm -f _shar_wnt_.tmp
  1069. fi
  1070. # ============= mxgdb/callgdb.c ==============
  1071. if test -f 'mxgdb/callgdb.c' -a X"$1" != X"-c"; then
  1072.     echo 'x - skipping mxgdb/callgdb.c (File already exists)'
  1073.     rm -f _shar_wnt_.tmp
  1074. else
  1075. > _shar_wnt_.tmp
  1076. echo 'x - extracting mxgdb/callgdb.c (Text)'
  1077. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/callgdb.c' &&
  1078. static char rcsid[] = "$Id: callgdb.c,v 1.1 1991/08/23 16:34:20 jtsillas Exp $";
  1079. X
  1080. /*****************************************************************************
  1081. X *
  1082. X *  xdbx - X Window System interface to the dbx debugger
  1083. X *
  1084. X *  Copyright 1989 The University of Texas at Austin
  1085. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  1086. X *
  1087. X *  Permission to use, copy, modify, and distribute this software and its
  1088. X *  documentation for any purpose and without fee is hereby granted,
  1089. X *  provided that the above copyright notice appear in all copies and that
  1090. X *  both that copyright notice and this permission notice appear in
  1091. X *  supporting documentation, and that the name of The University of Texas
  1092. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  1093. X *  used in advertising or publicity pertaining to distribution of
  1094. X *  the software without specific, written prior permission.  The
  1095. X *  University of Texas and MCC makes no representations about the 
  1096. X *  suitability of this software for any purpose.  It is provided "as is" 
  1097. X *  without express or implied warranty.
  1098. X *
  1099. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1100. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1101. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  1102. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1103. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  1104. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  1105. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1106. X *
  1107. X *  Author:      Po Cheung
  1108. X *  Created:       March 10, 1989
  1109. X *
  1110. X *****************************************************************************
  1111. X * 
  1112. X *  xxgdb - X Window System interface to the gdb debugger
  1113. X *  
  1114. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  1115. X *  
  1116. X *  Permission to use, copy, modify, and distribute this software and its
  1117. X *  documentation for any purpose and without fee is hereby granted,
  1118. X *  provided that the above copyright notice appear in all copies and that
  1119. X *  both that copyright notice and this permission notice appear in
  1120. X *  supporting documentation, and that the name of Thomson Consumer
  1121. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  1122. X *  to distribution of the software without specific, written prior
  1123. X *  permission.  TCE makes no representations about the suitability of
  1124. X *  this software for any purpose.  It is provided "as is" without express
  1125. X *  or implied warranty.
  1126. X *
  1127. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1128. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  1129. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  1130. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1131. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1132. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1133. X *  SOFTWARE.
  1134. X *
  1135. X *  Adaptation to GDB:  Pierre Willard
  1136. X *  XXGDB Created:       December, 1990
  1137. X *
  1138. X *****************************************************************************
  1139. X
  1140. /*  callgdb.c
  1141. X *
  1142. X *    Set up communication between dbx and xdbx using pseudo terminal, and
  1143. X *    call dbx.
  1144. X *
  1145. X *    open_master():    Open the master side of pty.
  1146. X *    open_slave():     Open the slave side of pty.
  1147. X *    callgdb():     Invoke dbx.
  1148. X */
  1149. X
  1150. #ifdef Mips 
  1151. #include     <sysv/sys/termio.h>
  1152. #else
  1153. #include    <termio.h>
  1154. #endif
  1155. X
  1156. #include    "global.h"
  1157. X
  1158. #ifdef SYSV 
  1159. #ifdef SCO
  1160. #  include        <sys/fcntl.h>
  1161. #endif
  1162. #endif
  1163. #ifdef SVR4_PTY
  1164. #include    <sys/stropts.h>
  1165. #endif
  1166. X
  1167. FILE               *dbxfp = NULL;        /* file pointer to gdb */
  1168. int                dbxpid = 0;        /* dbx process id */
  1169. char            dbxfbuf[BUFSIZ]; /* A buffer used by setvbuf on master pty */
  1170. static int    dbxInputId;        /* dbx input id */
  1171. X
  1172. #ifdef SVR4_PTY
  1173. static char     pty[] = "/dev/ptmx";    /* master side of pseudo-terminal */
  1174. static char     tty[] = "/dev/pts/XXX";    /* slave side of pseudo-terminal */
  1175. #else
  1176. static char     pty[11] = "/dev/pty??";    /* master side of pseudo-terminal */
  1177. static char     tty[11] = "/dev/tty??";    /* slave side of pseudo-terminal */
  1178. #endif
  1179. X
  1180. extern char    *dbxprompt;
  1181. static int hold_slave = -1;
  1182. X
  1183. /*
  1184. X *  mxgdb talks to gdb through a pseudo terminal which is a pair of master
  1185. X *  and slave devices: /dev/pty?? and /dev/tty??, where ?? goes from p0 to
  1186. X *  sf (system dependent).  The pty is opened for both read and write. Some 
  1187. X *  systems use ptmx style pty's. For these define SVR4_PTY.
  1188. X */
  1189. static int open_master()
  1190. {
  1191. X  int  i, master;
  1192. X  char c;
  1193. X  
  1194. #ifdef SVR4_PTY
  1195. X  if ((master  = open(pty, O_RDWR)) >= 0)
  1196. X    return master;
  1197. #else /* ! SVR4_PTY */
  1198. X  for (c='p'; c<'t'; c++) {
  1199. X    for (i=0; i<16; i++) {
  1200. X      pty[8] = c;
  1201. X      pty[9] = "0123456789abcdef"[i];
  1202. X      tty[8] = pty[8];
  1203. X      tty[9] = pty[9];
  1204. X      if ((master = open(pty, O_RDWR)) >= 0)
  1205. X    {
  1206. X      if ((hold_slave = open(tty, O_RDWR)) >= 0)
  1207. X        return (master);
  1208. X      else close(master);
  1209. X    }
  1210. X    }
  1211. X  }
  1212. #endif /* SVR4_PTY */
  1213. X  fprintf(stderr, "mxgdb: all ptys in use\n");
  1214. X  exit(2);
  1215. }
  1216. X
  1217. static int open_slave()
  1218. {
  1219. X  int slave;
  1220. X    
  1221. X  if (hold_slave >= 0) {
  1222. X    close(hold_slave);
  1223. X    hold_slave = -1;
  1224. X  }
  1225. X  if ((slave = open(tty, O_RDWR)) >= 0)
  1226. X    return (slave);
  1227. X  fprintf(stderr, "mxgdb: open: cannot open slave pty %s", tty);
  1228. X  exit(2);
  1229. }
  1230. X
  1231. /* ARGSUSED */
  1232. void callgdb(argc, argv)
  1233. int argc;
  1234. char *argv[];
  1235. {
  1236. X    struct termio Termio;
  1237. X    int        master;        /* file descriptor of master pty */
  1238. X    int        slave = -1;         /* file descriptor of slave pty */
  1239. X    int          fd;             /* file descriptor of controlling tty */
  1240. X    int          pid;            /* process id */
  1241. X    int          pgrp;            /* process group id */
  1242. X    char       *debugger;         /* name of executable debugger */
  1243. #ifdef SVR4_PTY
  1244. X    char          *slavename;
  1245. X    char          *ptsname();
  1246. #endif
  1247. X    char      errmsg[LINESIZ];
  1248. X
  1249. X    debugger = (char *) getenv("MXGDB_DEBUGGER");    /* first looks up env var */
  1250. X
  1251. X    if (debugger == NULL)
  1252. X    debugger = XtNewString(DEBUGGER);
  1253. X  
  1254. X    /* construct dbx prompt string based on the name of debugger invoked */
  1255. X    if (dbxprompt == NULL) {
  1256. X    dbxprompt = XtMalloc((4+strlen(debugger)) * sizeof(char));
  1257. X    sprintf(dbxprompt, "(%s) ", debugger);
  1258. X    }
  1259. X
  1260. X    /*
  1261. X     * Clear controlling tty.  Do this now, so that open_slave and
  1262. X     * open_master will cause the selected pty to become the
  1263. X     * controlling tty.
  1264. X     */
  1265. #ifndef SYSV 
  1266. X    if ((fd = open("/dev/tty", O_RDWR)) > 0) {
  1267. X      ioctl(fd, TIOCNOTTY, 0);
  1268. X      close(fd);
  1269. X    }
  1270. #endif /* SYSV */
  1271. X
  1272. X    master = open_master();
  1273. X
  1274. #ifndef SYSV 
  1275. X    slave = open_slave();
  1276. #endif
  1277. X
  1278. X    dbxpid = fork();
  1279. X    if (dbxpid == -1) {
  1280. X      perror("mxgdb error: cannot fork process");
  1281. X      exit(2);
  1282. X    }
  1283. X    else if (dbxpid) { 
  1284. X      /* 
  1285. X       * Parent : close the slave side of pty
  1286. X       *        close stdin and stdout
  1287. X       *        set the dbx file descriptor to nonblocking mode
  1288. X       *        open file pointer with read/write access to dbx
  1289. X       *        set line buffered mode
  1290. X       *        register dbx input with X
  1291. X       */
  1292. X      if (slave >= 0) {
  1293. X    close(slave);
  1294. X    slave = -1;
  1295. X      }
  1296. X      close(0);
  1297. X      close(1);
  1298. X      fcntl(master, F_SETFL, FNDELAY);
  1299. X      dbxfp = (FILE *)fdopen(master, "r+");
  1300. X      setvbuf(dbxfp, dbxfbuf, _IONBF, BUFSIZ);
  1301. X      dbxInputId = XtAppAddInput(app_context, master, XtInputReadMask, 
  1302. X                 read_dbx, NULL);
  1303. X    }
  1304. X    else { 
  1305. X      /* 
  1306. X       * Child : close master side of pty
  1307. X       *        redirect stdin, stdout, stderr of dbx to pty
  1308. X       *       unbuffer output data from dbx
  1309. X       *       exec dbx with arguments
  1310. X       */
  1311. X      
  1312. #ifdef SYSV 
  1313. X      setpgrp();
  1314. #ifdef SVR4_PTY
  1315. X      grantpt (master);            /* change permission of slave */
  1316. X      unlockpt (master);            /* unlock slave */
  1317. X      slavename = ptsname (master);        /* get name of slave */
  1318. X      strcpy (tty, slavename);        /* copy over to save area */
  1319. #endif
  1320. X      slave = open_slave();
  1321. #ifdef SVR4_PTY
  1322. X      /*XXX todo: need to make sure these succeed */
  1323. X      ioctl (slave, I_PUSH, "ptem");
  1324. X      ioctl (slave, I_PUSH, "ldterm");
  1325. #endif
  1326. #endif /* SYSV */
  1327. X      close(master);
  1328. X      
  1329. X      /*
  1330. X       * Modify local and output mode of slave pty
  1331. X       */
  1332. X
  1333. X      ioctl(slave, TCGETA, &Termio);
  1334. X      Termio.c_lflag &= ~ECHO;    /* No echo */
  1335. X      Termio.c_oflag &= ~ONLCR;    /* Do not map NL to CR-NL on output */
  1336. X      ioctl(slave, TCSETA, &Termio);
  1337. X      
  1338. X      dup2(slave, 0);
  1339. X      dup2(slave, 1);
  1340. X      dup2(slave, 2);
  1341. X      if (slave > 2)
  1342. X    close(slave);
  1343. X      
  1344. X      fcntl(1, F_SETFL, FAPPEND);
  1345. X      setbuf(stdout, NULL);
  1346. X      
  1347. X      /*
  1348. X       * Set our process group to that of the terminal,
  1349. X       * so we can change the group of the terminal.
  1350. X       */
  1351. #ifndef SYSV
  1352. X      /*
  1353. X       * Now set the process group of the terminal and of us
  1354. X       * to our process id.  This clears us from the control
  1355. X       * of the other process group.
  1356. X       */
  1357. X      pid = getpid();
  1358. X      ioctl(0, TIOCSPGRP, &pid);
  1359. X      setpgrp(0, pid);
  1360. #endif
  1361. X      argv[0] = debugger;
  1362. X      execvp(debugger, argv);
  1363. X      sprintf(errmsg, "mxgdb error: cannot exec %s", debugger);
  1364. X      perror(errmsg);
  1365. X      exit(2);
  1366. X    }
  1367. X  }
  1368. X
  1369. SHAR_EOF
  1370. chmod 0664 mxgdb/callgdb.c ||
  1371. echo 'restore of mxgdb/callgdb.c failed'
  1372. Wc_c="`wc -c < 'mxgdb/callgdb.c'`"
  1373. test 9084 -eq "$Wc_c" ||
  1374.     echo 'mxgdb/callgdb.c: original size 9084, current size' "$Wc_c"
  1375. rm -f _shar_wnt_.tmp
  1376. fi
  1377. # ============= mxgdb/source.c ==============
  1378. if test -f 'mxgdb/source.c' -a X"$1" != X"-c"; then
  1379.     echo 'x - skipping mxgdb/source.c (File already exists)'
  1380.     rm -f _shar_wnt_.tmp
  1381. else
  1382. > _shar_wnt_.tmp
  1383. echo 'x - extracting mxgdb/source.c (Text)'
  1384. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/source.c' &&
  1385. X
  1386. static char rcsid[] = "$Id: source.c,v 1.13 1991/08/23 16:34:43 jtsillas Exp $";
  1387. X
  1388. /*****************************************************************************
  1389. X *
  1390. X *  xdbx - X Window System interface to the dbx debugger
  1391. X *
  1392. X *  Copyright 1989 The University of Texas at Austin
  1393. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  1394. X *
  1395. X *  Permission to use, copy, modify, and distribute this software and its
  1396. X *  documentation for any purpose and without fee is hereby granted,
  1397. X *  provided that the above copyright notice appear in all copies and that
  1398. X *  both that copyright notice and this permission notice appear in
  1399. X *  supporting documentation, and that the name of The University of Texas
  1400. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  1401. X *  used in advertising or publicity pertaining to distribution of
  1402. X *  the software without specific, written prior permission.  The
  1403. SHAR_EOF
  1404. true || echo 'restore of mxgdb/source.c failed'
  1405. fi
  1406. echo 'End of  part 2'
  1407. echo 'File mxgdb/source.c is continued in part 3'
  1408. echo 3 > _shar_seq_.tmp
  1409. exit 0
  1410.