/* vi: set sw=4 ts=4: */
/*
 * Mini head implementation for busybox
 *
 *
 * Copyright (C) 1999,2000,2001 by Lineo, inc.
 * Written by John Beppu <beppu@lineo.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include <errno.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include "busybox.h"

int head(int len, FILE *fp)
{
	int i;
	char *input;

	for (i = 0; i < len; i++) {
		if ((input = get_line_from_file(fp)) == NULL)
			break;
		fputs(input, stdout);
		free(input);
	}
	return 0;
}

/* BusyBoxed head(1) */
int head_main(int argc, char **argv)
{
	FILE *fp;
	int need_headers, opt, len = 10, status = EXIT_SUCCESS;

	/* parse argv[] */
	while ((opt = getopt(argc, argv, "n:")) > 0) {
		switch (opt) {
		case 'n':
			len = atoi(optarg);
			if (len >= 1)
				break;
			/* fallthrough */
		default:
			show_usage();
		}
	}

	/* get rest of argv[] or stdin if nothing's left */
	if (argv[optind] == NULL) {
		head(len, stdin);
		return status;
	} 

	need_headers = optind != (argc - 1);
	while (argv[optind]) {
		if (strcmp(argv[optind], "-") == 0) {
			fp = stdin;
			argv[optind] = "standard input";
		} else {
			if ((fp = wfopen(argv[optind], "r")) == NULL)
				status = EXIT_FAILURE;
		}
		if (fp) {
			if (need_headers) {
				printf("==> %s <==\n", argv[optind]);
			}
			head(len, fp);
			if (errno) {
				perror_msg("%s", argv[optind]);
				status = EXIT_FAILURE;
				errno = 0;
			}
			if (optind < argc - 1)
				putchar('\n');
			if (fp != stdin)
				fclose(fp);
		}
		optind++;
	}

	return status;
}
