summaryrefslogtreecommitdiff
path: root/src/drivers/X11/Fl_X11_System_Driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/X11/Fl_X11_System_Driver.cxx')
-rw-r--r--src/drivers/X11/Fl_X11_System_Driver.cxx124
1 files changed, 59 insertions, 65 deletions
diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx
index 4914c1a29..0714ff753 100644
--- a/src/drivers/X11/Fl_X11_System_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_System_Driver.cxx
@@ -1,6 +1,4 @@
//
-// "$Id$"
-//
// Definition of Posix system driver
// for the Fast Light Tool Kit (FLTK).
//
@@ -10,11 +8,11 @@
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
-// http://www.fltk.org/COPYING.php
+// https://www.fltk.org/COPYING.php
//
-// Please report all bugs and problems on the following page:
+// Please see the following page on how to report bugs and issues:
//
-// http://www.fltk.org/str.php
+// https://www.fltk.org/bugs.php
//
#include "Fl_X11_System_Driver.H"
@@ -65,7 +63,7 @@ extern "C" {
/**
Creates a driver that manages all system related calls.
-
+
This function must be implemented once for every platform.
*/
Fl_System_Driver *Fl_System_Driver::newSystemDriver()
@@ -92,33 +90,33 @@ int Fl_X11_System_Driver::clocale_printf(FILE *output, const char *format, va_li
// Find a program in the path...
static char *path_find(const char *program, char *filename, int filesize) {
- const char *path; // Search path
- char *ptr, // Pointer into filename
- *end; // End of filename buffer
-
-
+ const char *path; // Search path
+ char *ptr, // Pointer into filename
+ *end; // End of filename buffer
+
+
if ((path = fl_getenv("PATH")) == NULL) path = "/bin:/usr/bin";
-
+
for (ptr = filename, end = filename + filesize - 1; *path; path ++) {
if (*path == ':') {
if (ptr > filename && ptr[-1] != '/' && ptr < end) *ptr++ = '/';
-
+
strlcpy(ptr, program, end - ptr + 1);
-
+
if (!access(filename, X_OK)) return filename;
-
+
ptr = filename;
} else if (ptr < end) *ptr++ = *path;
}
-
+
if (ptr > filename) {
if (ptr[-1] != '/' && ptr < end) *ptr++ = '/';
-
+
strlcpy(ptr, program, end - ptr + 1);
-
+
if (!access(filename, X_OK)) return filename;
}
-
+
return 0;
}
@@ -136,10 +134,10 @@ int Fl_X11_System_Driver::open_uri(const char *uri, char *msg, int msglen)
// 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[FL_PATH_MAX], // Command to run...
- *argv[4], // Command-line arguments
- remote[1024]; // Remote-mode command...
- const char * const *commands; // Array of commands to check...
+ char command[FL_PATH_MAX], // Command to run...
+ *argv[4], // Command-line arguments
+ remote[1024]; // Remote-mode command...
+ const char * const *commands; // Array of commands to check...
int i;
static const char * const browsers[] = {
"xdg-open", // Portland
@@ -170,35 +168,35 @@ int Fl_X11_System_Driver::open_uri(const char *uri, char *msg, int msglen)
"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;
@@ -212,16 +210,16 @@ int Fl_X11_System_Driver::open_uri(const char *uri, char *msg, int msglen)
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;
}
@@ -236,7 +234,7 @@ int Fl_X11_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser,
int res = -1, len;
char *list = NULL, *name;
struct vmount *vp;
-
+
// We always have the root filesystem
add("/", icon);
// Get the required buffer size for the vmount structures
@@ -274,7 +272,7 @@ int Fl_X11_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser,
// http://www.daemon-systems.org/man/getmntinfo.3.html
int res = -1;
struct statvfs *list;
-
+
// We always have the root filesystem
browser->add("/", icon);
# ifdef HAVE_PTHREAD
@@ -303,8 +301,8 @@ int Fl_X11_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser,
//
// UNIX code uses /etc/fstab or similar...
//
- FILE *mtab; // /etc/mtab or /etc/mnttab file
- char line[FL_PATH_MAX]; // Input line
+ FILE *mtab; // /etc/mtab or /etc/mnttab file
+ char line[FL_PATH_MAX]; // Input line
// Every Unix has a root filesystem '/'.
// This ensures that the user don't get an empty
@@ -317,15 +315,15 @@ int Fl_X11_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser,
//
// Note: this misses automounted filesystems on FreeBSD if absent from /etc/fstab
//
-
- mtab = fopen("/etc/mnttab", "r"); // Fairly standard
+
+ mtab = fopen("/etc/mnttab", "r"); // Fairly standard
if (mtab == NULL)
- mtab = fopen("/etc/mtab", "r"); // More standard
+ mtab = fopen("/etc/mtab", "r"); // More standard
if (mtab == NULL)
- mtab = fopen("/etc/fstab", "r"); // Otherwise fallback to full list
+ mtab = fopen("/etc/fstab", "r"); // Otherwise fallback to full list
if (mtab == NULL)
- mtab = fopen("/etc/vfstab", "r"); // Alternate full list file
-
+ mtab = fopen("/etc/vfstab", "r"); // Alternate full list file
+
if (mtab != NULL)
{
while (fgets(line, sizeof(line), mtab) != NULL)
@@ -336,15 +334,15 @@ int Fl_X11_System_Driver::file_browser_load_filesystem(Fl_File_Browser *browser,
continue;
if (strcmp("/", filename) == 0)
continue; // "/" was added before
-
+
// Add a trailing slash (except for the root filesystem)
strlcat(filename, "/", lname);
-
+
// printf("Fl_File_Browser::load() - adding \"%s\" to list...\n", filename);
browser->add(filename, icon);
num_files ++;
}
-
+
fclose(mtab);
}
#endif // _AIX || ...
@@ -357,17 +355,17 @@ void Fl_X11_System_Driver::newUUID(char *uuidBuffer)
// #include <uuid/uuid.h>
// void uuid_generate(uuid_t out);
unsigned char b[16];
- time_t t = time(0); // first 4 byte
+ time_t t = time(0); // first 4 byte
b[0] = (unsigned char)t;
b[1] = (unsigned char)(t>>8);
b[2] = (unsigned char)(t>>16);
b[3] = (unsigned char)(t>>24);
- int r = rand(); // four more bytes
+ int r = rand(); // four more bytes
b[4] = (unsigned char)r;
b[5] = (unsigned char)(r>>8);
b[6] = (unsigned char)(r>>16);
b[7] = (unsigned char)(r>>24);
- unsigned long a = (unsigned long)&t; // four more bytes
+ unsigned long a = (unsigned long)&t; // four more bytes
b[8] = (unsigned char)a;
b[9] = (unsigned char)(a>>8);
b[10] = (unsigned char)(a>>16);
@@ -390,7 +388,7 @@ void Fl_X11_System_Driver::newUUID(char *uuidBuffer)
b[10] = v.a[2];
b[11] = v.a[3];
# endif
- char name[80]; // last four bytes
+ char name[80]; // last four bytes
gethostname(name, 79);
memcpy(b+12, name, 4);
sprintf(uuidBuffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
@@ -425,7 +423,7 @@ char *Fl_X11_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Prefer
strcpy(filename, "/etc/fltk/");
break;
}
-
+
// Make sure that the parameters are not NULL
if ( (vendor==0L) || (vendor[0]==0) )
vendor = "unknown";
@@ -449,12 +447,12 @@ int Fl_X11_System_Driver::XParseGeometry(const char* string, int* x, int* y,
int Fl_X11_System_Driver::filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **) ) {
int dirlen;
char *dirloc;
-
+
// Assume that locale encoding is no less dense than UTF-8
dirlen = strlen(d);
dirloc = (char *)malloc(dirlen + 1);
fl_utf8to_mb(d, dirlen, dirloc, dirlen + 1);
-
+
#ifndef HAVE_SCANDIR
// This version is when we define our own scandir
int n = fl_scandir(dirloc, list, 0, sort);
@@ -475,31 +473,31 @@ int Fl_X11_System_Driver::filename_list(const char *d, dirent ***list, int (*sor
// changes:
int n = scandir(dirloc, list, 0, (int(*)(const void*,const void*))sort);
#endif
-
+
free(dirloc);
-
+
// convert every filename to UTF-8, and append a '/' to all
// filenames that are directories
int i;
char *fullname = (char*)malloc(dirlen+FL_PATH_MAX+3); // Add enough extra for two /'s and a nul
// Use memcpy for speed since we already know the length of the string...
memcpy(fullname, d, dirlen+1);
-
+
char *name = fullname + dirlen;
if (name!=fullname && name[-1]!='/')
*name++ = '/';
-
+
for (i=0; i<n; i++) {
int newlen;
dirent *de = (*list)[i];
int len = strlen(de->d_name);
newlen = fl_utf8from_mb(NULL, 0, de->d_name, len);
dirent *newde = (dirent*)malloc(de->d_name - (char*)de + newlen + 2); // Add space for a / and a nul
-
+
// Conversion to UTF-8
memcpy(newde, de, de->d_name - (char*)de);
fl_utf8from_mb(newde->d_name, newlen + 1, de->d_name, len);
-
+
// Check if dir (checks done on "old" name as we need to interact with
// the underlying OS)
if (de->d_name[len-1]!='/' && len<=FL_PATH_MAX) {
@@ -511,12 +509,12 @@ int Fl_X11_System_Driver::filename_list(const char *d, dirent ***list, int (*sor
*dst = 0;
}
}
-
+
free(de);
(*list)[i] = newde;
}
free(fullname);
-
+
return n;
}
@@ -619,7 +617,3 @@ const char *Fl_X11_System_Driver::shortcut_add_key_name(unsigned key, char *p, c
}
#endif // !defined(FL_DOXYGEN)
-
-//
-// End of "$Id$".
-//