Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/re/sed.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1995-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
#include <ast.h>
23
#include <ccode.h>
24
#include <error.h>
25
26
#include "regex.h"
27
28
typedef ptrdiff_t word;
29
30
typedef struct {
31
unsigned char *w; /* write pointer */
32
unsigned char *e; /* end */
33
unsigned char *s; /* start */
34
} Text;
35
36
extern void compile(Text*, Text*);
37
extern void execute(Text*, Text*);
38
extern word recomp(Text*, Text*, int);
39
extern int reexec(regex_t*, char*, size_t, size_t, regmatch_t*, int);
40
extern int match(unsigned char*, Text*, int);
41
extern int substitute(regex_t*, Text*);
42
extern regex_t* readdr(word);
43
extern void tcopy(Text*, Text*);
44
extern void printscript(Text*);
45
extern void vacate(Text*);
46
extern void synwarn(char*);
47
extern void syntax(char*);
48
extern void badre(regex_t*, int);
49
extern int readline(Text*);
50
extern int ateof(void);
51
extern void coda(void);
52
53
#define exch(a, b, t) ((t)=(a), (a)=(b), (b)=(t))
54
55
/* space management; assure room for n more chars in Text */
56
#define assure(t, n) \
57
do if((t)->s==0 || (t)->w>=(t)->e-(n)-1) grow((t), (n));while(0)
58
extern void grow(Text*, word);
59
60
/* round character pointer up to word pointer.
61
portable to the cray; simpler tricks are not */
62
63
#define wordp(p) (word*)((p) + sizeof(word) - 1 \
64
- ((p) + sizeof(word) - 1 - (unsigned char*)0)%sizeof(word))
65
66
extern int reflags;
67
extern int recno;
68
extern int nflag;
69
extern int qflag;
70
extern int sflag;
71
extern int bflag;
72
extern char* stdouterr;
73
74
extern Text files;
75
76
extern unsigned char* map;
77
78
/* SCRIPT LAYOUT
79
80
script commands are packed thus:
81
0,1,or2 address words signed + for numbers - for regexp
82
if 2 addresses, then another word indicates activity
83
positive: active, the record number where activated
84
negative: inactive, sign or-ed with number where deactivated
85
instruction word
86
high byte IMASK+flags; flags are NEG and SEL
87
next byte command code (a letter)
88
next two bytes, length of this command, including addrs
89
(length is a multiple of 4; capacity could be expanded
90
by counting the length in words instead of bytes)
91
after instruction word
92
on s command
93
offset of regexp in rebuf
94
word containing flags p,w plus n (g => n=0)
95
replacement text
96
word containing file designator, if flag w
97
on y command
98
256-byte transliteration table
99
on b and t command
100
offset of label in script
101
*/
102
103
#define BYTE CHAR_BIT
104
#define IMASK 0xC0000000 /* instruction flag */
105
#define NEG 0x01000000 /* instruction written with ! */
106
#define LMASK 0xffff /* low half word */
107
#define AMASK 0x7fffffff /* address mask, clear sign bit */
108
#define INACT (~AMASK) /* inactive bit, the sign bit */
109
#define DOLLAR AMASK /* huge address */
110
#define REGADR (~AMASK) /* context address */
111
112
extern word* instr(unsigned char*);
113
114
#define code(inst) ((inst)>>2*BYTE & 0xff)
115
#define nexti(p) ((p) + (*instr(p)&LMASK))
116
117