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