Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 07-17-2003, 12:58 AM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default 5.0 fixes / changes

I figured I'd make one thread for things I fix / change, this was just the first significant change. If I understood what calc() was supposed to do in parser.cpp (that is, calculate a simple math expression in a string) then it had a few problems. I rewrote it, see below:

Code:
int calc( string calc )
{
	string::iterator iterator = calc.begin();
	string buffer;
	string integer1;
	char op = 0;
	int returnvalue = 0;
	
	while (*iterator)
	{
		char ch = *iterator;
		
		if(ch >= '0' && ch <= '9')//If this character is numeric add it to the buffer
		{
			buffer += ch;
		}
		else if(ch == '+' || ch == '-' || ch == '/' || ch == '*')//otherwise, are we an operator?
		{
			int val = atoi(buffer.c_str());
			if(!op)//if this is the first time through, set returnvalue to what we have so far
			{
				returnvalue = val;
			}
			else//otherwise we've got returnvalue initialized, perform operation on previous numbers
			{
				if(buffer.length() == 0)//Do we have a value?
				{
					printf("Parser::calc() Error in syntax: '%s'.\n", calc);
					return 0;
				}
				//what was the previous op
				switch(op)
				{
				case '+':
					{
						returnvalue += val;
						break;
					}
				case '-':
					{
						returnvalue -= val;
						break;
					}
				case '/':
					{
						if(val == 0)//can't divide by zero
						{
							printf("Parser::calc() Error, Divide by zero '%s'.\n", calc);
							return 0;
						}
						returnvalue /= val;
						break;
					}
				case '*':
					{
						returnvalue *= val;
						break;
					}
				};
				op = ch;//save current operator and continue parsing
				buffer.clear();//clear buffer now that we're starting on a new number
			}
			op = ch;
		}
		else
		{
			printf("Parser::calc() Error processing '%c'.\n", ch);
			return 0;
		}
	}
	return returnvalue;
}
Reply With Quote
  #2  
Old 07-17-2003, 08:26 AM
Merth
Dragon
 
Join Date: May 2003
Location: Seattle, WA
Posts: 609
Default

This has been applied and will be available on the next CVS push. I only verified that it compiled, I haven't tested the code at all.

Thanks!
Reply With Quote
  #3  
Old 07-17-2003, 08:46 AM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

I was looking back through this and I missed a change that I had made.

At the end of the op section, where I call buffer.clear(), that needs to be moved outside of the if(!op) block, and the op = ch above it is redundant. So what was:

Code:
            }; 
            op = ch;//save current operator and continue parsing 
            buffer.clear();//clear buffer now that we're starting on a new number 
         } 
         op = ch; 
      }
should be:

Code:
            }; 
         } 
         buffer.clear();//clear buffer now that we're starting on a new number
         op = ch; 
      }
Reply With Quote
  #4  
Old 07-17-2003, 08:58 AM
Merth
Dragon
 
Join Date: May 2003
Location: Seattle, WA
Posts: 609
Default

Applied that change, too
Reply With Quote
  #5  
Old 07-17-2003, 04:16 PM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

EDIT: This doesn't really work. I was assuming the client kept it's connection to the world server, that doesn't look like the case. I hadn't tested it enough.
Reply With Quote
  #6  
Old 07-18-2003, 12:16 PM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

in parser.cpp the itoa() function should declare the tmp[] buffer as 12 chars instead of 10. it needs one char for the terminating null and it's possible the value is negative which will prepend a '-' to the string and requiring another character.
Reply With Quote
  #7  
Old 07-18-2003, 12:22 PM
devn00b's Avatar
devn00b
Demi-God
 
Join Date: Jan 2002
Posts: 15,658
Default

nice changes here alkrun
:juggle:
__________________
(Former)Senior EQEMu Developer
GuildWars Co-Founder / World Builder.
World Builder and Co-Founder Zek [PVP/Guild Wars/City Takeovers]
Member of the "I hate devn00b" Club
Most Senior EQEMu Member.

Current Work: EverQuest 2 Emulator. Zeklabs Server
Reply With Quote
  #8  
Old 07-18-2003, 12:32 PM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

thanks.

Another thing that's sort of unrelated to a code fix is that the anonymous CVS source is "messed up"(tm). A lot of the files are doublespaced when checked out on windows (not sure about unix). In some files the EOL sequence when checked out is CRCRLF. I've written something to strip all of the files of CRCRLF and replace it with a CRLF, but I figured I'd pass it along. My guess is that something is wrong with the way the code is being dumped into CVS.
Reply With Quote
  #9  
Old 07-18-2003, 12:39 PM
mangoo
Items Master
 
Join Date: Apr 2003
Posts: 293
Default

Alkrun, regarding CVS in the Windows platform... The double spacing isn't a problem in the CVS itself. I believe it's from going from UNIX to Windows. I'm assuming you are using WinCVS to retrieve files from CVS. So here is how to fix the double spacing...

In WinCVS go into preferences, Globals tab. At the bottom will be a checkbox for "Check out text files with the Unix LF". Make sure that is checked and all is well
Reply With Quote
  #10  
Old 07-18-2003, 12:46 PM
alkrun
Sarnak
 
Join Date: Jan 2002
Posts: 66
Default

Ah, I'm actually using cvs from the commandline. I've seen this before but it's normally when files are checked out on a unix platform, then checked in using a cygwin version of CVS or some other method of copying files checked out from CVS on one platform to the other.

But I'll take a look and see if there's an option, I don't see one, so I might have to just use wincvs. Thanks.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 02:18 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3