Avoid tabs in C output.

Signed-off-by: Wilson Snyder <[email protected]>
This commit is contained in:
Maarten De Braekeleer
2019-10-04 21:10:53 -04:00
committed by Wilson Snyder
parent 771a301f66
commit 977a767477
3 changed files with 6 additions and 24 deletions
+5 -22
View File
@@ -587,25 +587,6 @@ V3OutFormatter::V3OutFormatter(const string& filename, V3OutFormatter::Language
//----------------------------------------------------------------------
const char* V3OutFormatter::indentStr(int num) {
// Indent the specified number of spaces. Use tabs as possible.
static char str[MAXSPACE+20];
char* cp = str;
if (num>MAXSPACE) num = MAXSPACE;
if (m_lang!=LA_VERILOG && m_lang!=LA_XML) { // verilogPrefixedTree doesn't want tabs
while (num>=8) {
*cp++ = '\t';
num -= 8;
}
}
while (num>0) {
*cp++ = ' ';
num --;
}
*cp++ = '\0';
return (str);
}
const string V3OutFormatter::indentSpaces(int num) {
// Indent the specified number of spaces. Use spaces.
static char str[MAXSPACE+20];
@@ -639,6 +620,8 @@ int V3OutFormatter::endLevels(const char *strg) {
const char* cp = strg;
while (isspace(*cp)) cp++;
switch (*cp) {
case '\0': // End of string... No need for whitespace before it
return (0);
case '\n': // Newlines.. No need for whitespace before it
return (0);
case '#': // Preproc directive
@@ -680,7 +663,7 @@ int V3OutFormatter::endLevels(const char *strg) {
void V3OutFormatter::puts(const char *strg) {
if (m_prependIndent) {
putsNoTracking(indentStr(endLevels(strg)));
putsNoTracking(indentSpaces(endLevels(strg)));
m_prependIndent = false;
}
bool wordstart = true;
@@ -695,7 +678,7 @@ void V3OutFormatter::puts(const char *strg) {
m_prependIndent = true; // Add the indent later, may be a indentInc/indentDec called between now and then
} else {
m_prependIndent = false;
putsNoTracking(indentStr(endLevels(cp+1)));
putsNoTracking(indentSpaces(endLevels(cp+1)));
}
break;
case ' ':
@@ -808,7 +791,7 @@ void V3OutFormatter::putBreak() {
//char s[1000]; sprintf(s, "{%d,%d}", m_column, m_parenVec.top()); putsNoTracking(s);
if (exceededWidth()) {
putcNoTracking('\n');
if (!m_parenVec.empty()) putsNoTracking(indentStr(m_parenVec.top()));
if (!m_parenVec.empty()) putsNoTracking(indentSpaces(m_parenVec.top()));
}
}
}