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

📄 atari.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 2 页
字号:
      strcat( file_arg, "$" );           /* to get things like *.[ch] work */      if ((regptr = regcomp( file_arg )) == NULL)         return ZE_MEM;      strcpy( fullpath, "." );      myftw( recurse ? 99 : 1 );      free(regptr);   } else if (recurse) {      myftw( 99 );   } else      myftw( 1 ); /* ret = procname( fullpath, 0 ); */   return ret;}int procname(n, caseflag)char *n;                /* name to process */int caseflag;           /* true to force case-sensitive match *//* Process a name or sh expression to operate on (or exclude).  Return   an error code in the ZE_ class. */{  char *a;              /* path and name for recursion */  DIR *d;               /* directory stream from opendir() */  char *e;              /* pointer to name from readd() */  int m;                /* matched flag */  char *p;              /* path for recursion */  struct stat s;        /* result of stat() */  struct zlist far *z;  /* steps through zfiles list */  if (strcmp(n, "-") == 0)   /* if compressing stdin */    return newname(n, 0, caseflag);  else if (LSSTAT(n, &s))  {    /* Not a file or directory--search for shell expression in zip file */    p = ex2in(n, 0, (int *)NULL);       /* shouldn't affect matching chars */    m = 1;    for (z = zfiles; z != NULL; z = z->nxt) {      if (MATCH(p, z->iname, caseflag))      {        z->mark = pcount ? filter(z->zname, caseflag) : 1;        if (verbose)            fprintf(mesg, "zip diagnostic: %scluding %s\n",               z->mark ? "in" : "ex", z->name);        m = 0;      }    }    free((zvoid *)p);    return m ? ZE_MISS : ZE_OK;  }  /* Live name--use if file, recurse if directory */  for (p = n; *p; p++)          /* use / consistently */    if (*p == '\\')      *p = '/';  if (!S_ISDIR(s.st_mode))  {    /* add or remove name of file */    if ((m = newname(n, 0, caseflag)) != ZE_OK)      return m;  } else {    /* Add trailing / to the directory name */    if ((p = malloc(strlen(n)+2)) == NULL)      return ZE_MEM;    if (strcmp(n, ".") == 0) {      *p = '\0';  /* avoid "./" prefix and do not create zip entry */    } else {      strcpy(p, n);      a = p + strlen(p);      if (a[-1] != '/')        strcpy(a, "/");      if (dirnames && (m = newname(p, 1, caseflag)) != ZE_OK) {        free((zvoid *)p);        return m;      }    }    /* recurse into directory */    if (recurse && (d = opendir(n)) != NULL)    {      while ((e = readd(d)) != NULL) {        if (strcmp(e, ".") && strcmp(e, ".."))        {          if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)          {            closedir(d);            free((zvoid *)p);            return ZE_MEM;          }          strcat(strcpy(a, p), e);          if ((m = procname(a, caseflag)) != ZE_OK)   /* recurse on name */          {            if (m == ZE_MISS)              zipwarn("name not matched: ", a);            else              ziperr(m, a);          }          free((zvoid *)a);        }      }      closedir(d);    }    free((zvoid *)p);  } /* (s.st_mode & S_IFDIR) == 0) */  return ZE_OK;}char *ex2in(x, isdir, pdosflag)char *x;                /* external file name */int isdir;              /* input: x is a directory */int *pdosflag;          /* output: force MSDOS file attributes? *//* Convert the external file name to a zip file name, returning the malloc'ed   string or NULL if not enough memory. */{  char *n;              /* internal file name (malloc'ed) */  char *t, *p;          /* shortened name */  int dosflag;  dosflag = 0;  /* Find starting point in name before doing malloc */  t = *x && *(x + 1) == ':' ? x + 2 : x;  while (*t == '/' || *t == '\\')    t++;  /* Make changes, if any, to the copied name (leave original intact) */  for (n = t; *n; n++)    if (*n == '\\')      *n = '/';  if (!pathput)    t = last(t, PATH_END);  /* Malloc space for internal name and copy it */  if ((n = malloc(strlen(t) + 1)) == NULL)    return NULL;  strcpy(n, t);#if 0  if (p = strstr(t, " -> "))       /* shorten "link -> data" to "link" */    *p = '\0';#endif  if (dosify)    msname(n);  /* Returned malloc'ed name */  if (pdosflag)    *pdosflag = dosflag;  return n;}char *in2ex(n)char *n;                /* internal file name *//* Convert the zip file name to an external file name, returning the malloc'ed   string or NULL if not enough memory. */{  char *x;              /* external file name */  if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)      return NULL;  strcpy(x, n);  return x;}void stamp(f, d)char *f;                /* name of file to change */ulg d;                  /* dos-style time to change it to *//* Set last updated and accessed time of file f to the DOS time d. */{  struct utimbuf u;     /* argument for utime()  const ?? */  /* Convert DOS time to time_t format in u[0] and u[1] */  u.actime = u.modtime = dos2unixtime(d);  /* Set updated and accessed times of f */  utime(f, &u);}ulg filetime(f, a, n, t)char *f;                /* name of file to get info on */ulg *a;                 /* return value: file attributes */long *n;                /* return value: file size */iztimes *t;             /* return value: access, modific. and creation times *//* If file *f does not exist, return 0.  Else, return the file's last   modified date and time as an MSDOS date and time.  The date and   time is returned in a long with the date most significant to allow   unsigned integer comparison of absolute times.  Also, if a is not   a NULL pointer, store the file attributes there, with the high two   bytes being the Unix attributes, and the low byte being a mapping   of that to DOS attributes.  If n is not NULL, store the file size   there.  If t is not NULL, the file's access, modification and creation   times are stored there as UNIX time_t values.   If f is "-", use standard input as the file. If f is a device, return   a file size of -1 */{  struct stat s;        /* results of stat() */  char *name;  unsigned int len = strlen(f);  if (f == label) {    if (a != NULL)      *a = label_mode;    if (n != NULL)      *n = -2L; /* convention for a label name */    if (t != NULL)      t->atime = t->mtime = t->ctime = label_utim;    return label_time;  }  if ((name = malloc(len + 1)) == NULL) {    ZIPERR(ZE_MEM, "filetime");  }  strcpy(name, f);  if (name[len - 1] == '/')    name[len - 1] = '\0';  /* not all systems allow stat'ing a file with / appended */  if (strcmp(f, "-") == 0) {    if (fstat(fileno(stdin), &s) != 0) {      free(name);      error("fstat(stdin)");    }  } else if (LSSTAT(name, &s) != 0) {             /* Accept about any file kind including directories              * (stored with trailing / with -r option)              */    free(name);    return 0;  }  if (a != NULL) {/*  *a = ((ulg)s.st_mode << 16) | (ulg)GetFileMode(name); */    *a = ((ulg)s.st_mode << 16) | (ulg)s.st_attr;  }  if (n != NULL)    *n = S_ISREG(s.st_mode) ? s.st_size : -1L;  if (t != NULL) {    t->atime = s.st_atime;    t->mtime = s.st_mtime;    t->ctime = s.st_ctime;  }  free(name);  return unix2dostime(&s.st_mtime);}int set_extra_field(z, z_utim)  struct zlist far *z;  iztimes *z_utim;  /* create extra field and change z->att if desired */{#ifdef USE_EF_UT_TIME#ifdef IZ_CHECK_TZ  if (!zp_tz_is_valid) return ZE_OK;    /* skip silently if no valid TZ info */#endif  if ((z->extra = (char *)malloc(EB_HEADSIZE+EB_UT_LEN(2))) == NULL)    return ZE_MEM;  if ((z->cextra = (char *)malloc(EB_HEADSIZE+EB_UT_LEN(1))) == NULL)    return ZE_MEM;  z->extra[0]  = 'U';  z->extra[1]  = 'T';  z->extra[2]  = EB_UT_LEN(2);          /* length of data part of e.f. */  z->extra[3]  = 0;  z->extra[4]  = EB_UT_FL_MTIME | EB_UT_FL_ATIME;  z->extra[5]  = (char)(z_utim->mtime);  z->extra[6]  = (char)(z_utim->mtime >> 8);  z->extra[7]  = (char)(z_utim->mtime >> 16);  z->extra[8]  = (char)(z_utim->mtime >> 24);  z->extra[9]  = (char)(z_utim->atime);  z->extra[10] = (char)(z_utim->atime >> 8);  z->extra[11] = (char)(z_utim->atime >> 16);  z->extra[12] = (char)(z_utim->atime >> 24);  z->ext = (EB_HEADSIZE+EB_UX_LEN(2));  memcpy(z->cextra, z->extra, (EB_HEADSIZE+EB_UT_LEN(1)));  z->cextra[EB_LEN] = EB_UT_LEN(1);  z->cext = (EB_HEADSIZE+EB_UX_LEN(1));  return ZE_OK;#else /* !USE_EF_UT_TIME */  return (int)(z-z);#endif /* ?USE_EF_UT_TIME */}int deletedir(d)char *d;                /* directory to delete *//* Delete the directory *d if it is empty, do nothing otherwise.   Return the result of rmdir(), delete(), or system().   For VMS, d must be in format [x.y]z.dir;1  (not [x.y.z]). */{    return rmdir(d);}#endif /* !UTIL *//******************************//*  Function version_local()  *//******************************/void version_local(){    static ZCONST char CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n";#ifdef __TURBOC__    char buf[40];#endif    printf(CompiledWith,#ifdef __GNUC__      "gcc ", __VERSION__,#else#  if 0      "cc ", (sprintf(buf, " version %d", _RELEASE), buf),#  else#  ifdef __TURBOC__      "Turbo C", (sprintf(buf, " (0x%04x = %d)", __TURBOC__, __TURBOC__), buf),#  else      "unknown compiler", "",#  endif#  endif#endif#ifdef __MINT__      "Atari TOS/MiNT",#else      "Atari TOS",#endif      " (Atari ST/TT/Falcon030)",#ifdef __DATE__      " on ", __DATE__#else      "", ""#endif      );} /* end function version_local() */

⌨️ 快捷键说明

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