dhilst

Middleware manager..

Yeap, I got a job. Intern on middleware management area.. I really like it.. I have
close contact with commercial aplications and linux/unix environments... and the warm/pressure of the businesses.. There are nice guys there.. some times looks like an arena.. but with little fat funny guys instead of big muscle losers.. :-) 

by the way.. an tree prototype...


tree.h
#ifndef GKO_TREE_H
#define GKO_TREE_H

#include "stack.h"
#include "ll.h"
#include "common.h"

typedef struct branch {
char *name;
char *data;
ll cont;
struct branch *next;
} branch;

void init_tree (branch *, char *, char *) ;
void set_branch (branch *, char *, char *);
branch *get_branch (branch *, char *);

#endif


tree.c
#include "tree.h"

/* Initialize a Tree, set the root node */
void
init_tree (branch *t, char *name, char *data)
{
cpystr (&t->name, name);
cpystr (&t->data, data);
init_ll (&t->cont);
t->next = NULL;
}

/* Create a new branch or edit an existent one */
void
set_branch (branch *t, char *name, char *data)
{
lln **node = search_lln (&t->cont, name);
branch *b;

if (node) { /* edit branch */
b = node[0]->data; /* the address of found branch */
free (b->data);
cpystr (&b->data, data);
} else { /* create a brand new branch */
b = xmalloc (sizeof (branch));
init_tree (b, name, data);
}

add_lln (&t->cont, name, b); /* tree contains branch */
}

/* Return the address of a branch */
branch *
get_branch (branch *t, char *name)
{
lln **node = search_lln (&t->cont, name);
if (node)
return node[0]->data; /* return void * don't need casts */
return NULL;
}

/* Delete a branch an everything below that node */
/* @TODO */
void
del_branch ()
{
}



driver
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "tree.h"

main ()
{
branch myt;
branch *buf;

init_tree (&myt, "root", "root_data");
set_branch (&myt, "etc", "etc_data");
set_branch (&myt, "usr", "usr_data");

buf = get_branch (&myt, "etc");
printf ("Searched %s\n", buf->data);

set_branch (buf, "rc.conf", "rc.conf data");
buf = get_branch (buf, "rc.conf");
printf ("Searched %s\n", buf->data);

buf = get_branch (&myt, "usr");
printf ("User data? %s\n", buf->data);

set_branch (&myt, "etc", "etc_edited_data");
buf = get_branch (&myt, "etc");
printf ("Searched %s\n", buf->data);

return 0;
}


MAYBE I work more on this..