diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-09-04 19:03:17 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-09-04 19:03:17 -0300 |
| commit | 9b2292bdce7667c1a32e478925ee28b8f71b8f35 (patch) | |
| tree | 07455e5ad2645805746c0b5c95db655a34321e1c | |
| parent | 4a281dffcf3df607d2182ad4b6c5d37016015b72 (diff) | |
| download | game-9b2292bdce7667c1a32e478925ee28b8f71b8f35.tar.gz game-9b2292bdce7667c1a32e478925ee28b8f71b8f35.zip | |
fix problem with mail text parsing - fixes #19
| -rw-r--r-- | src/moveuse.cc | 43 |
1 files changed, 22 insertions, 21 deletions
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); } |
