"Fossies" - the Fresh Open Source Software Archive

Member "links-1.03/links.h" (23 Nov 2011, 60181 Bytes) of archive /linux/www/links-1.03.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "links.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8_vs_1.03.

    1 #ifndef __EXTENSIONS__
    2 #define __EXTENSIONS__
    3 #endif
    4 
    5 #ifndef _LARGEFILE_SOURCE
    6 #define _LARGEFILE_SOURCE   1
    7 #endif
    8 
    9 #ifndef _ALL_SOURCE
   10 #define _ALL_SOURCE             1
   11 #endif
   12 
   13 #ifndef _FILE_OFFSET_BITS
   14 #define _FILE_OFFSET_BITS   64
   15 #endif
   16 
   17 #ifdef HAVE_CONFIG_H
   18 #include "config.h"
   19 #endif
   20 #ifdef HAVE_CONFIG2_H
   21 #include "config2.h"
   22 #endif
   23 
   24 #include "os_dep.h"
   25 #include <stdio.h>
   26 #include <stdlib.h>
   27 #include <stdarg.h>
   28 #ifdef HAVE_UNISTD_H
   29 #include <unistd.h>
   30 #endif
   31 #include <string.h>
   32 #include <errno.h>
   33 #ifdef HAVE_LIMITS_H
   34 #include <limits.h>
   35 #endif
   36 #include <sys/types.h>
   37 
   38 #ifndef __USE_XOPEN
   39 #define U_X
   40 #define __USE_XOPEN
   41 #endif
   42 #ifndef _XOPEN_SOURCE
   43 #define X_S
   44 #define _XOPEN_SOURCE   5   /* The 5 is a kludge to get a strptime() prototype in NetBSD */
   45 #endif
   46 #ifdef TIME_WITH_SYS_TIME
   47 #ifdef HAVE_SYS_TIME_H
   48 #include <sys/time.h>
   49 #endif
   50 #ifdef HAVE_TIME_H
   51 #include <time.h>
   52 #endif
   53 #else
   54 #if defined(TM_IN_SYS_TIME) && defined(HAVE_SYS_TIME_H)
   55 #include <sys/time.h>
   56 #elif defined(HAVE_TIME_H)
   57 #include <time.h>
   58 #endif
   59 #endif
   60 #ifdef X_S
   61 #undef _XOPEN_SOURCE
   62 #endif
   63 #ifdef U_X
   64 #undef __USE_XOPEN
   65 #endif
   66 
   67 
   68 #include <sys/stat.h>
   69 #ifdef HAVE_FCNTL_H
   70 #include <fcntl.h>
   71 #endif
   72 #ifdef HAVE_DIRENT_H
   73 #include <dirent.h>
   74 #endif
   75 #include <signal.h>
   76 /*#ifdef HAVE_SIGACTION_H
   77 #include <sigaction.h>
   78 #endif*/
   79 #ifdef HAVE_SYS_WAIT_H
   80 #include <sys/wait.h>
   81 #endif
   82 #ifdef HAVE_SYS_SELECT_H
   83 #include <sys/select.h>
   84 #endif
   85 #ifdef HAVE_SYS_RESOURCE_H
   86 #include <sys/resource.h>
   87 #endif
   88 #ifdef HAVE_SYS_CYGWIN_H
   89 #include <sys/cygwin.h>
   90 #endif
   91 #ifdef HAVE_INTERIX_INTERIX_H
   92 #include <interix/interix.h>
   93 #endif
   94 #ifdef HAVE_IO_H
   95 #include <io.h>
   96 #endif
   97 #ifdef HAVE_SYS_UTSNAME_H
   98 #include <sys/utsname.h>
   99 #endif
  100 #ifdef HAVE_PWD_H
  101 #include <pwd.h>
  102 #endif
  103 #ifdef HAVE_GRP_H
  104 #include <grp.h>
  105 #endif
  106 /*
  107 #ifdef HAVE_WAIT_H
  108 #include <wait.h>
  109 #endif
  110 */
  111 
  112 #ifdef HAVE_NETINET_IN_SYSTM_H
  113 #include <netinet/in_systm.h>
  114 #else
  115 #ifdef HAVE_NETINET_IN_SYSTEM_H
  116 #include <netinet/in_system.h>
  117 #endif
  118 #endif
  119 #include <netdb.h>
  120 #include <sys/socket.h>
  121 #include <netinet/in.h>
  122 #ifdef HAVE_NETINET_IP_H
  123 #include <netinet/ip.h>
  124 #endif
  125 #ifdef HAVE_ARPA_INET_H
  126 #include <arpa/inet.h>
  127 #endif
  128 #include <utime.h>
  129 
  130 #include <termios.h>
  131 
  132 #ifdef HAVE_LONG_LONG
  133 #define longlong long long
  134 #else
  135 #define longlong double
  136 #endif
  137 
  138 #if defined(__INTERIX) && defined(HAVE_STRTOQ)
  139 extern quad_t
  140 #if defined(__cdecl) || defined(_MSC_VER)
  141 __cdecl
  142 #endif
  143 strtoq(const char *, char **, int);
  144 #endif
  145 
  146 #if defined(__hpux) && defined(__LP64__)
  147 #undef HAVE_SOCKLEN_T
  148 #endif
  149 
  150 #ifndef HAVE_SOCKLEN_T
  151 #define socklen_t int
  152 #endif
  153 
  154 #ifndef PF_INET
  155 #define PF_INET AF_INET
  156 #endif
  157 #ifndef PF_UNIX
  158 #define PF_UNIX AF_UNIX
  159 #endif
  160 
  161 #ifdef HAVE_SSL
  162 #include <openssl/ssl.h>
  163 #include <openssl/rand.h>
  164 #endif
  165 
  166 #include "os_depx.h"
  167 
  168 #include "setup.h"
  169 
  170 #define LINKS_COPYRIGHT "(C) 1999 - 2011 Mikulas Patocka"
  171 #define LINKS_COPYRIGHT_8859_1 "(C) 1999 - 2011 Mikul\341s Patocka"
  172 #define LINKS_COPYRIGHT_8859_2 "(C) 1999 - 2011 Mikul\341\271 Pato\350ka"
  173 
  174 #ifdef HAVE_POINTER_COMPARISON_BUG
  175 #define DUMMY ((void *)1L)
  176 #else
  177 #define DUMMY ((void *)-1L)
  178 #endif
  179 
  180 #define RET_OK      0
  181 #define RET_ERROR   1
  182 #define RET_SIGNAL  2
  183 #define RET_SYNTAX  3
  184 #define RET_FATAL   4
  185 
  186 #ifndef HAVE_MEMMOVE
  187 void *memmove(void *, const void *, size_t);
  188 #endif
  189 #ifndef HAVE_RAISE
  190 int raise(int);
  191 #endif
  192 #ifndef HAVE_STRTOUL
  193 unsigned long strtoul(const char *, char **, int);
  194 #endif
  195 #ifndef HAVE_STRERROR
  196 char *strerror(int);
  197 #endif
  198 #ifndef HAVE_GETTIMEOFDAY
  199 struct timeval {
  200     long tv_sec;
  201     long tv_usec;
  202 };
  203 struct timezone {
  204     int tz_minuteswest;
  205     int tz_dsttime;
  206 };
  207 int gettimeofday(struct timeval *tv, struct timezone *tz);
  208 #endif
  209 #ifndef HAVE_STRLEN
  210 size_t strlen(const char *s);
  211 #endif
  212 #ifndef HAVE_STRCPY
  213 char *strcpy(char *dst, const char *src);
  214 #endif
  215 #ifndef HAVE_STRCHR
  216 char *strchr(const char *s, int c);
  217 #endif
  218 #ifndef HAVE_STRRCHR
  219 char *strrchr(const char *s, int c);
  220 #endif
  221 #ifndef HAVE_STRCMP
  222 int strcmp(const char *s1, const char *s2);
  223 #endif
  224 #ifndef HAVE_STRNCMP
  225 int strncmp(const char *s1, const char *s2, size_t n);
  226 #endif
  227 #ifndef HAVE_STRCSPN
  228 size_t strcspn(const char *s, const char *reject);
  229 #endif
  230 #ifndef HAVE_STRSTR
  231 char *strstr(const char *haystack, const char *needle);
  232 #endif
  233 #ifndef HAVE_TEMPNAM
  234 char *tempnam(const char *dir, const char *pfx);
  235 #endif
  236 
  237 #define option option_dirty_workaround_for_name_clash_with_include_on_cygwin
  238 #define table table_dirty_workaround_for_name_clash_with_libraries_on_macos
  239 #define scroll scroll_dirty_workaround_for_name_clash_with_libraries_on_macos
  240 
  241 /* error.c */
  242 
  243 void do_not_optimize_here(void *p);
  244 void check_memory_leaks();
  245 void error(unsigned char *, ...);
  246 void debug_msg(unsigned char *, ...);
  247 void int_error(unsigned char *, ...);
  248 extern int errline;
  249 extern unsigned char *errfile;
  250 
  251 #define internal while (1) errfile = __FILE__, errline = __LINE__, int_error
  252 #define debug errfile = __FILE__, errline = __LINE__, debug_msg
  253 
  254 #ifdef SPECIAL_MALLOC
  255 
  256 void *sp_malloc(size_t);
  257 void sp_free(void *);
  258 void *sp_realloc(void *, size_t);
  259 
  260 #define xmalloc sp_malloc
  261 #define xfree sp_free
  262 #define xrealloc sp_realloc
  263 
  264 #else
  265 
  266 #define xmalloc malloc
  267 #define xfree free
  268 #define xrealloc realloc
  269 
  270 #endif
  271 
  272 /* inline */
  273 
  274 void fatal_tty_exit(void);
  275 
  276 #ifdef LEAK_DEBUG
  277 
  278 extern long mem_amount;
  279 extern long last_mem_amount;
  280 
  281 #ifndef LEAK_DEBUG_LIST
  282 struct alloc_header {
  283     size_t size;
  284 };
  285 #else
  286 struct alloc_header {
  287     struct alloc_header *next;
  288     struct alloc_header *prev;
  289     size_t size;
  290     int line;
  291     unsigned char *file;
  292     unsigned char *comment;
  293 };
  294 #endif
  295 
  296 #define L_D_S ((sizeof(struct alloc_header) + 15) & ~15)
  297 
  298 #endif
  299 
  300 #define overalloc()                         \
  301 do {                                    \
  302     error("ERROR: attempting to allocate too large block at %s:%d", __FILE__, __LINE__);\
  303     fatal_tty_exit();                       \
  304     exit(RET_FATAL);                        \
  305 } while (1) /* while (1) is not a type --- it's here to allow the
  306     compiler that doesn't know that exit doesn't return to do better
  307     optimizations */
  308 
  309 #ifdef LEAK_DEBUG
  310 
  311 void *debug_mem_alloc(unsigned char *, int, size_t);
  312 void debug_mem_free(unsigned char *, int, void *);
  313 void *debug_mem_realloc(unsigned char *, int, void *, size_t);
  314 void set_mem_comment(void *, unsigned char *, int);
  315 
  316 #define mem_alloc(x) debug_mem_alloc(__FILE__, __LINE__, x)
  317 #define mem_free(x) debug_mem_free(__FILE__, __LINE__, x)
  318 #define mem_realloc(x, y) debug_mem_realloc(__FILE__, __LINE__, x, y)
  319 
  320 #else
  321 
  322 static inline void *mem_alloc(size_t size)
  323 {
  324     void *p;
  325     if (!size) return DUMMY;
  326     if (size > MAXINT) overalloc();
  327     if (!(p = malloc(size))) {
  328         error("ERROR: out of memory (malloc returned NULL)");
  329         fatal_tty_exit();
  330         exit(RET_FATAL);
  331         return NULL;
  332     }
  333     return p;
  334 }
  335 
  336 static inline void mem_free(void *p)
  337 {
  338     if (p == DUMMY) return;
  339     if (!p) {
  340         internal("mem_free(NULL)");
  341         return;
  342     }
  343     free(p);
  344 }
  345 
  346 static inline void *mem_realloc(void *p, size_t size)
  347 {
  348     if (p == DUMMY) return mem_alloc(size);
  349     if (!p) {
  350         internal("mem_realloc(NULL, %d)", size);
  351         return NULL;
  352     }
  353     if (!size) {
  354         mem_free(p);
  355         return DUMMY;
  356     }
  357     if (size > MAXINT) overalloc();
  358     if (!(p = realloc(p, size))) {
  359         error("ERROR: out of memory (realloc returned NULL)");
  360         fatal_tty_exit();
  361         exit(RET_FATAL);
  362         return NULL;
  363     }
  364     return p;
  365 }
  366 
  367 static inline void *debug_mem_alloc(unsigned char *f, int l, size_t s) { return mem_alloc(s); }
  368 static inline void debug_mem_free(unsigned char *f, int l, void *p) { mem_free(p); }
  369 static inline void *debug_mem_realloc(unsigned char *f, int l, void *p, size_t s) { return mem_realloc(p, s); }
  370 static inline void set_mem_comment(void *p, unsigned char *c, int l) {}
  371 
  372 #endif
  373 
  374 static inline unsigned char upcase(unsigned char a)
  375 {
  376     if (a >= 'a' && a <= 'z') a -= 0x20;
  377     return a;
  378 }
  379 
  380 static inline int xstrcmp(unsigned char *s1, unsigned char *s2)
  381 {
  382         if (!s1 && !s2) return 0;
  383         if (!s1) return -1;
  384         if (!s2) return 1;
  385         return strcmp(s1, s2);
  386 }
  387 
  388 static inline int cmpbeg(unsigned char *str, unsigned char *b)
  389 {
  390     while (*str && upcase(*str) == upcase(*b)) str++, b++;
  391     return !!*b;
  392 }
  393 
  394 #if !(defined(LEAK_DEBUG) && defined(LEAK_DEBUG_LIST))
  395 
  396 static inline unsigned char *memacpy(const unsigned char *src, size_t len)
  397 {
  398     unsigned char *m;
  399     m = mem_alloc(len + 1);
  400     memcpy(m, src, len);
  401     m[len] = 0;
  402     return m;
  403 }
  404 
  405 static inline unsigned char *stracpy(const unsigned char *src)
  406 {
  407     return src ? memacpy(src, src != DUMMY ? strlen(src) : 0) : NULL;
  408 }
  409 
  410 #else
  411 
  412 static inline unsigned char *debug_memacpy(unsigned char *f, int l, unsigned char *src, size_t len)
  413 {
  414     unsigned char *m;
  415     m = debug_mem_alloc(f, l, len + 1);
  416     memcpy(m, src, len);
  417     m[len] = 0;
  418     return m;
  419 }
  420 
  421 #define memacpy(s, l) debug_memacpy(__FILE__, __LINE__, s, l)
  422 
  423 static inline unsigned char *debug_stracpy(unsigned char *f, int l, unsigned char *src)
  424 {
  425     return src ? debug_memacpy(f, l, src, src != DUMMY ? strlen(src) : 0) : NULL;
  426 }
  427 
  428 #define stracpy(s) debug_stracpy(__FILE__, __LINE__, s)
  429 
  430 #endif
  431 
  432 static inline int snprint(unsigned char *s, int n, off_t num)
  433 {
  434     off_t q = 1;
  435     while (q <= num / 10) q *= 10;
  436     while (n-- > 1 && q) *(s++) = num / q + '0', num %= q, q /= 10;
  437     *s = 0;
  438     return !!q;
  439 }
  440 
  441 static inline int snzprint(unsigned char *s, int n, off_t num)
  442 {
  443     if (n > 1 && num < 0) *(s++) = '-', num = -num, n--;
  444     return snprint(s, n, num);
  445 }
  446 
  447 static inline void add_to_strn(unsigned char **s, unsigned char *a)
  448 {
  449     unsigned char *p;
  450     size_t l1 = strlen(*s), l2 = strlen(a);
  451     if (((l1 | l2) | (l1 + l2 + 1)) > MAXINT) overalloc();
  452     p = mem_realloc(*s, l1 + l2 + 1);
  453     strcat(p, a);
  454     *s = p;
  455 }
  456 
  457 #define ALLOC_GR    0x040       /* must be power of 2 */
  458 
  459 #define init_str() init_str_x(__FILE__, __LINE__)
  460 
  461 static inline unsigned char *init_str_x(unsigned char *file, int line)
  462 {
  463     unsigned char *s = debug_mem_alloc(file, line, ALLOC_GR);
  464     *s = 0;
  465     return s;
  466 }
  467 
  468 static inline void add_to_str(unsigned char **s, int *l, unsigned char *a)
  469 {
  470     unsigned char *p;
  471     size_t ll = strlen(a);
  472     if (ll > MAXINT || *l + ll > MAXINT) overalloc();
  473     p = *s;
  474     if (((size_t)*l & ~(ALLOC_GR - 1)) != ((*l + ll) & ~(ALLOC_GR - 1))) {
  475         p = *s = mem_realloc(*s, (*l + ll + ALLOC_GR) & ~(ALLOC_GR - 1));
  476     }
  477     strcpy(p + *l, a); *l += ll;
  478 }
  479 
  480 static inline void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, int ll)
  481 {
  482     unsigned char *p;
  483     if (*l + ll < 0) overalloc();
  484     p = *s;
  485     if ((*l & ~(ALLOC_GR - 1)) != ((*l + ll) & ~(ALLOC_GR - 1))) {
  486         p = *s = mem_realloc(*s, (*l + ll + ALLOC_GR) & ~(ALLOC_GR - 1));
  487     }
  488     memcpy(p + *l, a, ll); p[*l += ll] = 0;
  489 }
  490 
  491 static inline void add_chr_to_str(unsigned char **s, int *l, unsigned char a)
  492 {
  493     unsigned char *p;
  494     if (*l + 1 < 0) overalloc();
  495     p = *s;
  496     if ((*l & (ALLOC_GR - 1)) == ALLOC_GR - 1) {
  497         p = *s = mem_realloc(*s, (*l + 1 + ALLOC_GR) & ~(ALLOC_GR - 1));
  498     }
  499     *(p + *l) = a; *(p + ++(*l)) = 0;
  500 }
  501 
  502 static inline void add_num_to_str(unsigned char **s, int *l, off_t n)
  503 {
  504     unsigned char a[64];
  505     /*sprintf(a, "%d", n);*/
  506     snzprint(a, 64, n);
  507     add_to_str(s, l, a);
  508 }
  509 
  510 static inline void add_knum_to_str(unsigned char **s, int *l, int n)
  511 {
  512     unsigned char a[13];
  513     if (n && n / (1024 * 1024) * (1024 * 1024) == n) snzprint(a, 12, n / (1024 * 1024)), strcat(a, "M");
  514     else if (n && n / 1024 * 1024 == n) snzprint(a, 12, n / 1024), strcat(a, "k");
  515     else snzprint(a, 13, n);
  516     add_to_str(s, l, a);
  517 }
  518 
  519 static inline long strtolx(unsigned char *c, unsigned char **end)
  520 {
  521     long l;
  522     if (c[0] == '0' && upcase(c[1]) == 'X' && c[2]) l = strtol((char *)c + 2, (char **)end, 16);
  523     else l = strtol((char *)c, (char **)end, 10);
  524     if (!*end) return l;
  525     if (upcase(**end) == 'K') {
  526         (*end)++;
  527         if (l < -MAXINT / 1024) return -MAXINT;
  528         if (l > MAXINT / 1024) return MAXINT;
  529         return l * 1024;
  530     }
  531     if (upcase(**end) == 'M') {
  532         (*end)++;
  533         if (l < -MAXINT / (1024 * 1024)) return -MAXINT;
  534         if (l > MAXINT / (1024 * 1024)) return MAXINT;
  535         return l * (1024 * 1024);
  536     }
  537     return l;
  538 }
  539 
  540 /* Copies at most dst_size chars into dst. Ensures null termination of dst. */
  541 static inline unsigned char *safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size)
  542 {
  543     size_t to_copy;
  544     if (!dst_size) return dst;
  545     to_copy = strlen(src);
  546     if (to_copy >= dst_size) to_copy = dst_size - 1;
  547     memcpy(dst, src, to_copy);
  548     memset(dst + to_copy, 0, dst_size - to_copy);
  549     return dst;
  550 }
  551 
  552 
  553 struct list_head {
  554     void *next;
  555     void *prev;
  556 };
  557 
  558 struct xlist_head {
  559     struct xlist_head *next;
  560     struct xlist_head *prev;
  561 };
  562 
  563 #define init_list(x) {do_not_optimize_here(&x); (x).next=&(x); (x).prev=&(x); do_not_optimize_here(&x);}
  564 #define list_empty(x) ((x).next == &(x))
  565 #define del_from_list(x) {do_not_optimize_here(x); ((struct list_head *)(x)->next)->prev=(x)->prev; ((struct list_head *)(x)->prev)->next=(x)->next; do_not_optimize_here(x);}
  566 /*#define add_to_list(l,x) {(x)->next=(l).next; (x)->prev=(typeof(x))&(l); (l).next=(x); if ((l).prev==&(l)) (l).prev=(x);}*/
  567 
  568 #if defined(HAVE_TYPEOF) && !(defined(__GNUC__) && __GNUC__ >= 4)
  569 /* GCC 4 emits warnings about this and I haven't found a way to stop it */
  570 #define add_at_pos(p,x) do {do_not_optimize_here(p); (x)->next=(p)->next; (x)->prev=(p); (p)->next=(x); (x)->next->prev=(x);do_not_optimize_here(p);} while(0)
  571 #define add_to_list(l,x) add_at_pos((typeof(x))(void *)&(l),(x))
  572 #define foreach(e,l) for ((e)=(l).next; (e)!=(typeof(e))(void *)&(l); (e)=(e)->next)
  573 #define foreachback(e,l) for ((e)=(l).prev; (e)!=(typeof(e))(void *)&(l); (e)=(e)->prev)
  574 #else
  575 #define add_at_pos(p,x) do {do_not_optimize_here(p); (x)->next=(p)->next; (x)->prev=(void *)(p); (p)->next=(x); (x)->next->prev=(x); do_not_optimize_here(p); } while(0)
  576 #define add_to_list(l,x) add_at_pos(&(l),(x))
  577 #define foreach(e,l) for ((e)=(l).next; (e)!=(void *)&(l); (e)=(e)->next)
  578 #define foreachback(e,l) for ((e)=(l).prev; (e)!=(void *)&(l); (e)=(e)->prev)
  579 #endif
  580 #define free_list(l) {struct xlist_head *a__;do_not_optimize_here(&l);foreach(a__,l) do_not_optimize_here(a__);foreachback(a__,l) do_not_optimize_here(a__); while ((l).next != &(l)) {a__=(l).next; del_from_list(a__); mem_free(a__); } do_not_optimize_here(&l);}
  581 
  582 #define WHITECHAR(x) ((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
  583 #define U(x) ((x) == '"' || (x) == '\'')
  584 
  585 static inline int isA(unsigned char c)
  586 {
  587     return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
  588             c == '_' || c == '-';
  589 }
  590 
  591 static inline int casecmp(unsigned char *c1, unsigned char *c2, size_t len)
  592 {
  593     size_t i;
  594     for (i = 0; i < len; i++) if (upcase(c1[i]) != upcase(c2[i])) return 1;
  595     return 0;
  596 }
  597 
  598 static inline int can_write(int fd)
  599 {
  600     fd_set fds;
  601     struct timeval tv = {0, 0};
  602     FD_ZERO(&fds);
  603     FD_SET(fd, &fds);
  604     return select(fd + 1, NULL, &fds, NULL, &tv);
  605 }
  606 
  607 static inline int can_read(int fd)
  608 {
  609     fd_set fds;
  610     struct timeval tv = {0, 0};
  611     FD_ZERO(&fds);
  612     FD_SET(fd, &fds);
  613     return select(fd + 1, &fds, NULL, NULL, &tv);
  614 }
  615 
  616 #define CI_BYTES    1
  617 #define CI_FILES    2
  618 #define CI_LOCKED   3
  619 #define CI_LOADING  4
  620 #define CI_TIMERS   5
  621 #define CI_TRANSFER 6
  622 #define CI_CONNECTING   7
  623 #define CI_KEEP     8
  624 #define CI_LIST     9
  625 
  626 /* os_dep.c */
  627 
  628 struct terminal;
  629 
  630 struct open_in_new {
  631     unsigned char *text;
  632     unsigned char *hk;
  633     void (*fn)(struct terminal *term, unsigned char *, unsigned char *);
  634 };
  635 
  636 void close_fork_tty();
  637 int get_system_env();
  638 int is_xterm();
  639 int can_twterm();
  640 int get_terminal_size(int, int *, int *);
  641 void handle_terminal_resize(int, void (*)());
  642 void unhandle_terminal_resize(int);
  643 void set_bin(int);
  644 int c_pipe(int *);
  645 int get_input_handle();
  646 int get_output_handle();
  647 int get_ctl_handle();
  648 void want_draw();
  649 void done_draw();
  650 void terminate_osdep();
  651 void *handle_mouse(int, void (*)(void *, unsigned char *, int), void *);
  652 void unhandle_mouse(void *);
  653 int check_file_name(unsigned char *);
  654 int start_thread(void (*)(void *, int), void *, int);
  655 char *get_clipboard_text();
  656 void set_clipboard_text(char *);
  657 void set_window_title(unsigned char *);
  658 unsigned char *get_window_title();
  659 int is_safe_in_shell(unsigned char);
  660 unsigned char *escape_path(unsigned char *);
  661 void check_shell_security(unsigned char **);
  662 int check_shell_url(unsigned char *);
  663 void block_stdin();
  664 void unblock_stdin();
  665 void init_os(void);
  666 void init_os_terminal(void);
  667 void get_path_to_exe(void);
  668 unsigned char *os_conv_to_external_path(unsigned char *, unsigned char *);
  669 unsigned char *os_fixup_external_program(unsigned char *);
  670 int exe(char *);
  671 int resize_window(int, int);
  672 int can_resize_window(int);
  673 int can_open_os_shell(int);
  674 struct open_in_new *get_open_in_new(int);
  675 void set_highpri();
  676 #ifdef HAVE_OPEN_PREALLOC
  677 int can_prealloc(char *);
  678 int open_prealloc(char *, int, int, off_t);
  679 void prealloc_truncate(int, off_t);
  680 #else
  681 static inline void prealloc_truncate(int x, off_t y) {}
  682 #endif
  683 void os_cfmakeraw(struct termios *t);
  684 
  685 /* select.c */
  686 
  687 #ifndef FD_SETSIZE
  688 #define FD_SETSIZE 1024
  689 #endif
  690 
  691 typedef long ttime;
  692 typedef unsigned long uttime;
  693 typedef unsigned tcount;
  694 
  695 extern int terminate;
  696 
  697 long select_info(int);
  698 void select_loop(void (*)());
  699 int register_bottom_half(void (*)(void *), void *);
  700 void check_bottom_halves();
  701 int install_timer(ttime, void (*)(void *), void *);
  702 void kill_timer(int);
  703 ttime get_time();
  704 
  705 #define H_READ  0
  706 #define H_WRITE 1
  707 #define H_ERROR 2
  708 #define H_DATA  3
  709 
  710 void *get_handler(int, int);
  711 void set_handlers(int, void (*)(void *), void (*)(void *), void (*)(void *), void *);
  712 void install_signal_handler(int, void (*)(void *), void *, int);
  713 void interruptible_signal(int sig, int in);
  714 void set_sigcld();
  715 
  716 /* dns.c */
  717 
  718 typedef unsigned ip;
  719 
  720 int do_real_lookup(unsigned char *, ip *);
  721 void shrink_dns_cache(int);
  722 int find_host(unsigned char *, ip *, void **, void (*)(void *, int), void *);
  723 int find_host_no_cache(unsigned char *, ip *, void **, void (*)(void *, int), void *);
  724 void kill_dns_request(void **);
  725 
  726 /* cache.c */
  727 
  728 struct cache_entry {
  729     struct cache_entry *next;
  730     struct cache_entry *prev;
  731     unsigned char *url;
  732     unsigned char *head;
  733     unsigned char *redirect;
  734     int redirect_get;
  735     off_t length;
  736     int incomplete;
  737     int tgc;
  738     unsigned char *last_modified;
  739     off_t data_size;
  740     struct list_head frag;
  741     tcount count;
  742     int refcount;
  743 #ifdef HAVE_SSL
  744     unsigned char *ssl_info;
  745 #endif
  746 };
  747 
  748 struct fragment {
  749     struct fragment *next;
  750     struct fragment *prev;
  751     off_t offset;
  752     off_t length;
  753     off_t real_length;
  754     unsigned char data[1];
  755 };
  756 
  757 extern int page_size;
  758 
  759 void init_cache();
  760 long cache_info(int);
  761 int find_in_cache(unsigned char *, struct cache_entry **);
  762 int get_cache_entry(unsigned char *, struct cache_entry **);
  763 int add_fragment(struct cache_entry *, off_t, unsigned char *, off_t);
  764 void defrag_entry(struct cache_entry *);
  765 void truncate_entry(struct cache_entry *, off_t, int);
  766 void free_entry_to(struct cache_entry *, off_t);
  767 void delete_entry_content(struct cache_entry *);
  768 void delete_cache_entry(struct cache_entry *);
  769 void garbage_collection(int);
  770 
  771 /* sched.c */
  772 
  773 #define PRI_MAIN    0
  774 #define PRI_DOWNLOAD    0
  775 #define PRI_FRAME   1
  776 #define PRI_NEED_IMG    2
  777 #define PRI_IMG     3
  778 #define PRI_PRELOAD 4
  779 #define PRI_CANCEL  5
  780 #define N_PRI       6
  781 
  782 struct remaining_info {
  783     int valid;
  784     off_t size, loaded, last_loaded, cur_loaded;
  785     off_t pos;
  786     ttime elapsed;
  787     ttime last_time;
  788     ttime dis_b;
  789     int data_in_secs[CURRENT_SPD_SEC];
  790     int timer;
  791 };
  792 
  793 struct connection {
  794     struct connection *next;
  795     struct connection *prev;
  796     tcount count;
  797     unsigned char *url;
  798     int running;
  799     int state;
  800     int prev_error;
  801     off_t from;
  802     int pri[N_PRI];
  803     int no_cache;
  804     int sock1;
  805     int sock2;
  806     void *dnsquery;
  807     pid_t pid;
  808     int tries;
  809     struct list_head statuss;
  810     void *info;
  811     void *buffer;
  812     struct conn_info *newconn;
  813     void (*conn_func)(void *);
  814     struct cache_entry *cache;
  815     off_t received;
  816     off_t est_length;
  817     int unrestartable;
  818     struct remaining_info prg;
  819     int timer;
  820     int detached;
  821 #ifdef HAVE_SSL
  822     SSL *ssl;
  823     int no_tsl;
  824 #endif
  825 };
  826 
  827 extern struct list_head queue;
  828 
  829 struct k_conn {
  830     struct k_conn *next;
  831     struct k_conn *prev;
  832     void (*protocol)(struct connection *);
  833     unsigned char *host;
  834     int port;
  835     int conn;
  836     ttime timeout;
  837     ttime add_time;
  838 };
  839 
  840 extern struct list_head keepalive_connections;
  841 
  842 static inline int getpri(struct connection *c)
  843 {
  844     int i;
  845     for (i = 0; i < N_PRI; i++) if (c->pri[i]) return i;
  846     internal("connection has no owner");
  847     return N_PRI;
  848 }
  849 
  850 #define NC_ALWAYS_CACHE 0
  851 #define NC_CACHE    1
  852 #define NC_IF_MOD   2
  853 #define NC_RELOAD   3
  854 #define NC_PR_NO_CACHE  4
  855 
  856 #define S_WAIT      0
  857 #define S_DNS       1
  858 #define S_CONN      2
  859 #define S_SSL_NEG   3
  860 #define S_SENT      4
  861 #define S_LOGIN     5
  862 #define S_GETH      6
  863 #define S_PROC      7
  864 #define S_TRANS     8
  865 
  866 #define S_OK            (-2000000000)
  867 #define S_INTERRUPTED       (-2000000001)
  868 #define S_EXCEPT        (-2000000002)
  869 #define S_INTERNAL      (-2000000003)
  870 #define S_OUT_OF_MEM        (-2000000004)
  871 #define S_NO_DNS        (-2000000005)
  872 #define S_CANT_WRITE        (-2000000006)
  873 #define S_CANT_READ     (-2000000007)
  874 #define S_MODIFIED      (-2000000008)
  875 #define S_BAD_URL       (-2000000009)
  876 #define S_TIMEOUT       (-2000000010)
  877 #define S_RESTART       (-2000000011)
  878 #define S_STATE         (-2000000012)
  879 #define S_LARGE_FILE        (-2000000014)
  880 
  881 #define S_HTTP_ERROR        (-2000000100)
  882 #define S_HTTP_100      (-2000000101)
  883 #define S_HTTP_204      (-2000000102)
  884 
  885 #define S_FILE_TYPE     (-2000000200)
  886 #define S_FILE_ERROR        (-2000000201)
  887 
  888 #define S_FTP_ERROR     (-2000000300)
  889 #define S_FTP_UNAVAIL       (-2000000301)
  890 #define S_FTP_LOGIN     (-2000000302)
  891 #define S_FTP_PORT      (-2000000303)
  892 #define S_FTP_NO_FILE       (-2000000304)
  893 #define S_FTP_FILE_ERROR    (-2000000305)
  894 
  895 #define S_SSL_ERROR     (-2000000400)
  896 #define S_NO_SSL        (-2000000401)
  897 
  898 #define S_NO_SMB_CLIENT     (-2000000500)
  899 
  900 #define S_WAIT_REDIR        (-2000000600)
  901 
  902 #define S_UNKNOWN_ERROR     (-2000000700)
  903 
  904 #define S_MAX           (-2000000900)
  905 
  906 extern struct s_msg_dsc {
  907     int n;
  908     unsigned char *msg;
  909 } msg_dsc[];
  910 
  911 struct status {
  912     struct status *next;
  913     struct status *prev;
  914     struct connection *c;
  915     struct cache_entry *ce;
  916     int state;
  917     int prev_error;
  918     int pri;
  919     void (*end)(struct status *, void *);
  920     void *data;
  921     struct remaining_info *prg;
  922 };
  923 
  924 void check_queue(void *dummy);
  925 long connect_info(int);
  926 void send_connection_info(struct connection *c);
  927 void setcstate(struct connection *c, int);
  928 int get_keepalive_socket(struct connection *c);
  929 void add_keepalive_socket(struct connection *c, ttime);
  930 void run_connection(struct connection *c);
  931 int is_connection_restartable(struct connection *c);
  932 void retry_connection(struct connection *c);
  933 void abort_connection(struct connection *c);
  934 void end_connection(struct connection *c);
  935 int load_url(unsigned char *, struct status *, int, int);
  936 void change_connection(struct status *, struct status *, int);
  937 void detach_connection(struct status *, off_t);
  938 void abort_all_connections();
  939 void abort_background_connections();
  940 int is_entry_used(struct cache_entry *);
  941 void connection_timeout(struct connection *);
  942 void set_timeout(struct connection *);
  943 void add_blacklist_entry(unsigned char *, int);
  944 void del_blacklist_entry(unsigned char *, int);
  945 int get_blacklist_flags(unsigned char *);
  946 void free_blacklist();
  947 
  948 #define BL_HTTP10       1
  949 #define BL_NO_ACCEPT_LANGUAGE   2
  950 #define BL_NO_CHARSET       4
  951 #define BL_NO_RANGE     8
  952 
  953 /* url.c */
  954 
  955 struct session;
  956 
  957 #define POST_CHAR 1
  958 
  959 static inline int end_of_dir(unsigned char c)
  960 {
  961     return c == POST_CHAR || c == '#' || c == ';' || c == '?';
  962 }
  963 
  964 int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **);
  965 unsigned char *get_host_name(unsigned char *);
  966 unsigned char *get_host_and_pass(unsigned char *);
  967 unsigned char *get_user_name(unsigned char *);
  968 unsigned char *get_pass(unsigned char *);
  969 unsigned char *get_port_str(unsigned char *);
  970 int get_port(unsigned char *);
  971 void (*get_protocol_handle(unsigned char *))(struct connection *);
  972 void (*get_external_protocol_function(unsigned char *))(struct session *, unsigned char *);
  973 unsigned char *get_url_data(unsigned char *);
  974 unsigned char *join_urls(unsigned char *, unsigned char *);
  975 unsigned char *translate_url(unsigned char *, unsigned char *);
  976 unsigned char *extract_position(unsigned char *);
  977 void get_filename_from_url(unsigned char *, unsigned char **, int *);
  978 void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special);
  979 
  980 /* connect.c */
  981 
  982 struct read_buffer {
  983     int sock;
  984     int len;
  985     int close;
  986     void (*done)(struct connection *, struct read_buffer *);
  987     unsigned char data[1];
  988 };
  989 
  990 void exception(struct connection *);
  991 void close_socket(int *);
  992 void make_connection(struct connection *, int, int *, void (*)(struct connection *));
  993 int get_pasv_socket(struct connection *, int, int *, unsigned char *);
  994 void write_to_socket(struct connection *, int, unsigned char *, int, void (*)(struct connection *));
  995 struct read_buffer *alloc_read_buffer(struct connection *c);
  996 void read_from_socket(struct connection *, int, struct read_buffer *, void (*)(struct connection *, struct read_buffer *));
  997 void kill_buffer_data(struct read_buffer *, int);
  998 
  999 /* cookies.c */
 1000 
 1001 int set_cookie(struct terminal *, unsigned char *, unsigned char *);
 1002 void send_cookies(unsigned char **, int *, unsigned char *);
 1003 void init_cookies();
 1004 void cleanup_cookies();
 1005 
 1006 /* http.c */
 1007 
 1008 unsigned char *parse_http_header(unsigned char *, unsigned char *, unsigned char **);
 1009 unsigned char *parse_header_param(unsigned char *, unsigned char *);
 1010 void http_func(struct connection *);
 1011 void proxy_func(struct connection *);
 1012 
 1013 
 1014 /* https.c */
 1015 
 1016 void https_func(struct connection *c);
 1017 #ifdef HAVE_SSL
 1018 void ssl_finish(void);
 1019 SSL *getSSL(void);
 1020 #endif
 1021 
 1022 /* file.c */
 1023 
 1024 void file_func(struct connection *);
 1025 
 1026 /* finger.c */
 1027 
 1028 void finger_func(struct connection *);
 1029 
 1030 /* ftp.c */
 1031 
 1032 #if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
 1033 #define HAVE_IPTOS
 1034 #endif
 1035 
 1036 void ftp_func(struct connection *);
 1037 
 1038 /* smb.c */
 1039 
 1040 void smb_func(struct connection *);
 1041 
 1042 /* mailto.c */
 1043 
 1044 void mailto_func(struct session *, unsigned char *);
 1045 void telnet_func(struct session *, unsigned char *);
 1046 void tn3270_func(struct session *, unsigned char *);
 1047 void mms_func(struct session *, unsigned char *);
 1048 
 1049 /* kbd.c */
 1050 
 1051 #define BM_BUTT     3
 1052 #define B_LEFT      0
 1053 #define B_MIDDLE    1
 1054 #define B_RIGHT     2
 1055 #define BM_ACT      12
 1056 #define B_DOWN      0
 1057 #define B_UP        4
 1058 #define B_DRAG      8
 1059 
 1060 #define KBD_ENTER   0x100
 1061 #define KBD_BS      0x101
 1062 #define KBD_TAB     0x102
 1063 #define KBD_ESC     0x103
 1064 #define KBD_LEFT    0x104
 1065 #define KBD_RIGHT   0x105
 1066 #define KBD_UP      0x106
 1067 #define KBD_DOWN    0x107
 1068 #define KBD_INS     0x108
 1069 #define KBD_DEL     0x109
 1070 #define KBD_HOME    0x10a
 1071 #define KBD_END     0x10b
 1072 #define KBD_PAGE_UP 0x10c
 1073 #define KBD_PAGE_DOWN   0x10d
 1074 
 1075 #define KBD_F1      0x120
 1076 #define KBD_F2      0x121
 1077 #define KBD_F3      0x122
 1078 #define KBD_F4      0x123
 1079 #define KBD_F5      0x124
 1080 #define KBD_F6      0x125
 1081 #define KBD_F7      0x126
 1082 #define KBD_F8      0x127
 1083 #define KBD_F9      0x128
 1084 #define KBD_F10     0x129
 1085 #define KBD_F11     0x12a
 1086 #define KBD_F12     0x12b
 1087 
 1088 #define KBD_CTRL_C  0x200
 1089 
 1090 #define KBD_SHIFT   1
 1091 #define KBD_CTRL    2
 1092 #define KBD_ALT     4
 1093 
 1094 void handle_trm(int, int, int, int, int, void *, int);
 1095 void free_all_itrms();
 1096 void resize_terminal();
 1097 void dispatch_special(unsigned char *);
 1098 void kbd_ctrl_c();
 1099 int is_blocked();
 1100 
 1101 extern unsigned char init_seq[];
 1102 extern unsigned char init_seq_x_mouse[];
 1103 extern unsigned char init_seq_tw_mouse[];
 1104 extern unsigned char term_seq[];
 1105 extern unsigned char term_seq_x_mouse[];
 1106 extern unsigned char term_seq_tw_mouse[];
 1107 
 1108 /* terminal.c */
 1109 
 1110 typedef unsigned short chr;
 1111 
 1112 struct event {
 1113     long ev;
 1114     long x;
 1115     long y;
 1116     long b;
 1117 };
 1118 
 1119 #define EV_INIT     0
 1120 #define EV_KBD      1
 1121 #define EV_MOUSE    2
 1122 #define EV_REDRAW   3
 1123 #define EV_RESIZE   4
 1124 #define EV_ABORT    5
 1125 
 1126 struct window {
 1127     struct window *next;
 1128     struct window *prev;
 1129     void (*handler)(struct window *, struct event *, int fwd);
 1130     void *data;
 1131     int xp, yp;
 1132     struct terminal *term;
 1133 };
 1134 
 1135 #define MAX_TERM_LEN    32  /* this must be multiple of 8! (alignment problems) */
 1136 
 1137 #define MAX_CWD_LEN 256 /* this must be multiple of 8! (alignment problems) */  
 1138 
 1139 #define ENV_XWIN    1
 1140 #define ENV_SCREEN  2
 1141 #define ENV_OS2VIO  4
 1142 #define ENV_BE      8
 1143 #define ENV_TWIN    16
 1144 #define ENV_WIN32   32
 1145 #define ENV_INTERIX 64
 1146 
 1147 struct terminal {
 1148     struct terminal *next;
 1149     struct terminal *prev;
 1150     int master;
 1151     int fdin;
 1152     int fdout;
 1153     int x;
 1154     int y;
 1155     int environment;
 1156     unsigned char term[MAX_TERM_LEN];
 1157     unsigned char cwd[MAX_CWD_LEN];
 1158     unsigned *screen;
 1159     unsigned *last_screen;
 1160     struct term_spec *spec;
 1161     int cx;
 1162     int cy;
 1163     int lcx;
 1164     int lcy;
 1165     int dirty;
 1166     int redrawing;
 1167     int blocked;
 1168     unsigned char *input_queue;
 1169     int qlen;
 1170     struct list_head windows;
 1171     unsigned char *title;
 1172 };
 1173 
 1174 struct term_spec {
 1175     struct term_spec *next;
 1176     struct term_spec *prev;
 1177     unsigned char term[MAX_TERM_LEN];
 1178     int mode;
 1179     int m11_hack;
 1180     int restrict_852;
 1181     int block_cursor;
 1182     int col;
 1183     int charset;
 1184 };
 1185 
 1186 #define TERM_DUMB   0
 1187 #define TERM_VT100  1
 1188 #define TERM_LINUX  2
 1189 #define TERM_KOI8   3
 1190 #define TERM_FREEBSD    4
 1191 
 1192 #define ATTR_FRAME  0x8000
 1193 
 1194 extern struct list_head term_specs;
 1195 extern struct list_head terminals;
 1196 
 1197 int hard_write(int, unsigned char *, int);
 1198 int hard_read(int, unsigned char *, int);
 1199 unsigned char *get_cwd();
 1200 void set_cwd(unsigned char *);
 1201 struct terminal *init_term(int, int, void (*)(struct window *, struct event *, int));
 1202 void sync_term_specs();
 1203 struct term_spec *new_term_spec(unsigned char *);
 1204 void free_term_specs();
 1205 void destroy_terminal(struct terminal *);
 1206 void redraw_terminal(struct terminal *);
 1207 void redraw_terminal_all(struct terminal *);
 1208 void redraw_terminal_cls(struct terminal *);
 1209 void cls_redraw_all_terminals();
 1210 void redraw_from_window(struct window *);
 1211 void redraw_below_window(struct window *);
 1212 void add_window(struct terminal *, void (*)(struct window *, struct event *, int), void *);
 1213 void add_window_at_pos(struct terminal *, void (*)(struct window *, struct event *, int), void *, struct window *);
 1214 void delete_window(struct window *);
 1215 void delete_window_ev(struct window *, struct event *ev);
 1216 void set_window_ptr(struct window *, int, int);
 1217 void get_parent_ptr(struct window *, int *, int *);
 1218 struct window *get_root_window(struct terminal *);
 1219 void add_empty_window(struct terminal *, void (*)(void *), void *);
 1220 void redraw_screen(struct terminal *);
 1221 void redraw_all_terminals();
 1222 void set_char(struct terminal *, int, int, unsigned);
 1223 unsigned get_char(struct terminal *, int, int);
 1224 void set_color(struct terminal *, int, int, unsigned);
 1225 void set_only_char(struct terminal *, int, int, unsigned);
 1226 void set_line(struct terminal *, int, int, int, chr *);
 1227 void set_line_color(struct terminal *, int, int, int, unsigned);
 1228 void fill_area(struct terminal *, int, int, int, int, unsigned);
 1229 void draw_frame(struct terminal *, int, int, int, int, unsigned, int);
 1230 void print_text(struct terminal *, int, int, int, unsigned char *, unsigned);
 1231 void set_cursor(struct terminal *, int, int, int, int);
 1232 void destroy_all_terminals();
 1233 void block_itrm(int);
 1234 int unblock_itrm(int);
 1235 void exec_thread(unsigned char *, int);
 1236 void close_handle(void *);
 1237 
 1238 #define TERM_FN_TITLE   1
 1239 #define TERM_FN_RESIZE  2
 1240 
 1241 void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, int);
 1242 void set_terminal_title(struct terminal *, unsigned char *);
 1243 void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
 1244 
 1245 /* language.c */
 1246 
 1247 #include "language.h"
 1248 
 1249 extern unsigned char dummyarray[];
 1250 
 1251 extern int current_language;
 1252 
 1253 void init_trans();
 1254 void shutdown_trans();
 1255 unsigned char *get_text_translation(unsigned char *, struct terminal *term);
 1256 unsigned char *get_english_translation(unsigned char *);
 1257 void set_language(int);
 1258 int n_languages();
 1259 unsigned char *language_name(int);
 1260 
 1261 #define _(_x_, _y_) get_text_translation(_x_, _y_)
 1262 #define TEXT_(x) (dummyarray + x) /* TEXT causes name clash on windows */
 1263 
 1264 /* af_unix.c */
 1265 
 1266 int bind_to_af_unix();
 1267 void af_unix_close();
 1268 
 1269 /* main.c */
 1270 
 1271 extern int retval;
 1272 
 1273 extern unsigned char *path_to_exe;
 1274 extern unsigned char **g_argv;
 1275 extern int g_argc;
 1276 
 1277 void unhandle_terminal_signals(struct terminal *term);
 1278 int attach_terminal(int, int, int, void *, int);
 1279 void program_exit();
 1280 void shrink_memory(int);
 1281 
 1282 /* types.c */
 1283 
 1284 struct assoc {
 1285     struct assoc *next;
 1286     struct assoc *prev;
 1287     tcount cnt;
 1288     unsigned char *label;
 1289     unsigned char *ct;
 1290     unsigned char *prog;
 1291     int cons;
 1292     int xwin;
 1293     int block;
 1294     int ask;
 1295     int system;
 1296 };
 1297 
 1298 struct extension {
 1299     struct extension *next;
 1300     struct extension *prev;
 1301     tcount cnt;
 1302     unsigned char *ext;
 1303     unsigned char *ct;
 1304 };
 1305 
 1306 struct protocol_program {
 1307     struct protocol_program *next;
 1308     struct protocol_program *prev;
 1309     unsigned char *prog;
 1310     int system;
 1311 };
 1312 
 1313 extern struct list_head assoc;
 1314 extern struct list_head extensions;
 1315 
 1316 extern struct list_head mailto_prog;
 1317 extern struct list_head telnet_prog;
 1318 extern struct list_head tn3270_prog;
 1319 extern struct list_head mms_prog;
 1320 
 1321 unsigned char *get_content_type(unsigned char *, unsigned char *);
 1322 struct assoc *get_type_assoc(struct terminal *term, unsigned char *);
 1323 void update_assoc(struct assoc *);
 1324 void update_ext(struct extension *);
 1325 void update_prog(struct list_head *, unsigned char *, int);
 1326 unsigned char *get_prog(struct list_head *);
 1327 void free_types();
 1328 
 1329 void menu_add_ct(struct terminal *, void *, void *);
 1330 void menu_del_ct(struct terminal *, void *, void *);
 1331 void menu_list_assoc(struct terminal *, void *, void *);
 1332 void menu_add_ext(struct terminal *, void *, void *);
 1333 void menu_del_ext(struct terminal *, void *, void *);
 1334 void menu_list_ext(struct terminal *, void *, void *);
 1335 
 1336 int is_html_type(unsigned char *ct);
 1337 
 1338 /* session.c */
 1339 
 1340 struct link_def {
 1341     unsigned char *link;
 1342     unsigned char *target;
 1343 };
 1344 
 1345 struct line {
 1346     int l;
 1347     chr c;
 1348     chr *d;
 1349 };
 1350 
 1351 struct point {
 1352     int x;
 1353     int y;
 1354 };
 1355 
 1356 struct form {
 1357     unsigned char *action;
 1358     unsigned char *target;
 1359     int method;
 1360     int num;
 1361 };
 1362 
 1363 #define FM_GET      0
 1364 #define FM_POST     1
 1365 #define FM_POST_MP  2
 1366 
 1367 #define FC_TEXT     1
 1368 #define FC_PASSWORD 2
 1369 #define FC_FILE     3
 1370 #define FC_TEXTAREA 4
 1371 #define FC_CHECKBOX 5
 1372 #define FC_RADIO    6
 1373 #define FC_SELECT   7
 1374 #define FC_SUBMIT   8
 1375 #define FC_IMAGE    9
 1376 #define FC_RESET    10
 1377 #define FC_HIDDEN   11
 1378 
 1379 struct form_control {
 1380     struct form_control *next;
 1381     struct form_control *prev;
 1382     int form_num;
 1383     int ctrl_num;
 1384     int g_ctrl_num;
 1385     int position;
 1386     int method;
 1387     unsigned char *action;
 1388     unsigned char *target;
 1389     int type;
 1390     unsigned char *name;
 1391     unsigned char *alt;
 1392     int ro;
 1393     unsigned char *default_value;
 1394     int default_state;
 1395     int size;
 1396     int cols, rows, wrap;
 1397     int maxlength;
 1398     int nvalues;
 1399     unsigned char **values;
 1400     unsigned char **labels;
 1401     struct menu_item *menu;
 1402 };
 1403 
 1404 struct form_state {
 1405     int form_num;
 1406     int ctrl_num;
 1407     int g_ctrl_num;
 1408     int position;
 1409     int type;
 1410     unsigned char *value;
 1411     int state;
 1412     int vpos;
 1413     int vypos;
 1414 };
 1415 
 1416 struct link {
 1417     int type;
 1418     int num;
 1419     unsigned char *where;
 1420     unsigned char *target;
 1421     unsigned char *where_img;
 1422     struct form_control *form;
 1423     unsigned sel_color;
 1424     int n;
 1425     struct point *pos;
 1426 };
 1427 
 1428 #define L_LINK      0
 1429 #define L_BUTTON    1
 1430 #define L_CHECKBOX  2
 1431 #define L_SELECT    3
 1432 #define L_FIELD     4
 1433 #define L_AREA      5
 1434 
 1435 #define SIZEOF_F_DATA sizeof(struct f_data)
 1436 
 1437 struct link_bg {
 1438     int x, y;
 1439     unsigned c;
 1440 };
 1441 
 1442 struct tag {
 1443     struct tag *next;
 1444     struct tag *prev;
 1445     int x;
 1446     int y;
 1447     unsigned char name[1];
 1448 };
 1449 
 1450 struct rgb {
 1451     unsigned char r, g, b;
 1452     unsigned char pad;
 1453 };
 1454 
 1455 struct document_setup {
 1456     int assume_cp, hard_assume;
 1457     int tables, frames, images;
 1458     int margin;
 1459     int num_links, table_order;
 1460 };
 1461 
 1462 struct document_options {
 1463     int xw, yw; /* size of window */
 1464     int xp, yp; /* pos of window */
 1465     int col, cp, assume_cp, hard_assume;
 1466     int tables, frames, images, margin;  /* if you add anything, fix it in compare_opt */
 1467     int plain;
 1468     int num_links, table_order;
 1469     struct rgb default_fg;
 1470     struct rgb default_bg;
 1471     struct rgb default_link;
 1472     struct rgb default_vlink;
 1473     unsigned char *framename;
 1474     int real_cp;    /* codepage of document. Does not really belong here. Must not be compared. Used only in get_attr_val */
 1475 };
 1476 
 1477 static inline void ds2do(struct document_setup *ds, struct document_options *doo)
 1478 {
 1479     doo->assume_cp = ds->assume_cp;
 1480     doo->hard_assume = ds->hard_assume;
 1481     doo->tables = ds->tables;
 1482     doo->frames = ds->frames;
 1483     doo->images = ds->images;
 1484     doo->margin = ds->margin;
 1485     doo->num_links = ds->num_links;
 1486     doo->table_order = ds->table_order;
 1487 }
 1488 
 1489 struct node {
 1490     struct node *next;
 1491     struct node *prev;
 1492     int x, y;
 1493     int xw, yw;
 1494 };
 1495 
 1496 struct search {
 1497     unsigned char c;
 1498     int n:24;   /* This structure is size-critical */
 1499     int x, y;
 1500 };
 1501 
 1502 struct frameset_desc;
 1503 
 1504 struct frame_desc {
 1505     struct frameset_desc *subframe;
 1506     unsigned char *name;
 1507     unsigned char *url;
 1508     int line;
 1509     int xw, yw;
 1510 };
 1511 
 1512 struct frameset_desc {
 1513     int n;
 1514     int x, y;
 1515     int xp, yp;
 1516     struct frame_desc f[1];
 1517 };
 1518 
 1519 struct f_data {
 1520     struct f_data *next;
 1521     struct f_data *prev;
 1522     int refcount;
 1523     unsigned char *url;
 1524     struct document_options opt;
 1525     unsigned char *title;
 1526     int cp, ass;
 1527     int x, y; /* size of document */
 1528     ttime time_to_get;
 1529     tcount use_tag;
 1530     int frame;
 1531     struct frameset_desc *frame_desc;
 1532     int bg;
 1533     struct line *data;
 1534     struct link *links;
 1535     int nlinks;
 1536     struct link **lines1;
 1537     struct link **lines2;
 1538     struct list_head forms;
 1539     struct list_head tags;
 1540     struct list_head nodes;
 1541     struct search *search;
 1542     int nsearch;
 1543     struct search **slines1;
 1544     struct search **slines2;
 1545 };
 1546 
 1547 struct f_data_c {
 1548     struct f_data_c *next;
 1549     struct f_data_c *prev;
 1550     int used;
 1551     unsigned char *name;
 1552     struct f_data *f_data;
 1553     int xw, yw; /* size of window */
 1554     int xp, yp; /* pos of window */
 1555     int xl, yl; /* last pos of window */
 1556     struct link_bg *link_bg;
 1557     int link_bg_n;
 1558     unsigned char **search_word;
 1559     struct view_state *vs;
 1560     int depth;
 1561 };
 1562 
 1563 struct view_state {
 1564     int view_pos;
 1565     int view_posx;
 1566     int orig_view_pos;
 1567     int orig_view_posx;
 1568     int current_link;
 1569     int orig_link;
 1570     int plain;
 1571     unsigned char *goto_position;
 1572     unsigned char *goto_position_end;
 1573     struct form_state *form_info;
 1574     int form_info_len;
 1575     unsigned char url[1];
 1576 };
 1577 
 1578 struct frame {
 1579     struct frame *next;
 1580     struct frame *prev;
 1581     unsigned char *name;
 1582     int redirect_cnt;
 1583     struct view_state vs;
 1584 };
 1585 
 1586 struct location {
 1587     struct location *next;
 1588     struct location *prev;
 1589     struct list_head frames;
 1590     struct status stat;
 1591     struct view_state vs;
 1592 };
 1593 
 1594 #define WTD_NO      0
 1595 #define WTD_FORWARD 1
 1596 #define WTD_IMGMAP  2
 1597 #define WTD_RELOAD  3
 1598 #define WTD_BACK    4
 1599 
 1600 #define cur_loc(x) ((struct location *)((x)->history.next))
 1601 
 1602 struct kbdprefix {
 1603     int rep;
 1604     int rep_num;
 1605     int prefix;
 1606 };
 1607 
 1608 struct download {
 1609     struct download *next;
 1610     struct download *prev;
 1611     unsigned char *url;
 1612     struct status stat;
 1613     unsigned char *file;
 1614     off_t last_pos;
 1615     int handle;
 1616     int redirect_cnt;
 1617     unsigned char *prog;
 1618     int prog_flags;
 1619     time_t remotetime;
 1620     struct session *ses;
 1621     struct window *win;
 1622     struct window *ask;
 1623 };
 1624 
 1625 extern struct list_head downloads;
 1626 
 1627 struct file_to_load {
 1628     struct file_to_load *next;
 1629     struct file_to_load *prev;
 1630     struct session *ses;
 1631     int req_sent;
 1632     int pri;
 1633     struct cache_entry *ce;
 1634     unsigned char *url;
 1635     struct status stat;
 1636 };
 1637 
 1638 struct session {
 1639     struct session *next;
 1640     struct session *prev;
 1641     struct list_head history;
 1642     struct terminal *term;
 1643     struct window *win;
 1644     int id;
 1645     struct f_data_c *screen;
 1646     struct list_head scrn_frames;
 1647     struct status loading;
 1648     int wtd;
 1649     unsigned char *wtd_target;
 1650     unsigned char *loading_url;
 1651     int display_timer;
 1652     struct list_head more_files;
 1653     unsigned char *goto_position;
 1654     unsigned char *imgmap_href_base;
 1655     unsigned char *imgmap_target_base;
 1656     struct document_setup ds;
 1657     struct kbdprefix kbdprefix;
 1658     int reloadlevel;
 1659     int redirect_cnt;
 1660     struct status tq;
 1661     unsigned char *tq_url;
 1662     struct cache_entry *tq_ce;
 1663     unsigned char *tq_goto_position;
 1664     unsigned char *tq_prog;
 1665     int tq_prog_flags;
 1666     unsigned char *dn_url;
 1667     unsigned char *search_word;
 1668     unsigned char *last_search_word;
 1669     int search_direction;
 1670     int exit_query;
 1671 };
 1672 
 1673 extern struct list_head sessions;
 1674 
 1675 time_t parse_http_date(const char *);
 1676 unsigned char *encode_url(unsigned char *);
 1677 unsigned char *decode_url(unsigned char *);
 1678 unsigned char *subst_file(unsigned char *, unsigned char *, int);
 1679 int are_there_downloads();
 1680 void free_strerror_buf();
 1681 int get_error_from_errno(int errn);
 1682 unsigned char *get_err_msg(int);
 1683 void print_screen_status(struct session *);
 1684 void print_error_dialog(struct session *, struct status *, unsigned char *);
 1685 void start_download(struct session *, unsigned char *);
 1686 void display_download(struct terminal *, struct download *, struct session *);
 1687 int create_download_file(struct terminal *, unsigned char *, int);
 1688 struct file_to_load *request_additional_file(struct session *, unsigned char *, int);
 1689 struct file_to_load *request_additional_loading_file(struct session *, unsigned char *, struct status *, int);
 1690 void process_file_requests(struct session *);
 1691 int read_session_info(int, struct session *, void *, int);
 1692 void *create_session_info(int, unsigned char *, int *);
 1693 void win_func(struct window *, struct event *, int);
 1694 void goto_url_f(struct session *, unsigned char *, unsigned char *);
 1695 void goto_url(struct session *, unsigned char *);
 1696 void abort_loading(struct session *);
 1697 void goto_imgmap(struct session *, unsigned char *, unsigned char *, unsigned char *);
 1698 void go_back(struct session *);
 1699 void reload(struct session*, int);
 1700 struct frame *ses_find_frame(struct session *, unsigned char *);
 1701 struct frame *ses_change_frame_url(struct session *, unsigned char *, unsigned char *);
 1702 void map_selected(struct terminal *, struct link_def *, struct session *);
 1703 void load_frames(struct session *, struct f_data_c *);
 1704 void destroy_session(struct session *);
 1705 void destroy_all_sessions();
 1706 void abort_all_downloads();
 1707 void destroy_location(struct location *);
 1708 
 1709 /* Information about the current document */
 1710 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
 1711 unsigned char *get_current_title(struct session *, unsigned char *, size_t);
 1712 
 1713 unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);
 1714 
 1715 /* bfu.c */
 1716 
 1717 struct memory_list {
 1718     int n;
 1719     void *p[1];
 1720 };
 1721 
 1722 struct memory_list *getml(void *, ...);
 1723 void add_to_ml(struct memory_list **, ...);
 1724 void freeml(struct memory_list *);
 1725 
 1726 #define MENU_FUNC (void (*)(struct terminal *, void *, void *))
 1727 
 1728 extern unsigned char m_bar;
 1729 
 1730 #define M_BAR   (&m_bar)
 1731 
 1732 struct menu_item {
 1733     unsigned char *text;
 1734     unsigned char *rtext;
 1735     unsigned char *hotkey;
 1736     void (*func)(struct terminal *, void *, void *);
 1737     void *data;
 1738     int in_m;
 1739     int free_i;
 1740 };
 1741 
 1742 struct menu {
 1743     int selected;
 1744     int view;
 1745     int xp, yp;
 1746     int x, y, xw, yw;
 1747     int ni;
 1748     void *data;
 1749     struct window *win;
 1750     struct menu_item *items;
 1751 };
 1752 
 1753 struct mainmenu {
 1754     int selected;
 1755     int sp;
 1756     int ni;
 1757     void *data;
 1758     struct window *win;
 1759     struct menu_item *items;
 1760 };
 1761 
 1762 struct history_item {
 1763     struct history_item *next;
 1764     struct history_item *prev;
 1765     unsigned char d[1];
 1766 };
 1767 
 1768 struct history {
 1769     int n;
 1770     struct list_head items;
 1771 };
 1772 
 1773 #define D_END       0
 1774 #define D_CHECKBOX  1
 1775 #define D_FIELD     2
 1776 #define D_FIELD_PASS    3
 1777 #define D_BUTTON    4
 1778 #define D_BOX       5
 1779 
 1780 #define B_ENTER     1
 1781 #define B_ESC       2
 1782 
 1783 struct dialog_item_data;
 1784 struct dialog_data;
 1785 
 1786 struct dialog_item {
 1787     int type;
 1788     int gid, gnum; /* for buttons: gid - flags B_XXX */ /* for fields: min/max */ /* for box: gid is box height */
 1789     int (*fn)(struct dialog_data *, struct dialog_item_data *);
 1790     struct history *history;
 1791     int dlen;
 1792     unsigned char *data;
 1793     void *udata; /* for box: holds list */
 1794     unsigned char *text;
 1795 };
 1796 
 1797 struct dialog_item_data {
 1798     int x, y, l;
 1799     int vpos, cpos;
 1800     int checked;
 1801     struct dialog_item *item;
 1802     struct list_head history;
 1803     struct history_item *cur_hist;
 1804     unsigned char *cdata;
 1805 };
 1806 
 1807 #define EVENT_PROCESSED     0
 1808 #define EVENT_NOT_PROCESSED 1
 1809 
 1810 struct dialog {
 1811     unsigned char *title;
 1812     void (*fn)(struct dialog_data *);
 1813     int (*handle_event)(struct dialog_data *, struct event *);
 1814     void (*abort)(struct dialog_data *);
 1815     void *udata;
 1816     void *udata2;
 1817     int align;
 1818     void (*refresh)(void *);
 1819     void *refresh_data;
 1820     struct dialog_item items[1];
 1821 };
 1822 
 1823 struct dialog_data {
 1824     struct window *win;
 1825     struct dialog *dlg;
 1826     int x, y, xw, yw;
 1827     int n;
 1828     int selected;
 1829     struct memory_list *ml;
 1830     struct dialog_item_data items[1];
 1831 };
 1832 
 1833 struct menu_item *new_menu(int);
 1834 void add_to_menu(struct menu_item **, unsigned char *, unsigned char *, unsigned char *, void (*)(struct terminal *, void *, void *), void *, int);
 1835 void do_menu(struct terminal *, struct menu_item *, void *);
 1836 void do_menu_selected(struct terminal *, struct menu_item *, void *, int);
 1837 void do_mainmenu(struct terminal *, struct menu_item *, void *, int);
 1838 void do_dialog(struct terminal *, struct dialog *, struct memory_list *);
 1839 int check_number(struct dialog_data *, struct dialog_item_data *);
 1840 int check_nonempty(struct dialog_data *, struct dialog_item_data *);
 1841 void max_text_width(struct terminal *, unsigned char *, int *);
 1842 void min_text_width(struct terminal *, unsigned char *, int *);
 1843 void dlg_format_text(struct terminal *, struct terminal *, unsigned char *, int, int *, int, int *, int, int);
 1844 void max_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
 1845 void min_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
 1846 void dlg_format_buttons(struct terminal *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, int);
 1847 void checkboxes_width(struct terminal *, unsigned char **, int *, void (*)(struct terminal *, unsigned char *, int *));
 1848 void dlg_format_checkbox(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, unsigned char *);
 1849 void dlg_format_checkboxes(struct terminal *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, unsigned char **);
 1850 void dlg_format_field(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
 1851 void max_group_width(struct terminal *, unsigned char **, struct dialog_item_data *, int, int *);
 1852 void min_group_width(struct terminal *, unsigned char **, struct dialog_item_data *, int, int *);
 1853 void dlg_format_group(struct terminal *, struct terminal *, unsigned char **, struct dialog_item_data *, int, int, int *, int, int *);
 1854 void dlg_format_box(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
 1855 void checkbox_list_fn(struct dialog_data *);
 1856 void group_fn(struct dialog_data *);
 1857 void center_dlg(struct dialog_data *);
 1858 void draw_dlg(struct dialog_data *);
 1859 void display_dlg_item(struct dialog_data *, struct dialog_item_data *, int);
 1860 int ok_dialog(struct dialog_data *, struct dialog_item_data *);
 1861 int cancel_dialog(struct dialog_data *, struct dialog_item_data *);
 1862 void msg_box(struct terminal *, struct memory_list *, unsigned char *, int, /*unsigned char *, void *, int,*/ ...);
 1863 void input_field_fn(struct dialog_data *);
 1864 void input_field(struct terminal *, struct memory_list *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, void *, struct history *, int, unsigned char *, int, int, int (*)(struct dialog_data *, struct dialog_item_data *), void (*)(void *, unsigned char *), void (*)(void *));
 1865 void add_to_history(struct history *, unsigned char *, int);
 1866 
 1867 void box_sel_move(struct dialog_item_data *, int ); 
 1868 void show_dlg_item_box(struct dialog_data *, struct dialog_item_data *);
 1869 void box_sel_set_visible(struct dialog_item_data *, int ); 
 1870 
 1871 /* menu.c */
 1872 
 1873 extern struct history goto_url_history;
 1874 
 1875 void activate_bfu_technology(struct session *, int);
 1876 void dialog_goto_url(struct session *ses, char *url);
 1877 void dialog_save_url(struct session *ses);
 1878 void free_history_lists();
 1879 void query_file(struct session *, unsigned char *, void (*)(struct session *, unsigned char *), void (*)(struct session *));
 1880 void search_dlg(struct session *, struct f_data_c *, int);
 1881 void search_back_dlg(struct session *, struct f_data_c *, int);
 1882 void exit_prog(struct terminal *, void *, struct session *);
 1883 void do_auth_dialog(struct session *);
 1884 
 1885 /* charsets.c */
 1886 
 1887 #include "codepage.h"
 1888 
 1889 struct conv_table {
 1890     int t;
 1891     union {
 1892         unsigned char *str;
 1893         struct conv_table *tbl;
 1894     } u;
 1895 };
 1896 
 1897 int cp2u(unsigned char ch, int from);
 1898 struct conv_table *get_translation_table(int, int);
 1899 int get_entity_number(unsigned char *st, int l);
 1900 unsigned char *get_entity_string(unsigned char *, int, int);
 1901 unsigned char *convert_string(struct conv_table *, unsigned char *, int);
 1902 int get_cp_index(unsigned char *n);
 1903 unsigned char *get_cp_name(int);
 1904 unsigned char *get_cp_mime_name(int);
 1905 int is_cp_special(int);
 1906 void free_conv_table();
 1907 
 1908 unsigned char charset_upcase(unsigned char, int);
 1909 void charset_upcase_string(unsigned char **, int);
 1910 
 1911 /* view.c */
 1912 
 1913 int can_open_in_new(struct terminal *);
 1914 void open_in_new_window(struct terminal *, void (*)(struct terminal *, void (*)(struct terminal *, unsigned char *, unsigned char *), struct session *ses), struct session *);
 1915 void send_open_in_new_xterm(struct terminal *term, void (*open_window)(struct terminal *term, unsigned char *, unsigned char *), struct session *ses);
 1916 void send_open_new_xterm(struct terminal *, void (*)(struct terminal *, unsigned char *, unsigned char *), struct session *);
 1917 void destroy_fc(struct form_control *);
 1918 void sort_links(struct f_data *);
 1919 void destroy_formatted(struct f_data *);
 1920 void clear_formatted(struct f_data *);
 1921 void init_formatted(struct f_data *);
 1922 void detach_formatted(struct f_data_c *);
 1923 void init_vs(struct view_state *, unsigned char *);
 1924 void destroy_vs(struct view_state *);
 1925 void copy_location(struct location *, struct location *);
 1926 void draw_doc(struct terminal *, struct f_data_c *, int);
 1927 int dump_to_file(struct f_data *, int);
 1928 void draw_formatted(struct session *);
 1929 void send_event(struct session *, struct event *);
 1930 void link_menu(struct terminal *, void *, struct session *);
 1931 void save_as(struct terminal *, void *, struct session *);
 1932 void save_url(struct session *, unsigned char *);
 1933 void menu_save_formatted(struct terminal *, void *, struct session *);
 1934 void selected_item(struct terminal *, void *, struct session *);
 1935 void toggle(struct session *, struct f_data_c *, int);
 1936 void do_for_frame(struct session *, void (*)(struct session *, struct f_data_c *, int), int);
 1937 int get_current_state(struct session *);
 1938 unsigned char *print_current_link(struct session *);
 1939 unsigned char *print_current_title(struct session *);
 1940 void loc_msg(struct terminal *, struct location *, struct f_data_c *);
 1941 void state_msg(struct session *);
 1942 void head_msg(struct session *);
 1943 void search_for(struct session *, unsigned char *);
 1944 void search_for_back(struct session *, unsigned char *);
 1945 void find_next(struct session *, struct f_data_c *, int);
 1946 void find_next_back(struct session *, struct f_data_c *, int);
 1947 void set_frame(struct session *, struct f_data_c *, int);
 1948 struct f_data_c *current_frame(struct session *);
 1949 
 1950 /* html.c */
 1951 
 1952 #define AT_BOLD     1
 1953 #define AT_ITALIC   2
 1954 #define AT_UNDERLINE    4
 1955 #define AT_FIXED    8
 1956 #define AT_GRAPHICS 16
 1957 
 1958 #define AL_LEFT     0
 1959 #define AL_CENTER   1
 1960 #define AL_RIGHT    2
 1961 #define AL_BLOCK    3
 1962 #define AL_NO       4
 1963 
 1964 #define AL_MASK     0x7f
 1965 
 1966 #define AL_EXTD_TEXT    0x80
 1967     /* DIRTY! for backward compatibility with old menu code */
 1968 
 1969 struct text_attrib_beginning {
 1970     int attr;
 1971     struct rgb fg;
 1972     struct rgb bg;
 1973 };
 1974 
 1975 struct text_attrib {
 1976     int attr;
 1977     struct rgb fg;
 1978     struct rgb bg;
 1979     int fontsize;
 1980     unsigned char *link;
 1981     unsigned char *target;
 1982     unsigned char *image;
 1983     struct form_control *form;
 1984     struct rgb clink;
 1985     struct rgb vlink;
 1986     unsigned char *href_base;
 1987     unsigned char *target_base;
 1988     unsigned char *select;
 1989     int select_disabled;
 1990 };
 1991 
 1992 #define P_NUMBER    1
 1993 #define P_alpha     2
 1994 #define P_ALPHA     3
 1995 #define P_roman     4
 1996 #define P_ROMAN     5
 1997 #define P_STAR      1
 1998 #define P_O     2
 1999 #define P_PLUS      3
 2000 #define P_LISTMASK  7
 2001 #define P_COMPACT   8
 2002 
 2003 struct par_attrib {
 2004     int align;
 2005     int leftmargin;
 2006     int rightmargin;
 2007     int width;
 2008     int list_level;
 2009     unsigned list_number;
 2010     int dd_margin;
 2011     int flags;
 2012     struct rgb bgcolor;
 2013 };
 2014 
 2015 struct html_element {
 2016     struct html_element *next;
 2017     struct html_element *prev;
 2018     struct text_attrib attr;
 2019     struct par_attrib parattr;
 2020     int invisible;
 2021     unsigned char *name;
 2022     int namelen;
 2023     unsigned char *options;
 2024     int linebreak;
 2025     int dontkill;
 2026     struct frameset_desc *frameset;
 2027 };
 2028 
 2029 extern int get_attr_val_nl;
 2030 
 2031 extern struct list_head html_stack;
 2032 extern int line_breax;
 2033 
 2034 extern unsigned char *startf;
 2035 extern unsigned char *eofff;
 2036 
 2037 #define format_ (((struct html_element *)html_stack.next)->attr)
 2038 #define par_format (((struct html_element *)html_stack.next)->parattr)
 2039 #define html_top (*(struct html_element *)html_stack.next)
 2040 
 2041 extern void *ff;
 2042 extern int (*put_chars_f)(void *, unsigned char *, int);
 2043 extern void (*line_break_f)(void *);
 2044 extern void *(*special_f)(void *, int, ...);
 2045 
 2046 void ln_break(int, void (*)(void *), void *);
 2047 void put_chrs(unsigned char *, int, int (*)(void *, unsigned char *, int), void *);
 2048 
 2049 extern int table_level;
 2050 extern int empty_format;
 2051 
 2052 extern struct form form;
 2053 extern unsigned char *last_form_tag;
 2054 extern unsigned char *last_form_attr;
 2055 extern unsigned char *last_input_tag;
 2056 
 2057 int parse_element(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **);
 2058 unsigned char *get_attr_val(unsigned char *, unsigned char *);
 2059 int has_attr(unsigned char *, unsigned char *);
 2060 int get_num(unsigned char *, unsigned char *);
 2061 int get_width(unsigned char *, unsigned char *, int);
 2062 int get_color(unsigned char *, unsigned char *, struct rgb *);
 2063 int get_bgcolor(unsigned char *, struct rgb *);
 2064 void html_stack_dup();
 2065 void kill_html_stack_item(struct html_element *);
 2066 unsigned char *skip_comment(unsigned char *, unsigned char *);
 2067 void parse_html(unsigned char *, unsigned char *, int (*)(void *, unsigned char *, int), void (*)(void *), void *(*)(void *, int, ...), void *, unsigned char *);
 2068 int get_image_map(unsigned char *, unsigned char *, unsigned char *, unsigned char *a, struct menu_item **, struct memory_list **, unsigned char *, unsigned char *, int, int, int);
 2069 void scan_http_equiv(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **);
 2070 
 2071 #define SP_TAG      0
 2072 #define SP_CONTROL  1
 2073 #define SP_TABLE    2
 2074 #define SP_USED     3
 2075 #define SP_FRAMESET 4
 2076 #define SP_FRAME    5
 2077 #define SP_NOWRAP   6
 2078 
 2079 struct frameset_param {
 2080     struct frameset_desc *parent;
 2081     int x, y;
 2082     int *xw, *yw;
 2083 };
 2084 
 2085 struct frame_param {
 2086     struct frameset_desc *parent;
 2087     unsigned char *name;
 2088     unsigned char *url;
 2089 };
 2090 
 2091 void free_menu(struct menu_item *);
 2092 void do_select_submenu(struct terminal *, struct menu_item *, struct session *);
 2093 
 2094 /* html_r.c */
 2095 
 2096 struct part {
 2097     int x, y;
 2098     int xp, yp;
 2099     int xmax;
 2100     int xa;
 2101     int cx, cy;
 2102     struct f_data *data;
 2103     int bgcolor;
 2104     unsigned char *spaces;
 2105     int spl;
 2106     int link_num;
 2107     struct list_head uf;
 2108 };
 2109 
 2110 struct sizes {
 2111     int xmin, xmax, y;
 2112 };
 2113 
 2114 extern struct document_options *d_opt;
 2115 extern int last_link_to_move;
 2116 extern int margin;
 2117 
 2118 void xxpand_line(struct part *, int, int);
 2119 void xxpand_lines(struct part *, int);
 2120 void xset_hchar(struct part *, int, int, unsigned);
 2121 void xset_hchars(struct part *, int, int, int, unsigned);
 2122 void align_line(struct part *, int);
 2123 
 2124 void free_table_cache();
 2125 
 2126 struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *, int);
 2127 extern int format_cache_entries;
 2128 long formatted_info(int);
 2129 void shrink_format_cache(int);
 2130 void count_format_cache();
 2131 void delete_unused_format_cache_entries();
 2132 void format_cache_reactivate(struct f_data *);
 2133 struct part *format_html_part(unsigned char *, unsigned char *, int, int, int, struct f_data *, int, int, unsigned char *, int);
 2134 void cached_format_html(struct view_state *, struct f_data_c *, struct document_options *);
 2135 void html_interpret(struct session *);
 2136 void get_search_data(struct f_data *);
 2137 
 2138 /* html_tbl.c */
 2139 
 2140 void format_table(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);
 2141 
 2142 /* default.c */
 2143 
 2144 #define MAX_STR_LEN 1024
 2145 
 2146 struct option {
 2147     int p;
 2148     unsigned char *(*rd_cmd)(struct option *, unsigned char ***, int *);
 2149     unsigned char *(*rd_cfg)(struct option *, unsigned char *);
 2150     void (*wr_cfg)(struct option *, unsigned char **, int *);
 2151     int min, max;
 2152     void *ptr;
 2153     unsigned char *cfg_name;
 2154     unsigned char *cmd_name;
 2155 };
 2156 
 2157 unsigned char *parse_options(int, unsigned char *[]);
 2158 void init_home();
 2159 unsigned char *read_config_file(unsigned char *name);
 2160 int write_to_config_file(unsigned char *, unsigned char *);
 2161 unsigned char *get_token(unsigned char **line);
 2162 void load_config();
 2163 void write_config(struct terminal *);
 2164 void write_html_config(struct terminal *);
 2165 void end_config();
 2166 
 2167 void load_url_history();
 2168 void save_url_history();
 2169 
 2170 extern int anonymous;
 2171 
 2172 extern unsigned char system_name[];
 2173 
 2174 extern unsigned char *links_home;
 2175 extern int first_use;
 2176 
 2177 extern int created_home;
 2178 
 2179 extern int no_connect;
 2180 extern int base_session;
 2181 extern int force_html;
 2182 
 2183 #define D_DUMP      1
 2184 #define D_SOURCE    2
 2185 extern int dmp;
 2186 
 2187 extern int async_lookup;
 2188 extern int download_utime;
 2189 extern int max_connections;
 2190 extern int max_connections_to_host;
 2191 extern int max_tries;
 2192 extern int screen_width;
 2193 extern int dump_codepage;
 2194 extern int receive_timeout;
 2195 extern int unrestartable_receive_timeout;
 2196 
 2197 extern struct document_setup dds;
 2198 
 2199 extern int max_format_cache_entries;
 2200 extern int memory_cache_size;
 2201 
 2202 extern struct rgb default_fg;
 2203 extern struct rgb default_bg;
 2204 extern struct rgb default_link;
 2205 extern struct rgb default_vlink;
 2206 
 2207 extern unsigned char http_proxy[];
 2208 extern unsigned char ftp_proxy[];
 2209 extern unsigned char download_dir[];
 2210 
 2211 struct http_bugs {
 2212     int http10;
 2213     int allow_blacklist;
 2214     int bug_302_redirect;
 2215     int bug_post_no_keepalive;
 2216     int no_accept_charset;
 2217 };
 2218 
 2219 extern struct http_bugs http_bugs;
 2220 
 2221 struct ftp_options {
 2222     unsigned char anon_pass[MAX_STR_LEN];
 2223     int fast_ftp;
 2224     int passive_ftp;
 2225     int set_tos;
 2226 };
 2227 
 2228 extern struct ftp_options ftp_options;
 2229 
 2230 /* bookmarks.c */
 2231 
 2232 /* Where all bookmarks are kept */
 2233 extern struct list_head bookmarks;
 2234 
 2235 /* A pointer independent id that bookmarks can be identified by. Guarenteed to 
 2236     be unique between all bookmarks */
 2237 typedef int bookmark_id;
 2238 extern bookmark_id next_bookmark_id;
 2239 #define     BAD_BOOKMARK_ID     (bookmark_id)(-1)
 2240 
 2241 
 2242 /* Stores display information about a box. Kept in cdata. */
 2243 struct dlg_data_item_data_box {
 2244     int sel;    /* Item currently selected */   
 2245     int box_top;    /* Index into items of the item that is on the top line of the box */
 2246     struct list_head items; /* The list being displayed */
 2247     int list_len;   /* Number of items in the list */
 2248 };
 2249 
 2250 /* An item in a box */
 2251 struct box_item {
 2252     struct box_item *next;
 2253     struct box_item *prev;
 2254     unsigned char *text;    /* Text to display */
 2255     void *data; /* data */
 2256 };
 2257 
 2258 
 2259 void show_dlg_item_box(struct dialog_data *, struct dialog_item_data *); 
 2260 
 2261 #define BOX_HILIGHT_FUNC (void (*)(struct terminal *, struct dlg_data_item_data_box *, struct box_item *))
 2262 #define BOX_ON_SELECTED_FUNC (int (*)(struct terminal *, struct dlg_data_item_data_box *, struct box_item *))
 2263 
 2264 /* Ops dealing with box data */
 2265 /* */
 2266 #define get_box_from_dlg_item_data(x) ((struct dlg_data_item_data_box *)(x->cdata))
 2267 #define get_box_list_height(x) (x->data_len)
 2268 
 2269 /* V.05 bookmarks: */
 2270 /*
 2271 struct bookmark {
 2272     struct bookmark *next;
 2273     struct bookmark *prev;
 2274     bookmark_id id; Bookmark id 
 2275     unsigned char *title;    title of bookmark 
 2276     unsigned char *url;  Location of bookmarked item 
 2277 };*/
 2278 
 2279 struct bookmark {
 2280     struct bookmark *next;
 2281     struct bookmark *prev;
 2282     bookmark_id id; /* Bookmark id */
 2283     unsigned char *title;   /* title of bookmark */
 2284     unsigned char *url; /* Location of bookmarked item */
 2285     unsigned int type; /* The type of bookmark we're dealing with. */
 2286     void *type_data; /* Type-dependent data. */
 2287 };
 2288 
 2289 void finalize_bookmarks();
 2290 
 2291 void read_bookmarks();
 2292 void write_bookmarks();
 2293 
 2294 void bookmark_menu(struct terminal *, void *, struct session *);
 2295 
 2296 /* Launches bookmark manager */
 2297 void menu_bookmark_manager(struct terminal *, void *, struct session *);
 2298 
 2299 void add_bookmark(const unsigned char *, const unsigned char *);
 2300 
 2301 struct bookmark *create_bookmark(const unsigned char *, const unsigned char *);
 2302 
 2303 /* Launches add dialogs */
 2304 void launch_bm_add_link_dialog(struct terminal *,struct dialog_data *,struct session *);
 2305 void launch_bm_add_doc_dialog(struct terminal *,struct dialog_data *,struct session *);
 2306 
 2307 /* kbdbind.c */
 2308 
 2309 #define KM_MAIN     0
 2310 #define KM_EDIT     1
 2311 #define KM_MENU     2
 2312 #define KM_MAX      3
 2313 
 2314 enum {
 2315     ACT_ADD_BOOKMARK,
 2316     ACT_AUTO_COMPLETE,
 2317     ACT_BACK,
 2318     ACT_BACKSPACE,
 2319     ACT_BOOKMARK_MANAGER,
 2320     ACT_COPY_CLIPBOARD,
 2321     ACT_CUT_CLIPBOARD,
 2322     ACT_DELETE,
 2323     ACT_DOCUMENT_INFO,
 2324     ACT_DOWN,
 2325     ACT_DOWNLOAD,
 2326     ACT_END,
 2327     ACT_ENTER,
 2328     ACT_FILE_MENU,
 2329     ACT_FIND_NEXT,
 2330     ACT_FIND_NEXT_BACK,
 2331     ACT_GOTO_URL,
 2332     ACT_GOTO_URL_CURRENT,
 2333     ACT_GOTO_URL_CURRENT_LINK,
 2334     ACT_HEADER_INFO,
 2335     ACT_HOME,
 2336     ACT_KILL_TO_BOL,
 2337     ACT_KILL_TO_EOL,
 2338     ACT_LEFT,
 2339     ACT_MENU,
 2340     ACT_NEXT_FRAME,
 2341     ACT_OPEN_NEW_WINDOW,
 2342     ACT_OPEN_LINK_IN_NEW_WINDOW,
 2343     ACT_PAGE_DOWN,
 2344     ACT_PAGE_UP,
 2345     ACT_PASTE_CLIPBOARD,
 2346     ACT_PREVIOUS_FRAME,
 2347     ACT_REALLYQUIT,
 2348     ACT_QUIT,
 2349     ACT_RELOAD,
 2350     ACT_RIGHT,
 2351     ACT_SCROLL_DOWN,
 2352     ACT_SCROLL_LEFT,
 2353     ACT_SCROLL_RIGHT,
 2354     ACT_SCROLL_UP,
 2355     ACT_SEARCH,
 2356     ACT_SEARCH_BACK,
 2357     ACT_TOGGLE_DISPLAY_IMAGES,
 2358     ACT_TOGGLE_DISPLAY_TABLES,
 2359     ACT_TOGGLE_HTML_PLAIN,
 2360     ACT_UP,
 2361     ACT_VIEW_IMAGE,
 2362     ACT_ZOOM_FRAME
 2363 };
 2364 
 2365 void init_keymaps();
 2366 void free_keymaps();
 2367 int kbd_action(int, struct event *);
 2368 unsigned char *bind_rd(struct option *, unsigned char *);
 2369 unsigned char *unbind_rd(struct option *, unsigned char *);