+} /* End of wait */
+
+void* AllocateLargestFreeBlock(size_t* Size)
+{
+ size_t s0, s1;
+ void* p;
+
+ s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
+
+ while (s0 && (p = malloc(s0)) == NULL)
+ s0 >>= 1;
+
+ if (p)
+ free(p);
+
+ s1 = s0 >> 1;
+
+ while (s1)
+ {
+ if ((p = malloc(s0 + s1)) != NULL)
+ {
+ s0 += s1;
+ free(p);
+ }
+ s1 >>= 1;
+ }
+
+ while (s0 && (p = malloc(s0)) == NULL)
+ s0 ^= s0 & -s0;
+
+ *Size = s0;
+ return p;
+}
+
+size_t GetFreeSize(void)
+{
+ size_t total = 0;
+ void* pFirst = NULL;
+ void* pLast = NULL;
+
+ for (;;)
+ {
+ size_t largest;
+ void* p = AllocateLargestFreeBlock(&largest);
+
+ if (largest < sizeof(void*))
+ {
+ if (p != NULL)
+ free(p);
+ break;
+ }
+
+ *(void**)p = NULL;
+
+ total += largest;
+
+ if (pFirst == NULL)
+ pFirst = p;
+
+ if (pLast != NULL)
+ *(void**)pLast = p;
+
+ pLast = p;
+ }
+
+ while (pFirst != NULL)
+ {
+ void* p = *(void**)pFirst;
+ free(pFirst);
+ pFirst = p;
+ }
+
+ return total;
+}
+
+long int
+filesize(FILE *fp)\r
+{\r
+ long int save_pos, size_of_file;\r
+\r
+ save_pos = ftell(fp);\r
+ fseek(fp, 0L, SEEK_END);\r
+ size_of_file = ftell(fp);\r
+ fseek(fp, save_pos, SEEK_SET);\r
+ return(size_of_file);\r
+}
+
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// US_CheckParm() - checks to see if a string matches one of a set of\r
+// strings. The check is case insensitive. The routine returns the\r
+// index of the string that matched, or -1 if no matches were found\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+int\r
+US_CheckParm(char *parm,char **strings)\r
+{\r
+ char cp,cs,\r
+ *p,*s;\r
+ int i;\r
+\r
+ while (!isalpha(*parm)) // Skip non-alphas\r
+ parm++;\r
+\r
+ for (i = 0;*strings && **strings;i++)\r
+ {\r
+ for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)\r
+ {\r
+ cs = *s++;\r
+ if (!cs)\r
+ return(i);\r
+ cp = *p++;\r
+\r
+ if (isupper(cs))\r
+ cs = tolower(cs);\r
+ if (isupper(cp))\r
+ cp = tolower(cp);\r
+ }\r
+ }\r
+ return(-1);\r
+}