|
From: Ethan M. <merritt@u.washington.edu> - 2009-11-11 03:45:33
|
On Tuesday 10 November 2009, Philipp K. Janert wrote:
> On Tuesday 10 November 2009 07:10:51 pm you wrote:
> > On Tuesday 10 November 2009, Philipp K. Janert wrote:
> > > > > Since 4.0 we support string variables. That means wherever a string
> > > > > is required in the input command, it is acceptable to provide
> > > > > a string constant, a string variable, or a string-valued function.
> > >
> > > Although there is still a confusion: you write
> > > "where a string is required"
> > >
> > > In this example, no string is required.
> >
> > Of course a string is required. It is going to become the
> > first N characters of a longer string. How could it be anything
> > other than a string itself?
> >
> > > A bareword
> > > is required. It is your assumption that it should be
> > > a string. (And it is now a discussion item whether
> > > it should be a string - in which case the string needs
> > > to be handled properly, admittedly.)
> > >
> > > > > So
> > > > > A = "mydata"
> > > > > stats "file.dat" using 1 variable=A
> > > > >
> > > > > must expand A to find "mydata", not use it as an unmarked constant.
> > > > > All strings should be parsed using the routine try_to_get_string(),
> > > > > which handles the three cases.
> > > > > Also, normal commands do not use = signs.
> > > >
> > > > Good point on the string variable issue - I did not
> > > > think of that.
> > > >
> > > > There is a reason for the equality sign, though:
> > > > it indicates that the next token is the prefix -
> > > > because we have chosen to make the prefix
> > > > optional. The equality sign is a way of telling
> > > > gnuplot that the next token is a prefix, not the
> > > > next keyword.
> >
> > Not following you here.
> > The keyword itself can be optional - you don't have to provide a prefix.
>
> Ha! But :
> stats "file"
> and
> stats "file" var
> have different behavior!
>
> In the first case, no assignment to variables is made.
> Only in the second do we assign to variables. (Without
> a prefix.)
>
> So, how do I distinguish without the equality sign (or
> another keyword) between:
> stats "file" var noout
> and
> stats "file" var foo
try_to_get_string() will return NULL if noout is not a currently
defined string variable. If you define a string variable that is
the same as a keyword then yes, you could create a problem.
If that bothers you, you could explicitly test whether the next
token is "noout".
> Here, the first is supposed to assign to variables and
> not print to screen (keyword "noout"), whereas the former
> assigns to variables with prefix foo, but does not print to
> screen? To distinguish these cases, I need to tell gnuplot
> that the foo in the second cases "belongs to" var. The simplest
> way I could think of was to use the equality sign.
>
> > But if you include the keyword in your command, then the next token
> > must be a string. Where does the = sign come in?
> >
> > [maybe "prefix" is a better keyword than "variable"]
> >
> > > > (I admit that the equality sign is unusual and I did
> > > > hesitate a little. But it does provide a simple solution
> > > > to this particular problem.)
> > > >
> > > > I don't want to make the prefix mandatory. For
> > > > convenience, it seems that in many cases it won't
> > > > be needed.
> >
> > So let it default to an empty string.
Same answer as before, with an explicit default case:
char *prefix= NULL;
if (equals(c_token,"variable")) {
c_token++;
prefix = try_to_get_string();
}
if (!prefix)
prefix = gp_strdup("");
...
free(prefix);
|