[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

baby shell: code that compiles (for the most part), but indent doesn't l

From: L A Walsh
Subject: baby shell: code that compiles (for the most part), but indent doesn't like it
Date: Sun, 09 Jun 2019 14:39:36 -0700
User-agent: Thunderbird

I'm not sure how to best handle this for the general case,
but for simple cases, probably substituting the define text ink,
then maybe removing it when finished would allow it to work?

I's the ",close(" -- creates a bunch of unmatched ')'

The code which implements a primitive shell was turned
into a obfuscation contest --, so my first thought was to
turn to 'indent' to reformat it (originally from


    #define D ,close(
    char*c,q[512],m[256],*v[99],**u,*i[3];int f[2],p;main(){for(m[m[60]=m[62]=
    r(o,0)D o)D*f):4,wait(0):(o?dup2(*f,0)D*f)D o):*i?1 D
    0),e(open(*i,0)):5,t?dup2(t,1)D t):i[2]?9 D
    e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||exit(1):5;}


        I hand formatted it, and substituted in the value
of the define: ",close(".  But the problem is since the compiler
handles the above, shouldn't 'indent' be able to as well?

if you want to run it, I had to substitute in my own
'exit' value that doesn't cause a compile error.
To get the original out, add an 'e' before the 2 calls
to 'xit' in the source.

#define D ,close(
int xit(int x) { exit(x) ;}

char*c,  q[512], m[256], *v[99], **u, *i[3];
int f[2], p;
      e(-8), gets(1+(c=q)) || xit(0);
r(t,o) {
  for(u=v+98; m[*--c]^9; m[*c]&32 ? i[*c&2] = *u, u-v^98&&++u
                                  : 3 )
    if (!m[*c]) {
    ? strcmp(*u,"cd") 
      ? *c  
        ? pipe(f), o=f[1] 
        : 1, (p=fork()) 
        ? e(p), o 
          ? r(o,0), close(o) , close(*f)
          : 4, wait(0)
        : ( o ? dup2(*f,0), close(*f), close(o)
              : *i  
                ? 1 , close(0), e(open(*i,0)) 
                : 5, t  
                ? dup2(t,1), close(t) 
                : i[2]  
                ? 9 ,close(1), e(creat(i[2],438))
                : 2, e(execvp(*u,u))
      : e(chdir(u[1])*2)
    : 6;
e (x) {
  x < 0 ? write(2,"?\n$ "-x/4, 2), x+1 || xit(1) 
        : 5 ;

Not that it is likely needed, but my ".indent.pro" file is here:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]