From 82a7c12e8338288ccb40d213fcc9e15d102aa968 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Thu, 1 Aug 2019 16:42:36 +0100 Subject: remove trailing blank lines in write_file - change check_bound --- draw.c | 33 +++++++++++++++++---------------- files.c | 14 +++++++++++--- gramscii.h | 6 ++++-- lineset.c | 9 +++++++-- main.c | 2 +- screen.c | 14 +++++++------- 6 files changed, 47 insertions(+), 31 deletions(-) diff --git a/draw.c b/draw.c index ae90458..1c383fa 100644 --- a/draw.c +++ b/draw.c @@ -94,7 +94,7 @@ void get_text(FILE *fc){ if (x >= WIDTH) x = orig_x; } - check_bound(); + check_bound(&x, &y); status_bar(); show_cursor(); } @@ -150,7 +150,7 @@ void get_box(FILE *fc){ goto update_box; if (!move_around(c, fc)) continue; - check_bound(); + check_bound(&x, &y); redraw(); step = 1; update_box: @@ -166,19 +166,19 @@ update_box: mode = MOVE; } -void draw_arrow(int x, int y, char *a, int a_len, int fix){ +void draw_arrow(int xl, int yl, char *a, int a_len, int fix){ int i, j, cur_dir; char line; void (*f)(int, int, char); - a_miny = a_maxy = y; + a_miny = a_maxy = yl; if (fix == FIX) f = set_xy; else f = draw_xy; - f(x,y,mark_st); + f(xl, yl, mark_st); if (!a_len){ show_cursor(); return; @@ -189,27 +189,28 @@ void draw_arrow(int x, int y, char *a, int a_len, int fix){ /* If we are switching between horizontal and vertical, put a "corner" */ if (((cur_dir & DIR_HOR) && (a[i] & DIR_VER)) || ((cur_dir & DIR_VER) && (a[i] & DIR_HOR))){ - f(x,y,corner); + f(xl, yl, corner); show_cursor(); } } for(j=0; j a_maxy) a_maxy = y; - f(x, y, line); + xl += progr_x(a[i]); + yl += progr_y(a[i]); + check_bound(&xl, &yl); + if (yl < a_miny) a_miny = yl; + if (yl > a_maxy) a_maxy = yl; + f(xl, yl, line); } /* f(x,y,mark_end);*/ cur_dir = a[i]; } if (autoend){ if (cur_dir != DIR_N) - f(x,y, get_mark(cur_dir)); + f(xl,yl, get_mark(cur_dir)); } else - f(x,y,mark_end); + f(xl,yl,mark_end); show_cursor(); } @@ -235,7 +236,7 @@ void get_arrow(FILE *fc){ goto update_arrow; if (!move_around(c, fc)) continue; - check_bound(); + check_bound(&x, &y); /* FIXME: if we are out of bound, do nothing? */ if (arrow_len == arrow_sz){ arrow_sz *=2; @@ -289,7 +290,7 @@ void erase(FILE *fc){ show_cursor(); while((c=fgetc(fc))!=EOF && c!=27 && c!= 'x' && c != '\n'){ if (!move_around(c, fc)) continue; - check_bound(); + check_bound(&x, &y); if (first || (y != orig_y && ! opened) || (y == orig_y && x != orig_x && !opened) ){ @@ -354,7 +355,7 @@ void visual_box(FILE *fc){ goto vis_exit; break; } - check_bound(); + check_bound(&x, &y); set_video(VIDEO_NRM); redraw(); step = 1; diff --git a/files.c b/files.c index 17743a5..dfeb3b2 100644 --- a/files.c +++ b/files.c @@ -7,7 +7,7 @@ void write_file(FILE *fc){ FILE *fout; - int i; + int i, ne; if (!fname[0] || force_new){ get_string(fc, "Write to: ", fname, 255); @@ -23,8 +23,16 @@ void write_file(FILE *fc){ get_key(fc, "Error opening file."); return; } + ne = 0; for (i=0; i= undo_sz - 1){ - undo_sz += 10; - tmp = realloc(undo, undo_sz * sizeof(lineset_t)); + tmp = realloc(undo, (undo_sz + 10) * sizeof(lineset_t)); if (tmp == NULL){ fprintf(stderr, "Error allocating undo buffer"); exit(1); } undo = tmp; + for (i=0; i<10; i++){ + undo[undo_sz + i].sz = 0; + undo[undo_sz + i].l = NULL; + undo[undo_sz + i].num = 0; + } + undo_sz += 10; } ensure_num_lines(&(undo[idx]), y2 - y1 + 1); for(i=y1; i<=y2; i++){ diff --git a/main.c b/main.c index 4118ecc..ea8a4fc 100644 --- a/main.c +++ b/main.c @@ -135,7 +135,7 @@ void commands(FILE *fc){ break; } } - check_bound(); + check_bound(&x, &y); status_bar(); show_cursor(); step = 1; diff --git a/screen.c b/screen.c index c27ab8b..8e1b8bc 100644 --- a/screen.c +++ b/screen.c @@ -196,11 +196,11 @@ void erase_screen(){ erase_line(i); } -void check_bound(){ - if (x<0) x=0; - else if (x>=WIDTH) x = WIDTH-1; - if (y<0) y=0; - else if (y>=HEIGHT) y = HEIGHT -1; +void check_bound(int *x, int *y){ + if (*x<0) *x=0; + else if (*x>=WIDTH) *x = WIDTH-1; + if (*y<0) *y=0; + else if (*y>=HEIGHT) *y = HEIGHT -1; } void reset_styles(){ @@ -242,7 +242,7 @@ void go_to(int where){ y = HEIGHT/2; break; } - check_bound(); + check_bound(&x, &y); show_cursor(); } @@ -279,7 +279,7 @@ void handle_goto(){ go_to(MIDDLE); break; } - check_bound(); + check_bound(&x, &y); show_cursor(); } -- cgit v1.2.3