int dmenu_switcher_dialog ( void ) { mode_init ( &dmenu_mode ); MenuFlags menu_flags = MENU_NORMAL; DmenuModePrivateData *pd = (DmenuModePrivateData *) dmenu_mode.private_data; char *input = NULL; unsigned int cmd_list_length = pd->cmd_list_length; char **cmd_list = pd->cmd_list; pd->only_selected = FALSE; if ( find_arg ( "-markup-rows" ) >= 0 ) { pd->do_markup = TRUE; } if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { pd->only_selected = TRUE; if ( cmd_list_length == 0 ) { return TRUE; } } if ( config.auto_select && cmd_list_length == 1 ) { dmenu_output_formatted_line ( pd->format, cmd_list[0], 0, config.filter ); return TRUE; } if ( find_arg ( "-password" ) >= 0 ) { menu_flags |= MENU_PASSWORD; } /* copy filter string */ input = g_strdup ( config.filter ); char *select = NULL; find_arg_str ( "-select", &select ); if ( select != NULL ) { char **tokens = tokenize ( select, config.case_sensitive ); unsigned int i = 0; for ( i = 0; i < cmd_list_length; i++ ) { if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) { pd->selected_line = i; break; } } g_strfreev ( tokens ); } if ( find_arg ( "-dump" ) >= 0 ) { char **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive ); unsigned int i = 0; for ( i = 0; i < cmd_list_length; i++ ) { if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) { dmenu_output_formatted_line ( pd->format, cmd_list[i], i, config.filter ); } } g_strfreev ( tokens ); return TRUE; } // TODO remove RofiViewState *state = rofi_view_create ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags, dmenu_finalize ); rofi_view_set_selected_line ( state, pd->selected_line ); rofi_view_set_active ( state ); return FALSE; }
static int drun_token_match ( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) { DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( data ); int match = 1; if ( tokens ) { for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { int test = 0; char *ftokens[2] = { tokens[j], NULL }; if ( !test && rmpd->entry_list[index].name && token_match ( ftokens, rmpd->entry_list[index].name, not_ascii, case_sensitive ) ) { test = 1; } if ( !test && rmpd->entry_list[index].generic_name && token_match ( ftokens, rmpd->entry_list[index].generic_name, not_ascii, case_sensitive ) ) { test = 1; } if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec, not_ascii, case_sensitive ) ) { test = 1; } if ( test == 0 ) { match = 0; } } } return match; }
static struct ast_node *parse_pipe(struct parser_context *context) { struct ast_node *left = parse_val(context); if(token_match(context, TOK_PIPE)) { token_read(context); struct ast_node *rdir = node_create(NODE_PIPE, sizeof(struct ast_node)); node_add_child(rdir, left); node_add_child(rdir, parse_pipe(context)); return rdir; } return left; }
static struct ast_node *parse_val(struct parser_context *ctx) { struct gsh_command *nod = (struct gsh_command*)node_create(NODE_CMD, sizeof(struct gsh_command)); char **args = (char*)malloc(512); memset(args, 0, 512); int i = 0; while(token_match(ctx, TOK_STRING)) { struct token *tok = token_read(ctx); args[i++] = tok->value; } nod->c_args = args; return nod; }
static expression parse_expression(str_iter& iter) { expression expr; token cur_tok = token::get(iter); cur_tok.match(token_match() .integer([&](u64 u) { expr.kind = Expr_int_literal; expr.data.int_literal.value = u; token::eat(iter, token_kind::semicolon); }) ._([&]() { cur_tok.error(str("expression")); }) ); return expr; }
static statement parse_stmt(str_iter& iter) { statement stmt; auto cur_tok = token::get(iter); cur_tok.match(token_match() .keyword_return([&]() { stmt.kind = Stmt_return; stmt.data.return_ = parse_expression(iter); }) .close_brace([&]() { stmt.kind = Stmt_none; }) ._([&](){ cur_tok.error(str("statement")); }) ); return stmt; }
int CFileSystemByteArray::ReadByteArray2D( ifstream &stream, int nx, int ny, BYTE *pdata ) { string buffer; int result; while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, buffer ); // str if ( g_verbose > 1) { cout << "Read token <" << buffer << ">\n"; } switch( token_match( buffer, token_list, token_num ) ) { case TOKEN_YSLICE: if ( g_verbose > 1 ) { cout << "Reading Y-slice\n"; } result &= ReadByteArray1D( stream, nx, pdata ); pdata += nx; break; default: cout << "ReadByteArray2D::Unknown token <"; cout << buffer.c_str() << " >\n"; break; } ReadClosePar( stream ); // } } stream.putback( '}' ); return true; }
void CFileSystemLongArray::ReadLongArray2D( std::ifstream &stream, unsigned int nx, unsigned int ny, long *pdata ) { std::string buffer; while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, buffer ); // str if ( g_verbose > 1) { std::cout << "Read token <" << buffer << ">\n"; } switch( token_match( buffer, token_list, token_num ) ) { case TOKEN_YSLICE: if ( g_verbose > 1 ) { std::cout << "Reading Y-slice\n"; } ReadLongArray1D( stream, nx, pdata ); pdata += nx; break; default: std::cout << "ReadLongArray2D::Unknown token <"; std::cout << buffer.c_str() << " >\n"; break; } ReadClosePar( stream ); // } } stream.putback( '}' ); }
int CExtensionHeaderFileSettingsIODataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; int entry_savedstates; result = true; if ( g_verbose ) { std::cout << "Reading CExtensionHeaderFileSettingsIODataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_SYSTEMLIST: m_systemlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <systemlist>\n"; } break; case TOKEN_NEWLIST: m_newlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <newlist>\n"; } break; case TOKEN_IGNORELIST: m_ignorelist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <ignorelist>\n"; } break; case TOKEN_VENDORLIST: m_vendorlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <vendorlist>\n"; } break; case TOKEN_VERSIONLIST: m_versionlist.ReadFile( stream ); if ( g_verbose ) { std::cout << "Read <versionlist>\n"; } break; case TOKEN_SAVEDSTATES: ReadInteger( stream, entry_savedstates ); m_savedstates = entry_savedstates; if ( g_verbose ) { std::cout << "Read <savedstates> = <" << entry_savedstates << ">\n"; } break; default: std::cout << "CExtensionHeaderFileSetIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return( result ); }
int dmenu_switcher_dialog ( char **input ) { char *dmenu_prompt = "dmenu "; int selected_line = -1; int retv = FALSE; int length = 0; char **list = get_dmenu ( &length ); int restart = FALSE; char *message = NULL; menu_match_cb filter = token_match; find_arg_str ( "-mesg", &message ); // By default we print the unescaped line back. char *format = "s"; // This is here for compatibility reason. // Use -format 'i' instead. if ( find_arg ( "-i" ) >= 0 ) { format = "i"; } // Allow user to override the output format. find_arg_str ( "-format", &format ); // Check prompt find_arg_str ( "-p", &dmenu_prompt ); find_arg_int ( "-l", &selected_line ); // Urgent. char *str = NULL; find_arg_str ( "-u", &str ); if ( str != NULL ) { parse_ranges ( str, &urgent_list, &num_urgent_list ); } // Active str = NULL; find_arg_str ( "-a", &str ); if ( str != NULL ) { parse_ranges ( str, &active_list, &num_active_list ); } int only_selected = FALSE; if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { only_selected = TRUE; if ( length == 0 ) { return TRUE; } } find_arg_str_alloc ( "-filter", input ); if ( find_arg ( "-z" ) >= 0 ) { filter = fuzzy_token_match; } char *select = NULL; find_arg_str ( "-select", &select ); if ( select != NULL ) { char **tokens = tokenize ( select, config.case_sensitive ); int i = 0; for ( i = 0; i < length; i++ ) { if ( token_match ( tokens, list[i], config.case_sensitive, 0, NULL ) ) { selected_line = i; break; } } g_strfreev ( tokens ); } do { int next_pos = selected_line; int mretv = menu ( list, length, input, dmenu_prompt, filter, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message ); // Special behavior. if ( only_selected ) { /** * Select item mode. */ restart = ( find_arg ( "-only-match" ) >= 0 ); if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { retv = 10 + ( mretv & MENU_LOWER_MASK ); } return retv; } selected_line = next_pos - 1; continue; } // We normally do not want to restart the loop. restart = FALSE; // Normal mode if ( ( mretv & MENU_OK ) && list[selected_line] != NULL ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } // Custom input else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { dmenu_output_formatted_line ( format, *input, -1, *input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } // Quick switch with entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line >= 0 ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } // Quick switch without entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line == -1 ) { dmenu_output_formatted_line ( format, *input, -1, *input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } } while ( restart ); g_strfreev ( list ); g_free ( urgent_list ); g_free ( active_list ); return retv; }
int CConfigurationFileSettingsDataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; int entry_newconfigflag; std::string entry_configsettingsfile; int entry_autoreadheaderflags; int entry_autoloadconfigflags; int entry_autosaveconfigflags; result = true; if ( g_verbose ) { ctrace << "Reading CConfigurationFileSettingsDataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_NEWCONFIGFLAG: ReadInteger( stream, entry_newconfigflag ); m_newconfigflag = entry_newconfigflag; if ( g_verbose ) { std::cout << "Read <newconfigflag> = <" << entry_newconfigflag << ">\n"; } break; case TOKEN_CONFIGSETTINGSFILE: ReadQuotedString( stream, entry_configsettingsfile ); m_configfile = entry_configsettingsfile; if ( g_verbose ) { std::cout << "Read <configsettingsfile> = <" << entry_configsettingsfile << ">\n"; } break; case TOKEN_AUTOREADHEADERFLAGS: ReadInteger( stream, entry_autoreadheaderflags ); m_autoreadheaderflags = entry_autoreadheaderflags; if ( g_verbose ) { std::cout << "Read <autoreadheaderflags> = <" << entry_autoreadheaderflags << ">\n"; } break; case TOKEN_AUTOLOADCONFIGFLAGS: ReadInteger( stream, entry_autoloadconfigflags ); m_autoloadconfigflags = entry_autoloadconfigflags; if ( g_verbose ) { std::cout << "Read <autoloadconfigflags> = <" << entry_autoloadconfigflags << ">\n"; } break; case TOKEN_AUTOSAVECONFIGFLAGS: ReadInteger( stream, entry_autosaveconfigflags ); m_autosaveconfigflags = entry_autosaveconfigflags; if ( g_verbose ) { std::cout << "Read <autosaveconfigflags> = <" << entry_autosaveconfigflags << ">\n"; } break; default: std::cout << "CConfigurationFileSettingsIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return result; }
int CExtensionSiteInfoIODataAsciiIO::ReadFile( std::ifstream &stream ) { int result; std::string tokenid; std::string entry_description; std::string entry_indexdirlocal; std::string entry_indexpagenet; std::string entry_indexpagelocal; std::string entry_glheadernet; std::string entry_glheaderlocal; std::string entry_glxheadernet; std::string entry_glxheaderlocal; std::string entry_wglheadernet; std::string entry_wglheaderlocal; std::string entry_coreheadernet; std::string entry_coreheaderlocal; int entry_downloadflags; std::string entry_filetypefilters; result = true; if ( g_verbose ) { std::cout << "Reading CExtensionSiteInfoIODataAsciiIO" << std::endl; } while ( ReadOpenClosePar( stream ) != 0 ) { ReadString( stream, tokenid ); if ( g_verbose > 1 ) { std::cout << "Read Token = <" << tokenid << ">\n"; } switch( token_match( tokenid, token_list, token_num ) ) { case TOKEN_DESCRIPTION: ReadQuotedString( stream, entry_description ); m_description = entry_description; if ( g_verbose ) { std::cout << "Read <description> = <" << entry_description << ">\n"; } break; case TOKEN_INDEXDIRLOCAL: ReadQuotedString( stream, entry_indexdirlocal ); m_indexdirlocal = entry_indexdirlocal; if ( g_verbose ) { std::cout << "Read <indexdirlocal> = <" << entry_indexdirlocal << ">\n"; } break; case TOKEN_INDEXPAGENET: ReadQuotedString( stream, entry_indexpagenet ); m_indexpagenet = entry_indexpagenet; if ( g_verbose ) { std::cout << "Read <indexpagenet> = <" << entry_indexpagenet << ">\n"; } break; case TOKEN_INDEXPAGELOCAL: ReadQuotedString( stream, entry_indexpagelocal ); m_indexpagelocal = entry_indexpagelocal; if ( g_verbose ) { std::cout << "Read <indexpagelocal> = <" << entry_indexpagelocal << ">\n"; } break; case TOKEN_GLHEADERNET: ReadQuotedString( stream, entry_glheadernet ); m_glheadernet = entry_glheadernet; if ( g_verbose ) { std::cout << "Read <glheadernet> = <" << entry_glheadernet << ">\n"; } break; case TOKEN_GLHEADERLOCAL: ReadQuotedString( stream, entry_glheaderlocal ); m_glheaderlocal = entry_glheaderlocal; if ( g_verbose ) { std::cout << "Read <glheaderlocal> = <" << entry_glheaderlocal << ">\n"; } break; case TOKEN_GLXHEADERNET: ReadQuotedString( stream, entry_glxheadernet ); m_glxheadernet = entry_glxheadernet; if ( g_verbose ) { std::cout << "Read <glxheadernet> = <" << entry_glxheadernet << ">\n"; } break; case TOKEN_GLXHEADERLOCAL: ReadQuotedString( stream, entry_glxheaderlocal ); m_glxheaderlocal = entry_glxheaderlocal; if ( g_verbose ) { std::cout << "Read <glxheaderlocal> = <" << entry_glxheaderlocal << ">\n"; } break; case TOKEN_WGLHEADERNET: ReadQuotedString( stream, entry_wglheadernet ); m_wglheadernet = entry_wglheadernet; if ( g_verbose ) { std::cout << "Read <wglheadernet> = <" << entry_wglheadernet << ">\n"; } break; case TOKEN_WGLHEADERLOCAL: ReadQuotedString( stream, entry_wglheaderlocal ); m_wglheaderlocal = entry_wglheaderlocal; if ( g_verbose ) { std::cout << "Read <wglheaderlocal> = <" << entry_wglheaderlocal << ">\n"; } break; case TOKEN_COREHEADERNET: ReadQuotedString( stream, entry_coreheadernet ); m_coreheadernet = entry_coreheadernet; if ( g_verbose ) { std::cout << "Read <coreheadernet> = <" << entry_coreheadernet << ">\n"; } break; case TOKEN_COREHEADERLOCAL: ReadQuotedString( stream, entry_coreheaderlocal ); m_coreheaderlocal = entry_coreheaderlocal; if ( g_verbose ) { std::cout << "Read <coreheaderlocal> = <" << entry_coreheaderlocal << ">\n"; } break; case TOKEN_DOWNLOADFLAGS: ReadInteger( stream, entry_downloadflags ); m_downloadflags = entry_downloadflags; if ( g_verbose ) { std::cout << "Read <downloadflags> = <" << entry_downloadflags << ">\n"; } break; case TOKEN_FILETYPEFILTERS: ReadQuotedString( stream, entry_filetypefilters ); m_filetypefilter = entry_filetypefilters; if ( g_verbose ) { std::cout << "Read <filetypefilters> = <" << entry_filetypefilters << ">\n"; } break; default: std::cout << "CExtensionSiteInfoIO::Unknown token <" << tokenid << ">\n"; break; } ReadClosePar( stream ); } stream.putback( '}' ); if ( g_verbose ) { std::cout << "Reading complete." << std::endl << std::endl; } return( result ); }
/** * @param sw Object handle to the SSH Mode object * @param tokens The set of tokens to match against * @param not_ascii If the entry is pure-ascii * @param case_sensitive If the entry should be matched case sensitive * @param index The index of the entry to match * * Match entry against the set of tokens. * * @returns TRUE if matches */ static int ssh_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index ) { SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw ); return token_match ( tokens, rmpd->hosts_list[index], not_ascii, case_sensitive ); }
static int run_token_match ( const Mode *sw, GRegex **tokens, unsigned int index ) { const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data; return token_match ( tokens, rmpd->cmd_list[index] ); }