Hi all, I start a new thread with this mail in order to have a thread on its own for this subject.
In another thread we've already had some discussion about GRUBs option parsing. I wanna summarize and describe here about the issue. Right now I see 2 problems with GRUBs argument parsing: 1) GRUBs argument parsing is not POSIX compliant. Problem: POSIX (and GNU too) recommends (see http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html): "An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, ‘-o foo’ and ‘-ofoo’ are equivalent." This is doesn't hold for GRUB. When I try load_env -fenv an error message error: unknown argument '-e'. is returned. Solution: The GRUB argument parser needs to be fixed so that short options are parsed according to POSIX/GNU standards. 2) Optional option argument is not handled correctly (and not according to POSIX/GNU standard) Problem: Right now the GRUB argument parser doesn't handle optional arguments properly and it doesn't comply to POSIX/GNU standards. For short options parsing fails for the reason described above and because the parser allows that the option and its (optional) argument might be separated with whitespace. For long options parsing fails too because the parser allows that the option and its (optional) argument might be separated with whitespace. Example: OK: search --file --set --nofloppy /boot/grub/grub.cfg OK: search --file --set -- /boot/grub/grub.cfg ERROR: search --file --set /boot/grub/grub.cfg Solution: This solution follows just the POSIX/GNU standards for argument syntax as stated in the above mentioned HTML document. In order to be able to handle optional arguments for options the GRUB argument parser needs to implement parsing according to the following syntax: a) Short option: e.g. option name 'x' taking an optional argument '<arg>' Possible options: "-x" or "-x<arg>" b) Long option: e.g. option name 'xlong' taking an optional argument '<arg>' Possible options: "--xlong" or "--xlong=<arg>" or "--xlong=" For the third form the upcoming implementation is somehow free to decide how to interpret that option. Regarding to GNUs getopt() man page, this form will be interpreted by getopt() as if the option isn't specified at all (due to a bug). Because that interpretation is based on a bug and because it might make more sense the third form could/should be interpreted as if "--xlong" has been specified (meaning: options is present but without value). So for both, short and long options taking an optional value, no whitespace between option and its value (if the value is present) is allowed. IMHO the option parsing code in GRUB2 should be fixed as soon as possible. The later it will be done the more we'll have to fight with compatibility issues. Any comments? Andreas _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel