mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-23 04:06:22 +00:00
Implemented /script show
This commit is contained in:
@@ -94,6 +94,44 @@ scripts_list(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
GSList*
|
||||
scripts_read(const char *const script)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptpath = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
g_string_append(scriptpath, "/profanity/scripts/");
|
||||
g_string_append(scriptpath, script);
|
||||
|
||||
FILE *scriptfile = g_fopen(scriptpath->str, "r");
|
||||
if (!scriptfile) {
|
||||
log_info("Script not found: %s", scriptpath->str);
|
||||
g_string_free(scriptpath, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_string_free(scriptpath, TRUE);
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
GSList *result = NULL;
|
||||
|
||||
while ((read = getline(&line, &len, scriptfile)) != -1) {
|
||||
if (g_str_has_suffix(line, "\n")) {
|
||||
result = g_slist_append(result, g_strndup(line, strlen(line) -1));
|
||||
} else {
|
||||
result = g_slist_append(result, strdup(line));
|
||||
}
|
||||
}
|
||||
|
||||
fclose(scriptfile);
|
||||
if (line) free(line);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
scripts_exec(const char *const script)
|
||||
{
|
||||
@@ -113,7 +151,7 @@ scripts_exec(const char *const script)
|
||||
|
||||
g_string_free(scriptpath, TRUE);
|
||||
|
||||
char * line = NULL;
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user