Skip to content
Snippets Groups Projects
Commit 5c9c62f2 authored by rswindell's avatar rswindell
Browse files

Replace unixtime.c with xptime.c and added to make/project files.

parent 2516f554
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,10 @@ $(WRAPTEST): $(XPDEV-MT_LIB_BUILD) $(TESTOBJS) $(EXEODIR)
@echo Linking $<
$(QUIET)$(CC) $(LDFLAGS) $(MT_LDFLAGS) $(XPDEV-MT_CFLAGS) $(XPDEV-MT_LDFLAGS) -e$@ $(TESTOBJS) $(XPDEV-MT_LIBS)
$(XPTIME): $(XPDEV_LIB_BUILD) $(OBJODIR)$(DIRSEP)xptime$(OFILE)
@echo Linking $<
$(QUIET)$(CC) $(LDFLAGS) $(LDFLAGS) $(XPDEV-CFLAGS) $(XPDEV-LDFLAGS) -e$@ $** $(XPDEV-LIBS)
$(XPDEV_LIB_BUILD): $(OBJS)
@echo Creating $< ...
-$(QUIET)$(DELETE) $@
......
......@@ -21,6 +21,7 @@ OBJS = \
$(OBJODIR)$(DIRSEP)str_list$(OFILE) \
$(OBJODIR)$(DIRSEP)strwrap$(OFILE) \
$(OBJODIR)$(DIRSEP)xpbeep$(OFILE) \
$(OBJODIR)$(DIRSEP)xpdatetime$(OFILE) \
$(OBJODIR)$(DIRSEP)xpprintf$(OFILE)
......@@ -42,6 +43,7 @@ MTOBJS = \
$(MTOBJODIR)$(DIRSEP)strwrap$(OFILE) \
$(MTOBJODIR)$(DIRSEP)threadwrap$(OFILE) \
$(MTOBJODIR)$(DIRSEP)xpbeep$(OFILE) \
$(MTOBJODIR)$(DIRSEP)xpdatetime$(OFILE) \
$(MTOBJODIR)$(DIRSEP)xpprintf$(OFILE)
TESTOBJS = \
......
......@@ -7,6 +7,7 @@
# ODIR, DIRSEP, LIBFILE, EXEFILE, and DELETE must be pre-defined
WRAPTEST = $(EXEODIR)$(DIRSEP)wraptest$(EXEFILE)
XPTIME = $(EXEODIR)$(DIRSEP)xptime$(EXEFILE)
XPDEV_LIB_BUILD = $(LIBODIR)$(DIRSEP)$(LIBPREFIX)xpdev$(LIBFILE)
XPDEV-MT_LIB_BUILD = $(LIBODIR)$(DIRSEP)$(LIBPREFIX)xpdev_mt$(LIBFILE)
XPDEV_SHLIB_BUILD = $(LIBODIR)$(DIRSEP)$(LIBPREFIX)xpdev$(SOFILE)
......@@ -26,4 +27,6 @@ mtlib: $(MTOBJODIR) $(LIBODIR) $(XPDEV-MT_LIB_BUILD)
dl-mtlib: $(MTOBJODIR) $(LIBODIR) $(XPDEV-MT_SHLIB_BUILD)
xptime: $(OBJODIR) $(LIBODIR) $(EXEODIR) $(XPTIME)
$(WRAPTEST): $(XPDEV-MT_LIB_BUILD)
......@@ -11,33 +11,7 @@
#define USE_SNPRINTF /* we don't need safe_snprintf for this project */
#include "genwrap.h"
#include "datewrap.h"
/****************************************************************************/
/* Converts a date string in format MM/DD/YY into unix time format */
/****************************************************************************/
time_t dstrtounix(char *str)
{
char *p;
struct tm t;
memset(&t,0,sizeof(t));
t.tm_year=((str[6]&0xf)*10)+(str[7]&0xf);
if(t.tm_year<70)
t.tm_year+=100;
t.tm_mon=((str[0]&0xf)*10)+(str[1]&0xf);
if(t.tm_mon) t.tm_mon--;
t.tm_mday=((str[3]&0xf)*10)+(str[4]&0xf);
p=strchr(str,' ');
if(p) {
t.tm_hour=atoi(++p);
p=strchr(p,':');
if(p) {
t.tm_min=atoi(++p);
p=strchr(p,':');
if(p)
t.tm_sec=atoi(++p); } }
return(mktime(&t));
}
#include "xpdatetime.h"
time_t checktime()
{
......@@ -51,11 +25,13 @@ time_t checktime()
int main(int argc, char **argv)
{
char str[256];
char revision[16];
time_t t;
struct tm* tm;
int argn=1;
char str[256];
char revision[16];
time_t t;
struct tm* tp;
struct tm tm;
int argn=1;
xpDateTime_t xpDateTime;
printf("\n");
DESCRIBE_COMPILER(str);
......@@ -71,7 +47,7 @@ int main(int argc, char **argv)
#endif
if(argc<2)
printf("usage: unixtime [-z] <MM/DD/YY HH:MM:SS || time_t>\n\n");
printf("usage: xptime [-z] <date_str || time_t>\n\n");
if(argc>1 && stricmp(argv[1],"-z")==0) { /* zulu/GMT/UTC timezone */
printf("Setting timezone to Zulu/GMT/UTC\n\n");
......@@ -83,29 +59,54 @@ int main(int argc, char **argv)
printf("Current timezone: %d\n", xpTimeZone_local());
printf("\n");
if(argc>argn && argv[argn][2]=='/') {
sprintf(str,"%s %s",argv[argn],argc>argn+1 ? argv[argn+1] : "");
if((t=dstrtounix(str))==-1) {
printf("dstrtounix error\n");
return -1;
}
printf("Using specified date and time: ");
if(argc>argn && strlen(argv[argn]) > 10) {
xpDateTime=isoDateTimeStr_parse(argv[argn]);
t=xpDateTime_to_time(xpDateTime);
printf("Using specified date and time:\n");
} else if(argc>argn) {
printf("Using specified time_t value: ");
printf("Using specified time_t value:\n");
t=strtoul(argv[argn],NULL,0);
xpDateTime=time_to_xpDateTime(t,xpTimeZone_LOCAL);
} else {
printf("Using current time_t value: ");
printf("Using current time:\n");
xpDateTime=xpDateTime_now();
t=time(NULL);
}
printf("%ld (%08lX)\n", t, t);
if((tm=localtime(&t))==NULL)
printf("localtime() failure\n");
else
printf("%-8s %.24s\n","local", asctime(tm));
if((tm=gmtime(&t))==NULL)
printf("gmtime() failure\n");
else
printf("%-8s %.24s\n","GMT", asctime(tm));
printf("%-8s %-10ld (0x%08lX) ISO %s\n"
,"time_t"
,t, t
,xpDateTime_to_isoDateTimeStr(xpDateTime
,NULL, " ", NULL
,/* precision: */3
, str, sizeof(str)));
{
const char* fmt="%-8s %.24s ISO %s\n";
if((tp=localtime_r(&t, &tm))==NULL)
printf("localtime() failure\n");
else
printf(fmt
,"local"
,asctime(tp)
,xpDateTime_to_isoDateTimeStr(
time_to_xpDateTime(t, xpTimeZone_LOCAL)
,NULL, " ", NULL
,/*precision: */0
,str, sizeof(str))
);
if((tp=gmtime_r(&t, &tm))==NULL)
printf("gmtime() failure\n");
else
printf(fmt
,"GMT"
,asctime(tp)
,xpDateTime_to_isoDateTimeStr(
gmtime_to_xpDateTime(t)
,NULL, " ", NULL
,/*precision: */0
,str, sizeof(str))
);
}
return(0);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment