/* main func */
int mainHCompV(int argc, char *argv[])
{
   static int ft=1;
   char *datafn, *s;
   void SetCovs(void);
   void PutVFloor(void);
   SpkrAcc *sa = NULL;
	zwangModify();
   if(InitShell(argc,argv,hcompv_version,hcompv_vc_id)<SUCCESS)
      HError(2000,"HCompV: InitShell failed");
   if(ft)
   {
	   if(isMemInit==0)
	   {
		   InitMem();  
		   isMemInit=1;
	   }
	   InitLabel();
	   InitMath();  InitSigP();
	   InitWave();  InitAudio();
	   InitVQ();    InitModel();
	   if(InitParm()<SUCCESS)  
		  HError(2000,"HCompV: InitParm failed");   
	   ft=0;
	   CreateHeap(&iStack,"InBuf", MSTAK, 1, 0.5, 100000, LONG_MAX);
   }
   zwangHMemGetConf();
	zwangHWaveGetConf();
	zwangHLabelGetConf();
	zwangHMathGetConf();
	zwangHSigPGetConf();
	zwangHAudioGetConf();
	zwangHVQGetConf();
	zwangHModelGetConf();
	zwangHParmGetConf();

   SetConfParms();
CreateHMMSet(&hset,&gstack,FALSE);
   pathPattern[0]='\0';
   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s)!=1) 
         HError(2019,"HCompV: Bad switch %s; must be single letter",s);
      switch(s[0]){
      case 'f':
         if (NextArg() != FLOATARG)
            HError(2019,"HCompV: Variance floor scale expected");
         vFloorScale = GetChkedFlt(0.0,100.0,s);
         break;
      case 'l':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Segment label expected");
         segLab = GetStrArg();
         break;
      case 'm':
         meanUpdate = TRUE;
         break;
      case 'o':
         outfn = GetStrArg();
         break;     
      case 'v':
         if (NextArg() != FLOATARG)
            HError(2019,"HCompV: Minimum variance level expected");
         minVar = GetChkedFlt(0.0,100.0,s);
         break;
      case 'k':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: speaker pattern expected");
         strcpy(spPattern,GetStrArg());
         if (strchr(spPattern,'%')==NULL)
            HError(2019,"HCompV: Speaker mask invalid");
         break;
      case 'c':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: CMV output dir expected");
         strcpy(cmDir,GetStrArg());
         DoCMV = TRUE;
         break;
      case 'p':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: path pattern expected");
         strcpy(pathPattern,GetStrArg());
         if (strchr(pathPattern,'%')==NULL)
            HError(2019,"HCompV: Path mask invalid");
         break;
      case 'q':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: output flags (nmv)");
         strcpy(oflags,GetStrArg());
         break;
      case 'B':
         saveBinary = TRUE;
         break;
      case 'F':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Data File format expected");
         if((dff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2089,"HCompV: Warning ALIEN Data file format set");
         break;
      case 'G':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: Label File format expected");
         if((lff = Str2Format(GetStrArg())) == ALIEN)
            HError(-2089,"HCompV: Warning ALIEN Label file format set");
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: HMM macro file name expected");
         AddMMF(&hset,GetStrArg());
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(2019,"HCompV: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'L':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Label file directory expected");
         labDir = GetStrArg();
         break;
      case 'M':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Output macro file directory expected");
         outDir = GetStrArg();
         break;
      case 'T':
         if (NextArg() != INTARG)
            HError(2019,"HCompV: Trace value expected");
         trace = GetChkedInt(0,077,s); 
         break;
      case 'X':
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Label file extension expected");
         labExt = GetStrArg();
         break;
      default:
         HError(2019,"HCompV: Unknown switch %s",s);
      }
   }

   /* if not doing CMV, do standard HCompV */
   if (DoCMV == FALSE){
      if (NextArg()!=STRINGARG)
         HError(2019,"HCompV: Source HMM file name expected");
      hmmfn = GetStrArg();
      Initialise();
      do {
         if (NextArg()!=STRINGARG)
            HError(2019,"HCompV: Training data file name expected");
         datafn = GetStrArg();
         LoadFile(datafn);
      } while (NumArgs()>0);
      SetCovs();
      FixGConsts(hmmLink);
      SaveModel(outfn);   
      if (trace&T_TOP)
         printf("Output written to directory %s\n",(outDir==NULL)?"./":outDir);
      if (vFloorScale>0.0)
         PutVFloor();
   }
   else {
      /* report export data type */
      ReportOutput();
      /* init input buffer mem heap */
      CreateHeap(&iStack,"BufferIn",MSTAK,1,0.5,100000,5000000);
      do {
         if (NextArg()!=STRINGARG){
            HError(2019,"HCompV: Training data file name expected");
         }
         datafn = GetStrArg();       
         /* accumulate stats for current utterance file and update speaker list */
         sa = AccGenUtt(spPattern,datafn,sa);
         salist = UpdateSpkrAccList(salist,sa);
         /* reset for next utterance */
         ClrSpkrAcc(sa);
      } while (NumArgs()>0);
      /* compute the means and variances for each speaker */
      UpdateMeanVar(salist);
      /* export NMV for each speaker */
      ExportNMV(salist,cmDir,TargetPKStr);
   }
   Dispose(hset.hmem,hset.mtab);
   ResetHeap(&gstack);
   ResetHeap(&iStack);
   zwangInitParmClear();
zwangInitShellClear();
   //Exit(0);
   return (0);          /* never reached -- make compiler happy */
}
Esempio n. 2
0
/* The main program.  Parse the command line and do it... */
int main(int argc, char **argv)
{
    static int version = 0;
    static int rpflag = 0;
    static int basisflag = 0;
    static int compress = 0;
    static int quiet = 0;
    static int statistics = 0;
    static int mhflag = 0;
    static struct s_options options[] = {
        {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
        {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
        {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
        {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
        {OPT_FSTR, "l", (char*)handle_l_option, "Set an output language (c, c++, d)."},
        {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"},
        {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
        {OPT_FLAG, "s", (char*)&statistics,
            "Print parser stats to standard output."},
        {OPT_FLAG, "x", (char*)&version, "Print the version number."},
        {OPT_FLAG,0,0,0}
    };
    int i;
    struct lemon lem;
    
    OptInit(argv,options,stderr);
    if( version ){
        printf("Lemon version 1.0\n");
        exit(0);
    }
    if( OptNArgs()!=1 ){
        ErrorMsg("lemon", LINENO_NONE, "Exactly one filename argument is required.\n");
        exit(1);
    }
    memset(&lem, 0, sizeof(lem));
    lem.errorcnt = 0;
    
    /* Initialize the machine */
    Strsafe_init();
    Symbol_init();
    State_init();
    lem.argv0 = argv[0];
    lem.filename = OptArg(0);
    lem.basisflag = basisflag;
    Symbol_new("$");
    lem.errsym = Symbol_new("error");
    lem.errsym->useCnt = 0;
    
    /* Parse the input file */
    Parse(&lem);
    if( lem.errorcnt ) exit(lem.errorcnt);
        if( lem.nrule==0 ){
            ErrorMsg(lem.filename, LINENO_NONE, "Empty grammar.\n");
            exit(1);
        }
    
    /* Count and index the symbols of the grammar */
    lem.nsymbol = Symbol_count();
    Symbol_new("{default}");
    lem.symbols = Symbol_arrayof();
    for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
        qsort(lem.symbols,lem.nsymbol+1,sizeof(struct symbol*),
              (int(*)())Symbolcmpp);
        for(i=0; i<=lem.nsymbol; i++) lem.symbols[i]->index = i;
            for(i=1; isupper(lem.symbols[i]->name[0]); i++);
    lem.nterminal = i;
    
    /* Generate a reprint of the grammar, if requested on the command line */
    if( rpflag ){
        Reprint(&lem);
    }else{
        /* Initialize the size for all follow and first sets */
        SetSize(lem.nterminal+1);
        
        /* Find the precedence for every production rule (that has one) */
        FindRulePrecedences(&lem);
        
        /* Compute the lambda-nonterminals and the first-sets for every
         ** nonterminal */
        FindFirstSets(&lem);
        
        /* Compute all LR(0) states.  Also record follow-set propagation
         ** links so that the follow-set can be computed later */
        lem.nstate = 0;
        FindStates(&lem);
        lem.sorted = State_arrayof();
        
        /* Tie up loose ends on the propagation links */
        FindLinks(&lem);
        
        /* Compute the follow set of every reducible configuration */
        FindFollowSets(&lem);
        
        /* Compute the action tables */
        FindActions(&lem);
        
        /* Compress the action tables */
        if( compress==0 ) CompressTables(&lem);
        
        /* Reorder and renumber the states so that states with fewer choices
         ** occur at the end. */
        ResortStates(&lem);
        
        /* Generate a report of the parser generated.  (the "y.output" file) */
        if( !quiet ) ReportOutput(&lem);
        
        /* Generate the source code for the parser */
        ReportTable(&lem, mhflag);
        
        /* Produce a header file for use by the scanner.  (This step is
         ** omitted if the "-m" option is used because makeheaders will
         ** generate the file for us.) */
        if (! mhflag && language != LANG_D)
            ReportHeader(&lem);
    }
    if( statistics ){
        LogMsg(LOGLEVEL_INFO, lem.filename, LINENO_NONE,
               "Parser statistics: %d terminals, %d nonterminals, %d rules\n",
               lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
        LogMsg(LOGLEVEL_INFO, lem.filename, LINENO_NONE,
               "                   %d states, %d parser table entries, %d conflicts\n",
               lem.nstate, lem.tablesize, lem.nconflict);
    }
    if( lem.nconflict ){
        LogMsg(LOGLEVEL_WARNING, lem.filename, LINENO_NONE, "%d parsing conflicts.\n", lem.nconflict);
    }
    exit(lem.errorcnt + lem.nconflict);
    return (lem.errorcnt + lem.nconflict);
}