📄 msdos.c
字号:
#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() *//************************/ /* 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 */#ifdef MAYBE_PLAIN_FAT char *last_dot=(char *)NULL; /* last dot not converted to underscore */ int dotname = FALSE; /* path component begins with dot? */# ifdef USE_LFN int use_lfn = USE_LFN; /* file system supports long filenames? */# endif#endif int error = 0; 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(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# ifdef USE_LFN if (!use_lfn)# endif { map2fat(pathcomp, last_dot); /* 8.3 trunc. (in place) */ last_dot = (char *)NULL; }#endif if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1) return error; pp = pathcomp; /* reset conversion buffer for next piece */ lastsemi = (char *)NULL; /* leave directory semi-colons alone */ break; /* 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;#ifdef MAYBE_PLAIN_FAT case '.':# ifdef USE_LFN if (use_lfn) { *pp++ = (char)workch; break; }# endif if (pp == pathcomp) { /* nothing appended yet... */ if (*cp == '/') { /* don't bother appending a "./" */ ++cp; /* component to the path: skip */ break; /* to next char after the '/' */ } else if (*cp == '.' && cp[1] == '/') { /* "../" */ *pp++ = '.'; /* add first dot, unchanged... */ ++cp; /* skip second dot, since it will */ } else { /* be "added" at end of if-block */ *pp++ = '_'; /* FAT doesn't allow null filename */ dotname = TRUE; /* bodies, so map .exrc -> _.exrc */ } /* (extra '_' now, "dot" below) */ } else if (dotname) { /* found a second dot, but still */ dotname = FALSE; /* have extra leading underscore: */ *pp = '\0'; /* remove it by shifting chars */ pp = pathcomp + 1; /* left one space (e.g., .p1.p2: */ while (pp[1]) { /* __p1 -> _p1_p2 -> _p1.p2 when */ *pp = pp[1]; /* finished) [opt.: since first */ ++pp; /* two chars are same, can start */ } /* shifting at second position] */ } last_dot = pp; /* point at last dot so far... */ *pp++ = '_'; /* convert dot to underscore for now */ break;#endif /* MAYBE_PLAIN_FAT */ 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 */ *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'; } if (G.pInfo->vollabel) { if (strlen(pathcomp) > 11) pathcomp[11] = '\0'; }#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/*--------------------------------------------------------------------------- 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); return IZ_CREATED_DIR; /* set dir time (note trailing '/') */ } else if (uO.overwrite_all) { /* overwrite attributes of existing directory on user's request */ /* set file attributes: */ z_dos_chmod(__G__ G.filename, G.pInfo->file_attr); } return 2; /* dir existed already; don't look for data to extract */ } if (*pathcomp == '\0') { Info(slide, 1, ((char *)slide, LoadFarString(ConversionFailed), FnFilter1(G.filename))); return 3; } 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 3; } return 2; /* success: skip the "extraction" quietly */ } return error;} /* end function mapname() */#ifdef MAYBE_PLAIN_FAT/**********************//* Function map2fat() *//**********************/static void map2fat(pathcomp, last_dot) char *pathcomp, *last_dot;{ char *pEnd = pathcomp + strlen(pathcomp);/*--------------------------------------------------------------------------- Case 1: filename has no dot, so figure out if we should add one. Note that the algorithm does not try to get too fancy: if there are no dots already, the name either gets truncated at 8 characters or the last un- derscore is converted to a dot (only if more characters are saved that way). In no case is a dot inserted between existing characters. GRR: have problem if filename is volume label?? ---------------------------------------------------------------------------*/ if (last_dot == (char *)NULL) { /* no dots: check for underscores... */ char *plu = strrchr(pathcomp, '_'); /* pointer to last underscore */ if (plu == (char *)NULL) { /* no dots, no underscores: truncate at */ if (pEnd > pathcomp+8) /* 8 chars (could insert '.' and keep 11) */ *(pEnd = pathcomp+8) = '\0'; } else if (MIN(plu - pathcomp, 8) + MIN(pEnd - plu - 1, 3) > 8) { last_dot = plu; /* be lazy: drop through to next if-block */ } else if ((pEnd - pathcomp) > 8) /* more fits into just basename */ pathcomp[8] = '\0'; /* than if convert last underscore to dot */ /* else whole thing fits into 8 chars or less: no change */ }/*--------------------------------------------------------------------------- Case 2: filename has dot in it, so truncate first half at 8 chars (shift extension if necessary) and second half at three. ---------------------------------------------------------------------------*/ if (last_dot != (char *)NULL) { /* one dot (or two, in the case of */ *last_dot = '.'; /* "..") is OK: put it back in */ if ((last_dot - pathcomp) > 8) { char *p, *q; int i; p = last_dot; q = last_dot = pathcomp + 8; for (i = 0; (i < 4) && *p; ++i) /* too many chars in basename: */ *q++ = *p++; /* shift extension left and */ *q = '\0'; /* truncate/terminate it */ } else if ((pEnd - last_dot) > 4) last_dot[4] = '\0'; /* too many chars in extension */ /* else filename is fine as is: no change */ if ((last_dot - pathcomp) > 0 && last_dot[-1] == ' ') last_dot[-1] = '_'; /* NO blank in front of '.'! */ }} /* end function map2fat() */#endif /* MAYBE_PLAIN_FAT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -