Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "regex/regguts.h"
00028
00029 #include "regex/regexport.h"
00030
00031 static void scancolormap(struct colormap * cm, int co,
00032 union tree * t, int level, chr partial,
00033 pg_wchar **chars, int *chars_len);
00034
00035
00036
00037
00038
00039 int
00040 pg_reg_getnumstates(const regex_t *regex)
00041 {
00042 struct cnfa *cnfa;
00043
00044 assert(regex != NULL && regex->re_magic == REMAGIC);
00045 cnfa = &((struct guts *) regex->re_guts)->search;
00046
00047 return cnfa->nstates;
00048 }
00049
00050
00051
00052
00053 int
00054 pg_reg_getinitialstate(const regex_t *regex)
00055 {
00056 struct cnfa *cnfa;
00057
00058 assert(regex != NULL && regex->re_magic == REMAGIC);
00059 cnfa = &((struct guts *) regex->re_guts)->search;
00060
00061 return cnfa->pre;
00062 }
00063
00064
00065
00066
00067 int
00068 pg_reg_getfinalstate(const regex_t *regex)
00069 {
00070 struct cnfa *cnfa;
00071
00072 assert(regex != NULL && regex->re_magic == REMAGIC);
00073 cnfa = &((struct guts *) regex->re_guts)->search;
00074
00075 return cnfa->post;
00076 }
00077
00078
00079
00080
00081
00082
00083 int
00084 pg_reg_getnumoutarcs(const regex_t *regex, int st)
00085 {
00086 struct cnfa *cnfa;
00087 struct carc *ca;
00088 int count;
00089
00090 assert(regex != NULL && regex->re_magic == REMAGIC);
00091 cnfa = &((struct guts *) regex->re_guts)->search;
00092
00093 if (st < 0 || st >= cnfa->nstates)
00094 return 0;
00095 count = 0;
00096 for (ca = cnfa->states[st]; ca->co != COLORLESS; ca++)
00097 {
00098 if (ca->co < cnfa->ncolors)
00099 count++;
00100 }
00101 return count;
00102 }
00103
00104
00105
00106
00107
00108
00109 void
00110 pg_reg_getoutarcs(const regex_t *regex, int st,
00111 regex_arc_t *arcs, int arcs_len)
00112 {
00113 struct cnfa *cnfa;
00114 struct carc *ca;
00115
00116 assert(regex != NULL && regex->re_magic == REMAGIC);
00117 cnfa = &((struct guts *) regex->re_guts)->search;
00118
00119 if (st < 0 || st >= cnfa->nstates || arcs_len <= 0)
00120 return;
00121 for (ca = cnfa->states[st]; ca->co != COLORLESS; ca++)
00122 {
00123 if (ca->co < cnfa->ncolors)
00124 {
00125 arcs->co = ca->co;
00126 arcs->to = ca->to;
00127 arcs++;
00128 if (--arcs_len == 0)
00129 break;
00130 }
00131 }
00132 }
00133
00134
00135
00136
00137 int
00138 pg_reg_getnumcolors(const regex_t *regex)
00139 {
00140 struct colormap *cm;
00141
00142 assert(regex != NULL && regex->re_magic == REMAGIC);
00143 cm = &((struct guts *) regex->re_guts)->cmap;
00144
00145 return cm->max + 1;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 int
00155 pg_reg_colorisbegin(const regex_t *regex, int co)
00156 {
00157 struct cnfa *cnfa;
00158
00159 assert(regex != NULL && regex->re_magic == REMAGIC);
00160 cnfa = &((struct guts *) regex->re_guts)->search;
00161
00162 if (co == cnfa->bos[0] || co == cnfa->bos[1])
00163 return true;
00164 else
00165 return false;
00166 }
00167
00168
00169
00170
00171 int
00172 pg_reg_colorisend(const regex_t *regex, int co)
00173 {
00174 struct cnfa *cnfa;
00175
00176 assert(regex != NULL && regex->re_magic == REMAGIC);
00177 cnfa = &((struct guts *) regex->re_guts)->search;
00178
00179 if (co == cnfa->eos[0] || co == cnfa->eos[1])
00180 return true;
00181 else
00182 return false;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 int
00196 pg_reg_getnumcharacters(const regex_t *regex, int co)
00197 {
00198 struct colormap *cm;
00199
00200 assert(regex != NULL && regex->re_magic == REMAGIC);
00201 cm = &((struct guts *) regex->re_guts)->cmap;
00202
00203 if (co <= 0 || co > cm->max)
00204 return -1;
00205 if (cm->cd[co].flags & PSEUDO)
00206 return -1;
00207
00208 return cm->cd[co].nchrs;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 void
00221 pg_reg_getcharacters(const regex_t *regex, int co,
00222 pg_wchar *chars, int chars_len)
00223 {
00224 struct colormap *cm;
00225
00226 assert(regex != NULL && regex->re_magic == REMAGIC);
00227 cm = &((struct guts *) regex->re_guts)->cmap;
00228
00229 if (co <= 0 || co > cm->max || chars_len <= 0)
00230 return;
00231 if (cm->cd[co].flags & PSEUDO)
00232 return;
00233
00234
00235 scancolormap(cm, co, cm->tree, 0, 0, &chars, &chars_len);
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 static void
00248 scancolormap(struct colormap * cm, int co,
00249 union tree * t, int level, chr partial,
00250 pg_wchar **chars, int *chars_len)
00251 {
00252 int i;
00253
00254 if (level < NBYTS - 1)
00255 {
00256
00257 for (i = 0; i < BYTTAB; i++)
00258 {
00259
00260
00261
00262
00263
00264
00265
00266 if (t->tptr[i] == &cm->tree[level + 1])
00267 continue;
00268
00269
00270 scancolormap(cm, co,
00271 t->tptr[i], level + 1,
00272 (partial | (chr) i) << BYTBITS,
00273 chars, chars_len);
00274 }
00275 }
00276 else
00277 {
00278
00279 for (i = 0; i < BYTTAB; i++)
00280 {
00281 if (t->tcolor[i] == co)
00282 {
00283 if (*chars_len > 0)
00284 {
00285 **chars = partial | (chr) i;
00286 (*chars)++;
00287 (*chars_len)--;
00288 }
00289 }
00290 }
00291 }
00292 }