From nobody Sun Apr 24 06:24:23 2022 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 256891996A9E; Sun, 24 Apr 2022 06:24:25 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KmJ5N271Yz3CYt; Sun, 24 Apr 2022 06:24:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650781464; 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=d3lPowPFmOT5JOYXSifl/PnFM6sK+uGb0ztOPCkxnQI=; b=vlBkrufqNV0MDMUO+/L3GqbHV7tTFTGP2avNPi5ZP1SHjs8SwZXQjTJnAe+8/sthLUKYQ5 mRtmlfP36zvPmAnIoSmDopmPNJAbmmwTDyaaTdgkF+AdIcVZCJPhqQORNEoMGsJFCUiigG t1fYV4Nuy/o1kTQtV1m1Kvi624r6771TWtWjzJ5xjl69J+TUywJwHQWbxpm4/Q/3NHMYg7 h4+UulX8uPpZJIboi5FOONIgOnwwvdmeROO23Q8bQYWxnf6RgRk+TMzXN8+NrypqrZ30YT 4OQdTR+PeR3MMUGV4Nu4m6wk+ThX4mxdlQbupLWR8WdHGNVX8reRZTEgQayYqw== 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 1F1E0213B6; Sun, 24 Apr 2022 06:24:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23O6ON8R043412; Sun, 24 Apr 2022 06:24:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23O6ONkB043411; Sun, 24 Apr 2022 06:24:23 GMT (envelope-from git) Date: Sun, 24 Apr 2022 06:24:23 GMT Message-Id: <202204240624.23O6ONkB043411@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Piotr Pawel Stefaniak Subject: git: ff2b1ffbb045 - main - bintrans: adjust mmencode.c to style(9) 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pstef X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ff2b1ffbb0454e23de374b0054b4bc06c81336a6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650781464; 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=d3lPowPFmOT5JOYXSifl/PnFM6sK+uGb0ztOPCkxnQI=; b=MU/44afR2lM/dg4r67YCVnNYZAgatz8k3b1+P22IhxntqURoAJCKKA8uhq7MD/xp77TiW6 PHkemBAIE0QpeheCUcp7yVkQsgKNi3u8cxLia/uiBspALTRowCQI/RNPxuj7w7I6se8PkK OiT0clMi+bwji57nNua2e7DR2G1GM3XZJgzwV6Wm1zuYXqcg4NlhHSdRdCG3hN71K+40iE uGNUabGKxrVnWx5Zqi5Teidj9ea93ZnD7Dc+Azhek7yoBCygEqoMO9xeGYKn7w77GSqLaD nRFbVm3AZT5MwcB1n6GFXi6DgYKQziQvEkbCobyKG/jPXxRjR2XUbfI0So/EuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650781464; a=rsa-sha256; cv=none; b=aW+hUc9nG2dKApVpe2hZdsh3nJCA7NlLLec+sfdM9y7/skhBmDfvZsbWaLr96LsRt7YJx9 x6ERH9RsF5l7V+R7r/nL2Rrrfuujn1B7KfVifCfMJZnZ//5W9KSntxlXQRl4nrWWThv/fG QJMT94xd/qSiiiIspDv5+SXKcSlXcaTgIjGAc17O/+am+GxN94ATum+qEaGIf89WfSf0ep vNYFmhr5kkiBv3ZCKD10TS/nQsoB3RT1OGWMLPVOMQS+ySc/kGLIaRsdnr5NOimybRjD4q 2D2bGO8SjgEHUHOGBaiw036uovs1U9G26HfQuRcVcJfyXLlDeqpGPHZ4vn1HIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pstef: URL: https://cgit.FreeBSD.org/src/commit/?id=ff2b1ffbb0454e23de374b0054b4bc06c81336a6 commit ff2b1ffbb0454e23de374b0054b4bc06c81336a6 Author: Piotr Pawel Stefaniak AuthorDate: 2022-04-15 13:00:36 +0000 Commit: Piotr Pawel Stefaniak CommitDate: 2022-04-24 06:19:49 +0000 bintrans: adjust mmencode.c to style(9) --- usr.bin/bintrans/mmencode.c | 445 ++++++++++++++++++++++---------------------- 1 file changed, 224 insertions(+), 221 deletions(-) diff --git a/usr.bin/bintrans/mmencode.c b/usr.bin/bintrans/mmencode.c index 511e470150bb..a391f4d7e1d4 100644 --- a/usr.bin/bintrans/mmencode.c +++ b/usr.bin/bintrans/mmencode.c @@ -1,52 +1,53 @@ /* Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore) -Permission to use, copy, modify, and distribute this material -for any purpose and without fee is hereby granted, provided -that the above copyright notice and this permission notice -appear in all copies, and that the name of Bellcore not be -used in advertising or publicity pertaining to this -material without the specific, prior written permission -of an authorized representative of Bellcore. BELLCORE -MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY -OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS", +Permission to use, copy, modify, and distribute this material +for any purpose and without fee is hereby granted, provided +that the above copyright notice and this permission notice +appear in all copies, and that the name of Bellcore not be +used in advertising or publicity pertaining to this +material without the specific, prior written permission +of an authorized representative of Bellcore. BELLCORE +MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY +OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. */ +#include #include #include #include #include -int PendingBoundary(s, Boundaries, BoundaryCt) -char *s; -char **Boundaries; -int *BoundaryCt; +static int +PendingBoundary(char *s, char **Boundaries, int *BoundaryCt) { - int i, len; + int i; + size_t len; - if (s[0] != '-' || s[1] != '-') return(0); + if (s[0] != '-' || s[1] != '-') + return (0); - - for (i=0; i < *BoundaryCt; ++i) { - len = strlen(Boundaries[i]); - if (!strncmp(s, Boundaries[i], len)) { - if (s[len] == '-' && s[len+1] == '-') *BoundaryCt = i; - return(1); - } - } - return(0); + for (i = 0; i < *BoundaryCt; ++i) { + len = strlen(Boundaries[i]); + if (strncmp(s, Boundaries[i], len) == 0) { + if (s[len] == '-' && s[len + 1] == '-') + *BoundaryCt = i; + return (1); + } + } + return (0); } -static char basis_hex[] = "0123456789ABCDEF"; -static char index_hex[128] = { - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1, - -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, - -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 +#define basis_hex "0123456789ABCDEF" +static const char index_hex[128] = { + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1, + -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1, + -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 }; /* The following version generated complaints on Solaris. */ @@ -54,201 +55,203 @@ static char index_hex[128] = { /* Since we're no longer ever calling it with anything signed, this should work: */ #define hexchar(c) (((c) > 127) ? -1 : index_hex[(c)]) -void toqp(infile, outfile) -FILE *infile, *outfile; +static void +toqp(FILE *infile, FILE *outfile) { - int c, ct=0, prevc=255; - while ((c = getc(infile)) != EOF) { - if ((c < 32 && (c != '\n' && c != '\t')) - || (c == '=') - || (c >= 127) - /* Following line is to avoid single periods alone on lines, - which messes up some dumb smtp implementations, sigh... */ - || (ct == 0 && c == '.')) { - putc('=', outfile); - putc(basis_hex[c>>4], outfile); - putc(basis_hex[c&0xF], outfile); - ct += 3; - prevc = 'A'; /* close enough */ - } else if (c == '\n') { - if (prevc == ' ' || prevc == '\t') { - putc('=', outfile); /* soft & hard lines */ - putc(c, outfile); - } - putc(c, outfile); - ct = 0; - prevc = c; - } else { - if (c == 'F' && prevc == '\n') { - /* HORRIBLE but clever hack suggested by MTR for sendmail-avoidance */ - c = getc(infile); - if (c == 'r') { - c = getc(infile); - if (c == 'o') { - c = getc(infile); - if (c == 'm') { - c = getc(infile); - if (c == ' ') { - /* This is the case we are looking for */ - fputs("=46rom", outfile); - ct += 6; - } else { - fputs("From", outfile); - ct += 4; - } - } else { - fputs("Fro", outfile); - ct += 3; - } - } else { - fputs("Fr", outfile); - ct += 2; - } - } else { - putc('F', outfile); - ++ct; - } - ungetc(c, infile); - prevc = 'x'; /* close enough -- printable */ - } else { /* END horrible hack */ - putc(c, outfile); - ++ct; - prevc = c; - } - } - if (ct > 72) { - putc('=', outfile); - putc('\n', outfile); - ct = 0; - prevc = '\n'; - } - } - if (ct) { - putc('=', outfile); - putc('\n', outfile); - } + int c, ct = 0, prevc = 255; + + while ((c = getc(infile)) != EOF) { + if ((c < 32 && (c != '\n' && c != '\t')) + || (c == '=') + || (c >= 127) + /* Following line is to avoid single periods alone on lines, + which messes up some dumb smtp implementations, sigh... */ + || (ct == 0 && c == '.')) { + putc('=', outfile); + putc(basis_hex[c >> 4], outfile); + putc(basis_hex[c & 0xF], outfile); + ct += 3; + prevc = 'A'; /* close enough */ + } else if (c == '\n') { + if (prevc == ' ' || prevc == '\t') { + putc('=', outfile); /* soft & hard lines */ + putc(c, outfile); + } + putc(c, outfile); + ct = 0; + prevc = c; + } else { + if (c == 'F' && prevc == '\n') { + /* HORRIBLE but clever hack suggested by MTR for sendmail-avoidance */ + c = getc(infile); + if (c == 'r') { + c = getc(infile); + if (c == 'o') { + c = getc(infile); + if (c == 'm') { + c = getc(infile); + if (c == ' ') { + /* This is the case we are looking for */ + fputs("=46rom", outfile); + ct += 6; + } else { + fputs("From", outfile); + ct += 4; + } + } else { + fputs("Fro", outfile); + ct += 3; + } + } else { + fputs("Fr", outfile); + ct += 2; + } + } else { + putc('F', outfile); + ++ct; + } + ungetc(c, infile); + prevc = 'x'; /* close enough -- printable */ + } else { /* END horrible hack */ + putc(c, outfile); + ++ct; + prevc = c; + } + } + if (ct > 72) { + putc('=', outfile); + putc('\n', outfile); + ct = 0; + prevc = '\n'; + } + } + if (ct) { + putc('=', outfile); + putc('\n', outfile); + } } -void fromqp(infile, outfile, boundaries, boundaryct) -FILE *infile, *outfile; -char **boundaries; -int *boundaryct; +static void +fromqp(FILE *infile, FILE *outfile, char **boundaries, int *boundaryct) { - unsigned int c1, c2; - int sawnewline = 1, neednewline = 0; - /* The neednewline hack is necessary because the newline leading into - a multipart boundary is part of the boundary, not the data */ + int c1, c2; + bool sawnewline = true, neednewline = false; + /* The neednewline hack is necessary because the newline leading into + a multipart boundary is part of the boundary, not the data */ - while ((c1 = getc(infile)) != EOF) { - if (sawnewline && boundaries && (c1 == '-')) { - char Buf[200]; - unsigned char *s; + while ((c1 = getc(infile)) != EOF) { + if (sawnewline && boundaries && c1 == '-') { + char Buf[200]; + unsigned char *s; - ungetc(c1, infile); - fgets(Buf, sizeof(Buf), infile); - if (boundaries - && (Buf[0] == '-') - && (Buf[1] == '-') - && PendingBoundary(Buf, boundaries, boundaryct)) { - return; - } - /* Not a boundary, now we must treat THIS line as q-p, sigh */ - if (neednewline) { - putc('\n', outfile); - neednewline = 0; - } - for (s=(unsigned char *) Buf; *s; ++s) { - if (*s == '=') { - if (!*++s) break; - if (*s == '\n') { - /* ignore it */ - sawnewline = 1; - } else { - c1 = hexchar(*s); - if (!*++s) break; - c2 = hexchar(*s); - putc(c1<<4 | c2, outfile); - } - } else { - putc(*s, outfile); - } - } - } else { - if (neednewline) { - putc('\n', outfile); - neednewline = 0; - } - if (c1 == '=') { - sawnewline = 0; - c1 = getc(infile); - if (c1 == '\n') { - /* ignore it */ - sawnewline = 1; - } else { - c2 = getc(infile); - c1 = hexchar(c1); - c2 = hexchar(c2); - putc(c1<<4 | c2, outfile); - if (c2 == '\n') sawnewline = 1; - } - } else { - if (c1 == '\n') { - sawnewline = 1; - neednewline = 1; - } else { - sawnewline = 0; - putc(c1, outfile); - } - } - } - } - if (neednewline) { - putc('\n', outfile); - neednewline = 0; - } + ungetc(c1, infile); + fgets(Buf, sizeof(Buf), infile); + if (boundaries + && Buf[0] == '-' + && Buf[1] == '-' + && PendingBoundary(Buf, boundaries, boundaryct)) { + return; + } + /* Not a boundary, now we must treat THIS line as q-p, sigh */ + if (neednewline) { + putc('\n', outfile); + neednewline = false; + } + for (s = (unsigned char *)Buf; *s; ++s) { + if (*s == '=') { + if (*++s == 0) + break; + if (*s == '\n') { + /* ignore it */ + sawnewline = true; + } else { + c1 = hexchar(*s); + if (*++s == 0) + break; + c2 = hexchar(*s); + putc(c1 << 4 | c2, outfile); + } + } else { + putc(*s, outfile); + } + } + } else { + if (neednewline) { + putc('\n', outfile); + neednewline = false; + } + if (c1 == '=') { + sawnewline = false; + c1 = getc(infile); + if (c1 == '\n') { + /* ignore it */ + sawnewline = true; + } else { + c2 = getc(infile); + c1 = hexchar(c1); + c2 = hexchar(c2); + putc(c1 << 4 | c2, outfile); + if (c2 == '\n') + sawnewline = true; + } + } else { + if (c1 == '\n') { + sawnewline = true; + neednewline = true; + } else { + sawnewline = false; + putc(c1, outfile); + } + } + } + } + if (neednewline) { + putc('\n', outfile); + neednewline = false; + } } -#define QP 2 /* quoted-printable */ - -int main(argc, argv) -int argc; -char **argv; +int +main(int argc, char *argv[]) { - int encode = 1, i; - FILE *fp = stdin; - FILE *fpo = stdout; + int i; + bool encode = true; + FILE *fp = stdin; + FILE *fpo = stdout; - for (i=1; i= argc) { - fprintf(stderr, "mimencode: -o requires a file name.\n"); - exit(-1); - } - fpo = fopen(argv[i], "w"); - if (!fpo) { - perror(argv[i]); - exit(-1); - } - break; - case 'u': - encode = 0; - break; - default: - fprintf(stderr, - "Usage: mmencode [-u] [-o outputfile] [file name]\n"); - exit(-1); - } - } else { - fp = fopen(argv[i], "r"); - if (!fp) { - perror(argv[i]); - exit(-1); - } - } - } - if (encode) toqp(fp, fpo); else fromqp(fp, fpo, NULL, 0); - return(0); + for (i = 1; i < argc; ++i) { + if (argv[i][0] == '-') { + switch (argv[i][1]) { + case 'o': + if (++i >= argc) { + fprintf(stderr, "mimencode: -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: + fprintf(stderr, + "Usage: mmencode [-u] [-o outputfile] [file name]\n"); + exit(EXIT_FAILURE); + } + } else { + fp = fopen(argv[i], "r"); + if (fp == NULL) { + perror(argv[i]); + exit(EXIT_FAILURE); + } + } + } + if (encode) + toqp(fp, fpo); + else + fromqp(fp, fpo, NULL, 0); + return (0); } -