Skip to content

Commit

Permalink
max width of 80 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
RealMelkor committed Nov 3, 2022
1 parent 96f9e18 commit eb47b15
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 227 deletions.
27 changes: 18 additions & 9 deletions src/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ int gethomefd() {
if (!pw) return -1;
home_fd = open(pw->pw_dir, O_DIRECTORY);
strlcpy(home_path, pw->pw_dir, sizeof(home_path));
snprintf(download_path, sizeof(download_path), "%s/%s", home_path, download_str);
snprintf(download_path, sizeof(download_path), "%s/%s",
home_path, download_str);
return home_fd;
}

Expand Down Expand Up @@ -79,11 +80,13 @@ int getconfigfd() {
return -1;
}
close(fd);
snprintf(config_path, sizeof(config_path), "%s/%s", home_path, "/.config/vgmi");
snprintf(config_path, sizeof(config_path), "%s/%s",
home_path, "/.config/vgmi");
return config_fd;
}

int cert_getpath(char* host, char* crt, size_t crt_len, char* key, size_t key_len) {
int cert_getpath(char* host, char* crt, size_t crt_len,
char* key, size_t key_len) {
int len = strnlen(host, 1024);
if (strlcpy(crt, host, crt_len) >= crt_len - 4)
goto getpath_overflow;
Expand Down Expand Up @@ -144,7 +147,8 @@ int cert_create(char* host, char* error, int errlen) {
// Key
fd = openat(config_fd, key, O_CREAT|O_WRONLY, 0600);
if (fd < 0) {
snprintf(error, errlen, "Failed to open %s : %s", key, strerror(errno));
snprintf(error, errlen, "Failed to open %s : %s",
key, strerror(errno));
goto skip_error;
}
f = fdopen(fd, "wb");
Expand Down Expand Up @@ -213,7 +217,8 @@ struct cert {
struct cert* first_cert = NULL;
struct cert* last_cert = NULL;

void cert_add(char* host, const char* hash, unsigned long long start, unsigned long long end) {
void cert_add(char* host, const char* hash, unsigned long long start,
unsigned long long end) {
struct cert* cert_ptr = malloc(sizeof(struct cert));
if (!cert_ptr) {
fatal();
Expand Down Expand Up @@ -263,7 +268,8 @@ int cert_load() {
if (*ptr == ' ' || *ptr == '\t' || (host?(*ptr == '\n'):0)) {
*ptr = '\0';
ptr++;
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') ptr++;
while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n')
ptr++;
if (!hash) {
hash = ptr;
ptr++;
Expand Down Expand Up @@ -343,7 +349,8 @@ int cert_getcert(char* host, int reload) {
key_pos = ftell(key_f);

if (!reload) {
client.certs = realloc(client.certs, sizeof(*client.certs) * (index + 1));
client.certs = realloc(client.certs,
sizeof(*client.certs) * (index + 1));
if (!client.certs) return fatalI();
bzero(&client.certs[index], sizeof(*client.certs));
} else {
Expand All @@ -370,7 +377,8 @@ int cert_getcert(char* host, int reload) {
client.certs[index].key[key_pos-1] = '\0';
client.certs[index].crt_len = crt_pos;
client.certs[index].key_len = key_pos;
strlcpy(client.certs[index].host, host, sizeof(client.certs[index].host));
strlcpy(client.certs[index].host, host,
sizeof(client.certs[index].host));
if (!reload)
client.certs_size++;
return index;
Expand All @@ -380,7 +388,8 @@ int cert_rewrite() {
int cfd = getconfigfd();
if (cfd < 0) return -1;

int fd = openat(cfd, "known_hosts", O_CREAT|O_WRONLY|O_CLOEXEC|O_TRUNC, 0600);
int fd = openat(cfd, "known_hosts",
O_CREAT|O_WRONLY|O_CLOEXEC|O_TRUNC, 0600);
if (fd == -1)
return -2;
#if defined(__FreeBSD__) && !defined(NO_SANDBOX)
Expand Down
3 changes: 2 additions & 1 deletion src/cert.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

int cert_create(char* url, char* error, int errlen);
int cert_getpath(char* host, char* crt, int crt_len, char* key, int key_len);
int cert_verify(char* host, const char* hash, unsigned long long start, unsigned long long end);
int cert_verify(char* host, const char* hash,
unsigned long long start, unsigned long long end);
int cert_forget(char* host);
int cert_getcert(char* host, int reload);
int gethomefd();
Expand Down
51 changes: 32 additions & 19 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void display() {
struct gmi_tab* tab = client.tab;
struct gmi_page* page = &tab->page;
if (tab->request.ask == 2) {
tab->request.ask = display_ask(tab->request.info, tab->request.action);
tab->request.ask = display_ask(tab->request.info,
tab->request.action);
}
tb_clear();

Expand All @@ -48,19 +49,22 @@ void display() {
sizeof(client.input.field),
client.input.cursor);
int w = tb_width();
w -= w&1; // make width even so double-width characters don't cause problem
w -= w&1; // make width even so double-width
// characters don't cause problem
if (page->code == 10 || page->code == 11)
w -= utf8_width(client.input.label, sizeof(client.input.label)) + 2;
w -= utf8_width(client.input.label,
sizeof(client.input.label)) + 2;
if (cpos >= w) {
input_offset = utf8_len_to(client.input.field,
sizeof(client.input.field),
cpos - cpos%w);
sizeof(client.input.field),
cpos - cpos%w);
cpos = cpos%w;
}

if (page->code == 11 || page->code == 10)
tb_set_cursor(cpos + utf8_width(client.input.label,
sizeof(client.input.label))+2, tb_height()-1);
sizeof(client.input.label))+2,
tb_height()-1);
else
tb_set_cursor(cpos, tb_height()-1);
}
Expand All @@ -86,18 +90,21 @@ void display() {
ptr = ptr->prev;
}
tb_printf(0, 0, TB_BLACK, bg,
" %s [%d/%d]", page->title, index, client.tabs_count);
" %s [%d/%d]", page->title,
index, client.tabs_count);
}

// current url
tb_colorline(0, tb_height()-2, bg);
char urlbuf[MAX_URL];
hide_query(tab->url, urlbuf);
tb_printf(0, tb_height()-2, TB_BLACK, bg, "%s (%s)", urlbuf, tab->page.meta);
tb_printf(0, tb_height()-2, TB_BLACK, bg, "%s (%s)",
urlbuf, tab->page.meta);

// Show selected link url
if (tab->selected != 0) {
int x = tb_width() - utf8_width(tab->selected_url, MAX_URL) - 5;
int x = tb_width() -
utf8_width(tab->selected_url, MAX_URL) - 5;
x = x < 10?10:x;
tb_printf(x, tb_height()-2, bg, TB_BLUE,
" => %s ", tab->selected_url);
Expand All @@ -110,8 +117,8 @@ void display() {

int count = atoi(client.vim.counter);
if (count) {
tb_printf(tb_width() - 8, tb_height() - 1, TB_DEFAULT, TB_DEFAULT,
"%d", count);
tb_printf(tb_width() - 8, tb_height() - 1,
TB_DEFAULT, TB_DEFAULT, "%d", count);
}

// input
Expand All @@ -128,11 +135,13 @@ void display() {
tab->show_info = 0;
} else if (page->code == 10) {
tb_printf(0, tb_height()-1, TB_DEFAULT, TB_DEFAULT,
"%s: %s", client.input.label, client.input.field + input_offset);
"%s: %s", client.input.label,
client.input.field + input_offset);
} else if (page->code == 11) {
char input_buf[1024];
size_t i = 0;
for (; client.input.field[i] && i < sizeof(client.input.field); i++)
for (; client.input.field[i] &&
i < sizeof(client.input.field); i++)
input_buf[i] = '*';
input_buf[i] = '\0';
tb_printf(0, tb_height()-1, TB_DEFAULT, TB_DEFAULT,
Expand All @@ -143,7 +152,8 @@ void display() {
}

if (client.input.mode && tb_width() & 1)
tb_set_cell(tb_width() - 1, tb_height() -1, ' ', TB_DEFAULT, TB_DEFAULT);
tb_set_cell(tb_width() - 1, tb_height() -1, ' ',
TB_DEFAULT, TB_DEFAULT);
tb_present();
}

Expand All @@ -163,7 +173,8 @@ void display_history() {
continue;
}
int y = 3;
for (struct gmi_link* link = tab->history->next; link; link = link->next) {
for (struct gmi_link* link = tab->history->next; link;
link = link->next) {
hide_query(link->url, urlbuf);
tb_printf(4, y, TB_DEFAULT, TB_DEFAULT, "%s", urlbuf);
y++;
Expand All @@ -173,15 +184,17 @@ void display_history() {
tb_printf(4, y, TB_DEFAULT, TB_BLUE, "-> %s", urlbuf);
y++;

for (struct gmi_link* link = tab->history->prev; link; link = link->prev) {
for (struct gmi_link* link = tab->history->prev; link;
link = link->prev) {
hide_query(link->url, urlbuf);
tb_printf(4, y, TB_DEFAULT, TB_DEFAULT, "%s", urlbuf);
y++;
}

tb_present();

} while(((ret = tb_poll_event(&ev)) == TB_OK && ev.type == TB_EVENT_RESIZE)
} while(((ret = tb_poll_event(&ev)) == TB_OK &&
ev.type == TB_EVENT_RESIZE)
|| ret == -14);
}

Expand All @@ -205,7 +218,7 @@ int display_ask(char* info, char* action) {

tb_present();

} while(((ret = tb_poll_event(&ev)) == TB_OK && ev.type == TB_EVENT_RESIZE)
|| ret == -14);
} while(((ret = tb_poll_event(&ev)) == TB_OK &&
ev.type == TB_EVENT_RESIZE) || ret == -14);
return ev.ch == 'y' || ev.ch == 'Y';
}
Loading

0 comments on commit eb47b15

Please sign in to comment.