⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cli.c

📁 4.8k/s速率FS1016标准语音压缩源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*#define	sun*/#include <stdio.h>#include <stdlib.h>#include <string.h>/*#include <sys/time.h>*/#include "main.h"#include "cli.h"/*#ifdef sun#include <unistd.h>#endif*/static void Usage(char	progname[]);static void ShortUsage(char	progname[],int	help);static int Parse(int	argc, char	*argv[], CLI	*UserParams,char	**infile, char	**outfile);static void GetNewArgs(int	i, char	*argv[], int	argc,int	*nargc, char	***nargv);static void AssignVal(FILE	*fp, int	arg_size,char	filename[],char	*new_args[]);/**************************************************************************** ROUTINE*               cli** FUNCTION*               UNIX Command line interface.*		Read and check the UNIX command line.*		Report job characteristics and performance.** SYNOPSIS*	cli (argc, argv, UserParams, infile, outfile)**   formal**			data	I/O*	name		type	type	function*       -------------------------------------------------------------------*	argc		int	 i	Number of arguments in command line*	argv		char	 i	Command line arguments*	UserParams	CLI	 o	User Parameters*	infile		char	 o	Name of input file*	outfile		char	 o 	Name of output file*****************************************************************************			CELP COMMAND*NAME:*     celp - execute the CELP coder**     The celp command generates a codebook-excited-linear-prediction*     processed output file from an input file.**SYNOPSIS:*     prog ifile ofile [options]*     prog -p [pfile]*     prog -h**ARGUMENTS:*	-a T/F*		>>Perform or not perform analysis *		(default=TRUE)*	-b 'bit error file name' *		>>Name of bit error file to read *		(default=BitErrors.txt)*	-c 'channel file name' *		>>Name of channel file to read/write *		(default=ChanFile.hex)*	-d 'edac params file name' *		>>Name of error parameters file to read (edac will be performed) *		(default=no edac)*	-e error rate*		>>Error rate is any number between 0 and 1 *		(default=0.0)*	-h*		>>Prints CELP parameters*	-p 'parameter file name' *		>>Name of parameter file to read for option values *		(default=CelpParms.par)*	-r F/H/B/I*		>>Read or not read channel file into synthesis in hex, binary, or binary_int format*		(default=FALSE)*	-s T/F*		>>Perform or not perform synthesis *		(default=TRUE)*	-t c/b/l/o*		>>Channel Type=clear/random bit/random block/other *		('other' requires bit error file name) *		(default=c)*	-w F/H/B/I*		>>Write or not write channel file from analysis in hex, binary, or binary_int format*		(default=FALSE)***************************************************************************/int cli(int	argc, char	*argv[], CLI	*UserParams,char	**infile, char	**outfile){/*char		*dir;time_t		TheTime;*/int		i;int		parm=FALSE;int		nargc;char		**nargv;int		status;/*  Check for a parameter file, and Parse accordingly */	for(i=1;i<argc;i++)	{	  if(strcmp(argv[i], "-p")==0)	{	    parm = TRUE;	    break;	  }	}	if(parm)	{	  GetNewArgs(i, argv, argc, &nargc, &nargv);	  status = Parse(nargc, nargv, UserParams, infile, outfile);	}	else	{	  status = Parse(argc, argv, UserParams, infile, outfile);	}/*  Print information for user if program is not in help mode */	if(status == ALL_VALID)	{/*	  dir = (char *)getcwd((char *)NULL, 83);*//*  General information */	 /* TheTime = time(NULL);	  printf("           Date and Time: %s", ctime(&TheTime));*/	  printf("                 Program: %s\n", argv[0]);	  /*printf("               Directory: %s\n", dir);*/	  printf("              Input file: %s\n", *infile);	  printf("             Output file: %s\n", *outfile);/*  Channel Information */	  printf("                 Channel: ");	  switch(UserParams->channel_type)	{	    case CLEAR:	      printf("Clear\n");	      break;	    case RBER:	      printf("%3.3f%% bit errors\n", UserParams->error_rate*100);	      break;	    case RBLER:	      printf("%3.3f%% block errors\n", UserParams->error_rate*100);	      break;	    case OTHER:	      printf("Errors as described in %s\n", UserParams->bit_error);	      break;	    default:	      printf("********* Unrecognized sequence ***********\n");	      break;	    }/*  Analysis/Synthesis execution */	  printf("               Execution: ");	  if(UserParams->analysis && UserParams->synthesis)	    printf("analyzer and synthesizer\n");	  if(UserParams->analysis && !UserParams->synthesis)	    printf("analyzer only \n");	  if(!UserParams->analysis && UserParams->synthesis)	    printf("synthesizer only\n");	  if(!UserParams->analysis && ! UserParams->synthesis)	    printf("*** no analyzer, no synthesizer => no coder!!! ***\n");/*  Reading/Writing Channels */	  printf("            Channel File:");	  if(UserParams->read_chan && UserParams->write_chan)	{	    printf("*** %s read and written --- this can't be!!! *** \n", UserParams->chan_file);	  }	  else	{	    if(!UserParams->read_chan && !UserParams->write_chan)	      printf(" None\n");	    else	{	      printf(" %s will be", UserParams->chan_file);	      if(UserParams->write_chan == BINARY_INT)	        printf(" written in binary as integers.\n");	      if(UserParams->write_chan == BINARY)	        printf(" written in binary as shorts.\n");	      if(UserParams->write_chan == HEX)	        printf(" written in hex.\n");	      if(UserParams->read_chan == BINARY_INT)	        printf(" read in binary as integers.\n");	      if(UserParams->read_chan == BINARY)	        printf(" read in binary as shorts.\n");	      if(UserParams->read_chan == HEX)	        printf(" read in hex.\n");	    }	  }/*  EDAC */	  printf("                    EDAC:");	  if (UserParams->edac)	{	    printf(" Performed using %s\n", UserParams->error_parms);	  }	  else	{	    printf(" None\n");	  }/*  Encode and Decode parameters */	  printf("         CELP Parameters: ");	  if(UserParams->code_param)	{	    printf("Are Encoded and Decoded\n");	  }	  else	{	    printf("Are NOT Encoded and Decoded\n");	  }/*  Smooth codebook indices and gains */	  printf("               Smoothing:");	  if(UserParams->smoothing)	{	    printf(" On\n");	  }	  else	{	    printf(" Off\n");	  }			}	fflush(stdout);	 	return status;}/**************************************************************************** ROUTINE*		ShortUsage** FUNCTION**		Prints out a short usage message describing how to call*		the program** SYNOPSIS*		ShortUsage(progname, help)**   formal**                       data    I/O*       name            type    type    function*       -------------------------------------------------------------------*	progname	char *	i	Name of the program being executed*	help		int	i	Flag to determine whether "help"*					  message should be displayed****************************************************************************/void ShortUsage(char	progname[],int	help){/*  Let the user know how to use this */	printf("Usage: \t%s [InputFileName] [OutputFileName] [options]\n", progname);	printf("\t%s -p [ParameterFileName]\n",progname);/*  Only print "help" information if calling routines requests it */	if(help)	  printf("\t%s -h for option information\n", progname);}/**************************************************************************** ROUTINE*		Usage** FUNCTION**		Prints out a long usage message describing how to call*		the program and all its options** SYNOPSIS*		Usage(progname)**   formal**                       data    I/O*       name            type    type    function*       -------------------------------------------------------------------*	progname	char *	i	Name of the program being executed****************************************************************************/void Usage(char	progname[]){/*  Print usage information without help information */	ShortUsage(progname, FALSE);/*  Print a description of each option */	printf("Options:\n");	printf("\t-a T/F\n\t\t>>Perform or not perform analysis \n\t\t(default=TRUE)\n");	printf("\t-b 'bit error file name' \n\t\t>>Name of bit error file to read \n\t\t(default=BitErrors.txt)\n");	printf("\t-c 'channel file name' \n\t\t>>Name of channel file to read/write \n\t\t(default=ChanFile.hex)\n");	printf("\t-d 'edac params file name' \n\t\t>>Name of error parameters file to read (edac will be performed) \n");	printf("\t-e error rate\n\t\t>>Error rate is any number between 0 and 1 \n\t\t(default=0.0)\n");	printf("\t-m T/F\n\t\t>>Perform or not perform smoothing of codebook parameters\n\t\t(default=TRUE)\n");	printf("\t-n T/F\n\t\t>>Perform or not perform parameter encoding \n\t\t(default=TRUE)\n");	printf("\t-p 'parameter file name' \n\t\t>>Name of paremeter file to read for option values \n\t\t(default=CelpParms.par)\n");	printf("\t-r F/H/B/I\n\t\t>>Read or not read channel file into synthesis in Hex, Binary, or BinaryInt format\n\t\t(default=FALSE)\n");	printf("\t-s T/F\n\t\t>>Perform or not perform synthesis \n\t\t(default=TRUE)\n");	printf("\t-t c/b/l/o\n\t\t>>Channel Type=clear/random bit/random block/other \n\t\t('other' requires bit error file name) \n\t\t(default=c)\n");	printf("\t-w F/H/B/I\n\t\t>>Write or not write channel file from analysis  in Hex, Binary, or BinaryInt format\n\t\t(default=FALSE)\n");}/**************************************************************************** ROUTINE*		Parse** FUNCTION**		Reads the string of characters passed in and sets the*		appropriate flags.** SYNOPSIS*		Parse(argc, argv, UserParams, infile,  outfile)**   formal**                       data    I/O*       name            type    type    function*       -------------------------------------------------------------------*	argc		int	 i	Number of arguments in command line*	argv		char	 i	Command line arguments*	UserParams	CLI	 o	Structure containing user parameters*	infile		char	 o	Name of input file*	outfile		char	 o 	Name of output file****************************************************************************/#include <ctype.h>int Parse(int	argc, char	*argv[], CLI	*UserParams,char	**infile, char	**outfile){int		i=1,j;int		status=ALL_VALID;int		infile_open = FALSE, outfile_open = FALSE;int		aswitch;/*  If there aren't enough arguments, tell the user how to use this correctly */	if(argc < 2)	{	  ShortUsage(argv[0], TRUE);	  exit(3);	}/*  Read optional arguments */	while (i < argc)	{	  j=0;/*  Look for hyphen */	  if(argv[i][j] != '-') 	{/*  If no hyphen, check for input file name */	    if(!infile_open)	{	      *infile = argv[i];	      infile_open = TRUE;	      i++;	      aswitch = FALSE;	    }	    else	{/*  If no hyphen and not input file, check for output file name */	      if(!outfile_open)	{		*outfile = argv[i];	        outfile_open = TRUE;	        i++;	        aswitch = FALSE;	      }	      else	{/*  If no hyphen, and not an i/o file name, print error message */		printf("Unrecognized delimiter: %c\n", argv[i][j]);		printf("\t(This could be caused by not assigning a specified value to an option)");/*  Change status so calling routines knows that an error occurred */		status = INVALID;	    	break;	      }	    }	    	  }/*  If hyphen, advance to next character and set switch flag */	  else	{	    j++;	    aswitch = TRUE;	  }		  if(aswitch) 	{	/*  If this is actually a switch (not an i/o file) *//*  Find next legal character 	(the next character could be within this argument or in the next) */	  if(argv[i][j] == '\0')	{	    i++; 	    j=0;	  }/*  Look for option */	  switch(argv[i][j])	{/*---------------------------------------------------------------------*/	    case 'a':	/* analysis *//*  Find next legal character */	      j++;	      if(argv[i][j] == '\0')	{	        i++; 		j=0;	      }/*  Assign value if next argument is valid, else consider it TRUE (default) */	      if(i<argc)	{	        if(argv[i][j] == 't' || argv[i][j] == 'T' || argv[i][j] == 'f' || argv[i][j] == 'F')	          UserParams->analysis = (argv[i][j] == 'F' || argv[i][j] == 'f')?FALSE:TRUE;	        else	          i--;	      }	      break;/*---------------------------------------------------------------------*/	    case 'b':/*  Find next legal character */	      j++;	      if(argv[i][j] == '\0')	{	        i++; 		j=0;	      }	      if(i >= argc)	{/*  If no more arguments, declare it invalid */		status = INVALID;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -