diff options
author | Kévin Redon <kredon@sysmocom.de> | 2018-07-08 13:58:12 +0200 |
---|---|---|
committer | Kévin Redon <kredon@sysmocom.de> | 2018-07-11 22:01:58 +0200 |
commit | 33d1eb73fdc3db0ca5f429c99ca65dd958cceaf1 (patch) | |
tree | 847873fb2f5e89c43032897f07c18daab5fb9477 /firmware/libcommon/source/stdio.c | |
parent | 93717e43b38348821b32cd476c1ab87b1bed9edb (diff) |
replace leading spaces with tabs
Change-Id: I86783eba0827b58303b10310e9f6b9625e1a27f1
Diffstat (limited to 'firmware/libcommon/source/stdio.c')
-rw-r--r-- | firmware/libcommon/source/stdio.c | 472 |
1 files changed, 236 insertions, 236 deletions
diff --git a/firmware/libcommon/source/stdio.c b/firmware/libcommon/source/stdio.c index 32bd617..505c895 100644 --- a/firmware/libcommon/source/stdio.c +++ b/firmware/libcommon/source/stdio.c @@ -76,8 +76,8 @@ FILE* const stderr = NULL; //------------------------------------------------------------------------------ signed int PutChar(char *pStr, char c) { - *pStr = c; - return 1; + *pStr = c; + return 1; } //------------------------------------------------------------------------------ @@ -89,15 +89,15 @@ signed int PutChar(char *pStr, char c) //------------------------------------------------------------------------------ signed int PutString(char *pStr, const char *pSource) { - signed int num = 0; + signed int num = 0; - while (*pSource != 0) { + while (*pSource != 0) { - *pStr++ = *pSource++; - num++; - } + *pStr++ = *pSource++; + num++; + } - return num; + return num; } //------------------------------------------------------------------------------ @@ -110,38 +110,38 @@ signed int PutString(char *pStr, const char *pSource) // \param value Integer value. //------------------------------------------------------------------------------ signed int PutUnsignedInt( - char *pStr, - char fill, - signed int width, - unsigned int value) + char *pStr, + char fill, + signed int width, + unsigned int value) { - signed int num = 0; + signed int num = 0; - // Take current digit into account when calculating width - width--; + // Take current digit into account when calculating width + width--; - // Recursively write upper digits - if ((value / 10) > 0) { + // Recursively write upper digits + if ((value / 10) > 0) { - num = PutUnsignedInt(pStr, fill, width, value / 10); - pStr += num; - } - // Write filler characters - else { + num = PutUnsignedInt(pStr, fill, width, value / 10); + pStr += num; + } + // Write filler characters + else { - while (width > 0) { + while (width > 0) { - PutChar(pStr, fill); - pStr++; - num++; - width--; - } - } + PutChar(pStr, fill); + pStr++; + num++; + width--; + } + } - // Write lower digit - num += PutChar(pStr, (value % 10) + '0'); + // Write lower digit + num += PutChar(pStr, (value % 10) + '0'); - return num; + return num; } //------------------------------------------------------------------------------ @@ -154,69 +154,69 @@ signed int PutUnsignedInt( // \param value Signed integer value. //------------------------------------------------------------------------------ signed int PutSignedInt( - char *pStr, - char fill, - signed int width, - signed int value) + char *pStr, + char fill, + signed int width, + signed int value) { - signed int num = 0; - unsigned int absolute; + signed int num = 0; + unsigned int absolute; - // Compute absolute value - if (value < 0) { + // Compute absolute value + if (value < 0) { - absolute = -value; - } - else { + absolute = -value; + } + else { - absolute = value; - } + absolute = value; + } - // Take current digit into account when calculating width - width--; + // Take current digit into account when calculating width + width--; - // Recursively write upper digits - if ((absolute / 10) > 0) { + // Recursively write upper digits + if ((absolute / 10) > 0) { - if (value < 0) { - - num = PutSignedInt(pStr, fill, width, -(absolute / 10)); - } - else { + if (value < 0) { + + num = PutSignedInt(pStr, fill, width, -(absolute / 10)); + } + else { - num = PutSignedInt(pStr, fill, width, absolute / 10); - } - pStr += num; - } - else { + num = PutSignedInt(pStr, fill, width, absolute / 10); + } + pStr += num; + } + else { - // Reserve space for sign - if (value < 0) { + // Reserve space for sign + if (value < 0) { - width--; - } + width--; + } - // Write filler characters - while (width > 0) { + // Write filler characters + while (width > 0) { - PutChar(pStr, fill); - pStr++; - num++; - width--; - } + PutChar(pStr, fill); + pStr++; + num++; + width--; + } - // Write sign - if (value < 0) { + // Write sign + if (value < 0) { - num += PutChar(pStr, '-'); - pStr++; - } - } + num += PutChar(pStr, '-'); + pStr++; + } + } - // Write lower digit - num += PutChar(pStr, (absolute % 10) + '0'); + // Write lower digit + num += PutChar(pStr, (absolute % 10) + '0'); - return num; + return num; } //------------------------------------------------------------------------------ @@ -230,51 +230,51 @@ signed int PutSignedInt( // \param value Hexadecimal value. //------------------------------------------------------------------------------ signed int PutHexa( - char *pStr, - char fill, - signed int width, - unsigned char maj, - unsigned int value) + char *pStr, + char fill, + signed int width, + unsigned char maj, + unsigned int value) { - signed int num = 0; + signed int num = 0; - // Decrement width - width--; + // Decrement width + width--; - // Recursively output upper digits - if ((value >> 4) > 0) { + // Recursively output upper digits + if ((value >> 4) > 0) { - num += PutHexa(pStr, fill, width, maj, value >> 4); - pStr += num; - } - // Write filler chars - else { + num += PutHexa(pStr, fill, width, maj, value >> 4); + pStr += num; + } + // Write filler chars + else { - while (width > 0) { + while (width > 0) { - PutChar(pStr, fill); - pStr++; - num++; - width--; - } - } + PutChar(pStr, fill); + pStr++; + num++; + width--; + } + } - // Write current digit - if ((value & 0xF) < 10) { + // Write current digit + if ((value & 0xF) < 10) { - PutChar(pStr, (value & 0xF) + '0'); - } - else if (maj) { + PutChar(pStr, (value & 0xF) + '0'); + } + else if (maj) { - PutChar(pStr, (value & 0xF) - 10 + 'A'); - } - else { + PutChar(pStr, (value & 0xF) - 10 + 'A'); + } + else { - PutChar(pStr, (value & 0xF) - 10 + 'a'); - } - num++; + PutChar(pStr, (value & 0xF) - 10 + 'a'); + } + num++; - return num; + return num; } //------------------------------------------------------------------------------ @@ -292,91 +292,91 @@ signed int PutHexa( //------------------------------------------------------------------------------ signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap) { - char fill; - unsigned char width; - signed int num = 0; - size_t size = 0; - - // Clear the string - if (pStr) { - - *pStr = 0; - } - - // Phase string - while (*pFormat != 0 && size < length) { - - // Normal character - if (*pFormat != '%') { - - *pStr++ = *pFormat++; - size++; - } - // Escaped '%' - else if (*(pFormat+1) == '%') { - - *pStr++ = '%'; - pFormat += 2; - size++; - } - // Token delimiter - else { - - fill = ' '; - width = 0; - pFormat++; - - // Parse filler - if (*pFormat == '0') { - - fill = '0'; - pFormat++; - } - - // Parse width - while ((*pFormat >= '0') && (*pFormat <= '9')) { - - width = (width*10) + *pFormat-'0'; - pFormat++; - } - - // Check if there is enough space - if (size + width > length) { - - width = length - size; - } - - // Parse type - switch (*pFormat) { - case 'd': - case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break; - case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break; - case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break; - case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break; - case 's': num = PutString(pStr, va_arg(ap, char *)); break; - case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break; - default: - return EOF; - } - - pFormat++; - pStr += num; - size += num; - } - } - - // NULL-terminated (final \0 is not counted) - if (size < length) { - - *pStr = 0; - } - else { - - *(--pStr) = 0; - size--; - } - - return size; + char fill; + unsigned char width; + signed int num = 0; + size_t size = 0; + + // Clear the string + if (pStr) { + + *pStr = 0; + } + + // Phase string + while (*pFormat != 0 && size < length) { + + // Normal character + if (*pFormat != '%') { + + *pStr++ = *pFormat++; + size++; + } + // Escaped '%' + else if (*(pFormat+1) == '%') { + + *pStr++ = '%'; + pFormat += 2; + size++; + } + // Token delimiter + else { + + fill = ' '; + width = 0; + pFormat++; + + // Parse filler + if (*pFormat == '0') { + + fill = '0'; + pFormat++; + } + + // Parse width + while ((*pFormat >= '0') && (*pFormat <= '9')) { + + width = (width*10) + *pFormat-'0'; + pFormat++; + } + + // Check if there is enough space + if (size + width > length) { + + width = length - size; + } + + // Parse type + switch (*pFormat) { + case 'd': + case 'i': num = PutSignedInt(pStr, fill, width, va_arg(ap, signed int)); break; + case 'u': num = PutUnsignedInt(pStr, fill, width, va_arg(ap, unsigned int)); break; + case 'x': num = PutHexa(pStr, fill, width, 0, va_arg(ap, unsigned int)); break; + case 'X': num = PutHexa(pStr, fill, width, 1, va_arg(ap, unsigned int)); break; + case 's': num = PutString(pStr, va_arg(ap, char *)); break; + case 'c': num = PutChar(pStr, va_arg(ap, unsigned int)); break; + default: + return EOF; + } + + pFormat++; + pStr += num; + size += num; + } + } + + // NULL-terminated (final \0 is not counted) + if (size < length) { + + *pStr = 0; + } + else { + + *(--pStr) = 0; + size--; + } + + return size; } //------------------------------------------------------------------------------ @@ -390,14 +390,14 @@ signed int vsnprintf(char *pStr, size_t length, const char *pFormat, va_list ap) //------------------------------------------------------------------------------ signed int snprintf(char *pString, size_t length, const char *pFormat, ...) { - va_list ap; - signed int rc; + va_list ap; + signed int rc; - va_start(ap, pFormat); - rc = vsnprintf(pString, length, pFormat, ap); - va_end(ap); + va_start(ap, pFormat); + rc = vsnprintf(pString, length, pFormat, ap); + va_end(ap); - return rc; + return rc; } //------------------------------------------------------------------------------ @@ -410,7 +410,7 @@ signed int snprintf(char *pString, size_t length, const char *pFormat, ...) //------------------------------------------------------------------------------ signed int vsprintf(char *pString, const char *pFormat, va_list ap) { - return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap); + return vsnprintf(pString, MAX_STRING_SIZE, pFormat, ap); } //------------------------------------------------------------------------------ @@ -422,17 +422,17 @@ signed int vsprintf(char *pString, const char *pFormat, va_list ap) //------------------------------------------------------------------------------ signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap) { - char pStr[MAX_STRING_SIZE]; - char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r"; + char pStr[MAX_STRING_SIZE]; + char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r"; - // Write formatted string in buffer - if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) { + // Write formatted string in buffer + if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) { - fputs(pError, stderr); - } + fputs(pError, stderr); + } - // Display string - return fputs(pStr, pStream); + // Display string + return fputs(pStr, pStream); } //------------------------------------------------------------------------------ @@ -443,7 +443,7 @@ signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap) //------------------------------------------------------------------------------ signed int vprintf(const char *pFormat, va_list ap) { - return vfprintf(stdout, pFormat, ap); + return vfprintf(stdout, pFormat, ap); } //------------------------------------------------------------------------------ @@ -454,15 +454,15 @@ signed int vprintf(const char *pFormat, va_list ap) //------------------------------------------------------------------------------ signed int fprintf(FILE *pStream, const char *pFormat, ...) { - va_list ap; - signed int result; + va_list ap; + signed int result; - // Forward call to vfprintf - va_start(ap, pFormat); - result = vfprintf(pStream, pFormat, ap); - va_end(ap); + // Forward call to vfprintf + va_start(ap, pFormat); + result = vfprintf(pStream, pFormat, ap); + va_end(ap); - return result; + return result; } //------------------------------------------------------------------------------ @@ -472,15 +472,15 @@ signed int fprintf(FILE *pStream, const char *pFormat, ...) //------------------------------------------------------------------------------ signed int printf(const char *pFormat, ...) { - va_list ap; - signed int result; + va_list ap; + signed int result; - // Forward call to vprintf - va_start(ap, pFormat); - result = vprintf(pFormat, ap); - va_end(ap); + // Forward call to vprintf + va_start(ap, pFormat); + result = vprintf(pFormat, ap); + va_end(ap); - return result; + return result; } //------------------------------------------------------------------------------ @@ -490,15 +490,15 @@ signed int printf(const char *pFormat, ...) //------------------------------------------------------------------------------ signed int sprintf(char *pStr, const char *pFormat, ...) { - va_list ap; - signed int result; + va_list ap; + signed int result; - // Forward call to vsprintf - va_start(ap, pFormat); - result = vsprintf(pStr, pFormat, ap); - va_end(ap); + // Forward call to vsprintf + va_start(ap, pFormat); + result = vsprintf(pStr, pFormat, ap); + va_end(ap); - return result; + return result; } //------------------------------------------------------------------------------ @@ -507,6 +507,6 @@ signed int sprintf(char *pStr, const char *pFormat, ...) //------------------------------------------------------------------------------ signed int puts(const char *pStr) { - return fputs(pStr, stdout); + return fputs(pStr, stdout); } |