Print this page
make: translate using gettext, rather than the unmaintainable catgets


  20  */
  21 /*
  22  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 
  27 /*
  28  * Included files
  29  */
  30 #include <arpa/inet.h>
  31 #include <mk/defs.h>
  32 #include <mksh/misc.h>
  33 #include <netdb.h>
  34 #include <netinet/in.h>
  35 #include <sys/socket.h>
  36 #include <sys/stat.h>
  37 #include <sys/types.h>
  38 #include <sys/utsname.h>
  39 #include <rpc/rpc.h>              /* host2netname(), netname2host() */

  40 
  41 /*
  42  * Defined macros
  43  */
  44 
  45 /*
  46  * typedefs & structs
  47  */
  48 
  49 /*
  50  * Static variables
  51  */
  52 
  53 /*
  54  * File table of contents
  55  */
  56 static int              get_max(wchar_t **ms_address, wchar_t *hostname);
  57 static Boolean          pskip_comment(wchar_t **cp_address);
  58 static void             pskip_till_next_word(wchar_t **cp);
  59 static Boolean          pskip_white_space(wchar_t **cp_address);


  81         struct hostent          *hp;
  82         wchar_t                 local_host[MAX_HOSTNAMELEN + 1];
  83         char                    local_host_mb[MAX_HOSTNAMELEN + 1] = "";
  84         int                     local_host_wslen;
  85         wchar_t                 full_host[MAXNETNAMELEN + 1];
  86         int                     full_host_wslen = 0;
  87         char                    *homedir;
  88         Name                    MAKE_MACHINES;
  89         struct stat             make_machines_buf;
  90         FILE                    *make_machines_file;
  91         wchar_t                 *make_machines_list = NULL;
  92         char                    *make_machines_list_mb = NULL;
  93         wchar_t                 make_machines_path[MAXPATHLEN];
  94         char                    mb_make_machines_path[MAXPATHLEN];
  95         wchar_t                 *mp;
  96         wchar_t                 *ms;
  97         int                     pmake_max_jobs = 0;
  98         struct utsname          uts_info;
  99 
 100 
 101         MBSTOWCS(wcs_buffer, NOCATGETS("MAKE_MACHINES"));
 102         MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
 103         /* Did the user specify a .make.machines file on the command line? */
 104         default_make_machines = false;
 105         if (make_machines_name == NULL) {
 106                 /* Try reading the default .make.machines file, in $(HOME). */
 107                 homedir = getenv(NOCATGETS("HOME"));
 108                 if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
 109                         sprintf(mb_make_machines_path,
 110                          NOCATGETS("%s/.make.machines"), homedir);
 111                         MBSTOWCS(make_machines_path, mb_make_machines_path);
 112                         make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
 113                         default_make_machines = true;
 114                 }
 115                 if (make_machines_name == NULL) {
 116                         /*
 117                          * No $(HOME)/.make.machines file.
 118                          * Return 0 for PMake max jobs.
 119                          */
 120                         return(0);
 121                 }
 122         }
 123 /*
 124         make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
 125  */
 126         /* Open the .make.machines file. */
 127         if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
 128                 if (!default_make_machines) {
 129                         /* Error opening .make.machines file. */
 130                         fatal(catgets(catd, 1, 314, "Open of %s failed: %s"),
 131                               make_machines_name->string_mb,
 132                               errmsg(errno));
 133                 } else {
 134                         /*
 135                          * No $(HOME)/.make.machines file.
 136                          * Return 0 for PMake max jobs.
 137                          */
 138                         return(0);
 139                 }
 140         /* Stat the .make.machines file to get the size of the file.  */
 141         } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
 142                 /* Error stat'ing .make.machines file. */
 143                 fatal(catgets(catd, 1, 315, "Stat of %s failed: %s"),
 144                       make_machines_name->string_mb,
 145                       errmsg(errno));
 146         } else {
 147                 /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
 148                 make_machines_list_mb =
 149                   (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
 150                                          2 +
 151                                          make_machines_buf.st_size));
 152                 sprintf(make_machines_list_mb,
 153                         "%s=",
 154                         MAKE_MACHINES->string_mb);
 155                 /* Read in the .make.machines file. */
 156                 if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
 157                           sizeof(char),
 158                           (int) make_machines_buf.st_size,
 159                           make_machines_file) != make_machines_buf.st_size) {
 160                         /*
 161                          * Error reading .make.machines file.
 162                          * Return 0 for PMake max jobs.
 163                          */
 164                         warning(catgets(catd, 1, 316, "Unable to read %s"),
 165                                 make_machines_name->string_mb);
 166                         (void) fclose(make_machines_file);
 167                         retmem_mb((caddr_t) make_machines_list_mb);
 168                         return(0);
 169                 } else {
 170                         (void) fclose(make_machines_file);
 171                         /* putenv "MAKE_MACHINES=<contents of .m.m>" */
 172                         *(make_machines_list_mb +
 173                           strlen(MAKE_MACHINES->string_mb) +
 174                           1 +
 175                           make_machines_buf.st_size) = (int) nul_char;
 176                         if (putenv(make_machines_list_mb) != 0) {
 177                                 warning(catgets(catd, 1, 317, "Couldn't put contents of %s in environment"),
 178                                         make_machines_name->string_mb);
 179                         } else {
 180                                 make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
 181                                 make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
 182                                 (void) mbstowcs(make_machines_list,
 183                                                 make_machines_list_mb,
 184                                                 (strlen(make_machines_list_mb) + 1));
 185                         }
 186                 }
 187         }
 188 
 189         uname(&uts_info);
 190         strcpy(local_host_mb, &uts_info.nodename[0]);
 191         MBSTOWCS(local_host, local_host_mb);
 192         local_host_wslen = wslen(local_host);
 193 
 194         // There is no getdomainname() function on Solaris.
 195         // And netname2host() function does not work on Linux.
 196         // So we have to use different APIs.
 197         if (host2netname(mbs_buffer, NULL, NULL) &&


 221                         mp = ms;
 222                         SKIPWORD(ms);
 223                         c = *ms;
 224                         *ms++ = '\0'; /* Append null to machine name. */
 225                         /*
 226                          * If this was the beginning of a comment
 227                          * (we overwrote a # sign) and it's not
 228                          * end of line yet, shift the # sign.
 229                          */
 230                         if ((c == '#') && (*ms != '\n') && (*ms)) {
 231                                 *ms = '#';
 232                         }
 233                         WCSTOMBS(mbs_buffer, mp);
 234                         /*
 235                          * Print "Ignoring unknown host" if:
 236                          * 1) hostname is longer than MAX_HOSTNAMELEN, or
 237                          * 2) hostname is unknown
 238                          */
 239                         if ((wslen(mp) > MAX_HOSTNAMELEN) ||
 240                             ((hp = gethostbyname(mbs_buffer)) == NULL)) {
 241                                 warning(catgets(catd, 1, 318, "Ignoring unknown host %s"),
 242                                         mbs_buffer);
 243                                 SKIPTOEND(ms);
 244                                 /* Increment ptr if not end of file. */
 245                                 if (*ms) {
 246                                         ms++;
 247                                 }
 248                         } else {
 249                                 /* Compare current hostname with local_host. */
 250                                 if (wslen(mp) == local_host_wslen &&
 251                                     IS_WEQUALN(mp, local_host, local_host_wslen)) {
 252                                         /*
 253                                          * Bingo, local_host is in .make.machines.
 254                                          * Continue reading.
 255                                          */
 256                                         pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
 257                                 /* Compare current hostname with full_host. */
 258                                 } else if (wslen(mp) == full_host_wslen &&
 259                                            IS_WEQUALN(mp, full_host, full_host_wslen)) {
 260                                         /*
 261                                          * Bingo, full_host is in .make.machines.
 262                                          * Continue reading.
 263                                          */
 264                                         pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
 265                                 } else {
 266                                         if (c != '\n') {
 267                                             SKIPTOEND(ms);
 268                                             if (*ms) {
 269                                                 ms++;
 270                                             }
 271                                         }
 272                                         continue;
 273                                 }
 274                                 /* If we get here, local_host is in .make.machines. */
 275                                 if (c != '\n')  {
 276                                         /* Now look for keyword 'max'. */
 277                                         MBSTOWCS(wcs_buffer, NOCATGETS("max"));
 278                                         SKIPSPACE(ms);
 279                                         while ((*ms != '\n') && (*ms)) {
 280                                                 if (*ms == '#') {
 281                                                         pskip_comment(&ms);
 282                                                 } else if (IS_WEQUALN(ms, wcs_buffer, 3)) {
 283                                                         /* Skip "max". */
 284                                                         ms += 3; 
 285                                                         pmake_max_jobs = get_max(&ms, mp); 
 286                                                         SKIPSPACE(ms);
 287                                                 } else {
 288                                                         warning(catgets(catd, 1, 322, "unknown option for host %s"), mbs_buffer);
 289                                                         SKIPTOEND(ms);
 290                                                         break;
 291                                                 }
 292                                         }
 293                                 }
 294                                 break; /* out of outermost for() loop. */
 295                         }
 296                 }
 297         }
 298         retmem(make_machines_list);
 299         return(pmake_max_jobs);
 300 }
 301 
 302 /*
 303  *      pskip_till_next_word(cp)
 304  *
 305  *      Parameters:
 306  *              cp              the address of the string pointer.
 307  *
 308  *      On return:


 376         /* Have we skipped a comment line? */
 377         if (cp != *cp_address)  {
 378                 *cp_address = cp;
 379                 return(true);
 380         } else {
 381                 return(false);
 382         }
 383 }
 384 
 385 static int
 386 get_max(wchar_t **ms_address, wchar_t *hostname)
 387 {
 388         wchar_t         *ms = *ms_address;
 389         int             limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
 390 
 391         WCSTOMBS(mbs_buffer, hostname);
 392         /* Look for `='. */
 393         SKIPSPACE(ms);
 394         if ((!*ms) || (*ms == '\n') || (*ms != '=')) {
 395                 SKIPTOEND(ms);
 396                 warning(catgets(catd, 1, 319, "expected `=' after max, ignoring rest of line for host %s"),
 397                         mbs_buffer);
 398                 *ms_address = ms;
 399                 return((int) limit);
 400         } else {
 401                 ms++;
 402                 SKIPSPACE(ms);
 403                 if ((*ms != '\n') && (*ms != '\0')) {
 404                         /* We've found, hopefully, a valid "max" value. */
 405                         limit = (int) wcstol(ms, &ms, 10);
 406                         if (limit < 1) {
 407                                 limit = PMAKE_DEF_MAX_JOBS;
 408                                 warning(catgets(catd, 1, 320, "max value cannot be less than or equal to zero for host %s"), mbs_buffer);
 409                         }
 410                 } else {
 411                         /* No "max" value after "max=". */
 412                         warning(catgets(catd, 1, 321, "no max value specified for host %s"), mbs_buffer);
 413                 }
 414                 *ms_address = ms;
 415                 return(limit);
 416         }
 417 }
 418 
 419 


  20  */
  21 /*
  22  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 
  27 /*
  28  * Included files
  29  */
  30 #include <arpa/inet.h>
  31 #include <mk/defs.h>
  32 #include <mksh/misc.h>
  33 #include <netdb.h>
  34 #include <netinet/in.h>
  35 #include <sys/socket.h>
  36 #include <sys/stat.h>
  37 #include <sys/types.h>
  38 #include <sys/utsname.h>
  39 #include <rpc/rpc.h>              /* host2netname(), netname2host() */
  40 #include <libintl.h>
  41 
  42 /*
  43  * Defined macros
  44  */
  45 
  46 /*
  47  * typedefs & structs
  48  */
  49 
  50 /*
  51  * Static variables
  52  */
  53 
  54 /*
  55  * File table of contents
  56  */
  57 static int              get_max(wchar_t **ms_address, wchar_t *hostname);
  58 static Boolean          pskip_comment(wchar_t **cp_address);
  59 static void             pskip_till_next_word(wchar_t **cp);
  60 static Boolean          pskip_white_space(wchar_t **cp_address);


  82         struct hostent          *hp;
  83         wchar_t                 local_host[MAX_HOSTNAMELEN + 1];
  84         char                    local_host_mb[MAX_HOSTNAMELEN + 1] = "";
  85         int                     local_host_wslen;
  86         wchar_t                 full_host[MAXNETNAMELEN + 1];
  87         int                     full_host_wslen = 0;
  88         char                    *homedir;
  89         Name                    MAKE_MACHINES;
  90         struct stat             make_machines_buf;
  91         FILE                    *make_machines_file;
  92         wchar_t                 *make_machines_list = NULL;
  93         char                    *make_machines_list_mb = NULL;
  94         wchar_t                 make_machines_path[MAXPATHLEN];
  95         char                    mb_make_machines_path[MAXPATHLEN];
  96         wchar_t                 *mp;
  97         wchar_t                 *ms;
  98         int                     pmake_max_jobs = 0;
  99         struct utsname          uts_info;
 100 
 101 
 102         MBSTOWCS(wcs_buffer, "MAKE_MACHINES");
 103         MAKE_MACHINES = GETNAME(wcs_buffer, FIND_LENGTH);
 104         /* Did the user specify a .make.machines file on the command line? */
 105         default_make_machines = false;
 106         if (make_machines_name == NULL) {
 107                 /* Try reading the default .make.machines file, in $(HOME). */
 108                 homedir = getenv("HOME");
 109                 if ((homedir != NULL) && (strlen(homedir) < (sizeof(mb_make_machines_path) - 16))) {
 110                         sprintf(mb_make_machines_path,
 111                          "%s/.make.machines", homedir);
 112                         MBSTOWCS(make_machines_path, mb_make_machines_path);
 113                         make_machines_name = GETNAME(make_machines_path, FIND_LENGTH);
 114                         default_make_machines = true;
 115                 }
 116                 if (make_machines_name == NULL) {
 117                         /*
 118                          * No $(HOME)/.make.machines file.
 119                          * Return 0 for PMake max jobs.
 120                          */
 121                         return(0);
 122                 }
 123         }
 124 /*
 125         make_machines_list_mb = getenv(MAKE_MACHINES->string_mb);
 126  */
 127         /* Open the .make.machines file. */
 128         if ((make_machines_file = fopen(make_machines_name->string_mb, "r")) == NULL) {
 129                 if (!default_make_machines) {
 130                         /* Error opening .make.machines file. */
 131                         fatal(gettext("Open of %s failed: %s"),
 132                               make_machines_name->string_mb,
 133                               errmsg(errno));
 134                 } else {
 135                         /*
 136                          * No $(HOME)/.make.machines file.
 137                          * Return 0 for PMake max jobs.
 138                          */
 139                         return(0);
 140                 }
 141         /* Stat the .make.machines file to get the size of the file.  */
 142         } else if (fstat(fileno(make_machines_file), &make_machines_buf) < 0) {
 143                 /* Error stat'ing .make.machines file. */
 144                 fatal(gettext("Stat of %s failed: %s"),
 145                       make_machines_name->string_mb,
 146                       errmsg(errno));
 147         } else {
 148                 /* Allocate memory for "MAKE_MACHINES=<contents of .m.m>" */
 149                 make_machines_list_mb =
 150                   (char *) getmem((int) (strlen(MAKE_MACHINES->string_mb) +
 151                                          2 +
 152                                          make_machines_buf.st_size));
 153                 sprintf(make_machines_list_mb,
 154                         "%s=",
 155                         MAKE_MACHINES->string_mb);
 156                 /* Read in the .make.machines file. */
 157                 if (fread(make_machines_list_mb + strlen(MAKE_MACHINES->string_mb) + 1,
 158                           sizeof(char),
 159                           (int) make_machines_buf.st_size,
 160                           make_machines_file) != make_machines_buf.st_size) {
 161                         /*
 162                          * Error reading .make.machines file.
 163                          * Return 0 for PMake max jobs.
 164                          */
 165                         warning(gettext("Unable to read %s"),
 166                                 make_machines_name->string_mb);
 167                         (void) fclose(make_machines_file);
 168                         retmem_mb((caddr_t) make_machines_list_mb);
 169                         return(0);
 170                 } else {
 171                         (void) fclose(make_machines_file);
 172                         /* putenv "MAKE_MACHINES=<contents of .m.m>" */
 173                         *(make_machines_list_mb +
 174                           strlen(MAKE_MACHINES->string_mb) +
 175                           1 +
 176                           make_machines_buf.st_size) = (int) nul_char;
 177                         if (putenv(make_machines_list_mb) != 0) {
 178                                 warning(gettext("Couldn't put contents of %s in environment"),
 179                                         make_machines_name->string_mb);
 180                         } else {
 181                                 make_machines_list_mb += strlen(MAKE_MACHINES->string_mb) + 1;
 182                                 make_machines_list = ALLOC_WC(strlen(make_machines_list_mb) + 1);
 183                                 (void) mbstowcs(make_machines_list,
 184                                                 make_machines_list_mb,
 185                                                 (strlen(make_machines_list_mb) + 1));
 186                         }
 187                 }
 188         }
 189 
 190         uname(&uts_info);
 191         strcpy(local_host_mb, &uts_info.nodename[0]);
 192         MBSTOWCS(local_host, local_host_mb);
 193         local_host_wslen = wslen(local_host);
 194 
 195         // There is no getdomainname() function on Solaris.
 196         // And netname2host() function does not work on Linux.
 197         // So we have to use different APIs.
 198         if (host2netname(mbs_buffer, NULL, NULL) &&


 222                         mp = ms;
 223                         SKIPWORD(ms);
 224                         c = *ms;
 225                         *ms++ = '\0'; /* Append null to machine name. */
 226                         /*
 227                          * If this was the beginning of a comment
 228                          * (we overwrote a # sign) and it's not
 229                          * end of line yet, shift the # sign.
 230                          */
 231                         if ((c == '#') && (*ms != '\n') && (*ms)) {
 232                                 *ms = '#';
 233                         }
 234                         WCSTOMBS(mbs_buffer, mp);
 235                         /*
 236                          * Print "Ignoring unknown host" if:
 237                          * 1) hostname is longer than MAX_HOSTNAMELEN, or
 238                          * 2) hostname is unknown
 239                          */
 240                         if ((wslen(mp) > MAX_HOSTNAMELEN) ||
 241                             ((hp = gethostbyname(mbs_buffer)) == NULL)) {
 242                                 warning(gettext("Ignoring unknown host %s"),
 243                                         mbs_buffer);
 244                                 SKIPTOEND(ms);
 245                                 /* Increment ptr if not end of file. */
 246                                 if (*ms) {
 247                                         ms++;
 248                                 }
 249                         } else {
 250                                 /* Compare current hostname with local_host. */
 251                                 if (wslen(mp) == local_host_wslen &&
 252                                     IS_WEQUALN(mp, local_host, local_host_wslen)) {
 253                                         /*
 254                                          * Bingo, local_host is in .make.machines.
 255                                          * Continue reading.
 256                                          */
 257                                         pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
 258                                 /* Compare current hostname with full_host. */
 259                                 } else if (wslen(mp) == full_host_wslen &&
 260                                            IS_WEQUALN(mp, full_host, full_host_wslen)) {
 261                                         /*
 262                                          * Bingo, full_host is in .make.machines.
 263                                          * Continue reading.
 264                                          */
 265                                         pmake_max_jobs = PMAKE_DEF_MAX_JOBS;
 266                                 } else {
 267                                         if (c != '\n') {
 268                                             SKIPTOEND(ms);
 269                                             if (*ms) {
 270                                                 ms++;
 271                                             }
 272                                         }
 273                                         continue;
 274                                 }
 275                                 /* If we get here, local_host is in .make.machines. */
 276                                 if (c != '\n')  {
 277                                         /* Now look for keyword 'max'. */
 278                                         MBSTOWCS(wcs_buffer, "max");
 279                                         SKIPSPACE(ms);
 280                                         while ((*ms != '\n') && (*ms)) {
 281                                                 if (*ms == '#') {
 282                                                         pskip_comment(&ms);
 283                                                 } else if (IS_WEQUALN(ms, wcs_buffer, 3)) {
 284                                                         /* Skip "max". */
 285                                                         ms += 3; 
 286                                                         pmake_max_jobs = get_max(&ms, mp); 
 287                                                         SKIPSPACE(ms);
 288                                                 } else {
 289                                                         warning(gettext("unknown option for host %s"), mbs_buffer);
 290                                                         SKIPTOEND(ms);
 291                                                         break;
 292                                                 }
 293                                         }
 294                                 }
 295                                 break; /* out of outermost for() loop. */
 296                         }
 297                 }
 298         }
 299         retmem(make_machines_list);
 300         return(pmake_max_jobs);
 301 }
 302 
 303 /*
 304  *      pskip_till_next_word(cp)
 305  *
 306  *      Parameters:
 307  *              cp              the address of the string pointer.
 308  *
 309  *      On return:


 377         /* Have we skipped a comment line? */
 378         if (cp != *cp_address)  {
 379                 *cp_address = cp;
 380                 return(true);
 381         } else {
 382                 return(false);
 383         }
 384 }
 385 
 386 static int
 387 get_max(wchar_t **ms_address, wchar_t *hostname)
 388 {
 389         wchar_t         *ms = *ms_address;
 390         int             limit = PMAKE_DEF_MAX_JOBS; /* Default setting. */
 391 
 392         WCSTOMBS(mbs_buffer, hostname);
 393         /* Look for `='. */
 394         SKIPSPACE(ms);
 395         if ((!*ms) || (*ms == '\n') || (*ms != '=')) {
 396                 SKIPTOEND(ms);
 397                 warning(gettext("expected `=' after max, ignoring rest of line for host %s"),
 398                         mbs_buffer);
 399                 *ms_address = ms;
 400                 return((int) limit);
 401         } else {
 402                 ms++;
 403                 SKIPSPACE(ms);
 404                 if ((*ms != '\n') && (*ms != '\0')) {
 405                         /* We've found, hopefully, a valid "max" value. */
 406                         limit = (int) wcstol(ms, &ms, 10);
 407                         if (limit < 1) {
 408                                 limit = PMAKE_DEF_MAX_JOBS;
 409                                 warning(gettext("max value cannot be less than or equal to zero for host %s"), mbs_buffer);
 410                         }
 411                 } else {
 412                         /* No "max" value after "max=". */
 413                         warning(gettext("no max value specified for host %s"), mbs_buffer);
 414                 }
 415                 *ms_address = ms;
 416                 return(limit);
 417         }
 418 }
 419 
 420