Example #1
0
const char* RegExp::ParseCCL(StrPP& ccl)
{
  int first = _RE_TRUE_;
  int len;

  ccl = "[ ";

  if(reExpression == NEGATE)		// if first character is NEGATE (^)
  {
    ccl[0] = NCCL;			// then we have a negated
    reExpression++;			// character class
  }

  // parse all characters up to the closing bracket or end of string marker

  while(reExpression != CCLEND && reExpression != ENDSTR)
  {
    if(reExpression == DASH && first == _RE_FALSE_)	// DASH, check for range
    {
      reExpression++;
      if(reExpression == NCCL)
	ccl += DASH;			// not range, literal DASH
      else
      {
	ParseDASH(ccl, reExpression);
	reExpression++;
      }
    }
    else
    {
      if(reExpression == ESCAPE)
      {
	reExpression++;
	ccl += ParseEscape();
	reExpression++;
      }
      else
      {
	ccl += reExpression[0];
	reExpression++;
      }
    }
    first = _RE_FALSE_;
  }

  len = ccl.Len()-2;

  if(len > 255)
    return NULL;			// character class too large
  else
  {
    ccl[1] = (char)len; 		// store CCL length at ccl[1]
    return ccl;
  }
}
Example #2
0
void CLexParseString(char *text, ILIntString *value)
{
	char *dest;
	int isUnicode;
	ILUInt64 ch;
	unsigned ch2;

	/* Initialize the value to be returned */
	if(*text == 'L' || *text == 'l' || *text == 's' || *text == 'S')
	{
		++text;
	}
	++text;
	value->string = text;
	value->len = 0;

	/* Expand any escape sequences that exist in the string */
	dest = text;
	while(*text != '"')
	{
		if(*text == '\\')
		{
			++text;
			text += ParseEscape(text, &ch, &isUnicode);
			if(isUnicode)
			{
				/* Expand the Unicode sequence to UTF-8 */
				if((text - dest) < 3)
				{
					CCWarningOnLine(yycurrfilename(), yycurrlinenum(),
								 	_("ignoring short '\\u' sequence"));
				}
				else
				{
					ch2 = (((unsigned)(ch)) & 0xFFFF);
					if(ch2 < 0x80)
					{
						*dest++ = (char)ch2;
						++(value->len);
					}
					else if(ch2 < (1 << 11))
					{
						*dest++ = (char)((ch2 >> 6) | 0xC0);
						*dest++ = (char)((ch2 & 0x3F) | 0x80);
						value->len += 2;
					}
					else
					{
						*dest++ = (char)((ch2 >> 12) | 0xE0);
						*dest++ = (char)(((ch2 >> 6) & 0x3F) | 0x80);
						*dest++ = (char)((ch2 & 0x3F) | 0x80);
						value->len += 3;
					}
				}
			}
Example #3
0
char* TANSIParser::ParseANSIBuffer(char* pszBuffer, char* pszBufferEnd)
{
	if(InPrintMode) {
		return PrintBuffer(pszBuffer, pszBufferEnd);
	}

	unsigned char tmpc = *(unsigned char *)pszBuffer;

	if(tmpc == 27) {
		return ParseEscape(pszBuffer, pszBufferEnd);
	}

//	if((fast_write && tmpc < 32) ||
//		!print_ctrl && (tmpc < 32 || (EightBit_Ansi &&
//		(tmpc > 128 && tmpc < 128 + ' ')))) {

	// We shouldn't print ctrl characters when fast write is enabled
	// and ctrl chars are disabled (Paul Brannan 9/1/98)
	if(tmpc < 32) {
		// From the Linux kernel (Paul Brannan 12/5/98):
		/* A bitmap for codes <32. A bit of 1 indicates that the code
		 * corresponding to that bit number invokes some special action
		 * (such as cursor movement) and should not be displayed as a
		 * glyph unless the disp_ctrl mode is explicitly enabled.
		 */
		const long CTRL_ACTION = 0x0d00ff81;
		const long CTRL_ALWAYS = 0x0800f501;
		if(!(((print_ctrl?CTRL_ALWAYS:CTRL_ACTION)>>tmpc)&1)) {

			Console.WriteString((char *)&tmpc, 1);
			pszBuffer++;
			return pszBuffer;
		}

		switch (tmpc) {
		case 0:
			pszBuffer++;
			break;

		// I.Ioannou 5/30/98
		case 7:
			Console.Beep();
			pszBuffer++;
			break;

		// destructive backspace
		case 8:
			// Added option for destructive backspace (Paul Brannan 5/13/98)
			// Changed to ConWriteCtrlString so that the cursor position can be
			// updated (Paul Brannan 5/25/98)
			if(ini.get_dstrbksp()) {
				Console.WriteCtrlChar('\b');
				Console.WriteString(" ", 1);
				Console.WriteCtrlChar('\b');
			}
			else Console.WriteCtrlChar('\b');
			pszBuffer++;
			break;

		// horizontal tab
		case 9:
			{
				pszBuffer++;
				int x = Console.GetCursorX();
				if(x != -1)
					Console.SetCursorPosition(tab_stops[x], Console.GetCursorY());
			}
			break;

		// Line Feed Char
		case 10:
			// Test for local echo (Paul Brannan 8/25/98)
			if(Network.get_local_echo() || newline_mode) // &&
				Console.WriteCtrlChar('\x0d');
			Console.WriteCtrlChar('\x0a');
			pszBuffer++;
			break;

		// form feed
		case 12:
			pszBuffer++;
			Console.ClearScreen();
			Console.SetRawCursorPosition(Console.GetCursorX(), 1); // changed fm 1
			break;

		case 13:
			Console.WriteCtrlChar('\x0d');
			pszBuffer++;

			break;

		case 14:  // shift out of alternate chararcter set
			pszBuffer++;
			Charmap.setmap(map_G1); // Paul Brannan 6/25/98
			current_map = 1;
			break;

		case 15:  // shift in
			pszBuffer++;
			Charmap.setmap(map_G0); // Paul Brannan 6/25/98
			current_map = 0;
			break;

		// Paul Brannan 9/1/98 - Is this okay?
		default:
			pszBuffer++;
		}

		return pszBuffer;
	}

	//  added by I.Ioannou 06 April, 1997
	//  In 8 bit systems the server may send 0x9b instead of ESC[
	//  Well, this will produce troubles in Greek 737 Code page
	//  which uses 0x9b as the small "delta" - and I thing that there
	//  is another European country with the same problem.
	//  If we have to stay 8-bit clean we may have to
	//  give the ability of ROM characters (ESC[11m),
	//  for striped 8'th bit (ESC[12m) as SCO does,
	//  or a parameter at compile (or run ?) time.
	// We now check for a flag in the ini file (Paul Brannan 5/13/98)
	// We also handle any 8-bit ESC sequence (Paul Brannan 6/28/98)
	if(ini.get_eightbit_ansi() && (tmpc > 128 && tmpc < 128 + ' ')) {
		// There's a chance the sequence might not parse.  If this happens
		// then pszBuffer will be one character too far back, since
		// ParseEscape is expecting two characters, not one.
		// In that case we must handle it.
		char *pszCurrent = pszBuffer;
		pszBuffer = ParseEscape(pszBuffer, pszBufferEnd);
		if(pszBuffer < pszCurrent) pszBuffer = pszCurrent;
	}

	char* pszCurrent = pszBuffer + 1;
	// I.Ioannou 04 Sep 1997 FIXME with ESC[11m must show chars < 32
	// Fixed (Paul Brannan 6/28/98)
	while ((pszCurrent < pszBufferEnd) && (!iscntrl(*pszCurrent))) {
		// I.Ioannou 04 Sep 1997 strip on high bit
		if ( (inGraphMode) && (*pszCurrent > (char)32) )
			*pszCurrent |= 0x80 ;
		pszCurrent++;
	}

	// Note that this may break dumpfiles slightly.
	// If 'B' is set to anything other than ASCII, this will cause problems
	// (Paul Brannan 6/28/98)
	if(current_map != 'B' && Charmap.enabled)
		Charmap.translate_buffer(pszBuffer, pszCurrent);

	last_char = *(pszCurrent-1);    // TITUS++: Remember last char

	if(fast_write) {
		pszBuffer += Console.WriteStringFast(pszBuffer,
			pszCurrent - pszBuffer);
	} else {
		pszBuffer += Console.WriteString(pszBuffer,
			pszCurrent - pszBuffer);
	}

	return pszBuffer;
}
Example #4
0
const char* RegExp::ParseFactor(StrPP& factor)
{
  StrPP tmp;
  factor = "";

  switch(reExpression[0])
  {
    case LPAREN:			// ( - parenthesised expression
      reExpression++;
      ParseExpression(tmp);
      factor += tmp;
      if(reExpression != RPAREN)
	return(NULL);
      reExpression++;
      break;

    case CCL:				// [ - character class; Ex: [0-9]
      reExpression++;
      ParseCCL(tmp);
      factor += tmp;
      if(reExpression != CCLEND)
	return(NULL);
      reExpression++;
      break;

    case ANY:				// .
    case EOL:				// $
      factor += reExpression[0];
      reExpression++;
      break;

    case ESCAPE :			// \
      reExpression++;
      factor += LITCHAR;
      factor += ParseEscape();
      reExpression++;
      break;

    case CLOSURE:			// *
    case POS_CLO:			// +
    case ZERO_ONE:			// ?
    case NEGATE:			// ^
    case CCLEND:			// ]
    case RPAREN:			// )
    case OR:				// |
      return(NULL);			// not valid characters

    default:				// literal character
      factor += LITCHAR;
      factor += reExpression[0];
      reExpression++;
      break;
  }

  if(reExpression == CLOSURE  ||	// check for closure
     reExpression == ZERO_ONE ||
     reExpression == POS_CLO)
  {
    if(ParseClosure(factor) == _RE_FALSE_)
      return(NULL);
  }
  return factor;
}
Example #5
0
void CLexParseChar(const char *text, CLexIntConst *value)
{
	int isUnicode;

	/* Skip the leading "'" */
	if(*text == 'L' || *text == 'l')
	{
		++text;
	}
	++text;

	/* Parse the character */
	if(*text == '\\')
	{
		/* Escaped character */
		++text;
		text += ParseEscape(text, &(value->value), &isUnicode);
		if(isUnicode)
		{
			/* Unicode escapes aren't strictly legal in signed 8-bit
			   characters, but do something useful anyway */
			if(value->value <= 127)
			{
				value->isneg = 0;
				value->type = ILMachineType_Int8;
			}
			else
			{
				value->isneg = 0;
				value->type = ILMachineType_UInt16;
			}
		}
		else
		{
			value->isneg = ((value->value & 0x80) != 0);
			if(value->isneg)
			{
				value->value =
					(ILUInt64)(-((ILInt64)(signed char)(value->value)));
			}
			value->type = ILMachineType_Int8;
		}
	}
	else
	{
		/* Normal character */
		value->value = (ILUInt64)(ILInt64)((int)(signed char)(*text++));
		value->isneg = ((value->value & 0x80) != 0);
		if(value->isneg)
		{
			value->value = (ILUInt64)(-((ILInt64)(value->value)));
		}
		value->type = ILMachineType_Int8;
	}

	/* Make sure that the constant is terminated correctly */
	if(*text != '\'')
	{
		CCWarningOnLine(yycurrfilename(), yycurrlinenum(),
					    _("multi-character constant"));
	}
}