DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦11c06bcf7⟧ TextFile

    Length: 5374 (0x14fe)
    Types: TextFile
    Names: »build_trees.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/others/quipu/photo/build_trees.c« 

TextFile

/* build_trees.c - build decode trees */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 6.0 89/03/18 23:33:57 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 6.0 89/03/18 23:33:57 mrose Rel $
 *
 *
 * $Log:	build_trees.c,v $
 * Revision 6.0  89/03/18  23:33:57  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */



#include <stdio.h>
#include "quipu/photo.h"

int built = 0;
char * malloc ();

extern node * bl_tree_top;      /* pointers to the decode trees */
extern node * wt_tree_top;
extern node * two_tree_top;

/* ROUTINE:     get_node                                                */
/*                                                                      */
/* SYNOPSIS:    creates a new node.                                     */
/*                                                                      */
/* DESCRIPTION: Uses malloc to allocate sufficient memory for a node to */
/*              be stored, and the sets all the pointer fields of the   */
/*              node to NULL, and initialises the other fields          */

node *
get_node ()

{
node * mem;

   mem = (node *) malloc (sizeof (node));
   mem->n_type = INTERNAL;              /* The most common node type */
   mem->zero = NULL;
   mem->one = NULL;

   return (mem);
}


char * file_path (faxdir,file)
char *faxdir, *file;
{
static char buf [200];
char * sprintf ();

	(void) sprintf (buf,"%s/%s",faxdir,file);
	return (buf);
}

/* ROUTINE:     build_trees.
/*
/* SYNOPSIS:    build the decode tree.
/*
/* DESCRIPTION: For each of the three trees, read the data in from a file
/* in string form, convert this into an integer, then add this integer to the
/* tree.
/* Also contained in the node is the value associated with the string read in,
/* so we need to count each string as it is read in.
*/

build_trees (faxdir)
char * faxdir;
{
FILE *  fptr;
register i;
char    buffer [15];
char *  string = buffer;
char * file;

   if (built)
	return (0);

   /* create the tops of the trees */
   bl_tree_top = get_node ();
   wt_tree_top = get_node ();
   two_tree_top = get_node ();

 /* Add the white terminals to the white tree */
   file = file_path (faxdir,"wt_term");
   if ((fptr = fopen (file,"r")) == NULL)
   {
	(void) fprintf(stderr,"Can't open data file %s\n",file);
	return(-1);
   }
   i=0;
   while ( fscanf(fptr,"%s",string) != EOF )
	add_tree (string,i++,WT_TERM,wt_tree_top);
   (void) fclose (fptr);

   /* Add the black terminals to the black tree */
   file = file_path (faxdir,"bl_term");
   if ((fptr = fopen (file,"r")) == NULL)
   {
	(void) fprintf(stderr,"Can't open data file %s\n",file);
	return(-1);
   }
   i=0;
   while ( fscanf(fptr,"%s",string) != EOF )
	add_tree (string,i++,BL_TERM,bl_tree_top);
   (void) fclose (fptr);

   /* Add the white make codes to the white tree */
   file = file_path (faxdir,"wt_make");
   if ((fptr = fopen (file,"r")) == NULL)
   {
	(void) fprintf(stderr,"Can't open data file %s\n",file);
	return(-1);
   }
   i = 64;
   while ( fscanf(fptr,"%s",string) != EOF ) {
	add_tree (string,i,MAKE,wt_tree_top);
	i += 64;
	}
   (void) fclose (fptr);

   /* Add the black make up codes to the black tree */
   file = file_path (faxdir,"bl_make");
   if ((fptr = fopen (file,"r")) == NULL)
   {
	(void) fprintf(stderr,"Can't open data file %s\n",file);
	return(-1);
   }
   i = 64;
   while ( fscanf(fptr,"%s",string) != EOF ) {
	add_tree (string,i,MAKE,bl_tree_top);
	i += 64;
	}
   (void) fclose (fptr);

   /* make the two dimensional decode tree */
   file = file_path (faxdir,"two_dim");
   if ((fptr = fopen (file,"r")) == NULL)
   {
	(void) fprintf(stderr,"Can't open data file %s\n",file);
	return(-1);
   }
   i = 1;
   while ( fscanf(fptr,"%s",string) != EOF )
	add_tree (string,i++,MAKE,two_tree_top);
   (void) fclose (fptr);

   /* put end of line markers on all three trees */
   add_tree ("00000000000",EOLN,EOLN,bl_tree_top);
   add_tree ("00000000000",EOLN,EOLN,wt_tree_top);
   add_tree ("00000000000",EOLN,EOLN,two_tree_top);

   built = 1;
   return(0);
}

/* ROUTINE:     add_tree                                                */
/*                                                                      */
/* SYNOPSIS:    adds a run to the tree                                  */
/*                                                                      */

add_tree (string,run,mode,root)

char *  string;         /* string containing the bit sequence           */
int     run;            /* the run length associated with the sequence  */
char    mode;           /* the type of data we are entering             */
node *  root;           /* top of the tree sting should be added to     */
{

char *   ptr;
node *   treeptr;
register i;

   ptr = string;
   treeptr = root;

   for ( i=0; i< strlen(string); i++,ptr++)
	if (*ptr == '0') {
	   if (treeptr->zero == NULL)
		treeptr->zero = get_node ();
	   treeptr = treeptr->zero;

	} else {
	      if (treeptr->one == NULL)
		   treeptr->one = get_node ();
	      treeptr = treeptr->one;
	}

   treeptr->n_type = mode;
   treeptr->value  = run;
}