Home | History | Annotate | Line # | Download | only in ed
ed.h revision 1.3
      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 
     94 	int type;			/* command type */
     95 	line_t	*h;			/* head of list */
     96 	line_t  *t;			/* tail of list */
     97 } undo_t;
     98 
     99 #ifndef max
    100 #  define max(a,b)	((a) > (b) ? (a) : (b))
    101 #endif
    102 
    103 #ifndef min
    104 #  define min(a,b)	((a) < (b) ? (a) : (b))
    105 #endif
    106 
    107 /* nextln: return line after l mod k */
    108 #define nextln(l,k)	((l)+1 > (k) ? 0 : (l)+1)
    109 
    110 /* nextln: return line before l mod k */
    111 #define prevln(l,k)	((l)-1 < 0 ? (k) : (l)-1)
    112 
    113 #define	skipblanks() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
    114 
    115 /* spl1: disable some interrupts (requires reliable signals) */
    116 #define spl1() mutex++
    117 
    118 /* spl0: enable all interrupts; check sigflags (requires reliable signals) */
    119 #define spl0() \
    120 if (--mutex == 0) { \
    121 	if (sigflags & (1 << SIGHUP)) dohup(SIGHUP); \
    122 	if (sigflags & (1 << SIGINT)) dointr(SIGINT); \
    123 }
    124 
    125 /* requeue: link pred before succ */
    126 #define requeue(pred, succ) (pred)->next = (succ), (succ)->prev = (pred)
    127 
    128 /* insqueue: insert elem in circular queue after pred */
    129 #define insqueue(elem, pred) \
    130 { \
    131 	requeue((elem), (pred)->next); \
    132 	requeue((pred), elem); \
    133 }
    134 
    135 /* remqueue: remove elem from circular queue */
    136 #define remqueue(elem) requeue((elem)->prev, (elem)->next);
    137 
    138 #ifndef __P
    139 # ifndef __STDC__
    140 #  define __P(proto) ()
    141 # else
    142 #  define __P(proto) proto
    143 # endif
    144 #endif
    145 
    146 /* local function declarations */
    147 int append __P((long, int));
    148 int cbcdec __P((char *, FILE *));
    149 int cbcenc __P((char *, int, FILE *));
    150 void cbcinit __P((void));
    151 int ckglob __P((void));
    152 int deflt __P((long, long));
    153 int del __P((long, long));
    154 int desgetc __P((FILE *));
    155 FILE *desopen __P((char *, char *));
    156 int desputc __P((int, FILE *));
    157 int docmd __P((int));
    158 char *ccl __P((int, char *));
    159 long doglob __P((void));
    160 void dohup __P((int));
    161 void dointr __P((int));
    162 void dowinch __P((int));
    163 int doprnt __P((long, long, int));
    164 long doread __P((long, char *));
    165 long dowrite __P((long, long, char *, char *));
    166 char *esctos __P((char *));
    167 long find __P((pattern_t *, int));
    168 void freecmdv __P((void));
    169 long getaddr __P((line_t *));
    170 char *getcmdv __P((void));
    171 char *getfn __P((void));
    172 int getkey __P((void));
    173 char *getlhs __P((int));
    174 int getline __P((char *, int));
    175 int getlist __P((void));
    176 long getnum __P((int));
    177 long getone __P((void));
    178 line_t *getptr __P((long));
    179 long getrange __P((line_t *, line_t *));
    180 int getrhs __P((char *, int));
    181 char *gettxt __P((line_t *));
    182 undo_t *getuptr __P((int, long, long));
    183 int join __P((long, long));
    184 line_t *lpdup __P((line_t *));
    185 void lpqueue __P((line_t *));
    186 char *makesub __P((char *, int, int));
    187 int move __P((long, int));
    188 int oddesc __P((char *, char *));
    189 void onhup __P((int));
    190 void onintr __P((int));
    191 pattern_t *optpat __P((void));
    192 void prntln __P((char *, long, int));
    193 char *puttxt __P((char *));
    194 void quit __P((int));
    195 char *regsub __P((pattern_t *, char *, char *, int));
    196 int sbclose __P((void));
    197 int sbopen __P((void));
    198 int sgetline __P((char *, int, FILE *));
    199 char *subcat __P((char *, regmatch_t *, char *, char *, char *));
    200 int subst __P((pattern_t *, char *, int));
    201 int transfer __P((long));
    202 int undo __P((void));
    203 void ureset __P((void));
    204