imgtools/imgcheck/src/cmdlinewriter.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 /**
    20 /**
    21  @file
    21 @file
    22  @internalComponent
    22 @internalComponent
    23  @released
    23 @released
    24 */
    24 */
    25 
    25 
    26 #include "cmdlinewriter.h"
    26 #include "cmdlinewriter.h"
    27 
    27 #include <stdio.h>
    28 /**
    28 /**
    29 Constructor: CmdLineWriter class
    29 Constructor: CmdLineWriter class
    30 
    30 
    31 @internalComponent
    31 @internalComponent
    32 @released
    32 @released
    33 */
    33 */
    34 CmdLineWriter::CmdLineWriter(unsigned int aInputOptions)
    34 CmdLineWriter::CmdLineWriter(unsigned int aInputOptions)
    35 : iForDepAlign(0), iFormatSize(0), iBuffer(0), iRptType(KCmdLine), iCmdOptions(aInputOptions)
    35 : iForDepAlign(0), iFormatSize(0),  iRptType(KCmdLine), iCmdOptions(aInputOptions) {
    36 {
    36 	//iFormatMessage.flush();
    37 	iFormatMessage.flush();
       
    38 }
    37 }
    39 
    38 
    40 
    39 
    41 /**
    40 /**
    42 Destructor:	CmdLineWriter class
    41 Destructor:	CmdLineWriter class
    44 Clear the Buffer.
    43 Clear the Buffer.
    45 
    44 
    46 @internalComponent
    45 @internalComponent
    47 @released
    46 @released
    48 */
    47 */
    49 CmdLineWriter::~CmdLineWriter(void)
    48 CmdLineWriter::~CmdLineWriter(void) {
    50 {
    49 
    51 	delete [] iBuffer;
       
    52 }
    50 }
    53 
    51 
    54 
    52 
    55 /**
    53 /**
    56 Writes report header to the cmd line..
    54 Writes report header to the cmd line..
    57 Allocates the memory for formatting purpose.
    55 Allocates the memory for formatting purpose.
    58 
    56 
    59 @internalComponent
    57 @internalComponent
    60 @released
    58 @released
    61 */
    59 */
    62 void CmdLineWriter::StartReport(void)
    60 void CmdLineWriter::StartReport(void) { 
    63 {
       
    64 	iBuffer = new char[KCmdGenBufferSize];
       
    65 	if (iBuffer == KNull)
       
    66 	{
       
    67 		throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
       
    68 	}
       
    69 }
    61 }
    70 
    62 
    71 
    63 
    72 /**
    64 /**
    73 Writes the end report info..
    65 Writes the end report info..
    74 Transfer the stream data to stdout.
    66 Transfer the stream data to stdout.
    75 
    67 
    76 @internalComponent
    68 @internalComponent
    77 @released
    69 @released
    78 */
    70 */
    79 void CmdLineWriter::EndReport(void)
    71 void CmdLineWriter::EndReport(void) {
    80 {
    72 	iFormatMessage.flush();
    81 	String outMsg = iFormatMessage.str();
    73 	string str ;
    82 	std::cout << outMsg.c_str();
    74 	while(!iFormatMessage.eof()){
       
    75 		getline(iFormatMessage,str);
       
    76 		cout << str.c_str()<<endl ;
       
    77 	}
    83 }
    78 }
    84 
    79 
    85 
    80 
    86 /**
    81 /**
    87 Writes the executable element footer.
    82 Writes the executable element footer.
    88 
    83 
    89 @internalComponent
    84 @internalComponent
    90 @released
    85 @released
    91 */
    86 */
    92 void CmdLineWriter::EndExecutable(void)
    87 void CmdLineWriter::EndExecutable(void) {
    93 {
    88 	iFormatMessage << endl;
    94 	iFormatMessage << std::endl;
       
    95 	iForDepAlign = false;
    89 	iForDepAlign = false;
    96 
    90 
    97 }
    91 }
    98 
    92 
    99 
    93 
   101 Writes the Delimiter to cmd line.
    95 Writes the Delimiter to cmd line.
   102 
    96 
   103 @internalComponent
    97 @internalComponent
   104 @released
    98 @released
   105 */
    99 */
   106 void CmdLineWriter::WriteDelimiter(void)
   100 void CmdLineWriter::WriteDelimiter(void) {
   107 {
   101 	if(iCmdOptions & KNoCheck) {
   108 	if(iCmdOptions & KNoCheck)
   102 		iFormatMessage << KCmdLineDelimiterNoStatus << endl;
   109 	{
   103 	}
   110 		iFormatMessage << KCmdLineDelimiterNoStatus.c_str() << std::endl;
   104 	else {
   111 	}
   105 		iFormatMessage << KCmdLineDelimiter << endl;
   112 	else
   106 	}
   113 	{
   107 
   114 		iFormatMessage << KCmdLineDelimiter.c_str() << std::endl;
       
   115 	}
       
   116 }
   108 }
   117 
   109 
   118 
   110 
   119 /**
   111 /**
   120 Formats the given element based on set size and places to outstream.
   112 Formats the given element based on set size and places to outstream.
   122 @internalComponent
   114 @internalComponent
   123 @released
   115 @released
   124 
   116 
   125 @param aElement - Reference element to be formated
   117 @param aElement - Reference element to be formated
   126 */
   118 */
   127 void CmdLineWriter::FormatAndWriteElement(const String& aElement)
   119 void CmdLineWriter::FormatAndWriteElement(const string& aElement) {
   128 {
   120 	if(aElement.length() < iFormatSize)
   129 	if (aElement.size() < iFormatSize)
   121 		iFormatMessage << setw(iFormatSize) << aElement.c_str(); 
   130 	{
   122 	else 
   131 		memset(iBuffer,' ',iFormatSize);
   123 		iFormatMessage << aElement.c_str() << ' '; 
   132 		iBuffer[iFormatSize] = '\0';
       
   133 		memcpy(iBuffer,aElement.c_str(),aElement.size());
       
   134 	}
       
   135 	else if(aElement.size() >= (unsigned long)KCmdGenBufferSize)
       
   136 	{
       
   137 		throw ExceptionReporter(FILENAMETOOBIG, __FILE__, __LINE__);
       
   138 	}
       
   139 	else
       
   140 	{
       
   141 		strcpy(iBuffer,aElement.c_str());
       
   142 	}
       
   143 	iFormatMessage << iBuffer << '\t';
       
   144 }
   124 }
   145 
   125 
   146 /**
   126 /**
   147 Writes the note about unknown dependency.
   127 Writes the note about unknown dependency.
   148 
   128 
   149 @internalComponent
   129 @internalComponent
   150 @released
   130 @released
   151 */
   131 */
   152 void CmdLineWriter::WriteNote(void)
   132 void CmdLineWriter::WriteNote(void){
   153 {
   133 	iFormatMessage << KNote << ": " << KUnknownDependency << KNoteMesg << endl;
   154 	iFormatMessage << KNote.c_str() << ": " << KUnknownDependency << KNoteMesg.c_str() << std::endl;
       
   155 }
   134 }
   156 
   135 
   157 
   136 
   158 /**
   137 /**
   159 Writes the image element footer.
   138 Writes the image element footer.
   160 
   139 
   161 @internalComponent
   140 @internalComponent
   162 @released
   141 @released
   163 */
   142 */
   164 void CmdLineWriter::EndImage(void)
   143 void CmdLineWriter::EndImage(void){
   165 {
       
   166 	WriteDelimiter();	
   144 	WriteDelimiter();	
       
   145 
   167 }
   146 }
   168 
   147 
   169 
   148 
   170 /**
   149 /**
   171 Writes the executable name element.
   150 Writes the executable name element.
   173 @internalComponent
   152 @internalComponent
   174 @released
   153 @released
   175 
   154 
   176 @param aExeName  - Reference to executable name.
   155 @param aExeName  - Reference to executable name.
   177 */
   156 */
   178 void CmdLineWriter::StartExecutable(const unsigned int /* aSerNo */, const String& aExeName)
   157 void CmdLineWriter::StartExecutable(const unsigned int /* aSerNo */, const string& aExeName) {
   179 {
   158 	iFormatSize = KCmdFormatTwentyEightWidth; 
   180 	iFormatSize = KCmdFormatTwentyTwoWidth;
       
   181 	FormatAndWriteElement(aExeName);
   159 	FormatAndWriteElement(aExeName);
   182 	iForDepAlign = true;
   160 	iForDepAlign = true;
   183 }	
   161 }	
   184 
   162 
   185 
   163 
   189 @internalComponent
   167 @internalComponent
   190 @released
   168 @released
   191 
   169 
   192 @param aImageName  - Reference to image name.
   170 @param aImageName  - Reference to image name.
   193 */
   171 */
   194 void CmdLineWriter::StartImage(const String& aImageName)
   172 void CmdLineWriter::StartImage(const string& aImageName) {
   195 {
       
   196 	WriteDelimiter();
   173 	WriteDelimiter();
   197 	iFormatMessage << KCmdImageName.c_str() << aImageName.c_str() << std::endl;
   174 	iFormatMessage << KCmdImageName << aImageName.c_str() << endl;
   198 	WriteDelimiter();
   175 	WriteDelimiter();
   199 	if(iCmdOptions & KNoCheck)
   176 	iFormatMessage << setw(KCmdFormatTwentyEightWidth) << left <<setfill(' ')<< "Executable" ;
   200 	{
   177 	iFormatMessage << setw(KCmdFormatTwelveWidth)  << "Attribute" ;
   201 		iFormatMessage << KCmdHeaderNoStatus.c_str() << std::endl;
   178 	iFormatMessage << setw(KCmdFormatTwelveWidth) << "Value" ;
   202 	}
   179 	if(0 == (iCmdOptions & KNoCheck)) {
   203 	else
   180 		iFormatMessage << setw(KCmdFormatTwelveWidth) << "Status" ;
   204 	{
   181 	}
   205 		iFormatMessage << KCmdHeader.c_str() << std::endl;
   182 	iFormatMessage<<endl;
   206 	}
       
   207 	WriteDelimiter();
   183 	WriteDelimiter();
   208 }
   184 }
   209 
   185 
   210 
   186 
   211 /**
   187 /**
   214 @internalComponent
   190 @internalComponent
   215 @released
   191 @released
   216 
   192 
   217 @param aOneSetExeAtt - Reference to the attributes, their value and status
   193 @param aOneSetExeAtt - Reference to the attributes, their value and status
   218 */	
   194 */	
   219 void CmdLineWriter::WriteExeAttribute(ExeAttribute& aOneSetExeAtt)
   195 void CmdLineWriter::WriteExeAttribute(ExeAttribute& aOneSetExeAtt) {
   220 {
   196 	if(!iForDepAlign) {		
   221 	if(!iForDepAlign)
   197 		iFormatSize = KCmdFormatTwentyEightWidth;
   222 	{
       
   223 		iFormatSize = KCmdFormatTwentyTwoWidth;
       
   224 		FormatAndWriteElement("");
   198 		FormatAndWriteElement("");
   225 	}
   199 	}
   226 
   200 	iFormatSize = KCmdFormatTwelveWidth; 
       
   201 	if(KCmdDbgName != aOneSetExeAtt.iAttName) { 
       
   202 		FormatAndWriteElement(aOneSetExeAtt.iAttName);
       
   203 	}
       
   204 	else {
       
   205 		FormatAndWriteElement(KCmdDbgDisplayName);
       
   206 	}
       
   207 
       
   208 	if (KCmdDepName != aOneSetExeAtt.iAttName && KCmdDbgName != aOneSetExeAtt.iAttName) {
       
   209 		unsigned int val = Common::StringToInt(aOneSetExeAtt.iAttValue);
       
   210 		char str[20];
       
   211 		sprintf(str,"0x%08X",val);
       
   212 		// to display the hex value in the format of 0x00000000 if the value is 0
       
   213 		iFormatMessage << setw(KCmdFormatTwelveWidth)  << str ; 
       
   214 	}
       
   215 	else {
       
   216 		iFormatSize = KCmdFormatTwentyEightWidth;
       
   217 		FormatAndWriteElement(aOneSetExeAtt.iAttValue);
       
   218 	}
   227 	iFormatSize = KCmdFormatTwelveWidth;
   219 	iFormatSize = KCmdFormatTwelveWidth;
   228 	if(KCmdDbgName != aOneSetExeAtt.iAttName)
   220 	FormatAndWriteElement(aOneSetExeAtt.iAttStatus);  
   229 	{
   221 	iFormatMessage << endl;
   230 		FormatAndWriteElement(aOneSetExeAtt.iAttName.c_str());
       
   231 	}
       
   232 	else
       
   233 	{
       
   234 		FormatAndWriteElement(KCmdDbgDisplayName.c_str());
       
   235 	}
       
   236 	
       
   237    	if (KCmdDepName != aOneSetExeAtt.iAttName && KCmdDbgName != aOneSetExeAtt.iAttName)
       
   238 	{
       
   239 		unsigned int val;
       
   240 		val = Common::StringToInt(aOneSetExeAtt.iAttValue);
       
   241 		
       
   242 		// to display the hex value in the format of 0x00000000 if the value is 0
       
   243 		iFormatMessage << "0x";
       
   244 		iFormatMessage.width(KCmdFormatEightWidth);
       
   245 		iFormatMessage.fill('0');
       
   246 		iFormatMessage << std::hex << val << '\t';	
       
   247 		iFormatMessage.fill(' ');
       
   248 		iFormatMessage.width(KCmdFormatThirtyWidth);
       
   249 	}
       
   250 	else
       
   251 	{
       
   252 		iFormatSize = KCmdFormatTwentyTwoWidth;
       
   253 		FormatAndWriteElement(aOneSetExeAtt.iAttValue.c_str());
       
   254 	}
       
   255 	iFormatSize = KCmdFormatTwentyTwoWidth;
       
   256 	FormatAndWriteElement(aOneSetExeAtt.iAttStatus.c_str());
       
   257 	iFormatMessage << std::endl;
       
   258 	iForDepAlign = false;
   222 	iForDepAlign = false;
   259 }
   223 }
   260 
   224 
   261 
   225 
   262 /**
   226 /**
   263 Returns the report type.
   227 Returns the report type.
   264 
   228 
   265 @internalComponent
   229 @internalComponent
   266 @released
   230 @released
   267 */
   231 */
   268 const String& CmdLineWriter::ReportType(void)
   232 const string& CmdLineWriter::ReportType(void) {
   269 {
       
   270 	return iRptType;
   233 	return iRptType;
   271 }
   234 }