geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

spawn.h
Go to the documentation of this file.
1/*
2 * spawn.h - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2013 The Geany contributors
5 *
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.
10 *
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.
15 *
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.
19 */
20
21
22#ifndef GEANY_SPAWN_H
23#define GEANY_SPAWN_H 1
24
25#include <glib.h>
26
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
38
39G_BEGIN_DECLS
40
41gboolean spawn_check_command(const gchar *command_line, gboolean execute, GError **error);
42
43gboolean spawn_kill_process(GPid pid, GError **error);
44
45gboolean spawn_async(const gchar *working_directory, const gchar *command_line, gchar **argv,
46 gchar **envp, GPid *child_pid, GError **error);
47
48/** Flags passed to @c spawn_with_callbacks(), which see. */
49typedef enum
50{
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. */
64
65/**
66 * Specifies the type of function passed to @c spawn_with_callbacks() as stdout or stderr
67 * callback.
68 *
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.
73 *
74 * If @c G_IO_IN or @c G_IO_PRI are set, the @a string will contain at least one character.
75 *
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.
79 */
80typedef void (*SpawnReadFunc)(GString *string, GIOCondition condition, gpointer data);
81
82gboolean 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);
87
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.
91 */
92typedef struct _SpawnWriteData
93{
94 const gchar *ptr; /**< Pointer to the data. May be NULL if the size is 0. */
95 gsize size; /**< Size of the data. */
97
98gboolean spawn_write_data(GIOChannel *channel, GIOCondition condition, SpawnWriteData *data);
99
100gboolean 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);
103
104G_END_DECLS
105
106#endif /* GEANY_SPAWN_H */
void error(const errorSelection selection, const char *const format,...)
Definition: error.c:53
gboolean spawn_with_callbacks(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, SpawnFlags spawn_flags, GIOFunc stdin_cb, gpointer stdin_data, SpawnReadFunc stdout_cb, gpointer stdout_data, gsize stdout_max_length, SpawnReadFunc stderr_cb, gpointer stderr_data, gsize stderr_max_length, GChildWatchFunc exit_cb, gpointer exit_data, GPid *child_pid, GError **error)
<simplesect kind="geany:skip"></simplesect> Executes a child program and setups callbacks.
Definition: spawn.c:1158
gboolean spawn_async(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, GPid *child_pid, GError **error)
Executes a child asynchronously.
Definition: spawn.c:814
gboolean spawn_check_command(const gchar *command_line, gboolean execute, GError **error)
Checks whether a command line is valid.
Definition: spawn.c:246
void(* SpawnReadFunc)(GString *string, GIOCondition condition, gpointer data)
Specifies the type of function passed to spawn_with_callbacks() as stdout or stderr callback.
Definition: spawn.h:80
SpawnFlags
Flags passed to spawn_with_callbacks(), which see.
Definition: spawn.h:50
@ SPAWN_STDOUT_RECURSIVE
The stdout callback is recursive.
Definition: spawn.h:60
@ SPAWN_ASYNC
Asynchronous execution [default].
Definition: spawn.h:51
@ SPAWN_RECURSIVE
All callbacks are recursive.
Definition: spawn.h:62
@ SPAWN_LINE_BUFFERED
stdout/stderr are line buffered [default].
Definition: spawn.h:54
@ SPAWN_STDOUT_UNBUFFERED
stdout is not buffered.
Definition: spawn.h:55
@ SPAWN_UNBUFFERED
stdout/stderr are not buffered.
Definition: spawn.h:57
@ SPAWN_STDIN_RECURSIVE
The stdin callback is recursive.
Definition: spawn.h:59
@ SPAWN_STDERR_UNBUFFERED
stderr is not buffered.
Definition: spawn.h:56
@ SPAWN_STDERR_RECURSIVE
The stderr callback is recursive.
Definition: spawn.h:61
@ SPAWN_SYNC
Synchronous execution.
Definition: spawn.h:52
struct _SpawnWriteData SpawnWriteData
A simple structure used by spawn_write_data() to write data to a channel.
gboolean spawn_sync(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, SpawnWriteData *stdin_data, GString *stdout_data, GString *stderr_data, gint *exit_status, GError **error)
Executes a child synchronously.
Definition: spawn.c:1357
gboolean spawn_write_data(GIOChannel *channel, GIOCondition condition, SpawnWriteData *data)
Writes (a portion of) the data pointed by data->ptr to the channel.
Definition: spawn.c:1297
gboolean spawn_kill_process(GPid pid, GError **error)
Kills a process.
Definition: spawn.c:289
A simple structure used by spawn_write_data() to write data to a channel.
Definition: spawn.h:93
gsize size
Size of the data.
Definition: spawn.h:95
const gchar * ptr
Pointer to the data.
Definition: spawn.h:94