test/checkkeys.c
changeset 1895 c121d94672cb
parent 1253 7c7ddaf195bf
child 2295 dbc6d1893869
     1.1 --- a/test/checkkeys.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/test/checkkeys.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -11,136 +11,140 @@
     1.4  #include "SDL.h"
     1.5  
     1.6  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.7 -static void quit(int rc)
     1.8 +static void
     1.9 +quit(int rc)
    1.10  {
    1.11 -	SDL_Quit();
    1.12 -	exit(rc);
    1.13 +    SDL_Quit();
    1.14 +    exit(rc);
    1.15  }
    1.16  
    1.17 -static void print_modifiers(void)
    1.18 +static void
    1.19 +print_modifiers(void)
    1.20  {
    1.21 -	int mod;
    1.22 -	printf(" modifiers:");
    1.23 -	mod = SDL_GetModState();
    1.24 -	if(!mod) {
    1.25 -		printf(" (none)");
    1.26 -		return;
    1.27 -	}
    1.28 -	if(mod & KMOD_LSHIFT)
    1.29 -		printf(" LSHIFT");
    1.30 -	if(mod & KMOD_RSHIFT)
    1.31 -		printf(" RSHIFT");
    1.32 -	if(mod & KMOD_LCTRL)
    1.33 -		printf(" LCTRL");
    1.34 -	if(mod & KMOD_RCTRL)
    1.35 -		printf(" RCTRL");
    1.36 -	if(mod & KMOD_LALT)
    1.37 -		printf(" LALT");
    1.38 -	if(mod & KMOD_RALT)
    1.39 -		printf(" RALT");
    1.40 -	if(mod & KMOD_LMETA)
    1.41 -		printf(" LMETA");
    1.42 -	if(mod & KMOD_RMETA)
    1.43 -		printf(" RMETA");
    1.44 -	if(mod & KMOD_NUM)
    1.45 -		printf(" NUM");
    1.46 -	if(mod & KMOD_CAPS)
    1.47 -		printf(" CAPS");
    1.48 -	if(mod & KMOD_MODE)
    1.49 -		printf(" MODE");
    1.50 +    int mod;
    1.51 +    printf(" modifiers:");
    1.52 +    mod = SDL_GetModState();
    1.53 +    if (!mod) {
    1.54 +        printf(" (none)");
    1.55 +        return;
    1.56 +    }
    1.57 +    if (mod & KMOD_LSHIFT)
    1.58 +        printf(" LSHIFT");
    1.59 +    if (mod & KMOD_RSHIFT)
    1.60 +        printf(" RSHIFT");
    1.61 +    if (mod & KMOD_LCTRL)
    1.62 +        printf(" LCTRL");
    1.63 +    if (mod & KMOD_RCTRL)
    1.64 +        printf(" RCTRL");
    1.65 +    if (mod & KMOD_LALT)
    1.66 +        printf(" LALT");
    1.67 +    if (mod & KMOD_RALT)
    1.68 +        printf(" RALT");
    1.69 +    if (mod & KMOD_LMETA)
    1.70 +        printf(" LMETA");
    1.71 +    if (mod & KMOD_RMETA)
    1.72 +        printf(" RMETA");
    1.73 +    if (mod & KMOD_NUM)
    1.74 +        printf(" NUM");
    1.75 +    if (mod & KMOD_CAPS)
    1.76 +        printf(" CAPS");
    1.77 +    if (mod & KMOD_MODE)
    1.78 +        printf(" MODE");
    1.79  }
    1.80  
    1.81 -static void PrintKey(SDL_keysym *sym, int pressed)
    1.82 +static void
    1.83 +PrintKey(SDL_keysym * sym, int pressed)
    1.84  {
    1.85 -	/* Print the keycode, name and state */
    1.86 -	if ( sym->sym ) {
    1.87 -		printf("Key %s:  %d-%s ", pressed ?  "pressed" : "released",
    1.88 -					sym->sym, SDL_GetKeyName(sym->sym));
    1.89 -	} else {
    1.90 -		printf("Unknown Key (scancode = %d) %s ", sym->scancode,
    1.91 -					pressed ?  "pressed" : "released");
    1.92 -	}
    1.93 +    /* Print the keycode, name and state */
    1.94 +    if (sym->sym) {
    1.95 +        printf("Key %s:  %d-%s ", pressed ? "pressed" : "released",
    1.96 +               sym->sym, SDL_GetKeyName(sym->sym));
    1.97 +    } else {
    1.98 +        printf("Unknown Key (scancode = %d) %s ", sym->scancode,
    1.99 +               pressed ? "pressed" : "released");
   1.100 +    }
   1.101  
   1.102 -	/* Print the translated character, if one exists */
   1.103 -	if ( sym->unicode ) {
   1.104 -		/* Is it a control-character? */
   1.105 -		if ( sym->unicode < ' ' ) {
   1.106 -			printf(" (^%c)", sym->unicode+'@');
   1.107 -		} else {
   1.108 +    /* Print the translated character, if one exists */
   1.109 +    if (sym->unicode) {
   1.110 +        /* Is it a control-character? */
   1.111 +        if (sym->unicode < ' ') {
   1.112 +            printf(" (^%c)", sym->unicode + '@');
   1.113 +        } else {
   1.114  #ifdef UNICODE
   1.115 -			printf(" (%c)", sym->unicode);
   1.116 +            printf(" (%c)", sym->unicode);
   1.117  #else
   1.118 -			/* This is a Latin-1 program, so only show 8-bits */
   1.119 -			if ( !(sym->unicode & 0xFF00) )
   1.120 -				printf(" (%c)", sym->unicode);
   1.121 -			else
   1.122 -				printf(" (0x%X)", sym->unicode);
   1.123 +            /* This is a Latin-1 program, so only show 8-bits */
   1.124 +            if (!(sym->unicode & 0xFF00))
   1.125 +                printf(" (%c)", sym->unicode);
   1.126 +            else
   1.127 +                printf(" (0x%X)", sym->unicode);
   1.128  #endif
   1.129 -		}
   1.130 -	}
   1.131 -	print_modifiers();
   1.132 -	printf("\n");
   1.133 +        }
   1.134 +    }
   1.135 +    print_modifiers();
   1.136 +    printf("\n");
   1.137  }
   1.138  
   1.139 -int main(int argc, char *argv[])
   1.140 +int
   1.141 +main(int argc, char *argv[])
   1.142  {
   1.143 -	SDL_Event event;
   1.144 -	int done;
   1.145 -	Uint32 videoflags;
   1.146 +    SDL_Event event;
   1.147 +    int done;
   1.148 +    Uint32 videoflags;
   1.149  
   1.150 -	/* Initialize SDL */
   1.151 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.152 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   1.153 -		return(1);
   1.154 -	}
   1.155 +    /* Initialize SDL */
   1.156 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.157 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.158 +        return (1);
   1.159 +    }
   1.160  
   1.161 -	videoflags = SDL_SWSURFACE;
   1.162 -	while( argc > 1 ) {
   1.163 -		--argc;
   1.164 -		if ( argv[argc] && !strcmp(argv[argc], "-fullscreen") ) {
   1.165 -			videoflags |= SDL_FULLSCREEN;
   1.166 -		} else {
   1.167 -			fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
   1.168 -			quit(1);
   1.169 -		}
   1.170 -	}
   1.171 +    videoflags = SDL_SWSURFACE;
   1.172 +    while (argc > 1) {
   1.173 +        --argc;
   1.174 +        if (argv[argc] && !strcmp(argv[argc], "-fullscreen")) {
   1.175 +            videoflags |= SDL_FULLSCREEN;
   1.176 +        } else {
   1.177 +            fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
   1.178 +            quit(1);
   1.179 +        }
   1.180 +    }
   1.181  
   1.182 -	/* Set 640x480 video mode */
   1.183 -	if ( SDL_SetVideoMode(640, 480, 0, videoflags) == NULL ) {
   1.184 -		fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
   1.185 -							SDL_GetError());
   1.186 -		quit(2);
   1.187 -	}
   1.188 +    /* Set 640x480 video mode */
   1.189 +    if (SDL_SetVideoMode(640, 480, 0, videoflags) == NULL) {
   1.190 +        fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
   1.191 +                SDL_GetError());
   1.192 +        quit(2);
   1.193 +    }
   1.194  
   1.195 -	/* Enable UNICODE translation for keyboard input */
   1.196 -	SDL_EnableUNICODE(1);
   1.197 +    /* Enable UNICODE translation for keyboard input */
   1.198 +    SDL_EnableUNICODE(1);
   1.199  
   1.200 -	/* Enable auto repeat for keyboard input */
   1.201 -	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
   1.202 -	                    SDL_DEFAULT_REPEAT_INTERVAL);
   1.203 +    /* Enable auto repeat for keyboard input */
   1.204 +    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
   1.205 +                        SDL_DEFAULT_REPEAT_INTERVAL);
   1.206  
   1.207 -	/* Watch keystrokes */
   1.208 -	done = 0;
   1.209 -	while ( !done ) {
   1.210 -		/* Check for events */
   1.211 -		SDL_WaitEvent(&event);
   1.212 -		switch (event.type) {
   1.213 -			case SDL_KEYDOWN:
   1.214 -				PrintKey(&event.key.keysym, 1);
   1.215 -				break;
   1.216 -			case SDL_KEYUP:
   1.217 -				PrintKey(&event.key.keysym, 0);
   1.218 -				break;
   1.219 -			case SDL_MOUSEBUTTONDOWN:
   1.220 -				/* Any button press quits the app... */
   1.221 -			case SDL_QUIT:
   1.222 -				done = 1;
   1.223 -				break;
   1.224 -			default:
   1.225 -				break;
   1.226 -		}
   1.227 -	}
   1.228 +    /* Watch keystrokes */
   1.229 +    done = 0;
   1.230 +    while (!done) {
   1.231 +        /* Check for events */
   1.232 +        SDL_WaitEvent(&event);
   1.233 +        switch (event.type) {
   1.234 +        case SDL_KEYDOWN:
   1.235 +            PrintKey(&event.key.keysym, 1);
   1.236 +            break;
   1.237 +        case SDL_KEYUP:
   1.238 +            PrintKey(&event.key.keysym, 0);
   1.239 +            break;
   1.240 +        case SDL_MOUSEBUTTONDOWN:
   1.241 +            /* Any button press quits the app... */
   1.242 +        case SDL_QUIT:
   1.243 +            done = 1;
   1.244 +            break;
   1.245 +        default:
   1.246 +            break;
   1.247 +        }
   1.248 +    }
   1.249  
   1.250 -	SDL_Quit();
   1.251 -	return(0);
   1.252 +    SDL_Quit();
   1.253 +    return (0);
   1.254  }