From: SourceForge.net <no...@so...> - 2008-08-11 10:12:35
|
Feature Requests item #1117980, was opened at 2005-02-07 11:34 Message generated for change (Comment added) made by bigrixx You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=684733&aid=1117980&group_id=119701 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Interpreter Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: mdlueck (mdlueck) Assigned to: Nobody/Anonymous (nobody) Summary: Enhancements to FILESPEC Initial Comment: Below is LDSFileSpec from my Object CUR. It handles some things more gracefully than IBM's code. Support for UNC exists. Also it returns '' vs 0 so it is safe to cross platform ask for drive || path and not get '0/blablabla...' on *nix platforms nor have to check OS and do something different. ::method LDSFileSpec expose LDSSystemInfo LDSLogging /* DEV */ if LDSSystemInfo~tracemode\='' then interpret 'trace 'LDSSystemInfo~tracemode RUNmode=arg(1) FINDfilename=arg(2) /* DEV */ LDSLogging~Verbose('LDSRexxUtil~LDSFileSpec, RUNmode='RUNmode' FINDfilename='FINDfilename) /* Check Params */ if strip(RUNmode)='' | strip(FINDfilename)='' then do LDSLogging~Logger('LDSRexxUtil~LDSFileSpec ERROR! -> Not Enough Paramaters') return 0 end RUNmode=translate(strip(RUNmode)) FINDfilename=strip(FINDfilename) /* See what slash we are using */ if pos('\', FINDfilename)\=0 & pos('/', FINDfilename)\=0 then do LDSLogging~Logger('LDSRexxUtil~LDSFileSpec ERROR! -> FINDfilename contains both slashes, can not process FINDfilename') return 0 end if pos('/', FINDfilename)=0 then do slash='\' doubleslash='\\' end else do slash='/' doubleslash='//' end select when RUNmode='DRIVE' then do FINDstring=left(FINDfilename, 2) select when datatype(left(FINDstring, 1), 'M') & right(FINDstring, 1)=':' then do /* DOS support, no extra code needed */ nop end /* DOS */ when FINDstring=doubleslash then do /* UNC mode */ NEXTpos=pos(slash, right(FINDfilename, length(FINDfilename)-2)) if NEXTpos=0 then do FINDstring='' end else do FINDstring=left(FINDfilename, NEXTpos+1) end end /* UNC */ otherwise do FINDstring='' end end /* select */ end when RUNmode='PATH' then do select when pos(slash, FINDfilename)\=0 & pos(doubleslash, FINDfilename)=0 then do /* DOS mode */ FIRSTpos=pos(slash, FINDfilename) LASTpos=lastpos(slash, FINDfilename) if FIRSTpos=LASTpos then do FINDstring=slash end else do FINDstring=substr(FINDfilename, FIRSTpos, LASTpos-FIRSTpos+1) end end /* DOS */ when left(FINDfilename, 2)=doubleslash then do /* UNC mode */ parse value FINDfilename with . =3 FINDfilename FIRSTpos=pos(slash, FINDfilename) LASTpos=lastpos(slash, FINDfilename) if FIRSTpos=LASTpos then do FINDstring=slash end else do FINDstring=substr(FINDfilename, FIRSTpos, LASTpos-FIRSTpos+1) end end /* UNC */ otherwise do FINDstring='' end end /* select */ end when RUNmode='NAME' then do if pos(slash, FINDfilename)=0 then do FINDstring='' end else do FINDstring=right(FINDfilename, length(FINDfilename)-lastpos(slash, FINDfilename)) end end otherwise do LDSLogging~Logger('LDSRexxUtil~LDSFileSpec ERROR! -> RUNmode=' || RUNmode || ' is not a supported RUNmode') FINDstring='' end end /* select */ return FINDstring ---------------------------------------------------------------------- >Comment By: Rick McGuire (bigrixx) Date: 2008-08-11 06:12 Message: Logged In: YES user_id=1125291 Originator: NO I was talking about the file class I was proposing...a good first start at that sort of class can be done by just using the the rexxutils functions, since a lot of the code would be written in ooRexx anyway, we can get a good first start on defining the methods and playing around with the capability. Methods such as the ones you were proposing would be a natural fit on that class. ---------------------------------------------------------------------- Comment By: Jon Wolfers (sahananda) Date: 2008-08-11 00:27 Message: Logged In: YES user_id=667060 Originator: NO Hi Rick, A couple of our comments crossed in the email, leaving me confused . When you said: > Actually, this might make a good incubator project. It could be > implemented initially mostly in ooRexx, using the rexxutils code for > anything where native access is required. were you encouraging me to go ahead with what I was proposing? It seems more likely to me that you meant the file class that you were speaking of. thanks, Jon ---------------------------------------------------------------------- Comment By: Rick McGuire (bigrixx) Date: 2008-08-10 12:53 Message: Logged In: YES user_id=1125291 Originator: NO Yes, I saw that discussion. The appropriate solution is the File class, which eliminates the need for parsing the information entirely. Rick ---------------------------------------------------------------------- Comment By: Jon Wolfers (sahananda) Date: 2008-08-10 12:49 Message: Logged In: YES user_id=667060 Originator: NO Hi Rick, Sounds very good - I'll leave well alone. I take it you did see the recent thread on comp.lang.rexx about filenames starting with blanks etc! Jon ---------------------------------------------------------------------- Comment By: Rick McGuire (bigrixx) Date: 2008-08-10 12:48 Message: Logged In: YES user_id=1125291 Originator: NO Actually, this might make a good incubator project. It could be implemented initially mostly in ooRexx, using the rexxutils code for anything where native access is required. ---------------------------------------------------------------------- Comment By: Rick McGuire (bigrixx) Date: 2008-08-10 12:43 Message: Logged In: YES user_id=1125291 Originator: NO I sort of have a longer range plan of having a File class object that implements a lot of the function currently in rexxutils in a class, including things like filespec capabilities. This will be loosely based on the Java File class, and portions of this will need to be implemented via native code. I've sort of been waiting for the new APIs to get fully implemented before taking a crack at this. ---------------------------------------------------------------------- Comment By: Jon Wolfers (sahananda) Date: 2008-08-10 12:34 Message: Logged In: YES user_id=667060 Originator: NO Hi Michael, I was looking at this and wondered whether a class might not be the way to go with this, such as you could do a = .filespec~new('c:\My Documents\rexx is great.doc') say a~drive say a~path say a~name or even say .filespec~new('c:\My Documents\rexx is great.doc')~name I quickly knocked up a class based on your code & wondered what you thought and whether you would be happy for me to take this further. I think it could benefit from suitable MakeArray and String Methods As I don't seem to be able to attach a file to this tracker I include the code inline as you did. Jon /* ========================================================================= */ ::class filespec public /* ========================================================================= */ ::attribute Drive get ::attribute Drive set private ::attribute Path get ::attribute Path set private ::attribute Name get ::attribute Name set private ::attribute error /* ------------------------------------------------------------------------- */ ::method init /* ------------------------------------------------------------------------- */ expose name path drive use strict arg filespec self~error = .false -- filespec = filespec~strip -- not sure this might not cause an error /* See what slash we are using */ if filespec~pos('\') \=0 & filespec~pos('/') \= 0 then do self~error = .true return self~error end if filespec~pos('/') = 0 then slash='\' else slash='/' doubleSlash = slash~copies(2) /* set the drive */ drive = filespec~left(2) select when drive~left(1)~datatype('M') & drive~right(1)=':' then nop /* DOS support, no extra code needed */ when drive = doubleslash then do /* UNC mode */ NEXTpos = filespec~right(filespec~length - 2)~pos(slash) if NEXTpos = 0 then drive = '' else drive = filespec~left(NEXTpos + 1) end /* UNC */ otherwise drive = '' end /* select */ /* set the name */ if filespec~pos(slash) = 0 then name = '' else name = filespec~right(filespec~length -filespec~lastpos(slash)) /* set the path */ select when filespec~pos(slash) \= 0 & filespec~pos(doubleslash) = 0 then do /* DOS mode */ FIRSTpos = filespec~pos(slash) LASTpos = filespec~lastpos(slash) if FIRSTpos = LASTpos then path = slash else path = filespec~substr(FIRSTpos, LASTpos-FIRSTpos+1) end /* DOS */ when filespec~left(2) = doubleslash then do /* UNC mode */ parse value filespec with . =3 filespec FIRSTpos = filespec~pos(slash) LASTpos = filespec~lastpos(slash) if FIRSTpos = LASTpos then path = slash else path = filespec~substr(FIRSTpos, LASTpos-FIRSTpos+1) end /* UNC */ otherwise path = '' end /* select */ ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=684733&aid=1117980&group_id=119701 |