Option name starting with "default" (like "defaultextension"). Bug?



I am not sure someone still reads this forum, but I try my luck.

There seems to be a bug when an option name starts by “default”.

For example, this:

 void main() {
 	tk_getSaveFile(defaultextension: "txt");

results in:

Error in startup script: bad option “-default”: must be -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -parent, -title, or -typevariable
while executing
"tclParseConfigSpec ::tk::dialog::file::$dataName $specs “” $argList"
(procedure “Config” line 48)
invoked from within
"Config $dataName $type $args"
(procedure “::tk::dialog::file::” line 7)
invoked from within
"::tk::dialog::file:: save {*}$args"
(procedure “tk_getSaveFile” line 5)
invoked from within
"tk_getSaveFile(defaultextension: “txt”)"
(procedure “main” line 9)
invoked from within

So, the option name I gave (“defaultextension”) was replaced with “default” at some point.

This looks like a bad detection of a “default” word, like a regexp with no end anchor, or like the common mistake caused in C by a typical wrong use of strncmp() instead of strcmp() resulting in matching all strings that start with a pattern instead of only those that are equal to the pattern.

In tcl/generic/Lscanner.l, we can find:

 	{ID}:		{
				 * Push back the : and return a T_ID
				 * unless it's "default".  The grammar relies
				 * on this to avoid a nasty conflict.
				if (!strncmp(yytext, "default", 7)) {
					return T_DEFAULT;
				L_lval.s = ckstrdup(yytext);
				L_lval.s[yyleng-1] = 0;
				return T_ID;

I don’t know how exactly this works, but it looks highly suspicious, according to what I said before. I guess it returns T_DEFAULT for every ID starting with “default” instead of being equal to “default”.


Hi GNX – thank you for the bug report. We’ll work on getting a fix into
the bitkeeper repository. Until then, here’s how I would change the
code snippet you cited:

{ID}:		{
			 * Push back the : and return a T_ID
			 * unless it's "default".  The grammar relies
			 * on this to avoid a nasty conflict.  See the
			 * rule for option_arg in Lgrammar.y
			if (!strcmp(yytext, "default:")) {
				return T_DEFAULT;
			L_lval.s = ckstrndup(yytext, yyleng-1);
			return T_ID;

To build this, do the following in a built tree. If you’re building Little as
part of bitkeeper, make sure that the TCLTK component is populated
and built.

$ cd tcl/generic
$ <apply the above code to Lscanner.l>
$ cd ../unix
$ make Lscanner.c && cp Lscanner.c ../generic/Lscanner-pregen.c

Now re-build in your normal way (I had to delete the Lgui directory first).
(For a windows build, replace “unix” with “win”.)

Can you give this a try and let us know?


Hey, glad to see you are still watching :slight_smile:

It seems your fix works.

I was afraid it would mess the switch default when it is written with spaces between the label and the colon ("default :"), but it doesn’t seem so; I guess spaces are eliminated at an earlier stage.

So, that looks fine, thank you :slight_smile:

Here are the complete (if I didn’t forget to copy any) list of instructions I had to execute (after making the small partch):

tar -zxvf little-lang-src-1.0.tar.gz
cd little-lang-src-1.0
patch -p1 < ~/patches/little-lang/1.0/little-lang-src-1.0--default_option_parsing.patch
cd tcl/unix/
make Lscanner.c
chmod 644 ../generic/Lscanner-pregen.c
cp Lscanner.c ../generic/Lscanner-pregen.c
cd ../..
make clean

BTW, while you are here :slight_smile: : did you develop fixes or new features for your own use in the last 2 years? and if so, is there a plan to release them one day?


I’ve only done one other bug fix (#include did not work inside .lhtml documents). No new
features. But please keep posting as you find things! I’m happy to have a look.


Rob’s solution to this has been pushed to bk://bkbits.net/bk/dev