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

📄 cmdutils.c

📁 DawnLightPlayer,一个新的基于ffmpeg的全功能播放器
💻 C
字号:
#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <errno.h>#include "avformat.h"#include "cmdutils.h"int av_strstart(const char *str, const char *pfx, const char **ptr){	while (*pfx && *pfx == *str)	{		pfx++;		str++;	}	if (!*pfx && ptr)		*ptr = str;	return !*pfx;}int av_stristart(const char *str, const char *pfx, const char **ptr){	while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str))	{		pfx++;		str++;	}	if (!*pfx && ptr)		*ptr = str;	return !*pfx;}size_t av_strlcpy(char *dst, const char *src, size_t size){	size_t len = 0;	while (++len < size && *src)		*dst++ = *src++;	if (len <= size)		*dst = 0;	return len + strlen(src) - 1;}size_t av_strlcat(char *dst, const char *src, size_t size){	size_t len = strlen(dst);	if (size <= len + 1)		return len + strlen(src);	return len + av_strlcpy(dst + len, src, size - len);}size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...){	int len = strlen(dst);	va_list vl;	va_start(vl, fmt);	len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);	va_end(vl);	return len;}void show_help_options(const OptionDef *options, const char *msg, int mask, int value){	const OptionDef *po;	int first;	first = 1;	for (po = options; po->name != NULL; po++)	{		char buf[64];		if ((po->flags & mask) == value)		{			if (first)			{				printf("%s", msg);				first = 0;			}			av_strlcpy(buf, po->name, sizeof(buf));			if (po->flags & HAS_ARG)			{				av_strlcat(buf, " ", sizeof(buf));				av_strlcat(buf, po->argname, sizeof(buf));			}			printf("-%-17s  %s\n", buf, po->help);		}	}}static const OptionDef* find_option(const OptionDef *po, const char *name){	while (po->name != NULL)	{		if (!strcmp(name, po->name))			break;		po++;	}	return po;}void parse_options(int argc, char **argv, const OptionDef *options,                   void (* parse_arg_function)(const char*)){	const char *opt, *arg;	int optindex, handleoptions=1;	const OptionDef *po;	/* parse options */	optindex = 1;	while (optindex < argc)	{		opt = argv[optindex++];		if (handleoptions && opt[0] == '-' && opt[1] != '\0')		{			if (opt[1] == '-' && opt[2] == '\0')			{				handleoptions = 0;				continue;			}			po= find_option(options, opt + 1);			if (!po->name)				po= find_option(options, "default");			if (!po->name)			{unknown_opt:				fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt);				exit(1);			}			arg = NULL;			if (po->flags & HAS_ARG)			{				arg = argv[optindex++];				if (!arg)				{					fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt);					exit(1);				}			}			if (po->flags & OPT_STRING)			{				char *str;				str = av_strdup(arg);				*po->u.str_arg = str;			}			else if (po->flags & OPT_BOOL)			{				*po->u.int_arg = 1;			}			else if (po->flags & OPT_INT)			{				*po->u.int_arg = atoi(arg);			}			else if (po->flags & OPT_INT64)			{				*po->u.int64_arg = strtoll(arg, (char **)NULL, 10);			}			else if (po->flags & OPT_FLOAT)			{				*po->u.float_arg = atof(arg);			}			else if (po->flags & OPT_FUNC2)			{				if (po->u.func2_arg(opt+1, arg)<0)					goto unknown_opt;			}			else			{				po->u.func_arg(arg);			}		}		else		{			if (parse_arg_function)				parse_arg_function(opt);		}	}}void print_error(const char *filename, int err){	switch (err)	{	case AVERROR_NUMEXPECTED:		fprintf(stderr, "%s: Incorrect image filename syntax.\n"		        "Use '%%d' to specify the image number:\n"		        "  for img1.jpg, img2.jpg, ..., use 'img%%d.jpg';\n"		        "  for img001.jpg, img002.jpg, ..., use 'img%%03d.jpg'.\n",		        filename);		break;	case AVERROR_INVALIDDATA:		fprintf(stderr, "%s: Error while parsing header\n", filename);		break;	case AVERROR_NOFMT:		fprintf(stderr, "%s: Unknown format\n", filename);		break;	case AVERROR(EIO):					fprintf(stderr, "%s: I/O error occured\n"					        "Usually that means that input file is truncated and/or corrupted.\n",					        filename);		break;	case AVERROR(ENOMEM):					fprintf(stderr, "%s: memory allocation error occured\n", filename);		break;	case AVERROR(ENOENT):					fprintf(stderr, "%s: no such file or directory\n", filename);		break;	default:		fprintf(stderr, "%s: Error while opening file\n", filename);		break;	}}void show_banner(void){	printf("\033[32m");	printf("-----------------------------------------------------------------------------\n");	printf("  DawnLightPlayer 2008-02-27 created by kf701 and maddrone\n");	printf("  based on FFMPEG, built on " __DATE__ " " __TIME__ "\n");	printf("  GCC: " __VERSION__ "\n");	printf("-----------------------------------------------------------------------------\n");	printf("\033[39m");	fflush(NULL);}void show_ui_key(void){	printf("\033[33m");	printf("-----------------------------------------------------------------------------\n");	printf("User Interface Basic Keys:\n");	printf(" %-17s  %s\n", "h", "show the help info");	printf(" %-17s  %s\n", "9 and 0", "decrease and increase volume");	printf(" %-17s  %s\n", "q or ESC", "stop playing and quit program");	printf(" %-17s  %s\n", "p or SPACE", "pause or play movie");	printf(" %-17s  %s\n", "<- or ->", "seek backward/forward 10 seconds");	printf(" %-17s  %s\n", "pgdown or pgup", "seek backward/forward  1 minute");	printf(" %-17s  %s\n", "f", "fullscreen or normal size");	printf("-----------------------------------------------------------------------------\n");	printf("\033[39m");	fflush(NULL);}

⌨️ 快捷键说明

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