printuni() fix
This commit is contained in:
parent
0d05ed299e
commit
1f0b633e90
32
base/types.c
32
base/types.c
@ -115,17 +115,22 @@ void Unitype_free(Unitype u){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SPRINT_BUFSIZE 1024
|
#define BUFSIZE 64
|
||||||
void sprintuni(char* buf,Unitype v){
|
char* sprintuni(Unitype v){
|
||||||
|
char* buf=malloc(BUFSIZE);
|
||||||
IFWIN(
|
IFWIN(
|
||||||
switch (v.type) {
|
switch (v.type) {
|
||||||
case Null: sprintf_s(buf, SPRINT_BUFSIZE, "{Null}");break;
|
case Null: sprintf_s(buf, BUFSIZE, "{Null}");break;
|
||||||
case Float64: sprintf_s(buf, SPRINT_BUFSIZE, "{%s : %lf}", my_type_name(v.type),v.Float64);break;
|
case Float64: sprintf_s(buf, BUFSIZE, "{%s : %lf}", my_type_name(v.type),v.Float64);break;
|
||||||
case Bool:
|
case Bool:
|
||||||
case UInt64: sprintf_s(buf, SPRINT_BUFSIZE, "{%s : %lu}", my_type_name(v.type),v.UInt64);break;
|
case UInt64: sprintf_s(buf, BUFSIZE, "{%s : %lu}", my_type_name(v.type),v.UInt64);break;
|
||||||
case Int64: sprintf_s(buf, SPRINT_BUFSIZE, "{%s : %ld}", my_type_name(v.type),v.Int64);break;
|
case Int64: sprintf_s(buf, BUFSIZE, "{%s : %ld}", my_type_name(v.type),v.Int64);break;
|
||||||
case CharPtr: sprintf_s(buf, SPRINT_BUFSIZE, "{%s : \"%s\"}", my_type_name(v.type),(char*)v.VoidPtr);break;
|
case CharPtr: ;
|
||||||
default: sprintf_s(buf, SPRINT_BUFSIZE, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
|
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
||||||
|
buf=realloc(buf, newBUFSIZE);
|
||||||
|
sprintf_s(buf, newBUFSIZE, "{%s : \"%s\"}", my_type_name(v.type),(char*)v.VoidPtr);
|
||||||
|
break;
|
||||||
|
default: sprintf_s(buf, BUFSIZE, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
|
||||||
},
|
},
|
||||||
switch (v.type) {
|
switch (v.type) {
|
||||||
case Null: sprintf(buf, "{Null}");break;
|
case Null: sprintf(buf, "{Null}");break;
|
||||||
@ -133,14 +138,19 @@ void sprintuni(char* buf,Unitype v){
|
|||||||
case Bool:
|
case Bool:
|
||||||
case UInt64: sprintf(buf, "{%s : %lu}", my_type_name(v.type),v.UInt64);break;
|
case UInt64: sprintf(buf, "{%s : %lu}", my_type_name(v.type),v.UInt64);break;
|
||||||
case Int64: sprintf(buf, "{%s : %ld}", my_type_name(v.type),v.Int64);break;
|
case Int64: sprintf(buf, "{%s : %ld}", my_type_name(v.type),v.Int64);break;
|
||||||
case CharPtr: sprintf(buf, "{%s : \"%s\"}", my_type_name(v.type),(char*)v.VoidPtr);break;
|
case CharPtr: ;
|
||||||
|
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
||||||
|
buf=realloc(buf, newBUFSIZE);
|
||||||
|
sprintf(buf, "{%s : \"%s\"}", my_type_name(v.type),(char*)v.VoidPtr);
|
||||||
|
break;
|
||||||
default: sprintf(buf, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
|
default: sprintf(buf, "{%s : %p}", my_type_name(v.type),v.VoidPtr);break;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printuni(Unitype v){
|
void printuni(Unitype v){
|
||||||
char s[SPRINT_BUFSIZE];
|
char* s=sprintuni(v);
|
||||||
sprintuni(s,v);
|
|
||||||
fputs(s, stdout);
|
fputs(s, stdout);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ static const Unitype UniFalse={.Bool=false,.type=Bool};
|
|||||||
// frees VoidPtr value or does nothing if type isn't pointer
|
// frees VoidPtr value or does nothing if type isn't pointer
|
||||||
void Unitype_free(Unitype u);
|
void Unitype_free(Unitype u);
|
||||||
void printuni(Unitype v);
|
void printuni(Unitype v);
|
||||||
void sprintuni(char* s, Unitype v);
|
char* sprintuni(Unitype v);
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user