Opened 10 years ago

Last modified 5 years ago

#2156 new defect

Parser does not honor the dash (-) means stdout convention

Reported by: wenzeslaus Owned by: grass-dev@…
Priority: trivial Milestone: 7.0.7
Component: Parser Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj Cc:
CPU: Unspecified Platform: Unspecified

Description

I cannot run r.colors.out with rules=- when I have file named - in the current directory:

# create a file named -
# touch - does not work for me
$ touch testfile && mv testfile -

# try to output rules
$ r.colors.out map=elevation rules=-
ERROR: option <rules>: <-> exists.

# now remove the file named - and try again
$ rm -
$ r.colors.out map=elevation@PERMANENT rules=-
55.5788 0:191:191
75.729 0:255:0
95.8792 255:255:0
116.029 255:127:0
136.18 191:127:63
156.33 20:20:20
nv 255:255:255
default 255:255:255

Well, I'm not sure what should be the right behavior of the parser, this current one is bit confusing, so I think that it should be at least reported. What puzzles me, is how the - file actually appeared in the directory. It already happened to me at least two times (in past moths) that r.colors.out (or something I used together with it), created the - file. I used some other way and haven't reported the issue at that time, now I'm not able to reproduce it (from command line and GUI). According to the short note I made at that time it seems that it was pretty clear that r.colors.out is the cause.

Nevertheless, the behavior of parser is confusing when the module supports "- (dash, minus) means standard output" convention and current directory contains file named -. Affected modules are at least G7:r.colors.out and G7:m.proj. Probably the number of modules supporting - as a placeholder for stdout, the preferred interpretation of - and safety are the factors influencing how parser behave.

To be complete, for standard input, no support is needed in parser, test for G7:r.color:

$ touch testfile && mv testfile -
$ r.colors map=elevation rules=-
Enter rules, "end" when done, "help" if you need it.
fp: Data range is 55.5787925720215 to 156.329864501953
> (and prompts for input)

# for both existing (empty) and not existing files
$ r.colors map=elevation rules=testfile
ERROR: Unable to load rules file <testfile>

Change History (9)

comment:1 by neteler, 10 years ago

What is the scope of using a hyphen as filename to then try to confuse the parser (which fights perhaps with the shell at the same time)?

In my experience the probability to find a file with "-" as filename is really low. Perhaps not the top priority in the remaining parser issues to be fixed :-)

Likely GRASS did not create it, at least not for me while I am also using the aforementioned modules.

in reply to:  1 ; comment:2 by wenzeslaus, 10 years ago

Replying to neteler:

What is the scope of using a hyphen as filename to then try to confuse the parser (which fights perhaps with the shell at the same time)?

Sure, I created the file to simulate the situation on my computer. Using - fights only with specific programs not shell. It is just a convention and different programs uses different command line parsing resulting in different behavior in this extreme case. Further reading:

In my experience the probability to find a file with "-" as filename is really low. Perhaps not the top priority in the remaining parser issues to be fixed :-)

Sure, it priority is set to trivial (which in this case mean "trivial for me to overcome" and not "trivial to fix"). On the other hand, I wouldn't close it as wontfix, at least not now.

Likely GRASS did not create it, at least not for me while I am also using the aforementioned modules.

Maybe, GUI caused it. I'm almost sure that it was done by GRASS. It happened several times at different computers (and the file is always in the place where I start GRASS session, so current directory). The main reason why I reported this issue is that if you encounter the first non-reported issue and then after some time this one, it takes some time to understand.

in reply to:  2 comment:3 by annakrat, 10 years ago

Replying to wenzeslaus:

Maybe, GUI caused it. I'm almost sure that it was done by GRASS. It happened several times at different computers (and the file is always in the place where I start GRASS session, so current directory). The main reason why I reported this issue is that if you encounter the first non-reported issue and then after some time this one, it takes some time to understand.

I found out that m.proj dialog caused this. It has a dash as a default parameter so when I entered text in the 'or enter values interactively' it didn't automatically create a temporary file but instead created file with name -. I fixed this case (r59097) so probably this problem will not appear again. The ticket is still valid although even less important.

comment:4 by wenzeslaus, 10 years ago

Approach used in r59115 for G7:r.colors.out of course causes that parser does not check for existence of - file, so no fix in parser is need in this case.

in reply to:  4 comment:5 by martinl, 10 years ago

Replying to wenzeslaus:

Approach used in r59115 for G7:r.colors.out of course causes that parser does not check for existence of - file, so no fix in parser is need in this case.

Bearing in mind GUI dialogs, '-' make sense to me for input (read from standard input), but not for output (if not given simply write to standard output).

comment:6 by martinl, 8 years ago

Milestone: 7.0.07.0.5

comment:7 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:8 by neteler, 6 years ago

Milestone: 7.0.67.0.7

comment:9 by martinl, 5 years ago

Still relevant?

Note: See TracTickets for help on using tickets.