home *** CD-ROM | disk | FTP | other *** search
- {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
- {$M 16384,0,0}
-
- (************************************************************************
- * *
- * Command Line parsing program with user time limit factoring *
- * *
- * For usage in DOS batch files to give operator *
- * a choice of which process to do next. *
- * *
- * Returns: *
- * errorlevel 3 if invalid time delay factor *
- * errorlevel 2 if user answers "Y" *
- * errorlevel 1 if user answers "N" *
- * errorlevel 0 if no user response *
- * *
- * *
- * Copyright (c) 1988 *
- * Dennis M. Passmore, Edgewater, FL. 32032 *
- * *
- ************************************************************************)
-
- uses
- crt,
- dos;
-
- var
- prompt : ^string;
- lngth : ^byte;
- inkey : char;
- timdly,X,Y,
- error : integer;
- hour,min,
- sec,hsec:word;
- time1,
- time2 : longint;
- tstr : string[4];
-
- procedure Report_error;
- begin
- writeln('Usage > DLYASK {user prompt} {seconds delay (max 120)} ');
- writeln;
- writeln('Example: DLYASK Do you want to EXIT to DOS (Y/N)? 10 ');
- writeln;
- writeln(' In the above example the program will prompt ');
- writeln(' the user with the line: ');
- writeln(' Do you want to EXIT to DOS (Y/N)? ');
- writeln(' and then wait for: ');
- writeln(' 10 seconds ');
- writeln(' for a reply from the user. If the user replys ');
- writeln(' "Y" then the program will return DOS errorlevel ');
- writeln(' 2. If the user returns replys "N" then the ');
- writeln(' program will return DOS errorlevel 1. If the ');
- writeln(' user does not reply the program will return ');
- writeln(' DOS errorlevel 0.');
- writeln;
- writeln(' A invalid Time Delay value will return errorlevel 3.');
- end;
-
-
- begin
- if paramcount = 0 then
- Report_error
- else
- begin
- prompt := ptr(Prefixseg,$80);
- lngth := ptr(Prefixseg,$80);
- tstr := '';
- while (lngth^<>0) and (prompt^[lngth^]<>' ') do
- begin
- tstr := prompt^[lngth^] + tstr;
- dec(lngth^);
- end;
- val(tstr,timdly,error);
- if (error<>0) or ((timdly<1)or(timdly>120)) then
- begin
- writeln('Invalid time delay factor must be >=1 and <= 120.',^G);
- writeln;
- Report_error;
- halt(3);
- end;
- writeln(prompt^);
- write(' ');
- X := wherex;
- Y := wherey;
- write(timdly:4,' seconds left to answer.');
- GetTime(hour,min,sec,hsec);
- Time1 := ((hour*360000)+(min*6000)+(sec*100)+hsec)+(timdly*100);
- GetTime(hour,min,sec,hsec);
- Time2 := ((hour*360000)+(min*6000)+(sec*100)+hsec);
- error := sec;
- while Time2<Time1 do
- begin
- if keypressed then
- begin
- inkey := Upcase(readkey);
- case inkey of
- 'Y' : halt(2);
- 'N' : halt(1);
- end;
- end;
- GetTime(hour,min,sec,hsec);
- Time2 := ((hour*360000)+(min*6000)+(sec*100)+hsec);
- if sec <> error then
- begin
- error := sec;
- dec(timdly);
- gotoxy(X,Y);
- write(timdly:4,^G);
- end;
- end;
- end;
- Halt(0);
- end.