+ file_info_type * file;
+ unsigned int line;
+ char buffer [LISTING_RHS_WIDTH];
+} cached_line;
+
+static void
+print_source (file_info_type * current_file,
+ list_info_type * list,
+ unsigned int width)
+{
+#define NUM_CACHE_LINES 3
+ static cached_line cached_lines[NUM_CACHE_LINES];
+ static int next_free_line = 0;
+ cached_line * cache = NULL;
+
+ if (current_file->linenum > list->hll_line
+ && list->hll_line > 0)
+ {
+ /* This can happen with modern optimizing compilers. The source
+ lines from the high level language input program are split up
+ and interleaved, meaning the line number we want to display
+ (list->hll_line) can have already been displayed. We have
+ three choices:
+
+ a. Do nothing, since we have already displayed the source
+ line. This was the old behaviour.
+
+ b. Display the particular line requested again, but only
+ that line. This is the new behaviour.
+
+ c. Display the particular line requested again and reset
+ the current_file->line_num value so that we redisplay
+ all the following lines as well the next time we
+ encounter a larger line number. */
+ int i;
+
+ /* Check the cache, maybe we already have the line saved. */
+ for (i = 0; i < NUM_CACHE_LINES; i++)
+ if (cached_lines[i].file == current_file
+ && cached_lines[i].line == list->hll_line)
+ {
+ cache = cached_lines + i;
+ break;
+ }
+
+ if (i == NUM_CACHE_LINES)
+ {
+ cache = cached_lines + next_free_line;
+ next_free_line ++;
+ if (next_free_line == NUM_CACHE_LINES)
+ next_free_line = 0;
+
+ cache->file = current_file;
+ cache->line = list->hll_line;
+ cache->buffer[0] = 0;
+ rebuffer_line (current_file, cache->line, cache->buffer, width);
+ }
+
+ emit_line (list, "%4u:%-13s **** %s\n",
+ cache->line, cache->file->filename, cache->buffer);
+ return;
+ }
+
+ if (!current_file->at_end)
+ {
+ int num_lines_shown = 0;
+
+ while (current_file->linenum < list->hll_line
+ && !current_file->at_end)
+ {
+ cached_line * cache = cached_lines + next_free_line;
+ char *p;
+
+ cache->file = current_file;
+ cache->line = current_file->linenum;
+ cache->buffer[0] = 0;
+ p = buffer_line (current_file, cache->buffer, width);
+
+ /* Cache optimization: If printing a group of lines
+ cache the first and last lines in the group. */
+ if (num_lines_shown == 0)
+ {
+ next_free_line ++;
+ if (next_free_line == NUM_CACHE_LINES)
+ next_free_line = 0;
+ }
+
+ emit_line (list, "%4u:%-13s **** %s\n",
+ cache->line, cache->file->filename, p);
+ num_lines_shown ++;
+ }