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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26785 invoked from network); 19 Feb 2022 15:44:43 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 19 Feb 2022 15:44:43 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id E62499C764; Sun, 20 Feb 2022 01:44:38 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 83E679BA3E; Sun, 20 Feb 2022 01:43:14 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="litGJ9hW"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id D67429BA3E; Sun, 20 Feb 2022 01:43:10 +1000 (AEST) Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by minnie.tuhs.org (Postfix) with ESMTPS id 911C49BA32 for ; Sun, 20 Feb 2022 01:43:07 +1000 (AEST) Received: by mail-oi1-f182.google.com with SMTP id k2so2572536oia.2 for ; Sat, 19 Feb 2022 07:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to:from :subject; bh=+cHMVrV6YAiIC0iITRtjMduIOE7A/aQej6H+rPElor4=; b=litGJ9hW/5vlZxlsQNfU3M9YFgkiyGxX3SwY3IiXpAFFq/sxREFHWjPVeFfM5NSfjT 7S0aAE8MsglIme11jzDwV2GCBK0YNA5bs94MOn74Aw5oZNrK+MXy10CKDu+tlfxqiZV8 CkhnFoA2dq+NLz4g73mweChoQqxNo+W6VkenZ6fB9Y7sMLXebjuBiXd5rUiEAaO0pl/J g1/MYNxTrGZZkPA6NHj9c3LL5gSlOJu2Jq2QHahBVjUnjI+h53LVHTDBxFrfcTYy5CbJ XoBElixwPrPf8qEAVZpeC0Ay9ba2LKnmp30yQTQHzDTo7FSxwDfWdAgN1ci4x5c2dksX Uk+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:from:subject; bh=+cHMVrV6YAiIC0iITRtjMduIOE7A/aQej6H+rPElor4=; b=47KpqcEY8WL9HX71xXRKGIOjRDReshr2/+QAUW1h/tJYfpLnVsAFW3CyottYiIn8oe qMx00QLPT/1pbZcUT/ANFsP+77j5ILm+Zzsk053Xr+i9/VVHCiRd7UjkyLtml1p3O1n1 UToO7f7d5vWIGysQqfAdc1JEJIZlgproA/sboDEp51k2gC8jaeUvSMiMq+AVliPl5HB/ wEG5TrC6Kt/+HMMwYCIX1n5guiWIubS/1DB7GdC4CQCyNJXnWTHfCGu3/bpPj32/0iyx QjESA7ZFYOQqqVqrtHq2LWxQCUlmH7CIIx49PVJqtVIaINrr41FKFd+zl3XINB0QT6+r nFtg== X-Gm-Message-State: AOAM532jotpg6aYWVZkEIcnIvsaCIHlpXL4N150mEY8ehfRSCaj8kAGd muyjrJb73laGRFUskbGEA8BFwvHeVhQ= X-Google-Smtp-Source: ABdhPJzd7R6S71tqtyeYxjxJl6mRfudVwJH3JoZjiuSZfoA7q5fzoqkQ5U+T4gxi8QbfYlcKfu4vfQ== X-Received: by 2002:aca:b7d6:0:b0:2cb:c1ab:cdfd with SMTP id h205-20020acab7d6000000b002cbc1abcdfdmr5664960oif.159.1645285386462; Sat, 19 Feb 2022 07:43:06 -0800 (PST) Received: from [10.8.2.5] ([2.56.188.40]) by smtp.gmail.com with ESMTPSA id f38sm1059464otf.22.2022.02.19.07.43.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Feb 2022 07:43:06 -0800 (PST) Content-Type: multipart/alternative; boundary="------------3ZNwoXiPL9od1qAPTOkP0cjJ" Message-ID: <69d88b37-5817-9a0d-4971-3d8641c2d153@gmail.com> Date: Sat, 19 Feb 2022 09:43:05 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: TUHS main list From: Will Senn Subject: [TUHS] v7 source code for sh X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" This is a multi-part message in MIME format. --------------3ZNwoXiPL9od1qAPTOkP0cjJ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit I have been poring through the v7 source code lately, and came across an oddity I would like to know more about. Specifically, in sh. The code for sh is c, but it makes *extensive* use of of macros, for example: /usr/src/cmd/sh/word.c ... WHILE (c=nextc(0), space(c)) DONE ... The macros for sh are defined in mac.h: /usr/src/cmd/sh/mac.h ... #define BEGIN   { #define END     } #define SWITCH  switch( #define IN      ){ #define ENDSW   } #define FOR     for( #define WHILE   while( #define DO      ){ #define OD      ;} #define REP     do{ #define PER     }while( #define DONE    ); ... I can read the resultant code through the lens of my experience coding c, but I'm curious why the macros and how this came about? In v6, the sh source is straight up c. Is there a story behind it worth knowing? Thanks, Will --------------3ZNwoXiPL9od1qAPTOkP0cjJ Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit I have been poring through the v7 source code lately, and came across an oddity I would like to know more about. Specifically, in sh. The code for sh is c, but it makes extensive use of of macros, for example:
/usr/src/cmd/sh/word.c
...
WHILE (c=nextc(0), space(c)) DONE
...

The macros for sh are defined in mac.h:
/usr/src/cmd/sh/mac.h
...
#define BEGIN   {
#define END     }
#define SWITCH  switch(
#define IN      ){
#define ENDSW   }
#define FOR     for(
#define WHILE   while(
#define DO      ){
#define OD      ;}
#define REP     do{
#define PER     }while(
#define DONE    );
...
I can read the resultant code through the lens of my experience coding c, but I'm curious why the macros and how this came about? In v6, the sh source is straight up c. Is there a story behind it worth knowing?

Thanks,

Will
--------------3ZNwoXiPL9od1qAPTOkP0cjJ--