28 #define G_LOG_DOMAIN "Dialogs.Script" 71 ssize_t length_key = 0;
72 while ( length_key <= length && line[length_key] !=
'\x1f' ) {
76 if ( length_key < length ) {
77 line[length_key] =
'\0';
78 char *value = line + length_key + 1;
79 if ( strcasecmp ( line,
"message" ) == 0 ) {
81 pd->
message = strlen(value)? g_strdup ( value ):NULL;
83 else if ( strcasecmp ( line,
"prompt" ) == 0 ) {
85 pd->
prompt = g_strdup ( value );
88 else if ( strcasecmp ( line,
"markup-rows" ) == 0 ) {
89 pd->
do_markup = ( strcasecmp ( value,
"true" ) == 0 );
91 else if ( strcasecmp ( line,
"urgent" ) == 0 ) {
94 else if ( strcasecmp ( line,
"active" ) == 0 ) {
103 GError *error = NULL;
108 if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) {
109 argv = g_realloc ( argv, ( argc + 2 ) *
sizeof (
char* ) );
110 argv[argc] = g_strdup ( arg );
111 argv[argc + 1] = NULL;
112 g_spawn_async_with_pipes ( NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
114 if ( error != NULL ) {
115 char *msg = g_strdup_printf (
"Failed to execute: '%s'\nError: '%s'", command, error->message );
119 g_error_free ( error );
123 FILE *inp = fdopen ( fd,
"r" );
126 size_t buffer_length = 0;
127 ssize_t read_length = 0;
128 size_t actual_size = 0;
129 while ( ( read_length = getline ( &buffer, &buffer_length, inp ) ) > 0 ) {
131 if ( buffer[read_length - 1] ==
'\n' ) {
132 buffer[read_length - 1] =
'\0';
134 if ( buffer[0] ==
'\0' ) {
138 if ( actual_size < ( ( *length ) + 2 ) ) {
140 retv = g_realloc ( retv, ( actual_size ) *
sizeof (
char* ) );
142 retv[( *length )] = g_strdup ( buffer );
143 retv[( *length ) + 1] = NULL;
150 if ( fclose ( inp ) != 0 ) {
151 g_warning (
"Failed to close stdout off executor script: '%s'",
152 g_strerror ( errno ) );
207 char **new_list = NULL;
208 unsigned int new_length = 0;
219 else if ( ( mretv &
MENU_OK ) && rmpd->
cmd_list[selected_line] != NULL ) {
223 else if ( ( mretv &
MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] !=
'\0' ) {
229 if ( new_list != NULL ) {
242 if ( rmpd != NULL ) {
252 static char *
_get_display_value (
const Mode *sw,
unsigned int selected_line, G_GNUC_UNUSED
int *state, G_GNUC_UNUSED GList **list,
int get_entry )
256 if ( selected_line >= pd->
active_list[i].
start && selected_line <= pd->active_list[i].stop ) {
261 if ( selected_line >= pd->
urgent_list[i].
start && selected_line <= pd->urgent_list[i].stop ) {
268 return get_entry ? g_strdup ( pd->
cmd_list[selected_line] ) : NULL;
279 return g_strdup ( pd->
message );
285 Mode *sw = g_malloc0 (
sizeof ( *sw ) );
287 char *parse = g_strdup ( str );
288 unsigned int index = 0;
289 const char *
const sep =
":";
290 for (
char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
292 sw->
name = g_strdup ( token );
294 else if ( index == 1 ) {
314 fprintf ( stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
321 return strchr ( token,
':' ) != NULL;
_mode_get_message _get_message
static int script_mode_init(Mode *sw)
_mode_token_match _token_match
unsigned int num_urgent_list
static char * _get_display_value(const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry)
static void script_switcher_free(Mode *sw)
static unsigned int script_mode_get_num_entries(const Mode *sw)
unsigned int num_active_list
_mode_preprocess_input _preprocess_input
int helper_token_match(rofi_int_matcher *const *tokens, const char *input)
unsigned int cmd_list_length
static char ** get_script_output(Mode *sw, char *command, char *arg, unsigned int *length)
int rofi_view_error_dialog(const char *msg, int markup)
static void script_mode_destroy(Mode *sw)
gboolean script_switcher_is_valid(const char *token)
char * rofi_expand_path(const char *input)
static void parse_header_entry(Mode *sw, char *line, ssize_t length)
void parse_ranges(char *input, rofi_range_pair **list, unsigned int *length)
Mode * script_switcher_parse_setup(const char *str)
struct rofi_range_pair * active_list
static int script_token_match(const Mode *sw, rofi_int_matcher **tokens, unsigned int index)
static ModeMode script_mode_result(Mode *sw, int mretv, char **input, unsigned int selected_line)
_mode_get_display_value _get_display_value
static char * script_get_message(const Mode *sw)
static char ** execute_executor(Mode *sw, char *result, unsigned int *length)
__mode_get_num_entries _get_num_entries
struct rofi_range_pair * urgent_list
static void script_mode_reset_highlight(Mode *sw)
_mode_get_completion _get_completion