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;
69 extern struct lineprefix line_prefixes[];
75 extern struct line_face line_faces[];
78 int background, tab, current_tab;
80 extern struct tab_face tab_face;
82 struct modeline_face {
85 extern struct modeline_face modeline_face;
87 struct minibuffer_face {
90 extern struct minibuffer_face minibuffer_face;
110 TAILQ_ENTRY(line) lines;
114 const struct line *parent;
117 TAILQ_ENTRY(vline) vlines;
123 typedef int (*parsechunkfn)(struct parser*, const char*, size_t);
124 typedef int (*parserfreefn)(struct parser*);
126 typedef void (imsg_handlerfn)(struct imsg*, size_t);
138 TAILQ_HEAD(, line) head;
142 * differnt types of trust for a certificate. Following
143 * gemini://thfr.info/gemini/modified-trust-verify.gmi
153 char domain[GEMINI_URL_LEN];
156 * enough space for ``PROTO:HASH''. probably isn't a good
164 TAILQ_HEAD(mhisthead, hist) head;
169 TAILQ_ENTRY(hist) entries;
175 size_t last_line_off;
182 struct vline *current_line;
184 TAILQ_HEAD(vhead, vline) head;
188 #define TAB_CURRENT 0x1
189 #define TAB_URGENT 0x2
191 #define NEW_TAB_URL "about:new"
193 extern TAILQ_HEAD(tabshead, tab) tabshead;
195 TAILQ_ENTRY(tab) tabs;
200 enum trust_state trust;
202 struct histhead hist;
203 struct hist *hist_cur;
207 char meta[GEMINI_URL_LEN];
210 struct buffer buffer;
213 short loading_anim_step;
214 struct event loadingev;
225 * should load the given url in the tab. Optionally, it may
226 * consider the given url as relative to the one already
227 * present in tab. It must set tab->urlstr to a serialized
228 * human-friendly URL.
230 void (*loadfn)(struct tab*, const char*);
234 TAILQ_HEAD(map, keymap) m;
235 void (*unhandled_input)(void);
242 void (*fn)(struct buffer*);
244 TAILQ_ENTRY(keymap) keymaps;
248 int config_setprfx(const char *, int, const char *);
249 int config_setvari(const char *, int);
250 int config_setvars(const char *, char *);
254 int fs_main(struct imsgbuf*);
255 int load_certs(struct ohash*);
256 int load_last_session(void(*)(const char*));
259 int client_main(struct imsgbuf*);
262 void gemtext_initparser(struct parser*);
265 void hist_clear_forward(struct histhead*, struct hist*);
266 void hist_push(struct histhead*, struct hist*);
269 int kbd(const char*);
270 const char *unkbd(int);
271 int kmap_define_key(struct kmap*, const char*, void(*)(struct buffer*));
274 int setup_parser_for(struct tab*);
277 extern const char *about_about;
278 extern const char *about_blank;
279 extern const char *about_help;
280 extern const char *about_new;
282 #define CANNOT_FETCH 0
283 #define TOO_MUCH_REDIRECTS 1
284 #define MALFORMED_RESPONSE 2
285 #define UNKNOWN_TYPE_OR_CSET 3
286 extern const char *err_pages[70];
289 void parseconfig(const char *, int);
292 int parser_append(struct parser*, const char*, size_t);
293 int parser_set_buf(struct parser*, const char*, size_t);
294 int parser_foreach_line(struct parser*, const char*, size_t, parsechunkfn);
297 void sandbox_network_process(void);
298 void sandbox_ui_process(void);
299 void sandbox_fs_process(void);
302 void load_about_url(struct tab*, const char*);
303 void load_gemini_url(struct tab*, const char*);
304 void load_url(struct tab*, const char*);
305 int load_previous_page(struct tab*);
306 int load_next_page(struct tab*);
307 void stop_tab(struct tab*);
308 void add_to_bookmarks(const char*);
309 void save_session(void);
312 void textplain_initparser(struct parser*);
315 void tofu_init(struct ohash*, unsigned int, ptrdiff_t);
316 struct tofu_entry *tofu_lookup(struct ohash*, const char*, const char*);
317 void tofu_add(struct ohash*, struct tofu_entry*);
318 void tofu_update(struct ohash*, struct tofu_entry*);
321 extern int body_lines;
322 extern int body_cols;
323 extern int in_minibuffer;
330 extern struct thiskey thiskey;
332 extern struct histhead eecmd_history,
341 void (*donefn)(void);
342 void (*abortfn)(void);
347 struct buffer buffer;
349 struct histhead *history;
350 struct hist *hist_cur;
353 extern struct ministate ministate;
355 void restore_cursor(struct buffer *);
356 void minibuffer_taint_hist(void);
357 void eecmd_self_insert(void);
358 void eecmd_select(void);
359 void ir_self_insert(void);
360 void ir_select(void);
361 void lu_self_insert(void);
362 void lu_select(void);
363 void bp_select(void);
364 void vmessage(const char*, va_list);
365 void message(const char*, ...) __attribute__((format(printf, 1, 2)));
366 void start_loading_anim(struct tab *tab);
367 void load_url_in_tab(struct tab *, const char *);
368 void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead *);
369 void exit_minibuffer(void);
370 void switch_to_tab(struct tab *);
371 struct tab *current_tab(void);
372 struct tab *new_tab(const char *);
373 unsigned int tab_new_id(void);
374 int ui_init(int, char * const*);
375 void ui_on_tab_loaded(struct tab*);
376 void ui_on_tab_refresh(struct tab*);
377 const char *ui_keyname(int);
378 void ui_toggle_side_window(void);
379 void ui_schedule_redraw(void);
380 void ui_require_input(struct tab*, int);
381 void ui_read(const char*, void(*)(const char*, unsigned int), unsigned int);
382 void ui_yornp(const char*, void (*)(int, unsigned int), unsigned int);
386 uint32_t utf8_decode(uint32_t*restrict, uint32_t*restrict, uint8_t);
387 size_t utf8_encode(uint32_t, char*);
388 char *utf8_nth(char*, size_t);
389 size_t utf8_cplen(char*);
390 size_t utf8_chwidth(uint32_t);
391 size_t utf8_snwidth(const char*, size_t);
392 size_t utf8_swidth(const char*);
393 size_t utf8_swidth_between(const char*, const char*);
394 char *utf8_next_cp(const char*);
395 char *utf8_prev_cp(const char*, const char*);
398 int mark_nonblock(int);
399 int has_prefix(const char*, const char*);
400 int unicode_isspace(uint32_t);
401 int unicode_isgraph(uint32_t);
402 void dispatch_imsg(struct imsgbuf*, imsg_handlerfn**, size_t);
405 void empty_linelist(struct buffer*);
406 void empty_vlist(struct buffer*);
407 int wrap_text(struct buffer*, const char*, struct line*, size_t);
408 int hardwrap_text(struct buffer*, struct line*, size_t);
410 #endif /* TELESCOPE_H */