Commit 5dc24413 authored by mbionchi's avatar mbionchi

quick bugfixes:

  - splashscreen no longer gets SIGSEGVd all the time
  - add nullbyte terminator to section names
  - factor out ncurses functions
parent 1784c870
......@@ -127,6 +127,7 @@ struct section **read_sections(DIR *dir, char *dirname, size_t *nmemb) {
base[i]->type = STATIC;
}
base[i]->title = strncpy(malloc((title_len+1)*sizeof(char)), title, title_len);
base[i]->title[title_len] = '\0';
base[i]->filename = filename;
i++;
}
......
......@@ -45,12 +45,21 @@ int main(int argc, char **argv) {
}
opt = getopt_long_only(argc, argv, "", options, NULL);
}
WINDOW *main_window = initscr();
cbreak();
halfdelay(1);
noecho();
curs_set(0);
nonl();
keypad(main_window, 1);
if (!site_path) {
fprintf(stderr, "Usage: %s --site <path-to-dir> [--splash <path-to-file>]\n", binary_name);
exit(1);
}
if (splash_path) {
splash(splash_path);
splash(main_window, splash_path);
}
site(site_path);
site(main_window, site_path);
endwin();
}
......@@ -63,7 +63,7 @@ void winch_handler(int signo) {
* - error handling everywhere please
* - refactor the event loop, it's horrifying atm
*/
void site(char *path) {
void site(WINDOW *window, char *path) {
signal(SIGWINCH, winch_handler);
struct window index_window;
......@@ -88,14 +88,6 @@ void site(char *path) {
gen_err_opening(&content_window.content);
}
WINDOW *main_window = initscr();
cbreak();
halfdelay(1);
noecho();
curs_set(0);
nonl();
keypad(main_window, 1);
int index_left_margin = 2;
int index_cols = get_index_width(sections, n_sections);
int index_scroll_threshold = 5;
......@@ -401,5 +393,4 @@ void site(char *path) {
delwin(index_window.window);
delwin(separator_window.window);
delwin(content_window.window);
endwin();
}
......@@ -18,6 +18,8 @@
#ifndef _TELNET_SITE_SITE_H
#define _TELNET_SITE_SITE_H
void site(char *site_path);
#include <ncurses.h>
void site(WINDOW *window, char *site_path);
#endif
......@@ -24,17 +24,20 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <ncurses.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
void splash(char *path) {
void splash(WINDOW *window, char *path) {
signal(SIGWINCH, SIG_IGN);
struct window splash_window;
FILE *fp = fopen(path, "r");
if (fp != NULL) {
splash_window.content.type = STATIC;
splash_window.content.lines = malloc(sizeof(struct static_content));
splash_window.content.lines->n_raw = read_nlines(fp, &splash_window.content.lines->raw);
fclose(fp);
} else {
......@@ -42,11 +45,7 @@ void splash(char *path) {
gen_err_opening(&splash_window.content);
}
splash_window.window = initscr();
cbreak();
halfdelay(1);
noecho();
curs_set(0);
splash_window.window = window;
splash_window.cols = COLS;
splash_window.rows = LINES;
......@@ -61,8 +60,7 @@ void splash(char *path) {
render_ncontent(&splash_window);
refresh();
wrefresh(splash_window.window);
wrefresh(window);
int ch = getch();
while (ch == ERR) {
......@@ -72,7 +70,6 @@ void splash(char *path) {
free_content(&splash_window);
free_anim_refs(&splash_window);
clear();
refresh();
endwin();
wrefresh(window);
return;
}
......@@ -18,6 +18,8 @@
#ifndef _TELNET_SPLASH_SITE_H
#define _TELNET_SPLASH_SITE_H
void splash(char *path);
#include <ncurses.h>
void splash(WINDOW *window, char *path);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment