home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 4 / 4008 < prev    next >
Encoding:
Text File  |  1991-09-09  |  39.9 KB  |  1,317 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 6/10)
  5. Organization: Bull HN, Worldwide Information Systems, Billerica, Mass., USA
  6. Distribution: alt
  7. Date: 6 Sep 91 14:29:26
  8. Message-ID: <JTSILLAS.91Sep6142926@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.06 (part 6 of a multipart archive)
  14. # do not concatenate these parts, unpack them in order with /bin/sh
  15. # file mxgdb/handler.c 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" != 6; 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/handler.c'
  31. else
  32. echo 'x - continuing file mxgdb/handler.c'
  33. sed 's/^X//' << 'SHAR_EOF' >> 'mxgdb/handler.c' &&
  34. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  35. X *
  36. X *  Author:      Po Cheung
  37. X *  Created:       March 10, 1989
  38. X * 
  39. X *****************************************************************************
  40. X * 
  41. X *  xxgdb - X Window System interface to the gdb debugger
  42. X *  
  43. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  44. X *  
  45. X *  Permission to use, copy, modify, and distribute this software and its
  46. X *  documentation for any purpose and without fee is hereby granted,
  47. X *  provided that the above copyright notice appear in all copies and that
  48. X *  both that copyright notice and this permission notice appear in
  49. X *  supporting documentation, and that the name of Thomson Consumer
  50. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  51. X *  to distribution of the software without specific, written prior
  52. X *  permission.  TCE makes no representations about the suitability of
  53. X *  this software for any purpose.  It is provided "as is" without express
  54. X *  or implied warranty.
  55. X *
  56. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  57. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  58. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  59. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  60. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  61. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  62. X *  SOFTWARE.
  63. X *
  64. X *  Adaptation to GDB:  Pierre Willard
  65. X *  XXGDB Created:       December, 1990
  66. X *
  67. X *****************************************************************************/
  68. X
  69. /*  handler.c
  70. X *
  71. X *    Contain action handlers for the parser to invoke upon a dbx command.
  72. X *
  73. X *    TextSetTopPosition():    Set the top character position of textdisplayed
  74. X *    AdjustText():        Adjust the portion of text displayed.
  75. X *    exec_handler():        Update file, line label, arrow position.
  76. X *    done_handler():        Progrm execution completed, clear breakpoints
  77. X *    stop_at_handler():    Place stop sign on line specified.
  78. X *    stop_in_handler():    Place stop sign on function specified.
  79. X *    updown_handler():        Update file, line label, updown arrow position.
  80. X *    clear_handler():        Remove stop sign.
  81. X *    func_handler():        Display function, if specified.
  82. X *    file_handler():        Display file, if specified.
  83. X *    debug_handler():        Check directory use list, display source file.
  84. X *    cd_handler():        Record current working directory.
  85. X *    use_handler():        Record directory paths.
  86. X *    search_handler():        Adjust source file to display matched line.
  87. X *    list_handler();        Adjust source file to display result.
  88. X *    display_handler():    Display results in display window.
  89. X */
  90. X
  91. #include <ctype.h>
  92. #include "global.h"
  93. #include <Xm/Xm.h>
  94. #include <Xm/Text.h>
  95. X
  96. Boolean        Echo = True;        /* display dbx output if true */
  97. static Boolean    Skip_func_handler = False;
  98. X
  99. /*  Display text starting from the top position specified by pos */
  100. X
  101. void TextSetTopPosition(w, pos)
  102. X    Widget w;
  103. X    XmTextPosition pos;
  104. {
  105. X    Arg args[MAXARGS];
  106. X
  107. X    XtSetArg(args[0], XmNtopCharacter, (XtArgVal) pos);
  108. X    XtSetValues(w, args, 1);
  109. }
  110. X
  111. short currpos;
  112. X
  113. /*
  114. X *  Adjust text so that 'line' will fall into the viewable part of the
  115. X *  source window.
  116. X *  Arrows, stop signs, and line label and Vertical Scroll bar
  117. X *  are updated accordingly.
  118. X */
  119. void AdjustText(line)
  120. X    int           line;
  121. {
  122. X    FileRec         *file;
  123. X    int                nlines = 0;
  124. X    int            i;
  125. X    XmTextPosition     pos;
  126. X    Dimension width;
  127. X    Arg                 args[5];
  128. X
  129. X    if ((file = displayedFile) == NULL || line <= 0) return;
  130. X    file->currentline = line;
  131. X
  132. X    if (line < file->topline || line > file->bottomline ) {
  133. X    /* Position line about 30% from the top */
  134. X    nlines = file->lines*0.3;
  135. X    if (line < nlines)               /* near top */
  136. X        file->topline = 1;
  137. X    else if (line > file->lastline - nlines)  /* near bottom */
  138. X        file->topline = MAX(file->lastline - file->lines + 1, 1);
  139. X    else
  140. X        file->topline = line - nlines;
  141. X    file->bottomline = MIN(file->topline + file->lines - 1, 
  142. X                   file->lastline);
  143. X    TextSetTopPosition(sourceWindow, file->linepos[file->topline]);
  144. X    file->topPosition = file->linepos[file->topline];
  145. X    }
  146. X    XmTextSetInsertionPosition(sourceWindow, file->linepos[line]);
  147. X
  148. X    /* Text window might have scrolled, check topline & bottomline */
  149. X    pos = XmTextGetTopCharacter(sourceWindow);
  150. X
  151. X    for (i=1; pos >= file->linepos[i]; i++);
  152. X    if (file->topline != i-1) {
  153. X    file->topline = i-1;
  154. X    file->bottomline = MIN (file->topline + file->lines - 1,
  155. X                file->lastline);
  156. X    }
  157. X
  158. X    if(pos != currpos && XtIsManaged(scrollV))
  159. X      {
  160. X    XtSetArg(args[0], XmNvalue, TextPositionToLine(pos));
  161. X    XtSetValues(scrollV, args, 1);
  162. X    currpos = pos;
  163. X      }
  164. X
  165. X    XtMapWidget(sourceWindow);
  166. X
  167. X    UpdateLineLabel(line);
  168. X    UpdateStops(file, -1);
  169. X    UpdateArrow(file);
  170. X    UpdateUpdown(file);
  171. X    UpdateBomb(file);
  172. }
  173. X
  174. #include "gdb_handler.c"
  175. X
  176. SHAR_EOF
  177. echo 'File mxgdb/handler.c is complete' &&
  178. chmod 0664 mxgdb/handler.c ||
  179. echo 'restore of mxgdb/handler.c failed'
  180. Wc_c="`wc -c < 'mxgdb/handler.c'`"
  181. test 6448 -eq "$Wc_c" ||
  182.     echo 'mxgdb/handler.c: original size 6448, current size' "$Wc_c"
  183. rm -f _shar_wnt_.tmp
  184. fi
  185. # ============= mxgdb/malloc.c ==============
  186. if test -f 'mxgdb/malloc.c' -a X"$1" != X"-c"; then
  187.     echo 'x - skipping mxgdb/malloc.c (File already exists)'
  188.     rm -f _shar_wnt_.tmp
  189. else
  190. > _shar_wnt_.tmp
  191. echo 'x - extracting mxgdb/malloc.c (Text)'
  192. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/malloc.c' &&
  193. static char rcsid[] = "$Id: malloc.c,v 1.1.1.1 1991/05/16 21:42:28 jtsillas Exp $";
  194. X
  195. /* dynamic memory allocation for GNU.
  196. X   Copyright (C) 1985, 1987 Free Software Foundation, Inc.
  197. X
  198. X               NO WARRANTY
  199. X
  200. X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  201. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  202. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  203. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  204. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  205. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  206. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  207. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  208. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  209. CORRECTION.
  210. X
  211. X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  212. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  213. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  214. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  215. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  216. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  217. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  218. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  219. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  220. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  221. X
  222. X        GENERAL PUBLIC LICENSE TO COPY
  223. X
  224. X  1. You may copy and distribute verbatim copies of this source file
  225. as you receive it, in any medium, provided that you conspicuously and
  226. appropriately publish on each copy a valid copyright notice "Copyright
  227. (C) 1985 Free Software Foundation, Inc."; and include following the
  228. copyright notice a verbatim copy of the above disclaimer of warranty
  229. and of this License.  You may charge a distribution fee for the
  230. physical act of transferring a copy.
  231. X
  232. X  2. You may modify your copy or copies of this source file or
  233. any portion of it, and copy and distribute such modifications under
  234. the terms of Paragraph 1 above, provided that you also do the following:
  235. X
  236. X    a) cause the modified files to carry prominent notices stating
  237. X    that you changed the files and the date of any change; and
  238. X
  239. X    b) cause the whole of any work that you distribute or publish,
  240. X    that in whole or in part contains or is a derivative of this
  241. X    program or any part thereof, to be licensed at no charge to all
  242. X    third parties on terms identical to those contained in this
  243. X    License Agreement (except that you may choose to grant more extensive
  244. X    warranty protection to some or all third parties, at your option).
  245. X
  246. X    c) You may charge a distribution fee for the physical act of
  247. X    transferring a copy, and you may at your option offer warranty
  248. X    protection in exchange for a fee.
  249. X
  250. Mere aggregation of another unrelated program with this program (or its
  251. derivative) on a volume of a storage or distribution medium does not bring
  252. the other program under the scope of these terms.
  253. X
  254. X  3. You may copy and distribute this program (or a portion or derivative
  255. of it, under Paragraph 2) in object code or executable form under the terms
  256. of Paragraphs 1 and 2 above provided that you also do one of the following:
  257. X
  258. X    a) accompany it with the complete corresponding machine-readable
  259. X    source code, which must be distributed under the terms of
  260. X    Paragraphs 1 and 2 above; or,
  261. X
  262. X    b) accompany it with a written offer, valid for at least three
  263. X    years, to give any third party free (except for a nominal
  264. X    shipping charge) a complete machine-readable copy of the
  265. X    corresponding source code, to be distributed under the terms of
  266. X    Paragraphs 1 and 2 above; or,
  267. X
  268. X    c) accompany it with the information you received as to where the
  269. X    corresponding source code may be obtained.  (This alternative is
  270. X    allowed only for noncommercial distribution and only if you
  271. X    received the program in object code or executable form alone.)
  272. X
  273. For an executable file, complete source code means all the source code for
  274. all modules it contains; but, as a special exception, it need not include
  275. source code for modules which are standard libraries that accompany the
  276. operating system on which the executable file runs.
  277. X
  278. X  4. You may not copy, sublicense, distribute or transfer this program
  279. except as expressly provided under this License Agreement.  Any attempt
  280. otherwise to copy, sublicense, distribute or transfer this program is void and
  281. your rights to use the program under this License agreement shall be
  282. automatically terminated.  However, parties who have received computer
  283. software programs from you with this License Agreement will not have
  284. their licenses terminated so long as such parties remain in full compliance.
  285. X
  286. X  5. If you wish to incorporate parts of this program into other free
  287. programs whose distribution conditions are different, write to the Free
  288. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  289. worked out a simple rule that can be stated here, but we will often permit
  290. this.  We will be guided by the two goals of preserving the free status of
  291. all derivatives of our free software and of promoting the sharing and reuse of
  292. software.
  293. X
  294. X
  295. In other words, you are welcome to use, share and improve this program.
  296. You are forbidden to forbid anyone else to use, share and improve
  297. what you give them.   Help stamp out software-hoarding!  */
  298. X
  299. X
  300. /*
  301. X * @(#)nmalloc.c 1 (Caltech) 2/21/82
  302. X *
  303. X *    U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
  304. X *
  305. X *    Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
  306. X *
  307. X * This is a very fast storage allocator.  It allocates blocks of a small 
  308. X * number of different sizes, and keeps free lists of each size.  Blocks
  309. X * that don't exactly fit are passed up to the next larger size.  In this 
  310. X * implementation, the available sizes are (2^n)-4 (or -16) bytes long.
  311. X * This is designed for use in a program that uses vast quantities of
  312. X * memory, but bombs when it runs out.  To make it a little better, it
  313. X * warns the user when he starts to get near the end.
  314. X *
  315. X * June 84, ACT: modified rcheck code to check the range given to malloc,
  316. X * rather than the range determined by the 2-power used.
  317. X *
  318. X * Jan 85, RMS: calls malloc_warning to issue warning on nearly full.
  319. X * No longer Emacs-specific; can serve as all-purpose malloc for GNU.
  320. X * You should call malloc_init to reinitialize after loading dumped Emacs.
  321. X * Call malloc_stats to get info on memory stats if MSTATS turned on.
  322. X * realloc knows how to return same block given, just changing its size,
  323. X * if the power of 2 is correct.
  324. X */
  325. X
  326. /*
  327. X * nextf[i] is the pointer to the next free block of size 2^(i+3).  The
  328. X * smallest allocatable block is 8 bytes.  The overhead information will
  329. X * go in the first int of the block, and the returned pointer will point
  330. X * to the second.
  331. X *
  332. #ifdef MSTATS
  333. X * nmalloc[i] is the difference between the number of mallocs and frees
  334. X * for a given block size.
  335. #endif MSTATS
  336. X */
  337. X
  338. #ifdef emacs
  339. /* config.h specifies which kind of system this is.  */
  340. #include "config.h"
  341. #else
  342. X
  343. /* Determine which kind of system this is.  */
  344. #ifndef USG
  345. #include <signal.h>
  346. #ifndef SIGTSTP
  347. #ifndef VMS
  348. #ifndef USG
  349. #define USG
  350. #endif
  351. #endif /* not VMS */
  352. #else /* SIGTSTP */
  353. #ifdef SIGIO
  354. #define BSD4_2
  355. #endif /* SIGIO */
  356. #endif /* SIGTSTP */
  357. #endif
  358. X
  359. #endif /* not emacs */
  360. X
  361. /* Define getpagesize () if the system does not.  */
  362. #include "getpagesize.h"
  363. X
  364. #ifndef BSD4_2
  365. #ifndef USG
  366. #include <sys/vlimit.h>        /* warn the user when near the end */
  367. #endif /* not USG */
  368. #else /* if BSD4_2 */
  369. #include <sys/time.h>
  370. #include <sys/resource.h>
  371. #endif /* BSD4_2 */
  372. X
  373. extern char *start_of_data ();
  374. X
  375. #ifdef BSD
  376. #ifndef DATA_SEG_BITS
  377. #define start_of_data() &etext
  378. #endif
  379. #endif
  380. X
  381. #ifndef emacs
  382. #define start_of_data() &etext
  383. #endif
  384. X
  385. #define ISALLOC ((char) 0xf7)    /* magic byte that implies allocation */
  386. #define ISFREE ((char) 0x54)    /* magic byte that implies free block */
  387. X                /* this is for error checking only */
  388. #define ISMEMALIGN ((char) 0xd6)  /* Stored before the value returned by
  389. X                     memalign, with the rest of the word
  390. X                     being the distance to the true
  391. X                     beginning of the block.  */
  392. X
  393. extern char etext;
  394. X
  395. /* These two are for user programs to look at, when they are interested.  */
  396. X
  397. unsigned int malloc_sbrk_used;       /* amount of data space used now */
  398. unsigned int malloc_sbrk_unused;     /* amount more we can have */
  399. X
  400. /* start of data space; can be changed by calling init_malloc */
  401. static char *data_space_start;
  402. X
  403. #ifdef MSTATS
  404. static int nmalloc[30];
  405. static int nmal, nfre;
  406. #endif /* MSTATS */
  407. X
  408. /* If range checking is not turned on, all we have is a flag indicating
  409. X   whether memory is allocated, an index in nextf[], and a size field; to
  410. X   realloc() memory we copy either size bytes or 1<<(index+3) bytes depending
  411. X   on whether the former can hold the exact size (given the value of
  412. X   'index').  If range checking is on, we always need to know how much space
  413. X   is allocated, so the 'size' field is never used. */
  414. X
  415. struct mhead {
  416. X    char     mh_alloc;    /* ISALLOC or ISFREE */
  417. X    char     mh_index;    /* index in nextf[] */
  418. /* Remainder are valid only when block is allocated */
  419. X    unsigned short mh_size;    /* size, if < 0x10000 */
  420. #ifdef rcheck
  421. X    unsigned mh_nbytes;    /* number of bytes allocated */
  422. X    int      mh_magic4;    /* should be == MAGIC4 */
  423. #endif /* rcheck */
  424. };
  425. X
  426. /* Access free-list pointer of a block.
  427. X  It is stored at block + 4.
  428. X  This is not a field in the mhead structure
  429. X  because we want sizeof (struct mhead)
  430. X  to describe the overhead for when the block is in use,
  431. X  and we do not want the free-list pointer to count in that.  */
  432. X
  433. #define CHAIN(a) \
  434. X  (*(struct mhead **) (sizeof (char *) + (char *) (a)))
  435. X
  436. #ifdef rcheck
  437. X
  438. /* To implement range checking, we write magic values in at the beginning and
  439. X   end of each allocated block, and make sure they are undisturbed whenever a
  440. X   free or a realloc occurs. */
  441. /* Written in each of the 4 bytes following the block's real space */
  442. #define MAGIC1 0x55
  443. /* Written in the 4 bytes before the block's real space */
  444. #define MAGIC4 0x55555555
  445. #define ASSERT(p) if (!(p)) botch("p"); else
  446. #define EXTRA  4        /* 4 bytes extra for MAGIC1s */
  447. #else
  448. #define ASSERT(p)
  449. #define EXTRA  0
  450. #endif /* rcheck */
  451. X
  452. X
  453. /* nextf[i] is free list of blocks of size 2**(i + 3)  */
  454. X
  455. static struct mhead *nextf[30];
  456. X
  457. /* busy[i] is nonzero while allocation of block size i is in progress.  */
  458. X
  459. static char busy[30];
  460. X
  461. /* Number of bytes of writable memory we can expect to be able to get */
  462. static unsigned int lim_data;
  463. X
  464. /* Level number of warnings already issued.
  465. X  0 -- no warnings issued.
  466. X  1 -- 75% warning already issued.
  467. X  2 -- 85% warning already issued.
  468. */
  469. static int warnlevel;
  470. X
  471. /* Function to call to issue a warning;
  472. X   0 means don't issue them.  */
  473. static void (*warnfunction) ();
  474. X
  475. /* nonzero once initial bunch of free blocks made */
  476. static int gotpool;
  477. X
  478. char *_malloc_base;
  479. X
  480. static void getpool ();
  481. X
  482. /* Cause reinitialization based on job parameters;
  483. X  also declare where the end of pure storage is. */
  484. void
  485. malloc_init (start, warnfun)
  486. X     char *start;
  487. X     void (*warnfun) ();
  488. {
  489. X  if (start)
  490. X    data_space_start = start;
  491. X  lim_data = 0;
  492. X  warnlevel = 0;
  493. X  warnfunction = warnfun;
  494. }
  495. X
  496. /* Return the maximum size to which MEM can be realloc'd
  497. X   without actually requiring copying.  */
  498. X
  499. int
  500. malloc_usable_size (mem)
  501. X     char *mem;
  502. {
  503. X  int blocksize = 8 << (((struct mhead *) mem) - 1) -> mh_index;
  504. X
  505. X  return blocksize - sizeof (struct mhead) - EXTRA;
  506. }
  507. X
  508. static void
  509. morecore (nu)            /* ask system for more memory */
  510. X     register int nu;        /* size index to get more of  */
  511. {
  512. X  char *sbrk ();
  513. X  register char *cp;
  514. X  register int nblks;
  515. X  register unsigned int siz;
  516. X  int oldmask;
  517. X
  518. #ifdef BSD
  519. #ifndef BSD4_1
  520. X  /* ?? There was a suggestion not to block SIGILL, somehow for GDB's sake.  */
  521. X  oldmask = sigsetmask (-1);
  522. #endif
  523. #endif
  524. X
  525. X  if (!data_space_start)
  526. X    {
  527. X      data_space_start = start_of_data ();
  528. X    }
  529. X
  530. X  if (lim_data == 0)
  531. X    get_lim_data ();
  532. X
  533. X /* On initial startup, get two blocks of each size up to 1k bytes */
  534. X  if (!gotpool)
  535. X    { getpool (); getpool (); gotpool = 1; }
  536. X
  537. X  /* Find current end of memory and issue warning if getting near max */
  538. X
  539. #ifndef VMS
  540. X  /* Maximum virtual memory on VMS is difficult to calculate since it
  541. X   * depends on several dynmacially changing things. Also, alignment
  542. X   * isn't that important. That is why much of the code here is ifdef'ed
  543. X   * out for VMS systems.
  544. X   */
  545. X  cp = sbrk (0);
  546. X  siz = cp - data_space_start;
  547. X
  548. X  if (warnfunction)
  549. X    switch (warnlevel)
  550. X      {
  551. X      case 0: 
  552. X    if (siz > (lim_data / 4) * 3)
  553. X      {
  554. X        warnlevel++;
  555. X        (*warnfunction) ("Warning: past 75% of memory limit");
  556. X      }
  557. X    break;
  558. X      case 1: 
  559. X    if (siz > (lim_data / 20) * 17)
  560. X      {
  561. X        warnlevel++;
  562. X        (*warnfunction) ("Warning: past 85% of memory limit");
  563. X      }
  564. X    break;
  565. X      case 2: 
  566. X    if (siz > (lim_data / 20) * 19)
  567. X      {
  568. X        warnlevel++;
  569. X        (*warnfunction) ("Warning: past 95% of memory limit");
  570. X      }
  571. X    break;
  572. X      }
  573. X
  574. X  if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  575. X    sbrk (1024 - ((int) cp & 0x3ff));
  576. #endif /* not VMS */
  577. X
  578. X /* Take at least 2k, and figure out how many blocks of the desired size
  579. X    we're about to get */
  580. X  nblks = 1;
  581. X  if ((siz = nu) < 8)
  582. X    nblks = 1 << ((siz = 8) - nu);
  583. X
  584. X  if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
  585. X    {
  586. #ifdef BSD
  587. #ifndef BSD4_1
  588. X      sigsetmask (oldmask);
  589. #endif
  590. #endif
  591. X      return;            /* no more room! */
  592. X    }
  593. X  malloc_sbrk_used = siz;
  594. X  malloc_sbrk_unused = lim_data - siz;
  595. X
  596. #ifndef VMS
  597. X  if ((int) cp & 7)
  598. X    {        /* shouldn't happen, but just in case */
  599. X      cp = (char *) (((int) cp + 8) & ~7);
  600. X      nblks--;
  601. X    }
  602. #endif /* not VMS */
  603. X
  604. X /* save new header and link the nblks blocks together */
  605. X  nextf[nu] = (struct mhead *) cp;
  606. X  siz = 1 << (nu + 3);
  607. X  while (1)
  608. X    {
  609. X      ((struct mhead *) cp) -> mh_alloc = ISFREE;
  610. X      ((struct mhead *) cp) -> mh_index = nu;
  611. X      if (--nblks <= 0) break;
  612. X      CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz);
  613. X      cp += siz;
  614. X    }
  615. X  CHAIN ((struct mhead *) cp) = 0;
  616. X
  617. #ifdef BSD
  618. #ifndef BSD4_1
  619. X  sigsetmask (oldmask);
  620. #endif
  621. #endif
  622. }
  623. X
  624. static void
  625. getpool ()
  626. {
  627. X  register int nu;
  628. X  char * sbrk ();
  629. X  register char *cp = sbrk (0);
  630. X
  631. X  if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  632. X    sbrk (1024 - ((int) cp & 0x3ff));
  633. X
  634. X  /* Record address of start of space allocated by malloc.  */
  635. X  if (_malloc_base == 0)
  636. X    _malloc_base = cp;
  637. X
  638. X  /* Get 2k of storage */
  639. X
  640. X  cp = sbrk (04000);
  641. X  if (cp == (char *) -1)
  642. X    return;
  643. X
  644. X  /* Divide it into an initial 8-word block
  645. X     plus one block of size 2**nu for nu = 3 ... 10.  */
  646. X
  647. X  CHAIN (cp) = nextf[0];
  648. X  nextf[0] = (struct mhead *) cp;
  649. X  ((struct mhead *) cp) -> mh_alloc = ISFREE;
  650. X  ((struct mhead *) cp) -> mh_index = 0;
  651. X  cp += 8;
  652. X
  653. X  for (nu = 0; nu < 7; nu++)
  654. X    {
  655. X      CHAIN (cp) = nextf[nu];
  656. X      nextf[nu] = (struct mhead *) cp;
  657. X      ((struct mhead *) cp) -> mh_alloc = ISFREE;
  658. X      ((struct mhead *) cp) -> mh_index = nu;
  659. X      cp += 8 << nu;
  660. X    }
  661. }
  662. X
  663. char *
  664. malloc (n)        /* get a block */
  665. X     unsigned n;
  666. {
  667. X  register struct mhead *p;
  668. X  register unsigned int nbytes;
  669. X  register int nunits = 0;
  670. X
  671. X  /* Figure out how many bytes are required, rounding up to the nearest
  672. X     multiple of 8, then figure out which nestf[] area to use.
  673. X     Both the beginning of the header and the beginning of the
  674. X     block should be on an eight byte boundary.  */
  675. X  nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
  676. X  {
  677. X    register unsigned int   shiftr = (nbytes - 1) >> 2;
  678. X
  679. X    while (shiftr >>= 1)
  680. X      nunits++;
  681. X  }
  682. X
  683. X  /* In case this is reentrant use of malloc from signal handler,
  684. X     pick a block size that no other malloc level is currently
  685. X     trying to allocate.  That's the easiest harmless way not to
  686. X     interfere with the other level of execution.  */
  687. X  while (busy[nunits]) nunits++;
  688. X  busy[nunits] = 1;
  689. X
  690. X  /* If there are no blocks of the appropriate size, go get some */
  691. X  /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
  692. X  if (nextf[nunits] == 0)
  693. X    morecore (nunits);
  694. X
  695. X  /* Get one block off the list, and set the new list head */
  696. X  if ((p = nextf[nunits]) == 0)
  697. X    {
  698. X      busy[nunits] = 0;
  699. X      return 0;
  700. X    }
  701. X  nextf[nunits] = CHAIN (p);
  702. X  busy[nunits] = 0;
  703. X
  704. X  /* Check for free block clobbered */
  705. X  /* If not for this check, we would gobble a clobbered free chain ptr */
  706. X  /* and bomb out on the NEXT allocate of this size block */
  707. X  if (p -> mh_alloc != ISFREE || p -> mh_index != nunits)
  708. #ifdef rcheck
  709. X    botch ("block on free list clobbered");
  710. #else /* not rcheck */
  711. X    abort ();
  712. #endif /* not rcheck */
  713. X
  714. X  /* Fill in the info, and if range checking, set up the magic numbers */
  715. X  p -> mh_alloc = ISALLOC;
  716. #ifdef rcheck
  717. X  p -> mh_nbytes = n;
  718. X  p -> mh_magic4 = MAGIC4;
  719. X  {
  720. X    /* Get the location n after the beginning of the user's space.  */
  721. X    register char *m = (char *) p + ((sizeof *p + 7) & ~7) + n;
  722. X
  723. X    *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
  724. X  }
  725. #else /* not rcheck */
  726. X  p -> mh_size = n;
  727. #endif /* not rcheck */
  728. #ifdef MSTATS
  729. X  nmalloc[nunits]++;
  730. X  nmal++;
  731. #endif /* MSTATS */
  732. X  return (char *) p + ((sizeof *p + 7) & ~7);
  733. }
  734. X
  735. free (mem)
  736. X     char *mem;
  737. {
  738. X  register struct mhead *p;
  739. X  {
  740. X    register char *ap = mem;
  741. X
  742. X    if (ap == 0)
  743. X      return;
  744. X
  745. X    p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
  746. X    if (p -> mh_alloc == ISMEMALIGN)
  747. X      {
  748. X    ap -= p->mh_size;
  749. X    p = (struct mhead *) (ap - ((sizeof *p + 7) & ~7));
  750. X      }
  751. X
  752. #ifndef rcheck
  753. X    if (p -> mh_alloc != ISALLOC)
  754. X      abort ();
  755. X
  756. #else /* rcheck */
  757. X    if (p -> mh_alloc != ISALLOC)
  758. X      {
  759. X    if (p -> mh_alloc == ISFREE)
  760. X      botch ("free: Called with already freed block argument\n");
  761. X    else
  762. X      botch ("free: Called with bad argument\n");
  763. X      }
  764. X
  765. X    ASSERT (p -> mh_magic4 == MAGIC4);
  766. X    ap += p -> mh_nbytes;
  767. X    ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
  768. X    ASSERT (*ap++ == MAGIC1); ASSERT (*ap   == MAGIC1);
  769. #endif /* rcheck */
  770. X  }
  771. X  {
  772. X    register int nunits = p -> mh_index;
  773. X
  774. X    ASSERT (nunits <= 29);
  775. X    p -> mh_alloc = ISFREE;
  776. X
  777. X    /* Protect against signal handlers calling malloc.  */
  778. X    busy[nunits] = 1;
  779. X    /* Put this block on the free list.  */
  780. X    CHAIN (p) = nextf[nunits];
  781. X    nextf[nunits] = p;
  782. X    busy[nunits] = 0;
  783. X
  784. #ifdef MSTATS
  785. X    nmalloc[nunits]--;
  786. X    nfre++;
  787. #endif /* MSTATS */
  788. X  }
  789. }
  790. X
  791. char *
  792. realloc (mem, n)
  793. X     char *mem;
  794. X     register unsigned n;
  795. {
  796. X  register struct mhead *p;
  797. X  register unsigned int tocopy;
  798. X  register unsigned int nbytes;
  799. X  register int nunits;
  800. X
  801. X  if (mem == 0)
  802. X    return malloc (n);
  803. X  p = (struct mhead *) (mem - ((sizeof *p + 7) & ~7));
  804. X  nunits = p -> mh_index;
  805. X  ASSERT (p -> mh_alloc == ISALLOC);
  806. #ifdef rcheck
  807. X  ASSERT (p -> mh_magic4 == MAGIC4);
  808. X  {
  809. X    register char *m = mem + (tocopy = p -> mh_nbytes);
  810. X    ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
  811. X    ASSERT (*m++ == MAGIC1); ASSERT (*m   == MAGIC1);
  812. X  }
  813. #else /* not rcheck */
  814. X  if (p -> mh_index >= 13)
  815. X    tocopy = (1 << (p -> mh_index + 3)) - ((sizeof *p + 7) & ~7);
  816. X  else
  817. X    tocopy = p -> mh_size;
  818. #endif /* not rcheck */
  819. X
  820. X  /* See if desired size rounds to same power of 2 as actual size. */
  821. X  nbytes = (n + ((sizeof *p + 7) & ~7) + EXTRA + 7) & ~7;
  822. X
  823. X  /* If ok, use the same block, just marking its size as changed.  */
  824. X  if (nbytes > (4 << nunits) && nbytes <= (8 << nunits))
  825. X    {
  826. #ifdef rcheck
  827. X      register char *m = mem + tocopy;
  828. X      *m++ = 0;  *m++ = 0;  *m++ = 0;  *m++ = 0;
  829. X      p-> mh_nbytes = n;
  830. X      m = mem + n;
  831. X      *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;
  832. #else /* not rcheck */
  833. X      p -> mh_size = n;
  834. #endif /* not rcheck */
  835. X      return mem;
  836. X    }
  837. X
  838. X  if (n < tocopy)
  839. X    tocopy = n;
  840. X  {
  841. X    register char *new;
  842. X
  843. X    if ((new = malloc (n)) == 0)
  844. X      return 0;
  845. X    bcopy (mem, new, tocopy);
  846. X    free (mem);
  847. X    return new;
  848. X  }
  849. }
  850. X
  851. #ifndef VMS
  852. X
  853. char *
  854. memalign (alignment, size)
  855. X     unsigned alignment, size;
  856. {
  857. X  register char *ptr = malloc (size + alignment);
  858. X  register char *aligned;
  859. X  register struct mhead *p;
  860. X
  861. X  if (ptr == 0)
  862. X    return 0;
  863. X  /* If entire block has the desired alignment, just accept it.  */
  864. X  if (((int) ptr & (alignment - 1)) == 0)
  865. X    return ptr;
  866. X  /* Otherwise, get address of byte in the block that has that alignment.  */
  867. X  aligned = (char *) (((int) ptr + alignment - 1) & -alignment);
  868. X
  869. X  /* Store a suitable indication of how to free the block,
  870. X     so that free can find the true beginning of it.  */
  871. X  p = (struct mhead *) aligned - 1;
  872. X  p -> mh_size = aligned - ptr;
  873. X  p -> mh_alloc = ISMEMALIGN;
  874. X  return aligned;
  875. }
  876. X
  877. #ifndef HPUX
  878. /* This runs into trouble with getpagesize on HPUX.
  879. X   Patching out seems cleaner than the ugly fix needed.  */
  880. char *
  881. valloc (size)
  882. {
  883. X  return memalign (getpagesize (), size);
  884. }
  885. #endif /* not HPUX */
  886. #endif /* not VMS */
  887. X
  888. #ifdef MSTATS
  889. /* Return statistics describing allocation of blocks of size 2**n. */
  890. X
  891. struct mstats_value
  892. X  {
  893. X    int blocksize;
  894. X    int nfree;
  895. X    int nused;
  896. X  };
  897. X
  898. struct mstats_value
  899. malloc_stats (size)
  900. X     int size;
  901. {
  902. X  struct mstats_value v;
  903. X  register int i;
  904. X  register struct mhead *p;
  905. X
  906. X  v.nfree = 0;
  907. X
  908. X  if (size < 0 || size >= 30)
  909. X    {
  910. X      v.blocksize = 0;
  911. X      v.nused = 0;
  912. X      return v;
  913. X    }
  914. X
  915. X  v.blocksize = 1 << (size + 3);
  916. X  v.nused = nmalloc[size];
  917. X
  918. X  for (p = nextf[size]; p; p = CHAIN (p))
  919. X    v.nfree++;
  920. X
  921. X  return v;
  922. }
  923. int
  924. malloc_mem_used ()
  925. {
  926. X  int i;
  927. X  int size_used;
  928. X
  929. X  size_used = 0;
  930. X  
  931. X  for (i = 0; i < 30; i++)
  932. X    {
  933. X      int allocation_size = 1 << (i + 3);
  934. X      struct mhead *p;
  935. X      
  936. X      size_used += nmalloc[i] * allocation_size;
  937. X    }
  938. X
  939. X  return size_used;
  940. }
  941. X
  942. int 
  943. malloc_mem_free ()
  944. {
  945. X  int i;
  946. X  int size_unused;
  947. X
  948. X  size_unused = 0;
  949. X  
  950. X  for (i = 0; i < 30; i++)
  951. X    {
  952. X      int allocation_size = 1 << (i + 3);
  953. X      struct mhead *p;
  954. X      
  955. X      for (p = nextf[i]; p ; p = CHAIN (p))
  956. X    size_unused += allocation_size;
  957. X    }
  958. X
  959. X  return size_unused;
  960. }
  961. #endif /* MSTATS */
  962. X
  963. /*
  964. X *    This function returns the total number of bytes that the process
  965. X *    will be allowed to allocate via the sbrk(2) system call.  On
  966. X *    BSD systems this is the total space allocatable to stack and
  967. X *    data.  On USG systems this is the data space only.
  968. X */
  969. X
  970. #ifdef USG
  971. X
  972. get_lim_data ()
  973. {
  974. X  extern long ulimit ();
  975. X    
  976. #ifdef ULIMIT_BREAK_VALUE
  977. X  lim_data = ULIMIT_BREAK_VALUE;
  978. #else
  979. X  lim_data = ulimit (3, 0);
  980. #endif
  981. X
  982. X  lim_data -= (long) data_space_start;
  983. }
  984. X
  985. #else /* not USG */
  986. #ifndef BSD4_2
  987. X
  988. get_lim_data ()
  989. {
  990. X  lim_data = vlimit (LIM_DATA, -1);
  991. }
  992. X
  993. #else /* BSD4_2 */
  994. X
  995. get_lim_data ()
  996. {
  997. X  struct rlimit XXrlimit;
  998. X
  999. X  getrlimit (RLIMIT_DATA, &XXrlimit);
  1000. #ifdef RLIM_INFINITY
  1001. X  lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  1002. #else
  1003. X  lim_data = XXrlimit.rlim_cur;    /* soft limit */
  1004. #endif
  1005. }
  1006. X
  1007. #endif /* BSD4_2 */
  1008. #endif /* not USG */
  1009. X
  1010. #ifdef VMS
  1011. /* There is a problem when dumping and restoring things on VMS. Calls
  1012. X * to SBRK don't necessarily result in contiguous allocation. Dumping
  1013. X * doesn't work when it isn't. Therefore, we make the initial
  1014. X * allocation contiguous by allocating a big chunk, and do SBRKs from
  1015. X * there. Once Emacs has dumped there is no reason to continue
  1016. X * contiguous allocation, malloc doesn't depend on it.
  1017. X *
  1018. X * There is a further problem of using brk and sbrk while using VMS C
  1019. X * run time library routines malloc, calloc, etc. The documentation
  1020. X * says that this is a no-no, although I'm not sure why this would be
  1021. X * a problem. In any case, we remove the necessity to call brk and
  1022. X * sbrk, by calling calloc (to assure zero filled data) rather than
  1023. X * sbrk.
  1024. X *
  1025. X * VMS_ALLOCATION_SIZE is the size of the allocation array. This
  1026. X * should be larger than the malloc size before dumping. Making this
  1027. X * too large will result in the startup procedure slowing down since
  1028. X * it will require more space and time to map it in.
  1029. X *
  1030. X * The value for VMS_ALLOCATION_SIZE in the following define was determined
  1031. X * by running emacs linked (and a large allocation) with the debugger and
  1032. X * looking to see how much storage was used. The allocation was 201 pages,
  1033. X * so I rounded it up to a power of two.
  1034. X */
  1035. #ifndef VMS_ALLOCATION_SIZE
  1036. #define VMS_ALLOCATION_SIZE    (512*256)
  1037. #endif
  1038. X
  1039. /* Use VMS RTL definitions */
  1040. #undef sbrk
  1041. #undef brk
  1042. #undef malloc
  1043. int vms_out_initial = 0;
  1044. char vms_initial_buffer[VMS_ALLOCATION_SIZE];
  1045. static char *vms_current_brk = &vms_initial_buffer;
  1046. static char *vms_end_brk = &vms_initial_buffer[VMS_ALLOCATION_SIZE-1];
  1047. X
  1048. #include <stdio.h>
  1049. X
  1050. char *
  1051. sys_sbrk (incr)
  1052. X     int incr;
  1053. {
  1054. X  char *sbrk(), *temp, *ptr;
  1055. X
  1056. X  if (vms_out_initial)
  1057. X    {
  1058. X      /* out of initial allocation... */
  1059. X      if (!(temp = malloc (incr)))
  1060. X    temp = (char *) -1;
  1061. X    }
  1062. X  else
  1063. X    {
  1064. X      /* otherwise, go out of our area */
  1065. X      ptr = vms_current_brk + incr; /* new current_brk */
  1066. X      if (ptr <= vms_end_brk)
  1067. X    {
  1068. X      temp = vms_current_brk;
  1069. X      vms_current_brk = ptr;
  1070. X    }
  1071. X      else
  1072. X    {
  1073. X      vms_out_initial = 1;    /* mark as out of initial allocation */
  1074. X      if (!(temp = malloc (incr)))
  1075. X        temp = (char *) -1;
  1076. X    }
  1077. X    }
  1078. X  return temp;
  1079. }
  1080. #endif /* VMS */
  1081. SHAR_EOF
  1082. chmod 0644 mxgdb/malloc.c ||
  1083. echo 'restore of mxgdb/malloc.c failed'
  1084. Wc_c="`wc -c < 'mxgdb/malloc.c'`"
  1085. test 25023 -eq "$Wc_c" ||
  1086.     echo 'mxgdb/malloc.c: original size 25023, current size' "$Wc_c"
  1087. rm -f _shar_wnt_.tmp
  1088. fi
  1089. # ============= mxgdb/parser.c ==============
  1090. if test -f 'mxgdb/parser.c' -a X"$1" != X"-c"; then
  1091.     echo 'x - skipping mxgdb/parser.c (File already exists)'
  1092.     rm -f _shar_wnt_.tmp
  1093. else
  1094. > _shar_wnt_.tmp
  1095. echo 'x - extracting mxgdb/parser.c (Text)'
  1096. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/parser.c' &&
  1097. static char rcsid[] = "$Id: parser.c,v 1.2 1991/08/23 16:34:40 jtsillas Exp $";
  1098. X
  1099. /*****************************************************************************
  1100. X *
  1101. X *  xdbx - X Window System interface to the dbx debugger
  1102. X *
  1103. X *  Copyright 1989 The University of Texas at Austin
  1104. X *  Copyright 1990 Microelectronics and Computer Technology Corporation
  1105. X *
  1106. X *  Permission to use, copy, modify, and distribute this software and its
  1107. X *  documentation for any purpose and without fee is hereby granted,
  1108. X *  provided that the above copyright notice appear in all copies and that
  1109. X *  both that copyright notice and this permission notice appear in
  1110. X *  supporting documentation, and that the name of The University of Texas
  1111. X *  and Microelectronics and Computer Technology Corporation (MCC) not be 
  1112. X *  used in advertising or publicity pertaining to distribution of
  1113. X *  the software without specific, written prior permission.  The
  1114. X *  University of Texas and MCC makes no representations about the 
  1115. X *  suitability of this software for any purpose.  It is provided "as is" 
  1116. X *  without express or implied warranty.
  1117. X *
  1118. X *  THE UNIVERSITY OF TEXAS AND MCC DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1119. X *  THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1120. X *  FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS OR MCC BE LIABLE FOR
  1121. X *  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1122. X *  RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
  1123. X *  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  1124. X *  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1125. X *
  1126. X *  Author:      Po Cheung
  1127. X *  Created:       March 10, 1989
  1128. X * 
  1129. X *****************************************************************************
  1130. X * 
  1131. X *  xxgdb - X Window System interface to the gdb debugger
  1132. X *  
  1133. X *     Copyright 1990 Thomson Consumer Electronics, Inc.
  1134. X *  
  1135. X *  Permission to use, copy, modify, and distribute this software and its
  1136. X *  documentation for any purpose and without fee is hereby granted,
  1137. X *  provided that the above copyright notice appear in all copies and that
  1138. X *  both that copyright notice and this permission notice appear in
  1139. X *  supporting documentation, and that the name of Thomson Consumer
  1140. X *  Electronics (TCE) not be used in advertising or publicity pertaining
  1141. X *  to distribution of the software without specific, written prior
  1142. X *  permission.  TCE makes no representations about the suitability of
  1143. X *  this software for any purpose.  It is provided "as is" without express
  1144. X *  or implied warranty.
  1145. X *
  1146. X *  TCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1147. X *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  1148. X *  SHALL TCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  1149. X *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1150. X *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1151. X *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1152. X *  SOFTWARE.
  1153. X *
  1154. X *  Adaptation to GDB:  Pierre Willard
  1155. X *  XXGDB Created:       December, 1990
  1156. X *
  1157. X *****************************************************************************/
  1158. X
  1159. /*  parser.c:
  1160. X *
  1161. X *    Parse output messages from dbx using regular expression pattern matching,
  1162. X *    and take appropriate action.
  1163. X *
  1164. X *    compile():    Compile the regular expressions in a table.
  1165. X *    match():        Try to best match a given string with the regular
  1166. X *            expressions found in the table and return an index.
  1167. X *    parser_init():    Initialization.
  1168. X *    parse():        Parse the dbx output and invoke the appropriate action
  1169. X *            handler.
  1170. X *    filter():        Modify the dbx output before it gets displayed on the
  1171. X *            dialog window.
  1172. X *    query_dbx():    Send a query command to dbx and process it.
  1173. X */
  1174. X
  1175. #include    "global.h"
  1176. #include    "regex.h"
  1177. #include    "gdb_regex.h"
  1178. X
  1179. #define BYTEWIDTH       8
  1180. #define RE_BUFFER       100
  1181. X
  1182. Tokens     Token;            /* gloabl token structure */
  1183. Boolean    Parse = True;        /* Parse flag for parse routine */
  1184. X
  1185. /*
  1186. X *  Compile all the regular expression patterns in a pattern table.
  1187. X *  A pattern table is an array of pattern records.
  1188. X *  Each pattern record consists of a regular
  1189. X *  expression, a buffer for the to-be-compiled regular expression,
  1190. X *  and an array to associate a given token with a matched register number.
  1191. X */
  1192. static void compile(patternTable)
  1193. PatternRec *patternTable;
  1194. {
  1195. X    PatternRec    *p;
  1196. X    char     fastmap[(1 << BYTEWIDTH)];
  1197. X    int        i;
  1198. X
  1199. X    for (i=0; patternTable[i].pat; i++) {
  1200. X    p = &patternTable[i];
  1201. X    p->buf = (struct re_pattern_buffer *) 
  1202. X      XtMalloc (sizeof (struct re_pattern_buffer));
  1203. X    p->buf->allocated = RE_BUFFER;
  1204. X    p->buf->buffer = (char *) XtMalloc (p->buf->allocated);
  1205. X    p->buf->fastmap = fastmap;
  1206. X    p->buf->translate = NULL;
  1207. X    re_compile_pattern(p->pat, strlen(p->pat), p->buf);
  1208. X    re_compile_fastmap(p->buf);
  1209. X    }
  1210. X
  1211. /*
  1212. X *  This routine tries to match a given string with each regular 
  1213. X *  expression in a given pattern table.  The best match is found, and
  1214. X *  the function returns an index to the pattern table.
  1215. X */
  1216. int match(patternTable, string, type)
  1217. X    PatternRec     *patternTable;
  1218. X    char     *string;
  1219. X    int        type;
  1220. {
  1221. X    struct re_registers    regs;
  1222. X    int            m, bestmatch = -1, index = -1, i, j, r, start, n;
  1223. X    char         *s;
  1224. X
  1225. X    if (!strcmp(string, "")) return -1;
  1226. X    for (i=0; patternTable[i].pat; i++) {
  1227. X    if (type != C_ANY && type != i)
  1228. X        continue;
  1229. X    m = re_match(patternTable[i].buf, string, strlen(string), 0, ®s);
  1230. X    if (m == -2 ) {        /* match error - failure stack overflow */
  1231. X        fprintf(stderr, "mxgdb error: regular expression matching failed \
  1232. (failure stack overflow)\n");
  1233. X        return (-1);
  1234. X    }
  1235. X    if (m > bestmatch) {
  1236. X        bestmatch = m;
  1237. X        index = i;
  1238. X        /* for GDB, free memory (if not done earlier) */
  1239. X        XtFree(Token.mesg);
  1240. X        XtFree(Token.file);
  1241. X        XtFree(Token.func);
  1242. X        XtFree(Token.display);
  1243. X        Token.mesg = Token.file = Token.func = Token.display = NULL;
  1244. X        Token.line = Token.stop = 0;
  1245. X        for (j=0; j<NTOKENS; j++) {
  1246. X        if ((r = patternTable[i].reg_token[j]) >= 0) {
  1247. X            start = regs.start[r];
  1248. X            if ((n = regs.end[r] - start) > 0) {
  1249. X        /* The following error could happen if the pattern table is not correct,
  1250. X        better test it here.. */
  1251. X        
  1252. X            if ( n > strlen(string))    /* Something is wrong here ! */
  1253. X                {
  1254. X                fprintf(stderr,"Error match() : n = %d is too big\n",n);
  1255. X                n = 0;
  1256. X                }
  1257. X            s = (char *) XtMalloc ((n+1) * sizeof(char));
  1258. X            strncpy(s, string+start, n);
  1259. X            s[n] = '\0';
  1260. X                switch (j) {
  1261. X              case TK_MESG: Token.mesg = s; break;
  1262. X              case TK_STOP: Token.stop = atoi(s); XtFree(s); break;
  1263. X              case TK_FUNC: Token.func = s; break;
  1264. X              case TK_LINE: Token.line = atoi(s); XtFree(s); break;
  1265. X              case TK_FILE: Token.file = s; break;
  1266. X              case TK_DISP: Token.display = s; break;
  1267. X                }
  1268. X            }
  1269. X        }
  1270. X        }
  1271. X    }
  1272. X    }
  1273. X    return index;
  1274. }
  1275. X
  1276. /*  Compile the regular expressions in the output and command pattern tables. */
  1277. X
  1278. void parser_init()
  1279. {
  1280. X    compile(output_pattern);
  1281. X    compile(command_pattern);
  1282. }
  1283. X
  1284. #include "gdb_parser.c"
  1285. X
  1286. SHAR_EOF
  1287. chmod 0664 mxgdb/parser.c ||
  1288. echo 'restore of mxgdb/parser.c failed'
  1289. Wc_c="`wc -c < 'mxgdb/parser.c'`"
  1290. test 6984 -eq "$Wc_c" ||
  1291.     echo 'mxgdb/parser.c: original size 6984, current size' "$Wc_c"
  1292. rm -f _shar_wnt_.tmp
  1293. fi
  1294. # ============= mxgdb/regex.c ==============
  1295. if test -f 'mxgdb/regex.c' -a X"$1" != X"-c"; then
  1296.     echo 'x - skipping mxgdb/regex.c (File already exists)'
  1297.     rm -f _shar_wnt_.tmp
  1298. else
  1299. > _shar_wnt_.tmp
  1300. echo 'x - extracting mxgdb/regex.c (Text)'
  1301. sed 's/^X//' << 'SHAR_EOF' > 'mxgdb/regex.c' &&
  1302. static char rcsid[] = "$Id: regex.c,v 1.1.1.1 1991/05/16 21:42:37 jtsillas Exp $";
  1303. X
  1304. /* Extended regular expression matching and search.
  1305. X   Copyright (C) 1985 Free Software Foundation, Inc.
  1306. X
  1307. X               NO WARRANTY
  1308. X
  1309. SHAR_EOF
  1310. true || echo 'restore of mxgdb/regex.c failed'
  1311. fi
  1312. echo 'End of  part 6'
  1313. echo 'File mxgdb/regex.c is continued in part 7'
  1314. echo 7 > _shar_seq_.tmp
  1315. exit 0
  1316.