#include "oslib.h" #include static char wildname[63]; static char wilddir[255]; static OSOpenedDir wilddirref; static OSSpec wildmatch; char STSbuf[256]; inline char dummyfunc(int ch) { return ch; } int WildCardMatch(char *wild, char *name) { char next; char *prev; if (!name[0]) return 0; while (*wild) { if (*wild == '*') { wild++; next = *wild; prev = 0; while (*name) { if (dummyfunc(*name) == dummyfunc(next)) prev = name; ++name; } if (prev) name = prev; if (dummyfunc(*name) != dummyfunc(next)) return 0; } else if (*wild == '?' && *name) { wild++; name++; if (!*wild && *name) return 0; } else if (dummyfunc(*wild) == dummyfunc(*name)) { wild++; name++; } else { return 0; } } return !name[0] || (name[0] == '/' && !name[1]); } OSSpec *OS_MatchPath(const char *path) { char filename[64]; Boolean isfile; OSSpec spec; const char *nptr; if (path) { nptr = strrchr(path, '/'); if (!nptr) { nptr = path; strcpyn(wilddir, ".", -1, 256); } else { nptr = nptr + 1; strcpyn(wilddir, path, nptr - path, 256); } if (OS_MakePathSpec(0, wilddir, &spec.path)) return 0; strcpyn(wildname, nptr, -1, 64); if (OS_MakeNameSpec(wildname, &spec.name)) return 0; if (OS_OpenDir(&spec.path, &wilddirref)) return 0; } while (!OS_ReadDir(&wilddirref, &wildmatch, filename, &isfile)) { if (isfile && WildCardMatch(wildname, filename)) return &wildmatch; } OS_CloseDir(&wilddirref); return 0; } char *OS_GetFileNamePtr(char *path) { char *ptr; ptr = strrchr(path, '/'); return !ptr ? path : (ptr + 1); } char *OS_GetDirName(const OSPathSpec *spec, char *buf, int size) { char *path; char *pptr; if (!spec || !buf || size <= 0) return 0; path = OS_PathSpecToString(spec, STSbuf, 256); pptr = path + strlen(path) - 1; if (pptr > path && *pptr == '/') { *pptr = 0; --pptr; } while (pptr >= path && *pptr != '/') pptr--; strncpy(buf, pptr, size - 1); buf[size - 1] = 0; return buf; } int OS_MakeSpec2(const char *path, const char *filename, OSSpec *spec) { char bpath[256]; char *eptr; int pthlen; int fnlen; if (!path) path = ""; if (!filename) filename = ""; fnlen = strlen(filename); pthlen = strlen(path); if (fnlen + pthlen + 1 > 255) return ENAMETOOLONG; strncpy(bpath, path, pthlen); eptr = bpath + pthlen; if (eptr[-1] != '/') *(eptr++) = '/'; strcpy(eptr, filename); return OS_MakeSpec(bpath, spec, 0); } int OS_MakeSpecWithPath(OSPathSpec *path, const char *filename, Boolean noRelative, OSSpec *spec) { Boolean relpath; char buf[256]; char *mptr; char *eptr; relpath = filename && strpbrk(filename, "/\\:"); if (!filename) { if (path) spec->path = *path; else OS_GetCWD(&spec->path); return OS_MakeNameSpec("", &spec->name); } else { if ((!noRelative || !relpath) && !OS_IsFullPath(filename)) { if (path) OS_PathSpecToString(path, buf, 256); else buf[0] = 0; mptr = &buf[255] - strlen(filename); eptr = &buf[strlen(buf)]; strcpy((eptr > mptr) ? mptr : eptr, filename); return OS_MakeSpec(buf, spec, 0); } else { return OS_MakeSpec(filename, spec, 0); } } } int OS_NameSpecChangeExtension(OSNameSpec *spec, const char *ext, Boolean append) { char tmp[64]; char *per; OS_NameSpecToString(spec, tmp, 256); if (!append) { per = strrchr(tmp, '.'); if (!per) per = tmp + strlen(tmp); } else { per = tmp + strlen(tmp); if (ext[0] != '.') { per[0] = '.'; per[1] = 0; per += 1; } } if (strlen(tmp) + strlen(ext) > 64) per = tmp + 63 - strlen(ext); strcpy(per, ext); return OS_MakeNameSpec(tmp, spec); } int OS_NameSpecSetExtension(OSNameSpec *spec, const char *ext) { char tmp[64]; char *per; OS_NameSpecToString(spec, tmp, 256); if (ext[0] != '.') { per = strrchr(tmp, '.'); if (!per) per = tmp + strlen(tmp); if (ext[0]) { if (strlen(tmp) + 1 >= 64) { per[-1] = '.'; } else { per[0] = '.'; per++; } } } else { per = tmp + strlen(tmp); } if (strlen(tmp) + strlen(ext) > 64) per = tmp + 63 - strlen(ext); strcpy(per, ext); return OS_MakeNameSpec(tmp, spec); } char *OS_CompactPaths(char *buf, const char *p, const char *n, int size) { int plen; int nlen; char *ptr; int bidx; } char *OS_SpecToStringRelative(const OSSpec *spec, const OSPathSpec *cwdspec, char *path, int size) { char fullbuf[256]; char *full; char cwfbuf[256]; char *cwd; OSPathSpec mycwdspec; char *pptr; } int OS_FindFileInPath(const char *filename, const char *plist, OSSpec *spec) { char *next; char path[256]; int err; } int OS_FindProgram(const char *filename, OSSpec *spec) { char *plist; int err; char temp[256]; } int OS_CopyHandle(OSHandle *hand, OSHandle *copy) { int err; UInt32 sz; void *f; void *t; } int OS_AppendHandle(OSHandle *hand, const void *data, UInt32 len) { int err; UInt32 sz; void *buffer; }