Re: Use of alarm() with 4gl code
Posted in 1997
--- On Thu, 22 May 1997 09:05:57 -0700 Jonathan Leffler <johnl@informix.com> wrote: >>Date: Thu, 22 May 97 15:29:37 MET >>From: Marco Greco <marcog@ctonline.it> >>X-Informix-List-Id: <list.14602> >> >>I would like to use a timer within a number of 4gl (works!) applications >>to trigger actions if the user hasn't pressed a key in some time. >>Alarm(), of course, is a likely candidate, so I have already strolled to >>the IIUG sw archives and downloaded timeout.Z. Works nicely. Since this >>is a request that crops up every so often (last time being some two months >>ago), I vaguely remember Jonathan saying that alarm() is internally used >>by INPUT (and I suspect INPUT ARRAY, DISPLAY ARRAY and CONSTRUCT too). > >I hope I said it is used during input (lower case), meaning while waiting You probably did >for keyboard input from the user. This would cover INPUT, INPUT ARRAY, DISPLAY >ARRAY and CONSTRUCT. It also covers PROMPT and MENU and maybe others too. >About the only interaction that is excluded is the keyboard reading for PAUSE >in a report -- and I'm not sure whether that uses the same function or not. > >>Fair enough. I will only be using alarm() while waiting for rgetkey() >>(for the unaware, an undocumented function that reads characters from the >>standard input) to return chars. > >For the unaware, rgetkey() calls down onto the code that messes around with >alarm(). That includes me :-) > >>Can somebody confirm that this will (probably!) work irrespective of the 4gl >>wersion used? > >Anybody who confirms that is probably fibbing. It won't work reliably, >because rgetkey() and friends use alarm(). You may be OK if users don't go >messing with function keys when your code is reading the input, but it is >not reliable. Also, using rgetkey() means that other I4GL functions such >as fgl_lastkey() won't know what was typed. I coded around that with the following readkey(nargs) int nargs; { char c[1]; eflastkey=rgetkey(); c[0]=0; if (eflastkey==_acckey) eflastkey=2016; else if (eflastkey==_inskey) eflastkey=2014; else if (eflastkey==_delkey) eflastkey=2015; else if (eflastkey==_nxtkey) eflastkey=2005; else if (eflastkey==_prvkey) eflastkey=2006; else if (eflastkey==_hlpkey) eflastkey=2008; else if (eflastkey<128) c[0]=eflastkey; clrmsg(); retquote(c); return 0; } Apart from that, rgetkey() fills eflastkey. Jonathan, can you please clarify? The code from the sw archives works nicely on the old box I'm using right now (4gl 4.10UC1 :-), both using prompt and rgetkey() directly. Indeed prompt goofes up with function keys, but rgetkey() *does not*. Also I had the impression that input statements would override signal(SIGALRM,...) with their own signal handler, and so in the worst case my alarm would just not be trapped, you (and experimental evidence, for that matter :-) now seem to imply the contrary. Again, I only need to use alarm()/signal(SIGALRM,...) while in 4glworks menus, which use rgetkey() directly. >Yours, >Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> Ciao, Marco ____________________________________________________________________________ Marco Greco <marcog@ctonline.it> rem radioterapia 39 95 447828 fax 446558 Informix-FAQ http://www.iiug.org 4glWorks http://www.ctonline.it/~marcog