bstrlib.o: bstrlib.c
$(CC) $(CFLAGS) bstrlib.c
-clean:
+clean:
rm $(OBJS)
- rm *~
- rm te
\ No newline at end of file
+ rm te
#define START_VSNBUFF (256)\r
#else\r
\r
-#ifdef __GNUC__\r
-/* Something is making gcc complain about this prototype not being here, so \r
- I've just gone ahead and put it in. */\r
-extern int vsnprintf (char *buf, size_t count, const char *format, va_list arg);\r
-#endif\r
-\r
#define exvsnprintf(r,b,n,f,a) {r = vsnprintf (b,n,f,a);}\r
#endif\r
#endif\r
#include <curses.h>
#include "zalloc.h"
-#include "error.h"
+#include "errors.h"
#include "buffer.h"
#include "interp.h"
#include "util.h"
+#include "screen.h"
+
void init_buffers(void)
{
struct te_buffer* search_buffer(char *name)
{
if (name == NULL)
- return;
+ return NULL;
struct te_buffer *b;
TAILQ_FOREACH(b, &buffers_head, buffers) {
if (strcmp(name, b->name) == 0)
return b;
}
+
+ return NULL;
}
struct te_buffer* load_buffer(char *filename)
fail("Unable to allocate memory for buffer contents");
FILE *fp = fopen(filename, "r");
-
+
if (fp == NULL) {
miniprintf("Creating an empty buffer");
} else {
int screen_numchar_to_offset(bstring s, int x)
{
int i = 0;
-
+
for (i = 0; i < x; i++)
if (bchar(s, i) == '\t')
i += TAB_LEN;
else
i += 1;
+
+ return i;
}
/*
The length of a line as displayed on the screen.
int prev_char(struct te_buffer *buf)
{
if (buf == NULL)
- return;
+ return -1;
return bchar(buf->contents, buf->point - 1);
}
int curr_char(struct te_buffer *buf)
{
if (buf == NULL)
- return;
+ return -1;
return bchar(buf->contents, buf->point);
}
int next_char(struct te_buffer *buf)
{
if (buf == NULL)
- return;
+ return -1;
return bchar(buf->contents, buf->point + 1);
}
int move_left(struct te_buffer *buf)
{
if (buf == NULL)
- return;
+ return -1;
if (buf->point > 0) {
buf->point--;
int move_right(struct te_buffer *buf)
{
if (buf == NULL)
- return;
+ return -1;
if (buf->point < blength(buf->contents)) {
buf->point++;
void insert_char(struct te_buffer *buf, char c);
void delete_char(struct te_buffer *buf);
int is_last_line(bstring s, int point);
+void write_buffer(struct te_buffer *buf);
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
+#include <curses.h>
void fail(char *fmt, ...);
while(1) {
int c = getch();
-
- if (command_mode)
+
+ if (command_mode) {
process_command(c);
- else
+ } else {
process_input(c);
+ }
refresh();
#include <curses.h>
#include "interp.h"
#include "screen.h"
+#include "keyb.h"
void init_interp(void);
void cmdline_help(void);
init_windows();
init_buffers();
- for (argv++; *argv != NULL ; argv++)
+ for (argv++; *argv != NULL ; argv++)
current_buf = load_buffer(*argv);
-
paint_buffer(current_buf);
statusprintf("%s", current_buf->name);
#include "screen.h"
#include "util.h"
#include "keyb.h"
+#include "errors.h"
#define saveyx() { int scr_y, scr_x; getyx(stdscr, scr_y, scr_x); do { } while(0)
saveyx();
move(y, 0);
clrtoeol();
-
+
/* FIXME : wrap line if we go beyond COLS */
for (i = 0; i < blength(s); i++) {
if (i == COLS - 1) {
goto bail_out;
return;
}
-
+
if (bchar(s, i) == '\t') {
for (j = 0; j < TAB_LEN; j++)
mvwaddch(buffer_win, y, screen_abs++, ' ');
screen_abs++;
}
}
-
+
bail_out:
restoreyx();
}
if(move_left(buf) == ERR)
return ERR;
-
if (curr_char(buf) == '\n') {
screen_prev_line(buf);
buf->x = screen_line_length(buf->contents, buf->point);
- } else {
- if (buf->x > 0)
+ } else {
+ if (buf->x > 0) {
if (curr_char(buf) == '\t') {
buf->x -= TAB_LEN;
} else {
buf->x--;
}
+ }
}
move(buf->y, buf->x);
if (prev_char(buf) == '\n') {
screen_next_line(buf);
- } else {
+ } else {
/* tab is the only character larger than 1 */
if (prev_char(buf) == '\t') {
buf->x += TAB_LEN;
buf->x++;
}
- if(buf->x == COLS - 1) {
+ if(buf->x == COLS - 1) {
bstring s = current_line_as_bstring(buf->contents, buf->point);
int off = screen_numchar_to_offset(s, COLS - 1);
bstring s2 = bmidstr(s, off, blength(s) - off);
int screen_move_right(struct te_buffer *buf);
void screen_move_up(struct te_buffer *buf);
void screen_move_down(struct te_buffer *buf);
+void screen_delete_char(struct te_buffer *buf);
+void screen_insert_char(struct te_buffer *buf, char c);
void statusprintf(char *fmt, ...);
void miniprintf(char *fmt, ...);