Beispiel #1
0
// ----------------------------------------------------------------------------
//
void TextUI::searchTrack( )
{
	InputField search_field( "Track Search Query", "" );
	TrackListField tracks_field( "Track", m_player );

	class MyForm : public Form {
		void fieldLeaveNotify( size_t field_num ) {
			if ( field_num == 0 ) {
				InputField* search_field = getField<InputField>( 0 );
				TrackListField* tracks_field = getField<TrackListField>( 1 );
				tracks_field->searchTracks( search_field->getValue() );
			}
		}

	public:
		MyForm( TextIO* input_stream ) :
			Form( input_stream ) {}
	};

	MyForm form( &m_text_io );
	form.add( search_field );
	form.add( tracks_field );

	if ( form.play() ) {
		m_player->playTrack( tracks_field.getTrack(), 0 );

		// Delay so the track starts 
		Sleep( 500 );
	}
}
Beispiel #2
0
void yylex(int c)
{
    switch (state) {
	case _S_:
	if (isalpha(c) || c == '_') {
	    save(c);
	    state = _A_;
	    ScoutAppAgentName = 1;
	} else if (isdigit(c)) {
	    save(c);
	    state = _D_;
	} else if (c == ' ' || c == '\t') {
	    state = _S_;
	} else if (c == '\n') {
	    state = _S_;
	} else if (c == '\r') {
	    state = _S_;
	} else if (c == '.') {
	    state = _DOT_;
	} else if (c == '"') {
	    state = _QUOTE_;
	} else if (c == '#') {
	    state = _HASH_;
	} else if (c == '&') {
	    state = _AND_;
	} else if (c == '|') {
	    state = _OR_;
	} else if (c == '=') {
	    state = _EQ_;
	} else if (c == '!') {
	    state = _NOT_;
	} else if (c == '<') {
	    state = _LT_;
	} else if (c == '>') {
	    state = _GT_;
	} else if (c == '/') {
	    state = _SLASH_;
	} else if (c == '~') {   /*  for agency -- sun */
	    state = _A_;
	    ScoutAppAgentName = 0;
	} else {
	    yyparse(c);
	    state = _S_;
	}
	break;
    case _A_:
	if (isalnum(c) || c == '_') {
	    save(c);
	    state = _A_;
	} else {
	    action_A();
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _D_:
	if (isdigit(c)) {
	    save(c);
	    state = _D_;
	} else if (c == '.') {
	    save(c);
	    state = _DDOT_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DDOT_:
	if (isdigit(c)) {
	    save(c);
	    state = _DDOTD_;
	} else if (c == '.') {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _DOT_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _DOT_;
	    yylex(c);
	}
	break;
    case _DDOTD_:
	if (isdigit(c)) {
	    save(c);
	    state = _DDOTD_;
	} else {
	    yylval.d = atof(yytext);
	    yyparse(NUMBER);
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOT_:
	if (c == ' ' || c == '\t') {
	    state = _DOT_;
	} else if (isalpha(c)) {
	    save(c);
	    state = _DOTA_;
	} else {
	    yyparse('.');
	    clearbuf();
	    state = _S_;
	    yylex(c);
	}
	break;
    case _DOTA_:
	if (isalpha(c)) {
	    save(c);
	    state = _DOTA_;
	} else {
	    int         pos = search_field(yytext);

	    clearbuf();
	    yyparse(pos == -1 ? ERROR : fields[pos].token);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _QUOTE_:
	if (c == '"') {
	    yylval.s = strdup(yytext);
	    yyparse(STR);
	    clearbuf();
	    state = _S_;
	} else if (c == '\\') {
	    state = _QBSLASH_;
	} else {
	    save(c);
	    state = _QUOTE_;
	}
	break;
    case _QBSLASH_:
	switch (c) {
	case 'n':
	    save('\n');
	    break;
	case '\n':		/* ignore \newline */
	    break;
	default:
	    save(c);
	    break;
	}
	state = _QUOTE_;
	break;
    case _HASH_:
	state = c == '\n' ? _S_ : _HASH_;
	break;
    case _AND_:
	if (c == '&') {
	    yyparse(AND);
	    state = _S_;
	} else {
	    yyparse('&');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _OR_:
	if (c == '|') {
	    yyparse(OR);
	    state = _S_;
	} else {
	    yyparse('|');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _EQ_:
	if (c == '=') {
	    yyparse(EQ);
	    state = _S_;
	} else {
	    yyparse('=');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _NOT_:
	if (c == '=') {
	    yyparse(NE);
	    state = _S_;
	} else {
	    yyparse('!');
	    state = _S_;
	    yylex(c);
	}
	break;
    case _LT_:
	if (c == '=') {
	    yyparse(LE);
	    state = _S_;
	} else {
	    yyparse(LT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _GT_:
	if (c == '=') {
	    yyparse(GE);
	    state = _S_;
	} else {
	    yyparse(GT);
	    state = _S_;
	    yylex(c);
	}
	break;
    case _SLASH_:
	if (c == '/') {
	    yyparse(CONCAT);
	    state = _S_;
	} else {
	    yyparse('/');
	    state = _S_;
	    yylex(c);
	}
	break;
    }
}