mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Fixed the remaining cpplint.py warnings (#160)
Replaced std::sprintf in BaeUtilities.cpp with std::stringstream and marked GetVisionErrorText() in FrcError.cpp as NOLINT
This commit is contained in:
committed by
Peter Johnson
parent
b51e85ae26
commit
c99e89dfca
@@ -8,6 +8,8 @@
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -52,7 +54,6 @@ void dprintf(const char* tempString, ...) {
|
||||
const char* functionName; /* Format passed in argument */
|
||||
const char* fmt; /* Format passed in argument */
|
||||
char text[512]; /* Text string */
|
||||
char outtext[512]; /* Text string */
|
||||
FILE* outfile_fd; /* Output file pointer */
|
||||
char filepath[128]; /* Text string */
|
||||
int fatalFlag = 0;
|
||||
@@ -96,35 +97,34 @@ void dprintf(const char* tempString, ...) {
|
||||
va_end(args);
|
||||
|
||||
/* Format output statement */
|
||||
std::stringstream ss;
|
||||
ss << std::setfill('0') << std::setw(4);
|
||||
ss << "[" << filename << ":" << functionName << "@" << line_number << "] ";
|
||||
switch (type) {
|
||||
case DEBUG_TYPE:
|
||||
std::sprintf(outtext, "[%s:%s@%04d] DEBUG %s\n", filename, functionName,
|
||||
line_number, text);
|
||||
ss << "DEBUG";
|
||||
break;
|
||||
case INFO_TYPE:
|
||||
std::sprintf(outtext, "[%s:%s@%04d] INFO %s\n", filename, functionName,
|
||||
line_number, text);
|
||||
ss << "INFO";
|
||||
break;
|
||||
case ERROR_TYPE:
|
||||
std::sprintf(outtext, "[%s:%s@%04d] ERROR %s\n", filename, functionName,
|
||||
line_number, text);
|
||||
ss << "ERROR";
|
||||
break;
|
||||
case CRITICAL_TYPE:
|
||||
std::sprintf(outtext, "[%s:%s@%04d] CRITICAL %s\n", filename,
|
||||
functionName, line_number, text);
|
||||
ss << "CRITICAL";
|
||||
break;
|
||||
case FATAL_TYPE:
|
||||
fatalFlag = 1;
|
||||
std::sprintf(outtext, "[%s:%s@%04d] FATAL %s\n", filename, functionName,
|
||||
line_number, text);
|
||||
ss << "FATAL";
|
||||
break;
|
||||
default:
|
||||
std::printf("ERROR in dprintf: malformed calling sequence\n");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
ss << " " << text << "\n";
|
||||
|
||||
std::sprintf(filepath, "%s.debug", filename);
|
||||
std::snprintf(filepath, sizeof(filepath), "%s.debug", filename);
|
||||
|
||||
/* Write output statement */
|
||||
switch (dprintfFlag) {
|
||||
@@ -134,24 +134,25 @@ void dprintf(const char* tempString, ...) {
|
||||
case DEBUG_MOSTLY_OFF:
|
||||
if (fatalFlag) {
|
||||
if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) {
|
||||
std::fwrite(outtext, sizeof(char), std::strlen(outtext), outfile_fd);
|
||||
std::fwrite(ss.str().c_str(), sizeof(char), ss.str().length(),
|
||||
outfile_fd);
|
||||
std::fclose(outfile_fd);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEBUG_SCREEN_ONLY:
|
||||
std::printf("%s", outtext);
|
||||
std::printf("%s", ss.str().c_str());
|
||||
break;
|
||||
case DEBUG_FILE_ONLY:
|
||||
if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) {
|
||||
fwrite(outtext, sizeof(char), strlen(outtext), outfile_fd);
|
||||
fwrite(ss.str().c_str(), sizeof(char), ss.str().length(), outfile_fd);
|
||||
std::fclose(outfile_fd);
|
||||
}
|
||||
break;
|
||||
case DEBUG_SCREEN_AND_FILE: // BOTH
|
||||
std::printf("%s", outtext);
|
||||
std::printf("%s", ss.str().c_str());
|
||||
if ((outfile_fd = std::fopen(filepath, "a+")) != nullptr) {
|
||||
fwrite(outtext, sizeof(char), strlen(outtext), outfile_fd);
|
||||
fwrite(ss.str().c_str(), sizeof(char), ss.str().length(), outfile_fd);
|
||||
std::fclose(outfile_fd);
|
||||
}
|
||||
break;
|
||||
@@ -331,7 +332,7 @@ int processFile(char* inputFile, char* outputString, int lineNumber) {
|
||||
if (lineNumber > lineCount) return (-1);
|
||||
// return the line selected; lineCount guaranteed to be greater than zero
|
||||
stripString(inputStr);
|
||||
std::strcpy(outputString, inputStr);
|
||||
std::strncpy(outputString, inputStr, kStringSize);
|
||||
return (lineCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -2398,4 +2398,4 @@ const char* GetVisionErrorText(int errorCode) {
|
||||
}
|
||||
|
||||
return errorText;
|
||||
}
|
||||
} // NOLINT
|
||||
|
||||
Reference in New Issue
Block a user