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;
71 extern struct lineprefix line_prefixes[];
74 int prfx_pair, pair, trail_pair;
75 int prfx_bg, bg, trail_bg;
76 int prfx_fg, fg, trail_fg;
77 int prfx_attr, attr, trail_attr;
79 int prefix, text, trail;
81 extern struct line_face line_faces[];
84 int bg_attr, bg_bg, bg_fg;
85 int t_attr, t_bg, t_fg;
86 int c_attr, c_bg, c_fg;
88 int background, tab, current;
90 extern struct tab_face tab_face;
97 int left, body, right;
99 extern struct body_face body_face;
101 struct modeline_face {
104 extern struct modeline_face modeline_face;
106 struct minibuffer_face {
109 extern struct minibuffer_face minibuffer_face;
129 TAILQ_ENTRY(line) lines;
133 const struct line *parent;
136 TAILQ_ENTRY(vline) vlines;
142 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
143 typedef int (*parserfreefn)(struct parser*);
145 typedef void (imsg_handlerfn)(struct imsg*, size_t);
157 TAILQ_HEAD(, line) head;
161 * differnt types of trust for a certificate. Following
162 * gemini://thfr.info/gemini/modified-trust-verify.gmi
172 char domain[GEMINI_URL_LEN];
175 * enough space for ``PROTO:HASH''. probably isn't a good
183 TAILQ_HEAD(mhisthead, hist) head;
188 TAILQ_ENTRY(hist) entries;
194 size_t last_line_off;
201 struct vline *current_line;
203 TAILQ_HEAD(vhead, vline) head;
206 #define TAB_CURRENT 0x1
207 #define TAB_URGENT 0x2
209 #define NEW_TAB_URL "about:new"
211 extern TAILQ_HEAD(tabshead, tab) tabshead;
213 TAILQ_ENTRY(tab) tabs;
218 enum trust_state trust;
221 struct histhead hist;
222 struct hist *hist_cur;
226 char meta[GEMINI_URL_LEN];
229 struct buffer buffer;
232 short loading_anim_step;
233 struct event loadingev;
244 * should load the given url in the tab. Optionally, it may
245 * consider the given url as relative to the one already
246 * present in tab. It must set tab->urlstr to a serialized
247 * human-friendly URL.
249 void (*loadfn)(struct tab*, const char*);
252 extern TAILQ_HEAD(proxylist, proxy) proxies;
260 TAILQ_ENTRY(proxy) proxies;
276 TAILQ_HEAD(map, keymap) m;
277 void (*unhandled_input)(void);
279 extern struct kmap global_map, minibuffer_map;
281 typedef void(interactivefn)(struct buffer *);
289 TAILQ_ENTRY(keymap) keymaps;
294 void (*fn)(struct buffer *);
296 extern struct cmd cmds[];
299 void config_init(void);
300 int config_setprfx(const char *, const char *, const char *);
301 int config_setvari(const char *, int);
302 int config_setvars(const char *, char *);
303 int config_setcolor(int, const char *, int, int, int);
304 int config_setattr(const char *, int, int, int);
305 void config_apply_style(void);
309 int fs_main(struct imsgbuf*);
310 int load_certs(struct ohash*);
311 int load_last_session(void(*)(const char*));
314 int client_main(struct imsgbuf*);
317 void gemtext_initparser(struct parser*);
320 void hist_clear_forward(struct histhead*, struct hist*);
321 void hist_push(struct histhead*, struct hist*);
324 int kbd(const char*);
325 const char *unkbd(int);
326 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
329 int setup_parser_for(struct tab*);
332 extern const char *about_about;
333 extern const char *about_blank;
334 extern const char *about_help;
335 extern const char *about_new;
337 #define CANNOT_FETCH 0
338 #define TOO_MUCH_REDIRECTS 1
339 #define MALFORMED_RESPONSE 2
340 #define UNKNOWN_TYPE_OR_CSET 3
341 extern const char *err_pages[70];
344 void parseconfig(const char *, int);
347 int parser_append(struct parser*, const char*, size_t);
348 int parser_set_buf(struct parser*, const char*, size_t);
349 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
352 void sandbox_network_process(void);
353 void sandbox_ui_process(void);
354 void sandbox_fs_process(void);
357 void load_about_url(struct tab*, const char*);
358 void load_gemini_url(struct tab*, const char*);
359 void load_via_proxy(struct tab *, const char *, struct proxy *);
360 void load_url(struct tab*, const char*);
361 int load_previous_page(struct tab*);
362 int load_next_page(struct tab*);
363 void stop_tab(struct tab*);
364 void add_to_bookmarks(const char*);
365 void save_session(void);
368 void textplain_initparser(struct parser*);
371 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
372 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
373 void tofu_add(struct ohash*, struct tofu_entry*);
374 void tofu_update(struct ohash*, struct tofu_entry*);
377 extern int body_lines;
378 extern int body_cols;
379 extern int in_minibuffer;
384 struct vline *current_line;
434 extern struct thiskey thiskey;
436 extern struct histhead eecmd_history,
445 void (*donefn)(void);
446 void (*abortfn)(void);
451 struct buffer buffer;
453 struct histhead *history;
454 struct hist *hist_cur;
457 extern struct ministate ministate;
459 void save_excursion(struct excursion *, struct buffer *);
460 void restore_excursion(struct excursion *, struct buffer *);
461 void restore_cursor(struct buffer *);
462 void minibuffer_taint_hist(void);
463 void eecmd_self_insert(void);
464 void eecmd_select(void);
465 void ir_self_insert(void);
466 void ir_select(void);
467 void lu_self_insert(void);
468 void lu_select(void);
469 void bp_select(void);
470 void vmessage(const char*, va_list);
471 void message(const char*, ...) __attribute__((format(printf, 1, 2)));
472 void start_loading_anim(struct tab *tab);
473 void load_url_in_tab(struct tab *, const char *);
474 void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead *);
475 void exit_minibuffer(void);
476 void switch_to_tab(struct tab *);
477 struct tab *current_tab(void);
478 struct tab *new_tab(const char *);
479 unsigned int tab_new_id(void);
480 int ui_init(int, char * const*);
481 void ui_on_tab_loaded(struct tab*);
482 void ui_on_tab_refresh(struct tab*);
483 const char *ui_keyname(int);
484 void ui_toggle_side_window(void);
485 void ui_schedule_redraw(void);
486 void ui_require_input(struct tab*, int);
487 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
488 void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
492 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
493 size_t utf8_encode(uint32_t, char*);
494 char *utf8_nth(char*, size_t);
495 size_t utf8_cplen(char*);
496 size_t utf8_chwidth(uint32_t);
497 size_t utf8_snwidth(const char*, size_t);
498 size_t utf8_swidth(const char*);
499 size_t utf8_swidth_between(const char*, const char*);
500 char *utf8_next_cp(const char*);
501 char *utf8_prev_cp(const char*, const char*);
504 int mark_nonblock(int);
505 int has_prefix(const char*, const char*);
506 int unicode_isspace(uint32_t);
507 int unicode_isgraph(uint32_t);
508 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
511 void empty_linelist(struct buffer*);
512 void empty_vlist(struct buffer*);
513 int wrap_text(struct buffer*, const char*, struct line*, size_t);
514 int hardwrap_text(struct buffer*, struct line*, size_t);
516 #endif /* TELESCOPE_H */