2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
8 /******************************************************************************
13 Wait [(n)] [SEC | SECS | MIN | MINS] [ UNTIL (time) ]
17 TIME/N,SEC=SECS/S,MIN=MINS/S,UNTIL/K
25 Wait a certain amount of time or until a specified time. Using
26 Wait without any arguments waits for one second.
30 TIME -- the number of time units to wait (default is seconds)
31 SEC=SECS -- set the time unit to seconds
32 MIN=MINS -- set the time unit to minutes
33 UNTIL -- wait until the specified time is reached. The time
34 is given in the format HH:MM.
48 ******************************************************************************/
50 #include <exec/execbase.h>
51 #include <exec/libraries.h>
52 #include <devices/timer.h>
55 #include <proto/dos.h>
56 #include <proto/exec.h>
61 static const char version
[] = "$VER: Wait 41.2 (30.04.2000)\n";
67 IPTR args
[4] = { 0, 0, 0, 0 };
69 LONG error
= RETURN_OK
;
72 #define ERROR(a) { error = a; goto end; }
74 rda
= ReadArgs("TIME/N,SEC=SECS/S,MIN=MINS/S,UNTIL/K", args
, NULL
);
78 PrintFault(IoErr(),"Wait");
87 LONG now_secs
, then_secs
, diff_secs
;
91 now_secs
= ds
.ds_Minute
* 60 + ds
.ds_Tick
/ TICKS_PER_SECOND
;
93 if (strlen((char *)args
[3]) > 5)
95 puts("Time should be HH:MM");
99 strcpy(timestring
, (UBYTE
*)args
[3]);
100 strcat(timestring
, ":00");
102 memset(&dt
, 0, sizeof(dt
));
103 dt
.dat_StrTime
= timestring
;
107 puts("Time should be HH:MM");
111 then_secs
= dt
.dat_Stamp
.ds_Minute
* 60 + dt
.dat_Stamp
.ds_Tick
/ TICKS_PER_SECOND
;
112 diff_secs
= then_secs
- now_secs
;
116 diff_secs
+= 60L * 60L * 24L;
119 delay
= diff_secs
* TICKS_PER_SECOND
;
126 delay
= *((ULONG
*)args
[0]);
134 delay
*= TICKS_PER_SECOND
;
139 if (delay
<= TICKS_PER_SECOND
)
141 /* Don't care about breaking if delay is less than 1 second */
146 struct MsgPort
*timermp
;
147 struct timerequest
*timerio
;
148 BOOL memok
= FALSE
, devok
= FALSE
;
150 if ((timermp
= CreateMsgPort()))
152 if ((timerio
= (struct timerequest
*)CreateIORequest(timermp
, sizeof(struct timerequest
))))
155 if (OpenDevice("timer.device", UNIT_VBLANK
, &timerio
->tr_node
, 0) == 0)
157 ULONG timermask
, sigs
;
162 timerio
->tr_node
.io_Command
= TR_ADDREQUEST
;
163 timerio
->tr_time
.tv_secs
= delay
/ TICKS_PER_SECOND
;
164 timerio
->tr_time
.tv_micro
= 1000000UL / TICKS_PER_SECOND
* (delay
% TICKS_PER_SECOND
);
166 timermask
= 1L << timermp
->mp_SigBit
;
168 SendIO(&timerio
->tr_node
);
172 sigs
= Wait(SIGBREAKF_CTRL_C
| timermask
);
174 if (sigs
& timermask
)
179 if (sigs
& SIGBREAKF_CTRL_C
)
181 if (!CheckIO(&timerio
->tr_node
)) AbortIO(&timerio
->tr_node
);
182 WaitIO(&timerio
->tr_node
);
188 } /* while(!finished) */
189 CloseDevice(&timerio
->tr_node
);
191 } /* if (OpenDevice("timer.device", UNIT_VBLANK, &timerio->tr_node, 0) == 0) */
192 DeleteIORequest(&timerio
->tr_node
);
194 } /* if (timerio = (struct timerequest *)CreateIORequest(timermp, sizeof(struct timerequest))) */
195 DeleteMsgPort(timermp
);
197 } /* if ((timermp = CreateMsgPort())) */
201 PrintFault(ERROR_NO_FREE_STORE
,"Wait");
206 puts("Wait: Could not open timer.device!");
212 } /* if (delay > 0) */