Article View: comp.os.msdos.programmer
Article #2610Re: Autoexec.bat prob: take two
From: Kevin D. Quitt
Date: Wed, 10 Oct 1990 16:36
Date: Wed, 10 Oct 1990 16:36
107 lines
3680 bytes
3680 bytes
In article <3936.27135c52@cc.curtin.edu.au> Thomson_PW@cc.curtin.edu.au writes:
>I saw once a programme which was called from the autoexec.bat file
>which loaded for a few seconds then finished and let the batch file
>continue on. This was to give the user time enough to do a <ctrl> c
>to stop the batch file.
I have a program called getyesno which will accept a prompt and a
timeout on its command line, then wait the specified amount of time for
a y/n response. The result is in the errorlevel variable. Aw, heck with it,
it's under 2K.
O /
----------------X---------------- Cut Here
O \
/* GETYESNO.C 30-Nov-87 Kevin D. Quitt
Gets a Yes or No answer from the operator, with a command-line
specified time-out. A timeout of zero waits forever. If yes is entered,
errorlevel is 1, no yields 0, a timeout yields 2.
13-Jul-88 10:48:10, [VTEK]c:\utils\source\getyesno.c, Edit 880713104810 by KDQ
Added one-time output of string parameters past the timeout value.
*/
#include "disk.h"
#include <stdio.h>
#include <conio.h>
#include <time.h>
#define TRUE (1==1)
#define FALSE (1!=1)
int main( int argc, char *argv[] )
{
int c, secs = 0, gotanswer = FALSE, response;
long elapsed = -1L, stime;
if ( argv[1][0] == '?' )
{
printf( "Format is:\ngetyesno [optional maximum wait]\n" );
return -1;
}
if ( --argc > 0 )
sscanf( argv[1], "%d", &secs );
c = 2;
while ( argv[ c ] ) /* Print the extra text */
printf( "%s ", argv[ c++ ] );
while (!gotanswer)
{
gotanswer = TRUE;
response = 'y'; /* and the answer is yes */
if ( secs == 0 )
response = getche();
else
{
stime = time( NULL );
elapsed = 0;
while ( elapsed < secs )
{
if (kbhit())
{
response = getche();
break;
}
else
{
if ( stime != time(NULL) )
{
elapsed++;
stime = time(NULL);
}
}
}
}
response |= ( 'a' ^ 'A' ); /* Fold down */
if ( (response != 'y') && (response != 'n' ) )
{
gotanswer = FALSE;
printf( "\nPlease answer Yes or No: " );
}
}
printf ("\n" );
if ( elapsed >= secs ) return 2;
if ( response == 'y' ) return 1;
else return 0;
}
O /
----------------X---------------- Cut Here
O \
It's not great, but I wrote it in a previous life, and it's free.
--
_
Kevin D. Quitt demott!kdq kdq@demott.com
DeMott Electronics Co. 14707 Keswick St. Van Nuys, CA 91405-1266
VOICE (818) 988-4975 FAX (818) 997-1190 MODEM (818) 997-4496 PEP last
96.37% of all statistics are made up.
Technical Details
Message-ID:
<744@demott.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!srhqla!demott!kdqReferences:
<3936.27135c52@cc.curtin.edu.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!srhqla!demott!kdq From: kdq@demott.COM (Kevin D. Quitt) Newsgroups: comp.os.msdos.programmer Subject: Re: Autoexec.bat prob: take two Message-ID: <744@demott.COM> Date: 10 Oct 90 16:36:18 GMT References: <3936.27135c52@cc.curtin.edu.au> Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 107