static char *parse_bar(char *p)
{
	struct SYMBOL *s;
	char *q;
	int bar_type, i;
	char repeat_value[32];

	q = --p;			// keep the first char
	bar_type = 0;
	for (;;) {
		switch (*p++) {
		case '|':
			bar_type <<= 4;
			bar_type |= B_BAR;
			continue;
		case '[':
			bar_type <<= 4;
			bar_type |= B_OBRA;
			continue;
		case ']':
			bar_type <<= 4;
			bar_type |= B_CBRA;
			continue;
		case ':':
			bar_type <<= 4;
			bar_type |= B_COL;
			continue;
		default:
			break;
		}
		break;
	}
	p--;

	/* if the last element is '[', it may start
	 * a chord, an embedded header or an other bar */
	if ((bar_type & 0x0f) == B_OBRA && bar_type != B_OBRA
	 && *p != ' ') {
		bar_type >>= 4;
		p--;
	}

	if (bar_type == (B_OBRA << 8) + (B_BAR << 4) + B_CBRA)	/* [|] */
		bar_type = (B_OBRA << 4) + B_CBRA;		/* [] */

/*	curvoice->last_note = NULL; */
	if (vover > 0) {
		curvoice = &voice_tb[curvoice->mvoice];
		vover = 0;
	}
	s = abc_new(ABC_T_BAR, gchord);
	if (gchord)
		gchord = NULL;

	/* handle the repeat sequences */
	if (bar_type == B_COL) {
		bar_type = B_BAR;
		s->u.bar.dotted = 1;
	} else {
		if (*q == ']') {		/* repeat bar stop */
			i = p - q - 1;
			if (i > 0)		/* remove the starting ']' */
				s->u.bar.type &= (1 << (i * 4)) - 1;
			s->flags |= ABC_F_RBSTOP;
			s->sflags |= S_RBSTOP;
		} else if ((bar_type & 0x0f) == B_COL	/* left or */
			|| *q == ':') {			/* right repeat bar */
			s->flags |= ABC_F_RBSTOP;
			s->sflags |= S_RBSTOP;
			if (*q == ':')		/* right repeat bar */
				s->sflags |= S_RRBAR;
		}
	}

	s->u.bar.type = bar_type;

	if (dc.n > 0) {
		memcpy(&s->u.bar.dc, &dc, sizeof s->u.bar.dc);
		dc.n = 0;
	}

	if (!lyric_started) {
		lyric_started = 1;
		s->flags |= ABC_F_LYRIC_START;
	}

	if (!isdigit((unsigned char) *p)	/* if not a repeat bar */
	 && (*p != '"' || p[-1] != '['))	/* ('["' only) */
		return p;

	if (*p == '"') {
		p = get_str(repeat_value, p, sizeof repeat_value);
	} else {
		char *q;

		q = repeat_value;
		while (isdigit((unsigned char) *p)
		    || *p == ','
		    || *p == '-'
		    || (*p == '.' && isdigit((unsigned char) p[1]))) {
			if (q < &repeat_value[sizeof repeat_value - 1])
				*q++ = *p++;
			else
				p++;
		}
		*q = '\0';
	}
	if (bar_type != B_OBRA
	 || s->text) {
		s = abc_new(ABC_T_BAR, repeat_value);
		s->u.bar.type = B_OBRA;
	} else {
		s->text = getarena(strlen(repeat_value) + 1);
		strcpy(s->text, repeat_value);
	}
	s->u.bar.repeat_bar = 1;
	s->flags |= ABC_F_RBSTART | ABC_F_RBSTOP;
	s->sflags |= S_RBSTART | S_RBSTOP;
	return p;
}
static char *parse_bar(char *p)
{
	struct SYMBOL *s;
	char *q;
	int bar_type, i;
	char repeat_value[32];

	q = --p;			 
	bar_type = 0;
	for (;;) {
		switch (*p++) {
		case '|':
			bar_type <<= 4;
			bar_type |= B_BAR;
			continue;
		case '[':
			bar_type <<= 4;
			bar_type |= B_OBRA;
			continue;
		case ']':
			bar_type <<= 4;
			bar_type |= B_CBRA;
			continue;
		case ':':
			bar_type <<= 4;
			bar_type |= B_COL;
			continue;
		default:
			break;
		}
		break;
	}
	p--;

	 
	if ((bar_type & 0x0f) == B_OBRA && bar_type != B_OBRA
	 && *p != ' ') {
		bar_type >>= 4;
		p--;
	}

	if (bar_type == (B_OBRA << 8) + (B_BAR << 4) + B_CBRA)	 
		bar_type = (B_OBRA << 4) + B_CBRA;		 

 
	if (vover > 0) {
		curvoice = &voice_tb[curvoice->mvoice];
		vover = 0;
	}
	s = abc_new(ABC_T_BAR, gchord);
	if (gchord)
		gchord = NULL;

	 
	if (bar_type == B_COL) {
		bar_type = B_BAR;
		s->u.bar.dotted = 1;
	} else {
		if (*q == ']') {		 
			i = p - q - 1;
			if (i > 0)		 
				s->u.bar.type &= (1 << (i * 4)) - 1;
			s->flags |= ABC_F_RBSTOP;
			s->sflags |= S_RBSTOP;
		} else if ((bar_type & 0x0f) == B_COL	 
			|| *q == ':') {			 
			s->flags |= ABC_F_RBSTOP;
			s->sflags |= S_RBSTOP;
			if (*q == ':')		 
				s->sflags |= S_RRBAR;
		}
	}

	s->u.bar.type = bar_type;

	if (dc.n > 0) {
		memcpy(&s->u.bar.dc, &dc, sizeof s->u.bar.dc);
		dc.n = 0;
	}

	if (!lyric_started) {
		lyric_started = 1;
		s->flags |= ABC_F_LYRIC_START;
	}

	if (!isdigit((unsigned char) *p)	 
	 && (*p != '"' || p[-1] != '['))	 
		return p;

	if (*p == '"') {
		p = get_str(repeat_value, p, sizeof repeat_value);
	} else {
		char *q;

		q = repeat_value;
		while (isdigit((unsigned char) *p)
		    || *p == ','
		    || *p == '-'
		    || (*p == '.' && isdigit((unsigned char) p[1]))) {
			if (q < &repeat_value[sizeof repeat_value - 1])
				*q++ = *p++;
			else
				p++;
		}
		*q = '\0';
	}
	if (bar_type != B_OBRA
	 || s->text) {
		s = abc_new(ABC_T_BAR, repeat_value);
		s->u.bar.type = B_OBRA;
	} else {
		s->text = getarena(strlen(repeat_value) + 1);
		strcpy(s->text, repeat_value);
	}
	s->u.bar.repeat_bar = 1;
	s->flags |= ABC_F_RBSTART | ABC_F_RBSTOP;
	s->sflags |= S_RBSTART | S_RBSTOP;
	return p;
}