* UNZIP.BCKX UNZIP.BCKLBACKUP/LOG [...]*.* SYS$SYSDEVICE:[HUNTER.TMP]UNZIP.BCK/SAV/INTER/BLOCK=8192 GOATHUNTER 5]V7.3 _MILO:: _MILO$DKA200: AXP72R001  *[UNZIP552]ACORN.DIR;1+, ./ 4-0123 KPWO56mW7mW89GHJIACORN.C# CONTENTS.  GMAKEFILE.  MAKEFILE.!%README.'RISCOS.C"RISCOS.H$3 RUNME1ST. SRCRENAME.%SWIVEN.H&SWIVEN.S(*[UNZIP552.ACORN]ACORN.C;1+,#.H/ 4HD@- 0@123KPWOE56'7'89GHJ/* Copyright (c) 1990-2005 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html */ /*--------------------------------------------------------------------------- acorn.c RISCOS-specific routines for use with Info-ZIP's UnZip 5.2 and later. Contains: do_wild() <-- generic enough to put in fileio.c? mapattr() mapname() checkdir() mkdir() setRISCOSexfield() printRISCOSexfield() close_outfile() stamp_file() version() ---------------------------------------------------------------------------*/ #define UNZIP_INTERNAL #include "^.unzip.h" #include "riscos.h" #define FTYPE_FFF (1<<17) /* set filetype to &FFF when extracting */ #ifdef WILD_STOP_AT_DIR # define WESEP , (oU.W_flag ? '.' : '\0') #else # define WESEP #endif static int created_dir; /* used in mapname(), checkdir() */ static int renamed_fullpath; /* ditto */ static int has_mimemap = -1; /* used in mimemap() */ extern int mkdir(const char *path, int mode); static int has_NFS_ext(const char *name); static void setRISCOSexfield(ZCONST char *path, ZCONST void *ef_spark); #ifdef DEBUG static void printRISCOSexfield(int isdir, ZCONST void *extra_field); #endif static int uxtime2acornftime(unsigned *pexadr, unsigned *pldadr, time_t ut); static int mimemap(const char *name); #ifndef SFX /**********************/ /* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */ /**********************/ char *do_wild(__G__ wildspec) __GDEF ZCONST char *wildspec; /* only used first time on a given dir */ { static DIR *wild_dir = (DIR *)NULL; static ZCONST char *wildname; static char *dirname, matchname[FILNAMSIZ]; static int notfirstcall=FALSE, have_dirname, dirnamelen; struct dirent *file; /* Even when we're just returning wildspec, we *always* do so in * matchname[]--calling routine is allowed to append four characters * to the returned string, and wildspec may be a pointer to argv[]. */ if (!notfirstcall) { /* first call: must initialize everything */ notfirstcall = TRUE; /* break the wildspec into a directory part and a wildcard filename */ if ((wildname = (ZCONST char *)strrchr(wildspec, '.')) == (ZCONST char *)NULL) { dirname = "."; dirnamelen = 1; have_dirname = FALSE; wildname = wildspec; } else { ++wildname; /* point at character after '/' */ dirnamelen = wildname - wildspec; if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) { Info(slide, 0x201, ((char *)slide, "warning: cannot allocate wildcard buffers\n")); strncpy(matchname, wildspec, FILNAMSIZ); matchname[FILNAMSIZ-1] = '\0'; return matchname; /* but maybe filespec was not a wildcard */ } strncpy(dirname, wildspec, dirnamelen); dirname[dirnamelen] = '\0'; /* terminate for strcpy below */ have_dirname = TRUE; } if ((wild_dir = opendir(dirname)) != (DIR *)NULL) { while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { if (file->d_name[0] == '/' && wildname[0] != '/') continue; /* Unix: '*' and '?' do not match leading dot */ if (match(file->d_name, wildname, 0 WESEP)) { /* 0=case sens.*/ if (have_dirname) { strcpy(matchname, dirname); strcpy(matchname+dirnamelen, file->d_name); } else strcpy(matchname, file->d_name); return matchname; } } /* if we get to here directory is exhausted, so close it */ closedir(wild_dir); wild_dir = (DIR *)NULL; } /* return the raw wildspec in case that works (e.g., directory not * searchable, but filespec was not wild and file is readable) */ strncpy(matchname, wildspec, FILNAMSIZ); matchname[FILNAMSIZ-1] = '\0'; return matchname; } /* last time through, might have failed opendir but returned raw wildspec */ if (wild_dir == (DIR *)NULL) { notfirstcall = FALSE; /* nothing left to try--reset for new wildspec */ if (have_dirname) free(dirname); return (char *)NULL; } /* If we've gotten this far, we've read and matched at least one entry * successfully (in a previous call), so dirname has been copied into * matchname already. */ while ((file = readdir(wild_dir)) != (struct dirent *)NULL) if (match(file->d_name, wildname, 0 WESEP)) { /* 0 == case sens. */ if (have_dirname) { /* strcpy(matchname, dirname); */ strcpy(matchname+dirnamelen, file->d_name); } else strcpy(matchname, file->d_name); return matchname; } closedir(wild_dir); /* have read at least one dir entry; nothing left */ wild_dir = (DIR *)NULL; notfirstcall = FALSE; /* reset for new wildspec */ if (have_dirname) free(dirname); return (char *)NULL; } /* end function do_wild() */ #endif /* !SFX */ /**************************/ /* Function has_NFS_ext() */ /**************************/ static int has_NFS_ext(const char* name) { int i = strlen(name) - 4; return (i >= 0 && name[i] == ',' && (i > 0 || name[i-1]=='/') && isxdigit(name[i+1]) && isxdigit(name[i+2]) && isxdigit(name[i+3])); } /* end function has_NFS_ext() */ /**********************/ /* Function mapattr() */ /**********************/ int mapattr(__G֠9 UNZIP.BCK# [UNZIP552.ACORN]ACORN.C;1H>H  ) __GDEF { ulg tmp = G.crec.external_file_attributes; switch (G.pInfo->hostnum) { case AMIGA_: tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */ G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp); break; case THEOS_: tmp &= 0xF1FFFFFFL; if ((tmp & 0xF0000000L) != 0x40000000L) tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */ else tmp &= 0x41FFFFFFL; /* leave directory bit as set */ /* fall through! */ case ACORN_: case UNIX_: case VMS_: case ATARI_: case ATHEOS_: case BEOS_: case QDOS_: case TANDEM_: G.pInfo->file_attr = (unsigned)(tmp >> 16); if (G.pInfo->file_attr != 0 || !G.extra_field) { break; } else { /* Some (non-Info-ZIP) implementations of Zip for Unix and VMS (and probably others ??) leave 0 in the upper 16-bit part of the external_file_attributes field. Instead, they store file permission attributes in some extra field. As a work-around, we search for the presence of one of these extra fields and fall back to the MSDOS compatible part of external_file_attributes if one of the known e.f. types has been detected. Later, we might implement extraction of the permission bits from the VMS extra field. But for now, the work-around should be sufficient to provide "readable" extracted files. (For ASI Unix e.f., an experimental remap of the e.f. mode value IS already provided!) */ ush ebID; unsigned ebLen; uch *ef = G.extra_field; unsigned ef_len = G.crec.extra_field_length; int r = FALSE; while (!r && ef_len >= EB_HEADSIZE) { ebID = makeword(ef); ebLen = (unsigned)makeword(ef+EB_LEN); if (ebLen > (ef_len - EB_HEADSIZE)) /* discoverd some e.f. inconsistency! */ break; switch (ebID) { case EF_ASIUNIX: if (ebLen >= (EB_ASI_MODE+2)) { G.pInfo->file_attr = (unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE)); /* force stop of loop: */ ef_len = (ebLen + EB_HEADSIZE); break; } /* else: fall through! */ case EF_PKVMS: /* "found nondecypherable e.f. with perm. attr" */ r = TRUE; default: break; }  ef_len -= (ebLen + EB_HEADSIZE); ef += (ebLen + EB_HEADSIZE); } if (!r) break; } /* fall through! */ /* all remaining cases: expand MSDOS read-only bit into write perms */ case FS_FAT_: /* PKWARE's PKZip for Unix marks entries as FS_FAT_, but stores the * Unix attributes in the upper 16 bits of the external attributes * field, just like Info-ZIP's Zip for Unix. We try to use that * value, after a check for consistency with the MSDOS attribute * bits (see below). */ G.pInfo->file_attr = (unsigned)(tmp >> 16); /* fall through! */ case FS_HPFS_: case FS_NTFS_: case MAC_: case TOPS20_: default: /* Ensure that DOS subdir bit is set when the entry's name ends * in a '/'. Some third-party Zip programs fail to set the subdir * bit for directory entries. */ if ((tmp & 0x10) == 0) { extent fnlen = strlen(G.filename); if (fnlen > 0 && G.filename[fnlen-1] == '/') tmp |= 0x10; } /* read-only bit --> write perms; subdir bit --> dir exec bit */ tmp = !(tmp & 1) << 1 | (tmp & 0x10) >> 4; if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6)) /* keep previous G.pInfo->file_attr setting, when its "owner" * part appears to be consistent with DOS attribute flags! */ break; G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp); break; } /* end switch (host-OS-created-by) */ G.pInfo->file_attr&=0xFFFF; G.pInfo->file_attr|=(0xFFDu<<20); if (has_NFS_ext(G.filename)) { int ftype=strtol(G.filename+strlen(G.filename)-3,NULL,16)&0xFFF; G.pInfo->file_attr = (G.pInfo->file_attr & 0x000FFFFF) | (ftype<<20); } else { int type = mimemap(G.filename); if (type == -1) type = (G.crec.internal_file_attributes & 1) ? 0xFFF : 0xFFD; G.pInfo->file_attr = (G.pInfo->file_attr & 0x000FFFFF) | (type<<20); } return 0; } /* end function mapattr() */ /************************/ /* Function mimemap() */ /************************/ static int mimemap(const char *name) { const char *ext = name; int type; if (has_mimemap < 0) has_mimemap = !(SWI_OS_CLI("%RMEnsure MimeMap 0.05 RMLoad System:Modules.Network.MimeMap") || SWI_OS_CLI("%RMEnsure MimeMap 0.05")); if (!has_mimemap) return -1; /* no MimeMap module; fall back on text flag test */ do { while (*ext && *ext!='.') ext++; if (!*ext) return -1; /* no suitable extension; fallback */ type = SWI_MimeMap_Translate(ext++); } while (type == -1); return type; } /************************/ /* Function mapname() */ /************************/ int mapname(__G__ renamed) __GDEF int renamed; /* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - caution (truncated filename) * MPN_INF_SKIP - info "skip entry" (dir doesn't exist) * MPN_ERR_SKIP - error -> skip entry * MPN_ERR_TOOLONG - error -> path is too long * MPN_NOMEM - error (memory allocation failed) -> skip entry * [also MPN_VOL_LABEL, MPN_CREATED_DIR] */ { char pathcomp[FILNAMSIZ]; /* path-component buffer */ char *pp, *cp=(char *)NULL; /* character pointers */ char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */ int error = MPN_OK; register unsigned workch; /* hold the character being tested */ char *checkswap=NULL; /* pointer the the extension to check */ /*--------------------------------------------------------------------------- Initialize various pointers and counters and stuff. ---------------------------------------------------------------------------*/ if (G.pInfo->vollabel) return MPN_VOL_LABEL; /* can't set disk volume labels in RISCOS */ /* can create path as long as not just freshening, or if user told us */ G.create_dirs = (!uO.fflag || renamed); created_dir = FALSE; /* not yet */ /* user gave full pathname: don't prepend rootpath */ renamed_fullpath = (renamed && (*G.filename == '/')); if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM) return MPN_NOMEM; /* initialize path buffer, unless no memory */ *|G UNZIP.BCK# [UNZIP552.ACORN]ACORN.C;1Hpathcomp = '\0'; /* initialize translation buffer */ pp = pathcomp; /* point to translation buffer */ if (uO.jflag) /* junking directories */ cp = (char *)strrchr(G.filename, '/'); if (cp == (char *)NULL) /* no '/' or not junking dirs */ cp = G.filename; /* point to internal zipfile-member pathname */ else ++cp; /* point to start of last component of path */ /*--------------------------------------------------------------------------- Begin main loop through characters in filename. ---------------------------------------------------------------------------*/ while ((workch = (uch)*cp++) != 0) { switch (workch) { case '/': /* can assume -j flag not given */ *pp = '\0'; if (((error = checkdir(__G__ pathcomp, APPEND_DIR)) & MPN_MASK) > MPN_INF_TRUNC) return error; pp = pathcomp; /* reset conversion buffer for next piece */ lastsemi = (char *)NULL; /* leave direct. semi-colons alone */ checkswap=NULL; /* reset checking at start of new leafname */ break; case '.': *pp++ = '/'; checkswap=pp; break; case ';': /* VMS version (or DEC-20 attrib?) */ lastsemi = pp; *pp++ = ';'; /* keep for now; remove VMS ";##" */ break; /* later, if requested */ case ' ': /* change spaces to hard-spaces */ *pp++ = 160; /* (ISO 8859-1 Latin-1 codepage) */ break; /* The following substitutions, unless stated otherwise, follow * those for DOSFS. They translate special symbols into other * characters which have no special meaning to RISC OS. */ case '#': *pp++ = '?'; break; /* single-char wildcard */ case '&': *pp++ = '+'; break; case '@': *pp++ = '='; break; case '%': *pp++ = ';'; break; case '$': *pp++ = '<'; break; case '^': *pp++ = '>'; break; /* parent-dir reference */ /* The following substitutions deal with the remaining special * symbols. ('.' is handled above.) */ case '*': *pp++ = 0xD7; break; /* Latin-1 'multiply' */ case '"': *pp++ = '~'; break; case ':': *pp++ = ';'; break; case '\\': *pp++ = '/'; break; case '|': *pp++ = 0xA6; break; /* Latin-1 'broken bar' */ default: /* allow European characters in filenames: */ if (isprint(workch) || (128 <= workch && workch <= 254)) *pp++ = (char)workch; } /* end switch */ } /* end while loop */ /*--------------------------------------------------------------------------- Report if directory was created (and no file to create: filename ended in '/'), check name to be sure it exists, and combine path and name be- fore exiting. ---------------------------------------------------------------------------*/ if (G.filename[strlen(G.filename) - 1] == '/') { checkdir(__G__ G.filename, GETPATH); if (created_dir) { if (QCOND2) { Info(slide, 0, ((char *)slide, " creating: %s\n", FnFilter1(G.filename))); } /* set dir time (note trailing '/') */ return (error & ~MPN_MASK) | MPN_CREATED_DIR; } /* dir existed already; don't look for data to extract */ return (error & ~MPN_MASK) | MPN_INF_SKIP; } *pp = '\0'; /* done with pathcomp: terminate it */ /* if not saving them, remove VMS version numbers (appended ";###") */ if (!uO.V_flag && lastsemi) { pp = lastsemi + 1; while (isdigit((uch)(*pp))) ++pp; if (*pp == '\0') /* only digits between ';' and end: nuke */ *lastsemi = '\0'; } if (*pathcomp == '\0') { Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n", FnFilter1(G.filename))); return (error & ~MPN_MASK) | MPN_ERR_SKIP; } if (checkswap!=NULL) { if (checkext(checkswap)) { if ((error = checkdir(__G__ checkswap, APPEND_DIR)) > 1) return error; *(checkswap-1)=0; /* remove extension from pathcomp */ % } } if (!uO.acorn_nfs_ext && has_NFS_ext(pathcomp)) { /* remove the filetype extension unless requested otherwise */ /* the filetype should be already set by mapattr() */ pathcomp[strlen(pathcomp)-4]=0; } checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */ checkdir(__G__ G.filename, GETPATH); return error; } /* end function mapname() */ /***********************/ /* Function checkdir() */ /***********************/ int checkdir(__G__ pathcomp, flag) __GDEF char *pathcomp; int flag; /* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename * MPN_INF_SKIP - path doesn't exist, not allowed to create * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path * exists and is not a directory, but is supposed to be * MPN_ERR_TOOLONG - path is too long * MPN_NOMEM - can't allocate memory for filename buffers */ { static int rootlen = 0; /* length of rootpath */ static char *rootpath; /* user's "extract-to" directory */ static char *buildpath; /* full path (so far) to extracted file */ static char *end; /* pointer to end of buildpath ('\0') */ # define FN_MASK 7 # define FUNCTION (flag & FN_MASK) /*--------------------------------------------------------------------------- APPEND_DIR: append the path component to the path being built and check for its existence. If doesn't exist and we are creating directories, do so for this one; else signal success or error as appropriate. ---------------------------------------------------------------------------*/ if (FUNCTION == APPEND_DIR) { int too_long = FALSE; #ifdef SHORT_NAMES char *old_end = end; #endif Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp))); while ((*end = *pathcomp++) != '\0') ++end; #ifdef SHORT_NAMES /* path components restricted to 14 chars, typically */ if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */ *(end = old_end + FILENAME_MAX) = '\0'; #endif /* GRR: could do better check, see if overrunning buffer as we go: * check end-buildpath after each append, set warning variable if * within 20 of FILNAMSIZ; then if var set, do careful check when * appending. Clear variable when begin new path. */ /* next check: need to append '/', at least one-char name, '\0' */ if ((end-buildpath) > FILNAMSIZ-3) too_long = TRUE; /* check if extracting dir? */ if (stat(buildpath, &G.statbuf)) { /* path doesn't exist */ if (!G.create_dirs) { /* told not to create (freshening) */ free(buildpath); return MPN_INF_SKIP; /* path doesn't exist: nothing to do */ } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too lo~: UNZIP.BCK# [UNZIP552.ACORN]ACORN.C;1Hu+ng: %s\n", FnFilter1(buildpath))); fflush(stderr); free(buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } if (mkdir(buildpath, 0777) == -1) { /* create the directory */ Info(slide, 1, ((char *)slide, "checkdir error: cannot create %s\n\ unable to process %s.\n", FnFilter2(buildpath), FnFilter1(G.filename))); free(buildpath); /* path didn't exist, tried to create, failed */ return MPN_ERR_SKIP; } created_dir = TRUE; } else if (!S_ISDIR(G.statbuf.st_mode)) { Info(slide, 1, ((char *)slide, "checkdir error: %s exists but is not directory\n\ unable to process %s.\n", FnFilter2(buildpath), FnFilter1(G.filename))); free(buildpath); /* path existed but wasn't dir */ return MPN_ERR_SKIP; } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too long: %s\n", FnFilter1(buildpath))); free(buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } *end++ = '.'; /************* was '/' *************/ *end = '\0'; Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath))); return MPN_OK; } /* end if (FUNCTION == APPEND_DIR) */ /*--------------------------------------------------------------------------- GETPATH: copy full path to the string pointed at by pathcomp, and free buildpath. ---------------------------------------------------------------------------*/ if (FUNCTION == GETPATH) { strcpy(pathcomp, buildpath); Trace((stderr, "getting and freeing path [%s]\n", FnFilter1(pathcomp))); free(buildpath); buildpath = end = (char *)NULL; return MPN_OK; } /*--------------------------------------------------------------------------- APPEND_NAME: assume the path component is the filename; append it and return without checking for existence. ---------------------------------------------------------------------------*/ if (FUNCTION == APPEND_NAME) { #ifdef SHORT_NAMES char *old_end = end; #endif Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp))); while ((*end = *pathcomp++) != '\0') { ++end; #ifdef SHORT_NAMES /* truncate name at 14 characters, typically */ if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */ *(end = old_end + FILENAME_MAX) = '\0'; #endif if ((end-buildpath) >= FILNAMSIZ) { *--end = '\0'; Info(slide, 0x201, ((char *)slide, "checkdir warning: path too long; truncating\n\ %s\n -> %s\n", FnFilter1(G.filename), FnFilter2(buildpath))); return MPN_INF_TRUNC; /* filename truncated */ } } Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath))); /* could check for existence here, prompt for new name... */ return MPN_OK; } /*--------------------------------------------------------------------------- INIT: allocate and initialize buffer space for the file currently being extracted. If file was renamed with an absolute path, don't prepend the extract-to path. ---------------------------------------------------------------------------*/ /* GRR: for VMS and TOPS-20, add up to 13 to strlen */ if (FUNCTION == INIT) { Trace((stderr, "initializing buildpath to ")); if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) == (char *)NULL) return MPN_NOMEM; if ((rootlen > 0) && !renamed_fullpath) { strcpy(buildpath, rootpath); end = buildpath + rootlen; } else { *buildpath = '\0'; end = buildpath; } Trace((stderr, "[%s]\n", FnFilter1(buildpath))); return MPN_OK; } /*--------------------------------------------------------------------------- ROOT: if appropriate, store the path in rootpath and create it if necessary; else assume it's a zipfile member and return. This path segment gets used in extracting all members from every zipfile specified on the command line. ---------------------------------------------------------------------------*/ #if (!defined(SFX) || defined(SFX_EXDIR)) if (FUNCTION == ROOT) { Trace((stderr, "initializing root path to [%s]\n", FnFilter1(pathcomp))); if (pathcomp == (char *)NULL) { rootlen = 0; return MPN_OK; } if (rootlen > 0) /* rootpath was already set, nothing to do */ return MPN_OK; if ((rootlen = strlen(pathcomp)) > 0) { char *tmproot; if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) { rootlen = 0; return MPN_NOMEM; } strcpy(tmproot, pathcomp); if (tmproot[rootlen-1] == '.') { /****** was '/' ********/ tmproot[--rootlen] = '\0'; } if (rootlen > 0 && (SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))) { /* path does not exist */ if (!G.create_dirs /* || isshexp(tmproot) */ ) { free(tmproot); rootlen = 0; /* skip (or treat as stored file) */ return MPN_INF_SKIP; } /* create the directory (could add loop here scanning tmproot * to create more than one level, but why really necessary?) */ if (mkdir(tmproot, 0777) == -1) { Info(slide, 1, ((char *)slide, "checkd7ir: cannot create extraction directory: %s\n", FnFilter1(tmproot))); free(tmproot); rootlen = 0; /* path didn't exist, tried to create, and failed: */ /* file exists, or 2+ subdir levels required */ return MPN_ERR_SKIP; } } tmproot[rootlen++] = '.'; /*********** was '/' *************/ tmproot[rootlen] = '\0'; if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) { free(tmproot); rootlen = 0; return MPN_NOMEM; } Trace((stderr, "rootpath now = [%s]\n", FnFilter1(rootpath))); } return MPN_OK; } #endif /* !SFX || SFX_EXDIR */ /*--------------------------------------------------------------------------- END: free rootpath, immediately prior to program exit. ---------------------------------------------------------------------------*/ if (FUNCTION == END) { Trace((stderr, "freeing rootpath\n")); if (rootlen > 0) { free(rootpath); rootlen = 0; } return MPN_OK; } return MPN_INVALID; /* should never reach */ } /* end function checkdir() */ /********************/ /* Function mkdir() */ /********************/ int mkdir(path, mode) const char *path; int mode; /* ignored */ /* * returns: 0 - successful * -1 - failed (errno not set, hc UNZIP.BCK# [UNZIP552.ACORN]ACORN.C;1HD:owever) */ { return (SWI_OS_File_8((char *)path) == NULL)? 0 : -1; } /*********************************/ /* extra_field-related functions */ /*********************************/ static void setRISCOSexfield(ZCONST char *path, ZCONST void *ef_spark) { if (ef_spark!=NULL) { extra_block *block=(extra_block *)ef_spark; SWI_OS_File_1((char *)path,block->loadaddr,block->execaddr,block->attr); } } #ifdef DEBUG static void printRISCOSexfield(int isdir, ZCONST void *extra_field) { extra_block *block=(extra_block *)extra_field; printf("\n This file has RISC OS file informations in the local extra field.\n"); if (isdir) { /* I prefer not to print this string... should change later... */ /* printf(" The file is a directory.\n");*/ } else if ((block->loadaddr & 0xFFF00000) != 0xFFF00000) { printf(" Load address: %.8X\n",block->loadaddr); printf(" Exec address: %.8X\n",block->execaddr); } else { /************* should change this to use OS_FSControl 18 to get filetype string ************/ char tmpstr[16]; char ftypestr[32]; int flen; sprintf(tmpstr,"File$Type_%03x",(block->loadaddr & 0x000FFF00) >> 8); if (SWI_OS_ReadVarVal(tmpstr,ftypestr,32,&flen)==NULL) { ftypestr[flen]=0; printf(" Filetype: %s (&%.3X)\n",ftypestr,(block->loadaddr & 0x000FFF00) >> 8); } else { printf(" Filetype: &%.3X\n",(block->loadaddr & 0x000FFF00) >> 8); } } printf(" Access: "); if (block->attr & (1<<3)) printf("L"); if (block->attr & (1<<0)) printf("W"); if (block->attr & (1<<1)) printf("R"); printf("/"); if (block->attr & (1<<4)) printf("w"); if (block->attr & (1<<5)) printf("r"); printf("\n\n"); } #endif /* DEBUG */ /**********************************************/ /* internal help function for time conversion */ /**********************************************/ static int uxtime2acornftime(unsigned *pexadr, unsigned *pldadr, time_t ut) { unsigned timlo; /* 3 lower bytes of acorn file-time plus carry byte */ unsigned timhi; /* 2 high bytes of acorn file-time */ timlo = ((unsigned)ut & 0x00ffffffU) * 100 + 0x00996a00U; timhi = ((unsigned)ut >> 24); timhi = timhi * 100 + 0x0000336eU + (timlo >> 24); if (timhi & 0xffff0000U) return 1; /* calculation overflow, do not change time */ /* insert the five time bytes into loadaddr and execaddr variables */ *pexadr = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24); *pldadr = (*pldadr & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU); return 0; /* subject to future extension to signal overflow */ } /****************************/ /* Function close_outfile() */ /****************************/ void close_outfile(__G) __GDEF { zvoid *spark_ef; fclose(G.outfile); if ((spark_ef = getRISCOSexfield(G.extra_field, G.lrec.extra_field_length)) != NULL) { setRISCOSexfield(G.filename, spark_ef); } else { unsigned int loadaddr, execaddr; int attr; int mode=G.pInfo->file_attr&0xffff; /* chmod equivalent mode */ time_t m_time; #ifdef USE_EF_UT_TIME iztimes z_utime; #endif #ifdef USE_EF_UT_TIME if (G.extra_field && #ifdef IZ_CHECK_TZ G.tz_is_valid && #endif (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime, &z_utime, NULL) & EB_UT_FL_MTIME)) { TTrace((stderr, "close_outfile: Unix e.f. modif. time = %ld\n", z_utime.mtime)); m_time = z_utime.mtime; } else #endif /* USE_EF_UT_TIME */ m_time = dos_to_unix_time(G.lrec.last_mod_dos_datetime); /* set the file's modification time */ SWI_OS_File_5(G.filename, NULL, &loadaddr, NULL, NULL, &attr); uxtime2acornftime(&execaddr, &loadaddr, m_time); loadaddr = (loadaddr & 0xfff000ffU) | ((G.pInfo->file_attr&0xfff00000) >> 12); attr=(attr&0xffffff00) | ((mode&0400) >> 8) | ((mode&0200) >> 6) | ((mode&0004) << 2) | ((mode&0002) << 4); SWI_OS_File_1(G.filename, loadaddr, execaddr, attr); } } /* end function close_outfile() */ #ifdef TIMESTAMP /***************************/ /* Function stamp_file() */ /***************************/ int stamp_file(fname, modtime) ZCONST char *fname; time_t modtime; { unsigned int loadaddr, execaddr; int attr; /* set the file's modification time */ if (SWI_OS_File_5((char *)fname, NULL, &loadaddr, NULL, NULL, &attr) != NULL) return -1; if (uxtime2acornftime(&execaddr, &loadaddr, modtime) != 0) return -1; return (SWI_OS_File_1((char *)fname, loadaddr, execaddr, attr) == NULL) ? 0 : -1; } /* end function stamp_file() */ #endif /* TIMESTAMP */ #ifndef SFX /************************/ /* Function version() */ /************************/ void version(__G) __GDEF { sprintf((char *)slide, LoadFarString(CompiledWith), #ifdef __GNUC__ "gcc ", __VERSION__, #else # ifdef __CC_NORCROFT "Norcroft ", "cc", # else "cc", "", # endif #endif "RISC OS", " (Acorn Computers Ltd)", #ifdef __DATE__ " on ", __DATE__ #else "", "" #endif ); (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0); } /* end function version() */ #endif /* !SFX */ *[UNZIP552.ACORN]CONTENTS.;1+, ./ 4n@- 0@123KPWO56:_ُ7:_ُ89GHJContents of the "acorn" subdirectory for UnZip 5.4 and later: acorn.c.acorn Acorn-specific resources acorn.c.riscos mainly file-handling routines for FileCore-based filesystems acorn.Contents this file acorn.GMakeFile Makefile for gcc acorn.h.riscos acorn.h.swiven acorn.makefile Makefile script for default Acorn C compiler acorn.README notes about Acorn-specific features acorn.RunMe1st Obey file to move files into suitable place for compilation on RISC OS machines acorn.s.swiven SWI veneers acorn.srcrename small executable that converts files from Unix style to RISC OS style, used by RunMe1st Notes: Use the "RunMe1st" file (it is an Obey file) to convert all the files from "filename/[chs]" to "[chs].filename" (so that UnZip could be easily compiled under RISC OS). It will also set the correct makefile. To compile just set the CSD to the main UnZip directory and run 'amu'. Currently only the Acorn C V5 compiler has been tested but probably also Acorn C V4 and the Acorn Assembler V2 will be able to compile UnZip. *[UNZIP552.ACORN]GMAKEFILE.;1+, ./ 4 @- 0@123KPWO 56hُ7hُ89GHJZ UNZIP.BCK  [UNZIP552.ACORN]GMAKEFILE.;1P# Makefile for UnZip, UnZipSFX, ZipInfo and fUnZip (5.2 or later) # using gcc 2.95.4 (or later). # You may look at for an up-to-date # gcc port. CC = gcc -mlibscl BIND = $(CC) AS = $(CC) -c ASM = as SQUEEZE = squeeze -v E = # flags # CFLAGS flags for C compile # LFLAGS1 flags after output file spec, before obj file list # LFLAGS2 flags after obj file list (libraries, etc) # LIB = CFLAGS = -O2 -mthrowback -DNO_STRNICMP ASMFLAGS = -throwback -objasm -upper LFLAGS1 = LFLAGS2 = $(LIB) # object file lists OBJS1 = o.unzip o.crc32 o.crctab o.crypt o.envargs o.explode OBJS2 = o.extract o.fileio o.globals o.inflate o.list o.match OBJS3 = o.process o.ttyio o.unreduce o.unshrink o.zipinfo OBJS = $(OBJS1) $(OBJS2) $(OBJS3) o.riscos o.swiven o.acorn OBJF = o.funzip o.crc32 o.cryptf o.globalsf o.inflatef o.ttyiof \ o.riscos o.swiven OBJX = o.unzipsfx o.crc32 o.crctab_ o.crypt_ o.extract_ o.fileio_ o.globals_ \ o.inflate_ o.match_ o.process_ o.ttyio_ o.acorn_ o.swiven o.riscos_ UNZIP_H = h.unzip h.unzpriv h.globals acorn.h.riscos acorn.h.swiven all: unzip funzip unzipsfx install: unzip funzip unzipsfx $(SQUEEZE) unzip %.unzip $(SQUEEZE) funzip %.funzip $(SQUEEZE) unzipsfx unzipsfx copy %.unzip %.zipinfo ~CVF # rules for unzip and funzip o.crc32: c.crc32 $(UNZIP_H) h.zip $(CC) $(CFLAGS) -c c.crc32 -o o.crc32 o.crctab: c.crctab $(UNZIP_H) h.zip $(CC) $(CFLAGS) -c c.crctab -o o.crctab o.crypt: c.crypt $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -c c.crypt -o o.crypt o.envargs: c.envargs $(UNZIP_H) $(CC) $(CFLAGS) -c c.envargs -o o.envargs o.explode: c.explode $(UNZIP_H) $(CC) $(CFLAGS) -c c.explode -o o.explode o.extract: c.extract $(UNZIP_H) h.crypt $(CC) $(CFLAGS) -c c.extract -o o.extract o.fileio: c.fileio $(UNZIP_H) h.crypt h.ttyio h.ebcdic $(CC) $(CFLAGS) -c c.fileio -o o.fileio o.funzip: c.funzip $(UNZIP_H) h.crypt h.ttyio h.tables $(CC) $(CFLAGS) -c c.funzip -o o.funzip o.globals: c.globals $(UNZIP_H) $(CC) $(CFLAGS) -c c.globals -o o.globals o.inflate: c.inflate h.inflate $(UNZIP_H) $(CC) $(CFLAGS) -c c.inflate -o o.inflate o.list: c.list $(UNZIP_H) $(CC) $(CFLAGS) -c c.list -o o.list o.match: c.match $(UNZIP_H) $(CC) $(CFLAGS) -c c.match -o o.match o.process: c.process $(UNZIP_H) $(CC) $(CFLAGS) -c c.process -o o.process o.ttyio: c.ttyio $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -c c.ttyio -o o.ttyio o.unreduce: c.unreduce $(UNZIP_H) $(CC) $(CFLAGS) -c c.unreduce -o o.unreduce o.unshrink: c.unshrink $(UNZIP_H) $(CC) $(CFLAGS) -c c.unshrink -o o.unshrink o.unzip: c.unzip $(UNZIP_H) h.crypt h.unzvers h.consts $(CC) $(CFLAGS) -c c.unzip -o o.unzip o.zipinfo: c.zipinfo $(UNZIP_H) $(CC) $(CFLAGS) -c c.zipinfo -o o.zipinfo o.crctab_: c.crctab $(UNZIP_H) h.zip $(CC) $(CFLAGS) -DSFX -c c.crctab -o o.crctab_ o.crypt_: c.crypt $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DSFX -c c.crypt -o o.crypt_ o.extract_: c.extract $(UNZIP_H) h.crypt $(CC) $(CFLAGS) -DSFX -c c.extract -o o.extract_ o.fileio_: c.fileio $(UNZIP_H) h.crypt h.ttyio h.ebcdic $(CC) $(CFLAGS) -DSFX -c c.fileio -o o.fileio_ o.globals_: c.globals $(UNZIP_H) $(CC) $(CFLAGS) -DSFX -c c.globals -o o.globals_ o.inflate_: c.inflate h.inflate $(UNZIP_H) h.crypt $(CC) $(CFLAGS) -DSFX -c c.inflate -o o.inflate_ o.match_: c.match $(UNZIP_H) $(CC) $(CFLAGS) -DSFX -c c.match -o o.match_ o.process_: c.process $(UNZIP_H) $(CC) $(CFLAGS) -DSFX -c c.process -o o.process_ o.ttyio_: c.ttyio $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DSFX -c c.ttyio -o o.ttyio_ o.unzipsfx: c.unzip $(UNZIP_H) h.crypt h.unzvers h.consts $(CC) $(CFLAGS) -DSFX -c c.unzip -o o.unzipsfx o.cryptf: c.crypt $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DFUNZIP -c c.crypt -o o.cryptf o.globalsf: c.globals $(UNZIP_H) $(CC) $(CFLAGS) -DFUNZIP -c c.globals -o o.globalsf o.inflatef: c.inflate h.inflate $(UNZIP_H) h.crypt $(CC) $(CFLAGS) -DFUNZIP -c c.inflate -o o.inflatef o.ttyiof: c.ttyio $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DFUNZIP -c c.ttyio -o o.ttyiof o.acorn: acorn.c.acorn $(UNZIP_H) $(CC) $(CFLAGS) -I@ -c acorn.c.acorn o.acorn_: acorn.c.acorn $(UNZIP_H) $(CC) $(CFLAGS) -I@ -c -DSFX -DSFX_EXDIR -o o.acorn_ acorn.c.acorn o.riscos: acorn.c.riscos $(UNZIP_H) $(CC) $(CFLAGS) -I@ -c acorn.c.riscos o.riscos_: acorn.c.riscos $(UNZIP_H) $(CC) $(CFLAGS) -I@ -c -DSFX -DSFX_EXDIR -o o.riscos_ acorn.c.riscos o.swiven: acorn.s.swiven $(ASM) $(ASMFLAGS) acorn.s.swiven -o o.swiven unzip: $(OBJS) $(BIND) -o unzip$(E) $(LFLAGS1) $(OBJS) $(LFLAGS2) funzip: $(OBJF) $(BIND) -o funzip$(E) $(LFLAGS1) $(OBJF) $(LFLAGS2) unzipsfx: $(OBJX) $(BIND) -o unzipsfx$(E) $(LFLAGS1) $(OBJX) $(LFLAGS2) clean: remove unzip remove funzip remove zipinfo remove unzipsfx create o.!fake! 0 wipe o.* ~cf # end of Makefile *[UNZIP552.ACORN]MAKEFILE.;1+,!%./ 4 z@- 0@123KPWO 56<7<89GHJ# Makefile for UnZip, UnZipSFX, ZipInfo and fUnZip (5.5 or later) # last modified: 01 Mar 2004 # add -g to CC to debug # add -d to BIND to debug CC = cc BIND = link AS = $(CC) -c ASM = objasm SQUEEZE = squeeze -v E = # flags # CFLAGS flags for C compile # LFLAGS1 flags after output file spec, before obj file list # LFLAGS2 flags after obj file list (libraries, etc) # LIB = CBASE = -throwback -wn -DNO_STRNICMP CFLAGS = $(CBASE) -IC:,@. ASMFLAGS = -Throwback -Stamp -NoCache -CloseExec -quit LFLAGS1 = LFLAGS2 = $(LIB) C:o.Stubs # object file lists OBJS1 = unzip.o crc32.o crctab.o crypt.o envargs.o explode.o OBJS2 = extract.o fileio.o globals.o inflate.o list.o match.o OBJS3 = process.o ttyio.o unreduce.o unshrink.o zipinfo.o OBJS = $(OBJS1) $(OBJS2) $(OBJS3) riscos.o swiven.o acorn.o OBJF = funzip.o crc32.o cryptf.o globalsf.o inflatef.o ttyiof.o \ riscos.o swiven.o OBJX = unzipsfx.o crc32.o crctab.o crypt_.o extract_.o fileio_.o globals.o \ inflate.o match.o process_.o ttyio.o acorn_.o swiven.o riscos_.o UNZIP_H = unzip.h unzpriv.h globals.h acorn/riscos.h acorn/swiven.h all: unzip funzip unzipsfx install: unzip funzip unzipsfx $(SQUEEZE) unzip %.unzip $(SQUEEZE) funzip %.funzip $(SQUEEZE) unzipsfx unzipsfx copy %.unzip %.zipinfo ~CVF # suffix rules .SUFFIXES: .o .c .c.o: $(CC) $(CFLAGS) -c $< .s.o: $(ASM) $(ASMFLAGS) -from @*.s -to @*.o # rules for unzip and funzip crc32.o: crc32.c $(UNZIP_H) zip.h crctab.o: crctab.c $(UNZIP_H) zip.h crypt.o: crypt.c $(UNZIP_H) zip.h crypt.h ttyio.h envargs.o: envargs.c $(UNZIP_H) explode.o: explode.c $(UNZIP_H) extract.o: extract.c $(UNZIP_H) crypt.h fileio.o: fileio.c $(UNZIP_H) crypt.h ttyio.h ebcdic.h funzip.o: funzip.c $(UNZIP_H) crypt.h ttyio.h tables.h globals.o: globals.c $(UNZIP_H) inflate.o: inflate.c inflate.h $(UNZIP_H) list.o: list.c $(UNZIP_H) match.o: match.c $(UNZIP_H) proces7 UNZIP.BCK!% NZIP552.ACORN]MAKEFILE.;1; s.o: process.c $(UNZIP_H) ttyio.o: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h unreduce.o: unreduce.c $(UNZIP_H) unshrink.o: unshrink.c $(UNZIP_H) unzip.o: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h zipinfo.o: zipinfo.c $(UNZIP_H) crypt_.o: crypt.c $(UNZIP_H) zip.h crypt.h ttyio.h $(CC) $(CFLAGS) -DSFX -c c.crypt -o o.crypt_ extract_.o: extract.c $(UNZIP_H) crypt.h $(CC) $(CFLAGS) -DSFX -c c.extract -o o.extract_ fileio_.o: fileio.c $(UNZIP_H) crypt.h $(CC) $(CFLAGS) -DSFX -c c.fileio -o o.fileio_ globals_.o: globals.c $(UNZIP_H) $(CC) $(CFLAGS) -DFUNZIP -c c.globals -o o.globals_ inflate_.o: inflate.c inflate.h $(UNZIP_H) crypt.h $(CC) $(CFLAGS) -DFUNZIP -c c.inflate -o o.inflate_ process_.o: process.c $(UNZIP_H) $(CC) $(CFLAGS) -DSFX -c c.process -o o.process_ ttyio_.o: ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h $(CC) $(CFLAGS) -DFUNZIP -c c.ttyio -o o.ttyio_ unzipsfx.o: unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h $(CC) $(CFLAGS) -DSFX -c c.unzip -o o.unzipsfx o.cryptf: c.crypt $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DFUNZIP -c c.crypt -o o.cryptf o.globalsf: c.globals $(UNZIP_H) $(CC) $(CFLAGS) -DFUNZIP -c c.globals -o o.globalsf o.inflatef: c.inflate h.inflate $(UNZIP_H) h.crypt $(CC) $(CFLAGS) -DFUNZIP -c c.inflate -o o.inflatef o.ttyiof: c.ttyio $(UNZIP_H) h.zip h.crypt h.ttyio $(CC) $(CFLAGS) -DFUNZIP -c c.ttyio -o o.ttyiof acorn.o: acorn/acorn.c $(UNZIP_H) $(CC) $(CFLAGS) -c acorn/acorn.c acorn_.o: acorn/acorn.c $(UNZIP_H) $(CC) $(CFLAGS) -c -DSFX -DSFX_EXDIR -o acorn_.o acorn/acorn.c riscos.o: acorn/riscos.c $(UNZIP_H) $(CC) $(CFLAGS) -c acorn/riscos.c riscos_.o: acorn/riscos.c $(UNZIP_H) $(CC) $(CFLAGS) -c -DSFX -DSFX_EXDIR -o riscos_.o acorn/riscos.c swiven.o: acorn/swiven.s $(ASM) $(ASMFLAGS) -from acorn.s.swiven -to o.swiven unzip: $(OBJS) $(BIND) -o unzip$(E) $(LFLAGS1) $(OBJS) $(LFLAGS2) funzip: $(OBJF) $(BIND) -o funzip$(E) $(LFLAGS1) $(OBJF) $(LFLAGS2) unzipsfx: $(OBJX) $(BIND) -o unzipsfx$(E) $(LFLAGS1) $(OBJX) $(LFLAGS2) clean: ;remove unzip; remove funzip; remove zipinfo; remove unzipsfx; create o.!fake! 0 wipe o.* ~cf # end of Makefile *[UNZIP552.ACORN]README.;1+,'./ 4W@- 0@123KPWO56:7:89GHJ Acorn-specific usage instructions --------------------------------- As zipfiles can come from a variety of sources apart from Acorn machines, consideration had to be given to the handling of dot-extensions, e.g. "DOSFILE.TXT", "unix-filename.tar.gz". These are extracted as "DOSFILE/TXT" and "unix-filename/tar/gz"; their names may or may not be truncated, depending on where the files are being created: what filing system and, for Filecore-based filing systems such as ADFS or an IDEFS or SCSIFS, which disk/partition format (names will not be truncated if you're using E+ or F+). Where truncation occurs, you must be REALLY careful about extracting files from archives. The files dummy_source.c and dummy_source.h will both be extracted as dummy_sour UnZip will prompt you for confirmation of the over-writing of these files, but you must be really careful unless you wish to lose files! Also, because UnZip is a unix-ported program, the filenames are CASE SENSITIVE. *unzip new/zip newfile will extract 'newfile', but not 'NewFile', 'NEWFILE' or any other combinations. However, you can use the -C option to force operations to disregard the case of filenames. The Acorn UnZip port has an additional feature to cope with the extraction of files containing 'c' code. As you may be aware, Acorn Desktop C requires all files called "foo.c" to be renamed to "c.foo", ie "foo" in a directory called "c". There are two ways of using this feature. - The old way: use a colon-separated environment variable named "Unzip$Exts". Any extensions found in this variable will be extracted to directories named after the extension, with the extension stripped. For example: *Set Unzip$Exts "c:h:o:s" *unzip foo/zip - The new way: use the -/ option. For example: Any extensions found in the parameter for this option will be extracted to directories named after the extension, with the extension stripped. For example: *unzip -/c:h:o:s foo/zip If foo/zip contains a file named "foo.c", this file will be written as "foo" in directory "c". This can be used to include "c:h:o:s:txt" to pull all the text files out to a separate directory. UnZip fully supports SparkFS Extra Field. This means that zipfiles created with SparkFS or Zip (on RISC OS) will be correctly unzipped, including filetypes. UnZipSFX can be used to create self-extracting archives. To use it, just create a common zipfile using Zip (or SparkFS), then load the UnZipSFX executable into an editor (eg. Edit, Zap), go with the caret the end of the file (using CTRL-CursorDown) and drag the zipfile to the editor window (in other words, append the zipfile to the UnZipSFX executable). Now, saving the resulting file (with filetype Absolute (&FF8)), you have a self-extracting archive (ie. double-clicking on it will unzip the contents of the original zipfile to the currently selected directory). *[UNZIP552.ACORN]RISCOS.C;1+,"./ 4@- 0@123KPWO56-?27-?289GHJ/* Copyright (c) 1990-2002 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html */ /* riscos.c */ #include #include #include /* #define NO_UNZIPH_STUFF */ #define UNZIP_INTERNAL #include "unzip.h" #include "riscos.h" #define MAXEXT 16 char *exts2swap = NULL; /* Extensions to swap (actually, directory names) */ int stat(char *filename,struct stat *res) { int attr; /* object attributes */ unsigned int load; /* load address */ unsigned int exec; /* exec address */ int type; /* type: 0 not found, 1 file, 2 dir, 3 image */ if (!res) return -1; if (SWI_OS_File_5(filename,&type,&load,&exec,(int *)&res->st_size,&attr)!=NULL) return -1; if (type==0) return -1; res->st_dev=0; res->st_ino=0; res->st_nlink=0; res->st_uid=1; res->st_gid=1; res->st_rdev=0; res->st_blksize=1024; res->st_mode = ((attr & 0001) << 8) | ((attr & 0002) << 6) | ((attr & 0020) >> 2) | ((attr & 0040) >> 4); switch (type) { case 1: /* File */ res->st_mode |= S_IFREG; break; case 2: /* Directory */ res->st_mode |= S_IFDIR | 0700; break; case 3: /* Image file */ if (uO.scanimage)܃ UNZIP.BCK" [UNZIP552.ACORN]RISCOS.C;1f res->st_mode |= S_IFDIR | 0700; else res->st_mode |= S_IFREG; break; } if ((((unsigned int) load) >> 20) == 0xfff) { /* date stamped file */ register unsigned int t1, t2, tc; t1 = (unsigned int) (exec); t2 = (unsigned int) (load & 0xff); tc = 0x6e996a00U; if (t1 < tc) t2--; t1 -= tc; t2 -= 0x33; /* 00:00:00 Jan. 1 1970 = 0x336e996a00 */ t1 = (t1 / 100) + (t2 * 42949673U); /* 0x100000000 / 100 = 42949672.96 */ t1 -= (t2 / 25); /* compensate for .04 error */ res->st_atime = res->st_mtime = res->st_ctime = t1; } else res->st_atime = res->st_mtime = res->st_ctime = 0; return 0; } #ifndef SFX DIR *opendir(char *dirname) { DIR *thisdir; int type; int attr; os_error *er; thisdir=(DIR *)malloc(sizeof(DIR)); if (thisdir==NULL) return NULL; thisdir->dirname=(char *)malloc(strlen(dirname)+1); if (thisdir->dirname==NULL) { free(thisdir); return NULL; } strcpy(thisdir->dirname,dirname); if (thisdir->dirname[strlen(thisdir->dirname)-1]=='.') thisdir->dirname[strlen(thisdir->dirname)-1]=0; if (er=SWI_OS_File_5(thisdir->dirname,&type,NULL,NULL,NULL,&attr),er!=NULL || type<=1 || (type==3 && !uO.scanimage)) { free(thisdir->dirname); free(thisdir); return NULL; } thisdir->buf=malloc(DIR_BUFSIZE); if (thisdir->buf==NULL) { free(thisdir->dirname); free(thisdir); return NULL; } thisdir->size=DIR_BUFSIZE; thisdir->offset=0; thisdir->read=0; return thisdir; } struct dirent *readdir(DIR *d) { static struct dirent dent; if (d->read==0) { /* no more objects read in the buffer */ if (d->offset==-1) { /* no more objects to read */ return NULL; } d->read=255; if (SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,DIR_BUFSIZE,NULL)!=NULL) return NULL; if (d->read==0) { d->offset=-1; return NULL; } d->read--; d->act=(char *)d->buf; } else { /* some object is ready in buffer */ d->read--; d->act=(char *)(d->act+strlen(d->act)+1); } strcpy(dent.d_name,d->act); dent.d_namlen=strlen(dent.d_name); /* If we're returning the last item, check if there are any more. * If there are, nothing will happen; if not, then d->offset = -1 */ if (!d->read) SWI_OS_GBPB_9(d->dirname,d->buf,&d->read,&d->offset,0,NULL); return &dent; } void closedir(DIR *d) { if (d->buf!=NULL) free(d->buf); if (d->dirname!=NULL) free(d->dirname); free(d); } int unlink(f) char *f; /* file to delete */ /* Delete the file *f, returning non-zero on failure. */ { os_error *er; char canon[256]; int size=255; er=SWI_OS_FSControl_37(f,canon,&size); if (er==NULL) { er=SWI_OS_FSControl_27(canon,0x100); } else { er=SWI_OS_FSControl_27(f,0x100); } return (int)er; } int rmdir(char *d) { int objtype; char *s; int len; len = strlen(d); if ((s = malloc(len + 1)) == NULL) return -1; strcpy(s,d); if (s[len-1]=='.') s[len-1]=0; if (SWI_OS_File_5(s,&objtype,NULL,NULL,NULL,NULL)!=NULL) { free(s); return -1; } if (objtype<2 || (!uO.scanimage && objtype==3)) { /* this is a file or it doesn't exist */ free(s); return -1; } if (SWI_OS_File_6(s)!=NULL) { free(s); return -1; } free(s); return 0; } #endif /* !SFX */ int chmod(char *file, int mode) { /*************** NOT YET IMPLEMENTED!!!!!! ******************/ /* I don't know if this will be needed or not... */ file=file; mode=mode; return 0; } void setfiletype(char *fname,int ftype) { char str[256]; sprintf(str,"SetType %s &%3.3X",fname,ftype); SWI_OS_CLI(str); } void getRISCOSexts(char *envstr) { char *envptr; /* value returned by getenv */ envptr = getenv(envstr); if (envptr == NULL || *envptr == 0) return; exts2swap=malloc(1+strlen(envptr)); if (exts2swap == NULL) return; strcpy(exts2swap, envptr); } int checkext(char *suff) { register char *extptr = exts2swap ? exts2swap : ""; register char *suffptr; register int e,s; while(*extptr) { suffptr=suff; e=*extptr; s=*suffptr; while (e && e!=':' && s && s!='.' && s!='/' && e==s) { e=*++extptr; s=*++suffptr; } if (e==':') e=0; if (s=='.' || s=='/') s=0; if (!e && !s) { return 1; } while(*extptr!=':' && *extptr!='\0') /* skip to next extension */ extptr++; if (*extptr!='\0') extptr++; } return 0; } void swapext(char *name, char *exptr) { char ext[MAXEXT]; register char *p1=exptr+1; register char *p2=ext; int extchar=*exptr; while(*p1 && *p1!='.' && *p1!='/') *p2++=*p1++; *p2=0; p2=exptr-1; p1--; while(p2 >= name) *p1--=*p2--; p1=name; p2=ext; while(*p2) *p1++=*p2++; *p1=(extchar=='/'?'.':'/'); } void remove_prefix(void) { SWI_DDEUtils_Prefix(NULL); } void set_prefix(void) { char *pref; int size=0; if (SWI_OS_FSControl_37("@",pref,&size)!=NULL) return; size=1-size; if (pref=malloc(size),pref!=NULL) { if (SWI_OS_FSControl_37("@",pref,&size)!=NULL) { free(pref); return; } if (SWI_DDEUtils_Prefix(pref)==NULL) { atexit(remove_prefix); } free(pref); } } #ifdef localtime # undef localtime #endif #ifdef gmtime # undef gmtime #endif /* Acorn's implementation of localtime() and gmtime() * doesn't consider the timezone offset, so we have to * add it before calling the library functions */ struct tm *riscos_localtime(const time_t *timer) { time_t localt=*timer; localt+=SWI_Read_Timezone()/100; return localtime(&localt); } struct tm *riscos_gmtime(const time_t *timer) { time_t localt=*timer; localt+=SWI_Read_Timezone()/100; return gmtime(&localt); } *[UNZIP552.ACORN]RISCOS.H;1+,$3./ 4@- 0@123KPWO56eO7eO89GHJ/* Copyright (c) 1990-2001 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html */ /* riscos.h */ #ifndef __riscos_h #define __riscos_h #include typedef struct { int errnum; char errmess[252]; } os_error; #ifndef __swiven_h # include "swiven.h" #endif #define MAXPATHLEN 256 #define MAXFILENAMELEN 64 /* should be 11 for ADFS, 13 for DOS, 64 seems a sensible value... */ #define DIR_BUFSIZE 1024 /* this should be enough to read a whole E-Format directory */ struct stat { unsigned int st_dev; int st_ino; unsigned int st_mode; int st_nlink; unsigned short st_uid; unsigned short st_gid; unsigned int st_rdev; unsigned int st_size; unsigned int st_blksize; time_t st_atime; time_t st_mtime; time_t st_ctime; }; $C UNZIP.BCK$3 [UNZIP552.ACORN]RISCOS.H;16  typedef struct { char *dirname; void *buf; int size; char *act; int offset; int read; } DIR; struct dirent { unsigned int d_off; /* offset of next disk directory entry */ int d_fileno; /* file number of entry */ size_t d_reclen; /* length of this record */ size_t d_namlen; /* length of d_name */ char d_name[MAXFILENAMELEN]; /* name */ }; typedef struct { unsigned int load_addr; unsigned int exec_addr; int lenght; int attrib; int objtype; char name[13]; } riscos_direntry; typedef struct { short ID; short size; int ID_2; unsigned int loadaddr; unsigned int execaddr; int attr; int zero; } extra_block; #define S_IFMT 0770000 #define S_IFDIR 0040000 #define S_IFREG 0100000 /* 0200000 in UnixLib !?!?!?!? */ #ifndef S_IEXEC # define S_IEXEC 0000100 # define S_IWRITE 0000200 # define S_IREAD 0000400 #endif #ifndef NO_UNZIPH_STUFF # include # if (!defined(HAVE_STRNICMP) & !defined(NO_STRNICMP)) # define NO_STRNICMP # endif # ifndef DATE_FORMAT # define DATE_FORMAT DF_DMY # endif # define lenEOL 1 # define PutNativeEOL *q++ = native(LF); # define USE_STRM_INPUT # define USE_FWRITE # define PIPE_ERROR (errno == 9999) /* always false */ # define isatty(x) (TRUE) /* used in funzip.c to find if stdin redirected: should find a better way, now just work as if stdin never redirected */ # define USE_EF_UT_TIME # if (!defined(NOTIMESTAMP) && !defined(TIMESTAMP)) # define TIMESTAMP # endif # define localtime riscos_localtime # define gmtime riscos_gmtime #endif /* !NO_UNZIPH_STUFF */ #define _raw_getc() SWI_OS_ReadC() extern char *exts2swap; /* Extensions to swap */ int stat(char *filename,struct stat *res); DIR *opendir(char *dirname); struct dirent *readdir(DIR *d); void closedir(DIR *d); int unlink(char *f); int rmdir(char *d); int chmod(char *file, int mode); void setfiletype(char *fname,int ftype); void getRISCOSexts(char *envstr); int checkext(char *suff); void swapext(char *name, char *exptr); void remove_prefix(void); void set_prefix(void); struct tm *riscos_localtime(const time_t *timer); struct tm *riscos_gmtime(const time_t *timer); #endif /* !__riscos_h */ *[UNZIP552.ACORN]RUNME1ST.;1+,./ 4c@- 0@123KPWO56ÖmH7ÖmH89GHJ| This Obey file prepares the UnZip port for a Desktop C re-compile. | Run it and it will copy all the needed files into the correct | place. | Set the correct type of 'srcrename' so that the only requirement | for the user is to set 'RunMe1st' to Obey SetType .srcrename FF8 | Run 'srcrename' on the main UnZip directory with recursion enabled /.srcrename -r -e c:h:s:o .^ | Create the 'o' directory CDir .^.o | Put the Makefile in its correct place and set the correct filetype SetType .makefile FE1 Copy .makefile .^.makefile ~C ~V F *[UNZIP552.ACORN]SRCRENAME.;1+,%./ 4 o@- 0@123KPWO 56vEDOF_q@LJHĚEƚn?oX/}ƚ-o*Ě:,pE@rIԈaSnf3rN"TSCbflzR;F99Jg?$7vؙęTKLYC9A;EAHZH皪જ+eC l6␘ԙ㘙ԙlԺfa4nN!u83gP7ݺԪEZ<6i\],+KCҚ7+XҚ=W6{,DT*}7~ԭl2salnb 4Xz" 𙻚 薙֔˩ әљ #ɟǙ a ng3sQyOY̚=+'BMGQH$NL/sI,84D5,?6Kw왬ī}FȚ|ND9)lWca4nN[ )I?v6i>?6H6i»\aob4w޺&/% - 0H'ފ(/&.@ (1ahne3qTPR?y8IrEɪ`Pp`VIwR6%RN_P&+1CMm|lE1 X8F:$iR4&I.V!&_DNJ q|CRMqO- m)LҪH6N:Z練bIa  "bT<8 ˒'N2#~Q]gbϭ.|-4`f:>Yg &tyH|خE^p|9"5[Ò>Zq_rxoMCja- At$鈥BXQ7,l w}薟+WKGT.y.}qޖ}C{V$:+~"(!, f{U]e t[fS`L *#p>7H3= o`Q#PdGv))+Xkf41_UsQ OB^@ *Cz6woaBqm&{f(e+w/;NL&nWF }q?ABtjTYLpk67s8k6`Qb@lpY!&6(ki^+U}094(+")̲[;UL1Us 5n^ .Xl%k{Vm3Ku-11-Pٶ* JrЯ2o+^jR,.+4(Qvp<|+:wd0_Ngد},uZ^8v8'>JH4)ވ?/(H)wRCޡ nb8\pwzQuU3_3;6PҘg N#tR0D`vI$ ]4sWS'7)]: G )V)L:bnf`*2™U%O~(B@2in)r, ,4 }W06@LRQ_s*d3"+wp6Q1]@nG 5llS3T DbCT,Mv¾>du\T!Aq-wC-/9@z=(ۙ,֥uubXJ#2D,N Hң(fww7t"X#\tg'N}A sb KyMOdP33/ mdD X qV=uRAA#?&[_dP [5 mJzQxhc{نXe: P ^LBo HqLyII4WV7h^i&'XQqb|h6W'dmT\i--+V%a,cTOG|, `TJR,wgwvv7b2jt%'3p@ {Z(w?g !pr<. "FT-1+2[x='x886c[r6b= <UJ[:q>Q [a,;E YB009e9`9-i~1ZweO@E#I=yR NBtZGo4C[8UgqP` ]Omq-h \kxFqNDPiu/4**8z[$L$u2'6 G@u4qh4iK.N*Hmx_r bej*4(3q{{LQ3vws C9ul8a"qZ[&m'dr.0`Ve};-44*kW3 Qt$V)rU"Dy)$L8/![qF:t$ I*K*mw7Ed ;)BkDm()}4:k8L]|d%zXp{ 3%0&9bR;^d=vZ&\08S1@c]$8-4-/#Iclrn[i f0iK#SBeVVy!%zT:r- Us e:v|"t!(QH+D XTUAyPu.; JlmVp 5 ZC!)0Ot@|}dWgC$'KLPLV"&Wyty.,m= w5A qem%S7x=lVkOT[K,{XB"WY S&?%Jr>:-F$#C2 qmC\BR=;wd33r80>lc1r*#"( Q?KP}d#MH{J9~)n9`";R]k%s=@! 6^AsX%6ZDt[v3KF{jmh X FM>!=t>81&( >qDxNNgZQ!j#&_l~rE,)mq|,3S"AI ^"/yLGz~>#CHXH:cO~_d~]!2rR}UD_th3|HC$Bu ab 3`;"Ml2iw1.sW n s>n>k+LST2j[`JYzu N[-]N"B@OU&Z}  H`_WotL ?]8+/x@ 9g<'-!x6|nd%GOY~sbpvvH|iUZ8^b%'cE5YZQ$p/FUW[ _Jb>G$fIf?FQzY\py vmWtO&3j68B' W ^s@Fy&dTf2|,HJ6| '?3=YKl*ebdu `r~ %_$B? p;k=ftSzo+UyM3PiJ v@{y]!bQgnACj H. 3854>[3P'CH27?~j.zD# mk%Q@# "sfDaGn@g\r=Wc>hT**%0^m^yZYc=hjm3Gg-phooJkoxގWS;PU+.(d[pIaBgPXhL}&&aS8A I}`ߴ!hz~ |oMD)/$%feqhJ;utoj'8Ap&^]EO'VC;p-n'+b:|7XUo;?xj-QH46jQ-@kh0OrYW!&Fu:Yo6*<5L`<&(72WPd#?*)eoQ(k>:&BIB J5N$RTU )3e{>j*;BKhm6}%&AJKz*Q;!!@g P<"&E,&^UXS]|B7yi; ZIXk.bW} Qm}1'5 is~wza}=98mj#Le:7{1Um/ E~%C,H9kj~Hd}\R9E.9Zox@r-K5l#e0{bvtm x|s(qRm8QpE ~-uvxoUZ h[HYj;S UAT)FLs:>:+2j?[u{[&i0g>Sdp#+h#Y734%AW@GHL]^Iija6J1lyDcU"XTlE?~ryl~>GK8\#psS%U_xy0nF F^.ah^J>I)}F .z5tXL F]SE"`{b[~|Rab0,9dRu4w!).|[#^1{V=4+5^vBlo3FCb WPF4 1.Kkw6G~@f.> x"*+c%jTC@YG]Fl PBG{f'pexRWiLV@Hdg7{jyr;GZP(~~zzw=7N{py^Hz`n\)md-qT8qH?v^#oEOf,a-E!K2()._ q\0'E*b|l`.z{/FP|!nD'BJ* OWigcl-GHWk%3 RplYQ=Kx 'n}I @%I_4_ uL~NHP"ZEc|xxLv0y JS,1|Lf$3wQLJ]II5K\H#;%?Ed[9*D6.OF|NCl[PMF[O@tMVD _7BerU}4tYsk&");sunZ{jR-B>C:$30 c,|:+N[wYW~13H0~*R?\ N(]iU H{cuXl,ұw3fDxՒMt9],oD@0gŃaQT<1 쏀!6,(a.IZ"OCYh8 ӕb,ޤ>1dۤ95R%[ȆŅ; ;[ܔ햩 *[m$A@[zthSy<dLUW \<Ѹ:wPK`ќ%7<m'|)7~ɵĈ65Q(V=њdr`tC$ ̉+>sj6#& Hޣضͣc \+˜鯶4Ư۝{JЛKǎTΥȯa?Ãĵ%˛ׅ͛g31*tGF=ٞrfrðaSڶ1[p\mc:t¯N7y£ 1Ld:5'iHTx?z׷О,㴷ٝtHٮ^ާ{$ ľШj樽Ϻ$ť5dsnpd6Fц͵iɹt{ {Շ}U@C~ȼ҅2ف^0xP1*<÷#{-ϩⲜԉ뫴ԎmiۊڢȲ\᜵򾒥ȷӨ۩Ɋ󩚽򯲟ٍ܋ޠ֊ϗ܇ŏ*z͝ߖ{ƔЮ븄 Szп~H쫳҇~pظ5ѶͮкɅݣٗᚐHI" .AcI(wٗRW/E9x N ~5FM>"ZH1^RXp[~cNJm1=vjR3v`Hl-x4BJ7ofxO`EmNCw;?h8jzk3j+$\n]yq+`=w74{7S\F  1TSI!ja{")+kFsF?a+plb&z>!xQ?MM Rܚ%7agq*w2m@rui~q2qls}A9.^8Tt:r c,|9ERwt9Hy%4'Y ak%;i2$=|*=`-!?l'dzQ]+;m7}D+J%zJ<z[yS@v_=xsi;dvkpkAEwK_vDN|i%lHw]xnc*K.),KI 8p0o++$1}85}GZB%/ wM!DOhxX%A iGV mbaeqR: y{K2%,B(r0TK C /7`^1z=%FzAI s _`W.m}Lnlg8:# %!EY*9?"(m2syx ?.1-  U ɓ'^Np2s"k}G#tltGh;Y}y #'|d@7#.P8,mʒwzѐqJ@_]3F NP i*##PjmI,VS'R7| Of ԺK>uTGgstō !b/!_Zإ_ .0`Q=$#24zIQ)_:p}fjv`*#^-EO췕fY/7j CbHn'!U 1XTl˛OB f짜XsJI6uPl\qLKl$tՋy5GՃ!EڒI6vC-pU,TYNih>{19VРkE+]y\Wa%MˈehK>zc #=&md$0jGe 64!>]+mF/jq-M~'U839'.1_"2S0 i r6gz7E__`%{_XQ)O_Ga)d/ŗxHW~vߍf;؞>pX+(S?w1 FX[R %Det=|=-M5DW+6b8NBI8MlH@zS J7rUAeLJ0;OmG&ObU2W5Mq&3mC㱦+IЄÚJh&/-#mÄo< #tLr X=u6L =XQZ\Ye$-#*@ u mo UNZIP.BCK( [UNZIP552.ACORN]SWIVEN.S;1J OVVC r0, #0 LDMFD sp!, {r4-r5,pc}^ ; os_error *SWI_OS_File_8(char *dirname); STARTCODE SWI_OS_File_8 STMFD sp!, {r4,lr} MOV r1, r0 MOV r4, #0 MOV r0, #8 SWI OS_File + XOS_Bit MOVVC r0, #0 LDMFD sp!, {r4,pc}^ ; os_error *SWI_OS_File_18(char *filename, int filetype); STARTCODE SWI_OS_File_18 STMFD sp!, {r4-r5,lr} MOV r2, r1 MOV r1, r0 MOV r0, #18 SWI OS_File + XOS_Bit MOVVC r0, #0 LDMFD sp!, {r4-r5,pc}^ ; os_error *SWI_OS_CLI(char *cmd); STARTCODE SWI_OS_CLI MOV ip, lr SWI OS_CLI + XOS_Bit MOVVC r0, #0 MOVS pc, ip ; int SWI_OS_ReadC(void); STARTCODE SWI_OS_ReadC MOV ip, lr SWI OS_ReadC + XOS_Bit MOVS pc, ip ; os_error *SWI_OS_ReadVarVal(char *var, char *buf, int len, int *bytesused); STARTCODE SWI_OS_ReadVarVal STMFD sp!, {r4,lr} MOV ip, r3 MOV r3, #0 MOV r4, #0 SWI OS_ReadVarVal + XOS_Bit LDMVSFD sp!, {r4,pc}^ TEQ ip, #0 STRNE r2, [ip] MOV r0, #0 LDMFD sp!, {r4,pc}^ ; os_error *SWI_OS_FSControl_54(char *buffer, int dir, char *fsname, int *size); STARTCODE SWI_OS_FSControl_54 STMFD sp!, {r3-r6,lr} LDR r5, [r3] MOV r3, r2 MOV r2, r1 MOV r1, r0 MOV r0, #54 SWI OS_FSControl + XOS_Bit LDMVSFD sp!, {r3-r6,pc}^ MOV r0, #0 LDMFD sp!, {r3} STR r5, [r3] LDMFD sp!, {r4-r6,pc}^ ; os_error *SWI_OS_FSControl_37(char *pathname, char *buffer, int *size); STARTCODE SWI_OS_FSControl_37 STMFD sp!, {r2,r3-r5,lr} LDR r5, [r2] MOV r3, #0 MOV r4, #0 MOV r2, r1 MOV r1, r0 MOV r0, #37 SWI OS_FSControl + XOS_Bit LDMVSFD sp!, {r2,r3-r5,pc}^ MOV r0, #0 LDMFD sp!, {r2} STR r5, [r2] LDMFD sp!, {r3-r5,pc}^ ; os_error *SWI_DDEUtils_Prefix(char *dir); STARTCODE SWI_DDEUtils_Prefix MOV ip, lr SWI DDEUtils_Prefix + XOS_Bit MOVVC r0, #0 MOVS pc, ip ; int SWI_Read_Timezone(void); STARTCODE SWI_Read_Timezone MOV ip, lr SWI Territory_ReadCurrentTimeZone + XOS_Bit MOVVC r0, r1 MOVVS r0, #0 MOVS pc, ip ; int SWI_MimeMap_Translate(char *ext); STARTCODE SWI_MimeMap_Translate MOV ip,lr MOV r1, r0 MOV r0, #3 MOV r2, #0 SWI MimeMap_Translate + XOS_Bit MOVVC r0, r3 MVNVS r0, #0 ; return -1 on error MOVS pc, ip END *[UNZIP552]AMIGA.DIR;1+,*./ 4-0123 KPWO56 W7 W89GHJIAMIGA.C,AMIGA.H2& CONTENTS.+CRC_68.A5> FILEDATE.C;"FLATE.A<' MAKEFILE.AZT= MAKESFX.C>  SMAKEFILE.@&STAT.CCZ-STAT.HD*[UNZIP552.AMIGA]AMIGA.C;1+,,.H/ 4HG@-*0@123KPWOH563f73f89GHJ/* Copyright (c) 1990-2005 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html */ /*------------------------------------------------------------------------ amiga.c Amiga-specific routines for use with Info-ZIP's UnZip 5.1 and later. See History.5xx for revision history. Contents: do_wild() mapattr() mapname() checkdir() close_outfile() stamp_file() _abort() (Aztec C only) [dateformat()] (currently not used) screensize() version() ------------------------------------------------------------------------*/ #define UNZIP_INTERNAL #ifdef AZTEC_C # define NO_FCNTL_H #endif #include "unzip.h" #include "unzvers.h" /* Globular varibundus -- now declared in SYSTEM_SPECIFIC_GLOBALS in amiga.h */ /* static int created_dir; */ /* used in mapname(), checkdir() */ /* static int renamed_fullpath; */ /* ditto */ #define PERMS 0777 #define MKDIR(path,mode) mkdir(path) #ifndef S_ISCRIPT /* not having one implies you have none */ # define S_IARCHIVE 0020 /* not modified since this bit was last set */ # define S_IREAD 0010 /* can be opened for reading */ # define S_IWRITE 0004 /* can be opened for writing */ # define S_IDELETE 0001 /* can be deleted */ #endif /* S_ISCRIPT */ #ifndef S_IRWD # define S_IRWD 0015 /* useful combo of Amiga privileges */ #endif /* !S_IRWD */ #ifndef S_IHIDDEN # define S_IHIDDEN 0200 /* hidden supported in future AmigaDOS (someday) */ #endif /* !S_HIDDEN */ #ifndef SFX /* Make sure the number here matches unzvers.h in the *EXACT* form */ /* UZ_MAJORVER "." UZ_MINORVER UZ_PATCHLEVEL vvvv No non-digits! */ const char version_id[] = "\0$VER: UnZip " UZ_VER_STRING " (" #include "env:VersionDate" ")\r\n"; #endif /* SFX */ static int ispattern(ZCONST char *p) { register char c; while (c = *p++) if (c == '\\') { if (!*++p) return FALSE; } else if (c == '?' || c == '*') return TRUE; else if (c == '[') { for (;;) { if (!(c = *p++)) return FALSE; else if (c == '\\') { if (!*++p) return FALSE; } else if (c == ']') return TRUE; } } return FALSE; } /**********************/ /* Function do_wild() */ /**********************/ char *do_wild(__G__ wildspec) __GDEF ZCONST char *wildspec; /* only used first time on a given dir */ { /* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in amiga.h: static DIR *wild_dir = NULL; static ZCONST char *wildname; static char *dirname, matchname[FILNAMSIZ]; static int notfirstcall = FALSE, dirnamelen; */ struct dirent *file; BPTR lok = 0; /* Even when we're just returning wildspec, we *always* do so in * matchname[]--calling routine is allowed to append four characters * to the returned string, and wildspec may be a pointer to argv[]. */ if (!G.notfirstcall) { /* first call: must initialize everything */ G.notfirstcall = TRUE; /* avoid needless readdir() scans: */ if (!ispattern(wildspec) || (lok = Lock((char *)wildspec, ACCESS_READ))) { if (lok) UnLock(lok); /* ^^ we ignore wildcard chars if */ G.dirnamelen = 0; /* the name matches a real file */ strncpy(G.matchname, wildspec, FILNAMSIZ); G.matchname[FILNAMSIZ-1] = '\0'; return G.matchname; } /* break the wildspec into a directory part and a wildcard filename */ if ((G.wildname = (ZCONST char *)strrchr(wildspec, '/ U UNZIP.BCK,*[UNZIP552.AMIGA]AMIGA.C;1Hku ')) == NULL && (G.wildname = (ZCONST char *)strrchr(wildspec, ':')) == NULL) { G.dirname = ""; /* current dir */ G.dirnamelen = 0; G.wildname = wildspec; } else { ++G.wildname; /* point at character after '/' or ':' */ G.dirnamelen = G.wildname - wildspec; if ((G.dirname = (char *)malloc(G.dirnamelen+1)) == NULL) { Info(slide, 1, ((char *)slide, "warning: cannot allocate wildcard buffers\n")); strncpy(G.matchname, wildspec, FILNAMSIZ); G.matchname[FILNAMSIZ-1] = '\0'; return G.matchname; /* but maybe filespec was not a wildcard */ } strncpy(G.dirname, wildspec, G.dirnamelen); G.dirname[G.dirnamelen] = '\0'; } if ((G.wild_dir = opendir(G.dirname)) != NULL) { while ((file = readdir(G.wild_dir)) != NULL) { if (match(file->d_name, G.wildname, 1 WISEP)) {/* ignore case */ strcpy(G.matchname, G.dirname); strcpy(G.matchname + G.dirnamelen, file->d_name); return G.matchname; } } /* if we get to here directory is exhausted, so close it */ closedir(G.wild_dir); G.wild_dir = NULL; } /* return the raw wildspec in case that works (e.g., directory not * searchable, but filespec was not wild and file is readable) */ strncpy(G.matchname, wildspec, FILNAMSIZ); G.matchname[FILNAMSIZ-1] = '\0'; return G.matchname; } /* last time through, might have failed opendir but returned raw wildspec */ if (G.wild_dir == NULL) { G.notfirstcall = FALSE; /* nothing left to try -- reset */ if (G.dirnamelen > 0) free(G.dirname); return (char *)NULL; } /* If we've gotten this far, we've read and matched at least one entry * successfully (in a previous call), so dirname has been copied into * matchname already. */ while ((file = readdir(G.wild_dir)) != NULL) if (match(file->d_name, G.wildname, 1 WISEP)) { /* 1 == ignore case */ /* strcpy(G.matchname, dirname); */ strcpy(G.matchname + G.dirnamelen, file->d_name); return G.matchname; } closedir(G.wild_dir); /* have read at least one dir entry; nothing left */ G.wild_dir = NULL; G.notfirstcall = FALSE; /* reset for new wildspec */ if (G.dirnamelen > 0) free(G.dirname); return (char *)NULL; } /* end function do_wild() */ /**********************/ /* Function mapattr() */ /**********************/ int mapattr(__G) /* Amiga version */ __GDEF { ulg tmp = G.crec.external_file_attributes; /* Amiga attributes = hsparwed = hidden, script, pure, archive, * read, write, execute, delete */ switch (G.pInfo->hostnum) { case AMIGA_: if ((tmp & 1) == (tmp>>18 & 1)) tmp ^= 0x000F0000; /* PKAZip compatibility kluge */ /* turn off archive bit for restored Amiga files */ G.pInfo->file_attr = (unsigned)((tmp>>16) & (~S_IARCHIVE)); break; case UNIX_: /* preserve read, write, execute: use logical-OR of */ case VMS_: /* user, group, and other; if writable, set delete bit */ case ACORN_: case ATARI_: case ATHEOS_: case BEOS_: case QDOS_: case TANDEM_: { unsigned uxattr = (unsigned)(tmp >> 16); int r = FALSE; if (uxattr == 0 && G.extra_field) { /* Some (non-Info-ZIP) implementations of Zip for Unix and VMS (and probably others ??) leave 0 in the upper 16-bit part of the external_file_attributes field. Instead, they store file permission attributes in some extra field. As a work-around, we search for the presence of one of these extra fields and fall back to the MSDOS compatible part of external_file_attributes if one of the known e.f. types has been detected. Later, we might implement extraction of the permission bits from the VMS extra field. But for now, the work-around should be sufficient to provide "readable" extracted files. (For ASI Unix e.f., an experimental remap of the e.f. mode value IS already provided!) */ ush ebID; unsigned ebLen; uch *ef = G.extra_field; unsigned ef_len = G.crec.extra_field_length; while (!r && ef_len >= EB_HEADSIZE) { ebID = makeword(ef); ebLen = (unsigned)makeword(ef+EB_LEN); if (ebLen > (ef_len - EB_HEADSIZE)) /* discoverd some e.f. inconsistency! */  break; switch (ebID) { case EF_ASIUNIX: if (ebLen >= (EB_ASI_MODE+2)) { uxattr = (unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE)); /* force stop of loop: */ ef_len = (ebLen + EB_HEADSIZE); break; } /* else: fall through! */ case EF_PKVMS: /* "found nondecypherable e.f. with perm. attr" */ r = TRUE; default: break; } ef_len -= (ebLen + EB_HEADSIZE); ef += (ebLen + EB_HEADSIZE); } } if (!r) { uxattr = (( uxattr>>6 | uxattr>>3 | uxattr) & 07) << 1; G.pInfo->file_attr = (unsigned)(uxattr&S_IWRITE ? uxattr|S_IDELETE : uxattr); break; } } /* fall through! */ /* all other platforms: assume read-only bit in DOS half of attribute * word is set correctly ==> will become READ or READ+WRITE+DELETE */ case FS_FAT_: case FS_HPFS_: /* can add S_IHIDDEN check to MSDOS/OS2/NT eventually */ case FS_NTFS_: case MAC_: case TOPS20_: default: G.pInfo->file_attr = (unsigned)(tmp&1? S_IREAD : S_IRWD); break; } /* end switch (host-OS-created-by) */ G.pInfo->file_attr &= 0xff; /* mask off all but lower eight bits */ return 0; } /* end function mapattr() */ /************************/ /* Function mapname() */ /************************/ int mapname(__G__ renamed) __GDEF int renamed; /* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - caution (truncated filename) * MPN_INF_SKIP - info "skip entry" (dir doesn't exist) * MPN_ERR_SKIP - error -> skip entry * MPN_ERR_TOOLONG - error -> path is too long * MPN_NOMEM - error (memory allocation failed) -> skip entry * [also MPN_VOL_LABEL, MPN_CREATED_DIR] */ { char pathcomp[FILNAMSIZ]; /* path-component buffer */ char *pp, *cp=NULL; /* character pointers */ char *lastsemi = NULL; /* pointer to last semi-colon in pathcomp */ int killed_ddot = FALSE; /* is set when skipping "../" pa=5 UNZIP.BCK,*[UNZIP552.AMIGA]AMIGA.C;1Hϟthcomp */ int error = MPN_OK; register unsigned workch; /* hold the character being tested */ /*--------------------------------------------------------------------------- Initialize various pointers and counters and stuff. ---------------------------------------------------------------------------*/ if (G.pInfo->vollabel) return MPN_VOL_LABEL; /* can't set disk volume labels in AmigaDOS */ /* can create path as long as not just freshening, or if user told us */ G.create_dirs = (!uO.fflag || renamed); G.created_dir = FALSE; /* not yet */ /* user gave full pathname: don't prepend G.rootpath */ #ifndef OLD_AMIGA_RENAMED G.renamed_fullpath = (renamed && (*G.filename == '/' || *G.filename == ':')); #else /* supress G.rootpath even when user gave a relative pathname */ # if 1 G.renamed_fullpath = (renamed && strpbrk(G.filename, ":/"); # else G.renamed_fullpath = (renamed && (strchr(G.filename, ':') || strchr(G.filename, '/'))); # endif #endif if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM) return MPN_NOMEM; /* initialize path buffer, unless no memory */ *pathcomp = '\0'; /* initialize translation buffer */ pp = pathcomp; /* point to translation buffer */ if (uO.jflag) /* junking directories */ cp = (char *)strrchr(G.filename, '/'); if (cp == (char *)NULL) /* no '/' or not junking dirs */ cp = G.filename; /* point to internal zipfile-member pathname */ else ++cp; /* point to start of last component of path */ /*--------------------------------------------------------------------------- Begin main loop through characters in filename. ---------------------------------------------------------------------------*/ while ((workch = (uch)*cp++) != 0) { switch (workch) { case '/': /* can assume -j flag not given */ *pp = '\0'; if (strcmp(pathcomp, ".") == 0) { /* don't bother appending "./" to the path */ *pathcomp = '\0'; } else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) { /* "../" dir traversal detected, skip over it */ *pathcomp = '\0'; killed_ddot = TRUE; /* set "show message" flag */ } /* when path component is not empty, append it now */ if (*pathcomp != '\0' && ((error = checkdir(__G__ pathcomp, APPEND_DIR)) & MPN_MASK) > MPN_INF_TRUNC) return error; pp = pathcomp; /* reset conversion buffer for next piece */ lastsemi = (char *)NULL; /* leave direct. semi-colons alone */ break; case ';': /* VMS version (or DEC-20 attrib?) */ lastsemi = pp; /* keep for now; remove VMS ";##" */ *pp++ = (char)workch; /* later, if requested */ break; default: /* allow ISO European characters in filenames: */ if (isprint(workch) || (160 <= workch && workch <= 255)) *pp++ = (char)workch; } /* end switch */ } /* end while loop */ /* Show warning when stripping insecure "parent dir" path components */ if (killed_ddot && QCOND2) { Info(slide, 0, ((char *)slide, "warning: skipped \"../\" path component(s) in %s\n", FnFilter1(G.filename))); if (!(error & ~MPN_MASK)) error = (error & MPN_MASK) | PK_WARN; } /*--------------------------------------------------------------------------- Report if directory was created (and no file to create: filename ended in '/'), check name to be sure it exists, and combine path and name be- fore exiting. ---------------------------------------------------------------------------*/ if (G.filename[strlen(G.filename) - 1] == '/') { checkdir(__G__ G.filename, GETPATH); if (G.created_dir) { if (QCOND2) { Info(slide, 0, ((char *)slide, " creating: %s\n", FnFilter1(G.filename))); } /* set dir time (note trailing '/') */ return (error & ~MPN_MASK) | MPN_CREATED_DIR; } /* dir existed already; don't look for data to extract */ return (error & ~MPN_MASK) | MPN_INF_SKIP; } *pp = '\0'; /* done with pathcomp: terminate it */ /* if not saving them, remove VMS version numbers (appended ";###") */ if (!uO.V_flag && lastsemi) { pp = lastsemi + 1; while (isdigit((uch)(*pp))) ++pp; if (*pp == '\0') /* only digits between ';' and end: nuke */ *lastsemi = '\0'; } if (*pathcomp == '\0') { Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n", FnFilter1(G.filename))); return (error & ~MPN_MASK) | MPN_ERR_SKIP; } error = (error & ~MPN_MASK) | checkdir(__G__ pathcomp, APPEND_NAME); if ((error & MPN_MASK) == MPN_INF_TRUNC) { /* GRR: OK if truncated here: warn and continue */ /* (warn in checkdir?) */ } checkdir(__G__ G.filename, GETPATH); return error; } /* end function mapname() */ /***********************/ /* Function checkdir() */ /***********************/ int checkdir(__G__ pathcomp, flag) __GDEF char *pathcomp; int flag; /* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename * MPN_INF_SKIP - path doesn't exist, not allowed to create * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path * exists and is not a directory, but is supposed to be * MPN_ERR_TOOLONG - path is too long * MPN_NOMEM - can't allocate memory for filename buffers */ { /* these statics are now declared in SYSTEM_SPECIFIC_GLOBALS in amiga.h: */ /* static int rootlen = 0; */ /* length of rootpath */ /* static char *rootpath; */ /* user's "extract-to" directory */ /* static char *buildpath; */ /* full path (so far) to extracted file */ /* static char *end; */ /* pointer to end of buildpath ('\0') */ # define FN_MASK 7 # define FUNCTION (flag & FN_MASK) /*--------------------------------------------------------------------------- APPEND_DIR: append the path component to the path being built and check for its existence. If doesn't exist and we are creating directories, do so for this one; else signal success or error as appropriate. ---------------------------------------------------------------------------*/ /* GRR: check path length after each segment: warn about truncation */ if (FUNCTION == APPEND_DIR) { int too_long = FALSE; Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp))); while ((*G.build_end = *pathcomp++) != '\0') ++G.build_end; /* Truncate components over 30 chars? Nah, the filesystem handles it. */ if ((G.build_end-G.buildpath) > FILNAMSIZ-3) /* room for "/a\0" */ too_long = TRUE; /* check if extracting dir? */ if (SSTAT(G.buildpath, &G.statbuf)) { /* path doesn't exist */ if (!G.create_dirs) { /* told not to create (freshening) */ free(G.buildpath); return MPN_INF_SKIP; /* paqM UNZIP.BCK,*[UNZIP552.AMIGA]AMIGA.C;1HR'th doesn't exist: nothing to do */ } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too long: %s\n", FnFilter1(G.buildpath))); free(G.buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } if (MKDIR(G.buildpath, 0777) == -1) { /* create the directory */ Info(slide, 1, ((char *)slide, "checkdir error: cannot create %s\n\ unable to process %s.\n", FnFilter2(G.buildpath), FnFilter1(G.filename))); free(G.buildpath); /* path didn't exist, tried to create, failed */ return MPN_ERR_SKIP; } G.created_dir = TRUE; } else if (!S_ISDIR(G.statbuf.st_mode)) { Info(slide, 1, ((char *)slide, "checkdir error: %s exists but is not directory\n\ unable to process %s.\n", FnFilter2(G.buildpath), FnFilter1(G.filename))); free(G.buildpath); /* path existed but wasn't dir */ return MPN_ERR_SKIP; } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too long: %s\n", FnFilter1(G.buildpath))); free(G.buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } *G.build_end++ = '/'; *G.build_end = '\0'; Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath))); return MPN_OK; } /* end if (FUNCTION == APPEND_DIR) */ /*--------------------------------------------------------------------------- GETPATH: copy full path to the string pointed at by pathcomp, and free G.buildpath. Not our responsibility to worry whether pathcomp has room. ---------------------------------------------------------------------------*/ if (FUNCTION == GETPATH) { strcpy(pathcomp, G.buildpath); Trace((stderr, "getting and freeing path [%s]\n", FnFilter1(pathcomp))); free(G.buildpath); G.buildpath = G.build_end = (char *)NULL; return MPN_OK; } /*--------------------------------------------------------------------------- APPEND_NAME: assume the path component is the filename; append it and return without checking for existence. ---------------------------------------------------------------------------*/ if (FUNCTION == APPEND_NAME) { Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp))); while ((*G.build_end = *pathcomp++) != '\0') { ++G.build_end; if ((G.build_end-G.buildpath) >= FILNAMSIZ) { *--G.build_end = '\0'; Info(slide, 0x201, ((char *)slide, "checkdir warning: path too long; truncating\n\ %s\n -> %s\n", FnFilter1(G.filename), FnFilter2(G.buildpath))); return MPN_INF_TRUNC; /* filename truncated */ } } Trace((stderr, "buildpath now = [%s]\n", FnFilter1(G.buildpath))); /* could check for existence here, prompt for new name... */ return MPN_OK; } /*--------------------------------------------------------------------------- INIT: allocate and initialize buffer space for the file currently being extracted. If file was renamed with an absolute path, don't prepend the extract-to path. ---------------------------------------------------------------------------*/ if (FUNCTION == INIT) { Trace((stderr, "initializing buildpath to ")); if ((G.buildpath = (char *)malloc(strlen(G.filename)+G.rootlen+1)) == (char *)NULL) return MPN_NOMEM; if ((G.rootlen > 0) && !G.renamed_fullpath) { strcpy(G.buildpath, G.rootpath); G.build_end = G.buildpath + G.rootlen; } else { *G.buildpath = '\0'; G.build_end = G.buildpath; } Trace((stderr, "[%s]\n", FnFilter1(G.buildpath))); return MPN_OK; } /*--------------------------------------------------------------------------- ROOT: if appropriate, store the path in G.rootpath and create it if necessary; else assume it's a zipfile member and return. This path segment gets used in extracting all members from every zipfile specified on the command line. ---------------------------------------------------------------------------*/ #if (!defined(SFX) || defined(SFX_EXDIR)) if (FUNCTION == ROOT) { Trace((stderr, "initializing root path to [%s]\n", FnFilter1(pathcomp))); if (pathcomp == (char *)NULL) { G.rootlen = 0; return MPN_OK; } if (G.rootlen > 0) /* rootpath was already set, nothing to do */ return MPN_OK; if ((G.rootlen = strlen(pathcomp)) > 0) { if (stat(pathcomp, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode)) { /* path does not exist */ if (!G.create_dirs) { G.rootlen = 0; /* skip (or treat as stored file) */ return MPN_INF_SKIP; } /* create the directory (could add loop here scanning pathcomp * to create more than one level, but why really necessary?) */ if (MKDIR(pathcomp, 0777) == -1) { Info(slide, 1, ((char *)slide, "checkdir: cannot create extraction directory: %s\n", FnFilter1(pathcomp))); G.rootlen = 0; /* path didn't exist, tried to create, and failed: */ /* file exists, or 2+ subdir levels required */ return MPN_ERR_SKIP; } } if ((G.rootpath = (char *)malloc(G.rootlen+2)) == NULL) { G.rootlen = 0; return MPN_NOMEM; } strcpy(G.rootpath, pathcomp); if (G.rootpath[G.rootlen-1] != ':' && G.rootpath[G.rootlen-1] != '/') G.rootpath[G.rootlen++] = '/'; G.rootpath[G.rootlen] = '\0'; Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.rootpath))); } return MPN_OK; } #endif /* !SFX || SFX_EXDIR */ /*--------------------------------------------------------------------------- END: free G.rootpath, immediately prior to program exit. ---------------------------------------------------------------------------*/ if (FUNCTION == END) { Trace((stderr, "freeing rootpath\n")); if (G.rootlen > 0) { free(G.rootpath); G.rootlen = 0; } return MPN_OK; } return MPN_INVALID; /* should never reach */ } /* end function checkdir() */ /**************************************/ /* Function close_outfile() */ /**************************************/ /* this part differs slightly with Zip */ /*-------------------------------------*/ void close_outfile(__G) __GDEF { time_t m_time; #ifdef USE_EF_UT_TIME iztimes z_utime; #endif LONG FileDate(); if (uO.cflag) /* can't set time or filenote on stdout */ return; /* close the file *before* setting its time under AmigaDOS */ fclose(G.outfile); #ifdef USE_EF_UT_TIME if (G.extra_field && #ifdef IZ_CHECK_TZ G.tz_is_valid && #endif (ef_scan_for_izux(G.extra_field, G.lrec.extrag&c UNZIP.BCK,*[UNZIP552.AMIGA]AMIGA.C;1H6_field_length, 0, G.lrec.last_mod_dos_datetime, &z_utime, NULL) & EB_UT_FL_MTIME)) { TTrace((stderr, "close_outfile: Unix e.f. modif. time = %ld\n", z_utime.mtime)); m_time = z_utime.mtime; } else { /* Convert DOS time to time_t format */ m_time = dos_to_unix_time(G.lrec.last_mod_dos_datetime); } #else /* !USE_EF_UT_TIME */ /* Convert DOS time to time_t format */ m_time = dos_to_unix_time(G.lrec.last_mod_dos_datetime); #endif /* ?USE_EF_UT_TIME */ #ifdef DEBUG Info(slide, 1, ((char *)slide, "\nclose_outfile(): m_time=%s\n", ctime(&m_time))); #endif if (!FileDate(G.filename, &m_time)) Info(slide, 1, ((char *)slide, "warning: cannot set the time for %s\n", G.filename)); /* set file perms after closing (not done at creation)--see mapattr() */ chmod(G.filename, G.pInfo->file_attr); /* give it a filenote from the zipfile comment, if appropriate */ if (uO.N_flag && G.filenotes[G.filenote_slot]) { SetComment(G.filename, G.filenotes[G.filenote_slot]); free(G.filenotes[G.filenote_slot]); G.filenotes[G.filenote_slot] = NULL; } } /* end function close_outfile() */ #ifdef TIMESTAMP /*************************/ /* Function stamp_file() */ /*************************/ int stamp_file(fname, modtime) ZCONST char *fname; time_t modtime; { time_t m_time; LONG FileDate(); m_time = modtime; return (FileDate((char *)fname, &m_time)); } /* end function stamp_file() */ #endif /* TIMESTAMP */ #ifndef __SASC /********************************************************************/ /* Load filedate as a separate external file; it's used by Zip, too.*/ /* */ # include "amiga/filedate.c" /* */ /* */ /********************************************************************/ /********************* do linewise with stat.c **********************/ # include "amiga/stat.c" /* this is the exact same stat.c used by Zip */ #endif /* !__SASC */ /* SAS/C makes separate object modules of these; there is less */ /* trouble that way when redefining standard library functions. */ #include void _abort(void) /* called when ^C is pressed */ { /* echon(); */ close_leftover_open_dirs(); fflush(stdout); fputs("\n^C\n", stderr); exit(1); } /************************************************************/ /* function screensize() -- uses sendpkt() from filedate.c: */ /************************************************************/ #include #include #include #include extern long sendpkt(struct MsgPort *pid, long action, long *args, long nargs); int screensize(int *ttrows, int *ttcols) { BPTR fh = Output(); if (fh && IsInteractive(fh)) { struct ConUnit *conunit = NULL; void *conp = ((struct FileHandle *) (fh << 2))->fh_Type; struct InfoData *ind = AllocMem(sizeof(*ind), MEMF_PUBLIC); long argp = ((unsigned long) ind) >> 2; if (ind && conp && sendpkt(conp, ACTION_DISK_INFO, &argp, 1)) conunit = (void *) ((struct IOStdReq *) ind->id_InUse)->io_Unit; if (ind) FreeMem(ind, sizeof(*ind)); if (conunit) { if (ttrows) *ttrows = conunit->cu_YMax + 1; if (ttcols) *ttcols = conunit->cu_XMax + 1; return 0; /* success */ } } if (ttrows) *ttrows = INT_MAX; if (ttcols) *ttcols = INT_MAX; return 1; /* failure */ } #ifdef AMIGA_VOLUME_LABELS /* This function is for if we someday implement -$ on the Amiga. */ # include # include # include BOOL is_floppy(ZCONST char *path) { BOOL okay = FALSE; char devname[32], *debna; ushort i; BPTR lok = Lock((char *)path, ACCESS_READ), pok; struct FileSysStartupMsg *fart; struct DeviceNode *debb, devlist = (void *) BADDR((struct DosInfo *) BADDR(DOSBase->dl_Root->rn_Info)->di_DevInfo); if (!lok) return FALSE; /* should not happen */ if (pok = ParentDir((char *)path)) { UnLock(lok); UnLock(pok); return FALSE; /* it's not a root directory path */ } Forbid(); for (debb = devlist; debb; debb = BADDR(debb->dn_Next)) if (debb->dn_Type == DLT_DEVICE && (debb->dn_Task == lick->fl_Task)) if (fart = BADDR(debb->dn_Startup)) { debna = (char *) BADDR(fart->fssm_Device) + 1; if ((i = debna[-1]) > 31) i = 30; strncpy(devname, debna, i); devname[i] = 0; okay = !strcmp(devname, "trackdisk.device") || !strcmp(devname, "mfm.device") || !strcmp(devname, "messydisk.device"); break; /* We only support obvious floppy drives, not tricky */ } /* things like removable cartrige hard drives, or */ Permit(); /* any unusual kind of floppy device driver. */ return okay; } #endif /* AMIGA_VOLUME_LABELS */ #ifndef SFX # if 0 /* As far as I can tell, all the locales AmigaDOS 2.1 knows about all */ /* happen to use DF_MDY ordering, so there's no point in using this. */ /*************************/ /* Function dateformat() */ /*************************/ #include #ifdef AZTEC_C # include #endif int dateformat() { /*--------------------------------------------------------------------------- For those operating systems which support it, this function returns a value which tells how national convention says that numeric dates are displayed. Return values are DF_YMD, DF_DMY and DF_MDY (the meanings should be fairly obvious). ---------------------------------------------------------------------------*/ struct Library *LocaleBase; struct Locale *ll; int result = DF_MDY; /* the default */ if ((LocaleBase = OpenLibrary("locale.library", 0))) { if (ll = OpenLocale(NULL)) { uch *f = ll->loc_ShortDateFormat; /* In this string, %y|%Y is year, %b|%B|%h|%m is month, */ /* %d|%e is day day, and %D|%x is short for mo/da/yr. */ if (!strstr(f, "%D") && !strstr(f, "%x")) { uch *da, *mo, *yr; if (!(mo = strstr(f, "%b")) && !(mo = strstr(f, "%B")) && !(mo = strstr(f, "%h"))) mo = strstr(f, "%m"); if (!(da = strstr(f, "%d"))) da = strstr(f, "%e"); if (!(yr = strstr(f, "%y"))) yr = strstr(f, "%Y"); if (yr && yr < mo) result = DF_YMD; else if (da && da < mo) result = DF_DMY; } CloseLocale(ll); } CloseLibrary(LocaleBase); } return result; } # endif /* 0 */ /************************/ /* Function version() */ /************************/ /* NOTE: the following include depends upon the environment * variable $Workbench to be set correctly. (Set by *