⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aosvs.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 3 页
字号:
/*---------------------------------------------------------------------------  aosvs.c  AOS/VS-specific routines for use with Info-ZIP's UnZip 5.2 and later.[GRR:  copied from unix.c -> undoubtedly has unnecessary stuff: delete at will]  Contains:  readdir()             do_wild()             open_outfile()             mapattr()             mapname()             checkdir()             screenlines()             close_outfile()             version()             <-- GRR:  needs work!  (Unix, not AOS/VS)             zvs_create()             zvs_credir()             ux_to_vs_name()             dgdate()  ---------------------------------------------------------------------------*/#define UNZIP_INTERNAL#include "unzip.h"#include "aosvs/aosvs.h"#include <packets/create.h>#include <sys_calls.h>#include <paru.h>#define symlink(resname,linkname) \  zvs_create(linkname,-1L,-1L,-1L,ux_to_vs_name(vs_resname,resname),$FLNK,-1,-1)                                             *  file type */#ifdef DIRENT#  include <dirent.h>#else#  ifdef SYSV#    ifdef SYSNDIR#      include <sys/ndir.h>#    else#      include <ndir.h>#    endif#  else /* !SYSV */#    ifndef NO_SYSDIR#      include <sys/dir.h>#    endif#  endif /* ?SYSV */#  ifndef dirent#    define dirent direct#  endif#endif /* ?DIRENT */static int            created_dir;          /* used in mapname(), checkdir() */static int            renamed_fullpath;     /* ditto */static ZEXTRAFLD      zzextrafld;           /* buffer for extra field containing                                             *  ?FSTAT packet & ACL buffer */static char           vs_resname[2*$MXPL];static char           vs_path[2*$MXPL];     /* buf for AOS/VS pathname */static char           Vs_path[512];         /* should be big enough [GRR: ?] */static P_CTIM         zztimeblock;          /* time block for file creation */static ZVSCREATE_STRU zzcreatepacket;       /* packet for sys_create(), any/***************************//* Strings used in aosvs.c *//***************************/static ZCONST char Far CannotDeleteOldFile[] =  "error:  cannot delete old %s\n";static ZCONST char Far CannotCreateFile[] = "error:  cannot create %s\n";#ifndef SFX#ifdef NO_DIR                  /* for AT&T 3B1 */#define opendir(path) fopen(path,"r")#define closedir(dir) fclose(dir)typedef FILE DIR;/* *  Apparently originally by Rich Salz. *  Cleaned up and modified by James W. Birdsall. */struct dirent *readdir(dirp)    DIR *dirp;{    static struct dirent entry;    if (dirp == NULL)        return NULL;    for (;;)        if (fread(&entry, sizeof (struct dirent), 1, dirp) == 0)            return (struct dirent *)NULL;        else if (entry.d_ino)            return &entry;} /* end function readdir() */#endif /* NO_DIR *//**********************//* Function do_wild() */   /* for porting:  dir separator; match(ignore_case) *//**********************/char *do_wild(__G__ wildspec)    __GDEF    char *wildspec;         /* only used first time on a given dir */{    static DIR *dir = (DIR *)NULL;    static char *dirname, *wildname, matchname[FILNAMSIZ];    static int firstcall=TRUE, 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 (firstcall) {        /* first call:  must initialize everything */        firstcall = FALSE;        if (!iswild(wildspec)) {            strcpy(matchname, wildspec);            have_dirname = FALSE;            dir = NULL;            return matchname;        }        /* break the wildspec into a directory part and a wildcard filename */        if ((wildname = strrchr(wildspec, '/')) == (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"));                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;        }        if ((dir = opendir(dirname)) != (DIR *)NULL) {            while ((file = readdir(dir)) != (struct dirent *)NULL) {                Trace((stderr, "do_wild:  readdir returns %s\n", 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) &&  /* 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(dir);            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) */        strcpy(matchname, wildspec);        return matchname;    }    /* last time through, might have failed opendir but returned raw wildspec */    if (dir == (DIR *)NULL) {        firstcall = TRUE;  /* 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(dir)) != (struct dirent *)NULL) {        Trace((stderr, "do_wild:  readdir returns %s\n", 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)) {   /* 0 == don't ignore case */            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(dir);     /* have read at least one dir entry; nothing left */    dir = (DIR *)NULL;    firstcall = TRUE;  /* 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{    int errc = 1;    /* init to show no success with AOS/VS info */    long dmm, ddd, dyy, dhh, dmin, dss;#ifdef DLL    if (G.redirect_data)        return redirect_outfile(__G)==FALSE;#endif    if (stat(G.filename, &G.statbuf) == 0 && unlink(G.filename) < 0) {        Info(slide, 0x401, ((char *)slide, LoadFarString(CannotDeleteOldFile),          G.filename));        return 1;    }/*---------------------------------------------------------------------------    If the file didn't already exist, we created it earlier.  But we just    deleted it, which we still had to do in case we are overwriting an exis-    ting file.  So we must create it now, again, to set the creation time    properly.  (The creation time is the best functional approximation of    the Unix mtime.  Really!)    If we stored this with an AOS/VS Zip that set the extra field to contain    the ?FSTAT packet and the ACL, we should use info from the ?FSTAT call    now.  Otherwise (or if that fails), we should create anyway as best we    can from the normal Zip info.    In theory, we should look through an entire series of extra fields that    might exist for the same file, but we're not going to bother.  If we set    up other types of extra fields, or if other environments we run into may    add their own stuff to existing entries in Zip files, we'll have to.    Note that all the packet types for sys_fstat() are the same size & mostly    have the same structure, with some fields being unused, etc.  Ditto for    sys_create().  Thus, we assume a normal one here, not a dir/cpd or device    or IPC file, & make little adjustments as necessary.  We will set ACLs    later (to reduce the chance of lacking access to what we create now); note    that for links the resolution name should be stored in the ACL field (once    we get Zip recognizing links OK).  ---------------------------------------------------------------------------*/    if (G.extra_field != NULL) {        memcpy((char *) &zzextrafld, G.extra_field, sizeof(zzextrafld));        if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,                    sizeof(zzextrafld.extra_header_id))  &&            !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel),                    sizeof(zzextrafld.extra_sentinel))        {            zzcreatepacket.norm_create_packet.cftyp_format =              zzextrafld.fstat_packet.norm_fstat_packet.styp_format;            zzcreatepacket.norm_create_packet.cftyp_entry =              zzextrafld.fstat_packet.norm_fstat_packet.styp_type;            /* for DIRS/CPDs, the next one will give the hash frame size; for             * IPCs it will give the port number */            zzcreatepacket.norm_create_packet.ccps =              zzextrafld.fstat_packet.norm_fstat_packet.scps;            zzcreatepacket.norm_create_packet.ctim = &zztimeblock;            zztimeblock.tcth = zzextrafld.fstat_packet.norm_fstat_packet.stch;            /* access & modification times default to current */            zztimeblock.tath.long_time = zztimeblock.tmth.long_time = -1;            /* give it current process's ACL unless link; then give it             * resolution name */            zzcreatepacket.norm_create_packet.cacp = (char *)(-1);            if (zzcreatepacket.norm_create_packet.cftyp_entry == $FLNK)                zzcreatepacket.norm_create_packet.cacp = zzextrafld.aclbuf;            zzcreatepacket.dir_create_packet.cmsh =              zzextrafld.fstat_packet.dir_fstat_packet.scsh;            if (zzcreatepacket.norm_create_packet.cftyp_entry != $FCPD) {                /* element size for normal files */                zzcreatepacket.norm_create_packet.cdel =                  zzextrafld.fstat_packet.norm_fstat_packet.sdeh;            }            zzcreatepacket.norm_create_packet.cmil =              zzextrafld.fstat_packet.norm_fstat_packet.smil;            if ((errc = sys_create(ux_to_vs_name(vs_path, G.filename),                 &zzcreatepacket)) != 0)                Info(slide, 0x201, ((char *)slide,                  "error creating %s with AOS/VS info -\n\                  will try again with ordinary Zip info\n", G.filename));        }    }    /* do it the hard way if no AOS/VS info was stored or if we had problems */    if (errc) {        dyy = (G.lrec.last_mod_dos_datetime >> 25) + 1980;        dmm = (G.lrec.last_mod_dos_datetime >> 21) & 0x0f;        ddd = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;        dhh = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;        dmin = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;        dss = (G.lrec.last_mod_dos_datetime << 1) & 0x3e;        if (zvs_create(G.filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) |            (dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1))        {            Info(slide, 0x201, ((char *)slide, "error: %s: cannot create\n",              G.filename));            return 1;        }    }    Trace((stderr, "open_outfile:  doing fopen(%s) for writing\n", G.filename));    if ((G.outfile = fopen(G.filename, FOPW)) == (FILE *)NULL) {        Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),          G.filename));        return 1;    }    Trace((stderr, "open_outfile:  fopen(%s) for writing succeeded\n",      G.filename));#ifdef USE_FWRITE#ifdef _IOFBF  /* make output fully buffered (works just about like write()) */    setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);#else    setbuf(G.outfile, (char *)slide);#endif#endif /* USE_FWRITE */    return 0;} /* end function open_outfile() *//**********************//* Function mapattr() *//**********************/int mapattr(__G)    __GDEF{    ulg tmp = G.crec.external_file_attributes;    switch (G.pInfo->hostnum) {        case UNIX_:        case VMS_:        case ACORN_:        case ATARI_:        case BEOS_:        case QDOS_:            G.pInfo->file_attr = (unsigned)(tmp >> 16);            return 0;        case AMIGA_:            tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */            G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);            break;        /* all remaining cases:  expand MSDOS read-only bit into write perms */        case FS_FAT_:        case FS_HPFS_:        case FS_NTFS_:        case MAC_:        case TOPS20_:        default:            tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */            G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);            break;    } /* end switch (host-OS-created-by) */    /* for originating systems with no concept of "group," "other," "system": */    umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */    G.pInfo->file_attr &= ~tmp;    return 0;} /* end function mapattr() *//************************//*  Function mapname()  *//************************/                             /* return 0 if no error, 1 if caution (filename */int mapname(__G__ renamed)   /*  truncated), 2 if warning (skip file because */    __GDEF                   /*  dir doesn't exist), 3 if error (skip file), */    int renamed;             /*  or 10 if out of memory (skip file) */{                            /*  [also IZ_VOL_LABEL, IZ_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 quote = FALSE;           /* flags */    int error = 0;    register unsigned workch;    /* hold the character being tested *//*---------------------------------------------------------------------------    Initialize various pointers and counters and stuff.  ---------------------------------------------------------------------------*/    if (G.pInfo->vollabel)        return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */    /* 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) == 10)        return 10;              /* 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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -