missing NULL terminator in set_config_x
[geda-gaf.git] / gschem / src / x_misc.c
blob79ab14b2ce994fa07744e17bc43d05ffdb02cf79
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 2011-2020 gEDA Contributors (see ChangeLog for details)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <config.h>
21 #ifdef OS_WIN32
22 # define STRICT
23 # include <windows.h>
24 # undef STRICT
25 #endif
27 #include "gschem.h"
29 #ifdef HAVE_SYS_WAIT_H
30 #include <sys/wait.h>
31 #endif
33 #if defined (OS_WIN32)
35 /*! \brief Launch application to show URI on Windows.
36 * \par Function Description
37 * On native Windows, the ShellExecute Windows API function provides a
38 * reliable way to open a URI in a default application.
40 * This function is called by x_show_uri().
42 * \param uri URI to launch viewer for.
43 * \param error Location to return error information.
44 * \return TRUE on success, FALSE on failure.
46 static gboolean
47 show_uri__win32 (const gchar *uri, GError **error)
50 /* On Windows, we need to use ShellExecute because allegedly GIO
51 * doesn't cope very well with Windows. :-( */
53 int status;
54 gchar *msg = NULL;
56 g_assert (uri);
58 status =
59 (int) ShellExecute (NULL, /* window handle */
60 "open",
61 uri,
62 NULL, /* No parameters (not launching application) */
63 NULL, /* Inherit working directory */
64 SW_SHOWNORMAL); /* Default application display mode */
65 if (status > 32) {
66 return TRUE;
69 if (status == 0) {
70 msg = g_strdup (_("The operating system is out of memory or resources."));
71 } else {
72 LPVOID buf;
73 FormatMessage ((FORMAT_MESSAGE_ALLOCATE_BUFFER |
74 FORMAT_MESSAGE_FROM_SYSTEM |
75 FORMAT_MESSAGE_IGNORE_INSERTS),
76 NULL,
77 status,
78 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
79 (LPTSTR) &buf,
81 NULL);
82 msg = g_strdup ((gchar *) buf);
83 LocalFree (buf);
85 /* \bug We should specify a domain and error code. */
86 g_set_error (error, 0, 0, "%s", msg);
87 g_free (msg);
88 return FALSE;
90 #endif /* OS_WIN32 */
92 /*! \brief Launch default application for a URI.
93 * \par Function Description
94 * Launches the default application associated with \a uri on the host
95 * platform.
97 * Depending on the way gEDA was configured, this may occur by one of
98 * the following three methods:
100 * -# Calling gtk_show_uri() to use the GIO library (default on Linux)
101 * -# Calling the ShellExecute() Windows API call (default on Windows)
102 * -# Running an appropriate external tool.
104 * \param w_current Current #GschemToplevel structure.
105 * \param uri URI to launch viewer for.
106 * \param error Location to return error information.
107 * \return TRUE on success, FALSE on failure.
109 gboolean
110 x_show_uri (GschemToplevel *w_current, const gchar *uri,
111 GError **error)
113 # if defined (SHOW_URI_GIO)
114 GdkScreen *screen;
116 g_assert (w_current);
117 g_assert (uri);
119 screen = gtk_window_get_screen (GTK_WINDOW (w_current->main_window));
120 return gtk_show_uri (screen, uri, GDK_CURRENT_TIME, error);
122 # elif defined (OS_WIN32) && !defined (OS_CYGWIN)
123 return show_uri__win32 (uri, error);
125 # else
126 gboolean spawn_status;
127 gint exit_status;
128 gchar *argv[3];
130 g_assert (uri);
132 argv[0] = SHOW_URI_COMMAND;
133 argv[1] = (gchar *) uri;
134 argv[2] = NULL; /* Null-terminated */
136 spawn_status = g_spawn_sync (NULL, /* Inherit working directory */
137 argv,
138 NULL, /* Inherit environment */
139 G_SPAWN_SEARCH_PATH, /* Flags */
140 NULL, /* No child setup function */
141 NULL, /* No child setup function data */
142 NULL, /* Don't need stdout */
143 NULL, /* Don't need stderr */
144 &exit_status,
145 error);
147 if (!spawn_status) return FALSE;
149 if (exit_status != 0) {
150 g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
151 _("%s failed to launch URI"), argv[0]);
152 return FALSE;
155 return TRUE;
157 # endif