10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This file contains the makefile reader.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <unistd.h> /* close(), unlink(), read() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * get_next_block_fn(source)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Will get the next block of text to read either
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * by popping one source bVSIZEOFlock of the stack of Sources
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * or by reading some more from the makefile.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The new source block to read from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * source The old source block
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Global variables used:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file_being_read The name of the current file, error msg
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (source->inp_buf_ptr >= source->inp_buf_end))) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We can't read from the makefile, so pop the source block */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Read the whole makefile.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Hopefully the kernel managed to prefetch the stuff.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->inp_buf_ptr = source->inp_buf = getmem(to_read + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe source->inp_buf_end = source->inp_buf + to_read;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe length = read(source->fd, source->inp_buf, (unsigned int) to_read);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe fatal_mksh(gettext("Error reading `%s': Premature EOF"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Try to convert the next piece.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ptr = source->inp_buf_ptr + STRING_LEN_TO_CONVERT;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe for (num_wc_chars = 0; ptr > source->inp_buf_ptr; ptr--) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe num_wc_chars = mbstowcs(source->string.text.end,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (source->inp_buf_ptr >= source->inp_buf_end) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (*(source->string.text.end - 1) != (int) newline_char) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning_mksh(gettext("newline is not last character in file %s"),