2011-11-23 22:56:57 -08:00
|
|
|
/* linux.c */
|
|
|
|
/* implements Linux specific functions */
|
2012-09-09 09:06:44 -07:00
|
|
|
#include "dive.h"
|
2013-05-03 11:04:51 -07:00
|
|
|
#include "display.h"
|
2012-09-09 09:06:44 -07:00
|
|
|
#include <string.h>
|
2013-09-16 18:04:42 -03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fnmatch.h>
|
2012-09-09 09:06:44 -07:00
|
|
|
|
2013-01-11 17:07:22 -08:00
|
|
|
const char system_divelist_default_font[] = "Sans 8";
|
2011-11-23 22:56:57 -08:00
|
|
|
|
2012-05-02 10:03:48 -07:00
|
|
|
void subsurface_flush_conf(void)
|
|
|
|
{
|
|
|
|
/* this is a no-op */
|
|
|
|
}
|
|
|
|
|
2011-11-23 22:56:57 -08:00
|
|
|
void subsurface_close_conf(void)
|
|
|
|
{
|
|
|
|
/* this is a no-op */
|
|
|
|
}
|
2011-12-13 20:34:56 -08:00
|
|
|
|
2011-12-28 15:57:36 -08:00
|
|
|
const char *subsurface_icon_name()
|
|
|
|
{
|
2013-02-02 12:19:28 +01:00
|
|
|
return "subsurface-icon.svg";
|
2011-12-28 15:57:36 -08:00
|
|
|
}
|
2012-01-01 13:41:47 -08:00
|
|
|
|
2013-01-11 17:07:22 -08:00
|
|
|
const char *system_default_filename(void)
|
2012-09-09 09:06:44 -07:00
|
|
|
{
|
2013-01-11 17:07:22 -08:00
|
|
|
const char *home, *user;
|
|
|
|
char *buffer;
|
|
|
|
int len;
|
|
|
|
|
2013-10-05 08:06:36 -07:00
|
|
|
home = getenv("HOME");
|
|
|
|
user = getenv("LOGNAME");
|
2013-01-11 17:07:22 -08:00
|
|
|
len = strlen(home) + strlen(user) + 17;
|
|
|
|
buffer = malloc(len);
|
|
|
|
snprintf(buffer, len, "%s/subsurface/%s.xml", home, user);
|
|
|
|
return buffer;
|
2012-09-09 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
2012-10-18 14:30:45 -07:00
|
|
|
const char *subsurface_gettext_domainpath(char *argv0)
|
2012-10-15 14:44:01 +02:00
|
|
|
{
|
2012-10-18 14:30:45 -07:00
|
|
|
if (argv0[0] == '.') {
|
|
|
|
/* we're starting a local copy */
|
|
|
|
return "./share/locale";
|
|
|
|
} else {
|
|
|
|
/* subsurface is installed, so system dir should be fine */
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-15 14:44:01 +02:00
|
|
|
}
|
|
|
|
|
2013-10-05 08:06:36 -07:00
|
|
|
void subsurface_command_line_init(int *argc, char ***argv)
|
2012-10-04 03:44:47 +03:00
|
|
|
{
|
|
|
|
/* this is a no-op */
|
|
|
|
}
|
|
|
|
|
2013-10-05 08:06:36 -07:00
|
|
|
void subsurface_command_line_exit(int *argc, char ***argv)
|
2012-10-04 03:44:47 +03:00
|
|
|
{
|
|
|
|
/* this is a no-op */
|
|
|
|
}
|
2012-10-20 02:31:06 +03:00
|
|
|
|
2013-10-05 08:06:36 -07:00
|
|
|
bool subsurface_os_feature_available(os_feature_t f)
|
2012-10-20 02:31:06 +03:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-01-15 01:20:29 +02:00
|
|
|
|
2013-09-16 18:04:42 -03:00
|
|
|
int enumerate_devices (device_callback_t callback, void *userdata)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
DIR *dp = NULL;
|
|
|
|
struct dirent *ep = NULL;
|
|
|
|
size_t i;
|
|
|
|
const char *dirname = "/dev";
|
|
|
|
const char *patterns[] = {
|
|
|
|
"ttyUSB*",
|
|
|
|
"ttyS*",
|
|
|
|
"ttyACM*",
|
|
|
|
"rfcomm*",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
dp = opendir (dirname);
|
|
|
|
if (dp == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((ep = readdir (dp)) != NULL) {
|
|
|
|
for (i = 0; patterns[i] != NULL; ++i) {
|
|
|
|
if (fnmatch (patterns[i], ep->d_name, 0) == 0) {
|
|
|
|
char filename[1024];
|
|
|
|
int n = snprintf (filename, sizeof (filename), "%s/%s", dirname, ep->d_name);
|
|
|
|
if (n >= sizeof (filename)) {
|
|
|
|
closedir (dp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
callback (filename, userdata);
|
|
|
|
if (is_default_dive_computer_device(filename))
|
|
|
|
index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: list UEMIS mount point from /proc/mounts
|
|
|
|
|
|
|
|
closedir (dp);
|
|
|
|
return index;
|
|
|
|
}
|