Tab completion bug fixes
Hi,
Like I said yesterday, I was fixing tab completion. Here is a patch for that. It changes the kernel and the command line parsing a lot and is a beginning for scripting support (at least for the lexer). So I will not commit it right away. If I do not receive complaints before Monday I will commit it after Monday.
i removed the old grub_split_cmdline. It was way too hard to read and some parts of it were required by tab completion. Now I am using a state machine:
http://www.xs4all.nl/~mgerards/grub_cmd_state.png
As you can see it contains all state transitions, for example:
foo "bar ${baz}"
^
|The arrow points to the { before baz. In the diagram this is the transition from qvariable to qvarname2. The old state was qvarname (because of the $) and because of the { the next state is qvarname2. In the sourcecode this is described by a table. This example is described by the following entry:
{ GRUB_PARSER_STATE_QVAR, GRUB_PARSER_STATE_QVARNAME2, '{', 0},
The last zero means that the character '{' should be discarded.
This kind of state machine is like how flex works AFAIK. I have written a function to determine the state transitions (grub_parser_cmdline_state) and grub_parser_split_cmdline. The last replaces grub_split_cmdline. Later it should be quite simple to write a lexer using grub_parser_cmdline_state without using flex.
Please test these changes if you have the time. Especially with tab completing files with spaces in it.
Thanks,
Marco
2005-10-22 Marco Gerards <[email protected]>
* include/grub/parser.h: New file.
* kern/parser.c: Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/parser.c'. (grub_setup_SOURCES): Likewise. (grub_probefs_SOURCES): Likewise. (grub_emu_SOURCES): Likewise. (kernel_img_HEADERS): Add parser.h'.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add parser.h'. (grub_emu_SOURCES): Add kern/parser.c'. (grubof_SOURCES): Likewise.
* conf/sparc64-ieee1275.rmk (grubof_HEADERS): Add parser.h'. (grubof_SOURCES): Add kern/parser.c'.
* include/grub/misc.h (grub_split_cmdline): Removed prototype.
* kern/misc.c (grub_split_cmdline): Removed function.
* kern/rescue.c: Include <grub/parser.h>. (grub_enter_rescue_mode): Use grub_parser_split_cmdline' instead of grub_split_cmdline'.
* normal/command.c: Include <grub/parser.h>. (grub_command_execute): Use grub_parser_split_cmdline' instead of grub_split_cmdline'.
* normal/completion.c: Include <grub/parser.h>. (cmdline_state): New variable.
(iterate_dir): End the filename with a quote depending on the command line state.
(get_state): new function. (grub_normal_do_completion): Use `grub_parser_split_cmdline' to split the arguments and determine the current argument. When the argument string is not quoted, escape all spaces.
Index: conf/i386-pc.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.49
i386-pc.rmk +7 -7
@@ -26,12 +26,12 @@ diskboot_img_LDFLAGS = -nostdlib -Wl,-N, kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \ kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ - kern/i386/dl.c kern/i386/pc/init.c kern/partition.c \ + kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \ kern/env.c disk/i386/pc/biosdisk.c \ term/i386/pc/console.c \ symlist.c kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ - file.h fs.h kernel.h loader.h misc.h mm.h net.h partition.h \ + file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h partition.h \ pc_partition.h rescue.h symbol.h term.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/time.h machine/vga.h \
@@ -63,7 +63,7 @@ grub_mkimage_LDFLAGS = $(LIBLZO) grub_setup_SOURCES = util/i386/pc/grub-setup.c util/i386/pc/biosdisk.c \ util/misc.c util/i386/pc/getroot.c kern/device.c kern/disk.c \ kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c \ - fs/sfs.c kern/partition.c partmap/pc.c \ + fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c \ fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c kern/file.c kern/fs.c kern/env.c fs/fshelp.c # For grub-mkdevicemap.
@@ -73,9 +73,9 @@ grub_mkdevicemap_SOURCES = util/i386/pc/ grub_probefs_SOURCES = util/i386/pc/grub-probefs.c \ util/i386/pc/biosdisk.c util/misc.c util/i386/pc/getroot.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c fs/fat.c \ - fs/ext2.c kern/partition.c partmap/pc.c fs/ufs.c fs/minix.c \ - fs/hfs.c fs/jfs.c kern/fs.c kern/env.c fs/fshelp.c fs/xfs.c \ - fs/affs.c fs/sfs.c + fs/ext2.c kern/parser.c kern/partition.c partmap/pc.c fs/ufs.c \ + fs/minix.c fs/hfs.c fs/jfs.c kern/fs.c kern/env.c fs/fshelp.c \ + fs/xfs.c fs/affs.c fs/sfs.c # For grub-emu. grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c \
@@ -89,7 +89,7 @@ grub_emu_SOURCES = commands/boot.c comma io/gzio.c \ kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ kern/file.c kern/fs.c kern/loader.c kern/main.c kern/misc.c \ - kern/partition.c kern/rescue.c kern/term.c \ + kern/parser.c kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ normal/completion.c normal/context.c normal/main.c \ normal/menu.c normal/menu_entry.c normal/misc.c \
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.44
powerpc-ieee1275.rmk +10 -10
@@ -10,7 +10,7 @@ MOSTLYCLEANFILES += grubof_symlist.c ker DEFSYMFILES += kernel_syms.lst grubof_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ - file.h fs.h kernel.h misc.h mm.h net.h rescue.h symbol.h \ + file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \ term.h types.h powerpc/libgcc.h loader.h \ partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h \ machine/kernel.h
@@ -44,9 +44,9 @@ grub_emu_SOURCES = commands/boot.c comma io/gzio.c \ kern/device.c kern/disk.c kern/dl.c kern/env.c kern/err.c \ kern/file.c kern/fs.c kern/loader.c kern/main.c kern/misc.c \ - kern/partition.c kern/rescue.c kern/term.c \ + kern/parser.c kern/partition.c kern/rescue.c kern/term.c \ normal/arg.c normal/cmdline.c normal/command.c \ - normal/completion.c normal/context.c \ + normal/completion.c normal/context.c \ normal/main.c normal/menu.c normal/menu_entry.c normal/misc.c \ partmap/amiga.c partmap/apple.c partmap/pc.c partmap/sun.c \ util/console.c util/grub-emu.c util/misc.c \
@@ -56,13 +56,13 @@ grub_emu_SOURCES = commands/boot.c comma grub_emu_LDFLAGS = $(LIBCURSES) grubof_SOURCES = kern/powerpc/ieee1275/crt0.S kern/powerpc/ieee1275/cmain.c \ - kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ - kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ - kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ - kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c \ - kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ - kern/partition.c kern/env.c kern/powerpc/dl.c grubof_symlist.c \ - kern/powerpc/cache.S + kern/ieee1275/ieee1275.c kern/main.c kern/device.c \ + kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \ + kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \ + kern/powerpc/ieee1275/init.c term/ieee1275/ofconsole.c \ + kern/powerpc/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ + kern/parser.c kern/partition.c kern/env.c kern/powerpc/dl.c \ + grubof_symlist.c kern/powerpc/cache.S grubof_HEADERS = grub/powerpc/ieee1275/ieee1275.h grubof_CFLAGS = $(COMMON_CFLAGS) grubof_ASFLAGS = $(COMMON_ASFLAGS)
Index: conf/sparc64-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/sparc64-ieee1275.rmk,v retrieving revision 1.2
sparc64-ieee1275.rmk +2 -2
@@ -10,7 +10,7 @@ MOSTLYCLEANFILES += grubof_symlist.c ker DEFSYMFILES += kernel_syms.lst grubof_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \ - file.h fs.h kernel.h misc.h mm.h net.h rescue.h symbol.h \ + file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h symbol.h \ term.h types.h loader.h \ partition.h pc_partition.h ieee1275/ieee1275.h machine/time.h
@@ -59,7 +59,7 @@ grubof_SOURCES = kern/sparc64/ieee1275/i kern/rescue.c kern/term.c term/ieee1275/ofconsole.c \ kern/sparc64/ieee1275/openfw.c disk/ieee1275/ofdisk.c \ kern/partition.c kern/env.c kern/sparc64/dl.c grubof_symlist.c \ - kern/sparc64/cache.c + kern/sparc64/cache.c kern/parser.c grubof_HEADERS = grub/sparc64/ieee1275/ieee1275.h grubof_CFLAGS = $(COMMON_CFLAGS) grubof_ASFLAGS = $(COMMON_ASFLAGS)
Index: include/grub/misc.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v retrieving revision 1.16
grub/misc.h +0 -4
@@ -76,8 +76,4 @@ grub_ssize_t EXPORT_FUNC(grub_utf8_to_ucconst grub_uint8_t *src, grub_size_t size); -grub_err_t EXPORT_FUNC (grub_split_cmdline ) (const char *str, -grub_err_t (* getline) (char **), -int *argc,char ***argv); -#endif /* ! GRUB_MISC_HEADER */
Index: include/grub/parser.h
===================================================================
RCS file: include/grub/parser.h
grub/parser.h new file +68 -0
68 lines not on this page · raw message
Index: kern/misc.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/misc.c,v
retrieving revision 1.23
misc.c +1 -223
234 lines not on this page · raw message
Index: kern/parser.c
===================================================================
RCS file: kern/parser.c
parser.c new file +230 -0
230 lines not on this page · raw message
Index: kern/rescue.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/rescue.c,v
retrieving revision 1.15
rescue.c +3 -2
@@ -1,7 +1,7 @@/* rescue.c - rescue mode */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002, 2003 Free Software Foundation, Inc. +* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@#include <grub/dl.h> #include <grub/partition.h> #include <grub/env.h> +#include <grub/parser.h> #define GRUB_RESCUE_BUF_SIZE 256#define GRUB_RESCUE_MAX_ARGS 20
@@ -650,7 +651,7 @@ grub_enter_rescue_mode (void)/* Get a command line. */ grub_rescue_get_command_line ("grub rescue> " ); -if (grub_split_cmdline (line, getline, &n, &args) || n <0 ) +if (grub_parser_split_cmdline (line, getline, &n, &args) || n <0 )continue ;/* In case of an assignment set the environment accordingly
Index: normal/command.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/command.c,v
retrieving revision 1.12
command.c +2 -1
@@ -24,6 +24,7 @@#include <grub/term.h> #include <grub/env.h> #include <grub/dl.h> +#include <grub/parser.h> static grub_command_t grub_command_list;
@@ -203,7 +204,7 @@ grub_command_execute (char *cmdline, intchar **arglist;int numargs; -if (grub_split_cmdline (cmdline, cmdline_get, &num, &args)) +if (grub_parser_split_cmdline (cmdline, cmdline_get, &num, &args))return 0 ;/* In case of an assignment set the environment accordingly instead
Index: normal/completion.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/completion.c,v retrieving revision 1.4
completion.c +73 -36
163 lines not on this page · raw message