Style changes

This commit is contained in:
Lior Halphon 2019-06-14 14:34:02 +03:00
parent 8389c6a450
commit 5a04054145

View File

@ -2,13 +2,15 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
void pair(size_t count, uint8_t byte) { void pair(size_t count, uint8_t byte)
{
static size_t unique_count = 0; static size_t unique_count = 0;
static uint8_t unique_data[15]; static uint8_t unique_data[15];
if (count == 1) { if (count == 1) {
unique_data[unique_count++] = byte; unique_data[unique_count++] = byte;
assert(unique_count <= 15); assert(unique_count <= 15);
} else { }
else {
assert(count <= 15); assert(count <= 15);
uint8_t control = (count << 4) | unique_count; uint8_t control = (count << 4) | unique_count;
putchar(control); putchar(control);
@ -19,7 +21,8 @@ void pair(size_t count, uint8_t byte) {
if (count != 0) { if (count != 0) {
putchar(byte); putchar(byte);
} else { }
else {
assert(control == 0); assert(control == 0);
} }
@ -27,7 +30,8 @@ void pair(size_t count, uint8_t byte) {
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
size_t count = 1; size_t count = 1;
uint8_t byte = getchar(); uint8_t byte = getchar();
int new; int new;
@ -36,7 +40,8 @@ int main(int argc, char *argv[]) {
while ((new = getchar()) != EOF) { while ((new = getchar()) != EOF) {
if (byte == new) { if (byte == new) {
count++; count++;
} else { }
else {
pair(count, byte); pair(count, byte);
byte = new; byte = new;
count = 1; count = 1;