Lines Matching defs:gp

78 gl_diropen(glob_t* gp, const char* path)
80 return (*gp->gl_opendir)(path);
88 gl_dirnext(glob_t* gp, void* handle)
92 while (dp = (struct dirent*)(*gp->gl_readdir)(handle))
99 gp->gl_status |= GLOB_NOTDIR;
111 gl_dirclose(glob_t* gp, void* handle)
113 (gp->gl_closedir)(handle);
121 gl_type(glob_t* gp, const char* path, int flags)
126 if ((flags & GLOB_STARSTAR) ? (*gp->gl_lstat)(path, &st) : (*gp->gl_stat)(path, &st))
144 gl_attr(glob_t* gp, const char* path, int flags)
154 gl_nextdir(glob_t* gp, char* dir)
156 if (!(dir = gp->gl_nextpath))
157 dir = gp->gl_nextpath = stakcopy(pathbin());
158 switch (*gp->gl_nextpath)
164 while (*gp->gl_nextpath == ':')
165 gp->gl_nextpath++;
169 while (*gp->gl_nextpath)
170 if (*gp->gl_nextpath++ == ':')
172 *(gp->gl_nextpath - 1) = 0;
185 errorcheck(register glob_t* gp, const char* path)
189 if (gp->gl_errfn)
190 r = (*gp->gl_errfn)(path, errno);
191 if (gp->gl_flags & GLOB_ERR)
194 gp->gl_error = GLOB_ABORTED;
231 addmatch(register glob_t* gp, const char* dir, const char* pat, register const char* rescan, char* endslash, int meta)
237 stakseek(MATCHPATH(gp));
241 stakputc(gp->gl_delim);
248 if ((*gp->gl_type)(gp, stakptr(MATCHPATH(gp)), 0) != GLOB_DIR)
250 stakputc(gp->gl_delim);
261 ap->gl_next = gp->gl_rescan;
262 gp->gl_rescan = ap;
266 if (!endslash && (gp->gl_flags & GLOB_MARK) && (type = (*gp->gl_type)(gp, stakptr(MATCHPATH(gp)), 0)))
268 if ((gp->gl_flags & GLOB_COMPLETE) && type != GLOB_EXE)
273 else if (type == GLOB_DIR && (gp->gl_flags & GLOB_MARK))
274 stakputc(gp->gl_delim);
277 ap->gl_next = gp->gl_match;
278 gp->gl_match = ap;
279 gp->gl_pathc++;
282 if (gp->gl_flags & GLOB_COMPLETE)
293 glob_dir(glob_t* gp, globlist_t* ap)
315 int meta = ((gp->re_flags & REG_ICASE) && *ap->gl_begin != '/') ? MATCH_META : 0;
325 if (*gp->gl_intr)
327 gp->gl_error = GLOB_INTR;
331 prefix = dirname = ap->gl_path + gp->gl_extra;
350 if (!first && !*rescan && *(rescan - 2) == gp->gl_delim)
353 c = (*gp->gl_type)(gp, prefix, 0);
354 *(rescan - 2) = gp->gl_delim;
356 addmatch(gp, NiL, prefix, NiL, rescan - 1, anymeta);
358 else if ((anymeta || !(gp->gl_flags & GLOB_NOCHECK)) && (*gp->gl_type)(gp, prefix, 0))
359 addmatch(gp, NiL, prefix, NiL, NiL, anymeta);
375 if (!(gp->gl_flags & GLOB_AUGMENTED))
382 if (!(gp->gl_flags & GLOB_NOESCAPE))
390 if (c == gp->gl_delim)
408 if (!rescan && (gp->gl_flags & GLOB_COMPLETE))
430 if (!complete && (gp->gl_flags & GLOB_STARSTAR))
453 if (rescan && !complete && (gp->gl_flags & GLOB_STARSTAR))
472 gp->gl_starstar++;
473 if (gp->gl_opt)
474 pat = strcpy(gp->gl_opt, pat);
479 if (!(dirname = (*gp->gl_nextdir)(gp, dirname)))
483 if ((!starstar && !gp->gl_starstar || (*gp->gl_type)(gp, dirname, GLOB_STARSTAR) == GLOB_DIR) && (dirf = (*gp->gl_diropen)(gp, dirname)))
485 if (!(gp->re_flags & REG_ICASE) && ((*gp->gl_attr)(gp, dirname, 0) & GLOB_ICASE))
489 if (err = regcomp(&rei, pat, gp->re_flags|REG_ICASE))
494 if (gp->gl_ignore)
496 if (!gp->gl_ignorei)
498 if (regcomp(&gp->re_ignorei, gp->gl_fignore, gp->re_flags|REG_ICASE))
500 gp->gl_error = GLOB_APPERR;
503 gp->gl_ignorei = &gp->re_ignorei;
505 ire = gp->gl_ignorei;
514 if (err = regcomp(&rec, pat, gp->re_flags))
519 ire = gp->gl_ignore;
522 *restore2 = gp->gl_delim;
523 while ((name = (*gp->gl_dirnext)(gp, dirf)) && !*gp->gl_intr)
525 if (notdir = (gp->gl_status & GLOB_NOTDIR))
526 gp->gl_status &= ~GLOB_NOTDIR;
530 addmatch(gp, prefix, name, matchdir, NiL, anymeta);
534 addmatch(gp, prefix, name, rescan, NiL, anymeta);
536 addmatch(gp, prefix, name, starstar==2?"":NiL, NiL, anymeta);
540 (*gp->gl_dirclose)(gp, dirf);
541 if (err || errno && !errorcheck(gp, dirname))
544 else if (!complete && !errorcheck(gp, dirname))
548 if (*gp->gl_intr)
550 gp->gl_error = GLOB_INTR;
555 *restore1 = gp->gl_delim;
557 *restore2 = gp->gl_delim;
563 gp->gl_error = GLOB_NOSPACE;
567 glob(const char* pattern, int flags, int (*errfn)(const char*, int), register glob_t* gp)
586 gp->gl_rescan = 0;
587 gp->gl_error = 0;
588 gp->gl_errfn = errfn;
591 if ((gp->gl_flags |= GLOB_APPEND) ^ (flags|GLOB_MAGIC))
593 if (((gp->gl_flags & GLOB_STACK) == 0) == (gp->gl_stak == 0))
595 if (gp->gl_starstar > 1)
596 gp->gl_flags |= GLOB_STARSTAR;
598 gp->gl_starstar = 0;
602 gp->gl_flags = (flags&0xffff)|GLOB_MAGIC;
603 gp->re_flags = REG_SHELL|REG_NOSUB|REG_LEFT|REG_RIGHT|((flags&GLOB_AUGMENTED)?REG_AUGMENTED:0);
604 gp->gl_pathc = 0;
605 gp->gl_ignore = 0;
606 gp->gl_ignorei = 0;
607 gp->gl_starstar = 0;
610 gp->gl_fignore = 0;
611 gp->gl_suffix = 0;
612 gp->gl_intr = 0;
613 gp->gl_delim = 0;
614 gp->gl_handle = 0;
615 gp->gl_diropen = 0;
616 gp->gl_dirnext = 0;
617 gp->gl_dirclose = 0;
618 gp->gl_type = 0;
619 gp->gl_attr = 0;
620 gp->gl_nextdir = 0;
621 gp->gl_stat = 0;
622 gp->gl_lstat = 0;
623 gp->gl_extra = 0;
627 gp->gl_opendir = (GL_opendir_f)opendir;
628 gp->gl_readdir = (GL_readdir_f)readdir;
629 gp->gl_closedir = (GL_closedir_f)closedir;
630 if (!gp->gl_stat)
631 gp->gl_stat = (GL_stat_f)pathstat;
633 if (!gp->gl_lstat)
634 gp->gl_lstat = (GL_stat_f)lstat;
635 if (!gp->gl_intr)
636 gp->gl_intr = &intr;
637 if (!gp->gl_delim)
638 gp->gl_delim = '/';
639 if (!gp->gl_diropen)
640 gp->gl_diropen = gl_diropen;
641 if (!gp->gl_dirnext)
642 gp->gl_dirnext = gl_dirnext;
643 if (!gp->gl_dirclose)
644 gp->gl_dirclose = gl_dirclose;
645 if (!gp->gl_type)
646 gp->gl_type = gl_type;
647 if (!gp->gl_attr)
648 gp->gl_attr = gl_attr;
650 gp->re_flags |= REG_ICASE;
651 if (!gp->gl_fignore)
652 gp->re_flags |= REG_SHELL_DOT;
653 else if (*gp->gl_fignore)
655 if (regcomp(&gp->re_ignore, gp->gl_fignore, gp->re_flags))
657 gp->gl_ignore = &gp->re_ignore;
659 if (gp->gl_flags & GLOB_STACK)
660 gp->gl_stak = 0;
661 else if (!(gp->gl_stak = stakcreate(0)))
663 if ((gp->gl_flags & GLOB_COMPLETE) && !gp->gl_nextdir)
664 gp->gl_nextdir = gl_nextdir;
666 skip = gp->gl_pathc;
667 if (gp->gl_stak)
668 oldstak = stakinstall(gp->gl_stak, 0);
670 extra += gp->gl_offs;
671 if (gp->gl_suffix)
672 suflen = strlen(gp->gl_suffix);
675 f = gp->gl_flags;
717 flags = (gp->gl_flags = f) & 0xffff;
719 gp->re_flags |= REG_ICASE;
721 gp->re_flags &= ~REG_ICASE;
732 top = ap = (globlist_t*)stakalloc((optlen ? 2 : 1) * strlen(pattern) + sizeof(globlist_t) + suflen + gp->gl_extra);
735 ap->gl_begin = ap->gl_path + gp->gl_extra;
738 pat = strcopy(pat, gp->gl_suffix);
739 gp->gl_pat = optlen ? strncpy(gp->gl_opt = pat + 1, pattern, optlen) : (char*)0;
742 gp->gl_match = 0;
745 gp->gl_rescan = ap->gl_next;
746 glob_dir(gp, ap);
747 } while (!gp->gl_error && (ap = gp->gl_rescan));
748 if (gp->gl_pathc == skip)
752 gp->gl_pathc++;
753 top->gl_next = gp->gl_match;
754 gp->gl_match = top;
755 strcopy(top->gl_path + gp->gl_extra, nocheck);
758 gp->gl_error = GLOB_NOMATCH;
761 gp->gl_list = gp->gl_match;
764 argv = (char**)stakalloc((gp->gl_pathc + extra) * sizeof(char*));
765 if (gp->gl_flags & GLOB_APPEND)
768 memcpy(argv, gp->gl_pathv, skip * sizeof(char*));
777 gp->gl_pathv = argv;
779 ap = gp->gl_match;
782 *argv++ = ap->gl_path + gp->gl_extra;
789 if (gp->gl_starstar > 1)
790 av[gp->gl_pathc = struniq(av, argv - av)] = 0;
791 gp->gl_starstar = 0;
794 if (gp->gl_starstar > 1)
795 gp->gl_flags &= ~GLOB_STARSTAR;
796 if (gp->gl_stak)
798 return gp->gl_error;
802 globfree(glob_t* gp)
804 if ((gp->gl_flags & GLOB_MAGIC) == GLOB_MAGIC)
806 gp->gl_flags &= ~GLOB_MAGIC;
807 if (gp->gl_stak)
808 stkclose(gp->gl_stak);
809 if (gp->gl_ignore)
810 regfree(gp->gl_ignore);
811 if (gp->gl_ignorei)
812 regfree(gp->gl_ignorei);