/* file ttp3s_prot.c  */

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


PROTECTED_CHR_STR *ttp3s_prot(PROTECTED_CHR_STR *sp, char *st,
   TTP_PCDRLS_PARAMETERS *ttp_pcdrls_parms, int *perr)
  /*********************************************/
  /*  Converts text to phones                  */
  /*   Input: *st is an ASCII text string;     */
  /*  Output: *sp is a protected ASCII phone string;    */
  /*   (Returns sp.)                           */
  /*  Process: applies ttp rules that are in   */
  /* the *ttp_pcdrls_parms, defaulting to      */
  /* spell-mode if result is unpronounceable.  */
  /*  On return, *perr > 0 iff error.          */
  /*********************************************/
   {char *proc = "ttp3s_prot";
    char *the_rest;
    PROTECTED_CHR_STR tpx, *token_pron = &tpx;
    PROTECTED_CHR_STR *psdbx;
    SUBSTRING sstkx, *ss_token = &sstkx;
/* code */
 db_enter_msg(proc,1); /* debug only */
if (db_level > 2) printf("%s input='%s'\n",pdb,st);
    *perr = 0;
    psdbx = create_prot_chr_str(133);
    alloc_prot_chr_str_guts(token_pron,133);
    strcpy_prot_s(token_pron,"");
   /* empty output string */
    sp = strcpy_prot_s(sp,"");
if (db_level > 2) printf("%s looping on tokens in the_rest\n",pdb);
   /* loop on tokens in input */
    the_rest = st;
    do
      {*ss_token = sstok4(the_rest);
if (db_level > 2) printf("%s the_rest = [%s]\n",pdb,the_rest);
       if (substr_length(ss_token) < 1) continue;
if (db_level > 2)
 {ss_to_ps(psdbx,ss_token);
  printf("%s ss_token = [%s]\n",pdb,psdbx->str);
 }
      /* generate pron using TTP rules */
       token_pron = ttp_pcdrls2ss_prot(token_pron,ss_token,
         ttp_pcdrls_parms->pcdrls,ttp_pcdrls_parms->bpath,perr);
       if (*perr > 0) goto RETURN;
if (db_level > 2) printf("%s returned form ttp_pcdrls2ss_prot()\n",pdb);
       zapchar(token_pron->str,'*'); /* mark of deletion by pcdrls */
      /* if result not pronounceable, say it in spell mode */
       if (!pronounceable_phon(token_pron->str,ttp_pcdrls_parms->syl_parms))
         token_pron = spell_mode_prot(token_pron,ss_token);
       sp = strcat_prot_p(sp,token_pron);
       the_rest = ss_token->end + 1;
      }
    while (substr_length(ss_token) > 0);
   RETURN:
    dealloc_prot_chr_str_guts(token_pron);
if (db_level > 2) printf("%s output='%s'\n",pdb,sp->str);
    destroy_prot_chr_str(psdbx);
 db_leave_msg(proc,1); /* debug only */
    return sp;
   }
