📄 human68k.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*//*--------------------------------------------------------------------------- human68k.c Human68k-specific routines for use with Info-ZIP's UnZip 5.41 and later. Contains: do_wild() mapattr() mapname() checkdir() close_outfile() stamp_file() (TIMESTAMP only) version() main() (for UnZipSFX) ---------------------------------------------------------------------------*/#include <dirent.h>#include <string.h>#include <sys/dos.h>#include <sys/xunistd.h>#ifdef HAVE_TWONCALL_H#include <twoncall.h>#endif#define UNZIP_INTERNAL#include "unzip.h"#if defined (SFX) && defined (MAIN)#include <sys/xstart.h>int MAIN(int argc, char *argv[]);#endifstatic void map2fat(char *pathcomp, char *last_dot);static char *trunc_name(char *name, int maxlen);static int created_dir; /* used in mapname(), checkdir() */static int renamed_fullpath; /* ditto */static char multi_period, special_char;#ifndef SFX/**********************//* Function do_wild() *//**********************/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; if (!iswild(wildspec)) { strncpy(matchname, wildspec, FILNAMSIZ); matchname[FILNAMSIZ-1] = '\0'; have_dirname = FALSE; wild_dir = (DIR *)NULL; return matchname; } /* break the wildspec into a directory part and a wildcard filename */ if ((wildname = strrchr(wildspec, '/')) == NULL) { dirname = "."; dirnamelen = 1; have_dirname = FALSE; wildname = wildspec; } else { ++wildname; /* point at character after '/' */ dirnamelen = wildname - wildspec; if ((dirname = (char *)malloc(dirnamelen+1)) == NULL) { Info(slide, 1, ((char *)slide, "warning: cannot allocate wildcard buffers\n")); strcpy(matchname, wildspec); return matchname; /* but maybe filespec was not a wildcard */ } strncpy(dirname, wildspec, dirnamelen); dirname[dirnamelen] = '\0'; /* terminate for strcpy below */ have_dirname = TRUE; } Trace((stderr, "do_wild: dirname = [%s]\n", FnFilter1(dirname))); if ((wild_dir = opendir(dirname)) != (DIR *)NULL) { while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { Trace((stderr, "do_wild: readdir returns %s\n", FnFilter1(file->d_name))); if (file->d_name[0] == '.' && wildname[0] != '.') continue; /* Unix: '*' and '?' do not match leading dot */ if (match(file->d_name, wildname, 0 WISEP) && /* 0=case sens.*/ /* skip "." and ".." directory entries */ strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) { Trace((stderr, "do_wild: match() succeeds\n")); 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; }#ifdef DEBUG else { Trace((stderr, "do_wild: Opendir(%s) returns NULL\n", FnFilter1(dirname))); }#endif /* DEBUG */ /* 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) { Trace((stderr, "do_wild: readdir returns %s\n", FnFilter1(file->d_name))); if (file->d_name[0] == '.' && wildname[0] != '.') continue; /* Unix: '*' and '?' do not match leading dot */ if (match(file->d_name, wildname, 0 WISEP)) { /* 0 == case sens. */ Trace((stderr, "do_wild: match() succeeds\n")); 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 mapattr() *//**********************/int mapattr(__G) __GDEF{ ulg tmp = G.crec.external_file_attributes; switch (G.pInfo->hostnum) { case UNIX_: if (tmp & 0xff) break; /* fall through */ case VMS_: case ACORN_: case ATARI_: case ATHEOS_: case BEOS_: case QDOS_: G.pInfo->file_attr = _mode2dos(tmp >> 16); return 0; default: break; } /* set archive bit (file is not backed up) */ if((tmp & 0x08) == 0) tmp |= 0x20; G.pInfo->file_attr = tmp & 0xff; 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=(char *)NULL; /* character pointers */ char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */ char *last_dot=(char *)NULL; /* last dot */ int error = MPN_OK; register unsigned workch; /* hold the character being tested */#ifdef HAVE_TWONCALL_H static char twentyone_flag; /* Get TwentyOne options */ if (twentyone_flag == 0) { twentyone_flag++; if (GetTwentyOneID () == TWON_ID) { int flags = GetTwentyOneOptions (); if (flags & (1 << TWON_PERIOD_BIT)) multi_period = TRUE; if (flags & (1 << TWON_SPECIAL_BIT)) special_char = TRUE; } }#endif/*--------------------------------------------------------------------------- Initialize various pointers and counters and stuff. ---------------------------------------------------------------------------*/ /* 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 */ renamed_fullpath = FALSE; if (renamed) { cp = G.filename - 1; /* point to beginning of renamed name... */ while (*++cp) if (*cp == '\\') /* convert backslashes to forward */ *cp = '/'; cp = G.filename; if ((G.filename[0] == '/') || (isalpha(G.filename[0]) && G.filename[1] == ':')) { /* user gave full pathname: don't prepend rootpath */ renamed_fullpath = TRUE; } } if ((error = checkdir(__G__ (char *)NULL, INIT)) != 0) return error; /* 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) { if (_ismbblead((unsigned char)workch)) { if (*cp) { *pp++ = (char)workch; *pp++ = (char)*cp++; } else *pp++ = '_'; continue; } switch (workch) { case '/': /* can assume -j flag not given */ *pp = '\0'; map2fat(pathcomp, last_dot); /* 18.3 trunc. (in place) */ 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))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -