89 lines
1.3 KiB
C
89 lines
1.3 KiB
C
/* $Id: catpoint.c,v 1.2 2013/03/28 12:00:48 lostd Exp $ */
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
|
|
#include <err.h>
|
|
#include <curses.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
int c, i, fd;
|
|
char **p; /* the slides */
|
|
|
|
if (argc == 1)
|
|
errx(1, "usage: %s file ...", argv[0]);
|
|
argv++;
|
|
argc--;
|
|
|
|
p = calloc(argc, sizeof(char *));
|
|
|
|
/* map files to mem */
|
|
for (i = 0; argv[i] != NULL; i++) {
|
|
fd = open(argv[i], O_RDONLY, 0);
|
|
if (fd == -1)
|
|
err(1, "open: %s", argv[i]);
|
|
p[i] = mmap(NULL, 0x1000, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
if (p[i] == MAP_FAILED)
|
|
err(1, "mmap");
|
|
close(fd);
|
|
}
|
|
|
|
/* init curses */
|
|
initscr();
|
|
cbreak();
|
|
noecho();
|
|
nonl();
|
|
intrflush(stdscr, FALSE);
|
|
keypad(stdscr, TRUE);
|
|
curs_set(FALSE); /* hide cursor */
|
|
|
|
/* start */
|
|
i = 0;
|
|
show:
|
|
/* display slide */
|
|
clear();
|
|
printw(p[i]);
|
|
again:
|
|
c = getch();
|
|
switch (c) {
|
|
case 'q':
|
|
break;
|
|
/* next */
|
|
case 'l':
|
|
case 'j':
|
|
case KEY_RIGHT:
|
|
case KEY_DOWN:
|
|
if (i < argc - 1) {
|
|
i++;
|
|
goto show;
|
|
}
|
|
goto again;
|
|
/* prev */
|
|
case 'h':
|
|
case 'k':
|
|
case KEY_LEFT:
|
|
case KEY_UP:
|
|
if (i > 0) {
|
|
i--;
|
|
goto show;
|
|
}
|
|
goto again;
|
|
default:
|
|
goto again;
|
|
}
|
|
|
|
/* unmap mem */
|
|
for (i = 0; argv[i] != NULL; i++)
|
|
munmap(p[i], 0x1000);
|
|
|
|
endwin(); /* restore terminal */
|
|
|
|
return (0);
|
|
}
|