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[];
78 extern struct line_face line_faces[];
81 int bg_attr, bg_bg, bg_fg;
82 int t_attr, t_bg, t_fg;
83 int c_attr, c_bg, c_fg;
85 int background, tab, current;
87 extern struct tab_face tab_face;
94 int left, body, right;
96 extern struct body_face body_face;
98 struct modeline_face {
101 extern struct modeline_face modeline_face;
103 struct minibuffer_face {
106 extern struct minibuffer_face minibuffer_face;
126 TAILQ_ENTRY(line) lines;
130 const struct line *parent;
133 TAILQ_ENTRY(vline) vlines;
139 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
140 typedef int (*parserfreefn)(struct parser*);
142 typedef void (imsg_handlerfn)(struct imsg*, size_t);
154 TAILQ_HEAD(, line) head;
158 * differnt types of trust for a certificate. Following
159 * gemini://thfr.info/gemini/modified-trust-verify.gmi
169 char domain[GEMINI_URL_LEN];
172 * enough space for ``PROTO:HASH''. probably isn't a good
180 TAILQ_HEAD(mhisthead, hist) head;
185 TAILQ_ENTRY(hist) entries;
191 size_t last_line_off;
198 struct vline *current_line;
200 TAILQ_HEAD(vhead, vline) head;
203 #define TAB_CURRENT 0x1
204 #define TAB_URGENT 0x2
206 #define NEW_TAB_URL "about:new"
208 extern TAILQ_HEAD(tabshead, tab) tabshead;
210 TAILQ_ENTRY(tab) tabs;
215 enum trust_state trust;
218 struct histhead hist;
219 struct hist *hist_cur;
223 char meta[GEMINI_URL_LEN];
226 struct buffer buffer;
229 short loading_anim_step;
230 struct event loadingev;
241 * should load the given url in the tab. Optionally, it may
242 * consider the given url as relative to the one already
243 * present in tab. It must set tab->urlstr to a serialized
244 * human-friendly URL.
246 void (*loadfn)(struct tab*, const char*);
249 extern TAILQ_HEAD(proxylist, proxy) proxies;
257 TAILQ_ENTRY(proxy) proxies;
273 TAILQ_HEAD(map, keymap) m;
274 void (*unhandled_input)(void);
281 void (*fn)(struct buffer*);
283 TAILQ_ENTRY(keymap) keymaps;
287 void config_init(void);
288 int config_setprfx(const char *, const char *, const char *);
289 int config_setvari(const char *, int);
290 int config_setvars(const char *, char *);
291 int config_setcolor(int, const char *, int, int, int);
292 int config_setattr(const char *, int, int, int);
293 void config_apply_style(void);
297 int fs_main(struct imsgbuf*);
298 int load_certs(struct ohash*);
299 int load_last_session(void(*)(const char*));
302 int client_main(struct imsgbuf*);
305 void gemtext_initparser(struct parser*);
308 void hist_clear_forward(struct histhead*, struct hist*);
309 void hist_push(struct histhead*, struct hist*);
312 int kbd(const char*);
313 const char *unkbd(int);
314 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
317 int setup_parser_for(struct tab*);
320 extern const char *about_about;
321 extern const char *about_blank;
322 extern const char *about_help;
323 extern const char *about_new;
325 #define CANNOT_FETCH 0
326 #define TOO_MUCH_REDIRECTS 1
327 #define MALFORMED_RESPONSE 2
328 #define UNKNOWN_TYPE_OR_CSET 3
329 extern const char *err_pages[70];
332 void parseconfig(const char *, int);
335 int parser_append(struct parser*, const char*, size_t);
336 int parser_set_buf(struct parser*, const char*, size_t);
337 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
340 void sandbox_network_process(void);
341 void sandbox_ui_process(void);
342 void sandbox_fs_process(void);
345 void load_about_url(struct tab*, const char*);
346 void load_gemini_url(struct tab*, const char*);
347 void load_via_proxy(struct tab *, const char *, struct proxy *);
348 void load_url(struct tab*, const char*);
349 int load_previous_page(struct tab*);
350 int load_next_page(struct tab*);
351 void stop_tab(struct tab*);
352 void add_to_bookmarks(const char*);
353 void save_session(void);
356 void textplain_initparser(struct parser*);
359 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
360 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
361 void tofu_add(struct ohash*, struct tofu_entry*);
362 void tofu_update(struct ohash*, struct tofu_entry*);
365 extern int body_lines;
366 extern int body_cols;
367 extern int in_minibuffer;
372 struct vline *current_line;
422 extern struct thiskey thiskey;
424 extern struct histhead eecmd_history,
433 void (*donefn)(void);
434 void (*abortfn)(void);
439 struct buffer buffer;
441 struct histhead *history;
442 struct hist *hist_cur;
445 extern struct ministate ministate;
447 void save_excursion(struct excursion *, struct buffer *);
448 void restore_excursion(struct excursion *, struct buffer *);
449 void restore_cursor(struct buffer *);
450 void minibuffer_taint_hist(void);
451 void eecmd_self_insert(void);
452 void eecmd_select(void);
453 void ir_self_insert(void);
454 void ir_select(void);
455 void lu_self_insert(void);
456 void lu_select(void);
457 void bp_select(void);
458 void vmessage(const char*, va_list);
459 void message(const char*, ...) __attribute__((format(printf, 1, 2)));
460 void start_loading_anim(struct tab *tab);
461 void load_url_in_tab(struct tab *, const char *);
462 void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead *);
463 void exit_minibuffer(void);
464 void switch_to_tab(struct tab *);
465 struct tab *current_tab(void);
466 struct tab *new_tab(const char *);
467 unsigned int tab_new_id(void);
468 int ui_init(int, char * const*);
469 void ui_on_tab_loaded(struct tab*);
470 void ui_on_tab_refresh(struct tab*);
471 const char *ui_keyname(int);
472 void ui_toggle_side_window(void);
473 void ui_schedule_redraw(void);
474 void ui_require_input(struct tab*, int);
475 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
476 void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
480 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
481 size_t utf8_encode(uint32_t, char*);
482 char *utf8_nth(char*, size_t);
483 size_t utf8_cplen(char*);
484 size_t utf8_chwidth(uint32_t);
485 size_t utf8_snwidth(const char*, size_t);
486 size_t utf8_swidth(const char*);
487 size_t utf8_swidth_between(const char*, const char*);
488 char *utf8_next_cp(const char*);
489 char *utf8_prev_cp(const char*, const char*);
492 int mark_nonblock(int);
493 int has_prefix(const char*, const char*);
494 int unicode_isspace(uint32_t);
495 int unicode_isgraph(uint32_t);
496 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
499 void empty_linelist(struct buffer*);
500 void empty_vlist(struct buffer*);
501 int wrap_text(struct buffer*, const char*, struct line*, size_t);
502 int hardwrap_text(struct buffer*, struct line*, size_t);
504 #endif /* TELESCOPE_H */