📄 filedate.c
字号:
struct Process *me = (void *) FindTask(NULL); void *old_window = me->pr_WindowPtr; char *ret = NULL; me->pr_WindowPtr = (void *) -1; /* suppress any "Please insert" popups */ if (SysBase->LibNode.lib_Version >= ReqVers) { if (GetVar((char *) var, space, ENVSIZE - 1, /* GVF_GLOBAL_ONLY */ 0) > 0) ret = space; } else { /* early AmigaDOS, get env var the crude way */ BPTR hand, foot, spine; int z = 0; if (foot = Lock("ENV:", ACCESS_READ)) { spine = CurrentDir(foot); if (hand = Open((char *) var, MODE_OLDFILE)) { z = Read(hand, space, ENVSIZE - 1); Close(hand); } UnLock(CurrentDir(spine)); } if (z > 0) { space[z] = '\0'; ret = space; } } me->pr_WindowPtr = old_window; return ret;}#ifdef __SASCint setenv(const char *var, const char *value, int overwrite){ struct Process *me = (void *) FindTask(NULL); void *old_window = me->pr_WindowPtr; int ret = -1; me->pr_WindowPtr = (void *) -1; /* suppress any "Please insert" popups */ if (SysBase->LibNode.lib_Version >= ReqVers) ret = !SetVar((char *) var, (char *) value, -1, GVF_GLOBAL_ONLY | LV_VAR); else { BPTR hand, foot, spine; long len = value ? strlen(value) : 0; if (foot = Lock("ENV:", ACCESS_READ)) { spine = CurrentDir(foot); if (len) { if (hand = Open((char *) var, MODE_NEWFILE)) { ret = Write(hand, (char *) value, len + 1) >= len; Close(hand); } } else ret = DeleteFile((char *) var); UnLock(CurrentDir(spine)); } } me->pr_WindowPtr = old_window; return ret;}#endif /* __SASC */#ifndef USE_TIME_LIB/* set timezone and daylight to settings found in locale.library */int locale_TZ(void){ struct Library *LocaleBase; struct Locale *ll; struct Process *me = (void *) FindTask(NULL); void *old_window = me->pr_WindowPtr; BPTR eh; int z, valid = FALSE; /* read timezone from locale.library if TZ envvar missing */ me->pr_WindowPtr = (void *) -1; /* suppress any "Please insert" popups */ if (LocaleBase = OpenLibrary("locale.library", 0)) { if (ll = OpenLocale(NULL)) { z = ll->loc_GMTOffset; if (z == -300) { if (eh = Lock("ENV:sys/locale.prefs", ACCESS_READ)) UnLock(eh); else z = 300; /* bug: locale not initialized, default is bogus! */ } else real_timezone_is_set = TRUE; timezone = z * 60; daylight = (z >= 4*60 && z <= 9*60); /* apply in the Americas */ valid = TRUE; CloseLocale(ll); } CloseLibrary(LocaleBase); } me->pr_WindowPtr = old_window; return valid;}void tzset(void){ char *p,*TZstring; int z,valid = FALSE; if (real_timezone_is_set) return; timezone = 0; /* default is GMT0 which means no offsets */ daylight = 0; /* from local system time */ TZstring = getenv("TZ"); /* read TZ envvar */ if (TZstring && TZstring[0]) { /* TZ exists and has contents? */ z = 3600; for (p = TZstring; *p && !isdigit(*p) && *p != '-'; p++) ; if (*p == '-') z = -3600, p++; if (*p) { timezone = 0; do { while (isdigit(*p)) timezone = timezone * 10 + z * (*p++ - '0'), valid = TRUE; if (*p == ':') p++; } while (isdigit(*p) && (z /= 60) > 0); } while (isspace(*p)) p++; /* probably not needed */ if (valid) { real_timezone_is_set = TRUE; daylight = !!*p; /* a DST name part exists */ } } if (!valid) locale_TZ(); /* read locale.library */#ifdef __SASC /* Some SAS/C library functions, e.g. stat(), call library */ /* __tzset() themselves. So envvar TZ *must* exist in order to */ /* to get the right offset from GMT. XXX WE SHOULD TRY HARD */ /* find and replace any remaining functions that need this! */ set_TZ(timezone, daylight);#endif /* __SASC */}struct tm *gmtime(const time_t *when){ static struct tm tbuf; /* this function is intrinsically non-reentrant */ static short smods[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; long days = *when / 86400; long secs = *when % 86400; short yell, yday; tbuf.tm_wday = (days + 4) % 7; /* 1/1/70 is a Thursday */ tbuf.tm_year = 70 + 4 * (days / 1461); yday = days % 1461; while (yday >= (yell = (tbuf.tm_year & 3 ? 365 : 366))) yday -= yell, tbuf.tm_year++; smods[1] = (tbuf.tm_year & 3 ? 28 : 29); tbuf.tm_mon = 0; tbuf.tm_yday = yday; while (yday >= smods[tbuf.tm_mon]) yday -= smods[tbuf.tm_mon++]; tbuf.tm_mday = yday + 1; tbuf.tm_isdst = 0; tbuf.tm_sec = secs % 60; tbuf.tm_min = (secs / 60) % 60; tbuf.tm_hour = secs / 3600;#ifdef AZTEC_C tbuf.tm_hsec = 0; /* this field exists for Aztec only */#endif return &tbuf;}struct tm *localtime(const time_t *when){ struct tm *t; time_t localwhen; int dst = FALSE, sundays, lastweekday; tzset(); localwhen = *when - timezone; t = gmtime(&localwhen); /* So far we support daylight savings correction by the USA rule only: */ if (daylight && t->tm_mon >= 3 && t->tm_mon <= 9) { if (t->tm_mon > 3 && t->tm_mon < 9) /* May Jun Jul Aug Sep: yes */ dst = TRUE; else { sundays = (t->tm_mday + 6 - t->tm_wday) / 7; if (t->tm_wday == 0 && t->tm_hour < 2 && sundays) sundays--; /* a Sunday does not count until 2:00am */ if (t->tm_mon == 3 && sundays > 0) /* first sunday in April */ dst = TRUE; else if (t->tm_mon == 9) { lastweekday = (t->tm_wday + 31 - t->tm_mday) % 7; if (sundays < (37 - lastweekday) / 7) dst = TRUE; /* last sunday in October */ } } if (dst) { localwhen += 3600; t = gmtime(&localwhen); /* crude but effective */ t->tm_isdst = 1; } } return t;}# ifdef ZIPtime_t time(time_t *tp){ time_t t; struct DateStamp ds; DateStamp(&ds); t = ds.ds_Tick / TICKS_PER_SECOND + ds.ds_Minute * 60 + (ds.ds_Days + 2922) * 86400; t = mktime(gmtime(&t)); /* gmtime leaves ds in the local timezone, mktime converts it to GMT */ if (tp) *tp = t; return t;}# endif /* ZIP */#endif /* !USE_TIME_LIB */#endif /* !FUNZIP */#if CRYPT || !defined(FUNZIP)/* sendpkt.c * by A. Finkel, P. Lindsay, C. Sheppner * returns Res1 of the reply packet *//*#include <exec/types.h>#include <exec/memory.h>#include <libraries/dos.h>#include <libraries/dosextens.h>#include <proto/exec.h>#include <proto/dos.h>*/LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);LONG sendpkt(pid,action,args,nargs)struct MsgPort *pid; /* process identifier (handler message port) */LONG action, /* packet type (desired action) */ *args, /* a pointer to argument list */ nargs; /* number of arguments in list */{ struct MsgPort *replyport, *CreatePort(UBYTE *, long); void DeletePort(struct MsgPort *); struct StandardPacket *packet; LONG count, *pargs, res1; replyport = CreatePort(NULL,0L); if( !replyport ) return(0); packet = (struct StandardPacket *)AllocMem( (long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR); if( !packet ) { DeletePort(replyport); return(0); } packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt); packet->sp_Pkt.dp_Link = &(packet->sp_Msg); packet->sp_Pkt.dp_Port = replyport; packet->sp_Pkt.dp_Type = action; /* copy the args into the packet */ pargs = &(packet->sp_Pkt.dp_Arg1); /* address of 1st argument */ for( count=0; count<nargs; count++ ) pargs[count] = args[count]; PutMsg(pid,(struct Message *)packet); /* send packet */ WaitPort(replyport); GetMsg(replyport); res1 = packet->sp_Pkt.dp_Res1; FreeMem((char *)packet,(long)sizeof(*packet)); DeletePort(replyport); return(res1);} /* sendpkt() */#endif /* CRYPT || !FUNZIP */#if CRYPT || (defined(UNZIP) && !defined(FUNZIP))/* Agetch() reads one raw keystroke -- uses sendpkt() */int Agetch(void){ LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs); struct Task *me = FindTask(NULL); struct CommandLineInterface *cli = BADDR(((struct Process *) me)->pr_CLI); BPTR fh = cli->cli_StandardInput; /* this is immune to < redirection */ void *conp = ((struct FileHandle *) BADDR(fh))->fh_Type; char longspace[8]; long *flag = (long *) ((ULONG) &longspace[4] & ~3); /* LONGWORD ALIGNED! */ UBYTE c; *flag = 1; sendpkt(conp, ACTION_SCREEN_MODE, flag, 1); /* assume success */ Read(fh, &c, 1); *flag = 0; sendpkt(conp, ACTION_SCREEN_MODE, flag, 1); if (c == 3) /* ^C in input */ Signal(me, SIGBREAKF_CTRL_C); return c;}#endif /* CRYPT || (UNZIP && !FUNZIP) */#endif /* __amiga_filedate_c*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -