Re: DISPLAY Time in a 4GL program
Posted in 1997
>From: Guy Germonpre <germonpre_guy/dis@bekaert.com> >Date: Fri, 18 Apr 1997 14:41:13 +0200 >X-Informix-List-Id: <news.36810> > >I wish to have a display of the current time in a 4GL program. This time >should be updated every minute, wether in input or not. A simple sounding request, but it is surprisingly difficult to do, for reasons which I'll outline. How you implement a solution will be up to you, but it probably isn't worth the effort. First, I4GL uses the alarm() function and SIGALRM signal internally and assumes that you do not. Therefore, any solution based on calling some C to trigger these is going to fail very quickly. Your best bet is to have a second (tiny) process written in C which is kicked off by the I4GL program. This program gives the invoking application a heartbeat signal every minute, probably using SIGUSR1. The I4GL application is set up with a signal handler which is called when the SIGUSR1 signals arrive. This much is easy. However, the signal handler is also responsible for displaying the time. This is very tricky! The heartbeat process cannot reliably display the time -- the I4GL program will redraw the screen and wipe out the displayed time unless it handles the display itself, via the curses routines. The signal handler cannot just write to the screen; it needs to position the cursor correctly. It also has to reposition the cursor after it has written the time (users get upset if their typing starts out in a box at the bottom of the screen and continues on the second line (because the time was displayed at the end of the top line, so the next character pushed the output onto the second line). You also have to worry about which I4GL window is going to display the time, and how you handle the other window which will typically be active at the time. All this is hairy; it would be bad enough if the curses code used by I4GL were documented, but it isn't, so you are reduced to trying to work out what will work by scanning through header files and so on. Alternatively, and probably more easily, you could have the signal handler set a variable, similar to INT_FLAG (eg TIME_FLAG)(, and have the application call a routine (eg display_time()) which is called at any convenient points in the program (eg function entry, etc). The function could be in I4GL and would make the relevant window current, display the current time, and then restore the previous current window. Aye, and there's the rub -- there isn't a way to handle windows like that. Well, I do have some code which I've not looked at in the last 8 years (code dated October 1988) which allowed me to handle multiple help files (so that there was an automatic stack of help files, which allowed library functions to set their own help file, but reinstate the applications help file on exit). This could be adapted to help with window tracking instead. It isn't trivial, though. It requires hacking of the standard sqlfm.h header distributed with I4GL, and modifying an I4GL library (simply adding some new functions). It could be done! I have my doubts about whether it is worth the trouble. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>