Annotation of 43BSDReno/contrib/isode-beta/others/quipu/photo/build_trees.c, revision 1.1.1.1

1.1       root        1: /* build_trees.c - build decode trees */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 7.0 89/11/23 22:01:33 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/others/quipu/photo/RCS/build_trees.c,v 7.0 89/11/23 22:01:33 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       build_trees.c,v $
                     12:  * Revision 7.0  89/11/23  22:01:33  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: 
                     29: #include <stdio.h>
                     30: #include "quipu/photo.h"
                     31: 
                     32: int built = 0;
                     33: char * malloc ();
                     34: 
                     35: extern node * bl_tree_top;      /* pointers to the decode trees */
                     36: extern node * wt_tree_top;
                     37: extern node * two_tree_top;
                     38: 
                     39: /* ROUTINE:     get_node                                                */
                     40: /*                                                                      */
                     41: /* SYNOPSIS:    creates a new node.                                     */
                     42: /*                                                                      */
                     43: /* DESCRIPTION: Uses malloc to allocate sufficient memory for a node to */
                     44: /*              be stored, and the sets all the pointer fields of the   */
                     45: /*              node to NULL, and initialises the other fields          */
                     46: 
                     47: node *
                     48: get_node ()
                     49: 
                     50: {
                     51: node * mem;
                     52: 
                     53:    mem = (node *) malloc (sizeof (node));
                     54:    mem->n_type = INTERNAL;              /* The most common node type */
                     55:    mem->zero = NULL;
                     56:    mem->one = NULL;
                     57: 
                     58:    return (mem);
                     59: }
                     60: 
                     61: 
                     62: char * file_path (faxdir,file)
                     63: char *faxdir, *file;
                     64: {
                     65: static char buf [200];
                     66: char * sprintf ();
                     67: 
                     68:        (void) sprintf (buf,"%s/%s",faxdir,file);
                     69:        return (buf);
                     70: }
                     71: 
                     72: /* ROUTINE:     build_trees.
                     73: /*
                     74: /* SYNOPSIS:    build the decode tree.
                     75: /*
                     76: /* DESCRIPTION: For each of the three trees, read the data in from a file
                     77: /* in string form, convert this into an integer, then add this integer to the
                     78: /* tree.
                     79: /* Also contained in the node is the value associated with the string read in,
                     80: /* so we need to count each string as it is read in.
                     81: */
                     82: 
                     83: build_trees (faxdir)
                     84: char * faxdir;
                     85: {
                     86: FILE *  fptr;
                     87: register i;
                     88: char    buffer [15];
                     89: char *  string = buffer;
                     90: char * file;
                     91: 
                     92:    if (built)
                     93:        return (0);
                     94: 
                     95:    /* create the tops of the trees */
                     96:    bl_tree_top = get_node ();
                     97:    wt_tree_top = get_node ();
                     98:    two_tree_top = get_node ();
                     99: 
                    100:  /* Add the white terminals to the white tree */
                    101:    file = file_path (faxdir,"wt_term");
                    102:    if ((fptr = fopen (file,"r")) == NULL)
                    103:    {
                    104:        (void) fprintf(stderr,"Can't open data file %s\n",file);
                    105:        return(-1);
                    106:    }
                    107:    i=0;
                    108:    while ( fscanf(fptr,"%s",string) != EOF )
                    109:        add_tree (string,i++,WT_TERM,wt_tree_top);
                    110:    (void) fclose (fptr);
                    111: 
                    112:    /* Add the black terminals to the black tree */
                    113:    file = file_path (faxdir,"bl_term");
                    114:    if ((fptr = fopen (file,"r")) == NULL)
                    115:    {
                    116:        (void) fprintf(stderr,"Can't open data file %s\n",file);
                    117:        return(-1);
                    118:    }
                    119:    i=0;
                    120:    while ( fscanf(fptr,"%s",string) != EOF )
                    121:        add_tree (string,i++,BL_TERM,bl_tree_top);
                    122:    (void) fclose (fptr);
                    123: 
                    124:    /* Add the white make codes to the white tree */
                    125:    file = file_path (faxdir,"wt_make");
                    126:    if ((fptr = fopen (file,"r")) == NULL)
                    127:    {
                    128:        (void) fprintf(stderr,"Can't open data file %s\n",file);
                    129:        return(-1);
                    130:    }
                    131:    i = 64;
                    132:    while ( fscanf(fptr,"%s",string) != EOF ) {
                    133:        add_tree (string,i,MAKE,wt_tree_top);
                    134:        i += 64;
                    135:        }
                    136:    (void) fclose (fptr);
                    137: 
                    138:    /* Add the black make up codes to the black tree */
                    139:    file = file_path (faxdir,"bl_make");
                    140:    if ((fptr = fopen (file,"r")) == NULL)
                    141:    {
                    142:        (void) fprintf(stderr,"Can't open data file %s\n",file);
                    143:        return(-1);
                    144:    }
                    145:    i = 64;
                    146:    while ( fscanf(fptr,"%s",string) != EOF ) {
                    147:        add_tree (string,i,MAKE,bl_tree_top);
                    148:        i += 64;
                    149:        }
                    150:    (void) fclose (fptr);
                    151: 
                    152:    /* make the two dimensional decode tree */
                    153:    file = file_path (faxdir,"two_dim");
                    154:    if ((fptr = fopen (file,"r")) == NULL)
                    155:    {
                    156:        (void) fprintf(stderr,"Can't open data file %s\n",file);
                    157:        return(-1);
                    158:    }
                    159:    i = 1;
                    160:    while ( fscanf(fptr,"%s",string) != EOF )
                    161:        add_tree (string,i++,MAKE,two_tree_top);
                    162:    (void) fclose (fptr);
                    163: 
                    164:    /* put end of line markers on all three trees */
                    165:    add_tree ("00000000000",EOLN,EOLN,bl_tree_top);
                    166:    add_tree ("00000000000",EOLN,EOLN,wt_tree_top);
                    167:    add_tree ("00000000000",EOLN,EOLN,two_tree_top);
                    168: 
                    169:    built = 1;
                    170:    return(0);
                    171: }
                    172: 
                    173: /* ROUTINE:     add_tree                                                */
                    174: /*                                                                      */
                    175: /* SYNOPSIS:    adds a run to the tree                                  */
                    176: /*                                                                      */
                    177: 
                    178: add_tree (string,run,mode,root)
                    179: 
                    180: char *  string;         /* string containing the bit sequence           */
                    181: int     run;            /* the run length associated with the sequence  */
                    182: char    mode;           /* the type of data we are entering             */
                    183: node *  root;           /* top of the tree sting should be added to     */
                    184: {
                    185: 
                    186: char *   ptr;
                    187: node *   treeptr;
                    188: register i;
                    189: 
                    190:    ptr = string;
                    191:    treeptr = root;
                    192: 
                    193:    for ( i=0; i< strlen(string); i++,ptr++)
                    194:        if (*ptr == '0') {
                    195:           if (treeptr->zero == NULL)
                    196:                treeptr->zero = get_node ();
                    197:           treeptr = treeptr->zero;
                    198: 
                    199:        } else {
                    200:              if (treeptr->one == NULL)
                    201:                   treeptr->one = get_node ();
                    202:              treeptr = treeptr->one;
                    203:        }
                    204: 
                    205:    treeptr->n_type = mode;
                    206:    treeptr->value  = run;
                    207: }
                    208: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.