zygo

ncurses gopher client
git clone https://hhvn.uk/zygo
git clone git://hhvn.uk/zygo
Log | Files | Refs

zygo.h (3178B)


      1 /*
      2  * zygo/zygo.h
      3  *
      4  * Copyright (c) 2022 hhvn <dev@hhvn.uk>
      5  *
      6  * Permission to use, copy, modify, and distribute this software for any
      7  * purpose with or without fee is hereby granted, provided that the above
      8  * copyright notice and this permission notice appear in all copies.
      9  *
     10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17  *
     18  */
     19 
     20 #define BUFLEN 2048
     21 #define zygo_assert(expr) (expr ? ((void)0) : (endwin(), assert(expr)))
     22 #define INFO(desc) {0, 'i', desc, NULL, NULL, NULL}
     23 #define LINK(type, desc, selector, server, port) \
     24 	{0, type, desc, selector, server, port}
     25 
     26 typedef struct Elem Elem;
     27 struct Elem {
     28 	int tls;
     29 	char type;
     30 	char *desc;
     31 	char *selector;
     32 	char *server;
     33 	char *port;
     34 	size_t id; /* only set when:
     35 		    * - type != 'i'
     36 		    * - in a list */
     37 	/* Following sizes only set when first in list */
     38 	size_t len;
     39 	size_t lastid;
     40 	struct Elem *next;
     41 };
     42 
     43 enum { DEFL, EXTR,
     44 	MDH1, MDH2, MDH3, MDH4 };
     45 typedef struct Scheme Scheme;
     46 struct Scheme {
     47 	char type;
     48 	char *name;
     49 	short fg;
     50 	short pair;
     51 };
     52 
     53 enum {
     54 	PAIR_BAR = 1,
     55 	PAIR_URI = 2,
     56 	PAIR_CMD = 3,
     57 	PAIR_ARG = 4,
     58 	PAIR_ERR = 5,
     59 	PAIR_EID = 6,
     60 	PAIR_SCHEME = 7,
     61 };
     62 
     63 extern Elem *history;
     64 extern Elem *page;
     65 extern Elem *current;
     66 extern int insecure;
     67 
     68 /* Memory functions */
     69 void *emalloc(size_t size);
     70 void *erealloc(void *ptr, size_t size);
     71 char *estrdup(const char *str);
     72 
     73 /* Elem functions */
     74 void elem_free(Elem *e);
     75 Elem *elem_create(int tls, char type, char *desc, char *selector, char *server, char *port);
     76 Elem *elem_dup(Elem *e);
     77 Elem *uritoelem(const char *uri);
     78 Elem *gophertoelem(Elem *from, const char *line);
     79 char *elemtouri(Elem *e);
     80 
     81 /* List functions */
     82 void list_free(Elem **l);
     83 void list_append(Elem **l, Elem *e);
     84 Elem *list_get(Elem **l, size_t elem);
     85 Elem *list_idget(Elem **l, size_t id);
     86 void list_rev(Elem **l);
     87 size_t list_len(Elem **l);
     88 
     89 /* Network functions
     90  * only works with one fd/ctx at 
     91  * a time, reset at net_connect */
     92 int net_connect(Elem *e, int silent);
     93 int net_read(void *buf, size_t count);
     94 int net_write(void *buf, size_t count);
     95 int net_close(void);
     96 
     97 /* UI functions */
     98 void error(char *format, ...);
     99 Scheme *getscheme(Elem *e);
    100 void find(int backward);
    101 int draw_line(Elem *e, int nwidth);
    102 void draw_page(void);
    103 void draw_bar(void);
    104 void input(int c);
    105 char *prompt(char *prompt, size_t count);
    106 Elem *strtolink(char *str);
    107 void pagescroll(int lines);
    108 void idgo(size_t id);
    109 int wantnum(char cmd);
    110 int acceptkey(char cmd, int key);
    111 
    112 /* Main loop */
    113 void run(void);
    114 
    115 /* Misc */
    116 int readline(char *buf, size_t count);
    117 int go(Elem *e, int mhist, int notls);
    118 int digits(int i);
    119 void sighandler(int signal);
    120 #ifdef ZYGO_STRLCAT
    121 #undef strlcat
    122 size_t strlcat(char *dst, const char *src, size_t dstsize);
    123 #endif