#include "ObjProGen/cpyrght_exe.h"
#include <stream.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

void usage()
{
	cerr << "Usage: cp_part [-u] 'start line' [ 'end line' ] < input > output\n" ;
	cerr << "With `-u' file is copied up to and including 'start line'.\n" ;
	exit(1);
}


void main(int argc, char **argv)
{
	const buf_size = 4096 ;
	char buf[buf_size] ;
	int do_skip = 0 ;
	int upto_flag = 0 ;
	int ltr ;
	while ((ltr = getopt(argc, argv, "u")) != EOF) switch (ltr) {
case 'u' :
		upto_flag = 1 ;
		break ;
defauult:
		usage();
	}

	if (argc - optind < 1) usage();
	if (argc - optind > 2) usage();
	const char * start = argv[optind] ;
	const char * end = 0 ;
	if (argc - optind == 2) {
		if (upto_flag) usage();
		end =  argv[optind+1] ;
	}
	int writing = 0 ;
	if (upto_flag) {
		writing = 1 ;
		end = start ;
		start = 0 ;
	}
	while(fgets(buf,buf_size,stdin)) {
		int length = strlen(buf);
		buf[length-1] = 0 ;
		if (writing) {
			int exit = 0 ;
			if (end) exit = !strcmp(buf,end) ;
			if (!upto_flag && exit) break ;
			fputs(buf,stdout);
			fputc('\n',stdout);
			if (exit) break ;
		} else if(!strcmp(buf,start)) writing = 1 ;
	}
}
