summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2020-04-01 13:58:01 +0200
committerDave Davenport <qball@gmpclient.org>2020-04-01 13:58:01 +0200
commitaa07b8ef9475032634492f42a4f568c01fc47763 (patch)
treee5cdbab79a8c9db1b1f855f3e08520216bf0eef9 /source
parent5b8aebad3e9be5cf22f2c313e58dec1b56ef7d9a (diff)
[Script] Add option to set deliminter and example script.
Issue: #1041
Diffstat (limited to 'source')
-rw-r--r--source/dialogs/script.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index 959f3c34..a1aa5647 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -68,6 +68,7 @@ typedef struct
char *message;
char *prompt;
gboolean do_markup;
+ char delim;
} ScriptModePrivateData;
/**
@@ -127,11 +128,15 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
else if ( strcasecmp ( line, "active" ) == 0 ) {
parse_ranges ( value, &( pd->active_list ), &( pd->num_active_list ) );
}
+ else if ( strcasecmp ( line, "delim" ) == 0 ) {
+ pd->delim = helper_parse_char ( value );
+ }
}
}
static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, unsigned int *length )
{
+ ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
int fd = -1;
GError *error = NULL;
DmenuScriptEntry *retv = NULL;
@@ -159,9 +164,9 @@ static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg,
size_t buffer_length = 0;
ssize_t read_length = 0;
size_t actual_size = 0;
- while ( ( read_length = getline ( &buffer, &buffer_length, inp ) ) > 0 ) {
+ while ( ( read_length = getdelim ( &buffer, &buffer_length, pd->delim, inp ) ) > 0 ) {
// Filter out line-end.
- if ( buffer[read_length - 1] == '\n' ) {
+ if ( buffer[read_length - 1] == pd->delim ) {
buffer[read_length - 1] = '\0';
}
if ( buffer[0] == '\0' ) {
@@ -217,6 +222,7 @@ static int script_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
+ pd->delim = '\n';
sw->private_data = (void *) pd;
pd->cmd_list = get_script_output ( sw, (char *) sw->ed, NULL, &( pd->cmd_list_length ) );
}