/* lain1.c (lain.c) - Don Yang (uguu.org) Preprocess 1: Remove comments, inline functions. 08/11/00 */ #include #include #include #define MAX_TEMPLATE_SIZE 512 #define MAX_OUTPUT_SIZE 9999 #define INIT_OUTPUT_SIZE 183 #define INIT_LEAF_COUNT 4 #define EXPR_COUNT 8 #define TERMINAL_COUNT 16 static int i, j, k, e, s; static int length = INIT_OUTPUT_SIZE; static int leaf = INIT_LEAF_COUNT; static int length0, leaf0; static char code[MAX_OUTPUT_SIZE] = "Zenum" "{" "x=Y127,y,z" "};" "Zchar t[z];" "Yint i,j,k;" "Zmain(Yint c,Zchar**a)" "{" "Yfor(i=j=t[x]=t[y]=0;i ' ' ) { charcount++; if( template[tindex] > 0 ) ++template[tindex]; else template[++tindex] = 1; } else { if( template[tindex] < 0 ) template[tindex]--; else template[++tindex] = -1; } } template[++tindex] = MAX_OUTPUT_SIZE; for(; length < charcount;) { k = rand() % leaf; for(i = j = 0; j <= k; i++) { if( code[i] == '@' ) j++; } i--; length0 = length--; leaf0 = leaf--; do { e = rand() % EXPR_COUNT; length0 = length; leaf0 = leaf; for(j = 0; expr[e][j]; j++) { if( expr[e][j] == '@' ) leaf0++; length0++; } } while( length0 > charcount + 1 ); length = length0; leaf = leaf0; for(s = 0; code[s]; s++); for(; s >= i; code[s-- + j - 1] = code[s]); for(k = 0; expr[e][k]; code[i + k++] = expr[e][k]); } for(i = 0; code[i]; i++) { if( code[i] == '@' ) code[i] = terminal[rand() % TERMINAL_COUNT]; } for(tindex = i = k = 0; code[i]; tindex++) { if( template[tindex] ) { if( template[tindex] > 0 ) { if( code[i] >= 'X' && code[i] <= 'Z' ) j = code[i++] - 'V'; else j = 1; for(; j-- > 0; template[tindex]--) { if( k ) k--; else putchar(code[i++]); } if( template[tindex] > 0 ) tindex--; else k = -template[tindex]; } else { for(; template[tindex]; template[tindex]++) { if( k ) k--; else putchar(' '); } } } else { putchar('\n'); k = 0; } } putchar('\n'); return 0; }