home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / misc1s.zoo / misc1 / combine / pass2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-23  |  2.8 KB  |  122 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "util.h"
  4. #include "combine.h"
  5. /*
  6.  * pass2: Determine anchor points in the files.
  7.  *
  8.  * This routine identifies lines which occur precisely once in atleast two
  9.  * files and no more than once in the third file. All such lines are
  10.  * anchor points for passes 3 and 4.
  11.  *
  12.  * This routine scans the symbol table. For each record which meets the
  13.  * above criteria, links are made in the record arrays to associate
  14.  * anchor records with each other.
  15.  *
  16.  * Return value:
  17.  *      This procedure has no return value.
  18.  */
  19.  
  20. void pass2 () {
  21.  
  22.     register int     good_files; /* Number of files that a record is unique in. */
  23.  
  24.     register int     hash_code;    /* Index into symbol table */
  25.  
  26.     register int     i;        /* Misc. variable */
  27.  
  28.     int     indexes[MAX_FILE_COUNT];/* Index into each record array */
  29.  
  30.     /*
  31.      * Clear the indexes for all non-existant files.
  32.      */
  33.  
  34.     for (i = file_count; i < MAX_FILE_COUNT; ++i) {
  35.         indexes[i] = 0;
  36.     }
  37.  
  38.     /*
  39.      * Set up a pseudo line at the front and end of each file as an
  40.      * anchor point.
  41.      */
  42.  
  43.     for (i = 0; i < MATCH_COUNT; ++i) {
  44.         if (files[curr_file[i]].record != 0 &&
  45.                 files[corres_file[i]].record != 0) {
  46.  
  47.             files[curr_file[i]].record[BEGIN_INDEX].
  48.                 value[value_sub[i]] = BEGIN_INDEX;
  49.             files[curr_file[i]].
  50.                 record[files[curr_file[i]].record_array_size-1].
  51.                 value[value_sub[i]] =
  52.                 files[corres_file[i]].record_array_size - 1;
  53.  
  54.         }
  55.     }
  56.  
  57.     /*
  58.      * Test each entry in the symbol table.
  59.      */
  60.  
  61.     for (hash_code = 1; hash_code < sym_tab_size; ++hash_code) {
  62.  
  63.         /*
  64.          * Quickly see if the hash code is used at all
  65.          */
  66.         if ( sym_tab_cache_ptr[hash_code] == CACHE_FREE_ENTRY ){
  67.             continue;
  68.         }
  69.  
  70.  
  71.         /*
  72.          * Ensure the record occurs at most once in all files.
  73.          *
  74.          * This code counts the number of files a unique record is found in.
  75.          * If the record does not exist precisely once in atleast two files or
  76.          * if the record is not unique in any file, then the record cannot be
  77.          * an anchor record.
  78.          */
  79.  
  80.         good_files = 0;    /* Assume the record exists in no files */
  81.         for (i = 0; i < file_count; ++i) {
  82.             indexes[i] = files[i].sym_tab_index[hash_code];
  83.             /* if record is not unique in this file */
  84.             if (indexes[i] < 0) {
  85.                 good_files = 0;
  86.                 break;
  87.             /* if record is unique in this file */
  88.             } else if (indexes[i] > 0) {
  89.                 good_files++;
  90.             }
  91.         }
  92.  
  93.         if (good_files < 2) {/* Record not unique in enough files */
  94.             continue;
  95.         }
  96.  
  97.         /*
  98.          * Link up anchors between any two files.
  99.          *
  100.          * If the current file and the corresponding file both contain
  101.          * the same unique line. Link the current file to the
  102.          * corresponding file.
  103.          */
  104.  
  105.         for (i = 0; i < MATCH_COUNT; ++i) {
  106.  
  107.             if (indexes[curr_file[i]] > 0 &&
  108.                 indexes[corres_file[i]] > 0) {
  109.  
  110.                 files[curr_file[i]].
  111.                     record[indexes[curr_file[i]]].
  112.                     value[value_sub[i]] =
  113.                     indexes[corres_file[i]];
  114.  
  115.             }
  116.  
  117.         }
  118.  
  119.     }
  120.  
  121. }
  122.