Esempio n. 1
0
void tputs(const char *str, int __UNUSED_PARAM(nlines), int __UNUSED_PARAM((*outfun)(int)))
{

	if (!str) {
		dbgprintf(PR_ERROR, "!!! %s(): NULL string\n", __FUNCTION__);
		return;
	}

	dbgprintf(PR_IOWC, "%s(\"%s\", ..)\n", __FUNCTION__, str);
	while (*str) {
		if (state == initial) {
			if (*str == ESC)
				state = gotesc;
			else {
				ChBuffer[nCharInBuffer++] = concealed ? ' ' : *str;
				if (nCharInBuffer >= (int)sizeof(ChBuffer))
					FlushBuffer();
			}
		} else if (state == gotesc) {
			if (*str == ESC)
				;	// \e\e...\e == \e
			else if (*str == '[') {
				FlushBuffer();
				prefix = *str;
				state = gotprefix;
			} else
				state = initial;
		} else if (state == gotprefix) {
			if (isdigit(*str)) {
				es_argc = 0;
				es_argv[0] = *str - '0';
				state = gotarg;
			} else if (*str == ';') {
				es_argc = 1;
				es_argv[0] = 0;
				es_argv[es_argc] = 0;
				state = gotarg;
			} else {
				es_argc = 0;
				suffix = *str;
				InterpretEscSeq();
				state = initial;
			}
		} else if (state == gotarg) {
			if (isdigit(*str)) {
				es_argv[es_argc] = 10 * es_argv[es_argc] + (*str - '0');
			} else if (*str == ';') {
				if (es_argc < MAX_ARG - 1)
					es_argc++;
				es_argv[es_argc] = 0;
			} else {
				if (es_argc < MAX_ARG - 1)
					es_argc++;
				suffix = *str;
				InterpretEscSeq();
				state = initial;
			}
		}
		str++;
	}
	FlushBuffer();
}
Esempio n. 2
0
BOOL
ParseAndPrintString( HANDLE hDev,
		     LPCVOID lpBuffer,
		     DWORD nNumberOfBytesToWrite,
		     LPDWORD lpNumberOfBytesWritten
		     )
{
  DWORD   i;
  LPCTSTR s;

  if (hDev != hConOut)	// reinit if device has changed
  {
    hConOut = hDev;
    state = 1;
    shifted = FALSE;
  }
  for (i = nNumberOfBytesToWrite, s = (LPCTSTR)lpBuffer; i > 0; i--, s++)
  {
    if (state == 1)
    {
      if (*s == ESC) state = 2;
      else if (*s == SO) shifted = TRUE;
      else if (*s == SI) shifted = FALSE;
      else PushBuffer( *s );
    }
    else if (state == 2)
    {
      if (*s == ESC) ;	// \e\e...\e == \e
      else if ((*s == '[') || (*s == ']'))
      {
	FlushBuffer();
	prefix = *s;
	prefix2 = 0;
	state = 3;
	Pt_len = 0;
	*Pt_arg = '\0';
      }
      else if (*s == ')' || *s == '(') state = 6;
      else state = 1;
    }
    else if (state == 3)
    {
      if (isdigit( *s ))
      {
        es_argc = 0;
	es_argv[0] = *s - '0';
        state = 4;
      }
      else if (*s == ';')
      {
        es_argc = 1;
        es_argv[0] = 0;
	es_argv[1] = 0;
        state = 4;
      }
      else if (*s == '?' || *s == '>')
      {
	prefix2 = *s;
      }
      else
      {
        es_argc = 0;
        suffix = *s;
        InterpretEscSeq();
        state = 1;
      }
    }
    else if (state == 4)
    {
      if (isdigit( *s ))
      {
	es_argv[es_argc] = 10 * es_argv[es_argc] + (*s - '0');
      }
      else if (*s == ';')
      {
        if (es_argc < MAX_ARG-1) es_argc++;
	es_argv[es_argc] = 0;
	if (prefix == ']')
	  state = 5;
      }
      else
      {
	es_argc++;
        suffix = *s;
        InterpretEscSeq();
        state = 1;
      }
    }
    else if (state == 5)
    {
      if (*s == BEL)
      {
	Pt_arg[Pt_len] = '\0';
        InterpretEscSeq();
        state = 1;
      }
      else if (*s == '\\' && Pt_len > 0 && Pt_arg[Pt_len-1] == ESC)
      {
	Pt_arg[--Pt_len] = '\0';
        InterpretEscSeq();
        state = 1;
      }
      else if (Pt_len < lenof(Pt_arg)-1)
	Pt_arg[Pt_len++] = *s;
    }
    else if (state == 6)
    {
      // Ignore it (ESC ) 0 is implicit; nothing else is supported).
      state = 1;
    }
  }
  FlushBuffer();
  if (lpNumberOfBytesWritten != NULL)
    *lpNumberOfBytesWritten = nNumberOfBytesToWrite - i;
  return( i == 0 );
}