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

« back to all changes in this revision

Viewing changes to info/echo-area.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
/* echo-area.c -- how to read a line in the echo area.
2
 
   $Id: echo-area.c,v 1.15 2001/12/12 16:19:39 karl Exp $
 
2
   $Id: echo-area.c,v 1.7 2004/12/14 00:15:36 karl Exp $
3
3
 
4
 
   Copyright (C) 1993, 97, 98, 99, 2001 Free Software Foundation, Inc.
 
4
   Copyright (C) 1993, 1997, 1998, 1999, 2001, 2004 Free Software
 
5
   Foundation, Inc.
5
6
 
6
7
   This program is free software; you can redistribute it and/or modify
7
8
   it under the terms of the GNU General Public License as published by
49
50
static int input_line_beg;
50
51
static int input_line_end;
51
52
static NODE input_line_node = {
52
 
  (char *)NULL, (char *)NULL, (char *)NULL, input_line, EA_MAX_INPUT, 0
 
53
  (char *)NULL, (char *)NULL, (char *)NULL, input_line,
 
54
  EA_MAX_INPUT, 0, N_IsInternal
53
55
};
54
56
 
55
 
static void echo_area_initialize_node ();
56
 
static void push_echo_area (), pop_echo_area ();
57
 
static int echo_area_stack_contains_completions_p ();
 
57
static void echo_area_initialize_node (void);
 
58
static void push_echo_area (void), pop_echo_area (void);
 
59
static int echo_area_stack_contains_completions_p (void);
58
60
 
59
 
static void ea_kill_text ();
 
61
static void ea_kill_text (int from, int to);
60
62
 
61
63
/* Non-zero means we force the user to complete. */
62
64
static int echo_area_must_complete_p = 0;
63
 
static int completions_window_p ();
 
65
static int completions_window_p (WINDOW *window);
64
66
 
65
67
/* If non-null, this is a window which was specifically created to display
66
68
   possible completions output.  We remember it so we can delete it when
76
78
 
77
79
/* Remember the node and pertinent variables of the calling window. */
78
80
static void
79
 
remember_calling_window (window)
80
 
     WINDOW *window;
 
81
remember_calling_window (WINDOW *window)
81
82
{
82
83
  /* Only do this if the calling window is not the completions window, or,
83
84
     if it is the completions window and there is no other window. */
94
95
/* Restore the caller's window so that it shows the node that it was showing
95
96
   on entry to info_read_xxx_echo_area (). */
96
97
static void
97
 
restore_calling_window ()
 
98
restore_calling_window (void)
98
99
{
99
100
  register WINDOW *win, *compwin = (WINDOW *)NULL;
100
101
 
124
125
          !echo_area_stack_contains_completions_p ())
125
126
        {
126
127
          WINDOW *next;
127
 
          int pagetop, start, end, amount;
 
128
          int pagetop = 0;
 
129
          int start = 0;
 
130
          int end = 0;
 
131
          int amount = 0;
128
132
 
129
133
          next = compwin->next;
130
134
          if (next)
156
160
 
157
161
/* Set up a new input line with PROMPT. */
158
162
static void
159
 
initialize_input_line (prompt)
160
 
     char *prompt;
 
163
initialize_input_line (char *prompt)
161
164
{
162
165
  input_line_prompt = prompt;
163
166
  if (prompt)
169
172
}
170
173
 
171
174
static char *
172
 
echo_area_after_read ()
 
175
echo_area_after_read (void)
173
176
{
174
177
  char *return_value;
175
178
 
198
201
   active window, so that we can restore it when we need to.  PROMPT, if
199
202
   non-null, is a prompt to print before reading the line. */
200
203
char *
201
 
info_read_in_echo_area (window, prompt)
202
 
     WINDOW *window;
203
 
     char *prompt;
 
204
info_read_in_echo_area (WINDOW *window, char *prompt)
204
205
{
205
206
  char *line;
206
207
 
246
247
 
247
248
/* (re) Initialize the echo area node. */
248
249
static void
249
 
echo_area_initialize_node ()
 
250
echo_area_initialize_node (void)
250
251
{
251
252
  register int i;
252
253
 
253
 
  for (i = input_line_end; i < sizeof (input_line); i++)
 
254
  for (i = input_line_end; (unsigned int) i < sizeof (input_line); i++)
254
255
    input_line[i] = ' ';
255
256
 
256
257
  input_line[i - 1] = '\n';
262
263
   echo area node, but its primary purpose is to side effect the input
263
264
   line buffer contents. */
264
265
void
265
 
echo_area_prep_read ()
 
266
echo_area_prep_read (void)
266
267
{
267
268
  if (the_echo_area->node != &input_line_node)
268
269
    echo_area_initialize_node ();
559
560
 
560
561
  if (!kill_ring_index)
561
562
    {
562
 
      inform_in_echo_area (_("Kill ring is empty"));
 
563
      inform_in_echo_area ((char *) _("Kill ring is empty"));
563
564
      return;
564
565
    }
565
566
 
576
577
{
577
578
  register int len;
578
579
 
579
 
  if (((ea_last_executed_command != ea_yank) &&
580
 
       (ea_last_executed_command != ea_yank_pop)) ||
 
580
  if (((ea_last_executed_command != (VFunction *) ea_yank) &&
 
581
       (ea_last_executed_command != (VFunction *) ea_yank_pop)) ||
581
582
      (kill_ring_index == 0))
582
583
    return;
583
584
 
670
671
   otherwise it is prepended.  If the last command was not a kill command,
671
672
   then a new slot is made for this kill. */
672
673
static void
673
 
ea_kill_text (from, to)
674
 
     int from, to;
 
674
ea_kill_text (int from, int to)
675
675
{
676
676
  register int i, counter, distance;
677
677
  int killing_backwards, slot;
776
776
static REFERENCE *LCD_completion;
777
777
 
778
778
/* Internal functions used by the user calls. */
779
 
static void build_completions (), completions_must_be_rebuilt ();
 
779
static void build_completions (void), completions_must_be_rebuilt (void);
780
780
 
781
781
/* Variable which holds the output of completions. */
782
782
static NODE *possible_completions_output_node = (NODE *)NULL;
785
785
 
786
786
/* Return non-zero if WINDOW is a window used for completions output. */
787
787
static int
788
 
completions_window_p (window)
789
 
     WINDOW *window;
 
788
completions_window_p (WINDOW *window)
790
789
{
791
790
  int result = 0;
792
791
 
800
799
/* Workhorse for completion readers.  If FORCE is non-zero, the user cannot
801
800
   exit unless the line read completes, or is empty. */
802
801
char *
803
 
info_read_completing_internal (window, prompt, completions, force)
804
 
     WINDOW *window;
805
 
     char *prompt;
806
 
     REFERENCE **completions;
807
 
     int force;
 
802
info_read_completing_internal (WINDOW *window, char *prompt,
 
803
    REFERENCE **completions, int force)
808
804
{
809
805
  char *line;
810
806
 
869
865
          if (i == completions_found_index)
870
866
            {
871
867
              if (!completions_found_index)
872
 
                inform_in_echo_area (_("No completions"));
 
868
                inform_in_echo_area ((char *) _("No completions"));
873
869
              else
874
 
                inform_in_echo_area (_("Not complete"));
 
870
                inform_in_echo_area ((char *) _("Not complete"));
875
871
              continue;
876
872
            }
877
873
        }
897
893
  
898
894
/* Read a line in the echo area with completion over COMPLETIONS. */
899
895
char *
900
 
info_read_completing_in_echo_area (window, prompt, completions)
901
 
     WINDOW *window;
902
 
     char *prompt;
903
 
     REFERENCE **completions;
 
896
info_read_completing_in_echo_area (WINDOW *window,
 
897
    char *prompt, REFERENCE **completions)
904
898
{
905
899
  return (info_read_completing_internal (window, prompt, completions, 1));
906
900
}
908
902
/* Read a line in the echo area allowing completion over COMPLETIONS, but
909
903
   not requiring it. */
910
904
char *
911
 
info_read_maybe_completing (window, prompt, completions)
912
 
     WINDOW *window;
913
 
     char *prompt;
914
 
     REFERENCE **completions;
 
905
info_read_maybe_completing (WINDOW *window,
 
906
    char *prompt, REFERENCE **completions)
915
907
{
916
908
  return (info_read_completing_internal (window, prompt, completions, 0));
917
909
}
929
921
  if (!completions_found_index)
930
922
    {
931
923
      terminal_ring_bell ();
932
 
      inform_in_echo_area (_("No completions"));
 
924
      inform_in_echo_area ((char *) _("No completions"));
933
925
    }
934
926
  else if ((completions_found_index == 1) && (key != '?'))
935
927
    {
936
 
      inform_in_echo_area (_("Sole completion"));
 
928
      inform_in_echo_area ((char *) _("Sole completion"));
937
929
    }
938
930
  else
939
931
    {
940
932
      register int i, l;
941
 
      int limit, count, max_label = 0;
 
933
      int limit, iterations, max_label = 0;
942
934
 
943
935
      initialize_message_buffer ();
944
936
      printf_to_message_buffer (completions_found_index == 1
945
 
                                ? _("One completion:\n")
946
 
                                : _("%d completions:\n"),
947
 
                                completions_found_index);
 
937
                                ? (char *) _("One completion:\n")
 
938
                                : (char *) _("%d completions:\n"),
 
939
                                (void *) (long) completions_found_index,
 
940
                                NULL, NULL);
948
941
 
949
942
      /* Find the maximum length of a label. */
950
943
      for (i = 0; i < completions_found_index; i++)
967
960
        limit = 1;
968
961
 
969
962
      /* How many iterations of the printing loop? */
970
 
      count = (completions_found_index + (limit - 1)) / limit;
 
963
      iterations = (completions_found_index + (limit - 1)) / limit;
971
964
 
972
965
      /* Watch out for special case.  If the number of completions is less
973
966
         than LIMIT, then just do the inner printing loop. */
974
967
      if (completions_found_index < limit)
975
 
        count = 1;
 
968
        iterations = 1;
976
969
 
977
970
      /* Print the sorted items, up-and-down alphabetically. */
978
 
      for (i = 0; i < count; i++)
 
971
      for (i = 0; i < iterations; i++)
979
972
        {
980
973
          register int j;
981
974
 
990
983
 
991
984
                  label = completions_found[l]->label;
992
985
                  printed_length = strlen (label);
993
 
                  printf_to_message_buffer ("%s", label);
 
986
                  printf_to_message_buffer ("%s", label, NULL, NULL);
994
987
 
995
988
                  if (j + 1 < limit)
996
989
                    {
997
990
                      for (k = 0; k < max_label - printed_length; k++)
998
 
                        printf_to_message_buffer (" ");
 
991
                        printf_to_message_buffer (" ", NULL, NULL, NULL);
999
992
                    }
1000
993
                }
1001
 
              l += count;
 
994
              l += iterations;
1002
995
            }
1003
 
          printf_to_message_buffer ("\n");
 
996
          printf_to_message_buffer ("\n", NULL, NULL, NULL);
1004
997
        }
1005
998
 
1006
999
      /* Make a new node to hold onto possible completions.  Don't destroy
1028
1021
          {
1029
1022
            /* If we can split the window to display most of the completion
1030
1023
               items, then do so. */
1031
 
            if (calling_window->height > (count * 2)
 
1024
            if (calling_window->height > (iterations * 2)
1032
1025
                && calling_window->height / 2 >= WINDOW_MIN_SIZE)
1033
1026
              {
1034
1027
                int start, pagetop;
1046
1039
                  window_make_window (possible_completions_output_node);
1047
1040
                active_window = the_echo_area;
1048
1041
                window_change_window_height
1049
 
                  (compwin, -(compwin->height - (count + 2)));
 
1042
                  (compwin, -(compwin->height - (iterations + 2)));
1050
1043
 
1051
1044
                window_adjust_pagetop (calling_window);
1052
1045
                remember_calling_window (calling_window);
1105
1098
      return;
1106
1099
    }
1107
1100
 
1108
 
  if (ea_last_executed_command == ea_complete)
 
1101
  if (ea_last_executed_command == (VFunction *) ea_complete)
1109
1102
    {
1110
1103
      /* If the keypress is a SPC character, and we have already tried
1111
1104
         completing once, and there are several completions, then check
1153
1146
}
1154
1147
 
1155
1148
/* Utility REFERENCE used to store possible LCD. */
1156
 
static REFERENCE LCD_reference = { (char *)NULL, (char *)NULL, (char *)NULL };
 
1149
static REFERENCE LCD_reference = {
 
1150
    (char *)NULL, (char *)NULL, (char *)NULL, 0, 0, 0
 
1151
};
1157
1152
 
1158
 
static void remove_completion_duplicates ();
 
1153
static void remove_completion_duplicates (void);
1159
1154
 
1160
1155
/* Variables which remember the state of the most recent call
1161
1156
   to build_completions (). */
1164
1159
 
1165
1160
/* How to tell the completion builder to reset internal state. */
1166
1161
static void
1167
 
completions_must_be_rebuilt ()
 
1162
completions_must_be_rebuilt (void)
1168
1163
{
1169
1164
  maybe_free (last_completion_request);
1170
1165
  last_completion_request = (char *)NULL;
1174
1169
/* Build a list of possible completions from echo_area_completion_items,
1175
1170
   and the contents of input_line. */
1176
1171
static void
1177
 
build_completions ()
 
1172
build_completions (void)
1178
1173
{
1179
1174
  register int i, len;
1180
1175
  register REFERENCE *entry;
1222
1217
      if (!informed_of_lengthy_job && completions_found_index > 100)
1223
1218
        {
1224
1219
          informed_of_lengthy_job = 1;
1225
 
          window_message_in_echo_area (_("Building completions..."));
 
1220
          window_message_in_echo_area ((char *) _("Building completions..."),
 
1221
              NULL, NULL);
1226
1222
        }
1227
1223
    }
1228
1224
 
1291
1287
 
1292
1288
/* Function called by qsort. */
1293
1289
static int
1294
 
compare_references (entry1, entry2)
1295
 
     REFERENCE **entry1, **entry2;
 
1290
compare_references (const void *entry1, const void *entry2)
1296
1291
{
1297
 
  return (strcasecmp ((*entry1)->label, (*entry2)->label));
 
1292
  REFERENCE **e1 = (REFERENCE **) entry1;
 
1293
  REFERENCE **e2 = (REFERENCE **) entry2;
 
1294
 
 
1295
  return (strcasecmp ((*e1)->label, (*e2)->label));
1298
1296
}
1299
1297
 
1300
1298
/* Prune duplicate entries from COMPLETIONS_FOUND. */
1301
1299
static void
1302
 
remove_completion_duplicates ()
 
1300
remove_completion_duplicates (void)
1303
1301
{
1304
1302
  register int i, j;
1305
1303
  REFERENCE **temp;
1359
1357
/* Function which gets called when an Info window is deleted while the
1360
1358
   echo area is active.  WINDOW is the window which has just been deleted. */
1361
1359
void
1362
 
echo_area_inform_of_deleted_window (window)
1363
 
     WINDOW *window;
 
1360
echo_area_inform_of_deleted_window (WINDOW *window)
1364
1361
{
1365
1362
  /* If this is the calling_window, forget what we remembered about it. */
1366
1363
  if (window == calling_window)
1400
1397
 
1401
1398
/* Pushing the echo_area has a side effect of zeroing the completion_items. */
1402
1399
static void
1403
 
push_echo_area ()
 
1400
push_echo_area (void)
1404
1401
{
1405
1402
  PUSHED_EA *pushed;
1406
1403
 
1422
1419
}
1423
1420
 
1424
1421
static void
1425
 
pop_echo_area ()
 
1422
pop_echo_area (void)
1426
1423
{
1427
1424
  PUSHED_EA *popped;
1428
1425
 
1460
1457
/* Returns non-zero if any of the prior stacked calls to read in the echo
1461
1458
   area produced a completions window. */
1462
1459
static int
1463
 
echo_area_stack_contains_completions_p ()
 
1460
echo_area_stack_contains_completions_p (void)
1464
1461
{
1465
1462
  register int i;
1466
1463
 
1483
1480
#endif /* HAVE_SYS_TIME_H */
1484
1481
 
1485
1482
static void
1486
 
pause_or_input ()
 
1483
pause_or_input (void)
1487
1484
{
1488
1485
#ifdef FD_SET
1489
1486
  struct timeval timer;
1503
1500
   for input or a couple of seconds, whichever comes first.  Then flush the
1504
1501
   informational message that was printed. */
1505
1502
void
1506
 
inform_in_echo_area (message)
1507
 
     char *message;
 
1503
inform_in_echo_area (const char *message)
1508
1504
{
1509
 
  register int i;
 
1505
  int i;
1510
1506
  char *text;
 
1507
  int avail = EA_MAX_INPUT + 1 - input_line_end;
1511
1508
 
1512
1509
  text = xstrdup (message);
1513
 
  for (i = 0; text[i] && text[i] != '\n'; i++)
 
1510
  for (i = 0; text[i] && text[i] != '\n' && i < avail; i++)
1514
1511
    ;
1515
1512
  text[i] = 0;
1516
1513