Created
August 26, 2010 00:34
-
-
Save SilverTab/550569 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* bewbs.c: In goes the bewbs, out goes the C! | |
* By: Jean-Nicolas Jolivet,(c)2010 | |
* (.)(.) ++ptr | |
* (.){.} --ptr | |
* (.)[.] ++*ptr | |
* [.](.) -- *ptr | |
* [.][.] putchar(*ptr) | |
* {.}{.} *ptr=getchar() | |
* {.}[.] while(*ptr) { | |
* [.]{.} } | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#define IZAWESOME 1 | |
#define BEWBS return | |
#define OUTYO 0 | |
const int BOOBSIZE = 3; | |
const char *ROUNDSYMBOL = "(.)"; | |
const char *SQUARESYMBOL = "[.]"; | |
const char *POINTYSYMBOL = "{.}"; | |
typedef enum { | |
NOBOOB, | |
ROUNDBOOB, /* (.) */ | |
SQUAREBOOB, /* [.] */ | |
POINTYBOOB /* {.} */ | |
} boob_t; | |
boob_t type_of_boob(char *boob) | |
{ | |
boob_t boob_type = NOBOOB; | |
if(strncmp(boob, SQUARESYMBOL, BOOBSIZE) == 0) { | |
boob_type = SQUAREBOOB; | |
} else if (strncmp(boob, ROUNDSYMBOL, BOOBSIZE) == 0) { | |
boob_type = ROUNDBOOB; | |
} else if (strncmp(boob, POINTYSYMBOL, BOOBSIZE) == 0) { | |
boob_type = POINTYBOOB; | |
} | |
BEWBS IZAWESOME; | |
} | |
/* Output the header to our resulting C file... */ | |
int output_header(FILE *fp) | |
{ | |
char header[] = "#include <stdio.h>\nint main() {\n \ | |
char a[30000];\n \ | |
char *ptr = a;\n"; | |
fwrite(header, 1, strlen(header), fp); | |
BEWBS IZAWESOME; | |
} | |
int output_footer(FILE *fp) | |
{ | |
char footer[] = "\nreturn 0;\n}"; | |
fwrite(footer, 1, strlen(footer), fp); | |
BEWBS IZAWESOME; | |
} | |
int parse_bewbs(char *path, char *outpath) | |
{ | |
char c; | |
FILE *fp; | |
FILE *op; /* output file */ | |
unsigned int line_number = 0; | |
boob_t last_boob = NOBOOB; | |
boob_t current_boob_type = NOBOOB; | |
int inner_boob_index = 0; | |
unsigned int boob_count = 0; | |
char current_boob[3]; | |
char current_pair[7]; | |
char output[15]; | |
/* open that file */ | |
fp = fopen(path, "r"); | |
op = fopen(outpath, "w"); | |
/* Output the header */ | |
output_header(op); | |
while((c = fgetc(fp)) != EOF) | |
{ | |
if(c == '\n') | |
line_number++; | |
if(c != ' ' && c != '\n' && c != '\t') { | |
/* not whitespace! */ | |
if(inner_boob_index < BOOBSIZE) | |
{ | |
/* squeeze the boob */ | |
current_boob[inner_boob_index] = c; | |
inner_boob_index++; | |
} | |
if(inner_boob_index == BOOBSIZE) | |
{ | |
/* end of a boob... */ | |
if(last_boob == NOBOOB){ | |
/* it's a left boob! */ | |
last_boob = type_of_boob(current_boob); | |
} | |
else { | |
/* we have a pair! SWEET */ | |
current_boob_type = type_of_boob(current_boob); | |
if(last_boob == ROUNDBOOB && | |
current_boob_type == ROUNDBOOB) { | |
strcpy(output, "\t++ptr;\n"); | |
} | |
else if(last_boob == ROUNDBOOB && | |
current_boob_type == POINTYBOOB) { | |
strcpy(output, "\t--ptr;\n"); | |
} else if(last_boob == ROUNDBOOB && | |
current_boob_type == SQUAREBOOB) { | |
strcpy(output, "\t++*ptr;\n"); | |
} else if(last_boob == SQUAREBOOB && | |
current_boob_type == ROUNDBOOB) { | |
strcpy(output, "\t--*ptr;\n"); | |
} else if(last_boob == SQUAREBOOB && | |
current_boob_type == SQUAREBOOB) { | |
strcpy(output, "\tputchar(*ptr);\n"); | |
} else if(last_boob == POINTYBOOB && | |
current_boob_type == POINTYBOOB) { | |
strcpy(output, "\t*ptr=getchar();\n"); | |
} else if(last_boob == POINTYBOOB && | |
current_boob_type == SQUAREBOOB) { | |
strcpy(output, "\twhile(*ptr) {\n"); | |
} else if(last_boob == SQUAREBOOB && | |
current_boob_type == POINTYBOOB) { | |
strcpy(output, "\t}\n"); | |
} else { | |
// ERROR! | |
fprintf(stderr, "BAD BEWBS (%ld)\n", line_number); | |
return 0; | |
} | |
if(output) | |
fwrite(output,1, strlen(output), op); | |
last_boob = NOBOOB; | |
} | |
current_boob_type = NOBOOB; | |
inner_boob_index = 0; | |
} | |
} | |
} | |
/* Output footer */ | |
output_footer(op); | |
fclose(fp); | |
fclose(op); | |
BEWBS IZAWESOME; | |
} | |
int main (int argc, char **argv) | |
{ | |
char *ovalue = NULL; | |
char *infile = NULL; | |
int index; | |
int c; | |
int bewbs = 0; | |
/* Boring getopt stuff */ | |
opterr = 0; | |
while ((c = getopt (argc, argv, "o:")) != -1) | |
switch (c) | |
{ | |
case 'o': | |
ovalue = optarg; | |
break; | |
case '?': | |
if (optopt == 'o') | |
fprintf (stderr, "Option -%c requires an argument.\n", | |
optopt); | |
else if (isprint (optopt)) | |
fprintf (stderr, "Unknown option `-%c'.\n", optopt); | |
else | |
fprintf (stderr, | |
"Unknown option character `\\x%x'.\n", | |
optopt); | |
return 1; | |
default: | |
abort (); | |
} | |
if(argc != 4) { | |
fprintf(stderr, "Dude, wtf? Usage: %s -o outfile infile.bewbs\n", | |
argv[0]); | |
return 1; | |
} | |
infile = argv[3]; | |
/* Ok we have everything! Now parse the hell out of it! */ | |
bewbs = parse_bewbs(infile, ovalue); | |
if(bewbs != IZAWESOME) | |
fprintf(stderr, "Not coo! (In cartman's voice). It failed!\n"); | |
BEWBS OUTYO; | |
} |
You're such a bewb.
Bewb,
Get it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everyone knows you don’t get any bewbs if you use C++.
Real men, men who get laid, use ISO C and inline assembler. #thatisall