Beispiel #1
0
/*!
	@brief try to get one parameter in []
	@param p string to obtain parameter
	@return true if string is returned else false
*/
bool Parser::_get_param_ncom(TokenString *p)
{
	bool whitechar = false;
	char wchar;
	_readchar();
	if (isspace(_char))
	{
		whitechar =  true;
		if (_char==cr)
			_char=newline;
		wchar	  =  _char;
	}
	else
		_putback();
	_skip_whitechars();
	_readchar();
	if (_char != lbracket )
	{
		_in.putback(_char);
		if (whitechar) 
			_in.putback(wchar);
		return false;
	}
	_readchar();
	while (_char != rbracket && !_isend)
	{
		*p << _char;
		_readchar();
	}
	if (_char != rbracket)
		return false;
	else
		return true;
}
Beispiel #2
0
/*!
	@brief skip all white character in the stream
*/
void Parser::_skip_whitechars(void)
{
	_readchar();
	while ( !_isend && isspace(_char)  )
	{
		_readchar();
	}
	if (!_isend)
		_in.putback(_char);
}
Beispiel #3
0
void Parser::_skip_comment()
{
	while (_char!=newline && !_isend)
	{
		_readchar();
	}
	_out << std::endl;
	_skip_whitechars(); // skip all whitechars on new line
}
Beispiel #4
0
size_t
fread(void* a, size_t size, size_t nelem, FILE* str)
{
  size_t ns = (size * nelem);
  size_t n;

  if ((ns == 0) || (a == NULL) || (str == NULL))
    return 0;

  _LOCK_FILE(str);

  if (str->nback > 0)
  {
    /* If there are ungetc'd characters and there's room in the buffer,
       then restore the characters.  Anything that doesn't fit gets
       flushed.  This may violate the guarantee that at least one
       ungetc must work. */

    while ((str->nback > 0) && (str->_Next > str->_Buf))
    {
      --str->_Next;

#if (BYTES_PER_WORD==1)
      *((unsigned char*) str->_Next) = str->_Back[--str->nback];
#else
      if (str->_Mode & M_BINARY) {
        *((unsigned char*) str->_Next) = str->_Back[--str->nback];
      } else {
        DEPOSIT_BYTE(*WORD_ADDR(str->_Next),
                     str->_Next,
                     str->_Back[--str->nback]);
      }
#endif
    }
    str->_Rend = str->rsave;
  }

#if (BYTES_PER_WORD==1)
  n = _readbinary(a,ns,str);
#else

  if ((BYTES_PER_WORD==1) || (str->_Mode & M_BINARY))
    n = _readbinary(a,ns,str);
  else
    n = _readchar(a,ns,str);

#endif

  _UNLOCK_FILE(str);

  return n / size;

}
Beispiel #5
0
/*!
	@brief return one token from stream
*/
void Parser::_readnexttoken()
{
	_tokenstring.clean();

	if (_skip_whitec)
	{
		_skip_whitechars();
	}

	if (_isend)
	{
		_token = tok_isend;
		return ;
	}
	_readchar();
	if (isspace(_char))
	{
		_tokenstring << _char;
		_token = _char;
		return ;
	} else
	if (ispunct(_char))
	{
		_token = _char;
		_tokenstring << _char;
		return;			
	} else
	{
		while (iscesym(_char) && !_isend)
		{
			/* create string from chars */
			_tokenstring << _char;		
			_readchar();
		}
		if (!_isend) _in.putback(_char);
		_token = tok_word;
	}
	//	_tokenstring.print();
}
Beispiel #6
0
/*!
	@brief try to find begin/end parameter
	@return parameter of \begin or \end
*/
TokenString	Parser::_get_begroup(void)
{
	_skip_whitechars();
	_readchar();
	if (_char != lbrace )
		return TokenString();
	_skip_whitechars();
	_readnexttoken();
	TokenString pom(_tokenstring);
	_skip_whitechars();
	_readnexttoken();
	if (_token != rbrace)
	{
		//std::cerr << "Chybny parametr u end/begin" << std::endl;
		return TokenString();
	}
	return pom;
}
Beispiel #7
0
/*!
	@brief try to recognize parameters in command \command{p1}[p2]
	@param p1 will be filled with compulsory parameters (params. in {})
	@param p2 will be filled with non-compulsory parameters (params in [])
	@return number of parameters 0=none, 1=only comp, 2=only non-comp, 4=comp+non-comp
*/
int Parser::_get_params(TokenString *p1, TokenString *p2)
{
	int save_c;
	int ret = 1;
	bool there_was_space = false;

	_skip_whitechars();
	_readchar();
	if (_char != lbrace && _char != lbracket )
	{
		_in.putback(_char);
		return 0;
	}
	save_c = _char;
	_skip_whitechars();
	if (save_c == lbrace)
	{
		p1->clean();
		_readchar();
		while (_char != rbrace && !_isend)
		{
				*p1 << _char;
				_readchar();
		}
		if (isspace(_char))
		{
			_skip_whitechars();
			there_was_space = true;
		}
		_readchar();
		if (_char == lbracket)
		{
			p2->clean();
			_readchar();
			while (_char != rbracket && !_isend)
			{
				*p2 << _char;
				_readchar();
			}
			_in.putback(_char);
			ret=4;
		} else { if (there_was_space) { _in.putback(' '); }; _in.putback(_char);}
	} else 
	{
		p2->clean();
		_readchar();
		while (_char != rbracket && !_isend)
		{
				*p2 << _char;
				_readchar();
		}
		ret=2;
		if (isspace(_char))
		{
			_skip_whitechars();
			there_was_space = true;
		}
		_readchar();
		if (_char == lbrace)
		{
			p1->clean();
			_readchar();
			while (_char != rbrace && !_isend)
			{
				*p1 << _char;
				_readchar();
			}
			//_in.putback(_char);
			ret=4;
		} else { if (there_was_space) { _in.putback(' '); } ; _in.putback(_char);}
	}
	return ret;
}
Beispiel #8
0
/*!
	@brief return one token from stream
*/
Token Parser::GetToken(void) 
{
	
	_readnexttoken();
	
	switch (_token)
	{
	case backslash:
		_getcommand();
		break;
	case cr:
		break;
	case newline:
		_printtoken();		// \n latex bere jako whitespace
		_skip_whitechars(); // vse bile, co je na zacatku noveho radku se ignoruje
		break;
	case space:
	case tab:
			_printtoken();		// vice whitespace se bere jako jedna whitespace
			_skip_whitechars();
			break;
	case tok_word:
			_printtoken();		
		break;
	case percent:
		_skip_comment();
		break;
	case accent1:			// oteviraci uvozovky se delaji pomoci ''
		_readchar();
		if ( _char == accent1)
		{
			_token = quote;
			_tokenstring.clean();
			_tokenstring << '\"';
		} else
		{
			_in.putback(_char);
		}
		_printtoken();
		break;
	case accent2:			// uzaviraci uvozovky se delaji pomoci ``
		_readchar();
		if ( _char == accent2)
		{
			_token = quote;
			_tokenstring.clean();
			_tokenstring << '\"';
		} else
		{
			_in.putback(_char);
		}
		_printtoken();
		break;
	case hyphen:
		_tokenstring.clean();
		_readchar();
		if ( _char == hyphen )
		{
				_readchar();
					if ( _char == hyphen )
					{
						_tokenstring << "&#8212;";
					}
					else
					{
						_in.putback(_char);
						_tokenstring << "&#8211;";
					}
		} else
		{
			_in.putback(_char);
			_tokenstring << "&#173;";
		}
		_printtoken();
		break;
	case tilda:
		_tokenstring.clean();
		_tokenstring << "&nbsp;";
		_printtoken();
		break;
	default:
			_printtoken();
			break;
	}
	return _token;
}
Beispiel #9
0
chtype
tgetch(int interpret)
{
	int		i = 0, j, collapse = 1;
#define	WAIT3		333
	chtype		inp;
	chtype		*inputQ = cur_term->_input_queue;
	char		*chars_onQ = &(cur_term->_chars_on_queue);

#ifdef	SYSV
	/*
	 * Register the fact that getch is being used so
	 * that typeahead checking can be done.
	 * This code should GO AWAY when a poll() or FIONREAD can
	 * be done on the file descriptor as then the check
	 * will be non-destructive.
	 */
	cur_term->fl_typeahdok = TRUE;
#endif	/* SYSV */

	/* ask for input */
	if (cur_term->_ungotten > 0) {
		cur_term->_ungotten--;
		/* decode an ungetch()'d character */
		inp = -inputQ[0];
	} else {
		/* Only read a character if there is no typeahead/peekahead. */
		if (*chars_onQ == 0) {
			/* (*chars_onQ)++;  MR */
#ifdef	FIONREAD
			inp = _readchar();
#else	/* FIONREAD */
			inp = (chtype) _pk();
			if ((int)inp == ERR) {
		/*
		 * interpret is set to 0 so that down below we don't
		 * drop into getkey since we already know there can't be
		 * a key that starts with -1.  Also, we don't want to
		 * access funckeystarter[-1].
		 */
				interpret = FALSE;
			}
#endif	/* FIONREAD */
			(*chars_onQ)++;
		} else
			inp = inputQ[0];

#ifdef	DEBUG
		if (outf)
			fprintf(outf, "TGETCH read '%s'\n", unctrl(inp));
#endif	/* DEBUG */

		/* Check for arrow and function keys */
		if (interpret && cur_term->funckeystarter[inp])
			collapse = _getkey(interpret - 1, &inp);
	}

	/* Collapse the input queue to remove the escape */
	/* sequence from the stack. */

	j = *chars_onQ;
	(*chars_onQ) -= collapse;
	while (collapse < j)
		inputQ[i++] = inputQ[collapse++];
	return (inp);
}