Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/amiga/filedate.c view on Meta::CPAN
* redefines SetFileDate() depending upon AMIGADOS2 definition.
* 11 Oct 92, John Bush, Eliminated AMIGADOS2 switch by determining
* revision via OpenLibrary() call. Now only one version of
* the program runs on both platforms (1.3.x vs. 2.x)
* 11 Oct 92, John Bush, Merged with Zip version and changed arg passing
* to take time_t input instead of struct DateStamp.
* Arg passing made to conform with utime().
* 22 Nov 92, Paul Kienitz, fixed includes for Aztec and cleaned up some
* lint-ish errors; simplified test for AmigaDOS version.
* 11 Nov 95, Paul Kienitz, added Agetch() for crypt password input and
* UnZip's "More" prompt -- simplifies crypt.h and avoids
* use of library code redundant with sendpkt(). Made it
* available to fUnZip, which does not use FileDate().
* 22 Nov 95, Paul Kienitz, created a new tzset() that gets the current
* timezone from the Locale preferences. These exist only under
* AmigaDOS 2.1 and up, but it is probably correctly set on more
* Amigas than the TZ environment variable is. We check that
* only if TZ is not validly set. We do not parse daylight
* savings syntax except to check for presence vs. absence of a
* DST part; United States rules are assumed. This is better
* than the tzset()s in the Amiga compilers' libraries do.
* 15 Jan 96, Chr. Spieler, corrected the logic when to select low level
* sendpkt() (when FileDate(), Agetch() or windowheight() is used),
* and AMIGA's Agetch() (CRYPT, and UnZip(SFX)'s UzpMorePause()).
* 10 Feb 96, Paul Kienitz, re-fiddled that selection logic again, moved
* stuff around for clarity.
* 16 Mar 96, Paul Kienitz, created a replacement localtime() to go with the
* new tzset(), because Aztec's is hopelessly broken. Also
* gmtime(), which localtime() calls.
* 12 Apr 96, Paul Kienitz, daylight savings was being handled incorrectly.
* 21 Apr 96, Paul Kienitz, had to replace time() as well, Aztec's returns
* local time instead of GMT. That's why their localtime() was bad,
* because it assumed time_t was already local, and gmtime() was
* the one that checked TZ.
* 23 Apr 96, Chr. Spieler, deactivated time() replacement for UnZip stuff.
* Currently, the UnZip sources do not make use of time() (and do
* not supply the working mktime() replacement, either!).
* 29 Apr 96, Paul Kienitz, created a replacement getenv() out of code that
* was previously embedded in tzset(), for reliable global test
* of whether TZ is set or not.
* 19 Jun 96, Haidinger Walter, re-adapted for current SAS/C compiler.
* 7 Jul 96, Paul Kienitz, smoothed together compiler-related changes.
* 4 Feb 97, Haidinger Walter, added set_TZ() for SAS/C.
* 23 Apr 97, Paul Kienitz, corrected Unix->Amiga DST error by adding
* mkgmtime() so localtime() could be used.
* 28 Apr 97, Christian Spieler, deactivated mkgmtime() definition for ZIP;
* the Zip sources supply this function as part of util.c.
* 24 May 97, Haidinger Walter, added time_lib support for SAS/C and moved
* set_TZ() to time_lib.c.
* 12 Jul 97, Paul Kienitz, adapted time_lib stuff for Aztec.
* 26 Jul 97, Chr. Spieler, old mkgmtime() fixed (ydays[] def, sign vs unsign).
* 30 Dec 97, Haidinger Walter, adaptation for SAS/C using z-stat.h functions.
* 19 Feb 98, Haidinger Walter, removed alloc_remember, more SAS.C fixes.
* 23 Apr 98, Chr. Spieler, removed mkgmtime(), changed FileDate to convert to
* Amiga file-time directly.
* 24 Apr 98, Paul Kienitz, clip Unix dates earlier than 1978 in FileDate().
* 02 Sep 98, Paul Kienitz, C. Spieler, always include zip.h to get a defined
* header inclusion sequence that resolves all header dependencies.
* 06 Jun 00, Paul Kienitz, removed time_lib.c due to its incompatible license,
* moved set_TZ() back here, replaced minimal tzset() and localtime()
* with new versions derived from GNU glibc source. Gave locale_TZ()
* reasonable European defaults for daylight savings.
* 17 Jun 00, Paul Kienitz, threw out GNU code because of objections to the GPL
* virus, replaced with similar functions based on the public domain
* timezone code at ftp://elsie.nci.nih.gov/pub. As with the GNU
* stuff, support for timezone files and leap seconds was removed.
* 23 Aug 00, Paul Kienitz, moved timezone code out from here into separate
* platform-independent module 'timezone.c'.
* 31 Dec 00, Christian Spieler, moved system-specific timezone help funcions
* back in here, from 'timezone.c'.
* 07 Jan 01, Paul Kienitz, Chr. Spieler, added missing #include "timezone.h"
* and "symbolic" preprocessor constants for time calculations.
* 15 Jan 02, Paul Kienitz, excluded all time handling code from compilation
* for Zip utilities (when "defined(UTIL)")
*/
#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)))
/* on 68020 or higher processors it is faster */
# define __USE_SYSBASE /* to use the pragma libcall instead of syscall */
# endif /* to access functions of the exec.library */
# 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 /* MWDEBUG */
#endif /* __SASC */
#include "crypt.h" /* just so we can tell if CRYPT is supported */
#if (!defined(FUNZIP) && !defined(UTIL))
#include "timezone.h" /* for AMIGA-specific timezone callbacks */
#ifndef SUCCESS
# define SUCCESS (-1L)
# define FAILURE 0L
#endif
#define ReqVers 36L /* required library version for SetFileDate() */
#define ENVSIZE 100 /* max space allowed for an environment var */
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[]; /* in unzip's fileio.c */
#endif
#define LEAP(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)
#define YDAYS(m, y) (ydays[m] + (m > 1 && LEAP(y)))
/* Number of leap years from 1978 to `y' (not including `y' itself). */
#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
/* prototypes */
char *getenv(const char *var);
#ifdef __SASC
/* XXX !! We have really got to find a way to operate without these. */
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);
unzip-6.0/amiga/filedate.c view on Meta::CPAN
}
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; /* 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;
}
/* Stores data from timezone and daylight to ENV:TZ. */
/* ENV:TZ is required to exist by some other SAS/C library functions, */
/* like stat() or fstat(). */
void set_TZ(long time_zone, int day_light)
{
char put_tz[MAXTIMEZONELEN]; /* string for putenv: "TZ=aaabbb:bb:bbccc" */
int offset;
void *exists; /* dummy ptr to see if global envvar TZ already exists */
exists = (void *)getenv(TZ_ENVVAR);
/* see if there is already an envvar TZ_ENVVAR. If not, create it */
if (exists == NULL) {
/* create TZ string by pieces: */
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 /* __SASC */
/* set state as well as possible from settings found in locale.library */
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;
/* 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; /* in minutes */
if (z == -300) {
if (eh = Lock("ENV:sys/locale.prefs", ACCESS_READ)) {
UnLock(eh);
valid = TRUE;
} else
z = 300; /* bug: locale not initialized, default bogus! */
} 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) {
/* At this point we make a really gratuitous assumption: */
/* if the time zone could be Europe, we use the European */
/* Union rules without checking what country we're in. */
/* The AmigaDOS locale country codes do not, at least in */
/* 2.x versions of the OS, recognize very many countries */
/* outside of Europe and North America. */
sp->typecnt = 2;
startrule.r_mon = 3; /* one week earlier than US DST */
startrule.r_week = 5;
} else if (z >= 150 && z <= 480 &&
/* no DST in alaska, hawaii */
(ll->loc_CountryCode == 0x55534100 /*"USA"*/ ||
ll->loc_CountryCode == 0x43414E00 /*"CAN"*/))
sp->typecnt = 2;
/* We check the country code for U.S. or Canada because */
/* most of Latin America has no DST. Even in these two */
/* countries there are some exceptions... */
/* else if... Feel free to add more cases here! */
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));
/* gmtime leaves ds in the local timezone, mktime converts it to GMT */
if (tp) *tp = t;
return t;
}
#endif /* ZIP */
#endif /* !FUNZIP && !UTIL */
#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);
( run in 2.533 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )