29 #define G_LOG_DOMAIN "Dialogs.Script"
80 size_t length_key = 0;
81 while ( length_key <= length && buffer[length_key] !=
'\x1f' ) {
84 if ( length_key < length ) {
85 buffer[length_key] =
'\0';
86 char *value = buffer + length_key + 1;
87 if ( strcasecmp(buffer,
"icon" ) == 0 ) {
100 ssize_t length_key = 0;
101 while ( length_key <= length && line[length_key] !=
'\x1f' ) {
105 if ( length_key < length ) {
106 line[length_key] =
'\0';
107 char *value = line + length_key + 1;
108 if ( strcasecmp ( line,
"message" ) == 0 ) {
110 pd->
message = strlen ( value ) ? g_strdup ( value ) : NULL;
112 else if ( strcasecmp ( line,
"prompt" ) == 0 ) {
114 pd->
prompt = g_strdup ( value );
117 else if ( strcasecmp ( line,
"markup-rows" ) == 0 ) {
118 pd->
do_markup = ( strcasecmp ( value,
"true" ) == 0 );
120 else if ( strcasecmp ( line,
"urgent" ) == 0 ) {
123 else if ( strcasecmp ( line,
"active" ) == 0 ) {
132 GError *error = NULL;
137 if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) {
138 argv = g_realloc ( argv, ( argc + 2 ) *
sizeof (
char* ) );
139 argv[argc] = g_strdup ( arg );
140 argv[argc + 1] = NULL;
141 g_spawn_async_with_pipes ( NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
143 if ( error != NULL ) {
144 char *msg = g_strdup_printf (
"Failed to execute: '%s'\nError: '%s'", command, error->message );
148 g_error_free ( error );
152 FILE *inp = fdopen ( fd,
"r" );
155 size_t buffer_length = 0;
156 ssize_t read_length = 0;
157 size_t actual_size = 0;
158 while ( ( read_length = getline ( &buffer, &buffer_length, inp ) ) > 0 ) {
160 if ( buffer[read_length - 1] ==
'\n' ) {
161 buffer[read_length - 1] =
'\0';
163 if ( buffer[0] ==
'\0' ) {
167 if ( actual_size < ( ( *length ) + 2 ) ) {
171 size_t buf_length = strlen(buffer)+1;
172 retv[( *length )].
entry = g_memdup ( buffer, buf_length);
175 if ( buf_length > 0 && (read_length > (ssize_t)buf_length) ) {
178 retv[( *length ) + 1].
entry = NULL;
185 if ( fclose ( inp ) != 0 ) {
186 g_warning (
"Failed to close stdout off executor script: '%s'",
187 g_strerror ( errno ) );
242 unsigned int new_length = 0;
257 else if ( ( mretv &
MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] !=
'\0' ) {
263 if ( new_list != NULL ) {
280 if ( rmpd != NULL ) {
294 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 )
298 if ( selected_line >= pd->
active_list[i].
start && selected_line <= pd->active_list[i].stop ) {
303 if ( selected_line >= pd->
urgent_list[i].
start && selected_line <= pd->urgent_list[i].stop ) {
310 return get_entry ? g_strdup ( pd->
cmd_list[selected_line].
entry ) : NULL;
321 return g_strdup ( pd->
message );
326 g_return_val_if_fail ( pd->
cmd_list != NULL, NULL );
341 Mode *sw = g_malloc0 (
sizeof ( *sw ) );
343 char *parse = g_strdup ( str );
344 unsigned int index = 0;
345 const char *
const sep =
":";
346 for (
char *token = strtok_r ( parse, sep, &endp ); token != NULL; token = strtok_r ( NULL, sep, &endp ) ) {
348 sw->
name = g_strdup ( token );
350 else if ( index == 1 ) {
371 fprintf ( stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.", str, index );
378 return strchr ( token,
':' ) != NULL;