~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to info/display.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* display.c -- How to display Info windows.
2
 
   $Id: display.c,v 1.6 1997/07/24 21:13:27 karl Exp $
 
2
   $Id: display.c,v 1.7 2004/04/11 17:56:45 karl Exp $
3
3
 
4
 
   Copyright (C) 1993, 97 Free Software Foundation, Inc.
 
4
   Copyright (C) 1993, 1997, 2003, 2004 Free Software Foundation, Inc.
5
5
 
6
6
   This program is free software; you can redistribute it and/or modify
7
7
   it under the terms of the GNU General Public License as published by
17
17
   along with this program; if not, write to the Free Software
18
18
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
19
 
20
 
   Written by Brian Fox (bfox@ai.mit.edu). */
 
20
   Originally written by Brian Fox (bfox@ai.mit.edu). */
21
21
 
22
22
#include "info.h"
23
23
#include "display.h"
24
24
 
25
 
extern int info_any_buffered_input_p (); /* Found in session.c. */
26
 
 
27
 
static void free_display ();
28
 
static DISPLAY_LINE **make_display ();
 
25
extern int info_any_buffered_input_p (void); /* Found in session.c. */
 
26
 
 
27
static void free_display (DISPLAY_LINE **display);
 
28
static DISPLAY_LINE **make_display (int width, int height);
 
29
 
 
30
void handle_tag (char *tag);
 
31
void handle_tag_start (char *tag);
 
32
void handle_tag_end (char *tag);
29
33
 
30
34
/* An array of display lines which tell us what is currently visible on
31
35
   the display.  */
36
40
 
37
41
/* Initialize THE_DISPLAY to WIDTH and HEIGHT, with nothing in it. */
38
42
void
39
 
display_initialize_display (width, height)
40
 
     int width, height;
 
43
display_initialize_display (int width, int height)
41
44
{
42
45
  free_display (the_display);
43
46
  the_display = make_display (width, height);
46
49
 
47
50
/* Clear all of the lines in DISPLAY making the screen blank. */
48
51
void
49
 
display_clear_display (display)
50
 
     DISPLAY_LINE **display;
 
52
display_clear_display (DISPLAY_LINE **display)
51
53
{
52
54
  register int i;
53
 
  register DISPLAY_LINE *display_line;
54
55
 
55
 
  for (i = 0; (display_line = display[i]); i++)
 
56
  for (i = 0; display[i]; i++)
56
57
    {
57
58
      display[i]->text[0] = '\0';
58
59
      display[i]->textlen = 0;
66
67
/* Update the windows pointed to by WINDOW in the_display.  This actually
67
68
   writes the text on the screen. */
68
69
void
69
 
display_update_display (window)
70
 
     WINDOW *window;
 
70
display_update_display (WINDOW *window)
71
71
{
72
72
  register WINDOW *win;
73
73
 
91
91
  display_update_one_window (the_echo_area);
92
92
}
93
93
 
 
94
void
 
95
handle_tag_start (char *tag)
 
96
{
 
97
  /* TODO really handle this tag.  */
 
98
  return;
 
99
}
 
100
 
 
101
void
 
102
handle_tag_end (char *tag)
 
103
{
 
104
  /* TODO really handle this tag.  */
 
105
  return;
 
106
}
 
107
 
 
108
void
 
109
handle_tag (char *tag)
 
110
{
 
111
    if (tag[0] == '/')
 
112
      {
 
113
        tag++;
 
114
        handle_tag_end (tag);
 
115
      }
 
116
    else
 
117
      handle_tag_start (tag);
 
118
}
 
119
 
94
120
/* Display WIN on the_display.  Unlike display_update_display (), this
95
121
   function only does one window. */
96
122
void
97
 
display_update_one_window (win)
98
 
     WINDOW *win;
 
123
display_update_one_window (WINDOW *win)
99
124
{
100
125
  register char *nodetext;      /* Current character to display. */
101
126
  register char *last_node_char; /* Position of the last character in node. */
103
128
  char *printed_line;           /* Buffer for a printed line. */
104
129
  int pl_index = 0;             /* Index into PRINTED_LINE. */
105
130
  int line_index = 0;           /* Number of lines done so far. */
 
131
  int pl_ignore = 0;            /* How many chars use zero width on screen. */
 
132
  int allocated_win_width;
106
133
  DISPLAY_LINE **display = the_display;
107
134
 
108
135
  /* If display is inhibited, that counts as an interrupted display. */
123
150
  /* Print each line in the window into our local buffer, and then
124
151
     check the contents of that buffer against the display.  If they
125
152
     differ, update the display. */
126
 
  printed_line = (char *)xmalloc (1 + win->width);
 
153
  allocated_win_width = win->width + 1;
 
154
  printed_line = (char *)xmalloc (allocated_win_width);
127
155
 
128
156
  if (!win->node || !win->line_starts)
129
157
    goto done_with_node_display;
133
161
 
134
162
  for (; nodetext < last_node_char; nodetext++)
135
163
    {
136
 
      char *rep, *rep_carried_over, rep_temp[2];
 
164
      char *rep = NULL, *rep_carried_over, rep_temp[2];
137
165
      int replen;
138
166
 
139
167
      if (isprint (*nodetext))
147
175
        {
148
176
          if (*nodetext == '\r' || *nodetext == '\n')
149
177
            {
150
 
              replen = win->width - pl_index;
 
178
              replen = win->width - pl_index + pl_ignore;
151
179
            }
 
180
          else if (*nodetext == '\0'
 
181
                   && (nodetext + 2) < last_node_char
 
182
                   && *(nodetext + 1) == '\b'
 
183
                   && *(nodetext + 2) == '[')
 
184
            {
 
185
              /* Found new style tag/cookie \0\b[
 
186
                 Read until the closing tag \0\b] */
 
187
              int element_len = 0;
 
188
              char *element;
 
189
 
 
190
              /* Skip the escapes.  */
 
191
              nodetext += 3;
 
192
 
 
193
              while (!(*nodetext == '\0'
 
194
                    && *(nodetext + 1) == '\b'
 
195
                    && *(nodetext + 2) == ']'))
 
196
                {
 
197
                  nodetext++;
 
198
                  element_len++;
 
199
                }
 
200
 
 
201
              element = (char *) malloc (element_len + 1);
 
202
              strncpy (element, nodetext - element_len, element_len);
 
203
 
 
204
              /* Skip the escapes.  */
 
205
              nodetext += 2;
 
206
              pl_ignore += element_len + 5;
 
207
              /* Append string terminator.  */
 
208
              element[element_len] = '\0';
 
209
 
 
210
              handle_tag (element);
 
211
 
 
212
              /* Over and out */
 
213
              free (element);
 
214
 
 
215
              continue;
 
216
            }
152
217
          else
153
218
            {
154
219
              rep = printed_representation (*nodetext, pl_index);
156
221
            }
157
222
        }
158
223
 
 
224
      /* Support ANSI escape sequences under -R.  */
 
225
      if (raw_escapes_p
 
226
          && *nodetext == '\033'
 
227
          && nodetext[1] == '['
 
228
          && isdigit (nodetext[2]))
 
229
        {
 
230
          if (nodetext[3] == 'm')
 
231
            pl_ignore += 4;
 
232
          else if (isdigit (nodetext[3]) && nodetext[4] == 'm')
 
233
            pl_ignore += 5;
 
234
        }
 
235
      while (pl_index + 2 >= allocated_win_width - 1)
 
236
        {
 
237
          allocated_win_width *= 2;
 
238
          printed_line = (char *)xrealloc (printed_line, allocated_win_width);
 
239
        }
 
240
 
159
241
      /* If this character can be printed without passing the width of
160
242
         the line, then stuff it into the line. */
161
 
      if (replen + pl_index < win->width)
 
243
      if (replen + pl_index < win->width + pl_ignore)
162
244
        {
163
245
          /* Optimize if possible. */
164
246
          if (replen == 1)
189
271
                 the next line.  Remember the offset of the last character
190
272
                 printed out of REP so that we can carry the character over
191
273
                 to the next line. */
192
 
              for (i = 0; pl_index < (win->width - 1);)
 
274
              for (i = 0; pl_index < (win->width + pl_ignore - 1);)
193
275
                printed_line[pl_index++] = rep[i++];
194
 
              
 
276
 
195
277
              rep_carried_over = rep + i;
196
278
 
197
279
              /* If printing the last character in this window couldn't
213
295
          entry = display[line_index + win->first_row];
214
296
 
215
297
          /* If the screen line is inversed, then we have to clear
216
 
             the line from the screen first.  Why, I don't know. */
217
 
          if (entry->inverse)
 
298
             the line from the screen first.  Why, I don't know.
 
299
             (But don't do this if we have no visible entries, as can
 
300
             happen if the window is shrunk very small.)  */
 
301
          if ((entry && entry->inverse)
 
302
              /* Need to erase the line if it has escape sequences.  */
 
303
              || (raw_escapes_p && strchr (entry->text, '\033') != 0))
218
304
            {
219
305
              terminal_goto_xy (0, line_index + win->first_row);
220
306
              terminal_clear_to_eol ();
242
328
              /* If the printed text didn't extend all the way to the edge
243
329
                 of the window, and text was appearing between here and the
244
330
                 edge of the window, clear from here to the end of the line. */
245
 
              if ((pl_index < win->width && pl_index < entry->textlen) ||
246
 
                  (entry->inverse))
 
331
              if ((pl_index < win->width + pl_ignore
 
332
                   && pl_index < entry->textlen)
 
333
                  || (entry->inverse))
247
334
                terminal_clear_to_eol ();
248
335
 
249
336
              fflush (stdout);
250
337
 
251
338
              /* Update the display text buffer. */
 
339
              if (strlen (printed_line) > (unsigned int) screenwidth)
 
340
                /* printed_line[] can include more than screenwidth
 
341
                   characters if we are under -R and there are escape
 
342
                   sequences in it.  However, entry->text was
 
343
                   allocated (in display_initialize_display) for
 
344
                   screenwidth characters only.  */
 
345
                entry->text = xrealloc (entry->text, strlen (printed_line)+1);
252
346
              strcpy (entry->text + i, printed_line + i);
253
347
              entry->textlen = pl_index;
254
348
 
274
368
 
275
369
          /* Reset PL_INDEX to the start of the line. */
276
370
          pl_index = 0;
 
371
          pl_ignore = 0;        /* this is computed per line */
277
372
 
278
373
          /* If there are characters from REP left to print, stuff them
279
374
             into the buffer now. */
291
386
              printed_line[0] = '\0';
292
387
 
293
388
              begin = nodetext;
294
 
              
 
389
 
295
390
              while ((nodetext < last_node_char) && (*nodetext != '\n'))
296
391
                nodetext++;
297
392
            }
353
448
   for no scrolling to take place in the case that the terminal doesn't
354
449
   support it.  This doesn't matter to us. */
355
450
void
356
 
display_scroll_display (start, end, amount)
357
 
     int start, end, amount;
 
451
display_scroll_display (int start, int end, int amount)
358
452
{
359
453
  register int i, last;
360
454
  DISPLAY_LINE *temp;
424
518
   starts that used to appear in this window.  OLD_COUNT is the number of lines
425
519
   that appear in the OLD_STARTS array. */
426
520
void
427
 
display_scroll_line_starts (window, old_pagetop, old_starts, old_count)
428
 
     WINDOW *window;
429
 
     int old_pagetop, old_count;
430
 
     char **old_starts;
 
521
display_scroll_line_starts (WINDOW *window, int old_pagetop,
 
522
    char **old_starts, int old_count)
431
523
{
432
524
  register int i, old, new;     /* Indices into the line starts arrays. */
433
525
  int last_new, last_old;       /* Index of the last visible line. */
499
591
 
500
592
/* Move the screen cursor to directly over the current character in WINDOW. */
501
593
void
502
 
display_cursor_at_point (window)
503
 
     WINDOW *window;
 
594
display_cursor_at_point (WINDOW *window)
504
595
{
505
596
  int vpos, hpos;
506
597
 
518
609
 
519
610
/* Make a DISPLAY_LINE ** with width and height. */
520
611
static DISPLAY_LINE **
521
 
make_display (width, height)
522
 
     int width, height;
 
612
make_display (int width, int height)
523
613
{
524
614
  register int i;
525
615
  DISPLAY_LINE **display;
539
629
 
540
630
/* Free the storage allocated to DISPLAY. */
541
631
static void
542
 
free_display (display)
543
 
     DISPLAY_LINE **display;
 
632
free_display (DISPLAY_LINE **display)
544
633
{
545
634
  register int i;
546
635
  register DISPLAY_LINE *display_line;