-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.c
117 lines (93 loc) · 2.5 KB
/
context.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iconv.h>
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include "context.h"
#include "common.h"
#define UTF8_STRING "UTF-8"
#define LATIN1_STRING "ISO_8859-1"
int errno;
Context_t *context_init (Context_params_t params, DB_t *db) {
Context_t *context = calloc(1, sizeof(Context_t));
params = params;
context->latin1_to_utf8 = iconv_open(UTF8_STRING, LATIN1_STRING); // iconv_open(tocode, fromcode)
if (context->latin1_to_utf8 == (iconv_t) -1) {
perror("iconv_open from " LATIN1_STRING " to " UTF8_STRING " failed");
return NULL;
}
context->utf8_to_latin1 = iconv_open(LATIN1_STRING, UTF8_STRING); // iconv_open(tocode, fromcode)
if (context->utf8_to_latin1 == (iconv_t) -1) {
perror("iconv_open from " UTF8_STRING " to " LATIN1_STRING " failed");
return NULL;
}
context->db = db;
context->banner = newwin(BANNER_HEIGHT, COLS, 0, 0);
if (!context->banner) {
perror("failed to create top window!");
return NULL;
}
keypad(context->banner, TRUE);
context->title = newwin(TITLE_HEIGHT, COLS, BANNER_HEIGHT, 0);
if (!context->title) {
perror("failed to create title window!");
return NULL;
}
keypad(context->title, TRUE);
context->main = newwin(LINES - (BANNER_HEIGHT + TITLE_HEIGHT + BOTTOM_HEIGHT), COLS, BANNER_HEIGHT + TITLE_HEIGHT, 0);
if (!context->main) {
perror("failed to create main window!");
return NULL;
}
keypad(context->main, TRUE);
context->bottom = newwin(BOTTOM_HEIGHT, COLS, LINES - BOTTOM_HEIGHT, 0);
if (!context->bottom) {
perror("failed to create bottom window!");
return NULL;
}
keypad(context->bottom, TRUE);
context->full = newwin(LINES, COLS, 0, 0);
if (!context->full) {
perror("failed to create full window!");
return NULL;
}
keypad(context->full, TRUE);
context->popup = newwin(LINES - 2, COLS/2, 1, COLS/4);
if (!context->popup) {
perror("failed to create popup window!");
return NULL;
}
return context;
}
char *context_error() {
return "asdf";
}
int context_term(Context_t *context) {
if (context) {
if (context->db) {
DB_term(context->db);
}
if (context->utf8_to_latin1) {
iconv_close(context->utf8_to_latin1);
}
if (context->latin1_to_utf8) {
iconv_close(context->latin1_to_utf8);
}
if (context->banner) {
delwin(context->banner);
}
if (context->title) {
delwin(context->title);
}
if (context->main) {
delwin(context->main);
}
if (context->bottom) {
delwin(context->bottom);
}
if (context->full) {
delwin(context->full);
}
free(context);
}
return 0;
}