feat(cli): added the diff command to display the difference of two files

This commit is contained in:
lisk77 2025-08-18 16:34:56 +02:00
parent 190aa7cc76
commit c8b4d93c89
2 changed files with 76 additions and 8 deletions

View file

@ -1,6 +1,9 @@
#ifndef UTILITIES_H
#define UTILITIES_H
#include <sys/stat.h>
#include <errno.h>
#include "file.h"
#include "action_list.h"
@ -9,6 +12,25 @@
#define GREEN_BG "\033[42m"
#define BLACK_FG "\033[30m"
typedef enum {
PT_NOEXIST,
PT_FILE,
PT_DIR,
PT_OTHER,
PT_ERROR
} PathType;
PathType get_path_type(const char* path) {
struct stat st;
int rc = stat(path, &st);
if (rc != 0) {
return (errno == ENOENT) ? PT_NOEXIST : PT_ERROR;
}
if (S_ISREG(st.st_mode)) return PT_FILE;
if (S_ISDIR(st.st_mode)) return PT_DIR;
return PT_OTHER;
}
void visualize_diff(File* old_version, File* new_version, ActionList* actions) {
int* deleted_lines = calloc(old_version->lines, sizeof(int));
int* inserted_lines = calloc(new_version->lines, sizeof(int));