contentLister/inc/search_files.h File Reference

content lister - More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MAX_TOKENS_IN_SEARCHSTRING   (20)
#define SEARCH_MAX_RECURSE   (25)
#define SEARCH_MAX_SYMLINKS   (100)

Functions

int execSearch (const char *sPath, const char *sTarget)


Detailed Description

content lister -

Definition in file search_files.h.


Define Documentation

#define MAX_TOKENS_IN_SEARCHSTRING   (20)

Definition at line 38 of file search_files.h.

#define SEARCH_MAX_RECURSE   (25)

Definition at line 40 of file search_files.h.

#define SEARCH_MAX_SYMLINKS   (100)

Definition at line 41 of file search_files.h.


Function Documentation

int execSearch ( const char *  sPath,
const char *  sTarget 
)

Definition at line 242 of file search_files.c.

00243 {
00244     int   i;
00245     char* cp;
00246     
00247     CL_SEARCHPRINTF("entry: path [%s] pattern [%s]", sPath, sPattern);
00248     
00249     gchar dir_searchresult[ERMDS_MAX_FILENAME_SIZE]; 
00250     mdsGetRootLocation(st_SearchResult, dir_searchresult, sizeof(dir_searchresult));
00251     CL_SEARCHPRINTF("dir_searchresult [%s]", dir_searchresult);
00252 
00253     gchar dir_searchresult_tmp[ERMDS_MAX_FILENAME_SIZE]; 
00254     snprintf(dir_searchresult_tmp, sizeof(dir_searchresult_tmp), "%s_tmp", dir_searchresult);
00255     CL_SEARCHPRINTF("dir_searchresult_tmp [%s]", dir_searchresult_tmp);
00256 
00257     const char* sSearchPath = NULL;    
00258     int         nRet = -1;  // 0 = ok, -1 = error    
00259     
00260     // check whether we are searchig in previous search results
00261     if( 0 == strncmp(sPath, dir_searchresult, sizeof(dir_searchresult)) ) 
00262     {
00263         // searching in search-results: move old results to temporary location
00264         rename(dir_searchresult, dir_searchresult_tmp);
00265         sSearchPath = dir_searchresult_tmp;
00266         CL_SEARCHPRINTF("search path [%s]", sSearchPath);
00267     }
00268     else
00269     {
00270         // searching elsewhere: discard old results
00271         DirDel(dir_searchresult);
00272         sSearchPath = sPath;
00273         CL_SEARCHPRINTF("search path [%s]", sSearchPath);
00274     }
00275     CL_SEARCHPRINTF("search path [%s]", sSearchPath);
00276     
00277     // create directory to hold the search result
00278     if( 0 != mkdir(dir_searchresult, 0755) )
00279     {
00280          CL_ERRORPRINTF("Could not create dir: [%s]",dir_searchresult);
00281          return nRet;
00282     }
00283 
00284     // split search pattern into multiple tokens
00285     //     make a working copy of sPattern
00286     char* pattern = alloca( strlen(sPattern) + 1 );
00287     g_assert(pattern != NULL);
00288     strcpy(pattern, sPattern);
00289     //     find tokens
00290     char* tokens[MAX_TOKENS_IN_SEARCHSTRING + 1];
00291     int   n_tokens = 0;
00292     cp = pattern;
00293     while (*cp)
00294     {
00295         if (*cp == ' ')
00296         {
00297             // separator: ignore
00298             cp++;
00299         }
00300         else
00301         {
00302             // start of new token
00303             if (n_tokens < MAX_TOKENS_IN_SEARCHSTRING)
00304             {
00305                 if (*cp == '"'  &&  *(cp+1) != '"')
00306                 {
00307                     // token is a quoted string, e.g. "this is a string"
00308                     cp++;
00309                     tokens[n_tokens++] = cp;
00310                     while (*cp != '"'  &&  *cp != '\0')
00311                     {
00312                         // character is part of token: next character
00313                         cp++;
00314                     }
00315                     if (*cp)
00316                     {
00317                         *cp = '\0';
00318                         cp++;
00319                     }
00320                 }
00321                 else
00322                 {
00323                     // token is a single word, e.g. "word"
00324                     tokens[n_tokens++] = cp;
00325                     while (*cp != ' '  &&  *cp != '\0')
00326                     {
00327                         // character is part of token: next character
00328                         cp++;
00329                     }
00330                     if (*cp)
00331                     {
00332                         *cp = '\0';
00333                         cp++;
00334                     }
00335                 }
00336             }
00337         }
00338     }
00339     if (n_tokens == 0)
00340     {
00341         tokens[n_tokens++] = "";
00342     }
00343     tokens[n_tokens] = NULL;
00344 
00345     CL_SEARCHPRINTF("Search string [%s]", sPattern);
00346     for (i = 0 ; i <= n_tokens ; i++)
00347     {
00348         CL_SEARCHPRINTF("Search token [%d] [%s]", i, tokens[i]);
00349     }
00350     
00351     // now search for it
00352     nRet = searchDirectory(sSearchPath, tokens, dir_searchresult);
00353 
00354     // clean-up temporary links
00355     DirDel(dir_searchresult_tmp);
00356 
00357     return nRet;
00358 }

Here is the call graph for this function:


Generated on Sun Dec 14 17:13:00 2008 by  doxygen 1.5.6