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

Diff of /grub/stage2/builtins.c

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

revision 1.134 by okuji, Sat May 25 11:33:47 2002 UTC revision 1.135 by okuji, Tue Jun 11 16:36:54 2002 UTC
# Line 26  Line 26 
26    
27  #include <shared.h>  #include <shared.h>
28  #include <filesys.h>  #include <filesys.h>
29    #include <term.h>
30    
31  #ifdef SUPPORT_NETBOOT  #ifdef SUPPORT_NETBOOT
32  # define GRUB   1  # define GRUB   1
# Line 47  Line 48 
48  # include <md5.h>  # include <md5.h>
49  #endif  #endif
50    
 /* Terminal types.  */  
 int terminal = TERMINAL_CONSOLE;  
51  /* The type of kernel loaded.  */  /* The type of kernel loaded.  */
52  kernel_t kernel_type;  kernel_t kernel_type;
53  /* The boot device.  */  /* The boot device.  */
# Line 70  char *password; Line 69  char *password;
69  password_t password_type;  password_t password_type;
70  /* The flag for indicating that the user is authoritative.  */  /* The flag for indicating that the user is authoritative.  */
71  int auth = 0;  int auth = 0;
 /* Color settings.  */  
 int normal_color;  
 int highlight_color;  
72  /* The timeout.  */  /* The timeout.  */
73  int grub_timeout = -1;  int grub_timeout = -1;
74  /* Whether to show the menu or not.  */  /* Whether to show the menu or not.  */
# Line 99  void Line 95  void
95  init_config (void)  init_config (void)
96  {  {
97    default_entry = 0;    default_entry = 0;
   normal_color = A_NORMAL;  
   highlight_color = A_REVERSE;  
98    password = 0;    password = 0;
99    fallback_entry = -1;    fallback_entry = -1;
100    grub_timeout = -1;    grub_timeout = -1;
# Line 413  cat_func (char *arg, int flags) Line 407  cat_func (char *arg, int flags)
407      return 1;      return 1;
408    
409    while (grub_read (&c, 1))    while (grub_read (&c, 1))
410      grub_putchar (c);      {
411          /* Because running "cat" with a binary file can confuse the terminal,
412             print only some characters as they are.  */
413          if (grub_isspace (c) || (c >= ' ' && c <= '~'))
414            grub_putchar (c);
415          else
416            grub_putchar ('?');
417        }
418      
419    grub_close ();    grub_close ();
420    return 0;    return 0;
421  }  }
# Line 696  color_func (char *arg, int flags) Line 697  color_func (char *arg, int flags)
697          return 1;          return 1;
698      }      }
699    
700    normal_color = new_normal_color;    if (current_term->setcolor)
701    highlight_color = new_highlight_color;      current_term->setcolor (new_normal_color, new_highlight_color);
702      
703    return 0;    return 0;
704  }  }
705    
# Line 3276  static struct builtin builtin_savedefaul Line 3278  static struct builtin builtin_savedefaul
3278  static int  static int
3279  serial_func (char *arg, int flags)  serial_func (char *arg, int flags)
3280  {  {
3281    unsigned short port = serial_get_port (0);    unsigned short port = serial_hw_get_port (0);
3282    unsigned int speed = 9600;    unsigned int speed = 9600;
3283    int word_len = UART_8BITS_WORD;    int word_len = UART_8BITS_WORD;
3284    int parity = UART_NO_PARITY;    int parity = UART_NO_PARITY;
# Line 3301  serial_func (char *arg, int flags) Line 3303  serial_func (char *arg, int flags)
3303                return 1;                return 1;
3304              }              }
3305    
3306            port = serial_get_port (unit);            port = serial_hw_get_port (unit);
3307          }          }
3308        else if (grub_memcmp (arg, "--speed=", sizeof ("--speed=") - 1) == 0)        else if (grub_memcmp (arg, "--speed=", sizeof ("--speed=") - 1) == 0)
3309          {          {
# Line 3388  serial_func (char *arg, int flags) Line 3390  serial_func (char *arg, int flags)
3390              *q++ = *p++;              *q++ = *p++;
3391                        
3392            *q = 0;            *q = 0;
3393            set_serial_device (dev);            serial_set_device (dev);
3394          }          }
3395  # endif /* GRUB_UTIL */  # endif /* GRUB_UTIL */
3396        else        else
# Line 3398  serial_func (char *arg, int flags) Line 3400  serial_func (char *arg, int flags)
3400      }      }
3401    
3402    /* Initialize the serial unit.  */    /* Initialize the serial unit.  */
3403    if (! serial_init (port, speed, word_len, parity, stop_bit_len))    if (! serial_hw_init (port, speed, word_len, parity, stop_bit_len))
3404      {      {
3405        errnum = ERR_BAD_ARGUMENT;        errnum = ERR_BAD_ARGUMENT;
3406        return 1;        return 1;
# Line 3981  static struct builtin builtin_setup = Line 3983  static struct builtin builtin_setup =
3983  static int  static int
3984  terminal_func (char *arg, int flags)  terminal_func (char *arg, int flags)
3985  {  {
3986    int default_terminal = 0;    /* The index of the default terminal in TERM_TABLE.  */
3987      int default_term = -1;
3988      struct term_entry *prev_term = current_term;
3989    int to = -1;    int to = -1;
   int dumb = 0;  
   int saved_terminal = terminal;  
3990    int lines = 0;    int lines = 0;
3991    int no_message = 0;    int no_message = 0;
3992      unsigned long term_flags = 0;
3993      /* XXX: Assume less than 32 terminals.  */
3994      unsigned long term_bitmap = 0;
3995    
3996    /* Get GNU-style long options.  */    /* Get GNU-style long options.  */
3997    while (1)    while (1)
3998      {      {
3999        if (grub_memcmp (arg, "--dumb", sizeof ("--dumb") - 1) == 0)        if (grub_memcmp (arg, "--dumb", sizeof ("--dumb") - 1) == 0)
4000          dumb = 1;          term_flags |= TERM_DUMB;
4001          else if (grub_memcmp (arg, "--no-echo", sizeof ("--no-echo") - 1) == 0)
4002            /* ``--no-echo'' implies ``--no-edit''.  */
4003            term_flags |= (TERM_NO_ECHO | TERM_NO_EDIT);
4004          else if (grub_memcmp (arg, "--no-edit", sizeof ("--no-edit") - 1) == 0)
4005            term_flags |= TERM_NO_EDIT;
4006        else if (grub_memcmp (arg, "--timeout=", sizeof ("--timeout=") - 1) == 0)        else if (grub_memcmp (arg, "--timeout=", sizeof ("--timeout=") - 1) == 0)
4007          {          {
4008            char *val = arg + sizeof ("--timeout=") - 1;            char *val = arg + sizeof ("--timeout=") - 1;
# Line 4025  terminal_func (char *arg, int flags) Line 4035  terminal_func (char *arg, int flags)
4035    /* If no argument is specified, show current setting.  */    /* If no argument is specified, show current setting.  */
4036    if (! *arg)    if (! *arg)
4037      {      {
4038        if (terminal & TERMINAL_CONSOLE)        grub_printf ("%s%s%s%s\n",
4039          grub_printf ("console%s\n",                     current_term->name,
4040                       terminal & TERMINAL_DUMB ? " (dumb)" : "");                     current_term->flags & TERM_DUMB ? " (dumb)" : "",
4041  #ifdef SUPPORT_HERCULES                     current_term->flags & TERM_NO_EDIT ? " (no edit)" : "",
4042        else if (terminal & TERMINAL_HERCULES)                     current_term->flags & TERM_NO_ECHO ? " (no echo)" : "");
         grub_printf ("hercules%s\n",  
                      terminal & TERMINAL_DUMB ? " (dumb)" : "");  
 #endif /* SUPPORT_HERCULES */  
 #ifdef SUPPORT_SERIAL  
       else if (terminal & TERMINAL_SERIAL)  
         grub_printf ("serial%s\n",  
                      terminal & TERMINAL_DUMB ? " (dumb)" : " (vt100)");  
 #endif /* SUPPORT_SERIAL */  
         
4043        return 0;        return 0;
4044      }      }
4045    
   /* Clear current setting.  */  
   terminal = dumb ? TERMINAL_DUMB : 0;  
     
4046    while (*arg)    while (*arg)
4047      {      {
4048        if (grub_memcmp (arg, "console", sizeof ("console") - 1) == 0)        int i;
4049          {        char *next = skip_to (0, arg);
4050            terminal |= TERMINAL_CONSOLE;        
4051            if (! default_terminal)        nul_terminate (arg);
4052              default_terminal = TERMINAL_CONSOLE;  
4053          }        for (i = 0; term_table[i].name; i++)
 #ifdef SUPPORT_HERCULES  
       else if (grub_memcmp (arg, "hercules", sizeof ("hercules") - 1) == 0)  
         {  
           terminal |= TERMINAL_HERCULES;  
           if (! default_terminal)  
             default_terminal = TERMINAL_HERCULES;  
         }  
 #endif /* SUPPORT_HERCULES */  
 #ifdef SUPPORT_SERIAL  
       else if (grub_memcmp (arg, "serial", sizeof ("serial") - 1) == 0)  
4054          {          {
4055            if (serial_exists ())            if (grub_strcmp (arg, term_table[i].name) == 0)
4056              {              {
4057                terminal |= TERMINAL_SERIAL;                if (term_table[i].flags & TERM_NEED_INIT)
4058                if (! default_terminal)                  {
4059                  default_terminal = TERMINAL_SERIAL;                    errnum = ERR_DEV_NEED_INIT;
4060              }                    return 1;
4061            else                  }
4062              {                
4063                terminal = saved_terminal;                if (default_term < 0)
4064                errnum = ERR_NEED_SERIAL;                  default_term = i;
4065                return 1;  
4066                  term_bitmap |= (1 << i);
4067                  break;
4068              }              }
4069          }          }
4070  #endif /* SUPPORT_SERIAL */  
4071        else        if (! term_table[i].name)
4072          {          {
           terminal = saved_terminal;  
4073            errnum = ERR_BAD_ARGUMENT;            errnum = ERR_BAD_ARGUMENT;
4074            return 1;            return 1;
4075          }          }
4076    
4077        arg = skip_to (0, arg);        arg = next;
4078      }      }
4079    
4080  #ifdef SUPPORT_SERIAL    /* If multiple terminals are specified, wait until the user pushes any
4081    /* If a seial console is turned on, wait until the user pushes any key.  */       key on one of the terminals.  */
4082    if (terminal & TERMINAL_SERIAL)    if (term_bitmap & ~(1 << default_term))
4083      {      {
4084        int time1, time2 = -1;        int time1, time2 = -1;
4085    
# Line 4104  terminal_func (char *arg, int flags) Line 4093  terminal_func (char *arg, int flags)
4093        /* Wait for a key input.  */        /* Wait for a key input.  */
4094        while (to)        while (to)
4095          {          {
4096            if ((terminal & TERMINAL_CONSOLE) && console_checkkey () != -1)            int i;
             {  
               terminal &= (TERMINAL_CONSOLE | TERMINAL_DUMB);  
               (void) getkey ();  
               return 0;  
             }  
           else if ((terminal & TERMINAL_SERIAL) && serial_checkkey () != -1)  
             {  
               terminal &= (TERMINAL_SERIAL | TERMINAL_DUMB);  
               (void) getkey ();  
4097    
4098                /* If the interface is currently the command-line, restart            for (i = 0; term_table[i].name; i++)
4099                   it to repaint the screen.  */              {
4100                if (flags & BUILTIN_CMDLINE)                if (term_bitmap & (1 << i))
4101                  grub_longjmp (restart_cmdline_env, 0);                  {
4102                                    if (term_table[i].checkkey () >= 0)
4103                return 0;                      {
4104                          (void) term_table[i].getkey ();
4105                          default_term = i;
4106                          
4107                          goto end;
4108                        }
4109                    }
4110              }              }
4111              
4112            /* Prompt the user, once per sec.  */            /* Prompt the user, once per sec.  */
4113            if ((time1 = getrtsecs ()) != time2 && time1 != 0xFF)            if ((time1 = getrtsecs ()) != time2 && time1 != 0xFF)
4114              {              {
# Line 4134  terminal_func (char *arg, int flags) Line 4120  terminal_func (char *arg, int flags)
4120                  to--;                  to--;
4121              }              }
4122          }          }
   
       /* Expired.  */  
       terminal &= (default_terminal | TERMINAL_DUMB);  
4123      }      }
 #endif /* SUPPORT_SERIAL */  
4124    
4125     end:
4126      current_term = term_table + default_term;
4127      current_term->flags = term_flags;
4128      
4129    if (lines)    if (lines)
4130      max_lines = lines;      max_lines = lines;
4131    else    else
4132      /* 24 would be a good default value.  */      /* 24 would be a good default value.  */
4133      max_lines = 24;      max_lines = 24;
4134        
4135      /* If the interface is currently the command-line,
4136         restart it to repaint the screen.  */
4137      if (current_term != prev_term && (flags & BUILTIN_CMDLINE))
4138        grub_longjmp (restart_cmdline_env, 0);
4139      
4140    return 0;    return 0;
4141  }  }
4142    
# Line 4154  static struct builtin builtin_terminal = Line 4145  static struct builtin builtin_terminal =
4145    "terminal",    "terminal",
4146    terminal_func,    terminal_func,
4147    BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,    BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_HELP_LIST,
4148    "terminal [--dumb] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial]",    "terminal [--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] [--silent] [console] [serial] [hercules]",
4149    "Select a terminal. When serial is specified, wait until you push any key"    "Select a terminal. When multiple terminals are specified, wait until"
4150    " to continue. If both console and serial are specified, the terminal"    " you push any key to continue. If both console and serial are specified,"
4151    " to which you input a key first will be selected. If no argument is"    " the terminal to which you input a key first will be selected. If no"
4152    " specified, print current setting. The option --dumb specifies that"    " argument is specified, print current setting. The option --dumb"
4153    " your terminal is dumb, otherwise, vt100-compatibility is assumed."    " specifies that your terminal is dumb, otherwise, vt100-compatibility"
4154      " is assumed. If you specify --no-echo, input characters won't be echoed."
4155      " If you specify --no-edit, the BASH-like editing feature will be disabled."
4156    " If --timeout is present, this command will wait at most for SECS"    " If --timeout is present, this command will wait at most for SECS"
4157    " seconds. The option --lines specifies the maximum number of lines."    " seconds. The option --lines specifies the maximum number of lines."
4158    " The option --silent is used to suppress messages."    " The option --silent is used to suppress messages."

Legend:
Removed from v.1.134  
changed lines
  Added in v.1.135

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