|
|
@@ -27,7 +27,8 @@
|
|
|
* SUCH DAMAGE.
|
|
|
*/
|
|
|
#include "flipbip_string.h"
|
|
|
-#include <string.h>
|
|
|
+// #include <string.h>
|
|
|
+#include <ctype.h>
|
|
|
char *
|
|
|
flipbip_strtok(char *s, const char *delim)
|
|
|
{
|
|
|
@@ -75,4 +76,41 @@ cont:
|
|
|
} while (sc != 0);
|
|
|
}
|
|
|
/* NOTREACHED */
|
|
|
+}
|
|
|
+void
|
|
|
+flipbip_strrev(unsigned char *str)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int j;
|
|
|
+ unsigned char a;
|
|
|
+ unsigned len = strlen((const char *)str);
|
|
|
+ for (i = 0, j = len - 1; i < j; i++, j--)
|
|
|
+ {
|
|
|
+ a = str[i];
|
|
|
+ str[i] = str[j];
|
|
|
+ str[j] = a;
|
|
|
+ }
|
|
|
+}
|
|
|
+int
|
|
|
+flipbip_itoa(int num, unsigned char* str, int len, int base)
|
|
|
+{
|
|
|
+ int sum = num;
|
|
|
+ int i = 0;
|
|
|
+ int digit;
|
|
|
+ if (len == 0)
|
|
|
+ return -1;
|
|
|
+ do
|
|
|
+ {
|
|
|
+ digit = sum % base;
|
|
|
+ if (digit < 0xA)
|
|
|
+ str[i++] = '0' + digit;
|
|
|
+ else
|
|
|
+ str[i++] = 'A' + digit - 0xA;
|
|
|
+ sum /= base;
|
|
|
+ }while (sum && (i < (len - 1)));
|
|
|
+ if (i == (len - 1) && sum)
|
|
|
+ return -1;
|
|
|
+ str[i] = '\0';
|
|
|
+ flipbip_strrev(str);
|
|
|
+ return 0;
|
|
|
}
|