home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / DLYASK.ZIP / DLYASK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-08-26  |  4.0 KB  |  114 lines

  1. {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
  2. {$M 16384,0,0}
  3.  
  4. (************************************************************************
  5. *                                                                       *
  6. *     Command Line parsing program with user time limit factoring       *
  7. *                                                                       *
  8. *          For usage in DOS batch files to give operator                *
  9. *          a choice of which process to do next.                        *
  10. *                                                                       *
  11. *          Returns:                                                     *
  12. *             errorlevel 3 if invalid time delay factor                 *
  13. *             errorlevel 2 if user answers "Y"                          *
  14. *             errorlevel 1 if user answers "N"                          *
  15. *             errorlevel 0 if no user response                          *
  16. *                                                                       *
  17. *                                                                       *
  18. *                       Copyright (c) 1988                              *
  19. *             Dennis M. Passmore, Edgewater, FL. 32032                  *
  20. *                                                                       *
  21. ************************************************************************)
  22.  
  23. uses
  24.   crt,
  25.   dos;
  26.  
  27. var
  28.   prompt : ^string;
  29.   lngth  : ^byte;
  30.   inkey  : char;
  31.   timdly,X,Y,
  32.   error  : integer;
  33.   hour,min,
  34.   sec,hsec:word;
  35.   time1,
  36.   time2  : longint;
  37.   tstr   : string[4];
  38.  
  39. procedure Report_error;
  40.   begin
  41.     writeln('Usage >  DLYASK {user prompt} {seconds delay (max 120)} ');
  42.     writeln;
  43.     writeln('Example: DLYASK Do you want to EXIT to DOS (Y/N)? 10 ');
  44.     writeln;
  45.     writeln('         In the above example the program will prompt ');
  46.     writeln('         the user with the line: ');
  47.     writeln('               Do you want to EXIT to DOS (Y/N)? ');
  48.     writeln('         and then wait for: ');
  49.     writeln('                10 seconds ');
  50.     writeln('         for a reply from the user. If the user replys ');
  51.     writeln('         "Y" then the program will return DOS errorlevel ');
  52.     writeln('         2. If the user returns replys "N" then the ');
  53.     writeln('         program will return DOS errorlevel 1. If the ');
  54.     writeln('         user does not reply the program will return ');
  55.     writeln('         DOS errorlevel 0.');
  56.     writeln;
  57.     writeln('      A invalid Time Delay value will return errorlevel 3.');
  58.   end;
  59.  
  60.  
  61. begin
  62.   if paramcount = 0 then
  63.     Report_error
  64.   else
  65.     begin
  66.       prompt := ptr(Prefixseg,$80);
  67.       lngth  := ptr(Prefixseg,$80);
  68.       tstr   := '';
  69.       while (lngth^<>0) and (prompt^[lngth^]<>' ') do
  70.         begin
  71.           tstr   := prompt^[lngth^] + tstr;
  72.           dec(lngth^);
  73.         end;
  74.       val(tstr,timdly,error);
  75.       if (error<>0) or ((timdly<1)or(timdly>120)) then
  76.         begin
  77.           writeln('Invalid time delay factor must be >=1 and <= 120.',^G);
  78.           writeln;
  79.           Report_error;
  80.           halt(3);
  81.         end;
  82.       writeln(prompt^);
  83.       write('   ');
  84.       X := wherex;
  85.       Y := wherey;
  86.       write(timdly:4,' seconds left to answer.');
  87.       GetTime(hour,min,sec,hsec);
  88.       Time1 := ((hour*360000)+(min*6000)+(sec*100)+hsec)+(timdly*100);
  89.       GetTime(hour,min,sec,hsec);
  90.       Time2 :=  ((hour*360000)+(min*6000)+(sec*100)+hsec);
  91.       error := sec;
  92.       while Time2<Time1 do
  93.         begin
  94.           if keypressed then
  95.             begin
  96.               inkey := Upcase(readkey);
  97.               case inkey of
  98.                 'Y' : halt(2);
  99.                 'N' : halt(1);
  100.               end;
  101.             end;
  102.           GetTime(hour,min,sec,hsec);
  103.           Time2 :=  ((hour*360000)+(min*6000)+(sec*100)+hsec);
  104.           if sec <> error then
  105.             begin
  106.               error := sec;
  107.               dec(timdly);
  108.               gotoxy(X,Y);
  109.               write(timdly:4,^G);
  110.             end;
  111.         end;
  112.     end;
  113.     Halt(0);
  114. end.