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:
@@ -169,6 +169,7 @@ int _scanf (struct indesc* D_, const char* format, va_list ap_)
|
||||
unsigned char Result; /* setjmp result */
|
||||
char* S;
|
||||
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
|
||||
* nice, but on a 6502 platform it gives better code, since the values
|
||||
@@ -238,10 +239,12 @@ Again:
|
||||
IsShort = 0;
|
||||
IsLong = 0;
|
||||
Width = UINT_MAX;
|
||||
HaveWidth = 0;
|
||||
|
||||
/* Check for flags. */
|
||||
while (1) {
|
||||
if (isdigit (F)) {
|
||||
HaveWidth = 1;
|
||||
Width = 0;
|
||||
do {
|
||||
/* ### Non portable ### */
|
||||
@@ -330,22 +333,43 @@ FlagsDone:
|
||||
case 'f':
|
||||
case 'g':
|
||||
/* Optionally signed float */
|
||||
longjmp (JumpBuf, RC_NOCONV);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
/* Whitespace terminated string */
|
||||
SkipWhite ();
|
||||
S = NoAssign? 0 : va_arg (ap, char*);
|
||||
while (C && !isspace (C) && Width--) {
|
||||
if (S) {
|
||||
if (!NoAssign) {
|
||||
S = va_arg (ap, char*);
|
||||
}
|
||||
while (!isspace (C) && Width--) {
|
||||
if (!NoAssign) {
|
||||
*S++ = C;
|
||||
}
|
||||
ReadChar ();
|
||||
}
|
||||
/* Terminate the string just read */
|
||||
if (!NoAssign) {
|
||||
*S = '\0';
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case '[':
|
||||
@@ -365,6 +389,7 @@ FlagsDone:
|
||||
|
||||
default:
|
||||
/* Invalid conversion */
|
||||
longjmp (JumpBuf, RC_NOCONV);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user