int exec_pipe( int fd[2]) { int res; while( ( res=pipe( fd ) ) ) { if( errno != EINTR ) { wperror(L"pipe"); return res; } } debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]); if( open_fds == 0 ) { open_fds = al_halloc( global_context ); } al_push_long( open_fds, (long)fd[0] ); al_push_long( open_fds, (long)fd[1] ); return res; }
/** The complete builtin. Used for specifying programmable tab-completions. Calls the functions in complete.c for any heavy lifting. Defined in builtin_complete.c */ static int builtin_complete( wchar_t **argv ) { int res=0; int argc=0; int result_mode=SHARED; int remove = 0; int authoritative = -1; int flags = COMPLETE_AUTO_SPACE; string_buffer_t short_opt; array_list_t gnu_opt, old_opt; wchar_t *comp=L"", *desc=L"", *condition=L""; wchar_t *do_complete = 0; array_list_t cmd; array_list_t path; static int recursion_level=0; if( !is_interactive_session ) { debug( 1, _(L"%ls: Command only available in interactive sessions"), argv[0] ); } al_init( &cmd ); al_init( &path ); sb_init( &short_opt ); al_init( &gnu_opt ); al_init( &old_opt ); argc = builtin_count_args( argv ); woptind=0; while( res == 0 ) { const static struct woption long_options[] = { { L"exclusive", no_argument, 0, 'x' } , { L"no-files", no_argument, 0, 'f' } , { L"require-parameter", no_argument, 0, 'r' } , { L"path", required_argument, 0, 'p' } , { L"command", required_argument, 0, 'c' } , { L"short-option", required_argument, 0, 's' } , { L"long-option", required_argument, 0, 'l' } , { L"old-option", required_argument, 0, 'o' } , { L"description", required_argument, 0, 'd' } , { L"arguments", required_argument, 0, 'a' } , { L"erase", no_argument, 0, 'e' } , { L"unauthoritative", no_argument, 0, 'u' } , { L"authoritative", no_argument, 0, 'A' } , { L"condition", required_argument, 0, 'n' } , { L"do-complete", optional_argument, 0, 'C' } , { L"help", no_argument, 0, 'h' } , { 0, 0, 0, 0 } } ; int opt_index = 0; int opt = wgetopt_long( argc, argv, L"a:c:p:s:l:o:d:frxeuAn:C::h", long_options, &opt_index ); if( opt == -1 ) break; switch( opt ) { case 0: if(long_options[opt_index].flag != 0) break; sb_printf( sb_err, BUILTIN_ERR_UNKNOWN, argv[0], long_options[opt_index].name ); builtin_print_help( argv[0], sb_err ); res = 1; break; case 'x': result_mode |= EXCLUSIVE; break; case 'f': result_mode |= NO_FILES; break; case 'r': result_mode |= NO_COMMON; break; case 'p': case 'c': { wchar_t *a = unescape( woptarg, 1); if( a ) { al_push( (opt=='p'?&path:&cmd), a ); } else { sb_printf( sb_err, L"%ls: Invalid token '%ls'\n", argv[0], woptarg ); res = 1; } break; } case 'd': desc = woptarg; break; case 'u': authoritative=0; break; case 'A': authoritative=1; break; case 's': sb_append( &short_opt, woptarg ); break; case 'l': al_push( &gnu_opt, woptarg ); break; case 'o': al_push( &old_opt, woptarg ); break; case 'a': comp = woptarg; break; case 'e': remove = 1; break; case 'n': condition = woptarg; break; case 'C': do_complete = woptarg?woptarg:reader_get_buffer(); break; case 'h': builtin_print_help( argv[0], sb_out ); return 0; case '?': builtin_unknown_option( argv[0], argv[woptind-1] ); res = 1; break; } } if( !res ) { if( condition && wcslen( condition ) ) { if( parser_test( condition, 0, 0, 0 ) ) { sb_printf( sb_err, L"%ls: Condition '%ls' contained a syntax error\n", argv[0], condition ); parser_test( condition, 0, sb_err, argv[0] ); res = 1; } } } if( !res ) { if( comp && wcslen( comp ) ) { if( parser_test_args( comp, 0, 0 ) ) { sb_printf( sb_err, L"%ls: Completion '%ls' contained a syntax error\n", argv[0], comp ); parser_test_args( comp, sb_err, argv[0] ); res = 1; } } } if( !res ) { if( do_complete ) { array_list_t *comp; int i; const wchar_t *prev_temporary_buffer = temporary_buffer; wchar_t *token; parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 ); temporary_buffer = do_complete; if( recursion_level < 1 ) { recursion_level++; comp = al_halloc( 0 ); complete( do_complete, comp ); for( i=0; i<al_get_count( comp ); i++ ) { completion_t *next = (completion_t *)al_get( comp, i ); wchar_t *prepend; if( next->flags & COMPLETE_NO_CASE ) { prepend = L""; } else { prepend = token; } if( next->description ) { sb_printf( sb_out, L"%ls%ls\t%ls\n", prepend, next->completion, next->description ); } else { sb_printf( sb_out, L"%ls%ls\n", prepend, next->completion ); } } halloc_free( comp ); recursion_level--; } temporary_buffer = prev_temporary_buffer; } else if( woptind != argc ) { sb_printf( sb_err, _( L"%ls: Too many arguments\n" ), argv[0] ); builtin_print_help( argv[0], sb_err ); res = 1; } else if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) ) { /* No arguments specified, meaning we print the definitions of * all specified completions to stdout.*/ complete_print( sb_out ); } else { if( remove ) { builtin_complete_remove( &cmd, &path, (wchar_t *)short_opt.buff, &gnu_opt, &old_opt ); } else { builtin_complete_add( &cmd, &path, (wchar_t *)short_opt.buff, &gnu_opt, &old_opt, result_mode, authoritative, condition, comp, desc, flags ); } } } al_foreach( &cmd, &free ); al_foreach( &path, &free ); al_destroy( &cmd ); al_destroy( &path ); sb_destroy( &short_opt ); al_destroy( &gnu_opt ); al_destroy( &old_opt ); return res; }
/** Add all terminfo mappings */ static void input_terminfo_init() { terminfo_mappings = al_halloc( 0 ); TERMINFO_ADD(key_a1); TERMINFO_ADD(key_a3); TERMINFO_ADD(key_b2); TERMINFO_ADD(key_backspace); TERMINFO_ADD(key_beg); TERMINFO_ADD(key_btab); TERMINFO_ADD(key_c1); TERMINFO_ADD(key_c3); TERMINFO_ADD(key_cancel); TERMINFO_ADD(key_catab); TERMINFO_ADD(key_clear); TERMINFO_ADD(key_close); TERMINFO_ADD(key_command); TERMINFO_ADD(key_copy); TERMINFO_ADD(key_create); TERMINFO_ADD(key_ctab); TERMINFO_ADD(key_dc); TERMINFO_ADD(key_dl); TERMINFO_ADD(key_down); TERMINFO_ADD(key_eic); TERMINFO_ADD(key_end); TERMINFO_ADD(key_enter); TERMINFO_ADD(key_eol); TERMINFO_ADD(key_eos); TERMINFO_ADD(key_exit); TERMINFO_ADD(key_f0); TERMINFO_ADD(key_f1); TERMINFO_ADD(key_f2); TERMINFO_ADD(key_f3); TERMINFO_ADD(key_f4); TERMINFO_ADD(key_f5); TERMINFO_ADD(key_f6); TERMINFO_ADD(key_f7); TERMINFO_ADD(key_f8); TERMINFO_ADD(key_f9); TERMINFO_ADD(key_f10); TERMINFO_ADD(key_f11); TERMINFO_ADD(key_f12); TERMINFO_ADD(key_f13); TERMINFO_ADD(key_f14); TERMINFO_ADD(key_f15); TERMINFO_ADD(key_f16); TERMINFO_ADD(key_f17); TERMINFO_ADD(key_f18); TERMINFO_ADD(key_f19); TERMINFO_ADD(key_f20); /* I know of no keyboard with more than 20 function keys, so adding the rest here makes very little sense, since it will take up a lot of room in any listings (like tab completions), but with no benefit. */ /* TERMINFO_ADD(key_f21); TERMINFO_ADD(key_f22); TERMINFO_ADD(key_f23); TERMINFO_ADD(key_f24); TERMINFO_ADD(key_f25); TERMINFO_ADD(key_f26); TERMINFO_ADD(key_f27); TERMINFO_ADD(key_f28); TERMINFO_ADD(key_f29); TERMINFO_ADD(key_f30); TERMINFO_ADD(key_f31); TERMINFO_ADD(key_f32); TERMINFO_ADD(key_f33); TERMINFO_ADD(key_f34); TERMINFO_ADD(key_f35); TERMINFO_ADD(key_f36); TERMINFO_ADD(key_f37); TERMINFO_ADD(key_f38); TERMINFO_ADD(key_f39); TERMINFO_ADD(key_f40); TERMINFO_ADD(key_f41); TERMINFO_ADD(key_f42); TERMINFO_ADD(key_f43); TERMINFO_ADD(key_f44); TERMINFO_ADD(key_f45); TERMINFO_ADD(key_f46); TERMINFO_ADD(key_f47); TERMINFO_ADD(key_f48); TERMINFO_ADD(key_f49); TERMINFO_ADD(key_f50); TERMINFO_ADD(key_f51); TERMINFO_ADD(key_f52); TERMINFO_ADD(key_f53); TERMINFO_ADD(key_f54); TERMINFO_ADD(key_f55); TERMINFO_ADD(key_f56); TERMINFO_ADD(key_f57); TERMINFO_ADD(key_f58); TERMINFO_ADD(key_f59); TERMINFO_ADD(key_f60); TERMINFO_ADD(key_f61); TERMINFO_ADD(key_f62); TERMINFO_ADD(key_f63);*/ TERMINFO_ADD(key_find); TERMINFO_ADD(key_help); TERMINFO_ADD(key_home); TERMINFO_ADD(key_ic); TERMINFO_ADD(key_il); TERMINFO_ADD(key_left); TERMINFO_ADD(key_ll); TERMINFO_ADD(key_mark); TERMINFO_ADD(key_message); TERMINFO_ADD(key_move); TERMINFO_ADD(key_next); TERMINFO_ADD(key_npage); TERMINFO_ADD(key_open); TERMINFO_ADD(key_options); TERMINFO_ADD(key_ppage); TERMINFO_ADD(key_previous); TERMINFO_ADD(key_print); TERMINFO_ADD(key_redo); TERMINFO_ADD(key_reference); TERMINFO_ADD(key_refresh); TERMINFO_ADD(key_replace); TERMINFO_ADD(key_restart); TERMINFO_ADD(key_resume); TERMINFO_ADD(key_right); TERMINFO_ADD(key_save); TERMINFO_ADD(key_sbeg); TERMINFO_ADD(key_scancel); TERMINFO_ADD(key_scommand); TERMINFO_ADD(key_scopy); TERMINFO_ADD(key_screate); TERMINFO_ADD(key_sdc); TERMINFO_ADD(key_sdl); TERMINFO_ADD(key_select); TERMINFO_ADD(key_send); TERMINFO_ADD(key_seol); TERMINFO_ADD(key_sexit); TERMINFO_ADD(key_sf); TERMINFO_ADD(key_sfind); TERMINFO_ADD(key_shelp); TERMINFO_ADD(key_shome); TERMINFO_ADD(key_sic); TERMINFO_ADD(key_sleft); TERMINFO_ADD(key_smessage); TERMINFO_ADD(key_smove); TERMINFO_ADD(key_snext); TERMINFO_ADD(key_soptions); TERMINFO_ADD(key_sprevious); TERMINFO_ADD(key_sprint); TERMINFO_ADD(key_sr); TERMINFO_ADD(key_sredo); TERMINFO_ADD(key_sreplace); TERMINFO_ADD(key_sright); TERMINFO_ADD(key_srsume); TERMINFO_ADD(key_ssave); TERMINFO_ADD(key_ssuspend); TERMINFO_ADD(key_stab); TERMINFO_ADD(key_sundo); TERMINFO_ADD(key_suspend); TERMINFO_ADD(key_undo); TERMINFO_ADD(key_up); }