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 */
61 extern char *new_tab_url;
62 extern int fill_column;
63 extern int olivetti_mode;
64 extern int enable_colors;
70 extern struct lineprefix line_prefixes[];
77 extern struct line_face line_faces[];
80 int background, tab, current_tab;
82 extern struct tab_face tab_face;
89 int left, body, right;
91 extern struct body_face body_face;
93 struct modeline_face {
96 extern struct modeline_face modeline_face;
98 struct minibuffer_face {
101 extern struct minibuffer_face minibuffer_face;
121 TAILQ_ENTRY(line) lines;
125 const struct line *parent;
128 TAILQ_ENTRY(vline) vlines;
134 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
135 typedef int (*parserfreefn)(struct parser*);
137 typedef void (imsg_handlerfn)(struct imsg*, size_t);
149 TAILQ_HEAD(, line) head;
153 * differnt types of trust for a certificate. Following
154 * gemini://thfr.info/gemini/modified-trust-verify.gmi
164 char domain[GEMINI_URL_LEN];
167 * enough space for ``PROTO:HASH''. probably isn't a good
175 TAILQ_HEAD(mhisthead, hist) head;
180 TAILQ_ENTRY(hist) entries;
186 size_t last_line_off;
193 struct vline *current_line;
195 TAILQ_HEAD(vhead, vline) head;
198 #define TAB_CURRENT 0x1
199 #define TAB_URGENT 0x2
201 #define NEW_TAB_URL "about:new"
203 extern TAILQ_HEAD(tabshead, tab) tabshead;
205 TAILQ_ENTRY(tab) tabs;
210 enum trust_state trust;
212 struct histhead hist;
213 struct hist *hist_cur;
217 char meta[GEMINI_URL_LEN];
220 struct buffer buffer;
223 short loading_anim_step;
224 struct event loadingev;
235 * should load the given url in the tab. Optionally, it may
236 * consider the given url as relative to the one already
237 * present in tab. It must set tab->urlstr to a serialized
238 * human-friendly URL.
240 void (*loadfn)(struct tab*, const char*);
244 TAILQ_HEAD(map, keymap) m;
245 void (*unhandled_input)(void);
252 void (*fn)(struct buffer*);
254 TAILQ_ENTRY(keymap) keymaps;
258 int config_setprfx(const char *, const char *, const char *);
259 int config_setvari(const char *, int);
260 int config_setvars(const char *, char *);
261 int config_setcolor(int, const char *, int, int, int);
262 void config_apply_colors(void);
266 int fs_main(struct imsgbuf*);
267 int load_certs(struct ohash*);
268 int load_last_session(void(*)(const char*));
271 int client_main(struct imsgbuf*);
274 void gemtext_initparser(struct parser*);
277 void hist_clear_forward(struct histhead*, struct hist*);
278 void hist_push(struct histhead*, struct hist*);
281 int kbd(const char*);
282 const char *unkbd(int);
283 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
286 int setup_parser_for(struct tab*);
289 extern const char *about_about;
290 extern const char *about_blank;
291 extern const char *about_help;
292 extern const char *about_new;
294 #define CANNOT_FETCH 0
295 #define TOO_MUCH_REDIRECTS 1
296 #define MALFORMED_RESPONSE 2
297 #define UNKNOWN_TYPE_OR_CSET 3
298 extern const char *err_pages[70];
301 void parseconfig(const char *, int);
304 int parser_append(struct parser*, const char*, size_t);
305 int parser_set_buf(struct parser*, const char*, size_t);
306 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
309 void sandbox_network_process(void);
310 void sandbox_ui_process(void);
311 void sandbox_fs_process(void);
314 void load_about_url(struct tab*, const char*);
315 void load_gemini_url(struct tab*, const char*);
316 void load_url(struct tab*, const char*);
317 int load_previous_page(struct tab*);
318 int load_next_page(struct tab*);
319 void stop_tab(struct tab*);
320 void add_to_bookmarks(const char*);
321 void save_session(void);
324 void textplain_initparser(struct parser*);
327 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
328 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
329 void tofu_add(struct ohash*, struct tofu_entry*);
330 void tofu_update(struct ohash*, struct tofu_entry*);
333 extern int body_lines;
334 extern int body_cols;
335 extern int in_minibuffer;
379 extern struct thiskey thiskey;
381 extern struct histhead eecmd_history,
390 void (*donefn)(void);
391 void (*abortfn)(void);
396 struct buffer buffer;
398 struct histhead *history;
399 struct hist *hist_cur;
402 extern struct ministate ministate;
404 void restore_cursor(struct buffer *);
405 void minibuffer_taint_hist(void);
406 void eecmd_self_insert(void);
407 void eecmd_select(void);
408 void ir_self_insert(void);
409 void ir_select(void);
410 void lu_self_insert(void);
411 void lu_select(void);
412 void bp_select(void);
413 void vmessage(const char*, va_list);
414 void message(const char*, ...) __attribute__((format(printf, 1, 2)));
415 void start_loading_anim(struct tab *tab);
416 void load_url_in_tab(struct tab *, const char *);
417 void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead *);
418 void exit_minibuffer(void);
419 void switch_to_tab(struct tab *);
420 struct tab *current_tab(void);
421 struct tab *new_tab(const char *);
422 unsigned int tab_new_id(void);
423 int ui_init(int, char * const*);
424 void ui_on_tab_loaded(struct tab*);
425 void ui_on_tab_refresh(struct tab*);
426 const char *ui_keyname(int);
427 void ui_toggle_side_window(void);
428 void ui_schedule_redraw(void);
429 void ui_require_input(struct tab*, int);
430 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
431 void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
435 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
436 size_t utf8_encode(uint32_t, char*);
437 char *utf8_nth(char*, size_t);
438 size_t utf8_cplen(char*);
439 size_t utf8_chwidth(uint32_t);
440 size_t utf8_snwidth(const char*, size_t);
441 size_t utf8_swidth(const char*);
442 size_t utf8_swidth_between(const char*, const char*);
443 char *utf8_next_cp(const char*);
444 char *utf8_prev_cp(const char*, const char*);
447 int mark_nonblock(int);
448 int has_prefix(const char*, const char*);
449 int unicode_isspace(uint32_t);
450 int unicode_isgraph(uint32_t);
451 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
454 void empty_linelist(struct buffer*);
455 void empty_vlist(struct buffer*);
456 int wrap_text(struct buffer*, const char*, struct line*, size_t);
457 int hardwrap_text(struct buffer*, struct line*, size_t);
459 #endif /* TELESCOPE_H */