📄 runtime.c
字号:
/*
* RUNTIME.C - Displays the time a command takes to execute.
*
* PROGRAMMER: Martti Ylikoski
* CREATED: 6.12.1990
* NOTES: Original implementation used DosExecPgm and DosSearchPath-functions.
* However, DosSearchPath is not a member of Family API and
* therefore cannot be made into a bound executable.
* That is why I used the spawnvp-function. The original calls
* are commented out.
*
*/
static char *VERSION = "Versio 1.1, Copyright (c) Martti Ylikoski, 1990-1992" ;
/*
*/
#include <stdio.h>
#include <string.h>
#include <process.h>
#include <errno.h>
#define INCL_DOS
#include <os2.h>
#include <param.h>
#include <paramstd.h>
static char *progname, *fname ;
extern unsigned long pflags ;
ParamEntry pentry[12] = {
"P", &ParamSetPause, 0,
"F", &ParamSetFold, 0,
"V", &ParamSetVerbose, 1,
"R", &ParamSetReport, 1,
"S", &ParamSetSubDirs, 0,
"?", &ParamSetHelp, 1,
"H", &ParamSetHelp, 1,
"NOD", &ParamSetNoDefault, 0,
"TEST", &ParamSetTest, 0,
"Y", &ParamSetYes, 0,
"N", &ParamSetTest, 0,
"\0", NULL, 0
} ;
ParamBlock params = {
"/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
pentry
} ;
int main(int argc, char *argv[])
{
USHORT ret ;
ULONG size ;
DATETIME dt1, dt2 ;
CHAR achFailName[128], launchpgm[128];
RESULTCODES rescResults;
int hours, minutes, seconds, hundredths ;
int output ;
progname = argv[0] ;
hours = 0 ; minutes = 0 ; seconds = 0 ; hundredths = 0 ;
output = FALSE ;
ParamHandle(¶ms, &argc, argv) ;
if (pflags & PA_HELP || argc == 1)
{
printf("%s - displays the time a command takes to execute.\n", progname) ;
puts(VERSION) ;
printf("Usage: %s [/H | /? | /R ] command arguments\n", progname) ;
puts("Where:") ;
puts(" /R = Report mode /H,/? = Help") ;
if (argc == 1)
return( 0 ) ;
}
if (( ret = DosGetDateTime(&dt1)) != 0)
{
printf("%s: error in DosGetDateTime...\nExiting...\n", progname ) ;
return( 1 ) ;
}
/* OS/2 only specific block below
if ( strchr(argv[1], (int) '.') == NULL)
{
CHAR szFoundFile[128] ;
int i ;
char *exts[] = { ".exe", ".cmd"
} ;
for (i = 0 ; i < sizeof(exts) /sizeof(char *) ; i ++)
{
strcpy(launchpgm, argv[1]) ;
strcat(launchpgm, exts[i]) ;
if (DosSearchPath(DSP_ENVIRONMENT | DSP_CUR_DIRECTORY ,
"PATH", launchpgm, szFoundFile, sizeof(szFoundFile)) == 0)
{
strcpy(launchpgm, szFoundFile) ;
break ;
}
}
}
else
strcpy(launchpgm, argv[1]) ;
{
BYTE mode ;
DosGetMachineMode(&mode) ;
if (mode != MODE_PROTECTED)
{
*/
if (spawnvp(P_WAIT,argv[1],&argv[1] )== -1)
{
printf("%s: error in execv...\nExiting...\n", progname ) ;
return( 1 ) ;
}
// }
// }
// if (( ret = DosExecPgm(achFailName, /* object-name buffer */
// sizeof(achFailName), /* length of buffer */
// EXEC_SYNC, /* async flag */
// argv[1], /* argument string */
// 0, /* environment string */
// &rescResults, /* address of result */
// launchpgm)) != 0) /* name of program */
// {
// printf("%s: error in DosExecPgm...\nExiting...\n", progname ) ;
// return( 1 ) ;
// }
if (( ret = DosGetDateTime(&dt2)) != 0)
{
printf("%s: error in DosGetDateTime...\nExiting...\n", progname ) ;
return( 1 ) ;
}
if (dt2.hours < dt1.hours) /* during midnight */
dt2.hours += 24 ;
hours = dt2.hours - dt1.hours ;
minutes = dt2.minutes - dt1.minutes ;
if (minutes < 0)
{
minutes += 60 ;
hours -- ;
}
seconds = dt2.seconds - dt1.seconds ;
if (seconds < 0)
{
seconds += 60 ;
minutes -- ;
}
hundredths = dt2.hundredths - dt1.hundredths ;
if (hundredths < 0)
{
hundredths += 100 ;
seconds -- ;
}
if (pflags & PA_REPORT)
{
printf("[RUNTIME]\nhours=%d\nminutes=%d\nseconds=%d\nhundredths=%d\n",
hours, minutes, seconds, hundredths) ;
}
else
{
printf("\nRUNTIME:\nTOTAL ELAPSED TIME:\n") ;
if (hours != 0)
{
output = TRUE ;
printf("%d hours, ", hours) ;
}
if (minutes != 0 || output == TRUE)
{
output = TRUE ;
printf("%d minutes, ", minutes ) ;
}
if (seconds != 0 || output == TRUE)
{
output = TRUE ;
printf("%d seconds, \n", seconds ) ;
}
printf("%d hundredths.\n", hundredths ) ;
}
return( 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -