From: Mark Wilson Date: 2003-08-23T08:36:43+09:00 Subject: Re: Line wrapping Here's some C code to do line wrapping (written by Joseph K. Myers) quickly, efficiently and simply. The code is presented verbatim: =begin /* An explanation is more troublesome than the problem. */ int main(int argc, char **argv) { char b[4096]; int l=0, m=-1, m1=-1, s1=0, c, i, s, w; if (argc < 2 || sscanf(argv[1], "%3d", &w) < 1) w = 72; while ((s=read(0, b, m == -1 ? 4096 : m)) > 0) { for (i=0; i w && m != -1) { b[m] = '\n'; l = i - (i < m ? m-s1 : m); m = -1; } } } if (m1 != -1) write(1, &b[m1], s1-m1); write(1, b, m == -1 ? s : m); m1=m, s1=s; } if (m != -1) write(1, &b[m], s1-m); return s; } =end I was planning on wrapping Ruby around this after I learned enough C, Swig and Ruby, but perhaps someone else would like to do it. It can also be called by system: `wrap < infile > outfile` or, if synchronization is needed: require 'shell' shell = Shell.new shell.transact do `wrap < infile > outfile` end Regards, Mark