/* file isylparms.c */

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

void init_syl_parms(struct SYL_PARMS *syl_parms,boolean plus_foreign_loans, int *perr)
  /**************************************************************/
  /*  Initializes parameter values needed for syllabification.  */
  /*  Files containing the phonemic pcodeset and tables of      */
  /*  allowable consonant clusters must be in "data_dir", which */
  /*  is the environmental parameter $LEXDATA for local work.   */
  /*  If plus_foreign_loans is T, the CC constraints are relaxed*/
  /*  to cover both native words and some foreign loans.        */
  /**************************************************************/
 {char *proc = "init_syl_parms";
  char fnx[LINE_LENGTH], *fname = &fnx[0];
  char *fname_pcodeset     = "phon1ax.pcd";
  char *fname_CC_inits     = "CC_inits.txt";
  char *fname_CC_bad_inits = "CC_bad_inits.txt";
  char *fname_CC_final     = "CC_final.txt";
  boolean export_code_version = T;
 /* code */
db_enter_msg(proc,1); /* debug only */
  *perr = 0;
  syl_parms->desc = strdup_safe("English syllabification parameters.",proc);
/* find directories for phonemic pcodeset and data tables */
  if (export_code_version)
    {syl_parms->pcdp_dir = strdup_safe("./data/",proc);
    if (plus_foreign_loans) syl_parms->data_dir = strdup_safe("./data/nat+for/",proc);
    else                    syl_parms->data_dir = strdup_safe("./data/native/",proc);
    }
  else
   {syl_parms->pcdp_dir = strdup_safe("$LEXDATA/",proc);
    if (plus_foreign_loans) syl_parms->data_dir = strdup_safe("$LEXDATA/nat+for/",proc);
    else                    syl_parms->data_dir = strdup_safe("$LEXDATA/native/",proc);
   }
  /* get phonemic pcodeset */
  fname = strcat(strcpy(fname,syl_parms->pcdp_dir),fname_pcodeset);
  syl_parms->pcdp = (pcodeset*)malloc_safe(sizeof(pcodeset),proc);
  get_pcode3(syl_parms->pcdp,"",fname,perr);
  if (*perr > 0)
    {fprintf(stdout," Get_pcode3 returned err code =%d\n",*perr);
     fprintf(stdout," trying to get pcode from file '%s'.\n",fname);
     if (*perr > 10) goto RETURN;
    }
 /* find left and right syllable boundary marks in int string form */
  syl_parms->lmark[0] = 1;
  syl_parms->lmark[1] = pcindex2("[",syl_parms->pcdp);
  syl_parms->rmark[0] = 1;
  syl_parms->rmark[1] = pcindex2("]",syl_parms->pcdp);
 /* and word boundary mark */
  syl_parms->wbound[0] = 1;
  syl_parms->wbound[1] = pcindex2("#",syl_parms->pcdp);
/* get integers representing some particular suprasegmental phones */
  syl_parms->iwordbound = pcindex2("#",syl_parms->pcdp);
  syl_parms->i_default_stress = pcindex2("'0",syl_parms->pcdp);
/* read in list of allowable initial consonant clusters */
  fname = strcat(strcpy(fname,syl_parms->data_dir),fname_CC_inits);
  get_nstr_table(syl_parms->CC_init,&(syl_parms->n_CC_inits),
    MAX_CC,fname,syl_parms->pcdp,";",perr);
  if (*perr > 0)
    {fprintf(stdout,"*ERR: read of '%s' fails, err=%d\n",fname_CC_inits,*perr);
     goto RETURN;
    }
/* read in list of universally disallowed initial  */
/* consonant clusters, for use in rule IV */
  fname = strcat(strcpy(fname,syl_parms->data_dir),fname_CC_bad_inits);
  get_nstr_table(syl_parms->CC_bad_init,&(syl_parms->n_CC_bad_inits),
    MAX_CC,fname,syl_parms->pcdp,";",perr);
  if (*perr > 0)
    {fprintf(stdout,"*ERR: read of '%s' fails, err=%d\n",fname_CC_bad_inits,*perr);
     goto RETURN;
    }
/* read in list of allowable final consonant clusters */
  fname = strcat(strcpy(fname,syl_parms->data_dir),fname_CC_final);
  get_nstr_table(syl_parms->CC_final,&(syl_parms->n_CC_final),
    MAX_CC,fname,syl_parms->pcdp,";",perr);
  if (*perr > 0)
    {fprintf(stdout,"*ERR: read of '%s' fails, err=%d\n",fname_CC_final,*perr);
     goto RETURN;
    }
 RETURN:
db_leave_msg(proc,1); /* debug only */
  return;
 }
