static STRPTR pattern_helper (const char *pat) { char *pdup; const char *p; int n; for (n = 0, p = pat; *p != '\0'; ++p, ++n) { if ((p = strchr (p, '*')) == NULL) break; } if (n == 0) pdup = SafeStrdup(pat); else { /* replace each "*" by "#?" */ n += (int) strlen(pat) + 1; pdup = (char *) SafeMalloc (n); for (n = 0, p = pat; *p != '\0'; ++p, ++n) { if (*p != '*') pdup[n] = *p; else { pdup[n] = '#'; ++n; pdup[n] = '?'; } } pdup[n] = '\0'; } return (STRPTR) pdup; }
const char *Q_FindFirstFile (const char *path, const char *pattern) { if (finddir) COM_Error ("FindFirst without FindClose"); finddir = opendir (path); if (!finddir) return NULL; findpattern = SafeStrdup (pattern); findpath = SafeStrdup (path); if (*findpath != '\0') { /* searching under "/" won't be a good idea, for example.. */ size_t siz = strlen(findpath) - 1; if (findpath[siz] == '/' || findpath[siz] == '\\') findpath[siz] = '\0'; } return Q_FindNextFile(); }
// Given two type descriptors for reference types (i.e. the initial code // letter is 'A'), return the type descriptor for their lub in the // lattice of types. // Note: the result is a string whose storage is allocated on the heap. // The caller should eventually deallocate it using SafeFree. char *LUB( char *type1, char *type2 ) { int cnt1, cnt2, i, j; char **path1, **path2, *result; if (type1[0] != 'A' || type2[1] != 'A') return "X"; path1 = AncestorTypes(type1, &cnt1); path2 = AncestorTypes(type2, &cnt2); result = "ALjava/lang/Object"; // default result i = cnt1; j = cnt2; while( i-- > 0 && j-- > 0 ) { if (strcmp(path1[i], path2[j]) != 0) break; result = path1[i]; } result = SafeStrdup(result); FreeTypeDescriptorArray(path1, cnt1); FreeTypeDescriptorArray(path2, cnt2); return result; }