📄 human68k.c
字号:
& MPN_MASK) > MPN_INF_TRUNC) return error; pp = pathcomp; /* reset conversion buffer for next piece */ lastsemi = (char *)NULL; /* leave direct. 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) */ case '[': /* these punctuation characters forbidden */ case ']': /* only on plain FAT file systems */ case '+': case ',': case '=': case '<': case '>': case '|': case '\"': case '\'': if (!special_char) workch = '_'; *pp++ = (char)workch; break; case '-': if (pp == pathcomp && !special_char) workch = '_'; *pp++ = (char)workch; break; case ':': case '\\': case '*': case '?': *pp++ = '_'; break; case ';': /* VMS version (or DEC-20 attrib?) */ lastsemi = pp; if (!special_char) workch = '_'; *pp++ = (char)workch; /* keep for now; remove VMS ";##" */ break; /* later, if requested */ case ' ': /* change spaces to underscores */#if 0 /* do it always */ if (uO.sflag) /* only if requested */#endif workch = '_'; *pp++ = (char)workch; break; default: /* allow European characters in filenames: */ if (isprint(workch) || workch >= 128) *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, "warning: skipped \"../\" path component(s) in %s\n", 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, " creating: %s\n", FnFilter1(G.filename))); } /* set dir time (note trailing '/') */ return (error & ~MPN_MASK) | MPN_CREATED_DIR; } /* 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) { pp = lastsemi + 1; while (isdigit((uch)(*pp))) ++pp; if (*pp == '\0') /* only digits between ';' and end: nuke */ *lastsemi = '\0'; } map2fat(pathcomp, last_dot); /* 18.3 truncation (in place) */ if (*pathcomp == '\0') { Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n", 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 */ int fd; if (QCOND2) Info(slide, 0, ((char *)slide, " labelling: %s\n", FnFilter1(G.filename))); if ((fd = _dos_newfile(G.filename, G.pInfo->file_attr)) < 0) { Info(slide, 1, ((char *)slide, "mapname: error setting volume label\n")); return (error & ~MPN_MASK) | MPN_ERR_SKIP; } _dos_close(fd); /* success: skip the "extraction" quietly */ return (error & ~MPN_MASK) | MPN_INF_SKIP; } return error;} /* end function mapname() *//**********************//* Function map2fat() *//**********************/static void map2fat(pathcomp, last_dot) char *pathcomp, *last_dot;{ char *np; if (pathcomp == last_dot) { /* dotfile(e.g. ".foo") */ pathcomp = last_dot; last_dot = (char *)NULL; } if (multi_period) { if (strlen(pathcomp) <= 18) return; } else { char *p; for (p = pathcomp; *p; p++) if (*p == (char)'.' && p != last_dot) *p = '_'; } if (last_dot) { *last_dot++ = '\0'; trunc_name(last_dot, 3); } np = trunc_name(pathcomp, 18); if (last_dot) { *--last_dot = '.'; if (np) strcpy(np, last_dot); }} /* end function map2fat() */static char *trunc_name(char *name, int maxlen){ if (strlen(name) <= maxlen) return (char *)NULL; do { if (_ismbblead((unsigned char)*name)) { if (--maxlen == 0) break; name++; } name++; maxlen--; } while (maxlen > 0); *name = '\0'; return name;}/***********************//* Function checkdir() *//***********************/int checkdir(__G__ pathcomp, flag) __GDEF char *pathcomp; int flag;/* * returns: * MPN_OK - no problem detected * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename * MPN_INF_SKIP - path doesn't exist, not allowed to create * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path * exists and is not a directory, but is supposed to be * MPN_ERR_TOOLONG - path is too long * MPN_NOMEM - can't allocate memory for filename buffers */{ static int rootlen = 0; /* length of rootpath */ static char *rootpath; /* user's "extract-to" directory */ static char *buildpath; /* full path (so far) to extracted file */ static char *end; /* pointer to end of buildpath ('\0') */# 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) { int too_long = FALSE; Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp))); while ((*end = *pathcomp++) != '\0') ++end; /* GRR: could do better check, see if overrunning buffer as we go: * check end-buildpath 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. */ if ((end-buildpath) > FILNAMSIZ-3) /* need '/', one-char name, '\0' */ too_long = TRUE; /* check if extracting directory? */ if (SSTAT(buildpath, &G.statbuf)) /* path doesn't exist */ { if (!G.create_dirs) { /* told not to create (freshening) */ free(buildpath); return MPN_INF_SKIP; /* path doesn't exist: nothing to do */ } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too long: %s\n", FnFilter1(buildpath))); free(buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } if (mkdir(buildpath, 0777) == -1) { /* create the directory */ Info(slide, 1, ((char *)slide, "checkdir error: cannot create %s\n\ unable to process %s.\n", FnFilter2(buildpath), FnFilter1(G.filename))); free(buildpath); /* path didn't exist, tried to create, failed */ return MPN_ERR_SKIP; } created_dir = TRUE; } else if (!S_ISDIR(G.statbuf.st_mode)) { Info(slide, 1, ((char *)slide, "checkdir error: %s exists but is not directory\n\ unable to process %s.\n", FnFilter2(buildpath), FnFilter1(G.filename))); free(buildpath); /* path existed but wasn't dir */ return MPN_ERR_SKIP; } if (too_long) { Info(slide, 1, ((char *)slide, "checkdir error: path too long: %s\n", FnFilter1(buildpath))); free(buildpath); /* no room for filenames: fatal */ return MPN_ERR_TOOLONG; } *end++ = '/'; *end = '\0'; Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath))); return MPN_OK; } /* end if (FUNCTION == APPEND_DIR) *//*--------------------------------------------------------------------------- GETPATH: copy full path to the string pointed at by pathcomp, and free buildpath. ---------------------------------------------------------------------------*/ if (FUNCTION == GETPATH) { strcpy(pathcomp, buildpath); Trace((stderr, "getting and freeing path [%s]\n", FnFilter1(pathcomp))); free(buildpath); buildpath = end = (char *)NULL; return MPN_OK; }/*--------------------------------------------------------------------------- APPEND_NAME: assume the path component is the filename; append it and return without checking for existence. ---------------------------------------------------------------------------*/ if (FUNCTION == APPEND_NAME) { Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp))); while ((*end = *pathcomp++) != '\0') { ++end; if ((end-buildpath) >= FILNAMSIZ) { *--end = '\0'; Info(slide, 1, ((char *)slide, "checkdir warning: path too long; truncating\n\ %s\n -> %s\n", FnFilter1(G.filename), FnFilter2(buildpath))); return MPN_INF_TRUNC; /* filename truncated */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -