From 9b2292bdce7667c1a32e478925ee28b8f71b8f35 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Thu, 4 Sep 2025 19:03:17 -0300 Subject: fix problem with mail text parsing - fixes #19 --- src/moveuse.cc | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/moveuse.cc b/src/moveuse.cc index 253f511..b1c7090 100644 --- a/src/moveuse.cc +++ b/src/moveuse.cc @@ -689,6 +689,26 @@ void SaveDepotBox(uint32 CreatureID, int Nr, Object Con){ } } +// TODO(fusion): Maybe move this to `strings.cc` or `utils.cc`? +static int ReadLine(char *Dest, int DestCapacity, const char *Text, int ReadPos){ + ASSERT(DestCapacity > 0); + int WritePos = 0; + while(Text[ReadPos] != 0 && Text[ReadPos] != '\n'){ + if(WritePos < (DestCapacity - 1)){ + Dest[WritePos] = Text[ReadPos]; + WritePos += 1; + } + ReadPos += 1; + } + + if(Text[ReadPos] == '\n'){ + ReadPos += 1; + } + + Dest[WritePos] = 0; + return ReadPos; +} + void SendMail(Object Obj){ if(!Obj.exists()){ error("SendMail: Übergebenes Objekt existiert nicht.\n"); @@ -729,31 +749,12 @@ void SendMail(Object Obj){ } - // TODO(fusion): Have some helper functions to read lines? char Addressee[256]; char Town[256]; { int ReadPos = 0; - int WritePos = 0; - while(Text[ReadPos] != 0 && Text[ReadPos] != '\n'){ - if(WritePos < (int)(sizeof(Addressee) - 1)){ - Addressee[WritePos] = Text[ReadPos]; - WritePos += 1; - } - ReadPos += 1; - } - Addressee[WritePos] = 0; - - WritePos = 0; - while(Text[ReadPos] != 0 && Text[ReadPos] != '\n'){ - if(WritePos < (int)(sizeof(Town) - 1)){ - Town[WritePos] = Text[ReadPos]; - WritePos += 1; - } - ReadPos += 1; - } - Town[WritePos] = 0; - + ReadPos = ReadLine(Addressee, sizeof(Addressee), Text, ReadPos); + ReadPos = ReadLine(Town, sizeof(Town), Text, ReadPos); Trim(Addressee); Trim(Town); } -- cgit v1.2.3