static char *get_progname(void)
{
#ifdef __LINUX__
	char *progname = NULL;
	FILE *fp;
	static char temp[BUFSIZ];

	SDL_snprintf(temp, SDL_arraysize(temp), "/proc/%d/cmdline", getpid());
	fp = fopen(temp, "r");
	if ( fp != NULL ) {
		if ( fgets(temp, sizeof(temp)-1, fp) ) {
			progname = SDL_strrchr(temp, '/');
			if ( progname == NULL ) {
				progname = temp;
			} else {
				progname = progname+1;
			}
		}
		fclose(fp);
	}
	return(progname);
#elif defined(__NetBSD__)
	return getprogname();
#else
	return("unknown");
#endif
}
Example #2
0
static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len)
{
    const char *value;
    char text[4096];
    char *word;
    int i;
    unsigned long v;

    SDL_memset(bitmask, 0, bitmask_len*sizeof(*bitmask));
    value = _this->udev_device_get_sysattr_value(pdev, attr);
    if (!value) {
        return;
    }

    SDL_strlcpy(text, value, sizeof(text));
    i = 0;
    while ((word = SDL_strrchr(text, ' ')) != NULL) {
        v = SDL_strtoul(word+1, NULL, 16);
        if (i < bitmask_len) {
            bitmask[i] = v;
        }
        ++i;
        *word = '\0';
    }
    v = SDL_strtoul(text, NULL, 16);
    if (i < bitmask_len) {
        bitmask[i] = v;
    }
}
Example #3
0
SDL_bool
SDL_IBus_Init(void)
{
    SDL_bool result = SDL_FALSE;
    SDL_DBusContext *dbus = SDL_DBus_GetContext();
    
    if(dbus){
        char *addr_file = IBus_GetDBusAddressFilename();
        if(!addr_file){
            return SDL_FALSE;
        }
        
        ibus_addr_file = SDL_strdup(addr_file);
        
        char *addr = IBus_ReadAddressFromFile(addr_file);
        
        inotify_fd = inotify_init();
        fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
        
        char *addr_file_dir = SDL_strrchr(addr_file, '/');
        if(addr_file_dir){
            *addr_file_dir = 0;
        }
        
        inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
        SDL_free(addr_file);
        
        result = IBus_SetupConnection(dbus, addr);
        SDL_free(addr);
    }
    
    return result;
}
Example #4
0
static char*
GetAppName()
{
#if defined(__LINUX__) || defined(__FREEBSD__)
    char *spot;
    char procfile[1024];
    char linkfile[1024];
    int linksize;

#if defined(__LINUX__)
    SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
    SDL_snprintf(procfile, sizeof(procfile), "/proc/%d/file", getpid());
#endif
    linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
    if (linksize > 0) {
        linkfile[linksize] = '\0';
        spot = SDL_strrchr(linkfile, '/');
        if (spot) {
            return SDL_strdup(spot + 1);
        } else {
            return SDL_strdup(linkfile);
        }
    }
#endif /* __LINUX__ || __FREEBSD__ */

    return SDL_strdup("SDL_App");
}
Example #5
0
/* Find out what class name we should use
 * Based on src/video/x11/SDL_x11video.c */
static char *
get_classname()
{
/* !!! FIXME: this is probably wrong, albeit harmless in many common cases. From protocol spec:
    "The surface class identifies the general class of applications
    to which the surface belongs. A common convention is to use the
    file name (or the full path if it is a non-standard location) of
    the application's .desktop file as the class." */

    char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
    char procfile[1024];
    char linkfile[1024];
    int linksize;
#endif

    /* First allow environment variable override */
    spot = SDL_getenv("SDL_VIDEO_WAYLAND_WMCLASS");
    if (spot) {
        return SDL_strdup(spot);
    } else {
        /* Fallback to the "old" envvar */
        spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
        if (spot) {
            return SDL_strdup(spot);
        }
    }

    /* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
    SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
    SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
                 getpid());
#else
#error Where can we find the executable name?
#endif
    linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
    if (linksize > 0) {
        linkfile[linksize] = '\0';
        spot = SDL_strrchr(linkfile, '/');
        if (spot) {
            return SDL_strdup(spot + 1);
        } else {
            return SDL_strdup(linkfile);
        }
    }
#endif /* __LINUX__ || __FREEBSD__ */

    /* Finally use the default we've used forever */
    return SDL_strdup("SDL_App");
}
Example #6
0
/* Find out what class name we should use
 * Based on src/video/x11/SDL_x11video.c */
static char *
get_classname()
{
    char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
    char procfile[1024];
    char linkfile[1024];
    int linksize;
#endif

    /* First allow environment variable override */
    spot = SDL_getenv("SDL_VIDEO_WAYLAND_WMCLASS");
    if (spot) {
        return SDL_strdup(spot);
    } else {
        /* Fallback to the "old" envvar */
        spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
        if (spot) {
            return SDL_strdup(spot);
        }
    }

    /* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
    SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
    SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file",
                 getpid());
#else
#error Where can we find the executable name?
#endif
    linksize = readlink(procfile, linkfile, sizeof(linkfile) - 1);
    if (linksize > 0) {
        linkfile[linksize] = '\0';
        spot = SDL_strrchr(linkfile, '/');
        if (spot) {
            return SDL_strdup(spot + 1);
        } else {
            return SDL_strdup(linkfile);
        }
    }
#endif /* __LINUX__ || __FREEBSD__ */

    /* Finally use the default we've used forever */
    return SDL_strdup("SDL_App");
}
Example #7
0
SDL_bool
SDL_IBus_Init(void)
{
    SDL_bool result = SDL_FALSE;
    SDL_DBusContext *dbus = SDL_DBus_GetContext();
    
    if (dbus) {
        char *addr_file = IBus_GetDBusAddressFilename();
        char *addr;
        char *addr_file_dir;

        if (!addr_file) {
            return SDL_FALSE;
        }
        
        /* !!! FIXME: if ibus_addr_file != NULL, this will overwrite it and leak (twice!) */
        ibus_addr_file = SDL_strdup(addr_file);
        
        addr = IBus_ReadAddressFromFile(addr_file);
        if (!addr) {
            SDL_free(addr_file);
            return SDL_FALSE;
        }
        
        if (inotify_fd < 0) {
            inotify_fd = inotify_init();
            fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
        }
        
        addr_file_dir = SDL_strrchr(addr_file, '/');
        if (addr_file_dir) {
            *addr_file_dir = 0;
        }
        
        inotify_wd = inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
        SDL_free(addr_file);
        
        if (addr) {
            result = IBus_SetupConnection(dbus, addr);
            SDL_free(addr);
        }
    }
    
    return result;
}
Example #8
0
static SDL_bool
IBus_CheckConnection(SDL_DBusContext *dbus)
{
    if (!dbus) return SDL_FALSE;
    
    if (ibus_conn && dbus->connection_get_is_connected(ibus_conn)) {
        return SDL_TRUE;
    }
    
    if (inotify_fd > 0 && inotify_wd > 0) {
        char buf[1024];
        ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
        if (readsize > 0) {
        
            char *p;
            SDL_bool file_updated = SDL_FALSE;
            
            for (p = buf; p < buf + readsize; /**/) {
                struct inotify_event *event = (struct inotify_event*) p;
                if (event->len > 0) {
                    char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
                    if (!addr_file_no_path) return SDL_FALSE;
                 
                    if (SDL_strcmp(addr_file_no_path + 1, event->name) == 0) {
                        file_updated = SDL_TRUE;
                        break;
                    }
                }
                
                p += sizeof(struct inotify_event) + event->len;
            }
            
            if (file_updated) {
                char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
                if (addr) {
                    SDL_bool result = IBus_SetupConnection(dbus, addr);
                    SDL_free(addr);
                    return result;
                }
            }
        }
    }
    
    return SDL_FALSE;
}
Example #9
0
/* Find out what class name we should use */
static char *get_classname(char *classname, int maxlen)
{
	char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
	char procfile[1024];
	char linkfile[1024];
	int linksize;
#endif

	/* First allow environment variable override */
	spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
	if ( spot ) {
		SDL_strlcpy(classname, spot, maxlen);
		return classname;
	}

	/* Next look at the application's executable name */
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif
	linksize = readlink(procfile, linkfile, sizeof(linkfile)-1);
	if ( linksize > 0 ) {
		linkfile[linksize] = '\0';
		spot = SDL_strrchr(linkfile, '/');
		if ( spot ) {
			SDL_strlcpy(classname, spot+1, maxlen);
		} else {
			SDL_strlcpy(classname, linkfile, maxlen);
		}
		return classname;
	}
#endif /* __LINUX__ */

	/* Finally use the default we've used forever */
	SDL_strlcpy(classname, "SDL_App", maxlen);
	return classname;
}
Example #10
0
static char *get_classname(char *classname, int maxlen)
{
	char *spot;
#if defined(__LINUX__) || defined(__FREEBSD__)
	char procfile[1024];
	char linkfile[1024];
	int linksize;
#endif

	
	spot = SDL_getenv("SDL_VIDEO_X11_WMCLASS");
	if ( spot ) {
		SDL_strlcpy(classname, spot, maxlen);
		return classname;
	}

	
#if defined(__LINUX__) || defined(__FREEBSD__)
#if defined(__LINUX__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/exe", getpid());
#elif defined(__FREEBSD__)
	SDL_snprintf(procfile, SDL_arraysize(procfile), "/proc/%d/file", getpid());
#else
#error Where can we find the executable name?
#endif
	linksize = readlink(procfile, linkfile, sizeof(linkfile)-1);
	if ( linksize > 0 ) {
		linkfile[linksize] = '\0';
		spot = SDL_strrchr(linkfile, '/');
		if ( spot ) {
			SDL_strlcpy(classname, spot+1, maxlen);
		} else {
			SDL_strlcpy(classname, linkfile, maxlen);
		}
		return classname;
	}
#endif 

	
	SDL_strlcpy(classname, "SDL_App", maxlen);
	return classname;
}
Example #11
0
static char *
IBus_GetDBusAddressFilename(void)
{
    SDL_DBusContext *dbus;
    const char *disp_env;
    char config_dir[PATH_MAX];
    char *display = NULL;
    const char *addr;
    const char *conf_env;
    char *key;
    char file_path[PATH_MAX];
    const char *host;
    char *disp_num, *screen_num;

    if (ibus_addr_file) {
        return SDL_strdup(ibus_addr_file);
    }
    
    dbus = SDL_DBus_GetContext();
    if (!dbus) {
        return NULL;
    }
    
    /* Use this environment variable if it exists. */
    addr = SDL_getenv("IBUS_ADDRESS");
    if (addr && *addr) {
        return SDL_strdup(addr);
    }
    
    /* Otherwise, we have to get the hostname, display, machine id, config dir
       and look up the address from a filepath using all those bits, eek. */
    disp_env = SDL_getenv("DISPLAY");

    if (!disp_env || !*disp_env) {
        display = SDL_strdup(":0.0");
    } else {
        display = SDL_strdup(disp_env);
    }
    
    host = display;
    disp_num   = SDL_strrchr(display, ':');
    screen_num = SDL_strrchr(display, '.');
    
    if (!disp_num) {
        SDL_free(display);
        return NULL;
    }
    
    *disp_num = 0;
    disp_num++;
    
    if (screen_num) {
        *screen_num = 0;
    }
    
    if (!*host) {
        host = "unix";
    }
        
    SDL_memset(config_dir, 0, sizeof(config_dir));
    
    conf_env = SDL_getenv("XDG_CONFIG_HOME");
    if (conf_env && *conf_env) {
        SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
    } else {
        const char *home_env = SDL_getenv("HOME");
        if (!home_env || !*home_env) {
            SDL_free(display);
            return NULL;
        }
        SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
    }
    
    key = dbus->get_local_machine_id();

    SDL_memset(file_path, 0, sizeof(file_path));
    SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s", 
                                               config_dir, key, host, disp_num);
    dbus->free(key);
    SDL_free(display);
    
    return SDL_strdup(file_path);
}
Example #12
0
int RISCOS_GetTaskName(char *task_name, size_t maxlen)
{
	_kernel_swi_regs regs;

   task_name[0] = 0;

   /* Figure out a sensible task name */
   if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0)
   {
	   char *command_line = (char *)regs.r[0];
	   size_t len = SDL_strlen(command_line)+1;
	   char *buffer = SDL_stack_alloc(char, len);
	   char *env_var;
	   char *p;

	   SDL_strlcpy(buffer, command_line, len);
	   p = SDL_strchr(buffer, ' ');
	   if (p) *p = 0;
	   p = SDL_strrchr(buffer, '.');
	   if (p == 0) p = buffer;
	   if (stricmp(p+1,"!RunImage") == 0)
	   {
		   *p = 0;
	   	   p = SDL_strrchr(buffer, '.');
		   if (p == 0) p = buffer;
	   }
	   if (*p == '.') p++;
	   if (*p == '!') p++; /* Skip "!" at beginning of application directories */

       if (*p == '<')
       {
          // Probably in the form <appname$Dir>
          char *q = SDL_strchr(p, '$');
          if (q == 0) q = SDL_strchr(p,'>'); /* Use variable name if not */
          if (q) *q = 0;
          p++; /* Move over the < */
       }

	   if (*p)
	   {
		   /* Read variables that effect the RISC OS SDL engine for this task */
		   len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */
		   env_var = SDL_stack_alloc(char, len);
		   if (env_var)
		   {
			   char *env_val;

			   /* See if a variable of form SDL$<dirname>$TaskName exists */

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$TaskName", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val) SDL_strlcpy(task_name, env_val, maxlen);

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$BackBuffer", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val) riscos_backbuffer = atoi(env_val);

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$CloseAction", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val && SDL_strcmp(env_val,"0") == 0) riscos_closeaction = 0;

			   SDL_stack_free(env_var);
		   }
		   
		   if (!*task_name) SDL_strlcpy(task_name, p, maxlen);
	   }

	   SDL_stack_free(buffer);
   }
int RISCOS_GetTaskName(char *task_name, size_t maxlen)
{
	_kernel_swi_regs regs;

   task_name[0] = 0;

   
   if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0)
   {
	   char *command_line = (char *)regs.r[0];
	   size_t len = SDL_strlen(command_line)+1;
	   char *buffer = SDL_stack_alloc(char, len);
	   char *env_var;
	   char *p;

	   SDL_strlcpy(buffer, command_line, len);
	   p = SDL_strchr(buffer, ' ');
	   if (p) *p = 0;
	   p = SDL_strrchr(buffer, '.');
	   if (p == 0) p = buffer;
	   if (stricmp(p+1,"!RunImage") == 0)
	   {
		   *p = 0;
	   	   p = SDL_strrchr(buffer, '.');
		   if (p == 0) p = buffer;
	   }
	   if (*p == '.') p++;
	   if (*p == '!') p++; 

       if (*p == '<')
       {
          
          char *q = SDL_strchr(p, '$');
          if (q == 0) q = SDL_strchr(p,'>'); 
          if (q) *q = 0;
          p++; 
       }

	   if (*p)
	   {
		   
		   len = SDL_strlen(p) + 18; 
		   env_var = SDL_stack_alloc(char, len);
		   if (env_var)
		   {
			   char *env_val;

			   

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$TaskName", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val) SDL_strlcpy(task_name, env_val, maxlen);

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$BackBuffer", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val) riscos_backbuffer = atoi(env_val);

			   SDL_strlcpy(env_var, "SDL$", len);
			   SDL_strlcat(env_var, p, len);
			   SDL_strlcat(env_var, "$CloseAction", len);

			   env_val = SDL_getenv(env_var);
			   if (env_val && SDL_strcmp(env_val,"0") == 0) riscos_closeaction = 0;

			   SDL_stack_free(env_var);
		   }
		   
		   if (!*task_name) SDL_strlcpy(task_name, p, maxlen);
	   }

	   SDL_stack_free(buffer);
   }