5 * Aligns the given pointer to FICL_ALIGN address units.
6 * Returns the aligned pointer value.
9 ficlAlignPointer(void *ptr
)
11 #if FICL_PLATFORM_ALIGNMENT > 1
12 intptr_t p
= (intptr_t)ptr
;
14 if (p
& (FICL_PLATFORM_ALIGNMENT
- 1))
15 ptr
= (void *)((p
& ~(FICL_PLATFORM_ALIGNMENT
- 1)) +
16 FICL_PLATFORM_ALIGNMENT
);
25 ficlStringReverse(char *string
)
27 int i
= strlen(string
);
28 char *p1
= string
; /* first char of string */
29 char *p2
= string
+ i
- 1; /* last non-NULL char of string */
45 * d i g i t _ t o _ c h a r
47 static char digits
[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
50 ficlDigitToCharacter(int value
)
52 return (digits
[value
]);
56 * i s P o w e r O f T w o
57 * Tests whether supplied argument is an integer power of 2 (2**n)
58 * where 32 > n > 1, and returns n if so. Otherwise returns zero.
61 ficlIsPowerOfTwo(ficlUnsigned u
)
66 for (; ((t
<= u
) && (t
!= 0)); i
++, t
<<= 1) {
78 ficlLtoa(ficlInteger value
, char *string
, int radix
)
81 int sign
= ((radix
== 10) && (value
< 0));
84 FICL_ASSERT(NULL
, radix
> 1);
85 FICL_ASSERT(NULL
, radix
< 37);
86 FICL_ASSERT(NULL
, string
);
88 pwr
= ficlIsPowerOfTwo((ficlUnsigned
)radix
);
96 ficlUnsigned v
= (ficlUnsigned
) value
;
97 ficlUnsigned mask
= (ficlUnsigned
) ~(-1 << pwr
);
99 *cp
++ = digits
[v
& mask
];
103 ficl2UnsignedQR result
;
105 FICL_UNSIGNED_TO_2UNSIGNED((ficlUnsigned
)value
, v
);
106 while (FICL_2UNSIGNED_NOT_ZERO(v
)) {
107 result
= ficl2UnsignedDivide(v
, (ficlUnsigned
)radix
);
108 *cp
++ = digits
[result
.remainder
];
118 return (ficlStringReverse(string
));
125 ficlUltoa(ficlUnsigned value
, char *string
, int radix
)
129 ficl2UnsignedQR result
;
131 FICL_ASSERT(NULL
, radix
> 1);
132 FICL_ASSERT(NULL
, radix
< 37);
133 FICL_ASSERT(NULL
, string
);
138 FICL_UNSIGNED_TO_2UNSIGNED(value
, ud
);
139 while (FICL_2UNSIGNED_NOT_ZERO(ud
)) {
140 result
= ficl2UnsignedDivide(ud
, (ficlUnsigned
)radix
);
141 ud
= result
.quotient
;
142 *cp
++ = digits
[result
.remainder
];
148 return (ficlStringReverse(string
));
153 * Case folds a NULL terminated string in place. All characters
154 * get converted to lower case.
157 ficlStringCaseFold(char *cp
)
162 if (isupper((unsigned char)*cp
))
163 *cp
= (char)tolower((unsigned char)*cp
);
172 * (jws) simplified the code a bit in hopes of appeasing Purify
175 ficlStrincmp(char *cp1
, char *cp2
, ficlUnsigned count
)
179 for (; 0 < count
; ++cp1
, ++cp2
, --count
) {
180 i
= tolower((unsigned char)*cp1
) - tolower((unsigned char)*cp2
);
183 else if (*cp1
== '\0')
191 * Given a string pointer, returns a pointer to the first non-space
192 * char of the string, or to the NULL terminator if no such char found.
193 * If the pointer reaches "end" first, stop there. Pass NULL to
194 * suppress this behavior.
197 ficlStringSkipSpace(char *cp
, char *end
)
199 FICL_ASSERT(NULL
, cp
);
201 while ((cp
!= end
) && isspace((unsigned char)*cp
))
208 ficlCompatibilityTextOutCallback(ficlCallback
*callback
, char *text
,
209 ficlCompatibilityOutputFunction outputFunction
)
212 char *bufferStop
= buffer
+ sizeof (buffer
) - 1;
215 outputFunction(callback
->vm
, NULL
, 0 /* false */);
220 int newline
= 0 /* false */;
221 char *trace
= buffer
;
222 while ((*text
) && (trace
< bufferStop
)) {
230 newline
= !0 /* true */;
239 (outputFunction
)(callback
->vm
, buffer
, newline
);