Fossil SCM
This change allows utf-8 characters (like → and •) in all c-sources to be replaced by its utf-8 equivalent. The translate utility will translate this to the right escape-sequence, so the C-compiler can handle it. As long as the C-source contains nu utf-8 characters, this generates exactly the same *_.c files as before.
Commit
b5e2e50040aadecf59edce7b86588adfaf20ed79
Parent
bf079432fb2ecc1…
1 file changed
+31
-4
+31
-4
| --- src/translate.c | ||
| +++ src/translate.c | ||
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /* |
| 2 | -** Copyright (c) 2002 D. Richard Hipp | |
| 2 | +** Copyright © 2002 D. Richard Hipp | |
| 3 | 3 | ** |
| 4 | 4 | ** This program is free software; you can redistribute it and/or |
| 5 | 5 | ** modify it under the terms of the Simplified BSD License (also |
| 6 | 6 | ** known as the "2-Clause License" or "FreeBSD License".) |
| 7 | 7 | |
| @@ -76,17 +76,34 @@ | ||
| 76 | 76 | char c1, c2; /* Characters used to start a comment */ |
| 77 | 77 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 78 | 78 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 79 | 79 | char zLine[2000]; /* A single line of input */ |
| 80 | 80 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 81 | + int isFirstline = 1; /* True if this is the first line */ | |
| 81 | 82 | |
| 82 | 83 | c1 = c2 = '-'; |
| 83 | 84 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 85 | + if (isFirstline) { | |
| 86 | + static const char bom[] = { 0xEF, 0xBB, 0xBF }; | |
| 87 | + if( memcmp(zLine, bom, 3)==0 ) { | |
| 88 | + memmove(zLine, zLine+3, sizeof(zLine)-3); | |
| 89 | + } | |
| 90 | + isFirstline = 0; | |
| 91 | + } | |
| 84 | 92 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 85 | 93 | if( zLine[i]!='@' ){ |
| 86 | 94 | if( inPrint || inStr ) end_block(out); |
| 87 | - fprintf(out,"%s",zLine); | |
| 95 | + for(j=0; zLine[i]; i++){ | |
| 96 | + if (128 <= (unsigned char)zLine[i]) { | |
| 97 | + sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); | |
| 98 | + j += 5; | |
| 99 | + } else { | |
| 100 | + zOut[j++] = zLine[i]; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + zOut[j] = 0; | |
| 104 | + fprintf(out,"%s",zOut); | |
| 88 | 105 | /* 0123456789 12345 */ |
| 89 | 106 | if( strncmp(zLine, "/* @-comment: ", 14)==0 ){ |
| 90 | 107 | c1 = zLine[14]; |
| 91 | 108 | c2 = zLine[15]; |
| 92 | 109 | } |
| @@ -110,11 +127,16 @@ | ||
| 110 | 127 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 111 | 128 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 112 | 129 | omitline = 1; break; |
| 113 | 130 | } |
| 114 | 131 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 115 | - zOut[j++] = zLine[i]; | |
| 132 | + if (128 <= (unsigned char)zLine[i]) { | |
| 133 | + sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); | |
| 134 | + j += 5; | |
| 135 | + } else { | |
| 136 | + zOut[j++] = zLine[i]; | |
| 137 | + } | |
| 116 | 138 | } |
| 117 | 139 | while( j>0 && isspace(zOut[j-1]) ){ j--; } |
| 118 | 140 | zOut[j] = 0; |
| 119 | 141 | if( j<=0 && omitline ){ |
| 120 | 142 | fprintf(out,"\n"); |
| @@ -134,11 +156,16 @@ | ||
| 134 | 156 | i++; |
| 135 | 157 | if( isspace(zLine[i]) ){ i++; } |
| 136 | 158 | indent = i; |
| 137 | 159 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 138 | 160 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 139 | - zOut[j++] = zLine[i]; | |
| 161 | + if (128 <= (unsigned char)zLine[i]) { | |
| 162 | + sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); | |
| 163 | + j += 5; | |
| 164 | + } else { | |
| 165 | + zOut[j++] = zLine[i]; | |
| 166 | + } | |
| 140 | 167 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 141 | 168 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 142 | 169 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| 143 | 170 | while( --nC ) zOut[j++] = zLine[++i]; |
| 144 | 171 | zArg[nArg++] = ','; |
| 145 | 172 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -1,7 +1,7 @@ | |
| 1 | /* |
| 2 | ** Copyright (c) 2002 D. Richard Hipp |
| 3 | ** |
| 4 | ** This program is free software; you can redistribute it and/or |
| 5 | ** modify it under the terms of the Simplified BSD License (also |
| 6 | ** known as the "2-Clause License" or "FreeBSD License".) |
| 7 | |
| @@ -76,17 +76,34 @@ | |
| 76 | char c1, c2; /* Characters used to start a comment */ |
| 77 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 78 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 79 | char zLine[2000]; /* A single line of input */ |
| 80 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 81 | |
| 82 | c1 = c2 = '-'; |
| 83 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 84 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 85 | if( zLine[i]!='@' ){ |
| 86 | if( inPrint || inStr ) end_block(out); |
| 87 | fprintf(out,"%s",zLine); |
| 88 | /* 0123456789 12345 */ |
| 89 | if( strncmp(zLine, "/* @-comment: ", 14)==0 ){ |
| 90 | c1 = zLine[14]; |
| 91 | c2 = zLine[15]; |
| 92 | } |
| @@ -110,11 +127,16 @@ | |
| 110 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 111 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 112 | omitline = 1; break; |
| 113 | } |
| 114 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 115 | zOut[j++] = zLine[i]; |
| 116 | } |
| 117 | while( j>0 && isspace(zOut[j-1]) ){ j--; } |
| 118 | zOut[j] = 0; |
| 119 | if( j<=0 && omitline ){ |
| 120 | fprintf(out,"\n"); |
| @@ -134,11 +156,16 @@ | |
| 134 | i++; |
| 135 | if( isspace(zLine[i]) ){ i++; } |
| 136 | indent = i; |
| 137 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 138 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 139 | zOut[j++] = zLine[i]; |
| 140 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 141 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 142 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| 143 | while( --nC ) zOut[j++] = zLine[++i]; |
| 144 | zArg[nArg++] = ','; |
| 145 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -1,7 +1,7 @@ | |
| 1 | /* |
| 2 | ** Copyright © 2002 D. Richard Hipp |
| 3 | ** |
| 4 | ** This program is free software; you can redistribute it and/or |
| 5 | ** modify it under the terms of the Simplified BSD License (also |
| 6 | ** known as the "2-Clause License" or "FreeBSD License".) |
| 7 | |
| @@ -76,17 +76,34 @@ | |
| 76 | char c1, c2; /* Characters used to start a comment */ |
| 77 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 78 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 79 | char zLine[2000]; /* A single line of input */ |
| 80 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 81 | int isFirstline = 1; /* True if this is the first line */ |
| 82 | |
| 83 | c1 = c2 = '-'; |
| 84 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 85 | if (isFirstline) { |
| 86 | static const char bom[] = { 0xEF, 0xBB, 0xBF }; |
| 87 | if( memcmp(zLine, bom, 3)==0 ) { |
| 88 | memmove(zLine, zLine+3, sizeof(zLine)-3); |
| 89 | } |
| 90 | isFirstline = 0; |
| 91 | } |
| 92 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 93 | if( zLine[i]!='@' ){ |
| 94 | if( inPrint || inStr ) end_block(out); |
| 95 | for(j=0; zLine[i]; i++){ |
| 96 | if (128 <= (unsigned char)zLine[i]) { |
| 97 | sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); |
| 98 | j += 5; |
| 99 | } else { |
| 100 | zOut[j++] = zLine[i]; |
| 101 | } |
| 102 | } |
| 103 | zOut[j] = 0; |
| 104 | fprintf(out,"%s",zOut); |
| 105 | /* 0123456789 12345 */ |
| 106 | if( strncmp(zLine, "/* @-comment: ", 14)==0 ){ |
| 107 | c1 = zLine[14]; |
| 108 | c2 = zLine[15]; |
| 109 | } |
| @@ -110,11 +127,16 @@ | |
| 127 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 128 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 129 | omitline = 1; break; |
| 130 | } |
| 131 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 132 | if (128 <= (unsigned char)zLine[i]) { |
| 133 | sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); |
| 134 | j += 5; |
| 135 | } else { |
| 136 | zOut[j++] = zLine[i]; |
| 137 | } |
| 138 | } |
| 139 | while( j>0 && isspace(zOut[j-1]) ){ j--; } |
| 140 | zOut[j] = 0; |
| 141 | if( j<=0 && omitline ){ |
| 142 | fprintf(out,"\n"); |
| @@ -134,11 +156,16 @@ | |
| 156 | i++; |
| 157 | if( isspace(zLine[i]) ){ i++; } |
| 158 | indent = i; |
| 159 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 160 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 161 | if (128 <= (unsigned char)zLine[i]) { |
| 162 | sprintf(&zOut[j], "\\0x%.2X", zLine[i] & 0xFF); |
| 163 | j += 5; |
| 164 | } else { |
| 165 | zOut[j++] = zLine[i]; |
| 166 | } |
| 167 | if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue; |
| 168 | for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){} |
| 169 | if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue; |
| 170 | while( --nC ) zOut[j++] = zLine[++i]; |
| 171 | zArg[nArg++] = ','; |
| 172 |