/[grub]/grub/stage2/char_io.c
ViewVC logotype

Diff of /grub/stage2/char_io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.46 by okuji, Mon Mar 25 21:43:55 2002 UTC revision 1.47 by okuji, Tue Jun 11 16:36:54 2002 UTC
# Line 19  Line 19 
19   */   */
20    
21  #include <shared.h>  #include <shared.h>
22    #include <term.h>
23    
24  #ifdef SUPPORT_HERCULES  #ifdef SUPPORT_HERCULES
25  # include <hercules.h>  # include <hercules.h>
# Line 29  Line 30 
30  #endif  #endif
31    
32  #ifndef STAGE1_5  #ifndef STAGE1_5
33  int auto_fill = 1;  struct term_entry term_table[] =
34      {
35        {
36          "console",
37          0,
38          console_putchar,
39          console_checkkey,
40          console_getkey,
41          console_getxy,
42          console_gotoxy,
43          console_cls,
44          console_highlight,
45          console_setcolor,
46          console_nocursor
47        },
48    #ifdef SUPPORT_SERIAL
49        {
50          "serial",
51          /* A serial device must be initialized.  */
52          TERM_NEED_INIT,
53          serial_putchar,
54          serial_checkkey,
55          serial_getkey,
56          serial_getxy,
57          serial_gotoxy,
58          serial_cls,
59          serial_highlight,
60          0,
61          0
62        },
63    #endif /* SUPPORT_SERIAL */
64    #ifdef SUPPORT_HERCULES
65        {
66          "hercules",
67          0,
68          hercules_putchar,
69          console_checkkey,
70          console_getkey,
71          hercules_getxy,
72          hercules_gotoxy,
73          hercules_cls,
74          hercules_highlight,
75          hercules_setcolor,
76          hercules_nocursor
77        },      
78    #endif /* SUPPORT_HERCULES */
79        /* This must be the last entry.  */
80        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
81      };
82    
83    /* This must be console.  */
84    struct term_entry *current_term = term_table;
85    
86  int max_lines = 24;  int max_lines = 24;
87  int count_lines = -1;  int count_lines = -1;
88  int use_pager = 1;  int use_pager = 1;
# Line 101  grub_printf (const char *format,...) Line 154  grub_printf (const char *format,...)
154    while ((c = *(format++)) != 0)    while ((c = *(format++)) != 0)
155      {      {
156        if (c != '%')        if (c != '%')
157          putchar (c);          grub_putchar (c);
158        else        else
159          switch (c = *(format++))          switch (c = *(format++))
160            {            {
# Line 120  grub_printf (const char *format,...) Line 173  grub_printf (const char *format,...)
173              ptr = str;              ptr = str;
174    
175              while (*ptr)              while (*ptr)
176                putchar (*(ptr++));                grub_putchar (*(ptr++));
177              break;              break;
178    
179  #ifndef STAGE1_5  #ifndef STAGE1_5
180            case 'c':            case 'c':
181              putchar ((*(dataptr++)) & 0xff);              grub_putchar ((*(dataptr++)) & 0xff);
182              break;              break;
183    
184            case 's':            case 's':
185              ptr = (char *) (*(dataptr++));              ptr = (char *) (*(dataptr++));
186    
187              while ((c = *(ptr++)) != 0)              while ((c = *(ptr++)) != 0)
188                putchar (c);                grub_putchar (c);
189              break;              break;
190  #endif  #endif
191            }            }
# Line 220  add_history (const char *cmdline, int no Line 273  add_history (const char *cmdline, int no
273      num_history++;      num_history++;
274  }  }
275    
276  /* Don't use this with a MAXLEN greater than 1600 or so!  The problem  static int
277     is that GET_CMDLINE depends on the everything fitting on the screen  real_get_cmdline (char *prompt, char *cmdline, int maxlen,
278     at once.  So, the whole screen is about 2000 characters, minus the                    int echo_char, int readline)
    PROMPT, and space for error and status lines, etc.  MAXLEN must be  
    at least 1, and PROMPT and CMDLINE must be valid strings (not NULL  
    or zero-length).  
   
    If ECHO_CHAR is nonzero, echo it instead of the typed character. */  
 int  
 get_cmdline (char *prompt, char *cmdline, int maxlen,  
              int echo_char, int readline)  
279  {  {
280    /* This is a rather complicated function. So explain the concept.    /* This is a rather complicated function. So explain the concept.
281            
# Line 279  get_cmdline (char *prompt, char *cmdline Line 324  get_cmdline (char *prompt, char *cmdline
324    char *buf = (char *) CMDLINE_BUF;    char *buf = (char *) CMDLINE_BUF;
325    /* The kill buffer.  */    /* The kill buffer.  */
326    char *kill_buf = (char *) KILL_BUF;    char *kill_buf = (char *) KILL_BUF;
   /* The original state of AUTO_FILL.  */  
   int saved_auto_fill = auto_fill;  
327        
328    /* Nested function definitions for code simplicity.  */    /* Nested function definitions for code simplicity.  */
329    
# Line 308  get_cmdline (char *prompt, char *cmdline Line 351  get_cmdline (char *prompt, char *cmdline
351          {          {
352            xpos -= count;            xpos -= count;
353    
354            if ((terminal & TERMINAL_CONSOLE)            if (current_term->flags & TERM_DUMB)
 # ifdef SUPPORT_HERCULES  
               || (terminal & TERMINAL_HERCULES)  
 # endif /* SUPPORT_HERCULES */  
               )  
             {  
               int y = getxy () & 0xFF;  
                 
               gotoxy (xpos, y);  
             }  
 # ifdef SUPPORT_SERIAL  
           else if (! (terminal & TERMINAL_DUMB) && (count > 4))  
             {  
               grub_printf ("\e[%dD", count);  
             }  
           else  
355              {              {
356                int i;                int i;
357                                
358                for (i = 0; i < count; i++)                for (i = 0; i < count; i++)
359                  grub_putchar ('\b');                  grub_putchar ('\b');
360              }              }
361  # endif /* SUPPORT_SERIAL */            else
362                gotoxy (xpos, getxy () & 0xFF);
363          }          }
364      }      }
365    
# Line 346  get_cmdline (char *prompt, char *cmdline Line 375  get_cmdline (char *prompt, char *cmdline
375          {          {
376            xpos += count;            xpos += count;
377    
378            if ((terminal & TERMINAL_CONSOLE)            if (current_term->flags & TERM_DUMB)
 # ifdef SUPPORT_HERCULES  
               || (terminal & TERMINAL_HERCULES)  
 # endif /* SUPPORT_HERCULES */  
               )  
             {  
               int y = getxy () & 0xFF;  
                 
               gotoxy (xpos, y);  
             }  
 # ifdef SUPPORT_SERIAL  
           else if (! (terminal & TERMINAL_DUMB) && (count > 4))  
             {  
               grub_printf ("\e[%dC", count);  
             }  
           else  
379              {              {
380                int i;                int i;
381                                
# Line 373  get_cmdline (char *prompt, char *cmdline Line 387  get_cmdline (char *prompt, char *cmdline
387                      grub_putchar (echo_char);                      grub_putchar (echo_char);
388                  }                  }
389              }              }
390  # endif /* SUPPORT_SERIAL */            else
391                gotoxy (xpos, getxy () & 0xFF);
392          }          }
393      }      }
394    
# Line 388  get_cmdline (char *prompt, char *cmdline Line 403  get_cmdline (char *prompt, char *cmdline
403        if (full)        if (full)
404          {          {
405            /* Recompute the section number.  */            /* Recompute the section number.  */
406            if ((terminal & TERMINAL_DUMB)            if (lpos + plen < CMDLINE_WIDTH)
               || (lpos + plen < CMDLINE_WIDTH))  
407              section = 0;              section = 0;
408            else            else
409              section = ((lpos + plen - CMDLINE_WIDTH)              section = ((lpos + plen - CMDLINE_WIDTH)
# Line 453  get_cmdline (char *prompt, char *cmdline Line 467  get_cmdline (char *prompt, char *cmdline
467            pos++;            pos++;
468          }          }
469                
470        if (! (terminal & TERMINAL_DUMB))        /* Fill up the rest of the line with spaces.  */
471          for (; i < start + len; i++)
472            {
473              grub_putchar (' ');
474              pos++;
475            }
476          
477          /* If the cursor is at the last position, put `>' or a space,
478             depending on if there are more characters in BUF.  */
479          if (pos == CMDLINE_WIDTH)
480          {          {
481           /* Fill up the rest of the line with spaces.  */            if (start + len < llen)
482           for (; i < start + len; i++)              grub_putchar ('>');
483             {            else
484               grub_putchar (' ');              grub_putchar (' ');
              pos++;  
            }  
485                        
486           /* If the cursor is at the last position, put `>' or a space,            pos++;
487              depending on if there are more characters in BUF.  */          }
488           if (pos == CMDLINE_WIDTH)        
489             {        /* Back to XPOS.  */
490               if (start + len < llen)        if (current_term->flags & TERM_DUMB)
491                 grub_putchar ('>');          {
492               else            for (i = 0; i < pos - xpos; i++)
493                 grub_putchar (' ');              grub_putchar ('\b');
494                        }
495               pos++;        else
496             }          gotoxy (xpos, getxy () & 0xFF);
           
          /* Back to XPOS.  */  
          if ((terminal & TERMINAL_CONSOLE)  
 # ifdef SUPPORT_HERCULES  
              || (terminal & TERMINAL_HERCULES)  
 # endif /* SUPPORT_HERCULES */  
              )  
            {  
              int y = getxy () & 0xFF;  
               
              gotoxy (xpos, y);  
            }  
 # ifdef SUPPORT_SERIAL        
          else if (! (terminal & TERMINAL_SERIAL) && (pos - xpos > 4))  
            {  
              grub_printf ("\e[%dD", pos - xpos);  
            }  
          else  
            {  
              for (i = 0; i < pos - xpos; i++)  
                grub_putchar ('\b');  
            }  
 # endif /* SUPPORT_SERIAL */  
        }  
497      }      }
498    
499    /* Initialize the command-line.  */    /* Initialize the command-line.  */
# Line 562  get_cmdline (char *prompt, char *cmdline Line 559  get_cmdline (char *prompt, char *cmdline
559    lpos = llen;    lpos = llen;
560    grub_strcpy (buf, cmdline);    grub_strcpy (buf, cmdline);
561    
   /* Disable the auto fill mode.  */  
   auto_fill = 0;  
     
562    cl_init ();    cl_init ();
563    
564    while (ASCII_CHAR (c = getkey ()) != '\n' && ASCII_CHAR (c) != '\r')    while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
565      {      {
       c = translate_keycode (c);  
         
566        /* If READLINE is non-zero, handle readline-like key bindings.  */        /* If READLINE is non-zero, handle readline-like key bindings.  */
567        if (readline)        if (readline)
568          {          {
# Line 617  get_cmdline (char *prompt, char *cmdline Line 609  get_cmdline (char *prompt, char *cmdline
609                     completion.  */                     completion.  */
610                  grub_memmove (completion_buffer, buf + i, lpos - i);                  grub_memmove (completion_buffer, buf + i, lpos - i);
611                  completion_buffer[lpos - i] = 0;                  completion_buffer[lpos - i] = 0;
                 /* Enable the auto fill mode temporarily.  */  
                 auto_fill = 1;  
612                  ret = print_completions (is_filename, 1);                  ret = print_completions (is_filename, 1);
                 /* Disable the auto fill mode again.  */  
                 auto_fill = 0;  
613                  errnum = ERR_NONE;                  errnum = ERR_NONE;
614    
615                  if (ret >= 0)                  if (ret >= 0)
# Line 633  get_cmdline (char *prompt, char *cmdline Line 621  get_cmdline (char *prompt, char *cmdline
621                        {                        {
622                          /* There are more than one candidates, so print                          /* There are more than one candidates, so print
623                             the list.  */                             the list.  */
   
624                          grub_putchar ('\n');                          grub_putchar ('\n');
                         /* Enable the auto fill mode temporarily.  */  
                         auto_fill = 1;  
625                          print_completions (is_filename, 0);                          print_completions (is_filename, 0);
                         /* Disable the auto fill mode again.  */  
                         auto_fill = 0;  
626                          errnum = ERR_NONE;                          errnum = ERR_NONE;
627                        }                        }
628                    }                    }
# Line 792  get_cmdline (char *prompt, char *cmdline Line 775  get_cmdline (char *prompt, char *cmdline
775    if (readline && lpos < llen)    if (readline && lpos < llen)
776      add_history (cmdline, 0);      add_history (cmdline, 0);
777    
   /* Restore the auto fill mode.  */  
   auto_fill = saved_auto_fill;  
     
778    return 0;    return 0;
779  }  }
780    
781  /* Translate a special key to a common ascii code.  */  /* Don't use this with a MAXLEN greater than 1600 or so!  The problem
782       is that GET_CMDLINE depends on the everything fitting on the screen
783       at once.  So, the whole screen is about 2000 characters, minus the
784       PROMPT, and space for error and status lines, etc.  MAXLEN must be
785       at least 1, and PROMPT and CMDLINE must be valid strings (not NULL
786       or zero-length).
787    
788       If ECHO_CHAR is nonzero, echo it instead of the typed character. */
789  int  int
790  translate_keycode (int c)  get_cmdline (char *prompt, char *cmdline, int maxlen,
791                 int echo_char, int readline)
792  {  {
793  # ifdef SUPPORT_SERIAL    /* Because it is hard to deal with different conditions simultaneously,
794    if (terminal & TERMINAL_SERIAL)       less functional cases are handled here. Assume that TERM_NO_ECHO
795         implies TERM_NO_EDIT.  */
796      if (current_term->flags & (TERM_NO_ECHO | TERM_NO_EDIT))
797      {      {
798        /* In a serial terminal, things are complicated, because several        char *p = cmdline;
799           key codes start from the character ESC, while we want to accept        int c;
800           ESC itself.  */        
801        if (c == '\e')        /* Make sure that MAXLEN is not too large.  */
802          {        if (maxlen > MAX_CMDLINE)
803            int start;          maxlen = MAX_CMDLINE;
804    
805            /* Get current time.  */        /* Print only the prompt. The contents of CMDLINE is simply discarded,
806            start = currticks ();           even if it is not empty.  */
807          grub_printf ("%s", prompt);
808    
809            while (checkkey () == -1)        /* Gather characters until a newline is gotten.  */
810              {        while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
811                /* Wait for a next character, at least for 0.1 sec          {
812                   (18.2 ticks/sec).  */            /* Return immediately if ESC is pressed.  */
813                int now;            if (c == 27)
814                              return 1;
               now = currticks ();  
               if (now - start >= 2)  
                 return c;  
             }  
815    
816            c = getkey ();            /* Printable characters are added into CMDLINE.  */
817            if (c == '[')            if (c >= ' ' && c <= '~')
818              {              {
819                int c1, c2;                if (! (current_term->flags & TERM_NO_ECHO))
820                    grub_putchar (c);
821    
822                /* To filter illegal states.  */                /* Preceding space characters must be ignored.  */
823                c = 0;                if (c != ' ' || p != cmdline)
824                c1 = getkey ();                  *p++ = c;
               switch (c1)  
                 {  
                 case 'A':       /* KEY_UP */  
                   c = 16;  
                   break;  
                 case 'B':       /* KEY_DOWN */  
                   c = 14;  
                   break;  
                 case 'C':       /* KEY_RIGHT */  
                   c = 6;  
                   break;  
                 case 'D':       /* KEY_LEFT */  
                   c = 2;  
                   break;  
                 case 'F':       /* End */  
                   c = 5;  
                   break;  
                 case 'H':       /* Home */  
                   c = 1;  
                   break;  
                 case '1':  
                   c2 = getkey ();  
                   if (c2 == '~')  
                     {  
                       /* One of control keys (pos1,....).  */  
                       c = 1;  
                     }  
                   break;  
                 case '3':  
                   c2 = getkey ();  
                   if (c2 == '~')  
                     {  
                       /* One of control keys (del,....).  */  
                       c = 4;  
                     }  
                   break;  
                 case '4':       /* Del */  
                   c = 4;  
                   break;  
                 }  
825              }              }
826          }          }
827    
828          *p = 0;
829    
830          if (! (current_term->flags & TERM_NO_ECHO))
831            grub_putchar ('\n');
832          
833          return 0;
834      }      }
835    else  
836  # endif /* SUPPORT_SERIAL */    /* Complicated features are left to real_get_cmdline.  */
837      {    return real_get_cmdline (prompt, cmdline, maxlen, echo_char, readline);
       switch (c)  
         {  
         case KEY_LEFT:  
           c = 2;  
           break;  
         case KEY_RIGHT:  
           c = 6;  
           break;  
         case KEY_UP:  
           c = 16;  
           break;  
         case KEY_DOWN:  
           c = 14;  
           break;  
         case KEY_HOME:  
           c = 1;  
           break;  
         case KEY_END:  
           c = 5;  
           break;  
         case KEY_DC:  
           c = 4;  
           break;  
         case KEY_BACKSPACE:  
           c = 8;  
           break;  
         }  
     }  
     
   return ASCII_CHAR (c);  
838  }  }
839  #endif /* STAGE1_5 */  #endif /* STAGE1_5 */
840    
# Line 1029  grub_strncat (char *s1, const char *s2, Line 954  grub_strncat (char *s1, const char *s2,
954     a static library supporting minimal standard C functions and link     a static library supporting minimal standard C functions and link
955     each image with the library. Complicated things should be left to     each image with the library. Complicated things should be left to
956     computer, definitely. -okuji  */     computer, definitely. -okuji  */
957  #if ! defined(STAGE1_5) || defined(FSYS_VSTAFS)  #if !defined(STAGE1_5) || defined(FSYS_VSTAFS)
958  int  int
959  grub_strcmp (const char *s1, const char *s2)  grub_strcmp (const char *s1, const char *s2)
960  {  {
# Line 1052  grub_strcmp (const char *s1, const char Line 977  grub_strcmp (const char *s1, const char
977  int  int
978  getkey (void)  getkey (void)
979  {  {
980    int c = -1;    return current_term->getkey ();
     
   if ((terminal & TERMINAL_CONSOLE)  
 #ifdef SUPPORT_HERCULES  
       || (terminal & TERMINAL_HERCULES)  
 #endif /* SUPPORT_HERCULES */  
       )  
     c = console_getkey ();  
 #ifdef SUPPORT_SERIAL  
   else if (terminal & TERMINAL_SERIAL)  
     c = serial_getkey ();  
 #endif /* SUPPORT_SERIAL */  
   
   return c;  
981  }  }
982    
983  /* Check if a key code is available.  */  /* Check if a key code is available.  */
984  int  int
985  checkkey (void)  checkkey (void)
986  {  {
987    int c = -1;    return current_term->checkkey ();
   
   if ((terminal & TERMINAL_CONSOLE)  
 #ifdef SUPPORT_HERCULES  
       || (terminal & TERMINAL_HERCULES)  
 #endif /* SUPPORT_HERCULES */  
       )  
     c = console_checkkey ();  
     
 #ifdef SUPPORT_SERIAL  
   if (terminal & TERMINAL_SERIAL)  
     c = serial_checkkey ();  
 #endif /* SUPPORT_SERIAL */  
   
   return c;  
988  }  }
   
989  #endif /* ! STAGE1_5 */  #endif /* ! STAGE1_5 */
990    
991  /* Display an ASCII character.  */  /* Display an ASCII character.  */
992  void  void
993  grub_putchar (int c)  grub_putchar (int c)
994  {  {
 #ifndef STAGE1_5  
   static int col = 0;  
 #endif  
     
995    if (c == '\n')    if (c == '\n')
996      grub_putchar ('\r');      grub_putchar ('\r');
997    #ifndef STAGE1_5
998      else if (c == '\t' && current_term->getxy)
999        {
1000          int n;
1001          
1002          n = 8 - ((current_term->getxy () >> 8) & 3);
1003          while (n--)
1004            grub_putchar (' ');
1005          
1006          return;
1007        }
1008    #endif /* ! STAGE1_5 */
1009        
1010  #ifdef STAGE1_5  #ifdef STAGE1_5
1011        
# Line 1109  grub_putchar (int c) Line 1014  grub_putchar (int c)
1014        
1015  #else /* ! STAGE1_5 */  #else /* ! STAGE1_5 */
1016    
1017    /* Track the cursor by software here.  */    if (c == '\n')
   /* XXX: This doesn't handle horizontal or vertical tabs.  */  
   if (c == '\r')  
     col = 0;  
   else if (c == '\b')  
     {  
       if (col > 0)  
         col--;  
     }  
   else if (c >= ' ' && c <= '~')  
     {  
       /* Fold a line only if AUTO_FILL is true.  */  
       if (auto_fill && col >= 79)  
         grub_putchar ('\n');  
   
       col++;  
     }  
   else if (c == '\n')  
1018      {      {
1019        /* Internal `more'-like feature.  */        /* Internal `more'-like feature.  */
1020        if (count_lines != -1)        if (count_lines >= 0)
1021          {          {
1022            count_lines++;            count_lines++;
1023            if (count_lines >= max_lines - 2)            if (count_lines >= max_lines - 2)
# Line 1139  grub_putchar (int c) Line 1027  grub_putchar (int c)
1027                /* It's important to disable the feature temporarily, because                /* It's important to disable the feature temporarily, because
1028                   the following grub_printf call will print newlines.  */                   the following grub_printf call will print newlines.  */
1029                count_lines = -1;                count_lines = -1;
1030    
1031                  if (current_term->highlight)
1032                    current_term->highlight (1);
1033                  
1034                  grub_printf ("\n[Hit return to continue]");
1035    
1036                  if (current_term->highlight)
1037                    current_term->highlight (0);
1038                                
               grub_printf ("\n\n[Hit return to continue]");  
1039                do                do
1040                  {                  {
1041                    tmp = ASCII_CHAR (getkey ());                    tmp = ASCII_CHAR (getkey ());
1042                  }                  }
1043                while (tmp != '\n' && tmp != '\r');                while (tmp != '\n' && tmp != '\r');
1044                grub_printf ("\n\n");                grub_printf ("\r                        \r");
1045                                
1046                /* Restart to count lines.  */                /* Restart to count lines.  */
1047                count_lines = 0;                count_lines = 0;
# Line 1155  grub_putchar (int c) Line 1050  grub_putchar (int c)
1050          }          }
1051      }      }
1052    
1053    if (terminal & TERMINAL_CONSOLE)    current_term->putchar (c);
     console_putchar (c);  
   
 # ifdef SUPPORT_HERCULES  
   if (terminal & TERMINAL_HERCULES)  
     herc_putchar (c);  
 # endif /* SUPPORT_HERCULES */  
   
 # ifdef SUPPORT_SERIAL  
   if (terminal & TERMINAL_SERIAL)  
     serial_putchar (c);  
 # endif /* SUPPORT_SERIAL */  
1054        
1055  #endif /* ! STAGE1_5 */  #endif /* ! STAGE1_5 */
1056  }  }
# Line 1175  grub_putchar (int c) Line 1059  grub_putchar (int c)
1059  void  void
1060  gotoxy (int x, int y)  gotoxy (int x, int y)
1061  {  {
1062    if (terminal & TERMINAL_CONSOLE)    current_term->gotoxy (x, y);
     console_gotoxy (x, y);  
 #ifdef SUPPORT_HERCULES  
   else if (terminal & TERMINAL_HERCULES)  
     herc_gotoxy (x, y);  
 #endif /* SUPPORT_HERCULES */  
 #ifdef SUPPORT_SERIAL  
   else if (terminal & TERMINAL_SERIAL)  
     serial_gotoxy (x, y);  
 #endif /* SUPPORT_SERIAL */  
 }  
   
 #ifdef SUPPORT_SERIAL  
 /* The serial part of gotoxy.  */  
 void  
 serial_gotoxy (int x, int y)  
 {  
   grub_printf ("\e[%d;%dH", y + 1, x + 1);  
1063  }  }
 #endif /* SUPPORT_SERIAL */  
1064    
1065  int  int
1066  getxy (void)  getxy (void)
1067  {  {
1068    int ret = 0;    return current_term->getxy ();
     
   if (terminal & TERMINAL_CONSOLE)  
     ret = console_getxy ();  
 #ifdef SUPPORT_HERCULES  
   else if (terminal & TERMINAL_HERCULES)  
     ret = herc_getxy ();  
 #endif /* SUPPORT_HERCULES */  
 #ifdef SUPPORT_SERIAL  
   else if (terminal & TERMINAL_SERIAL)  
     ret = serial_getxy ();  
 #endif /* SUPPORT_SERIAL */  
     
   return ret;  
1069  }  }
1070    
 #ifdef SUPPORT_SERIAL  
 /* The serial part of getxy.  */  
 int  
 serial_getxy (void)  
 {  
   int x, y;  
   int start, now;  
   char buf[32]; /* XXX */  
   int i;  
   int c;  
   char *p;  
     
   /* Drain the input buffer.  */  
   while (serial_checkkey () != -1)  
     serial_getkey ();  
   
   /* CPR.  */  
   grub_printf ("\e[6n");  
   
   /* Get current time.  */  
   while ((start = getrtsecs ()) == 0xFF)  
     ;  
   
  again:  
   i = 0;  
   c = 0;  
   do  
     {  
       if (serial_checkkey () != -1)  
         {  
           c = serial_getkey ();  
           if (i == 1 && c != '[')  
             i = 0;  
             
           if (i == 0 && c != '\e')  
             continue;  
   
           if (i != 0 && c == '\e')  
             i = 0;  
   
           buf[i] = c;  
           i++;  
         }  
       else  
         {  
           /* Get current time.  */  
           while ((now = getrtsecs ()) == 0xFF)  
             ;  
   
           /* FIXME: Remove this magic number.  */  
           if (now - start > 10)  
             {  
               /* Something is quite wrong.  */  
               return 0;  
             }  
         }  
     }  
   while (c != 'R' && i < sizeof (buf));  
     
   if (c != 'R')  
     goto again;  
   
   p = buf + 2;  
   if (! safe_parse_maxint (&p, &y))  
     {  
       errnum = 0;  
       goto again;  
     }  
     
   if (*p != ';')  
     goto again;  
   
   p++;  
   if (! safe_parse_maxint (&p, &x))  
     {  
       errnum = 0;  
       goto again;  
     }  
   
   if (*p != 'R')  
     goto again;  
   
   return ((x - 1) << 8) | (y - 1);  
 }  
 #endif /* SUPPORT_SERIAL */  
   
1071  void  void
1072  cls (void)  cls (void)
1073  {  {
   if (terminal & TERMINAL_CONSOLE)  
     console_cls ();  
 #ifdef SUPPORT_HERCULES  
   else if (terminal & TERMINAL_HERCULES)  
     herc_cls ();  
 #endif /* SUPPORT_HERCULES */  
 #ifdef SUPPORT_SERIAL  
   else if (terminal & TERMINAL_SERIAL)  
     serial_cls ();  
 #endif /* SUPPORT_SERIAL */  
 }  
   
 #ifdef SUPPORT_SERIAL  
 /* The serial part of cls.  */  
 void  
 serial_cls (void)  
 {  
1074    /* If the terminal is dumb, there is no way to clean the terminal.  */    /* If the terminal is dumb, there is no way to clean the terminal.  */
1075    if (terminal & TERMINAL_DUMB)    if (current_term->flags & TERM_DUMB)
1076      grub_putchar ('\n');      grub_putchar ('\n');
1077    else    else
1078      grub_printf ("\e[H\e[J");      current_term->cls ();
1079  }  }
 #endif /* SUPPORT_SERIAL */  
1080    
1081  void  void
1082  set_attrib (int attr)  nocursor (void)
1083  {  {
1084  #ifdef SUPPORT_HERCULES    if (current_term->nocursor)
1085    if (terminal & TERMINAL_HERCULES)      current_term->nocursor ();
     herc_set_attrib (attr);  
   else  
 #endif /* SUPPORT_HERCULES */  
     console_set_attrib (attr);  
1086  }  }
1087  #endif /* ! STAGE1_5 */  #endif /* ! STAGE1_5 */
1088    

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26