// (c) 1993-2007 Electronic Arts Inc.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if defined(__PPU__) && !defined(__ELF__)
#include <sys/timer.h>
#endif
#if defined(_MSC_VER)
#include <windows.h>
#else
#include <unistd.h>
#endif

/*
 originally written by Pete Veys
 documented and rewritten by Frank Barchard

 2005.9.14 switch to Sleep function
*/


/* Spit stubs */
char *SPIT_opt(const char *optptr)
{
    optptr;
    return (char *)0;
}

void SPIT_usage(const char *prgname, const char *envname,int utype)
{
    prgname;
    envname;
    utype;
    return;
}

#if 0
;
; ABSTRACT
;
; sleep - waits n seconds and continues
;
; SUMMARY
;
; sleep [<seconds>]
;
; DESCRIPTION
;
; Sleeps the specified number of seconds and then returns.
; This allows scripts to insert a delay before continuing to
; process.  The sleep amount is accurate to milliseconds.
;
; RETURNS
;
; no return.
;
; SEE ALSO
;
; sleep (SGI function), pause (DOS function)
;
; EXAMPLE
;
; >sleep 5
;
; END ABSTRACT
;
#endif

int main(int argc, char *argv[])
{
    double sleeptime;

    if (argc<2)
    {
        printf("sleep <n> where n is number of seconds (floating point)\n");
        exit(1);
    }

    sleeptime = atof(argv[1]);

#if defined(_MSC_VER)
    Sleep((int)(sleeptime*1000.0f));
#elif defined(__PPU__) && !defined(__ELF__)
    sys_timer_usleep((usecond_t)(sleeptime*1000000));
#else
    usleep((__useconds_t)(sleeptime*1000000));
#endif

    return(0);
}
