format the code
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
#include "todo.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// Memory management
|
||||
void todo_free_item(TodoItem *item) {
|
||||
free(item->title);
|
||||
}
|
||||
void todo_free_item(TodoItem *item) { free(item->title); }
|
||||
|
||||
// Item operations
|
||||
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 - title_length bytes
|
||||
// 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;
|
||||
|
||||
char *buffer = malloc(buffer_size);
|
||||
@@ -48,7 +47,8 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
|
||||
// copy title
|
||||
memcpy(buffer + sizeof(unsigned char), item->title, title_length);
|
||||
// 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;
|
||||
|
||||
|
||||
56
main.c
56
main.c
@@ -1,8 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include "engine/todo.h"
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_TODOS UINT_MAX
|
||||
#define SAVE_FILE "todos.todd"
|
||||
@@ -136,33 +136,33 @@ int main(int argc, char **argv) {
|
||||
getc(stdin); // remove the newline character from the buffer
|
||||
|
||||
switch (cmd) {
|
||||
case ADD:
|
||||
add_command_handler();
|
||||
break;
|
||||
case MARK:
|
||||
mark_command_handler();
|
||||
break;
|
||||
case PRINT:
|
||||
print_command_handler();
|
||||
break;
|
||||
case REMOVE:
|
||||
remove_command_handler();
|
||||
break;
|
||||
case WRITE_TO_FILE:
|
||||
write_to_file_handler();
|
||||
break;
|
||||
case LOAD_FROM_FILE:
|
||||
load_from_file_handler();
|
||||
break;
|
||||
case QUIT:
|
||||
break;
|
||||
default:
|
||||
printf("Invalid command\n");
|
||||
break;
|
||||
case ADD:
|
||||
add_command_handler();
|
||||
break;
|
||||
case MARK:
|
||||
mark_command_handler();
|
||||
break;
|
||||
case PRINT:
|
||||
print_command_handler();
|
||||
break;
|
||||
case REMOVE:
|
||||
remove_command_handler();
|
||||
break;
|
||||
case WRITE_TO_FILE:
|
||||
write_to_file_handler();
|
||||
break;
|
||||
case LOAD_FROM_FILE:
|
||||
load_from_file_handler();
|
||||
break;
|
||||
case QUIT:
|
||||
break;
|
||||
default:
|
||||
printf("Invalid command\n");
|
||||
break;
|
||||
}
|
||||
|
||||
} while (cmd != QUIT);
|
||||
|
||||
|
||||
for (int i = 0; i < arrlen(todos); i++) {
|
||||
todo_free_item(&todos[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user