Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

another parsing problem: converting dos filenames to rebol

 [1/8] from: princepawn:mailandnews at: 15-Sep-2000 12:49


Could someone please fix this? It hung my interpreter: REBOL [ Title: "DOS-REBOL File Name Conversion Routines" File: %dosbol.r Author: "Terrence Brannon" Email: [princepawn--yahoo--com] Purpose: "Ease working with dos filename in REBOL programs" Category: 'file ] dosbol: make object! [ char: make string! 0 out: make string! 0 drive-letter: charset [ #"A" - #"F" ] rules: [ copy char drive-letter ":" (out: rejoin [ "/" dl ]) | "\" (append out "/") | copy char (append out char) ] d2r: func [ dos-fn [string!] "takes a dos filename and converts to rebol format"] [ parse/all dos-fn [ any rules ] out ] ]
>> dosbol/d2r "c:\temp\file"
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer] free-email: http://www.MailAndNews.com free-usenet: http://www.mailAndNews.com ; all the above is real REBOL code, believe it or not.

 [2/8] from: ryanc:iesco-dms at: 15-Sep-2000 10:40


This works for absolute paths:
>> d: "c:\my\dir\is\this"
== "c:\my\dir\is\this"
>> insert replace/all replace/all d ":" "" "\" "/" "/"
== "c/my/dir/is/this"
>> print d
/c/my/dir/is/this
>>
With partial paths you will need get some logic involved. Also there may be some issues with knowing if the path is a directory or a file. --Ryan [princepawn--MailAndNews--com] wrote:

 [3/8] from: jelinem1:nationwide at: 15-Sep-2000 13:18


I know you're probably trying to learn parse by writing a hands-on example, but converting a MSDOS filename to REBOL format is not that tricky: dosbol: func [ dos-fn [string!] "takes a dos filename and converts to rebol format" ][ replace/all dos-fn "\\" "/" replace/all dos-fn "\" "/" replace/all dos-fn ":" "" return join "/" dos-fn ] This will take care of alot of cases which the program below doesn't apparently handle. A few comments about the program below is that you need to specify 'to or 'thru preceeding any literal you want 'parse to match, eg: copy char drive-letter to ":" Also, I don't know what the 'char is doing (above), and of course I think you meant 'drive-letter to be 'dl due the the statement following it. I'm guessing that the reason why this loops infinitely is that you are not moving the 'parse cursor with 'to or 'thru. - Michael Jelinek [princepawn--MailAndNews--com]@MailAndNews.com> on 09/15/2000 11:49:09 AM From: [princepawn--MailAndNews--com]@MailAndNews.com on 09/15/2000 11:49 AM Please respond to [list--rebol--com] Sent by: Terrence Brannon <[princepawn--MailAndNews--com]> To: [list--rebol--com] cc: Subject: [REBOL] another parsing problem: converting dos filenames to rebol Could someone please fix this? It hung my interpreter: REBOL [ Title: "DOS-REBOL File Name Conversion Routines" File: %dosbol.r Author: "Terrence Brannon" Email: [princepawn--yahoo--com] Purpose: "Ease working with dos filename in REBOL programs" Category: 'file ] dosbol: make object! [ char: make string! 0 out: make string! 0 drive-letter: charset [ #"A" - #"F" ] rules: [ copy char drive-letter ":" (out: rejoin [ "/" dl ]) | "\" (append out "/") | copy char (append out char) ] d2r: func [ dos-fn [string!] "takes a dos filename and converts to rebol format"] [ parse/all dos-fn [ any rules ] out ] ]
>> dosbol/d2r "c:\temp\file"
terrence-brannon: [[princepawn--yahoo--com] perl-refugee myth-gamer] free-email: http://www.MailAndNews.com free-usenet: http://www.mailAndNews.com ; all the above is real REBOL code, believe it or not.

 [4/8] from: jeff:rebol at: 15-Sep-2000 14:29


-jeff REBOL [ Title: "DOS-REBOL File Name Conversion Routines" File: %dosbol.r Author: "Terrence Brannon" Email: [princepawn--yahoo--com] Purpose: "Ease working with dos filename in REBOL programs" Category: 'file ] dosbol: make object! [ out: make string! 100 path-char: complement charset ":\/" rules: [ copy char path-char ":" (out: rejoin [ "/" char ]) | "\" (append out "/") | copy char some path-char (append out char) ] d2r: func [ dos-fn [string!] "takes a dos filename and converts to rebol format" ][ parse dos-fn [ some rules ] out ] ] dosbol/d2r "c:\temp\file" == "/c/temp/file"

 [5/8] from: brian:hawley:bigfoot at: 19-Sep-2000 20:09


Terrence Brannon wrote:
>Could someone please fix this? It hung my interpreter: > >REBOL [ > Title: "DOS-REBOL File Name Conversion Routines" > File: %dosbol.r > Author: "Terrence Brannon" > Email: [princepawn--yahoo--com]
Try this: do http://www.bigfoot.com/~brian.hawley/rebol/to-rebol-file.r Not only will it solve your parse problems but it will let you support the other REBOL platforms as well. I use it every day in my own scripts, on many platforms. It's fast, too. I just updated it to support MacOSX, QNX RTP and Tao Elate but the last two may not work right. Does QNX RTP use Unix-style filenames like the other QNX's? Does Tao Elate use Amiga-style, Unix-style or something new? Brian Hawley

 [6/8] from: rishi:picostar at: 19-Sep-2000 19:53


Most likely QNX Real Time Platform uses unix-style filenames. Not sure thought. It will be released on Sep. 26th so I will find out then. Looks like it is going to be a really great platform. On a side note, I'm a bit sad that rebol/view and rebol/command are not supported on qnx rtp. Especially rebol/view. But I am very happy that at least I will have the rebol/core available. (which is the reason I am currently developing all command line - rather than graphical - based apps)

 [7/8] from: g:santilli:tiscalinet:it at: 20-Sep-2000 19:45


Hello [brian--hawley--bigfoot--com]! On 20-Set-00, you wrote: b> I just updated it to support MacOSX, QNX RTP and Tao Elate but b> the last two may not work right. Does QNX RTP use Unix-style b> filenames like the other QNX's? Does Tao Elate use b> Amiga-style, Unix-style or something new? Unix style, at least currently. Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [8/8] from: brian:hawley:bigfoot at: 20-Sep-2000 22:29


Gabriele wrote:
>Hello [brian--hawley--bigfoot--com]! >On 20-Set-00, you wrote:
<<quoted lines omitted: 3>>
> b> Amiga-style, Unix-style or something new? >Unix style, at least currently.
I've changed to-rebol-file accordingly and put it up on the web site. It supports all of the released current and xpers versions of REBOL now. I really need to get a rebsite up. After I finish writing the accounting system they have me working on... Brian Hawley

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted