diff options
| author | Keith Packard <keithp@keithp.com> | 2018-01-04 02:23:40 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2018-01-04 02:23:40 -0800 | 
| commit | 036a5311cbc86dbc5a8f859778d52d588915e4e2 (patch) | |
| tree | 9a41876ad306a50786a34551285f10d8f906555e /src/scheme/ao_scheme_string.c | |
| parent | 0a0327330dcbf5531cd0f8ca8b912fa51ef44f13 (diff) | |
altos/scheme: add make-string builtin
Allocate a blank string.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_string.c')
| -rw-r--r-- | src/scheme/ao_scheme_string.c | 38 | 
1 files changed, 34 insertions, 4 deletions
| diff --git a/src/scheme/ao_scheme_string.c b/src/scheme/ao_scheme_string.c index dfc74966..2c636d7a 100644 --- a/src/scheme/ao_scheme_string.c +++ b/src/scheme/ao_scheme_string.c @@ -51,6 +51,7 @@ ao_scheme_string_alloc(int len)  	if (!s)  		return NULL;  	s->type = AO_SCHEME_STRING; +	s->val[len] = '\0';  	return s;  } @@ -70,7 +71,19 @@ ao_scheme_string_copy(struct ao_scheme_string *a)  }  struct ao_scheme_string * -ao_scheme_string_make(char *a) +ao_scheme_make_string(int32_t len, char fill) +{ +	struct ao_scheme_string	*r; + +	r = ao_scheme_string_alloc(len); +	if (!r) +		return NULL; +	memset(r->val, fill, len); +	return r; +} + +struct ao_scheme_string * +ao_scheme_string_new(char *a)  {  	struct ao_scheme_string	*r; @@ -138,7 +151,6 @@ ao_scheme_string_pack(struct ao_scheme_cons *cons)  			return ao_scheme_error(AO_SCHEME_INVALID, "non-int passed to pack");  		cons = ao_scheme_cons_cdr(cons);  	} -	*rval++ = 0;  	return ao_scheme_string_poly(r);  } @@ -183,14 +195,32 @@ ao_scheme_string_write(ao_poly p, bool write)  		putchar('"');  		while ((c = *sval++)) {  			switch (c) { +			case '\a': +				printf("\\a"); +				break; +			case '\b': +				printf("\\b"); +				break; +			case '\t': +				printf ("\\t"); +				break;  			case '\n':  				printf ("\\n");  				break;  			case '\r':  				printf ("\\r");  				break; -			case '\t': -				printf ("\\t"); +			case '\f': +				printf("\\f"); +				break; +			case '\v': +				printf("\\v"); +				break; +			case '\"': +				printf("\\\""); +				break; +			case '\\': +				printf("\\\\");  				break;  			default:  				if (c < ' ') | 
