/* slice.c & slice.1.man cLIeNUX data slicer C source and "manpage"
RIGHTS Copyright 1999 Richard Allen Hohensee (Rick) slice is released for redistribution under the terms of the GNU General Public License, version 2. A copy of said GPL with Linus Torvalds' comments and my comments appended is in cLIeNUX in /GPL . I also hereby donate the transferable copyrights to slice to the Free Software Foundation. Most other cLIeNUX-originated files ARE **NOT** GPL. I ask that I be mentioned if slice-like functionality is added to e.g. GNU dd. DESCRIPTION slice is, AFAICT, "the feature dd very nearly has"; truncate or pad sized input blocks to outblocksize. In fact, dd looks a lot like maybe it used to do this but the feature sloughed off over time, perhaps. Or I just missed it. I wrote this for console font data. fonter forces/pads edited fonts to 16 scanlines high on a save. slice can then slice out the pads. This is how I did fonts 11 and 13 in cLIeNUX (which are **NOT** GPL, BTW), along with fonter and some absolute filesize trimming and whatnot. This initial slice is a raw, minimal little utility. The stock unix stdin/stdout applies. There's no error checking or safety features. Break a leg. FORMAT slice inSliceSize outSliceSize [ < infile ] [ > outfile ] i.e. the command, 2 arguments and default unix redirection. With other than 2 arguments you get useage and version and return an error. EXAMPLES slice 16 12 < font.bogus16 > 12high slice 10 2 a_Big_Long_Line_Of_Random_Terminal_Input_Ad_Libido_HTJHEBTJHBETJ Sizes are decimal integer numbers of bytes. outfile will be bigger or smaller than infile by roughly the ratio of inSliceSize to outSliceSize. Padding is done with zeros. Spaces or whatever can be obtained off the zeros with tr in most text situations, I suppose. Think modular. BUGS see below */ int i, pad, red, wrote, insize, outsize, blocks; char *buffer ; int main(int argc, char ** argv) { if ( argc != 3 ) /* useage and version msg */ { printf("\ninitial slice version, 199903\n\n"); printf("USEAGE\n"); printf("slice inSliceSize outSliceSize [ < infile] [ > outfile] \n\n"); printf ("That is; the command, 2 decimal arguments, and standard unix\n"); printf("input-output specifiers.\n\n"); return -1; } insize = atoi(argv[1]) ; outsize = atoi(argv[2]) ; if ( insize > outsize ) { buffer = (char *)calloc(insize, 1) ; } else { buffer = (char *)calloc(outsize, 1) ; } red = insize ; while ( red == insize ) { red = read(0, buffer, insize) ; wrote = write(1, buffer, outsize) ; } return 0; /* main returns error = false */ }