~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to sand/src/matrix.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2009- The University of Notre Dame
 
3
This software is distributed under the GNU General Public License.
 
4
See the file COPYING for details.
 
5
*/
 
6
 
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
 
 
11
#include "matrix.h"
 
12
 
 
13
struct matrix * matrix_create( int width, int height )
 
14
{
 
15
        struct matrix *m = malloc(sizeof(*m));
 
16
 
 
17
        m->width = width;
 
18
        m->height = height;
 
19
        m->data = malloc(sizeof(struct cell) * (m->width+1) * (height+1) );
 
20
 
 
21
        return m;
 
22
}
 
23
 
 
24
void matrix_delete( struct matrix *m )
 
25
{
 
26
        free(m->data);
 
27
        free(m);
 
28
}
 
29
 
 
30
void matrix_print( struct matrix *m, const char *a, const char *b )
 
31
{
 
32
        int i,j;
 
33
 
 
34
        if(b) printf("     ");
 
35
 
 
36
        if(a) for(i=0;i<m->width;i++) printf("    %c",a[i]);
 
37
 
 
38
        printf("\n");
 
39
 
 
40
        for(j=0;j<=m->height;j++) {
 
41
                if(b) {
 
42
                        if(j>0) {
 
43
                                printf("%c ",b[j-1]);
 
44
                        } else {
 
45
                                printf("  ");
 
46
                        }
 
47
                }
 
48
 
 
49
                for(i=0;i<=m->width;i++) {
 
50
                        char t = matrix(m,i,j).traceback;
 
51
                        if(t==0) t=' ';
 
52
                        printf("%3d%c ",matrix(m,i,j).score,t);
 
53
                }
 
54
                printf("\n");
 
55
        }
 
56
 
 
57
}