/* shinobu1.c (shinobu.c) - Don Yang (uguu.org) Preprocess 1: Inline functions 10/11/00 */ #include #define MAX_STRING_SIZE (2 << 16) #define SPACE ' ' #define FILL_CHAR ';' /* Output code (A-Z = token length, @ = whitespace */ char code[MAX_STRING_SIZE] = /* String headers */ "Dchar" "@p[2B<o;iB--)" "q[i]=q[i-1];" "q[o]=a;" "}" "f()" "{" "Cfor(;(c=q[o])B64B&&c0;jB--)" "{" "Bif((k=q[o])-B59)" "{" "Bif(k-B32)" "g(B59);" "Delse@" "q[o]=B59;" "Freturn+1;" "}" "q[oB++]=e[iB++];" "}" "Freturn+0;" "}" "Freturn+x(e[iB++]);" "}" "s(z*a)" "{" "Cfor(i=o=0;a[i];iB++)" "Bif(a[i]-B32)" "a[oB++]=a[i];" "a[o]=0;" "}" "t(z*a)" "{" "Cfor(i=0;i<2B<B34B&&p[i]B92B&&p[i]B10;jB++)" "Bif(q[o+j]B==B59)" "kB++;" "Bif(!k)" "{" "g(B59);" "Freturn+1;" "}" "Cfor(j=1;j1)" "{" "Cfor(i=0;(c=Ggetchar())>0;q[iB++]=c);" "q[i]=0;" "t(q);" "}" "s(p);" "s(e);" "Cfor(w=u=v=0;wu)" "{" "u=i;" "v=0;" "}" "Bif(iB==u)" "Bif(B++v>B64)" "{" "Cfor(i=0;e[iB++];);" "e[i]=u=0;" "e[i-1]=B59;" "wB++;" "}" "}" "Cfor(i=0;q[i];Gputchar(q[iB++]));" "Bif(w>B31)" "Gputchar(B63);" "Freturn+0;" "}" ; /* Predefined template */ char template[MAX_STRING_SIZE] = "!"; /* Output text / input file */ char string[MAX_STRING_SIZE]; /* Generic data */ int i, j, k, o, c, d; /* Prototypes */ void Compress(char *source); void FindTokenSpace(void); void FormatString(char *source); void WriteChar(char token); void WriteToken(void); /******************************************************************** main */ int main(int argc, char **argv) { /* argv is unused */ /* Read template from stdin if command line arguments exist, otherwise use self template. */ if( argc > 1 ) { for(i = 0; (c = getchar()) != EOF; string[i++] = (char)c); string[i] = 0; for(i = 0; i < MAX_STRING_SIZE; template[i++] = 0); i = 0; for(j = 0; string[j]; j++) { if( (c = string[j]) == '\n' ) { /* Newline */ if( template[i] ) template[++i] = '!'; else template[i++] = '!'; } else if( c <= SPACE ) { /* Whitespace */ if( template[i] >= '#' && template[i] < '[' ) { template[i]++; } else { if( template[i] ) template[++i] = '#'; else template[i] = '#'; } } else { /* Character */ if( template[i] >= ']' && template[i] < '~' ) { template[i]++; } else { if( template[i] ) template[++i] = ']'; else template[i] = ']'; } } } } /* Generate output and adjust template continuously */ Compress(template); Compress(code); for(o = 0; o < MAX_STRING_SIZE; string[o++] = 0); for(i = o = 0; template[i]; i++) { if( (j = template[i]) == '!' ) { string[o++] = '\n'; } else { if( j <= '[' ) for(k = '#'; k++ <= j; string[o++] = SPACE); else for(k = ']'; k++ <= j; string[o++] = FILL_CHAR); } } /* i = index to code o = index to expanded template / output */ i = o = 0; /* Write data strings */ WriteToken(); FormatString(code); FormatString(template); for(; code[i]; WriteToken()); /* End */ for(i = 0; string[i]; putchar(string[i++])); return 0; } /* main() */ /**************************************************************** Compress */ void Compress(char *source) { for(i = o = 0; source[i]; i++) { if( source[i] != SPACE ) source[o++] = source[i]; } source[o] = 0; } /* Compress() */ /********************************************************** FindTokenSpace */ void FindTokenSpace(void) { for(; (c = string[o]) <= SPACE && c; o++); } /* FindTokenSpace() */ /************************************************************ FormatString */ void FormatString(char *source) { /* Write header */ for(d = 0; d < 8; d++) WriteToken(); /* Write contents */ for(d = 0; source[d];) { /* Write start of line */ WriteChar('\"'); /* Count available token space */ for(j = k = 0; string[o + j] > '\n'; j++) { if( string[o + j] == FILL_CHAR ) k++; } /* Write contents */ for(j = 1; source[d] && j < k; j++) WriteChar(source[d++]); WriteChar('\"'); } } /* FormatString() */ /*************************************************************** WriteChar */ void WriteChar(char token) { FindTokenSpace(); string[o++] = token; } /* WriteChar() */ /************************************************************** WriteToken */ void WriteToken(void) { if( (c = code[i]) == '@' ) { i++; if( string[o] <= SPACE ) { if( string[o] ) { o++; return; } } string[o] = SPACE; } else if( c > '@' && c <= 'Z' ) { FindTokenSpace(); c = code[i++] - '@'; for(j = c; j > 0; j--) { /* Adjust template */ if( string[o] == '\n' ) { for(k = MAX_STRING_SIZE - 1; k > o; k--) string[k] = string[k - 1]; } /* Write output */ string[o++] = code[i++]; } } else { WriteChar(code[i++]); } } /* WriteToken() */