Working on the _scanf implementation

git-svn-id: svn://svn.cc65.org/cc65/trunk@1199 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2002-03-17 17:11:54 +00:00
parent f901555264
commit d036b8946f

View File

@@ -169,6 +169,7 @@ int _scanf (struct indesc* D_, const char* format, va_list ap_)
unsigned char Result; /* setjmp result */ unsigned char Result; /* setjmp result */
char* S; char* S;
unsigned char Base; /* Integer base in %i */ unsigned char Base; /* Integer base in %i */
unsigned char HaveWidth; /* True if a width was given */
/* Place copies of the arguments into global variables. This is not very /* Place copies of the arguments into global variables. This is not very
* nice, but on a 6502 platform it gives better code, since the values * nice, but on a 6502 platform it gives better code, since the values
@@ -238,10 +239,12 @@ Again:
IsShort = 0; IsShort = 0;
IsLong = 0; IsLong = 0;
Width = UINT_MAX; Width = UINT_MAX;
HaveWidth = 0;
/* Check for flags. */ /* Check for flags. */
while (1) { while (1) {
if (isdigit (F)) { if (isdigit (F)) {
HaveWidth = 1;
Width = 0; Width = 0;
do { do {
/* ### Non portable ### */ /* ### Non portable ### */
@@ -330,22 +333,43 @@ FlagsDone:
case 'f': case 'f':
case 'g': case 'g':
/* Optionally signed float */ /* Optionally signed float */
longjmp (JumpBuf, RC_NOCONV);
break; break;
case 's': case 's':
/* Whitespace terminated string */ /* Whitespace terminated string */
SkipWhite (); SkipWhite ();
S = NoAssign? 0 : va_arg (ap, char*); if (!NoAssign) {
while (C && !isspace (C) && Width--) { S = va_arg (ap, char*);
if (S) { }
while (!isspace (C) && Width--) {
if (!NoAssign) {
*S++ = C; *S++ = C;
} }
ReadChar (); ReadChar ();
} }
/* Terminate the string just read */
if (!NoAssign) {
*S = '\0';
}
break; break;
case 'c': case 'c':
/* Fixed length string */ /* Fixed length string, NOT zero terminated */
if (!HaveWidth) {
/* No width given, default is 1 */
Width = 1;
}
if (!NoAssign) {
S = va_arg (ap, char*);
}
while (Width--) {
if (!NoAssign) {
*S++ = C;
}
ReadChar ();
}
++Conversions;
break; break;
case '[': case '[':
@@ -365,6 +389,7 @@ FlagsDone:
default: default:
/* Invalid conversion */ /* Invalid conversion */
longjmp (JumpBuf, RC_NOCONV);
break; break;
} }