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