[GRASS-dev] [GRASS GIS] #2156: Parser does not honor the dash (-) means stdout convention

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------
I cannot run `r.colors.out` with `rules=-` when I have file named `-` in
the current directory:

{{{
#!sh
# 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:

{{{
#!sh
$ 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>
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2156&gt;
GRASS GIS <http://grass.osgeo.org>

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------

Comment(by 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)?

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
:slight_smile:

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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2156#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------

Comment(by wenzeslaus):

Replying to [comment:1 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:

  * http://stackoverflow.com/questions/3797795/does-mean-stdout-in-bash
  * http://unix.stackexchange.com/questions/16357/usage-of-dash-in-place-
of-a-filename

> 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
:slight_smile:
>
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.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2156#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------

Comment(by annakrat):

Replying to [comment:2 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.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2156#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------

Comment(by 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2156#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2156: Parser does not honor the dash (-) means stdout convention
------------------------------------------+---------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: trivial | Milestone: 7.0.0
Component: Parser | Version: svn-trunk
Keywords: stdout, r.colors.out, m.proj | Platform: Unspecified
      Cpu: Unspecified |
------------------------------------------+---------------------------------

Comment(by martinl):

Replying to [comment:4 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).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2156#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>