URI: 
       fix bug in screen init - gramscii - A simple editor for ASCII box-and-arrow charts
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit a64ca9d14f8c197398badad39148b794757742b2
   DIR parent c9a6b0faecb76984eb51754f6d188a87be025e8f
  HTML Author: KatolaZ <katolaz@freaknet.org>
       Date:   Mon, 22 Jul 2019 18:14:51 +0100
       
       fix bug in screen init
       
       Diffstat:
         M gramscii.c                          |      34 ++++++++++++++++++++-----------
       
       1 file changed, 22 insertions(+), 12 deletions(-)
       ---
   DIR diff --git a/gramscii.c b/gramscii.c
       @@ -51,6 +51,8 @@
        #define MIN(x,y)  (x) < (y) ? (x) : (y)
        #define MAX(x,y)  (x) > (y) ? (x) : (y)
        
       +#define DEBUG 1
       +
        char **screen;
        int WIDTH, HEIGHT;
        
       @@ -129,6 +131,9 @@ void status_bar(){
                        printf(" [%s]", fname );
                else
                        printf(" *%s*", fname );
       +#ifdef DEBUG
       +        printf("  '%d'  ", screen[y][x]);
       +#endif
                printf("\033[0m");
        }
        
       @@ -168,7 +173,7 @@ void show_cursor(){
                printf("\033[%d;%df", y+1, x+1);
        }
        
       -void set(char c){
       +void set_cur(char c){
                screen[y][x] = c;
        }
        
       @@ -190,7 +195,8 @@ void update_current(){
        
        void erase_line(char *s){
                while(*s){
       -                *s++ = BG;
       +                *s = BG;
       +                s++;
                }
        }
        
       @@ -214,7 +220,6 @@ void erase_screen(){
                        erase_line(screen[i]);
        }
        
       -
        void check_bound(){
                if (x<0) x=0;
                else if (x>=WIDTH) x = WIDTH-1;
       @@ -232,10 +237,8 @@ void reset_styles(){
                line_v = vlines[cur_vl];
                mark_st = st_marks[cur_start];
                mark_end = end_marks[cur_end];
       -
        }
        
       -
        void redraw(){
                int i;
        
       @@ -302,7 +305,6 @@ void handle_goto(){
                show_cursor();
        }
        
       -
        int move_around(char c){
        
                switch(c){
       @@ -421,12 +423,12 @@ void get_text(){
                redraw();
                while((c=getchar())!=EOF && c != 27){
                        if(c=='\n'){
       -                        set(BG);
       +                        set_cur(BG);
                                y += 1;
                                x = orig_x;
                        }
                        else {
       -                        set(c);
       +                        set_cur(c);
                                update_current();
                                modified = 1;
                                x += 1;
       @@ -735,18 +737,26 @@ void init_screen(){
                struct winsize wsz;
                
                if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz)){
       -                WIDTH=wsz.ws_col;
       +                WIDTH=wsz.ws_col - 2;
                        HEIGHT=wsz.ws_row - 1;
                }
                else {
       -                WIDTH=8;
       +                WIDTH=80;
                        HEIGHT=24;
                }
                screen = malloc(HEIGHT * sizeof(char *));
       +        if (screen == NULL){
       +                perror("allocating screen");
       +                exit(1);
       +        }
                for (i=0; i<HEIGHT; i++){
                        screen[i] = malloc((WIDTH+1) * sizeof(char));
       -                memset(screen[i], 32, WIDTH);
       -                screen[WIDTH]='\0';
       +                if (screen[i] == NULL){
       +                        perror("allocating screen[i]");
       +                        exit(1);
       +                }
       +                memset(screen[i], ' ', WIDTH * sizeof(char));
       +                screen[i][WIDTH]='\0';
                }
                reset_styles();
        }