Modified!
This commit is contained in:
parent
4a0558d24f
commit
0aa48c58e2
10
makefile
10
makefile
@ -1,13 +1,13 @@
|
|||||||
# makefile for text.c
|
# makefile for text.c
|
||||||
|
|
||||||
CC=gcc
|
CC=i686-quinn-gcc
|
||||||
CFLAGS=-Wall -g
|
CFLAGS=-Wall
|
||||||
OBJS=text.o page.o line.o prompt.o
|
OBJS=text.o page.o line.o prompt.o
|
||||||
HEADERS=$(subst .o,.h,$(OBJS)) # text.h page.h ...
|
HEADERS=$(subst .o,.h,$(OBJS)) # text.h page.h ...
|
||||||
LIBS=-lncurses
|
LIBS=-lpdcurses -lSDL -lquinn -lfreetype -lpng -lz
|
||||||
|
|
||||||
text: $(OBJS)
|
text: $(OBJS)
|
||||||
$(CC) $(CFLAGS) -o text $(OBJS) $(LIBS)
|
$(CC) $(CFLAGS) -o text.exe $(OBJS) $(LIBS)
|
||||||
|
|
||||||
text.o: text.c $(HEADERS)
|
text.o: text.c $(HEADERS)
|
||||||
$(CC) $(CFLAGS) -c text.c
|
$(CC) $(CFLAGS) -c text.c
|
||||||
@ -24,7 +24,7 @@ page.o: page.c page.h line.h
|
|||||||
cleanall: clean cleantxt
|
cleanall: clean cleantxt
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) text
|
rm -f $(OBJS) text.exe
|
||||||
|
|
||||||
cleantxt:
|
cleantxt:
|
||||||
rm -f *.txt
|
rm -f *.txt
|
||||||
|
2
page.h
2
page.h
@ -2,7 +2,7 @@
|
|||||||
#define PAGE_H
|
#define PAGE_H
|
||||||
/* PAGE struct definition and related functions */
|
/* PAGE struct definition and related functions */
|
||||||
|
|
||||||
#include <ncurses.h> // might have to move this
|
#include <curses.h> // might have to move this
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
|
|
||||||
#define PAGE_SIZE 500 /* Default number of lines */
|
#define PAGE_SIZE 500 /* Default number of lines */
|
||||||
|
2
prompt.h
2
prompt.h
@ -1,7 +1,7 @@
|
|||||||
#ifndef PROMPT_H
|
#ifndef PROMPT_H
|
||||||
#define PROMPT_H
|
#define PROMPT_H
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <curses.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define PROMPT_STRING_LINES 5
|
#define PROMPT_STRING_LINES 5
|
||||||
|
25
text.c
25
text.c
@ -11,7 +11,7 @@
|
|||||||
int y_offset = 0; // TODO: move to local scope
|
int y_offset = 0; // TODO: move to local scope
|
||||||
int tab_offset = 0;
|
int tab_offset = 0;
|
||||||
|
|
||||||
#define DEBUG
|
// #define DEBUG
|
||||||
|
|
||||||
void print_loc(int x, int y)
|
void print_loc(int x, int y)
|
||||||
{
|
{
|
||||||
@ -48,7 +48,7 @@ int main(int argc, char *argv[])
|
|||||||
/* curses interface */
|
/* curses interface */
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
keypad(stdscr, true);
|
keypad(stdscr, 1);
|
||||||
|
|
||||||
int beg = 0;
|
int beg = 0;
|
||||||
int end = WIN_SIZE;
|
int end = WIN_SIZE;
|
||||||
@ -56,19 +56,18 @@ int main(int argc, char *argv[])
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
update_status("Press F4 to quit");
|
update_status(page.filename, "");
|
||||||
|
|
||||||
print_page(&page, beg, end);
|
print_page(&page, beg, end);
|
||||||
getyx(stdscr, y, x);
|
getyx(stdscr, y, x);
|
||||||
|
|
||||||
char status[NAME_LIMIT + 10];
|
while(1)
|
||||||
while(true)
|
|
||||||
{
|
{
|
||||||
print_loc(x, y);
|
print_loc(x, y);
|
||||||
beg = 0 + y_offset;
|
beg = 0 + y_offset;
|
||||||
end = WIN_SIZE + y_offset;
|
end = WIN_SIZE + y_offset;
|
||||||
int ch = getch();
|
int ch = getch();
|
||||||
update_status("Press F4 to quit"); // default text
|
update_status(page.filename, ""); // default text
|
||||||
switch(ch)
|
switch(ch)
|
||||||
{
|
{
|
||||||
case KEY_F(4):
|
case KEY_F(4):
|
||||||
@ -78,15 +77,13 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case KEY_F(5):
|
case KEY_F(5):
|
||||||
save_file(&page);
|
save_file(&page);
|
||||||
sprintf(status, "Saved as \'%s\'", page.filename);
|
update_status(page.filename, "Saved!");
|
||||||
update_status(status);
|
|
||||||
break;
|
break;
|
||||||
case KEY_F(6):
|
case KEY_F(6):
|
||||||
prompt_string("Save As:", page.filename, NAME_LIMIT);
|
prompt_string("Save As:", page.filename, NAME_LIMIT);
|
||||||
save_file(&page);
|
save_file(&page);
|
||||||
sprintf(status, "Saved as \'%s\'", page.filename);
|
|
||||||
print_page(&page, beg, end);
|
print_page(&page, beg, end);
|
||||||
update_status(status);
|
update_status(page.filename, "Saved!");
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
move_up(&page, &x, &y);
|
move_up(&page, &x, &y);
|
||||||
@ -103,6 +100,7 @@ int main(int argc, char *argv[])
|
|||||||
case KEY_DC:
|
case KEY_DC:
|
||||||
case 127: // backspace key...
|
case 127: // backspace key...
|
||||||
case KEY_BACKSPACE:
|
case KEY_BACKSPACE:
|
||||||
|
case '\b':
|
||||||
if(strlen(page.text[y + y_offset].line) == 0)
|
if(strlen(page.text[y + y_offset].line) == 0)
|
||||||
{ // can only delete blank lines for now
|
{ // can only delete blank lines for now
|
||||||
remove_line(&page, y + y_offset);
|
remove_line(&page, y + y_offset);
|
||||||
@ -146,14 +144,17 @@ endnc:
|
|||||||
} // main
|
} // main
|
||||||
|
|
||||||
// prints a message at the bottom of the window
|
// prints a message at the bottom of the window
|
||||||
void update_status(char *info)
|
void update_status(char *filename, char *info)
|
||||||
{
|
{
|
||||||
int oldy, oldx; getyx(stdscr, oldy, oldx);
|
int oldy, oldx; getyx(stdscr, oldy, oldx);
|
||||||
|
char status[81];
|
||||||
|
|
||||||
|
snprintf(status, 80, "F4: Quit F5: Save F6: Save As File: %-25.25s %s", filename, info);
|
||||||
|
|
||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
move(LINES - 1, 0);
|
move(LINES - 1, 0);
|
||||||
clrtoeol();
|
clrtoeol();
|
||||||
printw(info);
|
printw(status);
|
||||||
attroff(A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
|
|
||||||
move(oldy, oldx);
|
move(oldy, oldx);
|
||||||
|
4
text.h
4
text.h
@ -5,12 +5,12 @@
|
|||||||
#include <stdlib.h> // declared in line.h
|
#include <stdlib.h> // declared in line.h
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h> // declared in line.h
|
#include <string.h> // declared in line.h
|
||||||
#include <ncurses.h> // -lncurses. declared in page.h
|
#include <curses.h> // -lncurses. declared in page.h
|
||||||
|
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
|
|
||||||
void update_status(char *info);
|
void update_status(char *filename, char *info);
|
||||||
|
|
||||||
int count_lines(FILE *fp);
|
int count_lines(FILE *fp);
|
||||||
void load_file(PAGE *p, char* filename);
|
void load_file(PAGE *p, char* filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user