started working on logging

This commit is contained in:
FantasyPvP
2024-12-04 18:59:02 +00:00
parent ad96bcc0c8
commit ad8496ca68
7 changed files with 49 additions and 5 deletions
+16
View File
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include "editor.h"
#include "log.h"
void help() {
printf("Usage:\n");
@@ -198,6 +199,7 @@ CommandType str_to_cmd(const char* cmd) {
}
int main(int argc, char* argv[]) {
char log_fmt_string[128];
if (argc < 2) {
help();
@@ -209,12 +211,15 @@ int main(int argc, char* argv[]) {
if (argc == 3) {
switch (cmd) {
case CMD_OPEN:
sprintf(log_fmt_string, "Edited File [%s]", argv[2]);
open_editor(argv[2]);
break;
case CMD_RM:
remove(argv[2]);
sprintf(log_fmt_string, "Deleted File [%s]", argv[2]);
break;
case CMD_NEW:
sprintf(log_fmt_string, "Created File [%s]", argv[2]);
open_editor(argv[2]);
break;
case CMD_LENC:
@@ -233,11 +238,16 @@ int main(int argc, char* argv[]) {
case CMD_MV:
if (rename(argv[2], argv[3]) != 0) {
fprintf(stderr, "Error: Failed to move file %s to %s\n", argv[2], argv[3]);
} else {
sprintf(log_fmt_string, "Moved file [%s] To [%s]", argv[2], argv[3]);
}
break;
case CMD_CP:
if (copy_file(argv[2], argv[3]) != 0) {
fprintf(stderr, "Error: Failed to copy file %s to %s\n", argv[2], argv[3]);
sprintf(log_fmt_string, "Failed to copy file [%s] To [%s]", argv[2], argv[3]);
} else {
sprintf(log_fmt_string, "Copied file [%s] To [%s]", argv[2], argv[3]);
}
break;
default:
@@ -250,5 +260,11 @@ int main(int argc, char* argv[]) {
help();
}
// log output of command
if (log_fmt_string[0] != '\0') {
String_t str = str_from_chars(log_fmt_string);
write_log(&str, 1);
}
return 0;
}