unindented indenter?
turo
created: 2006-01-27 22:45:04

obsfucation is a kind of art,
an insane art, tough.
Anyway, i like perl obfuscation :-)

But what happens if you find some ugly unindented? ... use unix indent or other code-indenting tool? ... Yep, thats the solution for all those that do not like risks ... but for the rest, here you got a nano-script, for indenting some c code :-)

#!/usr/bin/perl
(/(?:}\s*(?:else(?{$/--})|
(?{$__="\t"x--$/.$_})))/xo,
/(?:{\s*(?{$__="\t"x$/++.$_}))$/o,
print($__?"$__":"\t"x$/.$_),
undef $__) while (<>)

¿how to use it?, very simple:

usage: indent [--help] file
example:
        indent file

I've use this file for testing:

#include 
#include 
#include 

int main() {
int pid,aux,status;
pid = fork();
if ( pid < 0 ) {
perror("fork");
exit(9);
} else if ( pid == 0 ) {
//Child
printf("do nothing ...\n");
exit( 0 );
} else {
printf("father\n");
do {
aux = waitpid(&pid,&status);
} while(pid == aux);
}
printf("end :-)\n");
}

Sure it's no perfect, sure it's useless ... but it's my baby monster ;-)

Dr. Frankesturein

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
Re: unindented indenter?
created: 2006-01-29 12:35:38

Once I had to write a one-liner script for similar purposes when I've extracted a code snippet from a PDF document (or some other similar format, I can't remember) and the indenting and newlines got lost.

perlmonks.org content © perlmonks.org and ambrus, turo

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03