diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-12-07 07:13:56 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-12-07 07:13:56 +0800 |
commit | 92b2a3c90af03a839fab06efb96429c9d4976ddd (patch) | |
tree | cc458fbcff11c5b511009a8374299b33f99c3179 /composer | |
parent | 159dc73e63bf9bf00f5c9211eddfe503b14f4b27 (diff) | |
download | gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar.gz gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar.bz2 gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar.lz gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar.xz gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.tar.zst gsoc2013-evolution-92b2a3c90af03a839fab06efb96429c9d4976ddd.zip |
Added. Executes the given file and returns its output as a string.
2001-12-06 Jon Trowbridge <trow@ximian.com>
* e-msg-composer.c (executed_file_output): Added. Executes the
given file and returns its output as a string.
(get_file_content): Stats the file to see if it is executable.
If it is, execute it and return the string. If not, just read
the file and return the contents.
svn path=/trunk/; revision=14917
Diffstat (limited to 'composer')
-rw-r--r-- | composer/ChangeLog | 8 | ||||
-rw-r--r-- | composer/e-msg-composer.c | 67 |
2 files changed, 64 insertions, 11 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog index d8445443cb..548c2f98dd 100644 --- a/composer/ChangeLog +++ b/composer/ChangeLog @@ -1,3 +1,11 @@ +2001-12-06 Jon Trowbridge <trow@ximian.com> + + * e-msg-composer.c (executed_file_output): Added. Executes the + given file and returns its output as a string. + (get_file_content): Stats the file to see if it is executable. + If it is, execute it and return the string. If not, just read + the file and return the contents. + 2001-11-30 Jeffrey Stedfast <fejj@ximian.com> * e-msg-composer.c (setup_ui): Change the FileSend tooltip the be diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index f1d3645d7c..b52295314c 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -44,6 +44,9 @@ #include <ctype.h> #include <stdlib.h> #include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include <libgnome/gnome-defs.h> #include <libgnomeui/gnome-app.h> #include <libgnomeui/gnome-uidefs.h> @@ -684,28 +687,70 @@ read_file_content (gint fd) } static char * -get_file_content (const gchar *file_name, gboolean convert, guint flags) +executed_file_output (const char *file_name) { + GByteArray *contents; + FILE *in; + char buf[4096]; + int n; + char *body; + + g_return_val_if_fail (file_name && *file_name, NULL); + + in = popen (file_name, "r"); + if (in == NULL) + return NULL; + + contents = g_byte_array_new (); + while ((n = fread (buf, 1, 4096, in)) > 0) { + g_byte_array_append (contents, buf, n); + } + g_byte_array_append (contents, "\0", 1); + + body = (n < 0) ? NULL : (char *) contents->data; + g_byte_array_free (contents, (n < 0)); + + pclose (in); + + return body; +} + +static char * +get_file_content (const char *file_name, gboolean convert, guint flags) +{ + struct stat statbuf; gint fd; char *raw; char *html; + char *msg = NULL; + + if (stat (file_name, &statbuf) == -1) + return g_strdup (""); + + if (statbuf.st_mode & S_IXUSR) { + + raw = executed_file_output (file_name); + if (raw == NULL) { + msg = g_strdup_printf (_("Error while executing file %s:\n" + "%s"), file_name, g_strerror (errno)); + } - fd = open (file_name, O_RDONLY | O_CREAT, 0775); - - raw = read_file_content (fd); - - if (raw == NULL) { - char *msg; + } else { - msg = g_strdup_printf (_("Error while reading file %s:\n" - "%s"), file_name, g_strerror (errno)); + fd = open (file_name, O_RDONLY | O_CREAT, 0775); + raw = read_file_content (fd); + if (raw == NULL) { + msg = g_strdup_printf (_("Error while reading file %s:\n" + "%s"), file_name, g_strerror (errno)); + } + close (fd); + } + if (msg != NULL) { gnome_error_dialog (msg); g_free (msg); - close (fd); return g_strdup (""); } - close (fd); html = convert ? e_text_to_html (raw, flags) : raw; |