示例#1
0
/*
 * grab the name string from a mapping string
 */
char *SDL_PrivateGetControllerNameFromMappingString(const char *pMapping)
{
    const char *pFirstComma, *pSecondComma;
    char *pchName;

    pFirstComma = SDL_strchr(pMapping, ',');
    if (!pFirstComma)
        return NULL;

    pSecondComma = SDL_strchr(pFirstComma + 1, ',');
    if (!pSecondComma)
        return NULL;

    pchName = SDL_malloc(pSecondComma - pFirstComma);
    if (!pchName) {
        SDL_OutOfMemory();
        return NULL;
    }
    SDL_memcpy(pchName, pFirstComma + 1, pSecondComma - pFirstComma);
    pchName[ pSecondComma - pFirstComma - 1 ] = 0;
    return pchName;
}
示例#2
0
/*
 * grab the guid string from a mapping string
 */
char *SDL_PrivateGetControllerGUIDFromMappingString(const char *pMapping)
{
    const char *pFirstComma = SDL_strchr(pMapping, ',');
    if (pFirstComma) {
        char *pchGUID = SDL_malloc(pFirstComma - pMapping + 1);
        if (!pchGUID) {
            SDL_OutOfMemory();
            return NULL;
        }
        SDL_memcpy(pchGUID, pMapping, pFirstComma - pMapping);
        pchGUID[ pFirstComma - pMapping ] = 0;
        return pchGUID;
    }
    return NULL;
}
示例#3
0
/*
 * translate unix-style slash-separated filename to mac-style colon-separated
 * name; return malloced string
 */
static char *unix_to_mac(const char *file)
{
    int flen = SDL_strlen(file);
    char *path = SDL_malloc(flen + 2);
    const char *src = file;
    char *dst = path;
    if(*src == '/') {
        /* really depends on filesystem layout, hope for the best */
        src++;
    } else {
        /* Check if this is a MacOS path to begin with */
        if(*src != ':')
            *dst++ = ':';   /* relative paths begin with ':' */
    }
    while(src < file + flen) {
        const char *end = SDL_strchr(src, '/');
        int len;
        if(!end)
            end = file + flen; /* last component */
        len = end - src;
        if(len == 0 || (len == 1 && src[0] == '.')) {
            /* remove repeated slashes and . */
        } else {
            if(len == 2 && src[0] == '.' && src[1] == '.') {
                /* replace .. with the empty string */
            } else {
                SDL_memcpy(dst, src, len);
                dst += len;
            }
            if(end < file + flen)
                *dst++ = ':';
        }
        src = end + 1;
    }
    *dst++ = '\0';
    return path;
}
static int glXExtensionSupported(_THIS, const char *extension)
{
	const char *extensions;
	const char *start;
	const char *where, *terminator;

	/* Extension names should not have spaces. */
	where = SDL_strchr(extension, ' ');
	if ( where || *extension == '\0' ) {
	      return 0;
	}

	extensions = this->gl_data->glXQueryExtensionsString(GFX_Display,SDL_Screen);
	/* It takes a bit of care to be fool-proof about parsing the
	 * OpenGL extensions string. Don't be fooled by sub-strings, etc.
	 */

	/* http://bugs.debian.org/537487 */
	if (extensions == NULL) {
	      return 0;
	}
	
	start = extensions;
	
	for (;;) {
		where = SDL_strstr(start, extension);
		if (!where) break;
		
		terminator = where + strlen(extension);
		if (where == start || *(where - 1) == ' ')
	        if (*terminator == ' ' || *terminator == '\0') return 1;
						  
		start = terminator;
	}
	return 0;
}
示例#5
0
static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
{
#ifndef _WIN32_WCE
    UINT	old_error_mode;
#endif
    HANDLE	h;
    DWORD	r_right, w_right;
    DWORD	must_exist, truncate;
    int		a_mode;

    if (!context)
        return -1; /* failed (invalid call) */

    context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
    context->hidden.win32io.buffer.data = NULL;
    context->hidden.win32io.buffer.size = 0;
    context->hidden.win32io.buffer.left = 0;

    /* "r" = reading, file must exist */
    /* "w" = writing, truncate existing, file may not exist */
    /* "r+"= reading or writing, file must exist            */
    /* "a" = writing, append file may not exist             */
    /* "a+"= append + read, file may not exist              */
    /* "w+" = read, write, truncate. file may not exist    */

    must_exist = ( SDL_strchr(mode,'r') != NULL ) ? OPEN_EXISTING : 0;
    truncate   = ( SDL_strchr(mode,'w') != NULL ) ? CREATE_ALWAYS : 0;
    r_right    = ( SDL_strchr(mode,'+') != NULL || must_exist ) ? GENERIC_READ : 0;
    a_mode     = ( SDL_strchr(mode,'a') != NULL ) ? OPEN_ALWAYS : 0;
    w_right    = ( a_mode || SDL_strchr(mode,'+') || truncate ) ? GENERIC_WRITE : 0;

    if (!r_right && !w_right) /* inconsistent mode */
        return -1; /* failed (invalid call) */

    context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
    if (!context->hidden.win32io.buffer.data) {
        SDL_OutOfMemory();
        return -1;
    }

#ifdef _WIN32_WCE
    {
        size_t size = SDL_strlen(filename)+1;
        wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);

        if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
            SDL_stack_free(filenameW);
            SDL_free(context->hidden.win32io.buffer.data);
            context->hidden.win32io.buffer.data = NULL;
            SDL_SetError("Unable to convert filename to Unicode");
            return -1;
        }
        h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
                       NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);
        SDL_stack_free(filenameW);
    }
#else
    /* Do not open a dialog box if failure */
    old_error_mode = SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS);

    h = CreateFile(filename, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
                   NULL, (must_exist|truncate|a_mode), FILE_ATTRIBUTE_NORMAL,NULL);

    /* restore old behaviour */
    SetErrorMode(old_error_mode);
#endif /* _WIN32_WCE */

    if (h==INVALID_HANDLE_VALUE) {
        SDL_free(context->hidden.win32io.buffer.data);
        context->hidden.win32io.buffer.data = NULL;
        SDL_SetError("Couldn't open %s",filename);
        return -2; /* failed (CreateFile) */
    }
    context->hidden.win32io.h = h;
    context->hidden.win32io.append = a_mode;

    return 0; /* ok */
}
示例#6
0
/* Calculate and initialize text and button locations. */
static int
X11_MessageBoxInitPositions( SDL_MessageBoxDataX11 *data )
{
    int i;
    int ybuttons;
    int text_width_max = 0;
    int button_text_height = 0;
    int button_width = MIN_BUTTON_WIDTH;
    const SDL_MessageBoxData *messageboxdata = data->messageboxdata;

    /* Go over text and break linefeeds into separate lines. */
    if ( messageboxdata->message && messageboxdata->message[ 0 ] ) {
        const char *text = messageboxdata->message;
        TextLineData *plinedata = data->linedata;

        for ( i = 0; i < MAX_TEXT_LINES; i++, plinedata++ ) {
            int height;
            char *lf = SDL_strchr( ( char * )text, '\n' );

            data->numlines++;

            /* Only grab length up to lf if it exists and isn't the last line. */
            plinedata->length = ( lf && ( i < MAX_TEXT_LINES - 1 ) ) ? ( lf - text ) : SDL_strlen( text );
            plinedata->text = text;

            GetTextWidthHeight( data, text, plinedata->length, &plinedata->width, &height );

            /* Text and widths are the largest we've ever seen. */
            data->text_height = IntMax( data->text_height, height );
            text_width_max = IntMax( text_width_max, plinedata->width );

            if (lf && (lf > text) && (lf[-1] == '\r')) {
                plinedata->length--;
            }

            text += plinedata->length + 1;

            /* Break if there are no more linefeeds. */
            if ( !lf )
                break;
        }

        /* Bump up the text height slightly. */
        data->text_height += 2;
    }

    /* Loop through all buttons and calculate the button widths and height. */
    for ( i = 0; i < data->numbuttons; i++ ) {
        int height;

        data->buttonpos[ i ].buttondata = &data->buttondata[ i ];
        data->buttonpos[ i ].length = SDL_strlen( data->buttondata[ i ].text );

        GetTextWidthHeight( data, data->buttondata[ i ].text, SDL_strlen( data->buttondata[ i ].text ),
                            &data->buttonpos[ i ].text_width, &height );

        button_width = IntMax( button_width, data->buttonpos[ i ].text_width );
        button_text_height = IntMax( button_text_height, height );
    }

    if ( data->numlines ) {
        /* x,y for this line of text. */
        data->xtext = data->text_height;
        data->ytext = data->text_height + data->text_height;

        /* Bump button y down to bottom of text. */
        ybuttons = 3 * data->ytext / 2 + ( data->numlines - 1 ) * data->text_height;

        /* Bump the dialog box width and height up if needed. */
        data->dialog_width = IntMax( data->dialog_width, 2 * data->xtext + text_width_max );
        data->dialog_height = IntMax( data->dialog_height, ybuttons );
    } else {
        /* Button y starts at height of button text. */
        ybuttons = button_text_height;
    }

    if ( data->numbuttons ) {
        int x, y;
        int width_of_buttons;
        int button_spacing = button_text_height;
        int button_height = 2 * button_text_height;

        /* Bump button width up a bit. */
        button_width += button_text_height;

        /* Get width of all buttons lined up. */
        width_of_buttons = data->numbuttons * button_width + ( data->numbuttons - 1 ) * button_spacing;

        /* Bump up dialog width and height if buttons are wider than text. */
        data->dialog_width = IntMax( data->dialog_width, width_of_buttons + 2 * button_spacing );
        data->dialog_height = IntMax( data->dialog_height, ybuttons + 2 * button_height );

        /* Location for first button. */
        x = ( data->dialog_width - width_of_buttons ) / 2;
        y = ybuttons + ( data->dialog_height - ybuttons - button_height ) / 2;

        for ( i = 0; i < data->numbuttons; i++ ) {
            /* Button coordinates. */
            data->buttonpos[ i ].rect.x = x;
            data->buttonpos[ i ].rect.y = y;
            data->buttonpos[ i ].rect.w = button_width;
            data->buttonpos[ i ].rect.h = button_height;

            /* Button text coordinates. */
            data->buttonpos[ i ].x = x + ( button_width - data->buttonpos[ i ].text_width ) / 2;
            data->buttonpos[ i ].y = y + ( button_height - button_text_height - 1 ) / 2 + button_text_height;

            /* Scoot over for next button. */
            x += button_width + button_spacing;
        }
    }

    return 0;
}
示例#7
0
static void CheckMounts(const char *mtab)
{
	FILE *mntfp;
	struct mntent *mntent;
	struct stat stbuf;

	mntfp = setmntent(mtab, "r");
	if ( mntfp != NULL ) {
		char *tmp;
		char *mnt_type;
		size_t mnt_type_len;
		char *mnt_dev;
		size_t mnt_dev_len;

		while ( (mntent=getmntent(mntfp)) != NULL ) {
			mnt_type_len = SDL_strlen(mntent->mnt_type) + 1;
			mnt_type = SDL_stack_alloc(char, mnt_type_len);
			if (mnt_type == NULL)
				continue;  /* maybe you'll get lucky next time. */

			mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1;
			mnt_dev = SDL_stack_alloc(char, mnt_dev_len);
			if (mnt_dev == NULL) {
				SDL_stack_free(mnt_type);
				continue;
			}

			SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len);
			SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len);

			/* Handle "supermount" filesystem mounts */
			if ( SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) {
				tmp = SDL_strstr(mntent->mnt_opts, "fs=");
				if ( tmp ) {
					SDL_stack_free(mnt_type);
					mnt_type = SDL_strdup(tmp + SDL_strlen("fs="));
					if ( mnt_type ) {
						tmp = SDL_strchr(mnt_type, ',');
						if ( tmp ) {
							*tmp = '\0';
						}
					}
				}
				tmp = SDL_strstr(mntent->mnt_opts, "dev=");
				if ( tmp ) {
					SDL_stack_free(mnt_dev);
					mnt_dev = SDL_strdup(tmp + SDL_strlen("dev="));
					if ( mnt_dev ) {
						tmp = SDL_strchr(mnt_dev, ',');
						if ( tmp ) {
							*tmp = '\0';
						}
					}
				}
			}
			if ( SDL_strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) {
#ifdef DEBUG_CDROM
  fprintf(stderr, "Checking mount path from %s: %s mounted on %s of %s\n",
	mtab, mnt_dev, mntent->mnt_dir, mnt_type);
#endif
				if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) {
					AddDrive(mnt_dev, &stbuf);
				}
			}
			SDL_stack_free(mnt_dev);
			SDL_stack_free(mnt_type);
		}
		endmntent(mntfp);
	}
示例#8
0
/*
 * Add or update an entry into the Mappings Database
 */
int
SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw)
{
    const char *platform = SDL_GetPlatform();
    int controllers = 0;
    char *buf, *line, *line_end, *tmp, *comma, line_platform[64];
    size_t db_size, platform_len;

    if (rw == NULL) {
        return SDL_SetError("Invalid RWops");
    }
    db_size = (size_t)SDL_RWsize(rw);

    buf = (char *)SDL_malloc(db_size + 1);
    if (buf == NULL) {
        if (freerw) {
            SDL_RWclose(rw);
        }
        return SDL_SetError("Could allocate space to not read DB into memory");
    }

    if (SDL_RWread(rw, buf, db_size, 1) != 1) {
        if (freerw) {
            SDL_RWclose(rw);
        }
        SDL_free(buf);
        return SDL_SetError("Could not read DB");
    }

    if (freerw) {
        SDL_RWclose(rw);
    }

    buf[db_size] = '\0';
    line = buf;

    while (line < buf + db_size) {
        line_end = SDL_strchr(line, '\n');
        if (line_end != NULL) {
            *line_end = '\0';
        } else {
            line_end = buf + db_size;
        }

        /* Extract and verify the platform */
        tmp = SDL_strstr(line, SDL_CONTROLLER_PLATFORM_FIELD);
        if (tmp != NULL) {
            tmp += SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD);
            comma = SDL_strchr(tmp, ',');
            if (comma != NULL) {
                platform_len = comma - tmp + 1;
                if (platform_len + 1 < SDL_arraysize(line_platform)) {
                    SDL_strlcpy(line_platform, tmp, platform_len);
                    if (SDL_strncasecmp(line_platform, platform, platform_len) == 0 &&
                        SDL_GameControllerAddMapping(line) > 0) {
                        controllers++;
                    }
                }
            }
        }

        line = line_end + 1;
    }

    SDL_free(buf);
    return controllers;
}
示例#9
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);
   }
示例#10
0
static int SDLCALL
windows_file_open(SDL_RWops * context, const char *filename, const char *mode)
{
    UINT old_error_mode;
    HANDLE h;
    DWORD r_right, w_right;
    DWORD must_exist, truncate;
    int a_mode;

    if (!context)
        return -1;              /* failed (invalid call) */

    context->hidden.windowsio.h = INVALID_HANDLE_VALUE;   /* mark this as unusable */
    context->hidden.windowsio.buffer.data = NULL;
    context->hidden.windowsio.buffer.size = 0;
    context->hidden.windowsio.buffer.left = 0;

    /* "r" = reading, file must exist */
    /* "w" = writing, truncate existing, file may not exist */
    /* "r+"= reading or writing, file must exist            */
    /* "a" = writing, append file may not exist             */
    /* "a+"= append + read, file may not exist              */
    /* "w+" = read, write, truncate. file may not exist    */

    must_exist = (SDL_strchr(mode, 'r') != NULL) ? OPEN_EXISTING : 0;
    truncate = (SDL_strchr(mode, 'w') != NULL) ? CREATE_ALWAYS : 0;
    r_right = (SDL_strchr(mode, '+') != NULL
               || must_exist) ? GENERIC_READ : 0;
    a_mode = (SDL_strchr(mode, 'a') != NULL) ? OPEN_ALWAYS : 0;
    w_right = (a_mode || SDL_strchr(mode, '+')
               || truncate) ? GENERIC_WRITE : 0;

    if (!r_right && !w_right)   /* inconsistent mode */
        return -1;              /* failed (invalid call) */

    context->hidden.windowsio.buffer.data =
        (char *) SDL_malloc(READAHEAD_BUFFER_SIZE);
    if (!context->hidden.windowsio.buffer.data) {
        SDL_OutOfMemory();
        return -1;
    }
    /* Do not open a dialog box if failure */
    old_error_mode =
        SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);

    {
        LPTSTR tstr = WIN_UTF8ToString(filename);
        h = CreateFile(tstr, (w_right | r_right),
                       (w_right) ? 0 : FILE_SHARE_READ, NULL,
                       (must_exist | truncate | a_mode),
                       FILE_ATTRIBUTE_NORMAL, NULL);
        SDL_free(tstr);
    }

    /* restore old behavior */
    SetErrorMode(old_error_mode);

    if (h == INVALID_HANDLE_VALUE) {
        SDL_free(context->hidden.windowsio.buffer.data);
        context->hidden.windowsio.buffer.data = NULL;
        SDL_SetError("Couldn't open %s", filename);
        return -2;              /* failed (CreateFile) */
    }
    context->hidden.windowsio.h = h;
    context->hidden.windowsio.append = a_mode ? SDL_TRUE : SDL_FALSE;

    return 0;                   /* ok */
}
示例#11
0
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);
   }
示例#12
0
/* Function to scan the system for joysticks */
int SDL_SYS_JoystickInit(void)
{
	/* The base path of the joystick devices */
	const char *joydev_pattern[] = {
#if SDL_INPUT_LINUXEV
		"/dev/input/event%d",
#endif
		"/dev/input/js%d",
		"/dev/js%d"
	};
	int numjoysticks;
	int i, j;
	int fd;
	char path[PATH_MAX];
	dev_t dev_nums[MAX_JOYSTICKS];  /* major/minor device numbers */
	struct stat sb;
	int n, duplicate;

	numjoysticks = 0;

	/* First see if the user specified one or more joysticks to use */
	if ( SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL ) {
		char *envcopy, *envpath, *delim;
		envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE"));
		envpath = envcopy;
		while ( envpath != NULL ) {
			delim = SDL_strchr(envpath, ':');
			if ( delim != NULL ) {
				*delim++ = '\0';
			}
			if ( stat(envpath, &sb) == 0 ) {
				fd = open(envpath, O_RDONLY, 0);
				if ( fd >= 0 ) {
					/* Assume the user knows what they're doing. */
					SDL_joylist[numjoysticks].fname = SDL_strdup(envpath);
					if ( SDL_joylist[numjoysticks].fname ) {
						dev_nums[numjoysticks] = sb.st_rdev;
						++numjoysticks;
					}
					close(fd);
				}
			}
			envpath = delim;
		}
		SDL_free(envcopy);
	}

	for ( i=0; i<SDL_arraysize(joydev_pattern); ++i ) {
		for ( j=0; j < MAX_JOYSTICKS; ++j ) {
			SDL_snprintf(path, SDL_arraysize(path), joydev_pattern[i], j);

			/* rcg06302000 replaced access(F_OK) call with stat().
			 * stat() will fail if the file doesn't exist, so it's
			 * equivalent behaviour.
			 */
			if ( stat(path, &sb) == 0 ) {
				/* Check to make sure it's not already in list.
				 * This happens when we see a stick via symlink.
				 */
				duplicate = 0;
				for (n=0; (n<numjoysticks) && !duplicate; ++n) {
					if ( sb.st_rdev == dev_nums[n] ) {
						duplicate = 1;
					}
				}
				if (duplicate) {
					continue;
				}

				fd = open(path, O_RDONLY, 0);
				if ( fd < 0 ) {
					continue;
				}
#if SDL_INPUT_LINUXEV
#ifdef DEBUG_INPUT_EVENTS
				printf("Checking %s\n", path);
#endif
				if ( (i == 0) && ! EV_IsJoystick(fd) ) {
					close(fd);
					continue;
				}
#endif
				close(fd);

				/* We're fine, add this joystick */
				SDL_joylist[numjoysticks].fname = SDL_strdup(path);
				if ( SDL_joylist[numjoysticks].fname ) {
					dev_nums[numjoysticks] = sb.st_rdev;
					++numjoysticks;
				}
			}
		}

#if SDL_INPUT_LINUXEV
		/* This is a special case...
		   If the event devices are valid then the joystick devices
		   will be duplicates but without extra information about their
		   hats or balls. Unfortunately, the event devices can't
		   currently be calibrated, so it's a win-lose situation.
		   So : /dev/input/eventX = /dev/input/jsY = /dev/jsY
		*/
		if ( (i == 0) && (numjoysticks > 0) )
			break;
#endif
	}
#ifndef NO_LOGICAL_JOYSTICKS
	numjoysticks += CountLogicalJoysticks(numjoysticks);
#endif

	return(numjoysticks);
}
示例#13
0
int SDL_SYS_CDInit(void)
{
    /* checklist: /dev/cdrom, /dev/cd?, /dev/scd? */
    static char *checklist[]={"cdrom", "?0 cd?", "?1 cd?", "?0 scd?", NULL};

    char *SDLcdrom;
    int i, j, exists;
    char drive[32];
    struct stat stbuf;

    /* Fill in our driver capabilities */
    SDL_CDcaps.Name = SDL_SYS_CDName;
    SDL_CDcaps.Open = SDL_SYS_CDOpen;
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
    SDL_CDcaps.Play = SDL_SYS_CDPlay;
    SDL_CDcaps.Pause = SDL_SYS_CDPause;
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
    SDL_CDcaps.Stop = SDL_SYS_CDStop;
    SDL_CDcaps.Eject = SDL_SYS_CDEject;
    SDL_CDcaps.Close = SDL_SYS_CDClose;

    /* clearing device open status */
    for (i=0; i<MAX_DRIVES; i++)
    {
       SDL_cdopen[i]=0;
    }

    /* Look in the environment for our CD-ROM drive list */
    SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
    if ( SDLcdrom != NULL )
    {
        char *cdpath, *delim;
	size_t len = SDL_strlen(SDLcdrom)+1;
        cdpath = SDL_stack_alloc(char, len);
        if (cdpath != NULL)
        {
            SDL_strlcpy(cdpath, SDLcdrom, len);
            SDLcdrom = cdpath;
            do {
                delim = SDL_strchr(SDLcdrom, ':');
                if (delim)
                {
                    *delim++ = '\0';
                }
                if (CheckDrive(SDLcdrom, &stbuf) > 0)
                {
                    AddDrive(SDLcdrom, &stbuf);
                }
                if (delim)
                {
                    SDLcdrom = delim;
                }
                else
                {
                    SDLcdrom = NULL;
                }
            } while (SDLcdrom);
            SDL_stack_free(cdpath);
        }

        /* If we found our drives, there's nothing left to do */
        if (SDL_numcds > 0)
        {
            return(0);
        }
    }
示例#14
0
SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
{
	SDL_RWops *rwops = NULL;
	
#if defined(__DREAMCAST__)
	file_t fd;
	int dc_mode = 0;
#elif defined(_HAVE_STDIO_H)
//#ifdef HAVE_STDIO_H
	FILE *fp = NULL;
#endif
	if ( !file || !*file || !mode || !*mode ) {
		SDL_SetError("SDL_RWFromFile(): No file or no mode specified");
		return NULL;
	}

#if defined(__WIN32__) && !defined(__SYMBIAN32__)
	rwops = SDL_AllocRW();
	if (!rwops)
		return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
	if (win32_file_open(rwops,file,mode) < 0) {
		SDL_FreeRW(rwops);
		return NULL;
	}	
	rwops->seek  = win32_file_seek;
	rwops->read  = win32_file_read;
	rwops->write = win32_file_write;
	rwops->close = win32_file_close;

#elif defined(HAVE_STDIO_H)

#ifdef __DREAMCAST__

	if(SDL_strchr(mode,'r') != NULL) {
		dc_mode = O_RDONLY;
	}
	
	if(SDL_strchr(mode,'w') != NULL) {
		if(dc_mode & O_RDONLY) {
			dc_mode &= ~O_RDONLY;
			dc_mode = (O_RDWR | O_CREAT | O_TRUNC);
		} else {
			dc_mode = (O_WRONLY | O_CREAT | O_TRUNC);
		}
	}
	
	if(SDL_strchr(mode,'a') != NULL) {
		if(!(dc_mode & O_RDONLY))
			dc_mode |= (O_WRONLY | O_APPEND);
	}
	
	if(SDL_strchr(mode,'+') != NULL) {
		if((dc_mode & O_WRONLY) || (dc_mode & O_RDWR)) {
			dc_mode &= ~(O_CREAT | O_TRUNC);
		} else {
			dc_mode |= O_RDONLY;
		}
	}
	
	fd = fs_open(file, dc_mode);

	if ( fd == FILEHND_INVALID ) {
		SDL_SetError("Couldn't open %s", file);
	} else {
		rwops = SDL_RWFromFD(fd, 1);
	}
	
#else

#ifdef __MACOS__
	{
		char *mpath = unix_to_mac(file);
		fp = fopen(mpath, mode);
		SDL_free(mpath);
	}
#else
	fp = fopen(file, mode);
#endif
	if ( fp == NULL ) {
		SDL_SetError("Couldn't open %s", file);
	} else {
		rwops = SDL_RWFromFP(fp, 1);
	}
	
#endif /* __DREAMCAST__ */

#else
	SDL_SetError("SDL not compiled with stdio support");
#endif /* !HAVE_STDIO_H */

	return(rwops);
}
示例#15
0
int
SDL_SYS_CDInit(void)
{
    /* checklist:
     *
     * Tru64 5.X (/dev/rdisk/cdrom?c)
     * dir: /dev/rdisk, name: cdrom
     *
     * Digital UNIX 4.0X (/dev/rrz?c)
     * dir: /dev, name: rrz
     *
     */
    struct
    {
        char *dir;
        char *name;
    } checklist[] = {
        {
        "/dev/rdisk", "cdrom"}, {
        "/dev", "rrz"}, {
    NULL, NULL}};
    char drive[32];
    char *SDLcdrom;
    int i, j, exists;
    struct stat stbuf;

    /* Fill in our driver capabilities */
    SDL_CDcaps.Name = SDL_SYS_CDName;
    SDL_CDcaps.Open = SDL_SYS_CDOpen;
    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
    SDL_CDcaps.Status = SDL_SYS_CDStatus;
    SDL_CDcaps.Play = SDL_SYS_CDPlay;
    SDL_CDcaps.Pause = SDL_SYS_CDPause;
    SDL_CDcaps.Resume = SDL_SYS_CDResume;
    SDL_CDcaps.Stop = SDL_SYS_CDStop;
    SDL_CDcaps.Eject = SDL_SYS_CDEject;
    SDL_CDcaps.Close = SDL_SYS_CDClose;


    /* Look in the environment for our CD-ROM drive list */
    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
    if (SDLcdrom != NULL) {
        char *cdpath, *delim;
        size_t len = SDL_strlen(SDLcdrom) + 1;
        cdpath = SDL_stack_alloc(char, len);
        if (cdpath != NULL) {
            SDL_strlcpy(cdpath, SDLcdrom, len);
            SDLcdrom = cdpath;
            do {
                delim = SDL_strchr(SDLcdrom, ':');
                if (delim) {
                    *delim++ = '\0';
                }
                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
                    AddDrive(SDLcdrom, &stbuf);
                }
                if (delim) {
                    SDLcdrom = delim;
                } else {
                    SDLcdrom = NULL;
                }
            } while (SDLcdrom);
            SDL_stack_free(cdpath);
        }

        /* If we found our drives, there's nothing left to do */
        if (SDL_numcds > 0) {
            return (0);
        }
    }
示例#16
0
static SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext)
{
    size_t ext_len;
    const char *ext_override;
    const char *egl_extstr;
    const char *ext_start;

    /* Invalid extensions can be rejected early */
    if (ext == NULL || *ext == 0 || SDL_strchr(ext, ' ') != NULL) {
        /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid EGL extension"); */
        return SDL_FALSE;
    }

    /* Extensions can be masked with an environment variable.
     * Unlike the OpenGL override, this will use the set bits of an integer
     * to disable the extension.
     *  Bit   Action
     *  0     If set, the display extension is masked and not present to SDL.
     *  1     If set, the client extension is masked and not present to SDL.
     */
    ext_override = SDL_getenv(ext);
    if (ext_override != NULL) {
        int disable_ext = SDL_atoi(ext_override);
        if (disable_ext & 0x01 && type == SDL_EGL_DISPLAY_EXTENSION) {
            return SDL_FALSE;
        } else if (disable_ext & 0x02 && type == SDL_EGL_CLIENT_EXTENSION) {
            return SDL_FALSE;
        }
    }

    ext_len = SDL_strlen(ext);
    switch (type) {
    case SDL_EGL_DISPLAY_EXTENSION:
        egl_extstr = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
        break;
    case SDL_EGL_CLIENT_EXTENSION:
        /* EGL_EXT_client_extensions modifies eglQueryString to return client extensions
         * if EGL_NO_DISPLAY is passed. Implementations without it are required to return NULL.
         * This behavior is included in EGL 1.5.
         */
        egl_extstr = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
        break;
    default:
        /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid extension type"); */
        return SDL_FALSE;
    }

    if (egl_extstr != NULL) {
        ext_start = egl_extstr;

        while (*ext_start) {
            ext_start = SDL_strstr(ext_start, ext);
            if (ext_start == NULL) {
                return SDL_FALSE;
            }
            /* Check if the match is not just a substring of one of the extensions */
            if (ext_start == egl_extstr || *(ext_start - 1) == ' ') {
                if (ext_start[ext_len] == ' ' || ext_start[ext_len] == 0) {
                    return SDL_TRUE;
                }
            }
            /* If the search stopped in the middle of an extension, skip to the end of it */
            ext_start += ext_len;
            while (*ext_start != ' ' && *ext_start != 0) {
                ext_start++;
            }
        }
    }

    return SDL_FALSE;
}