All pastes #257280 Raw Edit

Cobi

public shellscript v1 · immutable
#257280 ·published 2006-11-25 03:53 UTC
rendered paste body
#!/bin/shTEMP="`mktemp`.c"echo 'int main () {' \>  $TEMPecho -n 'unsigned char *ptr = malloc(sizeof(unsigned char) * ' \>> $TEMPcat $1 \| grep -oe '\(<\|>\)' \| awk 'BEGIN { count = 0 ; tot = 0; } />/ { count += 1; } /</ { if (count > tot) tot = count; count -= 1 } END { print tot }' \>> $TEMPecho ');' \>> $TEMPcat $1 \| grep -oe '\(+\|-\|<\|>\|\.\|\,\|\[\|\]\)' \| sed 's|+|++*ptr;\n|g' \| sed 's|-|--*ptr;\n|g' \| sed 's|>|++ptr;\n|g' \| sed 's|<|--ptr;\n|g' \| sed 's|\.|putchar(*ptr);\n|g' \| sed 's|,|*ptr = getchar();\n|g' \| sed 's|\[|while (*ptr) {\n|g' \| sed 's|\]|}\n|g' \>> $TEMPecho '}' \>> $TEMPgcc $TEMP -o $2rm -f $TEMP