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

📄 os2.c

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 C
📖 第 1 页 / 共 5 页
字号:
  free(dirp);}struct direct *readdir(__GPRO__ DIR * dirp){  /* moved to os2data.h so it can be global */  /* static struct direct dp; */  if (dirp -> dd_cp == NULL)    return NULL;  G.os2.dp.d_namlen = G.os2.dp.d_reclen =    strlen(strcpy(G.os2.dp.d_name, dirp -> dd_cp -> _d_entry));  G.os2.dp.d_ino = 0;  G.os2.dp.d_size = dirp -> dd_cp -> _d_size;  G.os2.dp.d_mode = dirp -> dd_cp -> _d_mode;  G.os2.dp.d_time = dirp -> dd_cp -> _d_time;  G.os2.dp.d_date = dirp -> dd_cp -> _d_date;  dirp -> dd_cp = dirp -> dd_cp -> _d_next;  dirp -> dd_loc++;  return &G.os2.dp;}#if 0  /* not used in unzip; retained for possibly future use */void seekdir(DIR * dirp, long off){  long i = off;  struct _dircontents *dp;  if (off >= 0)  {    for (dp = dirp -> dd_contents; --i >= 0 && dp; dp = dp -> _d_next);    dirp -> dd_loc = off - (i + 1);    dirp -> dd_cp = dp;  }}long telldir(DIR * dirp){  return dirp -> dd_loc;}#endif /* 0 */static void free_dircontents(struct _dircontents * dp){  struct _dircontents *odp;  while (dp)  {    if (dp -> _d_entry)      free(dp -> _d_entry);    dp = (odp = dp) -> _d_next;    free(odp);  }}static char *getdirent(__GPRO__ ZCONST char *dir){  int done;  /* moved to os2data.h so it can be global */  /* static int lower; */  if (dir != NULL)  {                                    /* get first entry */    G.os2.hdir = HDIR_SYSTEM;    G.os2.count = 1;    done = DosFindFirst((PSZ) dir, &G.os2.hdir, attributes,                        &G.os2.find, sizeof(G.os2.find), &G.os2.count);    G.os2.lower = IsFileSystemFAT(__G__ dir);  }  else                                 /* get next entry */    done = DosFindNext(G.os2.hdir,                       &G.os2.find, sizeof(G.os2.find), &G.os2.count);  if (done == 0)  {    if ( G.os2.lower )      StringLower(G.os2.find.achName);    return G.os2.find.achName;  }  else  {    DosFindClose(G.os2.hdir);    return NULL;  }}int IsFileSystemFAT(__GPRO__ ZCONST char *dir)  /* FAT / HPFS detection */{  /* moved to os2data.h so they can be global */  /* static USHORT nLastDrive=(USHORT)(-1), nResult; */  ULONG lMap;  BYTE bData[64];  char bName[3];#ifdef __32BIT__  ULONG nDrive, cbData;  PFSQBUFFER2 pData = (PFSQBUFFER2) bData;#else  USHORT nDrive, cbData;  PFSQBUFFER pData = (PFSQBUFFER) bData;#endif    /* We separate FAT and HPFS+other file systems here.       at the moment I consider other systems to be similar to HPFS,       i.e. support long file names and case sensitive */    if ( isalpha((uch)dir[0]) && (dir[1] == ':') )      nDrive = toupper(dir[0]) - '@';    else      DosQueryCurrentDisk(&nDrive, &lMap);    if ( nDrive == G.os2.nLastDrive )      return G.os2.nResult;    bName[0] = (char) (nDrive + '@');    bName[1] = ':';    bName[2] = 0;    G.os2.nLastDrive = nDrive;    cbData = sizeof(bData);    if ( !DosQueryFSAttach(bName, 0, FSAIL_QUERYNAME, (PVOID) pData, &cbData) )      G.os2.nResult = !strcmp((char *) (pData -> szFSDName) + pData -> cbName,                              "FAT");    else      G.os2.nResult = FALSE;    /* End of this ugly code */    return G.os2.nResult;} /* end function IsFileSystemFAT() *//************************//*  Function do_wild()  *//************************/char *do_wild(__G__ wildspec)    __GDEF    ZCONST char *wildspec;  /* only used first time on a given dir */{  /* moved to os2data.h so they can be global */#if 0  static DIR *wild_dir = NULL;  static ZCONST char *wildname;  static char *dirname, matchname[FILNAMSIZ];  static int notfirstcall=FALSE, have_dirname, dirnamelen;#endif    char *fnamestart;    struct direct *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 (!G.os2.notfirstcall) {  /* first call:  must initialize everything */        G.os2.notfirstcall = TRUE;        if (!iswild(wildspec)) {            strncpy(G.os2.matchname, wildspec, FILNAMSIZ);            G.os2.matchname[FILNAMSIZ-1] = '\0';            G.os2.have_dirname = FALSE;            G.os2.wild_dir = NULL;            return G.os2.matchname;        }        /* break the wildspec into a directory part and a wildcard filename */        if ((G.os2.wildname = (ZCONST char *)strrchr(wildspec, '/')) == NULL &&            (G.os2.wildname = (ZCONST char *)strrchr(wildspec, ':')) == NULL) {            G.os2.dirname = ".";            G.os2.dirnamelen = 1;            G.os2.have_dirname = FALSE;            G.os2.wildname = wildspec;        } else {            ++G.os2.wildname;     /* point at character after '/' or ':' */            G.os2.dirnamelen = G.os2.wildname - wildspec;            if ((G.os2.dirname = (char *)malloc(G.os2.dirnamelen+1)) == NULL) {                Info(slide, 1, ((char *)slide,                  LoadFarString(CantAllocateWildcard)));                strncpy(G.os2.matchname, wildspec, FILNAMSIZ);                G.os2.matchname[FILNAMSIZ-1] = '\0';                return G.os2.matchname;   /* but maybe filespec was not a wildcard */            }            strncpy(G.os2.dirname, wildspec, G.os2.dirnamelen);            G.os2.dirname[G.os2.dirnamelen] = '\0';   /* terminate for strcpy below */            G.os2.have_dirname = TRUE;        }        Trace((stderr, "do_wild:  dirname = [%s]\n",          FnFilter1(G.os2.dirname)));        if ((G.os2.wild_dir = opendir(__G__ G.os2.dirname)) != NULL) {            if (G.os2.have_dirname) {                strcpy(G.os2.matchname, G.os2.dirname);                fnamestart = G.os2.matchname + G.os2.dirnamelen;            } else                fnamestart = G.os2.matchname;            while ((file = readdir(__G__ G.os2.wild_dir)) != 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, G.os2.wildname, 1 WISEP) &&                                                      /* 1 == ignore case */                    /* skip "." and ".." directory entries */                    strcmp(fnamestart, ".") && strcmp(fnamestart, "..")) {                    Trace((stderr, "do_wild:  match() succeeds\n"));                    /* remove trailing dot */                    fnamestart += strlen(fnamestart) - 1;                    if (*fnamestart == '.')                        *fnamestart = '\0';                    return G.os2.matchname;                }            }            /* if we get to here directory is exhausted, so close it */            closedir(G.os2.wild_dir);            G.os2.wild_dir = NULL;        }#ifdef DEBUG        else {            Trace((stderr, "do_wild:  opendir(%s) returns NULL\n",              FnFilter1(G.os2.dirname)));        }#endif /* DEBUG */        /* return the raw wildspec in case that works (e.g., directory not         * searchable, but filespec was not wild and file is readable) */        strncpy(G.os2.matchname, wildspec, FILNAMSIZ);        G.os2.matchname[FILNAMSIZ-1] = '\0';        return G.os2.matchname;    }    /* last time through, might have failed opendir but returned raw wildspec */    if (G.os2.wild_dir == NULL) {        G.os2.notfirstcall = FALSE;  /* nothing left to try--reset */        if (G.os2.have_dirname)            free(G.os2.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.     */    if (G.os2.have_dirname) {        /* strcpy(G.os2.matchname, G.os2.dirname); */        fnamestart = G.os2.matchname + G.os2.dirnamelen;    } else        fnamestart = G.os2.matchname;    while ((file = readdir(__G__ G.os2.wild_dir)) != 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, G.os2.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 G.os2.matchname;        }    }    closedir(G.os2.wild_dir);   /* have read at least one entry; nothing left */    G.os2.wild_dir = NULL;    G.os2.notfirstcall = FALSE; /* reset for new wildspec */    if (G.os2.have_dirname)        free(G.os2.dirname);    return (char *)NULL;} /* end function do_wild() */#endif /* !SFX *//* scan extra fields for something we happen to know */static int EvalExtraFields(__GPRO__ const char *path,                           void *extra_field, unsigned ef_len){  char *ef_ptr = extra_field;  PEFHEADER pEFblock;  int rc = PK_OK;  while (ef_len >= sizeof(EFHEADER))  {    pEFblock = (PEFHEADER) ef_ptr;    if (pEFblock -> nSize > (ef_len - EB_HEADSIZE))      return PK_ERR;            /* claimed EFblock length exceeds EF size! */    switch (pEFblock -> nID)    {    case EF_OS2:      rc = SetEAs(__G__ path, ef_ptr);      break;    case EF_ACL:      rc = (uO.X_flag) ? SetACL(__G__ path, ef_ptr) : PK_OK;      break;#if 0    case EF_IZUNIX:    case EF_PKUNIX:      /* handled elsewhere */      break;#endif    default:      TTrace((stderr,"EvalExtraFields: unknown extra field block, ID=%d\n",              pEFblock -> nID));      break;    }    ef_ptr += (pEFblock -> nSize + EB_HEADSIZE);    ef_len -= (pEFblock -> nSize + EB_HEADSIZE);    if (rc != PK_OK)      break;  }  return rc;}/************************//*  Function mapattr()  *//************************/int mapattr(__G)    __GDEF{    /* set archive bit (file is not backed up): */    G.pInfo->file_attr = (unsigned)(G.crec.external_file_attributes | 32) & 0xff;    return 0;}/************************//*  Function mapname()  *//************************//* * There are presently two possibilities in OS/2:  the output filesystem is * FAT, or it is HPFS.  If the former, we need to map to FAT, obviously, but * we *also* must map to HPFS and store that version of the name in extended * attributes.  Either way, we need to map to HPFS, so the main mapname * routine does that.  In the case that the output file system is FAT, an * extra filename-mapping routine is called in checkdir().  While it should * be possible to determine the filesystem immediately upon entry to mapname(), * it is conceivable that the DOS APPEND utility could be added to OS/2 some- * day, allowing a FAT directory to be APPENDed to an HPFS drive/path.  There- * fore we simply check the filesystem at each path component. * * Note that when alternative IFSes become available/popular, everything will * become immensely more complicated.  For example, a Minix filesystem would * have limited filename lengths like FAT but no extended attributes in which * to store the longer versions of the names.  A BSD Unix filesystem would * support paths of length 1024 bytes or more, but it is not clear that FAT * EAs would allow such long .LONGNAME fields or that OS/2 would properly * restore such fields when moving files from FAT to the new filesystem. * * GRR:  some or all of the following chars should be checked in either *       mapname (HPFS) or map2fat (FAT), depending:  ,=^+'"[]<>|\t& */int mapname(__G__ renamed)    __GDEF    int renamed;/*

⌨️ 快捷键说明

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