#Line-oriented text editor

28 messages · Page 1 of 1 (latest)

cerulean monolith
#

Hi, I'm fairly new to C, and I wanted some feedback on a new project I made. It is a line-oriented text editor inspired (not based on, so functionality is not the same) by the 'ed' utility on UNIX systems. Here is the Github link: https://github.com/TSOA2/Blob
Any advice would be appreciated!

GitHub

A line-oriented text editor. Contribute to TSOA2/Blob development by creating an account on GitHub.

vague cradle
#

also one of the reasons to use do while(0) in a macro is to force the user to add a semicolon at the end

#

you shouldn't add that yourself, if you used a macro

#

also get rid of the PROMPT macro

#

macros are just evil in general

#

also you're relying on C99 since not every variable is declared at the start of a block, so commit to the style

cerulean monolith
#

Thank you for your help! Should I have PROMPT in a constant, and then just remove the linked list macros then?

vague cradle
#
FILE *create_empty_file(const char *fname)
{
-    FILE *create_file;
-    FILE *read_file;

-    create_file = fopen(fname, "w");
+    FILE *file = fopen(fname, "w+");
-    if (create_file == NULL) {
+    if (file == NULL) {
        perror("ed: create_empty_file");
        exit(EXIT_FAILURE);
    }

-    (void) fclose(create_file);

-    read_file = fopen(fname, "r");
-       FILE *read_file = freopen(fname, "r", create_file);
-    if (read_file == NULL) {
-        perror("ed: create_empty_file");
-        exit(EXIT_FAILURE);
-    }
-
-    return read_file;
+    return file;
}
#

or you could freopen or something

#

in any case, it's probably not good to open the same file twice with manual closing

cerulean monolith
#

Thanks, I didn't know that!

vague cradle
#

every platform will have slightly different signals and behavior around them though

#

just don't rely on it working in any particular way

cerulean monolith
#

Sounds good.

vague cradle
#

also you should be using const a lot more, especially in longer functions

#

lots of mutable variables make it very difficult to reason about code

cerulean monolith
#

Am I making any mistakes with memory allocation/freeing linked lists?

vague cradle
#

it's overall pretty clean though

vague cradle
#

you should run this through valgrind or an address sanitizer to be somewhat sure

cerulean monolith
#

Thank you for your help!

ebon bay
#

B - baffling
l - line
o - oriented
b - baboon?

cerulean monolith
#

@ebon bay why not, will add that

ebon bay
#

hah

#

i think you committed the executables by accident