librnr/path.c
char *SearchPathIterFirst(PathIter_T *pIter, const char *sSearchFile)
{
  const char      *sPath;   // search path component
  size_t           nLen;    // string length

  // logistics to [re]set iterator
  delete(pIter->m_sFileCanonical);  // clear any old canonical serach file 
  pIter->m_sFileCanonical = NULL;
  delete(pIter->m_sFilePath);       // clear any old constructed file path
  pIter->m_sFilePath      = NULL;
  pIter->m_nFileLen       = 0;      // no file, no length
  pIter->m_bIsEos         = true;   // assume end-of-search condition until
                                    //   proven otherwise

  // no serach file specified
  if( (sSearchFile == NULL) || (*sSearchFile == 0) )
  {
    LOGERROR("%s(): no file specified", LOGFUNCNAME);
    return NULL;
  }

  // cannot canonicalize search file
  else if( (pIter->m_sFileCanonical = NewSearchPathCanonicalized(sSearchFile)) 
                                        == NULL )
  {
    LOGERROR("NewSearchPathCanonicalized() failed");
    return NULL;
  }

  // set canonical file name length - used to speed iteration
  pIter->m_nFileLen = strlen(pIter->m_sFileCanonical);

  // no search path - just return canonical file
  if( DListStrCount(pIter->m_pSearchPaths) == 0 )
  {
    LOGDIAG4("'%s'=%s()", pIter->m_sFileCanonical, LOGFUNCNAME);

    return pIter->m_sFileCanonical;
  }

  // construct first file path
  else if( (sPath = DListStrIterDataFirst(pIter->m_pSearchPaths,
                                          &(pIter->m_iterPaths))) != NULL )
  {
    pIter->m_bIsEos = false;

    nLen  = strlen(sPath) + strlen(DIR_SEP_STR) + pIter->m_nFileLen;

    pIter->m_sFilePath = NEWSTR(nLen);

    sprintf(pIter->m_sFilePath, "%s%s%s", 
      sPath, DIR_SEP_STR, pIter->m_sFileCanonical);

    LOGDIAG4("'%s'=%s()", pIter->m_sFilePath, LOGFUNCNAME);

    return pIter->m_sFilePath;
  }

  // shouldn't have gotten here - so terminate search
  else
  {
    return NULL;
  }
}
/*!
 * \brief Get the first concatenated file path.
 *
 * Initialize search path iterator from given search file and returns first
 * concatenated file path.
 *
 * \param pIter         Path iterator.
 * \param sSearchFile   Search path.
 *
 * \return
 *  Returns first file path on success, NULL if at end of search or on error.
 */
\brief Get the first concatenated file path.
Initialize search path iterator from given search file and returns first
concatenated file path.

\param pIter         Path iterator.
\param sSearchFile   Search path.

\return
Returns first file path on success, NULL if at end of search or on error.
\ brief Get the first concatenated file path . Initialize search path iterator from given search file and returns first concatenated file path . \ param pIter Path iterator . \ param sSearchFile Search path . \ return Returns first file path on success NULL if at end of search or on error .
char *SearchPathIterFirst(PathIter_T *pIter, const char *sSearchFile)
{
  const char      *sPath;   
  size_t           nLen;    
  delete(pIter->m_sFileCanonical);  
  pIter->m_sFileCanonical = NULL;
  delete(pIter->m_sFilePath);       
  pIter->m_sFilePath      = NULL;
  pIter->m_nFileLen       = 0;      
  pIter->m_bIsEos         = true;   
  if( (sSearchFile == NULL) || (*sSearchFile == 0) )
  {
    LOGERROR("%s(): no file specified", LOGFUNCNAME);
    return NULL;
  }
  else if( (pIter->m_sFileCanonical = NewSearchPathCanonicalized(sSearchFile)) 
                                        == NULL )
  {
    LOGERROR("NewSearchPathCanonicalized() failed");
    return NULL;
  }
  pIter->m_nFileLen = strlen(pIter->m_sFileCanonical);
  if( DListStrCount(pIter->m_pSearchPaths) == 0 )
  {
    LOGDIAG4("'%s'=%s()", pIter->m_sFileCanonical, LOGFUNCNAME);
    return pIter->m_sFileCanonical;
  }
  else if( (sPath = DListStrIterDataFirst(pIter->m_pSearchPaths,
                                          &(pIter->m_iterPaths))) != NULL )
  {
    pIter->m_bIsEos = false;
    nLen  = strlen(sPath) + strlen(DIR_SEP_STR) + pIter->m_nFileLen;
    pIter->m_sFilePath = NEWSTR(nLen);
    sprintf(pIter->m_sFilePath, "%s%s%s", 
      sPath, DIR_SEP_STR, pIter->m_sFileCanonical);
    LOGDIAG4("'%s'=%s()", pIter->m_sFilePath, LOGFUNCNAME);
    return pIter->m_sFilePath;
  }
  else
  {
    return NULL;
  }
}
char * SearchPathIterFirst ( PathIter_T * pIter , const char * sSearchFile ) { const char * sPath ; size_t nLen ; delete ( pIter -> m_sFileCanonical ) ; pIter -> m_sFileCanonical = NULL ; delete ( pIter -> m_sFilePath ) ; pIter -> m_sFilePath = NULL ; pIter -> m_nFileLen = 0 ; pIter -> m_bIsEos = true ; if ( ( sSearchFile == NULL ) || ( * sSearchFile == 0 ) ) { LOGERROR ( " " , LOGFUNCNAME ) ; return NULL ; } else if ( ( pIter -> m_sFileCanonical = NewSearchPathCanonicalized ( sSearchFile ) ) == NULL ) { LOGERROR ( " " ) ; return NULL ; } pIter -> m_nFileLen = strlen ( pIter -> m_sFileCanonical ) ; if ( DListStrCount ( pIter -> m_pSearchPaths ) == 0 ) { LOGDIAG4 ( " " , pIter -> m_sFileCanonical , LOGFUNCNAME ) ; return pIter -> m_sFileCanonical ; } else if ( ( sPath = DListStrIterDataFirst ( pIter -> m_pSearchPaths , & ( pIter -> m_iterPaths ) ) ) != NULL ) { pIter -> m_bIsEos = false ; nLen = strlen ( sPath ) + strlen ( DIR_SEP_STR ) + pIter -> m_nFileLen ; pIter -> m_sFilePath = NEWSTR ( nLen ) ; sprintf ( pIter -> m_sFilePath , " " , sPath , DIR_SEP_STR , pIter -> m_sFileCanonical ) ; LOGDIAG4 ( " " , pIter -> m_sFilePath , LOGFUNCNAME ) ; return pIter -> m_sFilePath ; } else { return NULL ; } }
\brief Get the first concatenated file path.
\ brief Get the first concatenated file path .
// search path component // string length // logistics to [re]set iterator // clear any old canonical serach file  // clear any old constructed file path // no file, no length // assume end-of-search condition until //   proven otherwise // no serach file specified // cannot canonicalize search file // set canonical file name length - used to speed iteration // no search path - just return canonical file // construct first file path // shouldn't have gotten here - so terminate search