summaryrefslogtreecommitdiffstats
path: root/modules/filters/libsed.h
blob: 0256b1ea831f5102ce269d1bea86433287c3477c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (c) 2005, 2008 Sun Microsystems, Inc. All Rights Reserved.
 * Use is subject to license terms.
 *
 *      Copyright (c) 1984 AT&T
 *        All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LIBSED_H
#define LIBSED_H

#ifdef __cplusplus
extern "C" {
#endif

#include <limits.h>

#include "apr_file_io.h"

#define SED_NLINES 256
#define SED_DEPTH 20
#define SED_LABSIZE 50
#define SED_ABUFSIZE 20

typedef struct sed_reptr_s sed_reptr_t;

struct sed_reptr_s {
    sed_reptr_t *next;
    char        *ad1;
    char        *ad2;
    char        *re1;
    sed_reptr_t *lb1;
    char        *rhs;
    int         findex;
    char        command;
    int         gfl;
    char        pfl;
    char        negfl;
    int         nrep;
};

typedef struct sed_label_s sed_label_t;

struct sed_label_s {
    char        asc[9];
    sed_reptr_t *chain;
    sed_reptr_t *address;
};

typedef apr_status_t (sed_err_fn_t)(void *data, const char *error);
typedef apr_status_t (sed_write_fn_t)(void *ctx, char *buf, apr_size_t sz);

typedef struct sed_commands_s sed_commands_t;
#define NWFILES 11 /* 10 plus one for standard output */

struct sed_commands_s {
    sed_err_fn_t *errfn;
    void         *data;

    apr_size_t   lsize;
    char         *linebuf;
    char         *lbend;
    const char   *saveq;

    char         *cp;
    char         *lastre;
    char         *respace;
    char         sseof;
    char         *reend;
    const char   *earg;
    int          eflag;
    int          gflag;
    int          nflag;
    apr_int64_t  tlno[SED_NLINES];
    int          nlno;
    int          depth;

    char         *fname[NWFILES];
    int          nfiles;

    sed_label_t  ltab[SED_LABSIZE];
    sed_label_t  *labtab;
    sed_label_t  *lab;
    sed_label_t  *labend;

    sed_reptr_t  **cmpend[SED_DEPTH];
    sed_reptr_t  *ptrspace;
    sed_reptr_t  *ptrend;
    sed_reptr_t  *rep;
    int          nrep;
    apr_pool_t   *pool;
    int          canbefinal;
};

typedef struct sed_eval_s sed_eval_t;

struct sed_eval_s {
    sed_err_fn_t   *errfn;
    sed_write_fn_t *writefn;
    void           *data;

    sed_commands_t *commands;

    apr_int64_t    lnum;
    void           *fout;

    apr_size_t     lsize;
    char           *linebuf;
    char           *lspend;

    apr_size_t     hsize;
    char           *holdbuf;
    char           *hspend;

    apr_size_t     gsize;
    char           *genbuf;
    char           *lcomend;

    apr_file_t    *fcode[NWFILES];
    sed_reptr_t    *abuf[SED_ABUFSIZE];
    sed_reptr_t    **aptr;
    sed_reptr_t    *pending;
    unsigned char  *inar;
    int            nrep;

    int            dolflag;
    int            sflag;
    int            jflag;
    int            delflag;
    int            lreadyflag;
    int            quitflag;
    int            finalflag;
    int            numpass;
    int            nullmatch;
    int            col;
    apr_pool_t     *pool;
};

apr_status_t sed_init_commands(sed_commands_t *commands, sed_err_fn_t *errfn, void *data,
                               apr_pool_t *p);
apr_status_t sed_compile_string(sed_commands_t *commands, const char *s);
apr_status_t sed_compile_file(sed_commands_t *commands, apr_file_t *fin);
char* sed_get_finalize_error(const sed_commands_t *commands, apr_pool_t* pool);
int sed_canbe_finalized(const sed_commands_t *commands);
void sed_destroy_commands(sed_commands_t *commands);

apr_status_t sed_init_eval(sed_eval_t *eval, sed_commands_t *commands,
                           sed_err_fn_t *errfn, void *data,
                           sed_write_fn_t *writefn, apr_pool_t *p);
apr_status_t sed_reset_eval(sed_eval_t *eval, sed_commands_t *commands, sed_err_fn_t *errfn, void *data);
apr_status_t sed_eval_buffer(sed_eval_t *eval, const char *buf, apr_size_t bufsz, void *fout);
apr_status_t sed_eval_file(sed_eval_t *eval, apr_file_t *fin, void *fout);
apr_status_t sed_finalize_eval(sed_eval_t *eval, void *f);
void sed_destroy_eval(sed_eval_t *eval);

#ifdef __cplusplus
}
#endif

#endif /* LIBSED_H */