#include #include #include #include #include extern const char *__progname; typedef struct blk BLK; struct blk { BLK *link; char data[65500]; int fill; } ; static BLK *head; static BLK **tail; static int length; int main(void); int main(void) { BLK *b; int n; int w; int o; int l; tail = &head; length = 0; while <"input"> (1) { b = malloc(sizeof(BLK)); *tail = b; tail = &b->link; o = 0; while (o < sizeof(b->data)) { n = read(0,&b->data[o],sizeof(b->data)-o); if (n < 0) { fprintf(stderr,"%s: input read error: %s\n",__progname,strerror(errno)); exit(1); } if (n == 0) { b->fill = o; break <"input">; } o += n; length += n; } b->fill = o; } *tail = 0; if (! head) { printf("0:"); return(0); } n = 0; b = head; head = b->link; o = 0; while (1) { if (n < 1) { if (length < 1) break; n = length; if (n > 255) n = 255; length -= n; printf("%d:",n); fflush(stdout); } else if (o >= b->fill) { free(b); b = head; head = b->link; o = 0; } else { l = b->fill - o; if (l > n) l = n; w = write(1,&b->data[o],l); if (w < 0) { fprintf(stderr,"%s: output write error: %s\n",__progname,strerror(errno)); exit(1); } o += w; n -= w; } } if (length) abort(); printf("0:"); return(0); }