Skip to content

Commit 6df7f49

Browse files
committed
fixing new numerics
1 parent 5622b4b commit 6df7f49

File tree

12 files changed

+62
-32
lines changed

12 files changed

+62
-32
lines changed

BINARIES/ChatScriptmongo.exe

512 Bytes
Binary file not shown.

BINARIES/LinuxChatScript64

335 Bytes
Binary file not shown.

BINARIES/chatscript.exe

0 Bytes
Binary file not shown.

BINARIES/chatscriptpg.exe

512 Bytes
Binary file not shown.

SRC/mainSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "common.h"
22
#include "evserver.h"
3-
char* version = "7.41";
3+
char* version = "7.411";
44
char sourceInput[200];
55
FILE* userInitFile;
66
int externalTagger = 0;

SRC/outputSystem.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -381,28 +381,39 @@ void StdNumber(char* word,char*& buffer,int controls) // text numbers may have s
381381
return;
382382
}
383383

384-
if (IsFloat(word,word+len))
384+
// capture any percentage symbol
385+
char* end = word + len;
386+
bool percent = false;
387+
if (*(end - 1) == '%')
388+
{
389+
*--end = 0;
390+
percent = true;
391+
}
392+
393+
int useNumberStyle = numberStyle;
394+
if (controls & OUTPUT_NOCOMMANUMBER) useNumberStyle = NOSTYLE_NUMBERS;
395+
396+
if (IsFloat(word,end))
385397
{
386398
if (!fullfloat) // insure is not full
387399
{
388400
char c = word[len];
389401
word[len] = 0;
390-
WriteFloat(buffer, atof(word));
402+
WriteFloat(buffer, atof(word), useNumberStyle);
391403
word[len] = c;
392404
}
393-
else strcpy(buffer, word); // is best we can get
394-
return;
405+
else // write out what we have, don't redo the formatting
406+
{
407+
FormatFloat(word, buffer, useNumberStyle);
408+
}
395409
}
396-
397-
if (controls & OUTPUT_NOCOMMANUMBER) // no comma with <= 4 digit, e.g., year numbers
398-
{
399-
strcpy(buffer,word);
400-
return;
401-
}
402-
403-
// add commas between number triples
404-
// except india uses doubles until final triple
405-
WriteInteger(word, buffer);
410+
else
411+
{
412+
// add commas between number triples, unless not needed
413+
// except india uses doubles until final triple
414+
WriteInteger(word, buffer, useNumberStyle);
415+
}
416+
if (percent) strcat(buffer, "%");
406417
}
407418

408419
char* StdIntOutput(int n)

SRC/patternSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ bool Match(char* buffer,char* ptr, unsigned int depth, int startposition, char*
309309
unsigned int startNest = functionNest;
310310
int wildcardBase = wildcardIndex;
311311
unsigned int result;
312+
int bidirectional = 0;
312313
WORDP D;
313314
unsigned int oldtrace = trace;
314315
int beginmatch = -1; // for ( ) where did we actually start matching

SRC/textUtilities.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,13 @@ bool IsPlaceNumber(char* word) // place number and fraction numbers
12051205
return IsNumber(num,false) ? true : false; // show it is correctly a number - pass false to avoid recursion from IsNumber
12061206
}
12071207

1208-
void WriteInteger(char* word, char* buffer)
1208+
void WriteInteger(char* word, char* buffer, int useNumberStyle)
12091209
{
1210+
if (useNumberStyle == NOSTYLE_NUMBERS)
1211+
{
1212+
strcpy(buffer, word);
1213+
return;
1214+
}
12101215
char reverseFill[MAX_WORD_SIZE];
12111216
char* end = word + strlen(word);
12121217
char* at = reverseFill + 500;
@@ -1216,17 +1221,31 @@ void WriteInteger(char* word, char* buffer)
12161221
while (end != word)
12171222
{
12181223
*--at = *--end;
1219-
if (IsDigit(*at) && ++counter == limit)
1224+
if (IsDigit(*at) && ++counter == limit && end != word)
12201225
{
1221-
*--at = (numberStyle == FRENCH_NUMBERS) ? '.' : ',';
1226+
*--at = (useNumberStyle == FRENCH_NUMBERS) ? '.' : ',';
12221227
counter = 0;
1223-
limit = (numberStyle == INDIAN_NUMBERS) ? 2 : 3;
1228+
limit = (useNumberStyle == INDIAN_NUMBERS) ? 2 : 3;
12241229
}
12251230
}
12261231
strcpy(buffer, at);
12271232
}
12281233

1229-
char* WriteFloat(char* buffer, double value)
1234+
void FormatFloat(char* word, char* buffer, int useNumberStyle)
1235+
{
1236+
char* dot = strchr(word, '.');
1237+
if (dot) *dot = 0;
1238+
WriteInteger(word, buffer, useNumberStyle); // leading float/int bit
1239+
1240+
// Localise the decimal point
1241+
if (dot)
1242+
{
1243+
*dot = (useNumberStyle == FRENCH_NUMBERS) ? ',' : '.';
1244+
strcat(buffer, dot);
1245+
}
1246+
}
1247+
1248+
char* WriteFloat(char* buffer, double value, int useNumberStyle)
12301249
{
12311250
char floatpart[MAX_WORD_SIZE];
12321251
if (!fullfloat)
@@ -1245,14 +1264,7 @@ char* WriteFloat(char* buffer, double value)
12451264
}
12461265
else sprintf(floatpart, (char*)"%1.50g", value);
12471266

1248-
char* dot = strchr(floatpart, '.');
1249-
if (dot) *dot = 0;
1250-
char head[MAX_WORD_SIZE];
1251-
WriteInteger(floatpart, head); // leading float/int bit
1252-
1253-
strcpy(buffer, head);
1254-
if (dot && numberStyle == FRENCH_NUMBERS) *dot = ',';
1255-
if (dot) strcat(buffer, dot);
1267+
FormatFloat(floatpart, buffer, useNumberStyle);
12561268
return buffer;
12571269
}
12581270

SRC/textUtilities.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4141
#define VALIDLOWER 4
4242
#define VALIDUTF8 6
4343

44+
#define NOSTYLE_NUMBERS -1
4445
#define AMERICAN_NUMBERS 0
4546
#define INDIAN_NUMBERS 1
4647
#define FRENCH_NUMBERS 2
@@ -140,7 +141,7 @@ bool IsModelNumber(char* word);
140141
bool IsInteger(char* ptr, bool comma);
141142
char* IsUTF8(char* buffer,char* character);
142143
char* Purify(char* msg);
143-
void WriteInteger(char* word, char* buffer);
144+
void WriteInteger(char* word, char* buffer, int useNumberStyle = NOSTYLE_NUMBERS);
144145
void BOMAccess(int &BOMvalue, char &oldc, int &oldCurrentLine);
145146
size_t OutputLimit(unsigned char* data);
146147
extern int startSentence;
@@ -161,7 +162,7 @@ char GetTemperatureLetter (char* ptr);
161162
bool IsLegalName(char* name);
162163
unsigned char* GetCurrency(unsigned char* ptr,char* &number);
163164
bool IsRomanNumeral(char* word, uint64& val);
164-
char* WriteFloat(char* buffer, double value);
165+
char* WriteFloat(char* buffer, double value, int useNumberStyle = NOSTYLE_NUMBERS);
165166

166167
// conversion reoutines
167168
void MakeLowerCase(char* ptr);
@@ -176,6 +177,7 @@ char* TrimSpaces(char* msg,bool start = true);
176177
char* UTF2ExtendedAscii(char* bufferfrom);
177178
void RemoveImpure(char* buffer);
178179
void ChangeSpecial(char* buffer);
180+
void FormatFloat(char* word, char* buffer, int useNumberStyle = NOSTYLE_NUMBERS);
179181

180182
// startup
181183
void InitTextUtilities();

SRC/variableSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ void SetUserVariable(const char* var, char* word, bool assignment)
453453
// cs_numbers changes are noticed by the engine (india, french, other)
454454
else if (!stricmp(var, (char*)"$cs_numbers"))
455455
{
456-
if (!stricmp(word, "indian")) numberStyle = INDIAN_NUMBERS;
456+
if (!word) numberStyle = AMERICAN_NUMBERS;
457+
else if (!stricmp(word, "indian")) numberStyle = INDIAN_NUMBERS;
457458
else if (!stricmp(word, "french")) numberStyle = FRENCH_NUMBERS;
458459
else numberStyle = AMERICAN_NUMBERS;
459460
}

0 commit comments

Comments
 (0)