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

📄 os2.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 5 页
字号:
            case ';':             /* start of VMS version? */                lastsemi = pp;    /* remove VMS version later... */                *pp++ = ';';      /*  but keep semicolon for now */                break;            case '\026':          /* control-V quote for special chars */                quote = TRUE;     /* set flag for next character */                break;            case ' ':             /* keep spaces unless specifically */                if (uO.sflag)     /*  requested to change to underscore */                    *pp++ = '_';                else                    *pp++ = ' ';                break;            default:                /* allow ASCII 255 and European characters in filenames: */                if (isprint(workch) || workch >= 127)                    *pp++ = (char)workch;            } /* end switch */    } /* end while loop */    *pp = '\0';                   /* done with pathcomp:  terminate it */    /* if not saving them, remove VMS version numbers (appended "###") */    if (!uO.V_flag && lastsemi) {        pp = lastsemi + 1;        /* semi-colon was kept:  expect #s after */        while (isdigit((uch)(*pp)))            ++pp;        if (*pp == '\0')          /* only digits between ';' and end:  nuke */            *lastsemi = '\0';    }/*---------------------------------------------------------------------------    Report if directory was created (and no file to create:  filename ended    in '/'), check name to be sure it exists, and combine path and name be-    fore exiting.  ---------------------------------------------------------------------------*/    if (G.filename[G.os2.fnlen-1] == '/') {        checkdir(__G__ G.filename, GETPATH);        if (G.os2.created_dir) {            if (!uO.qflag)                Info(slide, 0, ((char *)slide, LoadFarString(Creating),                  G.filename));            if (G.extra_field) { /* zipfile extra field has extended attribs */                int err = EvalExtraFields(__G__ G.filename, G.extra_field,                                          G.lrec.extra_field_length);                if (err == IZ_EF_TRUNC) {                    if (uO.qflag)                        Info(slide, 1, ((char *)slide, "%-22s ", G.filename));                    Info(slide, 1, ((char *)slide, LoadFarString(TruncEAs),                      makeword(G.extra_field+2)-10, "\n"));                } else if (!uO.qflag)                    (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);            } else if (!uO.qflag)                (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);            /* set date/time stamps */            SetPathAttrTimes(__G__ G.pInfo->file_attr & ~A_ARCHIVE, 1);            return IZ_CREATED_DIR;   /* dir time already set */        } else if (G.extra_field && uO.overwrite_all) {            /* overwrite EAs of existing directory since user requested it */            int err = EvalExtraFields(__G__ G.filename, G.extra_field,                                      G.lrec.extra_field_length);            if (err == IZ_EF_TRUNC) {                Info(slide, 0x421, ((char *)slide, "%-22s ", G.filename));                Info(slide, 0x401, ((char *)slide, LoadFarString(TruncEAs),                  makeword(G.extra_field+2)-10, "\n"));            }            /* set date/time stamps (dirs only have creation times) */            SetPathAttrTimes(__G__ G.pInfo->file_attr & ~A_ARCHIVE, 1);        }        return 2;   /* dir existed already; don't look for data to extract */    }    if (*pathcomp == '\0') {        Info(slide, 1, ((char *)slide, LoadFarString(ConversionFailed),          G.filename));        return 3;    }    checkdir(__G__ pathcomp, APPEND_NAME);  /* returns 1 if truncated: care? */    checkdir(__G__ G.filename, GETPATH);    Trace((stderr, "mapname returns with filename = [%s] (error = %d)\n\n",      G.filename, error));    if (G.pInfo->vollabel) {    /* set the volume label now */        VOLUMELABEL FSInfoBuf;/* GRR:  "VOLUMELABEL" defined for IBM C and emx, but haven't checked MSC... */        strcpy(FSInfoBuf.szVolLabel, G.filename);        FSInfoBuf.cch = (BYTE)strlen(FSInfoBuf.szVolLabel);        if (!uO.qflag)            Info(slide, 0, ((char *)slide, LoadFarString(Labelling),              (char)(G.os2.nLabelDrive + 'a' - 1), G.filename));        if (DosSetFSInfo(G.os2.nLabelDrive, FSIL_VOLSER, (PBYTE)&FSInfoBuf,                         sizeof(VOLUMELABEL)))        {            Info(slide, 1, ((char *)slide, LoadFarString(ErrSetVolLabel)));            return 3;        }        return 2;   /* success:  skip the "extraction" quietly */    }    return error;} /* end function mapname() *//***********************//* Function checkdir() *//***********************/int checkdir(__G__ pathcomp, flag)    __GDEF    char *pathcomp;    int flag;/* * returns:  1 - (on APPEND_NAME) truncated filename *           2 - path doesn't exist, not allowed to create *           3 - path doesn't exist, tried to create and failed; or *               path exists and is not a directory, but is supposed to be *           4 - path is too long *          10 - can't allocate memory for filename buffers */{  /* moved to os2data.h so they can be global */#if 0    static int rootlen = 0;      /* length of rootpath */    static char *rootpath;       /* user's "extract-to" directory */    static char *buildpathHPFS;  /* full path (so far) to extracted file, */    static char *buildpathFAT;   /*  both HPFS/EA (main) and FAT versions */    static char *endHPFS;        /* corresponding pointers to end of */    static char *endFAT;         /*  buildpath ('\0') */#endif#   define FN_MASK   7#   define FUNCTION  (flag & FN_MASK)/*---------------------------------------------------------------------------    APPEND_DIR:  append the path component to the path being built and check    for its existence.  If doesn't exist and we are creating directories, do    so for this one; else signal success or error as appropriate.  ---------------------------------------------------------------------------*/    if (FUNCTION == APPEND_DIR) {        char *p = pathcomp;        int longdirEA, too_long=FALSE;        Trace((stderr, "appending dir segment [%s]\n", pathcomp));        while ((*G.os2.endHPFS = *p++) != '\0')     /* copy to HPFS filename */            ++G.os2.endHPFS;        if (IsFileNameValid(G.os2.buildpathHPFS)) {            longdirEA = FALSE;            p = pathcomp;            while ((*G.os2.endFAT = *p++) != '\0')  /* copy to FAT filename, too */                ++G.os2.endFAT;        } else {            longdirEA = TRUE;/* GRR:  check error return? */            map2fat(pathcomp, &G.os2.endFAT);  /* map, put in FAT fn, update endFAT */        }        /* GRR:  could do better check, see if overrunning buffer as we go:         * check endHPFS-G.os2.buildpathHPFS after each append, set warning variable         * if within 20 of FILNAMSIZ; then if var set, do careful check when         * appending.  Clear variable when begin new path. */        /* next check:  need to append '/', at least one-char name, '\0' */        if ((G.os2.endHPFS-G.os2.buildpathHPFS) > FILNAMSIZ-3)            too_long = TRUE;                 /* check if extracting dir? */#ifdef MSC /* MSC 6.00 bug:  stat(non-existent-dir) == 0 [exists!] */        if (GetFileTime(G.os2.buildpathFAT) == -1 || stat(G.os2.buildpathFAT, &G.statbuf))#else        if (stat(G.os2.buildpathFAT, &G.statbuf))    /* path doesn't exist */#endif        {            if (!G.create_dirs) { /* told not to create (freshening) */                free(G.os2.buildpathHPFS);                free(G.os2.buildpathFAT);                return 2;         /* path doesn't exist:  nothing to do */            }            if (too_long) {   /* GRR:  should allow FAT extraction w/o EAs */                Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),                  G.os2.buildpathHPFS));                free(G.os2.buildpathHPFS);                free(G.os2.buildpathFAT);                return 4;         /* no room for filenames:  fatal */            }            if (MKDIR(G.os2.buildpathFAT, 0777) == -1) {   /* create the directory */                Info(slide, 1, ((char *)slide, LoadFarString(CantCreateDir),                  G.os2.buildpathFAT, G.filename));                free(G.os2.buildpathHPFS);                free(G.os2.buildpathFAT);                return 3;      /* path didn't exist, tried to create, failed */            }            G.os2.created_dir = TRUE;            /* only set EA if creating directory *//* GRR:  need trailing '/' before function call? */            if (longdirEA) {#ifdef DEBUG                int e =#endif                  SetLongNameEA(G.os2.buildpathFAT, pathcomp);                Trace((stderr, "APPEND_DIR:  SetLongNameEA() returns %d\n", e));            }        } else if (!S_ISDIR(G.statbuf.st_mode)) {            Info(slide, 1, ((char *)slide, LoadFarString(DirIsntDirectory),              G.os2.buildpathFAT, G.filename));            free(G.os2.buildpathHPFS);            free(G.os2.buildpathFAT);            return 3;          /* path existed but wasn't dir */        }        if (too_long) {            Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),              G.os2.buildpathHPFS));            free(G.os2.buildpathHPFS);            free(G.os2.buildpathFAT);            return 4;         /* no room for filenames:  fatal */        }        *G.os2.endHPFS++ = '/';        *G.os2.endFAT++ = '/';        *G.os2.endHPFS = *G.os2.endFAT = '\0';        Trace((stderr, "buildpathHPFS now = [%s]\n", G.os2.buildpathHPFS));        Trace((stderr, "buildpathFAT now =  [%s]\n", G.os2.buildpathFAT));        return 0;    } /* end if (FUNCTION == APPEND_DIR) *//*---------------------------------------------------------------------------    GETPATH:  copy full FAT path to the string pointed at by pathcomp (want    filename to reflect name used on disk, not EAs; if full path is HPFS,    buildpathFAT and buildpathHPFS will be identical).  Also free both paths.  ---------------------------------------------------------------------------*/    if (FUNCTION == GETPATH) {        Trace((stderr, "getting and freeing FAT path [%s]\n", G.os2.buildpathFAT));        Trace((stderr, "freeing HPFS path [%s]\n", G.os2.buildpathHPFS));        strcpy(pathcomp, G.os2.buildpathFAT);        free(G.os2.buildpathFAT);        free(G.os2.buildpathHPFS);        G.os2.buildpathHPFS = G.os2.buildpathFAT = G.os2.endHPFS = G.os2.endFAT = (char *)NULL;        return 0;    }/*---------------------------------------------------------------------------    APPEND_NAME:  assume the path component is the filename; append it and    return without checking for existence.  ---------------------------------------------------------------------------*/    if (FUNCTION == APPEND_NAME) {        char *p = pathcomp;        int error = 0;        Trace((stderr, "appending filename [%s]\n", pathcomp));        while ((*G.os2.endHPFS = *p++) != '\0') {    /* copy to HPFS filename */            ++G.os2.endHPFS;            if ((G.os2.endHPFS-G.os2.buildpathHPFS) >= FILNAMSIZ) {                *--G.os2.endHPFS = '\0';                Info(slide, 1, ((char *)slide, LoadFarString(PathTooLongTrunc),                  G.filename, G.os2.buildpathHPFS));                error = 1;   /* filename truncated */            }        }/* GRR:  how can longnameEA ever be set before this point???  we don't want * to save the original name to EAs if user renamed it, do we? * * if (!G.os2.longnameEA && ((G.os2.longnameEA = !IsFileNameValid(name)) != 0)) */        if (G.pInfo->vollabel || IsFileNameValid(G.os2.buildpathHPFS)) {            G.os2.longnameEA = FALSE;            p = pathcomp;            while ((*G.os2.endFAT = *p++) != '\0')   /* copy to FAT filename, too */                ++G.os2.endFAT;        } else {            G.os2.longnameEA = TRUE;            if ((G.os2.lastpathcomp = (char *)malloc(strlen(pathcomp)+1)) ==                (char *)NULL)            {                Info(slide, 1, ((char *)slide,                 "checkdir warning:  cannot save longname EA: out of memory\n"));                G.os2.longnameEA = FALSE;                error = 1;   /* can't set .LONGNAME extended attribute */            } else           /* used and freed in close_outfile() */                strcpy(G.os2.lastpathcomp, pathcomp);            map2fat(pathcomp, &G.os2.endFAT);  /* map, put in FAT fn, update endFAT */        }        Trace((stderr, "buildpathHPFS: %s\nbuildpathFAT:  %s\n",          G.os2.buildpathHPFS, G.os2.buildpathFAT));        return error;  /* could check for existence, prompt for new name... */    } /* end if (FUNCTION == APPEND_NAME) *//*---------------------------------------------------------------------------    INIT:  allocate and initialize buffer space for the file currently being    extracted.  If file was renamed with an absolute path, don't prepend the    extract-to path.  ---------------------------------------------------------------------------*/    if (FUNCTION == INIT) {        Trace((stderr, "initializing buildpathHPFS and buildpathFAT to "));        if ((G.os2.buildpathHPFS = (char *)malloc(G.os2.fnlen+G.os2.rootlen+1)) == (char *)NULL)            return 10;        if ((G.os2.buildpathFAT = (char *)malloc(G.os2.fnlen+G.os2.rootlen+1)) == (char *)NULL) {            free(G.os2.buildpathHPFS);            return 10;        }        if (G.pInfo->vollabel) {  /* use root or renamed path, but don't store *//* GRR:  for network drives, do strchr() and return IZ_VOL_LABEL if not [1] */            if (G.os2.renamed_fullpath && pathcomp[1] == ':')                *G.os2.buildpathHPFS = (char)ToLower(*pathcomp);            else if (!G.os2.renamed_fullpath && G.os2.rootlen > 1 && G.os2.rootpath[1] == ':')                *G.os2.buildpathHPFS = (char)ToLower(*G.os2.rootpath);            else {                ULONG lMap;                DosQueryCurrentDisk(&G.os2.nLabelDrive, &lMap);                *G.os2.buildpathHPFS = (char)(G.os2.nLabelDrive - 1 + 'a');            }            G.os2.nLabelDrive = *G.os2.buildpathHPFS - 'a' + 1; /* save for mapname() */            if (uO.volflag == 0 || *G.os2.buildpathHPFS < 'a' ||  /* no labels/bogus? */                (uO.volflag == 1 && !isfloppy(G.os2.nLabelDrive))) { /* -$:  no fixed */                free(G.os2.buildpathHPFS);                free(G.os2.buildpathFAT);                return IZ_VOL_LABEL;   /* skipping with message */            }            *G.os2.buildpathHPFS = '\0';        } else if (G.os2.renamed_fullpath)   /* pathcomp = valid data */            strcpy(G.os2.buildpathHPFS, pathcomp);        else if (G.os2.rootlen > 0)            strcpy(G.os2.buildpathHPFS, G.os2.rootpath);        else            *G.os2.buildpathHPFS = '\0';        G.os2.endHPFS = G.os2.buildpathHPFS;        G.os2.endFAT = G.os2.buildpathFAT;        while ((*G.os2.endFAT = *G.os2.endHPFS) != '\0') {            ++G.os2.endFAT;            ++G.os2.endHPFS;        }        Trace((stderr, "[%s]\n", G.os2.buildpathHPFS));        return 0;    }/*---------------------------------------------------------------------------    ROOT:  if appropriate, store the path in rootpath and create it if neces-    sary; else assume it's a zipfile member and return.  This path segment    gets used in extracting all members from every zipfile specified on the    command line.  Note that under OS/2 and MS-DOS, if a candidate extract-to    directory specification includes a drive letter (leading "x:"), it is    treated just as if it had a trailing '/'--that is, one directory level    will be created if the path doesn't exist, unless this is otherwise pro-    hibited (e.g., freshening).  ---------------------------------------------------------------------------*/#if (!defined(SFX) || defined(SFX_EXDIR))    if (FUNCTION == ROOT) {        Trace((stderr, "initializing root path to [%s]\n", pathcomp));        if (pathcomp == (char *)NULL) {            G.os2.rootlen = 0;            return 0;        }        if ((G.os2.rootlen = strlen(pathcomp)) > 0) {            int had_trailing_pathsep=FALSE, has_drive=FALSE, xtra=2;            if (isalpha(pathcomp[0]) && pathcomp[1] == ':')                has_drive = TRUE;   /* drive designator */            if (pathcomp[G.os2.rootlen-1] == '/') {                pathcomp[--G.os2.rootlen] = '\0';                had_trailing_pathsep = TRUE;            }            if (has_drive && (G.os2.rootlen == 2)) {                if (!had_trailing_pathsep)   /* i.e., original wasn't "x:/" */                    xtra = 3;      /* room for '.' + '/' + 0 at end of "x:" */            } else if (G.os2.rootlen > 0) {     /* need not check "x:." and "x:/" */#ifdef MSC      /* MSC 6.00 bug:  stat(non-existent-dir) == 0 [exists!] */                if (GetFileTime(pathcomp) == -1 ||                    SSTAT(pathcomp, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))#else                if (SSTAT(pathcomp, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))#endif                {   /* path does not exist */                    if (!G.create_dirs                 /* || iswild(pathcomp) */                                       ) {                        G.os2.rootlen = 0;                        return 2;   /* treat as stored file */

⌨️ 快捷键说明

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