Fossil SCM
If a @-line for a string literal ends with "\" then omit the newline.
Commit
09d882ee819572a0f62a09e6daeef7e713280126f8d7c5a3939bfee9195b3706
Parent
cc846d4bcd880f4…
1 file changed
+19
-3
+19
-3
| --- src/translate.c | ||
| +++ src/translate.c | ||
| @@ -74,10 +74,15 @@ | ||
| 74 | 74 | /* |
| 75 | 75 | ** True if we are currently doing a free string |
| 76 | 76 | */ |
| 77 | 77 | static int inStr = 0; |
| 78 | 78 | |
| 79 | +/* | |
| 80 | +** Name of files being processed | |
| 81 | +*/ | |
| 82 | +static const char *zInFile = "(stdin)"; | |
| 83 | + | |
| 79 | 84 | /* |
| 80 | 85 | ** Terminate an active cgi_printf() or free string |
| 81 | 86 | */ |
| 82 | 87 | static void end_block(FILE *out){ |
| 83 | 88 | if( inPrint ){ |
| @@ -94,15 +99,17 @@ | ||
| 94 | 99 | static void trans(FILE *in, FILE *out){ |
| 95 | 100 | int i, j, k; /* Loop counters */ |
| 96 | 101 | char c1, c2; /* Characters used to start a comment */ |
| 97 | 102 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 98 | 103 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 104 | + int lineNo = 0; /* Line number */ | |
| 99 | 105 | char zLine[2000]; /* A single line of input */ |
| 100 | 106 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 101 | 107 | |
| 102 | 108 | c1 = c2 = '-'; |
| 103 | 109 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 110 | + lineNo++; | |
| 104 | 111 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 105 | 112 | if( zLine[i]!='@' ){ |
| 106 | 113 | if( inPrint || inStr ) end_block(out); |
| 107 | 114 | fprintf(out,"%s",zLine); |
| 108 | 115 | /* 0123456789 12345 */ |
| @@ -120,28 +127,36 @@ | ||
| 120 | 127 | ** generate a string literal. But skip comments |
| 121 | 128 | ** consisting of all text between c1 and c2 (default "--") |
| 122 | 129 | ** and end of line. |
| 123 | 130 | */ |
| 124 | 131 | int indent, omitline; |
| 132 | + char *zNewline = "\\n"; | |
| 125 | 133 | i++; |
| 126 | 134 | if( isspace(zLine[i]) ){ i++; } |
| 127 | 135 | indent = i - 2; |
| 128 | 136 | if( indent<0 ) indent = 0; |
| 129 | 137 | omitline = 0; |
| 130 | 138 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 131 | 139 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 132 | 140 | omitline = 1; break; |
| 133 | 141 | } |
| 134 | - if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } | |
| 142 | + if( zLine[i]=='\\' && (zLine[i+1]==0 || zLine[i+1]=='\r' | |
| 143 | + || zLine[i+1]=='\n') ){ | |
| 144 | + zLine[i] = 0; | |
| 145 | + zNewline = ""; | |
| 146 | + /* fprintf(stderr, "%s:%d: omit newline\n", zInFile, lineNo); */ | |
| 147 | + break; | |
| 148 | + } | |
| 149 | + if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; } | |
| 135 | 150 | zOut[j++] = zLine[i]; |
| 136 | 151 | } |
| 137 | - while( j>0 && isspace(zOut[j-1]) ){ j--; } | |
| 152 | + if( zNewline[0] ) while( j>0 && isspace(zOut[j-1]) ){ j--; } | |
| 138 | 153 | zOut[j] = 0; |
| 139 | 154 | if( j<=0 && omitline ){ |
| 140 | 155 | fprintf(out,"\n"); |
| 141 | 156 | }else{ |
| 142 | - fprintf(out,"%*s\"%s\\n\"\n",indent, "", zOut); | |
| 157 | + fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline); | |
| 143 | 158 | } |
| 144 | 159 | }else{ |
| 145 | 160 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 146 | 161 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 147 | 162 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| @@ -197,10 +212,11 @@ | ||
| 197 | 212 | FILE *in = fopen(argv[1], "r"); |
| 198 | 213 | if( in==0 ){ |
| 199 | 214 | fprintf(stderr,"can not open %s\n", argv[1]); |
| 200 | 215 | exit(1); |
| 201 | 216 | } |
| 217 | + zInFile = argv[1]; | |
| 202 | 218 | printf("#line 1 \""); |
| 203 | 219 | for(arg=argv[1]; *arg; arg++){ |
| 204 | 220 | if( *arg!='\\' ){ |
| 205 | 221 | printf("%c", *arg); |
| 206 | 222 | }else{ |
| 207 | 223 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -74,10 +74,15 @@ | |
| 74 | /* |
| 75 | ** True if we are currently doing a free string |
| 76 | */ |
| 77 | static int inStr = 0; |
| 78 | |
| 79 | /* |
| 80 | ** Terminate an active cgi_printf() or free string |
| 81 | */ |
| 82 | static void end_block(FILE *out){ |
| 83 | if( inPrint ){ |
| @@ -94,15 +99,17 @@ | |
| 94 | static void trans(FILE *in, FILE *out){ |
| 95 | int i, j, k; /* Loop counters */ |
| 96 | char c1, c2; /* Characters used to start a comment */ |
| 97 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 98 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 99 | char zLine[2000]; /* A single line of input */ |
| 100 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 101 | |
| 102 | c1 = c2 = '-'; |
| 103 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 104 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 105 | if( zLine[i]!='@' ){ |
| 106 | if( inPrint || inStr ) end_block(out); |
| 107 | fprintf(out,"%s",zLine); |
| 108 | /* 0123456789 12345 */ |
| @@ -120,28 +127,36 @@ | |
| 120 | ** generate a string literal. But skip comments |
| 121 | ** consisting of all text between c1 and c2 (default "--") |
| 122 | ** and end of line. |
| 123 | */ |
| 124 | int indent, omitline; |
| 125 | i++; |
| 126 | if( isspace(zLine[i]) ){ i++; } |
| 127 | indent = i - 2; |
| 128 | if( indent<0 ) indent = 0; |
| 129 | omitline = 0; |
| 130 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 131 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 132 | omitline = 1; break; |
| 133 | } |
| 134 | if( zLine[i]=='"' || zLine[i]=='\\' ){ zOut[j++] = '\\'; } |
| 135 | zOut[j++] = zLine[i]; |
| 136 | } |
| 137 | while( j>0 && isspace(zOut[j-1]) ){ j--; } |
| 138 | zOut[j] = 0; |
| 139 | if( j<=0 && omitline ){ |
| 140 | fprintf(out,"\n"); |
| 141 | }else{ |
| 142 | fprintf(out,"%*s\"%s\\n\"\n",indent, "", zOut); |
| 143 | } |
| 144 | }else{ |
| 145 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 146 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 147 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| @@ -197,10 +212,11 @@ | |
| 197 | FILE *in = fopen(argv[1], "r"); |
| 198 | if( in==0 ){ |
| 199 | fprintf(stderr,"can not open %s\n", argv[1]); |
| 200 | exit(1); |
| 201 | } |
| 202 | printf("#line 1 \""); |
| 203 | for(arg=argv[1]; *arg; arg++){ |
| 204 | if( *arg!='\\' ){ |
| 205 | printf("%c", *arg); |
| 206 | }else{ |
| 207 |
| --- src/translate.c | |
| +++ src/translate.c | |
| @@ -74,10 +74,15 @@ | |
| 74 | /* |
| 75 | ** True if we are currently doing a free string |
| 76 | */ |
| 77 | static int inStr = 0; |
| 78 | |
| 79 | /* |
| 80 | ** Name of files being processed |
| 81 | */ |
| 82 | static const char *zInFile = "(stdin)"; |
| 83 | |
| 84 | /* |
| 85 | ** Terminate an active cgi_printf() or free string |
| 86 | */ |
| 87 | static void end_block(FILE *out){ |
| 88 | if( inPrint ){ |
| @@ -94,15 +99,17 @@ | |
| 99 | static void trans(FILE *in, FILE *out){ |
| 100 | int i, j, k; /* Loop counters */ |
| 101 | char c1, c2; /* Characters used to start a comment */ |
| 102 | int lastWasEq = 0; /* True if last non-whitespace character was "=" */ |
| 103 | int lastWasComma = 0; /* True if last non-whitespace character was "," */ |
| 104 | int lineNo = 0; /* Line number */ |
| 105 | char zLine[2000]; /* A single line of input */ |
| 106 | char zOut[4000]; /* The input line translated into appropriate output */ |
| 107 | |
| 108 | c1 = c2 = '-'; |
| 109 | while( fgets(zLine, sizeof(zLine), in) ){ |
| 110 | lineNo++; |
| 111 | for(i=0; zLine[i] && isspace(zLine[i]); i++){} |
| 112 | if( zLine[i]!='@' ){ |
| 113 | if( inPrint || inStr ) end_block(out); |
| 114 | fprintf(out,"%s",zLine); |
| 115 | /* 0123456789 12345 */ |
| @@ -120,28 +127,36 @@ | |
| 127 | ** generate a string literal. But skip comments |
| 128 | ** consisting of all text between c1 and c2 (default "--") |
| 129 | ** and end of line. |
| 130 | */ |
| 131 | int indent, omitline; |
| 132 | char *zNewline = "\\n"; |
| 133 | i++; |
| 134 | if( isspace(zLine[i]) ){ i++; } |
| 135 | indent = i - 2; |
| 136 | if( indent<0 ) indent = 0; |
| 137 | omitline = 0; |
| 138 | for(j=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){ |
| 139 | if( zLine[i]==c1 && (c2==' ' || zLine[i+1]==c2) ){ |
| 140 | omitline = 1; break; |
| 141 | } |
| 142 | if( zLine[i]=='\\' && (zLine[i+1]==0 || zLine[i+1]=='\r' |
| 143 | || zLine[i+1]=='\n') ){ |
| 144 | zLine[i] = 0; |
| 145 | zNewline = ""; |
| 146 | /* fprintf(stderr, "%s:%d: omit newline\n", zInFile, lineNo); */ |
| 147 | break; |
| 148 | } |
| 149 | if( zLine[i]=='\\' || zLine[i]=='"' ){ zOut[j++] = '\\'; } |
| 150 | zOut[j++] = zLine[i]; |
| 151 | } |
| 152 | if( zNewline[0] ) while( j>0 && isspace(zOut[j-1]) ){ j--; } |
| 153 | zOut[j] = 0; |
| 154 | if( j<=0 && omitline ){ |
| 155 | fprintf(out,"\n"); |
| 156 | }else{ |
| 157 | fprintf(out,"%*s\"%s%s\"\n",indent, "", zOut, zNewline); |
| 158 | } |
| 159 | }else{ |
| 160 | /* Otherwise (if the last non-whitespace was not '=') then generate |
| 161 | ** a cgi_printf() statement whose format is the text following the '@'. |
| 162 | ** Substrings of the form "%C(...)" (where C is any sequence of |
| @@ -197,10 +212,11 @@ | |
| 212 | FILE *in = fopen(argv[1], "r"); |
| 213 | if( in==0 ){ |
| 214 | fprintf(stderr,"can not open %s\n", argv[1]); |
| 215 | exit(1); |
| 216 | } |
| 217 | zInFile = argv[1]; |
| 218 | printf("#line 1 \""); |
| 219 | for(arg=argv[1]; *arg; arg++){ |
| 220 | if( *arg!='\\' ){ |
| 221 | printf("%c", *arg); |
| 222 | }else{ |
| 223 |