|
Post by LordKaT on Jun 6, 2004 6:20:11 GMT -5
This is, by far, the ugliest bit of string manipulation I've ever done.
int Input::AddToBuffer(char *cTemp1, int iBuffer) { int iPos; int iTemp; char cText[MAX_BUFFER]; BUF *bPoint;
bPoint = GetBuffer(iBuffer);
for (int i = 0; i < MAX_BUFFER - 1; i++) sprintf(bPoint[i].cBuf, "%s", bPoint[i + 1].cBuf);
/* If our string is too long, it'll just get drawn off in null-space. So, we need to loop through and add each set of 40 chars to a new buffer. */
if (strlen(cTemp1) > 40) { iPos = 0; iTemp = 0; memset(&cText, NULL, sizeof(cText));
while (cTemp1[iPos] != '\0') { sprintf(&cText[iTemp], "%c", cTemp1[iPos]); iPos++; iTemp++; if (iTemp >= 40 || cTemp1[iPos] == '\0') { sprintf(bPoint[MAX_BUFFER - 1].cBuf, "%s", cText); if (cTemp1[iPos] != '\0') { for (int i = 0; i < MAX_BUFFER - 1; i++) sprintf(bPoint[i].cBuf, "%s", bPoint[i + 1].cBuf); } iTemp = 0; memset(&cText, NULL, sizeof(cText)); } } } else sprintf(bPoint[MAX_BUFFER - 1].cBuf, "%s", cTemp1); memset(&cTemp1, NULL, sizeof(cTemp1));
return ERROR_NONE; }
|
|
|
Post by Buddhist Kitten on Jun 6, 2004 14:00:30 GMT -5
WTF?
|
|
|
Post by LordKaT on Jun 6, 2004 17:11:30 GMT -5
Well, uhm, yeah. I have a nasty habbit of not commenting my source code ...
|
|
|
Post by otrfan on Jun 6, 2004 19:13:33 GMT -5
I chose to post a blob of a different sort...
|
|
|
Post by MonsterX on Jun 6, 2004 19:20:23 GMT -5
Beware of the Blob! It creeps and leaps and glides and slides across the floor Right through the door and all around the wall , A splotch , a blotch , Be careful of the Blob!
|
|
|
Post by Ator on Jun 6, 2004 19:33:47 GMT -5
This is, by far, the ugliest bit of string manipulation I've ever done. Believe me, when I used to write C and C++, my code was much uglier than your C code.
|
|
|
Post by LordKaT on Jun 7, 2004 4:09:54 GMT -5
My biggest problem with this set of code is that it adds each 40-line string of text into a new buffer. What I'd *like* to do is keep each line of text seperate but draw every 40 chars on a new line.
Except my problem is that when I attempt that, my buffer drawing routines get all flapjacksed up, and text starts to overdraw text and ... it's a real ugly mess.
Oh well, this is better than nothing, I suppose!
|
|
|
Post by marytrobot on Jun 7, 2004 4:28:27 GMT -5
|
|