Merge pull request #1181 from b4n/vte-2.91
[geany-mirror.git] / src / spawn.h
blob71bed50c3f48b1ca128e6e580e15d8b21f346b5c
1 /*
2 * spawn.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2013 Dimitar Toshkov Zhekov <dimitar(dot)zhekov(at)gmail(dot)com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef GEANY_SPAWN_H
23 #define GEANY_SPAWN_H 1
25 #include <glib.h>
27 #ifdef G_OS_WIN32
28 # define SPAWN_WIFEXITED(status) TRUE
29 # define SPAWN_WEXITSTATUS(status) (status)
30 # define SPAWN_WIFSIGNALED(status) FALSE
31 #else
32 # include <sys/types.h>
33 # include <sys/wait.h>
34 # define SPAWN_WIFEXITED(status) WIFEXITED(status) /**< non-zero if the child exited normally */
35 # define SPAWN_WEXITSTATUS(status) WEXITSTATUS(status) /**< exit status of a child if exited normally */
36 # define SPAWN_WIFSIGNALED(status) WIFSIGNALED(status) /**< non-zero if the child exited due to signal */
37 #endif
39 G_BEGIN_DECLS
41 gboolean spawn_check_command(const gchar *command_line, gboolean execute, GError **error);
43 gboolean spawn_kill_process(GPid pid, GError **error);
45 gboolean spawn_async(const gchar *working_directory, const gchar *command_line, gchar **argv,
46 gchar **envp, GPid *child_pid, GError **error);
48 /** Flags passed to @c spawn_with_callbacks(), which see. */
49 typedef enum
51 SPAWN_ASYNC = 0x00, /**< Asynchronous execution [default]. */
52 SPAWN_SYNC = 0x01, /**< Synchronous execution. */
53 /* buffering modes */
54 SPAWN_LINE_BUFFERED = 0x00, /**< stdout/stderr are line buffered [default]. */
55 SPAWN_STDOUT_UNBUFFERED = 0x02, /**< stdout is not buffered. */
56 SPAWN_STDERR_UNBUFFERED = 0x04, /**< stderr is not buffered. */
57 SPAWN_UNBUFFERED = 0x06, /**< stdout/stderr are not buffered. */
58 /* recursive modes */
59 SPAWN_STDIN_RECURSIVE = 0x08, /**< The stdin callback is recursive. */
60 SPAWN_STDOUT_RECURSIVE = 0x10, /**< The stdout callback is recursive. */
61 SPAWN_STDERR_RECURSIVE = 0x20, /**< The stderr callback is recursive. */
62 SPAWN_RECURSIVE = 0x38 /**< All callbacks are recursive. */
63 } SpawnFlags;
65 /**
66 * Specifies the type of function passed to @c spawn_with_callbacks() as stdout or stderr
67 * callback.
69 * In unbuffered mode, the @a string may contain nuls, while in line buffered mode, it may
70 * contain only a single nul as a line termination character at @a string->len - 1. In all
71 * cases, the @a string will be terminated with a nul character that is not part of the data
72 * at @a string->len.
74 * If @c G_IO_IN or @c G_IO_PRI are set, the @a string will contain at least one character.
76 * @param string contains the child data if @c G_IO_IN or @c G_IO_PRI are set.
77 * @param condition the I/O condition which has been satisfied.
78 * @param data the passed to @c spawn_with_callbacks() with the callback.
80 typedef void (*SpawnReadFunc)(GString *string, GIOCondition condition, gpointer data);
82 gboolean spawn_with_callbacks(const gchar *working_directory, const gchar *command_line,
83 gchar **argv, gchar **envp, SpawnFlags spawn_flags, GIOFunc stdin_cb, gpointer stdin_data,
84 SpawnReadFunc stdout_cb, gpointer stdout_data, gsize stdout_max_length,
85 SpawnReadFunc stderr_cb, gpointer stderr_data, gsize stderr_max_length,
86 GChildWatchFunc exit_cb, gpointer exit_data, GPid *child_pid, GError **error);
88 /**
89 * A simple structure used by @c spawn_write_data() to write data to a channel.
90 * See @c spawn_write_data() for more information.
92 typedef struct _SpawnWriteData
94 const gchar *ptr; /**< Pointer to the data. May be NULL if the size is 0. */
95 gsize size; /**< Size of the data. */
96 } SpawnWriteData;
98 gboolean spawn_write_data(GIOChannel *channel, GIOCondition condition, SpawnWriteData *data);
100 gboolean spawn_sync(const gchar *working_directory, const gchar *command_line, gchar **argv,
101 gchar **envp, SpawnWriteData *stdin_data, GString *stdout_data, GString *stderr_data,
102 gint *exit_status, GError **error);
104 G_END_DECLS
106 #endif /* GEANY_SPAWN_H */