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.

jan.nijtmans 2012-08-28 06:24 UTC trunk
Commit b5e2e50040aadecf59edce7b86588adfaf20ed79
1 file changed +31 -4
+31 -4
--- src/translate.c
+++ src/translate.c
@@ -1,7 +1,7 @@
11
/*
2
-** Copyright (c) 2002 D. Richard Hipp
2
+** Copyright © 2002 D. Richard Hipp
33
**
44
** This program is free software; you can redistribute it and/or
55
** modify it under the terms of the Simplified BSD License (also
66
** known as the "2-Clause License" or "FreeBSD License".)
77
@@ -76,17 +76,34 @@
7676
char c1, c2; /* Characters used to start a comment */
7777
int lastWasEq = 0; /* True if last non-whitespace character was "=" */
7878
int lastWasComma = 0; /* True if last non-whitespace character was "," */
7979
char zLine[2000]; /* A single line of input */
8080
char zOut[4000]; /* The input line translated into appropriate output */
81
+ int isFirstline = 1; /* True if this is the first line */
8182
8283
c1 = c2 = '-';
8384
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
+ }
8492
for(i=0; zLine[i] && isspace(zLine[i]); i++){}
8593
if( zLine[i]!='@' ){
8694
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);
88105
/* 0123456789 12345 */
89106
if( strncmp(zLine, "/* @-comment: ", 14)==0 ){
90107
c1 = zLine[14];
91108
c2 = zLine[15];
92109
}
@@ -110,11 +127,16 @@
110127
for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
111128
if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){
112129
omitline = 1; break;
113130
}
114131
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
+ }
116138
}
117139
while( j>0 && isspace(zOut[j-1]) ){ j--; }
118140
zOut[j] = 0;
119141
if( j<=0 && omitline ){
120142
fprintf(out,"\n");
@@ -134,11 +156,16 @@
134156
i++;
135157
if( isspace(zLine[i]) ){ i++; }
136158
indent = i;
137159
for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){
138160
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
+ }
140167
if( zLine[i]!='%' || zLine[i+1]=='%' || zLine[i+1]==0 ) continue;
141168
for(nC=1; zLine[i+nC] && zLine[i+nC]!='('; nC++){}
142169
if( zLine[i+nC]!='(' || !isalpha(zLine[i+nC-1]) ) continue;
143170
while( --nC ) zOut[j++] = zLine[++i];
144171
zArg[nArg++] = ',';
145172
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button