

char bras[] = "[{(<`«\"";
char kets[] = "]})>'»\"";

char *openbrackets = bras;
char *closebrackets = kets;

char match_of (char bra)
{
    int i;
    for (i = 0; open_brackets[i]; ++i) {
	if (bra == open_brackets[i]) {
	    return close_brackets[i];
	    break;
	} /* if */
    } /* for */
    return 0;
} /* match_of */


char * find_match (char *text)
{
    char bra  = *text, curr, ket;
    int stack = 0;

    ket = match_of(bra);             // get the close bracket

    while ((curr = *(++text)) && (stack || (curr != ket))) {
	if (IS_ESC(curr))
	    if (!(curr = *(++text))) // ignore escaped characters
		break;
	else if (curr == bra)        // count open-brackets
	    ++stack;
	else if (curr == ket)        // release them on close
	    --stack;
    } /* while */

    if (curr)
	return text;
    return NULL;
} /* find_match */


/* SLOW! */
char * strip_escs (char * text)
{
    int len = strlen (text);
    char *dest = text, *ret = text;

    *(text + len - 1) = 0;  // remove the last
    //REMOVE ();              // remove the first
    ++text;

    while (c = *(text)) {
	if (c == '\\') {
	    //REMOVE();       // remove the escape
	    ++text;
	    if (!(c = *text))
		return NULL;
	} /* if */
	//ACCEPT();           // accept the character
	*(dest++) = c; ++text;
    } /* while */

    return ret; 	    // return the stripped string
} /* strip_escs */


