aboutsummaryrefslogtreecommitdiff
path: root/gdb/mac-xdep.c
blob: 856591a949ce89c4d9ac8bbe2262ce9fa0a6bb97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
/* Top level support for Mac interface to GDB, the GNU debugger.
   Copyright 1994, 2001 Free Software Foundation, Inc.
   Contributed by Cygnus Support.  Written by Stan Shebs.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#include "defs.h"

#include <readline/readline.h>
#include <readline/history.h>

#include <Types.h>
#include <Resources.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <Events.h>
#include <Windows.h>
#include <Menus.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Desk.h>
#include <ToolUtils.h>
#include <Memory.h>
#include <SegLoad.h>
#include <Files.h>
#include <Folders.h>
#include <OSUtils.h>
#include <OSEvents.h>
#include <DiskInit.h>
#include <Packages.h>
#include <Traps.h>
#include <Lists.h>
#include <Gestalt.h>
#include <PPCToolbox.h>
#include <AppleEvents.h>
#include <StandardFile.h>
#include <Sound.h>

#ifdef MPW
#define QD(whatever) (qd.##whatever)
#define QDPat(whatever) (&(qd.##whatever))
#endif /* MPW */

#ifdef THINK_C
#define QD(whatever) (whatever)
#endif

#define p2c(pstr,cbuf)  \
  strncpy(cbuf, ((char *) (pstr) + 1), pstr[0]);  \
  cbuf[pstr[0]] = '\0';

#define pascalify(STR) \
  sprintf(tmpbuf, " %s", STR);  \
  tmpbuf[0] = strlen(STR);

#include "gdbcmd.h"
#include "call-cmds.h"
#include "symtab.h"
#include "inferior.h"
#include <signal.h>
#include "target.h"
#include "breakpoint.h"
#include "gdbtypes.h"
#include "expression.h"
#include "language.h"

#include "mac-defs.h"

int debug_openp = 0;

/* This is true if we are running as a standalone application.  */

int mac_app;

/* This is true if we are using WaitNextEvent.  */

int use_wne;

/* This is true if we have Color Quickdraw.  */

int has_color_qd;

/* This is true if we are using Color Quickdraw. */

int use_color_qd;

int inbackground;

Rect dragrect =
{-32000, -32000, 32000, 32000};
Rect sizerect;

int sbarwid = 15;

/* Globals for the console window. */

WindowPtr console_window;

ControlHandle console_v_scrollbar;

Rect console_v_scroll_rect;

TEHandle console_text;

Rect console_text_rect;

/* This will go away eventually. */
gdb_has_a_terminal (void)
{
  return 1;
}

mac_init (void)
{
  SysEnvRec se;
  int eventloopdone = 0;
  char *str;
  Boolean gotevent;
  Point mouse;
  EventRecord event;
  WindowPtr win;
  RgnHandle cursorRgn;
  int i;
  Handle menubar;
  MenuHandle menu;
  Handle siow_resource;

  mac_app = 0;

  str = getenv ("DEBUG_GDB");
  if (str != NULL && str[0] != '\0')
    {
      if (strcmp (str, "openp") == 0)
	debug_openp = 1;
    }

  /* Don't do anything if we`re running under MPW. */
  if (!StandAlone)
    return;

  /* Don't do anything if we're using SIOW. */
  /* This test requires that the siow 0 resource, as defined in
     {RIncludes}siow.r, not be messed with.  If it is, then the
     standard Mac setup below will step on SIOW's Mac setup and
     most likely crash the machine. */
  siow_resource = GetResource ('siow', 0);
  if (siow_resource != nil)
    return;

  mac_app = 1;

  /* Do the standard Mac environment setup. */
  InitGraf (&QD (thePort));
  InitFonts ();
  FlushEvents (everyEvent, 0);
  InitWindows ();
  InitMenus ();
  TEInit ();
  InitDialogs (NULL);
  InitCursor ();

  /* Color Quickdraw is different from Classic QD. */
  SysEnvirons (2, &se);
  has_color_qd = se.hasColorQD;
  /* Use it if we got it. */
  use_color_qd = has_color_qd;

  sizerect.top = 50;
  sizerect.left = 50;
  sizerect.bottom = 1000;
  sizerect.right = 1000;
#if 0
  sizerect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
  sizerect.right = screenBits.bounds.right - screenBits.bounds.left;
#endif

  /* Set up the menus. */
  menubar = GetNewMBar (mbMain);
  SetMenuBar (menubar);
  /* Add the DAs etc as usual. */
  menu = GetMHandle (mApple);
  if (menu != nil)
    {
      AddResMenu (menu, 'DRVR');
    }
  DrawMenuBar ();

  new_console_window ();
}

new_console_window (void)
{
  /* Create the main window we're going to play in. */
  if (has_color_qd)
    console_window = GetNewCWindow (wConsole, NULL, (WindowPtr) - 1L);
  else
    console_window = GetNewWindow (wConsole, NULL, (WindowPtr) - 1L);

  SetPort (console_window);
  console_text_rect = console_window->portRect;
  /* Leave 8 pixels of blank space, for aesthetic reasons and to
     make it easier to select from the beginning of a line. */
  console_text_rect.left += 8;
  console_text_rect.bottom -= sbarwid - 1;
  console_text_rect.right -= sbarwid - 1;
  console_text = TENew (&console_text_rect, &console_text_rect);
  TESetSelect (0, 40000, console_text);
  TEDelete (console_text);
  TEAutoView (1, console_text);

  console_v_scroll_rect = console_window->portRect;
  console_v_scroll_rect.bottom -= sbarwid - 1;
  console_v_scroll_rect.left = console_v_scroll_rect.right - sbarwid;
  console_v_scrollbar =
    NewControl (console_window, &console_v_scroll_rect,
		"\p", 1, 0, 0, 0, scrollBarProc, 0L);

  ShowWindow (console_window);
  SelectWindow (console_window);
}

mac_command_loop (void)
{
  SysEnvRec se;
  int eventloopdone = 0;
  Boolean gotevent;
  Point mouse;
  EventRecord event;
  WindowPtr win;
  RgnHandle cursorRgn;
  int i, tm;
  Handle menubar;
  MenuHandle menu;

  /* Figure out if the WaitNextEvent Trap is available.  */
  use_wne =
    (NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9f, ToolTrap));
  /* Pass WaitNextEvent an empty region the first time through.  */
  cursorRgn = NewRgn ();
  /* Go into the main event-handling loop.  */
  while (!eventloopdone)
    {
      /* Use WaitNextEvent if it is available, otherwise GetNextEvent.  */
      if (use_wne)
	{
	  get_global_mouse (&mouse);
	  adjust_cursor (mouse, cursorRgn);
	  tm = GetCaretTime ();
	  gotevent = WaitNextEvent (everyEvent, &event, tm, cursorRgn);
	}
      else
	{
	  SystemTask ();
	  gotevent = GetNextEvent (everyEvent, &event);
	}
      /* First decide if the event is for a dialog or is just any old event. */
      if (FrontWindow () != nil && IsDialogEvent (&event))
	{
	  short itemhit;
	  DialogPtr dialog;

	  /* Handle all the modeless dialogs here. */
	  if (DialogSelect (&event, &dialog, &itemhit))
	    {
	    }
	}
      else if (gotevent)
	{
	  /* Make sure we have the right cursor before handling the event. */
	  adjust_cursor (event.where, cursorRgn);
	  do_event (&event);
	}
      else
	{
	  do_idle ();
	}
    }
}

/* Collect the global coordinates of the mouse pointer.  */

get_global_mouse (Point *mouse)
{
  EventRecord evt;

  OSEventAvail (0, &evt);
  *mouse = evt.where;
}

/* Change the cursor's appearance to be appropriate for the given mouse
   location.  */

adjust_cursor (Point mouse, RgnHandle region)
{
}

/* Decipher an event, maybe do something with it.  */

do_event (EventRecord *evt)
{
  short part, err, rslt = 0;
  WindowPtr win;
  Boolean hit;
  char key;
  Point pnt;

  switch (evt->what)
    {
    case mouseDown:
      /* See if the click happened in a special part of the screen. */
      part = FindWindow (evt->where, &win);
      switch (part)
	{
	case inMenuBar:
	  adjust_menus ();
	  do_menu_command (MenuSelect (evt->where));
	  break;
	case inSysWindow:
	  SystemClick (evt, win);
	  break;
	case inContent:
	  if (win != FrontWindow ())
	    {
	      /* Bring the clicked-on window to the front. */
	      SelectWindow (win);
	      /* Fix the menu to match the new front window. */
	      adjust_menus ();
	      /* We always want to discard the event now, since clicks in a
	         windows are often irreversible actions. */
	    }
	  else
	    /* Mouse clicks in the front window do something useful. */
	    do_mouse_down (win, evt);
	  break;
	case inDrag:
	  /* Standard drag behavior, no tricks necessary. */
	  DragWindow (win, evt->where, &dragrect);
	  break;
	case inGrow:
	  grow_window (win, evt->where);
	  break;
	case inZoomIn:
	case inZoomOut:
	  zoom_window (win, evt->where, part);
	  break;
	case inGoAway:
	  close_window (win);
	  break;
	}
      break;
    case keyDown:
    case autoKey:
      key = evt->message & charCodeMask;
      /* Check for menukey equivalents. */
      if (evt->modifiers & cmdKey)
	{
	  if (evt->what == keyDown)
	    {
	      adjust_menus ();
	      do_menu_command (MenuKey (key));
	    }
	}
      else
	{
	  if (evt->what == keyDown)
	    {
	      /* Random keypress, interpret it. */
	      do_keyboard_command (key);
	    }
	}
      break;
    case activateEvt:
      activate_window ((WindowPtr) evt->message, evt->modifiers & activeFlag);
      break;
    case updateEvt:
      update_window ((WindowPtr) evt->message);
      break;
    case diskEvt:
      /* Call DIBadMount in response to a diskEvt, so that the user can format
         a floppy. (from DTS Sample) */
      if (HiWord (evt->message) != noErr)
	{
	  SetPt (&pnt, 50, 50);
	  err = DIBadMount (pnt, evt->message);
	}
      break;
    case app4Evt:
      /* Grab only a single byte. */
      switch ((evt->message >> 24) & 0xFF)
	{
	case 0xfa:
	  break;
	case 1:
	  inbackground = !(evt->message & 1);
	  activate_window (FrontWindow (), !inbackground);
	  break;
	}
      break;
    case kHighLevelEvent:
      AEProcessAppleEvent (evt);
      break;
    case nullEvent:
      do_idle ();
      rslt = 1;
      break;
    default:
      break;
    }
  return rslt;
}

/* Do any idle-time activities. */

do_idle (void)
{
  TEIdle (console_text);
}

grow_window (WindowPtr win, Point where)
{
  long winsize;
  int h, v;
  GrafPtr oldport;

  winsize = GrowWindow (win, where, &sizerect);
  /* Only do anything if it actually changed size. */
  if (winsize != 0)
    {
      GetPort (&oldport);
      SetPort (win);
      if (win == console_window)
	{
	  EraseRect (&win->portRect);
	  h = LoWord (winsize);
	  v = HiWord (winsize);
	  SizeWindow (win, h, v, 1);
	  resize_console_window ();
	}
      SetPort (oldport);
    }
}

zoom_window (WindowPtr win, Point where, short part)
{
  ZoomWindow (win, part, (win == FrontWindow ()));
  if (win == console_window)
    {
      resize_console_window ();
    }
}

resize_console_window (void)
{
  adjust_console_sizes ();
  adjust_console_scrollbars ();
  adjust_console_text ();
  InvalRect (&console_window->portRect);
}

close_window (WindowPtr win)
{
}

pascal void
v_scroll_proc (ControlHandle control, short part)
{
  int oldval, amount = 0, newval;
  int pagesize = ((*console_text)->viewRect.bottom - (*console_text)->viewRect.top) / (*console_text)->lineHeight;
  if (part)
    {
      oldval = GetCtlValue (control);
      switch (part)
	{
	case inUpButton:
	  amount = 1;
	  break;
	case inDownButton:
	  amount = -1;
	  break;
	case inPageUp:
	  amount = pagesize;
	  break;
	case inPageDown:
	  amount = -pagesize;
	  break;
	default:
	  /* (should freak out) */
	  break;
	}
      SetCtlValue (control, oldval - amount);
      newval = GetCtlValue (control);
      amount = oldval - newval;
      if (amount)
	TEScroll (0, amount * (*console_text)->lineHeight, console_text);
    }
}

do_mouse_down (WindowPtr win, EventRecord * event)
{
  short part, value;
  Point mouse;
  ControlHandle control;

  if (1 /*is_app_window(win) */ )
    {
      SetPort (win);
      mouse = event->where;
      GlobalToLocal (&mouse);
      part = FindControl (mouse, win, &control);
      if (control == console_v_scrollbar)
	{
	  switch (part)
	    {
	    case inThumb:
	      value = GetCtlValue (control);
	      part = TrackControl (control, mouse, nil);
	      if (part)
		{
		  value -= GetCtlValue (control);
		  if (value)
		    TEScroll (0, value * (*console_text)->lineHeight,
			      console_text);
		}
	      break;
	    default:
#if 0				/* don't deal with right now */
#if 1				/* universal headers */
	      value = TrackControl (control, mouse, (ControlActionUPP) v_scroll_proc);
#else
	      value = TrackControl (control, mouse, (ProcPtr) v_scroll_proc);
#endif
#endif
	      break;
	    }
	}
      else
	{
	  TEClick (mouse, 0, console_text);
	}
    }
}

scroll_text (int hlines, int vlines)
{
}

activate_window (WindowPtr win, int activate)
{
  Rect grow_rect;

  if (win == nil)
    return;
  /* It's convenient to make the activated window also be the
     current GrafPort. */
  if (activate)
    SetPort (win);
  /* Activate the console window's scrollbar. */
  if (win == console_window)
    {
      if (activate)
	{
	  TEActivate (console_text);
	  /* Cause the grow icon to be redrawn at the next update. */
	  grow_rect = console_window->portRect;
	  grow_rect.top = grow_rect.bottom - sbarwid;
	  grow_rect.left = grow_rect.right - sbarwid;
	  InvalRect (&grow_rect);
	}
      else
	{
	  TEDeactivate (console_text);
	  DrawGrowIcon (console_window);
	}
      HiliteControl (console_v_scrollbar, (activate ? 0 : 255));
    }
}

update_window (WindowPtr win)
{
  int controls = 1, growbox = 0;
  GrafPtr oldport;

  /* Set the updating window to be the current grafport. */
  GetPort (&oldport);
  SetPort (win);
/*  recalc_depths();  */
  BeginUpdate (win);
  if (win == console_window)
    {
      draw_console ();
      controls = 1;
      growbox = 1;
    }
  if (controls)
    UpdateControls (win, win->visRgn);
  if (growbox)
    DrawGrowIcon (win);
  EndUpdate (win);
  SetPort (oldport);
}

adjust_menus (void)
{
}

do_menu_command (long which)
{
  short menuid, menuitem;
  short itemHit;
  Str255 daname;
  short daRefNum;
  Boolean handledbyda;
  WindowPtr win;
  short ditem;
  int i;
  char cmdbuf[300];

  cmdbuf[0] = '\0';
  menuid = HiWord (which);
  menuitem = LoWord (which);
  switch (menuid)
    {
    case mApple:
      switch (menuitem)
	{
	case miAbout:
	  Alert (128, nil);
	  break;
#if 0
	case miHelp:
	  /* (should pop up help info) */
	  break;
#endif
	default:
	  GetItem (GetMHandle (mApple), menuitem, daname);
	  daRefNum = OpenDeskAcc (daname);
	}
      break;
    case mFile:
      switch (menuitem)
	{
	case miFileNew:
	  if (console_window == FrontWindow ())
	    {
	      close_window (console_window);
	    }
	  new_console_window ();
	  break;
	case miFileOpen:
	  SysBeep (20);
	  break;
	case miFileQuit:
	  ExitToShell ();
	  break;
	}
      break;
    case mEdit:
      /* handledbyda = SystemEdit(menuitem-1); */
      switch (menuitem)
	{
	case miEditCut:
	  TECut (console_text);
	  break;
	case miEditCopy:
	  TECopy (console_text);
	  break;
	case miEditPaste:
	  TEPaste (console_text);
	  break;
	case miEditClear:
	  TEDelete (console_text);
	  break;
	}
      /* All of these operations need the same postprocessing. */
      adjust_console_sizes ();
      adjust_console_scrollbars ();
      adjust_console_text ();
      break;
    case mDebug:
      switch (menuitem)
	{
	case miDebugTarget:
	  sprintf (cmdbuf, "target %s", "remote");
	  break;
	case miDebugRun:
	  sprintf (cmdbuf, "run");
	  break;
	case miDebugContinue:
	  sprintf (cmdbuf, "continue");
	  break;
	case miDebugStep:
	  sprintf (cmdbuf, "step");
	  break;
	case miDebugNext:
	  sprintf (cmdbuf, "next");
	  break;
	}
      break;
    }
  HiliteMenu (0);
  /* Execute a command if one had been given.  Do here because a command
     may longjmp before we get a chance to unhilite the menu. */
  if (strlen (cmdbuf) > 0)
    execute_command (cmdbuf, 0);
}

char commandbuf[1000];

do_keyboard_command (int key)
{
  int startpos, endpos, i, len;
  char *last_newline;
  char buf[10], *text_str, *command, *cmd_start;
  CharsHandle text;

  if (key == '\015' || key == '\003')
    {
      text = TEGetText (console_text);
      HLock ((Handle) text);
      text_str = *text;
      startpos = (*console_text)->selStart;
      endpos = (*console_text)->selEnd;
      if (startpos != endpos)
	{
	  len = endpos - startpos;
	  cmd_start = text_str + startpos;
	}
      else
	{
	  for (i = startpos - 1; i >= 0; --i)
	    if (text_str[i] == '\015')
	      break;
	  last_newline = text_str + i;
	  len = (text_str + startpos) - 1 - last_newline;
	  cmd_start = last_newline + 1;
	}
      if (len > 1000)
	len = 999;
      if (len < 0)
	len = 0;
      strncpy (commandbuf + 1, cmd_start, len);
      commandbuf[1 + len] = 0;
      command = commandbuf + 1;
      HUnlock ((Handle) text);
      commandbuf[0] = strlen (command);

      /* Insert a newline and recalculate before doing any command. */
      key = '\015';
      TEKey (key, console_text);
      TEInsert (buf, 1, console_text);
      adjust_console_sizes ();
      adjust_console_scrollbars ();
      adjust_console_text ();

      if (strlen (command) > 0)
	{
	  execute_command (command, 0);
	  bpstat_do_actions (&stop_bpstat);
	}
    }
  else
    {
      /* A self-inserting character.  This includes delete.  */
      TEKey (key, console_text);
    }
}

/* Draw all graphical stuff in the console window.  */

draw_console (void)
{
  SetPort (console_window);
  TEUpdate (&(console_window->portRect), console_text);
}

/* Cause an update of a given window's entire contents.  */

force_update (WindowPtr win)
{
  GrafPtr oldport;

  if (win == nil)
    return;
  GetPort (&oldport);
  SetPort (win);
  EraseRect (&win->portRect);
  InvalRect (&win->portRect);
  SetPort (oldport);
}

adjust_console_sizes (void)
{
  Rect tmprect;

  tmprect = console_window->portRect;
  /* Move and size the scrollbar. */
  MoveControl (console_v_scrollbar, tmprect.right - sbarwid, 0);
  SizeControl (console_v_scrollbar, sbarwid + 1, tmprect.bottom - sbarwid + 1);
  /* Move and size the text. */
  tmprect.left += 7;
  tmprect.right -= sbarwid;
  tmprect.bottom -= sbarwid;
  InsetRect (&tmprect, 1, 1);
  (*console_text)->destRect = tmprect;
  /* Fiddle bottom of viewrect to be even multiple of text lines. */
  tmprect.bottom = tmprect.top
    + ((tmprect.bottom - tmprect.top) / (*console_text)->lineHeight)
    * (*console_text)->lineHeight;
  (*console_text)->viewRect = tmprect;
}

adjust_console_scrollbars (void)
{
  int lines, newmax, value;

  (*console_v_scrollbar)->contrlVis = 0;
  lines = (*console_text)->nLines;
  newmax = lines - (((*console_text)->viewRect.bottom
		     - (*console_text)->viewRect.top)
		    / (*console_text)->lineHeight);
  if (newmax < 0)
    newmax = 0;
  SetCtlMax (console_v_scrollbar, newmax);
  value = ((*console_text)->viewRect.top - (*console_text)->destRect.top)
    / (*console_text)->lineHeight;
  SetCtlValue (console_v_scrollbar, value);
  (*console_v_scrollbar)->contrlVis = 0xff;
  ShowControl (console_v_scrollbar);
}

/* Scroll the TE record so that it is consistent with the scrollbar(s). */

adjust_console_text (void)
{
  TEScroll (((*console_text)->viewRect.left
	     - (*console_text)->destRect.left)
	    - 0 /* get h scroll value */ ,
	    ((((*console_text)->viewRect.top - (*console_text)->destRect.top)
	      / (*console_text)->lineHeight)
	     - GetCtlValue (console_v_scrollbar))
	    * (*console_text)->lineHeight,
	    console_text);
}

/* Readline substitute. */

char *
readline (char *prrompt)
{
  return gdb_readline (prrompt);
}

char *rl_completer_word_break_characters;

char *rl_completer_quote_characters;

int (*rl_completion_entry_function) ();

int rl_point;

char *rl_line_buffer;

char *rl_readline_name;

/* History substitute. */

void
add_history (char *buf)
{
}

void
stifle_history (int n)
{
}

int
unstifle_history (void)
{
}

int
read_history (char *name)
{
}

int
write_history (char *name)
{
}

int
history_expand (char *x, char **y)
{
}

extern HIST_ENTRY *
history_get (int xxx)
{
  return NULL;
}

int history_base;

char *
filename_completion_function (char *text, char *name)
{
  return "?";
}

char *
tilde_expand (char *str)
{
  return xstrdup (str);
}

/* Modified versions of standard I/O. */

#undef fprintf

int
hacked_fprintf (FILE * fp, const char *fmt,...)
{
  int ret;
  va_list ap;

  va_start (ap, fmt);
  if (mac_app && (fp == stdout || fp == stderr))
    {
      char buf[1000];

      ret = vsprintf (buf, fmt, ap);
      TEInsert (buf, strlen (buf), console_text);
    }
  else
    ret = vfprintf (fp, fmt, ap);
  va_end (ap);
  return ret;
}

#undef printf

int
hacked_printf (const char *fmt,...)
{
  int ret;
  va_list ap;

  va_start (ap, fmt);
  ret = hacked_vfprintf (stdout, fmt, ap);
  va_end (ap);
  return ret;
}

#undef vfprintf

int
hacked_vfprintf (FILE * fp, const char *format, va_list args)
{
  if (mac_app && (fp == stdout || fp == stderr))
    {
      char buf[1000];
      int ret;

      ret = vsprintf (buf, format, args);
      TEInsert (buf, strlen (buf), console_text);
      if (strchr (buf, '\n'))
	{
	  adjust_console_sizes ();
	  adjust_console_scrollbars ();
	  adjust_console_text ();
	}
      return ret;
    }
  else
    return vfprintf (fp, format, args);
}

#undef fputs

hacked_fputs (const char *s, FILE * fp)
{
  if (mac_app && (fp == stdout || fp == stderr))
    {
      TEInsert (s, strlen (s), console_text);
      if (strchr (s, '\n'))
	{
	  adjust_console_sizes ();
	  adjust_console_scrollbars ();
	  adjust_console_text ();
	}
      return 0;
    }
  else
    return fputs (s, fp);
}

#undef fputc

hacked_fputc (const char c, FILE * fp)
{
  if (mac_app && (fp == stdout || fp == stderr))
    {
      char buf[1];

      buf[0] = c;
      TEInsert (buf, 1, console_text);
      if (c == '\n')
	{
	  adjust_console_sizes ();
	  adjust_console_scrollbars ();
	  adjust_console_text ();
	}
      return c;
    }
  else
    return fputc (c, fp);
}

#undef putc

hacked_putc (const char c, FILE * fp)
{
  if (mac_app && (fp == stdout || fp == stderr))
    {
      char buf[1];

      buf[0] = c;
      TEInsert (buf, 1, console_text);
      if (c == '\n')
	{
	  adjust_console_sizes ();
	  adjust_console_scrollbars ();
	  adjust_console_text ();
	}
      return c;
    }
  else
    return fputc (c, fp);
}

#undef fflush

hacked_fflush (FILE * fp)
{
  if (mac_app && (fp == stdout || fp == stderr))
    {
      adjust_console_sizes ();
      adjust_console_scrollbars ();
      adjust_console_text ();
      return 0;
    }
  return fflush (fp);
}

#undef fgetc

hacked_fgetc (FILE * fp)
{
  if (mac_app && (fp == stdin))
    {
      /* Catch any attempts to use this.  */
      DebugStr ("\pShould not be reading from stdin!");
      return '\n';
    }
  return fgetc (fp);
}