comparison mm7text_ru.cpp @ 1572:19f1735fca80

Слияние
author Ritor1
date Sun, 08 Sep 2013 17:07:58 +0600
parents c4ab816fcc5e
children d28d3c006077
comparison
equal deleted inserted replaced
1571:ef20d4608b1a 1572:19f1735fca80
3 #endif 3 #endif
4 4
5 #include <string.h> 5 #include <string.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <assert.h>
9 8
10 #include "Log.h" 9 #include "Log.h"
10 #include "ErrorHandling.h"
11 11
12 12
13 struct GenderTableEntry 13 struct GenderTableEntry
14 { 14 {
15 const char *name; 15 const char *name;
1159 } 1159 }
1160 1160
1161 return nullptr; 1161 return nullptr;
1162 } 1162 }
1163 1163
1164 int sprintfex_internal(char *str) 1164 int sprintfex_internal(char *str)
1165 { 1165 {
1166 auto p = strstr(str, "^"); 1166 auto p = strstr(str, "^");
1167 if (!p) 1167 if (!p)
1168 return strlen(str); 1168 return strlen(str);
1169 1169
1170 char buf[8192]; 1170 char buf[8192];
1171 assert(strlen(str) < sizeof(buf)); 1171 Assert(strlen(str) < sizeof(buf));
1172 1172
1173 int next_integer_token = 0; 1173 int next_integer_token = 0;
1174 bool integer_tokens_defined[10] = {false, false, false, false, false, false, false, false, false, false}; 1174 bool integer_tokens_defined[10] = {false, false, false, false, false, false, false, false, false, false};
1175 int integer_tokens[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 1175 int integer_tokens[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1176 1176
1188 { 1188 {
1189 if (src[2] != '[') 1189 if (src[2] != '[')
1190 goto _invalid_token; 1190 goto _invalid_token;
1191 src += 3; // ^I[ 1191 src += 3; // ^I[
1192 1192
1193 assert(next_integer_token < 10); 1193 Assert(next_integer_token < 10);
1194 if (sscanf(src, "%d", &integer_tokens[next_integer_token])) 1194 if (sscanf(src, "%d", &integer_tokens[next_integer_token]))
1195 integer_tokens_defined[next_integer_token++] = true; 1195 integer_tokens_defined[next_integer_token++] = true;
1196 1196
1197 auto int_begin = src; 1197 auto int_begin = src;
1198 while (*src++ != ']'); 1198 while (*src++ != ']');
1215 src += 1; 1215 src += 1;
1216 } 1216 }
1217 else if (src[2] != '[') 1217 else if (src[2] != '[')
1218 goto _invalid_token; 1218 goto _invalid_token;
1219 1219
1220 assert(integer_tokens_defined[integer_token_idx]); 1220 Assert(integer_tokens_defined[integer_token_idx]);
1221 src += 3; // ^L[ 1221 src += 3; // ^L[
1222 1222
1223 auto ending1 = src; 1223 auto ending1 = src;
1224 while (*src++ != ';'); 1224 while (*src++ != ';');
1225 auto ending2 = src; 1225 auto ending2 = src;
1254 1254
1255 case 'R': 1255 case 'R':
1256 { 1256 {
1257 if (src[2] != '[') 1257 if (src[2] != '[')
1258 goto _invalid_token; 1258 goto _invalid_token;
1259 assert(gender_token_defined); 1259 Assert(gender_token_defined);
1260 1260
1261 src += 3; // ^R[ 1261 src += 3; // ^R[
1262 1262
1263 auto ending1 = src; 1263 auto ending1 = src;
1264 while (*src++ != ';'); 1264 while (*src++ != ';');
1283 else if (gender_token == 2) 1283 else if (gender_token == 2)
1284 { 1284 {
1285 actual_ending = ending3; 1285 actual_ending = ending3;
1286 actual_ending_len = src - ending3 - 1; 1286 actual_ending_len = src - ending3 - 1;
1287 } 1287 }
1288 else assert(false); 1288 else Error("Invalid gender token");
1289 1289
1290 strncpy(dst, actual_ending, actual_ending_len); 1290 strncpy(dst, actual_ending, actual_ending_len);
1291 dst += actual_ending_len; 1291 dst += actual_ending_len;
1292 } 1292 }
1293 break; 1293 break;
1365 int token_len = src - token_begin; 1365 int token_len = src - token_begin;
1366 char token[1024]; 1366 char token[1024];
1367 strncpy(token, token_begin, token_len); 1367 strncpy(token, token_begin, token_len);
1368 token[token_len] = 0; 1368 token[token_len] = 0;
1369 1369
1370 Log::Warning(L"Invalid format token: %S", token); 1370 Error("Invalid format token: %s", token);
1371 assert(false);
1372 } 1371 }
1373 break; 1372 break;
1374 } 1373 }
1375 1374
1376 *dst = 0; 1375 *dst = 0;