/* extract a portion of a file from some beginning line, to 
* some ending line
* this functions as a filter --- it doesn't take a list
* of file name arguments.
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int 
main (int argc, char * argv[] )
{
char * linestr;
long begin, end, current=0;
ssize_t * linelen;


linelen = 0; 
linestr=NULL;

if ( argc < 3 ) {
fprintf(stderr, "Usage: %s begin end\n", argv[0]);
exit(1);
}

begin=atol(argv[1]);
if ( begin < 1 ) {
fprintf(stderr, "Argument error: %s should be a number "
		"greater than zero\n", argv[1]);
exit(1);
}

end=atol(argv[2]);
if ( end < begin ) {
fprintf(stderr, "Argument error: %s should be a number "
		"greater than arg[1]\n", argv[1]);
exit(1);
}

while ( getline(&linestr, &linelen, stdin ) > -1 
  && (++current < end ) ) {
if (current >= begin) {
	printf("%s", linestr);
	}
}

exit(0);
return 0;
}

