Advertisement
ijontichy

teststr.c

Apr 15th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. #include "zcommon.acs"
  2.  
  3. global int 0:strings[];
  4.  
  5. function int addString(int string)
  6. {
  7.     int strSize = StrLen(string) + 1;  // gotta remember the null byte at the start
  8.  
  9.     int index = 0; int ret; int i = 0; int j; int c;
  10.  
  11.     while (1)
  12.     {
  13.         c = strings[index];
  14.        
  15.         if (c == 0)
  16.         {
  17.             if (i == 1)
  18.             {
  19.                 ret = index;
  20.             }
  21.  
  22.             i += 1;
  23.         }
  24.         else
  25.         {
  26.             i = 0;
  27.         }
  28.  
  29.         if (i >= strSize)
  30.         {
  31.             break;
  32.         }
  33.  
  34.         index += 1;
  35.     }
  36.    
  37.     for (i = 0; i < strSize; i++)
  38.     {
  39.         j = i + ret;
  40.  
  41.         strings[j] = GetChar(string, i);
  42.     }
  43.  
  44.     strings[ret + (strSize-1)] = 0;
  45.  
  46.     return ret;
  47. }
  48.  
  49. function int getString(int index)
  50. {
  51.     int ret = "";
  52.     int i = 0; int j; int c;
  53.  
  54.     while (1)
  55.     {
  56.         j = i + index;
  57.         i += 1;
  58.  
  59.         c = strings[j];
  60.  
  61.         if (c == 0)
  62.         {
  63.             break;
  64.         }
  65.  
  66.         ret = StrParam(s:ret, c:c);
  67.     }
  68.    
  69.     return ret;
  70. }
  71.  
  72. function void freeString(int index)
  73. {
  74.     int i = 0; int j; int c;
  75.  
  76.     while (1)
  77.     {
  78.         j = i + index;
  79.         i += 1;
  80.  
  81.         c = strings[j];
  82.  
  83.         if (c == 0)
  84.         {
  85.             break;
  86.         }
  87.  
  88.         strings[j] = 0;
  89.     }
  90. }
  91.  
  92. script 193 (void)
  93. {
  94.     int strIndex = addString("potato pie, tell me why.");
  95.     int herp = getString(strIndex);
  96.  
  97.     print(d:strIndex, s:"\n", s:herp);
  98.  
  99.     int strIndex2 = addString(StrParam(n:0));
  100.     int derp = getString(strIndex2);
  101.  
  102.     print(d:strIndex2, s:"\n", s:derp);
  103.     print(s:getString(strIndex));
  104.  
  105.     freeString(strIndex);
  106.     freeString(strIndex2);
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement