From: sparky4 Date: Mon, 29 Jun 2015 07:53:01 +0000 (-0500) Subject: modified: 16/inpu.bat X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=99830fddc7fb74d98405660cd959fce0f14862f5;p=16.git modified: 16/inpu.bat new file: 16/inputest.exe new file: 16/src/lib/lib_head.c --- diff --git a/16/inpu.bat b/16/inpu.bat index d7e9313c..e7fc3b24 100644 --- a/16/inpu.bat +++ b/16/inpu.bat @@ -1,2 +1,3 @@ -wcc -0 -mc src\lib\16_in.c -wcl -mc -0 -l=dos src\inputest.c 16_in.obj \ No newline at end of file +wcc -0 -mc src\lib\lib_head.c +wcc -0 -mc src\lib\16_in.c +wcl -mc -0 -l=dos src\inputest.c 16_in.obj lib_head.obj diff --git a/16/inputest.exe b/16/inputest.exe new file mode 100644 index 00000000..24896837 Binary files /dev/null and b/16/inputest.exe differ diff --git a/16/src/lib/lib_head.c b/16/src/lib/lib_head.c new file mode 100644 index 00000000..4ca25c9c --- /dev/null +++ b/16/src/lib/lib_head.c @@ -0,0 +1,165 @@ +/* Project 16 Source Code~ + * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669 + * + * This file is part of Project 16. + * + * Project 16 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Project 16 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see , or + * write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include "src/lib/lib_head.h" + +/* local function */ +void wait(clock_t wait); +void* AllocateLargestFreeBlock(size_t* Size); +size_t GetFreeSize(void); +long int filesize(FILE *fp); + +/* Function: Wait ********************************************************** +* +* Parameters: wait - time in microseconds +* +* Description: pauses for a specified number of microseconds. +* +*/ +void wait(clock_t wait){ + clock_t goal; + + if(!wait) return; + + goal = wait + clock(); + while((goal > clock()) && !kbhit()) ; +} /* 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) +{ + long int save_pos, size_of_file; + + save_pos = ftell(fp); + fseek(fp, 0L, SEEK_END); + size_of_file = ftell(fp); + fseek(fp, save_pos, SEEK_SET); + return(size_of_file); +} + +/////////////////////////////////////////////////////////////////////////// +// +// US_CheckParm() - checks to see if a string matches one of a set of +// strings. The check is case insensitive. The routine returns the +// index of the string that matched, or -1 if no matches were found +// +/////////////////////////////////////////////////////////////////////////// +int +US_CheckParm(char *parm,char **strings) +{ + char cp,cs, + *p,*s; + int i; + + while (!isalpha(*parm)) // Skip non-alphas + parm++; + + for (i = 0;*strings && **strings;i++) + { + for (s = *strings++,p = parm,cs = cp = 0;cs == cp;) + { + cs = *s++; + if (!cs) + return(i); + cp = *p++; + + if (isupper(cs)) + cs = tolower(cs); + if (isupper(cp)) + cp = tolower(cp); + } + } + return(-1); +}