|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T b
Length: 5374 (0x14fe)
Types: TextFile
Names: »build_trees.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z«
└─⟦de7628f85⟧
└─⟦this⟧ »isode-6.0/others/quipu/photo/build_trees.c«
/* build_trees.c - build decode trees */
#ifndef lint
static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 7.0 89/11/23 22:01:33 mrose Rel $";
#endif
/*
* $Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 7.0 89/11/23 22:01:33 mrose Rel $
*
*
* $Log: build_trees.c,v $
* Revision 7.0 89/11/23 22:01:33 mrose
* Release 6.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;
}