2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "phos/phos.h"
26 #define MIN(a, b) ((a) < (b) ? (a) : (b))
27 #define MAX(a, b) ((a) > (b) ? (a) : (b))
29 #define GEMINI_URL_LEN 1024
32 /* ui <-> client/fs */
33 IMSG_GET, /* data is URL, peerid the tab id */
34 IMSG_GET_RAW, /* get but with an explicit req str */
62 extern char *new_tab_url;
63 extern int fill_column;
64 extern int olivetti_mode;
65 extern int enable_colors;
66 extern int hide_pre_context;
67 extern int hide_pre_blocks;
73 extern struct lineprefix line_prefixes[];
76 int prfx_pair, pair, trail_pair;
77 int prfx_bg, bg, trail_bg;
78 int prfx_fg, fg, trail_fg;
79 int prfx_attr, attr, trail_attr;
81 int prefix, text, trail;
83 extern struct line_face line_faces[];
86 int bg_attr, bg_bg, bg_fg;
87 int t_attr, t_bg, t_fg;
88 int c_attr, c_bg, c_fg;
90 int background, tab, current;
92 extern struct tab_face tab_face;
99 int left, body, right;
101 extern struct body_face body_face;
103 struct modeline_face {
107 extern struct modeline_face modeline_face;
109 struct minibuffer_face {
113 extern struct minibuffer_face minibuffer_face;
128 /* for lines: mark as hidden */
131 /* for vlines: mark as continuation */
132 #define L_CONTINUATION 2
139 TAILQ_ENTRY(line) lines;
143 const struct line *parent;
146 TAILQ_ENTRY(vline) vlines;
152 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
153 typedef int (*parserfreefn)(struct parser*);
155 typedef void (imsg_handlerfn)(struct imsg*, size_t);
164 #define PARSER_IN_BODY 1
165 #define PARSER_IN_PRE 2
170 TAILQ_HEAD(, line) head;
174 * differnt types of trust for a certificate. Following
175 * gemini://thfr.info/gemini/modified-trust-verify.gmi
186 char domain[GEMINI_URL_LEN];
189 * enough space for ``PROTO:HASH''. probably isn't a good
197 TAILQ_HEAD(mhisthead, hist) head;
202 TAILQ_ENTRY(hist) entries;
208 size_t last_line_off;
215 struct vline *top_line;
216 struct vline *current_line;
218 TAILQ_HEAD(vhead, vline) head;
221 #define TAB_CURRENT 0x1
222 #define TAB_URGENT 0x2
224 #define NEW_TAB_URL "about:new"
226 extern TAILQ_HEAD(tabshead, tab) tabshead;
228 TAILQ_ENTRY(tab) tabs;
233 enum trust_state trust;
236 struct histhead hist;
237 struct hist *hist_cur;
241 char meta[GEMINI_URL_LEN];
244 struct buffer buffer;
247 short loading_anim_step;
248 struct event loadingev;
259 * should load the given url in the tab. Optionally, it may
260 * consider the given url as relative to the one already
261 * present in tab. It must set tab->urlstr to a serialized
262 * human-friendly URL.
264 void (*loadfn)(struct tab*, const char*);
267 extern TAILQ_HEAD(proxylist, proxy) proxies;
275 TAILQ_ENTRY(proxy) proxies;
291 TAILQ_HEAD(map, keymap) m;
292 void (*unhandled_input)(void);
294 extern struct kmap global_map, minibuffer_map;
296 typedef void(interactivefn)(struct buffer *);
304 TAILQ_ENTRY(keymap) keymaps;
309 void (*fn)(struct buffer *);
311 extern struct cmd cmds[];
314 void config_init(void);
315 int config_setprfx(const char *, const char *, const char *);
316 int config_setvari(const char *, int);
317 int config_setvars(const char *, char *);
318 int config_setcolor(int, const char *, int, int, int);
319 int config_setattr(const char *, int, int, int);
320 void config_apply_style(void);
325 int load_certs(struct ohash*);
326 int load_last_session(void(*)(const char*));
329 int client_main(void);
332 void gemtext_initparser(struct parser*);
335 void hist_clear_forward(struct histhead*, struct hist*);
336 void hist_push(struct histhead*, struct hist*);
339 int kbd(const char*);
340 const char *unkbd(int);
341 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
344 int setup_parser_for(struct tab*);
347 extern const char *about_about;
348 extern const char *about_blank;
349 extern const char *about_help;
350 extern const char *about_new;
352 #define CANNOT_FETCH 0
353 #define TOO_MUCH_REDIRECTS 1
354 #define MALFORMED_RESPONSE 2
355 #define UNKNOWN_TYPE_OR_CSET 3
356 extern const char *err_pages[70];
359 void parseconfig(const char *, int);
362 int parser_append(struct parser*, const char*, size_t);
363 int parser_set_buf(struct parser*, const char*, size_t);
364 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
367 void sandbox_network_process(void);
368 void sandbox_ui_process(void);
369 void sandbox_fs_process(void);
372 void load_about_url(struct tab*, const char*);
373 void load_gemini_url(struct tab*, const char*);
374 void load_via_proxy(struct tab *, const char *, struct proxy *);
375 void load_url(struct tab*, const char*);
376 int load_previous_page(struct tab*);
377 int load_next_page(struct tab*);
378 void stop_tab(struct tab*);
379 void add_to_bookmarks(const char*);
380 void save_session(void);
383 void textplain_initparser(struct parser*);
386 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
387 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
388 void tofu_add(struct ohash*, struct tofu_entry*);
389 void tofu_update(struct ohash*, struct tofu_entry*);
390 void tofu_temp_trust(struct ohash *, const char *, const char *, const char *);
393 extern int body_lines;
394 extern int body_cols;
395 extern int in_minibuffer;
397 extern struct kmap global_map, minibuffer_map, *current_map, *base_map;
402 struct vline *current_line;
456 extern struct thiskey thiskey;
458 extern struct histhead eecmd_history,
467 void (*donefn)(void);
468 void (*abortfn)(void);
473 struct buffer buffer;
475 struct histhead *history;
476 struct hist *hist_cur;
479 extern struct ministate ministate;
481 void save_excursion(struct excursion *, struct buffer *);
482 void restore_excursion(struct excursion *, struct buffer *);
483 void global_key_unbound(void);
484 void minibuffer_taint_hist(void);
485 void eecmd_self_insert(void);
486 void eecmd_select(void);
487 void ir_self_insert(void);
488 void ir_select(void);
489 void lu_self_insert(void);
490 void lu_select(void);
491 void bp_select(void);
492 void vmessage(const char*, va_list);
493 void message(const char*, ...) __attribute__((format(printf, 1, 2)));
494 void start_loading_anim(struct tab *tab);
495 void load_url_in_tab(struct tab *, const char *);
496 void switch_to_tab(struct tab *);
497 struct tab *current_tab(void);
498 struct buffer *current_buffer(void);
499 struct tab *new_tab(const char *);
500 unsigned int tab_new_id(void);
502 void ui_on_tab_loaded(struct tab*);
503 void ui_on_tab_refresh(struct tab*);
504 const char *ui_keyname(int);
505 void ui_toggle_side_window(void);
506 void ui_schedule_redraw(void);
507 void ui_require_input(struct tab*, int);
508 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
509 void ui_yornp(const char*, void (*)(int, struct tab *), struct tab *);
513 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
514 size_t utf8_encode(uint32_t, char*);
515 char *utf8_nth(char*, size_t);
516 size_t utf8_cplen(char*);
517 size_t utf8_chwidth(uint32_t);
518 size_t utf8_snwidth(const char*, size_t);
519 size_t utf8_swidth(const char*);
520 size_t utf8_swidth_between(const char*, const char*);
521 char *utf8_next_cp(const char*);
522 char *utf8_prev_cp(const char*, const char*);
525 int mark_nonblock(int);
526 int has_prefix(const char*, const char*);
527 int unicode_isspace(uint32_t);
528 int unicode_isgraph(uint32_t);
529 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
532 void erase_buffer(struct buffer *);
533 void empty_linelist(struct buffer*);
534 void empty_vlist(struct buffer*);
535 int wrap_text(struct buffer*, const char*, struct line*, size_t);
536 int hardwrap_text(struct buffer*, struct line*, size_t);
538 #endif /* TELESCOPE_H */