/* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more * meta characters. */ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { struct stat sb; Char *p, *q; int anymeta; /* * Loop over pattern segments until end of pattern or until * segment with meta character found. */ for (anymeta = 0;;) { if (*pattern == EOS) { /* End of pattern? */ *pathend = EOS; if (g_lstat(pathbuf, &sb, pglob)) return(0); if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { if (pathend+1 > pathend_last) return (1); *pathend++ = SEP; *pathend = EOS; } ++pglob->gl_matchc; return(globextend(pathbuf, pglob, limitp)); } /* Find end of next segment, copy tentatively to pathend. */ q = pathend; p = pattern; while (*p != EOS && *p != SEP) { if (ismeta(*p)) anymeta = 1; if (q+1 > pathend_last) return (1); *q++ = *p++; } if (!anymeta) { /* No expansion, do next segment. */ pathend = q; pattern = p; while (*pattern == SEP) { if (pathend+1 > pathend_last) return (1); *pathend++ = *pattern++; } } else /* Need expansion, recurse. */ return(glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, p, pattern_last, pglob, limitp)); } /* NOTREACHED */ }
/* * functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or * more meta characters. */ static int glob2(struct strbuf *pathbuf, const Char *pattern, glob_t *pglob, int no_match) { struct stat sbuf; int anymeta; const Char *p; size_t orig_len; /* * loop over pattern segments until end of pattern or until segment with * meta character found. */ anymeta = 0; for (;;) { if (*pattern == EOS) { /* end of pattern? */ strbuf_terminate(pathbuf); if (Lstat(pathbuf->s, &sbuf)) return (0); if (((pglob->gl_flags & GLOB_MARK) && pathbuf->s[pathbuf->len - 1] != SEP) && (S_ISDIR(sbuf.st_mode) #ifdef S_IFLNK || (S_ISLNK(sbuf.st_mode) && (Stat(pathbuf->s, &sbuf) == 0) && S_ISDIR(sbuf.st_mode)) #endif )) { strbuf_append1(pathbuf, SEP); strbuf_terminate(pathbuf); } ++pglob->gl_matchc; globextend(pathbuf->s, pglob); return 0; } /* find end of next segment, tentatively copy to pathbuf */ p = pattern; orig_len = pathbuf->len; while (*p != EOS && *p != SEP) { if (ismeta(*p)) anymeta = 1; strbuf_append1(pathbuf, *p++); } if (!anymeta) { /* no expansion, do next segment */ pattern = p; while (*pattern == SEP) strbuf_append1(pathbuf, *pattern++); } else { /* need expansion, recurse */ pathbuf->len = orig_len; return (glob3(pathbuf, pattern, p, pattern, pglob, no_match)); } } /* NOTREACHED */ }
/* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more * meta characters. */ static int glob2 ( Char *pathbuf, Char *pathend, Char *pattern, glob_t *pglob ) { Stat sb; Char *p, *q; int anymeta; /* * Loop over pattern segments until end of pattern or until * segment with meta character found. */ for (anymeta = 0;;) { if (*pattern == EOS) /* End of pattern? */ { *pathend = EOS; if (g_lstat(pathbuf, &sb, pglob)) return(0); if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) #ifdef S_ISLNK /* bummer for unixware */ || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)) #endif )) { *pathend++ = SEP; *pathend = EOS; } ++pglob->gl_matchc; return(globextend(pathbuf, pglob)); } /* Find end of next segment, copy tentatively to pathend. */ q = pathend; p = pattern; while (*p != EOS && *p != SEP) { if (ismeta(*p)) anymeta = 1; *q++ = *p++; } if (!anymeta) /* No expansion, do next segment. */ { pathend = q; pattern = p; while (*pattern == SEP) *pathend++ = *pattern++; } else /* Need expansion, recurse. */ return(glob3(pathbuf, pathend, pattern, p, pglob)); } /* NOTREACHED */ }
static int glob1(GDir *dir, gchar *pattern, gchar *pattern_last, wapi_glob_t *pglob, size_t *limitp, gboolean ignorecase, gboolean unique) { /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ if (*pattern == EOS) return(0); return(glob3(dir, pattern, pattern_last, pglob, limitp, ignorecase, unique)); }
// // The functions glob2 and glob3 are mutually recursive; there is one level // of recursion for each segment in the pattern that contains one or more // meta characters. // static int glob2(char *pathbuf, char *pathend, char *pathend_last, char *pattern, glob_t *pglob, size_t *limit) { struct stat sb; char *p, *q; int anymeta; // // Loop over pattern segments until end of pattern or until // segment with meta character found. // for (anymeta = 0;;) { if (*pattern == EOS) { // End of pattern? *pathend = EOS; if (lstat(pathbuf, &sb)) return 0; if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (stat(pathbuf, &sb) == 0) && S_ISDIR(sb.st_mode)))) { if (pathend + 1 > pathend_last) return GLOB_ABORTED; *pathend++ = SEP; *pathend = EOS; } pglob->gl_matchc++; return globextend(pathbuf, pglob, limit); } // Find end of next segment, copy tentatively to pathend. q = pathend; p = pattern; while (*p != EOS && *p != SEP) { if (ismeta(*p)) anymeta = 1; if (q + 1 > pathend_last) return GLOB_ABORTED; *q++ = *p++; } if (!anymeta) { // No expansion, do next segment. pathend = q; pattern = p; while (*pattern == SEP) { if (pathend + 1 > pathend_last) return GLOB_ABORTED; *pathend++ = *pattern++; } } else { // Need expansion, recurse return glob3(pathbuf, pathend, pathend_last, pattern, p, pglob, limit); } } }
int main () { Char *buf; Char *pattern; Char *bound; Char A [MAXPATHLEN+1]; Char B [PATTERNLEN]; buf = A; pattern = B; bound = A + sizeof(A) - 1; glob3 (buf, buf, bound, pattern); return 0; }
int main() { try { init(); SDL_Surface *screen = SDL_SetVideoMode(WIDTH, HEIGHT, 0, SDL_DOUBLEBUF); if (screen == NULL) { throw std::string("Unable to set video mode: ")+SDL_GetError(); } Sprite background("images/falsemirror.bmp", 0.0, 0.0, false); Sprite trees("images/ringotrees.bmp", 1.0, 0.0, true); Sprite flowers("images/ringoflowers.bmp", 1.0, 0.0, true); Sprite cells("images/lastring.bmp", 1.0, 0.0, true); Sprite glob1("images/oil.bmp", 430.0, 315.0, true); Sprite glob2("images/oil.bmp", 430.0, 315.0, true); Sprite glob3("images/oil.bmp", 430.0, 315.0, true); Manager manager(START_X, START_Y, INCR_X, X_VELOCITY, Y_VELOCITY, DISC_VELOCITY, DT); manager.animate(screen, background, trees, flowers, cells, glob1, glob2, glob3); SDL_FreeSurface(screen); } catch(const std::string& msg) { std::cout << msg << std::endl; } catch(...) { std::cout << "oops" << std::endl; } }
static int glob3(struct strbuf *pathbuf, const Char *pattern, const Char *restpattern, const Char *pglobstar, glob_t *pglob, int no_match) { DIR *dirp; struct dirent *dp; struct stat sbuf; int err; Char m_not = (pglob->gl_flags & GLOB_ALTNOT) ? M_ALTNOT : M_NOT; size_t orig_len; int globstar = 0; int chase_symlinks = 0; const Char *termstar = NULL; strbuf_terminate(pathbuf); orig_len = pathbuf->len; errno = err = 0; while (pglobstar < restpattern) { __Char wc; size_t width = One_Char_mbtowc(&wc, pglobstar, MB_LEN_MAX); if ((pglobstar[0] & M_MASK) == M_ALL && (pglobstar[width] & M_MASK) == M_ALL) { globstar = 1; chase_symlinks = (pglobstar[2 * width] & M_MASK) == M_ALL; termstar = pglobstar + (2 + chase_symlinks) * width; break; } pglobstar += width; } if (globstar) { err = pglobstar==pattern && termstar==restpattern ? *restpattern == EOS ? glob2(pathbuf, restpattern - 1, pglob, no_match) : glob2(pathbuf, restpattern + 1, pglob, no_match) : glob3(pathbuf, pattern, restpattern, termstar, pglob, no_match); if (err) return err; pathbuf->len = orig_len; strbuf_terminate(pathbuf); } if (*pathbuf->s && (Lstat(pathbuf->s, &sbuf) || !S_ISDIR(sbuf.st_mode) #ifdef S_IFLINK && ((globstar && !chase_symlinks) || !S_ISLNK(sbuf.st_mode)) #endif )) return 0; if (!(dirp = Opendir(pathbuf->s))) { /* todo: don't call for ENOENT or ENOTDIR? */ if ((pglob->gl_errfunc && (*pglob->gl_errfunc) (pathbuf->s, errno)) || (pglob->gl_flags & GLOB_ERR)) return (GLOB_ABEND); else return (0); } /* search directory for matching names */ while ((dp = readdir(dirp)) != NULL) { /* initial DOT must be matched literally */ if (dp->d_name[0] == DOT && *pattern != DOT) if (!(pglob->gl_flags & GLOB_DOT) || !dp->d_name[1] || (dp->d_name[1] == DOT && !dp->d_name[2])) continue; /*unless globdot and not . or .. */ pathbuf->len = orig_len; strbuf_append(pathbuf, dp->d_name); strbuf_terminate(pathbuf); if (globstar) { #ifdef S_IFLNK if (!chase_symlinks && (Lstat(pathbuf->s, &sbuf) || S_ISLNK(sbuf.st_mode))) continue; #endif if (match(pathbuf->s + orig_len, pattern, termstar, (int)m_not) == no_match) continue; strbuf_append1(pathbuf, SEP); strbuf_terminate(pathbuf); if ((err = glob2(pathbuf, pglobstar, pglob, no_match)) != 0) break; } else { if (match(pathbuf->s + orig_len, pattern, restpattern, (int) m_not) == no_match) continue; if ((err = glob2(pathbuf, restpattern, pglob, no_match)) != 0) break; } } /* todo: check error from readdir? */ closedir(dirp); return (err); }
/* * The functions glob2 and glob3 are mutually recursive; there is one level * of recursion for each segment in the pattern that contains one or more * meta characters. */ static int glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Char *pattern, Char *pattern_last, glob_t *pglob, size_t *limitp) { Stat_t sb; Char *p, *q; int anymeta; /* * Loop over pattern segments until end of pattern or until * segment with meta character found. */ for (anymeta = 0;;) { if (*pattern == BG_EOS) { /* End of pattern? */ *pathend = BG_EOS; if (g_lstat(pathbuf, &sb, pglob)) return(0); if (((pglob->gl_flags & GLOB_MARK) && pathend[-1] != BG_SEP #ifdef DOSISH && pathend[-1] != BG_SEP2 #endif ) && (S_ISDIR(sb.st_mode) || (S_ISLNK(sb.st_mode) && (g_stat(pathbuf, &sb, pglob) == 0) && S_ISDIR(sb.st_mode)))) { #ifdef MACOS_TRADITIONAL short err; err = glob_mark_Mac(pathbuf, pathend, pathend_last); if (err) return (err); #else if (pathend+1 > pathend_last) return (1); *pathend++ = BG_SEP; *pathend = BG_EOS; #endif } ++pglob->gl_matchc; #ifdef GLOB_DEBUG printf("calling globextend from glob2\n"); #endif /* GLOB_DEBUG */ return(globextend(pathbuf, pglob, limitp)); } /* Find end of next segment, copy tentatively to pathend. */ q = pathend; p = pattern; while (*p != BG_EOS && *p != BG_SEP #ifdef DOSISH && *p != BG_SEP2 #endif ) { if (ismeta(*p)) anymeta = 1; if (q+1 > pathend_last) return (1); *q++ = *p++; } if (!anymeta) { /* No expansion, do next segment. */ pathend = q; pattern = p; while (*pattern == BG_SEP #ifdef DOSISH || *pattern == BG_SEP2 #endif ) { if (pathend+1 > pathend_last) return (1); *pathend++ = *pattern++; } } else /* Need expansion, recurse. */ return(glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, p, pattern_last, pglob, limitp)); } /* NOTREACHED */ }