|
From: Ethan M. <merritt@u.washington.edu> - 2009-02-02 22:19:06
|
On Monday 02 February 2009 13:52:18 you wrote:
> > > seems we don't have "string index" or "string split" functions.
> >
> > We do. It is called strstrt(haystack,needle):
> >
> > gnuplot> show var GPFUN
> > GPFUN_f = "f(a,b) = a**2 + sqrt(b*a)"
> >
> > gnuplot> print strstrt(GPFUN_f,"=")
> > 8
> > gnuplot> print GPFUN_f[ strstrt(GPFUN_f,"=") : * ]
>
> Interesting, I have never used this.
>
> How can I get the "reversed" version of it? Just today I needed to extract
> the last part of the directory, e.g. from
> /tmp/bla/now
> I needed to get "now". Finally I've got it by calling shall's `basename` but
> the reversed version of "strstrt" would help a lot.
Gnuplot's strstrt() function is just a wrapper for the C library routine strstr().
In C you could do:
char *piece = "/some/long/path/name";
char *end;
while (end = strstr( piece, "/" ))
do {piece = end+1;}
Unfortunately, gnuplot doesn't support while/do so I think you are out of luck.
> Further I have noticed `pwd` command from shell is needed to set a variable
> for the current working directory because
> gnuplot> pwd
> just prints it to screen, but I cannot do
> a=pwd
> or a=eval pwd
The "pwd" command from the shell is needed in any case. It is only a matter
of whether it is called directly or called via the internal routine pwd_command().
I would do
a = system("pwd")
> Would an automatic variable GPVAL_PWD be the only chance for a portable
> solution?
I don't know. I don't think that the concept of "current working directory"
is universally portable even apart from how you would issue the command.
In VMS, for example, the current directory name and the current disk are
separate things. Just asking for the current directory would not tell you
what disk you would be writing to.
--
Ethan A Merritt
|