blob: 6959f054433e7fa970d12484564ef93832fd6562 (
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
|
/* _______ ____ __ ___ ___
* \ _ \ \ / \ / \ \ / / ' ' '
* | | \ \ | | || | \/ | . .
* | | | | | | || ||\ /| |
* | | | | | | || || \/ | | ' ' '
* | | | | | | || || | | . .
* | |_/ / \ \__// || | |
* /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque
* / \
* / . \
* itorder.c - Code to fix invalid patterns in / / \ \
* the pattern table. | < / \_
* | \/ /\ /
* By Julien Cugniere. \_ / > /
* | \ / /
* | ' /
* \__/
*/
#include <stdlib.h>
#include "dumb.h"
#include "internal/it.h"
/* This function ensures that any pattern mentioned in the order table but
* not present in the pattern table is treated as an empty 64 rows pattern.
* This is done by adding such a dummy pattern at the end of the pattern
* table, and redirect invalid orders to it.
* Patterns 254 and 255 are left untouched, unless the signal is an XM.
*/
int _dumb_it_fix_invalid_orders(DUMB_IT_SIGDATA *sigdata)
{
int i;
int found_some = 0;
int first_invalid = sigdata->n_patterns;
int last_invalid = (sigdata->flags & IT_WAS_AN_XM) ? 255 : 253;
for (i = 0; i < sigdata->n_orders; i++) {
if (sigdata->order[i] >= first_invalid && sigdata->order[i] <= last_invalid) {
sigdata->order[i] = sigdata->n_patterns;
found_some = 1;
}
}
if (found_some) {
IT_PATTERN *new_pattern = realloc(sigdata->pattern, sizeof(*sigdata->pattern) * (sigdata->n_patterns + 1));
if (!new_pattern)
return -1;
new_pattern[sigdata->n_patterns].n_rows = 64;
new_pattern[sigdata->n_patterns].n_entries = 0;
new_pattern[sigdata->n_patterns].entry = NULL;
sigdata->pattern = new_pattern;
sigdata->n_patterns++;
}
return 0;
}
|