2021-02-21 23:33:42 +03:00
|
|
|
/* $NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $ */
|
2021-02-21 18:41:04 +03:00
|
|
|
|
2013-08-04 09:42:47 +04:00
|
|
|
/*-
|
2021-02-21 23:33:42 +03:00
|
|
|
* Copyright (c) 2013, 2021 The NetBSD Foundation, Inc.
|
2013-08-04 09:42:47 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2021-02-21 23:33:42 +03:00
|
|
|
* by David A. Holland and Roland Illig.
|
2013-08-04 09:42:47 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(__RCSID) && !defined(lint)
|
|
|
|
__RCSID("$NetBSD: cgram.c,v 1.10 2021/02/21 20:33:42 rillig Exp $");
|
|
|
|
#endif
|
|
|
|
|
2021-02-21 18:42:21 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <curses.h>
|
|
|
|
#include <err.h>
|
2021-02-21 19:05:44 +03:00
|
|
|
#include <stdbool.h>
|
2013-08-04 09:42:47 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-02-21 18:42:21 +03:00
|
|
|
#include <string.h>
|
2013-08-04 09:42:47 +04:00
|
|
|
#include <time.h>
|
2021-02-21 18:42:21 +03:00
|
|
|
|
2013-08-04 09:42:47 +04:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 19:50:57 +03:00
|
|
|
static char
|
|
|
|
ch_toupper(char ch)
|
|
|
|
{
|
|
|
|
return (char)toupper((unsigned char)ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char
|
|
|
|
ch_tolower(char ch)
|
|
|
|
{
|
|
|
|
return (char)tolower((unsigned char)ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ch_isalpha(char ch)
|
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
return isalpha((unsigned char)ch) != 0;
|
2021-02-21 19:50:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ch_islower(char ch)
|
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
return islower((unsigned char)ch) != 0;
|
2021-02-21 19:50:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ch_isupper(char ch)
|
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
return isupper((unsigned char)ch) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
imax(int a, int b)
|
|
|
|
{
|
|
|
|
return a > b ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
imin(int a, int b)
|
|
|
|
{
|
|
|
|
return a < b ? a : b;
|
2021-02-21 19:50:57 +03:00
|
|
|
}
|
|
|
|
|
2013-08-04 09:42:47 +04:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
struct string {
|
|
|
|
char *s;
|
|
|
|
size_t len;
|
|
|
|
size_t cap;
|
|
|
|
};
|
|
|
|
|
2013-08-04 09:42:47 +04:00
|
|
|
struct stringarray {
|
2021-02-21 23:33:42 +03:00
|
|
|
struct string *v;
|
2021-02-21 20:16:00 +03:00
|
|
|
size_t num;
|
2013-08-04 09:42:47 +04:00
|
|
|
};
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static void
|
|
|
|
string_init(struct string *s)
|
|
|
|
{
|
|
|
|
s->s = NULL;
|
|
|
|
s->len = 0;
|
|
|
|
s->cap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
string_add(struct string *s, char ch)
|
|
|
|
{
|
|
|
|
if (s->len >= s->cap) {
|
|
|
|
s->cap = 2 * s->cap + 16;
|
|
|
|
s->s = realloc(s->s, s->cap);
|
|
|
|
if (s->s == NULL)
|
|
|
|
errx(1, "Out of memory");
|
|
|
|
}
|
|
|
|
s->s[s->len++] = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
string_finish(struct string *s)
|
|
|
|
{
|
|
|
|
string_add(s, '\0');
|
|
|
|
s->len--;
|
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
stringarray_init(struct stringarray *a)
|
|
|
|
{
|
|
|
|
a->v = NULL;
|
|
|
|
a->num = 0;
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
stringarray_cleanup(struct stringarray *a)
|
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
for (size_t i = 0; i < a->num; i++)
|
|
|
|
free(a->v[i].s);
|
2021-02-21 18:41:04 +03:00
|
|
|
free(a->v);
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
2021-02-21 23:33:42 +03:00
|
|
|
stringarray_add(struct stringarray *a, struct string *s)
|
2021-02-21 18:41:04 +03:00
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
size_t num = a->num++;
|
|
|
|
a->v = realloc(a->v, a->num * sizeof a->v[0]);
|
|
|
|
if (a->v == NULL)
|
2021-02-21 18:41:04 +03:00
|
|
|
errx(1, "Out of memory");
|
2021-02-21 23:33:42 +03:00
|
|
|
a->v[num] = *s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stringarray_dup(struct stringarray *dst, const struct stringarray *src)
|
|
|
|
{
|
|
|
|
assert(dst->num == 0);
|
|
|
|
for (size_t i = 0; i < src->num; i++) {
|
|
|
|
struct string str;
|
|
|
|
string_init(&str);
|
|
|
|
for (const char *p = src->v[i].s; *p != '\0'; p++)
|
|
|
|
string_add(&str, *p);
|
|
|
|
string_finish(&str);
|
|
|
|
stringarray_add(dst, &str);
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static struct stringarray lines;
|
|
|
|
static struct stringarray sollines;
|
|
|
|
static bool hinting;
|
2021-02-21 23:33:42 +03:00
|
|
|
static int extent_x;
|
|
|
|
static int extent_y;
|
|
|
|
static int offset_x;
|
|
|
|
static int offset_y;
|
|
|
|
static int cursor_x;
|
|
|
|
static int cursor_y;
|
|
|
|
|
|
|
|
static int
|
|
|
|
cur_max_x(void)
|
|
|
|
{
|
|
|
|
return (int)lines.v[cursor_y].len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cur_max_y(void)
|
|
|
|
{
|
|
|
|
return extent_y - 1;
|
|
|
|
}
|
2013-08-04 09:42:47 +04:00
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
readquote(void)
|
|
|
|
{
|
|
|
|
FILE *f = popen(_PATH_FORTUNE, "r");
|
2021-02-21 23:33:42 +03:00
|
|
|
if (f == NULL)
|
2021-02-21 18:41:04 +03:00
|
|
|
err(1, "%s", _PATH_FORTUNE);
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
struct string line;
|
|
|
|
string_init(&line);
|
|
|
|
|
|
|
|
int ch;
|
|
|
|
while ((ch = fgetc(f)) != EOF) {
|
|
|
|
if (ch == '\n') {
|
|
|
|
string_finish(&line);
|
|
|
|
stringarray_add(&lines, &line);
|
|
|
|
string_init(&line);
|
|
|
|
} else if (ch == '\t') {
|
|
|
|
string_add(&line, ' ');
|
|
|
|
while (line.len % 8 != 0)
|
|
|
|
string_add(&line, ' ');
|
|
|
|
} else if (ch == '\b') {
|
|
|
|
if (line.len > 0)
|
|
|
|
line.len--;
|
|
|
|
} else {
|
|
|
|
string_add(&line, (char)ch);
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
stringarray_dup(&sollines, &lines);
|
|
|
|
|
|
|
|
extent_y = (int)lines.num;
|
|
|
|
for (int i = 0; i < extent_y; i++)
|
|
|
|
extent_x = imax(extent_x, (int)lines.v[i].len);
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
pclose(f);
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
encode(void)
|
|
|
|
{
|
|
|
|
int key[26];
|
2021-02-21 20:16:00 +03:00
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
for (int i = 0; i < 26; i++)
|
|
|
|
key[i] = i;
|
2021-02-21 20:16:00 +03:00
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
for (int i = 26; i > 1; i--) {
|
2021-02-21 20:16:00 +03:00
|
|
|
int c = (int)(random() % i);
|
2021-02-21 18:41:04 +03:00
|
|
|
int t = key[i - 1];
|
|
|
|
key[i - 1] = key[c];
|
|
|
|
key[c] = t;
|
|
|
|
}
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
for (int y = 0; y < extent_y; y++) {
|
|
|
|
for (char *p = lines.v[y].s; *p != '\0'; p++) {
|
2021-02-21 20:16:00 +03:00
|
|
|
if (ch_islower(*p))
|
|
|
|
*p = (char)('a' + key[*p - 'a']);
|
|
|
|
if (ch_isupper(*p))
|
|
|
|
*p = (char)('A' + key[*p - 'A']);
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
}
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 19:05:44 +03:00
|
|
|
static bool
|
2021-02-21 20:16:00 +03:00
|
|
|
substitute(char ch)
|
2021-02-21 18:41:04 +03:00
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
assert(cursor_x >= 0 && cursor_x < extent_x);
|
|
|
|
assert(cursor_y >= 0 && cursor_y < extent_y);
|
|
|
|
if (cursor_x >= cur_max_x()) {
|
2021-02-21 18:41:04 +03:00
|
|
|
beep();
|
2021-02-21 19:05:44 +03:00
|
|
|
return false;
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
char och = lines.v[cursor_y].s[cursor_x];
|
2021-02-21 19:50:57 +03:00
|
|
|
if (!ch_isalpha(och)) {
|
2021-02-21 18:41:04 +03:00
|
|
|
beep();
|
2021-02-21 19:05:44 +03:00
|
|
|
return false;
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
|
2021-02-21 19:50:57 +03:00
|
|
|
char loch = ch_tolower(och);
|
|
|
|
char uoch = ch_toupper(och);
|
|
|
|
char lch = ch_tolower(ch);
|
|
|
|
char uch = ch_toupper(ch);
|
2021-02-21 18:41:04 +03:00
|
|
|
|
2021-02-21 20:16:00 +03:00
|
|
|
for (int y = 0; y < (int)lines.num; y++) {
|
2021-02-21 23:33:42 +03:00
|
|
|
for (char *p = lines.v[y].s; *p != '\0'; p++) {
|
2021-02-21 20:16:00 +03:00
|
|
|
if (*p == loch)
|
|
|
|
*p = lch;
|
|
|
|
else if (*p == uoch)
|
|
|
|
*p = uch;
|
|
|
|
else if (*p == lch)
|
|
|
|
*p = loch;
|
|
|
|
else if (*p == uch)
|
|
|
|
*p = uoch;
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-21 19:05:44 +03:00
|
|
|
return true;
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static bool
|
|
|
|
is_solved(void)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < lines.num; i++)
|
|
|
|
if (strcmp(lines.v[i].s, sollines.v[i].s) != 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
redraw(void)
|
|
|
|
{
|
|
|
|
erase();
|
2021-02-21 23:33:42 +03:00
|
|
|
|
|
|
|
int max_y = imin(LINES - 1, extent_y - offset_y);
|
|
|
|
for (int y = 0; y < max_y; y++) {
|
|
|
|
move(y, 0);
|
|
|
|
|
|
|
|
int len = (int)lines.v[offset_y + y].len;
|
|
|
|
int max_x = imin(COLS - 1, len - offset_x);
|
|
|
|
const char *line = lines.v[offset_y + y].s;
|
|
|
|
const char *solline = sollines.v[offset_y + y].s;
|
|
|
|
|
|
|
|
for (int x = 0; x < max_x; x++) {
|
|
|
|
char ch = line[offset_x + x];
|
|
|
|
bool bold = hinting &&
|
|
|
|
ch == solline[offset_x + x] &&
|
|
|
|
ch_isalpha(ch);
|
|
|
|
|
|
|
|
if (bold)
|
|
|
|
attron(A_BOLD);
|
|
|
|
addch(ch);
|
|
|
|
if (bold)
|
|
|
|
attroff(A_BOLD);
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
clrtoeol();
|
|
|
|
}
|
|
|
|
|
|
|
|
move(LINES - 1, 0);
|
2021-02-21 23:33:42 +03:00
|
|
|
if (is_solved())
|
2021-02-21 18:41:04 +03:00
|
|
|
addstr("*solved* ");
|
|
|
|
addstr("~ to quit, * to cheat, ^pnfb to move");
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
move(cursor_y - offset_y, cursor_x - offset_x);
|
2021-02-21 18:41:04 +03:00
|
|
|
|
|
|
|
refresh();
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
opencurses(void)
|
|
|
|
{
|
|
|
|
initscr();
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
2021-02-21 23:33:42 +03:00
|
|
|
keypad(stdscr, true);
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
|
|
|
closecurses(void)
|
|
|
|
{
|
|
|
|
endwin();
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-21 18:41:04 +03:00
|
|
|
static void
|
2021-02-21 23:33:42 +03:00
|
|
|
saturate_cursor(void)
|
2021-02-21 18:41:04 +03:00
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
assert(cursor_y >= 0);
|
|
|
|
assert(cursor_y <= cur_max_y());
|
|
|
|
|
|
|
|
assert(cursor_x >= 0);
|
|
|
|
cursor_x = imin(cursor_x, cur_max_x());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scroll_into_view(void)
|
|
|
|
{
|
|
|
|
if (cursor_x < offset_x)
|
|
|
|
offset_x = cursor_x;
|
|
|
|
if (cursor_x > offset_x + COLS - 1)
|
|
|
|
offset_x = cursor_x - (COLS - 1);
|
|
|
|
|
|
|
|
if (cursor_y < offset_y)
|
|
|
|
offset_y = cursor_y;
|
|
|
|
if (cursor_y > offset_y + LINES - 2)
|
|
|
|
offset_y = cursor_y - (LINES - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_char_input(int ch)
|
|
|
|
{
|
|
|
|
if (isascii(ch) && ch_isalpha((char)ch)) {
|
|
|
|
if (substitute((char)ch)) {
|
|
|
|
if (cursor_x < cur_max_x())
|
|
|
|
cursor_x++;
|
|
|
|
if (cursor_x == cur_max_x() &&
|
|
|
|
cursor_y < cur_max_y()) {
|
|
|
|
cursor_x = 0;
|
|
|
|
cursor_y++;
|
2021-02-21 18:41:04 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-21 23:33:42 +03:00
|
|
|
} else if (cursor_x < cur_max_x() &&
|
|
|
|
ch == lines.v[cursor_y].s[cursor_x]) {
|
|
|
|
cursor_x++;
|
|
|
|
if (cursor_x == cur_max_x() &&
|
|
|
|
cursor_y < cur_max_y()) {
|
|
|
|
cursor_x = 0;
|
|
|
|
cursor_y++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
beep();
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static bool
|
|
|
|
handle_key(void)
|
2021-02-21 18:41:04 +03:00
|
|
|
{
|
2021-02-21 23:33:42 +03:00
|
|
|
int ch = getch();
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case 1: /* ^A */
|
|
|
|
case KEY_HOME:
|
|
|
|
cursor_x = 0;
|
|
|
|
break;
|
|
|
|
case 2: /* ^B */
|
|
|
|
case KEY_LEFT:
|
|
|
|
if (cursor_x > 0) {
|
|
|
|
cursor_x--;
|
|
|
|
} else if (cursor_y > 0) {
|
|
|
|
cursor_y--;
|
|
|
|
cursor_x = cur_max_x();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5: /* ^E */
|
|
|
|
case KEY_END:
|
|
|
|
cursor_x = cur_max_x();
|
|
|
|
break;
|
|
|
|
case 6: /* ^F */
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if (cursor_x < cur_max_x()) {
|
|
|
|
cursor_x++;
|
|
|
|
} else if (cursor_y < cur_max_y()) {
|
|
|
|
cursor_y++;
|
|
|
|
cursor_x = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 12: /* ^L */
|
|
|
|
clear();
|
|
|
|
break;
|
|
|
|
case 14: /* ^N */
|
|
|
|
case KEY_DOWN:
|
|
|
|
if (cursor_y < cur_max_y())
|
|
|
|
cursor_y++;
|
|
|
|
break;
|
|
|
|
case 16: /* ^P */
|
|
|
|
case KEY_UP:
|
|
|
|
if (cursor_y > 0)
|
|
|
|
cursor_y--;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
hinting = !hinting;
|
|
|
|
break;
|
|
|
|
case '~':
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
handle_char_input(ch);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-21 18:41:04 +03:00
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static void
|
|
|
|
init(void)
|
|
|
|
{
|
2021-02-21 18:41:04 +03:00
|
|
|
stringarray_init(&lines);
|
|
|
|
stringarray_init(&sollines);
|
2021-02-21 20:16:00 +03:00
|
|
|
srandom((unsigned int)time(NULL));
|
2021-02-21 18:41:04 +03:00
|
|
|
readquote();
|
|
|
|
encode();
|
|
|
|
opencurses();
|
2021-02-21 23:33:42 +03:00
|
|
|
}
|
2021-02-21 18:41:04 +03:00
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static void
|
|
|
|
loop(void)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
redraw();
|
|
|
|
if (!handle_key())
|
|
|
|
break;
|
|
|
|
saturate_cursor();
|
|
|
|
scroll_into_view();
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 18:41:04 +03:00
|
|
|
|
2021-02-21 23:33:42 +03:00
|
|
|
static void
|
|
|
|
clean_up(void)
|
|
|
|
{
|
2021-02-21 18:41:04 +03:00
|
|
|
closecurses();
|
|
|
|
stringarray_cleanup(&sollines);
|
|
|
|
stringarray_cleanup(&lines);
|
2013-08-04 09:42:47 +04:00
|
|
|
}
|
2021-02-21 23:33:42 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
loop();
|
|
|
|
clean_up();
|
|
|
|
}
|