Re: baby shell: code that compiles (for the most part), but indent doesn't like it
Eric Deplagne <[email protected]> Tue, 11 Jun 2019 10:55:05 +0200
| Newsgroups | gmane.comp.gnu.indent.bugs |
|---|---|
| Message-ID | <[email protected]> |
--===============9106675485609629847==
Content-Type: multipart/signed; micalg=pgp-sha1;
protocol="application/pgp-signature"; boundary="3sv7gENtRriLHjvQ"
Content-Disposition: inline
--3sv7gENtRriLHjvQ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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?
>=20
> I's the ",close(" -- creates a bunch of unmatched ')'
>=20
> 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).
>=20
> =20
>=20
> #define D ,close(
> char*c,q[512],m[256],*v[99],**u,*i[3];int f[2],p;main(){for(m[m[60]=
=3Dm[62]=3D
> 32]=3Dm[*m=3D124[m]=3D9]=3D6;e(-8),gets(1+(c=3Dq))||exit(0);r(0,0))fo=
r(;*++c;);}
> r(t,o){*i=3Di[2]=3D0;for(u=3Dv+98;m[*--c]^9;m[*c]&32?i[*c&2]=3D
> *u,u-v^98&&++u:3)if(!m[*c]){for(*++c=3D0;!m[*--c];);*--u=3D
> ++c;}u-v^98?strcmp(*u,"cd")?*c?pipe(f),o=3Df[1]:1,(p=3Dfork())?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;}
>=20
> -----
>=20
> 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.
>=20
> #define D ,close(
> int xit(int x) { exit(x) ;}
>=20
> char*c, q[512], m[256], *v[99], **u, *i[3];
> int f[2], p;
> main(){
> for(m[m[60]=3Dm[62]=3D32]=3Dm[*m=3D124[m]=3D9]=3D6;
> e(-8), gets(1+(c=3Dq)) || xit(0);
> r(0,0))
> for(;*++c;);
> }
> =20
> r(t,o) {
> *i=3Di[2]=3D0;
> for(u=3Dv+98; m[*--c]^9; m[*c]&32 ? i[*c&2] =3D *u, u-v^98&&++u
> : 3 )
> if (!m[*c]) {
> for(*++c=3D0;!m[*--c];);
> *--u=3D++c;
> }
> u-v^98 =20
> ? strcmp(*u,"cd")=20
> ? *c =20
> ? pipe(f), o=3Df[1]=20
> : 1, (p=3Dfork())=20
> ? e(p), o=20
> ? r(o,0), close(o) , close(*f)
> : 4, wait(0)
> : ( o ? dup2(*f,0), close(*f), close(o)
> : *i =20
> ? 1 , close(0), e(open(*i,0))=20
> : 5, t =20
> ? dup2(t,1), close(t)=20
> : i[2] =20
> ? 9 ,close(1), e(creat(i[2],438))
> : 2, e(execvp(*u,u))
> )
> : e(chdir(u[1])*2)
> : 6;
> }
> =20
> e (x) {
> x < 0 ? write(2,"?\n$ "-x/4, 2), x+1 || xit(1)=20
> : 5 ;
> }
>=20
> -----
> 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
>=20
>=20
>=20
> .
>=20
>=20
>=20
> _______________________________________________
> bug-indent mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/bug-indent
--=20
Eric Deplagne
--3sv7gENtRriLHjvQ
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iD8DBQFc/2xpej7DisjVpq4RAgDAAJsEk7EDivFPKjBvYv3kBvh+MOGjWgCcD7bA
WcmXDPZzJcTa/4iolhM/1VU=
=dUNZ
-----END PGP SIGNATURE-----
--3sv7gENtRriLHjvQ--
--===============9106675485609629847==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYnVnLWluZGVu
dCBtYWlsaW5nIGxpc3QKYnVnLWluZGVudEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t
YWlsbWFuL2xpc3RpbmZvL2J1Zy1pbmRlbnQK
--===============9106675485609629847==--