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

📄 fileio.c

📁 《汇编源代码大全》
💻 C
📖 第 1 页 / 共 5 页
字号:
/* whole is a pathname with wildcards, wildtail points somewhere in the  *//* middle of it.  All wildcards to be expanded must come AFTER wildtail. */local int wild_recurse(whole, wildtail) char *whole; char *wildtail;{    dstrm *dir;    char *subwild, *name, *newwhole = NULL, *glue = NULL, plug = 0, plug2;    ush newlen, amatch = 0;    BPTR lok;    int e = ZE_MISS;    if (!isshexp(wildtail))        if (lok = Lock(whole, ACCESS_READ)) {       /* p exists? */            UnLock(lok);            return procname(whole);        } else            return ZE_MISS;                     /* woops, no wildcards! */    /* back up thru path components till existing dir found */    do {        name = wildtail + strlen(wildtail) - 1;        for (;;)            if (name-- <= wildtail || *name == '/') {                subwild = name + 1;                plug2 = *subwild;                *subwild = 0;                break;            }        if (glue)            *glue = plug;        glue = subwild;        plug = plug2;        dir = opend(whole);    } while (!dir && !disk_not_mounted && subwild > wildtail);    wildtail = subwild;                 /* skip past non-wild components */    if (subwild = strchr(wildtail + 1, '/')) {        /* this "+ 1" dodges the  ^^^ hole left by *glue == 0 */        *(subwild++) = 0;               /* wildtail = one component pattern */        newlen = strlen(whole) + strlen(subwild) + 32;    } else        newlen = strlen(whole) + 31;    if (!dir || !(newwhole = malloc(newlen))) {        if (glue)            *glue = plug;        e = dir ? ZE_MEM : ZE_MISS;        goto ohforgetit;    }    strcpy(newwhole, whole);    newlen = strlen(newwhole);    if (glue)        *glue = plug;                           /* repair damage to whole */    if (!isshexp(wildtail)) {        e = ZE_MISS;                            /* non-wild name not found */        goto ohforgetit;    }    while (name = readd(dir)) {        if (MATCH(wildtail, name)) {            strcpy(newwhole + newlen, name);            if (subwild) {                name = newwhole + strlen(newwhole);                *(name++) = '/';                strcpy(name, subwild);                e = wild_recurse(newwhole, name);            } else                e = procname(newwhole);            newwhole[newlen] = 0;            if (e == ZE_OK)                amatch = 1;            else if (e != ZE_MISS)                break;        }    }  ohforgetit:    if (dir) closed(dir);    if (subwild) *--subwild = '/';    if (newwhole) free(newwhole);    if (e == ZE_MISS && amatch)        e = ZE_OK;    return e;}int wild(p) char *p;{    char *use;    /* wild_recurse() can't handle colons in wildcard part: */    if (use = strchr(p, ':')) {        if (strchr(++use, ':'))            return ZE_PARMS;    } else        use = p;    return wild_recurse(p, use);}#endif /* AMIGA */                                          #ifdef VMSint wild(p)char *p;                /* path/pattern to match *//* Expand the pattern based on the contents of the file system.  Return an   error code in the ZE_ class. */{  dstrm *d;             /* stream for reading directory */  char *e;              /* name found in directory */  int f;                /* true if there was a match */  /* Search given pattern for matching names */  if ((d = (dstrm *)malloc(sizeof(dstrm))) == NULL)    return ZE_MEM;  vms_wild(p, d);       /* pattern may be more than just directory name */  /*   * Save version specified by user to use in recursive drops into   * subdirectories.   */  strncpy(wild_version_part,d->nam.nam$l_ver,d->nam.nam$b_ver);  wild_version_part[d->nam.nam$b_ver] = 0;  f = 0;  while ((e = readd(d)) != NULL)        /* "dosmatch" is already built in */    if (procname(e) == ZE_OK)      f = 1;  closed(d);  /* Done */  return f ? ZE_OK : ZE_MISS;}#endif /* VMS */char *getnam(n)char *n;                /* where to put name (must have >=FNMAX+1 bytes) *//* Read a space, \n, \r, or \t delimited name from stdin into n, and return   n.  If EOF, then return NULL.  Also, if the name read is too big, return   NULL. */{  int c;                /* last character read */  char *p;              /* pointer into name area */  p = n;  while ((c = getchar()) == ' ' || c == '\n' || c == '\r' || c == '\t')    ;  if (c == EOF)    return NULL;  do {    if (p - n >= FNMAX)      return NULL;    *p++ = (char)c;    c = getchar();  } while (c != EOF && c != ' ' && c != '\n' && c != '\r' && c != '\t');  *p = 0;  return n;}struct flist far *fexpel(f)struct flist far *f;    /* entry to delete *//* Delete the entry *f in the doubly-linked found list.  Return pointer to   next entry to allow stepping through list. */{  struct flist far *t;  /* temporary variable */  t = f->nxt;  *(f->lst) = t;                        /* point last to next, */  if (t != NULL)    t->lst = f->lst;                    /* and next to last */  if (f->name != NULL)                  /* free memory used */    free((voidp *)(f->name));  if (f->zname != NULL)    free((voidp *)(f->zname));  farfree((voidp far *)f);  fcount--;                             /* decrement count */  return t;                             /* return pointer to next */}local int fqcmp(a, b)const voidp *a, *b;           /* pointers to pointers to found entries *//* Used by qsort() to compare entries in the found list by name. */{  return strcmp((*(struct flist far **)a)->name,                (*(struct flist far **)b)->name);}local int fqcmpz(a, b)const voidp *a, *b;           /* pointers to pointers to found entries *//* Used by qsort() to compare entries in the found list by zname. */{  return strcmp((*(struct flist far **)a)->zname,                (*(struct flist far **)b)->zname);}local char *last(p)char *p;                /* sequence of / delimited path components *//* Return a pointer to the start of the last path component. For a * directory name terminated by /, the return value is an empty string. */{  char *t;              /* temporary variable */  if ((t = strrchr(p, PATH_END)) != NULL)    return t + 1;  else    return p;}local char *msname(n)char *n;/* Reduce all path components to MSDOS upper case 8.3 style names.  Probably   should also check for invalid characters, but I don't know which ones   those are. */{  int c;                /* current character */  int f;                /* characters in current component */  char *p;              /* source pointer */  char *q;              /* destination pointer */  p = q = n;  f = 0;  while ((c = (unsigned char)*p++) != 0)    if (c == '/')    {      *q++ = (char)c;      f = 0;                            /* new component */    }#ifdef __human68k__    else if (iskanji(c))    {      if (f == 7 || f == 11)        f++;      else if (*p != '\0' && f < 12 && f != 8)      {        *q++ = c;        *q++ = *p++;        f += 2;      }    }#endif    else if (c == '.')      if (f < 9)      {        *q++ = (char)c;        f = 9;                          /* now in file type */      }      else        f = 12;                         /* now just excess characters */    else      if (f < 12 && f != 8)      {        *q++ = (char)(to_up(c));        f++;                            /* do until end of name or type */      }  *q = 0;  return n;}#ifdef VMSlocal char *strlower(s)char *s;                /* string to convert *//* Convert all uppercase letters to lowercase in string s */{  char *p;              /* scans string */  for (p = s; *p; p++)    if (*p >= 'A' && *p <= 'Z')      *p += 'a' - 'A';  return s;}local char *strupper(s)char *s;                /* string to convert *//* Convert all lowercase letters to uppercase in string s */{  char *p;              /* scans string */  for (p = s; *p; p++)    if (*p >= 'a' && *p <= 'z')      *p -= 'a' - 'A';  return s;}#endif /* VMS */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;              /* shortened name */  int dosflag;#ifdef TOPS20  int jfn;  char *fp, fname[200];  int ablock[5];  jfn = _gtjfn(x, (O_RDONLY));  ablock[1] = (int) (fname - 1);  ablock[2] = jfn & 0777777;    /* jfn, no flags */  ablock[3] = 0111100000001;    /* DEV+DIR+NAME+TYPE, punctuate */  if (!jsys(JFNS, ablock)) {      _rljfn(jfn);      return NULL;              /* something bad happened */  }  _rljfn(jfn);  if ((fp = (char *)malloc(strlen(fname) + 1)) == NULL) {      return NULL;  }  strcpy(fp, fname);            /* copy the file name here */  x = fp;#endif /* TOPS20 */#if defined(OS2) || defined(WIN32)  dosflag = dosify || IsFileSystemFAT(x);  if (!dosify && use_longname_ea && (t = GetLongPathEA(x)) != NULL)  {    x = t;    dosflag = 0;  }#else /* !OS2 */# ifdef MSDOS  dosflag = 1;# else /* !MSDOS */  dosflag = dosify; /* default for non-DOS and non-OS/2 */# endif /* ?MSDOS */#endif /* ?OS2 */  /* Find starting point in name before doing malloc */#if defined(MSDOS) || defined(__human68k__) /* msdos */  t = *x && *(x + 1) == ':' ? x + 2 : x;  while (*t == '/' || *t == '\\')    t++;#else /* !MSDOS */#  if (defined(VMS) || defined(TOPS20))  t = x;  if ((n = strrchr(t, ':')) != NULL)    t = n + 1;  if (*t == PATH_START && (n = strrchr(t, PATH_END)) != NULL)    if ((x = strchr(t, '.')) != NULL && x < n)      t = x + 1;    else      t = n + 1;#  else /* !(VMS || TOPS20) */#    ifdef AMIGA  if ((t = strrchr(x, ':')) != NULL)    /* reject ":" */    t++;  else    t = x;  {                                     /* reject "//" */    char *tt = t;    while (tt = strchr(tt, '/'))      while (*++tt == '/')        t = tt;  }  while (*t == '/')             /* reject leading "/" on what's left */    t++;#    else /* !AMIGA */                      /* unix */  for (t = x; *t == '/'; t++)    ;#    endif /* ?AMIGA */#  endif /* ?(VMS || TOPS20) */#endif /* ?MSDOS */  /* Make changes, if any, to the copied name (leave original intact) */#ifdef __human68k__  _toslash(t);#endif /* !__human68k__ */#ifdef MSDOS  for (n = t; *n; n++)    if (*n == '\\')      *n = '/';#endif /* MSDOS */  if (!pathput)    t = last(t);  /* Discard directory names with zip -rj */  if (*t == '\0')    return t;  /* Malloc space for internal name and copy it */  if ((n = malloc(strlen(t) + 1)) == NULL)    return NULL;  strcpy(n, t);#if (defined(VMS) || defined(TOPS20))  if ((t = strrchr(n, PATH_END)) != NULL)  {    *t = '/';    while (--t > n)      if (*t == '.')        *t = '/';  }  /* Fix from Greg Roelofs: */  /* Get current working directory and strip from n (t now = n) */  {    char cwd[256], *p, *q;    int c;    if (getcwd(cwd, 256) && ((p = strchr(cwd, '.')) != NULL))    {      ++p;      if ((q = strrchr(p, PATH_END)) != NULL)      {        *q = '/';        while (--q > p)          if (*q == '.')            *q = '/';        /* strip bogus path parts from n */        if (strncmp(n, p, (c=strlen(p))) == 0)        {          q = n + c;          while (*t++ = *q++)            ;        }      }    }  }  strlower(n);  if (isdir)  {    if (strcmp((t=n+strlen(n)-6), ".dir;1"))      error("directory not version 1");    else      strcpy(t, "/");  }#ifdef VMS  else if (!vmsver)    if ((t = strrchr(n, ';')) != NULL)      *t = 0;#endif /* VMS */  if ((t = strrchr(n, '.')) != NULL)  {    if ( t[1] == 0)                /* "filename." -> "filename" */      *t = 0;#ifdef VMS    else if (t[1] == ';')         /* "filename.;vvv" -> "filename;vvv" */    {      char *f = t+1;      while (*t++ = *f++) ;    }#endif /* VMS */  }#else  if (isdir == 42) return n;      /* avoid warning on unused variable */#endif /* ?(VMS || TOPS20) */  if (dosify)    msname(n);#if defined(MSDOS) && !defined(OS2) && !defined(WIN32)  else    strlwr(n);#endif  /* 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 (defined(VMS) || defined(TOPS20))  char *t;              /* scans name */  if ((t = strrchr(n, '/')) == NULL)#endif  {    if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)      return NULL;    strcpy(x, n);  }#if (defined(VMS) || defined(TOPS20))  else  {

⌨️ 快捷键说明

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