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

@@ -37,11 +37,10 @@
 #include <mksh/i18n.h>          /* get_char_semantics_value() */
 #include <mksh/macro.h>
 #include <mksh/misc.h>          /* retmem() */
 #include <mksh/read.h>          /* get_next_block_fn() */
 
-#include <widec.h>
 #include <libintl.h>
 
 /*
  * File table of contents
  */

@@ -153,11 +152,11 @@
                              value->string_mb);
         }
         value->being_expanded = true;
         /* Setup the structure we read from */
         Wstring vals(value);
-        sourceb.string.text.p = sourceb.string.buffer.start = wsdup(vals.get_string());
+        sourceb.string.text.p = sourceb.string.buffer.start = wcsdup(vals.get_string());
         sourceb.string.free_after_use = true;
         sourceb.string.text.end =
           sourceb.string.buffer.end =
             sourceb.string.text.p + value->hash.length;
         sourceb.previous = NULL;

@@ -457,14 +456,14 @@
                         fatal_reader_mksh(gettext("Illegal macro reference `%s'"),
                                      mbs_buffer);
                 }
                 /* Internalize the macro name using the first char only. */
                 name = GETNAME(string.buffer.start, 1);
-                (void) wscpy(string.buffer.start, string.buffer.start + 2);
+                (void) wcscpy(string.buffer.start, string.buffer.start + 2);
         }
         /* Check for other kinds of translations. */
-        if ((colon = (wchar_t *) wschr(string.buffer.start,
+        if ((colon = (wchar_t *) wcschr(string.buffer.start,
                                        (int) colon_char)) != NULL) {
                 /*
                  * We have a $(FOO:.c=.o) type translation.
                  * Get the name of the macro proper.
                  */

@@ -474,53 +473,53 @@
                 }
                 /* Pickup all the translations. */
                 if (IS_WEQUAL(colon, colon_sh) || IS_WEQUAL(colon, colon_shell)) {
                         replacement = sh_replace;
                 } else if ((svr4) ||
-                           ((percent = (wchar_t *) wschr(colon + 1,
+                           ((percent = (wchar_t *) wcschr(colon + 1,
                                                          (int) percent_char)) == NULL)) {
                         while (colon != NULL) {
-                                if ((eq = (wchar_t *) wschr(colon + 1,
+                                if ((eq = (wchar_t *) wcschr(colon + 1,
                                                             (int) equal_char)) == NULL) {
                                         fatal_reader_mksh(gettext("= missing from replacement macro reference"));
                                 }
                                 left_tail_len = eq - colon - 1;
                                 if(left_tail) {
                                         retmem(left_tail);
                                 }
                                 left_tail = ALLOC_WC(left_tail_len + 1);
-                                (void) wsncpy(left_tail,
+                                (void) wcsncpy(left_tail,
                                               colon + 1,
                                               eq - colon - 1);
                                 left_tail[eq - colon - 1] = (int) nul_char;
                                 replacement = suffix_replace;
-                                if ((colon = (wchar_t *) wschr(eq + 1,
+                                if ((colon = (wchar_t *) wcschr(eq + 1,
                                                                (int) colon_char)) != NULL) {
                                         tmp_len = colon - eq;
                                         if(right_tail) {
                                                 retmem(right_tail);
                                         }
                                         right_tail = ALLOC_WC(tmp_len);
-                                        (void) wsncpy(right_tail,
+                                        (void) wcsncpy(right_tail,
                                                       eq + 1,
                                                       colon - eq - 1);
                                         right_tail[colon - eq - 1] =
                                           (int) nul_char;
                                 } else {
                                         if(right_tail) {
                                                 retmem(right_tail);
                                         }
-                                        right_tail = ALLOC_WC(wslen(eq) + 1);
-                                        (void) wscpy(right_tail, eq + 1);
+                                        right_tail = ALLOC_WC(wcslen(eq) + 1);
+                                        (void) wcscpy(right_tail, eq + 1);
                                 }
                         }
                 } else {
-                        if ((eq = (wchar_t *) wschr(colon + 1,
+                        if ((eq = (wchar_t *) wcschr(colon + 1,
                                                     (int) equal_char)) == NULL) {
                                 fatal_reader_mksh(gettext("= missing from replacement macro reference"));
                         }
-                        if ((percent = (wchar_t *) wschr(colon + 1,
+                        if ((percent = (wchar_t *) wcschr(colon + 1,
                                                          (int) percent_char)) == NULL) {
                                 fatal_reader_mksh(gettext("%% missing from replacement macro reference"));
                         }
                         if (eq < percent) {
                                 fatal_reader_mksh(gettext("%% missing from replacement macro reference"));

@@ -530,11 +529,11 @@
                                 tmp_len = percent - colon;
                                 if(left_head) {
                                         retmem(left_head);
                                 }
                                 left_head = ALLOC_WC(tmp_len);
-                                (void) wsncpy(left_head,
+                                (void) wcsncpy(left_head,
                                               colon + 1,
                                               percent - colon - 1);
                                 left_head[percent-colon-1] = (int) nul_char;
                                 left_head_len = percent-colon-1;
                         } else {

@@ -546,49 +545,49 @@
                                 tmp_len = eq - percent;
                                 if(left_tail) {
                                         retmem(left_tail);
                                 }
                                 left_tail = ALLOC_WC(tmp_len);
-                                (void) wsncpy(left_tail,
+                                (void) wcsncpy(left_tail,
                                               percent + 1,
                                               eq - percent - 1);
                                 left_tail[eq-percent-1] = (int) nul_char;
                                 left_tail_len = eq-percent-1;
                         } else {
                                 left_tail = NULL;
                                 left_tail_len = 0;
                         }
 
-                        if ((percent = (wchar_t *) wschr(++eq,
+                        if ((percent = (wchar_t *) wcschr(++eq,
                                                          (int) percent_char)) == NULL) {
 
-                                right_hand[0] = ALLOC_WC(wslen(eq) + 1);
+                                right_hand[0] = ALLOC_WC(wcslen(eq) + 1);
                                 right_hand[1] = NULL;
-                                (void) wscpy(right_hand[0], eq);
+                                (void) wcscpy(right_hand[0], eq);
                         } else {
                                 i = 0;
                                 do {
                                         right_hand[i] = ALLOC_WC(percent-eq+1);
-                                        (void) wsncpy(right_hand[i],
+                                        (void) wcsncpy(right_hand[i],
                                                       eq,
                                                       percent - eq);
                                         right_hand[i][percent-eq] =
                                           (int) nul_char;
                                         if (i++ >= VSIZEOF(right_hand)) {
                                                 fatal_mksh(gettext("Too many %% in pattern"));
                                         }
                                         eq = percent + 1;
                                         if (eq[0] == (int) nul_char) {
                                                 MBSTOWCS(wcs_buffer, "");
-                                                right_hand[i] = (wchar_t *) wsdup(wcs_buffer);
+                                                right_hand[i] = (wchar_t *) wcsdup(wcs_buffer);
                                                 i++;
                                                 break;
                                         }
-                                } while ((percent = (wchar_t *) wschr(eq, (int) percent_char)) != NULL);
+                                } while ((percent = (wchar_t *) wcschr(eq, (int) percent_char)) != NULL);
                                 if (eq[0] != (int) nul_char) {
-                                        right_hand[i] = ALLOC_WC(wslen(eq) + 1);
-                                        (void) wscpy(right_hand[i], eq);
+                                        right_hand[i] = ALLOC_WC(wcslen(eq) + 1);
+                                        (void) wcscpy(right_hand[i], eq);
                                         i++;
                                 }
                                 right_hand[i] = NULL;
                         }
                         replacement = pattern_replace;

@@ -694,11 +693,11 @@
                                  */
                                 if (p != NULL) {
                                         chr = *p;
                                         *p = (int) nul_char;
                                 }
-                                eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
+                                eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
                                 if (p != NULL) {
                                         *p = chr;
                                 }
                                 if ((eq == NULL) || (eq > p)) {
                                         MBSTOWCS(wcs_buffer, ".");

@@ -716,11 +715,11 @@
                                  */
                                 if (p != NULL) {
                                         chr = *p;
                                         *p = (int) nul_char;
                                 }
-                                eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
+                                eq = (wchar_t *) wcsrchr(block_start, (int) slash_char);
                                 if (p != NULL) {
                                         *p = chr;
                                 }
                                 if ((eq == NULL) || (eq > p)) {
                                         append_string(block_start,

@@ -917,17 +916,17 @@
                 if ((pipe = popen(mach_command, "r")) == NULL) {
                         fatal_mksh(gettext("Execute of %s failed"), mach_command);
                 }
                 while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
                         MBSTOWCS(wcs_buffer, mb_buf);
-                        append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
+                        append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
                 }
                 if (pclose(pipe) != 0) {
                         fatal_mksh(gettext("Execute of %s failed"), mach_command);
                 }
 
-                value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
+                value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
 
                 if (set_host) {
                         (void) setvar_daemon(host_arch, value, false, no_daemon, true, 0);
                 }
                 if (set_target) {

@@ -972,17 +971,17 @@
                 if ((pipe = popen(arch_command, "r")) == NULL) {
                         fatal_mksh(gettext("Execute of %s failed"), arch_command);
                 }
                 while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
                         MBSTOWCS(wcs_buffer, mb_buf);
-                        append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
+                        append_string(wcs_buffer, &result_string, wcslen(wcs_buffer));
                 }
                 if (pclose(pipe) != 0) {
                         fatal_mksh(gettext("Execute of %s failed"), arch_command);
                 }
 
-                value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
+                value = GETNAME(result_string.buffer.start, wcslen(result_string.buffer.start));
 
                 if (set_host) {
                         (void) setvar_daemon(host_mach, value, false, no_daemon, true, 0);
                 }
                 if (set_target) {

@@ -1296,28 +1295,28 @@
                 wchar_t * wcb_ha = ha_str.get_string();
                 wchar_t * wcb_ta = ta_str.get_string();
                 wchar_t * wcb_vr = vr_str.get_string();
 
                 length = 32 +
-                  wslen(wcb_ha) +
-                    wslen(wcb_ta) +
-                      wslen(wcb_vr);
+                  wcslen(wcb_ha) +
+                    wcslen(wcb_ta) +
+                      wcslen(wcb_vr);
                 old_vr = wcb_vr;
                 MBSTOWCS(wcs_buffer, "/usr/arch/");
                 if (IS_WEQUALN(old_vr,
                                wcs_buffer,
-                               wslen(wcs_buffer))) {
-                        old_vr = (wchar_t *) wschr(old_vr, (int) colon_char) + 1;
+                               wcslen(wcs_buffer))) {
+                        old_vr = (wchar_t *) wcschr(old_vr, (int) colon_char) + 1;
                 }
-                if ( (ha == ta) || (wslen(wcb_ta) == 0) ) {
+                if ( (ha == ta) || (wcslen(wcb_ta) == 0) ) {
                         new_value = old_vr;
                 } else {
                         new_value = ALLOC_WC(length);
                         new_value_allocated = true;
                         WCSTOMBS(mbs_buffer, old_vr);
-                        (void) wsprintf(new_value,
-                                        "/usr/arch/%s/%s:%s",
+                        (void) swprintf(new_value, length * SIZEOFWCHAR_T, 
+                                        L"/usr/arch/%s/%s:%s",
                                         ha->string_mb + 1,
                                         ta->string_mb + 1,
                                         mbs_buffer);
                 }
                 if (new_value[0] != 0) {