?? amiga.c
字號:
/* 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*//*------------------------------------------------------------------------ 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 */ strcpy(G.matchname, wildspec); return G.matchname; } /* break the wildspec into a directory part and a wildcard filename */ if ((G.wildname = (ZCONST char *)strrchr(wildspec, '/')) == 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")); strcpy(G.matchname, wildspec); 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)) { /* 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) */ strcpy(G.matchname, wildspec); 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)) { /* 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 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 (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 "../" pathcomp */ 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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -