format the code

This commit is contained in:
2023-12-22 04:11:26 +01:00
parent 01e6a6064d
commit 672998b17b
2 changed files with 34 additions and 34 deletions

View File

@@ -1,12 +1,10 @@
#include "todo.h" #include "todo.h"
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
// Memory management // Memory management
void todo_free_item(TodoItem *item) { void todo_free_item(TodoItem *item) { free(item->title); }
free(item->title);
}
// Item operations // Item operations
TodoItem todo_create_item(char *title) { TodoItem todo_create_item(char *title) {
@@ -38,7 +36,8 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
// title_length - 1 byte // title_length - 1 byte
// title - title_length bytes // title - title_length bytes
// completed - 1 byte // completed - 1 byte
unsigned char title_length = item->title_length; unsigned char completed_length = sizeof(item->completed); unsigned char title_length = item->title_length;
unsigned char completed_length = sizeof(item->completed);
int buffer_size = sizeof(unsigned char) + title_length + completed_length; int buffer_size = sizeof(unsigned char) + title_length + completed_length;
char *buffer = malloc(buffer_size); char *buffer = malloc(buffer_size);
@@ -48,7 +47,8 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
// copy title // copy title
memcpy(buffer + sizeof(unsigned char), item->title, title_length); memcpy(buffer + sizeof(unsigned char), item->title, title_length);
// copy completed // copy completed
memcpy(buffer + sizeof(unsigned char) + title_length, &item->completed, completed_length); memcpy(buffer + sizeof(unsigned char) + title_length, &item->completed,
completed_length);
*buffer_size_out = buffer_size; *buffer_size_out = buffer_size;

54
main.c
View File

@@ -1,8 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "engine/todo.h" #include "engine/todo.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_TODOS UINT_MAX #define MAX_TODOS UINT_MAX
#define SAVE_FILE "todos.todd" #define SAVE_FILE "todos.todd"
@@ -136,29 +136,29 @@ int main(int argc, char **argv) {
getc(stdin); // remove the newline character from the buffer getc(stdin); // remove the newline character from the buffer
switch (cmd) { switch (cmd) {
case ADD: case ADD:
add_command_handler(); add_command_handler();
break; break;
case MARK: case MARK:
mark_command_handler(); mark_command_handler();
break; break;
case PRINT: case PRINT:
print_command_handler(); print_command_handler();
break; break;
case REMOVE: case REMOVE:
remove_command_handler(); remove_command_handler();
break; break;
case WRITE_TO_FILE: case WRITE_TO_FILE:
write_to_file_handler(); write_to_file_handler();
break; break;
case LOAD_FROM_FILE: case LOAD_FROM_FILE:
load_from_file_handler(); load_from_file_handler();
break; break;
case QUIT: case QUIT:
break; break;
default: default:
printf("Invalid command\n"); printf("Invalid command\n");
break; break;
} }
} while (cmd != QUIT); } while (cmd != QUIT);