    <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  :: A Software Probe</title>
        <link>https://members.accu.org/index.php/articles/880</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>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 11, #4 - Jun 1999</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/articles/">All</a>

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

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

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c131/">114</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-131/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+131/">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;A Software Probe</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 June 1999 13:15:31 +01:00 or Thu, 03 June 1999 13:15:31 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="section" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>Software doesn't always work first time. There are many ways of
gaining insight into what's going on, and this is another. The
software probe described here is simple, designed to be added by
hand and removed when the debug is over - it could be left in place
to be switched on by command or compile option as required - you
code to extend.</p>
<p>The probe relies on linking a small function into your build and
#including a header into source files under investigation.
Thereafter, where some information is required a one-liner addition
is all that is required.</p>
<p>Header (<tt class="filename">log.h</tt>):-</p>
<pre class="programlisting">
#ifndef LOG_H_
#define LOG_H_
extern void log(char const * text, char const * file, int const line);
extern char logbuf[];
#define LOG() log(logbuf,__FILE__, __LINE__)
#endif 
Source File (log.c) to link in:-
#include &lt;stdio.h&gt;
#include &quot;log.h&quot;
char const * logname = &quot;DOS.LOG&quot;;
static FILE * fp = NULL;
static int usingLogFile = 1;
char logbuf[509]; /* max length defined in C Standard */
void log(char const * text, char const * file, int const line) {
  if(usingLogFile) {
    if( fp == NULL ) fp = fopen( logname, &quot;w&quot; );
    else  fp = fopen( logname, &quot;a&quot; );
    if( fp == NULL ) {
      usingLogFile = 0;
      printf( &quot;### Unable to (re)open log file %s ###&quot;, logname );
    }
    else  {
      if( text != NULL &amp;&amp; file != NULL ) fprintf( fp, &quot;[%s:%d] %s\n&quot;, file, line, text );
      else if( text != NULL &amp;&amp; file == NULL ) fprintf( fp, &quot;%s\n&quot;, text );
      else if( text == NULL &amp;&amp; file == NULL ) fprintf( fp, &quot;&lt;unexpected&gt;\n&quot; );
      else if( text == NULL &amp;&amp; file != NULL ) fprintf( fp, &quot;&lt;NULL msg in [%s:%d]&gt;\n&quot;, file, line );

      fclose( fp );
    }
  }
}
</pre>
<p>The usage in some file under test:-</p>
<pre class="programlisting">
#include &quot;log.h&quot;
#include &lt;stdio.c&gt;
...
/*..... possibly aberrant code ... */
sprintf(logbuf, &quot;format spec&quot;, varaldic data you want to record); LOG();
/*...more code */
</pre>
<p>The probe can be placed in several files and as the probe labels
the file and line number it is fairly straightforward to interpret
the results collected in DOS.LOG (the filename used). The
construction of <tt class="function">log()</tt> ensures that the
file always contains the last message logged as the file is closed
each time - a God send when software crashes and you are trying to
narrow in on the faulty code.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
