Home | History | Annotate | Line # | Download | only in ed
ed.h revision 1.2
      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 <regex.h>
     42 #if defined(BSD) && BSD >= 199103 || defined(__386BSD__)
     43 # include <sys/param.h>		/* for MAXPATHLEN */
     44 #endif
     45 
     46 #define BITSPERBYTE 8
     47 #define BITS(type)  (BITSPERBYTE * (int)sizeof(type))
     48 #define CHARBITS    BITS(char)
     49 #define INTBITS     BITS(int)
     50 
     51 #define	ESCHAR	'\\'
     52 #define CCL	'['	/* Character class: [...] */
     53 #define CCLEND	']'
     54 #define DITTO	'&'
     55 
     56 #define TRUE 	1
     57 #define FALSE	0
     58 #define ERR		(-2)
     59 #define EMOD		(ERR - 1)
     60 
     61 #ifndef MAXPATHLEN
     62 # define MAXPATHLEN 255		/* _POSIX_PATH_MAX */
     63 #endif
     64 
     65 #define MAXFNAME MAXPATHLEN	/* max file name size */
     66 #define MAXLINE	(4 << 10)	/* max number of chars per line */
     67 #define SE_MAX 30		/* max subexpressions in a regular expression */
     68 
     69 typedef regex_t pattern_t;
     70 
     71 #ifdef GNU_REGEX
     72 # define FASTMAP_SIZE 256	/* size of fastmap for 8 bit character set */
     73 #endif
     74 
     75 /* Line node */
     76 typedef struct	line {
     77 	struct line	*next;
     78 	struct line	*prev;
     79 	off_t		seek;		/* address of line in scratch buffer */
     80 
     81 #define ACTV	(1 << (INTBITS - 1))	/* active status: high bit of len */
     82 
     83 	int		len;		/* length of line */
     84 } line_t;
     85 
     86 
     87 typedef struct undo {
     88 
     89 /* type of undo nodes */
     90 #define UADD	0
     91 #define UDEL 	1
     92 
     93 	int type;			/* command type */
     94 	line_t	*h;			/* head of list */
     95 	line_t  *t;			/* tail of list */
     96 } undo_t;
     97 
     98 #ifndef max
     99 #  define max(a,b)	((a) > (b) ? (a) : (b))
    100 #endif
    101 
    102 #ifndef min
    103 #  define min(a,b)	((a) < (b) ? (a) : (b))
    104 #endif
    105 
    106 /* nextln: return line after l wrt k */
    107 #define nextln(l,k)	((l)+1 > (k) ? 0 : (l)+1)
    108 
    109 /* nextln: return line before l wrt k */
    110 #define prevln(l,k)	((l)-1 < 0 ? (k) : (l)-1)
    111 
    112 #define	skipblanks() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
    113 
    114 /* spl1: disable some interrupts (requires reliable signals) */
    115 #define spl1() mutex++
    116 
    117 /* spl0: enable all interrupts; check sigflags (requires reliable signals) */
    118 #define spl0() \
    119 if (--mutex == 0) { \
    120 	if (sigflags & (1 << SIGHUP)) dohup(SIGHUP); \
    121 	if (sigflags & (1 << SIGINT)) dointr(SIGINT); \
    122 }
    123 
    124 /* requeue: link pred before succ */
    125 #define requeue(pred, succ) (pred)->next = (succ), (succ)->prev = (pred)
    126 
    127 /* insqueue: insert elem in circular queue after pred */
    128 #define insqueue(elem, pred) \
    129 { \
    130 	requeue((elem), (pred)->next); \
    131 	requeue((pred), elem); \
    132 }
    133 
    134 /* remqueue: remove elem from circular queue */
    135 #define remqueue(elem) requeue((elem)->prev, (elem)->next);
    136 
    137 #ifndef __P
    138 # ifndef __STDC__
    139 #  define __P(proto) ()
    140 # else
    141 #  define __P(proto) proto
    142 # endif
    143 #endif
    144 
    145 /* local function declarations */
    146 int append __P((long, int));
    147 int cbcdec __P((char *, FILE *));
    148 int cbcenc __P((char *, int, FILE *));
    149 void cbcinit __P((void));
    150 int ckglob __P((void));
    151 int deflt __P((long, long));
    152 int del __P((long, long));
    153 int desgetc __P((FILE *));
    154 FILE *desopen __P((char *, char *));
    155 int desputc __P((int, FILE *));
    156 int docmd __P((int));
    157 char *ccl __P((int, char *));
    158 long doglob __P((void));
    159 void dohup __P((int));
    160 void dointr __P((int));
    161 void dowinch __P((int));
    162 int doprnt __P((long, long, int));
    163 long doread __P((long, char *));
    164 long dowrite __P((long, long, char *, char *));
    165 char *esctos __P((char *));
    166 long find __P((pattern_t *, int));
    167 void freecmdv __P((void));
    168 char *getcmdv __P((void));
    169 char *getfn __P((void));
    170 int getkey __P((void));
    171 char *getlhs __P((int));
    172 int getline __P((char *, int));
    173 int getlist __P((void));
    174 long getnum __P((int));
    175 long getone __P((void));
    176 line_t *getptr __P((long));
    177 long getrange __P((line_t *, line_t *));
    178 int getrhs __P((char *, int));
    179 char *gettxt __P((line_t *));
    180 undo_t *getuptr __P((int, long, long));
    181 int join __P((long, long));
    182 line_t *lpdup __P((line_t *));
    183 void lpqueue __P((line_t *));
    184 char *makesub __P((char *, int, int));
    185 int move __P((long, int));
    186 int oddesc __P((char *, char *));
    187 void onhup __P((int));
    188 void onintr __P((int));
    189 pattern_t *optpat __P((void));
    190 void prntln __P((char *, long, int));
    191 char *puttxt __P((char *));
    192 void quit __P((int));
    193 char *regsub __P((pattern_t *, char *, char *, int));
    194 int sbclose __P((void));
    195 int sbopen __P((void));
    196 int sgetline __P((char *, int, FILE *));
    197 char *subcat __P((char *, regmatch_t *, char *, char *, char *));
    198 int subst __P((pattern_t *, char *, int));
    199 int transfer __P((long));
    200 int undo __P((void));
    201 void ureset __P((void));
    202