home *** CD-ROM | disk | FTP | other *** search
- /*
-
- --------------------------------------------------------------------------
-
- Time v1.2 Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
- This piece of code is FREEWARE. Do anything with it but don't gain money
- for my work! And please spread exe + source!
-
- What does it do? Simply tells you how much time did a command take to
- complete.
-
- rekststef@unisi.it
-
- Stefano Reksten c/o Naimi,
- v.le Cavour 40,
- 53100 Siena
- Italy
-
- --------------------------------------------------------------------------
-
- Time v1.4 Copyright © February 2nd, 1997 by Matthias Andree
-
- mandree@sx1.hrz.uni-dortmund.de
-
- Matthias Andree
- Stormstr. 14
- 58099 Hagen
- Germany
-
- Motivation 1.2 -> 1.3
-
- GNU time did not start SEARCH properly
- This program
-
-
- Changes 1.2 -> 1.3
-
- - added Repeat option to improve accuracy for commands that last only a
- very short period of time
-
- - changed from system to SystemTags, thus OS 2.04+ only.
-
- - suppresses requesters
-
- - added SMAKEFILE and README
-
-
- Changes 1.3 -> 1.4
-
- - added FAILAT option, defaults to 10.
-
-
-
- Regards to Stefano Reksten, Oliver B. Warzecha
-
- --------------------------------------------------------------------------
-
- */
-
- #include <exec/types.h>
- #include <exec/io.h>
- #include <devices/timer.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/timer.h>
- #include <clib/alib_protos.h>
- #include <dos.h>
- #include <dos/dostags.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <utility/tagitem.h>
- #include <string.h>
-
- #define RES_SECS 0
- #define RES_MICRO 1
-
- #ifndef __SASC
- #error This file needs autoinitialization and autotermination functions
- #error It is meant for use with SAS/C only, at this moment. Sorry.
- #endif
-
- #define VERSION "1.4"
-
- const char * const ver = "$VER: Time " VERSION " " __AMIGADATE__;
- static const char * const template = "R=REPEAT/K/N,F=FAILAT/K/N,C=COMMAND/A/F";
-
- struct Library *TimerBase;
- static struct Window *oldWin = NULL;
-
- __regargs int __STI_init(void)
- { /* save window pointer and suppress requesters */
- struct Process *p = (struct Process *)FindTask(NULL);
-
- oldWin = p -> pr_WindowPtr;
- p -> pr_WindowPtr = (void *)-1L;
-
- return 0;
- }
-
- __regargs void __STD_exit(void)
- { /* restore old window pointer, re-enabling requesters */
- struct Process *p = (struct Process *)FindTask(NULL);
- if(oldWin) p -> pr_WindowPtr = oldWin;
- }
-
-
- int main( void )
- {
- struct RDArgs *args;
- struct timeval start_time, end_time;
- struct timerequest *tIO;
- struct MsgPort *mport;
- LONG error;
- struct {
- LONG *repeat;
- LONG *failat;
- char *cmd_line;
- } myargs = { NULL, NULL, NULL };
-
- BPTR output;
- ULONG res[2];
-
- char myname[256];
-
- if(DOSBase -> dl_lib.lib_Version < 37L) {
- char *warn = "This program requires OS 2.04 (V37) or newer.\n";
- Write(Output(), warn, (LONG)strlen(warn));
- return RETURN_FAIL;
- }
-
- if(!GetProgramName(myname, sizeof(myname))) strcpy(myname, "");
-
- if ( args = ReadArgs((char *)template, (LONG *)&myargs, NULL ) ) {
- if ( mport = CreateMsgPort() ) {
- if ( tIO = (struct timerequest *)CreateExtIO(mport,sizeof(struct timerequest)) ) {
- if ( !OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest*)tIO,0L) ) {
- ULONG count, i;
- LONG failat;
- BPTR nilhandle = Open("NIL:", MODE_NEWFILE); /* safe if NULL */
-
- TimerBase = (struct Library *)tIO->tr_node.io_Device;
-
- output = Output();
- VFPrintf( output, "Time v" VERSION " © 1994/1997 by Stefano Reksten, Matthias Andree\n", NULL );
- count = myargs.repeat ? *myargs.repeat : 1;
- failat = myargs.failat ? *myargs.failat : 10;
- if(failat < 0) {
- PrintFault(ERROR_BAD_NUMBER, myname);
- return RETURN_FAIL;
- }
-
- GetSysTime( &start_time );
-
- for(error = 0, i = 0;
- error >= 0 && error < failat && i < count;
- i++)
- {
- error = SystemTags( myargs.cmd_line,
- SYS_Input, NULL,
- SYS_Output, nilhandle, /* safe */
- NP_WindowPtr, -1, /* suppress requestors */
- TAG_DONE );
- }
-
- GetSysTime( &end_time );
-
- if(error < 0 || error > failat) {
- PrintFault(IoErr(), myname);
- } else {
- ULONG timediff;
-
- if ( end_time.tv_micro < start_time.tv_micro ) {
- start_time.tv_secs--;
- res[RES_MICRO] = (1000000 + end_time.tv_micro) - start_time.tv_micro;
- } else {
- res[RES_MICRO] = end_time.tv_micro - start_time.tv_micro;
- }
- res[RES_SECS] = end_time.tv_secs - start_time.tv_secs;
-
- timediff = res[RES_SECS] * 1000000 + res[RES_MICRO];
-
- timediff /= count;
-
- res[RES_SECS] = timediff / 1000000;
- res[RES_MICRO] = timediff % 1000000;
-
- VFPrintf( output, "Command took %lu,%06lu s.\n", (LONG *)res );
- }
- CloseDevice((struct IORequest *)tIO);
- }
- DeleteExtIO((struct IORequest *)tIO);
- }
- DeleteMsgPort(mport);
- }
- FreeArgs( args );
- } else {
- PrintFault( IoErr(), myname );
- }
- }
-