john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file julius command menu

/* John Pfeiffer 2010-08 extending my earlier c receive pipe program
 take input from stdin (piped voice recognition from Julius)
 if a successful voice match for a "DIAL" command, use the conf.txt dos command
 TODO: improve security from system() call 
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFFERMAX 1024
#define LINEMAX 1024


int getConfigurationFromFile ( char configfilebuffer [ BUFFERMAX ][ LINEMAX ]  );

int main( int argc, char* argv[] )
{   
    int configurationlines = 0;
    char configfilebuffer [ BUFFERMAX ][ LINEMAX ] ;

    char c;
    char buffer [ BUFFERMAX ];
    int charcounter = 0;    
    FILE* fptr;

    configurationlines = getConfigurationFromFile ( configfilebuffer );

    fptr = fopen( "log.txt" , "w" );

    if( fptr == NULL )
    {    fprintf( stderr , "error opening file\n");
         exit(1);
    }
    printf("\nusage: recv.c.exe  then type things, type @ or ~ followed by enter to quit\n");

    memset( buffer , '\0' , sizeof( buffer) );    
    charcounter = 0;
    c = fgetc( stdin );


    while( c != EOF && c != '~' && c != '@' && charcounter < BUFFERMAX )
    {   
        buffer[ charcounter ] = c;
        charcounter++;

        if( c == '\n' )
        {
            fprintf( fptr, "%s" , buffer ) ;
            fprintf( stdout , "%s" , buffer );
            fflush( fptr );

            if( strstr( buffer , "</s>") != NULL )
            {                
                if( strstr( buffer , "DIAL ZERO") != NULL )                
                {   system( configfilebuffer[ 0 ] );                    
                }
                if( strstr( buffer , "DIAL ONE") != NULL )                
                {   system( configfilebuffer[ 1 ] );                    
                }
                if( strstr( buffer , "DIAL TWO") != NULL )                
                {   system( configfilebuffer[ 2 ] );                    
                }
                if( strstr( buffer , "DIAL THREE") != NULL )                
                {   system( configfilebuffer[ 3 ] );                    
                }
                if( strstr( buffer , "DIAL FOUR") != NULL )                
                {   system( configfilebuffer[ 4 ] );                    
                }
                if( strstr( buffer , "DIAL FIVE") != NULL )
                {   system( configfilebuffer[ 5 ] );                    
                }
                if( strstr( buffer , "DIAL SIX") != NULL )                
                {   system( configfilebuffer[ 6 ] );                    
                }
                if( strstr( buffer , "DIAL SEVEN") != NULL )                
                {   system( configfilebuffer[ 7 ] );                    
                }
                if( strstr( buffer , "DIAL EIGHT") != NULL )                
                {   system( configfilebuffer[ 8 ] );                    
                }
                if( strstr( buffer , "DIAL NINE") != NULL )                
                {   system( configfilebuffer[ 9 ] );                    
                }

            } /* end if strstr( </s> ) */

            memset( buffer , '\0' , sizeof( buffer) );
            charcounter = 0;                        
        }             
        c = fgetc( stdin );
    } /* end while c != EOF */

    fclose( fptr );    
    return 0;
} /* end main */




int getConfigurationFromFile ( char configfilebuffer [ BUFFERMAX ][ LINEMAX ]  )
{
    int linecounter = 0;
    FILE* configfileptr;

    configfileptr = fopen( "conf.txt" , "r" );   
    if( configfileptr == NULL )
    {    fprintf( stderr , "\n\n!!!!!Error opening configuration file\n\n");         
         exit(1);
    }

    memset( configfilebuffer , '\0' , sizeof( configfilebuffer ) );


    while( ! feof(configfileptr) )
    {   
        fgets( configfilebuffer[ linecounter ] , LINEMAX , configfileptr);
        fputs( configfilebuffer[ linecounter ] , stdout );
        linecounter++;        
    }

    fclose( configfileptr );    
    return linecounter;
}/* end getConfigurationFromFile function */

  • « speech recognition julius voxforge commands
  • bootable floppy dos INCOMPLETE »

Published

Aug 8, 2010

Category

c

~311 words

Tags

  • c 95
  • command 29
  • file 92
  • julius 2
  • menu 9