started working on logging
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
*/target
|
*/target
|
||||||
*.out
|
*.out
|
||||||
|
*somefile*
|
||||||
|
*binary*
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef DYNSTR_H
|
#ifndef DYNSTR_H
|
||||||
#define DYNSTR_H
|
#define DYNSTR_H
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom String type that stores an array of characters
|
* Custom String type that stores an array of characters
|
||||||
|
|||||||
@@ -342,7 +342,3 @@ void shutdown_editor(Editor* self) {
|
|||||||
str_dealloc(&self->filename);
|
str_dealloc(&self->filename);
|
||||||
free(self->buffer);
|
free(self->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
String_t* to_string(Editor* self) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#include "dynstr.h"
|
||||||
|
|
||||||
|
|
||||||
|
int write_log(String_t* string, int lines) {
|
||||||
|
|
||||||
|
FILE* file = fopen("log.txt", "a");
|
||||||
|
|
||||||
|
for (int i = 0; i < lines; i++) {
|
||||||
|
str_to_file(&string[i], file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#include "dynstr.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the string to a file, appending a newline character
|
||||||
|
* This function automatically appends a newline character to the end of the string
|
||||||
|
*
|
||||||
|
* @param string the string to write
|
||||||
|
* @return 0 on success, -1 on error
|
||||||
|
* @note This function frees the string passed to it!
|
||||||
|
*/
|
||||||
|
int write_log(String_t* string, int lines);
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
@@ -198,6 +199,7 @@ CommandType str_to_cmd(const char* cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
char log_fmt_string[128];
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
help();
|
help();
|
||||||
@@ -209,12 +211,15 @@ int main(int argc, char* argv[]) {
|
|||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CMD_OPEN:
|
case CMD_OPEN:
|
||||||
|
sprintf(log_fmt_string, "Edited File [%s]", argv[2]);
|
||||||
open_editor(argv[2]);
|
open_editor(argv[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_RM:
|
case CMD_RM:
|
||||||
remove(argv[2]);
|
remove(argv[2]);
|
||||||
|
sprintf(log_fmt_string, "Deleted File [%s]", argv[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_NEW:
|
case CMD_NEW:
|
||||||
|
sprintf(log_fmt_string, "Created File [%s]", argv[2]);
|
||||||
open_editor(argv[2]);
|
open_editor(argv[2]);
|
||||||
break;
|
break;
|
||||||
case CMD_LENC:
|
case CMD_LENC:
|
||||||
@@ -233,11 +238,16 @@ int main(int argc, char* argv[]) {
|
|||||||
case CMD_MV:
|
case CMD_MV:
|
||||||
if (rename(argv[2], argv[3]) != 0) {
|
if (rename(argv[2], argv[3]) != 0) {
|
||||||
fprintf(stderr, "Error: Failed to move file %s to %s\n", argv[2], argv[3]);
|
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;
|
break;
|
||||||
case CMD_CP:
|
case CMD_CP:
|
||||||
if (copy_file(argv[2], argv[3]) != 0) {
|
if (copy_file(argv[2], argv[3]) != 0) {
|
||||||
fprintf(stderr, "Error: Failed to copy file %s to %s\n", argv[2], argv[3]);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -250,5 +260,11 @@ int main(int argc, char* argv[]) {
|
|||||||
help();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ fn somefunc() {
|
|||||||
let c2 = String::from("hello world");
|
let c2 = String::from("hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// some comment
|
||||||
|
|
||||||
|
|
||||||
struct EditorData {
|
struct EditorData {
|
||||||
buffer: Vec<Vec<char>>, // outer vec is the line, inner is col;
|
buffer: Vec<Vec<char>>, // outer vec is the line, inner is col;
|
||||||
file_line: i32,
|
file_line: i32,
|
||||||
|
|||||||
Reference in New Issue
Block a user