2001-04-19 06:46:30 +00:00
|
|
|
/*
|
|
|
|
* _scanf.c
|
|
|
|
*
|
2002-03-24 13:26:18 +00:00
|
|
|
* (C) Copyright 2001-2002 Ullrich von Bassewitz (uz@cc65.org)
|
2001-04-19 06:46:30 +00:00
|
|
|
*
|
2002-03-24 13:26:18 +00:00
|
|
|
* This is the basic layer for all scanf type functions. It should get
|
|
|
|
* rewritten in assembler at some time in the future, so most of the code
|
|
|
|
* is not as elegant as it could be.
|
2001-04-19 06:46:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2002-03-24 13:26:18 +00:00
|
|
|
#include <string.h>
|
2001-04-19 06:46:30 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "_scanf.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-07-14 14:41:30 +00:00
|
|
|
/* SetJmp return codes */
|
2001-04-19 06:46:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
#define RC_OK 0 /* Regular call */
|
|
|
|
#define RC_EOF 1 /* EOF reached */
|
|
|
|
#define RC_NOCONV 2 /* No conversion possible */
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-07-14 14:41:30 +00:00
|
|
|
/* Data */
|
2001-04-19 06:46:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static struct indesc* D; /* Copy of function argument */
|
|
|
|
static va_list ap; /* Copy of function argument */
|
|
|
|
static jmp_buf JumpBuf; /* Label that is used in case of EOF */
|
|
|
|
static char C; /* Character from input */
|
|
|
|
static unsigned Width; /* Maximum field width */
|
|
|
|
static long IntVal; /* Converted int value */
|
|
|
|
static unsigned Conversions; /* Number of conversions */
|
|
|
|
|
|
|
|
/* Flags */
|
|
|
|
static unsigned char Positive; /* Flag for positive value */
|
|
|
|
static unsigned char NoAssign; /* Supppress assigment */
|
|
|
|
static unsigned char IsShort; /* Short type */
|
|
|
|
static unsigned char IsLong; /* Long type */
|
2002-03-24 13:26:18 +00:00
|
|
|
static unsigned char Invert; /* Do we need to invert the charset? */
|
|
|
|
static unsigned char CharSet[32]; /* 32 * 8 bits = 256 bits */
|
|
|
|
static const unsigned char Bits[8] = {
|
|
|
|
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
|
|
|
|
};
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2002-03-24 13:26:18 +00:00
|
|
|
/* Character sets */
|
2001-04-19 06:46:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-24 13:26:18 +00:00
|
|
|
static void AddCharToSet (unsigned char C)
|
|
|
|
/* Set the given bit in the character set */
|
|
|
|
{
|
|
|
|
asm ("ldy #%o", C);
|
|
|
|
asm ("lda (sp),y");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("tax");
|
|
|
|
asm ("lda (sp),y");
|
|
|
|
asm ("and #$07");
|
|
|
|
asm ("tay");
|
|
|
|
asm ("lda %v,y", Bits);
|
|
|
|
asm ("ora %v,x", CharSet);
|
|
|
|
asm ("sta %v,x", CharSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char IsCharInSet (unsigned char C)
|
|
|
|
/* Check if the given char is part of the character set */
|
|
|
|
{
|
|
|
|
asm ("ldy #%o", C);
|
|
|
|
asm ("lda (sp),y");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("lsr a");
|
|
|
|
asm ("tax");
|
|
|
|
asm ("lda (sp),y");
|
|
|
|
asm ("and #$07");
|
|
|
|
asm ("tay");
|
|
|
|
asm ("lda %v,y", Bits);
|
|
|
|
asm ("and %v,x", CharSet);
|
|
|
|
asm ("ldx #$00");
|
|
|
|
return __AX__;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-19 06:46:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static void ReadChar (void)
|
2001-04-19 06:46:30 +00:00
|
|
|
/* Get an input character, count characters */
|
|
|
|
{
|
2001-07-14 14:41:30 +00:00
|
|
|
C = D->fin (D);
|
|
|
|
++D->ccount;
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static void SkipWhite (void)
|
2001-04-19 06:46:30 +00:00
|
|
|
/* Skip white space in the input and return the first non white character */
|
|
|
|
{
|
|
|
|
while (isspace (C)) {
|
2001-07-14 14:41:30 +00:00
|
|
|
ReadChar ();
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static void ReadSign (void)
|
|
|
|
/* Read an optional sign and skip it. Store 1 in Positive if the value is
|
|
|
|
* positive, store 0 otherwise.
|
2001-04-19 06:46:30 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
switch (C) {
|
|
|
|
case '-':
|
2001-07-14 14:41:30 +00:00
|
|
|
ReadChar ();
|
|
|
|
Positive = 0;
|
2001-04-19 06:46:30 +00:00
|
|
|
case '+':
|
2001-07-14 14:41:30 +00:00
|
|
|
ReadChar ();
|
2001-04-19 06:46:30 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2001-07-14 14:41:30 +00:00
|
|
|
Positive = 1;
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned char HexVal (char C)
|
|
|
|
/* Convert a digit to a value */
|
|
|
|
{
|
|
|
|
|
|
|
|
if (isdigit (C)) {
|
|
|
|
return C - '0';
|
|
|
|
} else {
|
|
|
|
return C - toupper (C) + ('A' + 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static void ReadInt (unsigned char Base)
|
|
|
|
/* Read an integer and store it into IntVal */
|
2001-04-19 06:46:30 +00:00
|
|
|
{
|
|
|
|
/* Value must start with a digit */
|
|
|
|
if (!isdigit (C)) {
|
|
|
|
longjmp (JumpBuf, RC_NOCONV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the value */
|
2001-07-14 14:41:30 +00:00
|
|
|
IntVal = 0;
|
2001-04-19 06:46:30 +00:00
|
|
|
while (isxdigit (C) && Width-- > 0) {
|
2001-07-14 14:41:30 +00:00
|
|
|
IntVal = IntVal * Base + HexVal (C);
|
|
|
|
ReadChar ();
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
/* One more conversion */
|
|
|
|
++Conversions;
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
static void AssignInt (void)
|
|
|
|
/* Assign the integer value in Val to the next argument. The function makes
|
|
|
|
* several non portable assumptions to reduce code size:
|
|
|
|
* - int and unsigned types have the same representation
|
|
|
|
* - short and int have the same representation.
|
|
|
|
* - all pointer types have the same representation.
|
2001-04-19 06:46:30 +00:00
|
|
|
*/
|
|
|
|
{
|
2001-07-14 14:41:30 +00:00
|
|
|
if (!NoAssign) {
|
|
|
|
/* Get the next argument pointer */
|
|
|
|
void* P = va_arg (ap, void*);
|
|
|
|
|
|
|
|
/* Assign to the converted value */
|
|
|
|
if (IsLong) {
|
|
|
|
*(long*)P = IntVal;
|
|
|
|
} else {
|
|
|
|
*(int*)P = (int) IntVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
int _scanf (struct indesc* D_, const char* format, va_list ap_)
|
|
|
|
/* This is the routine used to do the actual work. It is called from several
|
|
|
|
* types of wrappers to implement the actual ISO xxscanf functions.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
char F; /* Character from format string */
|
|
|
|
unsigned char Result; /* setjmp result */
|
|
|
|
char* S;
|
2002-03-17 17:11:54 +00:00
|
|
|
unsigned char Base; /* Integer base in %i */
|
|
|
|
unsigned char HaveWidth; /* True if a width was given */
|
2002-03-24 13:26:18 +00:00
|
|
|
char Start; /* Start of range */
|
2001-07-14 14:41:30 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
* do not have to be passed as parameters.
|
|
|
|
*/
|
|
|
|
D = D_;
|
|
|
|
ap = ap_;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
/* Initialize variables */
|
|
|
|
Conversions = 0;
|
2001-07-14 14:41:30 +00:00
|
|
|
D->ccount = 0;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
/* Set up the jump label. The get() routine will use this label when EOF
|
|
|
|
* is reached.
|
|
|
|
*/
|
|
|
|
Result = setjmp (JumpBuf);
|
|
|
|
if (Result == RC_OK) {
|
|
|
|
|
|
|
|
Again:
|
|
|
|
/* Get the next input character */
|
2001-07-14 14:41:30 +00:00
|
|
|
ReadChar ();
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
/* Walk over the format string */
|
|
|
|
while (F = *format++) {
|
|
|
|
|
|
|
|
/* Check for a conversion */
|
|
|
|
if (F != '%' || *format == '%') {
|
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* %% or any char other than % */
|
|
|
|
if (F == '%') {
|
|
|
|
++format;
|
|
|
|
}
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* Check for a match */
|
|
|
|
if (isspace (F)) {
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* Special white space handling: Any whitespace matches
|
|
|
|
* any amount of whitespace including none(!). So this
|
|
|
|
* match will never fail.
|
|
|
|
*/
|
|
|
|
SkipWhite ();
|
|
|
|
continue;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
} else if (F != C) {
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* A mismatch. We will stop scanning the input and return
|
|
|
|
* the number of conversions.
|
|
|
|
*/
|
|
|
|
return Conversions;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-24 13:26:18 +00:00
|
|
|
} else {
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* A match. Read the next input character and start over */
|
|
|
|
goto Again;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
}
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2002-03-17 17:11:54 +00:00
|
|
|
/* A conversion. Skip the percent sign. */
|
|
|
|
F = *format++;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
/* Initialize variables */
|
2002-03-17 17:11:54 +00:00
|
|
|
NoAssign = 0;
|
|
|
|
IsShort = 0;
|
|
|
|
IsLong = 0;
|
|
|
|
Width = UINT_MAX;
|
|
|
|
HaveWidth = 0;
|
|
|
|
|
|
|
|
/* Check for flags. */
|
|
|
|
while (1) {
|
|
|
|
if (isdigit (F)) {
|
|
|
|
HaveWidth = 1;
|
|
|
|
Width = 0;
|
|
|
|
do {
|
|
|
|
/* ### Non portable ### */
|
|
|
|
Width = Width * 10 + (F & 0x0F);
|
|
|
|
F = *format++;
|
|
|
|
} while (isdigit (F));
|
|
|
|
} else {
|
|
|
|
switch (F) {
|
2002-03-24 13:26:18 +00:00
|
|
|
case '*': NoAssign = 1; break;
|
2002-03-17 17:11:54 +00:00
|
|
|
case 'h': IsShort = 1; break;
|
|
|
|
case 'l':
|
|
|
|
case 'L': IsLong = 1; break;
|
2002-03-24 13:26:18 +00:00
|
|
|
default: goto FlagsDone;
|
2002-03-17 17:11:54 +00:00
|
|
|
}
|
|
|
|
F = *format++;
|
|
|
|
}
|
|
|
|
}
|
2001-04-19 06:46:30 +00:00
|
|
|
FlagsDone:
|
|
|
|
|
|
|
|
/* Check for the actual conversion character */
|
|
|
|
switch (F) {
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
case 'D':
|
2001-04-19 06:46:30 +00:00
|
|
|
IsLong = 1;
|
|
|
|
case 'd':
|
|
|
|
/* Optionally signed decimal integer */
|
2001-07-14 14:41:30 +00:00
|
|
|
SkipWhite ();
|
|
|
|
ReadSign ();
|
|
|
|
ReadInt (10);
|
2001-04-19 06:46:30 +00:00
|
|
|
if (!Positive) {
|
2001-07-14 14:41:30 +00:00
|
|
|
IntVal = -IntVal;
|
2001-04-19 06:46:30 +00:00
|
|
|
}
|
2001-07-14 14:41:30 +00:00
|
|
|
AssignInt ();
|
|
|
|
break;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
case 'i':
|
|
|
|
/* Optionally signed integer with a base */
|
2001-07-14 14:41:30 +00:00
|
|
|
SkipWhite ();
|
|
|
|
ReadSign ();
|
|
|
|
if (C == '0') {
|
|
|
|
ReadChar ();
|
|
|
|
switch (C) {
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
Base = 16;
|
2002-03-24 13:26:18 +00:00
|
|
|
ReadChar();
|
|
|
|
break;
|
2001-07-14 14:41:30 +00:00
|
|
|
default:
|
|
|
|
Base = 8;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Base = 10;
|
|
|
|
}
|
|
|
|
ReadInt (Base);
|
|
|
|
if (!Positive) {
|
|
|
|
IntVal = -IntVal;
|
|
|
|
}
|
|
|
|
AssignInt ();
|
|
|
|
break;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
case 'o':
|
2001-07-14 14:41:30 +00:00
|
|
|
/* Unsigned octal integer */
|
2002-03-24 13:26:18 +00:00
|
|
|
SkipWhite ();
|
2001-07-14 14:41:30 +00:00
|
|
|
ReadInt (8);
|
|
|
|
AssignInt ();
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
/* Unsigned decimal integer */
|
2001-07-14 14:41:30 +00:00
|
|
|
SkipWhite ();
|
|
|
|
ReadInt (10);
|
|
|
|
AssignInt ();
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
/* Unsigned hexadecimal integer */
|
2001-07-14 14:41:30 +00:00
|
|
|
SkipWhite ();
|
|
|
|
ReadInt (16);
|
|
|
|
AssignInt ();
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
case 'e':
|
|
|
|
case 'f':
|
|
|
|
case 'g':
|
|
|
|
/* Optionally signed float */
|
2002-03-17 17:11:54 +00:00
|
|
|
longjmp (JumpBuf, RC_NOCONV);
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
/* Whitespace terminated string */
|
2001-07-14 14:41:30 +00:00
|
|
|
SkipWhite ();
|
2002-03-17 17:11:54 +00:00
|
|
|
if (!NoAssign) {
|
|
|
|
S = va_arg (ap, char*);
|
|
|
|
}
|
|
|
|
while (!isspace (C) && Width--) {
|
|
|
|
if (!NoAssign) {
|
|
|
|
*S++ = C;
|
2001-07-14 14:41:30 +00:00
|
|
|
}
|
|
|
|
ReadChar ();
|
|
|
|
}
|
2002-03-17 17:11:54 +00:00
|
|
|
/* Terminate the string just read */
|
|
|
|
if (!NoAssign) {
|
|
|
|
*S = '\0';
|
2002-03-24 13:26:18 +00:00
|
|
|
}
|
|
|
|
++Conversions;
|
|
|
|
break;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
|
|
|
case 'c':
|
2002-03-17 17:11:54 +00:00
|
|
|
/* Fixed length string, NOT zero terminated */
|
|
|
|
if (!HaveWidth) {
|
|
|
|
/* No width given, default is 1 */
|
|
|
|
Width = 1;
|
|
|
|
}
|
|
|
|
if (!NoAssign) {
|
|
|
|
S = va_arg (ap, char*);
|
2002-03-24 13:26:18 +00:00
|
|
|
while (Width--) {
|
|
|
|
*S++ = C;
|
|
|
|
ReadChar ();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Just skip as many chars as given */
|
|
|
|
while (Width--) {
|
|
|
|
ReadChar ();
|
|
|
|
}
|
|
|
|
}
|
2002-03-17 17:11:54 +00:00
|
|
|
++Conversions;
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
/* String using characters from a set */
|
2002-03-24 13:26:18 +00:00
|
|
|
Invert = 0;
|
|
|
|
/* Clear the set */
|
|
|
|
memset (CharSet, 0, sizeof (CharSet));
|
|
|
|
F = *format++;
|
|
|
|
if (F == '^') {
|
|
|
|
Invert = 1;
|
|
|
|
F = *format++;
|
|
|
|
}
|
|
|
|
if (F == ']') {
|
|
|
|
AddCharToSet (']');
|
|
|
|
F = *format++;
|
|
|
|
}
|
|
|
|
/* Read the characters that are part of the set */
|
|
|
|
while (F != ']' && F != '\0') {
|
|
|
|
if (*format == '-') {
|
|
|
|
/* A range. Get start and end, skip the '-' */
|
|
|
|
Start = F;
|
|
|
|
F = *++format;
|
|
|
|
++format;
|
|
|
|
if (F == ']') {
|
|
|
|
/* '-' as last char means: include '-' */
|
|
|
|
AddCharToSet (Start);
|
|
|
|
AddCharToSet ('-');
|
|
|
|
} else if (F != '\0') {
|
|
|
|
/* Include all chars in the range */
|
|
|
|
while (1) {
|
|
|
|
AddCharToSet (Start);
|
|
|
|
if (Start == F) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Start;
|
|
|
|
}
|
|
|
|
/* Get next char after range */
|
|
|
|
F = *format++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Just a character */
|
|
|
|
AddCharToSet (F);
|
|
|
|
/* Get next char */
|
|
|
|
F = *format++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invert the set if requested */
|
|
|
|
if (Invert) {
|
|
|
|
for (Start = 0; Start < sizeof (CharSet); ++Start) {
|
|
|
|
CharSet[Start] ^= 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have the set in CharSet. Read characters and
|
|
|
|
* store them into a string while they are part of
|
|
|
|
* the set.
|
|
|
|
*/
|
|
|
|
if (!NoAssign) {
|
|
|
|
S = va_arg (ap, char*);
|
|
|
|
while (IsCharInSet (C) && Width--) {
|
|
|
|
*S++ = C;
|
|
|
|
ReadChar ();
|
|
|
|
}
|
|
|
|
*S = '\0';
|
|
|
|
} else {
|
|
|
|
while (IsCharInSet (C) && Width--) {
|
|
|
|
ReadChar ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++Conversions;
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
case 'p':
|
2002-03-24 13:26:18 +00:00
|
|
|
/* Pointer, format is 0xABCD */
|
|
|
|
SkipWhite ();
|
|
|
|
if (C != '0') {
|
|
|
|
longjmp (JumpBuf, RC_NOCONV);
|
|
|
|
}
|
|
|
|
ReadChar ();
|
|
|
|
if (C != 'x' && C != 'X') {
|
|
|
|
longjmp (JumpBuf, RC_NOCONV);
|
|
|
|
}
|
|
|
|
ReadChar ();
|
|
|
|
ReadInt (16);
|
|
|
|
AssignInt ();
|
2001-07-14 14:41:30 +00:00
|
|
|
break;
|
2001-04-19 06:46:30 +00:00
|
|
|
|
2001-07-14 14:41:30 +00:00
|
|
|
case 'n':
|
|
|
|
/* Store characters consumed so far */
|
|
|
|
IntVal = D->ccount;
|
|
|
|
AssignInt ();
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Invalid conversion */
|
2002-03-17 17:11:54 +00:00
|
|
|
longjmp (JumpBuf, RC_NOCONV);
|
2001-04-19 06:46:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip the format char */
|
|
|
|
goto Again;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (Result == RC_EOF) {
|
|
|
|
|
|
|
|
/* Jump via JumpBuf means EOF on input */
|
2001-07-14 14:41:30 +00:00
|
|
|
if (D->ccount == 0) {
|
2001-04-19 06:46:30 +00:00
|
|
|
/* Special case: error */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of conversions */
|
|
|
|
return Conversions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|