Re: patch /bin/ls again, for mb supporting.
On Tue, Mar 20, 2001 at 18:13:20 +, thinker wrote: > + sz = mbtowc(&c, p, dc); > + if (isprint(c)) { As MINOURA correctly notes, you can't use isprint() with wchar_t type (isprint() is for runes and single chars only, but runes are not widely accepted standard). You need to use iswprint(), see http://www.opengroup.org/onlinepubs/007908799/xsh/iswprint.html It means you need to implement wctype.h and isw*() family _before_ any ls modifications. Of course they can be easily implemented via existen runes, so consider runes as internal interface. -- Andrey A. Chernov http://ache.pp.ru/ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: patch /bin/ls again, for mb supporting.
In message <[EMAIL PROTECTED]> thinker writes: : + *ri = 0; *ri = '\0'; Yes, they are the same, but the style here is that you are terminating the string. Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: patch /bin/ls again, for mb supporting.
For style reason, I make another patch file. - begin --- --- util.c.orig Sun Mar 18 16:35:12 2001 +++ util.c Tue Mar 20 18:12:23 2001 @@ -60,15 +60,43 @@ prn_printable(s) const char *s; { - unsigned char c; - int n; + const char *p; /* String walker. */ + char *r, *ri; /* Ptr for result string & walker of it. */ + int len; + int dc; /* Count down of length after 'p' . */ + size_t sz; /* Number of bytes been processed. */ + wchar_t c; - for (n = 0; (c = *s) != '\0'; ++s, ++n) - if (isprint(c)) - putchar(c); - else - putchar('?'); - return n; + if (s == NULL) + return (0); + p = s; + dc = len = strlen(s); + ri = r = (char *)malloc(len + 1); + if (r == NULL) + return (0); + + while (dc > 0) { + sz = mbtowc(&c, p, dc); + if (sz < 0) { /* Not be recognized. */ + p++; + dc--; + *ri++ = '?'; + } else { + dc -= sz; + if (isprint(c)) { + while(sz--) + *ri++ = *p++; + } else {/* Non-printable char. */ + p += sz; + while(sz--) + *ri++ = '?'; + } + } + } + *ri = '\0'; + printf("%s", r); + free(r); + return (len); } /* - end - To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: patch /bin/ls again, for mb supporting.
On Tue, Mar 20, 2001 at 01:12:46AM -0800, Alfred Perlstein wrote: .. skip ... > > + size_t sz; > > + wchar_t c; > > C has allowed for identifiers larger than 6 characters for quite > some time, any chance on you making use of this feature? Or at > least adding a comment here and there? Ok.. I would add a comment here and there. > > > + p = s; > > + dc = len = strlen(s); > > + ri = r = (char *)malloc(len + 1); > > Where is the check for malloc failing? Yes, it is good idea. Although, I don't think that we can't alloc a memory block that less than 256+1 bytes. > > > + while (dc) { > > + sz = mbtowc(&c, p, dc); > > + if (sz < 0) { > > + p++; > > + dc--; > > + *ri++ = '?'; > > + } else { > > + dc -= sz; > > + if (isprint(c)) { > > + while(sz--) > > + *ri++ = *p++; > > + } else { > > + p += sz; > > + while(sz--) > > + *ri++ = '?'; > > Why didn't you use strlcpy/memcpy as suggested? As I can see, most codeset don't use more any 4 bytes to represent a character. For proformance reason, strlcpy/memcpy is not a good choice. For easy reading, I don't which one is better. For size, I think function call is more expensive. If we use strlcpy/memcpy, it mean we use strlcpy/memcpy to copy a block of memory that less than 4 bytes. I don't think it is good example to demo strlcpy/memcpy. > > > + } > > + } > > + } > > + *ri = 0; > > *ri = '\0'; For easy reading?? ok.. > > > + printf("%s", r); > > + free(r); > > + return len; > > return (len); > .. skip .. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: patch /bin/ls again, for mb supporting.
On Tue, Mar 20, 2001 at 01:12:46 -0800, Alfred Perlstein wrote: > > + p += sz; > > + while(sz--) > > + *ri++ = '?'; > > Why didn't you use strlcpy/memcpy as suggested? Choosen method is right. Calling *cpy for just one byte in 99% cases is overhead. -- Andrey A. Chernov http://ache.pp.ru/ To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: patch /bin/ls again, for mb supporting.
* thinker <[EMAIL PROTECTED]> [010320 00:48] wrote: > Hi, > There are some disscuss about patch file of /bin/ls. You guys > give me some suggestion, and I make a new patch file for /bin/ls to > meet people's wish. Following is patch for /bin/ls, plz review again. > I had change from rune to mb* & wc* ways. > - begin - > --- util.c.orig Sun Mar 18 16:35:12 2001 > +++ util.cTue Mar 20 16:11:37 2001 > @@ -60,15 +60,37 @@ > prn_printable(s) > const char *s; > { > - unsigned char c; > - int n; > + const char *p; > + char *r, *ri; > + int len, dc; > + size_t sz; > + wchar_t c; C has allowed for identifiers larger than 6 characters for quite some time, any chance on you making use of this feature? Or at least adding a comment here and there? > + p = s; > + dc = len = strlen(s); > + ri = r = (char *)malloc(len + 1); Where is the check for malloc failing? > + while (dc) { > + sz = mbtowc(&c, p, dc); > + if (sz < 0) { > + p++; > + dc--; > + *ri++ = '?'; > + } else { > + dc -= sz; > + if (isprint(c)) { > + while(sz--) > + *ri++ = *p++; > + } else { > + p += sz; > + while(sz--) > + *ri++ = '?'; Why didn't you use strlcpy/memcpy as suggested? > + } > + } > + } > + *ri = 0; *ri = '\0'; > + printf("%s", r); > + free(r); > + return len; return (len); > } -- -Alfred Perlstein - [[EMAIL PROTECTED]|[EMAIL PROTECTED]] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
patch /bin/ls again, for mb supporting.
Hi, There are some disscuss about patch file of /bin/ls. You guys give me some suggestion, and I make a new patch file for /bin/ls to meet people's wish. Following is patch for /bin/ls, plz review again. I had change from rune to mb* & wc* ways. - begin - --- util.c.orig Sun Mar 18 16:35:12 2001 +++ util.c Tue Mar 20 16:11:37 2001 @@ -60,15 +60,37 @@ prn_printable(s) const char *s; { - unsigned char c; - int n; + const char *p; + char *r, *ri; + int len, dc; + size_t sz; + wchar_t c; - for (n = 0; (c = *s) != '\0'; ++s, ++n) - if (isprint(c)) - putchar(c); - else - putchar('?'); - return n; + p = s; + dc = len = strlen(s); + ri = r = (char *)malloc(len + 1); + while (dc) { + sz = mbtowc(&c, p, dc); + if (sz < 0) { + p++; + dc--; + *ri++ = '?'; + } else { + dc -= sz; + if (isprint(c)) { + while(sz--) + *ri++ = *p++; + } else { + p += sz; + while(sz--) + *ri++ = '?'; + } + } + } + *ri = 0; + printf("%s", r); + free(r); + return len; } /* -- end -- To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message