1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

Initial import into SourceForge CVS

git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14685 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2004-07-26 16:36:55 +00:00
parent a9e8f137ad
commit 91bcdea2a2
669 changed files with 80825 additions and 0 deletions

74
test_programs/clib-bug.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
#include <string.h>
#define LINEBUFLENGTH 180
#define STRIP_LF(str) (str[strlen(str)-1]=0)
void invert_str(char * in)
{
char t;
while(t=*in)
{
*in++=~t;
}
}
int main(int i, char *c[])
{
char dest_fname[80], in_linebuffer[LINEBUFLENGTH];
FILE * fileout, * filein;
if(i>1)
{
sprintf(dest_fname, "%s.c", c[1]);
fileout=fopen(dest_fname, "w");
filein =fopen(c[1], "r");
if(fileout && filein)
{
fgets(in_linebuffer, LINEBUFLENGTH, filein);
STRIP_LF(in_linebuffer);
invert_str(in_linebuffer);
fputs("char *s_leading=\"", fileout);
fputs(in_linebuffer, fileout);
fputs("\";\n", fileout);
fputs("char *s_messages[]={\n", fileout);
while(fgets(in_linebuffer, LINEBUFLENGTH, filein))
{
STRIP_LF(in_linebuffer);
invert_str(in_linebuffer);
fputs("\"", fileout);
fputs(in_linebuffer, fileout);
fputs("\",\n", fileout);
}
fputs("};\n", fileout);
fputs("unsigned s_mess_num = sizeof(s_messages)/sizeof(char *);\n", fileout);
fclose(filein);
fclose(fileout);
}
}
return 0;
}
/*
What's this stuff for ? I use it in SP_Engine to hide the usual bunch of "secret
messages". As you can see, the strings are simply not'ed .
This source shows both flaws: fgets() and the missing buffer flush. You can
change the while() statement with
while(!feof(filein))
{
fgets(in_linebuffer, LINEBUFLENGTH, filein);
....
This way you'll workaround the first problem.
The second issue manifests itself this way: the last two fputs() followed by the
fclose() don't do anything: no "};\n" and no "unsigned....." lines are output to
'fileout'. With SAS, it works perfectly. Converting the source to dos.library
calls also works perfectly. I wonder if there's some kind of strange interaction
with the dos/shell updates.
*/

View File

@ -0,0 +1,41 @@
/*
* $Id: fgets_test.c,v 1.1.1.1 2004-07-26 16:36:07 obarthel Exp $
*
* :ts=4
*/
/****************************************************************************/
#include <string.h>
#include <stdio.h>
/****************************************************************************/
int
main(int argc,char ** argv)
{
char line[256];
size_t len;
FILE * in;
int i;
for(i = 1 ; i < argc ; i++)
{
in = fopen(argv[i],"rb");
if(in != NULL)
{
while(fgets(line,sizeof(line),in) != NULL)
{
len = strlen(line);
while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r'))
line[--len] = '\0';
printf("%s\n",line);
}
fclose(in);
}
}
return(0);
}

44
test_programs/iotest.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define FILE_SIZE 2048
#define WRITE_SIZE 32
char FileData[FILE_SIZE];
void CreateFile(char *filename)
{
FILE *file;
if (file = fopen(filename,"w")) {
memset(FileData,'0',FILE_SIZE);
memset(FileData,'-',WRITE_SIZE);
fwrite(FileData,1,FILE_SIZE,file);
fclose(file);
}
}
void ReadWriteFile(char *filename)
{
FILE *file;
if (file = fopen(filename,"r+")) {
fseek(file,0,SEEK_SET);
fread(FileData,1,FILE_SIZE,file);
fseek(file,0,SEEK_SET);
memset(FileData,'1',WRITE_SIZE);
fwrite(FileData,1,WRITE_SIZE,file);
fclose(file);
}
}
int main(int argc, char **argv)
{
if (argc > 1) {
CreateFile(argv[1]);
ReadWriteFile(argv[1]);
}
return 0;
}

View File

@ -0,0 +1,12 @@
#include <stdio.h>
int __debug_level = 2;
int main(void)
{
double val = 0.0001;
printf("%g\n", val);
return(0);
}

195
test_programs/printf_test.c Normal file
View File

@ -0,0 +1,195 @@
#include <string.h>
#include <stdio.h>
double x;
void
print_format_int(const char * format_string,int parameter1,int parameter2)
{
printf("\"");
printf(format_string,parameter1);
printf("\"\t");
printf("Value = % d, Format = \"%s\"\n",parameter1,format_string);
printf("\"");
printf(format_string,parameter2);
printf("\"\t");
printf("Value = % d, Format = \"%s\"\n",parameter2,format_string);
}
void
print_format_char(const char * format_string,char parameter)
{
printf("\"");
printf(format_string,parameter);
printf("\"\t");
printf("Value = '%c', Format = \"%s\"\n",parameter,format_string);
}
void
print_format_string(const char * format_string,const char *parameter1,const char *parameter2)
{
printf("\"");
printf(format_string,parameter1);
printf("\"\t");
printf("Value = \"%s\", Format = \"%s\"\n",parameter1,format_string);
printf("\"");
printf(format_string,parameter2);
printf("\"\t");
printf("Value = \"%s\", Format = \"%s\"\n",parameter2,format_string);
}
void
print_format_float(const char * format_string,double parameter1,double parameter2)
{
printf("\"");
printf(format_string,parameter1);
printf("\"\t");
printf("Value = % f, Format = \"%s\"\n",parameter1,format_string);
printf("\"");
printf(format_string,parameter2);
printf("\"\t");
printf("Value = % f, Format = \"%s\"\n",parameter2,format_string);
}
int
main(void)
{
/*
unsigned long foo[2] = { 0x41f00000, 0 };
memcpy(&x,foo,sizeof(x));
printf("%.20g\n",x);
*/
print_format_int("%12d",45,-45);
print_format_int("%012d",45,-45);
print_format_int("% 012d",45,-45);
print_format_int("%+12d",45,-45);
print_format_int("%+012d",45,-45);
print_format_int("%-12d",45,-45);
print_format_int("%- 12d",45,-45);
print_format_int("%-+12d",45,-45);
print_format_int("%12.4d",45,-45);
print_format_int("%-12.4d",45,-45);
print_format_int("%12.0d",45,-45);
printf("\n");
print_format_int("%14u",45,-45);
print_format_int("%014u",45,-45);
print_format_int("%#14u",45,-45);
print_format_int("%#014u",45,-45);
print_format_int("%-14u",45,-45);
print_format_int("%-#14u",45,-45);
print_format_int("%14.4u",45,-45);
print_format_int("%-14.4u",45,-45);
print_format_int("%14.0u",45,-45);
printf("\n");
print_format_int("%14o",45,-45);
print_format_int("%014o",45,-45);
print_format_int("%#14o",45,-45);
print_format_int("%#014o",45,-45);
print_format_int("%-14o",45,-45);
print_format_int("%-#14o",45,-45);
print_format_int("%14.4o",45,-45);
print_format_int("%-14.4o",45,-45);
print_format_int("%14.0o",45,-45);
printf("\n");
print_format_int("%12x",45,-45);
print_format_int("%012x",45,-45);
print_format_int("%#12X",45,-45);
print_format_int("%#012X",45,-45);
print_format_int("%-12x",45,-45);
print_format_int("%-#12x",45,-45);
print_format_int("%12.4x",45,-45);
print_format_int("%-12.4x",45,-45);
print_format_int("%12.0x",45,-45);
printf("\n");
print_format_char("%12c",'*');
print_format_char("%012c",'*');
print_format_char("%-12c",'*');
print_format_char("%12.0c",'*');
printf("\n");
print_format_string("%12s","zap","longish");
print_format_string("%12.5s","zap","longish");
print_format_string("%012s","zap","longish");
print_format_string("%-12s","zap","longish");
print_format_string("%12.0s","zap","longish");
printf("\n");
print_format_float("%10.2f",12.678,-12.678);
print_format_float("%010.2f",12.678,-12.678);
print_format_float("% 010.2f",12.678,-12.678);
print_format_float("%+10.2f",12.678,-12.678);
print_format_float("%+010.2f",12.678,-12.678);
print_format_float("%-10.2f",12.678,-12.678);
print_format_float("%- 10.2f",12.678,-12.678);
print_format_float("%-+10.4f",12.678,-12.678);
print_format_float("%f",12.678,-12.678);
print_format_float("%10f",12.678,-12.678);
print_format_float("%10.0f",12.678,-12.678);
printf("\n");
print_format_float("%10.2e",12.678,-12.678);
print_format_float("%010.2e",12.678,-12.678);
print_format_float("% 010.2e",12.678,-12.678);
print_format_float("%+10.2E",12.678,-12.678);
print_format_float("%+010.2E",12.678,-12.678);
print_format_float("%-10.2e",12.678,-12.678);
print_format_float("%- 10.2e",12.678,-12.678);
print_format_float("%-+10.2e",12.678,-12.678);
print_format_float("%e",12.678,-12.678);
print_format_float("%10e",12.678,-12.678);
print_format_float("%10.0e",12.678,-12.678);
printf("\n");
print_format_float("%10.2g",12.678,-12.678);
print_format_float("%010.2g",12.678,-12.678);
print_format_float("% 010.2g",12.678,-12.678);
print_format_float("%+10.2G",12.678,-12.678);
print_format_float("%+010.2G",12.678,-12.678);
print_format_float("%-10.2g",12.678,-12.678);
print_format_float("%- 10.2g",12.678,-12.678);
print_format_float("%-+10.2g",12.678,-12.678);
print_format_float("%g",12.678,-12.678);
print_format_float("%10g",12.678,-12.678);
print_format_float("%10.0g",12.678,-12.678);
printf("\n");
print_format_float("%10.2g",0.678,-0.678);
print_format_float("%010.2g",0.678,-0.678);
print_format_float("% 010.2g",0.678,-0.678);
print_format_float("%+10.2G",0.678,-0.678);
print_format_float("%+010.2G",0.678,-0.678);
print_format_float("%-10.2g",0.678,-0.678);
print_format_float("%- 10.2g",0.678,-0.678);
print_format_float("%-+10.2g",0.678,-0.678);
print_format_float("%g",0.678,-0.678);
print_format_float("%10g",0.678,-0.678);
print_format_float("%10.0g",0.678,-0.678);
return(0);
}

View File

@ -0,0 +1,84 @@
#include <string.h>
#include <stdio.h>
int
main(void)
{
int first, second, num;
int n,a,b,c;
char str[4];
num = sscanf("6", "%d %d", &first, &second);
printf("%d %d\n", num, first);
a = b = c = 0;
n = sscanf("","%*d,%d,%d",&a,&b,&c);
printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c);
a = b = c = 0;
n = sscanf("1,2,3","%*d,%d,%d",&a,&b,&c);
printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c);
a = b = c = 0;
n = sscanf("1,2","%*d,%d,%d",&a,&b,&c);
printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c);
a = b = c = 0;
n = sscanf("asdf","*d,d,d",&a,&b,&c);
printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c);
memset(str,0,sizeof(str));
n = sscanf("asdf","%[abc]",str);
printf("n = %d, str = '%s'\n",n,str);
memset(str,0,sizeof(str));
n = sscanf("asdbbfc","%[abc]",str);
printf("n = %d, str = '%s'\n",n,str);
memset(str,0,sizeof(str));
n = sscanf("","%[abc]",str);
printf("n = %d, str = '%s'\n",n,str);
memset(str,0,sizeof(str));
n = sscanf("abcdef","%[abc]",str);
printf("n = %d, str = '%s'\n",n,str);
a = b = c = 0;
n = sscanf("-","%d",&a);
printf("n = %d, a = %d\n",n,a);
a = b = c = 0;
n = sscanf("-4,-","%d,%d",&a,&b);
printf("n = %d, a = %d, b = %d\n",n,a,b);
memset(str,0,sizeof(str));
n = sscanf("1 abc","%d %4c",&a,str);
printf("n = %d, a = %d, str = '%s'\n",n,a,str);
memset(str,0,sizeof(str));
n = sscanf("abc","%4c",&a,str);
printf("n = %d, str = '%s'\n",n,str);
a = 0;
n = sscanf("17","%i",&a);
printf("n = %d, a = %d\n",n,a);
a = 0;
n = sscanf("017","%i",&a);
printf("n = %d, a = %d\n",n,a);
a = 0;
n = sscanf("0x17","%i",&a);
printf("n = %d, a = %d\n",n,a);
a = 0;
n = sscanf("0x80000000","%i",&a);
printf("n = %d, a = %u\n",n,a);
memset(str,0,sizeof(str));
n = sscanf("1,e","%*d,%[abc]",str);
printf("n = %d, str = '%s'\n",n,str);
return(0);
}

View File

@ -0,0 +1,31 @@
/* gcc -mstackextend -o stack_extension_test stack_extension_test.c */
#include <stdio.h>
#include <ctype.h>
void
recursive_function(char *data,int data_size,int level)
{
char local_data[10000];
char line[10];
int c;
data_size += sizeof(local_data);
level++;
printf("recursion level=%d, size=%d; continue? ",level,data_size);
fgets(line,sizeof(line),stdin);
c = toupper(line[0]);
if(c == 'Y')
recursive_function(local_data,data_size,level);
}
int
main(int argc,char ** argv)
{
recursive_function(NULL,0,0);
return(0);
}

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int __stack_size = 60000;
int
main(void)
{
int first, second, num;
num = sscanf("6", "%d %d", &first, &second);
printf("%d %d\n", num, first);
return(0);
}

241
test_programs/test.c Normal file
View File

@ -0,0 +1,241 @@
/*
* $Id: test.c,v 1.1.1.1 2004-07-26 16:36:08 obarthel Exp $
*
* :ts=4
*/
/****************************************************************************/
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>
#include <math.h>
#include <sys/stat.h>
/****************************************************************************/
/*int __stack_size = 20000;*/
/****************************************************************************/
#if defined(__GNUC__)
void __attribute__ ((constructor))
constructor_test1(void)
{
fprintf(stderr,"constructor #1 called\n");
}
void __attribute__ ((constructor))
constructor_test2(void)
{
fprintf(stderr,"constructor #2 called\n");
}
void __attribute__ ((destructor))
destructor_test1(void)
{
fprintf(stderr,"destructor #1 called\n");
}
void __attribute__ ((destructor))
destructor_test2(void)
{
fprintf(stderr,"destructor #2 called\n");
}
void __attribute__ ((destructor))
destructor_test3(void)
{
fprintf(stderr,"destructor #3 called\n");
}
#endif /* __GNUC__ */
/****************************************************************************/
int foo = 3;
int bar = 9;
/****************************************************************************/
#if 1
int
main(int argc,char ** argv)
{
time_t now;
int i,j,k;
long n,r;
for(i = 0 ; i < argc ; i++)
printf("%2d) \"%s\"\n",i,argv[i]);
printf("div %d mod %d\n",foo / 2,bar % 4);
time(&now);
printf("%s",ctime(&now));
#if defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT)
{
const double pi = 3.14159265358979323846;
const double ten = 10.0;
const double quarter = 0.25;
const double thousand = 1000.0;
const double foo = 4 * atan((double)1);
float f1;
double d1;
printf("pi=%3.1f (float)\n",pi);
printf("pi=%.21e (exponential)\n",pi);
printf("pi=%g (float/exponential)\n",pi);
printf("ten=%f (float)\n",ten);
printf("ten=%.21e (exponential)\n",ten);
printf("ten=%g (float/exponential)\n",ten);
printf("thousand=%f (float)\n",thousand);
printf("thousand=%.21e (exponential)\n",thousand);
printf("thousand=%g (float/exponential)\n",thousand);
printf("quarter=%f (float)\n",quarter);
printf("quarter=%.21e (exponential)\n",quarter);
printf("quarter=%g (float/exponential)\n",quarter);
printf("foo=%f (float)\n",foo);
printf("foo=%.21e (exponential)\n",foo);
printf("foo=%g (float/exponential)\n",foo);
printf("32 bit float = %f\n",4294967295.0);
printf("32+1 bit float = %f\n",-4294967295.0);
printf("big float on the edge = %f\n",4294967296.0);
printf("big float = %f\n",429496729654321.0);
printf("small float = %f\n",-429496729654321.0);
f1 = d1 = 9;
r = sscanf("13.24 1.324","%f %lf",&f1,&d1);
printf("r = %ld, f1 = %f, d1 = %f\n",r,f1,d1);
}
#endif
#ifndef NDEBUG
{
char * allocation;
allocation = malloc(4);
if(allocation != NULL)
{
strcpy(allocation,"....FOO");
strcpy(allocation-3,"bar");
}
}
#endif /* NDEBUG */
printf("hex 0x%08x\n",1);
printf("hex 0x%08x\n",1);
printf("hex 0x%08x\n",2);
printf("big int %d\n",0x80000000L);
printf("converted big int %d\n",atoi("-2147483648"));
r = sscanf("1324","%lx",&n);
printf("r = %ld, n = %ld\n",r,n);
r = sscanf("1234567890","%4d%3d%3d",&i,&j,&k);
printf("r = %ld, i = %d, j = %d, k = %d\n",r,i,j,k);
/*#if defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT)
{
const char *arg = "100x100";
float xres = 0, yres = 0;
printf("%d: ", sscanf(arg, "%fx%f", &xres, &yres));
printf("%.02fx%.02f\n", xres, yres);
}
#endif*/
if(argc > 1)
{
DIR * dir;
dir = opendir(argv[1]);
if(dir != NULL)
{
struct dirent *d;
struct stat st;
chdir(argv[1]);
while((d = readdir(dir)) != NULL)
{
if(stat(d->d_name,&st) == 0)
printf("%s%s\n",d->d_name,S_ISDIR(st.st_mode) ? " (dir)" : "");
}
closedir(dir);
}
}
return(0);
}
#endif
/****************************************************************************/
#if 0
#define LINEBUFLENGTH 180
#define STRIP_LF(str) (str[strlen(str)-1]=0)
void invert_str(char * in)
{
char t;
while(t=*in)
{
*in++=~t;
}
}
int main(int i, char *c[])
{
char dest_fname[80], in_linebuffer[LINEBUFLENGTH];
FILE * fileout, * filein;
if(i>1)
{
sprintf(dest_fname, "%s.c", c[1]);
fileout=fopen(dest_fname, "w");
filein =fopen(c[1], "r");
if(fileout && filein)
{
fgets(in_linebuffer, LINEBUFLENGTH, filein);
STRIP_LF(in_linebuffer);
invert_str(in_linebuffer);
fputs("char *s_leading=\"", fileout);
fputs(in_linebuffer, fileout);
fputs("\";\n", fileout);
fputs("char *s_messages[]={\n", fileout);
while(fgets(in_linebuffer, LINEBUFLENGTH, filein))
{
STRIP_LF(in_linebuffer);
invert_str(in_linebuffer);
fputs("\"", fileout);
fputs(in_linebuffer, fileout);
fputs("\",\n", fileout);
}
fputs("};\n", fileout);
fputs("unsigned s_mess_num = sizeof(s_messages)/sizeof(char *);\n", fileout);
fclose(filein);
fclose(fileout);
}
}
return 0;
}
#endif

View File

@ -0,0 +1,39 @@
/*
* $Id: translate_test.c,v 1.1.1.1 2004-07-26 16:36:08 obarthel Exp $
*
* :ts=4
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
extern char __current_path_name[];
int
main(int argc,char ** argv)
{
struct name_translation_info nti;
char * name;
int error;
int i;
/*strcpy(__current_path_name,"/absolute_path_name/whatever");*/
for(i = 1 ; i < argc ; i++)
{
name = argv[i];
printf("'%s' -> ",name);
error = __translate_unix_to_amiga_path_name(&name,&nti);
/*error = __translate_amiga_to_unix_path_name(&name,&nti);*/
if(error == 0)
printf("'%s'\n",name);
else
printf("%s\n",strerror(error));
}
return(0);
}