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

📄 qdos.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 2 页
字号:
    int chid;    struct qdirect qd;    char *dp;    int e = ZE_MISS;    if (l == 0)    {        nc = 0;        *base = '\0';        if (isdirdev (dnam))        {            dp = dnam;            strncpy (ddev, dnam, 5);        }        else        {            char *p;            char temp[40];            getcwd (temp, 40);            llen = strlen(temp);            p = (temp + llen - 1);            if (*p != '_')            {                *p++ = '_';                *p = 0;            }            strncpy (ddev, temp, 5);            dp = base;            p = stpcpy (dp, temp);            strcpy (p, dnam);        }        {            char *q = isshexp (dp);            if(q)            {                strcpy (match, dp + 5);                if (q)                {                    while (q != dp && *q != '_')                    {                        q--;                    }                    *(++q) = '\0';                }            }            else            {                struct stat s;                if (stat(dp, &s) == 0)                {                    if (!(s.st_mode & S_IFDIR))                    {                        return procname(dp, 0);                    }                }                else                {                    return ZE_MISS;  /* woops, no wildcards! */                }            }        }    }    else    {        dp = dnam;    }    if ((chid = io_open (dp, 4L)) > 0)    {        int id = 0;        while (io_fstrg (chid, -1, &qd, 64) > 0)        {            short j;            if (qd.d_szname)            {                if (CHECKDIR(qd))                {                    if(dorecurse)                    {                        char fnam[256], *p;                        p = stpcpy (fnam, ddev);                        strncpy (p, qd.d_name, qd.d_szname);                        *(p + qd.d_szname) = 0;                        e = qlwild (fnam, dorecurse, l+1);                    }                    else                    {                        continue;                    }                }                else                {                    char nam[48];                    strcpy(nam, ddev);                    strncpy (nam + 5, qd.d_name, qd.d_szname);                    *(nam + 5 + qd.d_szname) = 0;                    if (MATCH (match, nam + 5, 0) == 1)                    {                        if(dirnames && l && id == 0)                        {                            id = 1;                            if((e = add_dir(dp)) != ZE_OK)                            {                                return e;                            }                        }                        if((e = procname(nam, 0)) == ZE_OK)                        {                            nc++;                        }                    }                }            }        }        io_close (chid);    }    if (l == 0)    {        *ddev = 0;        *match = 0;        e = (nc) ? ZE_OK : ZE_MISS;    }    return e;}int wild(char *p){    return qlwild(p, recurse, 0);}# endif /* !UTIL *//* * Return QDOS error, 0 if exec 1 if found but not exe or rel */int qlstat(char *name, struct qdirect *qs, char *flag){    int r;    r = qstat(name, qs);    if(r == 0)    {        if(qs->d_type == 0)        {            r = 1;        }        else if(CHECKDIR(*qs))        {            r = 255;        }    }    return r;}#else /* !QDOS */long rev_long (ulg l){    uch cc[4];    cc[0] = (uch)(l >> 24);    cc[1] = (uch)((l >> 16) & 0xff);    cc[2] = (uch)((l >> 8) & 0xff);    cc[3] = (uch)(l & 0xff);    return *(ulg *)cc;}short rev_short (ush s){    uch cc[2];    cc[0] = (uch)((s >> 8) & 0xff);    cc[1] = (uch)(s & 0xff);    return *(ush *)cc;}#define O_BINARY 0int qlstat(char *name, struct qdirect *qs, char *flag){    int r = -1;    int n, fd;    struct stat s;    struct _ntc_    {        long id;        long dlen;    } ntc;    *flag = 0;    if((fd = open(name, O_RDONLY | O_BINARY)) > 0)    {        short nl;        fstat(fd, &s);        lseek(fd, -8, SEEK_END);        read(fd, &ntc, 8);        qs->d_length = rev_long(s.st_size);        qs->d_update = rev_long(s.st_ctime + 283996800);        nl = strlen(name);        if(nl > QDOS_FLMAX)        {            nl = QDOS_FLMAX;            *flag = 1;        }        qs->d_szname = rev_short(nl);        memcpy(qs->d_name, name, nl);        if(ntc.id == *(long *)"XTcc")        {            qs->d_datalen = ntc.dlen;    /* This is big endian */            qs->d_type = 1;            r = 0;        }        else        {            qs->d_type = 0;            qs->d_datalen = 0;            r = 1;        }        close(fd);        return r;    }    else    {        fprintf(stderr, "Fails %d\n", fd);        return r;    }}#endif /* ?QDOS */#ifdef USE_EF_UT_TIME#define EB_L_UT_SIZE    (EB_HEADSIZE + eb_l_ut_len)#define EB_C_UT_SIZE    (EB_HEADSIZE + eb_c_ut_len)#ifdef UNIX#define EB_L_UX2_SIZE     (EB_HEADSIZE + EB_UX2_MINLEN)#define EB_C_UX2_SIZE     EB_HEADSIZE#define EF_L_UT_UX2_SIZE  (EB_L_UT_SIZE + EB_L_UX2_SIZE)#define EF_C_UT_UX2_SIZE  (EB_C_UT_SIZE + EB_C_UX2_SIZE)#else#define EF_L_UT_UX2_SIZE  EB_L_UT_SIZE#define EF_C_UT_UX2_SIZE  EB_C_UT_SIZE#endiflocal int GetExtraTime(struct zlist far *z, iztimes *z_utim, unsigned ut_flg){  char *eb_l_ptr;  char *eb_c_ptr;  char *eb_pt;  extent eb_l_ut_len = 0;  extent eb_c_ut_len = 0;#ifdef UNIX  struct stat s;  /* For the full sized UT local field including the UID/GID fields, we   * have to stat the file, again.  */  if (stat(z->name, &s))    return ZE_OPEN;  /* update times in z_utim, stat() call might have changed atime... */  z_utim->mtime = s.st_mtime;  z_utim->atime = s.st_atime;  z_utim->ctime = s.st_mtime;   /* best guess (st_ctime != creation time) */#endif /* UNIX */#ifdef IZ_CHECK_TZ  if (!zp_tz_is_valid)    ut_flg = 0;          /* disable UT e.f creation if no valid TZ info */#endif  if (ut_flg != 0) {    if (ut_flg & EB_UT_FL_MTIME)      eb_l_ut_len = eb_c_ut_len = 1;    if (ut_flg & EB_UT_FL_ATIME)      eb_l_ut_len++;    if (ut_flg & EB_UT_FL_CTIME)      eb_l_ut_len++;    eb_l_ut_len = EB_UT_LEN(eb_l_ut_len);    eb_c_ut_len = EB_UT_LEN(eb_c_ut_len);  }  if (EF_L_UT_UX2_SIZE > EB_HEADSIZE) {    if(z->ext)      eb_l_ptr = realloc(z->extra, (z->ext + EF_L_UT_UX2_SIZE));    else      eb_l_ptr = malloc(EF_L_UT_UX2_SIZE);    if (eb_l_ptr == NULL)      return ZE_MEM;    if(z->cext)      eb_c_ptr = realloc(z->cextra, (z->cext + EF_C_UT_UX2_SIZE));    else      eb_c_ptr = malloc(EF_C_UT_UX2_SIZE);    if (eb_c_ptr == NULL)      return ZE_MEM;    z->extra = eb_l_ptr;    eb_l_ptr += z->ext;    z->ext += EF_L_UT_UX2_SIZE;    if (ut_flg != 0) {      eb_l_ptr[0]  = 'U';      eb_l_ptr[1]  = 'T';      eb_l_ptr[2]  = eb_l_ut_len;       /* length of data part of e.f. */      eb_l_ptr[3]  = 0;      eb_l_ptr[4]  = ut_flg;      eb_pt = eb_l_ptr + 5;      if (ut_flg & EB_UT_FL_MTIME) {        *eb_pt++ = (char)(z_utim->mtime);        *eb_pt++ = (char)(z_utim->mtime >> 8);        *eb_pt++ = (char)(z_utim->mtime >> 16);        *eb_pt++ = (char)(z_utim->mtime >> 24);      }      if (ut_flg & EB_UT_FL_ATIME) {        *eb_pt++ = (char)(z_utim->atime);        *eb_pt++ = (char)(z_utim->atime >> 8);        *eb_pt++ = (char)(z_utim->atime >> 16);        *eb_pt++ = (char)(z_utim->atime >> 24);      }      if (ut_flg & EB_UT_FL_CTIME) {        *eb_pt++ = (char)(z_utim->ctime);        *eb_pt++ = (char)(z_utim->ctime >> 8);        *eb_pt++ = (char)(z_utim->ctime >> 16);        *eb_pt++ = (char)(z_utim->ctime >> 24);      }    }#ifdef UNIX    else {      eb_pt = eb_l_ptr;    }    *eb_pt++ = 'U';    *eb_pt++ = 'x';    *eb_pt++ = EB_UX2_MINLEN;            /* length of data part of local e.f. */    *eb_pt++  = 0;    *eb_pt++ = (char)(s.st_uid);    *eb_pt++ = (char)(s.st_uid >> 8);    *eb_pt++ = (char)(s.st_gid);    *eb_pt++ = (char)(s.st_gid >> 8);#endif /* UNIX */    z->cextra = eb_c_ptr;    eb_c_ptr += z->cext;    z->cext += EF_C_UT_UX2_SIZE;    if (ut_flg != 0) {      memcpy(eb_c_ptr, eb_l_ptr, EB_C_UT_SIZE);      eb_c_ptr[EB_LEN] = eb_c_ut_len;    }#ifdef UNIX    memcpy(eb_c_ptr+EB_C_UT_SIZE, eb_l_ptr+EB_L_UT_SIZE, EB_C_UX2_SIZE);    eb_c_ptr[EB_LEN+EB_C_UT_SIZE] = 0;#endif /* UNIX */  }  return ZE_OK;}#endif /* USE_EF_UT_TIME */int set_extra_field (struct zlist *z, iztimes *z_utim ){    int rv = 0;    int last_rv = 0;    char flag = 0;    if ((qlflag & 3) != 1)    {        qdosextra       *lq, *cq;        if ((lq = (qdosextra *) calloc(sizeof(qdosextra), 1)) == NULL)            return ZE_MEM;        if ((cq = (qdosextra *) calloc(sizeof(qdosextra), 1)) == NULL)            return ZE_MEM;        rv = qlstat(z->name, &(lq->header), &flag);        if (rv == 0 || (rv == 1 && (qlflag & 2)))        {            lq->shortid = rev_short((short) SHORTID);            lq->len.lo  = (unsigned char)(EXTRALEN & 0xff);            lq->len.hi  = (unsigned char)(EXTRALEN >> 8);            strcpy(lq->longid, LONGID);            memcpy(cq, lq, sizeof(qdosextra));            z->ext      =   sizeof(qdosextra);            z->cext     =   sizeof(qdosextra);            z->extra    =   (void *) lq;            z->cextra   =   (void *) cq;            fprintf (stderr, " %c",                     lq->header.d_datalen ? '*' : '#');        }        else if (rv == -1)        {            fprintf(stderr,                    "%s: warning: cannot stat %s, no file header added\n",                    "zip", z->name);        }        if(flag)        {            fputs (" !", stderr);        }     }    last_rv = (rv == -1 ? ZE_OPEN : ZE_OK);#ifdef USE_EF_UT_TIME# ifdef QDOS#   define IZ_UT_FLAGS EB_UT_FL_MTIME# endif# ifdef UNIX#   define IZ_UT_FLAGS (EB_UT_FL_MTIME | EB_UT_FL_ATIME)# endif# ifndef IZ_UT_FLAGS#   define IZ_UT_FLAGS EB_UT_FL_MTIME# endif    rv = GetExtraTime(z, z_utim, IZ_UT_FLAGS);    if (rv != ZE_OK)        last_rv = rv;#endif /* USE_EF_UT_TIME */    return last_rv;}

⌨️ 快捷键说明

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