xref: /illumos-gate/usr/src/cmd/make/bin/pmake.cc (revision ae389aa9)
110d63b7dSRichard Lowe /*
210d63b7dSRichard Lowe  * CDDL HEADER START
310d63b7dSRichard Lowe  *
410d63b7dSRichard Lowe  * The contents of this file are subject to the terms of the
510d63b7dSRichard Lowe  * Common Development and Distribution License (the "License").
610d63b7dSRichard Lowe  * You may not use this file except in compliance with the License.
710d63b7dSRichard Lowe  *
810d63b7dSRichard Lowe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
910d63b7dSRichard Lowe  * or http://www.opensolaris.org/os/licensing.
1010d63b7dSRichard Lowe  * See the License for the specific language governing permissions
1110d63b7dSRichard Lowe  * and limitations under the License.
1210d63b7dSRichard Lowe  *
1310d63b7dSRichard Lowe  * When distributing Covered Code, include this CDDL HEADER in each
1410d63b7dSRichard Lowe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1510d63b7dSRichard Lowe  * If applicable, add the following below this CDDL HEADER, with the
1610d63b7dSRichard Lowe  * fields enclosed by brackets "[]" replaced with your own identifying
1710d63b7dSRichard Lowe  * information: Portions Copyright [yyyy] [name of copyright owner]
1810d63b7dSRichard Lowe  *
1910d63b7dSRichard Lowe  * CDDL HEADER END
2010d63b7dSRichard Lowe  */
2110d63b7dSRichard Lowe /*
2210d63b7dSRichard Lowe  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2310d63b7dSRichard Lowe  * Use is subject to license terms.
2410d63b7dSRichard Lowe  */
2510d63b7dSRichard Lowe 
2610d63b7dSRichard Lowe 
2710d63b7dSRichard Lowe /*
2810d63b7dSRichard Lowe  * Included files
2910d63b7dSRichard Lowe  */
3010d63b7dSRichard Lowe #include <arpa/inet.h>
3110d63b7dSRichard Lowe #include <mk/defs.h>
3210d63b7dSRichard Lowe #include <mksh/misc.h>
3310d63b7dSRichard Lowe #include <netdb.h>
3410d63b7dSRichard Lowe #include <netinet/in.h>
3510d63b7dSRichard Lowe #include <sys/socket.h>
3610d63b7dSRichard Lowe #include <sys/stat.h>
3710d63b7dSRichard Lowe #include <sys/types.h>
3810d63b7dSRichard Lowe #include <sys/utsname.h>
3910d63b7dSRichard Lowe #include <rpc/rpc.h>		/* host2netname(), netname2host() */
4010d63b7dSRichard Lowe #include <libintl.h>
4110d63b7dSRichard Lowe 
4210d63b7dSRichard Lowe /*
4310d63b7dSRichard Lowe  * Defined macros
4410d63b7dSRichard Lowe  */
4510d63b7dSRichard Lowe 
4610d63b7dSRichard Lowe /*
4710d63b7dSRichard Lowe  * typedefs & structs
4810d63b7dSRichard Lowe  */
4910d63b7dSRichard Lowe 
5010d63b7dSRichard Lowe /*
5110d63b7dSRichard Lowe  * Static variables
5210d63b7dSRichard Lowe  */
5310d63b7dSRichard Lowe 
5410d63b7dSRichard Lowe /*
5510d63b7dSRichard Lowe  * File table of contents
5610d63b7dSRichard Lowe  */
5710d63b7dSRichard Lowe static int		get_max(wchar_t **ms_address, wchar_t *hostname);
5810d63b7dSRichard Lowe static Boolean		pskip_comment(wchar_t **cp_address);
5910d63b7dSRichard Lowe static void		pskip_till_next_word(wchar_t **cp);
6010d63b7dSRichard Lowe static Boolean		pskip_white_space(wchar_t **cp_address);
6110d63b7dSRichard Lowe 
6210d63b7dSRichard Lowe 
6310d63b7dSRichard Lowe /*
6410d63b7dSRichard Lowe  *	read_make_machines(Name make_machines_name)
6510d63b7dSRichard Lowe  *
6610d63b7dSRichard Lowe  *	For backwards compatibility w/ PMake 1.x, when DMake 2.x is
6710d63b7dSRichard Lowe  *	being run in parallel mode, DMake should parse the PMake startup
6810d63b7dSRichard Lowe  *	file $(HOME)/.make.machines to get the PMake max jobs.
6910d63b7dSRichard Lowe  *
7010d63b7dSRichard Lowe  *	Return value:
7110d63b7dSRichard Lowe  *		int of PMake max jobs
7210d63b7dSRichard Lowe  *
7310d63b7dSRichard Lowe  *	Parameters:
7410d63b7dSRichard Lowe  *		make_machines_name	Name of .make.machines file
7510d63b7dSRichard Lowe  *
7610d63b7dSRichard Lowe  */
7710d63b7dSRichard Lowe int
read_make_machines(Name make_machines_name)7810d63b7dSRichard Lowe read_make_machines(Name make_machines_name)
7910d63b7dSRichard Lowe {
80*ae389aa9SAndy Fiddaman 	wchar_t			c;
8110d63b7dSRichard Lowe 	Boolean			default_make_machines;
8210d63b7dSRichard Lowe 	struct hostent		*hp;
8310d63b7dSRichard Lowe 	wchar_t			local_host[MAX_HOSTNAMELEN + 1];
8410d63b7dSRichard Lowe 	char			local_host_mb[MAX_HOSTNAMELEN + 1] = "";
8510d63b7dSRichard Lowe 	int			local_host_wslen;
8610d63b7dSRichard Lowe 	wchar_t			full_host[MAXNETNAMELEN + 1];
8710d63b7dSRichard Lowe 	int			full_host_wslen = 0;
8810d63b7dSRichard Lowe 	char			*homedir;
8910d63b7dSRichard Lowe 	Name			MAKE_MACHINES;
9010d63b7dSRichard Lowe 	struct stat		make_machines_buf;
9110d63b7dSRichard Lowe 	FILE			*make_machines_file;
9210d63b7dSRichard Lowe 	wchar_t			*make_machines_list = NULL;
9310d63b7dSRichard Lowe 	char			*make_machines_list_mb = NULL;
9410d63b7dSRichard Lowe 	wchar_t			make_machines_path[MAXPATHLEN];
9510d63b7dSRichard Lowe 	char			mb_make_machines_path[MAXPATHLEN];
9610d63b7dSRichard Lowe 	wchar_t			*mp;
9710d63b7dSRichard Lowe 	wchar_t			*ms;
9810d63b7dSRichard Lowe 	int			pmake_max_jobs = 0;
9910d63b7dSRichard Lowe 	struct utsname		uts_info;
10010d63b7dSRichard Lowe 
10110d63b7dSRichard Lowe 
10210d63b7dSRichard Lowe 	MBSTOWCS(wcs_buffer, "MAKE_MACHINES");
10310d63b7dSRichard Lowe 	MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
10410d63b7dSRichard Lowe 	/* Did the user specify a .make.machines file on the command line? */
10510d63b7dSRichard Lowe 	default_make_machines = false;
10610d63b7dSRichard Lowe 	if (make_machines_name == NULL) {
10710d63b7dSRichard Lowe 		/* Try reading the default .make.machines file, in $(HOME). */
10810d63b7dSRichard Lowe 		homedir = getenv("HOME");
10910d63b7dSRichard Lowe 		if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
11010d63b7dSRichard Lowe 			sprintf(mb_make_machines_path,
11110d63b7dSRichard Lowe 			 "%s/.make.machines", homedir);
11210d63b7dSRichard Lowe 			MBSTOWCS(make_machines_path, mb_make_machines_path);
11310d63b7dSRichard Lowe 			make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
11410d63b7dSRichard Lowe 			default_make_machines = true;
11510d63b7dSRichard Lowe 		}
11610d63b7dSRichard Lowe 		if (make_machines_name == NULL) {
11710d63b7dSRichard Lowe 			/*
11810d63b7dSRichard Lowe 			 * No $(HOME)/.make.machines file.
11910d63b7dSRichard Lowe 			 * Return 0 for PMake max jobs.
12010d63b7dSRichard Lowe 			 */
12110d63b7dSRichard Lowe 			return(0);
12210d63b7dSRichard Lowe 		}
12310d63b7dSRichard Lowe 	}
12410d63b7dSRichard Lowe /*
12510d63b7dSRichard Lowe 	make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
12610d63b7dSRichard Lowe  */
12710d63b7dSRichard Lowe 	/* Open the .make.machines file. */
12810d63b7dSRichard Lowe 	if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
12910d63b7dSRichard Lowe 		if (!default_make_machines) {
13010d63b7dSRichard Lowe 			/* Error opening .make.machines file. */
13110d63b7dSRichard Lowe 			fatal(gettext("Open of %s failed: %s"),
13210d63b7dSRichard Lowe 			      make_machines_name->string_mb,
13310d63b7dSRichard Lowe 			      errmsg(errno));
13410d63b7dSRichard Lowe 		} else {
13510d63b7dSRichard Lowe 			/*
13610d63b7dSRichard Lowe 			 * No $(HOME)/.make.machines file.
13710d63b7dSRichard Lowe 			 * Return 0 for PMake max jobs.
13810d63b7dSRichard Lowe 			 */
13910d63b7dSRichard Lowe 			return(0);
14010d63b7dSRichard Lowe 		}
14110d63b7dSRichard Lowe 	/* Stat the .make.machines file to get the size of the file.  */
14210d63b7dSRichard Lowe 	} else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
14310d63b7dSRichard Lowe 		/* Error stat'ing .make.machines file. */
14410d63b7dSRichard Lowe 		fatal(gettext("Stat of %s failed: %s"),
14510d63b7dSRichard Lowe 		      make_machines_name->string_mb,
14610d63b7dSRichard Lowe 		      errmsg(errno));
14710d63b7dSRichard Lowe 	} else {
14810d63b7dSRichard Lowe 		/* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
14910d63b7dSRichard Lowe 		make_machines_list_mb =
15010d63b7dSRichard Lowe 		  (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
15110d63b7dSRichard Lowe 		                         2 +
15210d63b7dSRichard Lowe 		                         make_machines_buf.st_size));
15310d63b7dSRichard Lowe 		sprintf(make_machines_list_mb,
15410d63b7dSRichard Lowe 			"%s=",
15510d63b7dSRichard Lowe 			MAKE_MACHINES->string_mb);
15610d63b7dSRichard Lowe 		/* Read in the .make.machines file. */
15710d63b7dSRichard Lowe 		if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
15810d63b7dSRichard Lowe 			  sizeof(char),
15910d63b7dSRichard Lowe 			  (int) make_machines_buf.st_size,
16010d63b7dSRichard Lowe 			  make_machines_file) != make_machines_buf.st_size) {
16110d63b7dSRichard Lowe 			/*
16210d63b7dSRichard Lowe 			 * Error reading .make.machines file.
16310d63b7dSRichard Lowe 			 * Return 0 for PMake max jobs.
16410d63b7dSRichard Lowe 			 */
16510d63b7dSRichard Lowe 			warning(gettext("Unable to read %s"),
16610d63b7dSRichard Lowe 				make_machines_name->string_mb);
16710d63b7dSRichard Lowe 			(void) fclose(make_machines_file);
16810d63b7dSRichard Lowe 			retmem_mb((caddr_t) make_machines_list_mb);
16910d63b7dSRichard Lowe 			return(0);
17010d63b7dSRichard Lowe 		} else {
17110d63b7dSRichard Lowe 			(void) fclose(make_machines_file);
17210d63b7dSRichard Lowe 			/* putenv "MAKE_MACHINES=<contents of .m.m>" */
17310d63b7dSRichard Lowe 			*(make_machines_list_mb +
17410d63b7dSRichard Lowe 			  strlen(MAKE_MACHINES->string_mb) +
17510d63b7dSRichard Lowe 			  1 +
17610d63b7dSRichard Lowe 			  make_machines_buf.st_size) = (int) nul_char;
17710d63b7dSRichard Lowe 			if (putenv(make_machines_list_mb) != 0) {
17810d63b7dSRichard Lowe 				warning(gettext("Couldn't put contents of %s in environment"),
17910d63b7dSRichard Lowe 					make_machines_name->string_mb);
18010d63b7dSRichard Lowe 			} else {
18110d63b7dSRichard Lowe 				make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
18210d63b7dSRichard Lowe 				make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
18310d63b7dSRichard Lowe 				(void) mbstowcs(make_machines_list,
18410d63b7dSRichard Lowe 				                make_machines_list_mb,
18510d63b7dSRichard Lowe 				                (strlen(make_machines_list_mb) + 1));
18610d63b7dSRichard Lowe 			}
18710d63b7dSRichard Lowe 		}
18810d63b7dSRichard Lowe 	}
18910d63b7dSRichard Lowe 
19010d63b7dSRichard Lowe 	uname(&uts_info);
19110d63b7dSRichard Lowe 	strcpy(local_host_mb, &uts_info.nodename[0]);
19210d63b7dSRichard Lowe 	MBSTOWCS(local_host, local_host_mb);
19310d63b7dSRichard Lowe 	local_host_wslen = wcslen(local_host);
19410d63b7dSRichard Lowe 
19510d63b7dSRichard Lowe 	// There is no getdomainname() function on Solaris.
19610d63b7dSRichard Lowe 	// And netname2host() function does not work on Linux.
19710d63b7dSRichard Lowe 	// So we have to use different APIs.
19810d63b7dSRichard Lowe 	if (host2netname(mbs_buffer, NULL, NULL) &&
19910d63b7dSRichard Lowe 	    netname2host(mbs_buffer, mbs_buffer2, MAXNETNAMELEN+1)) {
20010d63b7dSRichard Lowe 		MBSTOWCS(full_host, mbs_buffer2);
20110d63b7dSRichard Lowe 		full_host_wslen = wcslen(full_host);
20210d63b7dSRichard Lowe 	}
20310d63b7dSRichard Lowe 
20410d63b7dSRichard Lowe 	for (ms = make_machines_list;
20510d63b7dSRichard Lowe 	     (ms) && (*ms );
20610d63b7dSRichard Lowe 	     ) {
20710d63b7dSRichard Lowe 		/*
20810d63b7dSRichard Lowe 		 * Skip white space and comments till you reach
20910d63b7dSRichard Lowe 		 * a machine name.
21010d63b7dSRichard Lowe 		 */
21110d63b7dSRichard Lowe 		pskip_till_next_word(&ms);
21210d63b7dSRichard Lowe 
21310d63b7dSRichard Lowe 		/*
21410d63b7dSRichard Lowe 		 * If we haven't reached the end of file, process the
21510d63b7dSRichard Lowe 		 * machine name.
21610d63b7dSRichard Lowe 		 */
21710d63b7dSRichard Lowe 		if (*ms) {
218*ae389aa9SAndy Fiddaman 			/*
219*ae389aa9SAndy Fiddaman 			 * If invalid machine name decrement counter
22010d63b7dSRichard Lowe 			 * and skip line.
22110d63b7dSRichard Lowe 			 */
22210d63b7dSRichard Lowe 			mp = ms;
22310d63b7dSRichard Lowe 			SKIPWORD(ms);
22410d63b7dSRichard Lowe 			c = *ms;
22510d63b7dSRichard Lowe 			*ms++ = '\0'; /* Append null to machine name. */
22610d63b7dSRichard Lowe 			/*
22710d63b7dSRichard Lowe 			 * If this was the beginning of a comment
22810d63b7dSRichard Lowe 			 * (we overwrote a # sign) and it's not
22910d63b7dSRichard Lowe 			 * end of line yet, shift the # sign.
23010d63b7dSRichard Lowe 			 */
23110d63b7dSRichard Lowe 			if ((c == '#') && (*ms != '\n') && (*ms)) {
23210d63b7dSRichard Lowe 				*ms = '#';
23310d63b7dSRichard Lowe 			}
23410d63b7dSRichard Lowe 			WCSTOMBS(mbs_buffer, mp);
23510d63b7dSRichard Lowe 			/*
23610d63b7dSRichard Lowe 			 * Print "Ignoring unknown host" if:
23710d63b7dSRichard Lowe 			 * 1) hostname is longer than MAX_HOSTNAMELEN, or
23810d63b7dSRichard Lowe 			 * 2) hostname is unknown
23910d63b7dSRichard Lowe 			 */
24010d63b7dSRichard Lowe 			if ((wcslen(mp) > MAX_HOSTNAMELEN) ||
24110d63b7dSRichard Lowe 			    ((hp = gethostbyname(mbs_buffer)) == NULL)) {
24210d63b7dSRichard Lowe 				warning(gettext("Ignoring unknown host %s"),
24310d63b7dSRichard Lowe 					mbs_buffer);
24410d63b7dSRichard Lowe 				SKIPTOEND(ms);
24510d63b7dSRichard Lowe 				/* Increment ptr if not end of file. */
24610d63b7dSRichard Lowe 				if (*ms) {
24710d63b7dSRichard Lowe 					ms++;
24810d63b7dSRichard Lowe 				}
24910d63b7dSRichard Lowe 			} else {
25010d63b7dSRichard Lowe 				/* Compare current hostname with local_host. */
25110d63b7dSRichard Lowe 				if (wcslen(mp) == local_host_wslen &&
25210d63b7dSRichard Lowe 				    IS_WEQUALN(mp, local_host, local_host_wslen)) {
25310d63b7dSRichard Lowe 					/*
25410d63b7dSRichard Lowe 					 * Bingo, local_host is in .make.machines.
25510d63b7dSRichard Lowe 					 * Continue reading.
25610d63b7dSRichard Lowe 					 */
25710d63b7dSRichard Lowe 					pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
25810d63b7dSRichard Lowe 				/* Compare current hostname with full_host. */
25910d63b7dSRichard Lowe 				} else if (wcslen(mp) == full_host_wslen &&
26010d63b7dSRichard Lowe 					   IS_WEQUALN(mp, full_host, full_host_wslen)) {
26110d63b7dSRichard Lowe 					/*
26210d63b7dSRichard Lowe 					 * Bingo, full_host is in .make.machines.
26310d63b7dSRichard Lowe 					 * Continue reading.
26410d63b7dSRichard Lowe 					 */
26510d63b7dSRichard Lowe 					pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
26610d63b7dSRichard Lowe 				} else {
26710d63b7dSRichard Lowe 					if (c != '\n') {
26810d63b7dSRichard Lowe 					    SKIPTOEND(ms);
26910d63b7dSRichard Lowe 					    if (*ms) {
27010d63b7dSRichard Lowe 						ms++;
27110d63b7dSRichard Lowe 					    }
27210d63b7dSRichard Lowe 					}
27310d63b7dSRichard Lowe 					continue;
27410d63b7dSRichard Lowe 				}
27510d63b7dSRichard Lowe 				/* If we get here, local_host is in .make.machines. */
27610d63b7dSRichard Lowe 				if (c != '\n')  {
27710d63b7dSRichard Lowe 					/* Now look for keyword 'max'. */
27810d63b7dSRichard Lowe 					MBSTOWCS(wcs_buffer, "max");
27910d63b7dSRichard Lowe 					SKIPSPACE(ms);
28010d63b7dSRichard Lowe 					while ((*ms != '\n') && (*ms)) {
28110d63b7dSRichard Lowe 						if (*ms == '#') {
28210d63b7dSRichard Lowe 							pskip_comment(&ms);
28310d63b7dSRichard Lowe 						} else if (IS_WEQUALN(ms, wcs_buffer, 3)) {
28410d63b7dSRichard Lowe 							/* Skip "max". */
285*ae389aa9SAndy Fiddaman 							ms += 3;
286*ae389aa9SAndy Fiddaman 							pmake_max_jobs = get_max(&ms, mp);
28710d63b7dSRichard Lowe 							SKIPSPACE(ms);
28810d63b7dSRichard Lowe 						} else {
28910d63b7dSRichard Lowe 							warning(gettext("unknown option for host %s"), mbs_buffer);
29010d63b7dSRichard Lowe 							SKIPTOEND(ms);
29110d63b7dSRichard Lowe 							break;
29210d63b7dSRichard Lowe 						}
29310d63b7dSRichard Lowe 					}
29410d63b7dSRichard Lowe 				}
29510d63b7dSRichard Lowe 				break; /* out of outermost for() loop. */
29610d63b7dSRichard Lowe 			}
29710d63b7dSRichard Lowe 		}
29810d63b7dSRichard Lowe 	}
29910d63b7dSRichard Lowe 	retmem(make_machines_list);
30010d63b7dSRichard Lowe 	return(pmake_max_jobs);
30110d63b7dSRichard Lowe }
30210d63b7dSRichard Lowe 
30310d63b7dSRichard Lowe /*
30410d63b7dSRichard Lowe  *	pskip_till_next_word(cp)
30510d63b7dSRichard Lowe  *
30610d63b7dSRichard Lowe  *	Parameters:
30710d63b7dSRichard Lowe  *		cp		the address of the string pointer.
30810d63b7dSRichard Lowe  *
30910d63b7dSRichard Lowe  *	On return:
31010d63b7dSRichard Lowe  *		cp		points to beginning of machine name.
31110d63b7dSRichard Lowe  *
31210d63b7dSRichard Lowe  */
31310d63b7dSRichard Lowe static void
pskip_till_next_word(wchar_t ** cp)31410d63b7dSRichard Lowe pskip_till_next_word(wchar_t **cp)
31510d63b7dSRichard Lowe {
31610d63b7dSRichard Lowe 	/*
31710d63b7dSRichard Lowe 	 * Keep recursing until all combinations of white spaces
31810d63b7dSRichard Lowe 	 * and comments have been skipped.
31910d63b7dSRichard Lowe 	 */
32010d63b7dSRichard Lowe 	if (pskip_white_space(cp) || pskip_comment(cp)) {
32110d63b7dSRichard Lowe 		pskip_till_next_word(cp);
32210d63b7dSRichard Lowe 	}
32310d63b7dSRichard Lowe }
32410d63b7dSRichard Lowe 
32510d63b7dSRichard Lowe /*
32610d63b7dSRichard Lowe  *	pskip_white_space(cp_address)
32710d63b7dSRichard Lowe  *
32810d63b7dSRichard Lowe  *	Advances the string pointer so that it points to the first
32910d63b7dSRichard Lowe  *	non white character (space/tab/linefeed).
33010d63b7dSRichard Lowe  *
33110d63b7dSRichard Lowe  *	Parameters:
33210d63b7dSRichard Lowe  *		cp_address	the address of the string pointer.
33310d63b7dSRichard Lowe  *
33410d63b7dSRichard Lowe  *	Return Value:
33510d63b7dSRichard Lowe  *				True if the pointer was changed.
33610d63b7dSRichard Lowe  *
33710d63b7dSRichard Lowe  */
33810d63b7dSRichard Lowe static Boolean
pskip_white_space(wchar_t ** cp_address)33910d63b7dSRichard Lowe pskip_white_space(wchar_t **cp_address)
34010d63b7dSRichard Lowe {
34110d63b7dSRichard Lowe 	wchar_t		*cp = *cp_address;
34210d63b7dSRichard Lowe 
34310d63b7dSRichard Lowe 	while (*cp && iswspace(*cp)) {
34410d63b7dSRichard Lowe 		cp++;
34510d63b7dSRichard Lowe 	}
34610d63b7dSRichard Lowe 	/* Have we skipped any characters? */
34710d63b7dSRichard Lowe 	if (cp != *cp_address) {
34810d63b7dSRichard Lowe 		*cp_address = cp;
34910d63b7dSRichard Lowe 		return(true);
35010d63b7dSRichard Lowe 	} else {
35110d63b7dSRichard Lowe 		return(false);
35210d63b7dSRichard Lowe 	}
35310d63b7dSRichard Lowe }
35410d63b7dSRichard Lowe 
35510d63b7dSRichard Lowe /*
35610d63b7dSRichard Lowe  *	pskip_comment(cp_address)
35710d63b7dSRichard Lowe  *
35810d63b7dSRichard Lowe  *	If cp_address is pointing to '#' (the beginning of a comment),
35910d63b7dSRichard Lowe  *	increment the pointer till you reach end of line.
36010d63b7dSRichard Lowe  *
36110d63b7dSRichard Lowe  *	Parameters:
36210d63b7dSRichard Lowe  *		cp_address	the address of the string pointer.
36310d63b7dSRichard Lowe  *
36410d63b7dSRichard Lowe  *	Return Value:
36510d63b7dSRichard Lowe  *				True if the pointer was changed.
36610d63b7dSRichard Lowe  *
36710d63b7dSRichard Lowe  */
36810d63b7dSRichard Lowe static Boolean
pskip_comment(wchar_t ** cp_address)36910d63b7dSRichard Lowe pskip_comment(wchar_t **cp_address)
37010d63b7dSRichard Lowe {
37110d63b7dSRichard Lowe 	wchar_t		*cp = *cp_address;
37210d63b7dSRichard Lowe 
37310d63b7dSRichard Lowe 	/* Is this the beginning of a comment? Skip till end of line. */
37410d63b7dSRichard Lowe 	if (*cp == '#') {
37510d63b7dSRichard Lowe 		SKIPTOEND(cp);
37610d63b7dSRichard Lowe 	}
37710d63b7dSRichard Lowe 	/* Have we skipped a comment line? */
37810d63b7dSRichard Lowe 	if (cp != *cp_address)	{
37910d63b7dSRichard Lowe 		*cp_address = cp;
38010d63b7dSRichard Lowe 		return(true);
38110d63b7dSRichard Lowe 	} else {
38210d63b7dSRichard Lowe 		return(false);
38310d63b7dSRichard Lowe 	}
38410d63b7dSRichard Lowe }
38510d63b7dSRichard Lowe 
38610d63b7dSRichard Lowe static int
get_max(wchar_t ** ms_address,wchar_t * hostname)38710d63b7dSRichard Lowe get_max(wchar_t **ms_address, wchar_t *hostname)
38810d63b7dSRichard Lowe {
389*ae389aa9SAndy Fiddaman 	wchar_t		*ms = *ms_address;
39010d63b7dSRichard Lowe 	int		limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
39110d63b7dSRichard Lowe 
39210d63b7dSRichard Lowe 	WCSTOMBS(mbs_buffer, hostname);
39310d63b7dSRichard Lowe 	/* Look for `='. */
39410d63b7dSRichard Lowe 	SKIPSPACE(ms);
39510d63b7dSRichard Lowe 	if ((!*ms) || (*ms == '\n') || (*ms != '=')) {
39610d63b7dSRichard Lowe 		SKIPTOEND(ms);
39710d63b7dSRichard Lowe 		warning(gettext("expected `=' after max, ignoring rest of line for host %s"),
39810d63b7dSRichard Lowe 			mbs_buffer);
39910d63b7dSRichard Lowe 		*ms_address = ms;
40010d63b7dSRichard Lowe 		return((int) limit);
40110d63b7dSRichard Lowe 	} else {
40210d63b7dSRichard Lowe 		ms++;
40310d63b7dSRichard Lowe 		SKIPSPACE(ms);
40410d63b7dSRichard Lowe 		if ((*ms != '\n') && (*ms != '\0')) {
40510d63b7dSRichard Lowe 			/* We've found, hopefully, a valid "max" value. */
40610d63b7dSRichard Lowe 			limit = (int) wcstol(ms, &ms, 10);
40710d63b7dSRichard Lowe 			if (limit < 1) {
40810d63b7dSRichard Lowe 				limit = PMAKE_DEF_MAX_JOBS;
40910d63b7dSRichard Lowe 				warning(gettext("max value cannot be less than or equal to zero for host %s"), mbs_buffer);
41010d63b7dSRichard Lowe 			}
41110d63b7dSRichard Lowe 		} else {
41210d63b7dSRichard Lowe 			/* No "max" value after "max=". */
41310d63b7dSRichard Lowe 			warning(gettext("no max value specified for host %s"), mbs_buffer);
41410d63b7dSRichard Lowe 		}
41510d63b7dSRichard Lowe 		*ms_address = ms;
41610d63b7dSRichard Lowe 		return(limit);
41710d63b7dSRichard Lowe 	}
41810d63b7dSRichard Lowe }
41910d63b7dSRichard Lowe 
42010d63b7dSRichard Lowe 
421