1. gets(0) quibble...
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Feb 16, 1999
- 419 views
I'm still with 2.0 here, so again, it might have been fixed in 2.1... Try the following program: sequence File procedure getPipe() -- Get input from pipe. e.g. dir | ex thiscode.ex integer c File = {} c = gets(0) while c >= 0 do File = File & c c = gets(0) end while end procedure function input(sequence prompt) sequence out puts(1, prompt) out = gets(0) return out[1..length(out)-1] end function sequence name getPipe() name = input("What is your name?: ") -- Crashes here!! The solution is to do this for input(): function input(sequence prompt) sequence out integer fh puts(1, prompt) fh = open("CON","r") -- The keyboard CONsole out = gets(0) close(fh) return out[1..length(out)-1] end function Question: Which style of input() has Rob used in prompt_string() in the new library files? Or does he avoid gets() altogether? -- Carl R White -- Final Year Computer Science at the University of Bradford E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :) URL...........: http://www.bigfoot.com/~cyrek/ Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58"
2. Re: gets(0) quibble...
- Posted by Jeffrey Fielding <JJProg at CYBERBURY.NET> Feb 16, 1999
- 417 views
in getPipe(), you need to use getc instead of gets. EUPHORIA at LISTSERV.MUOHIO.EDU wrote: > I'm still with 2.0 here, so again, it might have been fixed in 2.1... > Try the following program: > > sequence File > > procedure getPipe() -- Get input from pipe. e.g. dir | ex thiscode.ex > integer c > > File = {} > c = gets(0) > > while c >= 0 do > File = File & c > c = gets(0) > end while > end procedure > > function input(sequence prompt) > sequence out > > puts(1, prompt) > > out = gets(0) > return out[1..length(out)-1] > end function > > sequence name > > getPipe() > > name = input("What is your name?: ") -- Crashes here!! > > The solution is to do this for input(): > > function input(sequence prompt) > sequence out > integer fh > > puts(1, prompt) > > fh = open("CON","r") -- The keyboard CONsole > out = gets(0) > close(fh) > return out[1..length(out)-1] > end function > > Question: Which style of input() has Rob used in prompt_string() in the > new library files? Or does he avoid gets() altogether? > > -- > Carl R White -- Final Year Computer Science at the University of Bradford > E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :) > URL...........: http://www.bigfoot.com/~cyrek/ > Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58" -- Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
3. Re: gets(0) quibble...
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Feb 16, 1999
- 403 views
- Last edited Feb 17, 1999
>> Question: Which style of input() has Rob used in prompt_string() in the >> new library files? Or does he avoid gets() altogether? I consider this a bug and am assuming Robert will fix it. (btw: did you fix the zero bug in puts ?) Anyway, here is a working 'wrapped' version of gets () global function gets (integer fh) sequence s s = {getc(fh)} while s[length(s)] != '\n' do s = append(s, getc(fh)) end while return s end function This will work. Ralf Nieuwenhuijsen .... Mailto://nieuwen at xs4all.nl .... Http://www.xs4all.nl/~nieuwen .... Uin://9289920
4. Re: gets(0) quibble...
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Feb 18, 1999
- 419 views
On Tue, 16 Feb 1999, Jeffrey Fielding wrote: ] in getPipe(), you need to use getc instead of gets. ] ] EUPHORIA at LISTSERV.MUOHIO.EDU wrote: ] ] > I'm still with 2.0 here, so again, it might have been fixed in 2.1... ] > Try the following program: ] > ] > sequence File ] > ] > procedure getPipe() -- Get input from pipe. e.g. dir | ex thiscode.ex ] > integer c ] > ] > File = {} ] > c = gets(0) ] > ] > while c >= 0 do ] > File = File & c ] > c = gets(0) ] > end while ] > end procedure Whoops. Coding on the fly from memory again... :-} One character changes the whole semantics of the program. Story of my life ;) ZipDir, SPLIT, GormLESS and GLess have all had bugs of this kind... The bug is/was also apparent when using getc(0) (GormLESS uses gets(0) and GLess uses getc(0) because of binary data). I checked this behaviour out with Kelley & Pohl's "A Book on C" (which is what Eu is written in), and it has something to do with the system setting a flag when a file reaches an EOF marker. The flag only resets when the file is closed. Since it's not possible to close the STD* files (0, 1 and 2), the EOF flag isn't reset and usage of get*(0) for keyboard input won't work after reading piped data. There is a C function (according to the book) that resets the EOF flag when *any* file is open, but this is probably unsafe, and it's probably better to use the "CON" solution I proposed. ] > Question: Which style of input() has Rob used in prompt_string() in the ] > new library files? Or does he avoid gets() altogether? No one answered this yet, and I still think it's a concern, albeit a very tiny one :) Carl -- Carl R White -- Final Year Computer Science at the University of Bradford E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :) URL...........: http://www.bigfoot.com/~cyrek/ Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58"