3 ** This module contains functions for displaying source in the source window
10 #include "breakpoint.h"
16 #include "tuiSourceWin.h"
17 #include "tuiSource.h"
20 /*****************************************
21 ** EXTERNAL DATA DECLS **
22 ******************************************/
23 extern int current_source_line
;
24 extern struct symtab
*current_source_symtab
;
27 /*****************************************
28 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
29 ******************************************/
31 static struct breakpoint
*_hasBreak (char *, int);
34 /*****************************************
35 ** STATIC LOCAL DATA **
36 ******************************************/
39 /*****************************************
40 ** PUBLIC FUNCTIONS **
41 ******************************************/
43 /*********************************
44 ** SOURCE/DISASSEM FUNCTIONS **
45 *********************************/
48 ** tuiSetSourceContent().
49 ** Function to display source in the source window.
58 tuiSetSourceContent (s
, lineNo
, noerror
)
64 TuiStatus ret
= TUI_FAILURE
;
66 if (s
!= (struct symtab
*) NULL
&& s
->filename
!= (char *) NULL
)
68 register FILE *stream
;
69 register int i
, desc
, c
, lineWidth
, nlines
;
70 register char *srcLine
;
72 if ((ret
= tuiAllocSourceBuffer (srcWin
)) == TUI_SUCCESS
)
74 lineWidth
= srcWin
->generic
.width
- 1;
76 ** Take hilite (window border) into account, when calculating
77 ** the number of lines
79 nlines
= (lineNo
+ (srcWin
->generic
.height
- 2)) - lineNo
;
80 desc
= open_source_file (s
);
85 char *name
= alloca (strlen (s
->filename
) + 100);
86 sprintf (name
, "%s:%d", s
->filename
, lineNo
);
87 print_sys_errmsg (name
, errno
);
93 if (s
->line_charpos
== 0)
94 find_source_lines (s
, desc
);
96 if (lineNo
< 1 || lineNo
> s
->nlines
)
100 "Line number %d out of range; %s has %d lines.\n",
101 lineNo
, s
->filename
, s
->nlines
);
103 else if (lseek (desc
, s
->line_charpos
[lineNo
- 1], 0) < 0)
106 perror_with_name (s
->filename
);
110 register int offset
, curLineNo
, curLine
, curLen
, threshold
;
111 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
113 ** Determine the threshold for the length of the line
114 ** and the offset to start the display
116 offset
= srcWin
->detail
.sourceInfo
.horizontalOffset
;
117 threshold
= (lineWidth
- 1) + offset
;
118 stream
= fdopen (desc
, FOPEN_RT
);
122 srcWin
->detail
.sourceInfo
.startLineOrAddr
.lineNo
= lineNo
;
124 srcLine
= (char *) xmalloc (
125 (threshold
+ 1) * sizeof (char));
126 while (curLine
< nlines
)
128 TuiWinElementPtr element
= (TuiWinElementPtr
)
129 srcWin
->generic
.content
[curLine
];
130 struct breakpoint
*bp
;
132 /* get the first character in the line */
136 srcLine
= ((TuiWinElementPtr
)
137 srcWin
->generic
.content
[
138 curLine
])->whichElement
.source
.line
;
139 /* Init the line with the line number */
140 sprintf (srcLine
, "%-6d", curLineNo
);
141 curLen
= strlen (srcLine
);
143 ((curLen
/ tuiDefaultTabLen ()) * tuiDefaultTabLen ());
144 while (i
< tuiDefaultTabLen ())
146 srcLine
[curLen
] = ' ';
150 srcLine
[curLen
] = (char) 0;
153 ** Set whether element is the execution point and
154 ** whether there is a break point on it.
156 element
->whichElement
.source
.lineOrAddr
.lineNo
=
158 element
->whichElement
.source
.isExecPoint
=
159 (strcmp (((TuiWinElementPtr
)
160 locator
->content
[0])->whichElement
.locator
.fileName
,
162 && curLineNo
== ((TuiWinElementPtr
)
163 locator
->content
[0])->whichElement
.locator
.lineNo
);
164 bp
= _hasBreak (s
->filename
, curLineNo
);
165 element
->whichElement
.source
.hasBreak
=
166 (bp
!= (struct breakpoint
*) NULL
&&
167 (!element
->whichElement
.source
.isExecPoint
||
168 (bp
->disposition
!= del
|| bp
->hit_count
<= 0)));
171 i
= strlen (srcLine
) - 1;
175 (c
!= '\r') && (++i
< threshold
))
177 if (c
< 040 && c
!= '\t')
180 srcLine
[i
] = c
+ 0100;
189 ** Store the charcter in the line
190 ** buffer. If it is a tab, then
191 ** translate to the correct number of
192 ** chars so we don't overwrite our
197 int j
, maxTabLen
= tuiDefaultTabLen ();
200 (i
/ maxTabLen
) * maxTabLen
);
214 ** if we have not reached EOL, then eat
217 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
221 while (c
!= EOF
&& c
!= '\n' && c
!= '\r' &&
222 i
< threshold
&& (c
= fgetc (stream
)));
224 /* Now copy the line taking the offset into account */
225 if (strlen (srcLine
) > offset
)
226 strcpy (((TuiWinElementPtr
) srcWin
->generic
.content
[
227 curLine
])->whichElement
.source
.line
,
231 srcWin
->generic
.content
[
232 curLine
])->whichElement
.source
.line
[0] = (char) 0;
239 srcWin
->generic
.contentSize
= nlines
;
246 } /* tuiSetSourceContent */
249 /* elz: this function sets the contents of the source window to empty
250 except for a line in the middle with a warning message about the
251 source not being available. This function is called by
252 tuiEraseSourceContents, which in turn is invoked when the source files
253 cannot be accessed */
257 tuiSetSourceContentNil (
258 TuiWinInfoPtr winInfo
,
259 char *warning_string
)
261 tuiSetSourceContentNil (winInfo
, warning_string
)
262 TuiWinInfoPtr winInfo
;
263 char *warning_string
;
270 lineWidth
= winInfo
->generic
.width
- 1;
271 nLines
= winInfo
->generic
.height
- 2;
273 /* set to empty each line in the window, except for the one
274 which contains the message */
275 while (curr_line
< winInfo
->generic
.contentSize
)
277 /* set the information related to each displayed line
278 to null: i.e. the line number is 0, there is no bp,
279 it is not where the program is stopped */
281 TuiWinElementPtr element
=
282 (TuiWinElementPtr
) winInfo
->generic
.content
[curr_line
];
283 element
->whichElement
.source
.lineOrAddr
.lineNo
= 0;
284 element
->whichElement
.source
.isExecPoint
= FALSE
;
285 element
->whichElement
.source
.hasBreak
= FALSE
;
287 /* set the contents of the line to blank */
288 element
->whichElement
.source
.line
[0] = (char) 0;
290 /* if the current line is in the middle of the screen, then we want to
291 display the 'no source available' message in it.
292 Note: the 'weird' arithmetic with the line width and height comes from
293 the function tuiEraseSourceContent. We need to keep the screen and the
294 window's actual contents in synch */
296 if (curr_line
== (nLines
/ 2 + 1))
300 int warning_length
= strlen (warning_string
);
303 srcLine
= element
->whichElement
.source
.line
;
305 if (warning_length
>= ((lineWidth
- 1) / 2))
308 xpos
= (lineWidth
- 1) / 2 - warning_length
;
310 for (i
= 0; i
< xpos
; i
++)
313 sprintf (srcLine
+ i
, "%s", warning_string
);
315 for (i
= xpos
+ warning_length
; i
< lineWidth
; i
++)
326 } /*tuiSetSourceContentNil */
333 ** Function to display source in the source window. This function
334 ** initializes the horizontal scroll to 0.
343 tuiShowSource (s
, line
, noerror
)
349 srcWin
->detail
.sourceInfo
.horizontalOffset
= 0;
350 m_tuiShowSourceAsIs (s
, line
, noerror
);
353 } /* tuiShowSource */
357 ** tuiSourceIsDisplayed().
358 ** Answer whether the source is currently displayed in the source window.
362 tuiSourceIsDisplayed (
365 tuiSourceIsDisplayed (fname
)
369 return (srcWin
->generic
.contentInUse
&&
370 (strcmp (((TuiWinElementPtr
) (locatorWinInfoPtr ())->
371 content
[0])->whichElement
.locator
.fileName
, fname
) == 0));
372 } /* tuiSourceIsDisplayed */
376 ** tuiVerticalSourceScroll().
377 ** Scroll the source forward or backward vertically
381 tuiVerticalSourceScroll (
382 TuiScrollDirection scrollDirection
,
385 tuiVerticalSourceScroll (scrollDirection
, numToScroll
)
386 TuiScrollDirection scrollDirection
;
390 if (srcWin
->generic
.content
!= (OpaquePtr
) NULL
)
395 TuiWinContent content
= (TuiWinContent
) srcWin
->generic
.content
;
397 if (current_source_symtab
== (struct symtab
*) NULL
)
398 s
= find_pc_symtab (selected_frame
->pc
);
400 s
= current_source_symtab
;
402 if (scrollDirection
== FORWARD_SCROLL
)
404 line
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
+
406 if (line
> s
->nlines
)
407 /*line = s->nlines - winInfo->generic.contentSize + 1; */
408 /*elz: fix for dts 23398 */
409 line
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
;
413 line
= content
[0]->whichElement
.source
.lineOrAddr
.lineNo
-
418 tuiUpdateSourceWindowAsIs (srcWin
, s
, (Opaque
) line
, FALSE
);
422 } /* tuiVerticalSourceScroll */
425 /*****************************************
426 ** STATIC LOCAL FUNCTIONS **
427 ******************************************/
431 ** Answer whether there is a break point at the input line in
432 ** the source file indicated
434 static struct breakpoint
*
437 char *sourceFileName
,
440 _hasBreak (sourceFileName
, lineNo
)
441 char *sourceFileName
;
445 struct breakpoint
*bpWithBreak
= (struct breakpoint
*) NULL
;
446 struct breakpoint
*bp
;
447 extern struct breakpoint
*breakpoint_chain
;
450 for (bp
= breakpoint_chain
;
451 (bp
!= (struct breakpoint
*) NULL
&&
452 bpWithBreak
== (struct breakpoint
*) NULL
);
454 if ((strcmp (sourceFileName
, bp
->source_file
) == 0) &&
455 (lineNo
== bp
->line_number
))