[TUHS] v7 source code for sh

Bakul Shah bakul at iitbombay.org
Sun Feb 20 02:06:23 AEST 2022


https://research.swtch.com/shmacro

> On Feb 19, 2022, at 7:44 AM, Will Senn <will.senn at gmail.com> wrote:
> 
>  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20220219/a6609b98/attachment.htm>


More information about the TUHS mailing list