29 #define G_LOG_DOMAIN "Dialogs.Script"
81 gchar **extras = g_strsplit ( buffer,
"\x1f", -1 );
83 for ( extra = extras; *extra != NULL && *( extra + 1 ) != NULL; extra += 2 ) {
85 gchar *value = *( extra + 1 );
86 if ( strcasecmp ( key,
"icon" ) == 0 ) {
89 else if ( strcasecmp ( key,
"meta" ) == 0 ) {
92 else if ( strcasecmp ( key,
"info" ) == 0 ) {
95 else if ( strcasecmp ( key,
"nonselectable" ) == 0 ) {
114 ssize_t length_key = 0;
115 while ( length_key < length && line[length_key] !=
'\x1f' ) {
119 if ( ( length_key + 1 ) < length ) {
120 line[length_key] =
'\0';
121 char *value = line + length_key + 1;
122 if ( strcasecmp ( line,
"message" ) == 0 ) {
124 pd->
message = strlen ( value ) ? g_strdup ( value ) : NULL;
126 else if ( strcasecmp ( line,
"prompt" ) == 0 ) {
128 pd->
prompt = g_strdup ( value );
131 else if ( strcasecmp ( line,
"markup-rows" ) == 0 ) {
132 pd->
do_markup = ( strcasecmp ( value,
"true" ) == 0 );
134 else if ( strcasecmp ( line,
"urgent" ) == 0 ) {
137 else if ( strcasecmp ( line,
"active" ) == 0 ) {
140 else if ( strcasecmp ( line,
"delim" ) == 0 ) {
143 else if ( strcasecmp ( line,
"no-custom" ) == 0 ) {
144 pd->
no_custom = ( strcasecmp ( value,
"true" ) == 0 );
153 GError *error = NULL;
160 char ** env = g_get_environ ();
162 char *str_value = g_strdup_printf (
"%d", value );
163 env = g_environ_setenv ( env,
"ROFI_RETV", str_value, TRUE );
164 g_free ( str_value );
166 str_value = g_strdup_printf (
"%d", (
int) getpid () );
167 env = g_environ_setenv ( env,
"ROFI_OUTSIDE", str_value, TRUE );
168 g_free ( str_value );
170 if ( entry && entry->
info ) {
171 env = g_environ_setenv ( env,
"ROFI_INFO", entry->
info, TRUE );
174 if ( g_shell_parse_argv ( sw->
ed, &argc, &argv, &error ) ) {
175 argv = g_realloc ( argv, ( argc + 2 ) *
sizeof (
char* ) );
176 argv[argc] = g_strdup ( arg );
177 argv[argc + 1] = NULL;
178 g_spawn_async_with_pipes ( NULL, argv, env, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
181 if ( error != NULL ) {
182 char *msg = g_strdup_printf (
"Failed to execute: '%s'\nError: '%s'", (
char *) sw->
ed, error->message );
186 g_error_free ( error );
190 FILE *inp = fdopen ( fd,
"r" );
193 size_t buffer_length = 0;
194 ssize_t read_length = 0;
195 size_t actual_size = 0;
196 while ( ( read_length = getdelim ( &buffer, &buffer_length, pd->
delim, inp ) ) > 0 ) {
198 if ( buffer[read_length - 1] == pd->
delim ) {
199 buffer[read_length - 1] =
'\0';
201 if ( buffer[0] ==
'\0' ) {
205 if ( actual_size < ( ( *length ) + 2 ) ) {
209 size_t buf_length = strlen ( buffer ) + 1;
210 retv[( *length )].entry = g_memdup ( buffer, buf_length );
211 retv[( *length )].icon_name = NULL;
212 retv[( *length )].meta = NULL;
213 retv[( *length )].info = NULL;
214 retv[( *length )].icon_fetch_uid = 0;
215 retv[( *length )].nonselectable = FALSE;
216 if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) {
219 retv[( *length ) + 1].entry = NULL;
226 if ( fclose ( inp ) != 0 ) {
227 g_warning (
"Failed to close stdout off executor script: '%s'",
228 g_strerror ( errno ) );
279 unsigned int new_length = 0;
290 if ( selected_line != UINT32_MAX ) {
309 else if ( ( mretv &
MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] !=
'\0' ) {
320 if ( new_list != NULL ) {
338 if ( rmpd != NULL ) {
353 static inline unsigned int get_index (
unsigned int length,
int index )
358 if ( ( (
unsigned int) -index ) <= length ) {
359 return length + index;
364 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 )
370 if ( selected_line >=
start && selected_line <=
stop ) {
377 if ( selected_line >=
start && selected_line <=
stop ) {
384 return get_entry ? g_strdup ( pd->
cmd_list[selected_line].
entry ) : NULL;
392 for (
int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
396 if ( test == tokens[j]->invert && rmpd->
cmd_list[index].
meta ) {
410 return g_strdup ( pd->
message );
415 g_return_val_if_fail ( pd->
cmd_list != NULL, NULL );
430 Mode *sw = g_malloc0 (
sizeof ( *sw ) );
432 char *parse = g_strdup ( str );
433 unsigned int index = 0;
434 const char *
const sep =
":";
435 for (
char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
437 sw->
name = g_strdup ( token );
439 else if ( index == 1 ) {
460 fprintf ( stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
467 return strchr ( token,
':' ) != NULL;