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:
Romain Vimont 2018-02-01 11:34:49 +01:00
parent 628f88ab89
commit 60b2f2ca64
3 changed files with 95 additions and 95 deletions

View file

@ -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) { int control_event_serialize(const struct control_event *event, unsigned char *buf) {
buf[0] = event->type; buf[0] = event->type;
switch (event->type) { switch (event->type) {
case CONTROL_EVENT_TYPE_KEYCODE: case CONTROL_EVENT_TYPE_KEYCODE:
buf[1] = event->keycode_event.action; buf[1] = event->keycode_event.action;
write32(&buf[2], event->keycode_event.keycode); write32(&buf[2], event->keycode_event.keycode);
write32(&buf[6], event->keycode_event.metastate); write32(&buf[6], event->keycode_event.metastate);
return 10; return 10;
case CONTROL_EVENT_TYPE_TEXT: { case CONTROL_EVENT_TYPE_TEXT: {
// write length (1 byte) + date (non nul-terminated) // write length (1 byte) + date (non nul-terminated)
size_t len = strlen(event->text_event.text); size_t len = strlen(event->text_event.text);
if (len > TEXT_MAX_LENGTH) { if (len > TEXT_MAX_LENGTH) {
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; case CONTROL_EVENT_TYPE_MOUSE:
memcpy(&buf[2], &event->text_event.text, len); buf[1] = event->mouse_event.action;
return 2 + len; write32(&buf[2], event->mouse_event.buttons);
} write_position(&buf[6], &event->mouse_event.position);
case CONTROL_EVENT_TYPE_MOUSE: return 14;
buf[1] = event->mouse_event.action; case CONTROL_EVENT_TYPE_SCROLL:
write32(&buf[2], event->mouse_event.buttons); write_position(&buf[1], &event->scroll_event.position);
write_position(&buf[6], &event->mouse_event.position); write32(&buf[9], (Uint32) event->scroll_event.hscroll);
return 14; write32(&buf[13], (Uint32) event->scroll_event.vscroll);
case CONTROL_EVENT_TYPE_SCROLL: return 17;
write_position(&buf[1], &event->scroll_event.position); default:
write32(&buf[9], (Uint32) event->scroll_event.hscroll); SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u\n", (unsigned) event->type);
write32(&buf[13], (Uint32) event->scroll_event.vscroll); return 0;
return 17;
default:
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u\n", (unsigned) event->type);
return 0;
} }
} }

View file

@ -16,37 +16,37 @@ int parse_args(struct args *args, int argc, char *argv[]) {
int c; int c;
while ((c = getopt(argc, argv, "p:m:")) != -1) { while ((c = getopt(argc, argv, "p:m:")) != -1) {
switch (c) { switch (c) {
case 'p': { case 'p': {
char *endptr; char *endptr;
long value = strtol(optarg, &endptr, 0); long value = strtol(optarg, &endptr, 0);
if (*optarg == '\0' || *endptr != '\0') { if (*optarg == '\0' || *endptr != '\0') {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg);
return -1; 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) { case 'm': {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld\n", value); char *endptr;
return -1; 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; default:
break; // getopt prints the error message on stderr
}
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; 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;
} }
} }

View file

@ -335,49 +335,49 @@ void event_loop(void) {
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) { while (SDL_WaitEvent(&event)) {
switch (event.type) { switch (event.type) {
case EVENT_DECODER_STOPPED: case EVENT_DECODER_STOPPED:
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped"); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped");
case SDL_QUIT: case SDL_QUIT:
return;
case EVENT_NEW_FRAME:
if (!handle_new_frame()) {
return; return;
} case EVENT_NEW_FRAME:
texture_empty = SDL_FALSE; if (!handle_new_frame()) {
count_frame(); // display fps for debug return;
break; }
case SDL_WINDOWEVENT: texture_empty = SDL_FALSE;
switch (event.window.event) { count_frame(); // display fps for debug
case SDL_WINDOWEVENT_EXPOSED: break;
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT:
render(renderer, texture_empty ? NULL : texture); 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;
} }
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;
}
} }
} }
} }