static void FillBoneController(Exporter* exporter, NiBSBoneLODControllerRef boneCtrl, INode *node) { for (int i=0; i<node->NumberOfChildren(); i++) { INode * child = node->GetChildNode(i); FillBoneController(exporter, boneCtrl, child); TSTR upb; child->GetUserPropBuffer(upb); if (!upb.isNull()) { // Check for bonelod and add bones to bone controller stringlist tokens = TokenizeString(upb.data(), "\r\n", true); for (stringlist::iterator itr = tokens.begin(); itr != tokens.end(); ++itr) { string& line = (*itr); if (wildmatch("*#", line)) { // ends with # stringlist bonelod = TokenizeString(line.c_str(), "#", true); for (stringlist::iterator token = bonelod.begin(); token != bonelod.end(); ++token) { if ( wildmatch("??BoneLOD", (*token).c_str())) { if (++token == bonelod.end()) break; if (strmatch("Bone", (*token).c_str())) { if (++token == bonelod.end()) break; int group = 0; std::stringstream str (*token); str >> group; boneCtrl->AddNodeToGroup(group, exporter->getNode(child)); } } } } } }
inline int git_fnmatch(const struct pathspec_item *item, const char *pattern, const char *string, int prefix) { if (prefix > 0) { if (ps_strncmp(item, pattern, string, prefix)) return WM_NOMATCH; pattern += prefix; string += prefix; } if (item->flags & PATHSPEC_ONESTAR) { int pattern_len = strlen(++pattern); int string_len = strlen(string); return string_len < pattern_len || ps_strcmp(item, pattern, string + string_len - pattern_len); } if (item->magic & PATHSPEC_GLOB) return wildmatch(pattern, string, WM_PATHNAME | (item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0), NULL); else /* wildmatch has not learned no FNM_PATHNAME mode yet */ return wildmatch(pattern, string, item->magic & PATHSPEC_ICASE ? WM_CASEFOLD : 0, NULL); }
static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { struct show_data *data = cb_data; if (!wildmatch(data->pattern, refname, 0)) { if (data->format == REPLACE_FORMAT_SHORT) printf("%s\n", refname); else if (data->format == REPLACE_FORMAT_MEDIUM) printf("%s -> %s\n", refname, oid_to_hex(oid)); else { /* data->format == REPLACE_FORMAT_LONG */ struct object_id object; enum object_type obj_type, repl_type; if (get_oid(refname, &object)) return error("Failed to resolve '%s' as a valid ref.", refname); obj_type = oid_object_info(the_repository, &object, NULL); repl_type = oid_object_info(the_repository, oid, NULL); printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), oid_to_hex(oid), type_name(repl_type)); } } return 0; }
static int fnmatch_icase_mem(const char *pattern, int patternlen, const char *string, int stringlen, int flags) { int match_status; struct strbuf pat_buf = STRBUF_INIT; struct strbuf str_buf = STRBUF_INIT; const char *use_pat = pattern; const char *use_str = string; if (pattern[patternlen]) { strbuf_add(&pat_buf, pattern, patternlen); use_pat = pat_buf.buf; } if (string[stringlen]) { strbuf_add(&str_buf, string, stringlen); use_str = str_buf.buf; } if (ignore_case) flags |= WM_CASEFOLD; match_status = wildmatch(use_pat, use_str, flags, NULL); strbuf_release(&pat_buf); strbuf_release(&str_buf); return match_status; }
NiNodeRef Exporter::createNode(INode* maxNode, const string& name) { USES_CONVERSION; bool ismatch = strmatch(T2A(maxNode->GetName()), name); if (ismatch) { NodeToNodeMap::iterator itr = mNodeMap.find(maxNode); if (itr != mNodeMap.end()) return (*itr).second; } NiNodeRef node; if (!findNode(name, node)) { node = createNode(); BOOL noname = FALSE; if (!maxNode->GetUserPropBool(NP_NONAME, noname) || !noname) node->SetName(name); } if (wildmatch("noname*", name)) { maxNode->SetUserPropBool(NP_NONAME, TRUE); } mNodeMap[maxNode] = node; return node; }
static void set_reflog_expiry_param(struct cmd_reflog_expire_cb *cb, int slot, const char *ref) { struct reflog_expire_cfg *ent; if (slot == (EXPIRE_TOTAL|EXPIRE_UNREACH)) return; /* both given explicitly -- nothing to tweak */ for (ent = reflog_expire_cfg; ent; ent = ent->next) { if (!wildmatch(ent->pattern, ref, 0)) { if (!(slot & EXPIRE_TOTAL)) cb->expire_total = ent->expire_total; if (!(slot & EXPIRE_UNREACH)) cb->expire_unreachable = ent->expire_unreachable; return; } } /* * If unconfigured, make stash never expire */ if (!strcmp(ref, "refs/stash")) { if (!(slot & EXPIRE_TOTAL)) cb->expire_total = 0; if (!(slot & EXPIRE_UNREACH)) cb->expire_unreachable = 0; return; } /* Nothing matched -- use the default value */ if (!(slot & EXPIRE_TOTAL)) cb->expire_total = default_reflog_expire; if (!(slot & EXPIRE_UNREACH)) cb->expire_unreachable = default_reflog_expire_unreachable; }
static short removearg ( struct arginfo *arg, char *str) { char *cp = NULL; int i; int cnt; i = arg->nargc; cp = arg->argbuf; while (i-- > 0) { cnt = strlen (cp) + 1; if (wildmatch (str, cp)) { arg->argpos -= cnt; memcpy (cp, cp + cnt, arg->argpos - (cp - arg->argbuf)); --arg->nargc; } else { cp += cnt; } } return 0; }
void Exporter::getChildNodes(INode *node, vector<NiNodeRef>& list) { for (int i = 0; i < node->NumberOfChildren(); i++) { INode * child = node->GetChildNode(i); ObjectState os = node->EvalWorldState(0); bool addBone = false; bool local = !mFlattenHierarchy; bool meshGroup = isMeshGroup(node); TSTR nodeName = node->GetName(); if (wildmatch(TEXT("Bip?? Footsteps"), nodeName)) { addBone = false; } else if (node->IsBoneShowing()) { addBone = true; } else if (os.obj && os.obj->SuperClassID() == GEOMOBJECT_CLASS_ID) { Class_ID clsid = os.obj->ClassID(); if (os.obj && (clsid == BONE_OBJ_CLASSID || clsid == Class_ID(BONE_CLASS_ID, 0) || clsid == Class_ID(0x00009125, 0) /* Biped Twist Helpers */ ) ) { // skip mesh groups in skeleton only situations if (!meshGroup || !local || !mSkeletonOnly) addBone = true; } else if (!mSkeletonOnly) { if (mExportType != NIF_WO_ANIM && isNodeTracked(node)) { addBone = true; } else if (mExportExtraNodes || (mExportType != NIF_WO_ANIM && isNodeKeyed(node))) { addBone = true; } } else if (mExportCameras && os.obj && os.obj->SuperClassID() == CAMERA_CLASS_ID) { addBone = true; } else if (meshGroup && local && !mSkeletonOnly) // only create node if local { addBone = true; } } if (addBone) { list.push_back(getNode(child)); } getChildNodes(child, list); } }
static int wildmatch( const char *s1, const char *s2) { if (s1 == NULL) { s1 = ""; } if (s2 == NULL) { s2 = ""; } while (*s1 && (*s2 || *s1 == '*')) { if (tolower (*s1) != tolower (*s2) && *s1 != '?' && *s1 != '*') { return 0; } if (*s2) { if (*s1 == '*') { ++s1; if (!*s1) { return 1; } while (*s2) { if (wildmatch (s1, s2)) { return 1; } ++s2; } return 0; } ++s2; } ++s1; } if (*s1 || *s2) { return 0; } else { return 1; } }
static int filter_refs(const char *refname, const struct object_id *oid, int flags, void *data) { struct ref_filter *filter = (struct ref_filter *)data; if (wildmatch(filter->pattern, refname, 0, NULL)) return 0; return filter->fn(refname, oid, flags, filter->cb_data); }
bool Exporter::isSkeletonRoot(INode *node) { if (wildmatch("Bip??", node->GetName())) { return true; } else if ( node->GetParentNode() == mI->GetRootNode() ) { return true; } return false; }
/* match just at the start of string (anchored tests) */ static void run_test(int line, bool matches, #ifdef COMPARE_WITH_FNMATCH bool same_as_fnmatch, #endif const char *text, const char *pattern) { bool matched; #ifdef COMPARE_WITH_FNMATCH bool fn_matched; int flags = strstr(pattern, "**")? 0 : FNM_PATHNAME; #endif if (explode_mod) { char buf[MAXPATHLEN*2], *texts[MAXPATHLEN]; int pos = 0, cnt = 0, ndx = 0, len = strlen(text); if (empty_at_start) texts[ndx++] = ""; /* An empty string must turn into at least one empty array item. */ while (1) { texts[ndx] = buf + ndx * (explode_mod + 1); strlcpy(texts[ndx++], text + pos, explode_mod + 1); if (pos + explode_mod >= len) break; pos += explode_mod; if (!(++cnt % empties_mod)) texts[ndx++] = ""; } if (empty_at_end) texts[ndx++] = ""; texts[ndx] = NULL; matched = wildmatch_array(pattern, (const char**)texts, 0); } else matched = wildmatch(pattern, text); #ifdef COMPARE_WITH_FNMATCH fn_matched = !fnmatch(pattern, text, flags); #endif if (matched != matches) { printf("wildmatch failure on line %d:\n %s\n %s\n expected %s match\n", line, text, pattern, matches? "a" : "NO"); wildmatch_errors++; } #ifdef COMPARE_WITH_FNMATCH if (fn_matched != (matches ^ !same_as_fnmatch)) { printf("fnmatch disagreement on line %d:\n %s\n %s\n expected %s match\n", line, text, pattern, matches ^ !same_as_fnmatch? "a" : "NO"); fnmatch_errors++; } #endif if (output_iterations) { printf("%d: \"%s\" iterations = %d\n", line, pattern, wildmatch_iteration_count); } }
static int match_patterns(const char **pattern, const char *refname) { if (!*pattern) return 1; /* no pattern always matches */ while (*pattern) { if (!wildmatch(*pattern, refname, 0, NULL)) return 1; pattern++; } return 0; }
/* * Function name: set_nsd_directory * Description : Use this function to set the directory in which the * save-files for this module as saved in. * Arguments : string directory - the name of the directory. */ nomask public void set_nsd_directory(string directory) { nsd_directory = directory; /* If there is no trailing slash '/' we add one. */ if (!wildmatch("*/", nsd_directory)) { nsd_directory += "/"; } }
int cmd__wildmatch(int argc, const char **argv) { int i; for (i = 2; i < argc; i++) { if (argv[i][0] == '/') die("Forward slash is not allowed at the beginning of the\n" "pattern because Windows does not like it. Use `XXX/' instead."); else if (!strncmp(argv[i], "XXX/", 4)) argv[i] += 3; } if (!strcmp(argv[1], "wildmatch")) return !!wildmatch(argv[3], argv[2], WM_PATHNAME); else if (!strcmp(argv[1], "iwildmatch")) return !!wildmatch(argv[3], argv[2], WM_PATHNAME | WM_CASEFOLD); else if (!strcmp(argv[1], "pathmatch")) return !!wildmatch(argv[3], argv[2], 0); else if (!strcmp(argv[1], "ipathmatch")) return !!wildmatch(argv[3], argv[2], WM_CASEFOLD); else return 1; }
static int subpath_matches(const char *path, const char *filter) { const char *subpath = path; while (subpath) { if (!wildmatch(filter, subpath, 0, NULL)) return subpath - path; subpath = strchr(subpath, '/'); if (subpath) subpath++; } return -1; }
BOOL DLLCALL wildmatch(const char *fname, const char *spec, BOOL path) { char *specp; char *fnamep; char *wildend; specp=(char *)spec; fnamep=(char *)fname; for(;;specp++, fnamep++) { switch(*specp) { case '?': if(!(*fnamep)) return(FALSE); break; case 0: if(!*fnamep) return(TRUE); break; case '*': while(*specp=='*') specp++; if(path) { for(wildend=fnamep; *wildend; wildend++) { if(IS_PATH_DELIM(*wildend)) { wildend--; break; } } } else wildend=strchr(fnamep, 0); for(;wildend >= fnamep;wildend--) { if(wildmatch(wildend, specp, path)) return(TRUE); } return(FALSE); default: if(*specp != *fnamep) return(FALSE); } if(!(*specp && *fnamep)) break; } while(*specp=='*') specp++; if(*specp==*fnamep) return(TRUE); return(FALSE); }
/* * Is there one among the list of patterns that match the tail part * of the path? */ static int tail_match(const char **pattern, const char *path) { const char *p; char *pathbuf; if (!pattern) return 1; /* no restriction */ pathbuf = xstrfmt("/%s", path); while ((p = *(pattern++)) != NULL) { if (!wildmatch(p, pathbuf, 0, NULL)) { free(pathbuf); return 1; } } free(pathbuf); return 0; }
BOOL DLLCALL wildmatchi(const char *fname, const char *spec, BOOL path) { char* s1; char* s2; BOOL result; if((s1=strdup(fname))==NULL) return(FALSE); if((s2=strdup(spec))==NULL) { free(s1); return(FALSE); } strupr(s1); strupr(s2); result = wildmatch(s1, s2, path); free(s1); free(s2); return(result); }
int findfile(const char* wildcard, BUFFER* foundfilebuff) { DIR* dirp; struct dirent* dp; const char* lastslash; const char* lastslash2; BUFFER pathbuff; lastslash = strrchr(wildcard, '/'); lastslash2 = strrchr(wildcard, '\\'); lastslash = lastslash > lastslash2 ? lastslash : lastslash2; buffer_init(&pathbuff); buffer_addstring(&pathbuff, wildcard, lastslash - wildcard); buffer_addchar(&pathbuff, 0); buffer_init(foundfilebuff); dirp = opendir(buffer_ptr(&pathbuff)); if (!dirp) { buffer_free(&pathbuff); return 0; } // Any files found? while ((dp = readdir(dirp)) != NULL) { if (wildmatch(lastslash + 1, dp->d_name, 1)) { buffer_addstring(foundfilebuff, wildcard, lastslash - wildcard + 1); buffer_addstring(foundfilebuff, dp->d_name, strlen(dp->d_name)); buffer_addchar(foundfilebuff, 0); closedir(dirp); return 1; } } closedir(dirp); return 0; }
static int append_matching_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data) { /* we want to allow pattern hold/<asterisk> to show all * branches under refs/heads/hold/, and v0.99.9? to show * refs/tags/v0.99.9a and friends. */ const char *tail; int slash = count_slash(refname); for (tail = refname; *tail && match_ref_slash < slash; ) if (*tail++ == '/') slash--; if (!*tail) return 0; if (wildmatch(match_ref_pattern, tail, 0, NULL)) return 0; if (starts_with(refname, "refs/heads/")) return append_head_ref(refname, oid, flag, cb_data); if (starts_with(refname, "refs/tags/")) return append_tag_ref(refname, oid, flag, cb_data); return append_ref(refname, oid, 0); }
static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data) { int is_tag = starts_with(path, "refs/tags/"); struct object_id peeled; int is_annotated, prio; /* Reject anything outside refs/tags/ unless --all */ if (!all && !is_tag) return 0; /* Accept only tags that match the pattern, if given */ if (pattern && (!is_tag || wildmatch(pattern, path + 10, 0, NULL))) return 0; /* Is it annotated? */ if (!peel_ref(path, peeled.hash)) { is_annotated = !!oidcmp(oid, &peeled); } else { oidcpy(&peeled, oid); is_annotated = 0; } /* * By default, we only use annotated tags, but with --tags * we fall back to lightweight ones (even without --tags, * we still remember lightweight ones, only to give hints * in an error message). --all allows any refs to be used. */ if (is_annotated) prio = 2; else if (is_tag) prio = 1; else prio = 0; add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash); return 0; }
static int wildmatch (char *s1, char *s2) { if (s1 == NULL) s1 = ""; if (s2 == NULL) s2 = ""; while (*s1 && (*s2 || *s1 == '*')) { if (tolower (*s1) != tolower (*s2) && *s1 != '?' && *s1 != '*') return 0; if (*s2) { if (*s1 == '*') { ++s1; if (!*s1) return 1; while (*s2) { if (wildmatch (s1, s2)) return 1; ++s2; } return 0; } ++s2; } ++s1; } if (*s1 || *s2) return 0; else return 1; }
// .FindAllByName("name", 0) - returns a table with indexes 1->N containing all entities on the map with matching names. // If the second parameter is supplied, it's a bool indicating whether to use wildcard matching or not int entity_FindAllByName(lua_State* ls) { DEBUGOUT("entity_FindAllByName"); luaCountArgs(ls, 1); ASSERT(game->mMap); string name = lua_tostring(ls, 1); bool useWildmatch = false; int numArgs = lua_gettop(ls); if (numArgs > 1) useWildmatch = lua_tonumber(ls, 2); //Construct a table to store all entities lua_newtable(ls); int top = lua_gettop(ls); Entity* e; int index = 1; //Table keys will be index numbers, starting at 1 (common for lua arrays) for (int i = 0; i < game->mMap->mEntities.size(); ++i) { e = game->mMap->mEntities.at(i); //if it matches the search, add to table if ( (useWildmatch && wildmatch(name.c_str(), e->GetName().c_str())) || (!useWildmatch && e->GetName() == name) ) { lua_pushnumber(ls, index); lua_pushlightuserdata(ls, e); lua_settable(ls, top); ++index; } } return 1; }
tstring AppSettings::FindMaterial(const tstring& fname) const { TCHAR buffer[MAX_PATH]; // Simply check for fully qualified path if (!PathIsRelative(fname.c_str())) { if (-1 != _taccess(fname.c_str(), 0)) return fname; } // Test if its relative and in one of the specified root paths for (tstringlist::const_iterator itr = materialRootPaths.begin(), end = materialRootPaths.end(); itr != end; ++itr) { PathCombine(buffer, itr->c_str(), fname.c_str()); if (-1 != _taccess(buffer, 0)) { return tstring(buffer); } } for (LPCTSTR filepart = PathFindNextComponent(fname.c_str()); filepart != nullptr; filepart = PathFindNextComponent(filepart)) { if (wildmatch(TEXT("materials\\*"), filepart)) { return FindMaterial(fname); } } return fname; }
static int match_hostname(char *host, char *tok) { if (!host || !*host) return 0; return wildmatch(tok, host); }
int doname(nameblkp p, int reclevel, time_t *tval, int nowait) { int errstat; int okdel1; int didwork; int len; time_t td, td1, tdep, ptime, ptime1; depblkp q; depblkp qtemp, suffp, suffp1; nameblkp p1, p2; struct shblock *implcom, *explcom; lineblkp lp; lineblkp lp1, lp2; char sourcename[100], prefix[100], temp[100], concsuff[20]; char *stem; char *pnamep, *p1namep; chainp allchain, qchain; char qbuf[QBUFMAX], tgsbuf[QBUFMAX]; wildp wp; int nproc1; char *lastslash, *s; if(p == 0) { *tval = 0; return 0; } if(dbgflag) { printf("doname(%s,%d)\n",p->namep,reclevel); fflush(stdout); } if(p->done > 0) { *tval = p->modtime; return (p->done == 3); } errstat = 0; tdep = 0; implcom = 0; explcom = 0; ptime = exists(p->namep); ptime1 = 0; didwork = NO; p->done = 1; /* avoid infinite loops */ nproc1 = nproc; /* current depth of process stack */ qchain = NULL; allchain = NULL; /* define values of Bradford's $$@ and $$/ macros */ for(s = lastslash = p->namep; *s; ++s) if(*s == '/') lastslash = s; setvar("$@", p->namep, YES); setvar("$/", lastslash, YES); /* expand any names that have embedded metacharacters */ for(lp = p->linep ; lp ; lp = lp->nxtlineblock) for(q = lp->depp ; q ; q=qtemp ) { qtemp = q->nxtdepblock; expand(q); } /* make sure all dependents are up to date */ for(lp = p->linep ; lp ; lp = lp->nxtlineblock) { td = 0; for(q = lp->depp ; q ; q = q->nxtdepblock) if(q->depname) { errstat += doname(q->depname, reclevel+1, &td1, q->nowait); if(dbgflag) printf("TIME(%s)=%ld\n",q->depname->namep, td1); if(td1 > td) td = td1; if(ptime < td1) qchain = appendq(qchain, q->depname->namep); allchain = appendq(allchain, q->depname->namep); } if(p->septype == SOMEDEPS) { if(lp->shp) if( ptime<td || (ptime==0 && td==0) || lp->depp==0) { okdel1 = okdel; okdel = NO; set3var("@", p->namep); setvar("?", mkqlist(qchain,qbuf), YES); setvar("^", mkqlist(allchain,tgsbuf), YES); qchain = NULL; if( !questflag ) errstat += docom(lp->shp, nowait, nproc1); set3var("@", CHNULL); okdel = okdel1; ptime1 = prestime(); didwork = YES; } } else { if(lp->shp != 0) { if(explcom) fprintf(stderr, "Too many command lines for `%s'\n", p->namep); else explcom = lp->shp; } if(td > tdep) tdep = td; } } /* Look for implicit dependents, using suffix rules */ for(lp = sufflist ; lp ; lp = lp->nxtlineblock) for(suffp = lp->depp ; suffp ; suffp = suffp->nxtdepblock) { pnamep = suffp->depname->namep; if(suffix(p->namep , pnamep , prefix)) { (void)srchdir(concat(prefix,"*",temp), NO, (depblkp) NULL); for(lp1 = sufflist ; lp1 ; lp1 = lp1->nxtlineblock) for(suffp1=lp1->depp; suffp1 ; suffp1 = suffp1->nxtdepblock) { p1namep = suffp1->depname->namep; if( (p1=srchname(concat(p1namep, pnamep ,concsuff))) && (p2=srchname(concat(prefix, p1namep ,sourcename))) ) { errstat += doname(p2, reclevel+1, &td, NO); if(ptime < td) qchain = appendq(qchain, p2->namep); if(dbgflag) printf("TIME(%s)=%ld\n", p2->namep, td); if(td > tdep) tdep = td; set3var("*", prefix); set3var("<", copys(sourcename)); for(lp2=p1->linep ; lp2 ; lp2 = lp2->nxtlineblock) if(implcom = lp2->shp) break; goto endloop; } } } } /* Look for implicit dependents, using pattern matching rules */ len = strlen(p->namep); for(wp = firstwild ; wp ; wp = wp->next) if(stem = wildmatch(wp, p->namep, len) ) { lp = wp->linep; for(q = lp->depp; q; q = q->nxtdepblock) { if(dbgflag>1 && q->depname) fprintf(stderr,"check dep of %s on %s\n", p->namep, wildsub(q->depname->namep,stem)); if(q->depname && ! chkname(wildsub(q->depname->namep,stem))) break; } if(q) /* some name not found, go to next line */ continue; for(q = lp->depp; q; q = q->nxtdepblock) { nameblkp tamep; if(q->depname == NULL) continue; tamep = srchname( wildsub(q->depname->namep,stem)); /*TEMP fprintf(stderr,"check dep %s on %s =>%s\n",p->namep,q->depname->namep,tamep->namep);*/ /*TEMP*/if(dbgflag) printf("%s depends on %s. stem=%s\n", p->namep,tamep->namep, stem); errstat += doname(tamep, reclevel+1, &td, q->nowait); if(ptime < td) qchain = appendq(qchain, tamep->namep); allchain = appendq(allchain, tamep->namep); if(dbgflag) printf("TIME(%s)=%ld\n", tamep->namep, td); if(td > tdep) tdep = td; set3var("<", copys(tamep->namep) ); } set3var("*", stem); setvar("%", stem, YES); implcom = lp->shp; goto endloop; } endloop: if(errstat==0 && (ptime<tdep || (ptime==0 && tdep==0) ) ) { ptime = (tdep>0 ? tdep : prestime() ); set3var("@", p->namep); setvar("?", mkqlist(qchain,qbuf), YES); setvar("^", mkqlist(allchain,tgsbuf), YES); if(explcom) errstat += docom(explcom, nowait, nproc1); else if(implcom) errstat += docom(implcom, nowait, nproc1); else if(p->septype == 0) if(p1=srchname(".DEFAULT")) { set3var("<", p->namep); for(lp2 = p1->linep ; lp2 ; lp2 = lp2->nxtlineblock) if(implcom = lp2->shp) { errstat += docom(implcom, nowait,nproc1); break; } } else if(keepgoing) { printf("Don't know how to make %s\n", p->namep); ++errstat; } else fatal1(" Don't know how to make %s", p->namep); set3var("@", CHNULL); if(noexflag || nowait || (ptime = exists(p->namep)) == 0 ) ptime = prestime(); } else if(errstat!=0 && reclevel==0) printf("`%s' not remade because of errors\n", p->namep); else if(!questflag && reclevel==0 && didwork==NO) printf("`%s' is up to date.\n", p->namep); if(questflag && reclevel==0) exit(ndocoms>0 ? -1 : 0); p->done = (errstat ? 3 : 2); if(ptime1 > ptime) ptime = ptime1; p->modtime = ptime; *tval = ptime; return errstat; }
int fnmatch_icase(const char *pattern, const char *string, int flags) { return wildmatch(pattern, string, flags | (ignore_case ? WM_CASEFOLD : 0), NULL); }
FILE *fopenlog(char *name, char logtype[14], flag *ispipe) /* [<][>][^][v][top][bottom][index][help] */ { /* open a logfile with a particular name for reading */ #ifndef NOPIPES extern FILE *popen(); #endif extern char *commandname; #ifndef NOPIPES extern struct loglist *uncompresshead; #endif extern flag warnq, anywarns, stdin_used; extern int debug; FILE *f; #ifndef NOPIPES struct loglist *uncompressp; char *w1, *w2; char command[MAXSTRINGLENGTH]; #endif *ispipe = OFF; if (STREQ(name, "stdin") || STREQ(name, "-")) { if (stdin_used) { if (warnq) { fprintf(stderr, "%s: Warning: stdin already used; cannot use it as %s\n", commandname, logtype); anywarns = ON; } } else { f = stdin; stdin_used = ON; if (debug > 0) fprintf(stderr, "F: Opening stdin as %s\n", logtype); } } else { #ifdef VMS f = fopen(name, "r", "shr=upd"); #else f = fopen(name, "r"); #endif if (f == NULL) { if (warnq) { fprintf(stderr, "%s: Warning: Failed to open %s %s: ignoring it\n", commandname, logtype, name); anywarns = ON; } } else { if (debug > 0) fprintf(stderr, "F: Opening %s as %s\n", name, logtype); #ifndef NOPIPES for (uncompressp = uncompresshead; uncompressp -> name[0] != '\0' && !(*ispipe); uncompressp = uncompressp -> next) { if (wildmatch(name, uncompressp -> name, &w1, &w2)) { fclose(f); strcpy(command, uncompressp -> prefix); strcat(command, " "); strncat(command, name, MAXSTRINGLENGTH - strlen(command) - 1); f = popen(command, "r"); *ispipe = ON; if (debug > 0) fprintf(stderr, "F: Using %s to uncompress it\n", uncompressp -> prefix); } } #endif } } return(f); }
int wildmatch(const char *pattern, const char *string, int flags) { const char *stringstart; const char *newp; const char *slash; char c, test; char prev; int wild = 0; /* WM_WILDSTAR implies WM_PATHNAME. */ if (check_flag(flags, WM_WILDSTAR)) { flags |= WM_PATHNAME; } for (stringstart = string;;) { switch (c = *pattern++) { case EOS: if (check_flag(flags, WM_LEADING_DIR) && *string == '/') return WM_MATCH; return (*string == EOS) ? WM_MATCH : WM_NOMATCH; case '?': if (*string == EOS) return WM_NOMATCH; if (*string == '/' && check_flag(flags, WM_PATHNAME)) return WM_NOMATCH; if (*string == '.' && check_flag(flags, WM_PERIOD) && (string == stringstart || (check_flag(flags, WM_PATHNAME) && *(string - 1) == '/'))) return WM_NOMATCH; ++string; break; case '*': c = *pattern; wild = check_flag(flags, WM_WILDSTAR) && c == '*'; if (wild) { prev = pattern[-2]; /* Collapse multiple stars and slash-** patterns, * e.g. "** / *** / **** / **" (without spaces) * is treated as a single ** wildstar. */ while (c == '*') { c = *++pattern; } while (c == '/' && pattern[1] == '*' && pattern[2] == '*') { prev = c; c = *++pattern; while (c == '*') { c = *++pattern; } } if (c == '/' && wildmatch(pattern+1, string, flags) == WM_MATCH) { return WM_MATCH; } } else { /* Collapse multiple stars. */ while (c == '*') { c = *++pattern; } } if (!wild && *string == '.' && check_flag(flags, WM_PERIOD) && (string == stringstart || (check_flag(flags, WM_PATHNAME) && *(string - 1) == '/'))) { return WM_NOMATCH; } /* Optimize for pattern with * or ** at end or before /. */ if (c == EOS) { if (wild && prev == '/') { return WM_MATCH; } if (check_flag(flags, WM_PATHNAME)) { return (check_flag(flags, WM_LEADING_DIR) || strchr(string, '/') == NULL ? WM_MATCH : WM_NOMATCH); } else { return WM_MATCH; } } else if (c == '/') { if (wild) { slash = strchr(stringstart, '/'); if (!slash) { return WM_NOMATCH; } while (slash) { if (wildmatch(pattern+1, slash+1, flags) == 0) { return WM_MATCH; } slash = strchr(slash+1, '/'); } } else { if (check_flag(flags, WM_PATHNAME)) { if ((string = strchr(string, '/')) == NULL) { return WM_NOMATCH; } } } } else if (wild) { return WM_NOMATCH; } /* General case, use recursion. */ while ((test = *string) != EOS) { if (!wildmatch(pattern, string, flags & ~WM_PERIOD)) return WM_MATCH; if (test == '/' && check_flag(flags, WM_PATHNAME)) break; ++string; } return WM_NOMATCH; case '[': if (*string == EOS) return WM_NOMATCH; if (*string == '/' && check_flag(flags, WM_PATHNAME)) return WM_NOMATCH; if (*string == '.' && check_flag(flags, WM_PERIOD) && (string == stringstart || (check_flag(flags, WM_PATHNAME) && *(string - 1) == '/'))) return WM_NOMATCH; switch (rangematch(pattern, *string, flags, &newp)) { case RANGE_ERROR: /* not a good range, treat as normal text */ ++string; goto normal; case RANGE_MATCH: pattern = newp; break; case RANGE_NOMATCH: return (WM_NOMATCH); } ++string; break; case '\\': if (!check_flag(flags, WM_NOESCAPE)) { if ((c = *pattern++) == EOS) { c = '\\'; --pattern; if (*(string+1) == EOS) { return WM_NOMATCH; } } } /* FALLTHROUGH */ default: normal: if (c != *string && !(check_flag(flags, WM_CASEFOLD) && (tolower((unsigned char)c) == tolower((unsigned char)*string)))) return WM_NOMATCH; ++string; break; } /* NOTREACHED */ } }