6 * Aligns the given pointer to FICL_ALIGN address units.
7 * Returns the aligned pointer value.
10 ficlAlignPointer(void *ptr
)
12 #if FICL_PLATFORM_ALIGNMENT > 1
13 intptr_t p
= (intptr_t)ptr
;
15 if (p
& (FICL_PLATFORM_ALIGNMENT
- 1))
16 ptr
= (void *)((p
& ~(FICL_PLATFORM_ALIGNMENT
- 1)) +
17 FICL_PLATFORM_ALIGNMENT
);
26 ficlStringReverse(char *string
)
28 int i
= strlen(string
);
29 char *p1
= string
; /* first char of string */
30 char *p2
= string
+ i
- 1; /* last non-NULL char of string */
46 * d i g i t _ t o _ c h a r
48 static char digits
[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
51 ficlDigitToCharacter(int value
)
53 return (digits
[value
]);
57 * i s P o w e r O f T w o
58 * Tests whether supplied argument is an integer power of 2 (2**n)
59 * where 32 > n > 1, and returns n if so. Otherwise returns zero.
62 ficlIsPowerOfTwo(ficlUnsigned u
)
67 for (; ((t
<= u
) && (t
!= 0)); i
++, t
<<= 1) {
79 ficlLtoa(ficlInteger value
, char *string
, int radix
)
82 int sign
= ((radix
== 10) && (value
< 0));
85 FICL_ASSERT(NULL
, radix
> 1);
86 FICL_ASSERT(NULL
, radix
< 37);
87 FICL_ASSERT(NULL
, string
);
89 pwr
= ficlIsPowerOfTwo((ficlUnsigned
)radix
);
97 ficlUnsigned v
= (ficlUnsigned
) value
;
98 ficlUnsigned mask
= ~(ULONG_MAX
<< pwr
);
100 *cp
++ = digits
[v
& mask
];
104 ficl2UnsignedQR result
;
106 FICL_UNSIGNED_TO_2UNSIGNED((ficlUnsigned
)value
, v
);
107 while (FICL_2UNSIGNED_NOT_ZERO(v
)) {
108 result
= ficl2UnsignedDivide(v
, (ficlUnsigned
)radix
);
109 *cp
++ = digits
[result
.remainder
];
119 return (ficlStringReverse(string
));
126 ficlUltoa(ficlUnsigned value
, char *string
, int radix
)
130 ficl2UnsignedQR result
;
132 FICL_ASSERT(NULL
, radix
> 1);
133 FICL_ASSERT(NULL
, radix
< 37);
134 FICL_ASSERT(NULL
, string
);
139 FICL_UNSIGNED_TO_2UNSIGNED(value
, ud
);
140 while (FICL_2UNSIGNED_NOT_ZERO(ud
)) {
141 result
= ficl2UnsignedDivide(ud
, (ficlUnsigned
)radix
);
142 ud
= result
.quotient
;
143 *cp
++ = digits
[result
.remainder
];
149 return (ficlStringReverse(string
));
154 * Case folds a NULL terminated string in place. All characters
155 * get converted to lower case.
158 ficlStringCaseFold(char *cp
)
163 if (isupper((unsigned char)*cp
))
164 *cp
= (char)tolower((unsigned char)*cp
);
173 * (jws) simplified the code a bit in hopes of appeasing Purify
176 ficlStrincmp(char *cp1
, char *cp2
, ficlUnsigned count
)
180 for (; 0 < count
; ++cp1
, ++cp2
, --count
) {
181 i
= tolower((unsigned char)*cp1
) - tolower((unsigned char)*cp2
);
184 else if (*cp1
== '\0')
192 * Given a string pointer, returns a pointer to the first non-space
193 * char of the string, or to the NULL terminator if no such char found.
194 * If the pointer reaches "end" first, stop there. Pass NULL to
195 * suppress this behavior.
198 ficlStringSkipSpace(char *cp
, char *end
)
200 FICL_ASSERT(NULL
, cp
);
202 while ((cp
!= end
) && isspace((unsigned char)*cp
))
209 ficlCompatibilityTextOutCallback(ficlCallback
*callback
, char *text
,
210 ficlCompatibilityOutputFunction outputFunction
)
213 char *bufferStop
= buffer
+ sizeof (buffer
) - 1;
216 outputFunction(callback
->vm
, NULL
, 0 /* false */);
221 int newline
= 0 /* false */;
222 char *trace
= buffer
;
223 while ((*text
) && (trace
< bufferStop
)) {
231 newline
= !0 /* true */;
240 (outputFunction
)(callback
->vm
, buffer
, newline
);