X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=visor;a=blobdiff_plain;f=visor%2Fsrc%2Fmain_unix.c;h=64302728b3d6b5c5da102ce0bf0031641f2899e3;hp=37406a0d3206d802c1502e659220cde9be4a0eb2;hb=7357e1f153279a9d84d8671f02fa146575d4935e;hpb=05b4673efbeb372387b0a9359af5046afb87c8cf diff --git a/visor/src/main_unix.c b/visor/src/main_unix.c index 37406a0..6430272 100644 --- a/visor/src/main_unix.c +++ b/visor/src/main_unix.c @@ -1,95 +1,181 @@ #include -#include -#include -#include -#include -#include -#include +#include +#include "term.h" +#include "visor.h" +struct file { + FILE *fp; + void *maddr; + size_t msize; +}; + +static int parse_args(int argc, char **argv); static int init(void); static void cleanup(void); -static void sighandler(int s); - -int term_width, term_height; -int ttyfd; -struct termios saved_term; +/* file operations */ +static vi_file *file_open(const char *path, unsigned int flags); +static void file_close(vi_file *file); +static long file_size(vi_file *file); +static void *file_map(vi_file *file); +static void file_unmap(vi_file *file); +static long file_read(vi_file *file, void *buf, long count); +static long file_write(vi_file *file, void *buf, long count); +static long file_seek(vi_file *file, long offs, int whence); + +static struct visor *vi; + +static int num_fpaths; +static char **fpaths; + +static struct vi_alloc alloc = { + malloc, free, realloc +}; + +static struct vi_fileops fops = { + file_open, file_close, file_size, + file_map, file_unmap, + file_read, file_write, file_seek +}; + +/* +static struct vi_ttyops ttyops = { + tty_clear, tty_clear_line, tty_clear_line_at, + tty_setcursor, tty_putchar, tty_putchar_at, + tty_scroll, tty_del_back, tty_del_fwd, tty_status +}; +*/ int main(int argc, char **argv) { - int res; - char c; - + if(parse_args(argc, argv) == -1) { + return 1; + } if(init() == -1) { return 1; } for(;;) { - if((res = read(ttyfd, &c, 1)) == 0 || (res < 0 && errno != EINTR)) { - break; + int c = term_getchar(); + + switch(c) { + case 27: + case 'q': + goto end; } - /* proc input */ } +end: cleanup(); return 0; } +static int parse_args(int argc, char **argv) +{ + int i; + + fpaths = argv + 1; + num_fpaths = 0; + for(i=1; ifp = fopen(path, attr))) { + free(file); + return 0; + } + return file; +} + +static void file_close(vi_file *file) +{ +} + +static long file_size(vi_file *file) +{ + return -1; +} + +static void *file_map(vi_file *file) +{ + return 0; +} + +static void file_unmap(vi_file *file) +{ +} + +static long file_read(vi_file *file, void *buf, long count) +{ + return -1; +} + +static long file_write(vi_file *file, void *buf, long count) +{ + return -1; +} + +static long file_seek(vi_file *file, long offs, int whence) +{ + return -1; }