From bef5547d501fec2fbd480e14c6680ec870356ce9 Mon Sep 17 00:00:00 2001 From: FantasyPvP <80643031+FantasyPvP@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:50:17 +0000 Subject: [PATCH] creating new lines works now, fixed several segfaults and bugs --- final/binary | Bin 21768 -> 21880 bytes final/dynstr.c | 48 ++++---------------------------- final/editor.c | 63 +++++++++++++++++------------------------- final/log.txt | 20 +++++++++++++- final/main.c | 7 ++--- prototype/src/main.rs | 2 ++ 6 files changed, 54 insertions(+), 86 deletions(-) diff --git a/final/binary b/final/binary index 62a1f15cfb36551ac1ac83f39638927cb8f4edfb..c5a21f5015b475820693e731b0d42853e8f92eb2 100755 GIT binary patch delta 4716 zcmZ7)ZFE${_0HS3n`|KD!-U;zNU{+@K9c~65F{UbJeYtvB$5T?7)1$4szM4x1sfL) zDDS*3gpNfK+XCtl>=zi0#nclw*h4^zMv694&?P|FKscoW5+N`>cV;#q^JC`S?>qP2 zxjVD#-zPoqlLmJ}TLOqtEEnk6H2l37h*ePRrej$#&Ugtq<5?ofa;|qsa6Ky_*~H6M z5uVU6R^s|rW@S6b@t(J{o<6*B-D~VE+prWb01yBWng|eB0~+Eo z*$LZVw%*}p!yIlBU_^J3keIKFxfN&Dpu1U6ca!}BS0m;fVm>40FU9;3&aBwsCQHOu zj_zh_>~1oW?XkN^65C_XCUXVnWifY)`At@C&n9D$ht)XTEM#}HGP|1$V%r@q&mRFG z0a74TCbt_c7l<;EJ8V)g-7?w%putX7?sSa_CJHGySSr`Z4r>&?{f?ctvn|f4B$=IX zx>5#75ivru<%${3V6ibSk@LP$F2C%U^TvXhzY>zfF7(?tCbf?PAgD}50YKVq_=C6M z(;Hvv-_Q0z{BDxQhr|>CEO7%s*Mggz^C23-DF~ObKPRM@HQE4p^5+ErmltQnWvmrC zX`tZSLI4`DAHgNRXJs=OKWJ6LMsAX3LBB&LrD z6aql)I3KMqm|p+@)I75?mRbeV3(+Jk00=MSoFA}Pu{DV~{@gTVX$|ka!8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ELFPQ*n|<83kqHzT$yqbpZ)K zD+xf1=7h|_Y|I1MuIEI`07MJ`U>DxjW;7!c^o0~f6(IzG7KN|yNO7x_)HCEiU)$`A zOmmZAVx(eRjN|C%HN3ESAaI9qc=S+j@c=1!u9E*t+?D>WqNWX&Xpt8H_>;n)b4&a$ z)UE&qi0#z+kt4Xj;(`X?(mdUFvhZ^Q@pyqul^Clc^s-26rurnpuQD2|@SvhRM^Dv!TYM((4Yi~)_}i)Y^Uy?@nZ`H$qUhWN{)J7Q0|7mBZ$5N z0FNtazg1zFuJ{+DG_ppFZ?ddx_vr14^CNZB6sHIP>J+|CIiMzJz`ai#SJaED(!|-t zUaat)$_w$+4*=&B{&%V*MRx;$3ksivzvuW0fM*y0uA>%jU#m>goptMDqo=#QW34hJ zN0bfWh)rT-x_i)%6!l|lF@RqU3vBOnclOUv2Y3NgWW!$>-cb9SlqW;g zepvQIN$IE}C|*^%e8n@PieN!;$%?YNc)FR?9hvb{t*&h5K~k6gP!S=(UZ0iX3aSq_ z;rTswVpfW)M(GL9narD;!W_BLtROcvvOpd30=6l4e0Ng_H-}7iBDca(ttya_JU4qb z&lMA{f$;p2lf98QDk@W*kj%mC^So?wfO%)9ME>xlC~x-o$eJ|iTut4k+0zMWVJGIK tM262}fVt*QAdata; - String_t* lines = NULL; - - // find the number of lines in the file - *numlines = 0; - for (int i = 0; i < strlen(string); i++) { - if (string[i] == '\n') { - (*numlines)++; - } - } - - // add one if the last char is not a newline - // in this case there is one more line than newline symbols - if (self->data[strlen(self->data) - 1] != '\n') { - (*numlines)++; - } - - // allocate memory for an array of pointers to each line - lines = (String_t*)malloc((*numlines + 1) * sizeof(String_t)); - - int i = 0; - char* start = string; - char* end = string; - - while (*end != '\0') { - if (*end == '\n') { - lines[i] = str_from_slice(start, end - start); - - end++; - start = end; - - i++; - } else { - end++; - } - } - // returns an array of String_t - return lines; -} - /// splits a string into an array of strings based on a delimiter String_t* str_split(String_t* self, int* res_len, char c) { @@ -198,6 +156,10 @@ String_t* str_split(String_t* self, int* res_len, char c) { return elements; } +String_t* str_lines(String_t* self, int* numlines) { + return str_split(self, numlines, '\n'); +} + int str_len(String_t* s) { return s->size; } @@ -207,7 +169,7 @@ char* to_chars(String_t* s) { } // int main() { -// String_t s = str_from_chars("hello\nworld\neeeee\notherline\n\0"); +// String_t s = str_from_chars("hello\nworld\neeeee\notherline\n"); // str_remove(&s, 10); // str_insert(&s, 10, 'h'); diff --git a/final/editor.c b/final/editor.c index dd8bd48..2b438b1 100644 --- a/final/editor.c +++ b/final/editor.c @@ -11,24 +11,6 @@ typedef struct { String_t* buffer; } Editor; -Editor new_editor() { - Editor e; - e.lines = 0; - e.screen_line = 0; - e.screen_col = 0; - e.editmode = false; - - String_t lines = str_from_chars(""); - int linenum = 0; - e.buffer = str_lines(&lines, &linenum); - e.lines = linenum; - str_dealloc(&lines); - - addstr(""); - - return e; -} - Editor editor_from(char* input_string) { Editor e; e.lines = 0; @@ -40,27 +22,26 @@ Editor editor_from(char* input_string) { String_t lines = str_from_chars(input_string); e.buffer = str_lines(&lines, &linenum); e.lines = (size_t)linenum; - - fprintf(stderr, "BUFFER: %s", to_chars(&e.buffer[2])); str_dealloc(&lines); - // String_t s = str_from_chars(input_string); - // int linen = 0; - // String_t* lines = str_lines(&s, &linen); - // for (int i=0; i < linen; i++) { - // fprintf(stderr, "%s", to_chars(&lines[i])); - // } - // e.lines = (size_t)linen; - // e.buffer = lines; - // str_dealloc(&s); - addstr(input_string); - + for (size_t i = 0; i < e.lines; i++) { + // adding the line number + char line_no[5]; + snprintf(line_no, 5, "%-5d", i + 1); + // adding the line of text to the buffer + addstr(line_no); + addch(' '); + addstr(to_chars(&e.buffer[i])); + addstr("\n"); + } return e; } +Editor new_editor() { + return editor_from(""); +} + void move_cursor(Editor* self, int x, int y) { - fprintf(stderr, "lns %d, line %d, col %d, mode %d", self->lines, self->screen_line, self->screen_col, self->editmode); - fprintf(stderr, "line: %s", to_chars(&self->buffer[self->screen_line])); if (y != 0 && (int)(self->screen_line) + y >= 0 && self->screen_line + y <= self->lines) @@ -71,8 +52,7 @@ void move_cursor(Editor* self, int x, int y) { self->screen_col = line_width; } } else if ((int)(self->screen_col) + x < 0) { - fprintf(stderr, "going off left side"); - if (self->screen_line - 1 >= 0) { + if ((int)self->screen_line - 1 >= 0) { self->screen_line -= 1; self->screen_col = str_len(&self->buffer[self->screen_line]); } @@ -84,8 +64,7 @@ void move_cursor(Editor* self, int x, int y) { } else if (x != 0) { self->screen_col += x; } - fprintf(stderr, "lns %d, line %d, col %d, mode %d", self->lines, self->screen_line, self->screen_col, self->editmode); - move(self->screen_line, self->screen_col); + move(self->screen_line, self->screen_col + 5); } void delchar(Editor* self) { @@ -97,10 +76,20 @@ void addchar(Editor* self, char c) { insch(c); // insert the character into the string at the given index if (self->screen_line == self->lines) { + fprintf(stderr, "buffer full\n"); // reallocate self->buffer to be 1 larger self->lines++; self->buffer = realloc(self->buffer, sizeof(String_t) * (self->lines + 1)); + + // allocate the memory space for the new line and add it to the buffer + self->buffer[self->screen_line] = str_new(); + for (size_t i = 0; i < self->lines; i++) { + fprintf(stderr, "size: %d\n", (&self->buffer[i])->size); + } + + fprintf(stderr, "ok!"); } + str_insert(&self->buffer[self->screen_line], self->screen_col, c); move_cursor(self, 1, 0); } diff --git a/final/log.txt b/final/log.txt index d3f768c..ca0ed9d 100644 --- a/final/log.txt +++ b/final/log.txt @@ -1 +1,19 @@ -BUFFER: (null)3 0 0 0lns 3, line 0, col 0, mode 1line: this is some text to editlns 3, line 0, col 1, mode 1lns 3, line 0, col 1, mode 1line: this is some text to editlns 3, line 0, col 2, mode 1lns 3, line 0, col 2, mode 1line: this is some text to editlns 3, line 0, col 3, mode 1lns 3, line 0, col 3, mode 1line: this is some text to editlns 3, line 0, col 4, mode 1lns 3, line 0, col 4, mode 1line: this is some text to editlns 3, line 0, col 5, mode 1lns 3, line 0, col 5, mode 1line: this is some text to editlns 3, line 1, col 5, mode 1lns 3, line 1, col 5, mode 1line: this is the second linelns 3, line 1, col 4, mode 1lns 3, line 1, col 4, mode 1line: this is the second linelns 3, line 1, col 3, mode 1lns 3, line 1, col 3, mode 1line: this is the second linelns 3, line 1, col 2, mode 1lns 3, line 1, col 2, mode 1line: this is the second linelns 3, line 1, col 1, mode 1lns 3, line 1, col 1, mode 1line: this is the second linelns 3, line 1, col 0, mode 1lns 3, line 1, col 0, mode 1line: this is the second linegoing off left sidelns 3, line 0, col 25, mode 1lns 3, line 0, col 25, mode 1line: this is some text to editlns 3, line 1, col 0, mode 1lns 3, line 1, col 0, mode 1line: this is the second linelns 3, line 1, col 1, mode 1lns 3, line 1, col 1, mode 1line: this is the second linelns 3, line 1, col 2, mode 1lns 3, line 1, col 2, mode 1line: this is the second linelns 3, line 1, col 3, mode 1lns 3, line 1, col 3, mode 1line: this is the second linelns 3, line 1, col 4, mode 1lns 3, line 1, col 4, mode 1line: this is the second linelns 3, line 1, col 5, mode 1lns 3, line 1, col 5, mode 1line: this is the second linelns 3, line 1, col 6, mode 1lns 3, line 1, col 6, mode 1line: this is the second linelns 3, line 1, col 7, mode 1lns 3, line 1, col 7, mode 1line: this is the second linelns 3, line 1, col 8, mode 1lns 3, line 1, col 8, mode 1line: this is the second linelns 3, line 1, col 9, mode 1lns 3, line 1, col 9, mode 1line: this is the second linelns 3, line 1, col 10, mode 1lns 3, line 1, col 10, mode 1line: this is the second linelns 3, line 1, col 11, mode 1lns 3, line 1, col 11, mode 1line: this is the second linelns 3, line 1, col 12, mode 1lns 3, line 1, col 12, mode 1line: this is the second linelns 3, line 1, col 13, mode 1lns 3, line 1, col 13, mode 1line: this is the second linelns 3, line 1, col 14, mode 1lns 3, line 1, col 14, mode 1line: this is the second linelns 3, line 1, col 15, mode 1lns 3, line 1, col 15, mode 1line: this is the second linelns 3, line 1, col 16, mode 1lns 3, line 1, col 16, mode 1line: this is the second linelns 3, line 1, col 17, mode 1lns 3, line 1, col 17, mode 1line: this is the second linelns 3, line 1, col 18, mode 1lns 3, line 1, col 18, mode 1line: this is the second linelns 3, line 1, col 19, mode 1lns 3, line 1, col 19, mode 1line: this is the second linelns 3, line 1, col 20, mode 1lns 3, line 1, col 20, mode 1line: this is the second linelns 3, line 1, col 21, mode 1lns 3, line 1, col 21, mode 1line: this is the second linelns 3, line 1, col 22, mode 1lns 3, line 1, col 22, mode 1line: this is the second linelns 3, line 1, col 23, mode 1lns 3, line 1, col 23, mode 1line: this is the second linelns 3, line 2, col 0, mode 1lns 3, line 2, col 0, mode 1line: (null)lns 3, line 3, col 0, mode 1lns 3, line 3, col 0, mode 1line: (null)lns 3, line 3, col 0, mode 1lns 3, line 3, col 0, mode 1line: (null)lns 3, line 3, col 0, mode 1lns 3, line 3, col 0, mode 1line: (null)lns 3, line 3, col 0, mode 1lns 3, line 3, col 0, mode 1line: (null)going off left sidelns 3, line 2, col 0, mode 1lns 3, line 2, col 0, mode 1line: (null)going off left sidelns 3, line 1, col 23, mode 1lns 3, line 1, col 23, mode 1line: this is the second linelns 3, line 1, col 22, mode 1lns 3, line 1, col 22, mode 1line: this is the second linelns 3, line 1, col 21, mode 1lns 3, line 1, col 21, mode 1line: this is the second linelns 3, line 1, col 20, mode 1lns 3, line 1, col 20, mode 1line: this is the second linelns 3, line 1, col 19, mode 1lns 3, line 1, col 19, mode 1line: this is the second linelns 3, line 1, col 18, mode 1lns 3, line 1, col 18, mode 1line: this is the second linelns 3, line 1, col 17, mode 1lns 3, line 1, col 17, mode 1line: this is the second linelns 3, line 1, col 16, mode 1lns 3, line 1, col 16, mode 1line: this is the second linelns 3, line 1, col 15, mode 1lns 3, line 1, col 15, mode 1line: this is the second linelns 3, line 1, col 14, mode 1lns 3, line 1, col 14, mode 1line: this is the second linelns 3, line 1, col 13, mode 1lns 3, line 1, col 13, mode 1line: this is the second linelns 3, line 1, col 12, mode 1lns 3, line 1, col 12, mode 1line: this is the second linelns 3, line 1, col 11, mode 1lns 3, line 1, col 11, mode 1line: this is the second linelns 3, line 1, col 10, mode 1lns 3, line 1, col 10, mode 1line: this is the second linelns 3, line 1, col 9, mode 1lns 3, line 1, col 9, mode 1line: this is the second linelns 3, line 1, col 8, mode 1lns 3, line 1, col 8, mode 1line: this is the second linelns 3, line 1, col 7, mode 1lns 3, line 1, col 7, mode 1line: this is the second linelns 3, line 1, col 6, mode 1lns 3, line 1, col 6, mode 1line: this is the second linelns 3, line 1, col 5, mode 1lns 3, line 1, col 5, mode 1line: this is the second linelns 3, line 1, col 4, mode 1lns 3, line 1, col 4, mode 1line: this is the second linelns 3, line 1, col 3, mode 1lns 3, line 1, col 3, mode 1line: this is the second linelns 3, line 1, col 2, mode 1lns 3, line 1, col 2, mode 1line: this is the second linelns 3, line 1, col 1, mode 1lns 3, line 1, col 1, mode 1line: this is the second linelns 3, line 1, col 0, mode 1lns 3, line 1, col 0, mode 1line: this is the second linegoing off left sidelns 3, line 0, col 25, mode 1lns 3, line 0, col 25, mode 1line: this is some text to editlns 3, line 0, col 24, mode 1lns 3, line 0, col 24, mode 1line: this is some text to editlns 3, line 0, col 23, mode 1lns 3, line 0, col 23, mode 1line: this is some text to editlns 3, line 0, col 22, mode 1lns 3, line 0, col 22, mode 1line: this is some text to editlns 3, line 0, col 21, mode 1lns 3, line 0, col 21, mode 1line: this is some text to editlns 3, line 0, col 20, mode 1lns 3, line 0, col 20, mode 1line: this is some text to editlns 3, line 0, col 19, mode 1lns 3, line 0, col 19, mode 1line: this is some text to editlns 3, line 0, col 18, mode 1lns 3, line 0, col 18, mode 1line: this is some text to editlns 3, line 0, col 17, mode 1lns 3, line 0, col 17, mode 1line: this is some textš to editlns 3, line 0, col 18, mode 1lns 3, line 0, col 18, mode 1line: this is some textšš to editlns 3, line 0, col 19, mode 1 \ No newline at end of file +buffer full +size: 25 +size: 23 +size: 25 +size: 0 +ok!buffer full +size: 25 +size: 23 +size: 30 +size: 4 +size: 0 +ok!buffer full +size: 25 +size: 23 +size: 30 +size: 4 +size: 1 +size: 0 +ok! \ No newline at end of file diff --git a/final/main.c b/final/main.c index a0c3f25..9036838 100644 --- a/final/main.c +++ b/final/main.c @@ -22,11 +22,8 @@ int open_editor() { int max_y, max_x; getmaxyx(stdscr, max_y, max_x); - move(0, 0); - Editor editor = editor_from("this is some text to edit\nthis is the second line\nand this is the third lol"); - - fprintf(stderr, "%d %d %d %d", editor.lines, editor.screen_line, editor.screen_col, editor.editmode); + move(0, 5); while (true) { refresh(); @@ -37,8 +34,8 @@ int open_editor() { editor.editmode = false; break; case KEY_BACKSPACE: - delchar(&editor); move_cursor(&editor, -1, 0); + delchar(&editor); break; case KEY_DC: delchar(&editor); diff --git a/prototype/src/main.rs b/prototype/src/main.rs index 118f743..299f890 100644 --- a/prototype/src/main.rs +++ b/prototype/src/main.rs @@ -223,6 +223,8 @@ fn open(filename: &str) -> Result<(), &'static str> { ncurses::mv(0, 0); + + loop { ncurses::refresh(); let keystroke = ncurses::getch();