From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26967 invoked from network); 16 Feb 2023 14:25:29 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 16 Feb 2023 14:25:29 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 687A241245; Fri, 17 Feb 2023 00:25:25 +1000 (AEST) Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by minnie.tuhs.org (Postfix) with ESMTPS id 2B66B40A3F for ; Fri, 17 Feb 2023 00:25:15 +1000 (AEST) Received: by mail-pg1-x52c.google.com with SMTP id x31so1366707pgl.6 for ; Thu, 16 Feb 2023 06:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=OqZnwx2VamTvCdLycpKodKHd53ZPLy922ux5Da+Mzj4=; b=TENShutHo6u9ucJwQ6ib/BM/tohhP96JHX34tZStnr+WI8WN0FMGIYebAgEbV0xRQJ 3OzvBT020ejsAhxDf7H2lmFR5Ca3MSX0ToZwTPHZJFJxmlTXM4tbqxFwgNaHckIj/er6 IDj26+4Jl2AHoIah2lJGCREGVunJCPoSp7SR//dHhojRdxprBZKEtiFXsXGehv3PxkMf g4MflP45xQCH05po2vxcTw0X0/fIiZCqIMv3UeADYwIrMUCgV2gYrtlgVPZOY2dRQOvP OBTZn1B7kke/G7mJEBcooap21lt8KG71pxtiB+BLKqM0Ox2nRYef60tk0Doy72Mf4yS1 anaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OqZnwx2VamTvCdLycpKodKHd53ZPLy922ux5Da+Mzj4=; b=PmWq1JmXqvTERhX+jnHevVQLVxoiOEKqVPYBM59OWxkUjwT363LxirSKvrbHWKomvs nlMtZe+hkdIKNrex/BeZ8CZZAM0Y8ewkd51CljRrMPa+Xufy+RQ65HmwNoednHBR5usM kmmy/obihtB9v1r07BHpOALYjrqjBqNoGhxfm4uu5xXRGI6kuCuSSQAkPp7aanZXG8IM qhxGgE9iT2oNfH25/eGiNjv3LNcLXIfOesO1dVnje6wcmmgzhDiHt9a8nHh9VPYhE/FD 4sfKE7otQkm1JgnTLaH/a31i3bfXzpyJ8vBSd+tgPj1OfJuJmINMJCKV5LAYay3sYzkf rFUA== X-Gm-Message-State: AO0yUKWwybFZaD2Z+E6vVyRPt1b5r8oaggGZ3LkOgcIcZYLL/wIEqFll xi58TmFtQgxPHkP4caCQmIeNoR3o18vY5sHIb+bH5GDQ+EQ= X-Google-Smtp-Source: AK7set+DDuLeP539NDXvemuaqvXRZmvlEBy8FQrt64EGmozCPbHaGsQGUzy6KAWmJqjdvTAp35JbS/lLgUC7upDvqRk= X-Received: by 2002:a62:cd44:0:b0:5a9:10a9:8839 with SMTP id o65-20020a62cd44000000b005a910a98839mr681466pfg.44.1676557514222; Thu, 16 Feb 2023 06:25:14 -0800 (PST) MIME-Version: 1.0 From: KenUnix Date: Thu, 16 Feb 2023 09:24:57 -0500 Message-ID: To: UNIX TUHS Group Content-Type: multipart/alternative; boundary="00000000000014b26905f4d1f718" Message-ID-Hash: TRUUVEXHBHUBY7O7MBSWBZW2IEANFNQJ X-Message-ID-Hash: TRUUVEXHBHUBY7O7MBSWBZW2IEANFNQJ X-MailFrom: ken.unix.guy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] 'more' command for Unix V7 List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --00000000000014b26905f4d1f718 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Here is a simplified 'more' command for Unix V7: /********************************************************************* * UNIX pager (v7 compatible) Chipmaster and KenUnix * * cc -o more more.c * * Usage examples: * man wall | more * more xyz * more abc def xyz * * Started February 15th, 2023 YeOlPiShack.net * * This is the ultimately dumbest version of more I have experienced. * Its main purpose is to illustrate the use of /dev/tty to interact * with the user while in a filter role (stdin -> stdout). This also * leaves stderr clear for actual errors. * * * NOTES on Antiquity: * * - The early C syntax didn't allow for combining type information * in the parenthesized argument list only the names were listed. * Then a "variable" list followed the () and preceded the { that * declared the types for the argument list. * * - There is no "void", specifically there is no distinction * between a function that returns an int or nothing at all. * * - Many of the modern day header files aren't there. * * - Apparently "/dev/tty" couldn't be opened for both reading and * writing on the same FD... at least not in our VM. * * - Apparently \a wasn't defined yet either. So I use the raw code * \007. * * - Modern compilers gripe if you do an assignment and comparison in * the same statement without enclosing the assignment in (). The * original compilers did not. So if it looks like there are too * many ()s it's to appease the modern compiler gods. * * - I'm not sure where they hid errno if there was one. I'd think * there had to be. Maybe Kernighan or Pike knows... * *********************************************************************/ #include /*** Let's make some assumptions about our terminal columns and lines. ***/ #define T_COLS 80 #define T_LINES 24 /*** Let's set up our global working environment ***/ FILE *cin; /* TTY (in) */ FILE *cout; /* | (out) */ int ct =3D 0; /*** message to stderr and exit with failure code ***/ err(msg) char *msg; { fputs(msg, stderr); exit(1); } /*** A poor man's CLear Screen *** * * Yup! This is how they used to do it, so says THE Kenrighan & Pike! * termcap?!?! What's that? */ cls() { int x; for(x=3D0; x1) { er =3D 0; for(x=3D1; x2) { if(!er) cls(); er =3D 0; /* remember all user interaction is on /dev/tty (cin/cout) */ fprintf(cout, ">>> %s <<<\n", argv[x]); pause(); } /* - is tradition for stdin */ if(strcmp("-", argv[x])=3D=3D0) { pg(stdin); /* it must be a file! */ } else if((in=3Dfopen(argv[x], "r"))) { pg(in); fclose(in); } else { /* errors go on stderr... JIC someone want to log */ fprintf(stderr, "Could not open '%s'!\n", argv[x]); fflush(stderr); er =3D 1; /* this prevents cls() above. */ } } /*** no args - read and page stdin ***/ } else { pg(stdin); } return 0; } End... --=20 WWL =F0=9F=93=9A --00000000000014b26905f4d1f718 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Here is a simplified 'more' command for Unix = V7:

/*********************************************= ************************
=C2=A0* UNIX pager (v7 compatible) =C2=A0 Chipm= aster and KenUnix
=C2=A0*
=C2=A0* cc -o more more.c
=C2=A0*
=C2= =A0* Usage examples:
=C2=A0* =C2=A0 man wall | more
=C2=A0* =C2=A0 mo= re xyz
=C2=A0* =C2=A0 more abc def xyz
=C2=A0*
=C2=A0* Started Feb= ruary 15th, 2023 YeOlPiShack.net
=C2=A0*
=C2=A0* This is the ultimate= ly dumbest version of more I have experienced.
=C2=A0* Its main purpose = is to illustrate the use of /dev/tty to interact
=C2=A0* with the user w= hile in a filter role (stdin -> stdout). This also
=C2=A0* leaves std= err clear for actual errors.
=C2=A0*
=C2=A0*
=C2=A0* NOTES on Anti= quity:
=C2=A0*
=C2=A0* =C2=A0 - The early C syntax didn't allow f= or combining type information
=C2=A0* =C2=A0 =C2=A0 in the parenthesized= argument list only the names were listed.
=C2=A0* =C2=A0 =C2=A0 Then a = "variable" list followed the () and preceded the { that
=C2=A0= * =C2=A0 =C2=A0 declared the types for the argument list.
=C2=A0*
=C2= =A0* =C2=A0 - There is no "void", specifically there is no distin= ction
=C2=A0* =C2=A0 =C2=A0 between a function that returns an int or no= thing at all.
=C2=A0*
=C2=A0* =C2=A0 - Many of the modern day header = files aren't there.
=C2=A0*
=C2=A0* =C2=A0 - Apparently "/de= v/tty" couldn't be opened for both reading and
=C2=A0* =C2=A0 = =C2=A0 writing on the same FD... at least not in our VM.
=C2=A0*
=C2= =A0* =C2=A0 - Apparently \a wasn't defined yet either. So I use the raw= code
=C2=A0* =C2=A0 =C2=A0 \007.
=C2=A0*
=C2=A0* =C2=A0 - Modern = compilers gripe if you do an assignment and comparison in
=C2=A0* =C2=A0= =C2=A0 the same statement without enclosing the assignment in (). The
= =C2=A0* =C2=A0 =C2=A0 original compilers did not. So if it looks like there= are too
=C2=A0* =C2=A0 =C2=A0 many ()s it's to appease the modern c= ompiler gods.
=C2=A0*
=C2=A0* =C2=A0 - I'm not sure where they hi= d errno if there was one. I'd think
=C2=A0* =C2=A0 =C2=A0 there had = to be. Maybe Kernighan or Pike knows...
=C2=A0*
=C2=A0***************= ******************************************************/
#include <std= io.h>

/*** Let's make some assumptions about our terminal col= umns and lines. ***/

#define T_COLS =C2=A080
#define T_LINES 24
/*** Let's set up our global working environment ***/

FILE= *cin; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* TTY (in) */
FI= LE *cout; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* =C2=A0| =C2=A0(out) = */
int =C2=A0 ct =3D 0;

/*** message to stderr and exit with fail= ure code ***/

err(msg)
=C2=A0 char *msg;
{
=C2=A0 fputs(msg= , stderr);
=C2=A0 exit(1);
}

/*** A poor man's CLear Scree= n ***
=C2=A0*
=C2=A0* Yup! This is how they used to do it, so says TH= E Kenrighan & Pike!
=C2=A0* termcap?!?! What's that?
=C2=A0*/=

cls()
{
=C2=A0 int x;
=C2=A0 for(x=3D0; x<T_LINES; ++x)= fputc('\n', cout);
=C2=A0 ct =3D 0; /* reset global line count = */
}

/*** The PAUSE prompt & wait ***/

pause()
{=C2=A0 char in[T_COLS+1]; /* TTY input buffer */

=C2=A0 fflush(stdo= ut); /*JIC*/
=C2=A0 fputs("--- [ENTER] to continue --- Ctrl-d exits= ", cout);
=C2=A0 fflush(cout);
=C2=A0 if(!fgets(in, 81, cin)) {=
=C2=A0 =C2=A0 /* ^D / EOF */
=C2=A0 =C2=A0 fputc('\n', cout)= ; /* cleaner terminal */
=C2=A0 =C2=A0 exit(0);
=C2=A0 }
}

= /*** Read and page a "file" ***/

int pg(f)
=C2=A0 FILE = *f;
{
=C2=A0 char =C2=A0buf[T_COLS+1]; =C2=A0 /* input line: usual te= rm width + \0 */

=C2=A0 /*** read and page stdin ***/

=C2=A0 = while(fgets(buf, sizeof(buf), f)) {
=C2=A0 =C2=A0 /* page break at T_LIN= ES */
=C2=A0 =C2=A0 if(++ct=3D=3DT_LINES) {
=C2=A0 =C2=A0 =C2=A0 paus= e();
=C2=A0 =C2=A0 =C2=A0 ct =3D 1;
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 = fputs(buf, stdout);
=C2=A0 }
=C2=A0 return 0;
}

/*** Let= 9;s do some paging!! ***/

int main(argc, argv)
=C2=A0 int argc;=C2=A0 char *argv[];
{
=C2=A0 FILE *in;
=C2=A0 int x, er;
=C2=A0 /*** Grab a direct line to the TTY ***/

=C2=A0 if(!(cin=3Dfo= pen("/dev/tty", "r")) || !(cout=3Dfopen("/dev/tty&= quot;, "w")))
=C2=A0 =C2=A0 err("\007Couldn't get con= trolling TTY\n");

=C2=A0 /*** with CLI args ***/

=C2=A0 = if(argc>1) {
=C2=A0 =C2=A0 er =3D 0;
=C2=A0 =C2=A0 for(x=3D1; x<= ;argc; ++x) {
=C2=A0 =C2=A0 =C2=A0 if(argc>2) {
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 if(!er) cls();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 er =3D 0;
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 /* remember all user interaction is on /dev/tty (c= in/cout) */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(cout, ">>>= %s <<<\n", argv[x]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pause();=
=C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0 /* - is tradition fo= r stdin */
=C2=A0 =C2=A0 =C2=A0 if(strcmp("-", argv[x])=3D=3D0= ) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pg(stdin);

=C2=A0 =C2=A0 =C2=A0 /= * it must be a file! */
=C2=A0 =C2=A0 =C2=A0 } else if((in=3Dfopen(argv[= x], "r"))) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pg(in);
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 fclose(in);
=C2=A0 =C2=A0 =C2=A0 } else {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 /* errors go on stderr... JIC someone want to log */=C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf(stderr, "Could not open '%s&= #39;!\n", argv[x]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fflush(stderr);
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 er =3D 1; /* this prevents cls() above. */
= =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 }

=C2=A0 /*** no args - = read and page stdin ***/
=C2=A0 } else {
=C2=A0 =C2=A0 pg(stdin);
= =C2=A0 }

=C2=A0 return 0;
}

End...
--
WWL =F0=9F=93=9A


--00000000000014b26905f4d1f718--