Raised This Month: $ Target: $400
 0% 

Need help parsing a large number of variables from a string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mugwump
Senior Member
Join Date: May 2004
Old 07-10-2004 , 03:11   Need help parsing a large number of variables from a string
Reply With Quote #1

These problems I am experiencing are with small, I'd appreciate any help that yopu can provide.

I am trying to parse 42 substrings from a string and its just not working, I am wondering if there is a builtin limit I have to stay within.

If I try to parse all 42 substrings I get a seg fault core dump when I attempt to compile.

If I reduce this down to just 22 of the fields it compiles cleanly, If I try 32 fields I get some compiler errors that are just wrong, complains about loose indentation, multiple fields, etc - but none of the reported errors are valid.

Here is a code sample:

Code:
   new playerid[32]
   new playername[32]
   new ip[32]
   new xp[32]
   new skill1[2], skill2[2], skill3[2], skill4[2], skill5[2]
   new skill6[2], skill7[2], skill8[2], skill9[2], skill10[2]
   new skill11[2], skill12[2], skill13[2], skill14[2], skill15[2]
   new skill16[2], skill17[2], skill18[2], skill19[2], skill20[2]
   new skill21[2], skill22[2], skill23[2], skill24[2], skill25[2]
   new skill26[2], skill27[2], skill28[2], skill29[2], skill30[2]
   new skill31[2], skill32[2], skill33[2], skill34[2], skill35[2]
   new skill36[2], skill37[2], skill38[2], skill39[2], skill40[2]

   // ... pkey is setup to retrieve the vault data, left out here
   new attempt = get_vaultdata(pkey, pdata, 511)

   // Now here is the code for parsing the 42 pieces of data from pdata
   if (attempt){
      new nparsed = parse(pdata, playerid, 31, xp, 7, skill1, 2, skill2, 2, skill3, 2, skill4, 2, skill5, 2, skill6, 2, skill7, 2, skill8, 2, skill9, 2, skill10, 2, skill11, 2, skill12, 2, skill13, 2, skill14, 2, skill15, 2, skill16, 2, skill17, 2, skill18, 2, skill19, 2, skill20, 2, skill21, 2, skill22, 2, skill23, 2, skill24, 2, skill25, 2, skill26, 2, skill27, 2, skill28, 2, skill29, 2, skill30, 2, skill31, 2, skill32, 2, skill33, 2, skill34, 2, skill35, 2, skill36, 2, skill37, 2, skill38, 2, skill39, 2, skill40, 2 )

       ...
   }
The new nparsed = line is the problem, only reducing the number of fields makes this work, so what is the limit here? Is there anyway anyone can think of to accomplish this?

Thanks in advance!
-Mug
Mugwump is offline
BAILOPAN
Join Date: Jan 2004
Old 07-10-2004 , 04:12  
Reply With Quote #2

parse() is a pretty bad function, I'd recommend not using it for anything personally... for 0.20 I've replaced it with a nicer function called strbreak().

The problem with parse is that it's not reentrant or loop-able, and your system of using like 30 skillx[2] variables is not the brightest idea either

Here is a suggestion, just make sure to reserve some extra memory for this plugin

Code:
#define MAX_SKILLS 41 //reserve 64K of memory #pragma dynamic 16384 new playerid[32] new playername[32] new ip[32] new xp[32] new skills[MAX_SKILLS][2] new pdata[512], i new temp1[512], temp2[512] get_vaultdata(pkey, pdata, 511) str_break(pdata, playerid, temp1, 32, 511) str_break(temp1, xp, temp2, 7, 511) new s = strlen(temp2) new j = 1, k = 0 for (i=0; i<s; i++) {    //check for space or quote    if (temp2[i] == 32 || temp2[i] == 34)       j++    else       skills[j][k++] = temp2[i] } stock str_break(const String[], Left[], Right[], lMax, rMax) {     new bool:quote_flag = false     new bool:done_flag = false     new left_pos = 0     new right_pos = 0     new i     new hold[] = "'^"x"         copy(Left, lMax, "")     copy(Right, rMax, "")         for (i=0; i<=strlen(String)-1; i++) {         if (equali(String[i], "^"", 1)) {             quote_flag = true         } else if ((equali(String[i], "^"", 1)) && (quote_flag)) {             quote_flag = false         }         if ((equali(String[i], " ", 1)) && (!quote_flag) && (!done_flag)) {             done_flag = true             i++         }         if (!done_flag && !equali(String[i], "^"", 1)) {             if (left_pos < lMax) {                 setc(Left[left_pos], 1, String[i])                 if (equali(Left[left_pos], "'", 1)) {                     setc(Left[left_pos], 1, hold[1])                 }                 left_pos++             }         } else {             if (right_pos < rMax && !equali(String[i], "^"", 1)) {                 setc(Right[right_pos], 1, String[i])                 if (equali(Right[right_pos], "'", 1)) {                     setc(Right[right_pos], 1, hold[1])                 }                 right_pos++             }         }     }     Left[left_pos] = 0     Right[right_pos] = 0         return true }

I have no clue if this will work, but the idea is to make smart character parsing instead of relying on outside functions

One of the advantages to having C style strings
__________________
egg
BAILOPAN is offline
Mugwump
Senior Member
Join Date: May 2004
Old 07-10-2004 , 08:11  
Reply With Quote #3

Yeah, I realize having 40 different variables for each skill was a horrible way to do it (outside of the routine all player skills are kept as a matrix anyway), but using parse() I didn't see any alternative, but I like your suggestion and I dont see why it shouldn't work ...

Thank you
Mug
Mugwump is offline
Reply


Thread Tools
Display Modes

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 14:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode