mod/maxgui.mod/fltkmaxgui.mod/src/fl_open_uri.cxx
int
fl_open_uri(const char *uri, char *msg, int msglen) {
  // Supported URI schemes...
  static const char * const schemes[] = {
    "file://",
    "ftp://",
    "http://",
    "https://",
    "mailto:",
    "news://",
    NULL
  };

  // Validate the URI scheme...
  int i;
  for (i = 0; schemes[i]; i ++)
    if (!strncmp(uri, schemes[i], strlen(schemes[i])))
      break;

  if (!schemes[i]) {
    if (msg) {
      char scheme[255];
      if (sscanf(uri, "%254[^:]", scheme) == 1) {
        snprintf(msg, msglen, "URI scheme \"%s\" not supported.", scheme);
      } else {
        snprintf(msg, msglen, "Bad URI \"%s\"", uri);
      }
    }

    return 0;
  }

#ifdef WIN32
  if (msg) snprintf(msg, msglen, "open %s", uri);

  return (int)ShellExecute(HWND_DESKTOP, "open", uri, NULL, NULL, SW_SHOW) > 32;

#elif defined(__APPLE__)
  char	*argv[3];			// Command-line arguments

  argv[0] = (char*)"open";
  argv[1] = (char*)uri;
  argv[2] = (char*)0;

  if (msg) snprintf(msg, msglen, "open %s", uri);

  return run_program("/usr/bin/open", argv, msg, msglen) != 0;

#else // !WIN32 && !__APPLE__
  // Run any of several well-known commands to open the URI.
  //
  // We give preference to the Portland group's xdg-utils
  // programs which run the user's preferred web browser, etc.
  // based on the current desktop environment in use.  We fall
  // back on older standards and then finally test popular programs
  // until we find one we can use.
  //
  // Note that we specifically do not support the MAILER and
  // BROWSER environment variables because we have no idea whether
  // we need to run the listed commands in a terminal program.

  char	command[1024],			// Command to run...
	*argv[4],			// Command-line arguments
	remote[1024];			// Remote-mode command...
  const char * const *commands;		// Array of commands to check...
  static const char * const browsers[] = {
    "xdg-open", // Portland
    "htmlview", // Freedesktop.org
    "firefox",
    "mozilla",
    "netscape",
    "konqueror", // KDE
    "opera",
    "hotjava", // Solaris
    "mosaic",
    NULL
  };
  static const char * const readers[] = {
    "xdg-email", // Portland
    "thunderbird",
    "mozilla",
    "netscape",
    "evolution", // GNOME
    "kmailservice", // KDE
    NULL
  };
  static const char * const managers[] = {
    "xdg-open", // Portland
    "fm", // IRIX
    "dtaction", // CDE
    "nautilus", // GNOME
    "konqueror", // KDE
    NULL
  };

  // Figure out which commands to check for...
  if (!strncmp(uri, "file://", 7)) commands = managers;
  else if (!strncmp(uri, "mailto:", 7) ||
           !strncmp(uri, "news:", 5)) commands = readers;
  else commands = browsers;

  // Find the command to run...
  for (i = 0; commands[i]; i ++)
    if (path_find(commands[i], command, sizeof(command))) break;

  if (!commands[i]) {
    if (msg) {
      snprintf(msg, msglen, "No helper application found for \"%s\"", uri);
    }

    return 0;
  }

  // Handle command-specific arguments...
  argv[0] = (char *)commands[i];

  if (!strcmp(commands[i], "firefox") ||
      !strcmp(commands[i], "mozilla") ||
      !strcmp(commands[i], "netscape") ||
      !strcmp(commands[i], "thunderbird")) {
    // program -remote openURL(uri)
    snprintf(remote, sizeof(remote), "openURL(%s)", uri);

    argv[1] = (char *)"-remote";
    argv[2] = remote;
    argv[3] = 0;
  } else if (!strcmp(commands[i], "dtaction")) {
    // dtaction open uri
    argv[1] = (char *)"open";
    argv[2] = (char *)uri;
    argv[3] = 0;
  } else {
    // program uri
    argv[1] = (char *)uri;
    argv[2] = 0;
  }

  if (msg) {
    strlcpy(msg, argv[0], msglen);

    for (i = 1; argv[i]; i ++) {
      strlcat(msg, " ", msglen);
      strlcat(msg, argv[i], msglen);
    }
  }

  return run_program(command, argv, msg, msglen) != 0;
#endif // WIN32
}
/**
 * Opens the specified Uniform Resource Identifier (URI).
 * Uses an operating-system dependent program or interface. For URIs
 * using the "ftp", "http", or "https" schemes, the system default web
 * browser is used to open the URI, while "mailto" and "news" URIs are
 * typically opened using the system default mail reader and "file" URIs
 * are opened using the file system navigator.
 *
 * On success, the (optional) msg buffer is filled with the command that
 * was run to open the URI; on Windows, this will always be "open uri".
 *
 * On failure, the msg buffer is filled with an English error message.
 *
 * \b Example
 * \code
 * #include <FL/filename.H>
 * [..]
 * char errmsg[512];
 * if ( !fl_open_uri("http://google.com/", errmsg, sizeof(errmsg)) ) {
 *     char warnmsg[768];
 *     sprintf(warnmsg, "Error: %s", errmsg);
 *     fl_alert(warnmsg);
 * }
 * \endcode
 *
 * @param uri The URI to open
 * @param msg Optional buffer which contains the command or error message
 * @param msglen Length of optional buffer
 * @return 1 on success, 0 on failure
 */
Opens the specified Uniform Resource Identifier (URI).
Uses an operating-system dependent program or interface.

On success, the (optional) msg buffer is filled with the command that
was run to open the URI; on Windows, this will always be "open uri".

On failure, the msg buffer is filled with an English error message.



@param uri The URI to open
@param msg Optional buffer which contains the command or error message
@param msglen Length of optional buffer
@return 1 on success, 0 on failure
Opens the specified Uniform Resource Identifier ( URI ) . Uses an operating - system dependent program or interface . On success the ( optional ) msg buffer is filled with the command that was run to open the URI ; on Windows this will always be " open uri " . On failure the msg buffer is filled with an English error message . @param uri The URI to open @param msg Optional buffer which contains the command or error message @param msglen Length of optional buffer @return 1 on success 0 on failure
int
fl_open_uri(const char *uri, char *msg, int msglen) {
  static const char * const schemes[] = {
    "file:",
    "ftp:",
    "http:",
    "https:",
    "mailto:",
    "news:",
    NULL
  };
  int i;
  for (i = 0; schemes[i]; i ++)
    if (!strncmp(uri, schemes[i], strlen(schemes[i])))
      break;
  if (!schemes[i]) {
    if (msg) {
      char scheme[255];
      if (sscanf(uri, "%254[^:]", scheme) == 1) {
        snprintf(msg, msglen, "URI scheme \"%s\" not supported.", scheme);
      } else {
        snprintf(msg, msglen, "Bad URI \"%s\"", uri);
      }
    }
    return 0;
  }
#ifdef WIN32
  if (msg) snprintf(msg, msglen, "open %s", uri);
  return (int)ShellExecute(HWND_DESKTOP, "open", uri, NULL, NULL, SW_SHOW) > 32;
#elif defined(__APPLE__)
  char	*argv[3];			
  argv[0] = (char*)"open";
  argv[1] = (char*)uri;
  argv[2] = (char*)0;
  if (msg) snprintf(msg, msglen, "open %s", uri);
  return run_program("/usr/bin/open", argv, msg, msglen) != 0;
#else 
   We give preference to the Portland group's xdg-utils
   programs which run the user's preferred web browser, etc.
   based on the current desktop environment in use.  We fall
   back on older standards and then finally test popular programs
   until we find one we can use.
   Note that we specifically do not support the MAILER and
   BROWSER environment variables because we have no idea whether
   we need to run the listed commands in a terminal program.
  char	command[1024],			 Command to run...
	*argv[4],			
	remote[1024];			 Remote-mode command...
  const char * const *commands;		 Array of commands to check...
  static const char * const browsers[] = {
    "xdg-open",  Portland
    "htmlview",  Freedesktop.org
    "firefox",
    "mozilla",
    "netscape",
    "konqueror",  KDE
    "opera",
    "hotjava",  Solaris
    "mosaic",
    NULL
  };
  static const char * const readers[] = {
    "xdg-email",  Portland
    "thunderbird",
    "mozilla",
    "netscape",
    "evolution",  GNOME
    "kmailservice",  KDE
    NULL
  };
  static const char * const managers[] = {
    "xdg-open",  Portland
    "fm",  IRIX
    "dtaction",  CDE
    "nautilus",  GNOME
    "konqueror",  KDE
    NULL
  };
   Figure out which commands to check for...
  if (!strncmp(uri, "file:", 7)) commands = managers;
  else if (!strncmp(uri, "mailto:", 7) ||
           !strncmp(uri, "news:", 5)) commands = readers;
  else commands = browsers;
   Find the command to run...
  for (i = 0; commands[i]; i ++)
    if (path_find(commands[i], command, sizeof(command))) break;
  if (!commands[i]) {
    if (msg) {
      snprintf(msg, msglen, "No helper application found for \"%s\"", uri);
    }
    return 0;
  }
   Handle command-specific arguments...
  argv[0] = (char *)commands[i];
  if (!strcmp(commands[i], "firefox") ||
      !strcmp(commands[i], "mozilla") ||
      !strcmp(commands[i], "netscape") ||
      !strcmp(commands[i], "thunderbird")) {
     program -remote openURL(uri)
    snprintf(remote, sizeof(remote), "openURL(%s)", uri);
    argv[1] = (char *)"-remote";
    argv[2] = remote;
    argv[3] = 0;
  } else if (!strcmp(commands[i], "dtaction")) {
     dtaction open uri
    argv[1] = (char *)"open";
    argv[2] = (char *)uri;
    argv[3] = 0;
  } else {
     program uri
    argv[1] = (char *)uri;
    argv[2] = 0;
  }
  if (msg) {
    strlcpy(msg, argv[0], msglen);
    for (i = 1; argv[i]; i ++) {
      strlcat(msg, " ", msglen);
      strlcat(msg, argv[i], msglen);
    }
  }
  return run_program(command, argv, msg, msglen) != 0;
#endif  WIN32
}
int fl_open_uri ( const char * uri , char * msg , int msglen ) { static const char * const schemes [ ] = { " " , " " , " " , " " , " " , " " , NULL } ; int i ; for ( i = 0 ; schemes [ i ] ; i ++ ) if ( ! strncmp ( uri , schemes [ i ] , strlen ( schemes [ i ] ) ) ) break ; if ( ! schemes [ i ] ) { if ( msg ) { char scheme [ 255 ] ; if ( sscanf ( uri , " " , scheme ) == 1 ) { snprintf ( msg , msglen , " \" \" " , scheme ) ; } else { snprintf ( msg , msglen , " \" \" " , uri ) ; } } return 0 ; } #ifdef WIN32 if ( msg ) snprintf ( msg , msglen , " " , uri ) ; return ( int ) ShellExecute ( HWND_DESKTOP , " " , uri , NULL , NULL , SW_SHOW ) > 32 ; #elif defined ( __APPLE__ ) char * argv [ 3 ] ; argv [ 0 ] = ( char * ) " " ; argv [ 1 ] = ( char * ) uri ; argv [ 2 ] = ( char * ) 0 ; if ( msg ) snprintf ( msg , msglen , " " , uri ) ; return run_program ( " " , argv , msg , msglen ) != 0 ; #else char command [ 1024 ] , * argv [ 4 ] , remote [ 1024 ] ; const char * const * commands ; static const char * const browsers [ ] = { " " , " " , " " , " " , " " , " " , " " , " " , " " , NULL } ; static const char * const readers [ ] = { " " , " " , " " , " " , " " , " " , NULL } ; static const char * const managers [ ] = { " " , " " , " " , " " , " " , NULL } ; if ( ! strncmp ( uri , " " , 7 ) ) commands = managers ; else if ( ! strncmp ( uri , " " , 7 ) || ! strncmp ( uri , " " , 5 ) ) commands = readers ; else commands = browsers ; for ( i = 0 ; commands [ i ] ; i ++ ) if ( path_find ( commands [ i ] , command , sizeof ( command ) ) ) break ; if ( ! commands [ i ] ) { if ( msg ) { snprintf ( msg , msglen , " \" \" " , uri ) ; } return 0 ; } argv [ 0 ] = ( char * ) commands [ i ] ; if ( ! strcmp ( commands [ i ] , " " ) || ! strcmp ( commands [ i ] , " " ) || ! strcmp ( commands [ i ] , " " ) || ! strcmp ( commands [ i ] , " " ) ) { snprintf ( remote , sizeof ( remote ) , " " , uri ) ; argv [ 1 ] = ( char * ) " " ; argv [ 2 ] = remote ; argv [ 3 ] = 0 ; } else if ( ! strcmp ( commands [ i ] , " " ) ) { argv [ 1 ] = ( char * ) " " ; argv [ 2 ] = ( char * ) uri ; argv [ 3 ] = 0 ; } else { argv [ 1 ] = ( char * ) uri ; argv [ 2 ] = 0 ; } if ( msg ) { strlcpy ( msg , argv [ 0 ] , msglen ) ; for ( i = 1 ; argv [ i ] ; i ++ ) { strlcat ( msg , " " , msglen ) ; strlcat ( msg , argv [ i ] , msglen ) ; } } return run_program ( command , argv , msg , msglen ) != 0 ; #endif }
Opens the specified Uniform Resource Identifier (URI).
Opens the specified Uniform Resource Identifier ( URI ) .
// Supported URI schemes... // Validate the URI scheme... // Command-line arguments // !WIN32 && !__APPLE__ // Run any of several well-known commands to open the URI. // // We give preference to the Portland group's xdg-utils // programs which run the user's preferred web browser, etc. // based on the current desktop environment in use.  We fall // back on older standards and then finally test popular programs // until we find one we can use. // // Note that we specifically do not support the MAILER and // BROWSER environment variables because we have no idea whether // we need to run the listed commands in a terminal program. // Command to run... // Command-line arguments // Remote-mode command... // Array of commands to check... // Portland // Freedesktop.org // KDE // Solaris // Portland // GNOME // KDE // Portland // IRIX // CDE // GNOME // KDE // Figure out which commands to check for... // Find the command to run... // Handle command-specific arguments... // program -remote openURL(uri) // dtaction open uri // program uri // WIN32