53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
/* build a list from a null-terminated char* vector. */
|
|
#include "cstuff.h"
|
|
s48_value char_pp_2_string_list(char **vec){
|
|
char ** ptr = vec;
|
|
s48_value list = S48_NULL;
|
|
|
|
S48_DECLARE_GC_PROTECT(1);
|
|
S48_GC_PROTECT_1(list);
|
|
|
|
while (ptr && *(ptr)){
|
|
list = s48_cons (s48_enter_string (*ptr), list);
|
|
ptr++;
|
|
}
|
|
S48_GC_UNPROTECT();
|
|
return list;
|
|
}
|
|
|
|
char *scheme2c_strcpy(s48_value sstr)
|
|
{
|
|
char *result;
|
|
int slen;
|
|
|
|
slen = S48_STRING_LENGTH(sstr);
|
|
result = Malloc(char, slen+1);
|
|
|
|
if( result == NULL ) {
|
|
fprintf(stderr,
|
|
"Fatal error: C stub tried to copy Scheme string,\n"
|
|
"but malloc failed on arg 0x%x, errno %d.\n",
|
|
sstr, errno);
|
|
exit(-1);
|
|
}
|
|
|
|
memcpy(result, s48_extract_string(sstr), slen);
|
|
result[slen] = '\000';
|
|
return result;
|
|
}
|
|
|
|
s48_value strlen_or_false(const char *s)
|
|
{ return s ? s48_enter_fixnum(strlen(s)) : S48_FALSE; }
|
|
|
|
/* Helper function for arg checking. Why bother, actually? */
|
|
void cig_check_nargs(int arity, int nargs, const char *fn)
|
|
{
|
|
if( arity != nargs ) {
|
|
fprintf(stderr,
|
|
"Cig fatal error (%s) -- C stub expected %d arg%s, "
|
|
"but got %d.\n",
|
|
fn, arity, (arity == 1) ? "" : "s", nargs);
|
|
exit(-1);
|
|
}
|
|
}
|