Subversion Repositories PlanixRsrch.SVN

Rev

Rev 329 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22 7u83 1
/*
2
 * Copyright 2019, The PLANIX Project
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are
6
 * met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 * this list of conditions and the following disclaimer.
10
 *
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 * notice, this list of conditions and the following disclaimer in the
13
 * documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
 
28
#include <stdlib.h>
29
#include <string.h>
30
#include <stdio.h>
31
 
32
#include "mavl.h"
33
 
34
 
306 7u83 35
static void 
22 7u83 36
print0(struct mavlnode *n, int depth, int cdepth, int x, 
37
		char *buffer,int width,
38
		void (*pcb)(char*,struct mavlnode *))
39
{
329 7u83 40
	char temp[180];
22 7u83 41
	int de;
42
	de = cdepth;
43
	if (!n)
44
		return;
45
	if (cdepth==depth){
46
		pcb(temp,n);
428 7u83 47
		(void)strcpy(buffer+x,temp); 
22 7u83 48
		return ;	
49
	}
50
	if (cdepth>depth)
51
		return;
40 7u83 52
	print0(n->s[0],depth,cdepth+1,x-width/(2<<(de+1)),buffer,width,pcb);
53
	print0(n->s[1],depth,cdepth+1,x+width/(2<<(de+1)),buffer,width,pcb);
22 7u83 54
 
55
}
56
 
57
void
23 7u83 58
mavl_print(struct mavl *t, void (*pcb)(char*,struct mavlnode *), int width)
22 7u83 59
{
60
	int de;
61
	char * buffer;
62
	buffer = malloc(sizeof(char)*(width+1));
63
 
64
	for (de=0;de<10;de++){
65
		(void)memset(buffer,' ',(size_t)width);
66
		print0(t->root,de,0,width/2,buffer,width,pcb);
67
		buffer[width+1]=0;
68
		(void)printf("%s\n",buffer);
69
	}
70
 
71
	free(buffer);
72
}
73
 
74