2008-12-30 23:45:08 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "dtypes.h"
|
|
|
|
|
|
|
|
char *int2str(char *dest, size_t n, long num, uint32_t base)
|
|
|
|
{
|
|
|
|
int i = n-1;
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
int b = (int)base, neg = 0;
|
2008-12-30 23:45:08 -05:00
|
|
|
char ch;
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
if (num < 0) {
|
|
|
|
num = -num;
|
|
|
|
neg = 1;
|
|
|
|
}
|
2008-12-30 23:45:08 -05:00
|
|
|
dest[i--] = '\0';
|
|
|
|
while (i >= 0) {
|
|
|
|
ch = (char)(num % b);
|
|
|
|
if (ch < 10)
|
|
|
|
ch += '0';
|
|
|
|
else
|
|
|
|
ch = ch-10+'a';
|
|
|
|
dest[i--] = ch;
|
|
|
|
num /= b;
|
|
|
|
if (num == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 0 && neg)
|
|
|
|
dest[i--] = '-';
|
|
|
|
return &dest[i+1];
|
|
|
|
}
|