1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "src/lib/lib_head.h"
25 /* local function */
\r
26 void wait(clock_t wait);
27 void* AllocateLargestFreeBlock(size_t* Size);
28 size_t GetFreeSize(void);
29 long int filesize(FILE *fp);
\r
31 /* Function: Wait **********************************************************
\r
33 * Parameters: wait - time in microseconds
\r
35 * Description: pauses for a specified number of microseconds.
\r
38 void wait(clock_t wait){
\r
43 goal = wait + clock();
\r
44 while((goal > clock()) && !kbhit()) ;
\r
47 void* AllocateLargestFreeBlock(size_t* Size)
52 s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
54 while (s0 && (p = malloc(s0)) == NULL)
64 if ((p = malloc(s0 + s1)) != NULL)
72 while (s0 && (p = malloc(s0)) == NULL)
79 size_t GetFreeSize(void)
88 void* p = AllocateLargestFreeBlock(&largest);
90 if (largest < sizeof(void*))
110 while (pFirst != NULL)
112 void* p = *(void**)pFirst;
123 long int save_pos, size_of_file;
\r
125 save_pos = ftell(fp);
\r
126 fseek(fp, 0L, SEEK_END);
\r
127 size_of_file = ftell(fp);
\r
128 fseek(fp, save_pos, SEEK_SET);
\r
129 return(size_of_file);
\r
132 ///////////////////////////////////////////////////////////////////////////
\r
134 // US_CheckParm() - checks to see if a string matches one of a set of
\r
135 // strings. The check is case insensitive. The routine returns the
\r
136 // index of the string that matched, or -1 if no matches were found
\r
138 ///////////////////////////////////////////////////////////////////////////
\r
140 US_CheckParm(char *parm,char **strings)
\r
146 while (!isalpha(*parm)) // Skip non-alphas
\r
149 for (i = 0;*strings && **strings;i++)
\r
151 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
\r