Indent switch blocks content
For readability, indent "case" in switch blocks. Replace: switch (x) { case 1: // ... case 2: // ... case 3: { // a local scope block int i = 42; // ... } } By: switch (x) { case 1: // ... case 2: // ... case 3: { // a local scope block int i = 42; // ... } }
This commit is contained in:
parent
628f88ab89
commit
60b2f2ca64
3 changed files with 95 additions and 95 deletions
|
@ -27,34 +27,34 @@ static void write_position(Uint8 *buf, const struct position *position) {
|
|||
int control_event_serialize(const struct control_event *event, unsigned char *buf) {
|
||||
buf[0] = event->type;
|
||||
switch (event->type) {
|
||||
case CONTROL_EVENT_TYPE_KEYCODE:
|
||||
buf[1] = event->keycode_event.action;
|
||||
write32(&buf[2], event->keycode_event.keycode);
|
||||
write32(&buf[6], event->keycode_event.metastate);
|
||||
return 10;
|
||||
case CONTROL_EVENT_TYPE_TEXT: {
|
||||
// write length (1 byte) + date (non nul-terminated)
|
||||
size_t len = strlen(event->text_event.text);
|
||||
if (len > TEXT_MAX_LENGTH) {
|
||||
len = TEXT_MAX_LENGTH;
|
||||
case CONTROL_EVENT_TYPE_KEYCODE:
|
||||
buf[1] = event->keycode_event.action;
|
||||
write32(&buf[2], event->keycode_event.keycode);
|
||||
write32(&buf[6], event->keycode_event.metastate);
|
||||
return 10;
|
||||
case CONTROL_EVENT_TYPE_TEXT: {
|
||||
// write length (1 byte) + date (non nul-terminated)
|
||||
size_t len = strlen(event->text_event.text);
|
||||
if (len > TEXT_MAX_LENGTH) {
|
||||
len = TEXT_MAX_LENGTH;
|
||||
}
|
||||
buf[1] = (Uint8) len;
|
||||
memcpy(&buf[2], &event->text_event.text, len);
|
||||
return 2 + len;
|
||||
}
|
||||
buf[1] = (Uint8) len;
|
||||
memcpy(&buf[2], &event->text_event.text, len);
|
||||
return 2 + len;
|
||||
}
|
||||
case CONTROL_EVENT_TYPE_MOUSE:
|
||||
buf[1] = event->mouse_event.action;
|
||||
write32(&buf[2], event->mouse_event.buttons);
|
||||
write_position(&buf[6], &event->mouse_event.position);
|
||||
return 14;
|
||||
case CONTROL_EVENT_TYPE_SCROLL:
|
||||
write_position(&buf[1], &event->scroll_event.position);
|
||||
write32(&buf[9], (Uint32) event->scroll_event.hscroll);
|
||||
write32(&buf[13], (Uint32) event->scroll_event.vscroll);
|
||||
return 17;
|
||||
default:
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u\n", (unsigned) event->type);
|
||||
return 0;
|
||||
case CONTROL_EVENT_TYPE_MOUSE:
|
||||
buf[1] = event->mouse_event.action;
|
||||
write32(&buf[2], event->mouse_event.buttons);
|
||||
write_position(&buf[6], &event->mouse_event.position);
|
||||
return 14;
|
||||
case CONTROL_EVENT_TYPE_SCROLL:
|
||||
write_position(&buf[1], &event->scroll_event.position);
|
||||
write32(&buf[9], (Uint32) event->scroll_event.hscroll);
|
||||
write32(&buf[13], (Uint32) event->scroll_event.vscroll);
|
||||
return 17;
|
||||
default:
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u\n", (unsigned) event->type);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,37 +16,37 @@ int parse_args(struct args *args, int argc, char *argv[]) {
|
|||
int c;
|
||||
while ((c = getopt(argc, argv, "p:m:")) != -1) {
|
||||
switch (c) {
|
||||
case 'p': {
|
||||
char *endptr;
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg);
|
||||
return -1;
|
||||
case 'p': {
|
||||
char *endptr;
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld\n", value);
|
||||
return -1;
|
||||
}
|
||||
args->port = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld\n", value);
|
||||
return -1;
|
||||
case 'm': {
|
||||
char *endptr;
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid maximum size: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Maximum size must be between 0 and 65535: %ld\n", value);
|
||||
return -1;
|
||||
}
|
||||
args->maximum_size = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
args->port = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
case 'm': {
|
||||
char *endptr;
|
||||
long value = strtol(optarg, &endptr, 0);
|
||||
if (*optarg == '\0' || *endptr != '\0') {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid maximum size: %s\n", optarg);
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return -1;
|
||||
}
|
||||
if (value & ~0xffff) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Maximum size must be between 0 and 65535: %ld\n", value);
|
||||
return -1;
|
||||
}
|
||||
args->maximum_size = (Uint16) value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// getopt prints the error message on stderr
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -335,49 +335,49 @@ void event_loop(void) {
|
|||
SDL_Event event;
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case EVENT_DECODER_STOPPED:
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped");
|
||||
case SDL_QUIT:
|
||||
return;
|
||||
case EVENT_NEW_FRAME:
|
||||
if (!handle_new_frame()) {
|
||||
case EVENT_DECODER_STOPPED:
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped");
|
||||
case SDL_QUIT:
|
||||
return;
|
||||
}
|
||||
texture_empty = SDL_FALSE;
|
||||
count_frame(); // display fps for debug
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
render(renderer, texture_empty ? NULL : texture);
|
||||
case EVENT_NEW_FRAME:
|
||||
if (!handle_new_frame()) {
|
||||
return;
|
||||
}
|
||||
texture_empty = SDL_FALSE;
|
||||
count_frame(); // display fps for debug
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
render(renderer, texture_empty ? NULL : texture);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT: {
|
||||
handle_text_input(&event.text);
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
handle_key(&event.key);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
handle_mouse_motion(&event.motion, frame_size);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL: {
|
||||
struct position position = {
|
||||
.screen_size = frame_size,
|
||||
.point = get_mouse_point(),
|
||||
};
|
||||
handle_mouse_wheel(&event.wheel, position);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
handle_mouse_button(&event.button, frame_size);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTINPUT: {
|
||||
handle_text_input(&event.text);
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
handle_key(&event.key);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
handle_mouse_motion(&event.motion, frame_size);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL: {
|
||||
struct position position = {
|
||||
.screen_size = frame_size,
|
||||
.point = get_mouse_point(),
|
||||
};
|
||||
handle_mouse_wheel(&event.wheel, position);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
handle_mouse_button(&event.button, frame_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue