Home | History | Annotate | Line # | Download | only in sed
defs.h revision 1.10.22.1
      1  1.10.22.1      tls /*	$NetBSD: defs.h,v 1.10.22.1 2014/08/10 06:58:55 tls Exp $	*/
      2        1.7      tls 
      3        1.1      alm /*-
      4  1.10.22.1      tls  * Copyright (c) 1992 Diomidis Spinellis.
      5        1.4      cgd  * Copyright (c) 1992, 1993
      6        1.4      cgd  *	The Regents of the University of California.  All rights reserved.
      7        1.1      alm  *
      8        1.1      alm  * This code is derived from software contributed to Berkeley by
      9        1.1      alm  * Diomidis Spinellis of Imperial College, University of London.
     10        1.1      alm  *
     11        1.1      alm  * Redistribution and use in source and binary forms, with or without
     12        1.1      alm  * modification, are permitted provided that the following conditions
     13        1.1      alm  * are met:
     14        1.1      alm  * 1. Redistributions of source code must retain the above copyright
     15        1.1      alm  *    notice, this list of conditions and the following disclaimer.
     16        1.1      alm  * 2. Redistributions in binary form must reproduce the above copyright
     17        1.1      alm  *    notice, this list of conditions and the following disclaimer in the
     18        1.1      alm  *    documentation and/or other materials provided with the distribution.
     19        1.8      agc  * 3. Neither the name of the University nor the names of its contributors
     20        1.8      agc  *    may be used to endorse or promote products derived from this software
     21        1.8      agc  *    without specific prior written permission.
     22        1.8      agc  *
     23        1.8      agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24        1.8      agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25        1.8      agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26        1.8      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27        1.8      agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28        1.8      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29        1.8      agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.8      agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.8      agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.8      agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.8      agc  * SUCH DAMAGE.
     34        1.8      agc  *
     35  1.10.22.1      tls  *	@(#)defs.h	8.1 (Berkeley) 6/6/93
     36  1.10.22.1      tls  * $FreeBSD: head/usr.bin/sed/defs.h 192732 2009-05-25 06:45:33Z brian $
     37        1.1      alm  */
     38        1.1      alm 
     39        1.1      alm /*
     40        1.1      alm  * Types of address specifications
     41        1.1      alm  */
     42        1.1      alm enum e_atype {
     43  1.10.22.1      tls 	AT_RE	    = 1,			/* Line that match RE */
     44        1.1      alm 	AT_LINE,				/* Specific line */
     45  1.10.22.1      tls 	AT_RELLINE,				/* Relative line */
     46        1.9    grant 	AT_LAST					/* Last line */
     47        1.1      alm };
     48        1.1      alm 
     49        1.1      alm /*
     50        1.1      alm  * Format of an address
     51        1.1      alm  */
     52        1.1      alm struct s_addr {
     53        1.1      alm 	enum e_atype type;			/* Address type */
     54        1.1      alm 	union {
     55        1.1      alm 		u_long l;			/* Line number */
     56        1.1      alm 		regex_t *r;			/* Regular expression */
     57        1.1      alm 	} u;
     58        1.1      alm };
     59        1.1      alm 
     60        1.1      alm /*
     61        1.1      alm  * Substitution command
     62        1.1      alm  */
     63        1.1      alm struct s_subst {
     64        1.1      alm 	int n;					/* Occurrence to subst. */
     65        1.1      alm 	int p;					/* True if p flag */
     66  1.10.22.1      tls 	int icase;				/* True if I flag */
     67        1.1      alm 	char *wfile;				/* NULL if no wfile */
     68        1.1      alm 	int wfd;				/* Cached file descriptor */
     69        1.1      alm 	regex_t *re;				/* Regular expression */
     70  1.10.22.1      tls 	unsigned int maxbref;			/* Largest backreference. */
     71        1.1      alm 	u_long linenum;				/* Line number. */
     72        1.1      alm 	char *new;				/* Replacement text */
     73        1.1      alm };
     74        1.1      alm 
     75  1.10.22.1      tls /*
     76  1.10.22.1      tls  * Translate command.
     77  1.10.22.1      tls  */
     78  1.10.22.1      tls struct s_tr {
     79  1.10.22.1      tls 	unsigned char bytetab[256];
     80  1.10.22.1      tls 	struct trmulti {
     81  1.10.22.1      tls 		size_t fromlen;
     82  1.10.22.1      tls 		char from[MB_LEN_MAX];
     83  1.10.22.1      tls 		size_t tolen;
     84  1.10.22.1      tls 		char to[MB_LEN_MAX];
     85  1.10.22.1      tls 	} *multis;
     86  1.10.22.1      tls 	size_t nmultis;
     87  1.10.22.1      tls };
     88        1.1      alm 
     89        1.1      alm /*
     90        1.1      alm  * An internally compiled command.
     91        1.4      cgd  * Initialy, label references are stored in t, on a second pass they
     92        1.1      alm  * are updated to pointers.
     93        1.1      alm  */
     94        1.1      alm struct s_command {
     95        1.1      alm 	struct s_command *next;			/* Pointer to next command */
     96        1.1      alm 	struct s_addr *a1, *a2;			/* Start and end address */
     97  1.10.22.1      tls 	u_long startline;			/* Start line number or zero */
     98        1.1      alm 	char *t;				/* Text for : a c i r w */
     99        1.1      alm 	union {
    100        1.1      alm 		struct s_command *c;		/* Command(s) for b t { */
    101        1.1      alm 		struct s_subst *s;		/* Substitute command */
    102  1.10.22.1      tls 		struct s_tr *y;			/* Replace command array */
    103        1.1      alm 		int fd;				/* File descriptor for w */
    104        1.1      alm 	} u;
    105        1.1      alm 	char code;				/* Command code */
    106        1.1      alm 	u_int nonsel:1;				/* True if ! */
    107        1.1      alm };
    108        1.1      alm 
    109        1.1      alm /*
    110        1.1      alm  * Types of command arguments recognised by the parser
    111        1.1      alm  */
    112        1.1      alm enum e_args {
    113        1.1      alm 	EMPTY,			/* d D g G h H l n N p P q x = \0 */
    114        1.1      alm 	TEXT,			/* a c i */
    115        1.1      alm 	NONSEL,			/* ! */
    116        1.1      alm 	GROUP,			/* { */
    117        1.6  mycroft 	ENDGROUP,		/* } */
    118        1.1      alm 	COMMENT,		/* # */
    119        1.1      alm 	BRANCH,			/* b t */
    120        1.1      alm 	LABEL,			/* : */
    121        1.1      alm 	RFILE,			/* r */
    122        1.1      alm 	WFILE,			/* w */
    123        1.1      alm 	SUBST,			/* s */
    124        1.1      alm 	TR			/* y */
    125        1.1      alm };
    126        1.1      alm 
    127        1.1      alm /*
    128        1.1      alm  * Structure containing things to append before a line is read
    129        1.1      alm  */
    130        1.1      alm struct s_appends {
    131        1.1      alm 	enum {AP_STRING, AP_FILE} type;
    132        1.1      alm 	char *s;
    133        1.4      cgd 	size_t len;
    134        1.1      alm };
    135        1.1      alm 
    136        1.1      alm enum e_spflag {
    137        1.1      alm 	APPEND,					/* Append to the contents. */
    138        1.9    grant 	REPLACE					/* Replace the contents. */
    139        1.1      alm };
    140        1.1      alm 
    141        1.1      alm /*
    142        1.1      alm  * Structure for a space (process, hold, otherwise).
    143        1.1      alm  */
    144        1.1      alm typedef struct {
    145        1.1      alm 	char *space;		/* Current space pointer. */
    146        1.1      alm 	size_t len;		/* Current length. */
    147        1.1      alm 	int deleted;		/* If deleted. */
    148        1.1      alm 	char *back;		/* Backing memory. */
    149        1.1      alm 	size_t blen;		/* Backing memory length. */
    150        1.1      alm } SPACE;
    151