-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickcheck.c
110 lines (84 loc) · 2.76 KB
/
quickcheck.c
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include "src/expression.h"
#include "src/operand.h"
#include "src/db.h"
const char const usage[ ]= "The Source is the doc.";
struct Substitution {
char* name;
char* value;
};
int main( const int argc,char* const argv[ ] ) {
// Parse arguments
bool help = false;
unsigned num_processors = 1;
QsEvaluatorOptions fermat_options = qs_evaluator_options_new( );
int opt;
while( ( opt = getopt( argc,argv,"s:p:" ) )!=-1 ) {
char* endptr,* symbol,* value;
switch( opt ) {
case 'p':
if( ( num_processors = strtoul( optarg,&endptr,0 ) )<1 || *endptr!='\0' )
help = true;
break;
case 's':
symbol = strtok( optarg,"=" );
value = strtok( NULL,"" );
qs_evaluator_options_add( fermat_options,symbol,value );
break;
}
}
if( argc-optind<1 || help ) {
printf( "%s %s\n",argv[ 0 ],usage );
exit( EXIT_FAILURE );
}
QsAEF aef = qs_aef_new( 0 );
int j;
for( j = 0; j<num_processors; j++ )
qs_aef_spawn( aef,fermat_options );
qs_evaluator_options_destroy( fermat_options );
for( j = optind; j<argc; j++ ) {
char* fullname;
asprintf( &fullname,"%s#type=kch",argv[ j ] );
fprintf( stderr,"Loading database with name '%s'\n",fullname );
QsDb db = qs_db_new( fullname,QS_DB_READ );
free( fullname );
if( db ) {
QsDbCursor cur = qs_db_cursor_new( db );
struct QsDbEntry* row;
while( ( row = qs_db_cursor_next( cur ) ) ) {
if( memcmp( row->key,"generated",row->keylen )&& memcmp( row->key,"setup",row->keylen ) ) {
QsExpression e = qs_expression_new_from_binary( row->val,row->vallen,NULL );
fprintf( stderr,"Checking entry with key " );
int k;
for( k = 0; k*sizeof (QsPower)<row->keylen; k++ )
fprintf( stderr,"%hhi ",( (QsPower*)row->key )[ k ] );
fprintf( stderr,"\n" );
QsTerminalGroup checks = qs_terminal_group_new( qs_expression_n_terms( e ) );
for( k = 0; k<qs_expression_n_terms( e ); k++ ) {
QsCoefficient coeff = qs_expression_coefficient( e,k );
QsTerminal issue = qs_operand_new( NULL,NULL );
qs_terminal_load( issue,coeff );
qs_terminal_group_push( checks,qs_operand_bake( 1,(QsOperand*)&issue,QS_OPERATION_ADD,aef,NULL,NULL ) );
qs_operand_unref( (QsOperand)issue );
qs_integral_destroy( qs_expression_integral( e,k ) );
}
qs_expression_disband( e );
while( qs_terminal_group_count( checks ) ) {
qs_terminal_group_wait( checks );
qs_operand_unref( (QsOperand)qs_terminal_group_pop( checks ) );
}
qs_terminal_group_destroy( checks );
}
qs_db_entry_destroy( row );
}
qs_db_cursor_destroy( cur );
qs_db_destroy( db );
} else {
fprintf( stderr,"Error: Could not load database\n" );
exit( EXIT_FAILURE );
}
}
exit( EXIT_SUCCESS );
}