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 * Included files
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <rpc/rpc.h> /* host2netname(), netname2host() */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Defined macros
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * typedefs & structs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Static variables
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * File table of contents
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int get_max(wchar_t **ms_address, wchar_t *hostname);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean pskip_comment(wchar_t **cp_address);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic Boolean pskip_white_space(wchar_t **cp_address);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * read_make_machines(Name make_machines_name)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * For backwards compatibility w/ PMake 1.x, when DMake 2.x is
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * being run in parallel mode, DMake should parse the PMake startup
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file $(HOME)/.make.machines to get the PMake max jobs.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * int of PMake max jobs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * make_machines_name Name of .make.machines file
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Did the user specify a .make.machines file on the command line? */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Try reading the default .make.machines file, in $(HOME). */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe MBSTOWCS(make_machines_path, mb_make_machines_path);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * No $(HOME)/.make.machines file.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return 0 for PMake max jobs.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Open the .make.machines file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Error opening .make.machines file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * No $(HOME)/.make.machines file.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return 0 for PMake max jobs.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Stat the .make.machines file to get the size of the file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Error stat'ing .make.machines file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Read in the .make.machines file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sizeof(char),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_machines_file) != make_machines_buf.st_size) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Error reading .make.machines file.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return 0 for PMake max jobs.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* putenv "MAKE_MACHINES=<contents of .m.m>" */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning(gettext("Couldn't put contents of %s in environment"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // There is no getdomainname() function on Solaris.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // And netname2host() function does not work on Linux.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe // So we have to use different APIs.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe netname2host(mbs_buffer, mbs_buffer2, MAXNETNAMELEN+1)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Skip white space and comments till you reach
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a machine name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If we haven't reached the end of file, process the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * machine name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If invalid machine name decrement counter
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and skip line.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *ms++ = '\0'; /* Append null to machine name. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If this was the beginning of a comment
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (we overwrote a # sign) and it's not
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * end of line yet, shift the # sign.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Print "Ignoring unknown host" if:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 1) hostname is longer than MAX_HOSTNAMELEN, or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 2) hostname is unknown
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Increment ptr if not end of file. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Compare current hostname with local_host. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe IS_WEQUALN(mp, local_host, local_host_wslen)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Bingo, local_host is in .make.machines.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Continue reading.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Compare current hostname with full_host. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Bingo, full_host is in .make.machines.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Continue reading.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (c != '\n') {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* If we get here, local_host is in .make.machines. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (c != '\n') {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Now look for keyword 'max'. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Skip "max". */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning(gettext("unknown option for host %s"), mbs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break; /* out of outermost for() loop. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pskip_till_next_word(cp)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cp the address of the string pointer.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * On return:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cp points to beginning of machine name.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Keep recursing until all combinations of white spaces
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and comments have been skipped.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (pskip_white_space(cp) || pskip_comment(cp)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pskip_white_space(cp_address)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Advances the string pointer so that it points to the first
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * non white character (space/tab/linefeed).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cp_address the address of the string pointer.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return Value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * True if the pointer was changed.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Have we skipped any characters? */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return(true);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return(false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * pskip_comment(cp_address)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If cp_address is pointing to '#' (the beginning of a comment),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * increment the pointer till you reach end of line.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * cp_address the address of the string pointer.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Return Value:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * True if the pointer was changed.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Is this the beginning of a comment? Skip till end of line. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Have we skipped a comment line? */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return(true);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return(false);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweget_max(wchar_t **ms_address, wchar_t *hostname)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* Look for `='. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning(gettext("expected `=' after max, ignoring rest of line for host %s"),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return((int) limit);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* We've found, hopefully, a valid "max" value. */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning(gettext("max value cannot be less than or equal to zero for host %s"), mbs_buffer);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* No "max" value after "max=". */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe warning(gettext("no max value specified for host %s"), mbs_buffer);