-
Notifications
You must be signed in to change notification settings - Fork 1
/
z.h
233 lines (190 loc) · 5.44 KB
/
z.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/* Copyright (C) 1988-2018 Sean MacLennan */
#ifndef _Z_H_
#define _Z_H_
#ifdef __STRICT_ANSI__
#define _XOPEN_SOURCE
#define _POSIX_SOURCE
#define _SVID_SOURCE
#define _DEFAULT_SOURCE
#endif
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <dirent.h>
#include <strings.h> /* needed for c11 */
#include <sys/stat.h>
#include "config.h"
struct zbuff;
#include "buff.h"
#include "reg.h"
#include "vars.h"
#include "funcs.h"
#include "keys.h"
#include "calc.h"
#include "tinit.h"
/** @defgroup zedit Zedit functions
* The core buffer routines including the mark functions.
*/
/** @addtogroup zedit
* @{
*/
#define ZSTR "Zedit"
#define VERSION "6.3"
#define INVALID -1
/* the first three must follow: (define + 1) % 4 = 0 */
#define BUFNAMMAX 31 /* max buffer name */
#define PATHMAX 255 /* max file name */
#define STRMAX 79 /* string max */
#define BACKWARD 0 /* go forwards */
#define FORWARD 1 /* go backwards */
#define REGEXP 2 /* reg exp search */
#define QUERY 3 /* query replace */
#define AGAIN -1 /* go again */
#define AGAIN_WRAP 128 /* wrap and go again */
/** Huge file size. If HUGE_FILES is defined, files bigger than
* HUGE_SIZE will be read on demand.
*/
#define HUGE_SIZE (2UL << 30)
/*
* BUFFER MODES
*/
/* minor modes - 0 to all allowed */
#define OVERWRITE 0x0001
#define EXACT 0x0002
#define VIEW 0x0004
/* majour modes - only one allowed */
#define NORMAL 0x0100
#define CMODE 0x0200
#define TXTMODE 0x0400
#define SHMODE 0x0800
/* super modes - 0 to all allowed */
#define SYSBUFF 0x2000
/* File modes in buff.h */
/* #define COMPRESSED 0x10000 */
/* #define CRLF 0x20000 */
/* some handy macro for buffer modes */
#define MAJORMODE 0x1f00
#define PROGMODE (CMODE | SHMODE)
/* System buffer names */
#define UNTITLED "NoFile" /* for buffers with no fname */
#define MAINBUFF "*scratch*"
#define HELPBUFF "*help*"
#define SHELLBUFF "*shell*"
#define LISTBUFF "*list*"
#define CONFBUFF "*config*"
#define TAGBUFF "*tags*"
#define LIFEBUFF "*life*"
/* ask return values */
#define BANG 2
#define YES 1
#define NO 0
#define ABORT -1
#define BADCHAR -2
struct cnames {
const char *name;
Byte fnum;
Byte flags;
const char *doc;
};
#define CNAMESIZE sizeof(struct cnames)
/* getplete structs must be aligned */
_Static_assert((sizeof(struct cnames) % sizeof(char *)) == 0,
"cnames not aligned");
struct wdo {
struct wdo *next;
struct zbuff *wbuff; /* buffer window looks on */
struct mark *wpnt; /* saved Point */
struct mark *wmrk; /* saved Mark */
struct mark *wstart; /* screen start */
int umark_set;
int first, last; /* screen line boundries */
int modecol; /* column for modeflags */
int modeflags; /* flags for modeflags */
};
#define foreachwdo(wdo) for (wdo = Whead; wdo; wdo = wdo->next)
#define wheight() (Curwdo->last - Curwdo->first)
extern struct wdo *Curwdo, *Whead;
extern struct zbuff *Curbuff;
extern struct buff *Bbuff;
struct zbuff {
struct zbuff *prev; /**< list of buffers */
struct zbuff *next; /**< list of buffers */
char *bname; /**< buffer name */
char *fname; /**< file associated with buffer */
struct mark *umark; /**< user mark */
struct buff *buff; /**< low-level buffer */
time_t mtime; /**< file modified time */
void *chead; /**< list of comments in file */
void *ctail; /**< list of comments in file */
Byte comchar; /**< single char comment character */
unsigned int bmode; /**< buffer mode */
};
#define foreachbuff(b) for ((b) = Bufflist; (b); (b) = (b)->next)
#define Buff() (*Bbuff->curcptr)
extern char *Home;
extern int Homelen;
extern bool Argp;
extern int Arg; /* must be signed */
extern int InPaw; /* Are we in the Paw window? */
extern char PawStr[]; /* handy string to put text in */
#define PAWSTRLEN (COLMAX + 10)
extern int Pawcol, Pawlen, Pshift;
extern struct zbuff *Paw;
extern int verbose;
extern unsigned int Cmd;
extern int Cmdpushed;
extern struct cnames Cnames[];
extern void (*Cmds[][2])();
extern int Curcmds;
extern Byte Keys[], Lfunc;
extern bool First;
extern int ring_bell;
extern int raw_mode;
extern int text_mode;
#define CMD(n) ((*Cmds[n][Curcmds])())
extern struct zbuff *Bufflist;
extern struct zbuff *Buff_save;
extern struct mark *Sstart;
extern bool Initializing;
extern bool Insearch;
extern int circf;
extern void (*Nextpart)(void);
#define clrpaw() putpaw("")
#define PREFLINE 10
#define CR ('\r')
#define NL ('\n')
/* Zedit specific attributes */
#define T_STANDOUT T_REVERSE
#ifdef TERMCAP
#define T_COMMENT T_BOLD
#else
#define T_COMMENT (T_FG | T_RED)
#endif
#define T_REGION T_REVERSE
void set_last_bufname(struct zbuff *buff);
char *zgetcwd(char *cwd, int len);
/* this is MUCH faster than an isascii isprint pair */
#define ZISPRINT(c) (c >= ' ' && c <= '~')
/* terminal variables */
extern int Prow, Pcol; /* Point row and column */
extern int Colmax, Rowmax; /* Row and column maximums */
extern int Tabsize;
#define ISNL(c) ((c) == '\n')
#define UMARK_SET (Curbuff->umark)
#define NEED_UMARK do { if (!UMARK_SET) { tbell(); return; } } while (0)
#define UMARK (Curbuff->umark) /* Must guarantee umark set! */
#define CLEAR_UMARK clear_umark()
#include "proto.h"
/* @} */
#endif /* _Z_H_ */
/* The NEED_UMARK macro is just too useful */
/*
* Local Variables:
* my-checkpatch-ignores: "SPDX_LICENSE_TAG,MACRO_WITH_FLOW_CONTROL"
* End:
*/