1*10d63b7dSRichard Lowe /* 2*10d63b7dSRichard Lowe * CDDL HEADER START 3*10d63b7dSRichard Lowe * 4*10d63b7dSRichard Lowe * The contents of this file are subject to the terms of the 5*10d63b7dSRichard Lowe * Common Development and Distribution License (the "License"). 6*10d63b7dSRichard Lowe * You may not use this file except in compliance with the License. 7*10d63b7dSRichard Lowe * 8*10d63b7dSRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*10d63b7dSRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*10d63b7dSRichard Lowe * See the License for the specific language governing permissions 11*10d63b7dSRichard Lowe * and limitations under the License. 12*10d63b7dSRichard Lowe * 13*10d63b7dSRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*10d63b7dSRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*10d63b7dSRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*10d63b7dSRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*10d63b7dSRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*10d63b7dSRichard Lowe * 19*10d63b7dSRichard Lowe * CDDL HEADER END 20*10d63b7dSRichard Lowe */ 21*10d63b7dSRichard Lowe /* 22*10d63b7dSRichard Lowe * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 23*10d63b7dSRichard Lowe * Use is subject to license terms. 24*10d63b7dSRichard Lowe */ 25*10d63b7dSRichard Lowe 26*10d63b7dSRichard Lowe 27*10d63b7dSRichard Lowe /* 28*10d63b7dSRichard Lowe * Included files 29*10d63b7dSRichard Lowe */ 30*10d63b7dSRichard Lowe #include <arpa/inet.h> 31*10d63b7dSRichard Lowe #include <mk/defs.h> 32*10d63b7dSRichard Lowe #include <mksh/misc.h> 33*10d63b7dSRichard Lowe #include <netdb.h> 34*10d63b7dSRichard Lowe #include <netinet/in.h> 35*10d63b7dSRichard Lowe #include <sys/socket.h> 36*10d63b7dSRichard Lowe #include <sys/stat.h> 37*10d63b7dSRichard Lowe #include <sys/types.h> 38*10d63b7dSRichard Lowe #include <sys/utsname.h> 39*10d63b7dSRichard Lowe #include <rpc/rpc.h> /* host2netname(), netname2host() */ 40*10d63b7dSRichard Lowe #include <libintl.h> 41*10d63b7dSRichard Lowe 42*10d63b7dSRichard Lowe /* 43*10d63b7dSRichard Lowe * Defined macros 44*10d63b7dSRichard Lowe */ 45*10d63b7dSRichard Lowe 46*10d63b7dSRichard Lowe /* 47*10d63b7dSRichard Lowe * typedefs & structs 48*10d63b7dSRichard Lowe */ 49*10d63b7dSRichard Lowe 50*10d63b7dSRichard Lowe /* 51*10d63b7dSRichard Lowe * Static variables 52*10d63b7dSRichard Lowe */ 53*10d63b7dSRichard Lowe 54*10d63b7dSRichard Lowe /* 55*10d63b7dSRichard Lowe * File table of contents 56*10d63b7dSRichard Lowe */ 57*10d63b7dSRichard Lowe static int get_max(wchar_t **ms_address, wchar_t *hostname); 58*10d63b7dSRichard Lowe static Boolean pskip_comment(wchar_t **cp_address); 59*10d63b7dSRichard Lowe static void pskip_till_next_word(wchar_t **cp); 60*10d63b7dSRichard Lowe static Boolean pskip_white_space(wchar_t **cp_address); 61*10d63b7dSRichard Lowe 62*10d63b7dSRichard Lowe 63*10d63b7dSRichard Lowe /* 64*10d63b7dSRichard Lowe * read_make_machines(Name make_machines_name) 65*10d63b7dSRichard Lowe * 66*10d63b7dSRichard Lowe * For backwards compatibility w/ PMake 1.x, when DMake 2.x is 67*10d63b7dSRichard Lowe * being run in parallel mode, DMake should parse the PMake startup 68*10d63b7dSRichard Lowe * file $(HOME)/.make.machines to get the PMake max jobs. 69*10d63b7dSRichard Lowe * 70*10d63b7dSRichard Lowe * Return value: 71*10d63b7dSRichard Lowe * int of PMake max jobs 72*10d63b7dSRichard Lowe * 73*10d63b7dSRichard Lowe * Parameters: 74*10d63b7dSRichard Lowe * make_machines_name Name of .make.machines file 75*10d63b7dSRichard Lowe * 76*10d63b7dSRichard Lowe */ 77*10d63b7dSRichard Lowe int 78*10d63b7dSRichard Lowe read_make_machines(Name make_machines_name) 79*10d63b7dSRichard Lowe { 80*10d63b7dSRichard Lowe wchar_t c; 81*10d63b7dSRichard Lowe Boolean default_make_machines; 82*10d63b7dSRichard Lowe struct hostent *hp; 83*10d63b7dSRichard Lowe wchar_t local_host[MAX_HOSTNAMELEN + 1]; 84*10d63b7dSRichard Lowe char local_host_mb[MAX_HOSTNAMELEN + 1] = ""; 85*10d63b7dSRichard Lowe int local_host_wslen; 86*10d63b7dSRichard Lowe wchar_t full_host[MAXNETNAMELEN + 1]; 87*10d63b7dSRichard Lowe int full_host_wslen = 0; 88*10d63b7dSRichard Lowe char *homedir; 89*10d63b7dSRichard Lowe Name MAKE_MACHINES; 90*10d63b7dSRichard Lowe struct stat make_machines_buf; 91*10d63b7dSRichard Lowe FILE *make_machines_file; 92*10d63b7dSRichard Lowe wchar_t *make_machines_list = NULL; 93*10d63b7dSRichard Lowe char *make_machines_list_mb = NULL; 94*10d63b7dSRichard Lowe wchar_t make_machines_path[MAXPATHLEN]; 95*10d63b7dSRichard Lowe char mb_make_machines_path[MAXPATHLEN]; 96*10d63b7dSRichard Lowe wchar_t *mp; 97*10d63b7dSRichard Lowe wchar_t *ms; 98*10d63b7dSRichard Lowe int pmake_max_jobs = 0; 99*10d63b7dSRichard Lowe struct utsname uts_info; 100*10d63b7dSRichard Lowe 101*10d63b7dSRichard Lowe 102*10d63b7dSRichard Lowe MBSTOWCS(wcs_buffer, "MAKE_MACHINES"); 103*10d63b7dSRichard Lowe MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH); 104*10d63b7dSRichard Lowe /* Did the user specify a .make.machines file on the command line? */ 105*10d63b7dSRichard Lowe default_make_machines = false; 106*10d63b7dSRichard Lowe if (make_machines_name == NULL) { 107*10d63b7dSRichard Lowe /* Try reading the default .make.machines file, in $(HOME). */ 108*10d63b7dSRichard Lowe homedir = getenv("HOME"); 109*10d63b7dSRichard Lowe if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) { 110*10d63b7dSRichard Lowe sprintf(mb_make_machines_path, 111*10d63b7dSRichard Lowe "%s/.make.machines", homedir); 112*10d63b7dSRichard Lowe MBSTOWCS(make_machines_path, mb_make_machines_path); 113*10d63b7dSRichard Lowe make_machines_name = GETNAME(make_machines_path, FIND_LENGTH); 114*10d63b7dSRichard Lowe default_make_machines = true; 115*10d63b7dSRichard Lowe } 116*10d63b7dSRichard Lowe if (make_machines_name == NULL) { 117*10d63b7dSRichard Lowe /* 118*10d63b7dSRichard Lowe * No $(HOME)/.make.machines file. 119*10d63b7dSRichard Lowe * Return 0 for PMake max jobs. 120*10d63b7dSRichard Lowe */ 121*10d63b7dSRichard Lowe return(0); 122*10d63b7dSRichard Lowe } 123*10d63b7dSRichard Lowe } 124*10d63b7dSRichard Lowe /* 125*10d63b7dSRichard Lowe make_machines_list_mb = getenv(MAKE_MACHINES->string_mb); 126*10d63b7dSRichard Lowe */ 127*10d63b7dSRichard Lowe /* Open the .make.machines file. */ 128*10d63b7dSRichard Lowe if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) { 129*10d63b7dSRichard Lowe if (!default_make_machines) { 130*10d63b7dSRichard Lowe /* Error opening .make.machines file. */ 131*10d63b7dSRichard Lowe fatal(gettext("Open of %s failed: %s"), 132*10d63b7dSRichard Lowe make_machines_name->string_mb, 133*10d63b7dSRichard Lowe errmsg(errno)); 134*10d63b7dSRichard Lowe } else { 135*10d63b7dSRichard Lowe /* 136*10d63b7dSRichard Lowe * No $(HOME)/.make.machines file. 137*10d63b7dSRichard Lowe * Return 0 for PMake max jobs. 138*10d63b7dSRichard Lowe */ 139*10d63b7dSRichard Lowe return(0); 140*10d63b7dSRichard Lowe } 141*10d63b7dSRichard Lowe /* Stat the .make.machines file to get the size of the file. */ 142*10d63b7dSRichard Lowe } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) { 143*10d63b7dSRichard Lowe /* Error stat'ing .make.machines file. */ 144*10d63b7dSRichard Lowe fatal(gettext("Stat of %s failed: %s"), 145*10d63b7dSRichard Lowe make_machines_name->string_mb, 146*10d63b7dSRichard Lowe errmsg(errno)); 147*10d63b7dSRichard Lowe } else { 148*10d63b7dSRichard Lowe /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */ 149*10d63b7dSRichard Lowe make_machines_list_mb = 150*10d63b7dSRichard Lowe (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) + 151*10d63b7dSRichard Lowe 2 + 152*10d63b7dSRichard Lowe make_machines_buf.st_size)); 153*10d63b7dSRichard Lowe sprintf(make_machines_list_mb, 154*10d63b7dSRichard Lowe "%s=", 155*10d63b7dSRichard Lowe MAKE_MACHINES->string_mb); 156*10d63b7dSRichard Lowe /* Read in the .make.machines file. */ 157*10d63b7dSRichard Lowe if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1, 158*10d63b7dSRichard Lowe sizeof(char), 159*10d63b7dSRichard Lowe (int) make_machines_buf.st_size, 160*10d63b7dSRichard Lowe make_machines_file) != make_machines_buf.st_size) { 161*10d63b7dSRichard Lowe /* 162*10d63b7dSRichard Lowe * Error reading .make.machines file. 163*10d63b7dSRichard Lowe * Return 0 for PMake max jobs. 164*10d63b7dSRichard Lowe */ 165*10d63b7dSRichard Lowe warning(gettext("Unable to read %s"), 166*10d63b7dSRichard Lowe make_machines_name->string_mb); 167*10d63b7dSRichard Lowe (void) fclose(make_machines_file); 168*10d63b7dSRichard Lowe retmem_mb((caddr_t) make_machines_list_mb); 169*10d63b7dSRichard Lowe return(0); 170*10d63b7dSRichard Lowe } else { 171*10d63b7dSRichard Lowe (void) fclose(make_machines_file); 172*10d63b7dSRichard Lowe /* putenv "MAKE_MACHINES=<contents of .m.m>" */ 173*10d63b7dSRichard Lowe *(make_machines_list_mb + 174*10d63b7dSRichard Lowe strlen(MAKE_MACHINES->string_mb) + 175*10d63b7dSRichard Lowe 1 + 176*10d63b7dSRichard Lowe make_machines_buf.st_size) = (int) nul_char; 177*10d63b7dSRichard Lowe if (putenv(make_machines_list_mb) != 0) { 178*10d63b7dSRichard Lowe warning(gettext("Couldn't put contents of %s in environment"), 179*10d63b7dSRichard Lowe make_machines_name->string_mb); 180*10d63b7dSRichard Lowe } else { 181*10d63b7dSRichard Lowe make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1; 182*10d63b7dSRichard Lowe make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1); 183*10d63b7dSRichard Lowe (void) mbstowcs(make_machines_list, 184*10d63b7dSRichard Lowe make_machines_list_mb, 185*10d63b7dSRichard Lowe (strlen(make_machines_list_mb) + 1)); 186*10d63b7dSRichard Lowe } 187*10d63b7dSRichard Lowe } 188*10d63b7dSRichard Lowe } 189*10d63b7dSRichard Lowe 190*10d63b7dSRichard Lowe uname(&uts_info); 191*10d63b7dSRichard Lowe strcpy(local_host_mb, &uts_info.nodename[0]); 192*10d63b7dSRichard Lowe MBSTOWCS(local_host, local_host_mb); 193*10d63b7dSRichard Lowe local_host_wslen = wcslen(local_host); 194*10d63b7dSRichard Lowe 195*10d63b7dSRichard Lowe // There is no getdomainname() function on Solaris. 196*10d63b7dSRichard Lowe // And netname2host() function does not work on Linux. 197*10d63b7dSRichard Lowe // So we have to use different APIs. 198*10d63b7dSRichard Lowe if (host2netname(mbs_buffer, NULL, NULL) && 199*10d63b7dSRichard Lowe netname2host(mbs_buffer, mbs_buffer2, MAXNETNAMELEN+1)) { 200*10d63b7dSRichard Lowe MBSTOWCS(full_host, mbs_buffer2); 201*10d63b7dSRichard Lowe full_host_wslen = wcslen(full_host); 202*10d63b7dSRichard Lowe } 203*10d63b7dSRichard Lowe 204*10d63b7dSRichard Lowe for (ms = make_machines_list; 205*10d63b7dSRichard Lowe (ms) && (*ms ); 206*10d63b7dSRichard Lowe ) { 207*10d63b7dSRichard Lowe /* 208*10d63b7dSRichard Lowe * Skip white space and comments till you reach 209*10d63b7dSRichard Lowe * a machine name. 210*10d63b7dSRichard Lowe */ 211*10d63b7dSRichard Lowe pskip_till_next_word(&ms); 212*10d63b7dSRichard Lowe 213*10d63b7dSRichard Lowe /* 214*10d63b7dSRichard Lowe * If we haven't reached the end of file, process the 215*10d63b7dSRichard Lowe * machine name. 216*10d63b7dSRichard Lowe */ 217*10d63b7dSRichard Lowe if (*ms) { 218*10d63b7dSRichard Lowe /* 219*10d63b7dSRichard Lowe * If invalid machine name decrement counter 220*10d63b7dSRichard Lowe * and skip line. 221*10d63b7dSRichard Lowe */ 222*10d63b7dSRichard Lowe mp = ms; 223*10d63b7dSRichard Lowe SKIPWORD(ms); 224*10d63b7dSRichard Lowe c = *ms; 225*10d63b7dSRichard Lowe *ms++ = '\0'; /* Append null to machine name. */ 226*10d63b7dSRichard Lowe /* 227*10d63b7dSRichard Lowe * If this was the beginning of a comment 228*10d63b7dSRichard Lowe * (we overwrote a # sign) and it's not 229*10d63b7dSRichard Lowe * end of line yet, shift the # sign. 230*10d63b7dSRichard Lowe */ 231*10d63b7dSRichard Lowe if ((c == '#') && (*ms != '\n') && (*ms)) { 232*10d63b7dSRichard Lowe *ms = '#'; 233*10d63b7dSRichard Lowe } 234*10d63b7dSRichard Lowe WCSTOMBS(mbs_buffer, mp); 235*10d63b7dSRichard Lowe /* 236*10d63b7dSRichard Lowe * Print "Ignoring unknown host" if: 237*10d63b7dSRichard Lowe * 1) hostname is longer than MAX_HOSTNAMELEN, or 238*10d63b7dSRichard Lowe * 2) hostname is unknown 239*10d63b7dSRichard Lowe */ 240*10d63b7dSRichard Lowe if ((wcslen(mp) > MAX_HOSTNAMELEN) || 241*10d63b7dSRichard Lowe ((hp = gethostbyname(mbs_buffer)) == NULL)) { 242*10d63b7dSRichard Lowe warning(gettext("Ignoring unknown host %s"), 243*10d63b7dSRichard Lowe mbs_buffer); 244*10d63b7dSRichard Lowe SKIPTOEND(ms); 245*10d63b7dSRichard Lowe /* Increment ptr if not end of file. */ 246*10d63b7dSRichard Lowe if (*ms) { 247*10d63b7dSRichard Lowe ms++; 248*10d63b7dSRichard Lowe } 249*10d63b7dSRichard Lowe } else { 250*10d63b7dSRichard Lowe /* Compare current hostname with local_host. */ 251*10d63b7dSRichard Lowe if (wcslen(mp) == local_host_wslen && 252*10d63b7dSRichard Lowe IS_WEQUALN(mp, local_host, local_host_wslen)) { 253*10d63b7dSRichard Lowe /* 254*10d63b7dSRichard Lowe * Bingo, local_host is in .make.machines. 255*10d63b7dSRichard Lowe * Continue reading. 256*10d63b7dSRichard Lowe */ 257*10d63b7dSRichard Lowe pmake_max_jobs = PMAKE_DEF_MAX_JOBS; 258*10d63b7dSRichard Lowe /* Compare current hostname with full_host. */ 259*10d63b7dSRichard Lowe } else if (wcslen(mp) == full_host_wslen && 260*10d63b7dSRichard Lowe IS_WEQUALN(mp, full_host, full_host_wslen)) { 261*10d63b7dSRichard Lowe /* 262*10d63b7dSRichard Lowe * Bingo, full_host is in .make.machines. 263*10d63b7dSRichard Lowe * Continue reading. 264*10d63b7dSRichard Lowe */ 265*10d63b7dSRichard Lowe pmake_max_jobs = PMAKE_DEF_MAX_JOBS; 266*10d63b7dSRichard Lowe } else { 267*10d63b7dSRichard Lowe if (c != '\n') { 268*10d63b7dSRichard Lowe SKIPTOEND(ms); 269*10d63b7dSRichard Lowe if (*ms) { 270*10d63b7dSRichard Lowe ms++; 271*10d63b7dSRichard Lowe } 272*10d63b7dSRichard Lowe } 273*10d63b7dSRichard Lowe continue; 274*10d63b7dSRichard Lowe } 275*10d63b7dSRichard Lowe /* If we get here, local_host is in .make.machines. */ 276*10d63b7dSRichard Lowe if (c != '\n') { 277*10d63b7dSRichard Lowe /* Now look for keyword 'max'. */ 278*10d63b7dSRichard Lowe MBSTOWCS(wcs_buffer, "max"); 279*10d63b7dSRichard Lowe SKIPSPACE(ms); 280*10d63b7dSRichard Lowe while ((*ms != '\n') && (*ms)) { 281*10d63b7dSRichard Lowe if (*ms == '#') { 282*10d63b7dSRichard Lowe pskip_comment(&ms); 283*10d63b7dSRichard Lowe } else if (IS_WEQUALN(ms, wcs_buffer, 3)) { 284*10d63b7dSRichard Lowe /* Skip "max". */ 285*10d63b7dSRichard Lowe ms += 3; 286*10d63b7dSRichard Lowe pmake_max_jobs = get_max(&ms, mp); 287*10d63b7dSRichard Lowe SKIPSPACE(ms); 288*10d63b7dSRichard Lowe } else { 289*10d63b7dSRichard Lowe warning(gettext("unknown option for host %s"), mbs_buffer); 290*10d63b7dSRichard Lowe SKIPTOEND(ms); 291*10d63b7dSRichard Lowe break; 292*10d63b7dSRichard Lowe } 293*10d63b7dSRichard Lowe } 294*10d63b7dSRichard Lowe } 295*10d63b7dSRichard Lowe break; /* out of outermost for() loop. */ 296*10d63b7dSRichard Lowe } 297*10d63b7dSRichard Lowe } 298*10d63b7dSRichard Lowe } 299*10d63b7dSRichard Lowe retmem(make_machines_list); 300*10d63b7dSRichard Lowe return(pmake_max_jobs); 301*10d63b7dSRichard Lowe } 302*10d63b7dSRichard Lowe 303*10d63b7dSRichard Lowe /* 304*10d63b7dSRichard Lowe * pskip_till_next_word(cp) 305*10d63b7dSRichard Lowe * 306*10d63b7dSRichard Lowe * Parameters: 307*10d63b7dSRichard Lowe * cp the address of the string pointer. 308*10d63b7dSRichard Lowe * 309*10d63b7dSRichard Lowe * On return: 310*10d63b7dSRichard Lowe * cp points to beginning of machine name. 311*10d63b7dSRichard Lowe * 312*10d63b7dSRichard Lowe */ 313*10d63b7dSRichard Lowe static void 314*10d63b7dSRichard Lowe pskip_till_next_word(wchar_t **cp) 315*10d63b7dSRichard Lowe { 316*10d63b7dSRichard Lowe /* 317*10d63b7dSRichard Lowe * Keep recursing until all combinations of white spaces 318*10d63b7dSRichard Lowe * and comments have been skipped. 319*10d63b7dSRichard Lowe */ 320*10d63b7dSRichard Lowe if (pskip_white_space(cp) || pskip_comment(cp)) { 321*10d63b7dSRichard Lowe pskip_till_next_word(cp); 322*10d63b7dSRichard Lowe } 323*10d63b7dSRichard Lowe } 324*10d63b7dSRichard Lowe 325*10d63b7dSRichard Lowe /* 326*10d63b7dSRichard Lowe * pskip_white_space(cp_address) 327*10d63b7dSRichard Lowe * 328*10d63b7dSRichard Lowe * Advances the string pointer so that it points to the first 329*10d63b7dSRichard Lowe * non white character (space/tab/linefeed). 330*10d63b7dSRichard Lowe * 331*10d63b7dSRichard Lowe * Parameters: 332*10d63b7dSRichard Lowe * cp_address the address of the string pointer. 333*10d63b7dSRichard Lowe * 334*10d63b7dSRichard Lowe * Return Value: 335*10d63b7dSRichard Lowe * True if the pointer was changed. 336*10d63b7dSRichard Lowe * 337*10d63b7dSRichard Lowe */ 338*10d63b7dSRichard Lowe static Boolean 339*10d63b7dSRichard Lowe pskip_white_space(wchar_t **cp_address) 340*10d63b7dSRichard Lowe { 341*10d63b7dSRichard Lowe wchar_t *cp = *cp_address; 342*10d63b7dSRichard Lowe 343*10d63b7dSRichard Lowe while (*cp && iswspace(*cp)) { 344*10d63b7dSRichard Lowe cp++; 345*10d63b7dSRichard Lowe } 346*10d63b7dSRichard Lowe /* Have we skipped any characters? */ 347*10d63b7dSRichard Lowe if (cp != *cp_address) { 348*10d63b7dSRichard Lowe *cp_address = cp; 349*10d63b7dSRichard Lowe return(true); 350*10d63b7dSRichard Lowe } else { 351*10d63b7dSRichard Lowe return(false); 352*10d63b7dSRichard Lowe } 353*10d63b7dSRichard Lowe } 354*10d63b7dSRichard Lowe 355*10d63b7dSRichard Lowe /* 356*10d63b7dSRichard Lowe * pskip_comment(cp_address) 357*10d63b7dSRichard Lowe * 358*10d63b7dSRichard Lowe * If cp_address is pointing to '#' (the beginning of a comment), 359*10d63b7dSRichard Lowe * increment the pointer till you reach end of line. 360*10d63b7dSRichard Lowe * 361*10d63b7dSRichard Lowe * Parameters: 362*10d63b7dSRichard Lowe * cp_address the address of the string pointer. 363*10d63b7dSRichard Lowe * 364*10d63b7dSRichard Lowe * Return Value: 365*10d63b7dSRichard Lowe * True if the pointer was changed. 366*10d63b7dSRichard Lowe * 367*10d63b7dSRichard Lowe */ 368*10d63b7dSRichard Lowe static Boolean 369*10d63b7dSRichard Lowe pskip_comment(wchar_t **cp_address) 370*10d63b7dSRichard Lowe { 371*10d63b7dSRichard Lowe wchar_t *cp = *cp_address; 372*10d63b7dSRichard Lowe 373*10d63b7dSRichard Lowe /* Is this the beginning of a comment? Skip till end of line. */ 374*10d63b7dSRichard Lowe if (*cp == '#') { 375*10d63b7dSRichard Lowe SKIPTOEND(cp); 376*10d63b7dSRichard Lowe } 377*10d63b7dSRichard Lowe /* Have we skipped a comment line? */ 378*10d63b7dSRichard Lowe if (cp != *cp_address) { 379*10d63b7dSRichard Lowe *cp_address = cp; 380*10d63b7dSRichard Lowe return(true); 381*10d63b7dSRichard Lowe } else { 382*10d63b7dSRichard Lowe return(false); 383*10d63b7dSRichard Lowe } 384*10d63b7dSRichard Lowe } 385*10d63b7dSRichard Lowe 386*10d63b7dSRichard Lowe static int 387*10d63b7dSRichard Lowe get_max(wchar_t **ms_address, wchar_t *hostname) 388*10d63b7dSRichard Lowe { 389*10d63b7dSRichard Lowe wchar_t *ms = *ms_address; 390*10d63b7dSRichard Lowe int limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */ 391*10d63b7dSRichard Lowe 392*10d63b7dSRichard Lowe WCSTOMBS(mbs_buffer, hostname); 393*10d63b7dSRichard Lowe /* Look for `='. */ 394*10d63b7dSRichard Lowe SKIPSPACE(ms); 395*10d63b7dSRichard Lowe if ((!*ms) || (*ms == '\n') || (*ms != '=')) { 396*10d63b7dSRichard Lowe SKIPTOEND(ms); 397*10d63b7dSRichard Lowe warning(gettext("expected `=' after max, ignoring rest of line for host %s"), 398*10d63b7dSRichard Lowe mbs_buffer); 399*10d63b7dSRichard Lowe *ms_address = ms; 400*10d63b7dSRichard Lowe return((int) limit); 401*10d63b7dSRichard Lowe } else { 402*10d63b7dSRichard Lowe ms++; 403*10d63b7dSRichard Lowe SKIPSPACE(ms); 404*10d63b7dSRichard Lowe if ((*ms != '\n') && (*ms != '\0')) { 405*10d63b7dSRichard Lowe /* We've found, hopefully, a valid "max" value. */ 406*10d63b7dSRichard Lowe limit = (int) wcstol(ms, &ms, 10); 407*10d63b7dSRichard Lowe if (limit < 1) { 408*10d63b7dSRichard Lowe limit = PMAKE_DEF_MAX_JOBS; 409*10d63b7dSRichard Lowe warning(gettext("max value cannot be less than or equal to zero for host %s"), mbs_buffer); 410*10d63b7dSRichard Lowe } 411*10d63b7dSRichard Lowe } else { 412*10d63b7dSRichard Lowe /* No "max" value after "max=". */ 413*10d63b7dSRichard Lowe warning(gettext("no max value specified for host %s"), mbs_buffer); 414*10d63b7dSRichard Lowe } 415*10d63b7dSRichard Lowe *ms_address = ms; 416*10d63b7dSRichard Lowe return(limit); 417*10d63b7dSRichard Lowe } 418*10d63b7dSRichard Lowe } 419*10d63b7dSRichard Lowe 420*10d63b7dSRichard Lowe 421