Source Code (Use browser search to find items of interest.)

Class Index

kdesu'Lexer (./kdebase/kdesu/kdesud/lexer.h:18)

class Lexer {
public:
    Lexer(const QCString &input);
    ~Lexer();

    /**
     * Read next token.
     */
    int lex();

    /**
     * Return the token's semantic value. A reference is returned because it
     * might contains sensitive information, that I don't want to copy.
     */
    QCString &lval();

    enum Tokens { 
	Tok_none, 
	Tok_exec=256, Tok_pass, Tok_user, Tok_del, 
	Tok_ping, Tok_str, Tok_num , Tok_stop,
	Tok_set, Tok_get, Tok_host, Tok_prio, Tok_sched
    };

private:
    QCString m_Input;
    QCString m_Output;

    int in;
};

kdesu'Lexer::Lexer() (./kdebase/kdesu/kdesud/lexer.cpp:17)

Lexer::Lexer(const QCString &input)
{
    m_Input = input;
    in = 0;
}


kdesu'Lexer::~Lexer() (./kdebase/kdesu/kdesud/lexer.cpp:23)

Lexer::~Lexer()
{
    // Erase buffers
    m_Input.fill('x');
    m_Output.fill('x');
}


kdesu'Lexer::lval() (./kdebase/kdesu/kdesud/lexer.cpp:30)

QCString &Lexer::lval()
{
    return m_Output;
}

/*
 * lex() is the lexer. There is no end-of-input check here so that has to be
 * done by the caller.
 */


kdesu'Lexer::lex() (./kdebase/kdesu/kdesud/lexer.cpp:40)

int Lexer::lex()
{
    char c;

    c = m_Input[in++];
    m_Output.fill('x');
    m_Output.resize(0);

    while (1) {

	// newline? 
	if (c == '\n')
	    return '\n';

	// No control characters 
	if (iscntrl(c))
	    return Tok_none;

	if (isspace(c))
	    while (isspace(c = m_Input[in++]));

	// number?
	if (isdigit(c)) {
	    m_Output += c;
	    while (isdigit(c = m_Input[in++]))
		m_Output += c;
	    in--;
	    return Tok_num;
	}

	// quoted string?
	if (c == '"') {
	    c = m_Input[in++];
	    while ((c != '"') && !iscntrl(c)) {
		// handle escaped characters
		if (c == '\\')
		    m_Output += m_Input[in++];
		else
		    m_Output += c;
		c = m_Input[in++];
	    }
	    if (c == '"')
		return Tok_str;
	    return Tok_none;
	}

	// normal string
	while (!isspace(c) && !iscntrl(c)) {
	    m_Output += c;
	    c = m_Input[in++];
	}
	in--;

	// command? 
	if (m_Output.length() <= 4) {
	    if (m_Output == "EXEC")
		return Tok_exec;
	    if (m_Output == "PASS")
		return Tok_pass;
	    if (m_Output == "DEL")
		return Tok_del;
	    if (m_Output == "PING")
		return Tok_ping;
	    if (m_Output == "STOP")
		return Tok_stop;
	    if (m_Output == "USER")
		return Tok_user;
	    if (m_Output == "SET")
		return Tok_set;
	    if (m_Output == "GET")
		return Tok_get;
	    if (m_Output == "HOST")
		return Tok_host;
	    if (m_Output == "SCHD")
		return Tok_sched;
	    if (m_Output == "PRIO")
		return Tok_prio;
	}

	return Tok_str;
    }
}