Mass reformat
This commit is contained in:
parent
4d27def35e
commit
df11e34235
27 changed files with 121 additions and 136 deletions
|
|
@ -30,12 +30,8 @@ typedef struct __attribute__((__packed__)) {
|
|||
|
||||
void print_command(CommandMessage *m) {
|
||||
switch (m->type) {
|
||||
case CMD_SET_LEVEL:
|
||||
printf("Type: SetLevel\nPayload: %d\n", m->data.set_level.level);
|
||||
break;
|
||||
case CMD_SET_LIGHTS:
|
||||
printf("Type: SetLights\nPayload: %d\n", m->data.set_lights.on);
|
||||
break;
|
||||
case CMD_SET_LEVEL: printf("Type: SetLevel\nPayload: %d\n", m->data.set_level.level); break;
|
||||
case CMD_SET_LIGHTS: printf("Type: SetLights\nPayload: %d\n", m->data.set_lights.on); break;
|
||||
case CMD_SET_DISTANCE_FACTOR:
|
||||
printf("Type: SetDistanceFactor\nPayload: %.2f\n", m->data.set_distance.factor);
|
||||
break;
|
||||
|
|
|
|||
11
break.c
11
break.c
|
|
@ -1,8 +1,8 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h> // mmap and friends
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main(void) {
|
||||
/*
|
||||
|
|
@ -12,8 +12,7 @@ int main(void) {
|
|||
* See: "man 3 getauxval" or
|
||||
* https://www.man7.org/linux/man-pages/man3/getauxval.3.html
|
||||
*/
|
||||
long page_size =
|
||||
sysconf(_SC_PAGESIZE); // or _SC_PAGE_SIZE (POSIX allows both)
|
||||
long page_size = sysconf(_SC_PAGESIZE); // or _SC_PAGE_SIZE (POSIX allows both)
|
||||
if (page_size == -1) {
|
||||
perror("sysconf");
|
||||
return 1;
|
||||
|
|
@ -45,11 +44,9 @@ int main(void) {
|
|||
* (which must be greater than 0).
|
||||
*/
|
||||
|
||||
uint8_t *first_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
uint8_t *first_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
|
||||
uint8_t *second_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
uint8_t *second_mmap = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
|
||||
printf("First mmap: %p\n", first_mmap);
|
||||
printf("Second mmap: %p\n", second_mmap);
|
||||
|
|
|
|||
29
calc.c
29
calc.c
|
|
@ -2,15 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum {
|
||||
TOKEN_INT,
|
||||
TOKEN_PLUS,
|
||||
TOKEN_MUL,
|
||||
TOKEN_DIV,
|
||||
TOKEN_LPAREN,
|
||||
TOKEN_RPAREN,
|
||||
TOKEN_EOF
|
||||
} TokenType;
|
||||
typedef enum { TOKEN_INT, TOKEN_PLUS, TOKEN_MUL, TOKEN_DIV, TOKEN_LPAREN, TOKEN_RPAREN, TOKEN_EOF } TokenType;
|
||||
|
||||
typedef struct {
|
||||
TokenType type;
|
||||
|
|
@ -43,19 +35,12 @@ Token get_next_token() {
|
|||
|
||||
pos++;
|
||||
switch (ch) {
|
||||
case '+':
|
||||
return (Token){TOKEN_PLUS, 0};
|
||||
case '*':
|
||||
return (Token){TOKEN_MUL, 0};
|
||||
case '/':
|
||||
return (Token){TOKEN_DIV, 0};
|
||||
case '(':
|
||||
return (Token){TOKEN_LPAREN, 0};
|
||||
case ')':
|
||||
return (Token){TOKEN_RPAREN, 0};
|
||||
default:
|
||||
fprintf(stderr, "Unexpected character: %c\n", ch);
|
||||
exit(1);
|
||||
case '+': return (Token){TOKEN_PLUS, 0};
|
||||
case '*': return (Token){TOKEN_MUL, 0};
|
||||
case '/': return (Token){TOKEN_DIV, 0};
|
||||
case '(': return (Token){TOKEN_LPAREN, 0};
|
||||
case ')': return (Token){TOKEN_RPAREN, 0};
|
||||
default: fprintf(stderr, "Unexpected character: %c\n", ch); exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,12 @@ typedef struct {
|
|||
int (*get)();
|
||||
} Test;
|
||||
|
||||
void my_put(int a) { global = a; }
|
||||
int my_get() { return global; }
|
||||
void my_put(int a) {
|
||||
global = a;
|
||||
}
|
||||
int my_get() {
|
||||
return global;
|
||||
}
|
||||
|
||||
void executor(Test *t) {
|
||||
t->put(10);
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ void *dynbuf_get(Dynbuf *v, size_t index) {
|
|||
return (char *)v->data + index * v->elem_size;
|
||||
}
|
||||
|
||||
inline size_t dynbuf_size(const Dynbuf *v) { return v->length; }
|
||||
inline size_t dynbuf_size(const Dynbuf *v) {
|
||||
return v->length;
|
||||
}
|
||||
|
||||
inline size_t dynbuf_capacity(const Dynbuf *v) { return v->capacity; }
|
||||
inline size_t dynbuf_capacity(const Dynbuf *v) {
|
||||
return v->capacity;
|
||||
}
|
||||
|
|
|
|||
5
fibmat.c
5
fibmat.c
|
|
@ -1,5 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* @brief Computes the n-th Fibonacci number using matrix exponentiation.
|
||||
|
|
@ -48,7 +48,8 @@ static FibMatrix matrix_power(FibMatrix base, uint32_t n) {
|
|||
}
|
||||
|
||||
uint64_t fibonacci_matrix(uint32_t n) {
|
||||
if (n == 0) return 0;
|
||||
if (n == 0)
|
||||
return 0;
|
||||
FibMatrix base = {1, 1, 1, 0};
|
||||
FibMatrix result = matrix_power(base, n - 1);
|
||||
return result.a;
|
||||
|
|
|
|||
|
|
@ -246,8 +246,7 @@ float mat3_det(const Mat3 *m) {
|
|||
float m21 = MAT3_AT(m, 2, 1);
|
||||
float m22 = MAT3_AT(m, 2, 2);
|
||||
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m12 * m20) +
|
||||
m02 * (m10 * m21 - m11 * m20);
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m12 * m20) + m02 * (m10 * m21 - m11 * m20);
|
||||
}
|
||||
|
||||
inline float vec3_dot(const Vec3 *a, const Vec3 *b) {
|
||||
|
|
@ -255,9 +254,7 @@ inline float vec3_dot(const Vec3 *a, const Vec3 *b) {
|
|||
}
|
||||
|
||||
Vec3 vec3_cross(const Vec3 *a, const Vec3 *b) {
|
||||
Vec3 res = {.x = a->y * b->z - a->z * b->y,
|
||||
.y = a->x * b->z - a->z * b->x,
|
||||
.z = a->x * b->y - a->y * b->x};
|
||||
Vec3 res = {.x = a->y * b->z - a->z * b->y, .y = a->x * b->z - a->z * b->x, .z = a->x * b->y - a->y * b->x};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -325,14 +322,10 @@ Vec2 vec2_scale(const Vec2 *a, const float scalar) {
|
|||
|
||||
Mat2 mat2_mul(const Mat2 *m1, const Mat2 *m2) {
|
||||
Mat2 m3 = {.arr = {
|
||||
MAT2_AT(m1, 0, 0) * MAT2_AT(m2, 0, 0) +
|
||||
MAT2_AT(m1, 0, 1) * MAT2_AT(m2, 1, 0),
|
||||
MAT2_AT(m1, 1, 0) * MAT2_AT(m2, 0, 0) +
|
||||
MAT2_AT(m1, 1, 1) * MAT2_AT(m2, 1, 0),
|
||||
MAT2_AT(m1, 0, 0) * MAT2_AT(m2, 0, 1) +
|
||||
MAT2_AT(m1, 0, 1) * MAT2_AT(m2, 1, 1),
|
||||
MAT2_AT(m1, 1, 0) * MAT2_AT(m2, 0, 1) +
|
||||
MAT2_AT(m1, 1, 1) * MAT2_AT(m2, 1, 1),
|
||||
MAT2_AT(m1, 0, 0) * MAT2_AT(m2, 0, 0) + MAT2_AT(m1, 0, 1) * MAT2_AT(m2, 1, 0),
|
||||
MAT2_AT(m1, 1, 0) * MAT2_AT(m2, 0, 0) + MAT2_AT(m1, 1, 1) * MAT2_AT(m2, 1, 0),
|
||||
MAT2_AT(m1, 0, 0) * MAT2_AT(m2, 0, 1) + MAT2_AT(m1, 0, 1) * MAT2_AT(m2, 1, 1),
|
||||
MAT2_AT(m1, 1, 0) * MAT2_AT(m2, 0, 1) + MAT2_AT(m1, 1, 1) * MAT2_AT(m2, 1, 1),
|
||||
}};
|
||||
|
||||
return m3;
|
||||
|
|
@ -385,8 +378,7 @@ bool vec2_approx_eq(const Vec2 *a, const Vec2 *b, float epsilon) {
|
|||
}
|
||||
|
||||
bool vec3_approx_eq(const Vec3 *a, const Vec3 *b, float epsilon) {
|
||||
return (fabsf(a->x - b->x) <= epsilon) && (fabsf(a->y - b->y) <= epsilon) &&
|
||||
(fabsf(a->z - b->z) <= epsilon);
|
||||
return (fabsf(a->x - b->x) <= epsilon) && (fabsf(a->y - b->y) <= epsilon) && (fabsf(a->z - b->z) <= epsilon);
|
||||
}
|
||||
|
||||
Mat2 mat2_adj(const Mat2 *m) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lua.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t lookup3(const void *key, size_t length, uint32_t initval);
|
||||
|
|
|
|||
|
|
@ -26,8 +26,12 @@ uint32_t murmur3_32(const uint8_t* key, size_t len, uint32_t seed) {
|
|||
/* fall through */
|
||||
case 2: k ^= key[i + 1] << 8;
|
||||
/* fall through */
|
||||
case 1: k ^= key[i + 0];
|
||||
k *= c1; k = (k << 15) | (k >> (32 - 15)); k *= c2; h ^= k;
|
||||
case 1:
|
||||
k ^= key[i + 0];
|
||||
k *= c1;
|
||||
k = (k << 15) | (k >> (32 - 15));
|
||||
k *= c2;
|
||||
h ^= k;
|
||||
}
|
||||
|
||||
h ^= len;
|
||||
|
|
|
|||
7
prand.c
7
prand.c
|
|
@ -4,8 +4,7 @@
|
|||
#include <time.h>
|
||||
|
||||
#define BUILD_SEED \
|
||||
((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * \
|
||||
(uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \
|
||||
((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * (uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \
|
||||
(uint64_t)(__TIME__[6]) * (uint64_t)(__TIME__[7]))
|
||||
|
||||
#define PRNG_SAVE_INTERVAL 50 // Save every 1000 calls to prand()
|
||||
|
|
@ -29,7 +28,9 @@ void sprand(uint64_t s) {
|
|||
}
|
||||
}
|
||||
|
||||
void rand_reseed() { seed = BUILD_SEED; }
|
||||
void rand_reseed() {
|
||||
seed = BUILD_SEED;
|
||||
}
|
||||
|
||||
#define PRAND_MAIN
|
||||
#ifdef PRAND_MAIN
|
||||
|
|
|
|||
4
sin.c
4
sin.c
|
|
@ -11,7 +11,9 @@ double factorial(int n) {
|
|||
return result;
|
||||
}
|
||||
|
||||
double abs_double(double x) { return x < 0 ? -x : x; }
|
||||
double abs_double(double x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
// SICP-style iterative approximation for sin(x)
|
||||
double sin_iter(double x) {
|
||||
|
|
|
|||
6
sock.c
6
sock.c
|
|
@ -29,8 +29,7 @@ int main(void) {
|
|||
};
|
||||
|
||||
// Bind socket
|
||||
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
|
||||
0) {
|
||||
if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
|
||||
perror("bind failed");
|
||||
close(server_fd);
|
||||
return EXIT_FAILURE;
|
||||
|
|
@ -48,8 +47,7 @@ int main(void) {
|
|||
// Accept one client connection
|
||||
struct sockaddr_in client_addr;
|
||||
socklen_t client_len = sizeof(client_addr);
|
||||
int client_fd =
|
||||
accept(server_fd, (struct sockaddr *)&client_addr, &client_len);
|
||||
int client_fd = accept(server_fd, (struct sockaddr *)&client_addr, &client_len);
|
||||
if (client_fd < 0) {
|
||||
perror("accept failed");
|
||||
close(server_fd);
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ int main() {
|
|||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) <
|
||||
0) {
|
||||
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
|
||||
perror("connect");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SOCKET_PATH "/tmp/demosocket"
|
||||
#define BUF_SIZE 128
|
||||
|
|
|
|||
|
|
@ -22,4 +22,6 @@ void ts_node_destroy(treeset_node_t *n) {
|
|||
free(n);
|
||||
}
|
||||
|
||||
void treeset_destroy(treeset_t *set) { ts_node_destroy(set->root); }
|
||||
void treeset_destroy(treeset_t *set) {
|
||||
ts_node_destroy(set->root);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue