| 1 |
/************************************************************************** |
| 2 |
* This program is Copyright (C) 1986-2002 by Jonathan Payne. JOVE is * |
| 3 |
* provided by Jonathan and Jovehacks without charge and without * |
| 4 |
* warranty. You may copy, modify, and/or distribute JOVE, provided that * |
| 5 |
* this notice is included in all the source files and documentation. * |
| 6 |
**************************************************************************/ |
| 7 |
|
| 8 |
/* maximum length of a line (including '\0'). Currently cannot |
| 9 |
* be larger than a logical disk block. |
| 10 |
*/ |
| 11 |
#define LBSIZE JBUFSIZ |
| 12 |
|
| 13 |
/* buffer types */ |
| 14 |
#define B_SCRATCH 1 /* for internal things, e.g. minibuffer ... */ |
| 15 |
#define B_FILE 2 /* normal file (we auto-save these.) */ |
| 16 |
#define B_PROCESS 3 /* unix process output in this buffer */ |
| 17 |
|
| 18 |
/* major modes (order must match entries in disp.c:majname[]) */ |
| 19 |
#define FUNDAMENTAL 0 /* Fundamental mode */ |
| 20 |
#define TEXTMODE 1 /* Text mode */ |
| 21 |
#define CMODE 2 /* C mode */ |
| 22 |
#ifdef LISP |
| 23 |
# define LISPMODE 3 /* Lisp mode */ |
| 24 |
# define NMAJORS 4 |
| 25 |
#else |
| 26 |
# define NMAJORS 3 |
| 27 |
#endif |
| 28 |
|
| 29 |
#define MajorMode(x) (curbuf->b_major == (x)) |
| 30 |
#define SetMajor(x) { curbuf->b_major = (x); UpdModLine = YES; } |
| 31 |
|
| 32 |
/* minor modes (order must match entries in disp.c:minname[]) */ |
| 33 |
#define Fill (1 << 0) /* text fill mode */ |
| 34 |
#define Abbrev (1 << 1) /* abbrev mode */ |
| 35 |
#define OverWrite (1 << 2) /* over write mode */ |
| 36 |
#define Indent (1 << 3) /* indent same as previous line after return */ |
| 37 |
#define BReadOnly (1 << 4) /* buffer is read only */ |
| 38 |
#define ShowMatch (1 << 5) /* paren flash mode */ |
| 39 |
#ifdef IPROCS |
| 40 |
/* buffer is running DBX process -- track source references */ |
| 41 |
# define DbxMode (1 << 6) |
| 42 |
#endif |
| 43 |
|
| 44 |
#define BufMinorMode(b, x) (((b)->b_minor & (x)) != 0) |
| 45 |
#define MinorMode(x) BufMinorMode(curbuf, (x)) |
| 46 |
|
| 47 |
/* global line scratch buffers */ |
| 48 |
extern char genbuf[LBSIZE], /* scratch pad points at s_genbuf (see main()) */ |
| 49 |
linebuf[LBSIZE], /* points at s_linebuf */ |
| 50 |
iobuff[LBSIZE]; /* for file reading ... points at s_iobuff */ |
| 51 |
|
| 52 |
/* typedef struct line *LinePtr in jove.h */ |
| 53 |
|
| 54 |
struct line { |
| 55 |
LinePtr l_prev, /* pointer to prev */ |
| 56 |
l_next; /* pointer to next */ |
| 57 |
daddr l_dline; /* pointer to disk location */ |
| 58 |
}; |
| 59 |
|
| 60 |
/* typedef struct mark Mark in jove.h */ |
| 61 |
|
| 62 |
struct mark { |
| 63 |
LinePtr m_line; |
| 64 |
int m_char; |
| 65 |
jbool m_big_delete; /* mark was within the range of a multi-line delete */ |
| 66 |
Mark *m_next; /* list of marks */ |
| 67 |
}; |
| 68 |
|
| 69 |
/* typedef struct buffer Buffer in jove.h */ |
| 70 |
|
| 71 |
struct buffer { |
| 72 |
#ifdef MAC |
| 73 |
int Type; /* kludge... to look like a data_obj */ |
| 74 |
char *Name; /* Name will not be used */ |
| 75 |
#endif |
| 76 |
Buffer *b_next; /* next buffer in chain */ |
| 77 |
char *b_name; /* buffer name */ |
| 78 |
char *b_fname; /* file name associated with buffer */ |
| 79 |
#ifdef USE_INO |
| 80 |
/* unique identification of file */ |
| 81 |
dev_t b_dev; /* device of file name. */ |
| 82 |
ino_t b_ino; /* inode of file name */ |
| 83 |
#endif |
| 84 |
time_t b_mtime; /* last modify time ... |
| 85 |
to detect two people writing |
| 86 |
to the same file */ |
| 87 |
LinePtr b_first, /* pointer to first line in list */ |
| 88 |
b_dot, /* current line */ |
| 89 |
b_last; /* last line in list */ |
| 90 |
int b_char; /* current character in line */ |
| 91 |
|
| 92 |
#define NMARKS 8 /* number of marks in the ring */ |
| 93 |
|
| 94 |
Mark *b_markring[NMARKS], /* new marks are pushed here */ |
| 95 |
#define b_curmark(b) ((b)->b_markring[(b)->b_themark]) |
| 96 |
#define curmark b_curmark(curbuf) |
| 97 |
*b_marks; /* all the marks for this buffer */ |
| 98 |
int b_themark, /* current mark (in b_markring) */ |
| 99 |
b_type; /* file, scratch, process, iprocess */ |
| 100 |
char b_ntbf, /* (jbool) needs to be found when we |
| 101 |
first select? */ |
| 102 |
b_modified, /* (jbool) is the buffer modified? */ |
| 103 |
b_diverged; /* (jbool) has the underlying file been changed behind our back? */ |
| 104 |
int b_major; /* major mode */ |
| 105 |
unsigned b_minor; /* and minor mode */ |
| 106 |
struct keymap *b_map; /* local bindings (if any) */ |
| 107 |
#ifdef IPROCS |
| 108 |
struct process *b_process; /* process we're attached to */ |
| 109 |
#endif |
| 110 |
}; |
| 111 |
|
| 112 |
extern Buffer |
| 113 |
*world, /* first buffer */ |
| 114 |
*curbuf, /* pointer into world for current buffer */ |
| 115 |
*lastbuf, /* Last buffer we were in so we have a default |
| 116 |
buffer during a select buffer. */ |
| 117 |
*perr_buf; /* Buffer with error messages */ |
| 118 |
|
| 119 |
#define curline (curbuf->b_dot) |
| 120 |
#define curchar (curbuf->b_char) |
| 121 |
|
| 122 |
/* typedef struct position Bufpos in jove.h */ |
| 123 |
|
| 124 |
struct position { |
| 125 |
LinePtr p_line; |
| 126 |
int p_char; |
| 127 |
}; |
| 128 |
|
| 129 |
extern jbool |
| 130 |
valid_bp(Buffer *bp); |
| 131 |
|
| 132 |
extern Buffer |
| 133 |
*buf_exists(const char *name), |
| 134 |
*do_find(Window *w, char *fname, jbool force, jbool do_macros), |
| 135 |
*do_select(Window *w, const char *name), |
| 136 |
*do_stat(const char *name, Buffer *target, int flags); |
| 137 |
|
| 138 |
/* flags to do_stat */ |
| 139 |
#define DS_NONE 0 |
| 140 |
#define DS_SET 1 /* set target buffers stat fields */ |
| 141 |
#define DS_REUSE 2 /* reuse result of last stat */ |
| 142 |
#define DS_DIR 4 /* directory OK as result */ |
| 143 |
|
| 144 |
extern jbool |
| 145 |
was_dir, /* do_stat found a directory */ |
| 146 |
was_file; /* do_stat found a (plain) file */ |
| 147 |
|
| 148 |
extern const char |
| 149 |
*ask_buf(Buffer *def, int flags); |
| 150 |
|
| 151 |
struct macro; /* forward declaration preventing prototype scoping */ |
| 152 |
|
| 153 |
extern void |
| 154 |
TogMinor(int bit), |
| 155 |
buf_clear(Buffer *b), |
| 156 |
setfname(Buffer *b, const char *name), |
| 157 |
SetABuf(Buffer *b), |
| 158 |
SetBuf(Buffer *newbuf), |
| 159 |
buf_init(void); |
| 160 |
|
| 161 |
extern LinePtr |
| 162 |
lastline(LinePtr lp), |
| 163 |
listput(Buffer *buf, LinePtr after), |
| 164 |
next_line(LinePtr line, long num), |
| 165 |
prev_line(LinePtr line, long num); |
| 166 |
|
| 167 |
/* Commands: */ |
| 168 |
|
| 169 |
extern void |
| 170 |
BufErase(void), |
| 171 |
BufKill(void), |
| 172 |
BufList(void), |
| 173 |
BufSelect(void), |
| 174 |
FindFile(void), |
| 175 |
KillSome(void), |
| 176 |
ReNamBuf(void); |
| 177 |
|
| 178 |
extern void |
| 179 |
Buf1Select(void), |
| 180 |
Buf2Select(void), |
| 181 |
Buf3Select(void), |
| 182 |
Buf4Select(void), |
| 183 |
Buf5Select(void), |
| 184 |
Buf6Select(void), |
| 185 |
Buf7Select(void), |
| 186 |
Buf8Select(void), |
| 187 |
Buf9Select(void), |
| 188 |
Buf10Select(void); |