/* file make_pcd_from_rls_file.c */

#if !defined(COMPILE_ENVIRONMENT)
#include <gp/stdcenvf.h> /* std compile environment for functions */
#endif

void make_pcd_from_rls_file(pcodeset *pcdrls,char *fname_pcdrls,
  char *path, char tgbound, int *perr)
     /********************************************************/
     /* reads in the pcdrls table from a ruleset file.       */
     /* Assumes that free_pcode(pcdrls) has already occurred.*/
     /* Modified 1/20/99 by WMF to use pcindex5r().          */
     /********************************************************/
 {char *proc = "make_pcd_from_rls_file";
  char kxx[LONG_LINE], *key = &kxx[0];
  int irule,item;
  boolean add_to_core = T, dont_add_to_file = F, hashed;
  RULESET2 rset_data, *rset = &rset_data;
 db_enter_msg(proc,0);
if (db_level > 1) printf("%s path='%s',fname_pcdrls='%s'\n",pdb,path,fname_pcdrls);
 *perr = 0;
 /* get pcdrls in standard ruleset form */
 get_rules2(rset,path,fname_pcdrls,perr);
 if (*perr > 0) fatal_error(proc,"get_rules2 fails",*perr);
if (db_level > 0) printf("%s rset->nrules = %d\n",pdb,rset->nrules);
 if (rset->nrules < 1) fatal_error(proc,"no rules in ruleset file",-1);
if (db_level > 2) dump_rules2(rset);
/* make pcdrls pcodeset encoding rules */
/* (re-)initialize pcdrls table */
 init_pcdrls(pcdrls,rset->nrules, hashed=T);
 free(pcdrls->file_name);
 pcdrls->file_name = strdup_safe(fname_pcdrls,proc);
 free(pcdrls->name);
 pcdrls->name = strdup_safe(rset->name,proc);
 free(pcdrls->desc);
 pcdrls->desc = strdup_safe(rset->desc,proc);
 /* add in individual codes from ruleset */ 
 for (irule = 1; irule <= rset->nrules; irule++)
   {key = build_key3(key,rset->rule[irule].lcontext,
      rset->rule[irule].sin,rset->rule[irule].rcontext,tgbound);
if (db_level > 1) printf("%s adding key=[%s]\n",pdb,key);
    item = pcindex5r(key,pcdrls,add_to_core,dont_add_to_file,NULL);
    if (item < 0) fatal_error(proc,"pcindex5r error",-1);
    pcdrls->pc[item].lc_ext = strdup_safe(rset->rule[irule].sout,proc);
   }
 /* trash ruleset */
 free_rules2(rset);
 db_leave_msg(proc,0);
  return;
 }
