From 99b2eac9248697be3b5f518b3740090d400162cd Mon Sep 17 00:00:00 2001 From: Mazar Farran Date: Fri, 28 Aug 2015 21:15:50 -0700 Subject: [PATCH] fixed tabs, cleaned up a bit --- line.h | 1 - page.h | 2 +- text.c | 27 +++++++++++++-------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/line.h b/line.h index a45bbfe..8188dce 100644 --- a/line.h +++ b/line.h @@ -11,7 +11,6 @@ typedef struct { char *line; - int tabs; // keeps track of tabs so we can offset int size; // size of array, not string } LINE; diff --git a/page.h b/page.h index 1efdecb..62b5791 100644 --- a/page.h +++ b/page.h @@ -5,7 +5,7 @@ #include // might have to move this #include "line.h" -#define PAGE_SIZE 500 /* Max number of lines. Currently not expandable. */ +#define PAGE_SIZE 500 /* Default number of lines */ #define WIN_SIZE (LINES - 2) /* Size of window, making room for bottom prompt */ #define NAME_LIMIT 256 /* Max size of a unix filename + 1 */ diff --git a/text.c b/text.c index a8f6b29..49f2a05 100644 --- a/text.c +++ b/text.c @@ -226,25 +226,24 @@ void load_file(int argc, char **argv, PAGE *p) int line;//, col; init_page(p, argv[1], size); - /*for(line = 0; line < PAGE_SIZE && ch != EOF; line++) - { - for(col = 0; - col < LINE_SIZE - 1 && ((ch = fgetc(fp)) != '\n') && ch != EOF; - col++) - { - p->text[line].line[col] = ch; - } - p->text[line].line[col] = '\0'; - p->numlines++; - }*/ - - for(line = 0; line < PAGE_SIZE && ch != EOF; line++) + for(line = 0; line < size && ch != EOF; line++) { ch = fgetc(fp); while(ch != '\n' && ch != EOF) { LINE *currline = &(p->text[line]); - add_char(currline, ch); + if(ch != '\t') + { + add_char(currline, ch); + } + else // tab. add 4 spaces instead + { + int i; + for(i = 0; i < TAB_WIDTH; i++) + { + add_char(currline, ' '); + } + } ch = fgetc(fp); } p->numlines++;