📄 flexos.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*//*--------------------------------------------------------------------------- flexos.c FlexOS-specific routines for use with Info-ZIP's UnZip 5.2 and later. Based upon the MSDOS version of this file (msdos/msdos.c) Contains: do_wild() mapattr() mapname() map2fat() checkdir() close_outfile() dateformat() version() _wildarg() ---------------------------------------------------------------------------*/#define UNZIP_INTERNAL#include "unzip.h"#include <flexif.h>/* The following should really be a static declaration, but the compiler complains (crappy compiler can't cope with a static forward declaration). */extern void map2fat OF((char *pathcomp, char *last_dot));static int created_dir; /* used by mapname(), checkdir() */static int renamed_fullpath; /* ditto *//*****************************//* Strings used in flexos.c *//*****************************/#ifndef SFX static ZCONST char Far CantAllocateWildcard[] = "warning: cannot allocate wildcard buffers\n";#endifstatic 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";#if (!defined(SFX) || defined(SFX_EXDIR)) static ZCONST char Far CantCreateExtractDir[] = "checkdir: cannot create extraction directory: %s\n";#endif#include <dirent.h>#ifndef SFX/************************//* Function do_wild() */ /* identical to OS/2 version *//************************/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; char *fnamestart; 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; dir = NULL; return matchname; } /* break the wildspec into a directory part and a wildcard filename */ if ((wildname = strrchr(wildspec, '/')) == (ZCONST char *)NULL && (wildname = strrchr(wildspec, ':')) == (ZCONST char *)NULL) { dirname = "."; dirnamelen = 1; have_dirname = FALSE; wildname = wildspec; } else { ++wildname; /* point at character after '/' or ':' */ dirnamelen = (int)(wildname - wildspec); if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) { Info(slide, 1, ((char *)slide, LoadFarString(CantAllocateWildcard))); strncpy(matchname, wildspec, FILNAMSIZ); matchname[FILNAMSIZ-1] = '\0'; return matchname; /* but maybe filespec was not a wildcard */ }/* GRR: cannot strip trailing char for opendir since might be "d:/" or "d:" * (would have to check for "./" at end--let opendir handle it instead) */ 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) { if (have_dirname) { strcpy(matchname, dirname); fnamestart = matchname + dirnamelen; } else fnamestart = matchname; while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { Trace((stderr, "do_wild: readdir returns %s\n", FnFilter1(file->d_name))); strcpy(fnamestart, file->d_name); if (strrchr(fnamestart, '.') == (char *)NULL) strcat(fnamestart, "."); if (match(fnamestart, wildname, 1 WISEP) && /* 1=ignore case */ /* skip "." and ".." directory entries */ strcmp(fnamestart, ".") && strcmp(fnamestart, "..")) { Trace((stderr, "do_wild: match() succeeds\n")); /* remove trailing dot */ fnamestart += strlen(fnamestart) - 1; if (*fnamestart == '.') *fnamestart = '\0'; 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. */ if (have_dirname) { /* strcpy(matchname, dirname); */ fnamestart = matchname + dirnamelen; } else fnamestart = matchname; while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { Trace((stderr, "do_wild: readdir returns %s\n", FnFilter1(file->d_name))); strcpy(fnamestart, file->d_name); if (strrchr(fnamestart, '.') == (char *)NULL) strcat(fnamestart, "."); if (match(fnamestart, wildname, 1 WISEP)) { /* 1 == ignore case */ Trace((stderr, "do_wild: match() succeeds\n")); /* remove trailing dot */ fnamestart += strlen(fnamestart) - 1; if (*fnamestart == '.') *fnamestart = '\0'; 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{ /* set archive bit (file is not backed up): */ G.pInfo->file_attr = (unsigned)(G.crec.external_file_attributes & 7) | 32; return 0;}/**********************//* 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 not converted to underscore */ int dotname = FALSE; /* path component begins with dot? */ int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */ int error = MPN_OK; register unsigned workch; /* hold the character being tested */ if (G.pInfo->vollabel) return MPN_VOL_LABEL; /* Cannot set disk volume labels in FlexOS *//*--------------------------------------------------------------------------- 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; /* use temporary rootpath if user gave full pathname */ if (G.filename[0] == '/') { renamed_fullpath = TRUE; pathcomp[0] = '/'; /* copy the '/' and terminate */ pathcomp[1] = '\0'; ++cp; } else if (isalpha((uch)G.filename[0]) && G.filename[1] == ':') { renamed_fullpath = TRUE; pp = pathcomp; *pp++ = *cp++; /* copy the "d:" (+ '/', possibly) */ *pp++ = *cp++; if (*cp == '/') *pp++ = *cp++; /* otherwise add "./"? */ *pp = '\0'; } } /* pathcomp is ignored unless renamed_fullpath is TRUE: */ if ((error = checkdir(__G__ pathcomp, INIT)) != 0) /* initialize path buf */ return error; /* ...unless no mem or vol label on hard disk */ *pathcomp = '\0'; /* initialize translation buffer */ pp = pathcomp; /* point to translation buffer */ if (!renamed) { /* cp already set if renamed */ 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -