franz/lam8.c
/*
 * C style sprintf: (sprintf "format" {<arg-list>})
 *
 * This function stacks the arguments onto the C stack in reverse
 * order and then calls sprintf with one argument...This is what the
 * C compiler does, so it works just fine. The return value is the
 * string that is the result of the sprintf.
 */
C style sprintf: (sprintf "format" {})
This function stacks the arguments onto the C stack in reverse
order and then calls sprintf with one argument...This is what the
C compiler does, so it works just fine. The return value is the
string that is the result of the sprintf.
C style sprintf : ( sprintf " format " {} ) This function stacks the arguments onto the C stack in reverse order and then calls sprintf with one argument ... This is what the C compiler does so it works just fine . The return value is the string that is the result of the sprintf .
lispval
Lsprintf()
{
	register struct argent *argp;
	register int j;
	char sbuf[600];			
	Keepxs();
	if (np-lbot == 0) {
		argerr("sprintf");
	}
	if (TYPE(lbot->val)==STRNG || TYPE(lbot->val)==INT) {
		for (argp = np-1; argp >= lbot; argp--) {
			switch(TYPE(argp->val)) {
			  case ATOM:
				stack((long)argp->val->a.pname);
				break;
			  case DOUB:
#ifndef SPISFP
				stack(argp->val->r);
#else
				{double rr = argp->val->r;
				stack(((long *)&rr)[1]);
				stack(((long *)&rr)[0]);}
#endif
				break;
			  case INT:
				stack(argp->val->i);
				break;
			  case STRNG:
				stack((long)argp->val);
				break;
			  default:
				error("sprintf: Bad data type to sprintf",
						FALSE);
			}
		}
		sprintf(sbuf);
		for (j = 0; j < np-lbot; j++)
			unstack();
	} else
		error("sprintf: First arg must be an atom or string", FALSE);
	Freexs();
	return ((lispval) inewstr(sbuf));
}
lispval Lsprintf ( ) { register struct argent * argp ; register int j ; char sbuf [ 600 ] ; Keepxs ( ) ; if ( np - lbot == 0 ) { argerr ( " " ) ; } if ( TYPE ( lbot -> val ) == STRNG || TYPE ( lbot -> val ) == INT ) { for ( argp = np - 1 ; argp >= lbot ; argp -- ) { switch ( TYPE ( argp -> val ) ) { case ATOM : stack ( ( long ) argp -> val -> a . pname ) ; break ; case DOUB : #ifndef SPISFP stack ( argp -> val -> r ) ; #else { double rr = argp -> val -> r ; stack ( ( ( long * ) & rr ) [ 1 ] ) ; stack ( ( ( long * ) & rr ) [ 0 ] ) ; } #endif break ; case INT : stack ( argp -> val -> i ) ; break ; case STRNG : stack ( ( long ) argp -> val ) ; break ; default : error ( " " , FALSE ) ; } } sprintf ( sbuf ) ; for ( j = 0 ; j < np - lbot ; j ++ ) unstack ( ) ; } else error ( " " , FALSE ) ; Freexs ( ) ; return ( ( lispval ) inewstr ( sbuf ) ) ; }
C style sprintf: (sprintf "format" {<arg-list>})
 This function stacks the arguments onto the C stack in reverse
 order and then calls sprintf with one argument...This is what the
 C compiler does, so it works just fine.
C style sprintf : ( sprintf " format " { <arg - list > } ) This function stacks the arguments onto the C stack in reverse order and then calls sprintf with one argument ... This is what the C compiler does so it works just fine .
/* better way? */