📄 msdos.c
字号:
if (have_dirname) { /* strcpy(matchname, dirname); */ fnamestart = matchname + dirnamelen; } else fnamestart = matchname; while ((file = Readdir(wild_dir)) != (struct zdirent *)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 = (zDIR *)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 for file entries (file is not backed up): */ G.pInfo->file_attr = ((unsigned)G.crec.external_file_attributes | (G.crec.external_file_attributes & FSUBDIR ? 0 : 32)) & 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 */#ifdef MAYBE_PLAIN_FAT char *last_dot=(char *)NULL; /* last dot not converted to underscore */# ifdef USE_LFN int use_lfn = USE_LFN; /* file system supports long filenames? */# endif#endif int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */ int error = MPN_OK; register unsigned workch; /* hold the character being tested *//*--------------------------------------------------------------------------- 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. ---------------------------------------------------------------------------*/ while ((workch = (uch)*cp++) != 0) { switch (workch) { case '/': /* can assume -j flag not given */ *pp = '\0';#ifdef MAYBE_PLAIN_FAT maskDOSdevice(__G__ pathcomp, last_dot);#else maskDOSdevice(__G__ pathcomp, NULL);#endif#ifdef MAYBE_PLAIN_FAT# ifdef USE_LFN if (!use_lfn)# endif { map2fat(pathcomp, last_dot); /* 8.3 trunc. (in place) */ last_dot = (char *)NULL; }#endif 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)) & MPN_MASK) > MPN_INF_TRUNC) return error; pp = pathcomp; /* reset conversion buffer for next piece */ lastsemi = (char *)NULL; /* leave direct. semi-colons alone */ break;#ifdef MAYBE_PLAIN_FAT case '.':# ifdef USE_LFN if (use_lfn) { /* LFN filenames may contain many */ *pp++ = '.'; /* dots, so simply copy it ... */ } else# endif if (pp == pathcomp && *cp == '.' && cp[1] == '/') { /* nothing appended yet.., and found "../" */ *pp++ = '.'; /* add first dot, */ *pp++ = '.'; /* second dot, and */ ++cp; /* skip over to the '/' */ } else { /* found dot within path component */ last_dot = pp; /* point at last dot so far... */ *pp++ = '_'; /* convert to underscore for now */ } break;#endif /* MAYBE_PLAIN_FAT */ /* drive names are not stored in zipfile, so no colons allowed; * no brackets or most other punctuation either (all of which * can appear in Unix-created archives; backslash is particularly * bad unless all necessary directories exist) */#ifdef MAYBE_PLAIN_FAT case '[': /* these punctuation characters forbidden */ case ']': /* only on plain FAT file systems */ case '+': case ',': case '=':# ifdef USE_LFN if (use_lfn) *pp++ = (char)workch; else *pp++ = '_'; break;# endif#endif case ':': /* special shell characters of command.com */ case '\\': /* (device and directory limiters, wildcard */ case '"': /* characters, stdin/stdout redirection and */ case '<': /* pipe indicators and the quote sign) are */ case '>': /* never allowed in filenames on (V)FAT */ case '|': case '*': case '?': *pp++ = '_'; break; case ';': /* start of VMS version? */ lastsemi = pp;#ifdef MAYBE_PLAIN_FAT# ifdef USE_LFN if (use_lfn) *pp++ = ';'; /* keep for now; remove VMS ";##" later */# endif#else *pp++ = ';'; /* keep for now; remove VMS ";##" later */#endif break;#ifdef MAYBE_PLAIN_FAT case ' ': /* change spaces to underscores */# ifdef USE_LFN if (!use_lfn && uO.sflag) /* only if requested and NO lfn! */# else if (uO.sflag) /* only if requested */# endif *pp++ = '_'; else *pp++ = (char)workch; break;#endif /* MAYBE_PLAIN_FAT */ default: /* allow ASCII 255 and European characters in filenames: */ if (isprint(workch) || workch >= 127) *pp++ = (char)workch; } /* end switch */ } /* end while loop */ /* Show warning when stripping insecure "parent dir" path components */ if (killed_ddot && QCOND2) { Info(slide, 0, ((char *)slide, LoadFarString(WarnDirTraversSkip), FnFilter1(G.filename))); if (!(error & ~MPN_MASK)) error = (error & MPN_MASK) | PK_WARN; }/*--------------------------------------------------------------------------- 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[strlen(G.filename) - 1] == '/') { checkdir(__G__ G.filename, GETPATH); if (created_dir) { if (QCOND2) { Info(slide, 0, ((char *)slide, LoadFarString(Creating), FnFilter1(G.filename))); } /* set file attributes: */ z_dos_chmod(__G__ G.filename, G.pInfo->file_attr); /* set dir time (note trailing '/') */ return (error & ~MPN_MASK) | MPN_CREATED_DIR; } else if (IS_OVERWRT_ALL) { /* overwrite attributes of existing directory on user's request */ /* set file attributes: */ z_dos_chmod(__G__ G.filename, G.pInfo->file_attr); } /* dir existed already; don't look for data to extract */ return (error & ~MPN_MASK) | MPN_INF_SKIP; } *pp = '\0'; /* done with pathcomp: terminate it */ /* if not saving them, remove VMS version numbers (appended ";###") */ if (!uO.V_flag && lastsemi) {#ifndef MAYBE_PLAIN_FAT pp = lastsemi + 1;#else# ifdef USE_LFN if (use_lfn) pp = lastsemi + 1; else pp = lastsemi; /* semi-colon was omitted: expect all #'s */# else pp = lastsemi; /* semi-colon was omitted: expect all #'s */# endif#endif while (isdigit((uch)(*pp))) ++pp; if (*pp == '\0') /* only digits between ';' and end: nuke */ *lastsemi = '\0'; }#ifdef MAYBE_PLAIN_FAT maskDOSdevice(__G__ pathcomp, last_dot);#else maskDOSdevice(__G__ pathcomp, NULL);#endif if (G.pInfo->vollabel) { if (strlen(pathcomp) > 11) pathcomp[11] = '\0'; } else {#ifdef MAYBE_PLAIN_FAT# ifdef USE_LFN if (!use_lfn) map2fat(pathcomp, last_dot); /* 8.3 truncation (in place) */# else map2fat(pathcomp, last_dot); /* 8.3 truncation (in place) */# endif#endif } if (*pathcomp == '\0') { Info(slide, 1, ((char *)slide, LoadFarString(ConversionFailed), FnFilter1(G.filename))); return (error & ~MPN_MASK) | MPN_ERR_SKIP; } checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */ checkdir(__G__ G.filename, GETPATH); if (G.pInfo->vollabel) { /* set the volume label now */ if (QCOND2) Info(slide, 0, ((char *)slide, LoadFarString(Labelling), (nLabelDrive + 'a' - 1), FnFilter1(G.filename))); if (volumelabel(G.filename)) { Info(slide, 1, ((char *)slide, LoadFarString(ErrSetVolLabel))); return (error & ~MPN_MASK) | MPN_ERR_SKIP; } /* success: skip the "extraction" quietly */ return (error & ~MPN_MASK) | MPN_INF_SKIP; } return error;} /* end function mapname() *//****************************//* Function maskDOSdevice() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -