if (buffer == 0)
if (nbuffer == 0) { if (buffer != 0) free(buffer);
char *_nc_tic_expand(const char *srcp, bool tic_format){static char *	buffer;static size_t	length;int		bufp;const char	*ptr, *str = VALID_STRING(srcp) ? srcp : "";bool		islong = (strlen(str) > 3);size_t		need = (2 + strlen(str)) * 4;int		ch;	if (buffer == 0) {		buffer = malloc(length = need);	} else if (need > length) {		buffer = realloc(buffer, length = need);	}	if (buffer == 0)		return(NULL);	bufp = 0;	ptr = str;	while ((ch = (*str & 0xff)) != 0) {		if (ch == '%' && REALPRINT(str+1)) {			buffer[bufp++] = *str++;			buffer[bufp++] = *str;		}		else if (ch == 128) {			buffer[bufp++] = '\\';			buffer[bufp++] = '0';		}		else if (ch == '\033') {			buffer[bufp++] = '\\';			buffer[bufp++] = 'E';		}		else if (ch == '\\' && tic_format && (str == srcp || str[-1] != '^')) {			buffer[bufp++] = '\\';			buffer[bufp++] = '\\';		}		else if (ch == ' ' && tic_format && (str == srcp || trailing_spaces(str))) {			buffer[bufp++] = '\\';			buffer[bufp++] = 's';		}		else if ((ch == ',' || ch == ':' || ch == '^') && tic_format) {			buffer[bufp++] = '\\';			buffer[bufp++] = ch;		}		else if (REALPRINT(str) && (ch != ',' && ch != ':' && !(ch == '!' && !tic_format) && ch != '^'))			buffer[bufp++] = ch;#if 0		/* FIXME: this would be more readable (in fact the whole 'islong' logic should be removed) */		else if (ch == '\b') {			buffer[bufp++] = '\\';			buffer[bufp++] = 'b';		}		else if (ch == '\f') {			buffer[bufp++] = '\\';			buffer[bufp++] = 'f';		}		else if (ch == '\t' && islong) {			buffer[bufp++] = '\\';			buffer[bufp++] = 't';		}#endif		else if (ch == '\r' && (islong || (strlen(srcp) > 2 && str[1] == '\0'))) {			buffer[bufp++] = '\\';			buffer[bufp++] = 'r';		}		else if (ch == '\n' && islong) {			buffer[bufp++] = '\\';			buffer[bufp++] = 'n';		}#define UnCtl(c) ((c) + '@')		else if (REALCTL(str) && ch != '\\' && (!islong || isdigit(str[1])))		{			(void) sprintf(&buffer[bufp], "^%c", UnCtl(ch));			bufp += 2;		}		else		{			(void) sprintf(&buffer[bufp], "\\%03o", ch);			bufp += 4;		}		str++;	}	buffer[bufp] = '\0';	return(buffer);}