lztrie loadLZTrie(FILE *f) { lztrie T; uint i,*ids; unsigned long long aux; T = malloc (sizeof(struct slztrie)); // loads n, the number of nodes in LZTrie if (fread(&T->n,sizeof(uint),1,f) != 1) { fprintf(stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } // loads the parentheses structure of LZTrie T->pdata = loadParentheses(f, 2*T->n,true); T->data = T->pdata->data; // loads the letters labeling the edges of the trie, in preorder T->letters = malloc(T->n*sizeof(byte)); if (fread(T->letters,sizeof(byte),T->n,f) != T->n) { fprintf(stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } T->ids = loadPerm(f); // boost first access T->boost = malloc(256*sizeof(trieNode)); for (i=0;i<256;i++) T->boost[i] = NULLT; i = 1; // shortcut for first child of root while (i != 2*T->n-1) { // shortcut for its closing parenthesis T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i; // shortcut for leftrankLZTrie i = findclose(T->pdata,i)+1; } return T; }
trieNode childLZTrie(lztrie T, trieNode i, byte c) { trieNode j; byte tc, *letters; bitmap bdata; parentheses pdata; #ifdef QUERYREPORT CALLS++; #endif if (i == ROOT) return T->boost[c]; j = i+1; letters = T->letters; bdata = T->pdata->bdata; pdata = T->pdata; while (!bitget1(T->data,j)) { // there is a child here tc = letters[j-rank(bdata,j)]; // shortcut for leftrankLZTrie: is a child by letter c? if (tc > c) break; if (tc == c) return j; j = findclose(pdata,j)+1; #ifdef QUERYREPORT JUMPS++; #endif } return NULLT; // no child to go down by c }
void hb_fsFindClose( PHB_FFIND ffind ) { if( ffind ) { if( ffind->pszFree ) hb_xfree( ffind->pszFree ); /* Do platform dependant cleanup */ if( ffind->info ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; if( ! ffind->bFirst ) { hb_vmUnlock(); #if defined( HB_OS_DOS ) # if defined( __WATCOMC__ ) _dos_findclose( &info->entry ); # elif ! defined( __DJGPP__ ) && ! defined( __BORLANDC__ ) findclose( &info->entry ); # endif #elif defined( HB_OS_OS2 ) if( info->hFindFile != HDIR_CREATE ) DosFindClose( info->hFindFile ); if( info->entry ) DosFreeMem( info->entry ); #elif defined( HB_OS_WIN ) if( info->hFindFile != INVALID_HANDLE_VALUE ) FindClose( info->hFindFile ); #elif defined( HB_OS_UNIX ) if( info->dir ) closedir( info->dir ); #else { /* Intentionally do nothing */ int iTODO; /* TODO: for given platform */ } #endif hb_vmLock(); } hb_xfree( info ); } hb_xfree( ffind ); } }
int main() { int c; c = 255; findclose(c); return 0; }
Boolean isDir( const char *str ) { Boolean result; finddata ff; intptr_t fh = findfirst( str, &ff ); result = Boolean( fh != -1 && (ff.attrib & FA_DIREC) != 0 ); findclose(fh); return result; }
int findclose(int c) { int d; while((d = getchar())!=EOF) { if(d == '{') { findclose('}'); } else if(d == '[') { findclose(']'); } else if(d == '(') { findclose(')'); } else if(d == '/') { if ((d = getchar()) == '*') in_comment(); } else if(d == '\'' || d == '"') { echo_quote(d); } else if(c == d) { return 0; } else if(d == '}' || d == ']' || d == ')') { printf("find %c, unexpected %c\nexit.\n", c, d); _exit(-1); } } if(c != 255) { printf("not match, %c\n", c); _exit(-1); } printf("ok\n"); return 0; }
trieNode childRevTrie(revtrie T, trieNode i, uint depth, byte c, trieNode *lzl, trieNode *lzr) { trieNode j; trieNode jlz; uint d,pos,jid; byte tc; uint *data; lztrie LZT = T->trie; #ifdef QUERYREPORT BCALLS++; #endif j = i+1; #ifdef QUERYREPORT DEPTH1 += depth; #endif data = T->data; while (!bitget1(data,j)) { // there is a child here pos = leftrankRevTrie(T,j); jid = rthRevTrie(T,pos); // leftmost id in subtree jlz = NODE(LZT,jid); for (d=depth;d;d--) jlz = parentLZTrie(LZT,jlz); #ifdef QUERYREPORT RJUMPS++; DEPTH += depth; #endif tc = letterLZTrie(LZT,jlz); if (tc > c) break; if (tc == c) { *lzl = jlz; if ((pos < T->n-1) && (rthRevTrie(T,pos+1)==jid) /*(isemptyRevTrie(T,j))*/) { // empty pos = rightrankRevTrie(T,j); jlz = NODE(LZT,rthRevTrie(T,pos)); // rightmost for (d=depth;d;d--) jlz = parentLZTrie(LZT,jlz); *lzr = jlz; } else *lzr = NULLT; return j; } j = findclose(T->pdata,j)+1; } *lzl = *lzr = NULLT; return NULLT; // no child to go down by c }
trieNode childRevTrie(revtrie T, trieNode i, uint depth, byte c, trieNode *lzl, trieNode *lzr) { trieNode j; trieNode jlz; uint d,pos,jid; byte tc; #ifdef QUERYREPORT BCALLS++; #endif j = i+1; #ifdef QUERYREPORT DEPTH1 += depth; #endif while (!bitget1(T->data,j)) { // there is a child here pos = leftrankRevTrie(T,j); jlz = mapto(T->Rev, getposRevTrie(T,pos)); for (d=depth;d;d--) jlz = parentLZTrie(T->trie,jlz); #ifdef QUERYREPORT RJUMPS++; DEPTH += depth; #endif tc = letterLZTrie(T->trie,jlz); if (tc > c) break; if (tc == c) { *lzl = jlz; if ((pos < T->n-1) && //(rthRevTrie(T,pos+1)==jid) (isemptyRevTrie(T,j))) { // empty pos = rightrankRevTrie(T,j); jlz = mapto(T->Rev, getposRevTrie(T,pos)); for (d=depth;d;d--) jlz = parentLZTrie(T->trie,jlz); *lzr = jlz; } else *lzr = NULLT; return j; } j = findclose(T->pdata,j)+1; } *lzl = *lzr = NULLT; return NULLT; // no child to go down by c }
lztrie createLZTrie(uint *string, byte *letters, uint *id, uint n) { lztrie T; uint i; T = malloc(sizeof(struct slztrie)); T->data = string; T->pdata = createParentheses(string,2*n,true,true); T->n = n; T->letters = letters; // creates the ids permutation T->ids = createPerm(id, n, PARAMETER_T_IDS); // boost first access T->boost = malloc(256*sizeof(trieNode)); for (i=0;i<256;i++) T->boost[i] = NULLT; i = 1; // shortcut for first child of root while (i != 2*n-1) { // shortcut for its closing parenthesis T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i; // shortcut for leftrankLZTrie i = findclose(T->pdata,i)+1; } return T; }
lztrie loadLZTrie (FILE *f) { lztrie T; uint i; T = malloc (sizeof(struct slztrie)); if (fread (&T->n,sizeof(uint),1,f) != 1) { fprintf (stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } T->data = malloc (((2*T->n+W-1)/W)*sizeof(uint)); if (fread (T->data,sizeof(uint),(2*T->n+W-1)/W,f) != (2*T->n+W-1)/W) { fprintf (stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } T->pdata = createParentheses (T->data,2*T->n,true); T->nbits = bits(T->n-1); T->letters = malloc (T->n*sizeof(byte)); if (fread (T->letters,sizeof(byte),T->n,f) != T->n) { fprintf (stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } T->id = malloc (((T->n*T->nbits+W-1)/W)*sizeof(uint)); if (fread (T->id,sizeof(uint),(T->n*T->nbits+W-1)/W,f) != (T->n*T->nbits+W-1)/W) { fprintf (stderr,"Error: Cannot read LZTrie from file\n"); exit(1); } // boost first access T->boost = malloc (256*sizeof(trieNode)); for (i=0;i<256;i++) T->boost[i] = NULLT; i = 1; // shortcut for first child of root while (i != 2*T->n-1) // shortcut for its closing parenthesis { T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i; // shortcut for leftrankLZTrie i = findclose(T->pdata,i)+1; } return T; }
lztrie createLZTrie (uint *string, byte *letters, uint *id, uint n) { lztrie T; uint i; T = malloc (sizeof(struct slztrie)); T->data = string; T->pdata = createParentheses (string,2*n,true); T->n = n; T->nbits = bits(n-1); T->letters = letters; T->id = malloc (((n*T->nbits+W-1)/W)*sizeof(uint)); for (i=0;i<n;i++) bitput (T->id,i*T->nbits,T->nbits,id[i]); // boost first access T->boost = malloc (256*sizeof(trieNode)); for (i=0;i<256;i++) T->boost[i] = NULLT; i = 1; // shortcut for first child of root while (i != 2*n-1) // shortcut for its closing parenthesis { T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i; // shortcut for leftrankLZTrie i = findclose(T->pdata,i)+1; } return T; }
void TDirListBox::showDirs( TDirCollection *dirs ) { const indentSize = 2; int indent = indentSize; char buf[MAXPATH+16]; memset( buf, ' ', sizeof( buf ) ); char *name = buf + sizeof(buf) - (MAXFILE+MAXEXT); char *org = name - strlen(pathDir); strcpy( org, pathDir ); char *curDir = dir; char *end = dir + 3; char hold = *end; *end = EOS; // mark end of drive name strcpy( name, curDir ); dirs->insert( new TDirEntry( org, name ) ); *end = hold; // restore full path curDir = end; while( (end = strchr( curDir, '\\' )) != 0 ) { *end = EOS; strncpy( name, curDir, size_t(end-curDir) ); name[size_t(end-curDir)] = EOS; dirs->insert( new TDirEntry( org - indent, dir ) ); *end = '\\'; curDir = end+1; indent += indentSize; } cur = dirs->getCount() - 1; end = strrchr( dir, '\\' ); char path[MAXPATH]; strncpy( path, dir, size_t(end-dir+1) ); end = path + unsigned(end-dir)+1; strcpy( end, "*.*" ); Boolean isFirst = True; ffblk ff; int res = findfirst( path, &ff, FA_DIREC ); while( res == 0 ) { if( (ff.ff_attrib & FA_DIREC) != 0 && ff.ff_name[0] != '.' ) { if( isFirst ) { memcpy( org, firstDir, strlen(firstDir)+1 ); isFirst = False; } else memcpy( org, middleDir, strlen(middleDir)+1 ); strcpy( name, ff.ff_name ); strcpy( end, ff.ff_name ); dirs->insert( new TDirEntry( org - indent, path ) ); } res = findnext( &ff ); } findclose( &ff ); char *p = dirs->at(dirs->getCount()-1)->text(); char *i = strchr( p, graphics[0] ); if( i == 0 ) { i = strchr( p, graphics[1] ); if( i != 0 ) *i = graphics[0]; } else { *(i+1) = graphics[2]; *(i+2) = graphics[2]; } }
uint rightrankRevTrie(revtrie T, trieNode i) { trieNode j; j = findclose(T->pdata,i); return j-rank(T->pdata->bdata,j)-1; }
bool ancestorRevTrie(revtrie T, trieNode i, trieNode j) { return (i <= j) && (j < findclose(T->pdata,i)); }
uint subtreesizeRevTrie(revtrie T, trieNode i) { trieNode j; j = findclose(T->pdata,i); return (j-i+1)/2; }
int main(int argc, register char** argv) { register int n; register char* s; char* args; char* codes; char** av; char** ap; int i; int count; int len; int traverse; int size; Dir_t* firstdir; Dir_t* lastdir; Exnode_t* x; Exnode_t* y; Ftw_t ftw; Finddisc_t disc; setlocale(LC_ALL, ""); error_info.id = "tw"; av = argv + 1; args = 0; codes = 0; count = 0; size = 0; traverse = 1; firstdir = lastdir = newof(0, Dir_t, 1, 0); firstdir->name = "."; state.action = LIST; state.cmdflags = CMD_EXIT|CMD_IGNORE|CMD_IMPLICIT|CMD_NEWLINE; state.errexit = EXIT_QUIT; state.ftwflags = ftwflags()|FTW_DELAY; state.select = ALL; state.separator = '\n'; memset(&disc, 0, sizeof(disc)); for (;;) { switch (optget(argv, usage)) { case 'a': args = opt_info.arg; state.cmdflags |= CMD_POST; continue; case 'c': if ((count = opt_info.num) < 0) error(3, "argument count must be >= 0"); continue; case 'd': lastdir = lastdir->next = newof(0, Dir_t, 1, 0); lastdir->name = opt_info.arg; continue; case 'e': compile(opt_info.arg, 0); continue; case 'f': state.pattern = opt_info.arg; continue; case 'i': state.ignore = 1; continue; case 'l': state.localfs = 1; continue; case 'm': state.intermediate = 1; continue; case 'n': traverse = 0; continue; case 'p': state.ftwflags |= FTW_TWICE; continue; case 'q': state.cmdflags |= CMD_QUERY; continue; case 'r': state.ftwflags |= FTW_RECURSIVE; continue; case 's': if ((size = opt_info.num) < 0) error(3, "command size must be >= 0"); continue; case 't': state.cmdflags |= CMD_TRACE; continue; case 'x': state.errexit = opt_info.arg ? opt_info.num : EXIT_QUIT; continue; case 'z': if (s = sfgetr(sfstdin, '\n', 1)) { if (!(s = strdup(s))) error(ERROR_SYSTEM|3, "out of space"); n = state.snapshot.format.delim = *s++; state.snapshot.format.path = s; if (!(s = strchr(s, n))) { osnap: error(3, "invalid snapshot on standard input"); } *s++ = 0; if (!streq(state.snapshot.format.path, SNAPSHOT_ID)) goto osnap; state.snapshot.format.path = s; if (!(s = strchr(s, n))) goto osnap; *s++ = 0; state.snapshot.format.easy = s; if (!(s = strchr(s, n))) goto osnap; *s++ = 0; if (*(state.snapshot.format.hard = s)) { if (!(s = strchr(s, n))) goto osnap; *s = 0; } else state.snapshot.format.hard = 0; state.snapshot.sp = sfstdin; state.snapshot.prev = sfgetr(sfstdin, '\n', 0); } else { state.snapshot.format.path = SNAPSHOT_PATH; state.snapshot.format.easy = SNAPSHOT_EASY; state.snapshot.format.hard = SNAPSHOT_HARD; state.snapshot.format.delim = SNAPSHOT_DELIM[0]; } if (!(state.snapshot.tmp = sfstropen())) error(ERROR_SYSTEM|3, "out of space"); compile("sort:name;", 0); continue; case 'C': state.ftwflags |= FTW_NOSEEDOTDIR; continue; case 'D': error_info.trace = -opt_info.num; continue; case 'E': compile(opt_info.arg, 1); continue; case 'F': codes = opt_info.arg; continue; case 'G': disc.flags |= FIND_GENERATE; if (streq(opt_info.arg, "old")) disc.flags |= FIND_OLD; else if (streq(opt_info.arg, "gnu") || streq(opt_info.arg, "locate")) disc.flags |= FIND_GNU; else if (streq(opt_info.arg, "type")) disc.flags |= FIND_TYPE; else if (streq(opt_info.arg, "?")) { error(2, "formats are { default|dir type old gnu|locate }"); return 0; } else if (!streq(opt_info.arg, "-") && !streq(opt_info.arg, "default") && !streq(opt_info.arg, "dir")) error(3, "%s: invalid find codes format -- { default|dir type old gnu|locate } expected", opt_info.arg); continue; case 'H': state.ftwflags |= FTW_META|FTW_PHYSICAL; continue; case 'I': state.icase = 1; continue; case 'L': state.ftwflags &= ~(FTW_META|FTW_PHYSICAL|FTW_SEEDOTDIR); continue; case 'P': state.ftwflags &= ~FTW_META; state.ftwflags |= FTW_PHYSICAL; continue; case 'S': state.separator = *opt_info.arg; continue; case 'X': state.ftwflags |= FTW_MOUNT; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; argc -= opt_info.index; if (error_info.errors) error(ERROR_USAGE|4, "%s", optusage(NiL)); /* * do it */ if (state.snapshot.tmp) sfprintf(sfstdout, "%c%s%c%s%c%s%c%s%c\n", state.snapshot.format.delim, SNAPSHOT_ID, state.snapshot.format.delim, state.snapshot.format.path, state.snapshot.format.delim, state.snapshot.format.easy, state.snapshot.format.delim, state.snapshot.format.hard ? state.snapshot.format.hard : "", state.snapshot.format.delim); if (x = exexpr(state.program, "begin", NiL, 0)) eval(x, NiL); if ((x = exexpr(state.program, "select", NiL, INTEGER)) || (x = exexpr(state.program, NiL, NiL, INTEGER))) state.select = x; if (!(state.ftwflags & FTW_PHYSICAL)) state.ftwflags &= ~FTW_DELAY; memset(&ftw, 0, sizeof(ftw)); ftw.path = ftw.name = ""; if (traverse) { if (x = exexpr(state.program, "action", NiL, 0)) state.action = x; if (x = exexpr(state.program, "sort", NiL, 0)) { state.sortkey = x; y = 0; for (;;) { switch (x->op) { case ',': y = x->data.operand.right; /*FALLTHROUGH*/ case '!': case '~': case S2B: case X2I: x = x->data.operand.left; continue; case ID: if (!(x = y)) break; y = 0; continue; default: error(3, "invalid sort identifier (op 0x%02x)", x->op); break; } break; } state.sort = order; } if (*argv && (*argv)[0] == '-' && (*argv)[1] == 0) { state.ftwflags |= FTW_LIST; argv++; argc--; } if (*argv || args || count || !(state.cmdflags & CMD_IMPLICIT)) { Cmddisc_t disc; CMDDISC(&disc, state.cmdflags, errorf); state.cmd = cmdopen(argv, count, size, args, &disc); state.ftwflags |= FTW_DOT; } else state.cmdflags &= ~CMD_IMPLICIT; if (codes && (disc.flags & FIND_GENERATE)) { char* p; Dir_t* dp; char pwd[PATH_MAX]; char tmp[PATH_MAX]; disc.version = FIND_VERSION; if (state.cmdflags & CMD_TRACE) disc.flags |= FIND_TYPE; if (state.cmdflags & CMD_QUERY) disc.flags |= FIND_OLD; disc.errorf = errorf; if (!(state.find = findopen(codes, NiL, NiL, &disc))) exit(2); if (disc.flags & FIND_TYPE) { state.act = ACT_CODETYPE; compile("_tw_init:mime;", 0); state.magicdisc.flags |= MAGIC_MIME; } else state.act = ACT_CODE; state.icase = 1; state.pattern = 0; state.sort = order; if (!state.program) compile("1", 0); if (!(state.sortkey = newof(0, Exnode_t, 1, 0)) || !(state.sortkey->data.variable.symbol = (Exid_t*)dtmatch(state.program->symbols, "name"))) error(ERROR_SYSTEM|3, "out of space"); state.sortkey->op = ID; s = p = 0; for (dp = (firstdir == lastdir) ? firstdir : firstdir->next; dp; dp = dp->next) { if (*(s = dp->name) == '/') sfsprintf(tmp, sizeof(tmp), "%s", s); else if (!p && !(p = getcwd(pwd, sizeof(pwd)))) error(ERROR_SYSTEM|3, "cannot determine pwd path"); else sfsprintf(tmp, sizeof(tmp), "%s/%s", p, s); pathcanon(tmp, sizeof(tmp), PATH_PHYSICAL); if (!(dp->name = strdup(tmp))) error(ERROR_SYSTEM|3, "out of space [PATH_PHYSICAL]"); } } else if (state.snapshot.tmp) state.act = ACT_SNAPSHOT; else if (state.cmdflags & CMD_IMPLICIT) state.act = ACT_CMDARG; else if (state.action == LIST) state.act = ACT_LIST; else if (state.action) state.act = ACT_EVAL; if (state.intermediate) { state.actII = state.act; state.act = ACT_INTERMEDIATE; } if (state.pattern) { disc.version = FIND_VERSION; if (state.icase) disc.flags |= FIND_ICASE; disc.errorf = errorf; disc.dirs = ap = av; if (firstdir != lastdir) firstdir = firstdir->next; do {*ap++ = firstdir->name;} while (firstdir = firstdir->next); *ap = 0; if (!(state.find = findopen(codes, state.pattern, NiL, &disc))) exit(1); state.ftwflags |= FTW_TOP; n = state.select == ALL ? state.act : ACT_EVAL; while (s = findread(state.find)) { switch (n) { case ACT_CMDARG: if ((i = cmdarg(state.cmd, s, strlen(s))) >= state.errexit) exit(i); break; case ACT_LIST: sfputr(sfstdout, s, '\n'); break; default: ftwalk(s, tw, state.ftwflags, NiL); break; } } } else if (state.ftwflags & FTW_LIST) { sfopen(sfstdin, NiL, "rt"); n = state.select == ALL && state.act == ACT_CMDARG; for (;;) { if (s = sfgetr(sfstdin, state.separator, 1)) len = sfvalue(sfstdin) - 1; else if (state.separator != '\n') { state.separator = '\n'; continue; } else if (s = sfgetr(sfstdin, state.separator, -1)) len = sfvalue(sfstdin); else break; if (!n) ftwalk(s, tw, state.ftwflags, NiL); else if ((i = cmdarg(state.cmd, s, len)) >= state.errexit) exit(i); } if (sferror(sfstdin)) error(ERROR_SYSTEM|2, "input read error"); } else if (firstdir == lastdir) ftwalk(firstdir->name, tw, state.ftwflags, state.sort); else { ap = av; while (firstdir = firstdir->next) *ap++ = firstdir->name; *ap = 0; ftwalk((char*)av, tw, state.ftwflags|FTW_MULTIPLE, state.sort); } if (state.cmd && (i = cmdflush(state.cmd)) >= state.errexit) exit(i); if (state.find && (findclose(state.find) || state.finderror)) exit(2); } else if (state.select) error_info.errors = eval(state.select, &ftw) == 0; if (x = exexpr(state.program, "end", NiL, 0)) eval(x, &ftw); if (sfsync(sfstdout)) error(ERROR_SYSTEM|2, "write error"); exit(error_info.errors != 0); }
int ScanFilesEx ( CTEXTSTR base , CTEXTSTR mask , void **pInfo , void CPROC Process( uintptr_t psvUser, CTEXTSTR name, int flags ) , int flags , uintptr_t psvUser , LOGICAL begin_sub_path , struct file_system_mounted_interface *mount ) { PMFD pDataCurrent = (PMFD)(pInfo); PMFD pData = (PMFD)(*pInfo); TEXTSTR tmp_base = NULL; int sendflags; int processed = 0; #ifndef WIN32 struct dirent *de; #endif if( begin_sub_path ) { pInfo = (void**)&(pDataCurrent->current); } else pDataCurrent = NULL; //lprintf( "Search in %s for %s %d %d", base?base:"(NULL)", mask?mask:"(*)", (*pInfo)?((PMFD)*pInfo)->scanning_mount:0, (*pInfo)?((PMFD)*pInfo)->single_mount:0 ); if( !*pInfo || begin_sub_path || ((PMFD)*pInfo)->new_mount ) { TEXTCHAR findmask[256]; pData = (PMFD)(*pInfo); if( !pData ) { *pInfo = Allocate( sizeof( MFD ) ); pData = (PMFD)(*pInfo); if( !( pData->scanning_mount = mount ) ) { if( !winfile_local ) SimpleRegisterAndCreateGlobal( winfile_local ); //lprintf( "... %p", winfile_local ); pData->single_mount = FALSE; pData->scanning_mount = (*winfile_local).mounted_file_systems; } else pData->single_mount = TRUE; if( !pData->scanning_mount ) { Deallocate( PMFD, pData ); if( tmp_base ) Release( tmp_base ); return 0; } if( pData->scanning_mount->fsi ) { //lprintf( "create cursor" ); tmp_base = ExpandPathEx( base, pData->scanning_mount->fsi ); pData->cursor = pData->scanning_mount->fsi->find_create_cursor( pData->scanning_mount->psvInstance, CStrDup( tmp_base ), CStrDup( mask ) ); } else { //lprintf( "no cursor" ); pData->cursor = NULL; } } else { if( pData->new_mount ) { if( pData->scanning_mount->fsi ) { //lprintf( "create cursor (new mount)" ); tmp_base = ExpandPathEx( base, pData->scanning_mount->fsi ); pData->cursor = pData->scanning_mount->fsi->find_create_cursor( pData->scanning_mount->psvInstance, CStrDup( tmp_base ), CStrDup( mask ) ); } else pData->cursor = NULL; } } pData->new_mount = FALSE; pData->current = NULL; pData->prior = pDataCurrent; if( pDataCurrent ) { pData->root_info = pDataCurrent->root_info; pInfo = (void**)pData->root_info; } else { pData->root_info = (struct myfinddata**)pInfo; } (*pData->root_info) = pData; if( base ) { TEXTSTR tmp; StrCpyEx( findbasename(pInfo), tmp = ExpandPathEx( base, pData->scanning_mount?pData->scanning_mount->fsi:NULL ), MAX_PATH_NAME ); Release( tmp ); StrCpyEx( findmask(pInfo), mask, MAX_PATH_NAME ); } else { CTEXTSTR p = pathrchr( mask ); if( p ) { StrCpyEx( findbasename(pInfo), mask, p - mask + 1 ); StrCpyEx( findmask(pInfo), p + 1, MAX_PATH_NAME ); //mask = p + 1; } else { StrCpyEx( findbasename(pInfo), WIDE(""), 2 ); StrCpyEx( findmask(pInfo), mask, MAX_PATH_NAME ); } } if( findbasename(pInfo)[0] ) tnprintf( findmask, sizeof(findmask), WIDE("%s/*"), findbasename(pInfo) ); else tnprintf( findmask, sizeof( findmask ), WIDE( "*" ) ); if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) if( pData->scanning_mount->fsi->find_first( findcursor(pInfo) ) ) findhandle(pInfo) = 0; else findhandle(pInfo) = (HANDLECAST)-1; else { #if WIN32 findhandle(pInfo) = findfirst( findmask, finddata(pInfo) ); #else //lprintf( "opendir %s", findbasename(pInfo) ); findhandle( pInfo ) = opendir( findbasename(pInfo) ); if( !findhandle(pInfo ) ) findhandle(pInfo) = (HANDLECAST)-1; else de = readdir( (DIR*)findhandle( pInfo ) ); #endif } if( findhandle(pInfo) == (HANDLECAST)-1 ) { PMFD prior = pData->prior; //lprintf( "first use of cursor or first open of directoy failed..." ); if( pData->scanning_mount && pData->scanning_mount->fsi ) pData->scanning_mount->fsi->find_close( (struct find_cursor*)findcursor(pInfo) ); else { #ifdef WIN32 findclose( findhandle(pInfo) ); #else // but it failed... so ... don't close //closedir( findhandle( pInfo ) ); #endif } pData->scanning_mount = NextThing( pData->scanning_mount ); if( !pData->scanning_mount || pData->single_mount ) { (*pData->root_info) = pData->prior; if( !begin_sub_path ) { Release( pData ); pInfo[0] = NULL; } //lprintf( WIDE( "%p %d" ), prior, processed ); if( tmp_base ) Release( tmp_base ); return prior?processed:0; } pData->new_mount = TRUE; if( tmp_base ) Release( tmp_base ); return 1; } } else { int r; getnext: //lprintf( "returning customer..." ); if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) r = !pData->scanning_mount->fsi->find_next( findcursor( pInfo ) ); else { #ifdef _WIN32 r = findnext( findhandle(pInfo), finddata( pInfo ) ); #else de = readdir( (DIR*)findhandle( pInfo ) ); //lprintf( "using %p got %p", findhandle( pInfo ), de ); r = (de == NULL); #endif } if( r ) { PMFD prior = pData->prior; //lprintf( "nothing left to find..." ); if( pData->scanning_mount->fsi ) pData->scanning_mount->fsi->find_close( findcursor(pInfo) ); else { #ifdef WIN32 findclose( findhandle(pInfo) ); #else closedir( (DIR*)findhandle(pInfo)); #endif } pData->scanning_mount = NextThing( pData->scanning_mount ); //lprintf( "Step mount... %p %d", pData->scanning_mount, pData->single_mount ); if( !pData->scanning_mount || pData->single_mount ) { //lprintf( "done with mounts?" ); (*pData->root_info) = pData->prior; Release( pData ); if( prior ) prior->current = NULL; if( !processed && !begin_sub_path ) { //pInfo = (void**)&(prior->prior->current); pData = prior; if( pData ) goto getnext; } if( tmp_base ) Release( tmp_base ); return (*pInfo)?processed:0; } pData->new_mount = TRUE; if( tmp_base ) Release( tmp_base ); return 1; } } if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) { char * path = pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ); //lprintf( "... %s", path ); if( !strcmp( ".", path ) || !strcmp( "..", path ) ) goto getnext; } else { #if WIN32 //lprintf( "... %s", finddata(pInfo)->name ); # ifdef UNDER_CE if( !StrCmp( WIDE("."), finddata(pInfo)->cFileName ) || !StrCmp( WIDE(".."), finddata(pInfo)->cFileName ) ) # else if( !StrCmp( WIDE("."), finddata(pInfo)->name ) || !StrCmp( WIDE(".."), finddata(pInfo)->name ) ) # endif #else if( !StrCmp( WIDE("."), de->d_name ) || !StrCmp( WIDE(".."), de->d_name ) ) #endif goto getnext; } if( !(flags & SFF_NAMEONLY) ) // if nameonly - have to rebuild the correct name. { if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) { tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) ); if( findbasename( pInfo )[0] ) tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), pData->file_buffer ); else tnprintf( pData->buffer, MAX_PATH_NAME, WIDE( "%s" ), pData->file_buffer ); } else { #ifdef WIN32 # ifdef UNDER_CE tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE( "%s" ), finddata( pInfo )->cFileName ); tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), finddata(pInfo)->cFileName ); # else tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name ); tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s"), findbasename(pInfo), findbasename( pInfo )[0]?"/":"", pData->file_buffer ); # endif #else tnprintf( pData->file_buffer, MAX_PATH_NAME, WIDE("%s"), de->d_name ); tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s/%s"), findbasename(pInfo), de->d_name ); #endif } } else { if( flags & SFF_SUBCURSE ) { if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) { tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s") , pData->prior?pData->prior->buffer:WIDE( "" ) , pData->prior?WIDE( "/" ):WIDE( "" ) , pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) ); } else { #if WIN32 # ifdef UNDER_CE tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s") , pData->prior?pData->prior->buffer:WIDE( "" ) , pData->prior?WIDE( "/" ):WIDE( "" ) , finddata(pInfo)->cFileName ); # else tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s") , pData->prior?pData->prior->buffer:WIDE( "" ) , pData->prior?WIDE( "/" ):WIDE( "" ) , finddata(pInfo)->name ); # endif #else tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s%s%s") , pData->prior?pData->prior->buffer:WIDE( "" ) , pData->prior?WIDE( "/" ):WIDE( "" ) , de->d_name ); lprintf( "resulting is %s", pData->buffer ); #endif } } else { if( pData->scanning_mount?pData->scanning_mount->fsi:NULL ) { tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), pData->scanning_mount->fsi->find_get_name( findcursor(pInfo) ) ); } else { #if WIN32 # ifdef UNDER_CE tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->cFileName ); # else # ifdef UNICODE snwprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name ); # else tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), finddata(pInfo)->name ); # endif # endif #else tnprintf( pData->buffer, MAX_PATH_NAME, WIDE("%s"), de->d_name ); #endif } } } pData->buffer[MAX_PATH_NAME-1] = 0; // force nul termination... #ifdef UNICODE { char *pDataBuffer = CStrDup( pData->buffer ); #else # define pDataBuffer pData->buffer #endif //lprintf( "Check if %s is a directory...", pData->buffer ); if( (flags & (SFF_DIRECTORIES | SFF_SUBCURSE)) && (pData->scanning_mount && pData->scanning_mount->fsi && (pData->scanning_mount->fsi->is_directory && pData->scanning_mount->fsi->is_directory( pDataBuffer ))) || (!(pData->scanning_mount ? pData->scanning_mount->fsi : NULL) #ifdef WIN32 # ifdef UNDER_CE && (finddata( pInfo )->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) # else && (finddata( pInfo )->attrib & _A_SUBDIR) # endif #else && IsPath( pData->buffer ) #endif ) ) { #ifdef UNICODE Deallocate( char *, pDataBuffer ); #else # undef pDataBuffer #endif //lprintf( "... it is?" ); if( flags & SFF_DIRECTORIES ) { if( Process != NULL ) { //lprintf( "Send %s", pData->buffer ); Process( psvUser, pData->buffer, SFF_DIRECTORY ); processed = 1; } //return 1; } if( flags & SFF_SUBCURSE ) { void *data = NULL; int ofs = 0; TEXTCHAR tmpbuf[MAX_PATH_NAME]; if( flags & SFF_NAMEONLY ) { // even in name only - need to have this full buffer for subcurse. if( pData->scanning_mount && pData->scanning_mount->fsi ) { ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), pData->scanning_mount->fsi->find_get_name( findcursor( pInfo ) ) ); } else { #ifdef WIN32 # ifdef UNDER_CE ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->cFileName ); # else # ifdef UNICODE ofs = snwprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->name ); # else ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), finddata( pInfo )->name ); # endif # endif #else ofs = tnprintf( tmpbuf, sizeof( tmpbuf ), WIDE( "%s/%s" ), findbasename( pInfo ), de->d_name ); #endif } //lprintf( "process sub... %s %s", tmpbuf, findmask(pInfo) ); processed |= ScanFilesEx( tmpbuf, findmask( pInfo ), (POINTER*)pData, Process, flags, psvUser, TRUE, pData->scanning_mount ); } else { //lprintf( "process sub..." ); processed |= ScanFilesEx( pData->buffer, findmask( pInfo ), (POINTER*)pData, Process, flags, psvUser, TRUE, pData->scanning_mount ); } } if( !processed ) goto getnext; if( tmp_base ) Release( tmp_base ); return (*pInfo) ? 1 : 0; } #ifdef UNICODE Deallocate( char *, pDataBuffer ); } #else # undef pDataBuffer #endif if( ( sendflags = SFF_DIRECTORY, ( ( flags & SFF_DIRECTORIES ) #ifdef WIN32 # ifdef UNDER_CE && ( finddata(pInfo)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) # else && ( finddata(pInfo)->attrib & _A_SUBDIR ) # endif #else && ( IsPath( pData->buffer ) ) #endif ) ) || ( sendflags = 0, CompareMask( findmask( pInfo ) #ifdef WIN32 # ifdef UNDER_CE , finddata(pInfo)->cFileName # else , pData->file_buffer # endif #else , de->d_name #endif // yes this is silly - but it's correct... , (flags & SFF_IGNORECASE)?0:0 ) ) ) { //lprintf( "Send %s", pData->buffer ); if( Process != NULL ) Process( psvUser, pData->buffer, sendflags ); if( tmp_base ) Release( tmp_base ); return (*pInfo)?1:0; } if( tmp_base ) Release( tmp_base ); return (*pInfo)?1:0; }
int CHashManager::HashPath(char *pszBasePath, char *pszFileSpec) { recursivesafe long lHandle = 0; recursivesafe long lSearcherHandle = 0; recursivesafe finddata fdInfo; recursivesafe char szFull[RH_MAX_PATH]; recursivesafe char szAll[RH_MAX_PATH]; if(pszBasePath == NULL) return RH_INVALID_PATH; if(pszFileSpec == NULL) return RH_INVALID_PATH; fmtPath(pszBasePath); fmtPath(pszFileSpec); if(strlen(pszBasePath) == 0) getcwd(pszBasePath, RH_MAX_PATH); fileonly(pszFileSpec); strcpy(szAll, pszBasePath); catdirsep(szAll); strcat(szAll, SZ_DIR_ALL); #ifdef RH_DEBUG printf("Function HashPath: pszBasePath=%s, pszFileSpec=%s", pszBasePath, pszFileSpec); printf(CPS_NEWLINE); printf("Function HashPath: szAll=%s", szAll); printf(CPS_NEWLINE); #endif ////////////////////////////////////////////////////////////////////////// // Start directory enumeration code lSearcherHandle = findfirst(szAll, &fdInfo); while(1) { if(fdInfo.attrib & _A_SUBDIR) { if((ispathnav(fdInfo.name) == false) && (m_bRecursive)) { if(chdir(fdInfo.name) == 0) { getcwd(szFull, RH_MAX_PATH); #ifdef RH_DEBUG printf("Opening new scan path: %s, filemask: %s", szFull, pszFileSpec); printf(CPS_NEWLINE); #endif HashPath(szFull, pszFileSpec); chdir(SZ_LEVEL_UP); } } } if(findnext(lSearcherHandle, &fdInfo) != 0) break; } findclose(lSearcherHandle); lSearcherHandle = 0; // End directory enumeration code ////////////////////////////////////////////////////////////////////////// memset(&fdInfo, 0, sizeof(finddata)); lHandle = findfirst(pszFileSpec, &fdInfo); if(lHandle == EINVAL) return RH_INVALID_PATH; if(lHandle == ENOENT) return RH_NO_PATTERN_MATCH; if(lHandle == -1) return RH_CANNOT_OPEN_FILE; while(1) { if(fdInfo.attrib & _A_SUBDIR) { // Don't process directories here } else { if(m_bFullPath) { fullpath(szFull, fdInfo.name, RH_MAX_PATH); HashFile(szFull); } else { HashFile(fdInfo.name); } printf(CPS_NEWLINE); } if(findnext(lHandle, &fdInfo) != 0) break; } findclose(lHandle); lHandle = 0; return RH_SUCCESS; }
bool ancestorLZTrie (lztrie T, trieNode i, trieNode j) { return (i <= j) && (j < findclose (T->pdata,i)); }