Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 96702 | Differences between
and this patch

Collapse All | Expand All

(-)table.c (-31 / +71 lines)
Lines 41-58 Link Here
41
	(((__c) < (VTE_TABLE_MAX_LITERAL)) ? (__c) : 0)
41
	(((__c) < (VTE_TABLE_MAX_LITERAL)) ? (__c) : 0)
42
#define _vte_table_is_numeric(__c) \
42
#define _vte_table_is_numeric(__c) \
43
	(((__c) >= '0') && ((__c) <= '9'))
43
	(((__c) >= '0') && ((__c) <= '9'))
44
enum _vte_table_specials {
44
45
	_vte_table_string = VTE_TABLE_MAX_LITERAL,
46
	_vte_table_number,
47
	_vte_table_max
48
};
49
struct _vte_table {
45
struct _vte_table {
50
	GQuark resultq;
46
	GQuark resultq;
51
	const char *result;
47
	const char *result;
52
	unsigned char *original;
48
	unsigned char *original;
53
	gssize original_length;
49
	gssize original_length;
54
	int increment;
50
	int increment;
55
	struct _vte_table *table[_vte_table_max];
51
	struct _vte_table *table_string;
52
	struct _vte_table *table_number;
53
	struct _vte_table **table;
56
};
54
};
57
55
58
/* Argument info. */
56
/* Argument info. */
Lines 74-89 _vte_table_new(void) Link Here
74
	return g_malloc0(sizeof(struct _vte_table));
72
	return g_malloc0(sizeof(struct _vte_table));
75
}
73
}
76
74
75
struct _vte_table **
76
_vte_table_literal_new(void)
77
{
78
	return g_malloc0(sizeof(struct _vte_table *) * VTE_TABLE_MAX_LITERAL);
79
}
80
77
/* Free a table. */
81
/* Free a table. */
78
void
82
void
79
_vte_table_free(struct _vte_table *table)
83
_vte_table_free(struct _vte_table *table)
80
{
84
{
81
	unsigned int i;
85
	unsigned int i;
82
	for (i = 0; i < G_N_ELEMENTS(table->table); i++) {
86
	if (table->table != NULL) {
83
		if (table->table[i] != NULL) {
87
		for (i = 0; i < VTE_TABLE_MAX_LITERAL; i++) {
84
			_vte_table_free(table->table[i]);
88
			if (table->table[i] != NULL) {
85
			table->table[i] = NULL;
89
				_vte_table_free(table->table[i]);
90
				table->table[i] = NULL;
91
			}
86
		}
92
		}
93
		g_free(table->table);
94
	}
95
	if (table->table_string != NULL) {
96
		_vte_table_free(table->table_string);
97
	}
98
	if (table->table_number != NULL) {
99
		_vte_table_free(table->table_number);
87
	}
100
	}
88
	if (table->original_length == 0) {
101
	if (table->original_length == 0) {
89
		g_assert(table->original == NULL);
102
		g_assert(table->original == NULL);
Lines 153-163 _vte_table_addi(struct _vte_table *table Link Here
153
		    (pattern[1] == '2') ||
166
		    (pattern[1] == '2') ||
154
		    (pattern[1] == '3')) {
167
		    (pattern[1] == '3')) {
155
			/* Create a new subtable. */
168
			/* Create a new subtable. */
156
			if (table->table[_vte_table_number] == NULL) {
169
			if (table->table_number == NULL) {
157
				subtable = _vte_table_new();
170
				subtable = _vte_table_new();
158
				table->table[_vte_table_number] = subtable;
171
				table->table_number = subtable;
159
			} else {
172
			} else {
160
				subtable = table->table[_vte_table_number];
173
				subtable = table->table_number;
161
			}
174
			}
162
			/* Add the rest of the string to the subtable. */
175
			/* Add the rest of the string to the subtable. */
163
			_vte_table_addi(subtable, original, original_length,
176
			_vte_table_addi(subtable, original, original_length,
Lines 213-223 _vte_table_addi(struct _vte_table *table Link Here
213
			/* It must have a terminator. */
226
			/* It must have a terminator. */
214
			g_assert(length >= 3);
227
			g_assert(length >= 3);
215
			/* Create a new subtable. */
228
			/* Create a new subtable. */
216
			if (table->table[_vte_table_string] == NULL) {
229
			if (table->table_string == NULL) {
217
				subtable = _vte_table_new();
230
				subtable = _vte_table_new();
218
				table->table[_vte_table_string] = subtable;
231
				table->table_string = subtable;
219
			} else {
232
			} else {
220
				subtable = table->table[_vte_table_string];
233
				subtable = table->table_string;
221
			}
234
			}
222
			/* Add the rest of the string to the subtable. */
235
			/* Add the rest of the string to the subtable. */
223
			_vte_table_addi(subtable, original, original_length,
236
			_vte_table_addi(subtable, original, original_length,
Lines 229-234 _vte_table_addi(struct _vte_table *table Link Here
229
		/* Handle an escaped '%'. */
242
		/* Handle an escaped '%'. */
230
		if (pattern[1] == '%') {
243
		if (pattern[1] == '%') {
231
			/* Create a new subtable. */
244
			/* Create a new subtable. */
245
			if (table->table == NULL) {
246
				table->table = _vte_table_literal_new();
247
				subtable = _vte_table_new();
248
				table->table['%'] = subtable;
249
			} else
232
			if (table->table['%'] == NULL) {
250
			if (table->table['%'] == NULL) {
233
				subtable = _vte_table_new();
251
				subtable = _vte_table_new();
234
				table->table['%'] = subtable;
252
				table->table['%'] = subtable;
Lines 250-255 _vte_table_addi(struct _vte_table *table Link Here
250
			 * character value. */
268
			 * character value. */
251
			for (i = pattern[2]; i < VTE_TABLE_MAX_LITERAL; i++) {
269
			for (i = pattern[2]; i < VTE_TABLE_MAX_LITERAL; i++) {
252
				/* Create a new subtable. */
270
				/* Create a new subtable. */
271
				if (table->table == NULL) {
272
					table->table = _vte_table_literal_new();
273
					subtable = _vte_table_new();
274
					table->table[i] = subtable;
275
				} else
253
				if (table->table[i] == NULL) {
276
				if (table->table[i] == NULL) {
254
					subtable = _vte_table_new();
277
					subtable = _vte_table_new();
255
					table->table[i] = subtable;
278
					table->table[i] = subtable;
Lines 263-268 _vte_table_addi(struct _vte_table *table Link Here
263
						result, quark, inc);
286
						result, quark, inc);
264
			}
287
			}
265
			/* Also add a subtable for higher characters. */
288
			/* Also add a subtable for higher characters. */
289
			if (table->table == NULL) {
290
				table->table = _vte_table_literal_new();
291
				subtable = _vte_table_new();
292
				table->table[0] = subtable;
293
			} else
266
			if (table->table[0] == NULL) {
294
			if (table->table[0] == NULL) {
267
				subtable = _vte_table_new();
295
				subtable = _vte_table_new();
268
				table->table[0] = subtable;
296
				table->table[0] = subtable;
Lines 280-285 _vte_table_addi(struct _vte_table *table Link Here
280
	/* A literal (or an unescaped '%', which is also a literal). */
308
	/* A literal (or an unescaped '%', which is also a literal). */
281
	check = (guint8) pattern[0];
309
	check = (guint8) pattern[0];
282
	g_assert(check < VTE_TABLE_MAX_LITERAL);
310
	g_assert(check < VTE_TABLE_MAX_LITERAL);
311
	if (table->table == NULL) {
312
		table->table = _vte_table_literal_new();
313
		subtable = _vte_table_new();
314
		table->table[check] = subtable;
315
	} else
283
	if (table->table[check] == NULL) {
316
	if (table->table[check] == NULL) {
284
		subtable = _vte_table_new();
317
		subtable = _vte_table_new();
285
		table->table[check] = subtable;
318
		table->table[check] = subtable;
Lines 334-344 _vte_table_matchi(struct _vte_table *tab Link Here
334
	}
367
	}
335
368
336
	/* Check if this node has a string disposition. */
369
	/* Check if this node has a string disposition. */
337
	if (table->table[_vte_table_string] != NULL) {
370
	if (table->table_string != NULL) {
338
		/* Iterate over all non-terminator values. */
371
		/* Iterate over all non-terminator values. */
339
		subtable = table->table[_vte_table_string];
372
		subtable = table->table_string;
340
		for (i = 0; i < length; i++) {
373
		for (i = 0; i < length; i++) {
341
			if (subtable->table[_vte_table_map_literal(candidate[i])] != NULL) {
374
			if ((subtable->table != NULL) &&
375
			    (subtable->table[_vte_table_map_literal(candidate[i])] != NULL)) {
342
				break;
376
				break;
343
			}
377
			}
344
		}
378
		}
Lines 356-363 _vte_table_matchi(struct _vte_table *tab Link Here
356
390
357
	/* Check if this could be a number. */
391
	/* Check if this could be a number. */
358
	if ((_vte_table_is_numeric(candidate[0])) &&
392
	if ((_vte_table_is_numeric(candidate[0])) &&
359
	    (table->table[_vte_table_number] != NULL)) {
393
	    (table->table_number != NULL)) {
360
		subtable = table->table[_vte_table_number];
394
		subtable = table->table_number;
361
		/* Iterate over all numeric characters. */
395
		/* Iterate over all numeric characters. */
362
		for (i = 0; i < length; i++) {
396
		for (i = 0; i < length; i++) {
363
			if (!_vte_table_is_numeric(candidate[i])) {
397
			if (!_vte_table_is_numeric(candidate[i])) {
Lines 377-383 _vte_table_matchi(struct _vte_table *tab Link Here
377
	}
411
	}
378
412
379
	/* Check for an exact match. */
413
	/* Check for an exact match. */
380
	if (table->table[_vte_table_map_literal(candidate[0])] != NULL) {
414
	if ((table->table != NULL) &&
415
	    (table->table[_vte_table_map_literal(candidate[0])] != NULL)) {
381
		subtable = table->table[_vte_table_map_literal(candidate[0])];
416
		subtable = table->table[_vte_table_map_literal(candidate[0])];
382
		/* Save the parameter info. */
417
		/* Save the parameter info. */
383
		arginfo = g_malloc(sizeof(struct _vte_table_arginfo));
418
		arginfo = g_malloc(sizeof(struct _vte_table_arginfo));
Lines 526-535 _vte_table_match(struct _vte_table *tabl Link Here
526
561
527
	/* If there's no literal path, and no generic path, and the numeric
562
	/* If there's no literal path, and no generic path, and the numeric
528
	 * path isn't available, then it's not a sequence, either. */
563
	 * path isn't available, then it's not a sequence, either. */
529
	if (table->table[_vte_table_map_literal(candidate[0])] == NULL) {
564
	if ((table->table == NULL) ||
530
		if (table->table[_vte_table_string] == NULL) {
565
	    (table->table[_vte_table_map_literal(candidate[0])] == NULL)) {
566
		if (table->table_string == NULL) {
531
			if (!(_vte_table_is_numeric(candidate[0])) ||
567
			if (!(_vte_table_is_numeric(candidate[0])) ||
532
			    (table->table[_vte_table_number] == NULL)) {
568
			    (table->table_number == NULL)) {
533
				/* No match. */
569
				/* No match. */
534
				return NULL;
570
				return NULL;
535
			}
571
			}
Lines 538-544 _vte_table_match(struct _vte_table *tabl Link Here
538
574
539
	/* Check for a literal match. */
575
	/* Check for a literal match. */
540
	for (i = 0, head = table; (i < length) && (head != NULL); i++) {
576
	for (i = 0, head = table; (i < length) && (head != NULL); i++) {
541
		head = head->table[_vte_table_map_literal(candidate[i])];
577
		if (head->table == NULL) {
578
			head = NULL;
579
		} else {
580
			head = head->table[_vte_table_map_literal(candidate[i])];
581
		}
542
	}
582
	}
543
	if ((head != NULL) && (head->result != NULL)) {
583
	if ((head != NULL) && (head->result != NULL)) {
544
		/* Got a literal match. */
584
		/* Got a literal match. */
Lines 645-651 _vte_table_printi(struct _vte_table *tab Link Here
645
685
646
	/* Literal? */
686
	/* Literal? */
647
	for (i = 1; i < VTE_TABLE_MAX_LITERAL; i++) {
687
	for (i = 1; i < VTE_TABLE_MAX_LITERAL; i++) {
648
		if (table->table[i] != NULL) {
688
		if ((table->table != NULL) && (table->table[i] != NULL)) {
649
			if (i < 32) {
689
			if (i < 32) {
650
				newlead = g_strdup_printf("%s^%c", lead,
690
				newlead = g_strdup_printf("%s^%c", lead,
651
							  i + 64);
691
							  i + 64);
Lines 658-674 _vte_table_printi(struct _vte_table *tab Link Here
658
	}
698
	}
659
699
660
	/* String? */
700
	/* String? */
661
	if (table->table[_vte_table_string] != NULL) {
701
	if (table->table_string != NULL) {
662
		newlead = g_strdup_printf("%s{string}", lead);
702
		newlead = g_strdup_printf("%s{string}", lead);
663
		_vte_table_printi(table->table[_vte_table_string],
703
		_vte_table_printi(table->table_string,
664
				  newlead, count);
704
				  newlead, count);
665
		g_free(newlead);
705
		g_free(newlead);
666
	}
706
	}
667
707
668
	/* Number(+)? */
708
	/* Number(+)? */
669
	if (table->table[_vte_table_number] != NULL) {
709
	if (table->table_number != NULL) {
670
		newlead = g_strdup_printf("%s{number}", lead);
710
		newlead = g_strdup_printf("%s{number}", lead);
671
		_vte_table_printi(table->table[_vte_table_number],
711
		_vte_table_printi(table->table_number,
672
				  newlead, count);
712
				  newlead, count);
673
		g_free(newlead);
713
		g_free(newlead);
674
	}
714
	}

Return to bug 96702