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

📄 atari.c

📁 infozip2.2源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1990-1997 Mark Adler, Richard B. Wales, Jean-loup Gailly, Kai Uwe Rommel, Onno van der Linden and Igor Mandrichenko. Permission is granted to any individual or institution to use, copy, or redistribute this software so long as all of the original files are included, that it is not sold for profit, and that this copyright notice is retained.*/#include "zip.h"#ifndef UTIL    /* the companion #endif is a bit of ways down ... */#include <time.h>#include <errno.h>#include <dirent.h>#include <mintbind.h>#include <osbind.h>#include <ostruct.h>#define MATCH shmatch#define PAD 0#define PATH_END '/'extern char *label;     /* defined in fileio.c */local ulg label_time = 0;local ulg label_mode = 0;local time_t label_utim = 0;local char *readd(d)DIR *d;                 /* directory stream to read from *//* Return a pointer to the next name in the directory stream d, or NULL if   no more entries or an error occurs. */{  struct dirent *e;  e = readdir(d);  return e == NULL ? (char *) NULL : e->d_name;}local char *getVolumeLabel(drive, vtime, vmode, utim)  int drive;  /* drive name: 'A' .. 'Z' or '\0' for current drive */  ulg *vtime; /* volume label creation time (DOS format) */  ulg *vmode; /* volume label file mode */  time_t utim;/* volume label creation time (UNIX format) *//* If a volume label exists for the given drive, return its name and   set its time and mode. The returned name must be static data. */{  static char vol[14];  _DTA *dtaptr;  if (drive) {    vol[0] = (char)drive;    strcpy(vol+1, ":/");  } else {    strcpy(vol, "/");  }  strcat(vol, "*.*");  if (Fsfirst(vol, FA_LABEL) == 0) {    dtaptr = Fgetdta();    strncpy(vol, dtaptr->dta_name, sizeof(vol)-1);    *vtime = ((ulg)dtaptr->dta_date << 16) |             ((ulg)dtaptr->dta_time & 0xffff);    *vmode = (ulg)dtaptr->dta_attribute;    return vol;  }  return NULL;}char GetFileMode(char *name){   struct stat sb;   sb.st_attr = 0;   Fxattr(linkput ? 1 : 0, name, &sb);   if (errno == EINVAL) {      _DTA *dtaptr, *old;      old = Fgetdta();      Fsfirst(name, FA_RDONLY+FA_HIDDEN+FA_SYSTEM+FA_DIR);      dtaptr = Fgetdta();      sb.st_attr = dtaptr->dta_attribute;      Fsetdta(old);   }   return sb.st_attr & 0x3f;}int wild2(w)char *w;                /* path/pattern to match *//* If not in exclude mode, expand the pattern based on the contents of the   file system.  Return an error code in the ZE_ class. */{  DIR *d;               /* stream for reading directory */  char *e;              /* name found in directory */  int r;                /* temporary variable */  char *n;              /* constructed name from directory */  int f;                /* true if there was a match */  char *a;              /* alloc'ed space for name */  char *p;              /* path */  char *q;              /* name */  char v[5];            /* space for device current directory */  if (volume_label == 1) {    volume_label = 2;    label = getVolumeLabel(w[1] == ':' ? to_up(w[0]) : '\0',                           &label_time, &label_mode, &label_utim);    if (label != NULL) {       newname(label, 0);    }    if (w[1] == ':' && w[2] == '\0') return ZE_OK;    /* "zip -$ foo a:" can be used to force drive name */  }  /* special handling of stdin request */  if (strcmp(w, "-") == 0)   /* if compressing stdin */    return newname(w, 0);  /* Allocate and copy pattern */  if ((p = a = malloc(strlen(w) + 1)) == NULL)    return ZE_MEM;  strcpy(p, w);  /* Normalize path delimiter as '/'. */  for (q = p; *q; q++)                  /* use / consistently */    if (*q == '\\')      *q = '/';  /* Only name can have special matching characters */  if ((q = isshexp(p)) != NULL &&      (strrchr(q, '/') != NULL || strrchr(q, ':') != NULL))  {    free((zvoid *)a);    return ZE_PARMS;  }  /* Separate path and name into p and q */  if ((q = strrchr(p, '/')) != NULL && (q == p || q[-1] != ':'))  {    *q++ = '\0';                        /* path/name -> path, name */    if (*p == '\0')                     /* path is just / */      p = strcpy(v, "/.");  }  else if ((q = strrchr(p, ':')) != NULL)  {                                     /* has device and no or root path */    *q++ = '\0';    p = strcat(strcpy(v, p), ":");      /* copy device as path */    if (*q == '/')                      /* -> device:/., name */    {      strcat(p, "/");      q++;    }    strcat(p, ".");  }  else if (recurse && (strcmp(p, ".") == 0 ||  strcmp(p, "..") == 0))  {                                    /* current or parent directory */    /* I can't understand Mark's code so I am adding a hack here to get     * "zip -r foo ." to work. Allow the dubious "zip -r foo .." but     * reject "zip -rm foo ..".     */    if (dispose && strcmp(p, "..") == 0)       ziperr(ZE_PARMS, "cannot remove parent directory");    q = "*.*";  }  else                                  /* no path or device */  {    q = p;    p = strcpy(v, ".");  }  if (recurse && *q == '\0') {    q = "*.*";  }  /* Search that level for matching names */  if ((d = opendir(p)) == NULL)  {    free((zvoid *)a);    return ZE_MISS;  }  if ((r = strlen(p)) > 1 &&      (strcmp(p + r - 2, ":.") == 0 || strcmp(p + r - 2, "/.") == 0))    *(p + r - 1) = '\0';  f = 0;  while ((e = readd(d)) != NULL) {    if (strcmp(e, ".") && strcmp(e, "..") && MATCH(q, e))    {      f = 1;      if (strcmp(p, ".") == 0) {                /* path is . */        r = procname(e);                        /* name is name */        if (r) {           f = 0;           break;        }      } else      {        if ((n = malloc(strlen(p) + strlen(e) + 2)) == NULL)        {          free((zvoid *)a);          closedir(d);          return ZE_MEM;        }        n = strcpy(n, p);        if (n[r = strlen(n) - 1] != '/' && n[r] != ':')          strcat(n, "/");        r = procname(strcat(n, e));             /* name is path/name */        free((zvoid *)n);        if (r) {          f = 0;          break;        }      }    }  }  closedir(d);  /* Done */  free((zvoid *)a);  return f ? ZE_OK : ZE_MISS;}#include <regexp.h>#include <osbind.h>void regerror( char ZCONST *msg ) {   perror( msg );}static int    ret;static regexp *regptr;static short  is_w, ind_w;static char   fullpath[FILENAME_MAX], file_arg[FILENAME_MAX];#define FTW_F   0#define FTW_D   1#define FTW_DNR 2#define FTW_NS  3static int ftwfunc( struct stat *stats, int ftw_status ){   char *path = &fullpath[0];   if (strncmp(path, "./", 2) == 0) path += 2;   switch (ftw_status) {   case FTW_NS:      zipwarn("can't stat file: ", path);      ret = ZE_MISS;      return 0;   case FTW_F:      if (!is_w || regexec(regptr, path, 1)) {#if 0         char fn[FILENAME_MAX];         int  k;         if (S_ISLNK(stats->st_mode) &&             (k = readlink(path, fn, FILENAME_MAX)) > 0) {            int l = strlen(path);            fn[k] = '\0';            strcat(strcat(path, " -> "), fn);            ret = newname(path, 0); /* procname(path); */            path[l] = '\0';         } else#endif            ret = newname(path, 0); /* procname(path); */      }      return 0;   case FTW_DNR:      zipwarn("can't open directory: ", path);      ret = ZE_MISS;      return 0;   case FTW_D:      if (strcmp(path, ".") == 0) return 0;      if (is_w && ind_w > 0 && strncmp(path, file_arg, ind_w) != 0)         return 4;   }   return 0;}static int myftw( int depth ){   register DIR   *dirp;   struct dirent  *entp;   struct stat    stats;   register char  *p,*q;   register long  i;   if (LSSTAT(fullpath, &stats) < 0)      return ftwfunc(&stats, FTW_NS);   if (!S_ISDIR(stats.st_mode))      return ftwfunc(&stats, FTW_F);   if ((dirp = opendir(fullpath)) == NULL)      return ftwfunc(&stats, FTW_DNR);   if (i = ftwfunc(&stats, FTW_D)) {      closedir(dirp);      return (i == 4 ? 0 : (int)i);   }   i = strlen(fullpath);   p = &fullpath[i];   *p++ = '/'; *p = '\0';   if (dirnames && i > 1) {      q = (strncmp(fullpath, "./", 2) == 0 ? &fullpath[2] : &fullpath[0]);      ret = newname(q, 1);   }   i = 0;   while (depth > 0 && (entp = readdir(dirp)) != 0)      if (strcmp(entp->d_name,".") != 0 && strcmp(entp->d_name,"..") != 0) {         strcpy(p, entp->d_name);         if (i = myftw(depth-1))            depth = 0;       /* force User's finish */      }   closedir(dirp);   return (int)i;}int wild( char *p ){   char *d;   ret = ZE_OK;   if (p == NULL) p = "*";   if (strcmp(p, "-") == 0)     /* if compressing stdin */      ret = newname(p, 0);   strcpy(fullpath, p);   /* now turning UNIX-Wildcards into basic regular expressions */   for (is_w = ind_w = 0, d = &file_arg[0]; *p; d++, p++)      switch (*p) {      case '*': *d++ = '.'; *d = *p; is_w = 1;  break;      case '?': *d = '.';            is_w = 1;  break;      case '[': *d = *p;

⌨️ 快捷键说明

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