parser.h 2.63 KB
Newer Older
1 2 3
/* parser.h - prototypes for the command line parser.  */
/*
 *  GRUB  --  GRand Unified Bootloader
4
 *  Copyright (C) 2005,2007,2009  Free Software Foundation, Inc.
5
 *
6
 *  GRUB is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation, either version 3 of the License, or
9 10
 *  (at your option) any later version.
 *
11
 *  GRUB is distributed in the hope that it will be useful,
12 13 14 15 16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
17
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
18 19 20 21 22 23 24
 */

#ifndef GRUB_PARSER_HEADER
#define GRUB_PARSER_HEADER	1

#include <grub/types.h>
#include <grub/err.h>
25
#include <grub/reader.h>
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

/* All the states for the command line.  */
typedef enum
  {
    GRUB_PARSER_STATE_TEXT = 1,
    GRUB_PARSER_STATE_ESC,
    GRUB_PARSER_STATE_QUOTE,
    GRUB_PARSER_STATE_DQUOTE,
    GRUB_PARSER_STATE_VAR,
    GRUB_PARSER_STATE_VARNAME,
    GRUB_PARSER_STATE_VARNAME2,
    GRUB_PARSER_STATE_QVAR,
    GRUB_PARSER_STATE_QVARNAME,
    GRUB_PARSER_STATE_QVARNAME2
  } grub_parser_state_t;

/* A single state transition.  */
struct grub_parser_state_transition
{
  /* The state that is looked up.  */
  grub_parser_state_t from_state;

  /* The next state, determined by FROM_STATE and INPUT.  */
  grub_parser_state_t to_state;

  /* The input that will determine the next state from FROM_STATE.  */
  char input;

  /* If set to 1, the input is valid and should be used.  */
  int keep_value;
};

/* Determines the state following STATE, determined by C.  */
grub_parser_state_t
EXPORT_FUNC (grub_parser_cmdline_state) (grub_parser_state_t state,
					 char c, char *result);

grub_err_t
EXPORT_FUNC (grub_parser_split_cmdline) (const char *cmdline,
65 66
					 grub_reader_getline_t getline_func,
					 void *getline_func_data,
67 68
					 int *argc, char ***argv);

69 70 71 72 73 74 75 76 77 78 79 80 81 82
struct grub_parser
{
  /* The next parser.  */
  struct grub_parser *next;

  /* The parser name.  */
  const char *name;

  /* Initialize the parser.  */
  grub_err_t (*init) (void);

  /* Clean up the parser.  */
  grub_err_t (*fini) (void);

83
  grub_err_t (*parse_line) (char *line,
84 85
			    grub_reader_getline_t getline_func,
			    void *getline_func_data);
86 87 88
};
typedef struct grub_parser *grub_parser_t;

89
grub_err_t grub_parser_execute (char *source);
90

91
grub_err_t
92
grub_rescue_parse_line (char *line,
93 94
			grub_reader_getline_t getline_func,
			void *getline_func_data);
95

96
#endif /* ! GRUB_PARSER_HEADER */