2020-12-20 14:38:14 +01:00
|
|
|
/* See LICENSE file for license details. */
|
2015-08-27 23:54:58 +02:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2020-05-04 12:51:49 +02:00
|
|
|
#include <sys/stat.h>
|
2015-08-27 23:54:58 +02:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <curses.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <locale.h>
|
2018-07-08 14:54:37 +02:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
char **p; /* the slides */
|
|
|
|
int n; /* the number of slides */
|
|
|
|
|
2018-07-08 14:59:13 +02:00
|
|
|
void
|
2020-12-20 14:41:04 +01:00
|
|
|
cleanup(int sig)
|
2018-07-08 14:54:37 +02:00
|
|
|
{
|
|
|
|
int i;
|
2020-12-20 11:44:12 +01:00
|
|
|
|
2020-12-20 14:40:03 +01:00
|
|
|
for (i = 0; i < n; i++)
|
2018-07-08 14:54:37 +02:00
|
|
|
munmap(p[i], 0x1000);
|
|
|
|
|
|
|
|
endwin(); /* restore terminal */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-12-20 11:44:12 +01:00
|
|
|
void
|
|
|
|
reload(char **argv, int i)
|
|
|
|
{
|
|
|
|
struct stat statbuf;
|
|
|
|
int fd;
|
|
|
|
|
2020-12-20 14:34:51 +01:00
|
|
|
if (p[i] != NULL) {
|
|
|
|
if (munmap(p[i], 0x1000) < 0)
|
|
|
|
err(1, "munmap: %s", argv[i]);
|
|
|
|
}
|
2020-12-20 11:44:12 +01:00
|
|
|
|
|
|
|
fd = open(argv[i], O_RDONLY, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
err(1, "open: %s", argv[i]);
|
|
|
|
if (fstat(fd, &statbuf) < 0)
|
|
|
|
err(1, "fstat: %s", argv[i]);
|
|
|
|
p[i] = mmap(NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
if (p[i] == MAP_FAILED)
|
|
|
|
err(1, "mmap");
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2018-07-08 14:54:37 +02:00
|
|
|
void
|
|
|
|
setsignal()
|
|
|
|
{
|
|
|
|
signal(SIGHUP, cleanup);
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
signal(SIGQUIT, cleanup);
|
|
|
|
signal(SIGABRT, cleanup);
|
|
|
|
signal(SIGKILL, cleanup);
|
|
|
|
signal(SIGTERM, cleanup);
|
|
|
|
}
|
|
|
|
|
2015-08-27 23:54:58 +02:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2020-12-20 11:44:12 +01:00
|
|
|
int c, i;
|
2015-08-27 23:54:58 +02:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
errx(1, "usage: %s file ...", argv[0]);
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
|
2018-07-08 14:54:37 +02:00
|
|
|
setsignal();
|
2015-08-27 23:54:58 +02:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
|
|
|
p = calloc(argc, sizeof(char *));
|
2018-07-08 14:54:37 +02:00
|
|
|
n = argc;
|
2015-08-27 23:54:58 +02:00
|
|
|
|
|
|
|
/* map files to mem */
|
2020-12-20 11:44:12 +01:00
|
|
|
for (i = 0; argv[i] != NULL; i++)
|
|
|
|
reload(argv, i);
|
2015-08-27 23:54:58 +02:00
|
|
|
|
|
|
|
/* init curses */
|
|
|
|
initscr();
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
|
|
|
nonl();
|
|
|
|
intrflush(stdscr, FALSE);
|
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
curs_set(FALSE); /* hide cursor */
|
|
|
|
|
|
|
|
/* start */
|
|
|
|
i = 0;
|
|
|
|
show:
|
|
|
|
/* display slide */
|
|
|
|
clear();
|
2020-12-20 11:44:12 +01:00
|
|
|
refresh();
|
2015-08-27 23:54:58 +02:00
|
|
|
printw("%s", p[i]);
|
|
|
|
again:
|
|
|
|
c = getch();
|
|
|
|
switch (c) {
|
2017-03-04 16:49:33 +01:00
|
|
|
/* powerpoint remote presenter shortcuts */
|
|
|
|
case 27:
|
|
|
|
case KEY_F(5):
|
|
|
|
/* end presentation */
|
2015-08-27 23:54:58 +02:00
|
|
|
case 'q':
|
|
|
|
break;
|
|
|
|
/* next */
|
|
|
|
case 'l':
|
|
|
|
case 'j':
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case KEY_DOWN:
|
|
|
|
case KEY_NPAGE:
|
|
|
|
if (i < argc - 1) {
|
|
|
|
i++;
|
|
|
|
goto show;
|
|
|
|
}
|
|
|
|
goto again;
|
|
|
|
/* prev */
|
|
|
|
case 'h':
|
|
|
|
case 'k':
|
|
|
|
case KEY_LEFT:
|
|
|
|
case KEY_UP:
|
|
|
|
case KEY_PPAGE:
|
|
|
|
if (i > 0) {
|
|
|
|
i--;
|
|
|
|
goto show;
|
|
|
|
}
|
|
|
|
goto again;
|
2017-03-04 16:49:33 +01:00
|
|
|
/* shortcut from powerpoint. Needed for remote presenters. */
|
|
|
|
case '.':
|
2015-08-27 23:54:58 +02:00
|
|
|
/* first */
|
|
|
|
case 'u':
|
|
|
|
case KEY_BEG:
|
2017-02-26 17:21:51 +01:00
|
|
|
case KEY_HOME:
|
2015-08-27 23:54:58 +02:00
|
|
|
i = 0;
|
|
|
|
goto show;
|
|
|
|
/* last */
|
|
|
|
case 'i':
|
|
|
|
case KEY_END:
|
|
|
|
i = argc - 1;
|
|
|
|
goto show;
|
2020-12-20 11:44:12 +01:00
|
|
|
/* reload */
|
|
|
|
case 'r':
|
|
|
|
reload(argv, i);
|
|
|
|
goto show;
|
2015-08-27 23:54:58 +02:00
|
|
|
default:
|
2017-03-04 16:49:33 +01:00
|
|
|
/* printf("key pressed = '%d'\n", c); */
|
2015-08-27 23:54:58 +02:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unmap mem */
|
2020-12-20 14:41:04 +01:00
|
|
|
cleanup(0);
|
2015-08-27 23:54:58 +02:00
|
|
|
|
2020-12-20 14:41:04 +01:00
|
|
|
return 0;
|
2015-08-27 23:54:58 +02:00
|
|
|
}
|