fileparts.m in octave (mingw and msvc)

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

fileparts.m in octave (mingw and msvc)

tmacchant
Hello

In octave for windows (except cygwin), a path name sometime contains both backslashes (\) and slashes
(/) like,  
 c:\usr\Tatsu\mingwhome\octaves\octave-3.0.4RC1\scripts/miscellaneous\fileparts.m

Should fileparts.m in octave for windows be adaptable for both separators?

Anyway I will consider the modification if my family will remain time for me to do :-).

Regards

Tatsuro

--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

tmacchant
Hello

I have considered a patch.

Sorry I cannot use Mercurial correctly.

So I placed 'diff -r' instead in the following:

# start
30c30,34
<       ds = rindex (filename, filesep);
---
>       if !( findstr (octave_config_info('canonical_host_type'), 'msvc')  || findstr
(octave_config_info('canonical_host_type'), 'mingw') )
>         ds = rindex (filename, filesep);
>       else
>         ds = max (rindex (filename, "\\"),rindex (filename, "/"));
>       endif
68,69c72,73
< %! [d, n, e] = fileparts ("/file.ext");
< %! assert (strcmp (d, "/") && strcmp (n, "file") && strcmp (e, ".ext"));
---
> %! [d, n, e] = fileparts ([filesep "file.ext"]);
> %! assert (strcmp (d, filesep) && strcmp (n, "file") && strcmp (e, ".ext"));
72c76
< %! [d, n, e] = fileparts ("dir/file.ext");
---
> %! [d, n, e] = fileparts (["dir" filesep "file.ext"]);
76c80
< %! [d, n, e] = fileparts ("./file.ext");
---
> %! [d, n, e] = fileparts (["." filesep "file.ext");
80c84
< %! [d, n, e] = fileparts ("d1/d2/file.ext");
---
> %! [d, n, e] = fileparts (["d1" filesep "d2" filesep "file.ext"]);
84c88
< %! [d, n, e] = fileparts ("/d1/d2/file.ext");
---
> %! [d, n, e] = fileparts ([filesep "d1" filesep "d2" filesep "file.ext"]);
88c92
< %! [d, n, e] = fileparts ("/.ext");
---
> %! [d, n, e] = fileparts ([filesep ".ext"]);
# end

Regards

Tatsuro


--- Tatsuro MATSUOKA <[hidden email]> wrote:

> Hello
>
> In octave for windows (except cygwin), a path name sometime contains both backslashes (\) and
> slashes
> (/) like,  
>  c:\usr\Tatsu\mingwhome\octaves\octave-3.0.4RC1\scripts/miscellaneous\fileparts.m
>
> Should fileparts.m in octave for windows be adaptable for both separators?
>
> Anyway I will consider the modification if my family will remain time for me to do :-).
>
> Regards
>
> Tatsuro
>
> --------------------------------------
> Power up the Internet with Yahoo! Toolbar.
> http://pr.mail.yahoo.co.jp/toolbar/
>


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

Michael Goffioul
I started to work on that problem 2 months ago and committed the
first half on the development branch,
see http://hg.savannah.gnu.org/hgweb/octave/rev/135c0e7d7802

I thought I also did the other half (on fileparts.m), but apparently I
didn't. Given the date of the first commit, it's probably because I
started my new job the day after...

If anyone wants to do, please do so. What's needed in fileparts.m
is using some sort of "find_first_of" implementation instead of
"rindex", and to retrieve all file separators using "filesep('all')"

Michael.


On Sun, Jan 18, 2009 at 7:17 AM, Tatsuro MATSUOKA <[hidden email]> wrote:

> Hello
>
> I have considered a patch.
>
> Sorry I cannot use Mercurial correctly.
>
> So I placed 'diff -r' instead in the following:
>
> # start
> 30c30,34
> <       ds = rindex (filename, filesep);
> ---
>>       if !( findstr (octave_config_info('canonical_host_type'), 'msvc')  || findstr
> (octave_config_info('canonical_host_type'), 'mingw') )
>>         ds = rindex (filename, filesep);
>>       else
>>         ds = max (rindex (filename, "\\"),rindex (filename, "/"));
>>       endif
> 68,69c72,73
> < %! [d, n, e] = fileparts ("/file.ext");
> < %! assert (strcmp (d, "/") && strcmp (n, "file") && strcmp (e, ".ext"));
> ---
>> %! [d, n, e] = fileparts ([filesep "file.ext"]);
>> %! assert (strcmp (d, filesep) && strcmp (n, "file") && strcmp (e, ".ext"));
> 72c76
> < %! [d, n, e] = fileparts ("dir/file.ext");
> ---
>> %! [d, n, e] = fileparts (["dir" filesep "file.ext"]);
> 76c80
> < %! [d, n, e] = fileparts ("./file.ext");
> ---
>> %! [d, n, e] = fileparts (["." filesep "file.ext");
> 80c84
> < %! [d, n, e] = fileparts ("d1/d2/file.ext");
> ---
>> %! [d, n, e] = fileparts (["d1" filesep "d2" filesep "file.ext"]);
> 84c88
> < %! [d, n, e] = fileparts ("/d1/d2/file.ext");
> ---
>> %! [d, n, e] = fileparts ([filesep "d1" filesep "d2" filesep "file.ext"]);
> 88c92
> < %! [d, n, e] = fileparts ("/.ext");
> ---
>> %! [d, n, e] = fileparts ([filesep ".ext"]);
> # end
>
> Regards
>
> Tatsuro
>
>
> --- Tatsuro MATSUOKA <[hidden email]> wrote:
>
>> Hello
>>
>> In octave for windows (except cygwin), a path name sometime contains both backslashes (\) and
>> slashes
>> (/) like,
>>  c:\usr\Tatsu\mingwhome\octaves\octave-3.0.4RC1\scripts/miscellaneous\fileparts.m
>>
>> Should fileparts.m in octave for windows be adaptable for both separators?
>>
>> Anyway I will consider the modification if my family will remain time for me to do :-).
>>
>> Regards
>>
>> Tatsuro
>>
>> --------------------------------------
>> Power up the Internet with Yahoo! Toolbar.
>> http://pr.mail.yahoo.co.jp/toolbar/
>>
>
>
> --------------------------------------
> Power up the Internet with Yahoo! Toolbar.
> http://pr.mail.yahoo.co.jp/toolbar/
>
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

tmacchant
Hello Michael

Thank you for your reply

--- Michael Goffioul <[hidden email]> wrote:

> I started to work on that problem 2 months ago and committed the
> first half on the development branch,
> see http://hg.savannah.gnu.org/hgweb/octave/rev/135c0e7d7802
>
> I thought I also did the other half (on fileparts.m), but apparently I
> didn't. Given the date of the first commit, it's probably because I
> started my new job the day after...
>
> If anyone wants to do, please do so. What's needed in fileparts.m
> is using some sort of "find_first_of" implementation instead of
> "rindex", and to retrieve all file separators using "filesep('all')"
>
> Michael.

OK. I agree with you.  
However, implementation of "filesep('all')" can not be done soon.

SO my patch is not necessarily to be adapted in Octave-3.0.4.
My patch for fileparts.m can be done the user level because it is .m file.

I think it is enough the patch to remain as a ML archive for octave maintainer list.

Hi, Benjamin and Jaroslav Hajek
Any comments to my mails and Michael's one ?

Regards

Tatsuro


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

Michael Goffioul
On Mon, Jan 19, 2009 at 1:52 AM, Tatsuro MATSUOKA <[hidden email]> wrote:
> OK. I agree with you.
> However, implementation of "filesep('all')" can not be done soon.

Well, filesep('all') is already implemented in development branch.
It's just a matter of backporting. There was also some good proposals
for an efficient find_last_of implementation in
http://www.nabble.com/filesep-extension-td20441910.html#a20441910

So I think everything is there to solve that problem elegantly.

Michael.
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

Jaroslav Hajek-2
On Mon, Jan 19, 2009 at 8:27 AM, Michael Goffioul
<[hidden email]> wrote:

> On Mon, Jan 19, 2009 at 1:52 AM, Tatsuro MATSUOKA <[hidden email]> wrote:
>> OK. I agree with you.
>> However, implementation of "filesep('all')" can not be done soon.
>
> Well, filesep('all') is already implemented in development branch.
> It's just a matter of backporting. There was also some good proposals
> for an efficient find_last_of implementation in
> http://www.nabble.com/filesep-extension-td20441910.html#a20441910
>
> So I think everything is there to solve that problem elegantly.
>
> Michael.
>

Humm.. I see that was my proposal ended by "I'll commit a changeset."
About time to fullfill the promise, I guess... hopefully today.

cheers

--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

tmacchant
Hello

It is good for me that my report contribute to call back what you have done and you would like to do.

Regards

Tatsuro

--- Jaroslav Hajek <[hidden email]> wrote:

> Humm.. I see that was my proposal ended by "I'll commit a changeset."
> About time to fullfill the promise, I guess... hopefully today.
>
> cheers
>
> --
> RNDr. Jaroslav Hajek
> computing expert
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

Jaroslav Hajek-2
In reply to this post by Jaroslav Hajek-2
On Mon, Jan 19, 2009 at 8:33 AM, Jaroslav Hajek <[hidden email]> wrote:

> On Mon, Jan 19, 2009 at 8:27 AM, Michael Goffioul
> <[hidden email]> wrote:
>> On Mon, Jan 19, 2009 at 1:52 AM, Tatsuro MATSUOKA <[hidden email]> wrote:
>>> OK. I agree with you.
>>> However, implementation of "filesep('all')" can not be done soon.
>>
>> Well, filesep('all') is already implemented in development branch.
>> It's just a matter of backporting. There was also some good proposals
>> for an efficient find_last_of implementation in
>> http://www.nabble.com/filesep-extension-td20441910.html#a20441910
>>
>> So I think everything is there to solve that problem elegantly.
>>
>> Michael.
>>
>
> Humm.. I see that was my proposal ended by "I'll commit a changeset."
> About time to fullfill the promise, I guess... hopefully today.
>

The function is now implemented.


--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
Reply | Threaded
Open this post in threaded view
|

Re: fileparts.m in octave (mingw and msvc)

John W. Eaton
Administrator
In reply to this post by Jaroslav Hajek-2
On 19-Jan-2009, Jaroslav Hajek wrote:

| On Mon, Jan 19, 2009 at 8:27 AM, Michael Goffioul
| <[hidden email]> wrote:
| > On Mon, Jan 19, 2009 at 1:52 AM, Tatsuro MATSUOKA <[hidden email]> wrote:
| >> OK. I agree with you.
| >> However, implementation of "filesep('all')" can not be done soon.
| >
| > Well, filesep('all') is already implemented in development branch.
| > It's just a matter of backporting. There was also some good proposals
| > for an efficient find_last_of implementation in
| > http://www.nabble.com/filesep-extension-td20441910.html#a20441910
| >
| > So I think everything is there to solve that problem elegantly.
| >
| > Michael.
| >
|
| Humm.. I see that was my proposal ended by "I'll commit a changeset."
| About time to fullfill the promise, I guess... hopefully today.

I see you added strchr, so I decided to look at fileparts.  I think
the following change will work, but should we make strchr return 0 for
no match (similar to index/rindex) or an empty matrix like find?  If
it returns 0 for no match, the change to fileparts is simpler.

jwe


diff --git a/scripts/miscellaneous/fileparts.m b/scripts/miscellaneous/fileparts.m
--- a/scripts/miscellaneous/fileparts.m
+++ b/scripts/miscellaneous/fileparts.m
@@ -27,7 +27,10 @@
 
   if (nargin == 1)
     if (ischar (filename))
-      ds = rindex (filename, filesep);
+      ds = strchr (filename, filesep ("all"), 1, "last");
+      if (isempty (ds))
+ ds = 0;
+      endif
       es = rindex (filename, ".");
       ## These can be the same if they are both 0 (no dir or ext).
       if (es <= ds)