1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 19:40:31 +03:00

removed dependency on sprintf which caused gcc to puke (shock and horror).

uses code from here:
66552ef8b0

git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@119 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
timecop 2012-03-17 15:08:05 +00:00
parent 2fc24b338e
commit c1cb4287b7
3 changed files with 2761 additions and 2777 deletions

View file

@ -86,6 +86,40 @@ const clivalue_t valueTable[] = {
static void cliSetVar(const clivalue_t *var, const int32_t value);
static void cliPrintVar(const clivalue_t *var);
/*
** The following two functions together make up an itoa()
** implementation. Function i2a() is a 'private' function
** called by the public itoa() function.
**
** itoa() takes three arguments:
** 1) the integer to be converted,
** 2) a pointer to a character conversion buffer,
** 3) the radix for the conversion
** which can range between 2 and 36 inclusive
** range errors on the radix default it to base10
** Code from http://groups.google.com/group/comp.lang.c/msg/66552ef8b04fe1ab?pli=1
*/
static char *i2a(unsigned i, char *a, unsigned r)
{
if (i / r > 0)
a = i2a(i / r, a, r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % r];
return a + 1;
}
char *itoa(int i, char *a, int r)
{
if ((r < 2) || (r > 36))
r = 10;
if (i < 0) {
*a = '-';
*i2a(-(unsigned)i, a + 1, r) = 0;
} else
*i2a(i, a, r) = 0;
return a;
}
static void cliPrompt(void)
{
uartPrint("\r\n# ");
@ -259,7 +293,7 @@ static void cliPrintVar(const clivalue_t *var)
value = *(int16_t *)var->ptr;
break;
}
snprintf(buf, 16, "%d", value);
itoa(value, buf, 10);
uartPrint(buf);
}