Commit bd1ae8da authored by mbionchi's avatar mbionchi

add wchar support (-DENABLE_WCHAR for now)

parent 1282c28b
This diff is collapsed.
......@@ -18,16 +18,79 @@
#ifndef _TELNET_SITE_DATA_H
#define _TELNET_SITE_DATA_H
#include <stdio.h>
#include <dirent.h>
#include <curses.h>
#include <wchar.h>
#define NO_TRAILING_NEWLINE 0x1
#ifdef ENABLE_WCHAR
#define ALIGN_HINT L";align"
#define ALIGN_LEFT_HINT L"left"
#define ALIGN_RIGHT_HINT L"right"
#define ALIGN_CENTER_HINT L"center"
#define ANIM_HINT L";anim"
#define FRAME_HINT L";frame"
#define LOOP_HINT L";loop"
#define NOLOOP_HINT L";noloop"
#else
#define ALIGN_HINT ";align"
#define ALIGN_LEFT_HINT "left"
#define ALIGN_RIGHT_HINT "right"
#define ALIGN_CENTER_HINT "center"
#define ANIM_HINT ";anim"
#define FRAME_HINT ";frame"
#define LOOP_HINT ";loop"
#define NOLOOP_HINT ";noloop"
#endif
#include <stdio.h>
#include <dirent.h>
#include <curses.h>
#ifdef ENABLE_WCHAR
#define ERR_OPENING_FILE_STR L"<error opening file>"
#else
#define ERR_OPENING_FILE_STR "<error opening file>"
#endif
#ifdef ENABLE_WCHAR
typedef wchar_t char_t;
typedef wint_t int_t;
#define MYEOF WEOF
#define myfgetc(X) fgetwc(X)
#define mystrlen(X) wcslen(X)
#define mystrchr(X, Y) wcschr(X, Y)
#define mystrtol(X, Y, Z) wcstol(X, Y, Z)
#define mystrcmp(X, Y) wcscmp(X, Y)
#define mystrncmp(X, Y, Z) wcsncmp(X, Y, Z)
#define mystrcpy(X, Y) wcscpy(X, Y)
#define mystrncpy(X, Y, Z) wcsncpy(X, Y, Z)
#define mystrcat(X, Y) wcscat(X, Y)
#define mystrncat(X, Y, Z) wcsncat(X, Y, Z)
#else
typedef char char_t;
typedef int int_t;
#define MYEOF EOF
#define myfgetc(X) fgetc(X)
#define mystrlen(X) strlen(X)
#define mystrchr(X, Y) strchr(X, Y)
#define mystrtol(X, Y, Z) strtol(X, Y, Z)
#define mystrcmp(X, Y) strcmp(X, Y)
#define mystrncmp(X, Y, Z) strncmp(X, Y, Z)
#define mystrcpy(X, Y) strcpy(X, Y)
#define mystrncpy(X, Y, Z) strncpy(X, Y, Z)
#define mystrcat(X, Y) strcat(X, Y)
#define mystrncat(X, Y, Z) strncat(X, Y, Z)
#endif
char *binary_name;
......@@ -44,7 +107,7 @@ struct section {
};
struct string {
char *data;
char_t *data;
size_t len;
};
......@@ -113,7 +176,7 @@ struct anim_ref {
void gen_err_opening(struct content *content);
int read_content_from_section(struct content *content, struct section *section);
struct nline *string2nline(char *str);
struct nline *string2nline(char_t *str);
size_t read_nlines(FILE *fp, struct nline ***nlines);
size_t flow_nlines(struct nline **from, size_t n_from, struct nline ***to, int width, int options);
void print_nlines(struct nline **nlines, size_t nmemb);
......@@ -121,11 +184,6 @@ void free_nlines(struct nline **nlines, size_t nmemb);
size_t gen_index(struct section **sections, size_t nmemb, struct nline ***to, size_t width);
#define ANIM_HINT ";anim"
#define FRAME_HINT ";frame"
#define LOOP_HINT ";loop"
#define NOLOOP_HINT ";noloop"
// ======= old stuff:
void dump_sections(struct section **sections, size_t n_sections);
......
......@@ -22,6 +22,8 @@
#include <getopt.h>
#include <stdlib.h>
#include <locale.h>
#include <ncurses.h>
enum { SITE_INDEX, SPLASH_INDEX };
......@@ -55,6 +57,7 @@ int main(int argc, char **argv) {
had_winch = 0;
signal(SIGWINCH, set_had_winch);
setlocale(LC_ALL, "");
WINDOW *main_window = initscr();
cbreak();
halfdelay(1);
......
......@@ -63,7 +63,11 @@ void render_nline(struct window *window, size_t cursor_y, struct nline *nline) {
cursor_x = (window->cols - s->len)/2;
}
scrollok(window->window, 0);
#ifdef ENABLE_WCHAR
mvwaddwstr(window->window, cursor_y, cursor_x, s->data);
#else
mvwprintw(window->window, cursor_y, cursor_x, "%s", s->data);
#endif
scrollok(window->window, 1);
}
}
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