Browse code

Improve debugging output

John Hawthorn authored on 31/08/2014 02:11:55
Showing 1 changed files

  • match.c index 4ce6ddb..5c68cd8 100644
... ...
@@ -23,9 +23,17 @@ typedef double score_t;
23 23
 #define SCORE_MIN -INFINITY
24 24
 
25 25
 /* print one of the internal matrices */
26
-void mat_print(score_t *mat, int n, int m){
26
+void mat_print(score_t *mat, const char *needle, const char *haystack){
27
+	int n = strlen(needle);
28
+	int m = strlen(haystack);
27 29
 	int i, j;
30
+	fprintf(stderr, "    ");
31
+	for(j = 0; j < m; j++){
32
+		fprintf(stderr, "     %c", haystack[j]);
33
+	}
34
+	fprintf(stderr, "\n");
28 35
 	for(i = 0; i < n; i++){
36
+		fprintf(stderr, " %c |", needle[i]);
29 37
 		for(j = 0; j < m; j++){
30 38
 			score_t val = mat[i*m + j];
31 39
 			if(val == SCORE_MIN){
... ...
@@ -129,10 +137,10 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
129 137
 	}
130 138
 
131 139
 #if 0
132
-	printf("\"%s\" =~ \"%s\"\n", needle, haystack);
133
-	mat_print(&D[0][0], n, m);
134
-	mat_print(&M[0][0], n, m);
135
-	printf("\n");
140
+	fprintf(stderr, "\"%s\" =~ \"%s\"\n", needle, haystack);
141
+	mat_print(&D[0][0], needle, haystack);
142
+	mat_print(&M[0][0], needle, haystack);
143
+	fprintf(stderr, "\n");
136 144
 #endif
137 145
 
138 146
 	/* backtrace to find the positions of optimal matching */