From ae887b75273250dc382c3ac063cd70433be23460 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 1 May 2007 20:23:57 +0000 Subject: [PATCH] Make date() command available to all architectures. Allow the user to specify the date/time format string. --- src/libCom/iocsh/libComRegister.c | 27 +++++++++++++++++++++++++++ src/libCom/osi/os/vxWorks/iocClock.c | 21 --------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/libCom/iocsh/libComRegister.c b/src/libCom/iocsh/libComRegister.c index a03762ccb..5ffd7b191 100644 --- a/src/libCom/iocsh/libComRegister.c +++ b/src/libCom/iocsh/libComRegister.c @@ -13,6 +13,7 @@ #define epicsExportSharedSymbols #include "iocsh.h" +#include "epicsTime.h" #include "epicsThread.h" #include "epicsMutex.h" #include "envDefs.h" @@ -22,6 +23,31 @@ #include "libComRegister.h" +void date(const char *format) +{ + epicsTimeStamp now; + char nowText[80] = {'\0'}; + + if (epicsTimeGetCurrent(&now)) { + puts("Current time not available."); + return; + } + if (format == NULL || format[0] == '\0') + format = "%Y/%m/%d %H:%M:%S.%06f"; + epicsTimeToStrftime(nowText, sizeof(nowText), format, &now); + puts(nowText); +} + +/* date */ +static const iocshArg dateArg0 = { "format",iocshArgString}; +static const iocshArg * const dateArgs[] = {&dateArg0}; +static const iocshFuncDef dateFuncDef = {"date", 1, dateArgs}; +static void dateCallFunc (const iocshArgBuf *args) +{ + date(args[0].sval); +} + + /* chdir */ static const iocshArg chdirArg0 = { "directory name",iocshArgString}; static const iocshArg * const chdirArgs[1] = {&chdirArg0}; @@ -267,6 +293,7 @@ static void epicsThreadResumeCallFunc(const iocshArgBuf *args) void epicsShareAPI libComRegister(void) { + iocshRegister(&dateFuncDef, dateCallFunc); iocshRegister(&chdirFuncDef, chdirCallFunc); iocshRegister(&pwdFuncDef, pwdCallFunc); diff --git a/src/libCom/osi/os/vxWorks/iocClock.c b/src/libCom/osi/os/vxWorks/iocClock.c index 545e504d0..5617b3ed0 100644 --- a/src/libCom/osi/os/vxWorks/iocClock.c +++ b/src/libCom/osi/os/vxWorks/iocClock.c @@ -217,24 +217,3 @@ int epicsTimeGetEvent (epicsTimeStamp *pDest, int eventNumber) return(epicsTimeERROR); } -/* Unless - putenv("TIMEZONE=::::") - is executed before and epics software is loaded, UTC rather than local - time will be displayed -*/ -void date() -{ - epicsTimeStamp now; - char nowText[40]; - size_t rtn; - - rtn = epicsTimeGetCurrent(&now); - if(rtn) { - printf("epicsTimeGetCurrent failed\n"); - return; - } - nowText[0] = 0; - rtn = epicsTimeToStrftime(nowText,sizeof(nowText), - "%Y/%m/%d %H:%M:%S.%06f",&now); - printf("%s\n",nowText); -}