Subversion Repositories PlanixRsrch.SVN

Rev

Rev 428 | 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
 
469 7u83 34
#define MAX_VAL_LEN 180
22 7u83 35
 
306 7u83 36
static void 
22 7u83 37
print0(struct mavlnode *n, int depth, int cdepth, int x, 
38
		char *buffer,int width,
39
		void (*pcb)(char*,struct mavlnode *))
40
{
469 7u83 41
	char temp[MAX_VAL_LEN];
22 7u83 42
	int de;
43
	de = cdepth;
44
	if (!n)
45
		return;
46
	if (cdepth==depth){
47
		pcb(temp,n);
428 7u83 48
		(void)strcpy(buffer+x,temp); 
469 7u83 49
		*(buffer+x+strlen(temp))=' ';
22 7u83 50
		return ;	
51
	}
52
	if (cdepth>depth)
53
		return;
40 7u83 54
	print0(n->s[0],depth,cdepth+1,x-width/(2<<(de+1)),buffer,width,pcb);
55
	print0(n->s[1],depth,cdepth+1,x+width/(2<<(de+1)),buffer,width,pcb);
22 7u83 56
 
57
}
58
 
59
void
23 7u83 60
mavl_print(struct mavl *t, void (*pcb)(char*,struct mavlnode *), int width)
22 7u83 61
{
62
	int de;
63
	char * buffer;
469 7u83 64
	buffer = malloc(sizeof(char)*(width+1+MAX_VAL_LEN));
22 7u83 65
 
469 7u83 66
	for (de=0;de<20;de++){
67
		(void)memset(buffer,' ',(size_t)width+1);
22 7u83 68
		print0(t->root,de,0,width/2,buffer,width,pcb);
69
		buffer[width+1]=0;
70
		(void)printf("%s\n",buffer);
71
	}
72
 
73
	free(buffer);
74
}
75