Skip to content

Commit b0af748

Browse files
committed
french revisions and other things
1 parent 89dba7e commit b0af748

15 files changed

+170
-100
lines changed

BINARIES/chatscript.exe

9 KB
Binary file not shown.

SRC/common1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern char* callArgumentList[MAX_ARGUMENT_COUNT+1]; // function callArgume
1010
extern unsigned int callArgumentBase;
1111

1212
#define ARGUMENT(n) callArgumentList[callArgumentBase+n]
13-
char* ReadCompiledWord(char* ptr, char* word,bool noquote = false,bool var = false);
13+
char* ReadCompiledWord(char* ptr, char* word,bool noquote = false,bool var = false,bool nolimit = false);
1414
char* ReadCompiledWordOrCall(char* ptr, char* word,bool noquote = false,bool var = false);
1515

1616
#define INPUT_BUFFER_SIZE 80000

SRC/evserver.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,22 @@ struct Client_t
106106
char* bot;
107107
char* message;
108108
char* user;
109-
char* data;
109+
char* data = NULL;
110110

111111
Client_t(int fd, struct ev_loop *l_p) : fd(fd), l(l_p), requestValid(false)
112112
{
113113
strcpy(this->magic, "deadbeef");
114114
ev_io_init(&this->ev_r, client_read, this->fd, EV_READ);
115115
ev_io_init(&this->ev_w, client_write, this->fd, EV_WRITE);
116-
this->data = NULL;
117-
this->ev_r.data = this;
116+
this->ev_r.data = this;
118117
this->ev_w.data = this;
119118
ev_io_start(this->l, &this->ev_r);
120119
}
121120

122-
~Client_t()
121+
~Client_t() // if child dies, this destructor is not called
123122
{
124-
if (this->data) free(this->data);
123+
if (this->data) free(this->data);
124+
this->data = NULL;
125125
if (ev_is_active(&this->ev_r)) ev_io_stop(this->l, &this->ev_r);
126126
if (ev_is_active(&this->ev_w)) ev_io_stop(this->l, &this->ev_w);
127127
close(this->fd);
@@ -186,7 +186,8 @@ struct Client_t
186186
}
187187

188188
Log(SERVERLOG, "evserver: send_data() could not send, errno: %s", strerror(errno));
189-
return -1;
189+
printf( "evserver: send_data() could not send, errno: %s", strerror(errno));
190+
return -1;
190191
}
191192

192193
if (r < (int)len)
@@ -209,7 +210,8 @@ struct Client_t
209210
if (this->ip.length() == 0)
210211
{
211212
Log(SERVERLOG, "evserver: prepare_for_chat() could not get ip for client: %d\r\n", this->fd);
212-
return -1;
213+
printf("evserver: prepare_for_chat() could not get ip for client: %d\r\n", this->fd);
214+
return -1;
213215
}
214216

215217
return 1;
@@ -258,12 +260,14 @@ static int setnonblocking(int fd)
258260
int flags = fcntl(fd, F_GETFL, 0);
259261
if (flags == -1) {
260262
Log(SERVERLOG, "evserver: setnonblocking() fcntl(F_GETFL) failed, errno: %s\r\n", strerror(errno));
261-
return -1;
263+
printf( "evserver: setnonblocking() fcntl(F_GETFL) failed, errno: %s\r\n", strerror(errno));
264+
return -1;
262265
}
263266
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
264267
{
265268
Log(SERVERLOG, "evserver: setnonblocking() fcntl(F_SETFL) failed, errno: %s\r\n", strerror(errno));
266-
return -1;
269+
printf( "evserver: setnonblocking() fcntl(F_SETFL) failed, errno: %s\r\n", strerror(errno));
270+
return -1;
267271
}
268272
return 1;
269273
}
@@ -277,7 +281,8 @@ int fork_child(ev_child *child_watcher = 0)
277281
pid = fork();
278282
if (pid < 0) {
279283
Log(SERVERLOG, "evserver: fork failed, errno %d\r\n", errno);
280-
return -1;
284+
printf( "evserver: fork failed, errno %d\r\n", errno);
285+
return -1;
281286
}
282287

283288
if (pid > 0) {
@@ -307,10 +312,21 @@ int fork_child(ev_child *child_watcher = 0)
307312
}
308313

309314
static void evsrv_child_died(EV_P_ ev_child *w, int revents) {
310-
Log(SERVERLOG, "evserver: evsrv_child_died [pid: %d]\r\n", w->pid);
311-
int r = fork_child(w);
312-
if (r < 0) Log(SERVERLOG, " evserver: could not re-spawn child after it died [pid: %d]\r\n", w->pid);
313-
else if (r == 1) Log(SERVERLOG, " evserver child: re-spawned [pid: %d]\r\n", getpid());
315+
Log(SERVERLOG, "evserver: evsrv_child_died [pid: %d]\r\n", w->pid);
316+
printf("evserver: evsrv_child_died [pid: %d]\r\n", w->pid);
317+
318+
int r = fork_child(w);
319+
if (r < 0)
320+
{
321+
Log(SERVERLOG, " evserver: could not re-spawn child after it died [pid: %d]\r\n", w->pid);
322+
printf(" evserver: could not re-spawn child after it died [pid: %d]\r\n", w->pid);
323+
}
324+
325+
else if (r == 1)
326+
{
327+
Log(SERVERLOG, " evserver child: re-spawned [pid: %d]\r\n", getpid());
328+
printf(" evserver child: re-spawned [pid: %d]\r\n", getpid());
329+
}
314330
}
315331
#endif
316332

@@ -453,6 +469,7 @@ int evsrv_init(const string &interfaceKind, int port, char* arg) {
453469
ev_io_init(&ev_accept_r_g, evsrv_accept, srv_socket_g, EV_READ);
454470
ev_io_start(l_g, &ev_accept_r_g);
455471
Log(SERVERLOG, " evserver: running pid: %d\r\n",getpid());
472+
printf( " evserver: running pid: %d\r\n", getpid());
456473

457474
return 1;
458475
}
@@ -541,6 +558,12 @@ static void client_read(EV_P_ ev_io *w, int revents)
541558
}
542559

543560
r = client->send_data();
561+
if (client->data)
562+
{
563+
free(client->data);
564+
client->data = NULL;
565+
}
566+
544567
if (r < 0) {
545568
Log(SERVERLOG, "evserver: could not sent data to client: %d\r\n", client->fd);
546569
delete client;
@@ -586,7 +609,8 @@ int evsrv_do_chat(Client_t *client)
586609
}
587610
#endif
588611
if (!client->data) client->data = (char*) malloc(outputsize);
589-
612+
if (!client->data) printf("Malloc failed for child data\r\n");
613+
590614
RESTART_RETRY:
591615
strcpy(ourMainInputBuffer,client->message);
592616
struct tm ptm;

SRC/factSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ bool GetSetMod(char* x)
227227

228228
char* GetSetType(char* x)
229229
{ // @13subject returns subject
230+
if (!x[0] || !x[1] ) return ""; // safety from bad data
230231
x += 2;
231232
if (IsDigit(*x)) ++x;
232233
return x;
@@ -1364,7 +1365,7 @@ char* ReadField(char* ptr,char* &field,char fieldkind, unsigned int& flags)
13641365
CopyRemoveEscapes(field,start,90000); // we only remove ones we added
13651366
return end+2; // point AFTER the space after the closer
13661367
}
1367-
else ptr = ReadCompiledWord(ptr,field); // no escaping or anything weird needed
1368+
else ptr = ReadCompiledWord(ptr,field,false,false,true); // no escaping or anything weird needed
13681369
if (field[0] == '~') MakeLowerCase(field); // all concepts/topics are lower case
13691370
return ptr; // return at new token
13701371
}

SRC/functionExecute.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ char* InvokeUser(char* &buffer,char* ptr, FunctionResult& result,WORDP D,unsigne
594594
if (id >= 0) val = AllocateStack(wildcardOriginalText[id],0,true);
595595
else val = AllocateStack("");
596596
}
597-
if (*val && *(val-2) != '`' && *(val-1) != '`')
598-
val = AllocateStack(val,0,true);
597+
else if (*val && *(val-1) != '`') val = AllocateStack(val,0,true);
599598
arg->w.userValue = val;
600599
}
601600
}
@@ -3850,11 +3849,9 @@ FunctionResult MatchCode(char* buffer)
38503849
ReadShortCommandArg(word1,word,result,OUTPUT_NOQUOTES);
38513850
if (result != NOPROBLEM_BIT) return result;
38523851
}
3853-
else
3854-
{
3855-
if (word1[0] == FUNCTIONSTRING && word1[1] == '(') strcpy(word,word1+1);
3856-
else strcpy(word,word1); // otherwise it is what to say (like from idiom table)
3857-
}
3852+
else if (word1[0] == FUNCTIONSTRING && word1[1] == '(') strcpy(word,word1+1);
3853+
else strcpy(word, ARGUMENT(1)); // otherwise it is what to say (like from idiom table)
3854+
38583855
WORDP X = FindWord(word);
38593856
if (*word == '~' && (!X || !(X->internalBits & (CONCEPT|TOPIC))) && strchr(word,'.')) // named an existing rule
38603857
{
@@ -5906,14 +5903,15 @@ static FunctionResult AddPropertyCode(char* buffer)
59065903
WORDP D = NULL;
59075904
int store = 0;
59085905
unsigned int count = 0;
5906+
char arg3 = 0;
59095907
if (*arg1 == '@') // add property to all facts in set either on a field or fact as a whole
59105908
{
59115909
store = GetSetID(arg1);
59125910
if (store == ILLEGAL_FACTSET) return FAILRULE_BIT;
59135911
count = FACTSET_COUNT(store);
5912+
arg3 = *GetSetType(arg1);
59145913
}
59155914
else D = StoreWord(arg1,0); // add property to dictionary word
5916-
char arg3 = *GetSetType(arg1);
59175915

59185916
uint64 val = 0;
59195917
uint64 sysval = 0;

SRC/json.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,15 @@ int factsJsonHelper(char *jsontext, jsmntok_t *tokens, int tokenlimit, int sizel
237237
}
238238
case JSMN_STRING: {
239239
char* limit;
240-
char* str = InfiniteStack(limit,"factsJsonHelper");
240+
char* str = InfiniteStack(limit,"factsJsonHelper string");
241241
strncpy(str,jsontext + curr.start,size);
242242
str[size] = 0;
243243
*flags = JSON_STRING_VALUE; // string null
244-
ReleaseInfiniteStack();
244+
CompleteBindStack();
245245
if (!PreallocateHeap(size)) return FAILRULE_BIT;
246246
if (size == 0) *retMeaning = MakeMeaning(StoreWord((char*)"null",AS_IS));
247247
else *retMeaning = MakeMeaning(StoreWord(str,AS_IS));
248+
ReleaseStack(str);
248249
break;
249250
}
250251
case JSMN_OBJECT: {
@@ -984,7 +985,7 @@ static char* jwritehierarchy(int depth, char* buffer, WORDP D, int subject, int
984985
size = (buffer - currentOutputBase + 400); // 400 slop to protect us
985986
if (size >= currentOutputLimit)
986987
{
987-
ReportBug((char*)"Json too much");
988+
ReportBug((char*)"Json too much %d items size %d", indexsize,size);
988989
ReleaseStack((char*)stack);
989990
return buffer; // too much output
990991
}

SRC/mainSystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,11 @@ void ProcessInputFile()
10881088
extraTopicData = NULL;
10891089
}
10901090
else turn = PerformChat(loginID, computerID, ourMainInputBuffer, NULL, ourMainOutputBuffer); // no ip
1091-
if (turn == PENDING_RESTART) Restart();
1091+
if (turn == PENDING_RESTART)
1092+
{
1093+
ourMainInputBuffer[0] = ourMainInputBuffer[1] = 0;
1094+
Restart();
1095+
}
10921096
}
10931097
if (sourceFile != stdin)
10941098
{

SRC/outputSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,10 @@ static char* Output_Backslash(char* word, char* ptr, char* space,char*& buffer,
606606
static char* ResetOutputPtr(char* start,char* buffer)
607607
{
608608
char* at = strrchr(start,'`'); // where it ended
609+
if (!at) return start;
609610
size_t len = strlen(at+1);
610611
memmove(start,at+1,len+1); // shift new data back to start
611-
if (start[len-1] == ' ') --len; // output ended with a space, remove it
612+
if (currentOutputBase != start && start[len-1] == ' ') --len; // output ended with a space, remove it
612613
start[len] = 0;
613614
return start + len; // resume back at original buffer location
614615
}

SRC/scriptCompile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ char* ReadSystemToken(char* ptr, char* word, bool separateUnderscore) // how w
385385
{
386386
*word = 0;
387387
if (!ptr) return 0;
388+
if (ptr[0] == '<' && ptr[1] == '<' && ptr[2] == '"')
389+
{
390+
int xx = 0;
391+
}
388392
char tmp[MAX_WORD_SIZE];
389393
char* start = word;
390394
ptr = SkipWhitespace(ptr);
@@ -668,6 +672,11 @@ char* ReadSystemToken(char* ptr, char* word, bool separateUnderscore) // how w
668672
word = start;
669673
size_t len = strlen(word);
670674
if (len == 0) return ptr;
675+
if (patternContext && word[len - 1] == '"' && word[len - 2] != '\\')
676+
{
677+
char* quote = strchr(word, '"');
678+
if (quote == word+len-1) BADSCRIPT("Tailing quote without start: %s", word)
679+
}
671680
if (*word == '#' && !strstr(readBuffer,"rename:")) // is this a constant from dictionary.h? or user constant
672681
{
673682
uint64 n;

SRC/spellcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ bool SpellCheckSentence()
616616
// dont spell check proper names to improper, if word before or after is lower case originally
617617
if (word && i != 1 && originalCapState[i] && !IsUpperCase(*word))
618618
{
619-
if (!originalCapState[i-1]) return false;
620-
else if (i != wordCount && !originalCapState[i+1]) return false;
619+
if (!originalCapState[i-1]) continue;
620+
else if (i != wordCount && !originalCapState[i+1]) continue;
621621
}
622622

623623
if (word && !*word) // performed substitution on prior word, restart this one

0 commit comments

Comments
 (0)