Clean up jenny's whitespace.

This commit is contained in:
John Ralls 2018-07-23 12:48:52 -07:00
parent 40680369f6
commit 1131aa6fc4

View File

@ -227,14 +227,14 @@ wchain *wc) /* restrictions */
while (i<w->len) {
int dimension_match = FALSE; /* match in this dimension */
do {
if (t->f[w->fe[i].d] == w->fe[i].f) {
dimension_match = TRUE;
}
++i;
if (t->f[w->fe[i].d] == w->fe[i].f) {
dimension_match = TRUE;
}
++i;
} while (i<w->len && (w->fe[i].d == w->fe[i-1].d));
if (!dimension_match) {
match = FALSE;
break;
match = FALSE;
break;
}
}
if (match) {
@ -326,10 +326,10 @@ cleanup(state *s)
ub2 d,f;
for (d=0; d<s->ndim; ++d) {
if (s->tu[d]) {
for (f=0; f<s->dim[d]; ++f) {
truncate_tuple(&s->tu[d][f], &s->tc[d][f]);
}
my_free((char *)s->tu[d]);
for (f=0; f<s->dim[d]; ++f) {
truncate_tuple(&s->tu[d][f], &s->tc[d][f]);
}
my_free((char *)s->tu[d]);
}
}
my_free((char *)s->tu);
@ -340,7 +340,7 @@ cleanup(state *s)
ub2 d;
for (d=0; d<s->ndim; ++d) {
if (s->n[d]) {
my_free((char *)s->n[d]);
my_free((char *)s->n[d]);
}
}
my_free((char *)s->n);
@ -351,7 +351,7 @@ cleanup(state *s)
ub2 d;
for (d=0; d<s->ndim; ++d) {
if (s->tc[d]) {
my_free((char *)s->tc[d]);
my_free((char *)s->tc[d]);
}
}
my_free((char *)s->tc);
@ -362,9 +362,9 @@ cleanup(state *s)
ub2 i;
for (i=0; i<s->ndim; ++i) {
while (s->wc[i]) {
wchain *wc = s->wc[i];
s->wc[i] = s->wc[i]->next;
my_free((char *)wc);
wchain *wc = s->wc[i];
s->wc[i] = s->wc[i]->next;
my_free((char *)wc);
}
}
my_free((char *)s->wc);
@ -571,7 +571,7 @@ subset_tuple( feature *t1, ub1 n1, feature *t2, ub1 n2)
for (i=0, j=0; i<n1; ++i) {
while (t1[i].d > t2[j].d) {
if (++j == n2)
return FALSE;
return FALSE;
}
if (t1[i].d != t2[j].d || t1[i].f != t2[j].f) {
return FALSE;
@ -648,7 +648,7 @@ parse_token(char *inp, ub4 inl, ub4 *curr, ub4 *rsl)
for (i=*curr+1; i < inl; ++i) {
mychar = inp[i];
if (!(mychar == ' ' || mychar == '\t' || mychar == '\n'))
break;
break;
}
*curr = i;
return TOKEN_SPACE;
@ -662,16 +662,16 @@ parse_token(char *inp, ub4 inl, ub4 *curr, ub4 *rsl)
*rsl = number;
return TOKEN_NUMBER;
} else if ((mychar >= 'a' && mychar <= 'z') ||
(mychar >= 'A' && mychar <= 'Z')) {
(mychar >= 'A' && mychar <= 'Z')) {
/*------------------------------------------------- parse a feature name */
ub4 i;
for (i=0; i<MAX_FEATURES; ++i)
if (feature_name[i] == mychar)
break;
break;
if (i == MAX_FEATURES) {
printf("jenny: the name '%c' is not used for any feature\n",
mychar);
return TOKEN_ERROR;
mychar);
return TOKEN_ERROR;
}
*rsl = i;
++*curr;
@ -715,25 +715,25 @@ load( state *s, char *testfile)
for (i=0; i<s->ndim; ++i) {
if (parse_token(buf, UB4MAXVAL, &curr, &value) != TOKEN_SPACE) {
printf("jenny: -o, non-space found where space expected\n");
goto failure;
printf("jenny: -o, non-space found where space expected\n");
goto failure;
}
if (parse_token(buf, UB4MAXVAL, &curr, &value) != TOKEN_NUMBER) {
printf("jenny: -o, non-number found where number expected\n");
goto failure;
printf("jenny: -o, non-number found where number expected\n");
goto failure;
}
if (value-1 != i) {
printf("jenny: -o, number %lu found out-of-place\n", value);
goto failure;
printf("jenny: -o, number %lu found out-of-place\n", value);
goto failure;
}
if (parse_token(buf, UB4MAXVAL, &curr, &value) != TOKEN_FEATURE) {
printf("jenny: -o, non-feature found where feature expected\n");
goto failure;
printf("jenny: -o, non-feature found where feature expected\n");
goto failure;
}
if (value >= s->dim[i]) {
printf("jenny: -o, feature %c does not exist in dimension %lu\n",
feature_name[value], i+1);
goto failure;
printf("jenny: -o, feature %c does not exist in dimension %lu\n",
feature_name[value], i+1);
goto failure;
}
t->f[i] = value;
}
@ -816,7 +816,7 @@ parse_n( state *s, char *myarg)
}
if (temp > s->ndim) {
printf("jenny: -n, %ld-tuples are impossible with only %d dimensions\n",
temp, s->ndim);
temp, s->ndim);
return FALSE;
}
s->n_final = (ub2)temp;
@ -858,7 +858,7 @@ parse_w( state *s, sb1 *myarg)
}
if (used[dimension_number]) {
printf("jenny: -w, dimension %lu was given twice in a single without\n",
dimension_number+1);
dimension_number+1);
return FALSE;
}
used[dimension_number] = TRUE;
@ -878,14 +878,14 @@ parse_w( state *s, sb1 *myarg)
feature:
if (value >= s->dim[dimension_number]) {
printf("jenny: -w, there is no feature '%c' in dimension %lu\n",
feature_name[value], dimension_number+1);
feature_name[value], dimension_number+1);
return FALSE;
}
fe[fe_len].d = dimension_number;
fe[fe_len].f = value;
if (++fe_len >= MAX_WITHOUT) {
printf("jenny: -w, at most %d features in a single without\n",
MAX_WITHOUT);
MAX_WITHOUT);
return FALSE;
}
@ -906,14 +906,14 @@ parse_w( state *s, sb1 *myarg)
for (i=0; i<fe_len; ++i) {
for (j=i+1; j<fe_len; ++j) {
if ((fe[i].d > fe[j].d) ||
((fe[i].d == fe[j].d) && (fe[i].f > fe[j].f))) {
ub2 fe_temp;
fe_temp = fe[i].d;
fe[i].d = fe[j].d;
fe[j].d = fe_temp;
fe_temp = fe[i].f;
fe[i].f = fe[j].f;
fe[j].f = fe_temp;
((fe[i].d == fe[j].d) && (fe[i].f > fe[j].f))) {
ub2 fe_temp;
fe_temp = fe[i].d;
fe[i].d = fe[j].d;
fe[j].d = fe_temp;
fe_temp = fe[i].f;
fe[i].f = fe[j].f;
fe[j].f = fe_temp;
}
}
}
@ -1002,11 +1002,11 @@ preliminary( state *s)
int i;
for (i=0; i<w->len; ++i) {
if (w->fe[i].d != old) {
wchain *wcx = (wchain *)my_alloc( s, sizeof(wchain));
wcx->w = w;
wcx->next = s->wc[w->fe[i].d];
s->wc[w->fe[i].d] = wcx;
old = w->fe[i].d;
wchain *wcx = (wchain *)my_alloc( s, sizeof(wchain));
wcx->w = w;
wcx->next = s->wc[w->fe[i].d];
s->wc[w->fe[i].d] = wcx;
old = w->fe[i].d;
}
}
}
@ -1034,7 +1034,7 @@ parse( int argc, char *argv[], state *s)
}
if (temp > MAX_DIMENSIONS) {
printf("jenny: maximum number of dimensions is %d. %ld is too many.\n",
MAX_DIMENSIONS, temp);
MAX_DIMENSIONS, temp);
return FALSE;
}
s->ndim = (ub2)temp;
@ -1049,18 +1049,18 @@ parse( int argc, char *argv[], state *s)
(void)parse_token(myarg, UB4MAXVAL, &curr, &temp);
if (parse_token(myarg, UB4MAXVAL, &curr, &dummy) != TOKEN_END) {
printf("jenny: something was trailing a dimension number\n");
return FALSE;
printf("jenny: something was trailing a dimension number\n");
return FALSE;
}
if (temp > MAX_FEATURES) {
printf("jenny: dimensions must be smaller than %d. %ld is too big.\n",
MAX_FEATURES, temp);
return FALSE;
printf("jenny: dimensions must be smaller than %d. %ld is too big.\n",
MAX_FEATURES, temp);
return FALSE;
}
if (temp < 2) {
printf("jenny: a dimension must have at least 2 features, not %lu\n",
temp);
return FALSE;
printf("jenny: a dimension must have at least 2 features, not %lu\n",
temp);
return FALSE;
}
s->dim[j++] = (ub2)temp;
} else if (argv[i][1] == 'h') {
@ -1092,14 +1092,14 @@ parse( int argc, char *argv[], state *s)
break;
default:
printf("jenny: legal arguments are numbers, -n, -s, -w, -h, not -%c\n",
argv[i][1]);
argv[i][1]);
return FALSE;
}
} /* for (each argument) if '-' */
if (s->n_final > s->ndim) {
printf("jenny: %hhu-tuples are impossible with only %hu dimensions\n",
s->n_final, s->ndim);
s->n_final, s->ndim);
return FALSE;
}
@ -1153,8 +1153,8 @@ next_builder( state *s, feature *tuple, ub1 n)
sb4 i = n;
while (i-- &&
tuple[i].d == s->ndim-n+i &&
tuple[i].f == s->dim[tuple[i].d]-1)
tuple[i].d == s->ndim-n+i &&
tuple[i].f == s->dim[tuple[i].d]-1)
;
if (i == -1)
return FALSE;
@ -1221,19 +1221,19 @@ build_tuples( state *s, ub2 d, ub2 f)
s->tuple_tester->f[tuple[i].d] = tuple[i].f;
}
if (count_withouts(s->tuple_tester, s->wc2) ||
count_withouts(s->tuple_tester, s->wc3))
count_withouts(s->tuple_tester, s->wc3))
goto make_next_tuple;
/* is this tuple covered by the existing tests? */
for (j=0; j<s->ntests; ++j) {
test *t = s->t[j];
for (i=0; i<n; ++i) {
if (t->f[tuple[i].d] != tuple[i].f) {
break;
}
if (t->f[tuple[i].d] != tuple[i].f) {
break;
}
}
if (i == n) {
goto make_next_tuple;
goto make_next_tuple;
}
}
@ -1319,31 +1319,31 @@ ub1 *mut) /* mut[i] = 1 if I am allowed to adjust dimension i */
/* test every feature of this dimension, trying to make progress */
for (k=0; k<s->dim[mydim]; ++k) {
ub2 newcount;
t->f[mydim] = k;
newcount = count_withouts(t, s->wc[mydim]);
if (newcount <= count) {
if (newcount < count) {
i = 0; /* partial progress! */
fcount = 0;
count = newcount;
}
best[fcount++] = k;
}
ub2 newcount;
t->f[mydim] = k;
newcount = count_withouts(t, s->wc[mydim]);
if (newcount <= count) {
if (newcount < count) {
i = 0; /* partial progress! */
fcount = 0;
count = newcount;
}
best[fcount++] = k;
}
}
/* choose one of the best features for this dimension at random */
if (fcount == 0) {
printf("jenny: internal error a\n");
printf("jenny: internal error a\n");
} else if (fcount == 1) {
t->f[mydim] = best[0];
t->f[mydim] = best[0];
} else {
temp = (flearand(&s->r) % fcount);
t->f[mydim] = best[temp];
temp = (flearand(&s->r) % fcount);
t->f[mydim] = best[temp];
}
if (count > 0)
ok = FALSE;
ok = FALSE;
}
if (ok) { /* no withouts disobeyed */
return TRUE;
@ -1409,24 +1409,24 @@ ub1 n) /* size of smallest tuple left to cover */
/* for every feature in mydim, see if using it would improve coverage */
for (f=0; f<s->dim[d]; ++f) {
t->f[d] = f; /* switch to the new feature */
if (!count_withouts(t, s->wc[d])) { /* need to obey withouts */
ub4 new_coverage = count_tuples(s, t, d, f);
if (s->n[d][f] < best_n) {
best_n = s->n[d][f];
progress = TRUE;
coverage = new_coverage;
count = 0;
best[count++] = f;
} else if (s->n[d][f] == best_n && new_coverage >= coverage) {
if (new_coverage > coverage) {
progress = TRUE;
coverage = new_coverage;
count = 0;
}
best[count++] = f;
}
}
t->f[d] = f; /* switch to the new feature */
if (!count_withouts(t, s->wc[d])) { /* need to obey withouts */
ub4 new_coverage = count_tuples(s, t, d, f);
if (s->n[d][f] < best_n) {
best_n = s->n[d][f];
progress = TRUE;
coverage = new_coverage;
count = 0;
best[count++] = f;
} else if (s->n[d][f] == best_n && new_coverage >= coverage) {
if (new_coverage > coverage) {
progress = TRUE;
coverage = new_coverage;
count = 0;
}
best[count++] = f;
}
}
}
/*
@ -1436,14 +1436,14 @@ ub1 n) /* size of smallest tuple left to cover */
* will be hit.
*/
if (count == 0) {
printf("jenny: internal error b\n");
printf("jenny: internal error b\n");
} else if (count == 1) {
t->f[d] = best[0];
t->f[d] = best[0];
} else {
t->f[d] = best[flearand(&s->r) % count];
t->f[d] = best[flearand(&s->r) % count];
}
if (s->n[d][t->f[d]] == n)
total += coverage;
total += coverage;
}
} while (progress);
@ -1482,7 +1482,7 @@ generate_test( state *s, test *t, feature *tuple, ub1 n)
/* If we can get all the withouts obeyed, break, success */
if (!s->wc2 || obey_withouts(s, t, mut)) {
if (count_withouts(t, s->wc2)) {
printf("internal error without %p\n", s->wc2);
printf("internal error without %p\n", s->wc2);
}
break;
}
@ -1526,27 +1526,27 @@ cover_tuples( state *s)
for (d=0; d<s->ndim; ++d) {
ub2 f;
for (f=0; f<s->dim[d]; ++f) {
build_tuples(s, d, f);
if (s->n[d][f] < tuple_n) {
tuple_n = s->n[d][f];
tuple_count = s->tc[d][f];
tuple = s->tu[d][f]->fe;
tuple_f = f;
tuple_d = d;
} else if (s->n[d][f] == tuple_n && s->tc[d][f] > tuple_count) {
tuple_count = s->tc[d][f];
tuple = s->tu[d][f]->fe;
tuple_f = f;
tuple_d = d;
}
build_tuples(s, d, f);
if (s->n[d][f] < tuple_n) {
tuple_n = s->n[d][f];
tuple_count = s->tc[d][f];
tuple = s->tu[d][f]->fe;
tuple_f = f;
tuple_d = d;
} else if (s->n[d][f] == tuple_n && s->tc[d][f] > tuple_count) {
tuple_count = s->tc[d][f];
tuple = s->tu[d][f]->fe;
tuple_f = f;
tuple_d = d;
}
}
}
if (tuple_count == 0) {
if (tuple_n == s->n_final)
break; /* no more tuples to cover, done! */
break; /* no more tuples to cover, done! */
else
continue;
continue;
}
@ -1560,17 +1560,17 @@ cover_tuples( state *s)
/* generate a test that covers the first tuple */
if (!(this_count = generate_test(s, curr_test, tuple, tuple_n))) {
continue;
continue;
}
covered = TRUE;
/* see how many tuples are covered altogether */
if (this_count > best_count) {
test *temp = best_test;
best_test = curr_test;
curr_test = temp;
test *temp = best_test;
best_test = curr_test;
curr_test = temp;
best_count = this_count;
best_count = this_count;
}
}
@ -1581,8 +1581,8 @@ cover_tuples( state *s)
/* make a copy of tuple, because we'll be deleting it */
for (i=0; i<tuple_n; ++i) {
extra[i].d = tuple[i].d;
extra[i].f = tuple[i].f;
extra[i].d = tuple[i].d;
extra[i].f = tuple[i].f;
}
printf("Could not cover tuple ");
@ -1596,56 +1596,56 @@ cover_tuples( state *s)
w->len = tuple_n;
w->fe = (feature *)my_alloc( s, sizeof(feature)*tuple_n);
for (i=0; i<tuple_n; ++i) {
w->fe[i].d = extra[i].d;
w->fe[i].f = extra[i].f;
w->fe[i].d = extra[i].d;
w->fe[i].f = extra[i].f;
}
for (d=0; d<s->ndim; ++d) {
ub2 f;
tu_iter ctx;
for (f=0; f<s->dim[d]; ++f) {
ub1 n = s->n[d][f];
feature *this = start_tuple(&ctx, &s->tu[d][f], n, &s->tc[d][f]);
ub2 f;
tu_iter ctx;
for (f=0; f<s->dim[d]; ++f) {
ub1 n = s->n[d][f];
feature *this = start_tuple(&ctx, &s->tu[d][f], n, &s->tc[d][f]);
/* remove all the tuples covered by it */
while (this) {
if (subset_tuple(extra, tuple_n, this, n)) {
this = delete_tuple(&ctx);
} else {
this = next_tuple(&ctx);
}
}
}
/* remove all the tuples covered by it */
while (this) {
if (subset_tuple(extra, tuple_n, this, n)) {
this = delete_tuple(&ctx);
} else {
this = next_tuple(&ctx);
}
}
}
}
my_free((char *)best_test->f);
my_free((char *)best_test);
} else {
ub2 d;
for (d=0; d<s->ndim; ++d) {
tu_iter ctx;
ub2 f = best_test->f[d];
ub1 n = s->n[d][f];
feature *this = start_tuple(&ctx, &s->tu[d][f], n, &s->tc[d][f]);
tu_iter ctx;
ub2 f = best_test->f[d];
ub1 n = s->n[d][f];
feature *this = start_tuple(&ctx, &s->tu[d][f], n, &s->tc[d][f]);
/* remove all the tuples covered by it */
while (this) {
if (test_tuple(best_test->f, this, n)) {
this = delete_tuple(&ctx);
} else {
this = next_tuple(&ctx);
}
}
/* remove all the tuples covered by it */
while (this) {
if (test_tuple(best_test->f, this, n)) {
this = delete_tuple(&ctx);
} else {
this = next_tuple(&ctx);
}
}
}
/* add it to the list of tests */
if (!add_test(s, best_test)) {
printf("jenny: exceeded maximum number of tests\n");
my_free((char *)curr_test->f);
my_free((char *)curr_test);
my_free((char *)best_test->f);
my_free((char *)best_test);
cleanup(s);
exit(0);
printf("jenny: exceeded maximum number of tests\n");
my_free((char *)curr_test->f);
my_free((char *)curr_test);
my_free((char *)best_test->f);
my_free((char *)best_test);
cleanup(s);
exit(0);
}
}
}
@ -1678,16 +1678,16 @@ prepare_reduce( state *s)
s->tuple_tester->f[tuple[i].d] = tuple[i].f;
}
if (count_withouts(s->tuple_tester, s->wc2) ||
count_withouts(s->tuple_tester, s->wc3))
count_withouts(s->tuple_tester, s->wc3))
goto make_next_tuple;
for (i=0; i<s->ntests; ++i) {
ub1 j;
for (j=0; j<n; ++j)
if (s->t[i]->f[tuple[j].d] != tuple[j].f)
break;
if (s->t[i]->f[tuple[j].d] != tuple[j].f)
break;
if (j == n)
break; /* this test contains this tuple */
break; /* this test contains this tuple */
}
/* no tests cover this tuple */
@ -1696,21 +1696,21 @@ prepare_reduce( state *s)
} else {
thistest = i;
for (++i; i<s->ntests; ++i) {
ub1 j;
for (j=0; j<n; ++j)
if (s->t[i]->f[tuple[j].d] != tuple[j].f)
break;
if (j == n)
break; /* this test contains this tuple */
ub1 j;
for (j=0; j<n; ++j)
if (s->t[i]->f[tuple[j].d] != tuple[j].f)
break;
if (j == n)
break; /* this test contains this tuple */
}
if (i == s->ntests) {
ub1 j;
for (j=0; j<n; ++j) {
tu_iter ctx;
(void)start_tuple(&ctx, &s->one[thistest][tuple[j].d], n,
&s->onec[thistest][tuple[j].d]);
(void)insert_tuple(s, &ctx, tuple);
}
ub1 j;
for (j=0; j<n; ++j) {
tu_iter ctx;
(void)start_tuple(&ctx, &s->one[thistest][tuple[j].d], n,
&s->onec[thistest][tuple[j].d]);
(void)insert_tuple(s, &ctx, tuple);
}
}
}
@ -1769,19 +1769,19 @@ confirm( state *s)
s->tuple_tester->f[offset[i].d] = offset[i].f;
}
if (count_withouts(s->tuple_tester, s->wc2) ||
count_withouts(s->tuple_tester, s->wc3))
count_withouts(s->tuple_tester, s->wc3))
goto make_next_tuple;
/* is this tuple covered by the existing tests? */
for (j=0; j<s->ntests; ++j) {
test *t = s->t[j];
for (i=0; i<n; ++i) {
if (t->f[offset[i].d] != offset[i].f) {
break;
}
if (t->f[offset[i].d] != offset[i].f) {
break;
}
}
if (i == n) {
goto make_next_tuple;
goto make_next_tuple;
}
}
@ -1794,24 +1794,24 @@ confirm( state *s)
}
i=n;
while (i-- &&
offset[i].d == s->ndim-n+i &&
offset[i].f == s->dim[offset[i].d]-1)
offset[i].d == s->ndim-n+i &&
offset[i].f == s->dim[offset[i].d]-1)
;
if (i == -1)
break; /* done */
else if (offset[i].f < s->dim[offset[i].d]-1) {
++offset[i].f; /* increment feature */
for (i; i<n-1; ++i) { /* reset all less significant positions */
offset[i+1].d = offset[i].d+1;
offset[i+1].f = 0;
offset[i+1].d = offset[i].d+1;
offset[i+1].f = 0;
}
}
else {
++offset[i].d; /* increment least significant non-maxed-out position */
offset[i].f = (ub2)0; /* reset its feature */
for (i; i<n-1; ++i) { /* reset all less significant positions */
offset[i+1].d = offset[i].d+1;
offset[i+1].f = 0;
offset[i+1].d = offset[i].d+1;
offset[i+1].f = 0;
}
}
}