source: rtems-testing/covoar/Explanations.cc @ a518bc5

4.11
Last change on this file since a518bc5 was a518bc5, checked in by Jennifer Averett <Jennifer.Averett@…>, on May 24, 2010 at 8:07:09 PM

2010-05-24 Jennifer Averett <Jennifer.Averett@…>

  • covoar/05_ascending.gif, covoar/05_descending.gif, covoar/05_unsorted.gif, covoar/ConfigFile.cc, covoar/ConfigFile.h, covoar/CoverageFactory.cc, covoar/CoverageFactory.h, covoar/CoverageMap.cc, covoar/CoverageMap.h, covoar/CoverageMapBase.cc, covoar/CoverageMapBase.h, covoar/CoverageRanges.cc, covoar/CoverageRanges.h, covoar/CoverageReaderBase.cc, covoar/CoverageReaderBase.h, covoar/CoverageReaderQEMU.cc, covoar/CoverageReaderQEMU.h, covoar/CoverageReaderRTEMS.cc, covoar/CoverageReaderRTEMS.h, covoar/CoverageReaderSkyeye.cc, covoar/CoverageReaderSkyeye.h, covoar/CoverageReaderTSIM.cc, covoar/CoverageReaderTSIM.h, covoar/CoverageWriterBase.cc, covoar/CoverageWriterBase.h, covoar/CoverageWriterRTEMS.cc, covoar/CoverageWriterRTEMS.h, covoar/CoverageWriterSkyeye.cc, covoar/CoverageWriterSkyeye.h, covoar/CoverageWriterTSIM.cc, covoar/CoverageWriterTSIM.h, covoar/DesiredSymbols.cc, covoar/DesiredSymbols.h, covoar/ExecutableInfo.cc, covoar/ExecutableInfo.h, covoar/Explanations.cc, covoar/Explanations.h, covoar/Makefile, covoar/ObjdumpProcessor.cc, covoar/ObjdumpProcessor.h, covoar/ReportsBase.cc, covoar/ReportsBase.h, covoar/ReportsHtml.cc, covoar/ReportsHtml.h, covoar/ReportsText.cc, covoar/ReportsText.h, covoar/SymbolTable.cc, covoar/SymbolTable.h, covoar/TargetBase.cc, covoar/TargetBase.h, covoar/TargetFactory.cc, covoar/TargetFactory.h, covoar/Target_arm.cc, covoar/Target_arm.h, covoar/Target_i386.cc, covoar/Target_i386.h, covoar/Target_lm32.cc, covoar/Target_lm32.h, covoar/Target_m68k.cc, covoar/Target_m68k.h, covoar/Target_powerpc.cc, covoar/Target_powerpc.h, covoar/Target_sparc.cc, covoar/Target_sparc.h, covoar/TraceConverter.cc, covoar/TraceList.cc, covoar/TraceList.h, covoar/TraceReaderBase.cc, covoar/TraceReaderBase.h, covoar/TraceReaderLogQEMU.cc, covoar/TraceReaderLogQEMU.h, covoar/TraceWriterBase.cc, covoar/TraceWriterBase.h, covoar/TraceWriterQEMU.cc, covoar/TraceWriterQEMU.h, covoar/app_common.cc, covoar/app_common.h, covoar/configfile_test.cc, covoar/coverage_converter.cc, covoar/covmerge.cc, covoar/covoar.cc, covoar/covoar.css, covoar/filter.gif, covoar/qemu-dump-trace.c, covoar/qemu-log.h, covoar/qemu-traces.h, covoar/rtemscov_header.h, covoar/skyeye_header.h, covoar/table.js: New files.
  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 *  $Id$
3 */
4
5/*! @file Explanations.cc
6 *  @brief Explanations Implementation
7 *
8 *  This file contains the implementation of the functions
9 *  which provide a base level of functionality of a Explanations.
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16
17#include "Explanations.h"
18
19namespace Coverage {
20
21  Explanations::Explanations()
22  {
23  }
24
25  Explanations::~Explanations()
26  {
27  }
28
29  void Explanations::load(
30    const char* const explanations
31  )
32  {
33    #define MAX_LINE_LENGTH 512
34    FILE       *explain;
35    char        buffer[MAX_LINE_LENGTH];
36    char        *cStatus;
37    Explanation *e;
38    int          line = 1;
39
40    if (!explanations)
41      return;
42
43    explain = fopen( explanations, "r" );
44    if (!explain) {
45      fprintf(
46        stderr,
47        "ERROR: Explanations::load - unable to open explanations file %s\n",
48        explanations
49      );
50      exit(-1);
51    }
52
53    while ( 1 ) {
54      e = new Explanation;
55      // Read the starting line of this explanation and
56      // skip blank lines between
57      do {
58        buffer[0] = '\0';
59        cStatus = fgets( buffer, MAX_LINE_LENGTH, explain );
60        if (cStatus == NULL) {
61          goto done;
62        }
63        buffer[ strlen(buffer) - 1] = '\0';
64        line++;
65      } while ( buffer[0] == '\0' );
66
67      // Have we already seen this one?
68      if (set.find( buffer ) != set.end()) {
69        fprintf(
70          stderr,
71          "ERROR: Explanations::load - line %d "
72          "contains a duplicate explanation (%s)\n",
73          line,
74          buffer
75        );
76        exit( -1 );
77      }
78
79      // Add the starting line and file
80      e->startingPoint = std::string(buffer);
81      e->found = false;
82
83      // Get the classification
84      cStatus = fgets( buffer, MAX_LINE_LENGTH, explain );
85      if (cStatus == NULL) {
86        fprintf(
87          stderr,
88          "ERROR: Explanations::load - line %d "
89          "out of sync at the classification\n",
90          line
91        );
92        exit( -1 );
93      }
94      buffer[ strlen(buffer) - 1] = '\0';
95      e->classification = buffer;
96      line++;
97
98      // Get the explanation
99      while (1) {
100        cStatus = fgets( buffer, MAX_LINE_LENGTH, explain );
101        // fprintf( stderr, "%d - %s\n", line, buffer );
102        if (cStatus == NULL) {
103          fprintf(
104            stderr,
105            "ERROR: Explanations::load - line %d "
106            "out of sync at the explanation\n",
107            line
108          );
109          exit( -1 );
110        }
111        buffer[ strlen(buffer) - 1] = '\0';
112        line++;
113
114        const char delimiter[4] = "+++";
115        if (!strncmp( buffer, delimiter, 3 )) {
116          break;
117        }
118        // XXX only taking last line.  Needs to be a vector
119        e->explanation.push_back( buffer );
120      }
121
122      // Add this to the set of Explanations
123      set[ e->startingPoint ] = *e;
124    }
125done:
126    ;
127
128    #undef MAX_LINE_LENGTH
129  }
130
131  const Explanation *Explanations::lookupExplanation(
132    std::string& start
133  )
134  {
135    if (set.find( start ) == set.end()) {
136      #if 0
137        fprintf( stderr,
138          "Warning: Unable to find explanation for %s\n",
139          start.c_str()
140        );
141      #endif
142      return NULL;
143    }
144    set[ start ].found = true;
145    return &set[ start ];
146  }
147
148  void Explanations::writeNotFound(
149    const char* const fileName
150  )
151  {
152    FILE* notFoundFile;
153    bool  notFoundOccurred = false;
154
155    if (!fileName)
156      return;
157   
158    notFoundFile = fopen( fileName, "w" );
159    if (!fileName) {
160      fprintf(
161        stderr,
162        "ERROR: Explanations::writeNotFound - unable to open file %s\n",
163        fileName
164      );
165      exit( -1 );
166    }
167   
168    for (std::map<std::string, Explanation>::iterator itr = set.begin();
169         itr != set.end();
170         itr++) {
171      Explanation e = (*itr).second;
172      std::string key = (*itr).first;
173 
174      if (!e.found) {
175        notFoundOccurred = true;
176        fprintf(
177          notFoundFile,
178          "%s\n",
179          e.startingPoint.c_str()
180        );
181      } 
182    }
183    fclose( notFoundFile );
184
185    if (!notFoundOccurred) {
186      if (!unlink( fileName )) {
187        fprintf( stderr, 
188          "Warning: Unable to unlink %s\n\n", 
189          fileName
190        );
191      }
192    } 
193  }
194
195}
Note: See TracBrowser for help on using the repository browser.