/*----------------------------------------------------------------------------*-YAdmin system - Misc FunctionsChangelog:24/03/07:First version.-*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*-Function: straddParams: string[] - The string to add to a format code and store the result in. format[] - The new text format to put the variable in.Return: -Notes: Sort of like: %1 = %1 . %2; Only it may not be done like that, %1 can be put anywhere in %2-*----------------------------------------------------------------------------*/#define stradd(%1,%2) \ format((%1), sizeof (%1), (%2), (%1))/*----------------------------------------------------------------------------*-Function: chrfindParams: needle - The character to find. haystack[] - The string to find it in. start - The offset to start from.Return: Fail - -1, Success - posNotes: --*----------------------------------------------------------------------------*/chrfind(needle, haystack[], start = 0){ new len = strlen(haystack); while (start < len) { if (haystack[start] == needle) return start; start++; } return -1;}/*----------------------------------------------------------------------------*-Function: strcpyParams: dest[] - Location to copy the string too.Return: source[] - Location to copy the string fromNotes: --*----------------------------------------------------------------------------*/strcpy(dest[], source[], len = -1){ //memcpy(dest, source, 0, strlen(source), max); new i; if (len == -1) len = strlen(source); while (i < len) dest[i] = source[i++]; dest[i] = 0;}/*----------------------------------------------------------------------------*-Function: bernsteinParams: string[] - the string to hash.Return: the bernstein hash of the input stringNotes: This is a 32bit hash system as so is not very secure, however we're only using this as a string enumerator to uniquely identify strings easilly and allow for a binary search of strings based on the hash of their name. crc32, then jenkins wer originally used however this is far faster, if a little collision prone, but we're checking the strings manually anyway so this doesn't matter as it would be done regardless of hash method, so this doesn't need to be accounted for and speed is all that matters with at least at bit of non collision (the number of strings we're dealing with, this should have none-few collisions). I modified it slightly from the original code pasted by aru, to code closer to the code http://www.burtleburtle.net/bob/hash/doobs.html and to work with PAWN (and shaved 0.2µs off the time for one call :D). Uber reduced version: b(s[]){new h=-1,i,j;while((j=s[i++]))h=h*33+j;return h;}-*----------------------------------------------------------------------------*/bernstein(string[]){ new hash = -1, i, j; while ((j = string[i++])) hash = hash * 33 + j; return hash;}/*----------------------------------------------------------------------------*-Function: StripNLParams: str[] - The string to remove the newline characters fromReturn: -Notes: Updated from old versions, should be more efficient-*----------------------------------------------------------------------------*/stock StripNL(str[]){ new l = strlen(str); while (l-- && (str[l] == '\n' || str[l] == '\r')) str[l] = 0;}/*----------------------------------------------------------------------------*-Function: quickSortParams: numbers[] - Array of values you want sorting. arraySize - Number of items.Return: -Notes: Entry point for the recursive q_sort function-*----------------------------------------------------------------------------*/#define QuickSort(%1,%2) \ QSort((%1), 0, (%2) - 1)/*----------------------------------------------------------------------------*-Function: QSortParams: numbers[] - Array of values to be sorted. left - Start index in the array. right - End index in the array.Return: -Notes: Adapted from: http://linux.wku.edu/~lamonml/algor/sort/quick.html Implementation of the quicksort routine.-*----------------------------------------------------------------------------*/stock QSort(numbers[], left, right){ new pivot = numbers[left], l_hold = left, r_hold = right; while (left < right) { while ((numbers[right] >= pivot) && (left < right)) right--; if (left != right) { numbers[left] = numbers[right]; left++; } while ((numbers[left] <= pivot) && (left < right)) left++; if (left != right) { numbers[right] = numbers[left]; right--; } } numbers[left] = pivot; pivot = left; left = l_hold; right = r_hold; if (left < pivot) QSort(numbers, left, pivot - 1); if (right > pivot) QSort(numbers, pivot + 1, right);}