~ubuntu-branches/ubuntu/karmic/edbrowse/karmic

« back to all changes in this revision

Viewing changes to src/eb.h

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2008-04-09 18:55:23 UTC
  • mfrom: (1.1.4 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080409185523-dqokcloumyn1ibn4
Tags: 3.3.4-1
* New upstream version (3.3.4).
 - Convert between iso8859-1 and utf-8 on the fly.
 - Support reading of pdf using pdftohtml.
 - French translation of html documentation.
 - Old html documentation renamed to usersguide.
 - Additional documentation on philosophy.
* debian/control:
 - Changed homepage to sourcefource site.
 - Moved homepage from description to its own field.
 - Added "poppler-utils | xpdf-utils" to Recommends.
 - Added "www-browser", "mail-reader" and "editor" to Provides. 
 - Removed "XS-" from Vcs-Svn tag.
 - Standards-Version: 3.7.3
* debian/docs: Added new documentation files
  from "doc/" subdirectory.
* debian/watch: Updated to use sourceforge site.
* debian/edbrowse.doc-base:
  - Changed name of upstream provided html documentation from
    "ebdoc.html" to "usersguide.html".
  - Changed section from "net" to "Network/Web Browsing".
* debian/install: Compiled binary is now in "src/".

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* eb.h
 
2
 * Copyright (c) Karl Dahlke, 2008
 
3
 * This file is part of the edbrowse project, released under GPL.
 
4
 */
 
5
 
 
6
#ifndef EB_H
 
7
#define EB_H 1
 
8
 
 
9
/* the symbol DOSLIKE is used to conditionally compile those constructs
 
10
 * that are common to DOS and NT, but not typical of Unix. */
 
11
#ifdef MSDOS
 
12
#define DOSLIKE 1
 
13
#endif
 
14
#ifdef _WIN32
 
15
#define DOSLIKE 1
 
16
#endif
 
17
 
 
18
/* System V or system BSD? */
 
19
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD)
 
20
#define SYSBSD 1
 
21
#endif
 
22
 
 
23
/* seems like everybody needs these header files */
 
24
#include <sys/types.h>
 
25
#include <ctype.h>
 
26
#include <string.h>
 
27
#include <memory.h>
 
28
#include <stdarg.h>
 
29
#include <stdlib.h>
 
30
#include <stdio.h>
 
31
#include <errno.h>
 
32
#include <fcntl.h>
 
33
#ifdef DOSLIKE
 
34
#include <io.h>
 
35
#else
 
36
#include <unistd.h>
 
37
#endif
 
38
 
 
39
#include "tcp.h"
 
40
 
 
41
#ifndef O_BINARY
 
42
#define O_BINARY 0
 
43
#endif
 
44
#ifndef O_TEXT
 
45
#define O_TEXT 0
 
46
#endif
 
47
#ifndef O_SYNC
 
48
#define O_SYNC 0
 
49
#endif
 
50
 
 
51
/* WARNING:  the following typedef is pseudo-standard in C.
 
52
 * Some systems will define ushort in sys/types.h, others will not.
 
53
 * Unfortunately there is no #define symbol to key on;
 
54
 * no way to conditionally compile the following statement. */
 
55
#ifdef DOSLIKE
 
56
typedef unsigned short ushort;
 
57
typedef unsigned long ulong;
 
58
#endif
 
59
/* sys/types.h defines unsigned char as unchar.  I prefer uchar.
 
60
 * It is consistent with ushort uint and ulong, and doesn't remind
 
61
 * me of the uncola, a char that isn't really a char. */
 
62
typedef unsigned char uchar;
 
63
 
 
64
/* We use uchar for boolean fields. */
 
65
typedef uchar bool;
 
66
#define true 1
 
67
#define false 0
 
68
 
 
69
typedef ushort idNameCode;
 
70
 
 
71
#define stringEqual !strcmp
 
72
 
 
73
/* ctype macros, when you're passing a byte,
 
74
 * and you don't want to worry about whether it's char or uchar.
 
75
 * Call the regular routines when c is an int, from fgetc etc. */
 
76
#define isspaceByte(c) isspace((uchar)c)
 
77
#define isalphaByte(c) isalpha((uchar)c)
 
78
#define isalnumByte(c) isalnum((uchar)c)
 
79
#define islowerByte(c) islower((uchar)c)
 
80
#define isupperByte(c) isupper((uchar)c)
 
81
#define isdigitByte(c) isdigit((uchar)c)
 
82
#define ispunctByte(c) ispunct((uchar)c)
 
83
#define isprintByte(c) isprint((uchar)c)
 
84
 
 
85
/* http encoding, content type, content transfer encoding */
 
86
enum { ENC_PLAIN, ENC_COMPRESS, ENC_GZIP, ENC_URL, ENC_MFD };
 
87
enum { CT_OTHER, CT_TEXT, CT_HTML, CT_RICH, CT_APPLIC, CT_MULTI, CT_ALT };
 
88
enum { CE_7BIT, CE_8BIT, CE_QP, CE_64 };
 
89
 
 
90
/* This program was originally written in perl.
 
91
 * So I got use to perl strings, which admit nulls.
 
92
 * In our case, they will be terminated by newline. */
 
93
typedef uchar *pst;             /* perl string */
 
94
 
 
95
/* A specific nonascii char denotes an html tag
 
96
 * in the rendered html text.
 
97
 * See the comments in bufsub.c for the rationale. */
 
98
#define InternalCodeChar '\2'
 
99
#define InternalCodeCharAlternate '\1'
 
100
 
 
101
/* How long can a regular expression be? */
 
102
#define MAXRE 400
 
103
/* How long can an entered line be? */
 
104
#define MAXTTYLINE 256
 
105
/* Longest line that can take the substitute command */
 
106
#define REPLACELINELEN 50000
 
107
/* How many pages can we fetch, through frames etc. */
 
108
#define MAXFETCH 100
 
109
/* The longest string, in certain contexts. */
 
110
#define MAXSTRLEN 1024
 
111
/* How about user login and password? */
 
112
#define MAXUSERPASS 40
 
113
/* Number of pop3 mail accounts */
 
114
#define MAXACCOUNT 100
 
115
/* Number of mime types */
 
116
#define MAXMIME 40
 
117
/* number of db tables */
 
118
#define MAXDBT 100
 
119
#define MAXTCOLS 20
 
120
/* How many sessions open concurrently */
 
121
#define MAXSESSION 1000
 
122
/* Allocation increment for a growing string, that we don't expect
 
123
 * to get too large.  This must be a power of 2. */
 
124
#define ALLOC_GR        0x100
 
125
 
 
126
/* alignments */
 
127
#define AL_LEFT         0
 
128
#define AL_CENTER       1
 
129
#define AL_RIGHT        2
 
130
#define AL_BLOCK        3
 
131
#define AL_NO           4
 
132
 
 
133
/* left and top borders for dialog box, stubs. */
 
134
#define DIALOG_LB 1
 
135
#define DIALOG_TB 1
 
136
#define COLOR_DIALOG_TEXT 0
 
137
#define G_BFU_FONT_SIZE 0
 
138
 
 
139
/* .trash is small or capital t, on different systems */
 
140
#ifndef TRASHDIR
 
141
#define TRASHDIR ".Trash"
 
142
#endif
 
143
 
 
144
/* the version of edbrowse */
 
145
extern const char *version;
 
146
extern const char eol[];        /* internet end of line */
 
147
extern char EMPTYSTRING[];      /* use this whenever you would use "" */
 
148
 
 
149
/* Here are the strings you can send out to identify this browser.
 
150
 * Most of the time we will send out the first string, edbrowse-2.15.3.
 
151
 * But sometimes we have to lie.
 
152
 * When you deal with clickbank, for instance, they won't let you in the
 
153
 * door unless you are one of three approved browsers.
 
154
 * I've written to them about this particular flavor of stupidity,
 
155
 * but they obviously don't care.  So lie!
 
156
 * Tell them you're Explorer, and walk right in.
 
157
 * Anyways, this array holds up to 10 user agent strings. */
 
158
extern char *userAgents[10], *currentAgent;
 
159
 
 
160
struct MACCOUNT {               /* pop3 account */
 
161
    char *login, *password, *from, *reply;
 
162
    char *inurl, *outurl;
 
163
    int inport, outport;
 
164
    bool inssl, outssl;
 
165
};
 
166
 
 
167
struct MIMETYPE {
 
168
    char *type, *desc;
 
169
    char *suffix, *prot, *program;
 
170
    bool stream;
 
171
};
 
172
 
 
173
struct DBTABLE {
 
174
    char *name, *shortname;
 
175
    char *cols[MAXTCOLS];
 
176
    char ncols;
 
177
    char key1, key2;
 
178
    char *types;
 
179
};
 
180
 
 
181
/* various globals */
 
182
extern int debugLevel;          /* 0 to 9 */
 
183
extern int webTimeout, mailTimeout;
 
184
extern int browseLine;          /* line number, for error reporting */
 
185
extern bool ismc;               /* Is the program running as a mail client? */
 
186
extern bool cons_utf8;          /* does the console expect utf8? */
 
187
extern bool iuConvert;          /* perform iso utf8 conversions automatically */
 
188
extern bool zapMail;            /* just get rid of the mail */
 
189
extern bool js_redirects;       /* window.location = new_url */
 
190
extern uchar browseLocal;       /* browsing a local file */
 
191
extern bool parsePage;          /* parsing the html page, and any java therein */
 
192
extern bool htmlAttrVal_nl;     /* allow nl in the attribute of an html tag */
 
193
extern bool unformatMail;       /* suppress formatting */
 
194
extern bool passMail;           /* pass mail across the filters */
 
195
extern bool errorExit;          /* exit on any error, for scripting purposes */
 
196
extern bool isInteractive;
 
197
extern volatile bool intFlag;   /* set this when interrupt signal is caught */
 
198
extern bool binaryDetect;
 
199
extern bool listNA;             /* list nonascii chars */
 
200
extern bool inInput;            /* reading line from standard in */
 
201
extern int fileSize;            /* when reading/writing files */
 
202
extern int maxFileSize;         /* max size of an editable file */
 
203
extern int mssock;              /* mail server socket */
 
204
extern int hcode;               /* http code, like 404 file not found */
 
205
extern char herror[];           /* html error */
 
206
extern char errorMsg[];         /* generated error message */
 
207
extern char serverLine[MAXTTYLINE];     /* lines to and from the mail server */
 
208
extern void *jcx;               /* javascript context */
 
209
extern void *jwin;              /* javascript window object */
 
210
extern void *jdoc;              /* javascript document object */
 
211
extern void *jwloc;             /* javascript window.location */
 
212
extern void *jdloc;             /* javascript document.location */
 
213
extern int maxAccount;          /* how many email accounts specified */
 
214
extern int localAccount;        /* this is the smtp server for outgoing mail */
 
215
extern char *mailDir;           /* move to this directory when fetching mail */
 
216
extern struct MACCOUNT accounts[];      /* all the email accounts */
 
217
extern int maxMime;             /* how many mime types specified */
 
218
extern struct MIMETYPE mimetypes[];
 
219
extern char *dbarea, *dblogin, *dbpw;   /* to log into the database */
 
220
extern char *proxy_host;
 
221
extern int proxy_port;
 
222
extern bool caseInsensitive, searchStringsAll;
 
223
extern bool textAreaDosNewlines;        /* when transmitting a textarea */
 
224
extern bool undoable;           /* an undoable operation is taking place */
 
225
extern bool allowRedirection;   /* from http code 301, or http refresh */
 
226
extern bool sendReferrer;       /* in the http header */
 
227
extern bool allowJS;            /* javascript on */
 
228
extern bool helpMessagesOn;     /* no need to type h */
 
229
extern char ftpMode;
 
230
extern bool showHiddenFiles;    /* during directory scan */
 
231
extern uchar dirWrite;          /* directory write mode, e.g. rename files */
 
232
extern uchar endMarks;          /* do we print ^ $ at the start and end of lines? */
 
233
extern int context;             /* which session (buffer) are we in? */
 
234
extern uchar linePending[];
 
235
extern char *changeFileName;
 
236
extern char *addressFile;       /* your address book */
 
237
extern char *ipbFile;           /* file holding ip blacklist */
 
238
extern char *serverData;
 
239
extern int serverDataLen;
 
240
extern char replaceLine[];
 
241
extern char *currentReferrer;
 
242
extern char *home;              /* home directory */
 
243
extern char *recycleBin;        /* holds deleted files */
 
244
extern char *configFile, *sigFile;
 
245
extern char *cookieFile;        /* persistent cookies */
 
246
extern char *spamCan;           /* dump spam emails */
 
247
extern char *edbrowseTempFile;
 
248
extern char *edbrowseTempPDF;
 
249
extern char *edbrowseTempHTML;
 
250
 
 
251
/* Ok, this is kinda simple and stupid.
 
252
 * Every line in every window in every session is a string, without the
 
253
 * newline, and all these strings are managed by an array of pointers.
 
254
 * So your particular buffer may have 3 lines in it,
 
255
 * and these are represented internally by three numbers, 12 29 and 83.
 
256
 * So the text is textLines[12], textLines[29], textLines[83].
 
257
 * Now, if you copy a line of text, I actually copy the string.
 
258
 * This is a waste I suppose, but then I don't have to worry about
 
259
 * what happens if you edit one line and not the other.
 
260
 * They're already separate strings, so we're ok. */
 
261
extern pst *textLines;
 
262
extern int textLinesMax, textLinesCount;        /* size of textLines array */
 
263
 
 
264
/* If a file has 30 lines, it is represented by 30 numbers,
 
265
 * indexes into textLines[] above.
 
266
 * Should we use an array of numbers, or a string of numbers
 
267
 * represented by decimal digits?
 
268
 * Both are painful, in different ways.
 
269
 * Consider inserting a block of text, a very common operation.
 
270
 * In a list, we would have to slide all the following numbers down.
 
271
 * Granted, that's better than moving all those lines of text,
 
272
 * but it's still a pain to program, and somewhat inefficient.
 
273
 * If we use strings, we take the original string of numbers,
 
274
 * break it at the insert point, and make a new string
 
275
 * by concatenating these two pieces with the new block.
 
276
 * The same issues arise when deleting text near the top of a file.
 
277
 * This and other considerations push me towards strings.
 
278
 * I currently use 6 characters for a line number,
 
279
 * a seventh for the g// flag.
 
280
 * 8th is reserved,
 
281
 * and 9 and 10 hold the directory suffix.
 
282
 * You know, the slash that we put on the end of a directory,
 
283
 * or the | on the end of a fifo etc.
 
284
 * Thus the following definitions. */
 
285
#define LNMAX 1000000
 
286
#define LNWIDTH 10
 
287
#define LNSPACE "          "
 
288
#define LNFORMAT "%06d    "
 
289
 
 
290
struct listHead {
 
291
    void *next;
 
292
    void *prev;
 
293
};
 
294
 
 
295
/* Macros to loop through the items in a list. */
 
296
#define foreach(e,l) for((e)=(l).next; \
 
297
(e) != (void*)&(l); \
 
298
(e) = ((struct listHead *)e)->next)
 
299
#define foreachback(e,l) for((e)=(l).prev; \
 
300
(e) != (void*)&(l); \
 
301
(e) = ((struct listHead *)e)->prev)
 
302
 
 
303
/* an edbrowse window */
 
304
struct ebWindow {
 
305
/* windows stack up as you open new files or follow hyperlinks.
 
306
 * Use the back command to pop the stack.
 
307
 * The back command follows this link, which is 0 if you are at the top. */
 
308
    struct ebWindow *prev;
 
309
/* This is right out of the source for ed.  Current and last line numbers. */
 
310
    int dot, dol;
 
311
/* remember dot and dol for the raw text, when in browse mode */
 
312
    int r_dot, r_dol;
 
313
    char *fileName;             /* name of file or url */
 
314
    char *referrer;
 
315
    char *baseDirName;          /* when scanning a directory */
 
316
    char *ft, *fd, *fk;         /* title, description, keywords */
 
317
    char *mailInfo;
 
318
    char lhs[MAXRE], rhs[MAXRE];        /* remembered substitution strings */
 
319
    char *map;                  /* indexes into textLines[] */
 
320
    char *r_map;
 
321
/* The labels that you set with the k command, and access via 'x.
 
322
 * Basically, that's 26 line numbers.
 
323
 * Number 0 means the label is not set. */
 
324
    int labels[26], r_labels[26];
 
325
/* Yeah, these could be bit fields in the structure :1; but who cares. */
 
326
    bool lhs_yes, rhs_yes;
 
327
    bool binMode;               /* binary file */
 
328
    bool nlMode;                /* newline at the end */
 
329
    bool rnlMode;
 
330
/* Two text modes; these are incompatible with binMode */
 
331
    bool utf8Mode;
 
332
    bool iso8859Mode;
 
333
    bool browseMode;            /* browsing html */
 
334
    bool changeMode;            /* something has changed in this file */
 
335
    bool dirMode;               /* directory mode */
 
336
    bool firstOpMode;           /* first change has been made, undo is possible */
 
337
    bool jsdead;                /* javascript is dead, for this window */
 
338
    bool sqlMode;               /* accessing a table */
 
339
    char *dw;                   /* document.write string */
 
340
    int dw_l;                   /* length of the above */
 
341
    void *tags;                 /* array of html tags, when browsing */
 
342
    IP32bit *iplist;            /* ip addresses referenced by this page */
 
343
    void *jsc;                  /* js context, if in browse mode, and running javascript */
 
344
    struct DBTABLE *table;      /* if in sqlMode */
 
345
};
 
346
extern struct ebWindow *cw;     /* current window */
 
347
 
 
348
/* An edit session */
 
349
struct ebSession {
 
350
    struct ebWindow *fw, *lw;   /* first window, last window */
 
351
};
 
352
extern struct ebSession sessionList[];
 
353
extern struct ebSession *cs;    /* current session */
 
354
 
 
355
 
 
356
/* function prototypes */
 
357
#include "eb.p"
 
358
 
 
359
/* Symbolic constants for language independent messages */
 
360
#include "messages.h"
 
361
 
 
362
#endif