src/uutils.c
/************************************************************************/
/*									*/
/*		c _ s t r i n g _ t o _ l i s p _ s t r i n g		*/
/*									*/
/*	copies a C string into an existing Lisp string (it does not 	*/
/*	create a new Lisp string).  Returns 0 if succeeds, -1 if	*/
/*	error (Lisp string is not a simple string, or not long enough,	*/
/*	or is FATP).  The string will end with a null, which the	*/
/*	length must include.						*/
/*									*/
/************************************************************************/
c _ s t r i n g _ t o _ l i s p _ s t r i n g

copies a C string into an existing Lisp string (it does not
create a new Lisp string).  Returns 0 if succeeds, -1 if
error (Lisp string is not a simple string, or not long enough,
or is FATP).  The string will end with a null, which the
length must include.
c _ s t r i n g _ t o _ l i s p _ s t r i n g copies a C string into an existing Lisp string ( it does not create a new Lisp string ) . Returns 0 if succeeds - 1 if error ( Lisp string is not a simple string or not long enough or is FATP ) . The string will end with a null which the length must include .
int c_string_to_lisp_string(char *C, LispPTR Lisp) {
  register OneDArray *arrayp;
  char *base;
  register size_t length;
  length = strlen(C);
  if (GetTypeNumber(Lisp) != TYPE_ONED_ARRAY) { return (-1); }
  arrayp = (OneDArray *)(Addr68k_from_LADDR(Lisp));
  if (arrayp->totalsize < length + 1) { return (-1); }
  switch (arrayp->typenumber) {
    case THIN_CHAR_TYPENUMBER:
      base = ((char *)(Addr68k_from_LADDR(arrayp->base))) + ((int)(arrayp->offset));
#ifndef BYTESWAP
      strcpy(base, C);
#else
      {
        register size_t i;
        register char *dp;
        for (i = 0, dp = C; i < length + 1; i++) {
          char ch = *dp++;
#ifdef DOS
          if (ch == '\\') dp++; 
#endif 
          GETBYTE(base++) = ch;
        }
      }
#endif 
      return 0;
    default: return -1;
  }
}
int c_string_to_lisp_string ( char * C , LispPTR Lisp ) { register OneDArray * arrayp ; char * base ; register size_t length ; length = strlen ( C ) ; if ( GetTypeNumber ( Lisp ) != TYPE_ONED_ARRAY ) { return ( -1 ) ; } arrayp = ( OneDArray * ) ( Addr68k_from_LADDR ( Lisp ) ) ; if ( arrayp -> totalsize < length + 1 ) { return ( -1 ) ; } switch ( arrayp -> typenumber ) { case THIN_CHAR_TYPENUMBER : base = ( ( char * ) ( Addr68k_from_LADDR ( arrayp -> base ) ) ) + ( ( int ) ( arrayp -> offset ) ) ; #ifndef BYTESWAP strcpy ( base , C ) ; #else { register size_t i ; register char * dp ; for ( i = 0 , dp = C ; i < length + 1 ; i ++ ) { char ch = * dp ++ ; #ifdef DOS if ( ch == ' \\ ' ) dp ++ ; #endif GETBYTE ( base ++ ) = ch ; } } #endif return 0 ; default : return -1 ; } }
c _ s t r i n g _ t o _ l i s p _ s t r i n g
c _ s t r i n g _ t o _ l i s p _ s t r i n g
/* too short for C string */ /* skip 2nd \ in \\ in C strings */ /* DOS */ /* BYTESWAP */