On Sun, 09 Jun 2019 14:39:36 -0700, L A Walsh wrote: > 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 > https://www.ioccc.org/1990/tbr.hint). > > > > #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]= > 32]=m[*m=124[m]=9]=6;e(-8),gets(1+(c=q))||exit(0);r(0,0))for(;*++c;);} > r(t,o){*i=i[2]=0;for(u=v+98;m[*--c]^9;m[*c]&32?i[*c&2]= > *u,u-v^98&&++u:3)if(!m[*c]){for(*++c=0;!m[*--c];);*--u= > ++c;}u-v^98?strcmp(*u,"cd")?*c?pipe(f),o=f[1]:1,(p=fork())?e(p),o? > 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 > 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||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?
Clearly, a #define with both "," and "(", NO. Just remember the preprocessor can do almost any dirty trick (is cpp formally turing complete or not ?). > 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; > main(){ > for(m[m[60]=m[62]=32]=m[*m=124[m]=9]=6; > e(-8), gets(1+(c=q)) || xit(0); > r(0,0)) > for(;*++c;); > } > > r(t,o) { > *i=i[2]=0; > for(u=v+98; m[*--c]^9; m[*c]&32 ? i[*c&2] = *u, u-v^98&&++u > : 3 ) > if (!m[*c]) { > for(*++c=0;!m[*--c];); > *--u=++c; > } > u-v^98 > ? 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: > --braces-on-if-line > --braces-on-func-def-line > --braces-on-struct-decl-line > --break-after-boolean-operator > --cuddle-do-while > --cuddle-else > --continuation-indentation2 > --case-indentation2 > --dont-break-function-decl-args > --no-space-after-function-call-names > --no-space-after-parentheses > --paren-indentation2 > --preserve-mtime > --space-special-semicolon > --swallow-optional-blank-lines > --tab-size2 > --use-tabs > > > > . > > > > _______________________________________________ > bug-indent mailing list > bug-indent@gnu.org > https://lists.gnu.org/mailman/listinfo/bug-indent -- Eric Deplagne
signature.asc
Description: Digital signature
_______________________________________________ bug-indent mailing list bug-indent@gnu.org https://lists.gnu.org/mailman/listinfo/bug-indent