Intial commit
[profile/ivi/w3m.git] / fm.h
1 /* $Id: fm.h,v 1.138 2007/05/30 04:47:24 inu Exp $ */
2 /* 
3  * w3m: WWW wo Miru utility
4  * 
5  * by A.ITO  Feb. 1995
6  * 
7  * You can use,copy,modify and distribute this program without any permission.
8  */
9
10 #ifndef FM_H
11 #define FM_H
12
13
14 #ifndef _GNU_SOURCE
15 #define _GNU_SOURCE             /* strcasestr() */
16 #endif
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include "config.h"
26 #include "history.h"
27
28 #ifdef USE_MENU
29 #define MENU_SELECT
30 #define MENU_MAP
31 #endif                          /* USE_MENU */
32
33 #ifndef USE_COLOR
34 #undef USE_ANSI_COLOR
35 #undef USE_BG_COLOR
36 #endif
37
38 #include "ctrlcode.h"
39 #include "html.h"
40 #include <gc.h>
41 #include "Str.h"
42 #ifdef USE_M17N
43 #include "wc.h"
44 #include "wtf.h"
45 #else
46 typedef int wc_ces;     /* XXX: not used */
47 #endif
48
49 #ifdef HAVE_LOCALE_H
50 #include <locale.h>
51 #endif
52 #if !HAVE_SETLOCALE
53 #define setlocale(category, locale)     /* empty */
54 #endif
55
56 #ifdef ENABLE_NLS
57 #include <libintl.h>
58 #define _(String) gettext (String)
59 #define N_(String) (String)
60 #else
61 # undef bindtextdomain
62 # define bindtextdomain(Domain, Directory)      /* empty */
63 # undef textdomain
64 # define textdomain(Domain)     /* empty */
65 # define _(Text) Text
66 # define N_(Text) Text
67 # define gettext(Text) Text
68 #endif
69
70 #include "form.h"
71 #include "frame.h"
72 #include "parsetag.h"
73 #include "parsetagx.h"
74 #include "func.h"
75 #include "menu.h"
76 #include "textlist.h"
77 #include "funcname1.h"
78 #include "terms.h"
79
80 #ifndef HAVE_BCOPY
81 void bcopy(const void *, void *, int);
82 void bzero(void *, int);
83 #endif                          /* HAVE_BCOPY */
84 #ifdef __EMX__
85 #include <strings.h>            /* for bzero() and bcopy() */
86 #endif
87
88 #ifdef MAINPROGRAM
89 #define global
90 #define init(x) =(x)
91 #else                           /* not MAINPROGRAM */
92 #define global extern
93 #define init(x)
94 #endif                          /* not MAINPROGRAM */
95
96 #define DEFUN(funcname, macroname, docstring) void funcname(void)
97
98 /* 
99  * Constants.
100  */
101 #define LINELEN 256             /* Initial line length */
102 #define PAGER_MAX_LINE  10000   /* Maximum line kept as pager */
103
104 #ifdef USE_IMAGE
105 #define MAX_IMAGE 1000
106 #define MAX_IMAGE_SIZE 2048
107
108 #define DEFAULT_PIXEL_PER_CHAR  7.0     /* arbitrary */
109 #define DEFAULT_PIXEL_PER_LINE  14.0    /* arbitrary */
110 #else
111 #define DEFAULT_PIXEL_PER_CHAR  8.0     /* arbitrary */
112 #endif
113 #define MINIMUM_PIXEL_PER_CHAR  4.0
114 #define MAXIMUM_PIXEL_PER_CHAR  32.0
115
116 #ifdef FALSE
117 #undef FALSE
118 #endif
119
120 #ifdef TRUE
121 #undef TRUE
122 #endif
123
124 #define FALSE 0
125 #define TRUE   1
126
127 #define SHELLBUFFERNAME "*Shellout*"
128 #define PIPEBUFFERNAME  "*stream*"
129 #define CPIPEBUFFERNAME "*stream(closed)*"
130 #ifdef USE_DICT
131 #define DICTBUFFERNAME "*dictionary*"
132 #endif                          /* USE_DICT */
133
134 /* 
135  * Line Property
136  */
137
138 #define P_CHARTYPE      0x3f00
139 #ifdef USE_M17N
140 #define PC_ASCII        (WTF_TYPE_ASCII << 8)
141 #define PC_CTRL         (WTF_TYPE_CTRL << 8)
142 #define PC_WCHAR1       (WTF_TYPE_WCHAR1 << 8)
143 #define PC_WCHAR2       (WTF_TYPE_WCHAR2 << 8)
144 #define PC_KANJI        (WTF_TYPE_WIDE << 8)
145 #define PC_KANJI1       (PC_WCHAR1 | PC_KANJI)
146 #define PC_KANJI2       (PC_WCHAR2 | PC_KANJI)
147 #define PC_UNKNOWN      (WTF_TYPE_UNKNOWN << 8)
148 #define PC_UNDEF        (WTF_TYPE_UNDEF << 8)
149 #else
150 #define PC_ASCII        0x0000
151 #define PC_CTRL         0x0100
152 #endif
153 #define PC_SYMBOL       0x8000
154
155 /* Effect ( standout/underline ) */
156 #define P_EFFECT        0x40ff
157 #define PE_NORMAL       0x00
158 #define PE_MARK         0x01
159 #define PE_UNDER        0x02
160 #define PE_STAND        0x04
161 #define PE_BOLD         0x08
162 #define PE_ANCHOR       0x10
163 #define PE_EMPH         0x08
164 #define PE_IMAGE        0x20
165 #define PE_FORM         0x40
166 #define PE_ACTIVE       0x80
167 #define PE_VISITED      0x4000
168
169 /* Extra effect */
170 #define PE_EX_ITALIC    0x01
171 #define PE_EX_INSERT    0x02
172 #define PE_EX_STRIKE    0x04
173
174 #define PE_EX_ITALIC_E  PE_UNDER
175 #define PE_EX_INSERT_E  PE_UNDER
176 #define PE_EX_STRIKE_E  PE_STAND
177
178 #define CharType(c)     ((c)&P_CHARTYPE)
179 #define CharEffect(c)   ((c)&(P_EFFECT|PC_SYMBOL))
180 #define SetCharType(v,c)        ((v)=(((v)&~P_CHARTYPE)|(c)))
181
182
183 #define COLPOS(l,c)     calcPosition(l->lineBuf,l->propBuf,l->len,c,0,CP_AUTO)
184
185 /* Flags for displayBuffer() */
186 #define B_NORMAL        0
187 #define B_FORCE_REDRAW  1
188 #define B_REDRAW        2
189 #define B_SCROLL        3
190 #define B_REDRAW_IMAGE  4
191
192 /* Buffer Property */
193 #define BP_NORMAL       0x0
194 #define BP_PIPE         0x1
195 #define BP_FRAME        0x2
196 #define BP_INTERNAL     0x8
197 #define BP_NO_URL       0x10
198 #define BP_REDIRECTED   0x20
199 #define BP_CLOSE        0x40
200
201 /* Link Buffer */
202 #define LB_NOLINK       -1
203 #define LB_FRAME        0       /* rFrame() */
204 #define LB_N_FRAME      1
205 #define LB_INFO         2       /* pginfo() */
206 #define LB_N_INFO       3
207 #define LB_SOURCE       4       /* vwSrc() */
208 #define LB_N_SOURCE     LB_SOURCE
209 #define MAX_LB          5
210
211 /* Search Result */
212 #define SR_FOUND       0x1
213 #define SR_NOTFOUND    0x2
214 #define SR_WRAPPED     0x4
215
216 #ifdef MAINPROGRAM
217 int REV_LB[MAX_LB] = {
218     LB_N_FRAME, LB_FRAME, LB_N_INFO, LB_INFO, LB_N_SOURCE,
219 };
220 #else                           /* not MAINPROGRAM */
221 extern int REV_LB[];
222 #endif                          /* not MAINPROGRAM */
223
224 /* mark URL, Message-ID */
225 #define CHK_URL                1
226 #define CHK_NMID       2
227
228 /* Flags for calcPosition() */
229 #define CP_AUTO         0
230 #define CP_FORCE        1
231
232 /* Completion status. */
233 #define CPL_OK          0
234 #define CPL_AMBIG       1
235 #define CPL_FAIL        2
236 #define CPL_MENU        3
237
238 #define CPL_NEVER       0x0
239 #define CPL_OFF         0x1
240 #define CPL_ON          0x2
241 #define CPL_ALWAYS      0x4
242 #define CPL_URL         0x8
243
244 /* Flags for inputLine() */
245 #define IN_STRING       0x10
246 #define IN_FILENAME     0x20
247 #define IN_PASSWORD     0x40
248 #define IN_COMMAND      0x80
249 #define IN_URL          0x100
250 #define IN_CHAR         0x200
251
252 #define IMG_FLAG_SKIP   1
253 #define IMG_FLAG_AUTO   2
254
255 #define IMG_FLAG_START  0
256 #define IMG_FLAG_STOP   1
257 #define IMG_FLAG_NEXT   2
258
259 #define IMG_FLAG_UNLOADED       0
260 #define IMG_FLAG_LOADED         1
261 #define IMG_FLAG_ERROR          2
262 #define IMG_FLAG_DONT_REMOVE    4
263
264 /* 
265  * Macros.
266  */
267
268 #define inputLineHist(p,d,f,h)  inputLineHistSearch(p,d,f,h,NULL)
269 #define inputLine(p,d,f)        inputLineHist(p,d,f,NULL)
270 #define inputStr(p,d)           inputLine(p,d,IN_STRING)
271 #define inputStrHist(p,d,h)     inputLineHist(p,d,IN_STRING,h)
272 #define inputFilename(p,d)      inputLine(p,d,IN_FILENAME)
273 #define inputFilenameHist(p,d,h)        inputLineHist(p,d,IN_FILENAME,h)
274 #define inputChar(p)            inputLine(p,"",IN_CHAR)
275
276 #define free(x)  GC_free(x)     /* let GC do it. */
277
278 #ifdef __EMX__
279 #define HAVE_STRCASECMP
280 #define strcasecmp      stricmp
281 #define strncasecmp     strnicmp
282 #endif                          /* __EMX__ */
283
284
285 #define SKIP_BLANKS(p) {while(*(p)&&IS_SPACE(*(p)))(p)++;}
286 #define SKIP_NON_BLANKS(p) {while(*(p)&&!IS_SPACE(*(p)))(p)++;}
287 #define IS_ENDL(c) ((c)=='\0'||(c)=='\r'||(c)=='\n')
288 #define IS_ENDT(c) (IS_ENDL(c)||(c)==';')
289
290 #define bpcmp(a,b) \
291   (((a).line - (b).line) ? ((a).line - (b).line) : ((a).pos - (b).pos))
292
293 #define RELATIVE_WIDTH(w)   (((w)>=0)?(int)((w)/pixel_per_char):(w))
294 #define REAL_WIDTH(w,limit) (((w)>=0)?(int)((w)/pixel_per_char):-(w)*(limit)/100)
295
296 #define EOL(l) (&(l)->ptr[(l)->length])
297 #define IS_EOL(p,l) ((p)==&(l)->ptr[(l)->length])
298
299 /* 
300  * Types.
301  */
302
303 typedef unsigned short Lineprop;
304 #ifdef USE_ANSI_COLOR
305 typedef unsigned char Linecolor;
306 #endif
307
308 typedef struct _MapArea {
309     char *url;
310     char *target;
311     char *alt;
312 #ifdef USE_IMAGE
313     char shape;
314     short *coords;
315     int ncoords;
316     short center_x;
317     short center_y;
318 #endif
319 } MapArea;
320
321 typedef struct _MapList {
322     Str name;
323     GeneralList *area;
324     struct _MapList *next;
325 } MapList;
326
327 typedef struct _Line {
328     char *lineBuf;
329     Lineprop *propBuf;
330 #ifdef USE_ANSI_COLOR
331     Linecolor *colorBuf;
332 #endif
333     struct _Line *next;
334     struct _Line *prev;
335     int len;
336     int width;
337     long linenumber;            /* on buffer */
338     long real_linenumber;       /* on file */
339     unsigned short usrflags;
340     int size;
341     int bpos;
342     int bwidth;
343 } Line;
344
345 typedef struct {
346     int line;
347     int pos;
348     int invalid;
349 } BufferPoint;
350
351 #ifdef USE_IMAGE
352 typedef struct _imageCache {
353     char *url;
354     ParsedURL *current;
355     char *file;
356     char *touch;
357     pid_t pid;
358     char loaded;
359     int index;
360     short width;
361     short height;
362 } ImageCache;
363
364 typedef struct _image {
365     char *url;
366     char *ext;
367     short width;
368     short height;
369     short xoffset;
370     short yoffset;
371     short y;
372     short rows;
373     char *map;
374     char ismap;
375     int touch;
376     ImageCache *cache;
377 } Image;
378 #endif
379
380 typedef struct _anchor {
381     char *url;
382     char *target;
383     char *referer;
384     char *title;
385     unsigned char accesskey;
386     BufferPoint start;
387     BufferPoint end;
388     int hseq;
389     char slave;
390     short y;
391     short rows;
392 #ifdef USE_IMAGE
393     Image *image;
394 #endif
395 } Anchor;
396
397 #define NO_REFERER ((char*)-1)
398
399 typedef struct _anchorList {
400     Anchor *anchors;
401     int nanchor;
402     int anchormax;
403     int acache;
404 } AnchorList;
405
406 typedef struct {
407     BufferPoint *marks;
408     int nmark;
409     int markmax;
410     int prevhseq;
411 } HmarkerList;
412
413 #define LINK_TYPE_NONE 0
414 #define LINK_TYPE_REL  1
415 #define LINK_TYPE_REV  2
416 typedef struct _LinkList {
417     char *url;
418     char *title;                /* Next, Contents, ... */
419     char *ctype;                /* Content-Type */
420     char type;                  /* Rel, Rev */
421     struct _LinkList *next;
422 } LinkList;
423
424 typedef struct _Buffer {
425     char *filename;
426     char *buffername;
427     Line *firstLine;
428     Line *topLine;
429     Line *currentLine;
430     Line *lastLine;
431     struct _Buffer *nextBuffer;
432     struct _Buffer *linkBuffer[MAX_LB];
433     short width;
434     short height;
435     char *type;
436     char *real_type;
437     int allLine;
438     short bufferprop;
439     int currentColumn;
440     short cursorX;
441     short cursorY;
442     int pos;
443     int visualpos;
444     short rootX;
445     short rootY;
446     short COLS;
447     short LINES;
448     InputStream pagerSource;
449     AnchorList *href;
450     AnchorList *name;
451     AnchorList *img;
452     AnchorList *formitem;
453     LinkList *linklist;
454     FormList *formlist;
455     MapList *maplist;
456     HmarkerList *hmarklist;
457     HmarkerList *imarklist;
458     ParsedURL currentURL;
459     ParsedURL *baseURL;
460     char *baseTarget;
461     int real_scheme;
462     char *sourcefile;
463     struct frameset *frameset;
464     struct frameset_queue *frameQ;
465     int *clone;
466     size_t trbyte;
467     char check_url;
468 #ifdef USE_M17N
469     wc_ces document_charset;
470     wc_uint8 auto_detect;
471 #endif
472     TextList *document_header;
473     FormItemList *form_submit;
474     char *savecache;
475     char *edit;
476     struct mailcap *mailcap;
477     char *mailcap_source;
478     char *header_source;
479     char search_header;
480 #ifdef USE_SSL
481     char *ssl_certificate;
482 #endif
483     char image_flag;
484     char image_loaded;
485     char need_reshape;
486     Anchor *submit;
487     struct _BufferPos *undo;
488 #ifdef USE_ALARM
489     struct _AlarmEvent *event;
490 #endif
491 } Buffer;
492
493 typedef struct _BufferPos {
494     long top_linenumber;
495     long cur_linenumber;
496     int currentColumn;
497     int pos;
498     int bpos;
499     struct _BufferPos *next;
500     struct _BufferPos *prev;
501 } BufferPos;
502
503 typedef struct _TabBuffer {
504     struct _TabBuffer *nextTab;
505     struct _TabBuffer *prevTab;
506     Buffer *currentBuffer;
507     Buffer *firstBuffer;
508     short x1;
509     short x2;
510     short y;
511 } TabBuffer;
512
513 typedef struct _DownloadList {
514     pid_t pid;
515     char *url;
516     char *save;
517     char *lock;
518     clen_t size;
519     time_t time;
520     int ok;
521     struct _DownloadList *next;
522     struct _DownloadList *prev;
523 } DownloadList;
524 #define DOWNLOAD_LIST_TITLE "Download List Panel"
525
526 #define COPY_BUFROOT(dstbuf, srcbuf) {\
527  (dstbuf)->rootX = (srcbuf)->rootX; \
528  (dstbuf)->rootY = (srcbuf)->rootY; \
529  (dstbuf)->COLS = (srcbuf)->COLS; \
530  (dstbuf)->LINES = (srcbuf)->LINES; \
531 }
532
533 #define COPY_BUFPOSITION(dstbuf, srcbuf) {\
534  (dstbuf)->topLine = (srcbuf)->topLine; \
535  (dstbuf)->currentLine = (srcbuf)->currentLine; \
536  (dstbuf)->pos = (srcbuf)->pos; \
537  (dstbuf)->cursorX = (srcbuf)->cursorX; \
538  (dstbuf)->cursorY = (srcbuf)->cursorY; \
539  (dstbuf)->visualpos = (srcbuf)->visualpos; \
540  (dstbuf)->currentColumn = (srcbuf)->currentColumn; \
541 }
542 #define SAVE_BUFPOSITION(sbufp) COPY_BUFPOSITION(sbufp, Currentbuf)
543 #define RESTORE_BUFPOSITION(sbufp) COPY_BUFPOSITION(Currentbuf, sbufp)
544 #define TOP_LINENUMBER(buf) ((buf)->topLine ? (buf)->topLine->linenumber : 1)
545 #define CUR_LINENUMBER(buf) ((buf)->currentLine ? (buf)->currentLine->linenumber : 1)
546
547 #define NO_BUFFER ((Buffer*)1)
548
549 #define RB_STACK_SIZE 10
550
551 #define TAG_STACK_SIZE 10
552
553 #define FONT_STACK_SIZE 5
554
555 #define FONTSTAT_SIZE 7
556
557 #define _INIT_BUFFER_WIDTH (COLS - (showLineNum ? 6 : 1))
558 #define INIT_BUFFER_WIDTH ((_INIT_BUFFER_WIDTH > 0) ? _INIT_BUFFER_WIDTH : 0)
559 #define FOLD_BUFFER_WIDTH (FoldLine ? (INIT_BUFFER_WIDTH + 1) : -1)
560
561 typedef struct {
562     int pos;
563     int len;
564     int tlen;
565     long flag;
566     Anchor anchor;
567     Str img_alt;
568     char fontstat[FONTSTAT_SIZE];
569     short nobr_level;
570     Lineprop prev_ctype;
571     char init_flag;
572     short top_margin;
573     short bottom_margin;
574 } Breakpoint;
575
576 struct readbuffer {
577     Str line;
578     Lineprop cprop;
579     short pos;
580     Str prevchar;
581     long flag;
582     long flag_stack[RB_STACK_SIZE];
583     int flag_sp;
584     int status;
585     unsigned char end_tag;
586     short table_level;
587     short nobr_level;
588     Anchor anchor;
589     Str img_alt;
590     char fontstat[FONTSTAT_SIZE];
591     char fontstat_stack[FONT_STACK_SIZE][FONTSTAT_SIZE];
592     int fontstat_sp;
593     Lineprop prev_ctype;
594     Breakpoint bp;
595     struct cmdtable *tag_stack[TAG_STACK_SIZE];
596     int tag_sp;
597     short top_margin;
598     short bottom_margin;
599 };
600
601 #define in_bold fontstat[0]
602 #define in_under fontstat[1]
603 #define in_italic fontstat[2]
604 #define in_strike fontstat[3]
605 #define in_ins fontstat[4]
606 #define in_stand fontstat[5]
607
608 #define RB_PRE          0x01
609 #define RB_SCRIPT       0x02
610 #define RB_STYLE        0x04
611 #define RB_PLAIN        0x08
612 #define RB_LEFT         0x10
613 #define RB_CENTER       0x20
614 #define RB_RIGHT        0x40
615 #define RB_ALIGN        (RB_LEFT| RB_CENTER | RB_RIGHT)
616 #define RB_NOBR         0x80
617 #define RB_P            0x100
618 #define RB_PRE_INT      0x200
619 #define RB_IN_DT        0x400
620 #define RB_INTXTA       0x800
621 #define RB_INSELECT     0x1000
622 #define RB_IGNORE_P     0x2000
623 #define RB_TITLE        0x4000
624 #define RB_NFLUSHED     0x8000
625 #define RB_NOFRAMES     0x10000
626 #define RB_INTABLE      0x20000
627 #define RB_PREMODE      (RB_PRE | RB_PRE_INT | RB_SCRIPT | RB_STYLE | RB_PLAIN | RB_INTXTA)
628 #define RB_SPECIAL      (RB_PRE | RB_PRE_INT | RB_SCRIPT | RB_STYLE | RB_PLAIN | RB_NOBR)
629 #define RB_PLAIN_PRE    0x40000
630
631 #ifdef FORMAT_NICE
632 #define RB_FILL         0x80000
633 #endif                          /* FORMAT_NICE */
634 #define RB_DEL          0x100000
635 #define RB_S            0x200000
636
637 #define RB_GET_ALIGN(obuf) ((obuf)->flag&RB_ALIGN)
638 #define RB_SET_ALIGN(obuf,align) {(obuf)->flag &= ~RB_ALIGN; (obuf)->flag |= (align); }
639 #define RB_SAVE_FLAG(obuf) {\
640   if ((obuf)->flag_sp < RB_STACK_SIZE) \
641     (obuf)->flag_stack[(obuf)->flag_sp++] = RB_GET_ALIGN(obuf); \
642 }
643 #define RB_RESTORE_FLAG(obuf) {\
644   if ((obuf)->flag_sp > 0) \
645    RB_SET_ALIGN(obuf,(obuf)->flag_stack[--(obuf)->flag_sp]); \
646 }
647
648 /* status flags */
649 #define R_ST_NORMAL 0           /* normal */
650 #define R_ST_TAG0   1           /* within tag, just after < */
651 #define R_ST_TAG    2           /* within tag */
652 #define R_ST_QUOTE  3           /* within single quote */
653 #define R_ST_DQUOTE 4           /* within double quote */
654 #define R_ST_EQL    5           /* = */
655 #define R_ST_AMP    6           /* within ampersand quote */
656 #define R_ST_EOL    7           /* end of file */
657 #define R_ST_CMNT1  8           /* <!  */
658 #define R_ST_CMNT2  9           /* <!- */
659 #define R_ST_CMNT   10          /* within comment */
660 #define R_ST_NCMNT1 11          /* comment - */
661 #define R_ST_NCMNT2 12          /* comment -- */
662 #define R_ST_NCMNT3 13          /* comment -- space */
663 #define R_ST_IRRTAG 14          /* within irregular tag */
664 #define R_ST_VALUE  15          /* within tag attribule value */
665
666 #define ST_IS_REAL_TAG(s)   ((s)==R_ST_TAG||(s)==R_ST_TAG0||(s)==R_ST_EQL||(s)==R_ST_VALUE)
667
668 /* is this '<' really means the beginning of a tag? */
669 #define REALLY_THE_BEGINNING_OF_A_TAG(p) \
670           (IS_ALPHA(p[1]) || p[1] == '/' || p[1] == '!' || p[1] == '?' || p[1] == '\0' || p[1] == '_')
671
672 /* flags for loadGeneralFile */
673 #define RG_NOCACHE   1
674 #define RG_FRAME     2
675 #define RG_FRAME_SRC 4
676
677 struct html_feed_environ {
678     struct readbuffer *obuf;
679     TextLineList *buf;
680     FILE *f;
681     Str tagbuf;
682     int limit;
683     int maxlimit;
684     struct environment *envs;
685     int nenv;
686     int envc;
687     int envc_real;
688     char *title;
689     int blank_lines;
690 };
691
692 #ifdef USE_COOKIE
693 struct portlist {
694     unsigned short port;
695     struct portlist *next;
696 };
697
698 struct cookie {
699     ParsedURL url;
700     Str name;
701     Str value;
702     time_t expires;
703     Str path;
704     Str domain;
705     Str comment;
706     Str commentURL;
707     struct portlist *portl;
708     char version;
709     char flag;
710     struct cookie *next;
711 };
712 #define COO_USE         1
713 #define COO_SECURE      2
714 #define COO_DOMAIN      4
715 #define COO_PATH        8
716 #define COO_DISCARD     16
717 #define COO_OVERRIDE    32      /* user chose to override security checks */
718
719 #define COO_OVERRIDE_OK 32      /* flag to specify that an error is overridable */
720                                                 /* version 0 refers to the original cookie_spec.html */
721                                                 /* version 1 refers to RFC 2109 */
722                                                 /* version 1' refers to the Internet draft to obsolete RFC 2109 */
723 #define COO_EINTERNAL   (1)     /* unknown error; probably forgot to convert "return 1" in cookie.c */
724 #define COO_ETAIL       (2 | COO_OVERRIDE_OK)   /* tail match failed (version 0) */
725 #define COO_ESPECIAL    (3)     /* special domain check failed (version 0) */
726 #define COO_EPATH       (4)     /* Path attribute mismatch (version 1 case 1) */
727 #define COO_ENODOT      (5 | COO_OVERRIDE_OK)   /* no embedded dots in Domain (version 1 case 2.1) */
728 #define COO_ENOTV1DOM   (6 | COO_OVERRIDE_OK)   /* Domain does not start with a dot (version 1 case 2.2) */
729 #define COO_EDOM        (7 | COO_OVERRIDE_OK)   /* domain-match failed (version 1 case 3) */
730 #define COO_EBADHOST    (8 | COO_OVERRIDE_OK)   /* dot in matched host name in FQDN (version 1 case 4) */
731 #define COO_EPORT       (9)     /* Port match failed (version 1' case 5) */
732 #define COO_EMAX        COO_EPORT
733 #endif                          /* USE_COOKIE */
734
735 /* modes for align() */
736
737 #define ALIGN_CENTER 0
738 #define ALIGN_LEFT   1
739 #define ALIGN_RIGHT  2
740 #define ALIGN_MIDDLE 4
741 #define ALIGN_TOP    5
742 #define ALIGN_BOTTOM 6
743
744 #define VALIGN_MIDDLE 0
745 #define VALIGN_TOP    1
746 #define VALIGN_BOTTOM 2
747
748 typedef struct http_request {
749     char command;
750     char flag;
751     char *referer;
752     FormList *request;
753 } HRequest;
754
755 #define HR_COMMAND_GET          0
756 #define HR_COMMAND_POST         1
757 #define HR_COMMAND_CONNECT      2
758 #define HR_COMMAND_HEAD         3
759
760 #define HR_FLAG_LOCAL           1
761 #define HR_FLAG_PROXY           2
762
763 #define HTST_UNKNOWN            255
764 #define HTST_MISSING            254
765 #define HTST_NORMAL             0
766 #define HTST_CONNECT            1
767
768 #define TMPF_DFL        0
769 #define TMPF_SRC        1
770 #define TMPF_FRAME      2
771 #define TMPF_CACHE      3
772 #define TMPF_COOKIE     4
773 #define MAX_TMPF_TYPE   5
774
775 #define set_no_proxy(domains) (NO_proxy_domains=make_domain_list(domains))
776
777 /* 
778  * Globals.
779  */
780
781 extern int LINES, COLS;
782 #if defined(__CYGWIN__)
783 extern int LASTLINE;
784 #else                           /* not defined(__CYGWIN__) */
785 #define LASTLINE (LINES-1)
786 #endif                          /* not defined(__CYGWIN__) */
787
788 global int Tabstop init(8);
789 global int IndentIncr init(4);
790 global int ShowEffect init(TRUE);
791 global int PagerMax init(PAGER_MAX_LINE);
792
793 global char SearchHeader init(FALSE);
794 global char *DefaultType init(NULL);
795 global char RenderFrame init(FALSE);
796 global char TargetSelf init(FALSE);
797 global char PermitSaveToPipe init(FALSE);
798 global char DecodeCTE init(FALSE);
799 global char AutoUncompress init(FALSE);
800 global char PreserveTimestamp init(TRUE);
801 global char ArgvIsURL init(FALSE);
802 global char MetaRefresh init(FALSE);
803
804 global char fmInitialized init(FALSE);
805 global char QuietMessage init(FALSE);
806 global char TrapSignal init(TRUE);
807 #define TRAP_ON if (TrapSignal) { \
808     prevtrap = mySignal(SIGINT, KeyAbort); \
809     if (fmInitialized) \
810         term_cbreak(); \
811 }
812 #define TRAP_OFF if (TrapSignal) { \
813     if (fmInitialized) \
814         term_raw(); \
815     if (prevtrap) \
816         mySignal(SIGINT, prevtrap); \
817 }
818
819 extern unsigned char GlobalKeymap[];
820 extern unsigned char EscKeymap[];
821 extern unsigned char EscBKeymap[];
822 extern unsigned char EscDKeymap[];
823 #ifdef __EMX__
824 extern unsigned char PcKeymap[];
825 #endif
826 extern FuncList w3mFuncList[];
827
828 global char *HTTP_proxy init(NULL);
829 #ifdef USE_SSL
830 global char *HTTPS_proxy init(NULL);
831 #endif                          /* USE_SSL */
832 #ifdef USE_GOPHER
833 global char *GOPHER_proxy init(NULL);
834 #endif                          /* USE_GOPHER */
835 global char *FTP_proxy init(NULL);
836 global ParsedURL HTTP_proxy_parsed;
837 #ifdef USE_SSL
838 global ParsedURL HTTPS_proxy_parsed;
839 #endif                          /* USE_SSL */
840 #ifdef USE_GOPHER
841 global ParsedURL GOPHER_proxy_parsed;
842 #endif                          /* USE_GOPHER */
843 global ParsedURL FTP_proxy_parsed;
844 global char *NO_proxy init(NULL);
845 global int NOproxy_netaddr init(TRUE);
846 #ifdef INET6
847 #define DNS_ORDER_UNSPEC     0
848 #define DNS_ORDER_INET_INET6 1
849 #define DNS_ORDER_INET6_INET 2
850 #define DNS_ORDER_INET_ONLY  4
851 #define DNS_ORDER_INET6_ONLY 6
852 global int DNS_order init(DNS_ORDER_UNSPEC);
853 extern int ai_family_order_table[7][3]; /* XXX */
854 #endif                          /* INET6 */
855 global TextList *NO_proxy_domains;
856 global char NoCache init(FALSE);
857 global char use_proxy init(TRUE);
858 #define Do_not_use_proxy (!use_proxy)
859 global int Do_not_use_ti_te init(FALSE);
860 #ifdef USE_NNTP
861 global char *NNTP_server init(NULL);
862 global char *NNTP_mode init(NULL);
863 global int MaxNewsMessage init(50);
864 #endif
865
866 global char *document_root init(NULL);
867 global char *personal_document_root init(NULL);
868 global char *cgi_bin init(NULL);
869 global char *index_file init(NULL);
870
871 global char *CurrentDir;
872 global int CurrentPid;
873 /*
874  * global Buffer *Currentbuf;
875  * global Buffer *Firstbuf;
876  */
877 global TabBuffer *CurrentTab;
878 global TabBuffer *FirstTab;
879 global TabBuffer *LastTab;
880 global int open_tab_blank init(FALSE);
881 global int open_tab_dl_list init(FALSE);
882 global int close_tab_back init(FALSE);
883 global int nTab;
884 global int TabCols init(10);
885 #define NO_TABBUFFER ((TabBuffer *)1)
886 #define Currentbuf (CurrentTab->currentBuffer)
887 #define Firstbuf (CurrentTab->firstBuffer)
888 global DownloadList *FirstDL init(NULL);
889 global DownloadList *LastDL init(NULL);
890 global int CurrentKey;
891 global char *CurrentKeyData;
892 global char *CurrentCmdData;
893 global char *w3m_reqlog;
894 extern char *w3m_version;
895
896 #define DUMP_BUFFER   0x01
897 #define DUMP_HEAD     0x02
898 #define DUMP_SOURCE   0x04
899 #define DUMP_EXTRA    0x08
900 #define DUMP_HALFDUMP 0x10
901 #define DUMP_FRAME    0x20
902 global int w3m_debug;
903 global int w3m_dump init(0);
904 #define w3m_halfdump (w3m_dump & DUMP_HALFDUMP)
905 global int w3m_halfload init(FALSE);
906 global Str header_string init(NULL);
907 global int override_content_type init(FALSE);
908
909 #ifdef USE_COLOR
910 global int useColor init(TRUE);
911 global int basic_color init(8); /* don't change */
912 global int anchor_color init(4);        /* blue  */
913 global int image_color init(2); /* green */
914 global int form_color init(1);  /* red   */
915 #ifdef USE_BG_COLOR
916 global int bg_color init(8);    /* don't change */
917 global int mark_color init(6);  /* cyan */
918 #endif                          /* USE_BG_COLOR */
919 global int useActiveColor init(FALSE);
920 global int active_color init(6);        /* cyan */
921 global int useVisitedColor init(FALSE);
922 global int visited_color init(5);       /* magenta  */
923 #endif                          /* USE_COLOR */
924 global int confirm_on_quit init(TRUE);
925 #ifdef USE_MARK
926 global int use_mark init(FALSE);
927 #endif
928 global int emacs_like_lineedit init(FALSE);
929 global int vi_prec_num init(FALSE);
930 global int label_topline init(FALSE);
931 global int nextpage_topline init(FALSE);
932 global char *displayTitleTerm init(NULL);
933 global int displayLink init(FALSE);
934 global int displayLineInfo init(FALSE);
935 global int DecodeURL init(FALSE);
936 global int retryAsHttp init(TRUE);
937 global int showLineNum init(FALSE);
938 global int show_srch_str init(TRUE);
939 #ifdef USE_IMAGE
940 global char *Imgdisplay init(IMGDISPLAY);
941 global int activeImage init(FALSE);
942 global int displayImage init(TRUE);
943 global int autoImage init(TRUE);
944 global int useExtImageViewer init(TRUE);
945 global int maxLoadImage init(4);
946 global int image_map_list init(TRUE);
947 #else
948 global int displayImage init(FALSE);    /* XXX: emacs-w3m use display_image=off */
949 #endif
950 global char *Editor init(DEF_EDITOR);
951 #ifdef USE_W3MMAILER
952 global char *Mailer init(NULL);
953 #else
954 global char *Mailer init(DEF_MAILER);
955 #endif
956 global char *ExtBrowser init(DEF_EXT_BROWSER);
957 global char *ExtBrowser2 init(NULL);
958 global char *ExtBrowser3 init(NULL);
959 global int BackgroundExtViewer init(TRUE);
960 global int disable_secret_security_check init(FALSE);
961 global char *passwd_file init(PASSWD_FILE);
962 global char *pre_form_file init(PRE_FORM_FILE);
963 global char *ftppasswd init(NULL);
964 global int ftppass_hostnamegen init(TRUE);
965 global int do_download init(FALSE);
966 #ifdef USE_IMAGE
967 global char *image_source init(NULL);
968 #endif
969 global char *UserAgent init(NULL);
970 global int NoSendReferer init(FALSE);
971 global char *AcceptLang init(NULL);
972 global char *AcceptEncoding init(NULL);
973 global char *AcceptMedia init(NULL);
974 global int WrapDefault init(FALSE);
975 global int IgnoreCase init(TRUE);
976 global int WrapSearch init(FALSE);
977 global int squeezeBlankLine init(FALSE);
978 global char *BookmarkFile init(NULL);
979 global char *pauth init(NULL);
980 global Str proxy_auth_cookie init(NULL);
981 global int UseExternalDirBuffer init(TRUE);
982 global char *DirBufferCommand init("file:///$LIB/dirlist" CGI_EXTENSION);
983 #ifdef USE_DICT
984 global int UseDictCommand init(FALSE);
985 global char *DictCommand init("file:///$LIB/w3mdict" CGI_EXTENSION);
986 #endif                          /* USE_DICT */
987 global int ignore_null_img_alt init(TRUE);
988 #define DISPLAY_INS_DEL_SIMPLE  0
989 #define DISPLAY_INS_DEL_NORMAL  1
990 #define DISPLAY_INS_DEL_FONTIFY 2
991 global int displayInsDel init(DISPLAY_INS_DEL_NORMAL);
992 global int FoldTextarea init(FALSE);
993 global int FoldLine init(FALSE);
994 #define DEFAULT_URL_EMPTY       0
995 #define DEFAULT_URL_CURRENT     1
996 #define DEFAULT_URL_LINK        2
997 global int DefaultURLString init(DEFAULT_URL_EMPTY);
998 global int MarkAllPages init(FALSE);
999
1000 #ifdef USE_MIGEMO
1001 global int use_migemo init(FALSE);
1002 global int migemo_active init(0);
1003 global char *migemo_command init(DEF_MIGEMO_COMMAND);
1004 #endif                          /* USE_MIGEMO */
1005
1006 global struct auth_cookie *Auth_cookie init(NULL);
1007 #ifdef USE_COOKIE
1008 global struct cookie *First_cookie init(NULL);
1009 #endif                          /* USE_COOKIE */
1010
1011 global char *mailcap_files init(USER_MAILCAP ", " SYS_MAILCAP);
1012 global char *mimetypes_files init(USER_MIMETYPES ", " SYS_MIMETYPES);
1013 #ifdef USE_EXTERNAL_URI_LOADER
1014 global char *urimethodmap_files init(USER_URIMETHODMAP ", " SYS_URIMETHODMAP);
1015 #endif
1016
1017 global TextList *fileToDelete;
1018
1019 extern Hist *LoadHist;
1020 extern Hist *SaveHist;
1021 extern Hist *URLHist;
1022 extern Hist *ShellHist;
1023 extern Hist *TextHist;
1024 #ifdef USE_HISTORY
1025 global int UseHistory init(TRUE);
1026 global int URLHistSize init(100);
1027 global int SaveURLHist init(TRUE);
1028 #endif                          /* USE_HISTORY */
1029 global int multicolList init(FALSE);
1030
1031 #ifdef USE_M17N
1032 global wc_ces InnerCharset init(WC_CES_WTF);    /* Don't change */
1033 global wc_ces DisplayCharset init(DISPLAY_CHARSET);
1034 global wc_ces DocumentCharset init(DOCUMENT_CHARSET);
1035 global wc_ces SystemCharset init(SYSTEM_CHARSET);
1036 global wc_ces BookmarkCharset init(SYSTEM_CHARSET);
1037 global char ExtHalfdump init(FALSE);
1038 global char FollowLocale init(TRUE);
1039 global char UseContentCharset init(TRUE);
1040 global char SearchConv init(TRUE);
1041 #define Str_conv_from_system(x) wc_Str_conv((x), SystemCharset, InnerCharset)
1042 #define Str_conv_to_system(x) wc_Str_conv_strict((x), InnerCharset, SystemCharset)
1043 #define Str_conv_to_halfdump(x) (ExtHalfdump ? wc_Str_conv((x), InnerCharset, DisplayCharset) : (x))
1044 #define conv_from_system(x) wc_conv((x), SystemCharset, InnerCharset)->ptr
1045 #define conv_to_system(x) wc_conv_strict((x), InnerCharset, SystemCharset)->ptr
1046 #define url_quote_conv(x,c) url_quote(wc_conv_strict((x), InnerCharset, (c))->ptr)
1047 #else
1048 #define Str_conv_from_system(x) (x)
1049 #define Str_conv_to_system(x) (x)
1050 #define Str_conv_to_halfdump(x) (x)
1051 #define conv_from_system(x) (x)
1052 #define conv_to_system(x) (x)
1053 #define url_quote_conv(x,c) url_quote(x)
1054 #define wc_Str_conv(x,charset0,charset1) (x)
1055 #define wc_Str_conv_strict(x,charset0,charset1) (x)
1056 #endif
1057 global char UseAltEntity init(TRUE);
1058 global char UseGraphicChar init(FALSE);
1059 extern char *graph_symbol[];
1060 extern char *graph2_symbol[];
1061 extern int symbol_width;
1062 extern int symbol_width0;
1063 #define N_GRAPH_SYMBOL 32
1064 #define SYMBOL_BASE 0x20
1065 global int no_rc_dir init(FALSE);
1066 global char *rc_dir init(NULL);
1067 global char *tmp_dir;
1068 global char *config_file init(NULL);
1069
1070 #ifdef USE_MOUSE
1071 global int use_mouse init(TRUE);
1072 extern int mouseActive;
1073 global int reverse_mouse init(FALSE);
1074 global int relative_wheel_scroll init(FALSE);
1075 global int fixed_wheel_scroll_count init(5);
1076 global int relative_wheel_scroll_ratio init(30);
1077 typedef struct _MouseActionMap {
1078     void (*func) ();
1079     char *data;
1080 } MouseActionMap;
1081 typedef struct _MouseAction {
1082     char *menu_str;
1083     char *lastline_str;
1084     int menu_width;
1085     int lastline_width;
1086     int in_action;
1087     int cursorX;
1088     int cursorY;
1089     MouseActionMap default_map[3];
1090     MouseActionMap anchor_map[3];
1091     MouseActionMap active_map[3];
1092     MouseActionMap tab_map[3];
1093     MouseActionMap *menu_map[3];
1094     MouseActionMap *lastline_map[3];
1095 } MouseAction;
1096 global MouseAction mouse_action;
1097 #define LIMIT_MOUSE_MENU 100
1098 #endif                          /* USE_MOUSE */
1099
1100 #ifdef USE_COOKIE
1101 global int default_use_cookie init(TRUE);
1102 global int use_cookie init(FALSE);
1103 global int show_cookie init(TRUE);
1104 global int accept_cookie init(FALSE);
1105 #define ACCEPT_BAD_COOKIE_DISCARD       0
1106 #define ACCEPT_BAD_COOKIE_ACCEPT        1
1107 #define ACCEPT_BAD_COOKIE_ASK           2
1108 global int accept_bad_cookie init(ACCEPT_BAD_COOKIE_DISCARD);
1109 global char *cookie_reject_domains init(NULL);
1110 global char *cookie_accept_domains init(NULL);
1111 global TextList *Cookie_reject_domains;
1112 global TextList *Cookie_accept_domains;
1113 #endif                          /* USE_COOKIE */
1114
1115 #ifdef USE_IMAGE
1116 global int view_unseenobject init(FALSE);
1117 #else
1118 global int view_unseenobject init(TRUE);
1119 #endif
1120
1121 #if defined(USE_SSL) && defined(USE_SSL_VERIFY)
1122 global int ssl_verify_server init(FALSE);
1123 global char *ssl_cert_file init(NULL);
1124 global char *ssl_key_file init(NULL);
1125 global char *ssl_ca_path init(NULL);
1126 global char *ssl_ca_file init(NULL);
1127 global int ssl_path_modified init(FALSE);
1128 #endif                          /* defined(USE_SSL) &&
1129                                  * defined(USE_SSL_VERIFY) */
1130 #ifdef USE_SSL
1131 global char *ssl_forbid_method init(NULL);
1132 #endif
1133
1134 global int is_redisplay init(FALSE);
1135 global int clear_buffer init(TRUE);
1136 global double pixel_per_char init(DEFAULT_PIXEL_PER_CHAR);
1137 global int set_pixel_per_char init(FALSE);
1138 #ifdef USE_IMAGE
1139 global double pixel_per_line init(DEFAULT_PIXEL_PER_LINE);
1140 global int set_pixel_per_line init(FALSE);
1141 global double image_scale init(100);
1142 #endif
1143 global int use_lessopen init(FALSE);
1144
1145 global char *keymap_file init(KEYMAP_FILE);
1146
1147 #ifdef USE_M17N
1148 #define get_mctype(c) ((Lineprop)wtf_type((wc_uchar *)(c)) << 8)
1149 #define get_mclen(c) wtf_len1((wc_uchar *)(c))
1150 #define get_mcwidth(c) wtf_width((wc_uchar *)(c))
1151 #define get_strwidth(c) wtf_strwidth((wc_uchar *)(c))
1152 #define get_Str_strwidth(c) wtf_strwidth((wc_uchar *)((c)->ptr))
1153 #else
1154 #define get_mctype(c) (IS_CNTRL(*(c)) ? PC_CTRL : PC_ASCII)
1155 #define get_mclen(c) 1
1156 #define get_mcwidth(c) 1
1157 #define get_strwidth(c) strlen(c)
1158 #define get_Str_strwidth(c) ((c)->length)
1159 #endif
1160
1161 global int FollowRedirection init(10);
1162
1163 global int w3m_backend init(FALSE);
1164 global TextLineList *backend_halfdump_buf;
1165 global TextList *backend_batch_commands init(NULL);
1166 int backend(void);
1167 extern void deleteFiles(void);
1168 void w3m_exit(int i);
1169
1170 #ifdef USE_ALARM
1171 #define AL_UNSET         0
1172 #define AL_EXPLICIT      1
1173 #define AL_IMPLICIT      2
1174 #define AL_IMPLICIT_ONCE 3
1175
1176 typedef struct _AlarmEvent {
1177     int sec;
1178     short status;
1179     int cmd;
1180     void *data;
1181 } AlarmEvent;
1182 #endif
1183
1184 /* 
1185  * Externals
1186  */
1187
1188 #include "table.h"
1189 #include "proto.h"
1190
1191 #endif                          /* not FM_H */