123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- #ifndef __amiga_filedate_c
- #define __amiga_filedate_c
- #include "zip.h"
- #include <ctype.h>
- #include <errno.h>
- #include <exec/types.h>
- #include <exec/execbase.h>
- #include <exec/memory.h>
- #include <dos/dosextens.h>
- #ifdef AZTEC_C
- # include <libraries/dos.h>
- # include <libraries/dosextens.h>
- # include <clib/exec_protos.h>
- # include <clib/dos_protos.h>
- # include <clib/locale_protos.h>
- # include <pragmas/exec_lib.h>
- # include <pragmas/dos_lib.h>
- # include <pragmas/locale_lib.h>
- # define ESRCH ENOENT
- # define EOSERR EIO
- #endif
- #ifdef __SASC
- # include <stdlib.h>
- # if (defined(_M68020) && (!defined(__USE_SYSBASE)))
-
- # define __USE_SYSBASE
- # endif
- # include <proto/exec.h> /* see SAS/C manual:part 2,chapter 2,pages 6-7 */
- # include <proto/dos.h>
- # include <proto/locale.h>
- # ifdef DEBUG
- # include <sprof.h>
- # endif
- # ifdef MWDEBUG
- # include <stdio.h> /* include both before memwatch.h again just */
- # include <stdlib.h> /* to be safe */
- # include "memwatch.h"
- # endif
- #endif
- #include "crypt.h"
- #if (!defined(FUNZIP) && !defined(UTIL))
- #include "timezone.h"
- #ifndef SUCCESS
- # define SUCCESS (-1L)
- # define FAILURE 0L
- #endif
- #define ReqVers 36L
- #define ENVSIZE 100
- extern struct ExecBase *SysBase;
- #ifndef min
- # define min(a, b) ((a) < (b) ? (a) : (b))
- # define max(a, b) ((a) < (b) ? (b) : (a))
- #endif
- #if defined(ZIP) || defined(HAVE_MKTIME)
- static const unsigned short ydays[] =
- { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
- #else
- extern const unsigned short ydays[];
- #endif
- #define LEAP(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
- #define YDAYS(m, y) (ydays[m] + (m > 1 && LEAP(y)))
- #define ANLEAP(y) (((y) - 1977) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)
- #define SECSPERMIN 60
- #define MINSPERHOUR 60
- #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
- #define SECSPERDAY 86400L
- char *getenv(const char *var);
- #ifdef __SASC
- int setenv(const char *var, const char *value, int overwrite);
- void set_TZ(long time_zone, int day_light);
- #endif
- LONG FileDate(char *filename, time_t u[]);
- LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);
- int Agetch(void);
- LONG FileDate(filename, u)
- char *filename;
- time_t u[];
- {
- LONG SetFileDate(UBYTE *filename, struct DateStamp *pDate);
- LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);
- struct MsgPort *taskport;
- BPTR dirlock, lock;
- struct FileInfoBlock *fib;
- LONG pktargs[4];
- UBYTE *ptr;
- long ret;
- struct DateStamp pDate;
- struct tm *ltm;
- int years;
- tzset();
-
- ltm = localtime(&u[0]);
- years = ltm->tm_year + 1900;
- if (years < 1978)
- pDate.ds_Days = pDate.ds_Minute = pDate.ds_Tick = 0;
- else {
- pDate.ds_Days = (years - 1978) * 365L + (ANLEAP(years)) +
- YDAYS(ltm->tm_mon, years) + (ltm->tm_mday - 1);
- pDate.ds_Minute = ltm->tm_hour * 60 + ltm->tm_min;
- pDate.ds_Tick = ltm->tm_sec * TICKS_PER_SECOND;
- }
- if (SysBase->LibNode.lib_Version >= ReqVers)
- {
- return (SetFileDate(filename,&pDate));
- }
- else
- {
- if( !(taskport = (struct MsgPort *)DeviceProc(filename)) )
- {
- errno = ESRCH;
- return FAILURE;
- }
- if( !(lock = Lock(filename,SHARED_LOCK)) )
- {
- errno = ENOENT;
- return FAILURE;
- }
- if( !(fib = (struct FileInfoBlock *)AllocMem(
- (long)sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR)) )
- {
- errno = ENOMEM;
- UnLock(lock);
- return FAILURE;
- }
- if( Examine(lock,fib)==FAILURE )
- {
- errno = EOSERR;
- UnLock(lock);
- FreeMem(fib,(long)sizeof(*fib));
- return FAILURE;
- }
- dirlock = ParentDir(lock);
- ptr = (UBYTE *)AllocMem(64L,MEMF_PUBLIC);
- strcpy((ptr+1),fib->fib_FileName);
- *ptr = strlen(fib->fib_FileName);
- FreeMem(fib,(long)sizeof(*fib));
- UnLock(lock);
-
- pktargs[0] = 0;
- pktargs[1] = (LONG)dirlock;
- pktargs[2] = (LONG)&ptr[0] >> 2;
- pktargs[3] = (LONG)&pDate;
- errno = ret = sendpkt(taskport,ACTION_SET_DATE,pktargs,4L);
- FreeMem(ptr,64L);
- UnLock(dirlock);
- return SUCCESS;
- }
- }
- char *getenv(const char *var)
- {
- static char space[ENVSIZE];
- struct Process *me = (void *) FindTask(NULL);
- void *old_window = me->pr_WindowPtr;
- char *ret = NULL;
- me->pr_WindowPtr = (void *) -1;
- if (SysBase->LibNode.lib_Version >= ReqVers) {
- if (GetVar((char *) var, space, ENVSIZE - 1, 0) > 0)
- ret = space;
- } else {
- 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 __SASC
- int 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;
- 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;
- }
- void set_TZ(long time_zone, int day_light)
- {
- char put_tz[MAXTIMEZONELEN];
- int offset;
- void *exists;
- exists = (void *)getenv(TZ_ENVVAR);
-
- if (exists == NULL) {
-
- sprintf(put_tz, "GMT%+ld", time_zone / 3600L);
- if (time_zone % 3600L) {
- offset = (int) labs(time_zone % 3600L);
- sprintf(put_tz + strlen(put_tz), ":%02d", offset / 60);
- if (offset % 60)
- sprintf(put_tz + strlen(put_tz), ":%02d", offset % 60);
- }
- if (day_light)
- strcat(put_tz,"DST");
- setenv(TZ_ENVVAR, put_tz, 1);
- }
- }
- #endif
- int GetPlatformLocalTimezone(sp, fill_tzstate_from_rules)
- register struct state * ZCONST sp;
- void (*fill_tzstate_from_rules)(struct state * ZCONST sp_res,
- ZCONST struct rule * ZCONST start,
- ZCONST struct rule * ZCONST end);
- {
- struct Library *LocaleBase;
- struct Locale *ll;
- struct Process *me = (void *) FindTask(NULL);
- void *old_window = me->pr_WindowPtr;
- BPTR eh;
- int z, valid = FALSE;
-
- me->pr_WindowPtr = (void *) -1;
- 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);
- valid = TRUE;
- } else
- z = 300;
- } else
- valid = TRUE;
- if (valid) {
- struct rule startrule, stoprule;
- sp->timecnt = 0;
- sp->typecnt = 1;
- sp->charcnt = 2;
- sp->chars[0] = sp->chars[1] = '\0';
- sp->ttis[0].tt_abbrind = 0;
- sp->ttis[1].tt_abbrind = 1;
- sp->ttis[0].tt_gmtoff = -z * MINSPERHOUR;
- sp->ttis[1].tt_gmtoff = -z * MINSPERHOUR + SECSPERHOUR;
- sp->ttis[0].tt_isdst = 0;
- sp->ttis[1].tt_isdst = 1;
- stoprule.r_type = MONTH_NTH_DAY_OF_WEEK;
- stoprule.r_day = 0;
- stoprule.r_week = 5;
- stoprule.r_mon = 10;
- stoprule.r_time = 2 * SECSPERHOUR;
- startrule = stoprule;
- startrule.r_mon = 4;
- startrule.r_week = 1;
- if (z >= -180 && z < 150) {
-
-
-
-
-
-
- sp->typecnt = 2;
- startrule.r_mon = 3;
- startrule.r_week = 5;
- } else if (z >= 150 && z <= 480 &&
-
- (ll->loc_CountryCode == 0x55534100 ||
- ll->loc_CountryCode == 0x43414E00 ))
- sp->typecnt = 2;
-
-
-
-
- if (sp->typecnt > 1)
- (*fill_tzstate_from_rules)(sp, &startrule, &stoprule);
- }
- CloseLocale(ll);
- }
- CloseLibrary(LocaleBase);
- }
- me->pr_WindowPtr = old_window;
- return valid;
- }
- #ifdef ZIP
- time_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) * SECSPERDAY;
- t = mktime(gmtime(&t));
-
- if (tp) *tp = t;
- return t;
- }
- #endif
- #endif
- #if CRYPT || !defined(FUNZIP)
- LONG sendpkt(struct MsgPort *pid, LONG action, LONG *args, LONG nargs);
- LONG sendpkt(pid,action,args,nargs)
- struct MsgPort *pid;
- LONG action,
- *args,
- nargs;
- {
- 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;
-
- pargs = &(packet->sp_Pkt.dp_Arg1);
- for( count=0; count<nargs; count++ )
- pargs[count] = args[count];
- PutMsg(pid,(struct Message *)packet);
- WaitPort(replyport);
- GetMsg(replyport);
- res1 = packet->sp_Pkt.dp_Res1;
- FreeMem((char *)packet,(long)sizeof(*packet));
- DeletePort(replyport);
- return(res1);
- }
- #endif
- #if CRYPT || (defined(UNZIP) && !defined(FUNZIP))
- 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;
- void *conp = ((struct FileHandle *) BADDR(fh))->fh_Type;
- char longspace[8];
- long *flag = (long *) ((ULONG) &longspace[4] & ~3);
- UBYTE c;
- *flag = 1;
- sendpkt(conp, ACTION_SCREEN_MODE, flag, 1);
- Read(fh, &c, 1);
- *flag = 0;
- sendpkt(conp, ACTION_SCREEN_MODE, flag, 1);
- if (c == 3)
- Signal(me, SIGBREAKF_CTRL_C);
- return c;
- }
- #endif
- #endif
|