1. why does this crash?
- Posted by Greg Haberek <ghaberek at gmail.com> Oct 03, 2004
- 491 views
Maybe its late, maybe I'm just too tired... I don't know whats wrong with this code. I have *no idea* why this is crashing. Last time I checked, d+1 = 5, not -4. Anyway, here's the code. Someone please test it and tell me what I may or may not be doing wrong.
include misc.e with trace global function split_file( sequence filename ) integer d, s sequence out out = {"","",""} -- {path, filename, extension} filename = reverse( filename ) d = find( '.', filename ) -- find the first dot s = find( '\\', filename ) -- find the first slash out[3] = reverse( filename[1..d] ) out[2] = reverse( filename[d+1..s] ) if s then out[1] = reverse( filename[s..length(filename)] ) end if return out end function sequence file1, file2, file3 --trace(1) file1 = split_file("file with no path.exe") file2 = split_file("C:\\some path name\\a file with no extension") file3 = split_file("C:\\full path info\\path number 2\\correct filename.ext") --trace(0) pretty_print(1, file1, {2}) puts(1, "\n") pretty_print(1, file2, {2}) puts(1, "\n") pretty_print(1, file3, {2}) puts(1, "\n") ? getc(0)
And here's my ex.err file: C:\EUPHORIA\projects\test.exw:17 in function split_file() slice length is less than 0 (-4) filename = {101'e',120'x',101'e',46'.',104'h',116't',97'a',112'p',32' ', 111'o',110'n',32' ',104'h',116't',105'i',119'w',32' ',101'e',108'l',105'i', 102'f'} d = 4 s = 0 out = { {}, {}, {46'.',101'e',120'x',101'e'} } ... called from C:\EUPHORIA\projects\test.exw:29 HELP! ~Greg
2. Re: why does this crash?
- Posted by Derek Parnell <ddparnell at bigpond.com> Oct 03, 2004
- 440 views
Greg Haberek wrote: > > Maybe its late, maybe I'm just too tired... I don't know whats wrong > with this code. I have *no idea* why this is crashing. Because the first file you test does not have a slash in it. Thus 's' is set to zero, and 'd' is set to 4, the location of the dot. This means that 'filename[d+1..s]' resolves to 'filename[5..0]' which is not a valid slice. > Last time I > checked, d+1 = 5, not -4. Anyway, here's the code. Someone please test > it and tell me what I may or may not be doing wrong. The length of the slice is calculated as ... end - start + 1 substituting the values in your code, we get ... 0 - 5 + 1 = -4 Hope that helps. By the way, you code might do better with ... if s then out[2] = reverse( filename[d+1..s] ) out[1] = reverse( filename[s..length(filename)] ) else out[2] = reverse( filename[d+1 .. length(filename)] out[1] = "" end if -- Derek Parnell Melbourne, Australia
3. Re: why does this crash?
- Posted by "Kat" <gertie at visionsix.com> Oct 03, 2004
- 446 views
On 2 Oct 2004, at 21:20, Derek Parnell wrote: > > > posted by: Derek Parnell <ddparnell at bigpond.com> > > Greg Haberek wrote: > > > > Maybe its late, maybe I'm just too tired... I don't know whats wrong > > with this code. I have *no idea* why this is crashing. > > Because the first file you test does not have a slash in it. Thus 's' > is set to zero, and 'd' is set to 4, the location of the dot. > > This means that 'filename[d+1..s]' resolves to 'filename[5..0]' which > is not a valid slice. > > > Last time I > > checked, d+1 = 5, not -4. Anyway, here's the code. Someone please test > > it and tell me what I may or may not be doing wrong. > > The length of the slice is calculated as ... > > end - start + 1 > > substituting the values in your code, we get ... > > 0 - 5 + 1 = -4 > > Hope that helps. > > By the way, you code might do better with ... > > if s then > out[2] = reverse( filename[d+1..s] ) > out[1] = reverse( filename[s..length(filename)] ) > else > out[2] = reverse( filename[d+1 .. length(filename)] > out[1] = "" > end if > -- > Derek Parnell > Melbourne, Australia If the next step is to save the file in the form of the url, see: http://www.tiggrbox.info/program/createdir.html Kat
4. Re: why does this crash?
- Posted by Greg Haberek <ghaberek at gmail.com> Oct 03, 2004
- 487 views
Thanks Derek, I re-read the Reference Manual on subscripting and slicing sequences. I knew 0 was a valid subscript, but I forgot that its only if you're starting at 1 (i.e. my_seq[1..0] = {}). Like I said, its late. In fact, as I'm respoding to this its 4:50am. I've just beek pecking away at my computer all night. Time for bed. ~Greg On Sat, 02 Oct 2004 21:20:11 -0700, Derek Parnell <guest at rapideuphoria.com> wrote: > > posted by: Derek Parnell <ddparnell at bigpond.com> > > Greg Haberek wrote: > > > > Maybe its late, maybe I'm just too tired... I don't know whats wrong > > with this code. I have *no idea* why this is crashing. > > Because the first file you test does not have a slash in it. Thus 's' > is set to zero, and 'd' is set to 4, the location of the dot. > > This means that 'filename[d+1..s]' resolves to 'filename[5..0]' which > is not a valid slice. > > > Last time I > > checked, d+1 = 5, not -4. Anyway, here's the code. Someone please test > > it and tell me what I may or may not be doing wrong. > > The length of the slice is calculated as ... > > end - start + 1 > > substituting the values in your code, we get ... > > 0 - 5 + 1 = -4 > > Hope that helps. > > By the way, you code might do better with ... > > if s then > out[2] = reverse( filename[d+1..s] ) > out[1] = reverse( filename[s..length(filename)] ) > else > out[2] = reverse( filename[d+1 .. length(filename)] > out[1] = "" > end if > -- > Derek Parnell > Melbourne, Australia > > > > >