From patchwork Thu Aug 20 21:49:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 21778 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6F81844AE38 for ; Fri, 21 Aug 2020 00:55:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4A17068B674; Fri, 21 Aug 2020 00:55:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A7AD868A760 for ; Fri, 21 Aug 2020 00:55:41 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id 9so72245wmj.5 for ; Thu, 20 Aug 2020 14:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=885v4ZVKCIovelMo+eYW/xfvajsG1SjB1S3+Y0Gw+Qo=; b=yH7qv25ndDRZd0/NlSYEt7HUug872D5LH6llyEi29vaFZVQqKffg5G8ffHnzf1YySy bHfUacPh04IplHLmOuWzRFzsPNCthmw8ZMGKF/7fXshXvgzYZ1ATyUrxUEX6fAc7bOW+ 55e+D5blHRqEThZwQLH5tf1RSqLI6H8h9ptd0vDsaAHkkVdrsmx1nKTGibUxNw/v0sSF 150bUEi/KFv4JaLTYV7wxt2SP3HGkMM/OtPZC9rEjSMNw7UY40cQkOFbHvgvZNffTtVC D5oiDoIgSErAvxJtGxkPQpxmbYffYRQNKYAFcWd2pXGunQq7J99QMieMJZAn/70AKWUt hhtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=885v4ZVKCIovelMo+eYW/xfvajsG1SjB1S3+Y0Gw+Qo=; b=c09o9UY06Y3Q32y3NZaJ6LyXNdT94m+MOqL4rTYRErlsnuWkaNV9zF+W0gXMb/X1fz iQ/0XTnm0DxG1kNuYzwBmQx4pysSKtz1Gvwhfr4PDIuxw10D3LsVr8EnGkIhy/ZNueFP 4Ig9NxNPC//+bZfOVaMO/3/z2/QNVY66F2Af7BjyvLN9c6OqvkMlVgDLzqyU8wBqaz1Q XHeYLFHdM7b9yUTZhifhf2jjmx29/IEbPdKg2mSTxbaXHq5UyfQzoBKeJT1TK7jSBDhP ktEgvQZeVgzORpoJqVNTQRmhosTlXH1Mx3feYTb7NSFl+0QrptyUSjXbNBE/onPagd7D Yhjg== X-Gm-Message-State: AOAM530+Z3FpSz/YUtBAfgHcFuNnB7hsu4cw/nvKOMbznkzTco/gPZxd IjyQOA6Qrnsgju29ZmycVNdkPGaql7z8lQ== X-Google-Smtp-Source: ABdhPJxvvHohaphyeE88c4ooVGOmwBYuYzJJeyh+RhptsGPhYhYUE7PRJ19IQYg+3w5Jn0bhlOAlOw== X-Received: by 2002:a1c:7918:: with SMTP id l24mr432126wme.132.1597960157754; Thu, 20 Aug 2020 14:49:17 -0700 (PDT) Received: from [192.168.0.3] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id b204sm91820wmd.34.2020.08.20.14.49.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2020 14:49:16 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <20200816113139.360344-1-george@nsup.org> <20200816162721.k3dmfbt3wt7yn7pf@phare.normalesup.org> <20200816194938.GC2079@akuma.local> <20200816211238.wrz3eokipyxmgz5o@phare.normalesup.org> <20200817084353.GE2114@akuma.local> <20200820174933.sn6l66bodn2dyfso@phare.normalesup.org> From: Mark Thompson Message-ID: <8472b869-e00a-171f-05d4-503379702c3b@jkqxz.net> Date: Thu, 20 Aug 2020 22:49:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200820174933.sn6l66bodn2dyfso@phare.normalesup.org> Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] fftools: Accept more negative prefixes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" In addition to "no", also allow "no_", "disable" and "disable_". --- On 20/08/2020 18:49, Nicolas George wrote: > Alexander Strasser (12020-08-17): >> Here are some suggestions in no particular order: >> >> * auto_conversion_filters (from Marton) > > I can be ok with this one. I really dislike boolean options that default > to yes and have to be disabled with no, because it requires remembering > what the default is, but if that is what everybody else prefers. But we can fix that to be nicer! With this patch, -disable_auto_conversion_filters does what you want. (The duplication below is because one part is used for ffmpeg and the other for ffplay/ffprobe.) - Mark fftools/cmdutils.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 88fdbeaf1e..1a1740b46e 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -345,6 +345,13 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, return 0; } +static const char *negative_prefixes[] = { + "no_", + "no", + "disable_", + "disable", +}; + int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options) { @@ -352,11 +359,18 @@ int parse_option(void *optctx, const char *opt, const char *arg, int ret; po = find_option(options, opt); - if (!po->name && opt[0] == 'n' && opt[1] == 'o') { - /* handle 'no' bool option */ - po = find_option(options, opt + 2); - if ((po->name && (po->flags & OPT_BOOL))) - arg = "0"; + if (!po->name) { + /* Try to match a boolean option with a negative prefix. */ + for (int i = 0; i < FF_ARRAY_ELEMS(negative_prefixes); i++) { + size_t len = strlen(negative_prefixes[i]); + if (!strncmp(opt, negative_prefixes[i], len)) { + po = find_option(options, opt + len); + if (po->name && (po->flags & OPT_BOOL)) { + arg = "0"; + break; + } + } + } } else if (po->flags & OPT_BOOL) arg = "1"; @@ -764,6 +778,7 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], while (optindex < argc) { const char *opt = argv[optindex++], *arg; const OptionDef *po; + int negative_match; int ret; av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt); @@ -831,10 +846,19 @@ do { \ } } - /* boolean -nofoo options */ - if (opt[0] == 'n' && opt[1] == 'o' && - (po = find_option(options, opt + 2)) && - po->name && po->flags & OPT_BOOL) { + /* Boolean options with a negative prefix. */ + negative_match = 0; + for (int i = 0; i < FF_ARRAY_ELEMS(negative_prefixes); i++) { + size_t len = strlen(negative_prefixes[i]); + if (!strncmp(opt, negative_prefixes[i], len)) { + po = find_option(options, opt + len); + if (po->name && (po->flags & OPT_BOOL)) { + negative_match = 1; + break; + } + } + } + if (negative_match) { add_opt(octx, po, opt, "0"); av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with " "argument 0.\n", po->name, po->help);