~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/re/debug.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "regex.h"
 
2
 
 
3
#include "utils.h"
 
4
#include "regex2.h"
 
5
#include "debug.ih"
 
6
 
 
7
/*
 
8
 - regprint - print a regexp for debugging
 
9
 == void regprint(regex_t *r, FILE *d);
 
10
 */
 
11
void
 
12
regprint(r, d)
 
13
regex_t *r;
 
14
FILE *d;
 
15
{
 
16
     register struct re_guts *g = r->re_g;
 
17
     register int i;
 
18
     register int c;
 
19
     register int last;
 
20
     int nincat[NC];
 
21
 
 
22
     fprintf(d, "%ld states, %d categories", (long)g->nstates,
 
23
                                   g->ncategories);
 
24
     fprintf(d, ", first %ld last %ld", (long)g->firststate,
 
25
                              (long)g->laststate);
 
26
     if (g->iflags&USEBOL)
 
27
          fprintf(d, ", USEBOL");
 
28
     if (g->iflags&USEEOL)
 
29
          fprintf(d, ", USEEOL");
 
30
     if (g->iflags&BAD)
 
31
          fprintf(d, ", BAD");
 
32
     if (g->nsub > 0)
 
33
          fprintf(d, ", nsub=%ld", (long)g->nsub);
 
34
     if (g->must != NULL)
 
35
          fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen,
 
36
                                        g->must);
 
37
     if (g->backrefs)
 
38
          fprintf(d, ", backrefs");
 
39
     if (g->nplus > 0)
 
40
          fprintf(d, ", nplus %ld", (long)g->nplus);
 
41
     fprintf(d, "\n");
 
42
     s_print(g, d);
 
43
     for (i = 0; i < g->ncategories; i++) {
 
44
          nincat[i] = 0;
 
45
          for (c = CHAR_MIN; c <= CHAR_MAX; c++)
 
46
               if (g->categories[c] == i)
 
47
                    nincat[i]++;
 
48
     }
 
49
     fprintf(d, "cc0#%d", nincat[0]);
 
50
     for (i = 1; i < g->ncategories; i++)
 
51
          if (nincat[i] == 1) {
 
52
               for (c = CHAR_MIN; c <= CHAR_MAX; c++)
 
53
                    if (g->categories[c] == i)
 
54
                         break;
 
55
               fprintf(d, ", %d=%s", i, regchar(c));
 
56
          }
 
57
     fprintf(d, "\n");
 
58
     for (i = 1; i < g->ncategories; i++)
 
59
          if (nincat[i] != 1) {
 
60
               fprintf(d, "cc%d\t", i);
 
61
               last = -1;
 
62
               for (c = CHAR_MIN; c <= CHAR_MAX+1; c++)     /* +1 does flush */
 
63
                    if (c <= CHAR_MAX && g->categories[c] == i) {
 
64
                         if (last < 0) {
 
65
                              fprintf(d, "%s", regchar(c));
 
66
                              last = c;
 
67
                         }
 
68
                    } else {
 
69
                         if (last >= 0) {
 
70
                              if (last != c-1)
 
71
                                   fprintf(d, "-%s",
 
72
                                        regchar(c-1));
 
73
                              last = -1;
 
74
                         }
 
75
                    }
 
76
               fprintf(d, "\n");
 
77
          }
 
78
}
 
79
 
 
80
/*
 
81
 - s_print - print the strip for debugging
 
82
 == static void s_print(register struct re_guts *g, FILE *d);
 
83
 */
 
84
static void
 
85
s_print(g, d)
 
86
register struct re_guts *g;
 
87
FILE *d;
 
88
{
 
89
     register sop *s;
 
90
     register cset *cs;
 
91
     register int i;
 
92
     register int done = 0;
 
93
     register sop opnd;
 
94
     register int col = 0;
 
95
     register int last;
 
96
     register sopno offset = 2;
 
97
#    define    GAP()     {    if (offset % 5 == 0) { \
 
98
                         if (col > 40) { \
 
99
                              fprintf(d, "\n\t"); \
 
100
                              col = 0; \
 
101
                         } else { \
 
102
                              fprintf(d, " "); \
 
103
                              col++; \
 
104
                         } \
 
105
                    } else \
 
106
                         col++; \
 
107
                    offset++; \
 
108
               }
 
109
 
 
110
     if (OP(g->strip[0]) != OEND)
 
111
          fprintf(d, "missing initial OEND!\n");
 
112
     for (s = &g->strip[1]; !done; s++) {
 
113
          opnd = OPND(*s);
 
114
          switch (OP(*s)) {
 
115
          case OEND:
 
116
               fprintf(d, "\n");
 
117
               done = 1;
 
118
               break;
 
119
          case OCHAR:
 
120
               if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL)
 
121
                    fprintf(d, "\\%c", (char)opnd);
 
122
               else
 
123
                    fprintf(d, "%s", regchar((char)opnd));
 
124
               break;
 
125
          case OBOL:
 
126
               fprintf(d, "^");
 
127
               break;
 
128
          case OEOL:
 
129
               fprintf(d, "$");
 
130
               break;
 
131
          case OBOW:
 
132
               fprintf(d, "\\{");
 
133
               break;
 
134
          case OEOW:
 
135
               fprintf(d, "\\}");
 
136
               break;
 
137
          case OANY:
 
138
               fprintf(d, ".");
 
139
               break;
 
140
          case OANYOF:
 
141
               fprintf(d, "[(%ld)", (long)opnd);
 
142
               cs = &g->sets[opnd];
 
143
               last = -1;
 
144
               for (i = 0; i < g->csetsize+1; i++)     /* +1 flushes */
 
145
                    if (CHIN(cs, i) && i < g->csetsize) {
 
146
                         if (last < 0) {
 
147
                              fprintf(d, "%s", regchar(i));
 
148
                              last = i;
 
149
                         }
 
150
                    } else {
 
151
                         if (last >= 0) {
 
152
                              if (last != i-1)
 
153
                                   fprintf(d, "-%s",
 
154
                                        regchar(i-1));
 
155
                              last = -1;
 
156
                         }
 
157
                    }
 
158
               fprintf(d, "]");
 
159
               break;
 
160
          case OBACK_:
 
161
               fprintf(d, "(\\<%ld>", (long)opnd);
 
162
               break;
 
163
          case O_BACK:
 
164
               fprintf(d, "<%ld>\\)", (long)opnd);
 
165
               break;
 
166
          case OPLUS_:
 
167
               fprintf(d, "(+");
 
168
               if (OP(*(s+opnd)) != O_PLUS)
 
169
                    fprintf(d, "<%ld>", (long)opnd);
 
170
               break;
 
171
          case O_PLUS:
 
172
               if (OP(*(s-opnd)) != OPLUS_)
 
173
                    fprintf(d, "<%ld>", (long)opnd);
 
174
               fprintf(d, "+)");
 
175
               break;
 
176
          case OQUEST_:
 
177
               fprintf(d, "(?");
 
178
               if (OP(*(s+opnd)) != O_QUEST)
 
179
                    fprintf(d, "<%ld>", (long)opnd);
 
180
               break;
 
181
          case O_QUEST:
 
182
               if (OP(*(s-opnd)) != OQUEST_)
 
183
                    fprintf(d, "<%ld>", (long)opnd);
 
184
               fprintf(d, "?)");
 
185
               break;
 
186
          case OLPAREN:
 
187
               fprintf(d, "((<%ld>", (long)opnd);
 
188
               break;
 
189
          case ORPAREN:
 
190
               fprintf(d, "<%ld>))", (long)opnd);
 
191
               break;
 
192
          case OCH_:
 
193
               fprintf(d, "<");
 
194
               if (OP(*(s+opnd)) != OOR2)
 
195
                    fprintf(d, "<%ld>", (long)opnd);
 
196
               break;
 
197
          case OOR1:
 
198
               if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_)
 
199
                    fprintf(d, "<%ld>", (long)opnd);
 
200
               fprintf(d, "|");
 
201
               break;
 
202
          case OOR2:
 
203
               fprintf(d, "|");
 
204
               if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH)
 
205
                    fprintf(d, "<%ld>", (long)opnd);
 
206
               break;
 
207
          case O_CH:
 
208
               if (OP(*(s-opnd)) != OOR1)
 
209
                    fprintf(d, "<%ld>", (long)opnd);
 
210
               fprintf(d, ">");
 
211
               break;
 
212
          default:
 
213
               fprintf(d, "!%ld(%ld)!", OP(*s), opnd);
 
214
               break;
 
215
          }
 
216
          if (!done)
 
217
               GAP();
 
218
     }
 
219
}
 
220
 
 
221
/*
 
222
 - regchar - make a character printable
 
223
 == static char *regchar(int ch);
 
224
 */
 
225
static char *            /* -> representation */
 
226
regchar(ch)
 
227
int ch;
 
228
{
 
229
     static char buf[10];
 
230
 
 
231
     if (isprint(ch) || ch == ' ')
 
232
          sprintf(buf, "%c", ch);
 
233
     else
 
234
          sprintf(buf, "\\%o", ch);
 
235
     return(buf);
 
236
}