Revision: 3255 Author: lewis Date: 2015-02-12 19:00:34 -0800 (Thu, 12 Feb 2015) Log Message: ----------- squeak -help says that the default encoding for external text is UTF-8, make it so. Modified Paths: -------------- trunk/platforms/unix/vm/sqUnixMain.c Modified: trunk/platforms/unix/vm/sqUnixMain.c =================================================================== --- trunk/platforms/unix/vm/sqUnixMain.c 2015-02-12 19:20:06 UTC (rev 3254) +++ trunk/platforms/unix/vm/sqUnixMain.c 2015-02-13 03:00:34 UTC (rev 3255) @@ -99,7 +99,7 @@ int uxDropFileCount= 0; /* number of dropped items */ char **uxDropFileNames= 0; /* dropped filenames */ - int textEncodingUTF8= 0; /* 1 if copy from external selection uses UTF8 */ + int textEncodingUTF8= 1; /* 1 if copy from external selection uses UTF8 */ #if defined(IMAGE_DUMP) static int dumpImageFile= 0; /* 1 after SIGHUP received */ @@ -1082,10 +1082,11 @@ len= strlen(buf); for (i= 0; i < len; ++i) buf[i]= toupper(buf[i]); - if ((!strcmp(buf, "UTF8")) || (!strcmp(buf, "UTF-8"))) - textEncodingUTF8= 1; - else - setEncoding(&uxTextEncoding, buf); + if (strcmp(buf, "UTF8") && strcmp(buf, "UTF-8")) + { + textEncodingUTF8= 0; + setEncoding(&uxTextEncoding, buf); + } free(buf); return 2; } |
> On 13 Feb 2015, at 4:00 , [hidden email] wrote: > > > Revision: 3255 > Author: lewis > Date: 2015-02-12 19:00:34 -0800 (Thu, 12 Feb 2015) > Log Message: > ----------- > squeak -help says that the default encoding for external text is UTF-8, make it so. > > Modified Paths: > -------------- > trunk/platforms/unix/vm/sqUnixMain.c > > Modified: trunk/platforms/unix/vm/sqUnixMain.c > =================================================================== > --- trunk/platforms/unix/vm/sqUnixMain.c 2015-02-12 19:20:06 UTC (rev 3254) > +++ trunk/platforms/unix/vm/sqUnixMain.c 2015-02-13 03:00:34 UTC (rev 3255) > @@ -99,7 +99,7 @@ > int uxDropFileCount= 0; /* number of dropped items */ > char **uxDropFileNames= 0; /* dropped filenames */ > > - int textEncodingUTF8= 0; /* 1 if copy from external selection uses UTF8 */ > + int textEncodingUTF8= 1; /* 1 if copy from external selection uses UTF8 */ > > #if defined(IMAGE_DUMP) > static int dumpImageFile= 0; /* 1 after SIGHUP received */ > @@ -1082,10 +1082,11 @@ > len= strlen(buf); > for (i= 0; i < len; ++i) > buf[i]= toupper(buf[i]); > - if ((!strcmp(buf, "UTF8")) || (!strcmp(buf, "UTF-8"))) > - textEncodingUTF8= 1; > - else > - setEncoding(&uxTextEncoding, buf); > + if (strcmp(buf, "UTF8") && strcmp(buf, "UTF-8")) > + { > + textEncodingUTF8= 0; > + setEncoding(&uxTextEncoding, buf); > + } > free(buf); > return 2; > } > Wait, wat? They way I read that, it says, "If buf is both "UTF8" and "UTF-8", set the text encoding to not be utf8"? I don't get how the initial version could work either (the if/else blocks look reversed, for my interpretation "if buf is neither UTF8 nor UTF-8"... ), but does anyone fluent in C have time to explain to me how the new version works / how I'm reading wrong? Cheers, Henry |
strcmp answers zero if the strings are the same. zero, interpreted as a boolean, is false. so, !strcmp() means that the strings are equal. kind regards wolfgang > Am 13.02.2015 um 14:02 schrieb Henrik Johansen <[hidden email]>: > > > >> On 13 Feb 2015, at 4:00 , [hidden email] wrote: >> >> >> Revision: 3255 >> Author: lewis >> Date: 2015-02-12 19:00:34 -0800 (Thu, 12 Feb 2015) >> Log Message: >> ----------- >> squeak -help says that the default encoding for external text is UTF-8, make it so. >> >> Modified Paths: >> -------------- >> trunk/platforms/unix/vm/sqUnixMain.c >> >> Modified: trunk/platforms/unix/vm/sqUnixMain.c >> =================================================================== >> --- trunk/platforms/unix/vm/sqUnixMain.c 2015-02-12 19:20:06 UTC (rev 3254) >> +++ trunk/platforms/unix/vm/sqUnixMain.c 2015-02-13 03:00:34 UTC (rev 3255) >> @@ -99,7 +99,7 @@ >> int uxDropFileCount= 0; /* number of dropped items */ >> char **uxDropFileNames= 0; /* dropped filenames */ >> >> - int textEncodingUTF8= 0; /* 1 if copy from external selection uses UTF8 */ >> + int textEncodingUTF8= 1; /* 1 if copy from external selection uses UTF8 */ >> >> #if defined(IMAGE_DUMP) >> static int dumpImageFile= 0; /* 1 after SIGHUP received */ >> @@ -1082,10 +1082,11 @@ >> len= strlen(buf); >> for (i= 0; i < len; ++i) >> buf[i]= toupper(buf[i]); >> - if ((!strcmp(buf, "UTF8")) || (!strcmp(buf, "UTF-8"))) >> - textEncodingUTF8= 1; >> - else >> - setEncoding(&uxTextEncoding, buf); >> + if (strcmp(buf, "UTF8") && strcmp(buf, "UTF-8")) >> + { >> + textEncodingUTF8= 0; >> + setEncoding(&uxTextEncoding, buf); >> + } >> free(buf); >> return 2; >> } >> > > Wait, wat? > They way I read that, it says, "If buf is both "UTF8" and "UTF-8", set the text encoding to not be utf8"? > I don't get how the initial version could work either (the if/else blocks look reversed, for my interpretation "if buf is neither UTF8 nor UTF-8"... ), but does anyone fluent in C have time to explain to me how the new version works / how I'm reading wrong? > > Cheers, > Henry smime.p7s (5K) Download Attachment |
Strange but true ;-). The reason is that strcmp answers a - b fir the first difference in the string. In which case it should have been called strdiff. Ugh... Eliot (phone) On Feb 13, 2015, at 5:13 AM, Wolfgang Eder <[hidden email]> wrote: > strcmp answers zero if the strings are the same. > zero, interpreted as a boolean, is false. > so, !strcmp() means that the strings are equal. > kind regards wolfgang > >> Am 13.02.2015 um 14:02 schrieb Henrik Johansen <[hidden email]>: >> >> >> >>> On 13 Feb 2015, at 4:00 , [hidden email] wrote: >>> >>> >>> Revision: 3255 >>> Author: lewis >>> Date: 2015-02-12 19:00:34 -0800 (Thu, 12 Feb 2015) >>> Log Message: >>> ----------- >>> squeak -help says that the default encoding for external text is UTF-8, make it so. >>> >>> Modified Paths: >>> -------------- >>> trunk/platforms/unix/vm/sqUnixMain.c >>> >>> Modified: trunk/platforms/unix/vm/sqUnixMain.c >>> =================================================================== >>> --- trunk/platforms/unix/vm/sqUnixMain.c 2015-02-12 19:20:06 UTC (rev 3254) >>> +++ trunk/platforms/unix/vm/sqUnixMain.c 2015-02-13 03:00:34 UTC (rev 3255) >>> @@ -99,7 +99,7 @@ >>> int uxDropFileCount= 0; /* number of dropped items */ >>> char **uxDropFileNames= 0; /* dropped filenames */ >>> >>> - int textEncodingUTF8= 0; /* 1 if copy from external selection uses UTF8 */ >>> + int textEncodingUTF8= 1; /* 1 if copy from external selection uses UTF8 */ >>> >>> #if defined(IMAGE_DUMP) >>> static int dumpImageFile= 0; /* 1 after SIGHUP received */ >>> @@ -1082,10 +1082,11 @@ >>> len= strlen(buf); >>> for (i= 0; i < len; ++i) >>> buf[i]= toupper(buf[i]); >>> - if ((!strcmp(buf, "UTF8")) || (!strcmp(buf, "UTF-8"))) >>> - textEncodingUTF8= 1; >>> - else >>> - setEncoding(&uxTextEncoding, buf); >>> + if (strcmp(buf, "UTF8") && strcmp(buf, "UTF-8")) >>> + { >>> + textEncodingUTF8= 0; >>> + setEncoding(&uxTextEncoding, buf); >>> + } >>> free(buf); >>> return 2; >>> } >> >> Wait, wat? >> They way I read that, it says, "If buf is both "UTF8" and "UTF-8", set the text encoding to not be utf8"? >> I don't get how the initial version could work either (the if/else blocks look reversed, for my interpretation "if buf is neither UTF8 nor UTF-8"... ), but does anyone fluent in C have time to explain to me how the new version works / how I'm reading wrong? >> >> Cheers, >> Henry > |
Free forum by Nabble | Edit this page |