Skip to content

Instantly share code, notes, and snippets.

@aniruddha-a
Created February 12, 2015 11:12
Show Gist options
  • Save aniruddha-a/33422cceb3e4aa24ed91 to your computer and use it in GitHub Desktop.
Save aniruddha-a/33422cceb3e4aa24ed91 to your computer and use it in GitHub Desktop.
Two-column code (like two-column research papers ;-) )
#!/usr/bin/perl -w
$blk = 0;
while (<STDIN>) {
chomp $_;
if (m/\s>\|<\s/) {
($l, $r) = split (/\s>\|<\s/);
print "$l\n";
$rhalf{$blk} = { 'start'=>$., 'code' => '' } if not defined $rhalf{$blk};
$rhalf{$blk}{'code'} .= "$r\n";
} else {
print $_, "\n";
$blk++;
}
}
foreach $k (keys %rhalf) {
print "#line ",$rhalf{$k}{'start'},"\n";
print $rhalf{$k}{'code'};
}
__DATA__
// $ cat thefoll.c | above.pl > tmp.c && gcc tmp.c
#include <stdio.h>
int main (int argc, char *argv[]) >|< int func(int x)
{ >|< {
int x = 99; >|< if (x) return x;
printf("\n TEST: %d\n", func(x)); >|< return -1;
return 0; >|< }
} >|<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment