struct te_buffer* load_buffer(char *filename)
{
- FILE *fp = fopen(filename, "r");
-
- if (fp == NULL)
- fail("Unable to open %s", filename);
-
+
struct te_buffer *b = alloc_and_insert_buffer();
b->name = strdup(filename);
if (b->contents == NULL)
fail("Unable to allocate memory for buffer contents");
- if (breada(b->contents, (bNread) &fread, fp) != 0)
- fail("Unable to read file contents");
+ FILE *fp = fopen(filename, "r");
- statusprintf("%s", filename);
+ if (fp == NULL) {
+ miniprintf("Creating an empty buffer");
+ } else {
+ if (breada(b->contents, (bNread) &fread, fp) != 0)
+ fail("Unable to read file contents");
+
+ fclose(fp);
+ }
return b;
}
fwrite(c, strlen(c), sizeof(char), fp);
+ fclose(fp);
free(c);
}
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
-
+ puts("");
fflush(stdout);
exit(EXIT_FAILURE);
}
void input_loop(void)
{
while(1) {
+
int c = getch();
if (command_mode)
*/
#include <stdio.h>
+#include <stdlib.h>
#include <curses.h>
#include "interp.h"
#include "screen.h"
void init_interp(void);
+void cmdline_help(void);
extern struct te_buffer *current_buf;
int main(int argc, char **argv)
{
init_buffers();
- init_windows();
- if (argc != 1)
- current_buf = load_buffer(argv[1]);
+ if (argc > 1)
+ for (argv++; *argv != NULL ; argv++)
+ current_buf = load_buffer(*argv);
else
- current_buf = load_buffer("tests/bufferfuncs.c");
+ cmdline_help();
- load_buffer("README");
- load_buffer("main.c");
-
+ init_windows();
paint_buffer(current_buf);
+ statusprintf("%s", current_buf->name);
+
refresh();
input_loop();
}
+void cmdline_help(void)
+{
+ puts("te file1 file2");
+ exit(EXIT_SUCCESS);
+}
/* mvwaddstr(buffer_win, y, screen_abs++, "\\n"); */
/* screen_abs++; */
/* mvwaddch(buffer_win, y, screen_abs++, '\n'); */
-/* } */ else {
+ /* } */
+ else if (i == COLS - 1) {
+ mvwaddch(buffer_win, y, screen_abs, '\\');
+ screen_next_line(current_buf);
+ } else {
mvwaddch(buffer_win, y, screen_abs, bchar(s, i));
screen_abs++;
}
buf->x = screen_line_length(s, 0);
move(buf->y, buf->x);
} else {
- bstring s = current_line_as_bstring(buf->contents, buf->point);
+ bstring s = current_line_as_bstring(buf->contents, buf->point - 1);
draw_line(s, buf->y);
screen_move_left(buf);
move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
}
wrefresh(status_win);
-
restoreyx();
}