home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / source / covutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  3.0 KB  |  81 lines

  1. /*-------------------------------------------------------------------*/
  2. /* Copyright (c) 1992-1993 SAS Institute Inc., Cary NC               */
  3. /*                                                                   */
  4. /* SUPPORT:    walker - Doug Walker                                  */
  5. /* SCRIPT:     sprof                                                 */
  6. /*-------------------------------------------------------------------*/
  7. /* CUT HERE */
  8.  
  9. #include <proto/dos.h>
  10. #include <string.h>
  11.  
  12. // These are linker-defined symbols.  Always use the ADDRESS of the
  13. // symbol, not the symbol itself;  The linker will replace the reference
  14. // with the start address and length of the coverage data section
  15.  
  16. extern long __far _CoverStart;
  17. extern long __far _CoverLength;
  18.  
  19. void __stdargs _STI_210_cover_init(void)
  20. {
  21.     BPTR fh;
  22.     char tag[4];
  23.     long length;
  24.     
  25.     /* read in existing coverage data */
  26.     fh = Open("cover.dat", MODE_OLDFILE);
  27.     if (fh)
  28.     {
  29.        /* If the file looks OK, load the data.  The first four bytes */
  30.        /* should be 'C' 'O' 'V' '\0'; the next four, the length.     */
  31.        /* If the "COV\0" tag doesn't match up, either this isn't a   */
  32.        /* coverage file or it's an incompatible file format; either  */
  33.        /* way, give up.  If the length doesn't match, the file was   */
  34.        /* generated by a different program, so don't try to merge    */
  35.        /* the data.                                                  */
  36.        /*                                                            */
  37.        /* If the file looks good, we read it in to initialize the    */
  38.        /* coverage section.  This means that the "cover.dat" file    */
  39.        /* will reflect the results of all previous runs as well as   */
  40.        /* this run.                                                  */
  41.  
  42.        if(Read(fh, tag, 4) == 4)                   // Read the tag
  43.        {
  44.          if(memcmp(tag, "COV", 4) == 0)            // Check the tag
  45.          {
  46.             if(Read(fh, &length, 4) == 4)          // Read the length
  47.             {
  48.                if(length == (long)&_CoverLength)   // Check the length
  49.                {
  50.                   Read(fh, &_CoverStart, length);  // Read the data
  51.                }
  52.             }
  53.          }
  54.       }
  55.       Close(fh);
  56.    }
  57. }
  58.  
  59. void __stdargs _STD_210_cover_term(void)
  60. {
  61.    BPTR fh;
  62.    long length;
  63.     
  64.    /* Write out coverage data                            */
  65.    /* Note that we destroy the old "cover.dat" file here */
  66.    fh = Open("cover.dat", MODE_NEWFILE);
  67.    if (fh)
  68.    {
  69.       /* Note that the linker replaces &_CoverLength with the actual */
  70.       /* length; this isn't really an address.  We have to assign it */
  71.       /* to a local variable in order to take its address to pass it */
  72.       /* to Write().                                                 */
  73.       length = (long)&_CoverLength;
  74.       Write(fh, "COV", 4);             // Write the tag
  75.       Write(fh, &length, 4);           // And the length
  76.       Write(fh, &_CoverStart, length); // Dump the data
  77.       Close(fh);
  78.    }
  79. }
  80.  
  81.