#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # Wrapped by Chetan Anand # on Thu Jan 26 18:59:35 1995 # # alarm.c timeout.4gl # echo "Extracting file alarm.c" sed -e 's/^X//' <<\SHAR_EOF > alarm.c X X/* X * Program : alarm.c X * Date : May-19-1994 X * Author : Chetan Anand X * Desc : Initiates Alarm Signal Handler For 4GL Program Time out X * Compile : c4gl -c alarm.c X * Library : Any Archive Library X */ X Xstatic char sccsid[]=" @(#) alarm.c 1.1 95/01/25 07:13:21 (C) Copyright "; X X#ifndef _HPUX X#define _HPUX X#endif X X#include X#include X#include X#include X X#define FAILURE -1 X#define SUCCESS 0 X Xint TimeOut(); X Xextern int applstop(); X Xvoid initalarm(); X X/* X * Initiates SIGNAL ALARM For Interval Seconds X */ X X#ifdef _HPUX Xstruct itimerval rttimer; Xstruct itimerval old_rttimer; X#endif X Xvoid initalarm(nargs) Xint nargs; X{ X unsigned int Interval; X X int Seconds; X X popint(&Seconds); /* Interval Seconds Set in Calling 4GL Program */ X X Interval=Seconds; X X /* X * Initiates Signal Alarm and Handler : TimeOut Will be Executed X * Upon Expiring of the Interval Set X */ X X if((int)signal(SIGALRM, TimeOut) == (int)FAILURE) { X perror("Failed to Initiate Signal Handler"); X sleep(1); X exit(1); X } X X /* X * Passing ZERO For Interval Will Disable Signal Handler X */ X X#ifdef _HPUX X rttimer.it_value.tv_sec = Interval; X rttimer.it_value.tv_usec = 0; X rttimer.it_interval.tv_sec = 0; X rttimer.it_interval.tv_usec = 500000; /* X * 0.5 Seconds Subsequent Intervals X * Optional X */ X setitimer(ITIMER_REAL, &rttimer, &old_rttimer); X#else X alarm(Interval); X#endif X X sleep(1); X X return; X} X Xint TimeOut() X{ X exit((int)applstop()); /* External Function to EXIT Current Application */ X} X X/* X * End of Timeout Routine X */ SHAR_EOF if [ `wc -c < alarm.c` -ne 1760 ] then echo "Lengths do not match -- Bad Copy of alarm.c" fi echo "Extracting file timeout.4gl" sed -e 's/^X//' <<\SHAR_EOF > timeout.4gl X X# X# Filename: timeoout.4gl X# Desc : Sample Program to Test Application Timeout X# Version : 1.00 X# Author : Chetan Anand X# SCCS : "@(#) timeout.4gl 1.1 95/01/25 07:12:43 (C) Copyright" X# Date : 19-May-1994 X# X# Usage : $0 X# X# Compile : c4gl $0 alarm.o -o X# X# Amended : X# Initials Amend date Version Description of amendment X# anand 19 May 94 1.00 initial release X# X# X XGLOBALS X X Define g_timeout_secs smallint, X g_program char(25) X XEND GLOBALS X XMAIN X X let g_program = arg_val(0) X X # --- Command Line Timeout Interval X X let g_timeout_secs = arg_val(1) X X if(g_timeout_secs is NULL or g_timeout_secs <= 0) then X display " Usage : $0 " X exit program 1 X end if X X Call AcceptDetails() X XEND MAIN X X# --- Function Will be Called From alarm.c For Application Timeout X XFUNCTION ApplStop() X X display "Program : [", g_program CLIPPED, "]", X " got self terminated after ", g_timeout_secs Using "&&", " Secs " X X exit program 2 # --- Timeout Status for Further Action in Calling Script X # --- Check Exit Status thru $? X XEND FUNCTION X X# --- Function to Set/Reset Timeout Interval & Accept Input Entries X XFUNCTION AcceptDetails() X X Define v_getchar char(5) X X while(1) X X let v_getchar = NULL X X # --- InitAlarm() is a 'C' Function to Set SIGNAL ALARM for Timeout X X Call InitAlarm(g_timeout_secs) # --- Initiate Timeout X X message " Timeout = ", g_timeout_secs Using "&&", X " Secs, F11 = Exit Program " X X Prompt " Enter Something Before Timeout : " for v_getchar X on key(F11) X exit program 0 X End Prompt X X Call InitAlarm(0) # --- Deactivate Timeout to do some Process X # --- Based on the Input Entries X X Call DoSomething() X X end while X XEND FUNCTION X XFUNCTION DoSomething() X X Define v_getchar char(1) X X let v_getchar = NULL X X message " " X Prompt " Do Something, as Timeout has been Deactivated : " X for char v_getchar X XEND FUNCTION SHAR_EOF if [ `wc -c < timeout.4gl` -ne 2147 ] then echo "Lengths do not match -- Bad Copy of timeout.4gl" fi echo "Done." exit 0