#include "defs.h" #include "prims.h" PRIM(systime) { STACKROOM(1); MPUSH(PROG_INTEGER,(int)curtm()); } PRIM(ctime) { struct inst *v; time_t t; char buf[25]; NARGS(1); v = TOS(0); if (v->type != PROG_INTEGER) ABORT_INTERP("Invalid argument."); t = v->data.number; bcopy(asctime(localtime(&t)),&buf[0],24); buf[24] = '\0'; POP(1); MPUSH(PROG_STRING,dup_string(&buf[0])); } #define FOO(name,f1,f2,f3) \ PRIM(name) { time_t t; struct tm *tm; STACKROOM(3); t = curtm(); \ tm = localtime(&t); MPUSH(PROG_INTEGER,(int)(f1)); \ MPUSH(PROG_INTEGER,(int)(f2)); MPUSH(PROG_INTEGER,(int)(f3)); } FOO(time,tm->tm_sec,tm->tm_min,tm->tm_hour) FOO(date,tm->tm_mday,tm->tm_mon+1,tm->tm_year+1900) #undef FOO #define BAR(x) MPUSH(PROG_INTEGER,(int)(x)) #define FOO(name,cvt) \ PRIM(name) { struct inst *v; time_t t; struct tm *tm; NARGS(1); \ v = TOS(0); if (v->type != PROG_INTEGER) \ { ABORT_INTERP("Invalid argument."); } t = v->data.number; \ POP(1); STACKROOM(8); tm = cvt(&t); BAR(tm->tm_sec); \ BAR(tm->tm_min); BAR(tm->tm_hour); BAR(tm->tm_mday); \ BAR(tm->tm_mon+1); BAR(tm->tm_year+1900); BAR(tm->tm_wday+1); \ BAR(tm->tm_yday+1); } FOO(gmtsplit,gmtime) FOO(timesplit,localtime) #undef FOO #undef BAR #ifdef TIMESTAMPS PRIM(touch) { struct inst *v; NARGS(1); v = TOS(0); if (! valid_object(v)) ABORT_INTERP("Invalid object."); DBSTORE(v->data.objref,time_used,curtm()); POP(1); } #define FOO(name) \ PRIM(name) { struct inst *v; int rv; NARGS(1); v = TOS(0); \ if (! valid_object(v)) ABORT_INTERP("Invalid object."); \ rv = DBFETCH(v->data.objref)->name; POP(1); \ MPUSH(PROG_INTEGER,rv); } FOO(time_created) FOO(time_modified) FOO(time_used) #endif #if 0 void prims_gmtmerge (dbref player, dbref program, struct inst *pc, struct inst *arg, int *top, struct frame *fr) { struct tm tm; time_t t; CHECKOP(8); oper1 = POP(); oper2 = POP(); oper3 = POP(); oper4 = POP(); oper5 = POP(); oper6 = POP(); oper7 = POP(); oper8 = POP(); if ( (oper1->type != PROG_INTEGER) || (oper2->type != PROG_INTEGER) || (oper3->type != PROG_INTEGER) || (oper4->type != PROG_INTEGER) || (oper5->type != PROG_INTEGER) || (oper6->type != PROG_INTEGER) || (oper7->type != PROG_INTEGER) || (oper8->type != PROG_INTEGER) ) ABORT_INTERP("Invalid argument."); tm.tm_sec = oper1->data.number; tm.tm_min = oper2->data.number; tm.tm_hour = oper3->data.number; tm.tm_mday = oper4->data.number; tm.tm_mon = oper5->data.number - 1; tm.tm_year = oper6->data.number - 1900; tm.tm_wday = oper7->data.number - 1; tm.tm_yday = oper8->data.number - 1; CLEAR(oper1); CLEAR(oper2); CLEAR(oper3); CLEAR(oper4); CLEAR(oper5); CLEAR(oper6); CLEAR(oper7); CLEAR(oper8); t = timegm(&tm); PUSHINT(t); } void prims_timemerge (dbref player, dbref program, struct inst *pc, struct inst *arg, int *top, struct frame *fr) { struct tm tm; time_t t; CHECKOP(8); oper1 = POP(); oper2 = POP(); oper3 = POP(); oper4 = POP(); oper5 = POP(); oper6 = POP(); oper7 = POP(); oper8 = POP(); if ( (oper1->type != PROG_INTEGER) || (oper2->type != PROG_INTEGER) || (oper3->type != PROG_INTEGER) || (oper4->type != PROG_INTEGER) || (oper5->type != PROG_INTEGER) || (oper6->type != PROG_INTEGER) || (oper7->type != PROG_INTEGER) || (oper8->type != PROG_INTEGER) ) ABORT_INTERP("Invalid argument."); tm.tm_sec = oper1->data.number; tm.tm_min = oper2->data.number; tm.tm_hour = oper3->data.number; tm.tm_mday = oper4->data.number; tm.tm_mon = oper5->data.number - 1; tm.tm_year = oper6->data.number - 1900; tm.tm_wday = oper7->data.number - 1; tm.tm_yday = oper8->data.number - 1; CLEAR(oper1); CLEAR(oper2); CLEAR(oper3); CLEAR(oper4); CLEAR(oper5); CLEAR(oper6); CLEAR(oper7); CLEAR(oper8); t = timelocal(&tm); PUSHINT(t); } #endif