-
Fabrice Bellard authored
Originally committed as revision 1936 to svn://svn.ffmpeg.org/ffmpeg/trunk
Fabrice Bellard authoredOriginally committed as revision 1936 to svn://svn.ffmpeg.org/ffmpeg/trunk
cmdutils.c 3.62 KiB
/*
* Various utilities for command line tools
* Copyright (c) 2000-2003 Fabrice Bellard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "avformat.h"
#include "cmdutils.h"
void show_help_options(const OptionDef *options)
{
const OptionDef *po;
int i, expert, first;
printf("Main options are:\n");
for(i=0;i<2;i++) {
first = 1;
for(po = options; po->name != NULL; po++) {
char buf[64];
expert = (po->flags & OPT_EXPERT) != 0;
if (expert == i) {
if (expert && first) {
printf("\nAdvanced options are:\n");
first = 0;
}
strcpy(buf, po->name);
if (po->flags & HAS_ARG) {
strcat(buf, " ");
strcat(buf, po->argname);
}
printf("-%-17s %s\n", buf, po->help);
}
}
}
}
void parse_options(int argc, char **argv, const OptionDef *options)
{
const char *opt, *arg;
int optindex;
const OptionDef *po;
/* parse options */
optindex = 1;
while (optindex < argc) {
opt = argv[optindex++];
if (opt[0] == '-' && opt[1] != '\0') {
po = options;
while (po->name != NULL) {
if (!strcmp(opt + 1, po->name))
break;