/* l8.c - Don Yang (uguu.org) 04/17/05 */ #include #include #include typedef int L; typedef char *l; typedef void P; typedef union { l I; L i; } h; typedef struct { L i, g; h *t; } v; v V[26], w; l x, y; L _, D, e, A, T, H, N, O, t, E; FILE *f; L s(l d) { for(D = 0; *d++; D++); return D; } P p(L o) { putchar(o); } L X(l o) { return (L)(*o += ((*o > 64 && *o < 91) ? 32 : 0)); } P q(l o) { for(; *o; p(*o++)); } P k(L o) { fseek(f, 0, o); } P R(v *l) { l->t = (h*)0; l->i = l->g = 0; } P F(P *o) { free(o); } P S(v *o, l d) { h *a, *b, *c; D = sizeof(h); if( !o->t ) o->t = (h*)malloc((o->g = 32) * D); if( o->t && o->i + 1 > o->g ) { if( (a = c = (h*)malloc((o->g * 2) * D)) ) { b = o->t; for(D = o->i; D--; a++->i = b++->i); F(o->t); o->t = c; o->g *= 2; } } if( o->t ) o->t[o->i++].I = d; } P Z(v *o) { if( o->t ) F(o->t); } P z(l a, l b) { for(N = 0; *a && *b && *a == *b; a++, b++, N++); } P Q(P) { fclose(f); } L main(L u, l *U) { if( u < 2 ) { q(" [width] [...]\n"); } else { if( (f = fopen(U[1], "rb")) ) { k(2); _ = ftell(f); if( _ > 9 && (y = (l)malloc(_ + 1)) ) { k(0); y[fread(y, 1, _, f)] = 0; Q(); for(e = 0; e < 26; R(&V[e++])); R(&w); for(x = y; _--; *(x++) = 0) { if( (*x > 64 && *x < 91) || (*x > 96 && *x < 123) ) { S(&V[X(x) - 97], (l)w.i); for(S(&w, x); _-- ? (*x > 64 && *x < 91) || (*x > 96 && *x < 123) || (*x > 47 && *x < 58) : 0; x++) X(x); _++; } } if( (_ = (u > 2) ? atoi(U[2]) : 80) < 1 ) _ = 80; if( u > 3 ) { for(srand(time(0)); u-- > 3;) { p(10); t = s(x = U[u]); for(e = 0; e < t; e++) X(x + e); q(x); for(E = _ - 1 - s(U[u - 1]); t < E; t += 1 + s(x)) { for(A = e = 0; !A || (t + 1 + s(w.t[e].I) >= _);) { O = *x - 97; e = rand() % w.i; if( O >= 0 && O < 26 ) { if( V[O].i ) { z(x, w.t[e = V[O].t[rand() % V[O].i].i].I); H = N; for(A = 0; A < V[O].i / 2; A++) { T = V[O].t[rand() % V[O].i].i; z(x, w.t[T].I); if( N > H ) { H = N; e = T; } } e = (e + 1) % w.i; } } } p(32); q(x = w.t[e].I); } } } else { t = _; for(e = 0; e < w.i; e++) { if( (t + 1 + s(w.t[e].I)) >= _ ) { p(10); t = 0; } else { p(32); t++; } q(w.t[e].I); t += s(w.t[e].I); } } q("\n\n"); for(e = 0; e < 26; Z(&V[e++])); Z(&w); F(y); } else { Q(); } } else { q("open error\n"); } } return 0; }