char_io.c revision a5602e1bdcf9570fa24684b54cf57a3f22e05ae1
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* char_io.c - basic console input and output */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * GRUB -- GRand Unified Bootloader
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright (C) 1999,2000,2001,2002,2004 Free Software Foundation, Inc.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This program is free software; you can redistribute it and/or modify
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * it under the terms of the GNU General Public License as published by
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the Free Software Foundation; either version 2 of the License, or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (at your option) any later version.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This program is distributed in the hope that it will be useful,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * but WITHOUT ANY WARRANTY; without even the implied warranty of
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * GNU General Public License for more details.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You should have received a copy of the GNU General Public License
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * along with this program; if not, write to the Free Software
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* A serial device must be initialized. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe "composite",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* SUPPORT_SERIAL */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* SUPPORT_HERCULES */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe { "graphics",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* SUPPORT_GRAPHICS */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* This must be the last entry. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* This must be console. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* printf("\7\n %s\n", err_list[errnum]); */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe printf ("\nError %u: %s\n", errnum, err_list[errnum]);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#else /* STAGE1_5 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* STAGE1_5 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *(ptr++) = ((dig > 9) ? dig + 'a' - 10 : '0' + dig);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* reorder to correct direction!! */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((c = *(format++)) != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (c != '%')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (c = *(format++))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_printf ("\n GNU GRUB version %s (%dK lower / %dK upper memory)\n\n",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* The number of the history entries. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int num_history = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Get the NOth history. If NO is less than zero or greater than or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe equal to NUM_HISTORY, return NULL. Otherwise return a valid string. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic char *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (char *) HISTORY_BUF + MAX_CMDLINE * no;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Add CMDLINE to the history buffer. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove ((char *) HISTORY_BUF + MAX_CMDLINE * (no + 1),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_strcpy ((char *) HISTORY_BUF + MAX_CMDLINE * no, cmdline);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowereal_get_cmdline (char *prompt, char *cmdline, int maxlen,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* This is a rather complicated function. So explain the concept.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe A command-line consists of ``section''s. A section is a part of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe line which may be displayed on the screen, but a section is never
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe displayed with another section simultaneously.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Each section is basically 77 or less characters, but the exception
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is the first section, which is 78 or less characters, because the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe starting point is special. See below.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe The first section contains a prompt and a command-line (or the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe first part of a command-line when it is too long to be fit in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe screen). So, in the first section, the number of command-line
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe characters displayed is 78 minus the length of the prompt (or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe less). If the command-line has more characters, `>' is put at the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe position 78 (zero-origin), to inform the user of the hidden
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Other sections always have `<' at the first position, since there
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is absolutely a section before each section. If there is a section
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe after another section, this section consists of 77 characters and
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe `>' at the last position. The last section has 77 or less
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe characters and doesn't have `>'.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe Each section other than the last shares some characters with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe previous section. This region is called ``margin''. If the cursor
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is put at the magin which is shared by the first section and the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe second, the first section is displayed. Otherwise, a displayed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe section is switched to another section, only if the cursor is put
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe outside that section. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* XXX: These should be defined in shared.h, but I leave these here,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe until this code is freezed. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The length of PROMPT. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The length of the command-line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The index for the history. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The working buffer for the command-line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The kill buffer. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Nested function definitions for code simplicity. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* The forward declarations of nested functions are prefixed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe with `auto'. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe auto void cl_init (void);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Move the cursor backward. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the cursor is in the first section, display the first section
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe instead of the second. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (section == 1 && plen + lpos < CMDLINE_WIDTH)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (i = 0; i < count; i++)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Move the cursor forward. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the cursor goes outside, scroll the screen to the right. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Refresh the screen. If FULL is true, redraw the full line, otherwise,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe only LEN characters from LPOS. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Recompute the section number. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* From the start to the end. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If SECTION is the first section, print the prompt, otherwise,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe print `<'. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Compute the index to start writing BUF and the resulting position
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe on the screen. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe start = ((section - 1) * (CMDLINE_WIDTH - 1 - CMDLINE_MARGIN)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Print BUF. If ECHO_CHAR is not zero, put it instead. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (i = start; i < start + len && i < llen; i++)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Fill up the rest of the line with spaces. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the cursor is at the last position, put `>' or a space,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe depending on if there are more characters in BUF. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Back to XPOS. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Initialize the command-line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Distinguish us from other lines and error messages! */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Print full line and set position here. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Insert STR to BUF. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove (buf + lpos + l, buf + lpos, llen - lpos + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else if (xpos + l + llen - lpos > CMDLINE_WIDTH)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Delete COUNT characters in BUF. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove (buf + lpos, buf + lpos + count, llen - count + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (xpos + llen + count - lpos > CMDLINE_WIDTH)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If READLINE is non-zero, handle readline-like key bindings. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* POS points to the first space after a command. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *completion_buffer = (char *) COMPLETION_BUF;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Find the first word. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (buf[pos] && buf[pos] != '=' && buf[pos] != ' ')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Find the position of the equal character after a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe command, and replace it with a space. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Find the position of the first character in this
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (i = lpos; i > 0 && buf[i - 1] != ' '; i--)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Invalidate the cache, because the user may exchange
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe removable disks. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Copy this word to COMPLETION_BUFFER and do the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe completion. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove (completion_buffer, buf + i, lpos - i);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Found, so insert COMPLETION_BUFFER. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* There are more than one candidates, so print
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe the list. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Restore the command-line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Copy the string being deleted to KILL_BUF. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* XXX: Not very clever. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Copy the string being deleted to KILL_BUF. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove (kill_buf, buf + lpos, llen - lpos + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Save the working buffer. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else if (grub_strcmp (get_history (history), buf) != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If BUF is modified, add it into the history list. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else if (grub_strcmp (get_history (history), buf) != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If BUF is modified, add it into the history list. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* ESC, C-d and C-h are always handled. Actually C-d is not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe functional if READLINE is zero, as the cursor cannot go
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe backward, but that's ok. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case 4: /* C-d delete character under cursor */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe default: /* insert printable character into line */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If ECHO_CHAR is NUL, remove the leading spaces. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Copy the working buffer to CMDLINE. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_memmove (cmdline, buf + lpos, llen - lpos + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If the readline-like feature is turned on and CMDLINE is not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe empty, add it into the history list. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Don't use this with a MAXLEN greater than 1600 or so! The problem
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe is that GET_CMDLINE depends on the everything fitting on the screen
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe at once. So, the whole screen is about 2000 characters, minus the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe PROMPT, and space for error and status lines, etc. MAXLEN must be
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe at least 1, and PROMPT and CMDLINE must be valid strings (not NULL
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe or zero-length).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe If ECHO_CHAR is nonzero, echo it instead of the typed character. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweget_cmdline (char *prompt, char *cmdline, int maxlen,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Because it is hard to deal with different conditions simultaneously,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe less functional cases are handled here. Assume that TERM_NO_ECHO
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe implies TERM_NO_EDIT. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (current_term->flags & (TERM_NO_ECHO | TERM_NO_EDIT))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Make sure that MAXLEN is not too large. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Print only the prompt. The contents of CMDLINE is simply discarded,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe even if it is not empty. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Gather characters until a newline is gotten. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Return immediately if ESC is pressed. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (c == 27)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Printable characters are added into CMDLINE. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Preceding space characters must be ignored. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Complicated features are left to real_get_cmdline. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ret = real_get_cmdline (prompt, cmdline, maxlen, echo_char, readline);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesafe_parse_maxint (char **str_ptr, int *myint_ptr)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Is this a hex number?
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (*ptr == '0' && tolower (*(ptr + 1)) == 'x')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* A bit tricky. This below makes use of the equivalence:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (A >= B && A <= C) <=> ((A - B) <= (C - B))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe when C > B and A is unsigned. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe unsigned int digit;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* STAGE1_5 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowegrub_vsprintf (char *buffer, const char *format, int *dataptr)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* XXX hohmuth
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ugly hack -- should unify with printf() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((c = *format++) != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (c != '%') {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (c = *(format++))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *convert_to_ascii (str, c, *((unsigned long *) dataptr++)) = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* putchar((*(dataptr++))&0xff); */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((c = *ptr++) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowegrub_sprintf (char *buffer, const char *format, ...)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (grub_vsprintf (buffer, format, dataptr));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* !defined(STAGE1_5) || defined(FSYS_ZFS) */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * print to a buffer, unless verbose mode is on
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * if verbos mode is switched on, the buffer is dumped in verbose_func()
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (silent.buffer_start - silent.buffer + len + 1 >=
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (len < SCREENBUF) /* all other cases loop safely */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe grub_vsprintf(silent.buffer_start, format, dataptr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* ! STAGE1_5 || FSYS_FAT */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowegrub_memcmp (const char *s1, const char *s2, int n)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* ! STAGE1_5 || FSYS_ISO9660 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (++i < n && s1[i] != 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#endif /* ! STAGE1_5 */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* XXX: This below is an evil hack. Certainly, we should change the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe strategy to determine what should be defined and what shouldn't be
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe defined for each image. For example, it would be better to create
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe a static library supporting minimal standard C functions and link
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe each image with the library. Complicated things should be left to
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe computer, definitely. -okuji */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/* Make some grub_str* routines available to ZFS plug-in as well */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#if !defined(STAGE1_5) || defined(FSYS_VSTAFS) || defined(FSYS_ZFS)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowegrub_strncmp(const char *s1, const char *s2, int n)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return ((n == 0) ? 0 : *(unsigned char *)s1 - *(unsigned char *)--s2);
#ifndef STAGE1_5
getkey (void)
checkkey (void)
grub_putchar (int c)
#ifndef STAGE1_5
#ifdef STAGE1_5
console_putchar (c);
if (count_lines >= 0)
count_lines++;
int tmp;
count_lines = 0;
#ifndef STAGE1_5
gotoxy (int x, int y)
getxy (void)
cls (void)
if (! *(s1++))
s2 ++;
if (*s1 == 0)
while (*s1)
return (char *) s1;
s1++;
int len = 0;
while (*str++)
len++;
return len;
#ifndef STAGE1_5
int ch;
str++;
*str = 0;
return ch;
int local_errnum = 0;
#ifdef GRUB_UTIL
auto unsigned long start_addr (void);
auto unsigned long end_addr (void);
auto unsigned long start_addr (void)
int ret;
# if defined(HAVE_START_SYMBOL)
return ret;
auto unsigned long end_addr (void)
int ret;
# if defined(HAVE_END_SYMBOL)
return ret;
return ! local_errnum;
return ! local_errnum;
for (i = 0; i < len; i++)
linux-2.2.2/include/asm-i386/string.h. This is not very fast
return to;
return NULL;
char *p = start;
while (len -- > 0)
#ifndef STAGE1_5
return dest;
#ifndef GRUB_UTIL