12 static int parse_args(int argc, char **argv);
13 static int init(void);
14 static void cleanup(void);
16 static vi_file *file_open(const char *path, unsigned int flags);
17 static void file_close(vi_file *file);
18 static long file_size(vi_file *file);
19 static void *file_map(vi_file *file);
20 static void file_unmap(vi_file *file);
21 static long file_read(vi_file *file, void *buf, long count);
22 static long file_write(vi_file *file, void *buf, long count);
23 static long file_seek(vi_file *file, long offs, int whence);
25 static struct visor *vi;
27 static int num_fpaths;
30 static struct vi_alloc alloc = {
34 static struct vi_fileops fops = {
35 file_open, file_close, file_size,
37 file_read, file_write, file_seek
41 static struct vi_ttyops ttyops = {
42 tty_clear, tty_clear_line, tty_clear_line_at,
43 tty_setcursor, tty_putchar, tty_putchar_at,
44 tty_scroll, tty_del_back, tty_del_fwd, tty_status
48 int main(int argc, char **argv)
50 if(parse_args(argc, argv) == -1) {
58 int c = term_getchar();
72 static int parse_args(int argc, char **argv)
78 for(i=1; i<argc; i++) {
79 if(argv[i][0] == '-') {
80 fprintf(stderr, "invalid option: %s\n", argv[i]);
83 argv[++num_fpaths] = argv[i];
93 if(term_init(0) == -1) {
98 if(!(vi = vi_create(&alloc))) {
101 vi_set_fileops(vi, &fops);
103 for(i=0; i<num_fpaths; i++) {
109 static void cleanup(void)
117 static vi_file *file_open(const char *path, unsigned int flags)
122 switch(flags & 0xff) {
128 attr = (flags & VI_CREAT) ? "w+b" : "wb";
132 attr = (flags & VI_CREAT) ? "w+b" : "r+b";
140 if(!(file = calloc(1, sizeof *file))) {
143 if(!(file->fp = fopen(path, attr))) {
150 static void file_close(vi_file *file)
154 static long file_size(vi_file *file)
159 static void *file_map(vi_file *file)
164 static void file_unmap(vi_file *file)
168 static long file_read(vi_file *file, void *buf, long count)
173 static long file_write(vi_file *file, void *buf, long count)
178 static long file_seek(vi_file *file, long offs, int whence)