    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Quality Matters: Diagnostic Measures (Listings)</title>
        <link>https://members.accu.org/index.php/journals/1612</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #95 - February 2010 + Programming Topics + Design of applications and programs</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c265/">95</a>
                    (6)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c67/">Design</a>
                    (236)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c265-65-67/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c265+65+67/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Quality Matters: Diagnostic Measures (Listings)</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 07 February 2010 08:55:00 +00:00 or Sun, 07 February 2010 08:55:00 +00:00</p>
<p><strong>Summary:</strong>&nbsp;Program listings for Quality Matters: Diagnostic Measures</p>
<p><strong>Body:</strong>&nbsp;  <p>
<a name="listing1"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    unsigned list_all_files_r(char const* path)  
    {  
      STLSOFT_ASSERT(NULL != path);  
      STLSOFT_ASSERT('\0' != 0[path]);  
      std::string directory(path);  
      if(directory[directory.size() - 1u] != '/')  
      {  
        directory += '/';  
      }  

      DIR* dir = ::opendir(path);

      if(NULL == dir)  
      {  
        ff::fmtln(std::cerr,  
           &quot;failed to search '{0}': {1} ({2})&quot;, path,  
           stlsoft::error_desc(errno), errno);  
        return ~0u;  
      }  
      else  
      {  
        stlsoft::scoped_handle&lt;DIR*&gt;  scoper(dir,  
           ::closedir);  
        unsigned n = 0u;  
        { for(struct dirent* de; NULL != (  
           de = ::readdir(dir));)  
        {  
          if( de-&gt;d_name[0] == '.' &amp;&amp;  
              de-&gt;d_name[1] == '\0')  
          {  
            // '.'  
          }  
          else if(de-&gt;d_name[0] == '.' &amp;&amp;  
                  de-&gt;d_name[1] == '.' &amp;&amp;  
                  de-&gt;d_name[2] == '\0')  
          {  
            // '..'  
          }  
          else  
          {  
            std::string entryPath   
               = directory + de-&gt;d_name;  
            struct stat st;  
            int r = ::stat(entryPath.c_str(), &amp;st);  
            if(0 != r)  
            {  
              ff::fmtln(std::cerr,  
                 &quot;failed to stat '{0}': {1} ({2})&quot;,  
                 entryPath,  
                 stlsoft::error_desc(errno), errno);  
            }  
            else  
            {  
              if(st.st_mode &amp; S_IFREG)  
              {  
                ff::fmtln(std::cout, &quot;    {0}&quot;,  
                   entryPath);  
                ++n;  
              }  
              else  
              {  
                n += list_all_files_r(  
                   entryPath.c_str());  
              }  
            }  
          }  
        }}  
        return n;  
      }  
    }  
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
      unsigned n = list_all_files_r(path);  
      if(~0u != n)  
      {  
        ff::fmtln(std::cout, &quot;  {0} file(s) found&quot;,  
           n);  
      }  
    }
</pre></td></tr><tr><td class="title">Listing 1</td></tr></table>
  </p><p> 
<a name="listing2"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    unsigned list_all_files_r(char const* path)  
    {  
      STLSOFT_ASSERT(NULL != path);  
      STLSOFT_ASSERT('\0' != 0[path]);  
      std::string directory(path);  
      if(directory[directory.size() - 1u] != '\\')  
      {  
        directory += '\\';  
      }  
      std::string searchSpec = directory + &quot;*.*&quot;;  
      WIN32_FIND_DATA data;  
      HANDLE  h = ::FindFirstFile(searchSpec.c_str(),  
         &amp;data);  
      if(INVALID_HANDLE_VALUE == h)  
      {  
        DWORD err = ::GetLastError();  
        ff::fmtln(std::cerr, &quot;failed to search '{0}'  
           : {1} ({2})&quot;, path,  
           winstl::error_desc(err), err);  
        return ~0u;  
      }  
      else  
      {  
        stlsoft::scoped_handle&lt;HANDLE&gt;  scoper(h,  
           ::FindClose, INVALID_HANDLE_VALUE);  
        unsigned n = 0u;  
        do  
        {  
          if(data.dwFileAttributes   
             &amp; FILE_ATTRIBUTE_DIRECTORY)  
          {  
            if( data.cFileName[0] == '.' &amp;&amp;  
                data.cFileName[1] == '\0')  
            {  
              // '.'  
            }  
            else if(data.cFileName[0] == '.' &amp;&amp;  
                    data.cFileName[1] == '.' &amp;&amp;  
                    data.cFileName[2] == '\0')  
            {  
              // '..'  
            }  
            else  
            {  
              n += list_all_files_r((directory   
                 + data.cFileName).c_str());  
            }  
          }  
          else  
          {  
            ff::fmtln(std::cout, &quot;    {0}{1}&quot;,  
               directory, data.cFileName);  
            ++n;  
          }  
        } while(::FindNextFile(h, &amp;data));  
        return n;  
      }  
    }  
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
      unsigned n = list_all_files_r(path);  
      if(~0u != n)  
      {  
        ff::fmtln(std::cout,  
           &quot;  {0} file(s) found&quot;, n);  
      }  
    }  
</pre></td></tr><tr><td class="title">Listing 2</td></tr></table>
  </p><p> 
<a name="listing3"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    // Assumes introduction of recls namespace symbols  
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
      hrecls_t    hSrch;  
      recls_rc_t  rc  = Recls_Search(path, NULL,  
         recls::FILES | recls::RECURSIVE, &amp;hSrch);  
      if(RECLS_FAILED(rc))  
      {  
        ff::fmtln(std::cerr,  
           &quot;failed to search '{0}': {1} ({2})&quot;,  
           path, rc, int(rc));  
      }  
      else  
      {  
        stlsoft::scoped_handle&lt;hrecls_t&gt; scoper(  
           hSrch, Recls_SearchClose);  
        unsigned  n = 0u;  
        entry_t   entry;  
        { for(RECLS_GetDetails(hSrch, &amp;entry);  
           RECLS_SUCCEEDED(rc);  
           rc = Recls_GetNextDetails(hSrch, &amp;entry),  
           ++n)  
        {  
          stlsoft::scoped_handle&lt;entry_t&gt; scoper2(  
             entry, Recls_CloseDetails);  
          ff::fmtln(std::cout, &quot;    {0}&quot;,  
             entry-&gt;path);  
        }}  
        ff::fmtln(std::cout,  
           &quot;  {0} file(s) found&quot;, n);  
      }  
    }  
</pre></td></tr><tr><td class="title">Listing 3</td></tr></table>
  </p><p> 
<a name="listing4"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    // Assumes introduction of recls namespace symbols  
    int RECLS_CALLCONV_DEFAULT onFile(  
        recls_entry_t               entry  
    ,   recls_process_fn_param_t    param  
    )  
    {  
      ff::fmtln(std::cout, &quot;    {0}&quot;, entry-&gt;path);  
      ++*static_cast&lt;unsigned*&gt;(param);  
      return +1; // continue
    }  
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
      unsigned    n   = 0u;  
      recls_rc_t  rc  = Recls_SearchProcess(path,  
         NULL, recls::FILES | recls::RECURSIVE,  
         onFile, &amp;n);  
      if(RECLS_SUCCEEDED(rc))  
      {  
        ff::fmtln(std::cout,  
           &quot;  {0} file(s) found&quot;, n);  
      }  
      else  
      {  
        ff::fmtln(std::cerr,  
           &quot;failed to search '{0}': {1} ({2})&quot;, path,  
           rc, int(rc));  
      }  
    }
</pre></td></tr><tr><td class="title">Listing 4</td></tr></table>
  </p><p> 
<a name="listing5"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
      try  
      {  
        recls::search_sequence files(path,  
           recls::wildcardsAll(), recls::FILES |  
           recls::RECURSIVE);  
        unsigned n = 0;  
        { for(recls::search_sequence  
           ::const_iterator i = files.begin();   
           i != files.end(); ++i, ++n)  
        {  
          ff::fmtln(std::cout, &quot;    {0}&quot;, *i);  
        }}  
        ff::fmtln(std::cout,  
           &quot;  {0} file(s) found&quot;, n);  
      }  
      catch(recls::recls_exception&amp; x)  
      {  
        ff::fmtln(std::cerr,  
           &quot;failed to search '{0}': {1} ({2})&quot;,  
           path, x, int(x.get_rc()));  
      }  
    }
</pre></td></tr><tr><td class="title">Listing 5</td></tr></table>
  </p><p> 
<a name="listing6"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    typedef struct recls_entryinfo_t const* recls_entry_t;  
 
    struct recls_strptrs_t  
    {  
      recls_char_t const* begin;  
      recls_char_t const* end;  
    };  
    struct recls_strptrsptrs_t  
    {  
      struct recls_strptrs_t const* begin;  
      struct recls_strptrs_t const* end;  
    };  
 
    #if !defined(RECLS_PURE_API)  
    struct recls_entryinfo_t  
    {  
      recls_uint32_t              attributes;  
      struct recls_strptrs_t      path;  
    # if defined(RECLS_PLATFORM_IS_WINDOWS)  
      struct recls_strptrs_t      shortFile;  
      recls_char_t                drive;  
    # endif /* RECLS_PLATFORM_IS_WINDOWS */
      struct recls_strptrs_t      directory;  
      struct recls_strptrs_t      fileName;  
      struct recls_strptrs_t      fileExt;  
      struct recls_strptrsptrs_t  directoryParts;  
    # if defined(RECLS_PLATFORM_IS_WINDOWS)  
      recls_time_t                creationTime;  
    # endif /* RECLS_PLATFORM_IS_WINDOWS */
      recls_time_t                modificationTime;  
      recls_time_t                lastAccessTime;  
    # if defined(RECLS_PLATFORM_IS_UNIX)  
      recls_time_t               lastStatusChangeTime;  
    # endif /* RECLS_PLATFORM_IS_UNIX */
      recls_filesize_t            size;  
      struct recls_strptrs_t      searchDirectory;  
      struct recls_strptrs_t      searchRelativePath;  
      /* Remaining member are undocumented and subject  
         to change */    
      recls_uint64_t              checkSum;  
      recls_uint32_t              extendedFlags[2];  
      recls_byte_t                data[1];  
    };  
    #endif /* !RECLS_PURE_API */
</pre></td></tr><tr><td class="title">Listing 6</td></tr></table>
  </p><p> 
<a name="listing7"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    ReclsFileSearchDirectoryNode::  
       ReclsFileSearchDirectoryNode(  
      recls_uint32_t            flags  
    , recls_char_t const*       searchDir  
    , size_t                    rootDirLen  
    , recls_char_t const*       pattern  
    , size_t                    patternLen  
    , hrecls_progress_fn_t      pfn  
    , recls_process_fn_param_t  param  
    )  
      : m_current(NULL)  
      , m_dnode(NULL)  
      , m_flags(flags)  
      , m_rootDirLen(rootDirLen)  
      , m_searchDir()  
      , m_searchDirLen(prepare_searchDir_(  
        m_searchDir, searchDir))  
      , m_pattern(pattern)  
      , m_patternLen(patternLen)  
      , m_directories(  
          searchDir  
    #if defined(RECLS_PLATFORM_IS_WINDOWS)  
        , types::traits_type::pattern_all()  
    #endif /* platform */
        , dssFlags_from_reclsFlags_(flags))  
      , m_directoriesBegin(  
          select_iter_if_(  
            flags &amp; RECLS_F_RECURSIVE  
          , m_directories.begin()  
          , m_directories.end()))  
      , m_entries(  
          searchDir  
        , pattern  
    #ifdef RECLS_SUPPORTS_MULTIPATTERN_  
        , types::traits_type::path_separator()  
    #endif /* RECLS_SUPPORTS_MULTIPATTERN_ */
        , essFlags_from_reclsFlags_(flags))  
      , m_entriesBegin(m_entries.begin())  
      , m_pfn(pfn)  
      , m_param(param)  
    {  
      . . .  
    }
</pre></td></tr><tr><td class="title">Listing 7</td></tr></table>
  </p><p> 
<a name="listing8"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    void list_all_files(char const* path)  
    {  
      ff::fmtln(std::cout, &quot;Searching '{0}'&quot;, path);  
 
      try  
      {  
        recls::cpp::FileSearch search(path,  
           recls::Recls_GetWildcardsAll(),  
           recls::FILES | recls::RECURSIVE);  
 
        unsigned n = 0;  
        for(; search.HasMoreElements();  
           search.GetNext(), ++n)  
        {  
          recls::cpp::FileEntry entry   
             = search.GetCurrentEntry();  
          ff::fmtln(std::cout, &quot;    {0}&quot;, entry);  
        }  
        ff::fmtln(std::cout,  
           &quot;  {0} file(s) found&quot;, n);  
      }  
 
      catch(recls::cpp::ReclsException&amp; x)  
      {  
        ff::fmtln(std::cerr,  
           &quot;failed to search '{0}': {1} ({2})&quot;,  
           path, x, int(x.rc()));  
      }  
    }
</pre></td></tr><tr><td class="title">Listing 8</td></tr></table>
  </p><p> 
<a name="listing9"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    search_sequence::const_iterator  
    search_sequence::begin() const  
    {  
      hrecls_t    hSrch;  
      recls_rc_t  rc = Recls_Search(m_directory,  
         m_pattern, m_flags, &amp;hSrch);  
 
      if( RECLS_FAILED(rc) &amp;&amp;  
          RECLS_RC_NO_MORE_DATA != rc)  
      {  
        throw recls_exception(rc);  
      }  
      return const_iterator(hSrch);  
    }  
 
    ftp_search_sequence::const_iterator  
    ftp_search_sequence::begin() const  
    {  
      hrecls_t    hSrch;  
      recls_rc_t    
         rc = Recls_SearchFtp(m_host.c_str(),  
         m_username.c_str(), m_password.c_str(),  
         m_directory, m_pattern, m_flags, &amp;hSrch);  
      if( RECLS_FAILED(rc) &amp;&amp;  
          RECLS_RC_NO_MORE_DATA != rc)  
      {  
        throw recls_exception(rc);  
      }  
 
      return const_iterator(hSrch);  
    }

    template &lt;typename C, typename T, typename V&gt;  
    basic_search_sequence_const_iterator&lt;C, T, V&gt;&amp;  
    basic_search_sequence_const_iterator&lt;C, T, V&gt;::operator ++()  
    {  
      RECLS_MESSAGE_ASSERT(  
         &quot;Attempting to increment invalid iterator&quot;,  
         NULL != m_handle);  
      if(RECLS_FAILED(Recls_GetNext(  
         m_handle-&gt;hSrch)))  
      {  
        m_handle-&gt;Release();  
        m_handle = NULL;  
      }  
      return *this;  
    }  
    class entry  
    {  
      . . .  
    public: /// Attribute Methods
      char_type const* c_str() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return m_entry-&gt;path.begin;  
      }  
      . . .  
      recls_time_t get_creation_time() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return Recls_GetCreationTime(m_entry);  
      }  
      . . .  
      string_type get_path() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;path.begin,  
           m_entry-&gt;path.end);  
      }  
      string_type get_drive() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;path.begin,  
           m_entry-&gt;directory.begin);  
      }  
      string_type get_directory_path() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;path.begin,  
           m_entry-&gt;directory.end);  
      }  
      string_type get_directory() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;directory.begin,  
           m_entry-&gt;directory.end);  
      }  
      string_type get_file() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;fileName.begin,  
           m_entry-&gt;fileExt.end);  
      }  
      string_type get_file_name() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        return string_type(m_entry-&gt;fileName.begin,  
           m_entry-&gt;fileName.end);  
      }

      string_type get_file_extension() const  
      {  
        STLSOFT_ASSERT(NULL != m_entry);  
        if(m_entry-&gt;fileExt.begin   
           == m_entry-&gt;fileExt.end)  
        {  
          return string_type();  
        }  
        else  
        {  
          return string_type(  
             m_entry-&gt;fileExt.begin - 1,  
             m_entry-&gt;fileExt.end);  
        }  
      }  
      . . .  
    private: /// Member Variables
      recls_entry_t m_entry;  
    };
</pre></td></tr><tr><td class="title">Listing 9</td></tr></table>
  </p><p> 
<a name="listing10"></a>
<table class="sidebartable"><tr><td><pre class="programlisting">
    /* test.unit.api.combine_paths.c */  
    static void test_1(void);  
    static void test_2(void);  
    static void test_3(void);  
    static void test_4(void);  
    int main(int argc, char **argv)  
    {  
      int retCode = EXIT_SUCCESS;  
      int verbosity = 2;  
      XTESTS_COMMANDLINE_PARSEVERBOSITY(argc,  
         argv, &amp;verbosity);  
      if(XTESTS_START_RUNNER(  
         &quot;test.unit.api.combine_paths&quot;, verbosity))  
      {  
        XTESTS_RUN_CASE(test_1);  
        XTESTS_RUN_CASE(test_2);  
        XTESTS_RUN_CASE(test_3);  
        XTESTS_RUN_CASE(test_4);  
    #ifdef XCOVER_VER  
        XCOVER_REPORT_GROUP_COVERAGE(  
           &quot;recls.core.extended.combine_paths&quot;, NULL);  
    #endif /* XCOVER_VER */  
        XTESTS_PRINT_RESULTS();  
        XTESTS_END_RUNNER_UPDATE_EXITCODE(  
           &amp;retCode);  
      }  
      return retCode;  
    }  
    . . .  
    static void test_4()  
    {  
      char    result[101];  
      size_t  cch = Recls_CombinePaths(&quot;abc&quot;, &quot;def&quot;,  
         &amp;result[0], STLSOFT_NUM_ELEMENTS(result));  
      result[cch] = '\0';  
      XTESTS_TEST_INTEGER_EQUAL(7u, cch);  
    #if defined(RECLS_PLATFORM_IS_UNIX)  
      XTESTS_TEST_MULTIBYTE_STRING_EQUAL(&quot;abc/def&quot;,  
         result);  
    #elif defined(RECLS_PLATFORM_IS_WINDOWS)  
      XTESTS_TEST_MULTIBYTE_STRING_EQUAL(&quot;abc\\def&quot;,  
         result);  
    #endif  
    }
</pre></td></tr><tr><td class="title">Listing 10</td></tr></table>
  </p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
