From nobody Thu Jan 09 09:27:26 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YTKFB5v48z5kRMk; Thu, 09 Jan 2025 09:27:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YTKFB4Bvgz4ZbL; Thu, 9 Jan 2025 09:27:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736414846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5pZ8aj/mvw3eYKxEEWJSyf1C8JmDgOsfyVIqiWvv2xI=; b=pnH00gUlnlkT8GvwGzpIWyUgaMYZsu8DTkXNoWJ1d5tRTom7sNNxADgtDl+cmyWWZQmQ2/ TskfVd4hDxxa+xxyJKS7eldQ/smk02KBTPMdPJ4AB9qcFRbU7V/HUEIVB4UGn0v0GN6/Ml bmHoXKlZtp/Oe5TlZxNUv21Zi82JSD7JSNvMuy5ckXEopHvNFdE0AEZRwZpRn7ruzmyHY8 aEwp8PraIhX4Ra1VV9S3ipozVnltHHIaqgvEi+XvqWFDLQPfnDFmPIX6+Vn4ZJiFagql+N YoTrOV7+nfmfR4ELkp6ymBolZU9OqX8e6wORi2cBC2MipYH9C43YiINN6n9KqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736414846; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5pZ8aj/mvw3eYKxEEWJSyf1C8JmDgOsfyVIqiWvv2xI=; b=ilwH+4R02sNV8oaY2cRO0XVYRcFvWhH8NxyQ1rXksgTGXa2NQRQptXn/wuS2psXcGAv1wS uFgnfXN7nrW3iG3nttkJm8kSRq7t/8P7JMYxabZybMUm8/Mojze48PujaUDf8uppfltrcF FU9WlL/JgNe1cgpqLrVRACu1x4RgiMaFk9i6o/6ASe5HmZxV+j6CUpF3u3eDt0NvPH6ljk ZoccYVyQ0d1MYVfVz1+nZJfbZ1LhXCd0r2xoJibrBiIqaPOszt7MfOJHBczK+1R//soDOu RMrW4b9I/mWQIhIZqJrsjvp7Wpyvs37WbeOPCIW1OSScoel+hwcV0dHLBlHWtQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736414846; a=rsa-sha256; cv=none; b=m7RII3U372dlEDOKOrlr02YUasTGCTdzD+drXHVBmrkXt1tZ4kBnRRu6NOM9kewXQP8KvF cmBTTVBAzOKS0BkO0GKlSQTnISDhNZHu7sInKnmpEvjCM6M9uc2/my0vb1ptnumgGcmfh3 hIGTRzQdX692fIl45ZSRb3wLoPMdQhpsTahV9DG5UomuyXi8IXHPh60DnEuGAj0MDChdwQ lfXIp72jsG3lth/3iKfk/Wt2HrNqAFVUqu3c79RoOL1ElFTWmzF1GY9cd/zKqyEjBcDL4J mkPv5v3/KCqD05H4asOlikJ4djopK23f3UA4Uethj2qhfQrWAiwLlYM5/+v2+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YTKFB3q7lz5P6; Thu, 09 Jan 2025 09:27:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5099RQo1028422; Thu, 9 Jan 2025 09:27:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5099RQYl028419; Thu, 9 Jan 2025 09:27:26 GMT (envelope-from git) Date: Thu, 9 Jan 2025 09:27:26 GMT Message-Id: <202501090927.5099RQYl028419@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: a8d9bd3fa585 - main - bintrans(1): qp switch to getopt_long List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a8d9bd3fa5855fe7583ed05946296ab6b9937d69 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=a8d9bd3fa5855fe7583ed05946296ab6b9937d69 commit a8d9bd3fa5855fe7583ed05946296ab6b9937d69 Author: Baptiste Daroussin AuthorDate: 2025-01-08 11:13:54 +0000 Commit: Baptiste Daroussin CommitDate: 2025-01-09 09:24:34 +0000 bintrans(1): qp switch to getopt_long In preparation for more arguments, switch bintrans qp argument parsing to getopt_long, while here make the decodign argument being -d|--decode for compatibility with base64 encoding/decoding MFC After: 1 week Reviewed by: pstef Differential Revision: https://reviews.freebsd.org/D48380 --- usr.bin/bintrans/bintrans.1 | 4 +-- usr.bin/bintrans/qp.c | 61 +++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/usr.bin/bintrans/bintrans.1 b/usr.bin/bintrans/bintrans.1 index 3376ecd332ed..4177a5c6b9eb 100644 --- a/usr.bin/bintrans/bintrans.1 +++ b/usr.bin/bintrans/bintrans.1 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 23, 2024 +.Dd January 8, 2025 .Dt BINTRANS 1 .Os .Sh NAME @@ -230,7 +230,7 @@ through a dedicated program: is a quoted-printable converter and accepts the following options: .Bl -tag -width indent -.It Fl u +.It Fl d Decode. .It Fl o Ar output_file Output to diff --git a/usr.bin/bintrans/qp.c b/usr.bin/bintrans/qp.c index c2c9dfa7a224..3bff47945acf 100644 --- a/usr.bin/bintrans/qp.c +++ b/usr.bin/bintrans/qp.c @@ -26,6 +26,7 @@ */ #include +#include #include #include #include @@ -151,44 +152,50 @@ static void usage(void) { fprintf(stderr, - "usage: bintrans qp [-u] [-o outputfile] [file name]\n"); + "usage: bintrans qp [-d] [-o outputfile] [file name]\n"); } int main_quotedprintable(int argc, char *argv[]) { - int i; + int ch; bool encode = true; FILE *fp = stdin; FILE *fpo = stdout; - for (i = 1; i < argc; ++i) { - if (argv[i][0] == '-') { - switch (argv[i][1]) { - case 'o': - if (++i >= argc) { - fprintf(stderr, "qp: -o requires a file name.\n"); - exit(EXIT_FAILURE); - } - fpo = fopen(argv[i], "w"); - if (fpo == NULL) { - perror(argv[i]); - exit(EXIT_FAILURE); - } - break; - case 'u': - encode = false; - break; - default: - usage(); - exit(EXIT_FAILURE); - } - } else { - fp = fopen(argv[i], "r"); - if (fp == NULL) { - perror(argv[i]); + static const struct option opts[] = + { + { "decode", no_argument, NULL, 'd'}, + { "output", required_argument, NULL, 'o'}, + {NULL, no_argument, NULL, 0} + }; + + while ((ch = getopt_long(argc, argv, "do:u", opts, NULL)) != -1) { + switch(ch) { + case 'o': + fpo = fopen(optarg, "w"); + if (fpo == NULL) { + perror(optarg); exit(EXIT_FAILURE); } + break; + case 'u': + /* FALLTHROUGH for backward compatibility */ + case 'd': + encode = false; + break; + default: + usage(); + exit(EXIT_FAILURE); + } + }; + argc -= optind; + argv += optind; + if (argc > 0) { + fp = fopen(argv[0], "r"); + if (fp == NULL) { + perror(argv[0]); + exit(EXIT_FAILURE); } } qp(fp, fpo, encode);