configfile.c
资源名称:NETVIDEO.rar [点击查看]
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:18k
源码类别:
流媒体/Mpeg4/MP4
开发平台:
Visual C++
- /*
- ***********************************************************************
- * COPYRIGHT AND WARRANTY INFORMATION
- *
- * Copyright 2001, International Telecommunications Union, Geneva
- *
- * DISCLAIMER OF WARRANTY
- *
- * These software programs are available to the user without any
- * license fee or royalty on an "as is" basis. The ITU disclaims
- * any and all warranties, whether express, implied, or
- * statutory, including any implied warranties of merchantability
- * or of fitness for a particular purpose. In no event shall the
- * contributor or the ITU be liable for any incidental, punitive, or
- * consequential damages of any kind whatsoever arising from the
- * use of these programs.
- *
- * This disclaimer of warranty extends to the user of these programs
- * and user's customers, employees, agents, transferees, successors,
- * and assigns.
- *
- * The ITU does not represent or warrant that the programs furnished
- * hereunder are free of infringement of any third-party patents.
- * Commercial implementations of ITU-T Recommendations, including
- * shareware, may be subject to royalty fees to patent holders.
- * Information regarding the ITU-T patent policy is available from
- * the ITU Web site at http://www.itu.int.
- *
- * THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE ITU-T PATENT POLICY.
- ************************************************************************
- */
- /*!
- ***********************************************************************
- * file
- * configfile.c
- * brief
- * Configuration handling.
- * author
- * Main contributors (see contributors.h for copyright, address and affiliation details)
- * - Stephan Wenger <stewe@cs.tu-berlin.de>
- * note
- * In the future this module should hide the Parameters and offer only
- * Functions for their access. Modules which make frequent use of some parameters
- * (e.g. picture size in macroblocks) are free to buffer them on local variables.
- * This will not only avoid global variable and make the code more readable, but also
- * speed it up. It will also greatly facilitate future enhancements such as the
- * handling of different picture sizes in the same sequence. n
- * n
- * For now, everything is just copied to the inp_par structure (gulp)
- *
- **************************************************************************************
- * par New configuration File Format
- **************************************************************************************
- * Format is line oriented, maximum of one parameter per line n
- * n
- * Lines have the following format: n
- * <ParameterName> = <ParameterValue> # Comments \n n
- * Whitespace is space and \t
- * par
- * <ParameterName> are the predefined names for Parameters and are case sensitive.
- * See configfile.h for the definition of those names and their mapping to
- * configinput->values.
- * par
- * <ParameterValue> are either integers [0..9]* or strings.
- * Integers must fit into the wordlengths, signed values are generally assumed.
- * Strings containing no whitespace characters can be used directly. Strings containing
- * whitespace characters are to be inclosed in double quotes ("string with whitespace")
- * The double quote character is forbidden (may want to implement something smarter here).
- * par
- * Any Parameters whose ParameterName is undefined lead to the termination of the program
- * with an error message.
- *
- * par Known bug/Shortcoming:
- * zero-length strings (i.e. to signal an non-existing file
- * have to be coded as "".
- *
- * par Rules for using command files
- * n
- * All Parameters are initially taken from DEFAULTCONFIGFILENAME, defined in configfile.h.
- * If an -f <config> parameter is present in the command line then this file is used to
- * update the defaults of DEFAULTCONFIGFILENAME. There can be more than one -f parameters
- * present. If -p <ParameterName = ParameterValue> parameters are present then these
- * overide the default and the additional config file's settings, and are themselfes
- * overridden by future -p parameters. There must be whitespace between -f and -p commands
- * and their respecitive parameters
- ***********************************************************************
- */
- #define INCLUDED_BY_CONFIGFILE_C
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #include "global.h"
- #include "configfile.h"
- static char *GetConfigFileContent (char *Filename);
- static void ParseContent (char *buf, int bufsize);
- static int ParameterNameToMapIndex (char *s);
- static void PatchInp ();
- #define MAX_ITEMS_TO_PARSE 10000
- /*!
- ***********************************************************************
- * brief
- * Parse the command line parameters and read the config files.
- * param ac
- * number of command line parameters
- * param av
- * command line parameters
- ***********************************************************************
- */
- void Configure (int ac, char *av[])
- {
- char *content;
- int CLcount, ContentLen, NumberParams;
- memset (&configinput, 0, sizeof (InputParameters));
- #ifdef H26L_LIB
- if (ac > 0) {
- ParseContent (av[0], strlen(av[0]));
- } else {
- printf("Warning: no configuration givenn");
- }
- #else
- // Process default config file
- printf ("Parsing Configfile %s", DEFAULTCONFIGFILENAME);
- content = GetConfigFileContent (DEFAULTCONFIGFILENAME);
- ParseContent (content, strlen(content));
- printf ("n");
- free (content);
- // Parse the command line
- CLcount = 1;
- while (CLcount < ac)
- {
- if (0 == strncmp (av[CLcount], "-f", 2)) // A file parameter?
- {
- content = GetConfigFileContent (av[CLcount+1]);
- printf ("Parsing Configfile %s", av[CLcount+1]);
- ParseContent (content, strlen (content));
- printf ("n");
- free (content);
- CLcount += 2;
- } else
- {
- if (0 == strncmp (av[CLcount], "-p", 2)) // A config change?
- {
- // Collect all data until next parameter (starting with -<x> (x is any character)),
- // put it into content, and parse content.
- CLcount++;
- ContentLen = 0;
- NumberParams = CLcount;
- // determine the necessary size for content
- while (NumberParams < ac && av[NumberParams][0] != '-')
- ContentLen += strlen (av[NumberParams++]); // Space for all the strings
- ContentLen += 1000; // Additional 1000 bytes for spaces and