gschem

x_misc.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 2011 gEDA Contributors (see ChangeLog for details)
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 #include <config.h>
00020 
00021 #ifdef OS_WIN32
00022 # define STRICT
00023 # include <windows.h>
00024 # undef STRICT
00025 #endif
00026 
00027 #include "gschem.h"
00028 
00029 #ifdef HAVE_LIBDMALLOC
00030 #include <dmalloc.h>
00031 #endif
00032 
00033 #ifdef HAVE_SYS_WAIT_H
00034 #include <sys/wait.h>
00035 #endif
00036 
00037 #if defined (OS_WIN32)
00038 
00050 static gboolean
00051 show_uri__win32 (const gchar *uri, GError **error)
00052 {
00053 
00054   /* On Windows, we need to use ShellExecute because allegedly GIO
00055    * doesn't cope very well with Windows. :-( */
00056 
00057   int status;
00058   gchar *msg = NULL;
00059 
00060   g_assert (uri);
00061 
00062   status =
00063     (int) ShellExecute (NULL, /* window handle */
00064                         "open",
00065                         uri,
00066                         NULL, /* No parameters (not launching application) */
00067                         NULL, /* Inherit working directory */
00068                         SW_SHOWNORMAL); /* Default application display mode */
00069   if (status > 32) {
00070     return TRUE;
00071   }
00072 
00073   if (status == 0) {
00074     msg = g_strdup (_("The operating system is out of memory or resources."));
00075   } else {
00076     LPVOID buf;
00077     FormatMessage ((FORMAT_MESSAGE_ALLOCATE_BUFFER |
00078                     FORMAT_MESSAGE_FROM_SYSTEM |
00079                     FORMAT_MESSAGE_IGNORE_INSERTS),
00080                    NULL,
00081                    status,
00082                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00083                    (LPTSTR) &buf,
00084                    0,
00085                    NULL);
00086     msg = g_strdup ((gchar *) buf);
00087     LocalFree (buf);
00088   }
00089   /* \bug We should specify a domain and error code. */
00090   g_set_error (error, 0, 0, "%s", msg);
00091   g_free (msg);
00092   return FALSE;
00093 }
00094 #endif /* OS_WIN32 */
00095 
00113 gboolean
00114 x_show_uri (GSCHEM_TOPLEVEL *w_current, const gchar *uri,
00115             GError **error)
00116 {
00117 # if defined (SHOW_URI_GIO)
00118   GdkScreen *screen;
00119 
00120   g_assert (w_current);
00121   g_assert (uri);
00122 
00123   screen = gtk_window_get_screen (GTK_WINDOW (w_current->main_window));
00124   return gtk_show_uri (screen, uri, GDK_CURRENT_TIME, error);
00125 
00126 # elif defined (OS_WIN32) && !defined (OS_CYGWIN)
00127   return show_uri__win32 (uri, error);
00128 
00129 # else
00130   gboolean spawn_status;
00131   gint exit_status;
00132   gchar *argv[3];
00133 
00134   g_assert (uri);
00135 
00136   argv[0] = SHOW_URI_COMMAND;
00137   argv[1] = (gchar *) uri;
00138   argv[2] = NULL; /* Null-terminated */
00139 
00140   spawn_status = g_spawn_sync (NULL, /* Inherit working directory */
00141                                argv,
00142                                NULL, /* Inherit environment */
00143                                G_SPAWN_SEARCH_PATH, /* Flags */
00144                                NULL, /* No child setup function */
00145                                NULL, /* No child setup function data */
00146                                NULL, /* Don't need stdout */
00147                                NULL, /* Don't need stderr */
00148                                &exit_status,
00149                                error);
00150 
00151   if (!spawn_status) return FALSE;
00152 
00153   if (exit_status != 0) {
00154     g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
00155                  _("%s failed to launch URI"), argv[0]);
00156     return FALSE;
00157   }
00158 
00159   return TRUE;
00160 
00161 # endif
00162 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines