forked from KolibriOS/kolibrios
ktcc: removed old files
git-svn-id: svn://kolibrios.org@9777 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
7b2b4533ba
commit
c5ebb23061
@ -1,27 +0,0 @@
|
||||
1. create asm listing:
|
||||
compile .o only, then use objdump
|
||||
kos32-tcc.exe -c -g clipview.c -o clipviewtcc.o
|
||||
kos32-objdump -d -M intel -S -l clipviewtcc.o > clipviewtcc.asm
|
||||
|
||||
2. see offset in resulting kolibri executable compared to listing (i have 0xD0)
|
||||
|
||||
3. in kolibri debugger mtdbg set breakpoint to funtion address
|
||||
>bp 140
|
||||
where 0x140 is 0x70 in assemly + offset 0xD0
|
||||
|
||||
|
||||
Warning !!Error. sometimes tcc dont warn about unsuccesful linking
|
||||
(not found function body code). Hopefully, i fix this.
|
||||
|
||||
Usually, at runtime you have crash with "Illegal cpu instruction"
|
||||
In assembler code this is easy to recognize as
|
||||
myaddr:E8 FC FF FF FF call myaddr+1
|
||||
|
||||
4.how to see defines
|
||||
kos32-tcc.exe -E -dD null
|
||||
|
||||
5.if you use GNU LD as a linker, add option -Map=hellocpp.map to ld.
|
||||
Mtdbg can use resulting .map file
|
||||
|
||||
6.now you can use -g option to generate .dbg file. This enables
|
||||
source code level debugging with Mtdbg
|
@ -1,68 +0,0 @@
|
||||
@echo off
|
||||
echo ####################################################
|
||||
echo # test libc builder #
|
||||
echo # usage: build [clean] #
|
||||
echo ####################################################
|
||||
rem #### CONFIG SECTION ####
|
||||
set LIBNAME=libck.a
|
||||
set INCLUDE=include
|
||||
set CC=D:\VSProjects\msys-kos32-4.8.2\ktcc\trunk\libc\kos32-tcc.exe
|
||||
set CFLAGS=-I"%cd%\%INCLUDE%" -Wall
|
||||
set AR=kos32-ar
|
||||
set ASM=fasm
|
||||
set dirs=.
|
||||
rem #### END OF CONFIG SECTION ####
|
||||
|
||||
set objs=
|
||||
set target=%1
|
||||
if not "%1"=="clean" set target=all
|
||||
|
||||
set INCLUDE="%cd%"
|
||||
call :Target_%target%
|
||||
|
||||
if ERRORLEVEL 0 goto Exit_OK
|
||||
|
||||
echo Probably at runing has been created error
|
||||
echo For help send a report...
|
||||
pause
|
||||
goto :eof
|
||||
|
||||
:Compile_C
|
||||
%CC% %CFLAGS% %1 -o "%~dpn1.kex" -lck
|
||||
if not %errorlevel%==0 goto Error_Failed
|
||||
set objs=%objs% "%~dpn1.o"
|
||||
goto :eof
|
||||
|
||||
:Compile_Asm
|
||||
%ASM% %1 "%~dpn1.o"
|
||||
if not %errorlevel%==0 goto Error_Failed
|
||||
set objs=%objs% "%~dpn1.o"
|
||||
goto :eof
|
||||
|
||||
:Target_clean
|
||||
echo cleaning ...
|
||||
for %%a in (%dirs%) do del /Q "%%a\*.o"
|
||||
for %%a in (%dirs%) do del /Q "%%a\*.kex"
|
||||
goto :Exit_OK
|
||||
|
||||
:Target_all
|
||||
echo building all ...
|
||||
for %%a in (%dirs%) do (
|
||||
for %%f in ("%%a\*.asm") do call :Compile_Asm "%%f"
|
||||
for %%f in ("%%a\*.c") do call :Compile_C "%%f"
|
||||
)
|
||||
:: %AR% -ru %LIBNAME% %objs%
|
||||
:: if not %errorlevel%==0 goto Error_Failed
|
||||
goto Exit_OK
|
||||
|
||||
:Error_Failed
|
||||
echo error: execution failed
|
||||
pause
|
||||
exit 1
|
||||
|
||||
:Exit_OK
|
||||
echo ####################################################
|
||||
echo # All operations has been done... #
|
||||
echo ####################################################
|
||||
pause
|
||||
exit 0
|
@ -1,42 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
printf("------------------------------------------------------\n");
|
||||
printf ( "remainder of 5.3 / 2 is %f\n", remainder (5.3,2) );
|
||||
printf ( "remainder of 18.5 / 4.2 is %f\n", remainder (18.5,4.2) );
|
||||
//remainder of 5.3 / 2 is -0.700000
|
||||
//remainder of 18.5 / 4.2 is 1.700000
|
||||
|
||||
printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) );
|
||||
printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) );
|
||||
// fmod of 5.3 / 2 is 1.300000
|
||||
// fmod of 18.5 / 4.2 is 1.700000
|
||||
|
||||
double param, fractpart, intpart, result;
|
||||
int n;
|
||||
|
||||
param = 3.14159265;
|
||||
fractpart = modf (param , &intpart);
|
||||
printf ("%f = %f + %f \n", param, intpart, fractpart);
|
||||
//3.141593 = 3.000000 + 0.141593
|
||||
|
||||
param = 0.95;
|
||||
n = 4;
|
||||
result = ldexp (param , n);
|
||||
printf ("%f * 2^%d = %f\n", param, n, result);
|
||||
//0.950000 * 2^4 = 15.200000
|
||||
|
||||
param = 8.0;
|
||||
result = frexp (param , &n);
|
||||
printf ("%f = %f * 2^%d\n", param, result, n);
|
||||
//8.000000 = 0.500000 * 2^4
|
||||
param = 50;
|
||||
result = frexp (param , &n);
|
||||
printf ("%f = %f * 2^%d\n", param, result, n);
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "test.h"
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
errno=0, ((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x, strerror(errno)), 0) )
|
||||
|
||||
#define TEST_S(s, x, m) ( \
|
||||
!strcmp((s),(x)) || \
|
||||
(t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
|
||||
|
||||
static FILE *writetemp(const char *data)
|
||||
{
|
||||
FILE *f = fopen("_tmpfile.tmp", "w+");
|
||||
if (!f) return 0;
|
||||
if (!fwrite(data, strlen(data), 1, f)) {
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
rewind(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, x, y;
|
||||
double u;
|
||||
char a[100], b[100];
|
||||
FILE *f;
|
||||
|
||||
|
||||
TEST(i, !!(f=writetemp("hello, world")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
TEST(i, fscanf(f, "%s %[own]", a, b), 2, "got %d fields, expected %d");
|
||||
TEST_S(a, "hello,", "wrong result for %s");
|
||||
TEST_S(b, "wo", "wrong result for %[own]");
|
||||
TEST(i, fgetc(f), 'r', "'%c' != '%c') (%s)");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp("ld 0x12 0x34")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
TEST(i, fscanf(f, "ld %5i%2i", &x, &y), 1, "got %d fields, expected %d");
|
||||
TEST(i, x, 0x12, "%d != %d");
|
||||
TEST(i, fgetc(f), '3', "'%c' != '%c'");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp(" 42")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
x=y=-1;
|
||||
TEST(i, fscanf(f, " %n%*d%n", &x, &y), 0, "%d != %d");
|
||||
TEST(i, x, 6, "%d != %d");
|
||||
TEST(i, y, 8, "%d != %d");
|
||||
TEST(i, ftell(f), 8, "%d != %d");
|
||||
TEST(i, !!feof(f), 1, "%d != %d");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp("[abc123]....x")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
x=y=-1;
|
||||
TEST(i, fscanf(f, "%10[^]]%n%10[].]%n", a, &x, b, &y), 2, "%d != %d");
|
||||
TEST_S(a, "[abc123", "wrong result for %[^]]");
|
||||
TEST_S(b, "]....", "wrong result for %[].]");
|
||||
TEST(i, x, 7, "%d != %d");
|
||||
TEST(i, y, 12, "%d != %d");
|
||||
TEST(i, ftell(f), 12, "%d != %d");
|
||||
TEST(i, feof(f), 0, "%d != %d");
|
||||
TEST(i, fgetc(f), 'x', "%d != %d");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp("0x1.0p12")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
x=y=-1;
|
||||
u=-1;
|
||||
TEST(i, fscanf(f, "%lf%n %d", &u, &x, &y), 1, "%d != %d");
|
||||
TEST(u, u, 0.0, "%g != %g");
|
||||
TEST(i, x, 1, "%d != %d");
|
||||
TEST(i, y, -1, "%d != %d");
|
||||
TEST(i, ftell(f), 1, "%d != %d");
|
||||
TEST(i, feof(f), 0, "%d != %d");
|
||||
TEST(i, fgetc(f), 'x', "%d != %d");
|
||||
rewind(f);
|
||||
TEST(i, fgetc(f), '0', "%d != %d");
|
||||
TEST(i, fgetc(f), 'x', "%d != %d");
|
||||
TEST(i, fscanf(f, "%lf%n%c %d", &u, &x, a, &y), 3, "%d != %d");
|
||||
TEST(u, u, 1.0, "%g != %g");
|
||||
TEST(i, x, 3, "%d != %d");
|
||||
TEST(i, a[0], 'p', "%d != %d");
|
||||
TEST(i, y, 12, "%d != %d");
|
||||
TEST(i, ftell(f), 8, "%d != %d");
|
||||
TEST(i, !!feof(f), 1, "%d != %d");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp("1.0 012")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
x=y=-1;
|
||||
u=-1;
|
||||
TEST(i, fscanf(f, "%lf%n %i", &u, &x, &y), 2, "%d != %d");
|
||||
TEST(u, u, 1.0, "%g != %g");
|
||||
TEST(i, x, 3, "%d != %d");
|
||||
TEST(i, y, 10, "%d != %d");
|
||||
TEST(i, ftell(f), 13, "%d != %d");
|
||||
TEST(i, !!feof(f), 1, "%d != %d");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(i, !!(f=writetemp("0xx")), 1, "failed to make temp file");
|
||||
if (f) {
|
||||
x=y=-1;
|
||||
TEST(i, fscanf(f, "%x%n", &x, &y), 0, "%d != %d");
|
||||
TEST(i, x, -1, "%d != %d");
|
||||
TEST(i, y, -1, "%d != %d");
|
||||
TEST(i, ftell(f), 2, "%d != %d");
|
||||
TEST(i, feof(f), 0, "%d != %d");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
/* A minor test-program for memmove.
|
||||
Copyright (C) 2005 Axis Communications.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Neither the name of Axis Communications nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS
|
||||
COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
/* Test moves of 0..MAX bytes; overlapping-src-higher,
|
||||
overlapping-src-lower and non-overlapping. The overlap varies with
|
||||
1..N where N is the size moved. This means an order of MAX**2
|
||||
iterations. The size of an octet may seem appropriate for MAX and
|
||||
makes an upper limit for simple testing. For the CRIS simulator,
|
||||
making this 256 added 90s to the test-run (2GHz P4) while 64 (4s) was
|
||||
enough to spot the bugs that had crept in, hence the number chosen. */
|
||||
#define MAX 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TOO_MANY_ERRORS 11
|
||||
int errors = 0;
|
||||
|
||||
#define DEBUGP \
|
||||
if (errors == TOO_MANY_ERRORS) \
|
||||
printf ("Further errors omitted\n"); \
|
||||
else if (errors < TOO_MANY_ERRORS) \
|
||||
printf
|
||||
|
||||
/* A safe target-independent memmove. */
|
||||
|
||||
void
|
||||
mymemmove (unsigned char *dest, unsigned char *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if ((src <= dest && src + n <= dest)
|
||||
|| src >= dest)
|
||||
while (n-- > 0)
|
||||
*dest++ = *src++;
|
||||
else
|
||||
{
|
||||
dest += n;
|
||||
src += n;
|
||||
while (n-- > 0)
|
||||
*--dest = *--src;
|
||||
}
|
||||
}
|
||||
|
||||
/* It's either the noinline attribute or forcing the test framework to
|
||||
pass -fno-builtin-memmove. */
|
||||
void
|
||||
xmemmove (unsigned char *dest, unsigned char *src, size_t n)
|
||||
__attribute__ ((__noinline__));
|
||||
|
||||
void
|
||||
xmemmove (unsigned char *dest, unsigned char *src, size_t n)
|
||||
{
|
||||
void *retp;
|
||||
retp = memmove (dest, src, n);
|
||||
|
||||
if (retp != dest)
|
||||
{
|
||||
errors++;
|
||||
DEBUGP ("memmove of n bytes returned %p instead of dest=%p\n",
|
||||
retp, dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Fill the array with something we can associate with a position, but
|
||||
not exactly the same as the position index. */
|
||||
|
||||
void
|
||||
fill (unsigned char dest[MAX*3])
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < MAX*3; i++)
|
||||
dest[i] = (10 + i) % MAX;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
size_t i;
|
||||
int errors = 0;
|
||||
|
||||
/* Leave some room before and after the area tested, so we can detect
|
||||
overwrites of up to N bytes, N being the amount tested. If you
|
||||
want to test using valgrind, make these malloced instead. */
|
||||
unsigned char from_test[MAX*3];
|
||||
unsigned char to_test[MAX*3];
|
||||
unsigned char from_known[MAX*3];
|
||||
unsigned char to_known[MAX*3];
|
||||
|
||||
/* Non-overlap. */
|
||||
for (i = 0; i < MAX; i++)
|
||||
{
|
||||
/* Do the memmove first before setting the known array, so we know
|
||||
it didn't change any of the known array. */
|
||||
fill (from_test);
|
||||
fill (to_test);
|
||||
xmemmove (to_test + MAX, 1 + from_test + MAX, i);
|
||||
|
||||
fill (from_known);
|
||||
fill (to_known);
|
||||
mymemmove (to_known + MAX, 1 + from_known + MAX, i);
|
||||
|
||||
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
|
||||
{
|
||||
errors++;
|
||||
DEBUGP ("memmove failed non-overlap test for %d bytes\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Overlap-from-before. */
|
||||
for (i = 0; i < MAX; i++)
|
||||
{
|
||||
size_t j;
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
fill (to_test);
|
||||
xmemmove (to_test + MAX * 2 - i, to_test + MAX * 2 - i - j, i);
|
||||
|
||||
fill (to_known);
|
||||
mymemmove (to_known + MAX * 2 - i, to_known + MAX * 2 - i - j, i);
|
||||
|
||||
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
|
||||
{
|
||||
errors++;
|
||||
DEBUGP ("memmove failed for %d bytes,"
|
||||
" with src %d bytes before dest\n",
|
||||
i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Overlap-from-after. */
|
||||
for (i = 0; i < MAX; i++)
|
||||
{
|
||||
size_t j;
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
fill (to_test);
|
||||
xmemmove (to_test + MAX, to_test + MAX + j, i);
|
||||
|
||||
fill (to_known);
|
||||
mymemmove (to_known + MAX, to_known + MAX + j, i);
|
||||
|
||||
if (memcmp (to_known, to_test, sizeof (to_known)) != 0)
|
||||
{
|
||||
errors++;
|
||||
DEBUGP ("memmove failed when moving %d bytes,"
|
||||
" with src %d bytes after dest\n",
|
||||
i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
|
||||
if (errors != 0)
|
||||
abort ();
|
||||
exit (0);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#test line 1;
|
||||
-test line 2;
|
||||
@test line 3;
|
||||
#testline4.
|
||||
#
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 by ARM Ltd. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char m[8] = {'M','M','M','M','M','M','M','M'};
|
||||
|
||||
int main()
|
||||
{
|
||||
printf ("%.*s\n", 8, m); // must print MMMMMMMM
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
|
||||
exit (0);
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
//#include <unistd.h>
|
||||
//#include "test.h"
|
||||
|
||||
volatile int t_status = 0;
|
||||
|
||||
int t_printf(const char *s, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[512];
|
||||
int n;
|
||||
|
||||
t_status = 1;
|
||||
va_start(ap, s);
|
||||
n = vsnprintf(buf, sizeof buf, s, ap);
|
||||
va_end(ap);
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
else if (n >= sizeof buf) {
|
||||
n = sizeof buf;
|
||||
buf[n - 1] = '0';
|
||||
buf[n - 2] = '.';
|
||||
buf[n - 3] = '.';
|
||||
buf[n - 4] = '.';
|
||||
}
|
||||
return printf("%s\n", buf);
|
||||
}
|
@ -1,173 +0,0 @@
|
||||
//#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "test.h"
|
||||
|
||||
static int scmp(const void *a, const void *b)
|
||||
{
|
||||
return strcmp(*(char **)a, *(char **)b);
|
||||
}
|
||||
|
||||
static int icmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int*)a - *(int*)b;
|
||||
}
|
||||
|
||||
static int ccmp(const void *a, const void *b)
|
||||
{
|
||||
return *(char*)a - *(char*)b;
|
||||
}
|
||||
|
||||
static int cmp64(const void *a, const void *b)
|
||||
{
|
||||
const uint64_t *ua = a, *ub = b;
|
||||
return *ua < *ub ? -1 : *ua != *ub;
|
||||
}
|
||||
|
||||
/* 26 items -- even */
|
||||
static const char *s[] = {
|
||||
"Bob", "Alice", "John", "Ceres",
|
||||
"Helga", "Drepper", "Emeralda", "Zoran",
|
||||
"Momo", "Frank", "Pema", "Xavier",
|
||||
"Yeva", "Gedun", "Irina", "Nono",
|
||||
"Wiener", "Vincent", "Tsering", "Karnica",
|
||||
"Lulu", "Quincy", "Osama", "Riley",
|
||||
"Ursula", "Sam"
|
||||
};
|
||||
static const char *s_sorted[] = {
|
||||
"Alice", "Bob", "Ceres", "Drepper",
|
||||
"Emeralda", "Frank", "Gedun", "Helga",
|
||||
"Irina", "John", "Karnica", "Lulu",
|
||||
"Momo", "Nono", "Osama", "Pema",
|
||||
"Quincy", "Riley", "Sam", "Tsering",
|
||||
"Ursula", "Vincent", "Wiener", "Xavier",
|
||||
"Yeva", "Zoran"
|
||||
};
|
||||
|
||||
/* 23 items -- odd, prime */
|
||||
static int n[] = {
|
||||
879045, 394, 99405644, 33434, 232323, 4334, 5454,
|
||||
343, 45545, 454, 324, 22, 34344, 233, 45345, 343,
|
||||
848405, 3434, 3434344, 3535, 93994, 2230404, 4334
|
||||
};
|
||||
static int n_sorted[] = {
|
||||
22, 233, 324, 343, 343, 394, 454, 3434,
|
||||
3535, 4334, 4334, 5454, 33434, 34344, 45345, 45545,
|
||||
93994, 232323, 848405, 879045, 2230404, 3434344, 99405644
|
||||
};
|
||||
|
||||
static void str_test(const char **a, const char **a_sorted, int len)
|
||||
{
|
||||
int i;
|
||||
qsort(a, len, sizeof *a, scmp);
|
||||
for (i=0; i<len; i++) {
|
||||
if (strcmp(a[i], a_sorted[i]) != 0) {
|
||||
t_error("string sort failed at index %d\n", i);
|
||||
t_printf("\ti\tgot\twant\n");
|
||||
for (i=0; i<len; i++)
|
||||
t_printf("\t%d\t%s\t%s\n", i, a[i], a_sorted[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void int_test(int *a, int *a_sorted, int len)
|
||||
{
|
||||
int i;
|
||||
qsort(a, len, sizeof *a, icmp);
|
||||
for (i=0; i<len; i++) {
|
||||
if (a[i] != a_sorted[i]) {
|
||||
t_error("integer sort failed at index %d\n", i);
|
||||
t_printf("\ti\tgot\twant\n");
|
||||
for (i=0; i<len; i++)
|
||||
t_printf("\t%d\t%d\t%d\n", i, a[i], a_sorted[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void uint64_gen(uint64_t *p, uint64_t *p_sorted, int n)
|
||||
{
|
||||
int i;
|
||||
uint64_t r = 0;
|
||||
t_randseed(n);
|
||||
for (i = 0; i < n; i++) {
|
||||
r += t_randn(20);
|
||||
p[i] = r;
|
||||
}
|
||||
memcpy(p_sorted, p, n * sizeof *p);
|
||||
t_shuffle(p, n);
|
||||
}
|
||||
|
||||
static void uint64_test(uint64_t *a, uint64_t *a_sorted, int len)
|
||||
{
|
||||
int i;
|
||||
qsort(a, len, sizeof *a, cmp64);
|
||||
for (i=0; i<len; i++) {
|
||||
if (a[i] != a_sorted[i]) {
|
||||
t_error("uint64 sort failed at index %d\n", i);
|
||||
t_printf("\ti\tgot\twant\n");
|
||||
for (i=0; i<len; i++)
|
||||
t_printf("\t%d\t%Ld \t%Ld\n", i, a[i], a_sorted[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define T(a, a_sorted) do { \
|
||||
char p[] = a; \
|
||||
qsort(p, sizeof p - 1, 1, ccmp); \
|
||||
if (memcmp(p, a_sorted, sizeof p) != 0) { \
|
||||
t_error("character sort failed\n"); \
|
||||
t_printf("\tgot: \"%s\"\n", p); \
|
||||
t_printf("\twant: \"%s\"\n", a_sorted); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
static void char_test(void)
|
||||
{
|
||||
T("", "");
|
||||
T("1", "1");
|
||||
T("11", "11");
|
||||
T("12", "12");
|
||||
T("21", "12");
|
||||
T("111", "111");
|
||||
T("211", "112");
|
||||
T("121", "112");
|
||||
T("112", "112");
|
||||
T("221", "122");
|
||||
T("212", "122");
|
||||
T("122", "122");
|
||||
T("123", "123");
|
||||
T("132", "123");
|
||||
T("213", "123");
|
||||
T("231", "123");
|
||||
T("321", "123");
|
||||
T("312", "123");
|
||||
T("1423", "1234");
|
||||
T("51342", "12345");
|
||||
T("261435", "123456");
|
||||
T("4517263", "1234567");
|
||||
T("37245618", "12345678");
|
||||
T("812436597", "123456789");
|
||||
T("987654321", "123456789");
|
||||
T("321321321", "111222333");
|
||||
T("49735862185236174", "11223344556677889");
|
||||
T("1", "This must fail");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
str_test(s, s_sorted, sizeof s/sizeof*s);
|
||||
int_test(n, n_sorted, sizeof n/sizeof*n);
|
||||
char_test();
|
||||
for (i = 1023; i<=1026; i++) {
|
||||
uint64_t p[1026], p_sorted[1026];
|
||||
uint64_gen(p, p_sorted, i);
|
||||
uint64_test(p, p_sorted, i);
|
||||
}
|
||||
return t_status;
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
#include <float.h>
|
||||
|
||||
// TODO: use large period prng
|
||||
static uint64_t seed = -1;
|
||||
static uint32_t rand32(void)
|
||||
{
|
||||
seed = 6364136223846793005ULL*seed + 1;
|
||||
return seed >> 32;
|
||||
}
|
||||
static uint64_t rand64(void)
|
||||
{
|
||||
uint64_t u = rand32();
|
||||
return u<<32 | rand32();
|
||||
}
|
||||
static double frand()
|
||||
{
|
||||
return rand64() * 0x1p-64;
|
||||
}
|
||||
static float frandf()
|
||||
{
|
||||
return rand32() * 0x1p-32f;
|
||||
}
|
||||
static long double frandl()
|
||||
{
|
||||
return rand64() * 0x1p-64L
|
||||
#if LDBL_MANT_DIG > 64
|
||||
+ rand64() * 0x1p-128L
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
void t_randseed(uint64_t s)
|
||||
{
|
||||
seed = s;
|
||||
}
|
||||
|
||||
/* uniform random in [0,n), n > 0 must hold */
|
||||
uint64_t t_randn(uint64_t n)
|
||||
{
|
||||
uint64_t r, m;
|
||||
|
||||
/* m is the largest multiple of n */
|
||||
m = -1;
|
||||
m -= m%n;
|
||||
while ((r = rand64()) >= m);
|
||||
return r%n;
|
||||
}
|
||||
|
||||
/* uniform on [a,b], a <= b must hold */
|
||||
uint64_t t_randint(uint64_t a, uint64_t b)
|
||||
{
|
||||
uint64_t n = b - a + 1;
|
||||
if (n)
|
||||
return a + t_randn(n);
|
||||
return rand64();
|
||||
}
|
||||
|
||||
/* shuffle the elements of p and q until the elements in p are well shuffled */
|
||||
static void shuffle2(uint64_t *p, uint64_t *q, size_t np, size_t nq)
|
||||
{
|
||||
size_t r;
|
||||
uint64_t t;
|
||||
|
||||
while (np) {
|
||||
r = t_randn(nq+np--);
|
||||
t = p[np];
|
||||
if (r < nq) {
|
||||
p[np] = q[r];
|
||||
q[r] = t;
|
||||
} else {
|
||||
p[np] = p[r-nq];
|
||||
p[r-nq] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* shuffle the elements of p */
|
||||
void t_shuffle(uint64_t *p, size_t n)
|
||||
{
|
||||
shuffle2(p,0,n,0);
|
||||
}
|
||||
|
||||
void t_randrange(uint64_t *p, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < n; i++)
|
||||
p[i] = i;
|
||||
t_shuffle(p, n);
|
||||
}
|
||||
|
||||
/* hash table insert, 0 means empty, v > 0 must hold, len is power-of-2 */
|
||||
static int insert(uint64_t *tab, size_t len, uint64_t v)
|
||||
{
|
||||
size_t i = v & (len-1);
|
||||
size_t j = 1;
|
||||
|
||||
while (tab[i]) {
|
||||
if (tab[i] == v)
|
||||
return -1;
|
||||
i += j++;
|
||||
i &= len-1;
|
||||
}
|
||||
tab[i] = v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* choose k unique numbers from [0,n), k <= n */
|
||||
int t_choose(uint64_t n, size_t k, uint64_t *p)
|
||||
{
|
||||
uint64_t *tab;
|
||||
size_t i, j, len;
|
||||
|
||||
if (n < k)
|
||||
return -1;
|
||||
|
||||
if (n < 16) {
|
||||
/* no alloc */
|
||||
while (k)
|
||||
if (t_randn(n--) < k)
|
||||
p[--k] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (k < 8) {
|
||||
/* no alloc, n > 15 > 2*k */
|
||||
for (i = 0; i < k;) {
|
||||
p[i] = t_randn(n);
|
||||
for (j = 0; p[j] != p[i]; j++);
|
||||
if (j == i)
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: if k < n/k use k*log(k) solution without alloc
|
||||
|
||||
if (n < 5*k && (n-k)*sizeof *tab < (size_t)-1) {
|
||||
/* allocation is n-k < 4*k */
|
||||
tab = malloc((n-k) * sizeof *tab);
|
||||
if (!tab)
|
||||
return -1;
|
||||
for (i = 0; i < k; i++)
|
||||
p[i] = i;
|
||||
for (; i < n; i++)
|
||||
tab[i-k] = i;
|
||||
if (k < n-k)
|
||||
shuffle2(p, tab, k, n-k);
|
||||
else
|
||||
shuffle2(tab, p, n-k, k);
|
||||
free(tab);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* allocation is 2*k <= len < 4*k */
|
||||
for (len = 16; len < 2*k; len *= 2);
|
||||
tab = calloc(len, sizeof *tab);
|
||||
if (!tab)
|
||||
return -1;
|
||||
for (i = 0; i < k; i++)
|
||||
while (insert(tab, len, t_randn(n)+1));
|
||||
for (i = 0; i < len; i++)
|
||||
if (tab[i])
|
||||
*p++ = tab[i]-1;
|
||||
free(tab);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
most test adapted from "musl-libctest-master" project
|
||||
some taken from newlib
|
||||
|
||||
Status or libc tests
|
||||
|
||||
---NOT TESTED---
|
||||
no library fns realized
|
||||
qsort
|
||||
strtol
|
||||
time
|
||||
|
||||
---HANG---
|
||||
sscanf
|
||||
>TEST_F(0x1234p56)
|
||||
|
||||
|
||||
---STACK IS SMALL---
|
||||
strtod_long
|
||||
tstring
|
||||
|
||||
|
||||
--other--
|
||||
fscanf
|
||||
-?scanf ignores width specs, '*' and [chars], cant read %a float
|
||||
-%n counts as parameter
|
||||
|
||||
snprintf
|
||||
-some format misturbances
|
||||
|
||||
ungetc
|
||||
-ungetc fails if filepos == 0 - no tricks
|
||||
|
||||
all file ops limited to 2Gb
|
||||
|
@ -1,188 +0,0 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
//#include <errno.h>
|
||||
//#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "test.h"
|
||||
|
||||
#define DISABLE_SLOW_TESTS
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x), 0) )
|
||||
|
||||
#define TEST_S(s, x, m) ( \
|
||||
!strcmp((s),(x)) || \
|
||||
(t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
|
||||
|
||||
static const struct {
|
||||
const char *fmt;
|
||||
int i;
|
||||
const char *expect;
|
||||
} int_tests[] = {
|
||||
/* width, precision, alignment */
|
||||
{ "%04d", 12, "0012" },
|
||||
{ "%.3d", 12, "012" },
|
||||
{ "%3d", 12, " 12" },
|
||||
{ "%-3d", 12, "12 " },
|
||||
{ "%+3d", 12, "+12" },
|
||||
{ "%+-5d", 12, "+12 " },
|
||||
{ "%+- 5d", 12, "+12 " },
|
||||
{ "%- 5d", 12, " 12 " },
|
||||
{ "% d", 12, " 12" },
|
||||
{ "%0-5d", 12, "12 " },
|
||||
{ "%-05d", 12, "12 " },
|
||||
|
||||
/* ...explicit precision of 0 shall be no characters. */
|
||||
{ "%.0d", 0, "" },
|
||||
{ "%.0o", 0, "" },
|
||||
{ "%#.0d", 0, "" },
|
||||
{ "%#.0o", 0, "" },
|
||||
{ "%#.0x", 0, "" },
|
||||
|
||||
/* ...but it still has to honor width and flags. */
|
||||
{ "%2.0u", 0, " " },
|
||||
{ "%02.0u", 0, " " },
|
||||
{ "%2.0d", 0, " " },
|
||||
{ "%02.0d", 0, " " },
|
||||
{ "% .0d", 0, " " },
|
||||
{ "%+.0d", 0, "+" },
|
||||
|
||||
/* hex: test alt form and case */
|
||||
{ "%x", 63, "3f" },
|
||||
{ "%#x", 63, "0x3f" },
|
||||
{ "%X", 63, "3F" },
|
||||
|
||||
/* octal: test alt form */
|
||||
{ "%o", 15, "17" },
|
||||
{ "%#o", 15, "017" },
|
||||
|
||||
{ NULL, 0.0, NULL }
|
||||
};
|
||||
|
||||
static const struct {
|
||||
const char *fmt;
|
||||
double f;
|
||||
const char *expect;
|
||||
} fp_tests[] = {
|
||||
/* basic form, handling of exponent/precision for 0 */
|
||||
{ "%a", 0.0, "0x0p+0" },
|
||||
{ "%e", 0.0, "0.000000e+00" },
|
||||
{ "%f", 0.0, "0.000000" },
|
||||
{ "%g", 0.0, "0" },
|
||||
{ "%#g", 0.0, "0.00000" },
|
||||
{ "%la", 0.0, "0x0p+0" },
|
||||
{ "%le", 0.0, "0.000000e+00" },
|
||||
{ "%lf", 0.0, "0.000000" },
|
||||
{ "%lg", 0.0, "0" },
|
||||
{ "%#lg", 0.0, "0.00000" },
|
||||
|
||||
/* rounding */
|
||||
{ "%f", 1.1, "1.100000" },
|
||||
{ "%f", 1.2, "1.200000" },
|
||||
{ "%f", 1.3, "1.300000" },
|
||||
{ "%f", 1.4, "1.400000" },
|
||||
{ "%f", 1.5, "1.500000" },
|
||||
{ "%.4f", 1.06125, "1.0613" }, /* input is not representible exactly as double */
|
||||
{ "%.4f", 1.03125, "1.0312" }, /* 0x1.08p0 */
|
||||
{ "%.2f", 1.375, "1.38" },
|
||||
{ "%.1f", 1.375, "1.4" },
|
||||
{ "%.1lf", 1.375, "1.4" },
|
||||
{ "%.15f", 1.1, "1.100000000000000" },
|
||||
{ "%.16f", 1.1, "1.1000000000000001" },
|
||||
{ "%.17f", 1.1, "1.10000000000000009" },
|
||||
{ "%.2e", 1500001.0, "1.50e+06" },
|
||||
{ "%.2e", 1505000.0, "1.50e+06" },
|
||||
{ "%.2e", 1505000.00000095367431640625, "1.51e+06" },
|
||||
{ "%.2e", 1505001.0, "1.51e+06" },
|
||||
{ "%.2e", 1506000.0, "1.51e+06" },
|
||||
|
||||
/* correctness in DBL_DIG places */
|
||||
{ "%.15g", 1.23456789012345, "1.23456789012345" },
|
||||
|
||||
/* correct choice of notation for %g */
|
||||
{ "%g", 0.0001, "0.0001" },
|
||||
{ "%g", 0.00001, "1e-05" },
|
||||
{ "%g", 123456, "123456" },
|
||||
{ "%g", 1234567, "1.23457e+06" },
|
||||
{ "%.7g", 1234567, "1234567" },
|
||||
{ "%.7g", 12345678, "1.234568e+07" },
|
||||
{ "%.8g", 0.1, "0.1" },
|
||||
{ "%.9g", 0.1, "0.1" },
|
||||
{ "%.10g", 0.1, "0.1" },
|
||||
{ "%.11g", 0.1, "0.1" },
|
||||
|
||||
/* pi in double precision, printed to a few extra places */
|
||||
{ "%.15f", M_PI, "3.141592653589793" },
|
||||
{ "%.18f", M_PI, "3.141592653589793116" },
|
||||
|
||||
/* exact conversion of large integers */
|
||||
{ "%.0f", 340282366920938463463374607431768211456.0,
|
||||
"340282366920938463463374607431768211456" },
|
||||
|
||||
{ NULL, 0.0, NULL }
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, j, k;
|
||||
char b[2000];
|
||||
|
||||
TEST(i, snprintf(0, 0, "%d", 123456), 6, "length returned %d != %d");
|
||||
TEST(i, snprintf(0, 0, "%.4s", "hello"), 4, "length returned %d != %d");
|
||||
TEST(i, snprintf(b, 0, "%.0s", "goodbye"), 0, "length returned %d != %d");
|
||||
|
||||
strcpy(b, "xxxxxxxx");
|
||||
TEST(i, snprintf(b, 4, "%d", 123456), 6, "length returned %d != %d");
|
||||
TEST_S(b, "123", "incorrect output");
|
||||
TEST(i, b[5], 'x', "buffer overrun");
|
||||
|
||||
/* Perform ascii arithmetic to test printing tiny doubles */
|
||||
TEST(i, snprintf(b, sizeof b, "%.1022f", 0x1p-1021), 1024, "%d != %d");
|
||||
b[1] = '0';
|
||||
for (i=0; i<1021; i++) {
|
||||
for (k=0, j=1023; j>0; j--) {
|
||||
if (b[j]<'5') b[j]+=b[j]-'0'+k, k=0;
|
||||
else b[j]+=b[j]-'0'-10+k, k=1;
|
||||
}
|
||||
}
|
||||
TEST(i, b[1], '1', "'%c' != '%c'");
|
||||
for (j=2; b[j]=='0'; j++);
|
||||
TEST(i, j, 1024, "%d != %d");
|
||||
|
||||
|
||||
#ifndef DISABLE_SLOW_TESTS
|
||||
errno = 0;
|
||||
TEST(i, snprintf(NULL, 0, "%.*u", 2147483647, 0), 2147483647, "cannot print max length %d");
|
||||
TEST(i, snprintf(NULL, 0, "%.*u ", 2147483647, 0), -1, "integer overflow %d");
|
||||
TEST(i, errno, EOVERFLOW, "after overflow: %d != %d");
|
||||
#endif
|
||||
for (j=0; int_tests[j].fmt; j++) {
|
||||
i = snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i);
|
||||
if (i != strlen(int_tests[j].expect)) {
|
||||
t_error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n",
|
||||
int_tests[j].fmt, int_tests[j].i, i, strlen(int_tests[j].expect));
|
||||
}
|
||||
if (strcmp(b, int_tests[j].expect) != 0)
|
||||
t_error("bad integer conversion fmt[%s]: got \"%s\", want \"%s\"\n", int_tests[j].fmt, b, int_tests[j].expect);
|
||||
}
|
||||
|
||||
for (j=0; fp_tests[j].fmt; j++) {
|
||||
i = snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f);
|
||||
if (i != strlen(fp_tests[j].expect)) {
|
||||
t_error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n",
|
||||
fp_tests[j].fmt, fp_tests[j].f, i, strlen(fp_tests[j].expect));
|
||||
}
|
||||
if (strcmp(b, fp_tests[j].expect) != 0)
|
||||
t_error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect);
|
||||
}
|
||||
|
||||
TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d");
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
|
||||
return t_status;
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
//#include <limits.h>
|
||||
#include "test.h"
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x), 0) )
|
||||
|
||||
#define TEST_S(s, x, m) ( \
|
||||
!strcmp((s),(x)) || \
|
||||
(t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
|
||||
|
||||
#define TEST_F(x) ( \
|
||||
TEST(i, sscanf(# x, "%lf", &d), 1, "got %d fields, expected %d"), \
|
||||
TEST(t, d, (double)x, "%g != %g") )
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
char a[100], b[100];
|
||||
int x, y, z, u, v;
|
||||
double d, t;
|
||||
/*
|
||||
TEST(i, sscanf("hello, world\n", "%s %s", a, b), 2, "only %d fields, expected %d");
|
||||
TEST_S(a, "hello,", "");
|
||||
TEST_S(b, "world", "");
|
||||
|
||||
TEST(i, sscanf("hello, world\n", "%[hel]%s", a, b), 2, "only %d fields, expected %d");
|
||||
TEST_S(a, "hell", "");
|
||||
TEST_S(b, "o,", "");
|
||||
|
||||
TEST(i, sscanf("hello, world\n", "%[hel] %s", a, b), 2, "only %d fields, expected %d");
|
||||
TEST_S(a, "hell", "");
|
||||
TEST_S(b, "o,", "");
|
||||
|
||||
a[8] = 'X';
|
||||
a[9] = 0;
|
||||
TEST(i, sscanf("hello, world\n", "%8c%8c", a, b), 1, "%d fields, expected %d");
|
||||
TEST_S(a, "hello, wX", "");
|
||||
*/
|
||||
TEST(i, sscanf("56789 0123 56a72", "%2d%d%*d %[0123456789]\n", &x, &y, a), 3, "only %d fields, expected %d");
|
||||
TEST(i, x, 56, "%d != %d");
|
||||
TEST(i, y, 789, "%d != %d");
|
||||
TEST_S(a, "56", "");
|
||||
|
||||
TEST(i, sscanf("011 0x100 11 0x100 100", "%i %i %o %x %x\n", &x, &y, &z, &u, &v), 5, "only %d fields, expected %d");
|
||||
TEST(i, x, 9, "%d != %d");
|
||||
TEST(i, y, 256, "%d != %d");
|
||||
TEST(i, z, 9, "%d != %d");
|
||||
TEST(i, u, 256, "%d != %d");
|
||||
TEST(i, v, 256, "%d != %d");
|
||||
|
||||
TEST(i, sscanf("20 xyz", "%d %d\n", &x, &y), 1, "only %d fields, expected %d");
|
||||
TEST(i, x, 20, "%d != %d");
|
||||
|
||||
TEST(i, sscanf("xyz", "%d %d\n", &x, &y), 0, "got %d fields, expected no match (%d)");
|
||||
|
||||
TEST(i, sscanf("", "%d %d\n", &x, &y), -1, "got %d fields, expected input failure (%d)");
|
||||
|
||||
TEST(i, sscanf(" 12345 6", "%2d%d%d", &x, &y, &z), 3, "only %d fields, expected %d");
|
||||
TEST(i, x, 12, "%d != %d");
|
||||
TEST(i, y, 345, "%d != %d");
|
||||
TEST(i, z, 6, "%d != %d");
|
||||
|
||||
TEST(i, sscanf(" 0x12 0x34", "%5i%2i", &x, &y), 1, "got %d fields, expected %d");
|
||||
TEST(i, x, 0x12, "%d != %d");
|
||||
|
||||
TEST_F(123);
|
||||
TEST_F(123.0);
|
||||
TEST_F(123.0e+0);
|
||||
TEST_F(123.0e+4);
|
||||
TEST_F(1.234e1234);
|
||||
TEST_F(1.234e-1234);
|
||||
TEST_F(1.234e56789);
|
||||
TEST_F(1.234e-56789);
|
||||
TEST_F(-0.5);
|
||||
TEST_F(0.1);
|
||||
TEST_F(0.2);
|
||||
TEST_F(0.1e-10);
|
||||
// TEST_F(0x1234p56); hangs on
|
||||
|
||||
TEST(i, sscanf("10e", "%lf", &d), 0, "got %d fields, expected no match (%d)");
|
||||
TEST(i, sscanf("", "%lf\n", &d), -1, "got %d fields, expected input failure (%d)");
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,147 +0,0 @@
|
||||
#define _BSD_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "test.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a<b)?a:b)
|
||||
#endif
|
||||
|
||||
size_t strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
int nsrc = strlen(src);
|
||||
strncpy(dst, src, min(size, nsrc+1));
|
||||
if (size > 0 && nsrc >= size)
|
||||
dst[size - 1] = '\0';
|
||||
|
||||
return nsrc;
|
||||
}
|
||||
|
||||
size_t strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
int ndest = strlen(dst);
|
||||
int nsrc = strlen(src);
|
||||
if (size > ndest + 1)
|
||||
{
|
||||
strncat(dst, src, size - ndest - 1);
|
||||
if (size > 0 && nsrc + ndest >= size)
|
||||
dst[size - 1] = '\0';
|
||||
}
|
||||
|
||||
return nsrc + ndest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* r = place to store result
|
||||
* f = function call to test (or any expression)
|
||||
* x = expected result
|
||||
* m = message to print on failure (with formats for r & x)
|
||||
**/
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x), 0) )
|
||||
|
||||
#define TEST_S(s, x, m) ( \
|
||||
!strcmp((s),(x)) || \
|
||||
(t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char b[32];
|
||||
char *s;
|
||||
int i;
|
||||
|
||||
b[16]='a'; b[17]='b'; b[18]='c'; b[19]=0;
|
||||
TEST(s, strcpy(b, b+16), b, "wrong return %p != %p");
|
||||
TEST_S(s, "abc", "strcpy gave incorrect string");
|
||||
TEST(s, strcpy(b+1, b+16), b+1, "wrong return %p != %p");
|
||||
TEST_S(s, "abc", "strcpy gave incorrect string");
|
||||
TEST(s, strcpy(b+2, b+16), b+2, "wrong return %p != %p");
|
||||
TEST_S(s, "abc", "strcpy gave incorrect string");
|
||||
TEST(s, strcpy(b+3, b+16), b+3, "wrong return %p != %p");
|
||||
TEST_S(s, "abc", "strcpy gave incorrect string");
|
||||
|
||||
TEST(s, strcpy(b+1, b+17), b+1, "wrong return %p != %p");
|
||||
TEST_S(s, "bc", "strcpy gave incorrect string");
|
||||
TEST(s, strcpy(b+2, b+18), b+2, "wrong return %p != %p");
|
||||
TEST_S(s, "c", "strcpy gave incorrect string");
|
||||
TEST(s, strcpy(b+3, b+19), b+3, "wrong return %p != %p");
|
||||
TEST_S(s, "", "strcpy gave incorrect string");
|
||||
|
||||
TEST(s, memset(b, 'x', sizeof b), b, "wrong return %p != %p");
|
||||
TEST(s, strncpy(b, "abc", sizeof b - 1), b, "wrong return %p != %p");
|
||||
TEST(i, memcmp(b, "abc\0\0\0\0", 8), 0, "strncpy fails to zero-pad dest");
|
||||
TEST(i, b[sizeof b - 1], 'x', "strncpy overruns buffer when n > strlen(src)");
|
||||
|
||||
b[3] = 'x'; b[4] = 0;
|
||||
strncpy(b, "abc", 3);
|
||||
TEST(i, b[2], 'c', "strncpy fails to copy last byte: %hhu != %hhu");
|
||||
TEST(i, b[3], 'x', "strncpy overruns buffer to null-terminate: %hhu != %hhu");
|
||||
|
||||
TEST(i, !strncmp("abcd", "abce", 3), 1, "strncmp compares past n");
|
||||
TEST(i, !!strncmp("abc", "abd", 3), 1, "strncmp fails to compare n-1st byte");
|
||||
|
||||
strcpy(b, "abc");
|
||||
TEST(s, strncat(b, "123456", 3), b, "%p != %p");
|
||||
TEST(i, b[6], 0, "strncat failed to null-terminate (%d)");
|
||||
TEST_S(s, "abc123", "strncat gave incorrect string");
|
||||
|
||||
strcpy(b, "aaababccdd0001122223");
|
||||
TEST(s, strchr(b, 'b'), b+3, "%p != %p");
|
||||
TEST(s, strrchr(b, 'b'), b+5, "%p != %p");
|
||||
TEST(i, strspn(b, "abcd"), 10, "%d != %d");
|
||||
TEST(i, strcspn(b, "0123"), 10, "%d != %d");
|
||||
TEST(s, strpbrk(b, "0123"), b+10, "%d != %d");
|
||||
|
||||
strcpy(b, "abc 123; xyz; foo");
|
||||
TEST(s, strtok(b, " "), b, "%p != %p");
|
||||
TEST_S(s, "abc", "strtok result");
|
||||
|
||||
TEST(s, strtok(NULL, ";"), b+4, "%p != %p");
|
||||
TEST_S(s, " 123", "strtok result");
|
||||
|
||||
TEST(s, strtok(NULL, " ;"), b+11, "%p != %p");
|
||||
TEST_S(s, "xyz", "strtok result");
|
||||
|
||||
TEST(s, strtok(NULL, " ;"), b+16, "%p != %p");
|
||||
TEST_S(s, "foo", "strtok result");
|
||||
|
||||
memset(b, 'x', sizeof b);
|
||||
TEST(i, strlcpy(b, "abc", sizeof b - 1), 3, "length %d != %d");
|
||||
TEST(i, b[3], 0, "strlcpy did not null-terminate short string (%d)");
|
||||
TEST(i, b[4], 'x', "strlcpy wrote extra bytes (%d)");
|
||||
|
||||
memset(b, 'x', sizeof b);
|
||||
TEST(i, strlcpy(b, "abc", 2), 3, "length %d != %d");
|
||||
TEST(i, b[0], 'a', "strlcpy did not copy character %d");
|
||||
TEST(i, b[1], 0, "strlcpy did not null-terminate long string (%d)");
|
||||
|
||||
memset(b, 'x', sizeof b);
|
||||
TEST(i, strlcpy(b, "abc", 3), 3, "length %d != %d");
|
||||
TEST(i, b[2], 0, "strlcpy did not null-terminate l-length string (%d)");
|
||||
|
||||
TEST(i, strlcpy(NULL, "abc", 0), 3, "length %d != %d");
|
||||
|
||||
memcpy(b, "abc\0\0\0x\0", 8);
|
||||
TEST(i, strlcat(b, "123", sizeof b), 6, "length %d != %d");
|
||||
TEST_S(b, "abc123", "strlcat result");
|
||||
|
||||
memcpy(b, "abc\0\0\0x\0", 8);
|
||||
TEST(i, strlcat(b, "123", 6), 6, "length %d != %d");
|
||||
TEST_S(b, "abc12", "strlcat result");
|
||||
TEST(i, b[6], 'x', "strlcat wrote past string %d != %d");
|
||||
|
||||
memcpy(b, "abc\0\0\0x\0", 8);
|
||||
TEST(i, strlcat(b, "123", 4), 6, "length %d != %d");
|
||||
TEST_S(b, "abc", "strlcat result");
|
||||
|
||||
memcpy(b, "abc\0\0\0x\0", 8);
|
||||
TEST(i, strlcat(b, "123", 3), 6, "length %d != %d");
|
||||
TEST_S(b, "abc", "strlcat result");
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdint.h>
|
||||
#include "test.h"
|
||||
|
||||
static char buf[512];
|
||||
|
||||
static void *(*volatile pmemcpy)(void *restrict, const void *restrict2, size_t);
|
||||
|
||||
static void *aligned(void *p) {
|
||||
return (void*)(((uintptr_t)p + 63) & -64U);
|
||||
}
|
||||
|
||||
#define N 80
|
||||
static void test_align(int dalign, int salign, int len)
|
||||
{
|
||||
char *src = aligned(buf);
|
||||
char *dst = aligned(buf + 128);
|
||||
char *want = aligned(buf + 256);
|
||||
char *p;
|
||||
int i;
|
||||
|
||||
if (salign + len > N || dalign + len > N)
|
||||
abort();
|
||||
for (i = 0; i < N; i++) {
|
||||
src[i] = '#';
|
||||
dst[i] = want[i] = ' ';
|
||||
}
|
||||
for (i = 0; i < len; i++)
|
||||
src[salign+i] = want[dalign+i] = '0'+i;
|
||||
p = pmemcpy(dst+dalign, src+salign, len);
|
||||
if (p != dst+dalign)
|
||||
t_error("memcpy(%p,...) returned %p\n", dst+dalign, p);
|
||||
for (i = 0; i < N; i++)
|
||||
if (dst[i] != want[i]) {
|
||||
t_error("memcpy(align %d, align %d, %d) failed\n", dalign, salign, len);
|
||||
t_printf("got : %.*s\n", dalign+len+1, dst);
|
||||
t_printf("want: %.*s\n", dalign+len+1, want);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i,j,k;
|
||||
|
||||
pmemcpy = memcpy;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
for (j = 0; j < 16; j++)
|
||||
for (k = 0; k < 64; k++)
|
||||
test_align(i,j,k);
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
//#include <stdint.h>
|
||||
#include "test.h"
|
||||
|
||||
static char buf[512];
|
||||
|
||||
static void *(*volatile pmemset)(void *, int, size_t);
|
||||
|
||||
static void *aligned(void *p)
|
||||
{
|
||||
return (void*)(((uintptr_t)p + 63) & -64U);
|
||||
}
|
||||
|
||||
#define N 80
|
||||
static void test_align(int align, int len)
|
||||
{
|
||||
char *s = aligned(buf);
|
||||
char *want = aligned(buf + 256);
|
||||
char *p;
|
||||
int i;
|
||||
|
||||
if (align + len > N)
|
||||
abort();
|
||||
for (i = 0; i < N; i++)
|
||||
s[i] = want[i] = ' ';
|
||||
for (i = 0; i < len; i++)
|
||||
want[align+i] = '#';
|
||||
p = pmemset(s+align, '#', len);
|
||||
if (p != s+align)
|
||||
t_error("memset(%p,...) returned %p\n", s+align, p);
|
||||
for (i = 0; i < N; i++)
|
||||
if (s[i] != want[i]) {
|
||||
t_error("memset(align %d, '#', %d) failed\n", align, len);
|
||||
t_printf("got : %.*s\n", align+len+1, s);
|
||||
t_printf("want: %.*s\n", align+len+1, want);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_value(int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
pmemset(buf, c, 10);
|
||||
for (i = 0; i < 10; i++)
|
||||
if ((unsigned char)buf[i] != (unsigned char)c) {
|
||||
t_error("memset(%d) failed: got %d\n", c, buf[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i,j,k;
|
||||
|
||||
pmemset = memset;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
for (j = 0; j < 64; j++)
|
||||
test_align(i,j);
|
||||
|
||||
test_value('c');
|
||||
test_value(0);
|
||||
test_value(-1);
|
||||
test_value(-5);
|
||||
test_value(0xab);
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "test.h"
|
||||
|
||||
#define N(s, c) { \
|
||||
char *p = s; \
|
||||
char *q = strchr(p, c); \
|
||||
if (q) \
|
||||
t_error("strchr(%s,%s) returned str+%d, wanted 0\n", #s, #c, q-p); \
|
||||
}
|
||||
|
||||
#define T(s, c, n) { \
|
||||
char *p = s; \
|
||||
char *q = strchr(p, c); \
|
||||
if (q == 0) \
|
||||
t_error("strchr(%s,%s) returned 0, wanted str+%d\n", #s, #c, n); \
|
||||
else if (q - p != n) \
|
||||
t_error("strchr(%s,%s) returned str+%d, wanted str+%d\n", #s, #c, q-p, n); \
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
char a[128];
|
||||
char s[256];
|
||||
|
||||
for (i = 0; i < 128; i++)
|
||||
a[i] = (i+1) & 127;
|
||||
for (i = 0; i < 256; i++)
|
||||
*((unsigned char*)s+i) = i+1;
|
||||
|
||||
N("", 'a')
|
||||
N("a", 'b')
|
||||
N("abc abc", 'x')
|
||||
N(a, 128)
|
||||
N(a, 255)
|
||||
|
||||
T("", 0, 0)
|
||||
T("a", 'a', 0)
|
||||
T("a", 'a'+256, 0)
|
||||
T("a", 0, 1)
|
||||
T("ab", 'b', 1)
|
||||
T("aab", 'b', 2)
|
||||
T("aaab", 'b', 3)
|
||||
T("aaaab", 'b', 4)
|
||||
T("aaaaab", 'b', 5)
|
||||
T("aaaaaab", 'b', 6)
|
||||
T("abc abc", 'c', 2)
|
||||
T(s, 1, 0)
|
||||
T(s, 2, 1)
|
||||
T(s, 10, 9)
|
||||
T(s, 11, 10)
|
||||
T(s, 127, 126)
|
||||
T(s, 128, 127)
|
||||
T(s, 255, 254)
|
||||
T(s, 0, 255)
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "test.h"
|
||||
|
||||
#define T(s, c, n) { \
|
||||
char *p = s; \
|
||||
char *q = c; \
|
||||
size_t r = strcspn(p, q); \
|
||||
if (r != n) \
|
||||
t_error("strcspn(%s,%s) returned %lu, wanted %lu\n", #s, #c, (unsigned long)r, (unsigned long)(n)); \
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
char a[128];
|
||||
char s[256];
|
||||
|
||||
for (i = 0; i < 128; i++)
|
||||
a[i] = (i+1) & 127;
|
||||
for (i = 0; i < 256; i++)
|
||||
*((unsigned char*)s+i) = i+1;
|
||||
|
||||
T("", "", 0)
|
||||
T("a", "", 1)
|
||||
T("", "a", 0)
|
||||
T("abc", "cde", 2)
|
||||
T("abc", "ccc", 2)
|
||||
T("abc", a, 0)
|
||||
T("\xff\x80 abc", a, 2)
|
||||
T(s, "\xff", 254)
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "test.h"
|
||||
|
||||
#define N(s, sub) { \
|
||||
char *p = s; \
|
||||
char *q = strstr(p, sub); \
|
||||
if (q) \
|
||||
t_error("strstr(%s,%s) returned str+%d, wanted 0\n", #s, #sub, q-p); \
|
||||
}
|
||||
|
||||
#define T(s, sub, n) { \
|
||||
char *p = s; \
|
||||
char *q = strstr(p, sub); \
|
||||
if (q == 0) \
|
||||
t_error("strstr(%s,%s) returned 0, wanted str+%d\n", #s, #sub, n); \
|
||||
else if (q - p != n) \
|
||||
t_error("strstr(%s,%s) returned str+%d, wanted str+%d\n", #s, #sub, q-p, n); \
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
N("", "a")
|
||||
N("a", "aa")
|
||||
N("a", "b")
|
||||
N("aa", "ab")
|
||||
N("aa", "aaa")
|
||||
N("abba", "aba")
|
||||
N("abc abc", "abcd")
|
||||
N("0-1-2-3-4-5-6-7-8-9", "-3-4-56-7-8-")
|
||||
N("0-1-2-3-4-5-6-7-8-9", "-3-4-5+6-7-8-")
|
||||
N("_ _ _\xff_ _ _", "_\x7f_")
|
||||
N("_ _ _\x7f_ _ _", "_\xff_")
|
||||
|
||||
T("", "", 0)
|
||||
T("abcd", "", 0)
|
||||
T("abcd", "a", 0)
|
||||
T("abcd", "b", 1)
|
||||
T("abcd", "c", 2)
|
||||
T("abcd", "d", 3)
|
||||
T("abcd", "ab", 0)
|
||||
T("abcd", "bc", 1)
|
||||
T("abcd", "cd", 2)
|
||||
T("ababa", "baba", 1)
|
||||
T("ababab", "babab", 1)
|
||||
T("abababa", "bababa", 1)
|
||||
T("abababab", "bababab", 1)
|
||||
T("ababababa", "babababa", 1)
|
||||
T("nanabanabanana", "aba", 3)
|
||||
T("nanabanabanana", "ban", 4)
|
||||
T("nanabanabanana", "anab", 1)
|
||||
T("nanabanabanana", "banana", 8)
|
||||
T("_ _\xff_ _", "_\xff_", 2)
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "test.h"
|
||||
|
||||
#define length(x) (sizeof(x) / sizeof *(x))
|
||||
|
||||
static struct {
|
||||
char *s;
|
||||
double f;
|
||||
} t[] = {
|
||||
{"0", 0.0},
|
||||
{"00.00", 0.0},
|
||||
{"-.00000", -0.0},
|
||||
{"1e+1000000", INFINITY},
|
||||
{"1e-1000000", 0},
|
||||
// 2^-1074 * 0.5 - eps
|
||||
{".2470328229206232720882843964341106861825299013071623822127928412503377536351043e-323", 0},
|
||||
// 2^-1074 * 0.5 + eps
|
||||
{".2470328229206232720882843964341106861825299013071623822127928412503377536351044e-323", 0x1p-1074},
|
||||
// 2^-1074 * 1.5 - eps
|
||||
{".7410984687618698162648531893023320585475897039214871466383785237510132609053131e-323", 0x1p-1074},
|
||||
// 2^-1074 * 1.5 + eps
|
||||
{".7410984687618698162648531893023320585475897039214871466383785237510132609053132e-323", 0x1p-1073},
|
||||
// 2^-1022 + 2^-1075 - eps
|
||||
{".2225073858507201630123055637955676152503612414573018013083228724049586647606759e-307", 0x1p-1022},
|
||||
// 2^-1022 + 2^-1075 + eps
|
||||
{".2225073858507201630123055637955676152503612414573018013083228724049586647606760e-307", 0x1.0000000000001p-1022},
|
||||
// 2^1024 - 2^970 - eps
|
||||
{"17976931348623158079372897140530341507993413271003782693617377898044"
|
||||
"49682927647509466490179775872070963302864166928879109465555478519404"
|
||||
"02630657488671505820681908902000708383676273854845817711531764475730"
|
||||
"27006985557136695962284291481986083493647529271907416844436551070434"
|
||||
"2711559699508093042880177904174497791.999999999999999999999999999999", 0x1.fffffffffffffp1023},
|
||||
// 2^1024 - 2^970
|
||||
{"17976931348623158079372897140530341507993413271003782693617377898044"
|
||||
"49682927647509466490179775872070963302864166928879109465555478519404"
|
||||
"02630657488671505820681908902000708383676273854845817711531764475730"
|
||||
"27006985557136695962284291481986083493647529271907416844436551070434"
|
||||
"2711559699508093042880177904174497792", INFINITY},
|
||||
// some random numbers
|
||||
{".5961860348131807091861002266453941950428e00", 0.59618603481318067}, // 0x1.313f4bc3b584cp-1
|
||||
{"1.815013169218038729887460898733526957442e-1", 0.18150131692180388}, // 0x1.73b6f662e1712p-3
|
||||
{"42.07082357534453600681618685682257590772e-2", 0.42070823575344535}, // 0x1.aece23c6e028dp-2
|
||||
{"665.4686306516261456328973225579833470816e-3", 0.66546863065162609}, // 0x1.54b84dea53453p-1
|
||||
{"6101.852922970868621786690495485449831753e-4", 0.61018529229708685}, // 0x1.386a34e5d516bp-1
|
||||
{"76966.95208236968077849464348875471158549e-5", 0.76966952082369677}, // 0x1.8a121f9954dfap-1
|
||||
{"250506.5322228682496132604807222923702304e-6", 0.25050653222286823}, // 0x1.0084c8cd538c2p-2
|
||||
{"2740037.230228005325852424697698331177377e-7", 0.27400372302280052}, // 0x1.18946e9575ef4p-2
|
||||
{"20723093.50049742645941529268715428324490e-8", 0.20723093500497428}, // 0x1.a868b14486e4dp-3
|
||||
{"0.7900280238081604956226011047460238748912e1", 7.9002802380816046}, // 0x1.f99e3100f2eaep+2
|
||||
{"0.9822860653737296848190558448760465863597e2", 98.228606537372968}, // 0x1.88ea17d506accp+6
|
||||
{"0.7468949723190370809405570560160405324869e3", 746.89497231903704}, // 0x1.75728e73f48b7p+9
|
||||
{"0.1630268320282728475980459844271031751665e4", 1630.2683202827284}, // 0x1.97912c28d5cbp+10
|
||||
{"0.4637168629719170695109918769645492022088e5", 46371.686297191707}, // 0x1.6a475f6258737p+15
|
||||
{"0.6537805944497711554209461686415872067523e6", 653780.59444977110}, // 0x1.3f3a9305bb86cp+19
|
||||
{"0.2346324356502437045212230713960457676531e6", 234632.43565024371}, // 0x1.ca4437c3631eap+17
|
||||
{"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26
|
||||
{"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
double x;
|
||||
char *p;
|
||||
|
||||
for (i = 0; i < length(t); i++) {
|
||||
x = strtod(t[i].s, &p);
|
||||
if (x != t[i].f)
|
||||
t_error("strtod(\"%s\") want %a got %a\n", t[i].s, t[i].f, x);
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "test.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
double x, want = .1111111111111111111111;
|
||||
char buf[40000];
|
||||
|
||||
memset(buf, '1', sizeof buf);
|
||||
buf[0] = '.';
|
||||
buf[sizeof buf - 1] = 0;
|
||||
|
||||
if ((x=strtod(buf, 0)) != want)
|
||||
t_error("strtod(.11[...]1) got %.18f want %.18f\n", x, want);
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "test.h"
|
||||
|
||||
/* r = place to store result
|
||||
* f = function call to test (or any expression)
|
||||
* x = expected result
|
||||
* m = message to print on failure (with formats for r & x)
|
||||
*/
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
double d, d2;
|
||||
char buf[1000];
|
||||
|
||||
for (i=0; i<100; i++) {
|
||||
d = sin(i);
|
||||
snprintf(buf, sizeof buf, "%.300f", d);
|
||||
TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
|
||||
}
|
||||
|
||||
TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
|
||||
TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "test.h"
|
||||
|
||||
#define length(x) (sizeof(x) / sizeof *(x))
|
||||
|
||||
static struct {
|
||||
char *s;
|
||||
float f;
|
||||
} t[] = {
|
||||
// 2^-149 * 0.5 - eps
|
||||
{".7006492321624085354618647916449580656401309709382578858785341419448955413429303e-45", 0},
|
||||
// 2^-149 * 0.5 + eps
|
||||
{".7006492321624085354618647916449580656401309709382578858785341419448955413429304e-45", 0x1p-149},
|
||||
// 2^-149 * 0.5 - eps
|
||||
{".2101947696487225606385594374934874196920392912814773657635602425834686624028790e-44", 0x1p-149},
|
||||
// 2^-149 * 0.5 + eps
|
||||
{".2101947696487225606385594374934874196920392912814773657635602425834686624028791e-44", 0x1p-148},
|
||||
// 2^-126 + 2^-150 - eps
|
||||
{".1175494420887210724209590083408724842314472120785184615334540294131831453944281e-37", 0x1p-126},
|
||||
// 2^-126 + 2^-150 + eps
|
||||
{".1175494420887210724209590083408724842314472120785184615334540294131831453944282e-37", 0x1.000002p-126},
|
||||
// 2^128 - 2^103 - eps
|
||||
{"340282356779733661637539395458142568447.9999999999999999999", 0x1.fffffep127},
|
||||
// 2^128 - 2^103
|
||||
{"340282356779733661637539395458142568448", INFINITY},
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
float x;
|
||||
char *p;
|
||||
|
||||
for (i = 0; i < length(t); i++) {
|
||||
x = strtof(t[i].s, &p);
|
||||
if (x != t[i].f)
|
||||
t_error("strtof(\"%s\") want %a got %a\n", t[i].s, t[i].f, x);
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <errno.h>
|
||||
#include "test.h"
|
||||
|
||||
/* r = place to store result
|
||||
* f = function call to test (or any expression)
|
||||
* x = expected result
|
||||
* m = message to print on failure (with formats for r & x)
|
||||
**/
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
errno = 0, msg = #f, ((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x), 0) )
|
||||
|
||||
#define TEST2(r, f, x, m) ( \
|
||||
((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", msg, r, x), 0) )
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
long l;
|
||||
unsigned long ul;
|
||||
char *msg="";
|
||||
char *s, *c;
|
||||
|
||||
TEST(l, atol("2147483647"), 2147483647L, "max 32bit signed %ld != %ld");
|
||||
TEST(l, strtol("2147483647", 0, 0), 2147483647L, "max 32bit signed %ld != %ld");
|
||||
TEST(ul, strtoul("4294967295", 0, 0), 4294967295UL, "max 32bit unsigned %lu != %lu");
|
||||
|
||||
if (sizeof(long) == 4) {
|
||||
TEST(l, strtol(s="2147483648", &c, 0), 2147483647L, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c-s, 10, "wrong final position %d != %d");
|
||||
TEST2(i, errno, ERANGE, "missing errno %d != %d");
|
||||
TEST(l, strtol(s="-2147483649", &c, 0), -2147483647L-1, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c-s, 11, "wrong final position %d != %d");
|
||||
TEST2(i, errno, ERANGE, "missing errno %d != %d");
|
||||
TEST(ul, strtoul(s="4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
|
||||
TEST2(i, c-s, 10, "wrong final position %d != %d");
|
||||
TEST2(i, errno, ERANGE, "missing errno %d != %d");
|
||||
TEST(ul, strtoul(s="-1", &c, 0), -1UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c-s, 2, "wrong final position %d != %d");
|
||||
TEST2(i, errno, 0, "spurious errno %d != %d");
|
||||
TEST(ul, strtoul(s="-2", &c, 0), -2UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c-s, 2, "wrong final position %d != %d");
|
||||
TEST2(i, errno, 0, "spurious errno %d != %d");
|
||||
TEST(ul, strtoul(s="-2147483648", &c, 0), -2147483648UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c-s, 11, "wrong final position %d != %d");
|
||||
TEST2(i, errno, 0, "spurious errno %d != %d");
|
||||
TEST(ul, strtoul(s="-2147483649", &c, 0), -2147483649UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c-s, 11, "wrong final position %d != %d");
|
||||
TEST2(i, errno, 0, "spurious errno %d != %d");
|
||||
} else {
|
||||
TEST(i, 0, 1, "64bit tests not implemented");
|
||||
}
|
||||
|
||||
TEST(l, strtol("z", 0, 36), 35, "%ld != %ld");
|
||||
TEST(l, strtol("00010010001101000101011001111000", 0, 2), 0x12345678, "%ld != %ld");
|
||||
TEST(l, strtol(s="0F5F", &c, 16), 0x0f5f, "%ld != %ld");
|
||||
|
||||
TEST(l, strtol(s="0xz", &c, 16), 0, "%ld != %ld");
|
||||
TEST2(i, c-s, 1, "wrong final position %ld != %ld");
|
||||
|
||||
TEST(l, strtol(s="0x1234", &c, 16), 0x1234, "%ld != %ld");
|
||||
TEST2(i, c-s, 6, "wrong final position %ld != %ld");
|
||||
|
||||
c = NULL;
|
||||
TEST(l, strtol(s="123", &c, 37), 0, "%ld != %ld");
|
||||
TEST2(i, c-s, 0, "wrong final position %d != %d");
|
||||
TEST2(i, errno, EINVAL, "%d != %d");
|
||||
|
||||
TEST(l, strtol(s=" 15437", &c, 8), 015437, "%ld != %ld");
|
||||
TEST2(i, c-s, 7, "wrong final position %d != %d");
|
||||
|
||||
TEST(l, strtol(s=" 1", &c, 0), 1, "%ld != %ld");
|
||||
TEST2(i, c-s, 3, "wrong final position %d != %d");
|
||||
return t_status;
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include "test.h"
|
||||
|
||||
#define length(x) (sizeof(x) / sizeof *(x))
|
||||
|
||||
static struct {
|
||||
char *s;
|
||||
long double f;
|
||||
} t[] = {
|
||||
{"0", 0.0},
|
||||
{"12.345", 12.345L},
|
||||
{"1.2345e1", 12.345L},
|
||||
{"1e+1000000", INFINITY},
|
||||
{"1e-1000000", 0},
|
||||
#if LDBL_MANT_DIG == 53
|
||||
// 2^-1074 * 0.5 - eps
|
||||
{".2470328229206232720882843964341106861825299013071623822127928412503377536351043e-323", 0},
|
||||
// 2^-1074 * 0.5 + eps
|
||||
{".2470328229206232720882843964341106861825299013071623822127928412503377536351044e-323", 0x1p-1074},
|
||||
// 2^-1074 * 1.5 - eps
|
||||
{".7410984687618698162648531893023320585475897039214871466383785237510132609053131e-323", 0x1p-1074},
|
||||
// 2^-1074 * 1.5 + eps
|
||||
{".7410984687618698162648531893023320585475897039214871466383785237510132609053132e-323", 0x1p-1073},
|
||||
// 2^-1022 + 2^-1075 - eps
|
||||
{".2225073858507201630123055637955676152503612414573018013083228724049586647606759e-307", 0x1p-1022},
|
||||
// 2^-1022 + 2^-1075 + eps
|
||||
{".2225073858507201630123055637955676152503612414573018013083228724049586647606760e-307", 0x1.0000000000001p-1022},
|
||||
// 2^1024 - 2^970 - eps
|
||||
{"17976931348623158079372897140530341507993413271003782693617377898044"
|
||||
"49682927647509466490179775872070963302864166928879109465555478519404"
|
||||
"02630657488671505820681908902000708383676273854845817711531764475730"
|
||||
"27006985557136695962284291481986083493647529271907416844436551070434"
|
||||
"2711559699508093042880177904174497791.999999999999999999999999999999", 0x1.fffffffffffffp1023},
|
||||
// 2^1024 - 2^970
|
||||
{"17976931348623158079372897140530341507993413271003782693617377898044"
|
||||
"49682927647509466490179775872070963302864166928879109465555478519404"
|
||||
"02630657488671505820681908902000708383676273854845817711531764475730"
|
||||
"27006985557136695962284291481986083493647529271907416844436551070434"
|
||||
"2711559699508093042880177904174497792", INFINITY},
|
||||
// some random numbers
|
||||
{".5961860348131807091861002266453941950428e00", 0.59618603481318067}, // 0x1.313f4bc3b584cp-1
|
||||
{"1.815013169218038729887460898733526957442e-1", 0.18150131692180388}, // 0x1.73b6f662e1712p-3
|
||||
{"42.07082357534453600681618685682257590772e-2", 0.42070823575344535}, // 0x1.aece23c6e028dp-2
|
||||
{"665.4686306516261456328973225579833470816e-3", 0.66546863065162609}, // 0x1.54b84dea53453p-1
|
||||
{"6101.852922970868621786690495485449831753e-4", 0.61018529229708685}, // 0x1.386a34e5d516bp-1
|
||||
{"76966.95208236968077849464348875471158549e-5", 0.76966952082369677}, // 0x1.8a121f9954dfap-1
|
||||
{"250506.5322228682496132604807222923702304e-6", 0.25050653222286823}, // 0x1.0084c8cd538c2p-2
|
||||
{"2740037.230228005325852424697698331177377e-7", 0.27400372302280052}, // 0x1.18946e9575ef4p-2
|
||||
{"20723093.50049742645941529268715428324490e-8", 0.20723093500497428}, // 0x1.a868b14486e4dp-3
|
||||
{"0.7900280238081604956226011047460238748912e1", 7.9002802380816046}, // 0x1.f99e3100f2eaep+2
|
||||
{"0.9822860653737296848190558448760465863597e2", 98.228606537372968}, // 0x1.88ea17d506accp+6
|
||||
{"0.7468949723190370809405570560160405324869e3", 746.89497231903704}, // 0x1.75728e73f48b7p+9
|
||||
{"0.1630268320282728475980459844271031751665e4", 1630.2683202827284}, // 0x1.97912c28d5cbp+10
|
||||
{"0.4637168629719170695109918769645492022088e5", 46371.686297191707}, // 0x1.6a475f6258737p+15
|
||||
{"0.6537805944497711554209461686415872067523e6", 653780.59444977110}, // 0x1.3f3a9305bb86cp+19
|
||||
{"0.2346324356502437045212230713960457676531e6", 234632.43565024371}, // 0x1.ca4437c3631eap+17
|
||||
{"0.9709481716420048341897258980454298205278e8", 97094817.164200485}, // 0x1.7263284a8242cp+26
|
||||
{"0.4996908522051874110779982354932499499602e9", 499690852.20518744}, // 0x1.dc8ad6434872ap+28
|
||||
#elif LDBL_MANT_DIG == 64
|
||||
// 2^-16445 * 0.5 - eps
|
||||
{".1822599765941237301264202966809709908199525407846781671860490243514185844316698e-4950", 0},
|
||||
// 2^-16445 * 0.5 + eps
|
||||
{".1822599765941237301264202966809709908199525407846781671860490243514185844316699e-4950", 0x1p-16445L},
|
||||
// 2^-16445 * 1.5 - eps
|
||||
{".5467799297823711903792608900429129724598576223540345015581470730542557532950096e-4950", 0x1p-16445L},
|
||||
// 2^-16445 * 1.5 + eps
|
||||
{".5467799297823711903792608900429129724598576223540345015581470730542557532950097e-4950", 0x1p-16444L},
|
||||
// 2^-16382 + 2^-16446 - eps
|
||||
{".3362103143112093506444937793915876332724499641527442230928779770593420866576777e-4931", 0x1p-16382L},
|
||||
// 2^-16382 + 2^-16446 + eps
|
||||
{".3362103143112093506444937793915876332724499641527442230928779770593420866576778e-4931", 0x1.0000000000000002p-16382L},
|
||||
// 2^16384 - 2^16319 - eps
|
||||
{"118973149535723176505351158982948.86679662540046955672e4900", 0x1.fffffffffffffffep16383L},
|
||||
// 2^16384 - 2^16319 + eps
|
||||
{"118973149535723176505351158982948.86679662540046955673e4900", INFINITY},
|
||||
#endif
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
long double x;
|
||||
char *p;
|
||||
|
||||
for (i = 0; i < length(t); i++) {
|
||||
x = strtold(t[i].s, &p);
|
||||
if (x != t[i].f)
|
||||
t_error("strtold(\"%s\") want %La got %La\n", t[i].s, t[i].f, x);
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __GNUC__
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* TODO: not thread-safe nor fork-safe */
|
||||
extern volatile int t_status;
|
||||
|
||||
#define T_LOC2(l) __FILE__ ":" #l
|
||||
#define T_LOC1(l) T_LOC2(l)
|
||||
#define t_error(...) t_printf(T_LOC1(__LINE__) ": " __VA_ARGS__)
|
||||
|
||||
int t_printf(const char *s, ...);
|
||||
|
||||
int t_vmfill(void **, size_t *, int);
|
||||
int t_memfill(void);
|
||||
|
||||
void t_fdfill(void);
|
||||
|
||||
void t_randseed(uint64_t s);
|
||||
uint64_t t_randn(uint64_t n);
|
||||
uint64_t t_randint(uint64_t a, uint64_t b);
|
||||
void t_shuffle(uint64_t *p, size_t n);
|
||||
void t_randrange(uint64_t *p, size_t n);
|
||||
int t_choose(uint64_t n, size_t k, uint64_t *p);
|
||||
|
||||
char *t_pathrel(char *buf, size_t n, char *argv0, char *p);
|
||||
|
||||
int t_setrlim(int r, long lim);
|
||||
|
||||
#include "print.inc"
|
||||
#include "rand.inc"
|
@ -1,41 +0,0 @@
|
||||
//#include <tgmath.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "test.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long i;
|
||||
/*
|
||||
i = lrint(123456789.1f) & 0x7fffffff;
|
||||
if (i != 123456792)
|
||||
t_error("lrint(123456789.1f)&0x7fffffff want 123456792 got %ld\n", i);
|
||||
i = lrint(123456789.1) & 0x7fffffff;
|
||||
if (i != 123456789)
|
||||
t_error("lrint(123456789.1)&0x7fffffff want 123456789 got %ld\n", i);
|
||||
*/
|
||||
if (sqrt(2.0f) != 1.41421353816986083984375)
|
||||
t_error("sqrt(2.0f) want 1.41421353816986083984375 got %f\n", sqrt(2.0f));
|
||||
if (sqrt(2.0) != 1.414213562373095145474621858738828450441360)
|
||||
t_error("sqrt(2.0) want 1.414213562373095145474621858738828450441360 got %d\n", sqrt(2.0));
|
||||
if (sqrt(2) != 1.414213562373095145474621858738828450441360)
|
||||
t_error("sqrt(2) want 0x1.6a09e667f3bcdp+0 got %a\n", sqrt(2.0));
|
||||
|
||||
if (sizeof pow(sqrt(8),0.5f) != sizeof(double))
|
||||
t_error("sizeof pow(sqrt(8),0.5f) want %d got %d\n", (int)sizeof(double), (int)sizeof pow(sqrt(8),0.5f));
|
||||
if (sizeof pow(2.0,0.5) != sizeof(double))
|
||||
t_error("sizeof pow(2.0,0.5) want %d got %d\n", (int)sizeof(double), (int)sizeof pow(2.0,0.5));
|
||||
if (sizeof pow(2.0f,0.5f) != sizeof(float))
|
||||
t_error("sizeof pow(2.0f,0.5f) want %d got %d\n", (int)sizeof(float), (int)sizeof pow(2.0f,0.5f));
|
||||
// if (sizeof pow(2.0,0.5+0*I) != sizeof(double complex))
|
||||
// t_error("sizeof pow(2.0,0.5+0*I) want %d got %d\n", (int)sizeof(double complex), (int)sizeof pow(2.0,0.5+0*I));
|
||||
|
||||
if (pow(2.0,0.5) != 1.414213562373095145474621858738828450441360)
|
||||
t_error("pow(2.0,0.5) want 0x1.6a09e667f3bcdp+0 got %a\n", pow(2.0,0.5));
|
||||
if (pow(2,0.5) != 1.414213562373095145474621858738828450441360)
|
||||
t_error("pow(2,0.5) want 0x1.6a09e667f3bcdp+0 got %a\n", pow(2,0.5));
|
||||
if (pow(2,0.5f) != 1.414213562373095145474621858738828450441360)
|
||||
t_error("pow(2,0.5f) want 0x1.6a09e667f3bcdp+0 got %a\n", pow(2,0.5f));
|
||||
|
||||
return t_status;
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include "test.h"
|
||||
|
||||
/* We use this instead of memcmp because some broken C libraries
|
||||
* add additional nonstandard fields to struct tm... */
|
||||
|
||||
int tm_cmp(struct tm tm1, struct tm tm2)
|
||||
{
|
||||
return tm1.tm_sec != tm2.tm_sec ||
|
||||
tm1.tm_min != tm2.tm_min ||
|
||||
tm1.tm_hour != tm2.tm_hour ||
|
||||
tm1.tm_mday != tm2.tm_mday ||
|
||||
tm1.tm_mon != tm2.tm_mon ||
|
||||
tm1.tm_year != tm2.tm_year ||
|
||||
tm1.tm_wday != tm2.tm_wday ||
|
||||
tm1.tm_yday != tm2.tm_yday ||
|
||||
tm1.tm_isdst!= tm2.tm_isdst;
|
||||
}
|
||||
|
||||
char *tm_str(struct tm tm)
|
||||
{
|
||||
static int i;
|
||||
static char b[4][64];
|
||||
i = (i+1)%4;
|
||||
snprintf(b[i], sizeof b[i],
|
||||
"s=%02d m=%02d h=%02d mday=%02d mon=%02d year=%04d wday=%d yday=%d isdst=%d",
|
||||
tm.tm_sec, tm.tm_min, tm.tm_hour,
|
||||
tm.tm_mday, tm.tm_mon, tm.tm_year,
|
||||
tm.tm_wday, tm.tm_yday, tm.tm_isdst);
|
||||
return b[i];
|
||||
}
|
||||
|
||||
#define TM(ss,mm,hh,md,mo,yr,wd,yd,dst) (struct tm){ \
|
||||
.tm_sec = ss, .tm_min = mm, .tm_hour = hh, \
|
||||
.tm_mday = md, .tm_mon = mo, .tm_year = yr, \
|
||||
.tm_wday = wd, .tm_yday = yd, .tm_isdst = dst }
|
||||
|
||||
#define TM_EPOCH TM(0,0,0,1,0,70,4,0,0)
|
||||
#define TM_Y2038_1S TM(7,14,3,19,0,138,2,18,0)
|
||||
#define TM_Y2038 TM(8,14,3,19,0,138,2,18,0)
|
||||
|
||||
static void sec2tm(time_t t, char *m)
|
||||
{
|
||||
struct tm *tm;
|
||||
time_t r;
|
||||
|
||||
errno = 0;
|
||||
tm = gmtime(&t);
|
||||
if (errno != 0)
|
||||
t_error("%s: gmtime((time_t)%lld) should not set errno, got %s\n",
|
||||
m, (long long)t, strerror(errno));
|
||||
errno = 0;
|
||||
r = mktime(tm);
|
||||
if (errno != 0)
|
||||
t_error("%s: mktime(%s) should not set errno, got %s\n",
|
||||
m, tm_str(*tm), strerror(errno));
|
||||
if (t != r)
|
||||
t_error("%s: mktime(gmtime(%lld)) roundtrip failed: got %lld (gmtime is %s)\n",
|
||||
m, (long long)t, (long long)r, tm_str(*tm));
|
||||
}
|
||||
|
||||
static void tm2sec(struct tm *tm, int big, char *m)
|
||||
{
|
||||
struct tm *r;
|
||||
time_t t;
|
||||
int overflow = big && (time_t)LLONG_MAX!=LLONG_MAX;
|
||||
|
||||
errno = 0;
|
||||
t = mktime(tm);
|
||||
if (overflow && t != -1)
|
||||
t_error("%s: mktime(%s) expected -1, got (time_t)%ld\n",
|
||||
m, tm_str(*tm), (long)t);
|
||||
if (overflow && errno != 10000) //EOVERFLOW
|
||||
t_error("%s: mktime(%s) expected EOVERFLOW (%s), got (%s)\n",
|
||||
m, tm_str(*tm), strerror(10000), strerror(errno));
|
||||
if (!overflow && t == -1)
|
||||
t_error("%s: mktime(%s) expected success, got (time_t)-1\n",
|
||||
m, tm_str(*tm));
|
||||
if (!overflow && errno)
|
||||
t_error("%s: mktime(%s) expected no error, got (%s)\n",
|
||||
m, tm_str(*tm), strerror(errno));
|
||||
r = gmtime(&t);
|
||||
if (!overflow && tm_cmp(*r, *tm))
|
||||
t_error("%s: gmtime(mktime(%s)) roundtrip failed: got %s\n",
|
||||
m, tm_str(*tm), tm_str(*r));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
putenv("TZ=GMT");
|
||||
tzset();
|
||||
tm2sec(&TM_EPOCH, 0, "gmtime(0)");
|
||||
tm2sec(&TM_Y2038_1S, 0, "2038-1s");
|
||||
tm2sec(&TM_Y2038, 1, "2038");
|
||||
|
||||
sec2tm(0, "EPOCH");
|
||||
for (t = 1; t < 1000; t++)
|
||||
sec2tm(t*100003, "EPOCH+eps");
|
||||
|
||||
/* FIXME: set a TZ var and check DST boundary conditions */
|
||||
return t_status;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
# define TRACE1(s, a) printf(s, a)
|
||||
|
||||
void caller(void* ptr)
|
||||
{
|
||||
|
||||
ptr = 0xaaaaaaaa;
|
||||
TRACE1("caller is called from EIP@%x\n", *(int*)((char*)&ptr-4)-5);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
caller(0xffffffff);
|
||||
}
|
||||
|
@ -1,357 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef MAX_1
|
||||
#ifdef __SPU__
|
||||
#define MAX_1 11000
|
||||
#else
|
||||
#define MAX_1 33000
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAX_2 (2 * MAX_1 + MAX_1 / 10)
|
||||
|
||||
void eprintf (int line, char *result, char *expected, int size)
|
||||
{
|
||||
if (size != 0)
|
||||
printf ("Failure at line %d, result is <%.*s>, should be <%s> of size %d\n",
|
||||
line, size, result, expected, size);
|
||||
else
|
||||
printf ("Failure at line %d, result is <%s>, should be <%s>\n",
|
||||
line, result, expected);
|
||||
}
|
||||
|
||||
void mycopy (char *target, char *source, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
target[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
void myset (char *target, char ch, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
target[i] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char target[MAX_1] = "A";
|
||||
char first_char;
|
||||
char second_char;
|
||||
char array[] = "abcdefghijklmnopqrstuvwxz";
|
||||
char array2[] = "0123456789!@#$%^&*(";
|
||||
char buffer2[MAX_1];
|
||||
char buffer3[MAX_1];
|
||||
char buffer4[MAX_1];
|
||||
char buffer5[MAX_2];
|
||||
char buffer6[MAX_2];
|
||||
char buffer7[MAX_2];
|
||||
char expected[MAX_1];
|
||||
char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7;
|
||||
int i, j, k, x, z, align_test_iterations;
|
||||
|
||||
int test_failed = 0;
|
||||
|
||||
tmp1 = target;
|
||||
tmp2 = buffer2;
|
||||
tmp3 = buffer3;
|
||||
tmp4 = buffer4;
|
||||
tmp5 = buffer5;
|
||||
tmp6 = buffer6;
|
||||
tmp7 = buffer7;
|
||||
|
||||
tmp2[0] = 'Z';
|
||||
tmp2[1] = '\0';
|
||||
|
||||
if (memset (target, 'X', 0) != target ||
|
||||
memcpy (target, "Y", 0) != target ||
|
||||
memmove (target, "K", 0) != target ||
|
||||
strncpy (tmp2, "4", 0) != tmp2 ||
|
||||
strncat (tmp2, "123", 0) != tmp2 ||
|
||||
strcat (target, "") != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "A", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strcmp (target, "A") || strlen(target) != 1 || memchr (target, 'A', 0) != NULL
|
||||
|| memcmp (target, "J", 0) || strncmp (target, "A", 1) || strncmp (target, "J", 0) ||
|
||||
tmp2[0] != 'Z' || tmp2[1] != '\0')
|
||||
{
|
||||
eprintf (__LINE__, target, "A", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
tmp2[2] = 'A';
|
||||
if (strcpy (target, "") != target ||
|
||||
strncpy (tmp2, "", 4) != tmp2 ||
|
||||
strcat (target, "") != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (target[0] != '\0' || strncmp (target, "", 1) ||
|
||||
memcmp (tmp2, "\0\0\0\0", 4))
|
||||
{
|
||||
eprintf (__LINE__, target, "", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
tmp2[2] = 'A';
|
||||
if (strncat (tmp2, "1", 3) != tmp2 ||
|
||||
memcmp (tmp2, "1\0A", 3))
|
||||
{
|
||||
eprintf (__LINE__, tmp2, "1\0A", 3);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strcpy (tmp3, target) != tmp3 ||
|
||||
strcat (tmp3, "X") != tmp3 ||
|
||||
strncpy (tmp2, "X", 2) != tmp2 ||
|
||||
memset (target, tmp2[0], 1) != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "X", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strcmp (target, "X") || strlen (target) != 1 ||
|
||||
memchr (target, 'X', 2) != target ||
|
||||
strchr (target, 'X') != target ||
|
||||
memchr (target, 'Y', 2) != NULL ||
|
||||
strchr (target, 'Y') != NULL ||
|
||||
strcmp (tmp3, target) ||
|
||||
strncmp (tmp3, target, 2) ||
|
||||
memcmp (target, "K", 0) ||
|
||||
strncmp (target, tmp3, 3))
|
||||
{
|
||||
eprintf (__LINE__, target, "X", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strcpy (tmp3, "Y") != tmp3 ||
|
||||
strcat (tmp3, "Y") != tmp3 ||
|
||||
memset (target, 'Y', 2) != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "Y", 0);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
target[2] = '\0';
|
||||
if (memcmp (target, "YY", 2) || strcmp (target, "YY") ||
|
||||
strlen (target) != 2 || memchr (target, 'Y', 2) != target ||
|
||||
strcmp (tmp3, target) ||
|
||||
strncmp (target, tmp3, 3) ||
|
||||
strncmp (target, tmp3, 4) ||
|
||||
strncmp (target, tmp3, 2) ||
|
||||
strchr (target, 'Y') != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "YY", 2);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
strcpy (target, "WW");
|
||||
if (memcmp (target, "WW", 2) || strcmp (target, "WW") ||
|
||||
strlen (target) != 2 || memchr (target, 'W', 2) != target ||
|
||||
strchr (target, 'W') != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "WW", 2);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strncpy (target, "XX", 16) != target ||
|
||||
memcmp (target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
|
||||
{
|
||||
eprintf (__LINE__, target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
if (strcpy (tmp3, "ZZ") != tmp3 ||
|
||||
strcat (tmp3, "Z") != tmp3 ||
|
||||
memcpy (tmp4, "Z", 2) != tmp4 ||
|
||||
strcat (tmp4, "ZZ") != tmp4 ||
|
||||
memset (target, 'Z', 3) != target)
|
||||
{
|
||||
eprintf (__LINE__, target, "ZZZ", 3);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
target[3] = '\0';
|
||||
tmp5[0] = '\0';
|
||||
strncat (tmp5, "123", 2);
|
||||
if (memcmp (target, "ZZZ", 3) || strcmp (target, "ZZZ") ||
|
||||
strcmp (tmp3, target) || strcmp (tmp4, target) ||
|
||||
strncmp (target, "ZZZ", 4) || strncmp (target, "ZZY", 3) <= 0 ||
|
||||
strncmp ("ZZY", target, 4) >= 0 ||
|
||||
memcmp (tmp5, "12", 3) ||
|
||||
strlen (target) != 3)
|
||||
{
|
||||
eprintf (__LINE__, target, "ZZZ", 3);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
target[2] = 'K';
|
||||
if (memcmp (target, "ZZZ", 2) || strcmp (target, "ZZZ") >= 0 ||
|
||||
memcmp (target, "ZZZ", 3) >= 0 || strlen (target) != 3 ||
|
||||
memchr (target, 'K', 3) != target + 2 ||
|
||||
strncmp (target, "ZZZ", 2) || strncmp (target, "ZZZ", 4) >= 0 ||
|
||||
strchr (target, 'K') != target + 2)
|
||||
{
|
||||
eprintf (__LINE__, target, "ZZK", 3);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
strcpy (target, "AAA");
|
||||
if (memcmp (target, "AAA", 3) || strcmp (target, "AAA") ||
|
||||
strncmp (target, "AAA", 3) ||
|
||||
strlen (target) != 3)
|
||||
{
|
||||
eprintf (__LINE__, target, "AAA", 3);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
j = 5;
|
||||
while (j < MAX_1)
|
||||
{
|
||||
for (i = j-1; i <= j+1; ++i)
|
||||
{
|
||||
/* don't bother checking unaligned data in the larger
|
||||
sizes since it will waste time without performing additional testing */
|
||||
if (i <= 16 * sizeof(long))
|
||||
{
|
||||
align_test_iterations = 2*sizeof(long);
|
||||
if (i <= 2 * sizeof(long) + 1)
|
||||
z = 2;
|
||||
else
|
||||
z = 2 * sizeof(long);
|
||||
}
|
||||
else
|
||||
{
|
||||
align_test_iterations = 1;
|
||||
}
|
||||
|
||||
for (x = 0; x < align_test_iterations; ++x)
|
||||
{
|
||||
tmp1 = target + x;
|
||||
tmp2 = buffer2 + x;
|
||||
tmp3 = buffer3 + x;
|
||||
tmp4 = buffer4 + x;
|
||||
tmp5 = buffer5 + x;
|
||||
tmp6 = buffer6 + x;
|
||||
|
||||
first_char = array[i % (sizeof(array) - 1)];
|
||||
second_char = array2[i % (sizeof(array2) - 1)];
|
||||
memset (tmp1, first_char, i);
|
||||
mycopy (tmp2, tmp1, i);
|
||||
myset (tmp2 + z, second_char, i - z - 1);
|
||||
if (memcpy (tmp1 + z, tmp2 + z, i - z - 1) != tmp1 + z)
|
||||
{
|
||||
printf ("error at line %d\n", __LINE__);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
tmp1[i] = '\0';
|
||||
tmp2[i] = '\0';
|
||||
if (strcpy (expected, tmp2) != expected)
|
||||
{
|
||||
printf ("error at line %d\n", __LINE__);
|
||||
test_failed = 1;
|
||||
}
|
||||
tmp2[i-z] = first_char + 1;
|
||||
if (memmove (tmp2 + z + 1, tmp2 + z, i - z - 1) != tmp2 + z + 1 ||
|
||||
memset (tmp3, first_char, i) != tmp3)
|
||||
{
|
||||
printf ("error at line %d\n", __LINE__);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
myset (tmp4, first_char, i);
|
||||
tmp5[0] = '\0';
|
||||
if (strncpy (tmp5, tmp1, i+1) != tmp5 ||
|
||||
strcat (tmp5, tmp1) != tmp5)
|
||||
{
|
||||
printf ("error at line %d\n", __LINE__);
|
||||
test_failed = 1;
|
||||
}
|
||||
mycopy (tmp6, tmp1, i);
|
||||
mycopy (tmp6 + i, tmp1, i + 1);
|
||||
|
||||
tmp7[2*i+z] = second_char;
|
||||
strcpy (tmp7, tmp1);
|
||||
|
||||
strchr (tmp1, second_char);
|
||||
|
||||
if (memcmp (tmp1, expected, i) || strcmp (tmp1, expected) ||
|
||||
strncmp (tmp1, expected, i) ||
|
||||
strncmp (tmp1, expected, i+1) ||
|
||||
strcmp (tmp1, tmp2) >= 0 || memcmp (tmp1, tmp2, i) >= 0 ||
|
||||
strncmp (tmp1, tmp2, i+1) >= 0 ||
|
||||
strlen (tmp1) != i || memchr (tmp1, first_char, i) != tmp1 ||
|
||||
strchr (tmp1, first_char) != tmp1 ||
|
||||
memchr (tmp1, second_char, i) != tmp1 + z ||
|
||||
strchr (tmp1, second_char) != tmp1 + z ||
|
||||
strcmp (tmp5, tmp6) ||
|
||||
strncat (tmp7, tmp1, i+2) != tmp7 ||
|
||||
strcmp (tmp7, tmp6) ||
|
||||
tmp7[2*i+z] != second_char)
|
||||
{
|
||||
eprintf (__LINE__, tmp1, expected, 0);
|
||||
printf ("x is %d\n",x);
|
||||
printf ("i is %d\n", i);
|
||||
printf ("tmp1 is <%p>\n", tmp1);
|
||||
printf ("tmp5 is <%p> <%s>\n", tmp5, tmp5);
|
||||
printf ("tmp6 is <%p> <%s>\n", tmp6, tmp6);
|
||||
test_failed = 1;
|
||||
}
|
||||
|
||||
for (k = 1; k <= align_test_iterations && k <= i; ++k)
|
||||
{
|
||||
if (memcmp (tmp3, tmp4, i - k + 1) != 0 ||
|
||||
strncmp (tmp3, tmp4, i - k + 1) != 0)
|
||||
{
|
||||
printf ("Failure at line %d, comparing %.*s with %.*s\n",
|
||||
__LINE__, i, tmp3, i, tmp4);
|
||||
test_failed = 1;
|
||||
}
|
||||
tmp4[i-k] = first_char + 1;
|
||||
if (memcmp (tmp3, tmp4, i) >= 0 ||
|
||||
strncmp (tmp3, tmp4, i) >= 0 ||
|
||||
memcmp (tmp4, tmp3, i) <= 0 ||
|
||||
strncmp (tmp4, tmp3, i) <= 0)
|
||||
{
|
||||
printf ("Failure at line %d, comparing %.*s with %.*s\n",
|
||||
__LINE__, i, tmp3, i, tmp4);
|
||||
test_failed = 1;
|
||||
}
|
||||
tmp4[i-k] = first_char;
|
||||
}
|
||||
}
|
||||
}
|
||||
j = ((2 * j) >> 2) << 2;
|
||||
}
|
||||
|
||||
printf("\n %s finished\n", __FILE__);
|
||||
if (test_failed)
|
||||
{
|
||||
printf("\n %s FAILED\n", __FILE__);
|
||||
abort();
|
||||
}
|
||||
else
|
||||
exit(0);
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
#include "test.h"
|
||||
//#include <stdint.h>
|
||||
|
||||
/*
|
||||
static uint64_t randstate = 0x123456789abcdef0ull;
|
||||
static uint64_t rnd(void) {
|
||||
randstate = 6364136223846793005ull*randstate + 1;
|
||||
return randstate;
|
||||
}
|
||||
void test_maketest()
|
||||
{
|
||||
int i;
|
||||
uint64_t x,y;
|
||||
for (i = 0; i < 128; i++) {
|
||||
x = rnd();
|
||||
y = rnd()>>(i/2);
|
||||
if (!y)
|
||||
continue;
|
||||
printf("0x%llxull, 0x%llxull, 0x%llxull, 0x%llxull,\n", x, y, x/y, x%y);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
static struct {
|
||||
uint64_t x, y, div, mod;
|
||||
} t[] = {
|
||||
0x8ddb1a43e77c4031ull, 0x5950e8c33d34979eull, 0x1ull, 0x348a3180aa47a893ull,
|
||||
0x723f4114006c08c7ull, 0x817de530db2b43fcull, 0x0ull, 0x723f4114006c08c7ull,
|
||||
0x47811fa5f00f74dull, 0x3d98e7d3fcd5d5c5ull, 0x0ull, 0x47811fa5f00f74dull,
|
||||
0x51ffcc7cdc989d43ull, 0x36be8bd6746b70e4ull, 0x1ull, 0x1b4140a6682d2c5full,
|
||||
0x57bf9128512fe829ull, 0x197b3858155d498dull, 0x3ull, 0xb4de82011180b82ull,
|
||||
0x89fc1c5968fa817full, 0xdcea797734c7115ull, 0x9ull, 0xdb838065b4a87c2ull,
|
||||
0x4ed5264cf7092ec5ull, 0xde40d1e15ef3e74ull, 0x5ull, 0x960e4b6895cf681ull,
|
||||
0xffd86b253d97317bull, 0x13f9ff2d24b6d6f4ull, 0xcull, 0x1020750785051e0bull,
|
||||
0x8771fa2da656a721ull, 0x9210fe654c59bfcull, 0xeull, 0x7a31b9503881f59ull,
|
||||
0xb5961d12bcd3e937ull, 0xbdb5a33662f547aull, 0xfull, 0x3bbd40fc00df611ull,
|
||||
0x93c79eecdac7ed3dull, 0x6f267c57ea2b7b5ull, 0x15ull, 0x1e51bb9776edb64ull,
|
||||
0x6b93ffce49f1a4b3ull, 0x3583d1f9702ee03ull, 0x20ull, 0x8c5bdb6993e453ull,
|
||||
0x138aefcc98ce5d19ull, 0x117002fa7600b11ull, 0x11ull, 0x103eca27b6da0f8ull,
|
||||
0xb3da641cef491fefull, 0x357615f638334b8ull, 0x35ull, 0x2c33b5d551f35d7ull,
|
||||
0x71c4b06e463912b5ull, 0x1c286ad9e8f5229ull, 0x40ull, 0x1230506a2648875ull,
|
||||
0x97d4cf7df046d6ebull, 0x1e9412f5c77b2b8ull, 0x4full, 0xd9b1e06756b023ull,
|
||||
0x1428f04bd490ea11ull, 0x9d97f29a897c93ull, 0x20ull, 0x75f1f8836157b1ull,
|
||||
0x35256c76832705a7ull, 0xa962f1a447dcd7ull, 0x50ull, 0x3680f32cb20277ull,
|
||||
0x2969e82bd9347f2dull, 0x723d68574d4156ull, 0x5cull, 0x5bd6ac79710445ull,
|
||||
0x9061a12aae71a823ull, 0x4186d8a1a66175ull, 0x234ull, 0x48be68be2f25full,
|
||||
0x695b8d33ef342e09ull, 0x3ed1fe1a998fe3ull, 0x1adull, 0x15a6615bde0ea2ull,
|
||||
0x46b4dd1e06367a5full, 0xa04e70622e4e8ull, 0x70eull, 0x64750bc0b9dafull,
|
||||
0xd68b05ba7eee12a5ull, 0x72ab3fb682444ull, 0x1defull, 0x3c437fc988329ull,
|
||||
0x1e59cc2ac508f85bull, 0xeb15ae6d4d7f9ull, 0x210ull, 0xc00aeae0b86cbull,
|
||||
0x296f8d2c76a0901ull, 0xf65628b31b01ull, 0x2b0ull, 0xf14566117651ull,
|
||||
0x7036f5ad7cbc5e17ull, 0xa09d3bfcf72cfull, 0xb2dull, 0x72236db564ab4ull,
|
||||
0x915d6883c575ad1dull, 0x3a38d68d3a38eull, 0x27f2ull, 0x241de6f7a6ee1ull,
|
||||
0x845ba74f5adfa793ull, 0x2f6950e58d00bull, 0x2caaull, 0x249dc90239c45ull,
|
||||
0xb910d16c54805af9ull, 0x1fc2ca5c99a7aull, 0x5d3aull, 0x1771487b50955ull,
|
||||
0x27a2e280bcf990cfull, 0x389aa0c0b0cc0ull, 0xb34ull, 0x9d71d12eb9cfull,
|
||||
0x1e032f04a5372e95ull, 0x63c2a1d58710ull, 0x4d04ull, 0x154ce4414255ull,
|
||||
0x3a1a5659908495cbull, 0x279dcd85418aull, 0x17775ull, 0x132c6f9c7bb9ull,
|
||||
0xd769a376e5e103f1ull, 0xadacb670e0c7ull, 0x13d85ull, 0x8ad256e5d18eull,
|
||||
0x269f4f4baaaf287ull, 0x1aed2ad9daf0ull, 0x16f3ull, 0x426550f80b7ull,
|
||||
0x6700daeeb87a770dull, 0xeca7ab1aa93ull, 0x6f6c5ull, 0x70d9466f1eeull,
|
||||
0xd0201f3783c2a303ull, 0x3a0c01aa3e6aull, 0x395e1ull, 0x18b33b9015d9ull,
|
||||
0xca3f2e00d291e3e9ull, 0xbe0e048cd94ull, 0x1106c2ull, 0x37f7fc0a1c1ull,
|
||||
0xec4d240dc289633full, 0x4f8aadb7483ull, 0x2f8855ull, 0x46e0db91bc0ull,
|
||||
0xd7967b29e2e36685ull, 0xe61d902db27ull, 0xefd69ull, 0x36811fff886ull,
|
||||
0xe3ecd4374320af3bull, 0x4edd0edd0a0ull, 0x2e3defull, 0x4ad0da4c9dbull,
|
||||
0x7a08fe1d98b4dae1ull, 0x6bced9c0c15ull, 0x121c89ull, 0x40c856617a4ull,
|
||||
0x34435992a5c9c2f7ull, 0x4f4a94c109full, 0xa8bc9ull, 0x94c5d46120ull,
|
||||
0x6fd0027468f1dcfdull, 0x597186b0153ull, 0x140060ull, 0x16f26555dddull,
|
||||
0x4fe37c1db1619a73ull, 0x47a0c30bd15ull, 0x11d861ull, 0x5964fb3d7eull,
|
||||
0x77aa77f86d07c8d9ull, 0x3a39cf03d65ull, 0x20e21cull, 0x37f7fede7cdull,
|
||||
0xc072e76ad59cf1afull, 0x3a786701dull, 0x34a98c59ull, 0x22b6b1b9aull,
|
||||
0xfb8e8f1f7781ba75ull, 0xe8ca427d3eull, 0x114a34dull, 0xa344eb94cfull,
|
||||
0x160e34cf590444abull, 0xe2388f12feull, 0x18f574ull, 0xc303329393ull,
|
||||
0x2509ddea3a648dd1ull, 0xec762d81bcull, 0x281955ull, 0xc0463d1e65ull,
|
||||
0xc9ba10cd6eafcf67ull, 0x96a51d06f7ull, 0x156ce72ull, 0x133e2df369ull,
|
||||
0x1dd4fe261b4adeedull, 0x2736e25406ull, 0xc2bfefull, 0x1354c1f353ull,
|
||||
0x480258f92fc38de3ull, 0x2599b52bb0ull, 0x1ea450cull, 0x2879f11a3ull,
|
||||
0x5a3257b1114109c9ull, 0x2978f9f1aaull, 0x22cc30aull, 0x1317311b25ull,
|
||||
0xf4eeda8f34ab3c1full, 0x1aa70450d9ull, 0x9309d64ull, 0x1187b6925bull,
|
||||
0x3c2c319ca8612a65ull, 0x73fc01eceull, 0x84d0088ull, 0x3165accf5ull,
|
||||
0x4f6034e74a16561bull, 0x1f29d53707ull, 0x28c0daaull, 0xd88e07075ull,
|
||||
0x206665a7072f1cc1ull, 0xda87e7ceaull, 0x25f48c1ull, 0xd3ddb2057ull,
|
||||
0x100c559d7db417d7ull, 0xb907ebbc2ull, 0x1634188ull, 0xa2eae16c7ull,
|
||||
0x64c5f83691b47cddull, 0x5aced6ebbull, 0x11c17fb7ull, 0x344109030ull,
|
||||
0x32a812777eaf7d53ull, 0x1cb63fe4full, 0x1c3a9675ull, 0xb113f938ull,
|
||||
0x67478d96865ca6b9ull, 0x142fa03aull, 0x51dcb463dull, 0x11359ce7ull,
|
||||
0x71024e740deb428full, 0x142d3885ull, 0x599d9edd5ull, 0x13b1ae6ull,
|
||||
0x52c78160b090b655ull, 0xd02101c6ull, 0x65d1b205ull, 0x1c0a0177ull,
|
||||
0x16917d5f9fde38bull, 0xfb1566c7ull, 0x17029e0ull, 0x1bbe166bull,
|
||||
0xa6ee688a0d1387b1ull, 0x22c4d384ull, 0x4cd19afcfull, 0x77143f5ull,
|
||||
0x74babc1be2ed9c47ull, 0x22eda9a6ull, 0x3578b1967ull, 0x189b247dull,
|
||||
0x7c5cbf2dfc1db6cdull, 0x5f09c060ull, 0x14efd44d4ull, 0x5210e74dull,
|
||||
0x7c046071c1ac68c3ull, 0x3696c8e6ull, 0x24596d86bull, 0x26060a1ull,
|
||||
0x84728ab55d399fa9ull, 0x267d7771ull, 0x370ea7405ull, 0x255d1674ull,
|
||||
0x99f57100ef5404ffull, 0x10c0df86ull, 0x9308fef0dull, 0x9009131ull,
|
||||
0x3f4c0514b0df5e45ull, 0xf2c3810ull, 0x42bf84d39ull, 0x3aa12b5ull,
|
||||
0xd01edb572821ecfbull, 0x2a443aeull, 0x4ec8b88639ull, 0x111c73dull,
|
||||
0xeecb08561bd0cea1ull, 0xbeca231ull, 0x140692508bull, 0x9b36e06ull,
|
||||
0x8c856facc6335cb7ull, 0x398eab4ull, 0x271008c7a5ull, 0x922ab3ull,
|
||||
0x23fb9839e8358cbdull, 0x24deb54ull, 0xf9d714151ull, 0xb9c329ull,
|
||||
0x2005d5de30015033ull, 0x47c06dbull, 0x7240bccbaull, 0x104d115ull,
|
||||
0x67d59c29e076f499ull, 0x179f009ull, 0x465554ac22ull, 0x10b0767ull,
|
||||
0x32d2dd34369c836full, 0x13d3fbfull, 0x2902f2fb54ull, 0x7553c3ull,
|
||||
0x3960c3c99fdc2235ull, 0x1b808baull, 0x21618743cdull, 0x11e7743ull,
|
||||
0x343bad5adfa9726bull, 0xeef444ull, 0x37f58c51a6ull, 0x3d8a53ull,
|
||||
0x7a4aadd7b4e5f191ull, 0x129c9ull, 0x6921bb5a2a53ull, 0x6b66ull,
|
||||
0x9eb7dae5d71c5927ull, 0x31d7f5ull, 0x32f2ff2c6d5ull, 0x22c4eull,
|
||||
0x1b285999316afeadull, 0x115477ull, 0x1912cf6611eull, 0x801bbull,
|
||||
0x917aee3d84b533a3ull, 0x71d26full, 0x1473408589aull, 0x6e74ddull,
|
||||
0x18e6a86b0473a589ull, 0x50a12ull, 0x4f0fabc67d4ull, 0x210a1ull,
|
||||
0xf22c9887813bbddfull, 0x5b17aull, 0x2a897505c07bull, 0x1f841ull,
|
||||
0xef7a551239d60225ull, 0x7fb5aull, 0x1e00b98e188bull, 0x41847ull,
|
||||
0xffd2ad0e77b73dbull, 0x146f14ull, 0xc8500600a3ull, 0xba1full,
|
||||
0x76743abdfb91f081ull, 0xd5888ull, 0x8e0303c479cull, 0x245a1ull,
|
||||
0xc2eeb030bcff9197ull, 0x7a4e8ull, 0x198034e02c37ull, 0x343bfull,
|
||||
0x63cc9c23f0ed0c9dull, 0x6c1e5ull, 0xec4d5841041ull, 0x38178ull,
|
||||
0x7ad70f846e8f1313ull, 0x7fdf5ull, 0xf5ecec69bc9ull, 0x756b6ull,
|
||||
0x60de3d71574eb279ull, 0x6ea3ull, 0xe02421997a61ull, 0x18b6ull,
|
||||
0xd27054901c68b44full, 0x2dd0full, 0x497d639c8f46ull, 0xe135ull,
|
||||
0xbcf297b8f0dbfe15ull, 0xcf17ull, 0xe992af0ca1abull, 0x32b8ull,
|
||||
0x96c3ae70323ef14bull, 0xbbdcull, 0xcd7329b68d81ull, 0x1b6full,
|
||||
0xdc1a13cfa4d3cb71ull, 0xdb16ull, 0x1012fe5ed296full, 0x46e7ull,
|
||||
0xa1d40a2986f40607ull, 0x8067ull, 0x142a473fdb7beull, 0x1895ull,
|
||||
0x227f92ef6daab68dull, 0x15ecull, 0x192dda5d5ed25ull, 0xf71ull,
|
||||
0xc0a4a7810015ee83ull, 0x6064ull, 0x1ffa220762fc8ull, 0x4463ull,
|
||||
0xd38b6eb9f0e71b69ull, 0x1909ull, 0x8732ce2cc77f4ull, 0xfd5ull,
|
||||
0x2e588bdb751a66bfull, 0x229cull, 0x156d025c70d97ull, 0x10bbull,
|
||||
0xd90f7e11dcbd1605ull, 0x760ull, 0x1d6e934381ba2eull, 0x2c5ull,
|
||||
0x60ab67a4e5aeabbull, 0x1bf7ull, 0x374f26f3e3edull, 0x210ull,
|
||||
0x224f627be76a8261ull, 0x4f4ull, 0x6ed4d3882b567ull, 0x35ull,
|
||||
0x300d1ab91bd0b677ull, 0xe9cull, 0x34a002fb76e63ull, 0x823ull,
|
||||
0x2a63d80e0c52fc7dull, 0x32ull, 0xd90970ebc4383full, 0x2full,
|
||||
0xb0e94bbc1f90c5f3ull, 0x3b3ull, 0x2fd2ef70381c52ull, 0x29dull,
|
||||
0x2b5dc22562dbe059ull, 0x30aull, 0xe45055015fff5ull, 0x1c7ull,
|
||||
0x4a7fd1078807d52full, 0x18dull, 0x300a32f60677d4ull, 0x16bull,
|
||||
0x41a01ee8ab0849f5ull, 0x13cull, 0x352a3971f57e9dull, 0x29ull,
|
||||
0x95a7287ad5f6602bull, 0x1d0ull, 0x529130d1034a23ull, 0xbbull,
|
||||
0x723bacc76bd51551ull, 0x16ull, 0x53142091089af83ull, 0xfull,
|
||||
0x81c49febaa2ca2e7ull, 0xcdull, 0xa20d44956f5bf4ull, 0x83ull,
|
||||
0x11593d6b3f54de6dull, 0x63ull, 0x2cdc6b1a7f9078ull, 0x5ull,
|
||||
0x756c82d6f7069963ull, 0x5cull, 0x146bea3ba565525ull, 0x17ull,
|
||||
0xda882ab2a88c0149ull, 0x1bull, 0x8180194d6d5c728ull, 0x11ull,
|
||||
0xbb03671751a7ff9full, 0x20ull, 0x5d81b38ba8d3ffcull, 0x1full,
|
||||
0x6884fa0a8f0c99e5ull, 0x12ull, 0x5ce7fab40d6088cull, 0xdull,
|
||||
0x5052a2953c528441ull, 0x7ull, 0xb7984f0bf79809bull, 0x4ull,
|
||||
0x58dd1583185ecb57ull, 0x9ull, 0x9dfad0e90ee1697ull, 0x8ull,
|
||||
0xaa6870c376df5c5dull, 0x3ull, 0x38cd7aebd24a741full, 0x0ull,
|
||||
0x4b21d01617167e39ull, 0x2ull, 0x2590e80b0b8b3f1cull, 0x1ull,
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint64_t x, y, div, mod;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof t/sizeof *t; i++) {
|
||||
x = t[i].x;
|
||||
y = t[i].y;
|
||||
div = x / y;
|
||||
mod = x % y;
|
||||
if (div != t[i].div)
|
||||
t_error("udiv %llu/%llu want %llu got %llu\n", x, y, t[i].div, div);
|
||||
if (mod != t[i].mod)
|
||||
t_error("umod %llu%%%llu want %llu got %llu\n", x, y, t[i].mod, mod);
|
||||
}
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
return t_status;
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <errno.h>
|
||||
//#include <limits.h>
|
||||
//#include <unistd.h>
|
||||
#include "test.h"
|
||||
|
||||
#define TEST(r, f, x, m) ( \
|
||||
errno = 0, ((r) = (f)) == (x) || \
|
||||
(t_error("%s failed (" m ")\n", #f, r, x, strerror(errno)), 0) )
|
||||
|
||||
#define TEST_S(s, x, m) ( \
|
||||
!strcmp((s),(x)) || \
|
||||
(t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <kolibrisys.h>
|
||||
|
||||
#define fgetc fgetc_dbg
|
||||
#define ungetc ungetc_dbg
|
||||
|
||||
|
||||
int fgetc_dbg(FILE* file)
|
||||
{
|
||||
int c = 0, rc;
|
||||
|
||||
rc = fread(&c, 1, 1, file);
|
||||
|
||||
if (rc < 1) return EOF;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int ungetc_dbg(int c,FILE* file)
|
||||
{
|
||||
dword res;
|
||||
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (file->filepos>file->filesize || file->filepos==0 || c == EOF || file->ungetc_buf != EOF)
|
||||
{
|
||||
errno = E_EOF;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
file->ungetc_buf = c;
|
||||
file->filepos--;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void mark(int n)
|
||||
{
|
||||
n++;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
char a[100];
|
||||
FILE *f;
|
||||
|
||||
TEST(i, !(f = fopen("_tmpfile.tmp","w+")), 0, "failed to create temp file %d!=%d (%s)");
|
||||
|
||||
if (!f) return t_status;
|
||||
|
||||
TEST(i, fprintf(f, "hello, world\n"), 13, "%d != %d (%m)");
|
||||
TEST(i, fseek(f, 0, SEEK_SET), 0, "%d != %d (%m)");
|
||||
|
||||
TEST(i, feof(f), 0, "%d != %d");
|
||||
TEST(i, fgetc(f), 'h', "'%c' != '%c'");
|
||||
TEST(i, ftell(f), 1, "%d != %d");
|
||||
TEST(i, ungetc('x', f), 'x', "%d != %d");
|
||||
TEST(i, ftell(f), 0, "%d != %d");
|
||||
TEST(i, fscanf(f, "%[h]", a), 0, "got %d fields, expected %d");
|
||||
TEST(i, ftell(f), 0, "%d != %d");
|
||||
mark(0x11);
|
||||
printf("debug file ungetbuf=%d\n", f->ungetc_buf);
|
||||
TEST(i, fgetc(f), 'x', "'%c' != '%c'");
|
||||
TEST(i, ftell(f), 1, "%d != %d");
|
||||
|
||||
TEST(i, fseek(f, 0, SEEK_SET), 0, "%d != %d");
|
||||
TEST(i, ungetc('x', f), 'x', "%d != %d");
|
||||
mark(0x22);
|
||||
TEST(i, fread(a, 1, sizeof a, f), 14, "read %d, expected %d");
|
||||
a[14] = 0;
|
||||
TEST_S(a, "xhello, world\n", "mismatch reading ungot character");
|
||||
|
||||
TEST(i, fseek(f, 0, SEEK_SET), 0, "%d != %d");
|
||||
TEST(i, fscanf(f, "%[x]", a), 0, "got %d fields, expected %d");
|
||||
TEST(i, ungetc('x', f), 'x', "unget failed after fscanf: %d != %d");
|
||||
TEST(i, fgetc(f), 'x', "'%c' != '%c'");
|
||||
mark(0x33);
|
||||
TEST(i, ftell(f), 1, "%d != %d");
|
||||
TEST(i, fgetc(f), 'h', "'%c' != '%c'");
|
||||
|
||||
printf("%s finished\n", __FILE__);
|
||||
fclose(f);
|
||||
return t_status;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/* ungetc example */
|
||||
#include <stdio.h>
|
||||
|
||||
void trace_file(FILE* f, char* cmt);
|
||||
|
||||
int main ()
|
||||
{
|
||||
FILE * pFile;
|
||||
int c;
|
||||
char buffer [256];
|
||||
|
||||
pFile = fopen ("myfile.txt","rt");
|
||||
if (pFile==NULL) perror ("Error opening file");
|
||||
else while (!feof (pFile)) {
|
||||
trace_file(pFile, "1");
|
||||
|
||||
c=getc (pFile);
|
||||
|
||||
trace_file(pFile, "before ungetc");
|
||||
|
||||
if (c == EOF) break;
|
||||
if (c == '#') ungetc ('@',pFile);
|
||||
else ungetc (c,pFile);
|
||||
|
||||
trace_file(pFile, "after");
|
||||
|
||||
if (fgets (buffer,255,pFile) != NULL)
|
||||
puts (buffer);
|
||||
else break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void trace_file(FILE* f, char* cmt)
|
||||
{
|
||||
printf("%s[%s]\n", cmt, f->buffer);
|
||||
printf("mode=%0X, filesize=%d, filepos=%d\n", f->mode, f->filesize, f->filepos);
|
||||
printf("ungetc=%d, buffer_start=%d, buffer_end=%d\n", f->ungetc_buf, f->buffer_start, f->buffer_end);
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
// suballocator functions
|
||||
extern void* wtmalloc(size_t size);
|
||||
extern void wtfree(void *pointer);
|
||||
extern void* wtrealloc(void* pointer, size_t size);
|
||||
extern void* wtcalloc (size_t num, size_t size);
|
||||
extern int wtmalloc_freelist_check();
|
||||
extern int wtmalloc_poiner_check(void *ptr);
|
||||
extern void wtdump_alloc_stats();
|
||||
|
||||
#ifdef __GNUC__
|
||||
void* sysmalloc(size_t sz)
|
||||
{
|
||||
return malloc(sz);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define NUMPTR 10000
|
||||
|
||||
char *pointers[NUMPTR];
|
||||
char values[NUMPTR];
|
||||
int sizes[NUMPTR];
|
||||
|
||||
int checkvalues()
|
||||
{
|
||||
for (int i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
if (!pointers[i]) continue;
|
||||
assert(wtmalloc_poiner_check(pointers[i]));
|
||||
|
||||
for (int j = 0; j < sizes[i]; j++)
|
||||
assert(pointers[i][j] == values[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
char *ptr;
|
||||
int i, sz;
|
||||
|
||||
puts("Test started");
|
||||
|
||||
// test start settings
|
||||
assert(wtmalloc_freelist_check());
|
||||
// test just single alloc/dealloc
|
||||
ptr = wtmalloc(1000);
|
||||
assert(wtmalloc_poiner_check(ptr));
|
||||
wtfree(ptr);
|
||||
assert(wtmalloc_freelist_check());
|
||||
|
||||
puts("test allocation started");
|
||||
// test allocation
|
||||
for (i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
sz = rand() % 4200;
|
||||
pointers[i] = wtmalloc(sz);
|
||||
sizes[i] = sz;
|
||||
values[i] = sz % 256;
|
||||
memset(pointers[i], values[i], sz);
|
||||
|
||||
assert(wtmalloc_freelist_check());
|
||||
}
|
||||
assert(checkvalues());
|
||||
|
||||
puts("test random deallocation started");
|
||||
// random deallocation
|
||||
for (i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
sz = rand() % 2;
|
||||
if (sz)
|
||||
{
|
||||
wtfree(pointers[i]);
|
||||
pointers[i] = NULL;
|
||||
}
|
||||
}
|
||||
assert(wtmalloc_freelist_check());
|
||||
assert(checkvalues());
|
||||
|
||||
puts("test allocation in free list gaps started");
|
||||
// test allocation in free list gaps
|
||||
for (i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
if (pointers[i]) continue;
|
||||
|
||||
sz = rand() % 4200;
|
||||
pointers[i] = wtmalloc(sz);
|
||||
sizes[i] = sz;
|
||||
values[i] = sz % 256;
|
||||
memset(pointers[i], values[i], sz);
|
||||
}
|
||||
assert(wtmalloc_freelist_check());
|
||||
assert(checkvalues());
|
||||
|
||||
puts("test realloc started");
|
||||
// test realloc
|
||||
for (i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
sz = rand() % 4200;
|
||||
pointers[i] = wtrealloc(pointers[i], sz);
|
||||
|
||||
sizes[i] = sz;
|
||||
memset(pointers[i], values[i], sz);
|
||||
}
|
||||
assert(wtmalloc_freelist_check());
|
||||
assert(checkvalues());
|
||||
|
||||
|
||||
puts("test full deallocation started");
|
||||
// full deallocation
|
||||
for (i = 0; i < NUMPTR; i++)
|
||||
{
|
||||
wtfree(pointers[i]);
|
||||
pointers[i] = NULL;
|
||||
}
|
||||
assert(wtmalloc_freelist_check());
|
||||
|
||||
wtdump_alloc_stats();
|
||||
|
||||
printf("\ntests all OK\n");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
see
|
||||
source/readme.*
|
||||
source/changelog
|
||||
source/tcc-doc.info or .texi
|
||||
|
||||
building Kolibri version
|
||||
>make -f Makefile.kos32
|
||||
|
||||
========= for compiler developers =========
|
||||
read .\source\readme_kos32.txt
|
||||
|
||||
------ TODO -------
|
||||
-more libc stardard functions. see report below
|
||||
-more Kolibly SysFn wrappers. see \libc\KOSfuncs_inc_status.txt
|
||||
-add stdin, stderr, stdout emulation íå õâàòàåò stdin, stdout - ìîæíî ñäåëàòü êàê stderr!, íî íàäî âîçèòüñÿ çàîäíî ñ ferror & feof
|
||||
-getchar, gets if returs errorcode (0, null) - you must exit program, because of closed console window
|
||||
-ïðè íîðìàëüíîì âûõîäå çàêðûâàòü êîíñîëü
|
||||
|
||||
|
||||
------ errors ------
|
||||
-åñëè ïðîåêò ìíîãîôàéëîâûé - .dbg ãåíåðèò äóáëèðóþùèåñÿ ìåòêè äàííûõ, òèïà L.78 ìîæåò óêàçûâàòü íà äðóãîé ñåãìåíò (
|
||||
-.dbg sometimes generated improperly for source code labels
|
||||
|
||||
----- fixed errors ------
|
||||
-if static var sized more than 14096+ -> crash compiled .exe (kos)
|
||||
(^ default stack size set at compile time tccmeos:177 is below 4k)
|
||||
FIX - use -stack=1280000 option
|
||||
-con_set_title is NULL. fixed 180128
|
||||
-not working: default search path are ./include ./lib from executable (under KOS need to use -Bpath_to_ktcc)
|
||||
--start.o not found using -B (kos) - put near your.c file fixed 181027
|
||||
|
||||
|
||||
|
||||
========= libc ===========
|
||||
-no "finished" in title of console program after exit console - use con_exit()
|
||||
-used system memory allocator (4096 bytes minimum)
|
||||
|
||||
|
||||
libc not complete. overall status:
|
||||
no files:
|
||||
limits.h
|
||||
locale.h
|
||||
setjmp.h
|
||||
signal.h
|
||||
wchar.h
|
||||
wctype.h
|
||||
|
||||
|
||||
|
||||
functions absent list:
|
||||
|
||||
stdio.h:
|
||||
remove
|
||||
rename
|
||||
tmpfile
|
||||
tmpnam
|
||||
freopen
|
||||
setbuf
|
||||
setvbuf
|
||||
|
||||
|
||||
stdlib.h:
|
||||
atexit
|
||||
getenv
|
||||
system
|
||||
bsearch
|
||||
qsort
|
||||
mblen
|
||||
mbtowc
|
||||
wctomb
|
||||
mbstowcs
|
||||
wcstombs
|
||||
|
||||
string.h:
|
||||
strxfrm
|
||||
|
||||
time.h: - needs include kos32sys1.h
|
||||
asctime
|
||||
ctime
|
||||
gmtime
|
||||
localtime - non standard
|
||||
strftime
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Status or libc tests
|
||||
|
||||
---FAILED---
|
||||
strtoul incorrect work with big unsigned > MAX_LONG
|
||||
|
||||
|
||||
---NOT TESTED---
|
||||
no library fns realized
|
||||
qsort
|
||||
time
|
||||
|
||||
---HANG---
|
||||
sscanf
|
||||
>TEST_F(0x1234p56) - no %a formats
|
||||
|
||||
|
||||
---STACK IS SMALL---
|
||||
use new -stack=1280000 option to pass test
|
||||
tstring
|
||||
strtodlong
|
||||
|
||||
|
||||
--other--
|
||||
fscanf
|
||||
-?scanf ignores width specs, '*' and [chars], cant read %a float
|
||||
-%n counts as parameter
|
||||
|
||||
snprintf
|
||||
-some format misturbances
|
||||
-may incorrect prints unsigned > 2147483647L
|
||||
|
||||
ungetc
|
||||
-ungetc fails if filepos == 0 - by design
|
||||
|
||||
all file ops limited to 2Gb
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
CC=../bin/kos32-tcc
|
||||
CFLAGS= -I ../libc/include
|
||||
|
||||
all:
|
||||
$(CC) $(CFLAGS) asm_ex.c -lck -o asm_ex.kex
|
||||
$(CC) $(CFLAGS) consoleio.c -lck -o consoleio.kex
|
||||
$(CC) $(CFLAGS) files.c -lck -o files.kex
|
||||
$(CC) $(CFLAGS) winbasics.c -lck -o winbasics.kex
|
||||
$(CC) $(CFLAGS) dynamic.c -lck -lhttp -linputbox -o dynamic.kex
|
||||
$(CC) $(CFLAGS) load_coff.c -o load_coff.kex -lck
|
||||
$(CC) $(CFLAGS) graphics.c -lck -lgb -o graphics.kex
|
||||
$(CC) $(CFLAGS) dir_example.c -lck -o dir_example.kex
|
||||
$(CC) $(CFLAGS) getopt_ex.c -lck -o getopt_ex.kex
|
||||
|
||||
$(CC) $(CFLAGS) clayer/msgbox.c -lck -lmsgbox -o clayer/msgbox.kex
|
||||
$(CC) $(CFLAGS) clayer/rasterworks.c -lck -lrasterworks -o clayer/rasterworks.kex
|
||||
$(CC) $(CFLAGS) clayer/boxlib.c -lck -lbox -o clayer/boxlib.kex
|
||||
$(CC) $(CFLAGS) clayer/libimg.c -lck -limg -o clayer/libimg.kex
|
||||
$(CC) $(CFLAGS) clayer/dialog.c -lck -ldialog -o clayer/dialog.kex
|
||||
|
||||
$(CC) $(CFLAGS) net/tcpsrv_demo.c -lck -o net/tcpsrv_demo.kex
|
||||
$(CC) $(CFLAGS) net/nslookup.c -lck -lnetwork -o net/nslookup.kex
|
||||
$(CC) $(CFLAGS) net/http_tcp_demo.c -lck -lnetwork -o net/http_tcp_demo.kex
|
||||
|
||||
$(CC) $(CFLAGS) tinygl/fps.c tinygl/gears.c -o tinygl/gears.kex -ltinygl -lck
|
||||
|
||||
clean:
|
||||
rm *.kex clayer/*.kex net/*.kex tinygl/*.kex
|
@ -1,68 +0,0 @@
|
||||
/* examples for interoperability with assembler
|
||||
|
||||
1. Calling assembler code from .c : see in libc\math any .asm file
|
||||
2. Using inline assembler: see \include\kos32sys1.h and libc\math\fmod.c
|
||||
- https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Extended-Asm.html
|
||||
- not all constraints from gcc are supported, no "f" or "t" for example
|
||||
- not supported clobberring st registers, must manual add "fstp %%st" at end or similar
|
||||
- need full suffixes for opcodes, fstpl but not fstp
|
||||
|
||||
3. Calling c functions from .asm: see \libc\start\start.asm:99
|
||||
Remember:
|
||||
- small ints always passed as int32, floating point params as 64-bit
|
||||
- returned structs passed on stack with additional hidden 1st param
|
||||
- c functions can use EAX, ECX, EDX without warnings
|
||||
- .c default is cdecl calling convention https://en.wikipedia.org/wiki/X86_calling_conventions
|
||||
- dont use fastcall calling convention, tinycc realized it non-conformant way
|
||||
- tinycc supports only ELF object files
|
||||
|
||||
tcc can be used as a linker
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
printf("------------------------------------------------------\n");
|
||||
printf ( "remainder of 5.3 / 2 is %f\n", remainder (5.3,2) );
|
||||
printf ( "remainder of 18.5 / 4.2 is %f\n", remainder (18.5,4.2) );
|
||||
//remainder of 5.3 / 2 is -0.700000
|
||||
//remainder of 18.5 / 4.2 is 1.700000
|
||||
|
||||
printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) );
|
||||
printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) );
|
||||
// fmod of 5.3 / 2 is 1.300000
|
||||
// fmod of 18.5 / 4.2 is 1.700000
|
||||
|
||||
double param, fractpart, intpart, result;
|
||||
int n;
|
||||
|
||||
param = 3.14159265;
|
||||
fractpart = modf (param , &intpart);
|
||||
printf ("%f = %f + %f \n", param, intpart, fractpart);
|
||||
//3.141593 = 3.000000 + 0.141593
|
||||
|
||||
param = 0.95;
|
||||
n = 4;
|
||||
result = ldexp (param , n);
|
||||
printf ("%f * 2^%d = %f\n", param, n, result);
|
||||
//0.950000 * 2^4 = 15.200000
|
||||
|
||||
param = 8.0;
|
||||
result = frexp (param , &n);
|
||||
printf ("%f = %f * 2^%d\n", param, result, n);
|
||||
//8.000000 = 0.500000 * 2^4
|
||||
param = 50;
|
||||
result = frexp (param , &n);
|
||||
printf ("%f = %f * 2^%d\n", param, result, n);
|
||||
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#SHS
|
||||
/sys/@notify 'Build in progress...\nYou will find binaries in /tmp0/1/tccbin' -I
|
||||
mkdir /tmp0/1/tccbin
|
||||
../tcc asm_ex.c -lck -o /tmp0/1/tccbin/asm_ex
|
||||
../tcc consoleio.c -lck -o /tmp0/1/tccbin/consoleio
|
||||
../tcc files.c -lck -o /tmp0/1/tccbin/files
|
||||
../tcc winbasics.c -lck -o /tmp0/1/tccbin/winbasics
|
||||
../tcc dynamic.c -lck -lhttp -linputbox -o /tmp0/1/tccbin/dynamic
|
||||
../tcc load_coff.c -o /tmp0/1/tccbin/load_coff -lck
|
||||
../tcc clayer/msgbox.c -lck -lmsgbox -o /tmp0/1/tccbin/msgbox
|
||||
../tcc graphics.c -lck -lgb -o /tmp0/1/tccbin/graphics
|
||||
../tcc clayer/rasterworks.c -lck -lrasterworks -o /tmp0/1/tccbin/rasterworks
|
||||
../tcc clayer/boxlib.c -lck -lbox -o /tmp0/1/tccbin/boxlib_ex
|
||||
../tcc clayer/libimg.c -lck -limg -o /tmp0/1/tccbin/libimg_ex
|
||||
cp clayer/logo.png /tmp0/1/tccbin/logo.png
|
||||
../tcc clayer/dialog.c -lck -ldialog -o /tmp0/1/tccbin/dialog_ex
|
||||
../tcc dir_example.c -lck -o /tmp0/1/tccbin/dir_example
|
||||
../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tccbin/tcpsrv_demo
|
||||
../tcc net/nslookup.c -lck -lnetwork -o /tmp0/1/tccbin/nslookup
|
||||
../tcc net/http_tcp_demo.c -lck -lnetwork -o /tmp0/1/tccbin/http_tcp_demo
|
||||
../tcc getopt_ex.c -lck -o /tmp0/1/tccbin/getopt_ex
|
||||
../tcc tinygl/fps.c tinygl/gears.c -o /tmp0/1/tccbin/gears -ltinygl -lck
|
||||
exit
|
@ -1,110 +0,0 @@
|
||||
// BOXLIB EXAMPLE (scrollbar, progressbar, editbox and checkbox)
|
||||
// Writed by maxcodehack and superturbocat2001
|
||||
|
||||
#include <kos32sys1.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <clayer/boxlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WIN_W 640
|
||||
#define WIN_H 563
|
||||
|
||||
#define ED_BUFF_LEN 50
|
||||
#define TEXT_SIZE 0x10000000
|
||||
#define SCROLL_BUTTON_SIZE 15
|
||||
#define SCROLL_MAX_LEN 215
|
||||
#define BLACK 0x000000
|
||||
#define WHITE 0xFFFFFF
|
||||
#define BLUE 0x0000FF
|
||||
|
||||
uint32_t wheels;
|
||||
char* title = "Boxlib example";
|
||||
char ed_buff[ED_BUFF_LEN];
|
||||
|
||||
|
||||
scrollbar scroll = {15, WIN_W - 26, WIN_H - 29, 0, 0, 2, 215, SCROLL_BUTTON_SIZE, 0,0x707070,0xD2CED0,0x555555};
|
||||
progressbar pg = {0, 10, 10, 270, 35, 1, 0, 200, 0xB4B4B4, 0x2728FF, 0xA9A9A9};
|
||||
edit_box ed={WIN_W-140,10,60,0xFFFFFF,0x6a9480,0,0x6a9480, BLACK | TEXT_SIZE, ED_BUFF_LEN, ed_buff,NULL,ed_focus};
|
||||
check_box output_off={X_W(10, 15), Y_H(120,15), 10, WHITE, BLUE, BLACK | TEXT_SIZE, "Disable duplicate output",0};
|
||||
|
||||
void draw_window(){
|
||||
BeginDraw();
|
||||
DrawWindow(215,100,WIN_W,WIN_H,title, 0x858585, 0x34);
|
||||
edit_box_draw(&ed);
|
||||
check_box_draw2(&output_off);
|
||||
if(!output_off.flags)
|
||||
{
|
||||
draw_text_sys(ed_buff, 10, 90, strlen(ed_buff), BLACK | TEXT_SIZE);
|
||||
}
|
||||
scrollbar_v_draw(&scroll);
|
||||
progressbar_draw(&pg);
|
||||
EndDraw();
|
||||
}
|
||||
|
||||
//// EVENTMASK
|
||||
#define EVM_REDRAW 1
|
||||
#define EVM_KEY 2
|
||||
#define EVM_BUTTON 4
|
||||
#define EVM_EXIT 8
|
||||
#define EVM_BACKGROUND 16
|
||||
#define EVM_MOUSE 32
|
||||
#define EVM_IPC 64
|
||||
#define EVM_STACK 128
|
||||
#define EVM_DEBUG 256
|
||||
#define EVM_STACK2 512
|
||||
#define EVM_MOUSE_FILTER 0x80000000
|
||||
#define EVM_CURSOR_FILTER 0x40000000
|
||||
//// EVENTMASK
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
kolibri_boxlib_init();
|
||||
init_checkbox2(&output_off);
|
||||
set_event_mask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE+EVM_MOUSE_FILTER);
|
||||
while(1)
|
||||
{
|
||||
switch(GetOsEvent())
|
||||
{
|
||||
case KOLIBRI_EVENT_BUTTON:
|
||||
if (get_os_button() == 1) exit(0);
|
||||
break;
|
||||
|
||||
case KOLIBRI_EVENT_KEY:
|
||||
edit_box_key(&ed, get_key().val);
|
||||
draw_window();
|
||||
break;
|
||||
|
||||
case KOLIBRI_EVENT_REDRAW:
|
||||
draw_window();
|
||||
break;
|
||||
case KOLIBRI_EVENT_MOUSE:
|
||||
edit_box_mouse(&ed);
|
||||
scrollbar_v_mouse(&scroll);
|
||||
pg.value = scroll.position;
|
||||
progressbar_draw(&pg);
|
||||
check_box_mouse2(&output_off);
|
||||
unsigned int scroll_strong = 10;
|
||||
wheels = GetMouseWheels();
|
||||
if(wheels & 0xFFFF)
|
||||
{
|
||||
if((short)wheels > 0){
|
||||
scroll.position += scroll_strong;
|
||||
if(scroll.position>scroll.max_area-scroll.cur_area)
|
||||
{
|
||||
scroll.position=scroll.max_area-scroll.cur_area;
|
||||
}
|
||||
}
|
||||
else if((short)wheels < 0 && scroll.position > 0){
|
||||
scroll.position -= scroll_strong;
|
||||
if((int)scroll.position<0){
|
||||
scroll.position=0;
|
||||
}
|
||||
}
|
||||
scrollbar_v_draw(&scroll);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#include <kos32sys1.h>
|
||||
#include <clayer/dialog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
kolibri_dialog_init(); // dialog init
|
||||
open_dialog *dlg_open = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); // create opendialog struct
|
||||
OpenDialog_init(dlg_open); // Initializing an open dialog box.
|
||||
OpenDialog_start(dlg_open); // Show open dialog box
|
||||
|
||||
color_dialog *color_select = kolibri_new_color_dialog(SELECT, 10, 10,420,320); // create colordialog struct
|
||||
ColorDialog_init(color_select); // Initializing an color dialog box.
|
||||
ColorDialog_start(color_select); // Show color dialog
|
||||
|
||||
if(dlg_open->status == SUCCESS){
|
||||
printf("File selected '%s'\n",dlg_open->openfile_path);
|
||||
}else{
|
||||
puts("No file selected!");
|
||||
}
|
||||
|
||||
if(color_select->status == SUCCESS){
|
||||
printf("Color selected: #%06X\n",color_select->color);
|
||||
RGB color_rgb = (RGB)color_select->color;
|
||||
printf("Red:%d Green:%d Blue:%d", color_rgb.red, color_rgb.green, color_rgb.blue);
|
||||
}else{
|
||||
puts("No color selected!");
|
||||
}
|
||||
|
||||
free(dlg_open);
|
||||
free(color_select);
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/* Written by turbocat2001 (Logaev Maxim) */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <clayer/libimg.h>
|
||||
#include <kos32sys1.h>
|
||||
|
||||
#define NEW_IMG_H 128
|
||||
#define NEW_IMG_W 128
|
||||
|
||||
#define IMG_H 256
|
||||
#define IMG_W 256
|
||||
|
||||
Image *image_blend; // Create image struct
|
||||
|
||||
struct kolibri_system_colors sys_color_table; // Create system colors table
|
||||
|
||||
char* load_img(char* fname, int32_t* read_sz){ // Image file upload function
|
||||
FILE *f = fopen(fname, "rb");
|
||||
if (!f) {
|
||||
printf("Can't open file: %s\n", fname);
|
||||
exit(0);
|
||||
}
|
||||
if (fseek(f, 0, SEEK_END)) {
|
||||
printf("Can't SEEK_END file: %s\n", fname);
|
||||
exit(0);
|
||||
}
|
||||
int filesize = ftell(f);
|
||||
rewind(f);
|
||||
char* fdata = malloc(filesize);
|
||||
if(!fdata) {
|
||||
printf("No memory for file %s\n", fname);
|
||||
exit(0);
|
||||
}
|
||||
*read_sz = fread(fdata, 1, filesize, f);
|
||||
if (ferror(f)) {
|
||||
printf("Error reading file %s\n", fname);
|
||||
exit(0);
|
||||
}
|
||||
fclose(f);
|
||||
return fdata;
|
||||
}
|
||||
|
||||
void DrawGUI(){
|
||||
BeginDraw();
|
||||
DrawWindow(10, 40, (IMG_W+NEW_IMG_W)+50, IMG_H+50, "Libimg", sys_color_table.work_area, 0x34);
|
||||
img_draw(image_blend, 10, 10, IMG_W*2, IMG_H , 0, 0); // Draw blended image to window
|
||||
EndDraw();
|
||||
}
|
||||
|
||||
int main(){
|
||||
if (kolibri_libimg_init() == -1){
|
||||
printf("Error loading lib_img.obj\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
get_system_colors(&sys_color_table); // Get system colors theme
|
||||
set_event_mask(0xC0000027);
|
||||
|
||||
uint32_t img_size;
|
||||
void *file_data = load_img("logo.png", &img_size); // Get RAW data and size
|
||||
|
||||
Image* image = img_decode(file_data, img_size, 0); // Decode RAW data to Image data
|
||||
|
||||
if (image->Type != IMAGE_BPP32) {
|
||||
image = img_convert(image, NULL, IMAGE_BPP32, 0, 0); // Convert image to format BPP32
|
||||
if (!image) {
|
||||
printf("Сonvert error!: \n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
image_blend = img_create(IMG_W+NEW_IMG_W, IMG_H, IMAGE_BPP32); // Create an empty layer
|
||||
img_fill_color(image_blend, IMG_W+NEW_IMG_W, IMG_H, sys_color_table.work_area); // Fill the layer with one color
|
||||
img_blend(image_blend, image, 0, 0, 0, 0, IMG_W, IMG_H); // Blending images to display the alpha channel.
|
||||
/* Reduce image size from 256x256 to 128x128 */
|
||||
image = img_scale(image, 0, 0, IMG_W, IMG_H, NULL, LIBIMG_SCALE_STRETCH , LIBIMG_INTER_BILINEAR, NEW_IMG_W, NEW_IMG_H);
|
||||
img_blend(image_blend, image, 256, 0, 0, 0, NEW_IMG_W, NEW_IMG_H);
|
||||
img_destroy(image); // Destroy image structure
|
||||
free(file_data); // Free allocated file_data buffer
|
||||
|
||||
/* Main event loop */
|
||||
while (1) {
|
||||
switch(get_os_event()){
|
||||
case KOLIBRI_EVENT_REDRAW:
|
||||
DrawGUI();
|
||||
break;
|
||||
case KOLIBRI_EVENT_BUTTON:
|
||||
if (get_os_button() == 1){
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 51 KiB |
@ -1,8 +0,0 @@
|
||||
#include <clayer/msgbox.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
msgbox *msg1 = NULL;
|
||||
msg1 = kolibri_new_msgbox("Title", "Text in window", 0, "Ok");
|
||||
kolibri_start_msgbox(msg1, NULL);
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <kos32sys1.h>
|
||||
#include <clayer/rasterworks.h>
|
||||
|
||||
// Sizes
|
||||
int x_size = 768, y_size = 256;
|
||||
|
||||
// Out example string
|
||||
char* string = "Пример/Example";
|
||||
|
||||
int main()
|
||||
{
|
||||
// Count length
|
||||
int ln_str = countUTF8Z(string, -1);
|
||||
|
||||
// Create image buffer
|
||||
void *buffi = malloc(x_size * y_size * 3 * sizeof(char) + 8);
|
||||
|
||||
// Set sizes
|
||||
*((int*)buffi) = x_size;
|
||||
*((int*)buffi+1) = y_size;
|
||||
|
||||
// Fill color
|
||||
memset((char*)buffi + 8, 0xFF, x_size * y_size * 3);
|
||||
|
||||
// Draw text on buffer
|
||||
drawText(buffi, 5, 0, string, ln_str, 0xFF000000, 0x30C18);
|
||||
drawText(buffi, 5, 32, string, ln_str, 0xFF000000, 0x1030C18);
|
||||
drawText(buffi, 5, 64, string, ln_str, 0xFF000000, 0x2030C18);
|
||||
drawText(buffi, 5, 96, string, ln_str, 0xFF000000, 0x4030C18);
|
||||
drawText(buffi, 5, 128, string, ln_str, 0xFF000000, 0x8030C18);
|
||||
drawText(buffi, 5, 160, string, ln_str, 0xFF000000, 0x0F031428);
|
||||
|
||||
while (1)
|
||||
{
|
||||
switch (get_os_event())
|
||||
{
|
||||
case 1:
|
||||
BeginDraw();
|
||||
DrawWindow(50, 50, 800, 300, "Rasterworks Example", 0x999999, 0x34);
|
||||
DrawBitmap(buffi + 8, 10, 10, 768, 256);
|
||||
EndDraw();
|
||||
break;
|
||||
case 2:
|
||||
get_key();
|
||||
break;
|
||||
case 3:
|
||||
if (get_os_button() == 1) exit(0);
|
||||
break;
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// demonstration conio use, color text
|
||||
// more info in conio.h
|
||||
|
||||
#include <conio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
if (con_init_console_dll()) return 1; // init fail
|
||||
|
||||
// con_write_asciiz("\033[0;31;42m test \n"); // red on green bk
|
||||
|
||||
for(i = 30; i < 48; i++)
|
||||
{
|
||||
con_printf("\033[%dmColor 0x%02X: ", i, i);
|
||||
con_write_asciiz("Text sample.");
|
||||
|
||||
con_printf(" printf %s test %d\n", "small", i);
|
||||
|
||||
}
|
||||
|
||||
con_exit(0);
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#include <dir.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char *path=getcwd(NULL, PATH_MAX);
|
||||
printf("Current directory: %s\n", path);
|
||||
if(true==mkdir("test")){
|
||||
puts("Test folder created!");
|
||||
}
|
||||
else{
|
||||
puts("Error creating folder!");
|
||||
}
|
||||
short_file_info *info;
|
||||
int num = lsdir(path, &info);
|
||||
if(num==FS_ERROR)
|
||||
{
|
||||
puts("File system error.");
|
||||
return -1;
|
||||
}
|
||||
printf("Objects in the folder: %d\n", num);
|
||||
for(int j=0; j<num; j++)
|
||||
{
|
||||
printf("%s ", info[j].name);
|
||||
if(info[j].type==T_FOLDER)
|
||||
{
|
||||
printf("(Folder)\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("(File)\n");
|
||||
}
|
||||
}
|
||||
free(info);
|
||||
setcwd("/sys");
|
||||
path=getcwd(NULL, PATH_MAX);
|
||||
printf("Move to the directory: %s\n", path);
|
||||
free(path);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#include <conio.h>
|
||||
#include <clayer/http.h>
|
||||
#include <clayer/inputbox.h>
|
||||
|
||||
#define OK 200
|
||||
|
||||
int main() {
|
||||
if (con_init_console_dll()) return 1; // init fail
|
||||
con_write_asciiz("Wait, I'll ask you... when I'll done to fetch one site...\n");
|
||||
con_set_title("Dynamicaly linked app");
|
||||
|
||||
http_msg *h = http_get("http://kolibrios.org/en/", 0, HTTP_FLAG_BLOCK, "");
|
||||
http_long_receive(h);
|
||||
|
||||
if (h->status == OK) {
|
||||
con_write_string(h->content_ptr, h->content_length);
|
||||
} else {
|
||||
con_write_asciiz("Oops! Can't access to the page.\n");
|
||||
}
|
||||
char buffer[256];
|
||||
InputBox(buffer, "Hay!", "How do you do?", "Hmm?", 0, 256, 0);
|
||||
con_printf("Your answer is \"%s\"\n", buffer);
|
||||
con_write_string("It's surprising, isn't it?", 26);
|
||||
con_exit(0);
|
||||
return 0;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
int i;
|
||||
char c;
|
||||
FILE *f;
|
||||
FILE *fin;
|
||||
FILE *fout;
|
||||
|
||||
//write to file
|
||||
f=fopen("testfile.txt","w");
|
||||
|
||||
for(i=0;i<50;i++)
|
||||
{
|
||||
fputc('1',f);
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
//append to file
|
||||
f=fopen("testfile.txt","a");
|
||||
|
||||
for(i=0;i<50;i++)
|
||||
{
|
||||
fputc('2',f);
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
//copy from testfile.txt to copyfile.txt
|
||||
|
||||
fin=fopen("testfile.txt","r");
|
||||
fout=fopen("copyfile.txt","w");
|
||||
|
||||
while((c=fgetc(fin))!=EOF)
|
||||
{
|
||||
fputc(c,fout);
|
||||
}
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void main(int argc, char *argv[]) {
|
||||
int c;
|
||||
if(argc<2)
|
||||
{
|
||||
puts("Usage: getopt_ex [options]\n");
|
||||
puts("-a Show 'Option a'");
|
||||
puts("-B Show 'Option B'");
|
||||
puts("-n [num] Show 'num'");
|
||||
}
|
||||
while ((c = getopt(argc, argv, "aBn:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
puts("Option 'a'");
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
puts("Option 'B'");
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
printf("Option n: value=%d\n", atoi(optarg));
|
||||
break;
|
||||
|
||||
case '?':
|
||||
printf("ERROR: illegal option %s\n", argv[optind-1]);
|
||||
exit(0);
|
||||
|
||||
default:
|
||||
printf("WARNING: no handler for option %c\n", c);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#include <kos32sys1.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <clayer/gb.h>
|
||||
|
||||
/// ===========================================================
|
||||
|
||||
int main()
|
||||
{
|
||||
GB_BMP b;
|
||||
unsigned event;
|
||||
|
||||
b.w = 300;
|
||||
b.h = 200;
|
||||
b.bmp = malloc (300*200*3);
|
||||
|
||||
gb_bar (&b, 4, 8, 4, 12, 0xff0000); // red
|
||||
gb_bar (&b, 10, 8, 4, 12, 0x00ff00); // green
|
||||
gb_bar (&b, 16, 8, 4, 12, 0x0000ff); // blue
|
||||
|
||||
gb_line(&b, 4, 30, 50, 30, 0xffffff); // white line
|
||||
gb_line(&b, 55, 4, 120, 60, 0xf0f033); // another line
|
||||
|
||||
gb_rect(&b, 65, 24, 100, 60, 0x2065ff); // rectangle
|
||||
|
||||
gb_circle(&b, 55, 95, 40, 0x20ff20); // circle
|
||||
|
||||
for (;;)
|
||||
{
|
||||
event = get_os_event();
|
||||
switch (event)
|
||||
{
|
||||
case 1:
|
||||
begin_draw();
|
||||
sys_create_window(50, 50, 310, 230, "testlibgb" ,0x34f0f0f0, 0x14);
|
||||
draw_bitmap(b.bmp, 5, 25, 300, 200);
|
||||
end_draw();
|
||||
break;
|
||||
case 2:
|
||||
get_key();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (1==get_os_button())
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
/// ===========================================================
|
@ -1,21 +0,0 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
/*Using the "coff" library in ktcc using "inputbox.obj" as an example*/
|
||||
|
||||
unsigned (*InputBox)(void* Buffer, char* Caption, char* Prompt, char* Default, unsigned long Flags, unsigned long BufferSize, void* RedrawProc);
|
||||
|
||||
void *InputBoxLib;
|
||||
|
||||
void load_coff()
|
||||
{
|
||||
InputBoxLib = dlopen("/sys/lib/inputbox.obj", RTLD_GLOBAL);
|
||||
InputBox = dlsym(InputBoxLib,"InputBox");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
load_coff();
|
||||
char buffer[256];
|
||||
InputBox(buffer, "Hay!", "How do you do?", "Hmm?", 10, 256, 0);
|
||||
dlclose(InputBoxLib);
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
#include <net/network.h>
|
||||
#include <conio.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
con_init_console_dll();
|
||||
networklib_init();
|
||||
con_set_title("http request demo using raw sockets");
|
||||
|
||||
char *host = "kolibrios.org";
|
||||
int port = 80;
|
||||
printf("Connecting to %s on port %d\n", host, port);
|
||||
|
||||
struct addrinfo *addr_info;
|
||||
char port_str[16]; sprintf(port_str, "%d", port);
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
|
||||
if (getaddrinfo(host, port_str, 0, &addr_info) != 0) {
|
||||
printf("Host %s not found!\n", host);
|
||||
freeaddrinfo(addr_info);
|
||||
exit(-1);
|
||||
}
|
||||
printf("IP address of %s is %s\n", host, inet_ntoa(addr_info->ai_addr->sin_addr));
|
||||
//printf("Host port = %d\n", addr_info->ai_addr->sin_port >> 8);
|
||||
|
||||
char request[256];
|
||||
sprintf(request, "GET /en/ HTTP/1.1\r\nHost: %s\r\n\r\n", host);
|
||||
printf("request = %s\n", request);
|
||||
|
||||
int sock = socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
puts("Connecting...\n");
|
||||
if (connect(sock, addr_info->ai_addr, addr_info->ai_addrlen) != 0) {
|
||||
printf("Connection failed, errno = %d\n", errno);
|
||||
exit(errno);
|
||||
}
|
||||
puts("Connected successfully\n");
|
||||
|
||||
puts("Sending request...\n");
|
||||
if (send(sock, request, strlen(request), MSG_NOFLAG) == -1) {
|
||||
printf("Sending failed, errno = %d\n", errno);
|
||||
exit(errno);
|
||||
}
|
||||
puts("Request sended successfully, waiting for response...\n");
|
||||
|
||||
char buf[512 + 1];
|
||||
if (recv(sock, buf, 512, MSG_NOFLAG) == -1) {
|
||||
printf("Receive failed, errno = %d\n", errno);
|
||||
exit(errno);
|
||||
}
|
||||
|
||||
printf("Response = %s\n", buf);
|
||||
|
||||
freeaddrinfo(addr_info);
|
||||
|
||||
close(sock);
|
||||
puts("\n goodbye)\n");
|
||||
con_exit(0);
|
||||
return 0;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#include <net/network.h>
|
||||
#include <conio.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct addrinfo *res;
|
||||
char host[256];
|
||||
|
||||
void main()
|
||||
{
|
||||
con_init_console_dll();
|
||||
networklib_init();
|
||||
con_set_title("nslookup demo");
|
||||
printf("Host name to resolve: ");
|
||||
con_gets(host, 256);
|
||||
host[strlen(host)-1] = '\0';
|
||||
if(getaddrinfo(host ,0, 0, &res)!=0)
|
||||
{
|
||||
puts("Host not found!");
|
||||
freeaddrinfo(res);
|
||||
con_exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s",inet_ntoa(res->ai_addr->sin_addr));
|
||||
freeaddrinfo(res);
|
||||
con_exit(0);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#include <net/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const char msg1[]="Hello!";
|
||||
char msg2='\0';
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sockaddr addr={AF_INET4, PORT(23) , 0, 0};
|
||||
|
||||
int sk1=socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
|
||||
printf("Open socket: %d. Status: %s\n",sk1, strerror(errno));
|
||||
|
||||
bind(sk1, &addr,sizeof(addr));
|
||||
printf("Socket binding. Status: %s\n", strerror(errno));
|
||||
|
||||
listen(sk1, 1);
|
||||
printf("Listening to a socket. Status: %s\n", strerror(errno));
|
||||
printf("You can connect to 'tcp server' via 'telnet' on localhost:23 !");
|
||||
|
||||
int sk2 = accept(sk1, &addr, sizeof(addr));
|
||||
printf("Accept done. Status: %s\n", strerror(errno));
|
||||
|
||||
send(sk2, msg1, strlen(msg1),MSG_NOFLAG);
|
||||
printf("Send message: '%s'. Status: %s\n",msg1, strerror(errno));
|
||||
puts("Received data:");
|
||||
while(msg2!='!')
|
||||
{
|
||||
recv(sk2, &msg2, 1, MSG_NOFLAG);
|
||||
printf("%c",msg2);
|
||||
}
|
||||
close(sk1);
|
||||
close(sk2);
|
||||
puts("\nGood bye!");
|
||||
exit(0);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#include <kos32sys1.h>
|
||||
int time1=0;
|
||||
int time2=0;
|
||||
int fps1=0;
|
||||
int timerend=0;
|
||||
|
||||
int Fps()
|
||||
{
|
||||
int tr;
|
||||
time1=get_tick_count();
|
||||
if (timerend==0)
|
||||
{
|
||||
time2=time1;
|
||||
timerend=time1;
|
||||
}
|
||||
|
||||
tr = time1 - timerend;
|
||||
|
||||
if ((time1 - time2) < 100)
|
||||
{
|
||||
fps1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_bar(330,8, 50,10,0xFFFFFF);
|
||||
draw_number_sys(fps1,330,8,10,0x0);
|
||||
fps1=0;
|
||||
time2=time1;
|
||||
}
|
||||
timerend=time1;
|
||||
return tr;
|
||||
}
|
||||
|
@ -1,313 +0,0 @@
|
||||
#include <tinygl/kosgl.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <kos32sys1.h>
|
||||
#include <kolibrisys.h>
|
||||
|
||||
int Fps();
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int dx,dy;
|
||||
} win;
|
||||
|
||||
#define KEY_ESC 1
|
||||
#define KEY_F 33
|
||||
|
||||
char *title1 = "TinyGL in KolibriOS";
|
||||
char *title2 = "F full screen";
|
||||
char *title3 = "ESC - exit";
|
||||
char *fps = "FPS:";
|
||||
|
||||
unsigned char FullScreen = 0;
|
||||
unsigned char skin = 3;
|
||||
|
||||
struct process_table_entry *pri;
|
||||
KOSGLContext cgl;
|
||||
|
||||
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
|
||||
static GLuint limit;
|
||||
static GLuint count = 1;
|
||||
|
||||
/*
|
||||
* Draw a gear wheel. You'll probably want to call this function when
|
||||
* building a display list since we do a lot of trig here.
|
||||
*
|
||||
* Input: inner_radius - radius of hole at center
|
||||
* outer_radius - radius at center of teeth
|
||||
* width - width of gear
|
||||
* teeth - number of teeth
|
||||
* tooth_depth - depth of tooth
|
||||
*/
|
||||
static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth )
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth/2.0;
|
||||
r2 = outer_radius + tooth_depth/2.0;
|
||||
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel( GL_FLAT );
|
||||
|
||||
glNormal3f( 0.0, 0.0, 1.0 );
|
||||
|
||||
/* draw front face */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin( GL_QUADS );
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f( 0.0, 0.0, -1.0 );
|
||||
|
||||
/* draw back face */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin( GL_QUADS );
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
u = r2*cos(angle+da) - r1*cos(angle);
|
||||
v = r2*sin(angle+da) - r1*sin(angle);
|
||||
len = sqrt( u*u + v*v );
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f( v, -u, 0.0 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
|
||||
glNormal3f( cos(angle), sin(angle), 0.0 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
|
||||
u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
|
||||
v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
|
||||
glNormal3f( v, -u, 0.0 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glNormal3f( cos(angle), sin(angle), 0.0 );
|
||||
}
|
||||
|
||||
glVertex3f( r1*cos(0.0), r1*sin(0.0), width*0.5 );
|
||||
glVertex3f( r1*cos(0.0), r1*sin(0.0), -width*0.5 );
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel( GL_SMOOTH );
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glNormal3f( -cos(angle), -sin(angle), 0.0 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void init( void )
|
||||
{
|
||||
static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };
|
||||
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
|
||||
static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
|
||||
static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
|
||||
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, pos );
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable( GL_LIGHTING );
|
||||
glEnable( GL_LIGHT0 );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red );
|
||||
gear( 1.0, 4.0, 1.0, 20, 0.7 );
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
|
||||
gear( 0.5, 2.0, 2.0, 10, 0.7 );
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue );
|
||||
gear( 1.3, 2.0, 0.5, 10, 0.7 );
|
||||
glEndList();
|
||||
|
||||
glEnable( GL_NORMALIZE );
|
||||
|
||||
glViewport(0, 0, (GLint)500, (GLint)480);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum( -1.0, 1.0, -1, 1, 5.0, 60.0 );
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0.0, 0.0, -40.0 );
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void reshape()
|
||||
{
|
||||
_ksys_get_process_table(pri, -1);
|
||||
glViewport(0, 0, pri->winx_size, pri->winy_size-20);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 60.0);
|
||||
glTranslatef( 0.0, 0.0, 20.0 );
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void disabletgl()
|
||||
{
|
||||
kosglDestroyContext(cgl);
|
||||
free(pri);
|
||||
}
|
||||
|
||||
void Title()
|
||||
{
|
||||
_ksys_write_text(300,8,0x0,fps,strlen(fps));
|
||||
_ksys_write_text(8,8,0x0,title1,strlen(title1));
|
||||
_ksys_write_text(180,8,0x0,title2,strlen(title2));
|
||||
_ksys_write_text(600,8,0x0,title3,strlen(title3));
|
||||
}
|
||||
|
||||
|
||||
void draw_window()
|
||||
{
|
||||
begin_draw();
|
||||
sys_create_window(win.x, win.y, win.dx, win.dy,"Gears", 0xFFFFFF, 0x34);
|
||||
Title();
|
||||
end_draw();
|
||||
}
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
pri=malloc(sizeof(struct process_table_entry));
|
||||
win.x = 100;
|
||||
win.y = 100;
|
||||
win.dx = 400;
|
||||
win.dy = 400;
|
||||
draw_window();
|
||||
_ksys_set_keyboard_mode(1);
|
||||
cgl = kosglCreateContext( 0, 0);
|
||||
kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
|
||||
init();
|
||||
reshape();
|
||||
do{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glPushMatrix();
|
||||
glRotatef( view_rotx, 1.0, 0.0, 0.0 );
|
||||
glRotatef( view_roty, 0.0, 1.0, 0.0 );
|
||||
glRotatef( view_rotz, 0.0, 0.0, 1.0 );
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( -2.0, -2.0, 0.0 );
|
||||
glRotatef( angle, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( 4.1, -2.0, 0.0 );
|
||||
glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( -2.1, 4.2, 0.0 );
|
||||
glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
kosglSwapBuffers();
|
||||
|
||||
angle += 0.01 + 0.3* Fps();
|
||||
switch(_ksys_check_for_event()){
|
||||
case KOLIBRI_EVENT_REDRAW: draw_window();
|
||||
reshape();
|
||||
break;
|
||||
|
||||
case KOLIBRI_EVENT_KEY:
|
||||
switch(get_key().ctrl_key){
|
||||
case KEY_F:
|
||||
if(!FullScreen){
|
||||
skin=0;
|
||||
int screen_size_x;
|
||||
int screen_size_y;
|
||||
_ksys_get_screen_size(&screen_size_x, &screen_size_y);
|
||||
sys_change_window(0,0,screen_size_x,screen_size_y);
|
||||
draw_window();
|
||||
reshape();
|
||||
FullScreen = 1;
|
||||
}
|
||||
else{
|
||||
skin=3;
|
||||
draw_window();
|
||||
sys_change_window(win.x,win.y, win.dx, win.dy);
|
||||
reshape();
|
||||
FullScreen = 0;
|
||||
};
|
||||
break;
|
||||
case KEY_ESC: disabletgl();
|
||||
return;}
|
||||
break;
|
||||
|
||||
case 3: disabletgl();
|
||||
return;
|
||||
}
|
||||
} while(1);
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
newlib-style window example
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "kos32sys1.h"
|
||||
|
||||
struct kolibri_system_colors sys_color_table;
|
||||
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
|
||||
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
|
||||
|
||||
char statusbar[255];
|
||||
char proc_info[1024];
|
||||
char text_line[255];
|
||||
|
||||
enum BUTTONS
|
||||
{
|
||||
BTN_QUIT = 1,
|
||||
BTN_POP = 10,
|
||||
BTN_UNLOCK = 11
|
||||
};
|
||||
|
||||
#define FONT_W 8
|
||||
#define FONT_H 14
|
||||
#define LINES 10
|
||||
|
||||
void draw_window()
|
||||
{
|
||||
int win_hight, win_width, i, pos_y = get_skin_height() + 36; // 60 == 24+36
|
||||
|
||||
// start redraw
|
||||
begin_draw();
|
||||
// define&draw window
|
||||
sys_create_window(10, 40, 600, 400, "My window", /*sys_color_table.work_area*/0xFFFFFF, 0x13);
|
||||
|
||||
get_proc_info(proc_info);
|
||||
win_width = *(int*)(proc_info + 0x3E); // client, 2A windows
|
||||
win_hight = *(int*)(proc_info + 0x42); // client, 2E windows
|
||||
|
||||
define_button((10 << 16) + 80, (30 << 16) + 20, BTN_POP, sys_color_table.work_button);
|
||||
draw_text_sys("BUTTON1", 15, 34, 0, 0x90000000 | sys_color_table.work_button_text); //0x80000000 asciiz
|
||||
|
||||
define_button((100 << 16) + 100, (30 << 16) + 20, BTN_UNLOCK, sys_color_table.work_button);
|
||||
draw_text_sys("BUTTTON2", 110, 34, 0, 0x90000000 | sys_color_table.work_button_text);
|
||||
|
||||
// display statusbar
|
||||
draw_bar(6, win_hight - 17, win_width - 11, 12, 0x80000000 | sys_color_table.work_area); //0x80000000 gradient
|
||||
draw_text_sys(statusbar, 10, win_hight - 15, 0, 0x80000000 | sys_color_table.work_text);
|
||||
|
||||
// display strings
|
||||
for (i = LINES; i > 0; i--)
|
||||
{
|
||||
tiny_snprintf (text_line, sizeof text_line, "Line[%d]<<Just a text>>", i);
|
||||
|
||||
text_line[(win_width - 10 - 5) / FONT_W + 1] = '\0'; // clip text size, seems to big lines crashing OS, and form len by window size
|
||||
// draw_number_sys(nbytes, 5, pos_y, 6, 0x10000000); 8x12 font
|
||||
draw_text_sys(text_line, 5, pos_y, 0, 0x90000000 /*| sys_color_table.work_text*/);
|
||||
pos_y += FONT_H;
|
||||
|
||||
if(pos_y + 29 > win_hight) break; // 12 font + 12 statusbar + 5 border
|
||||
}
|
||||
|
||||
// end redraw
|
||||
end_draw();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int gui_event;
|
||||
uint32_t pressed_button = 0, mouse_button;
|
||||
pos_t mouse_pos;
|
||||
strcpy(statusbar, "Program running...Double click on TEXT for details");
|
||||
|
||||
get_system_colors(&sys_color_table);
|
||||
set_event_mask(0xC0000027); // mouse events only when focused window and mouse inside
|
||||
|
||||
do /* Start of main activity loop */
|
||||
{
|
||||
// gui_event = wait_for_event(10); // 100 = 1 sec, case you have background work
|
||||
gui_event = get_os_event();
|
||||
switch(gui_event)
|
||||
{
|
||||
case KOLIBRI_EVENT_NONE:
|
||||
// background work
|
||||
break;
|
||||
case KOLIBRI_EVENT_REDRAW:
|
||||
draw_window();
|
||||
break;
|
||||
case KOLIBRI_EVENT_KEY:
|
||||
// scroll
|
||||
break;
|
||||
case KOLIBRI_EVENT_BUTTON:
|
||||
pressed_button = get_os_button();
|
||||
switch (pressed_button)
|
||||
{
|
||||
case BTN_POP:
|
||||
strcpy(statusbar, "POP pressed....");
|
||||
draw_window();
|
||||
break;
|
||||
case BTN_UNLOCK:
|
||||
strcpy(statusbar, "UNLOCK pressed....");
|
||||
draw_window();
|
||||
break;
|
||||
case BTN_QUIT:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case KOLIBRI_EVENT_MOUSE:
|
||||
mouse_pos = get_mouse_pos(POS_WINDOW); // window relative
|
||||
mouse_button = get_mouse_eventstate();
|
||||
debug_board_printf("mouse ev (%d,%d)%x\n", mouse_pos.x, mouse_pos.y, mouse_button);
|
||||
if (mouse_button & (1<<24)) // double click
|
||||
{
|
||||
int n = (mouse_pos.y - 60) / FONT_H;
|
||||
if (n < 0 || n >= LINES) break;
|
||||
debug_board_printf("click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
|
||||
tiny_sprintf(statusbar, "click on str(%d), clip slot(%d)\n", n, LINES - n - 1);
|
||||
draw_window();
|
||||
}
|
||||
// ignore
|
||||
break;
|
||||
}
|
||||
} while(1) ; /* End of main activity loop */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
|
||||
while(*str)
|
||||
debug_board_write_byte(*str++);
|
||||
}
|
||||
|
||||
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
|
||||
{
|
||||
va_list ap;
|
||||
char log_board[300];
|
||||
|
||||
va_start (ap, format);
|
||||
tiny_vsnprintf(log_board, sizeof log_board, format, ap);
|
||||
va_end(ap);
|
||||
debug_board_write_str(log_board);
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
# This configuration file for TCC behaviour
|
||||
# (actually was added for on/off KX extension)
|
||||
|
||||
# Change %ktcc_root%\ to %ktcc_root%\kx
|
||||
# Uncomment this to enable KX extension
|
||||
#tcc_root kx
|
Loading…
Reference in New Issue
Block a user