Subversion Repositories planix.SVN

Rev

Rev 115 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
105 7u83 1
/*
2
 * Copyright (c) 1980 Regents of the University of California.
3
 * All rights reserved.  The Berkeley software License Agreement
4
 * specifies the terms and conditions for redistribution.
5
 *
6
 *	@(#)ex.h	7.7.1.1 (Berkeley) 8/12/86
7
 */
8
 
9
#ifdef V6
10
#include <retrofit.h>
11
#endif
12
 
13
/*
14
 * Ex version 3 (see exact version in ex_cmds.c, search for /Version/)
15
 *
16
 * Mark Horton, UC Berkeley
17
 * Bill Joy, UC Berkeley
18
 * November 1979
19
 *
20
 * Changes by Gunnar Ritter, Freiburg i. Br., Germany
21
 * May 2000
22
 *
23
 * This file contains most of the declarations common to a large number
24
 * of routines.  The file ex_vis.h contains declarations
25
 * which are used only inside the screen editor.
26
 * The file ex_tune.h contains parameters which can be diddled per installation.
27
 *
28
 * The declarations relating to the argument list, regular expressions,
29
 * the temporary file data structure used by the editor
30
 * and the data describing terminals are each fairly substantial and
31
 * are kept in the files ex_{argv,re,temp,tty}.h which
32
 * we #include separately.
33
 *
34
 * If you are going to dig into ex, you should look at the outline of the
35
 * distribution of the code into files at the beginning of ex.c and ex_v.c.
36
 * Code which is similar to that of ed is lightly or undocumented in spots
37
 * (e.g. the regular expression code).  Newer code (e.g. open and visual)
38
 * is much more carefully documented, and still rough in spots.
39
 *
40
 * Please forward bug reports to
41
 *
42
 *	Mark Horton
43
 *	Computer Science Division, EECS
44
 *	EVANS HALL
45
 *	U.C. Berkeley 94704
46
 *	(415) 642-4948
47
 *	(415) 642-1024 (dept. office)
48
 *
49
 * or to csvax.mark@berkeley on the ARPA-net.  I would particularly like to hear
50
 * of additional terminal descriptions you add to the termcap data base.
51
 */
52
 
53
#include <sys/param.h>
54
#include <ctype.h>
55
#include <errno.h>
56
#include <signal.h>
57
#include <setjmp.h>
58
#include <sys/stat.h>
59
 
60
#ifndef var
61
#define var	extern
62
#endif
63
/*
64
 *	The following little dance copes with the new USG tty handling.
65
 *	This stuff has the advantage of considerable flexibility, and
66
 *	the disadvantage of being incompatible with anything else.
67
 *	The presence of the symbol USG3TTY will indicate the new code:
68
 *	in this case, we define CBREAK (because we can simulate it exactly),
69
 *	but we won't actually use it, so we set it to a value that will
70
 *	probably blow the compilation if we goof up.
71
 */
72
#ifdef USG3TTY
73
#include <termios.h>
74
#define CBREAK xxxxx
75
#else
76
#include <sgtty.h>
77
#endif
78
 
79
extern	int errno;
80
 
116 7u83 81
 
82
 
83
/* defined in ex_put.c */
84
void flush(void);
85
void noonl(void);
86
void putNFL(void);
87
 
88
 
89
 
90
 
91
 
92
 
93
 
94
 
95
 
105 7u83 96
#ifdef	NCURSES
97
/*
98
 * Some of the symbols collide.
99
 */
100
#define	LINES		LI_NES
101
#define	cleanup		clean_up
102
#define	filter		fil_ter
103
#define	getch		get_ch
104
#define	longname	long_name
116 7u83 105
//#define	ttytype		tty_type
105 7u83 106
#define	winch		win_ch
107
#endif
108
 
109
#ifndef	VMUNIX
110
typedef	short	line;
111
#else
112
typedef	int	line;
113
#endif
114
typedef	short	bool;
115
 
116
#include "ex_tune.h"
117
#include "ex_vars.h"
118
/*
119
 * Options in the editor are referred to usually by "value(name)" where
120
 * name is all uppercase, i.e. "value(PROMPT)".  This is actually a macro
121
 * which expands to a fixed field in a static structure and so generates
122
 * very little code.  The offsets for the option names in the structure
123
 * are generated automagically from the structure initializing them in
124
 * ex_data.c... see the shell script "makeoptions".
125
 */
126
struct	option {
127
	char	*oname;
128
	char	*oabbrev;
129
	short	otype;		/* Types -- see below */
130
	short	odefault;	/* Default value */
131
	short	ovalue;		/* Current value */
132
	char	*osvalue;
133
};
134
 
135
#define	ONOFF	0
136
#define	NUMERIC	1
137
#define	STRING	2		/* SHELL or DIRECTORY */
138
#define	OTERM	3
139
 
140
#define	value(a)	options[a].ovalue
141
#define	svalue(a)	options[a].osvalue
142
 
143
extern	 struct	option options[NOPTS + 1];
144
 
145
 
146
/*
147
 * The editor does not normally use the standard i/o library.  Because
148
 * we expect the editor to be a heavily used program and because it
149
 * does a substantial amount of input/output processing it is appropriate
150
 * for it to call low level read/write primitives directly.  In fact,
151
 * when debugging the editor we use the standard i/o library.  In any
152
 * case the editor needs a printf which prints through "putchar" ala the
153
 * old version 6 printf.  Thus we normally steal a copy of the "printf.c"
154
 * and "strout" code from the standard i/o library and mung it for our
155
 * purposes to avoid dragging in the stdio library headers, etc if we
156
 * are not debugging.  Such a modified printf exists in "printf.c" here.
157
 */
158
#ifdef TRACE
159
#	include <stdio.h>
160
	var	FILE	*trace;
161
	var	bool	trubble;
162
	var	bool	techoin;
163
	var	char	tracbuf[BUFSIZ];
164
#	undef	putchar
165
#	undef	getchar
166
#else
167
#ifndef	BUFSIZ	/* GR */
168
# ifdef	VMUNIX
169
#   ifdef BIGMEM
170
#       define	BUFSIZ	4096
171
#   else
172
#	define	BUFSIZ	1024
173
#   endif
174
# else
175
#  ifdef u370
176
#	define	BUFSIZ	4096
177
#  else
178
#	define	BUFSIZ	512
179
#  endif
180
# endif
181
#endif
182
#	define	NULL	0
183
#	define	EOF	-1
184
#endif
185
 
186
#ifndef	MAXBSIZE	/* GR */
187
#define	MAXBSIZE	BUFSIZ
188
#endif
189
 
190
/*
191
 * Character constants and bits
192
 *
193
 * The editor uses the QUOTE bit as a flag to pass on with characters
194
 * e.g. to the putchar routine.  The editor never uses a simple char variable.
195
 * Only arrays of and pointers to characters are used and parameters and
196
 * registers are never declared character.
197
 */
198
#ifndef	BIT8
199
#define	QUOTE	0200
200
#define	TRIM	0177
201
#else
202
#define	QUOTE	0x200
203
#define	TRIM	0x1FF
204
short *ss_strcpy();
205
short *sc_strcpy();
206
char *cs_strcpy();
207
unsigned int s_strlen();
208
short *sc_strcat();
209
#endif
210
#undef CTRL
211
#define	CTRL(c)	(c & 037)
212
#define	NL	CTRL('j')
213
#define	CR	CTRL('m')
214
#define	DELETE	0177		/* See also ATTN, QUIT in ex_tune.h */
215
#define	ESCAPE	033
216
 
217
#ifdef	ISO
218
#define	niso(c)	((c) & QUOTE && ((unsigned char)(c)) < (QUOTE + ' '))
219
#endif
220
 
221
var	const char *versionstring;
222
 
223
/*
224
 * Miscellaneous random variables used in more than one place
225
 */
226
var	bool	aiflag;		/* Append/change/insert with autoindent */
227
var	bool	anymarks;	/* We have used '[a-z] */
228
var	int	chng;		/* Warn "No write" */
229
var	char	*Command;
230
var	short	defwind;	/* -w# change default window size */
231
var	int	dirtcnt;	/* When >= MAXDIRT, should sync temporary */
232
/*#if defined (TIOCLGET) || defined (__linux__)*/
233
var	bool	dosusp;		/* Do SIGTSTP in visual when ^Z typed */
234
/*#endif*/
235
var	bool	edited;		/* Current file is [Edited] */
236
var	line	*endcore;	/* Last available core location */
237
extern	 bool	endline;	/* Last cmd mode command ended with \n */
238
#ifndef VMUNIX
239
var	short	erfile;		/* Error message file unit */
240
#endif
241
var	line	*fendcore;	/* First address in line pointer space */
242
var	char	file[FNSIZE];	/* Working file name */
243
var	char	genbuf[MAXBSIZE]; /* Working buffer when manipulating linebuf */
244
var	bool	hush;		/* Command line option - was given, hush up! */
245
#ifndef	BIT8
246
var	char	*globp;		/* (Untyped) input string to command mode */
247
#else
248
var	short	*globp;		/* (Untyped) input string to command mode */
249
#endif
250
var	bool	holdcm;		/* Don't cursor address */
251
var	bool	inappend;	/* in ex command append mode */
252
var	bool	inglobal;	/* Inside g//... or v//... */
253
#ifndef	BIT8
254
var	char	*initev;	/* Initial : escape for visual */
255
#else
256
var	short	*initev;	/* Initial : escape for visual */
257
#endif
258
var	bool	inopen;		/* Inside open or visual */
259
var	char	*input;		/* Current position in cmd line input buffer */
260
var	bool	intty;		/* Input is a tty */
261
var	short	io;		/* General i/o unit (auto-closed on error!) */
262
extern	 short	lastc;		/* Last character ret'd from cmd input */
263
var	bool	laste;		/* Last command was an "e" (or "rec") */
264
var	char	lastmac;	/* Last macro called for ** */
265
var	char	lasttag[TAGSIZE];	/* Last argument to a tag command */
266
var	char	*linebp;	/* Used in substituting in \n */
267
var	char	linebuf[LBSIZE];	/* The primary line buffer */
268
var	bool	listf;		/* Command should run in list mode */
269
var	char	*loc1;		/* Where re began to match (in linebuf) */
270
var	char	*loc2;		/* First char after re match (") */
271
var	line	names['z'-'a'+2];	/* Mark registers a-z,' */
272
var	int	notecnt;	/* Count for notify (to visual from cmd) */
273
var	bool	numberf;	/* Command should run in number mode */
274
var	char	obuf[BUFSIZ];	/* Buffer for tty output */
275
var	short	oprompt;	/* Saved during source */
276
extern	short	o_speed;	/* Output speed (from gtty) */
277
var	int	otchng;		/* Backup tchng to find changes in macros */
278
var	short	peekc;		/* Peek ahead character (cmd mode input) */
279
var	char	*pkill[2];	/* Trim for put with ragged (LISP) delete */
280
var	bool	pfast;		/* Have stty -nl'ed to go faster */
281
var	int	pid;		/* Process id of child */
282
var	int	ppid;		/* Process id of parent (e.g. main ex proc) */
283
var	jmp_buf	resetlab;	/* For error throws to top level (cmd mode) */
284
var	int	rpid;		/* Pid returned from wait() */
285
var	bool	ruptible;	/* Interruptible is normal state */
286
var	bool	seenprompt;	/* 1 if have gotten user input */
287
var	bool	shudclob;	/* Have a prompt to clobber (e.g. on ^D) */
288
var	int	status;		/* Status returned from wait() */
289
var	int	tchng;		/* If nonzero, then [Modified] */
290
extern	short	tfile;		/* Temporary file unit */
291
var	bool	vcatch;		/* Want to catch an error (open/visual) */
292
var	jmp_buf	vreslab;	/* For error throws to a visual catch */
293
var	bool	writing;	/* 1 if in middle of a file write */
294
var	int	xchng;		/* Suppresses multiple "No writes" in !cmd */
295
var	int	bsize;		/* Block size for disk i/o */
296
 
297
/*
298
 * Macros
299
 */
115 7u83 300
#define	CP(a, b)	(ignore(strcpy(a, b)))
105 7u83 301
			/*
302
			 * FIXUNDO: do we want to mung undo vars?
303
			 * Usually yes unless in a macro or global.
304
			 */
305
#define FIXUNDO		(inopen >= 0 && (inopen || !inglobal))
306
#define ckaw()		{if (chng && value(AUTOWRITE)) wop(0);}
307
#define	copy(a,b,c)	Copy((char *) a, (char *) b, c)
308
#define	eq(a, b)	((a) && (b) && strcmp(a, b) == 0)
309
#define	getexit(a)	copy(a, resetlab, sizeof (jmp_buf))
310
#define	lastchar()	lastc
311
#define	outchar(c)	(*Outchar)(c)
312
#define	pastwh()	(ignore(skipwh()))
313
#define	pline(no)	(*Pline)(no)
314
#define	reset()		longjmp(resetlab,1)
315
#define	resexit(a)	copy(resetlab, a, sizeof (jmp_buf))
316
#define	setexit()	setjmp(resetlab)
317
#define	setlastchar(c)	lastc = c
318
#define	ungetchar(c)	peekc = c
319
 
320
#define	CATCH		vcatch = 1; if (setjmp(vreslab) == 0) {
321
#define	ONERR		} else { vcatch = 0;
322
#define	ENDCATCH	} vcatch = 0;
323
 
324
/*
325
 * Environment like memory
326
 */
327
var	char	altfile[FNSIZE];	/* Alternate file name */
328
extern	 char	direct[ONMSZ];		/* Temp file goes here */
329
extern	 char	shell[ONMSZ];		/* Copied to be settable */
116 7u83 330
extern	 char	ex_ttytype[ONMSZ];		/* A long and pretty name */
105 7u83 331
var	char	uxb[UXBSIZE + 2];	/* Last !command for !! */
332
 
333
/*
334
 * The editor data structure for accessing the current file consists
335
 * of an incore array of pointers into the temporary file tfile.
336
 * Each pointer is 15 bits (the low bit is used by global) and is
337
 * padded with zeroes to make an index into the temp file where the
338
 * actual text of the line is stored.
339
 *
340
 * To effect undo, copies of affected lines are saved after the last
341
 * line considered to be in the buffer, between dol and unddol.
342
 * During an open or visual, which uses the command mode undo between
343
 * dol and unddol, a copy of the entire, pre-command buffer state
344
 * is saved between unddol and truedol.
345
 */
346
var	line	*addr1;			/* First addressed line in a command */
347
var	line	*addr2;			/* Second addressed line */
348
var	line	*dol;			/* Last line in buffer */
349
var	line	*dot;			/* Current line */
350
var	line	*one;			/* First line */
351
var	line	*truedol;		/* End of all lines, including saves */
352
var	line	*unddol;		/* End of undo saved lines */
353
var	line	*zero;			/* Points to empty slot before one */
354
 
355
/*
356
 * Undo information
357
 *
358
 * For most commands we save lines changed by salting them away between
359
 * dol and unddol before they are changed (i.e. we save the descriptors
360
 * into the temp file tfile which is never garbage collected).  The
361
 * lines put here go back after unddel, and to complete the undo
362
 * we delete the lines [undap1,undap2).
363
 *
364
 * Undoing a move is much easier and we treat this as a special case.
365
 * Similarly undoing a "put" is a special case for although there
366
 * are lines saved between dol and unddol we don't stick these back
367
 * into the buffer.
368
 */
369
var	short	undkind;
370
 
371
var	line	*unddel;	/* Saved deleted lines go after here */
372
var	line	*undap1;	/* Beginning of new lines */
373
var	line	*undap2;	/* New lines end before undap2 */
374
var	line	*undadot;	/* If we saved all lines, dot reverts here */
375
 
376
#define	UNDCHANGE	0
377
#define	UNDMOVE		1
378
#define	UNDALL		2
379
#define	UNDNONE		3
380
#define	UNDPUT		4
381
 
382
 
383
/*
384
 * Function type definitions
385
 */
386
#define	NOSTR	(char *) 0
387
#define	NOLINE	(line *) 0
388
 
115 7u83 389
extern	int	(*Outchar)();
105 7u83 390
extern	int	(*Pline)();
115 7u83 391
extern	int	(*Putchar)();
108 7u83 392
void	(*oldhup)();
115 7u83 393
int	(*setlist())();
105 7u83 394
int	(*setnorm())();
395
int	(*setnorm())();
396
int	(*setnumb())();
397
line	*address();
398
char	*cgoto();
399
char	*genindent();
400
char	*getblock();
401
char	*getenv();
402
line	*getmark();
403
char	*longname();
404
char	*mesg();
405
char	*place();
406
char	*plural();
407
line	*scanfor();
408
line	*setin();
409
char	*strcat();
410
char	*strcpy();
411
char	*strend();
412
char	*tailpath();
413
char	*tgetstr();
414
char	*tgoto();
415
char	*ttyname();
416
line	*vback();
417
char	*vfindcol();
418
char	*vgetline();
419
char	*vinit();
420
char	*vpastwh();
421
char	*vskipwh();
115 7u83 422
int	put();
423
int	putreg();
105 7u83 424
int	YANKreg();
425
int	delete();
426
int	execl();
427
int	filter();
428
int	getfile();
429
int	getsub();
430
int	gettty();
431
int	join();
115 7u83 432
int	listchar();
105 7u83 433
off_t	lseek();
115 7u83 434
int	normchar();
105 7u83 435
int	normline();
436
int	numbline();
437
var	void	(*oldquit)();
438
void	onhup();
106 7u83 439
void	onintr();
105 7u83 440
void	onsusp();
441
int	putch();
442
int	shift();
115 7u83 443
int	termchar();
444
int	vfilter();
105 7u83 445
#ifdef CBREAK
106 7u83 446
void	vintr();
105 7u83 447
#endif
448
int	vputch();
115 7u83 449
int	vshftop();
105 7u83 450
int	yank();
451
 
107 7u83 452
int tgets(char *, int cnt, int fd);
453
 
454
 
105 7u83 455
/*
456
 * C doesn't have a (void) cast, so we have to fake it for lint's sake.
457
 */
458
#ifdef lint
459
#	define	ignore(a)	Ignore((char *) (a))
460
#	define	ignorf(a)	Ignorf((int (*) ()) (a))
461
#else
462
#	define	ignore(a)	a
463
#	define	ignorf(a)	a
464
#endif
116 7u83 465
 
466
 
467
 
468