1 0 jyri /* 2 0 jyri * Copyright (c) 2005, 2008 Sun Microsystems, Inc. All Rights Reserved. 3 0 jyri * Use is subject to license terms. 4 0 jyri * 5 0 jyri * Copyright (c) 1984 AT&T 6 0 jyri * All Rights Reserved 7 0 jyri * 8 0 jyri * Licensed under the Apache License, Version 2.0 (the "License"); 9 0 jyri * you may not use this file except in compliance with the License. 10 0 jyri * You may obtain a copy of the License at 11 0 jyri * http://www.apache.org/licenses/LICENSE-2.0. 12 0 jyri * 13 0 jyri * Unless required by applicable law or agreed to in writing, software 14 0 jyri * distributed under the License is distributed on an "AS IS" BASIS, 15 0 jyri * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 16 0 jyri * or implied. 17 0 jyri * See the License for the specific language governing permissions and 18 0 jyri * limitations under the License. 19 0 jyri */ 20 0 jyri 21 0 jyri #ifndef LIBSED_H 22 0 jyri #define LIBSED_H 23 0 jyri 24 0 jyri #ifdef __cplusplus 25 0 jyri extern "C" { 26 0 jyri #endif 27 0 jyri 28 0 jyri #include <limits.h> 29 0 jyri 30 0 jyri #include "apr_file_io.h" 31 0 jyri #ifndef PATH_MAX 32 0 jyri #define PATH_MAX MAX_PATH 33 0 jyri #endif 34 0 jyri 35 0 jyri #define SED_NLINES 256 36 0 jyri #define SED_DEPTH 20 37 0 jyri #define SED_LABSIZE 50 38 0 jyri #define SED_ABUFSIZE 20 39 0 jyri 40 0 jyri typedef struct sed_reptr_s sed_reptr_t; 41 0 jyri 42 0 jyri struct sed_reptr_s { 43 0 jyri sed_reptr_t *next; 44 0 jyri char *ad1; 45 0 jyri char *ad2; 46 0 jyri char *re1; 47 0 jyri sed_reptr_t *lb1; 48 0 jyri char *rhs; 49 0 jyri int findex; 50 0 jyri char command; 51 0 jyri int gfl; 52 0 jyri char pfl; 53 0 jyri char negfl; 54 0 jyri int nrep; 55 0 jyri }; 56 0 jyri 57 0 jyri typedef struct sed_label_s sed_label_t; 58 0 jyri 59 0 jyri struct sed_label_s { 60 0 jyri char asc[9]; 61 0 jyri sed_reptr_t *chain; 62 0 jyri sed_reptr_t *address; 63 0 jyri }; 64 0 jyri 65 0 jyri typedef void (sed_err_fn_t)(void *data, const char *error); 66 0 jyri typedef void (sed_write_fn_t)(void *ctx, char *buf, int sz); 67 0 jyri 68 0 jyri typedef struct sed_commands_s sed_commands_t; 69 0 jyri #define NWFILES 11 /* 10 plus one for standard output */ 70 0 jyri 71 0 jyri struct sed_commands_s { 72 0 jyri sed_err_fn_t *errfn; 73 0 jyri void *data; 74 0 jyri 75 0 jyri unsigned lsize; 76 0 jyri char *linebuf; 77 0 jyri char *lbend; 78 0 jyri const char *saveq; 79 0 jyri 80 0 jyri char *cp; 81 0 jyri char *lastre; 82 0 jyri char *respace; 83 0 jyri char sseof; 84 0 jyri char *reend; 85 0 jyri const char *earg; 86 0 jyri int eflag; 87 0 jyri int gflag; 88 0 jyri int nflag; 89 0 jyri apr_int64_t tlno[SED_NLINES]; 90 0 jyri int nlno; 91 0 jyri int depth; 92 0 jyri 93 0 jyri char *fname[NWFILES]; 94 0 jyri int nfiles; 95 0 jyri 96 0 jyri sed_label_t ltab[SED_LABSIZE]; 97 0 jyri sed_label_t *labtab; 98 0 jyri sed_label_t *lab; 99 0 jyri sed_label_t *labend; 100 0 jyri 101 0 jyri sed_reptr_t **cmpend[SED_DEPTH]; 102 0 jyri sed_reptr_t *ptrspace; 103 0 jyri sed_reptr_t *ptrend; 104 0 jyri sed_reptr_t *rep; 105 0 jyri int nrep; 106 0 jyri apr_pool_t *pool; 107 4 basantk int canbefinal; 108 0 jyri }; 109 0 jyri 110 0 jyri typedef struct sed_eval_s sed_eval_t; 111 0 jyri 112 0 jyri struct sed_eval_s { 113 0 jyri sed_err_fn_t *errfn; 114 0 jyri sed_write_fn_t *writefn; 115 0 jyri void *data; 116 0 jyri 117 0 jyri sed_commands_t *commands; 118 0 jyri 119 0 jyri apr_int64_t lnum; 120 0 jyri void *fout; 121 0 jyri 122 0 jyri unsigned lsize; 123 0 jyri char *linebuf; 124 0 jyri char *lspend; 125 0 jyri 126 0 jyri unsigned hsize; 127 0 jyri char *holdbuf; 128 0 jyri char *hspend; 129 0 jyri 130 0 jyri unsigned gsize; 131 0 jyri char *genbuf; 132 0 jyri char *lcomend; 133 0 jyri 134 0 jyri apr_file_t *fcode[NWFILES]; 135 0 jyri sed_reptr_t *abuf[SED_ABUFSIZE]; 136 0 jyri sed_reptr_t **aptr; 137 0 jyri sed_reptr_t *pending; 138 0 jyri unsigned char *inar; 139 0 jyri int nrep; 140 0 jyri 141 0 jyri int dolflag; 142 0 jyri int sflag; 143 0 jyri int jflag; 144 0 jyri int delflag; 145 0 jyri int lreadyflag; 146 0 jyri int quitflag; 147 0 jyri int finalflag; 148 0 jyri int numpass; 149 0 jyri int nullmatch; 150 0 jyri int col; 151 0 jyri apr_pool_t *pool; 152 0 jyri }; 153 0 jyri 154 0 jyri apr_status_t sed_init_commands(sed_commands_t *commands, sed_err_fn_t *errfn, void *data, 155 0 jyri apr_pool_t *p); 156 0 jyri apr_status_t sed_compile_string(sed_commands_t *commands, const char *s); 157 0 jyri apr_status_t sed_compile_file(sed_commands_t *commands, apr_file_t *fin); 158 4 basantk char* sed_get_finalize_error(const sed_commands_t *commands, apr_pool_t* pool); 159 4 basantk int sed_canbe_finalized(const sed_commands_t *commands); 160 0 jyri void sed_destroy_commands(sed_commands_t *commands); 161 0 jyri 162 0 jyri apr_status_t sed_init_eval(sed_eval_t *eval, sed_commands_t *commands, 163 0 jyri sed_err_fn_t *errfn, void *data, 164 0 jyri sed_write_fn_t *writefn, apr_pool_t *p); 165 0 jyri apr_status_t sed_reset_eval(sed_eval_t *eval, sed_commands_t *commands, sed_err_fn_t *errfn, void *data); 166 0 jyri apr_status_t sed_eval_buffer(sed_eval_t *eval, const char *buf, int bufsz, void *fout); 167 0 jyri apr_status_t sed_eval_file(sed_eval_t *eval, apr_file_t *fin, void *fout); 168 0 jyri apr_status_t sed_finalize_eval(sed_eval_t *eval, void *f); 169 0 jyri void sed_destroy_eval(sed_eval_t *eval); 170 0 jyri 171 0 jyri #ifdef __cplusplus 172 0 jyri } 173 0 jyri #endif 174 0 jyri 175 0 jyri #endif /* LIBSED_H */ 176