OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [gdb/] [tui/] [tuiLayout.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
/* TUI layout window management.
2
 
3
   Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4
   Inc.
5
 
6
   Contributed by Hewlett-Packard Company.
7
 
8
   This file is part of GDB.
9
 
10
   This program is free software; you can redistribute it and/or modify
11
   it under the terms of the GNU General Public License as published by
12
   the Free Software Foundation; either version 2 of the License, or
13
   (at your option) any later version.
14
 
15
   This program is distributed in the hope that it will be useful,
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
   GNU General Public License for more details.
19
 
20
   You should have received a copy of the GNU General Public License
21
   along with this program; if not, write to the Free Software
22
   Foundation, Inc., 59 Temple Place - Suite 330,
23
   Boston, MA 02111-1307, USA.  */
24
 
25
/* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26
   "defs.h" should be included first.  Unfortunatly some systems
27
   (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28
   and they clash with "bfd.h"'s definiton of true/false.  The correct
29
   fix is to remove true/false from "bfd.h", however, until that
30
   happens, hack around it by including "config.h" and <curses.h>
31
   first.  */
32
 
33
#include "config.h"
34
#ifdef HAVE_NCURSES_H       
35
#include <ncurses.h>
36
#else
37
#ifdef HAVE_CURSES_H
38
#include <curses.h>
39
#endif
40
#endif
41
 
42
#include "defs.h"
43
#include "command.h"
44
#include "symtab.h"
45
#include "frame.h"
46
#include <ctype.h>
47
 
48
#include "tui.h"
49
#include "tuiData.h"
50
#include "tuiDataWin.h"
51
#include "tuiGeneralWin.h"
52
#include "tuiStack.h"
53
#include "tuiRegs.h"
54
#include "tuiWin.h"
55
#include "tuiSourceWin.h"
56
#include "tuiDisassem.h"
57
 
58
/*******************************
59
** Static Local Decls
60
********************************/
61
static void showLayout (TuiLayoutType);
62
static void _initGenWinInfo (TuiGenWinInfoPtr, TuiWinType, int, int, int, int);
63
static void _initAndMakeWin (Opaque *, TuiWinType, int, int, int, int, int);
64
static void _showSourceOrDisassemAndCommand (TuiLayoutType);
65
static void _makeSourceOrDisassemWindow (TuiWinInfoPtr *, TuiWinType, int, int);
66
static void _makeCommandWindow (TuiWinInfoPtr *, int, int);
67
static void _makeSourceWindow (TuiWinInfoPtr *, int, int);
68
static void _makeDisassemWindow (TuiWinInfoPtr *, int, int);
69
static void _makeDataWindow (TuiWinInfoPtr *, int, int);
70
static void _showSourceCommand (void);
71
static void _showDisassemCommand (void);
72
static void _showSourceDisassemCommand (void);
73
static void _showData (TuiLayoutType);
74
static TuiLayoutType _nextLayout (void);
75
static TuiLayoutType _prevLayout (void);
76
static void _tuiLayout_command (char *, int);
77
static void _tuiToggleLayout_command (char *, int);
78
static void _tuiToggleSplitLayout_command (char *, int);
79
static CORE_ADDR _extractDisplayStartAddr (void);
80
static void _tuiHandleXDBLayout (TuiLayoutDefPtr);
81
 
82
 
83
/***************************************
84
** DEFINITIONS
85
***************************************/
86
 
87
#define LAYOUT_USAGE     "Usage: layout prev | next | <layout_name> \n"
88
 
89
/* Show the screen layout defined.  */
90
static void
91
showLayout (TuiLayoutType layout)
92
{
93
  TuiLayoutType curLayout = currentLayout ();
94
 
95
  if (layout != curLayout)
96
    {
97
      /*
98
         ** Since the new layout may cause changes in window size, we
99
         ** should free the content and reallocate on next display of
100
         ** source/asm
101
       */
102
      freeAllSourceWinsContent ();
103
      clearSourceWindows ();
104
      if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
105
        {
106
          _showData (layout);
107
          refreshAll (winList);
108
        }
109
      else
110
        {
111
          /* First make the current layout be invisible */
112
          m_allBeInvisible ();
113
          m_beInvisible (locatorWinInfoPtr ());
114
 
115
          switch (layout)
116
            {
117
              /* Now show the new layout */
118
            case SRC_COMMAND:
119
              _showSourceCommand ();
120
              addToSourceWindows (srcWin);
121
              break;
122
            case DISASSEM_COMMAND:
123
              _showDisassemCommand ();
124
              addToSourceWindows (disassemWin);
125
              break;
126
            case SRC_DISASSEM_COMMAND:
127
              _showSourceDisassemCommand ();
128
              addToSourceWindows (srcWin);
129
              addToSourceWindows (disassemWin);
130
              break;
131
            default:
132
              break;
133
            }
134
        }
135
    }
136
}
137
 
138
 
139
/*
140
   ** tuiSetLayout()
141
   **    Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
142
   **    SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
143
   **    If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
144
   **    UNDEFINED_LAYOUT, then the data window is populated according
145
   **    to regsDisplayType.
146
 */
147
TuiStatus
148
tuiSetLayout (TuiLayoutType layoutType,
149
              TuiRegisterDisplayType regsDisplayType)
150
{
151
  TuiStatus status = TUI_SUCCESS;
152
 
153
  if (layoutType != UNDEFINED_LAYOUT || regsDisplayType != TUI_UNDEFINED_REGS)
154
    {
155
      TuiLayoutType curLayout = currentLayout (), newLayout = UNDEFINED_LAYOUT;
156
      int regsPopulate = FALSE;
157
      CORE_ADDR addr = _extractDisplayStartAddr ();
158
      TuiWinInfoPtr newWinWithFocus = (TuiWinInfoPtr) NULL, winWithFocus = tuiWinWithFocus ();
159
      TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
160
 
161
 
162
      if (layoutType == UNDEFINED_LAYOUT &&
163
          regsDisplayType != TUI_UNDEFINED_REGS)
164
        {
165
          if (curLayout == SRC_DISASSEM_COMMAND)
166
            newLayout = DISASSEM_DATA_COMMAND;
167
          else if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
168
            newLayout = SRC_DATA_COMMAND;
169
          else if (curLayout == DISASSEM_COMMAND ||
170
                   curLayout == DISASSEM_DATA_COMMAND)
171
            newLayout = DISASSEM_DATA_COMMAND;
172
        }
173
      else
174
        newLayout = layoutType;
175
 
176
      regsPopulate = (newLayout == SRC_DATA_COMMAND ||
177
                      newLayout == DISASSEM_DATA_COMMAND ||
178
                      regsDisplayType != TUI_UNDEFINED_REGS);
179
      if (newLayout != curLayout || regsDisplayType != TUI_UNDEFINED_REGS)
180
        {
181
          if (newLayout != curLayout)
182
            {
183
              showLayout (newLayout);
184
              /*
185
                 ** Now determine where focus should be
186
               */
187
              if (winWithFocus != cmdWin)
188
                {
189
                  switch (newLayout)
190
                    {
191
                    case SRC_COMMAND:
192
                      tuiSetWinFocusTo (srcWin);
193
                      layoutDef->displayMode = SRC_WIN;
194
                      layoutDef->split = FALSE;
195
                      break;
196
                    case DISASSEM_COMMAND:
197
                      /* the previous layout was not showing
198
                         ** code. this can happen if there is no
199
                         ** source available:
200
                         ** 1. if the source file is in another dir OR
201
                         ** 2. if target was compiled without -g
202
                         ** We still want to show the assembly though!
203
                       */
204
                      addr = tuiGetBeginAsmAddress ();
205
                      tuiSetWinFocusTo (disassemWin);
206
                      layoutDef->displayMode = DISASSEM_WIN;
207
                      layoutDef->split = FALSE;
208
                      break;
209
                    case SRC_DISASSEM_COMMAND:
210
                      /* the previous layout was not showing
211
                         ** code. this can happen if there is no
212
                         ** source available:
213
                         ** 1. if the source file is in another dir OR
214
                         ** 2. if target was compiled without -g
215
                         ** We still want to show the assembly though!
216
                       */
217
                      addr = tuiGetBeginAsmAddress ();
218
                      if (winWithFocus == srcWin)
219
                        tuiSetWinFocusTo (srcWin);
220
                      else
221
                        tuiSetWinFocusTo (disassemWin);
222
                      layoutDef->split = TRUE;
223
                      break;
224
                    case SRC_DATA_COMMAND:
225
                      if (winWithFocus != dataWin)
226
                        tuiSetWinFocusTo (srcWin);
227
                      else
228
                        tuiSetWinFocusTo (dataWin);
229
                      layoutDef->displayMode = SRC_WIN;
230
                      layoutDef->split = FALSE;
231
                      break;
232
                    case DISASSEM_DATA_COMMAND:
233
                      /* the previous layout was not showing
234
                         ** code. this can happen if there is no
235
                         ** source available:
236
                         ** 1. if the source file is in another dir OR
237
                         ** 2. if target was compiled without -g
238
                         ** We still want to show the assembly though!
239
                       */
240
                      addr = tuiGetBeginAsmAddress ();
241
                      if (winWithFocus != dataWin)
242
                        tuiSetWinFocusTo (disassemWin);
243
                      else
244
                        tuiSetWinFocusTo (dataWin);
245
                      layoutDef->displayMode = DISASSEM_WIN;
246
                      layoutDef->split = FALSE;
247
                      break;
248
                    default:
249
                      break;
250
                    }
251
                }
252
              if (newWinWithFocus != (TuiWinInfoPtr) NULL)
253
                tuiSetWinFocusTo (newWinWithFocus);
254
              /*
255
                 ** Now update the window content
256
               */
257
              if (!regsPopulate &&
258
                  (newLayout == SRC_DATA_COMMAND ||
259
                   newLayout == DISASSEM_DATA_COMMAND))
260
                tuiDisplayAllData ();
261
 
262
              tuiUpdateSourceWindowsWithAddr (addr);
263
            }
264
          if (regsPopulate)
265
            {
266
              layoutDef->regsDisplayType =
267
                (regsDisplayType == TUI_UNDEFINED_REGS ?
268
                 TUI_GENERAL_REGS : regsDisplayType);
269
              tuiShowRegisters (layoutDef->regsDisplayType);
270
            }
271
        }
272
    }
273
  else
274
    status = TUI_FAILURE;
275
 
276
  return status;
277
}
278
 
279
/*
280
   ** tuiAddWinToLayout().
281
   **        Add the specified window to the layout in a logical way.
282
   **        This means setting up the most logical layout given the
283
   **        window to be added.
284
 */
285
void
286
tuiAddWinToLayout (TuiWinType type)
287
{
288
  TuiLayoutType curLayout = currentLayout ();
289
 
290
  switch (type)
291
    {
292
    case SRC_WIN:
293
      if (curLayout != SRC_COMMAND &&
294
          curLayout != SRC_DISASSEM_COMMAND &&
295
          curLayout != SRC_DATA_COMMAND)
296
        {
297
          clearSourceWindowsDetail ();
298
          if (curLayout == DISASSEM_DATA_COMMAND)
299
            showLayout (SRC_DATA_COMMAND);
300
          else
301
            showLayout (SRC_COMMAND);
302
        }
303
      break;
304
    case DISASSEM_WIN:
305
      if (curLayout != DISASSEM_COMMAND &&
306
          curLayout != SRC_DISASSEM_COMMAND &&
307
          curLayout != DISASSEM_DATA_COMMAND)
308
        {
309
          clearSourceWindowsDetail ();
310
          if (curLayout == SRC_DATA_COMMAND)
311
            showLayout (DISASSEM_DATA_COMMAND);
312
          else
313
            showLayout (DISASSEM_COMMAND);
314
        }
315
      break;
316
    case DATA_WIN:
317
      if (curLayout != SRC_DATA_COMMAND &&
318
          curLayout != DISASSEM_DATA_COMMAND)
319
        {
320
          if (curLayout == DISASSEM_COMMAND)
321
            showLayout (DISASSEM_DATA_COMMAND);
322
          else
323
            showLayout (SRC_DATA_COMMAND);
324
        }
325
      break;
326
    default:
327
      break;
328
    }
329
 
330
  return;
331
}                               /* tuiAddWinToLayout */
332
 
333
 
334
/*
335
   ** tuiDefaultWinHeight().
336
   **        Answer the height of a window.  If it hasn't been created yet,
337
   **        answer what the height of a window would be based upon its
338
   **        type and the layout.
339
 */
340
int
341
tuiDefaultWinHeight (TuiWinType type, TuiLayoutType layout)
342
{
343
  int h;
344
 
345
  if (winList[type] != (TuiWinInfoPtr) NULL)
346
    h = winList[type]->generic.height;
347
  else
348
    {
349
      switch (layout)
350
        {
351
        case SRC_COMMAND:
352
        case DISASSEM_COMMAND:
353
          if (m_winPtrIsNull (cmdWin))
354
            h = termHeight () / 2;
355
          else
356
            h = termHeight () - cmdWin->generic.height;
357
          break;
358
        case SRC_DISASSEM_COMMAND:
359
        case SRC_DATA_COMMAND:
360
        case DISASSEM_DATA_COMMAND:
361
          if (m_winPtrIsNull (cmdWin))
362
            h = termHeight () / 3;
363
          else
364
            h = (termHeight () - cmdWin->generic.height) / 2;
365
          break;
366
        default:
367
          h = 0;
368
          break;
369
        }
370
    }
371
 
372
  return h;
373
}                               /* tuiDefaultWinHeight */
374
 
375
 
376
/*
377
   ** tuiDefaultWinViewportHeight().
378
   **        Answer the height of a window.  If it hasn't been created yet,
379
   **        answer what the height of a window would be based upon its
380
   **        type and the layout.
381
 */
382
int
383
tuiDefaultWinViewportHeight (TuiWinType type, TuiLayoutType layout)
384
{
385
  int h;
386
 
387
  h = tuiDefaultWinHeight (type, layout);
388
 
389
  if (winList[type] == cmdWin)
390
    h -= 1;
391
  else
392
    h -= 2;
393
 
394
  return h;
395
}                               /* tuiDefaultWinViewportHeight */
396
 
397
 
398
/*
399
   ** _initialize_tuiLayout().
400
   **        Function to initialize gdb commands, for tui window layout
401
   **        manipulation.
402
 */
403
void
404
_initialize_tuiLayout (void)
405
{
406
  add_com ("layout", class_tui, _tuiLayout_command,
407
           "Change the layout of windows.\n\
408
Usage: layout prev | next | <layout_name> \n\
409
Layout names are:\n\
410
   src   : Displays source and command windows.\n\
411
   asm   : Displays disassembly and command windows.\n\
412
   split : Displays source, disassembly and command windows.\n\
413
   regs  : Displays register window. If existing layout\n\
414
           is source/command or assembly/command, the \n\
415
           register window is displayed. If the\n\
416
           source/assembly/command (split) is displayed, \n\
417
           the register window is displayed with \n\
418
           the window that has current logical focus.\n");
419
  if (xdb_commands)
420
    {
421
      add_com ("td", class_tui, _tuiToggleLayout_command,
422
               "Toggle between Source/Command and Disassembly/Command layouts.\n");
423
      add_com ("ts", class_tui, _tuiToggleSplitLayout_command,
424
               "Toggle between Source/Command or Disassembly/Command and \n\
425
Source/Disassembly/Command layouts.\n");
426
    }
427
}
428
 
429
 
430
/*************************
431
** STATIC LOCAL FUNCTIONS
432
**************************/
433
 
434
 
435
/*
436
   ** _tuiSetLayoutTo()
437
   **    Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, REGS,
438
   **        $REGS, $GREGS, $FREGS, $SREGS.
439
 */
440
TuiStatus
441
tui_set_layout (const char *layoutName)
442
{
443
  TuiStatus status = TUI_SUCCESS;
444
 
445
  if (layoutName != (char *) NULL)
446
    {
447
      register int i;
448
      register char *bufPtr;
449
      TuiLayoutType newLayout = UNDEFINED_LAYOUT;
450
      TuiRegisterDisplayType dpyType = TUI_UNDEFINED_REGS;
451
      TuiLayoutType curLayout = currentLayout ();
452
 
453
      bufPtr = (char *) xstrdup (layoutName);
454
      for (i = 0; (i < strlen (layoutName)); i++)
455
        bufPtr[i] = toupper (bufPtr[i]);
456
 
457
      /* First check for ambiguous input */
458
      if (strlen (bufPtr) <= 1 && (*bufPtr == 'S' || *bufPtr == '$'))
459
        {
460
          warning ("Ambiguous command input.\n");
461
          status = TUI_FAILURE;
462
        }
463
      else
464
        {
465
          if (subset_compare (bufPtr, "SRC"))
466
            newLayout = SRC_COMMAND;
467
          else if (subset_compare (bufPtr, "ASM"))
468
            newLayout = DISASSEM_COMMAND;
469
          else if (subset_compare (bufPtr, "SPLIT"))
470
            newLayout = SRC_DISASSEM_COMMAND;
471
          else if (subset_compare (bufPtr, "REGS") ||
472
                   subset_compare (bufPtr, TUI_GENERAL_SPECIAL_REGS_NAME) ||
473
                   subset_compare (bufPtr, TUI_GENERAL_REGS_NAME) ||
474
                   subset_compare (bufPtr, TUI_FLOAT_REGS_NAME) ||
475
                   subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
476
            {
477
              if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
478
                newLayout = SRC_DATA_COMMAND;
479
              else
480
                newLayout = DISASSEM_DATA_COMMAND;
481
 
482
/* could ifdef out the following code. when compile with -z, there are null
483
   pointer references that cause a core dump if 'layout regs' is the first
484
   layout command issued by the user. HP has asked us to hook up this code
485
   - edie epstein
486
 */
487
              if (subset_compare (bufPtr, TUI_FLOAT_REGS_NAME))
488
                {
489
                  if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
490
                      TUI_SFLOAT_REGS &&
491
                      dataWin->detail.dataDisplayInfo.regsDisplayType !=
492
                      TUI_DFLOAT_REGS)
493
                    dpyType = TUI_SFLOAT_REGS;
494
                  else
495
                    dpyType =
496
                      dataWin->detail.dataDisplayInfo.regsDisplayType;
497
                }
498
              else if (subset_compare (bufPtr,
499
                                      TUI_GENERAL_SPECIAL_REGS_NAME))
500
                dpyType = TUI_GENERAL_AND_SPECIAL_REGS;
501
              else if (subset_compare (bufPtr, TUI_GENERAL_REGS_NAME))
502
                dpyType = TUI_GENERAL_REGS;
503
              else if (subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
504
                dpyType = TUI_SPECIAL_REGS;
505
              else if (dataWin)
506
                {
507
                  if (dataWin->detail.dataDisplayInfo.regsDisplayType !=
508
                      TUI_UNDEFINED_REGS)
509
                    dpyType =
510
                      dataWin->detail.dataDisplayInfo.regsDisplayType;
511
                  else
512
                    dpyType = TUI_GENERAL_REGS;
513
                }
514
 
515
/* end of potential ifdef
516
 */
517
 
518
/* if ifdefed out code above, then assume that the user wishes to display the
519
   general purpose registers
520
 */
521
 
522
/*              dpyType = TUI_GENERAL_REGS;
523
 */
524
            }
525
          else if (subset_compare (bufPtr, "NEXT"))
526
            newLayout = _nextLayout ();
527
          else if (subset_compare (bufPtr, "PREV"))
528
            newLayout = _prevLayout ();
529
          else
530
            status = TUI_FAILURE;
531
          xfree (bufPtr);
532
 
533
          tuiSetLayout (newLayout, dpyType);
534
        }
535
    }
536
  else
537
    status = TUI_FAILURE;
538
 
539
  return status;
540
}
541
 
542
 
543
static CORE_ADDR
544
_extractDisplayStartAddr (void)
545
{
546
  TuiLayoutType curLayout = currentLayout ();
547
  CORE_ADDR addr;
548
  CORE_ADDR pc;
549
 
550
  switch (curLayout)
551
    {
552
    case SRC_COMMAND:
553
    case SRC_DATA_COMMAND:
554
      find_line_pc (current_source_symtab,
555
                    srcWin->detail.sourceInfo.startLineOrAddr.lineNo,
556
                    &pc);
557
      addr = pc;
558
      break;
559
    case DISASSEM_COMMAND:
560
    case SRC_DISASSEM_COMMAND:
561
    case DISASSEM_DATA_COMMAND:
562
      addr = disassemWin->detail.sourceInfo.startLineOrAddr.addr;
563
      break;
564
    default:
565
      addr = 0;
566
      break;
567
    }
568
 
569
  return addr;
570
}                               /* _extractDisplayStartAddr */
571
 
572
 
573
static void
574
_tuiHandleXDBLayout (TuiLayoutDefPtr layoutDef)
575
{
576
  if (layoutDef->split)
577
    {
578
      tuiSetLayout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
579
      tuiSetWinFocusTo (winList[layoutDef->displayMode]);
580
    }
581
  else
582
    {
583
      if (layoutDef->displayMode == SRC_WIN)
584
        tuiSetLayout (SRC_COMMAND, TUI_UNDEFINED_REGS);
585
      else
586
        tuiSetLayout (DISASSEM_DATA_COMMAND, layoutDef->regsDisplayType);
587
    }
588
 
589
 
590
  return;
591
}                               /* _tuiHandleXDBLayout */
592
 
593
 
594
static void
595
_tuiToggleLayout_command (char *arg, int fromTTY)
596
{
597
  TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
598
 
599
  /* Make sure the curses mode is enabled.  */
600
  tui_enable ();
601
  if (layoutDef->displayMode == SRC_WIN)
602
    layoutDef->displayMode = DISASSEM_WIN;
603
  else
604
    layoutDef->displayMode = SRC_WIN;
605
 
606
  if (!layoutDef->split)
607
    _tuiHandleXDBLayout (layoutDef);
608
 
609
}
610
 
611
 
612
static void
613
_tuiToggleSplitLayout_command (char *arg, int fromTTY)
614
{
615
  TuiLayoutDefPtr layoutDef = tuiLayoutDef ();
616
 
617
  /* Make sure the curses mode is enabled.  */
618
  tui_enable ();
619
  layoutDef->split = (!layoutDef->split);
620
  _tuiHandleXDBLayout (layoutDef);
621
 
622
}
623
 
624
 
625
static void
626
_tuiLayout_command (char *arg, int fromTTY)
627
{
628
  /* Make sure the curses mode is enabled.  */
629
  tui_enable ();
630
 
631
  /* Switch to the selected layout.  */
632
  if (tui_set_layout (arg) != TUI_SUCCESS)
633
    warning ("Invalid layout specified.\n%s", LAYOUT_USAGE);
634
 
635
}
636
 
637
/*
638
   ** _nextLayout().
639
   **        Answer the previous layout to cycle to.
640
 */
641
static TuiLayoutType
642
_nextLayout (void)
643
{
644
  TuiLayoutType newLayout;
645
 
646
  newLayout = currentLayout ();
647
  if (newLayout == UNDEFINED_LAYOUT)
648
    newLayout = SRC_COMMAND;
649
  else
650
    {
651
      newLayout++;
652
      if (newLayout == UNDEFINED_LAYOUT)
653
        newLayout = SRC_COMMAND;
654
    }
655
 
656
  return newLayout;
657
}                               /* _nextLayout */
658
 
659
 
660
/*
661
   ** _prevLayout().
662
   **        Answer the next layout to cycle to.
663
 */
664
static TuiLayoutType
665
_prevLayout (void)
666
{
667
  TuiLayoutType newLayout;
668
 
669
  newLayout = currentLayout ();
670
  if (newLayout == SRC_COMMAND)
671
    newLayout = DISASSEM_DATA_COMMAND;
672
  else
673
    {
674
      newLayout--;
675
      if (newLayout == UNDEFINED_LAYOUT)
676
        newLayout = DISASSEM_DATA_COMMAND;
677
    }
678
 
679
  return newLayout;
680
}                               /* _prevLayout */
681
 
682
 
683
 
684
/*
685
   ** _makeCommandWindow().
686
 */
687
static void
688
_makeCommandWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
689
{
690
  _initAndMakeWin ((Opaque *) winInfoPtr,
691
                   CMD_WIN,
692
                   height,
693
                   termWidth (),
694
                   0,
695
                   originY,
696
                   DONT_BOX_WINDOW);
697
 
698
  (*winInfoPtr)->canHighlight = FALSE;
699
 
700
  return;
701
}                               /* _makeCommandWindow */
702
 
703
 
704
/*
705
   ** _makeSourceWindow().
706
 */
707
static void
708
_makeSourceWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
709
{
710
  _makeSourceOrDisassemWindow (winInfoPtr, SRC_WIN, height, originY);
711
 
712
  return;
713
}                               /* _makeSourceWindow */
714
 
715
 
716
/*
717
   ** _makeDisassemWindow().
718
 */
719
static void
720
_makeDisassemWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
721
{
722
  _makeSourceOrDisassemWindow (winInfoPtr, DISASSEM_WIN, height, originY);
723
 
724
  return;
725
}                               /* _makeDisassemWindow */
726
 
727
 
728
/*
729
   ** _makeDataWindow().
730
 */
731
static void
732
_makeDataWindow (TuiWinInfoPtr * winInfoPtr, int height, int originY)
733
{
734
  _initAndMakeWin ((Opaque *) winInfoPtr,
735
                   DATA_WIN,
736
                   height,
737
                   termWidth (),
738
                   0,
739
                   originY,
740
                   BOX_WINDOW);
741
 
742
  return;
743
}                               /* _makeDataWindow */
744
 
745
 
746
 
747
/*
748
   **    _showSourceCommand().
749
   **        Show the Source/Command layout
750
 */
751
static void
752
_showSourceCommand (void)
753
{
754
  _showSourceOrDisassemAndCommand (SRC_COMMAND);
755
 
756
  return;
757
}                               /* _showSourceCommand */
758
 
759
 
760
/*
761
   **    _showDisassemCommand().
762
   **        Show the Dissassem/Command layout
763
 */
764
static void
765
_showDisassemCommand (void)
766
{
767
  _showSourceOrDisassemAndCommand (DISASSEM_COMMAND);
768
 
769
  return;
770
}                               /* _showDisassemCommand */
771
 
772
 
773
/*
774
   **    _showSourceDisassemCommand().
775
   **        Show the Source/Disassem/Command layout
776
 */
777
static void
778
_showSourceDisassemCommand (void)
779
{
780
  if (currentLayout () != SRC_DISASSEM_COMMAND)
781
    {
782
      int cmdHeight, srcHeight, asmHeight;
783
 
784
      if (m_winPtrNotNull (cmdWin))
785
        cmdHeight = cmdWin->generic.height;
786
      else
787
        cmdHeight = termHeight () / 3;
788
 
789
      srcHeight = (termHeight () - cmdHeight) / 2;
790
      asmHeight = termHeight () - (srcHeight + cmdHeight);
791
 
792
      if (m_winPtrIsNull (srcWin))
793
        _makeSourceWindow (&srcWin, srcHeight, 0);
794
      else
795
        {
796
          _initGenWinInfo (&srcWin->generic,
797
                           srcWin->generic.type,
798
                           srcHeight,
799
                           srcWin->generic.width,
800
                           srcWin->detail.sourceInfo.executionInfo->width,
801
                           0);
802
          srcWin->canHighlight = TRUE;
803
          _initGenWinInfo (srcWin->detail.sourceInfo.executionInfo,
804
                           EXEC_INFO_WIN,
805
                           srcHeight,
806
                           3,
807
                           0,
808
                           0);
809
          m_beVisible (srcWin);
810
          m_beVisible (srcWin->detail.sourceInfo.executionInfo);
811
          srcWin->detail.sourceInfo.hasLocator = FALSE;;
812
        }
813
      if (m_winPtrNotNull (srcWin))
814
        {
815
          TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
816
 
817
          tuiShowSourceContent (srcWin);
818
          if (m_winPtrIsNull (disassemWin))
819
            {
820
              _makeDisassemWindow (&disassemWin, asmHeight, srcHeight - 1);
821
              _initAndMakeWin ((Opaque *) & locator,
822
                               LOCATOR_WIN,
823
                               2 /* 1 */ ,
824
                               termWidth (),
825
                               0,
826
                               (srcHeight + asmHeight) - 1,
827
                               DONT_BOX_WINDOW);
828
            }
829
          else
830
            {
831
              _initGenWinInfo (locator,
832
                               LOCATOR_WIN,
833
                               2 /* 1 */ ,
834
                               termWidth (),
835
                               0,
836
                               (srcHeight + asmHeight) - 1);
837
              disassemWin->detail.sourceInfo.hasLocator = TRUE;
838
              _initGenWinInfo (
839
                                &disassemWin->generic,
840
                                disassemWin->generic.type,
841
                                asmHeight,
842
                                disassemWin->generic.width,
843
                        disassemWin->detail.sourceInfo.executionInfo->width,
844
                                srcHeight - 1);
845
              _initGenWinInfo (disassemWin->detail.sourceInfo.executionInfo,
846
                               EXEC_INFO_WIN,
847
                               asmHeight,
848
                               3,
849
                               0,
850
                               srcHeight - 1);
851
              disassemWin->canHighlight = TRUE;
852
              m_beVisible (disassemWin);
853
              m_beVisible (disassemWin->detail.sourceInfo.executionInfo);
854
            }
855
          if (m_winPtrNotNull (disassemWin))
856
            {
857
              srcWin->detail.sourceInfo.hasLocator = FALSE;
858
              disassemWin->detail.sourceInfo.hasLocator = TRUE;
859
              m_beVisible (locator);
860
              tuiShowLocatorContent ();
861
              tuiShowSourceContent (disassemWin);
862
 
863
              if (m_winPtrIsNull (cmdWin))
864
                _makeCommandWindow (&cmdWin,
865
                                    cmdHeight,
866
                                    termHeight () - cmdHeight);
867
              else
868
                {
869
                  _initGenWinInfo (&cmdWin->generic,
870
                                   cmdWin->generic.type,
871
                                   cmdWin->generic.height,
872
                                   cmdWin->generic.width,
873
                                   0,
874
                                   cmdWin->generic.origin.y);
875
                  cmdWin->canHighlight = FALSE;
876
                  m_beVisible (cmdWin);
877
                }
878
              if (m_winPtrNotNull (cmdWin))
879
                tuiRefreshWin (&cmdWin->generic);
880
            }
881
        }
882
      setCurrentLayoutTo (SRC_DISASSEM_COMMAND);
883
    }
884
 
885
  return;
886
}                               /* _showSourceDisassemCommand */
887
 
888
 
889
/*
890
   **    _showData().
891
   **        Show the Source/Data/Command or the Dissassembly/Data/Command layout
892
 */
893
static void
894
_showData (TuiLayoutType newLayout)
895
{
896
  int totalHeight = (termHeight () - cmdWin->generic.height);
897
  int srcHeight, dataHeight;
898
  TuiWinType winType;
899
  TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
900
 
901
 
902
  dataHeight = totalHeight / 2;
903
  srcHeight = totalHeight - dataHeight;
904
  m_allBeInvisible ();
905
  m_beInvisible (locator);
906
  _makeDataWindow (&dataWin, dataHeight, 0);
907
  dataWin->canHighlight = TRUE;
908
  if (newLayout == SRC_DATA_COMMAND)
909
    winType = SRC_WIN;
910
  else
911
    winType = DISASSEM_WIN;
912
  if (m_winPtrIsNull (winList[winType]))
913
    {
914
      if (winType == SRC_WIN)
915
        _makeSourceWindow (&winList[winType], srcHeight, dataHeight - 1);
916
      else
917
        _makeDisassemWindow (&winList[winType], srcHeight, dataHeight - 1);
918
      _initAndMakeWin ((Opaque *) & locator,
919
                       LOCATOR_WIN,
920
                       2 /* 1 */ ,
921
                       termWidth (),
922
                       0,
923
                       totalHeight - 1,
924
                       DONT_BOX_WINDOW);
925
    }
926
  else
927
    {
928
      _initGenWinInfo (&winList[winType]->generic,
929
                       winList[winType]->generic.type,
930
                       srcHeight,
931
                       winList[winType]->generic.width,
932
                   winList[winType]->detail.sourceInfo.executionInfo->width,
933
                       dataHeight - 1);
934
      _initGenWinInfo (winList[winType]->detail.sourceInfo.executionInfo,
935
                       EXEC_INFO_WIN,
936
                       srcHeight,
937
                       3,
938
                       0,
939
                       dataHeight - 1);
940
      m_beVisible (winList[winType]);
941
      m_beVisible (winList[winType]->detail.sourceInfo.executionInfo);
942
      _initGenWinInfo (locator,
943
                       LOCATOR_WIN,
944
                       2 /* 1 */ ,
945
                       termWidth (),
946
                       0,
947
                       totalHeight - 1);
948
    }
949
  winList[winType]->detail.sourceInfo.hasLocator = TRUE;
950
  m_beVisible (locator);
951
  tuiShowLocatorContent ();
952
  addToSourceWindows (winList[winType]);
953
  setCurrentLayoutTo (newLayout);
954
 
955
  return;
956
}                               /* _showData */
957
 
958
/*
959
   ** _initGenWinInfo().
960
 */
961
static void
962
_initGenWinInfo (TuiGenWinInfoPtr winInfo, TuiWinType type,
963
                 int height, int width, int originX, int originY)
964
{
965
  int h = height;
966
 
967
  winInfo->type = type;
968
  winInfo->width = width;
969
  winInfo->height = h;
970
  if (h > 1)
971
    {
972
      winInfo->viewportHeight = h - 1;
973
      if (winInfo->type != CMD_WIN)
974
        winInfo->viewportHeight--;
975
    }
976
  else
977
    winInfo->viewportHeight = 1;
978
  winInfo->origin.x = originX;
979
  winInfo->origin.y = originY;
980
 
981
  return;
982
}                               /* _initGenWinInfo */
983
 
984
/*
985
   ** _initAndMakeWin().
986
 */
987
static void
988
_initAndMakeWin (Opaque * winInfoPtr, TuiWinType winType,
989
                 int height, int width, int originX, int originY, int boxIt)
990
{
991
  Opaque opaqueWinInfo = *winInfoPtr;
992
  TuiGenWinInfoPtr generic;
993
 
994
  if (opaqueWinInfo == (Opaque) NULL)
995
    {
996
      if (m_winIsAuxillary (winType))
997
        opaqueWinInfo = (Opaque) allocGenericWinInfo ();
998
      else
999
        opaqueWinInfo = (Opaque) allocWinInfo (winType);
1000
    }
1001
  if (m_winIsAuxillary (winType))
1002
    generic = (TuiGenWinInfoPtr) opaqueWinInfo;
1003
  else
1004
    generic = &((TuiWinInfoPtr) opaqueWinInfo)->generic;
1005
 
1006
  if (opaqueWinInfo != (Opaque) NULL)
1007
    {
1008
      _initGenWinInfo (generic, winType, height, width, originX, originY);
1009
      if (!m_winIsAuxillary (winType))
1010
        {
1011
          if (generic->type == CMD_WIN)
1012
            ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = FALSE;
1013
          else
1014
            ((TuiWinInfoPtr) opaqueWinInfo)->canHighlight = TRUE;
1015
        }
1016
      makeWindow (generic, boxIt);
1017
    }
1018
  *winInfoPtr = opaqueWinInfo;
1019
}
1020
 
1021
 
1022
/*
1023
   ** _makeSourceOrDisassemWindow().
1024
 */
1025
static void
1026
_makeSourceOrDisassemWindow (TuiWinInfoPtr * winInfoPtr, TuiWinType type,
1027
                             int height, int originY)
1028
{
1029
  TuiGenWinInfoPtr executionInfo = (TuiGenWinInfoPtr) NULL;
1030
 
1031
  /*
1032
     ** Create the exeuction info window.
1033
   */
1034
  if (type == SRC_WIN)
1035
    executionInfo = sourceExecInfoWinPtr ();
1036
  else
1037
    executionInfo = disassemExecInfoWinPtr ();
1038
  _initAndMakeWin ((Opaque *) & executionInfo,
1039
                   EXEC_INFO_WIN,
1040
                   height,
1041
                   3,
1042
                   0,
1043
                   originY,
1044
                   DONT_BOX_WINDOW);
1045
  /*
1046
     ** Now create the source window.
1047
   */
1048
  _initAndMakeWin ((Opaque *) winInfoPtr,
1049
                   type,
1050
                   height,
1051
                   termWidth () - executionInfo->width,
1052
                   executionInfo->width,
1053
                   originY,
1054
                   BOX_WINDOW);
1055
 
1056
  (*winInfoPtr)->detail.sourceInfo.executionInfo = executionInfo;
1057
 
1058
  return;
1059
}                               /* _makeSourceOrDisassemWindow */
1060
 
1061
 
1062
/*
1063
   **    _showSourceOrDisassemAndCommand().
1064
   **        Show the Source/Command or the Disassem layout
1065
 */
1066
static void
1067
_showSourceOrDisassemAndCommand (TuiLayoutType layoutType)
1068
{
1069
  if (currentLayout () != layoutType)
1070
    {
1071
      TuiWinInfoPtr *winInfoPtr;
1072
      int srcHeight, cmdHeight;
1073
      TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
1074
 
1075
      if (m_winPtrNotNull (cmdWin))
1076
        cmdHeight = cmdWin->generic.height;
1077
      else
1078
        cmdHeight = termHeight () / 3;
1079
      srcHeight = termHeight () - cmdHeight;
1080
 
1081
 
1082
      if (layoutType == SRC_COMMAND)
1083
        winInfoPtr = &srcWin;
1084
      else
1085
        winInfoPtr = &disassemWin;
1086
 
1087
      if (m_winPtrIsNull (*winInfoPtr))
1088
        {
1089
          if (layoutType == SRC_COMMAND)
1090
            _makeSourceWindow (winInfoPtr, srcHeight - 1, 0);
1091
          else
1092
            _makeDisassemWindow (winInfoPtr, srcHeight - 1, 0);
1093
          _initAndMakeWin ((Opaque *) & locator,
1094
                           LOCATOR_WIN,
1095
                           2 /* 1 */ ,
1096
                           termWidth (),
1097
                           0,
1098
                           srcHeight - 1,
1099
                           DONT_BOX_WINDOW);
1100
        }
1101
      else
1102
        {
1103
          _initGenWinInfo (locator,
1104
                           LOCATOR_WIN,
1105
                           2 /* 1 */ ,
1106
                           termWidth (),
1107
                           0,
1108
                           srcHeight - 1);
1109
          (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1110
          _initGenWinInfo (
1111
                            &(*winInfoPtr)->generic,
1112
                            (*winInfoPtr)->generic.type,
1113
                            srcHeight - 1,
1114
                            (*winInfoPtr)->generic.width,
1115
                      (*winInfoPtr)->detail.sourceInfo.executionInfo->width,
1116
                            0);
1117
          _initGenWinInfo ((*winInfoPtr)->detail.sourceInfo.executionInfo,
1118
                           EXEC_INFO_WIN,
1119
                           srcHeight - 1,
1120
                           3,
1121
                           0,
1122
                           0);
1123
          (*winInfoPtr)->canHighlight = TRUE;
1124
          m_beVisible (*winInfoPtr);
1125
          m_beVisible ((*winInfoPtr)->detail.sourceInfo.executionInfo);
1126
        }
1127
      if (m_winPtrNotNull (*winInfoPtr))
1128
        {
1129
          (*winInfoPtr)->detail.sourceInfo.hasLocator = TRUE;
1130
          m_beVisible (locator);
1131
          tuiShowLocatorContent ();
1132
          tuiShowSourceContent (*winInfoPtr);
1133
 
1134
          if (m_winPtrIsNull (cmdWin))
1135
            {
1136
              _makeCommandWindow (&cmdWin, cmdHeight, srcHeight);
1137
              tuiRefreshWin (&cmdWin->generic);
1138
            }
1139
          else
1140
            {
1141
              _initGenWinInfo (&cmdWin->generic,
1142
                               cmdWin->generic.type,
1143
                               cmdWin->generic.height,
1144
                               cmdWin->generic.width,
1145
                               cmdWin->generic.origin.x,
1146
                               cmdWin->generic.origin.y);
1147
              cmdWin->canHighlight = FALSE;
1148
              m_beVisible (cmdWin);
1149
            }
1150
        }
1151
      setCurrentLayoutTo (layoutType);
1152
    }
1153
 
1154
  return;
1155
}                               /* _showSourceOrDisassemAndCommand */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.