📄 macos.c
字号:
/* 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*//*--------------------------------------------------------------------------- macos.c Macintosh-specific routines for use with Info-ZIP's UnZip 5.4 and later. Contains: do_wild () mapattr () checkdir () version () macmkdir () macopen () maccreat () macread () macwrite () macclose () maclseek () BuildMacFilename() SetFinderInfo () isMacOSexfield () makePPClong () makePPCword () PrintMacExtraInfo () GetExtraFieldData () DecodeMac3ExtraField () DecodeJLEEextraField () PrintTextEncoding () MacGlobalsInit () ---------------------------------------------------------------------------*//*****************************************************************************//* Includes *//*****************************************************************************/#define UNZIP_INTERNAL#include "unzip.h"#include <script.h>#include <sound.h>#include "pathname.h"#include "helpers.h"#include "macstuff.h"#include "mactime.h"#include "macbin3.h"/*****************************************************************************//* Macros, typedefs *//*****************************************************************************//* disable ZipIt support#define SwitchZIPITefSupportOff */#define read_only file_attr /* for readability only */#define EB_MAX_OF_VARDATA 1300 /* max possible datasize of extra-field */#ifdef WILD_STOP_AT_DIR# define WESEP , (oU.W_flag ? ':' : '\0')#else# define WESEP#endif/*****************************************************************************//* Global Vars *//*****************************************************************************//* Note: sizeof() returns the size of this allusion 13 is current length of "XtraStuf.mac:" */extern const char ResourceMark[13]; /* var is initialized in file pathname.c */Boolean MacUnzip_Noisy; /* MacUnzip_Noisy is also used by console */MACINFO newExtraField; /* contains all extra-field data */short MacZipMode;/*****************************************************************************//* Module level Vars *//*****************************************************************************/static const char MacPathEnd = ':'; /* the Macintosh dir separator */static int created_dir; /* used in mapname(), checkdir() */static int renamed_fullpath; /* ditto */static FSSpec CurrentFile;static Boolean OpenZipFile = true;static Boolean UseUT_ExtraField = false;static Boolean IgnoreEF_Macfilename = false;static short fileSystemID;static uch *attrbuff = NULL;static uch *malloced_attrbuff = NULL;const short HFS_fileSystem = 0;/*****************************************************************************//* Prototypes *//*****************************************************************************/extern char *GetUnZipInfoVersions(void);static OSErr SetFinderInfo(FSSpec *spec, MACINFO *mi);static Boolean GetExtraFieldData(short *MacZipMode, MACINFO *mi);static uch *scanMacOSexfield(uch *ef_ptr, unsigned ef_len, short *MacZipMode);static Boolean isMacOSexfield(unsigned id, unsigned size, short *MacZipMode);static void PrintMacExtraInfo(MACINFO *mi);static OSErr SetFileTime(void);static void DecodeMac3ExtraField(ZCONST uch *buff, MACINFO *mi);static void DecodeJLEEextraField(ZCONST uch *buff, MACINFO *mi);static void DecodeZPITextraField(ZCONST uch *buff, MACINFO *mi);static char *PrintTextEncoding(short script);static void BuildMacFilename(void);/*****************************************************************************//* Constants (strings, etc.) *//*****************************************************************************/static ZCONST char Far CannotCreateFile[] = "error: cannot create %s\n";static ZCONST char Far OutOfMemEF[] = "Can't allocate memory to uncompress"\ " file attributes.\n";static ZCONST char Far ErrUncmpEF[] = "Error uncompressing file attributes.\n";static ZCONST char Far No64Time[] = "Don't support 64 bit Timevalues; get "\ " a newer version of MacZip \n";static ZCONST char Far NoUniCode[] = "Don't support Unicoded Filenames; get"\ " a newer version of MacZip\n";static ZCONST char Far ZitIt_EF[] = "warning: found ZipIt extra field "\ " -> file is probably not "\ "usable!!\n";static ZCONST char Far CantAllocateWildcard[] = "warning: cannot allocate wildcard buffers\n";static ZCONST char Far ErrNoTimeSet[] = "error (%d): cannot set the time for"\ " %s\n";static ZCONST char Far MacBinaryMsg[] = "\n ... decoding MacBinary ";static ZCONST char Far WarnDirTraversSkip[] = "warning: skipped \"../\" path component(s) in %s\n";static ZCONST char Far Creating[] = " creating: %s\n";static ZCONST char Far ConversionFailed[] = "mapname: conversion of %s failed\n";static ZCONST char Far PathTooLong[] = "checkdir error: path too long: %s\n";static ZCONST char Far CantCreateDir[] = "checkdir error: cannot create %s\n\ unable to process %s.\n";static ZCONST char Far DirIsntDirectory[] = "checkdir error: %s exists but is not directory\n\ unable to process %s.\n";static ZCONST char Far PathTooLongTrunc[] = "checkdir warning: path too long; truncating\n %s\n\ -> %s\n";static ZCONST char Far CantCreateExtractDir[] = "checkdir: cannot create extraction directory: %s\n";static ZCONST char Far FilenameToLong[] = "Filename is to long; truncated: %s\n";/*****************************************************************************//* Functions *//*****************************************************************************/#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; static unsigned long 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; /* Folder names must always end with a colon */ if (uO.exdir[strlen(uO.exdir)-1] != ':') { strcat(uO.exdir, ":"); } MacUnzip_Noisy = !uO.qflag; if (MacUnzip_Noisy) printf("%s \n\n", GetUnZipInfoVersions()); /* 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, LoadFarString(CantAllocateWildcard))); 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 (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 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 open_outfile() *//***************************/int open_outfile(__G) /* return 1 if fail */ __GDEF{ short outfd, fDataFork = true;#ifdef DLL if (G.redirect_data) return (redirect_outfile(__G) == FALSE);#endif Trace((stderr, "open_outfile: trying to open (%s) for writing\n", FnFilter1(G.filename))); if (!uO.aflag) { /* unknown type documents */ /* all files are considered to be of type 'TEXT' and creator 'hscd' */ /* this is the default type for CDROM ISO-9660 without Apple extensions */ newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdType = 'TEXT'; newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdCreator = 'hscd'; } else { /* unknown text-files defaults to 'TEXT' */ newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdType = 'TEXT'; /* Bare Bones BBEdit */ newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdCreator = 'R*ch'; } BuildMacFilename(); if (MacZipMode <= TomBrownZipIt2_EF) { fDataFork = true; } else { fDataFork = (newExtraField.flags & EB_M3_FL_DATFRK) ? TRUE : FALSE; } if ((outfd = maccreat(G.filename)) != -1) { outfd = macopen(G.filename, (fDataFork) ? 1 : 2); } if (outfd == -1) { G.outfile = (FILE *)NULL; Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile), FnFilter1(G.filename))); return 1; } G.outfile = (FILE *)outfd; Trace((stderr, "open_outfile: successfully opened (%s) for writing\n", FnFilter1(G.filename))); return 0;} /* end function open_outfile() *//**********************//* Function mapattr() *//**********************/int mapattr(__G) __GDEF{ /* only care about read-only bit, so just look at MS-DOS side of attrs */ G.pInfo->read_only = (unsigned)(G.crec.external_file_attributes & 1); 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -