void vlog2file(int prepend_time, char *filename, char *format, va_list args) { FILE *fp; time_t lt; char buf[40]; lt = time(NULL); *buf = '\0'; if ((fp = fopen(filename, "ab")) == NULL) { fprintf(stderr, "Unable to open %s!\n", filename); if (prepend_time) fprintf(stderr, "%.16s: ", ctime(<)); vfprintf(stderr, format, args); } else { if (prepend_time) { format_time(buf, 32, "%c", MUCK_LOCALTIME(lt)); fprintf(fp, "%.32s: ", buf); } vfprintf(fp, format, args); fprintf(fp, "\n"); fclose(fp); } }
void prim_timesplit(PRIM_PROTOTYPE) { time_t lt = 0; CHECKOP(1); oper1 = POP(); /* integer: time */ if (oper1->type != PROG_INTEGER) abort_interp("Invalid argument"); lt = (time_t) oper1->data.number; time_tm = MUCK_LOCALTIME(lt); CHECKOFLOW(8); CLEAR(oper1); result = time_tm->tm_sec; PushInt(result); result = time_tm->tm_min; PushInt(result); result = time_tm->tm_hour; PushInt(result); result = time_tm->tm_mday; PushInt(result); result = time_tm->tm_mon + 1; PushInt(result); result = time_tm->tm_year + 1900; PushInt(result); result = time_tm->tm_wday + 1; PushInt(result); result = time_tm->tm_yday + 1; PushInt(result); }
void interp_err(dbref player, dbref program, struct inst *pc, struct inst *arg, int atop, dbref origprog, const char *msg1, const char *msg2) { char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char tbuf[40]; int errcount; time_t lt; err++; if (OWNER(origprog) == OWNER(player)) { strcpyn(buf, sizeof(buf), "\033[1;31;40mProgram Error. Your program just got the following error.\033[0m"); } else { snprintf(buf, sizeof(buf), "\033[1;31;40mProgrammer Error. Please tell %s what you typed, and the following message.\033[0m", NAME(OWNER(origprog))); } notify_nolisten(player, buf, 1); notifyf_nolisten(player, "\033[1m%s(#%d), line %d; %s: %s\033[0m", NAME(program), program, pc ? pc->line : -1, msg1, msg2); lt = time(NULL); format_time(tbuf, 32, "%c", MUCK_LOCALTIME(lt)); strip_ansi(buf2, buf); errcount = get_property_value(origprog, ".debug/errcount"); errcount++; add_property(origprog, ".debug/errcount", NULL, errcount); add_property(origprog, ".debug/lasterr", buf2, 0); add_property(origprog, ".debug/lastcrash", NULL, (int)lt); add_property(origprog, ".debug/lastcrashtime", tbuf, 0); if (origprog != program) { errcount = get_property_value(program, ".debug/errcount"); errcount++; add_property(program, ".debug/errcount", NULL, errcount); add_property(program, ".debug/lasterr", buf2, 0); add_property(program, ".debug/lastcrash", NULL, (int)lt); add_property(program, ".debug/lastcrashtime", tbuf, 0); } }
void prim_date(PRIM_PROTOTYPE) { CHECKOP(0); CHECKOFLOW(3); { time_t lt; struct tm *tm; lt = time(NULL); tm = MUCK_LOCALTIME(lt); result = tm->tm_mday; PushInt(result); result = tm->tm_mon + 1; PushInt(result); result = tm->tm_year + 1900; PushInt(result); } }
void prim_time(PRIM_PROTOTYPE) { CHECKOP(0); CHECKOFLOW(3); { time_t lt; struct tm *tm; lt = time(NULL); tm = MUCK_LOCALTIME(lt); result = tm->tm_sec; PushInt(result); result = tm->tm_min; PushInt(result); result = tm->tm_hour; PushInt(result); } }
void log_user(dbref player, dbref program, char *logmessage) { char logformat[BUFFER_LEN]; char buf[40]; time_t lt = 0; int len = 0; *buf='\0'; *logformat='\0'; lt=time(NULL); format_time(buf, 32, "%c", MUCK_LOCALTIME(lt)); snprintf(logformat,BUFFER_LEN,"%s(#%d) [%s(#%d)] at %.32s: ", NAME(player), player, NAME(program), program, buf); len = BUFFER_LEN - strlen(logformat)-1; strncat (logformat, logmessage, len); strip_evil_characters(logformat); log2file(USER_LOG,"%s",logformat); }
long get_tz_offset(void) { /* * SunOS don't seem to have timezone as a "extern long", but as * a structure. This makes it very hard (at best) to check for, * therefor I'm checking for tm_gmtoff. --WF */ #ifdef HAVE_STRUCT_TM_TM_GMTOFF time_t now; time(&now); return (MUCK_LOCALTIME(now)->tm_gmtoff); #elif defined(HAVE_DECL__TIMEZONE) /* CygWin uses _timezone instead of timezone. */ return _timezone; #else /* extern long timezone; */ return timezone; #endif }
void prim_timefmt(PRIM_PROTOTYPE) { time_t lt = 0; CHECKOP(2); oper2 = POP(); /* integer: time */ oper1 = POP(); /* string: format */ if (oper1->type != PROG_STRING) abort_interp("Invalid argument (1)"); if (!oper1->data.string) abort_interp("Illegal NULL string (1)"); if (oper2->type != PROG_INTEGER) abort_interp("Invalid argument (2)"); lt = (time_t) oper2->data.number; time_tm = MUCK_LOCALTIME(lt); if (!format_time(buf, BUFFER_LEN, oper1->data.string->data, time_tm)) abort_interp("Operation would result in overflow."); CHECKOFLOW(1); CLEAR(oper1); CLEAR(oper2); PushString(buf); }