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

📄 cmdline.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************MPEG-4 Audio VMCommand line moduleThis software module was originally developed byCharalampos Ferkidis (University of Hannover / ACTS-MoMuSys)Heiko Purnhagen (University of Hannover / ACTS-MoMuSys)partially based on a concept by FhG IIS, Erlangenand edited byin the course of development of the MPEG-2 NBC/MPEG-4 Audio standardISO/IEC 13818-7, 14496-1,2 and 3. This software module is animplementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio toolsas specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC givesusers of the MPEG-2 NBC/MPEG-4 Audio standards free license to thissoftware module or modifications thereof for use in hardware orsoftware products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audiostandards. Those intending to use this software module in hardware orsoftware products are advised that this use may infringe existingpatents. The original developer of this software module and his/hercompany, the subsequent editors and their companies, and ISO/IEC haveno liability for use of this software module or modifications thereofin an implementation. Copyright is not released for non MPEG-2NBC/MPEG-4 Audio conforming products. The original developer retainsfull right to use the code for his/her own purpose, assign or donatethe code to a third party and to inhibit third party from using thecode for non MPEG-2 NBC/MPEG-4 Audio conforming products. Thiscopyright notice must be included in all copies or derivative works.Copyright (c) 1996.Source file: cmdline.c$Id: cmdline.c,v 1.9 1999/04/23 16:02:04 purnhage Exp $Required modules:common.o		common moduleAuthors:      partially based on a concept by FHG <iis.fhg.de>CF    Charalampos Ferekidis, Uni Hannover <ferekidi@tnt.uni-hannover.de>HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>Changes:28-may-96   CF    added functions for parsing of init files and strings05-jun-96   HP    minor changes                  moved ErrorMsg() to seperat module06-jun-96   HP    setDefault added to CmdLineEval()07-jun-96   HP    use CommonProgName(), CommonWarning(), CommonExit()10-jun-96   HP    ...13-jun-96   HP    changed ComposeFileName()14-jun-96   HP    fixed bug in ComposeFileName()19-jun-96   HP    changed ComposeFileName()                  fixed bug in CmdLineParseString()20-jun-96   HP    added NOTE re CmdLineParseString()08-aug-96   HP    changed string handling in CmdLineParseString()                  changed handling of variable length argument list                  added CmdLineEvalFree(), CmdLineParseFree()09-aug-96   HP    ...14-aug-96   HP    fixed minor bug in CmdLineHelp(), added debug code26-aug-96   HP    CVS27-aug-96   HP    fixed bug in CmdLineEvalFree()10-dec-96   HP    changed dflt. extension concat in ComposeFileName()07-apr-97   HP    "-" support in CmdLineEval() and ComposeFileName()04-may-98   HP/BT unsigned in ComposeFileName()**********************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "cmdline.h"		/* command line module */#include "common_m4a.h"		/* common module *//* ---------- declarations ---------- */#define MAX_HELP_SIZE 4096	/* max length of parameter/switch help */#define MAX_TOKEN_NUM 4096	/* max num of tokens generated by parser */#define MAX_LINE_SIZE 1024	/* max length of line in parsed init file */#define MAX_FILE_SIZE 65536	/* max length of parsed init file *//* ---------- variables ---------- */static int CLdebugLevel = 0;	/* debug level *//* ---------- internal functions ---------- *//* StripPath() *//* Strip path from file name. */static char *StripPath (  char *fileName)	/* in: file name */			/* returns: file name without path */{  char *tmpName;  do {    tmpName = strchr(fileName,':');    if (tmpName==NULL)      tmpName=strchr(fileName,'\\');    if (tmpName==NULL)      tmpName=strchr(fileName,'/');    if (tmpName!=NULL)      fileName = tmpName+1;  } while (tmpName!=NULL);  return fileName;}/* ---------- functions ---------- *//* CmdLineInit() *//* Init command line module. */void CmdLineInit (  int debugLevel)		/* in: debug level */				/*     0=off  1=basic  2=full */{  CLdebugLevel = debugLevel;  if (CLdebugLevel >= 1)    printf("CmdLineInit: debugLevel=%d\n",CLdebugLevel);}/* CmdLineEval() *//* Evaluate parameters and switches in argv[]. *//* Command line mode (progNamePtr!=NULL): *//*   Evaluate command line in argv[] from main() and extract program name *//*   from argv[0]. Switches are identified by preceding '-' in the *//*   command line. *//* Token list mode (progNamePtr==NULL): *//*   Evaluate token list in argv[] (as generated by CmdLineParseString() or *//*   CmdLineParseFile()). Switches are identified by preceding '-' if *//*   paraList!=NULL. Switches don't have a preceding '-' if paraList==NULL. */int CmdLineEval (  int argc,			/* in: num command line args */  char *argv[],			/* in: command line args */  CmdLinePara *paraList,	/* in: parameter info list */				/*     or NULL */  CmdLineSwitch *switchList,	/* in: switch info list */				/*     or NULL */  int setDefault,		/* in: 0 = leave switch used flags and args */				/*         unchanged */				/*     1 = init switch used flags and args */				/*         with defaultValue */  char **progNamePtr)		/* out: program name */				/*      or NULL */				/* returns: */				/*  0=OK  1=help switch  2=error */{  char *progName;  char *tmpProgName;  int i;  int minusFlag;  char *minusChar;  CmdLinePara *paraPtr;  CmdLineSwitch *switchPtr;  int tmpVarArgIdx[MAX_TOKEN_NUM];  int count;    int *varArgIdx;  /* extract program name from argv[0] if command line mode */  if (progNamePtr != NULL) {    progName = StripPath(argv[0]);    if ((tmpProgName=strchr(progName,'.'))!=NULL)      *tmpProgName = '\0';    *progNamePtr = progName;    CommonProgName(progName);  }  else	/* progNamePtr==NULL */    progName = NULL;  /* set minusFlag if switches are preceded by '-' */  minusFlag = (progNamePtr!=NULL || paraList!=NULL);  minusChar = (minusFlag) ? "-" : "";      if (CLdebugLevel >= 1)    printf("CmdLineEval: argc=%d  mode=%s  minusChar=\"%s\"\n",	   argc,(progNamePtr!=NULL)?"cmd line":"token list",minusChar);  if (setDefault) {    /* reset switch used flags and evaluate default values */    switchPtr = switchList;    while (switchPtr != NULL && switchPtr->switchName != NULL) {      if (switchPtr->argument != NULL) {	if (switchPtr->usedFlag != NULL)	  *((int*)switchPtr->usedFlag) = 0;	if (switchPtr->format == NULL)	  *((int*)switchPtr->argument) = 0;	else	  if (switchPtr->defaultValue != NULL) {	    if (strcmp(switchPtr->format,"%s") == 0)	      *((char**)switchPtr->argument) = switchPtr->defaultValue;	    else	      if (sscanf(switchPtr->defaultValue,switchPtr->format,			 switchPtr->argument) != 1) {		CommonWarning("CmdLineEval: "			      "switch %s%s default argument format error",			      minusChar,switchPtr->switchName);		return 2;	      }	  }      }      switchPtr++;    }  }  /* scan arguments  */  i = (progNamePtr==NULL) ? 0 : 1;	/* skip program name */					/* if command line mode */  paraPtr = paraList;  count = 0;  while (i < argc) {    if ((*argv[i] == '-' && *(argv[i]+1) != '\0') ||	(minusFlag == 0 && *argv[i] != '\0')) {      /* evaluate cmdline switch */      switchPtr = switchList;      while (switchPtr != NULL && switchPtr->switchName != NULL) {	if (strcmp(argv[i]+minusFlag,switchPtr->switchName) == 0) {	  /* switchList entry found */	  if (switchPtr->argument == NULL) {	    /* help switch found */	    return 1;	  }	  if (switchPtr->format != NULL) {	    /* read switch argument */	    if (++i >= argc) {	      CommonWarning("CmdLineEval: switch %s%s has no argument",			    minusChar,switchPtr->switchName);	      return 2;	    }	    else	      if (strcmp(switchPtr->format,"%s") == 0)		*((char**)switchPtr->argument) = argv[i];	      else		if (sscanf(argv[i],switchPtr->format,switchPtr->argument)		    != 1) {		  CommonWarning("CmdLineEval: "				"switch %s%s argument format error",				minusChar,switchPtr->switchName);		  return 2;		}	  }	  else	    /* switch without argument */	    *((int*)switchPtr->argument) = 1;	  /* set switch used flag */	  if (switchPtr->usedFlag != NULL)	    *((int*)switchPtr->usedFlag) = 1;	  break;	/* while (switchPtr ...) */	}	switchPtr++;      }		/* while (switchPtr ...) */      if (switchPtr == NULL || switchPtr->switchName == NULL) {	CommonWarning("CmdLineEval: switch %s unknown",argv[i]);	return 2;      }    }    else {	/* if (*argv[i] == '-' && ...) */      /* evaluate cmdline argument */      if (paraPtr == NULL || paraPtr->argument == NULL) {	CommonWarning("CmdLineEval: too many arguments",argv[i]);	return 2;      }      if (paraPtr->format == NULL) {	/* variable length argument list */	if (count+1 >= MAX_TOKEN_NUM) {	  CommonWarning("CmdLineEval: argument list %s too long",			paraPtr->help);	  return 2;	}	tmpVarArgIdx[count++] = i;      }      else {	if (strcmp(paraPtr->format,"%s") == 0)	  *((char**)paraPtr->argument) = argv[i];	else	  if (sscanf(argv[i],paraPtr->format,paraPtr->argument) != 1) {	    CommonWarning("CmdLineEval: argument %s format error",			  paraPtr->help);	    return 2;	  }	paraPtr++;      }    }        i++;  }		/* while (i < argc) */      if (paraPtr != NULL && paraPtr->argument != NULL &&      paraPtr->format == NULL) {    /* variable length argument list */    if ((varArgIdx = (int*)malloc((count+1)*sizeof(int))) == NULL)      CommonExit(1,"CmdLineEval: memory allocation error (varArgIdx)");    for (i=0; i<count; i++)      varArgIdx[i] = tmpVarArgIdx[i];    varArgIdx[count] = -1;    *((int**)paraPtr->argument) = varArgIdx;    paraPtr++;  }  if (paraPtr != NULL && paraPtr->argument != NULL) {    CommonWarning("CmdLineEval: argument %s is missing",		  paraPtr->help);    return 2;  }  return 0;}/* CmdLineEvalFree() *//* Free memory allocated by CmdLineEval() for variable length *//* argument list. */void CmdLineEvalFree (  CmdLinePara *paraList)	/* in: parameter info list */				/*     or NULL */{  CmdLinePara *paraPtr;  paraPtr = paraList;  while (paraPtr != NULL && paraPtr->argument != NULL)    if (paraPtr->format == NULL) {      free(*((void**)paraPtr->argument));      paraPtr = NULL;    }    else      paraPtr++;  if (CLdebugLevel >= 1)    printf("CmdLineEvalFree: %s\n",	   (paraList && !paraPtr) ? "free varArgIdx" : "no varArgIdx");}/* CmdLineHelp() *//* Print help text about program usage including description of *//* command line parameters and switches. */void CmdLineHelp (  char *progName,		/* in: program name */				/*     or NULL */  CmdLinePara *paraList,	/* in: parameter info list */				/*     or NULL */  CmdLineSwitch *switchList,	/* in: switch info list */				/*     or NULL */  FILE *outStream)		/* in: output stream */				/*     (e.g. stdout) */{  int minusFlag;  char *minusChar;  char help[MAX_HELP_SIZE];	/* copy of help for strtok() */

⌨️ 快捷键说明

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