Home | History | Annotate | Line # | Download | only in ed
ed.h revision 1.6
      1 /* ed.h: type and constant definitions for the ed editor. */
      2 /*
      3  * Copyright (c) 1993 The Regents of the University of California.
      4  * All rights reserved.
      5  *
      6  * This code is derived from software contributed to Berkeley by
      7  * Andrew Moore, Talke Studio.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	@(#)ed.h	5.5 (Berkeley) 3/28/93
     38  */
     39 
     40 #include <unistd.h>
     41 #include <errno.h>
     42 #include <regex.h>
     43 #if defined(BSD) && BSD >= 199103 || defined(__386BSD__)
     44 # include <sys/param.h>		/* for MAXPATHLEN */
     45 #endif
     46 
     47 #define BITSPERBYTE 8
     48 #define BITS(type)  (BITSPERBYTE * (int)sizeof(type))
     49 #define CHARBITS    BITS(char)
     50 #define INTBITS     BITS(int)
     51 
     52 #define	ESCHAR	'\\'
     53 #define CCL	'['	/* Character class: [...] */
     54 #define CCLEND	']'
     55 #define DITTO	'&'
     56 
     57 #define TRUE 	1
     58 #define FALSE	0
     59 #define ERR		(-2)
     60 #define EMOD		(ERR - 1)
     61 
     62 #ifndef MAXPATHLEN
     63 # define MAXPATHLEN 255		/* _POSIX_PATH_MAX */
     64 #endif
     65 
     66 #define MAXFNAME MAXPATHLEN	/* max file name size */
     67 #define MAXLINE	(4 << 10)	/* max number of chars per line */
     68 #define SE_MAX 30		/* max subexpressions in a regular expression */
     69 
     70 typedef regex_t pattern_t;
     71 
     72 #ifdef GNU_REGEX
     73 # define FASTMAP_SIZE 256	/* size of fastmap for 8 bit character set */
     74 #endif
     75 
     76 /* Line node */
     77 typedef struct	line {
     78 	struct line	*next;
     79 	struct line	*prev;
     80 	off_t		seek;		/* address of line in scratch buffer */
     81 
     82 #define ACTV	(1 << (INTBITS - 1))	/* active status: high bit of len */
     83 
     84 	int		len;		/* length of line */
     85 } line_t;
     86 
     87 
     88 typedef struct undo {
     89 
     90 /* type of undo nodes */
     91 #define UADD	0
     92 #define UDEL 	1
     93 #define UMOV	2
     94 #define VMOV	3
     95 
     96 	int type;			/* command type */
     97 	line_t	*h;			/* head of list */
     98 	line_t  *t;			/* tail of list */
     99 } undo_t;
    100 
    101 #ifndef max
    102 #  define max(a,b)	((a) > (b) ? (a) : (b))
    103 #endif
    104 
    105 #ifndef min
    106 #  define min(a,b)	((a) < (b) ? (a) : (b))
    107 #endif
    108 
    109 /* nextln: return line after l mod k */
    110 #define nextln(l,k)	((l)+1 > (k) ? 0 : (l)+1)
    111 
    112 /* nextln: return line before l mod k */
    113 #define prevln(l,k)	((l)-1 < 0 ? (k) : (l)-1)
    114 
    115 #define	skipblanks() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
    116 
    117 /* spl1: disable some interrupts (requires reliable signals) */
    118 #define spl1() mutex++
    119 
    120 /* spl0: enable all interrupts; check sigflags (requires reliable signals) */
    121 #define spl0() \
    122 if (--mutex == 0) { \
    123 	if (sigflags & (1 << SIGHUP)) dohup(SIGHUP); \
    124 	if (sigflags & (1 << SIGINT)) dointr(SIGINT); \
    125 }
    126 
    127 /* requeue: link pred before succ */
    128 #define requeue(pred, succ) (pred)->next = (succ), (succ)->prev = (pred)
    129 
    130 /* insqueue: insert elem in circular queue after pred */
    131 #define insqueue(elem, pred) \
    132 { \
    133 	requeue((elem), (pred)->next); \
    134 	requeue((pred), elem); \
    135 }
    136 
    137 /* remqueue: remove elem from circular queue */
    138 #define remqueue(elem) requeue((elem)->prev, (elem)->next);
    139 
    140 #ifndef strerror
    141 # define strerror(n) sys_errlist[n]
    142 #endif
    143 
    144 #ifndef __P
    145 # ifndef __STDC__
    146 #  define __P(proto) ()
    147 # else
    148 #  define __P(proto) proto
    149 # endif
    150 #endif
    151 
    152 /* local function declarations */
    153 int append __P((long, int));
    154 int cbcdec __P((char *, FILE *));
    155 int cbcenc __P((char *, int, FILE *));
    156 void cbcinit __P((void));
    157 int ckglob __P((void));
    158 int deflt __P((long, long));
    159 int del __P((long, long));
    160 int desgetc __P((FILE *));
    161 FILE *desopen __P((char *, char *));
    162 int desputc __P((int, FILE *));
    163 int docmd __P((int));
    164 int err __P((char *));
    165 char *ccl __P((int, char *));
    166 int cvtkey __P((char *, char *));
    167 long doglob __P((int));
    168 void dohup __P((int));
    169 void dointr __P((int));
    170 void dowinch __P((int));
    171 int doprnt __P((long, long, int));
    172 long doread __P((long, char *));
    173 long dowrite __P((long, long, char *, char *));
    174 char *esctos __P((char *));
    175 long find __P((pattern_t *, int));
    176 long getaddr __P((line_t *));
    177 char *getcmdv __P((int));
    178 char *getfn __P((void));
    179 int getkey __P((void));
    180 char *getlhs __P((int));
    181 int getline __P((char *, int));
    182 int getlist __P((void));
    183 long getnum __P((int));
    184 long getone __P((void));
    185 line_t *getptr __P((long));
    186 int getrhs __P((char *, int));
    187 int getshcmd __P((char **));
    188 char *gettxt __P((line_t *));
    189 int join __P((long, long));
    190 line_t *lpdup __P((line_t *));
    191 void lpqueue __P((line_t *));
    192 int makekey __P((char *));
    193 char *makesub __P((char *, int, int));
    194 int move __P((long));
    195 int oddesc __P((char *, char *));
    196 void onhup __P((int));
    197 void onintr __P((int));
    198 pattern_t *optpat __P((void));
    199 void prntln __P((char *, long, int));
    200 char *puttxt __P((char *));
    201 void quit __P((int));
    202 char *regsub __P((pattern_t *, char *, char *, int));
    203 int sbclose __P((void));
    204 int sbopen __P((void));
    205 int sgetline __P((char *, int, FILE *));
    206 char *subcat __P((char *, regmatch_t *, char *, char *, char *));
    207 int subst __P((pattern_t *, char *, int));
    208 int tobinhex __P((int, int));
    209 int transfer __P((long));
    210 int undo __P((void));
    211 undo_t *upush __P((int, long, long));
    212 void ureset __P((void));
    213 
    214 extern char *sys_errlist[];
    215