printf() now handles various formats of strings
git-svn-id: http://picoc.googlecode.com/svn/trunk@328 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
d432ebf74a
commit
390ff153a1
20
clibrary.c
20
clibrary.c
|
@ -195,7 +195,10 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NextArg = (struct Value *)((char *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg));
|
NextArg = (struct Value *)((char *)NextArg + sizeof(struct Value) + TypeStackSizeValue(NextArg));
|
||||||
if (NextArg->Typ != FormatType && !((FormatType == &IntType || *FPos == 'f') && IS_NUMERIC_COERCIBLE(NextArg)))
|
if (NextArg->Typ != FormatType &&
|
||||||
|
!((FormatType == &IntType || *FPos == 'f') && IS_NUMERIC_COERCIBLE(NextArg)) &&
|
||||||
|
!(FormatType == CharPtrType && ( (NextArg->Typ->Base == TypePointer && NextArg->Typ->FromType->Base == TypeArray && NextArg->Typ->FromType->FromType->Base == TypeChar) ||
|
||||||
|
(NextArg->Typ->Base == TypeArray && NextArg->Typ->FromType->Base == TypeChar) ) ) )
|
||||||
PrintStr("XXX", Stream); /* bad type for format */
|
PrintStr("XXX", Stream); /* bad type for format */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -204,13 +207,20 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
#ifndef NATIVE_POINTERS
|
#ifndef NATIVE_POINTERS
|
||||||
struct Value *CharArray = NextArg->Val->Pointer.Segment;
|
struct Value *CharArray;
|
||||||
char *Str;
|
char *Str;
|
||||||
|
|
||||||
if (NextArg->Val->Pointer.Offset < 0 || NextArg->Val->Pointer.Offset >= CharArray->Val->Array.Size)
|
if (NextArg->Typ == CharPtrType || NextArg->Typ->Base == TypePointer && NextArg->Typ->FromType->Base == TypeArray && NextArg->Typ->FromType->FromType->Base == TypeChar)
|
||||||
Str = StrEmpty;
|
{
|
||||||
|
CharArray = NextArg->Val->Pointer.Segment;
|
||||||
|
|
||||||
|
if (NextArg->Val->Pointer.Offset < 0 || NextArg->Val->Pointer.Offset >= CharArray->Val->Array.Size)
|
||||||
|
Str = StrEmpty;
|
||||||
|
else
|
||||||
|
Str = (char *)CharArray->Val->Array.Data + NextArg->Val->Pointer.Offset;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Str = (char *)CharArray->Val->Array.Data + NextArg->Val->Pointer.Offset;
|
Str = NextArg->Val->Array.Data;
|
||||||
#else
|
#else
|
||||||
char *Str = NextArg->Val->NativePointer;
|
char *Str = NextArg->Val->NativePointer;
|
||||||
/* XXX - dereference this properly */
|
/* XXX - dereference this properly */
|
||||||
|
|
Loading…
Reference in a new issue