Old bug fixes that I never commited.

Also added a .gitignore and modified the readme.
This commit is contained in:
Mazar Farran 2015-08-18 19:03:55 -07:00
parent 00cd082403
commit fe910b6e31
5 changed files with 47 additions and 9 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.out
*.o
*.txt
text

View File

@ -2,7 +2,23 @@ Text Editor
===========
I learned ncurses and figured why not.
Posting this now (9/30) because school is starting
Posting this now (9/30/15) because school is starting
so I don't plan on working on it anymore.
Probably the most well-developed program I made this summer.
How to use:
F4 quits (no prompt)
F5 saves the current file as save.txt
Current issues:
x-y coordinates in ncurses correspond to rows and columns in
the text document. This means tabs are an issue and text
wrapping is impossible. Solution: separate screen logic
from document logic.
Can only save files under the name save.txt. Solution: create
a prompt window (from scratch...) that retuns a string to the
caller.

View File

@ -2,17 +2,20 @@
CC=gcc
CFLAGS=-Wall -g
OBJS=line.o page.o
OBJS=text.o page.o line.o
LIBS=-lncurses
text: text.c text.h $(OBJS)
$(CC) $(CFLAGS) -o text text.c $(OBJS) $(LIBS)
line.o: line.c line.h
$(CC) $(CFLAGS) -c line.c
text: $(OBJS)
$(CC) $(CFLAGS) -o text $(OBJS) $(LIBS)
text.o: text.c text.h page.h line.h
$(CC) $(CFLAGS) -c text.c
page.o: page.c page.h line.h
$(CC) $(CFLAGS) -c page.c
line.o: line.c line.h
$(CC) $(CFLAGS) -c line.c
clean:
rm -f $(OBJS) text

6
page.c
View File

@ -85,6 +85,12 @@ void print_page(const PAGE *p, int start, int end)
clrtoeol();
printw(" %s", p->text[i].line);
}
if(start < end)
{
move(line, 0);
clrtoeol(); // if we deleted a line this may be necessary
move(line-1, 1);
}
refresh();
} // print_page

13
text.c
View File

@ -9,6 +9,7 @@
**/
int y_offset = 0; // TODO: move to local scope
int tab_offset = 0;
#define DEBUG
@ -143,7 +144,14 @@ void move_left(int *x, int *y)
void move_right(PAGE *p, int *x, int *y)
{
if(*x <= strlen(p->text[*y + y_offset].line)) move(*y, ++(*x));
if(*x <= strlen(p->text[*y + y_offset].line))
{
if(p->text[*y + y_offset].line[*x + tab_offset] == '\t') {
move(*y, ++(*x));
} else {
move(*y, ++(*x));
}
}
}
void move_up(PAGE *p, int *x, int *y)
@ -187,7 +195,8 @@ int count_lines(int argc, char **argv)
while((ch = fgetc(fp)) != EOF)
if( ch == '\n' )
count++;
fclose(fp);
return count;
} // count_lines