Print this page
make: use the more modern wchar routines, not widec.h

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/make/lib/mksh/macro.cc
          +++ new/usr/src/cmd/make/lib/mksh/macro.cc
↓ open down ↓ 31 lines elided ↑ open up ↑
  32   32  
  33   33  /*
  34   34   * Included files
  35   35   */
  36   36  #include <mksh/dosys.h>         /* sh_command2string() */
  37   37  #include <mksh/i18n.h>          /* get_char_semantics_value() */
  38   38  #include <mksh/macro.h>
  39   39  #include <mksh/misc.h>          /* retmem() */
  40   40  #include <mksh/read.h>          /* get_next_block_fn() */
  41   41  
  42      -#include <widec.h>
  43   42  #include <libintl.h>
  44   43  
  45   44  /*
  46   45   * File table of contents
  47   46   */
  48   47  static void     add_macro_to_global_list(Name macro_to_add);
  49   48  static void     expand_value_with_daemon(Name, register Property macro, register String destination, Boolean cmd);
  50   49  
  51   50  static void     init_arch_macros(void);
  52   51  static void     init_mach_macros(void);
↓ open down ↓ 95 lines elided ↑ open up ↑
 148  147                  return;
 149  148          }
 150  149  
 151  150          if (value->being_expanded) {
 152  151                  fatal_reader_mksh(gettext("Loop detected when expanding macro value `%s'"),
 153  152                               value->string_mb);
 154  153          }
 155  154          value->being_expanded = true;
 156  155          /* Setup the structure we read from */
 157  156          Wstring vals(value);
 158      -        sourceb.string.text.p = sourceb.string.buffer.start = wsdup(vals.get_string());
      157 +        sourceb.string.text.p = sourceb.string.buffer.start = wcsdup(vals.get_string());
 159  158          sourceb.string.free_after_use = true;
 160  159          sourceb.string.text.end =
 161  160            sourceb.string.buffer.end =
 162  161              sourceb.string.text.p + value->hash.length;
 163  162          sourceb.previous = NULL;
 164  163          sourceb.fd = -1;
 165  164          sourceb.inp_buf =
 166  165            sourceb.inp_buf_ptr =
 167  166              sourceb.inp_buf_end = NULL;
 168  167          sourceb.error_converting = false;
↓ open down ↓ 283 lines elided ↑ open up ↑
 452  451                  case 'F':
 453  452                          extraction = file_extract;
 454  453                          break;
 455  454                  default:
 456  455                          WCSTOMBS(mbs_buffer, string.buffer.start);
 457  456                          fatal_reader_mksh(gettext("Illegal macro reference `%s'"),
 458  457                                       mbs_buffer);
 459  458                  }
 460  459                  /* Internalize the macro name using the first char only. */
 461  460                  name = GETNAME(string.buffer.start, 1);
 462      -                (void) wscpy(string.buffer.start, string.buffer.start + 2);
      461 +                (void) wcscpy(string.buffer.start, string.buffer.start + 2);
 463  462          }
 464  463          /* Check for other kinds of translations. */
 465      -        if ((colon = (wchar_t *) wschr(string.buffer.start,
      464 +        if ((colon = (wchar_t *) wcschr(string.buffer.start,
 466  465                                         (int) colon_char)) != NULL) {
 467  466                  /*
 468  467                   * We have a $(FOO:.c=.o) type translation.
 469  468                   * Get the name of the macro proper.
 470  469                   */
 471  470                  if (name == NULL) {
 472  471                          name = GETNAME(string.buffer.start,
 473  472                                         colon - string.buffer.start);
 474  473                  }
 475  474                  /* Pickup all the translations. */
 476  475                  if (IS_WEQUAL(colon, colon_sh) || IS_WEQUAL(colon, colon_shell)) {
 477  476                          replacement = sh_replace;
 478  477                  } else if ((svr4) ||
 479      -                           ((percent = (wchar_t *) wschr(colon + 1,
      478 +                           ((percent = (wchar_t *) wcschr(colon + 1,
 480  479                                                           (int) percent_char)) == NULL)) {
 481  480                          while (colon != NULL) {
 482      -                                if ((eq = (wchar_t *) wschr(colon + 1,
      481 +                                if ((eq = (wchar_t *) wcschr(colon + 1,
 483  482                                                              (int) equal_char)) == NULL) {
 484  483                                          fatal_reader_mksh(gettext("= missing from replacement macro reference"));
 485  484                                  }
 486  485                                  left_tail_len = eq - colon - 1;
 487  486                                  if(left_tail) {
 488  487                                          retmem(left_tail);
 489  488                                  }
 490  489                                  left_tail = ALLOC_WC(left_tail_len + 1);
 491      -                                (void) wsncpy(left_tail,
      490 +                                (void) wcsncpy(left_tail,
 492  491                                                colon + 1,
 493  492                                                eq - colon - 1);
 494  493                                  left_tail[eq - colon - 1] = (int) nul_char;
 495  494                                  replacement = suffix_replace;
 496      -                                if ((colon = (wchar_t *) wschr(eq + 1,
      495 +                                if ((colon = (wchar_t *) wcschr(eq + 1,
 497  496                                                                 (int) colon_char)) != NULL) {
 498  497                                          tmp_len = colon - eq;
 499  498                                          if(right_tail) {
 500  499                                                  retmem(right_tail);
 501  500                                          }
 502  501                                          right_tail = ALLOC_WC(tmp_len);
 503      -                                        (void) wsncpy(right_tail,
      502 +                                        (void) wcsncpy(right_tail,
 504  503                                                        eq + 1,
 505  504                                                        colon - eq - 1);
 506  505                                          right_tail[colon - eq - 1] =
 507  506                                            (int) nul_char;
 508  507                                  } else {
 509  508                                          if(right_tail) {
 510  509                                                  retmem(right_tail);
 511  510                                          }
 512      -                                        right_tail = ALLOC_WC(wslen(eq) + 1);
 513      -                                        (void) wscpy(right_tail, eq + 1);
      511 +                                        right_tail = ALLOC_WC(wcslen(eq) + 1);
      512 +                                        (void) wcscpy(right_tail, eq + 1);
 514  513                                  }
 515  514                          }
 516  515                  } else {
 517      -                        if ((eq = (wchar_t *) wschr(colon + 1,
      516 +                        if ((eq = (wchar_t *) wcschr(colon + 1,
 518  517                                                      (int) equal_char)) == NULL) {
 519  518                                  fatal_reader_mksh(gettext("= missing from replacement macro reference"));
 520  519                          }
 521      -                        if ((percent = (wchar_t *) wschr(colon + 1,
      520 +                        if ((percent = (wchar_t *) wcschr(colon + 1,
 522  521                                                           (int) percent_char)) == NULL) {
 523  522                                  fatal_reader_mksh(gettext("%% missing from replacement macro reference"));
 524  523                          }
 525  524                          if (eq < percent) {
 526  525                                  fatal_reader_mksh(gettext("%% missing from replacement macro reference"));
 527  526                          }
 528  527  
 529  528                          if (percent > (colon + 1)) {
 530  529                                  tmp_len = percent - colon;
 531  530                                  if(left_head) {
 532  531                                          retmem(left_head);
 533  532                                  }
 534  533                                  left_head = ALLOC_WC(tmp_len);
 535      -                                (void) wsncpy(left_head,
      534 +                                (void) wcsncpy(left_head,
 536  535                                                colon + 1,
 537  536                                                percent - colon - 1);
 538  537                                  left_head[percent-colon-1] = (int) nul_char;
 539  538                                  left_head_len = percent-colon-1;
 540  539                          } else {
 541  540                                  left_head = NULL;
 542  541                                  left_head_len = 0;
 543  542                          }
 544  543  
 545  544                          if (eq > percent+1) {
 546  545                                  tmp_len = eq - percent;
 547  546                                  if(left_tail) {
 548  547                                          retmem(left_tail);
 549  548                                  }
 550  549                                  left_tail = ALLOC_WC(tmp_len);
 551      -                                (void) wsncpy(left_tail,
      550 +                                (void) wcsncpy(left_tail,
 552  551                                                percent + 1,
 553  552                                                eq - percent - 1);
 554  553                                  left_tail[eq-percent-1] = (int) nul_char;
 555  554                                  left_tail_len = eq-percent-1;
 556  555                          } else {
 557  556                                  left_tail = NULL;
 558  557                                  left_tail_len = 0;
 559  558                          }
 560  559  
 561      -                        if ((percent = (wchar_t *) wschr(++eq,
      560 +                        if ((percent = (wchar_t *) wcschr(++eq,
 562  561                                                           (int) percent_char)) == NULL) {
 563  562  
 564      -                                right_hand[0] = ALLOC_WC(wslen(eq) + 1);
      563 +                                right_hand[0] = ALLOC_WC(wcslen(eq) + 1);
 565  564                                  right_hand[1] = NULL;
 566      -                                (void) wscpy(right_hand[0], eq);
      565 +                                (void) wcscpy(right_hand[0], eq);
 567  566                          } else {
 568  567                                  i = 0;
 569  568                                  do {
 570  569                                          right_hand[i] = ALLOC_WC(percent-eq+1);
 571      -                                        (void) wsncpy(right_hand[i],
      570 +                                        (void) wcsncpy(right_hand[i],
 572  571                                                        eq,
 573  572                                                        percent - eq);
 574  573                                          right_hand[i][percent-eq] =
 575  574                                            (int) nul_char;
 576  575                                          if (i++ >= VSIZEOF(right_hand)) {
 577  576                                                  fatal_mksh(gettext("Too many %% in pattern"));
 578  577                                          }
 579  578                                          eq = percent + 1;
 580  579                                          if (eq[0] == (int) nul_char) {
 581  580                                                  MBSTOWCS(wcs_buffer, "");
 582      -                                                right_hand[i] = (wchar_t *) wsdup(wcs_buffer);
      581 +                                                right_hand[i] = (wchar_t *) wcsdup(wcs_buffer);
 583  582                                                  i++;
 584  583                                                  break;
 585  584                                          }
 586      -                                } while ((percent = (wchar_t *) wschr(eq, (int) percent_char)) != NULL);
      585 +                                } while ((percent = (wchar_t *) wcschr(eq, (int) percent_char)) != NULL);
 587  586                                  if (eq[0] != (int) nul_char) {
 588      -                                        right_hand[i] = ALLOC_WC(wslen(eq) + 1);
 589      -                                        (void) wscpy(right_hand[i], eq);
      587 +                                        right_hand[i] = ALLOC_WC(wcslen(eq) + 1);
      588 +                                        (void) wcscpy(right_hand[i], eq);
 590  589                                          i++;
 591  590                                  }
 592  591                                  right_hand[i] = NULL;
 593  592                          }
 594  593                          replacement = pattern_replace;
 595  594                  }
 596  595          }
 597  596          if (name == NULL) {
 598  597                  /*
 599  598                   * No translations found.
↓ open down ↓ 89 lines elided ↑ open up ↑
 689  688                          case dir_extract:
 690  689                                  /*
 691  690                                   * $(@D) type transform. Extract the
 692  691                                   * path from the word. Deliver "." if
 693  692                                   * none is found.
 694  693                                   */
 695  694                                  if (p != NULL) {
 696  695                                          chr = *p;
 697  696                                          *p = (int) nul_char;
 698  697                                  }
 699      -                                eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
      698 +                                eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
 700  699                                  if (p != NULL) {
 701  700                                          *p = chr;
 702  701                                  }
 703  702                                  if ((eq == NULL) || (eq > p)) {
 704  703                                          MBSTOWCS(wcs_buffer, ".");
 705  704                                          append_string(wcs_buffer, &extracted, 1);
 706  705                                  } else {
 707  706                                          append_string(block_start,
 708  707                                                        &extracted,
 709  708                                                        eq - block_start);
↓ open down ↓ 1 lines elided ↑ open up ↑
 711  710                                  break;
 712  711                          case file_extract:
 713  712                                  /*
 714  713                                   * $(@F) type transform. Remove the path
 715  714                                   * from the word if any.
 716  715                                   */
 717  716                                  if (p != NULL) {
 718  717                                          chr = *p;
 719  718                                          *p = (int) nul_char;
 720  719                                  }
 721      -                                eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
      720 +                                eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
 722  721                                  if (p != NULL) {
 723  722                                          *p = chr;
 724  723                                  }
 725  724                                  if ((eq == NULL) || (eq > p)) {
 726  725                                          append_string(block_start,
 727  726                                                        &extracted,
 728  727                                                        p - block_start);
 729  728                                  } else {
 730  729                                          append_string(eq + 1,
 731  730                                                        &extracted,
↓ open down ↓ 180 lines elided ↑ open up ↑
 912  911  
 913  912          if (set_host || set_target) {
 914  913                  INIT_STRING_FROM_STACK(result_string, wc_buf);
 915  914                  append_char((int) hyphen_char, &result_string);
 916  915  
 917  916                  if ((pipe = popen(mach_command, "r")) == NULL) {
 918  917                          fatal_mksh(gettext("Execute of %s failed"), mach_command);
 919  918                  }
 920  919                  while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
 921  920                          MBSTOWCS(wcs_buffer, mb_buf);
 922      -                        append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
      921 +                        append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
 923  922                  }
 924  923                  if (pclose(pipe) != 0) {
 925  924                          fatal_mksh(gettext("Execute of %s failed"), mach_command);
 926  925                  }
 927  926  
 928      -                value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
      927 +                value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
 929  928  
 930  929                  if (set_host) {
 931  930                          (void) setvar_daemon(host_arch, value, false, no_daemon, true, 0);
 932  931                  }
 933  932                  if (set_target) {
 934  933                          (void) setvar_daemon(target_arch, value, false, no_daemon, true, 0);
 935  934                  }
 936  935          }
 937  936  }
 938  937  
↓ open down ↓ 28 lines elided ↑ open up ↑
 967  966  
 968  967          if (set_host || set_target) {
 969  968                  INIT_STRING_FROM_STACK(result_string, wc_buf);
 970  969                  append_char((int) hyphen_char, &result_string);
 971  970  
 972  971                  if ((pipe = popen(arch_command, "r")) == NULL) {
 973  972                          fatal_mksh(gettext("Execute of %s failed"), arch_command);
 974  973                  }
 975  974                  while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
 976  975                          MBSTOWCS(wcs_buffer, mb_buf);
 977      -                        append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
      976 +                        append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
 978  977                  }
 979  978                  if (pclose(pipe) != 0) {
 980  979                          fatal_mksh(gettext("Execute of %s failed"), arch_command);
 981  980                  }
 982  981  
 983      -                value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
      982 +                value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
 984  983  
 985  984                  if (set_host) {
 986  985                          (void) setvar_daemon(host_mach, value, false, no_daemon, true, 0);
 987  986                  }
 988  987                  if (set_target) {
 989  988                          (void) setvar_daemon(target_mach, value, false, no_daemon, true, 0);
 990  989                  }
 991  990          }
 992  991  }
 993  992  
↓ open down ↓ 297 lines elided ↑ open up ↑
1291 1290  
1292 1291                  Wstring         ha_str(ha);
1293 1292                  Wstring         ta_str(ta);
1294 1293                  Wstring         vr_str(vr);
1295 1294  
1296 1295                  wchar_t * wcb_ha = ha_str.get_string();
1297 1296                  wchar_t * wcb_ta = ta_str.get_string();
1298 1297                  wchar_t * wcb_vr = vr_str.get_string();
1299 1298  
1300 1299                  length = 32 +
1301      -                  wslen(wcb_ha) +
1302      -                    wslen(wcb_ta) +
1303      -                      wslen(wcb_vr);
     1300 +                  wcslen(wcb_ha) +
     1301 +                    wcslen(wcb_ta) +
     1302 +                      wcslen(wcb_vr);
1304 1303                  old_vr = wcb_vr;
1305 1304                  MBSTOWCS(wcs_buffer, "/usr/arch/");
1306 1305                  if (IS_WEQUALN(old_vr,
1307 1306                                 wcs_buffer,
1308      -                               wslen(wcs_buffer))) {
1309      -                        old_vr = (wchar_t *) wschr(old_vr, (int) colon_char) + 1;
     1307 +                               wcslen(wcs_buffer))) {
     1308 +                        old_vr = (wchar_t *) wcschr(old_vr, (int) colon_char) + 1;
1310 1309                  }
1311      -                if ( (ha == ta) || (wslen(wcb_ta) == 0) ) {
     1310 +                if ( (ha == ta) || (wcslen(wcb_ta) == 0) ) {
1312 1311                          new_value = old_vr;
1313 1312                  } else {
1314 1313                          new_value = ALLOC_WC(length);
1315 1314                          new_value_allocated = true;
1316 1315                          WCSTOMBS(mbs_buffer, old_vr);
1317      -                        (void) wsprintf(new_value,
1318      -                                        "/usr/arch/%s/%s:%s",
     1316 +                        (void) swprintf(new_value, length * SIZEOFWCHAR_T, 
     1317 +                                        L"/usr/arch/%s/%s:%s",
1319 1318                                          ha->string_mb + 1,
1320 1319                                          ta->string_mb + 1,
1321 1320                                          mbs_buffer);
1322 1321                  }
1323 1322                  if (new_value[0] != 0) {
1324 1323                          (void) setvar_daemon(virtual_root,
1325 1324                                               GETNAME(new_value, FIND_LENGTH),
1326 1325                                               false,
1327 1326                                               no_daemon,
1328 1327                                               true,
1329 1328                                               debug_level);
1330 1329                  }
1331 1330                  if (new_value_allocated) {
1332 1331                          retmem(new_value);
1333 1332                  }
1334 1333          }
1335 1334          return macro;
1336 1335  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX