From a45133730435df3fa695c1e167a04e5a00e932d0 Mon Sep 17 00:00:00 2001 From: BlastBrothers <83738994+BlastBrothers@users.noreply.github.com> Date: Mon, 8 Jul 2024 06:26:49 -0400 Subject: [PATCH] Readd accidentally deleted files. --- src/libc/arg_processing.c | 200 ++++ src/libc/time.c | 42 + src/libc/time.c.src | 65 -- src/libc/ungetc.c | 29 + src/libc/uscan.c | 530 ++++++++++ src/libc/uscan.c.src | 2037 ------------------------------------- src/libc/usscan.c | 174 ++++ 7 files changed, 975 insertions(+), 2102 deletions(-) create mode 100644 src/libc/arg_processing.c create mode 100644 src/libc/time.c delete mode 100644 src/libc/time.c.src create mode 100644 src/libc/ungetc.c create mode 100644 src/libc/uscan.c delete mode 100644 src/libc/uscan.c.src create mode 100644 src/libc/usscan.c diff --git a/src/libc/arg_processing.c b/src/libc/arg_processing.c new file mode 100644 index 0000000..ccce46f --- /dev/null +++ b/src/libc/arg_processing.c @@ -0,0 +1,200 @@ +/* Complex argument processing for program invocation + +Called from within crt0.src - see extract below + +; Process the command line into argc & argv[] +; ------------------------------------------- +; +; Parse the parameter string into a C array +; Parameters +; - HL: Address of parameter string (seems to be set by MOS at start of programme) +; - IX: Address for array pointer storage +; Returns: +; - C: Number of parameters parsed +; +; Only include conditionally if ___main_argc_argv is present + + section .init.args +ifextern ___main_argc_argv + + private _parse_params +_parse_params: + + if HAS_ARG_PROCESSING ; if want to do complex arg processing + + extern ___arg_processing + + ld bc, _exec_name ; first value in argv is program name + ld (ix+0), bc + push ix + push hl + call ___arg_processing ; call a C function to do this + pop hl + pop hl + lb bc, 0 ; clear out top part of UBC + ld c, a + ret +*/ + +/* + Processes up to argv_ptrs_max values from zero terminated param_str + and stores the results in argv[] + + Will need to allocated its own storage, at least in some instances, as can do wild card + expansion (TBD) +*/ + +#include +#include +#include +#include +#include + +#define ARGV_PTRS_MAX 16 // this should align with the value defined in crt0.src + +int __parse_args( char *param_str, char *argv[] ); +int __check_redirect( int in_cnt, char *argv[] ); +char *__get_redir_fname( char *s, char *t ); +void __close_redir_files( void ); + +uint8_t __arg_processing( char *param_str, char *argv[] ) +{ + int cnt; + +// puts( "Parameter processing including redirection." ); +// puts( param_str ); + cnt = __parse_args( param_str, argv ); + cnt = __check_redirect( cnt, argv ); + return (uint8_t)cnt; +} + +// Parse the arguments from the command string, separating out +// - space separated and +// - quoted strings +// the strings are left in place with their locations in argv +// and zero terminated over the delimiter + +int __parse_args( char *param_str, char *argv[] ) +{ + int cnt = 1; + char *s = param_str; + char delim = ' '; + + // skip the leading spaces + + while ( cnt < ARGV_PTRS_MAX ) { + while ( *s != '\0' && *s == delim ) s++; + if ( *s == '\0' ) return cnt; + if ( *s == '"' ) { + delim = '"'; + s++; + } + argv[cnt++] = s; + + // skip over the letters + + while ( *s != '\0' && *s != delim ) s++; + if ( *s == '\0' ) return cnt; + if ( *s == '"' ) delim = ' '; + *s++ = '\0'; // terminate the string in place + } + return cnt; +} + +// Check for input / ouput redirection +// > redirect stdout (creates new file) +// >> redirects stdout (appends) +// Not implemented yet +// 2> and 2>> as above for stderr +// p>&q merges output from stream p with stream q (stdin=0, stdout=1, stderr=2) +// < redirect stdin +// +// file follows the redirection operator, with or without spaces +// removes redirection operators and associated file names from argv +// by changing the pointer to NULL +// uses freopen to redirect + +int __check_redirect( int in_cnt, char *argv[] ) +{ + char *s, *t; + char *fname; + char *mode; + FILE *fp; + bool redirect = false; + + for ( int i = 1; i < in_cnt; i++ ) { + s = argv[i]; + fname = NULL; + + if ( i+1 < in_cnt) t = argv[i+1]; + else t = NULL; + + if ( *s == '<' ) { + fname = __get_redir_fname( s+1, t ); + fp = stdin; + mode = "r"; + } else if ( *s == '>' ) { + if ( *(++s) == '>' ) { + fname = __get_redir_fname( s+1, t ); + fp = stdout; + mode = "a"; + } else { + fname = __get_redir_fname( s, t ); + fp = stdout; + mode = "w"; + } +/* + } else if ( *s == '&' ) { + + } else if ( *s == '2' ) { +*/ + } + if ( fname ) { + argv[i] = NULL; + if ( fname == t ) argv[++i] = NULL; +// puts( fname ); +// puts( mode ); +// getchar(); + if ( !freopen( fname, mode, fp ) ) exit( EXIT_FAILURE ); + redirect = true; + } + } + + // Register atexit() function to close the filehandles + + if ( redirect ) atexit( __close_redir_files ); + + // Re-pack argv to remove any redirection operators and file names + + int cnt = 1; + + for ( int i = 1; i < in_cnt; i++ ) + if ( argv[i] ) argv[cnt++] = argv[i]; + + return cnt; +} + +// Get redirection filename from argv list +// - can either be in the in current parameter (s) or next parameter (t) +// - the current parameter is passed with the redirection operators skipped over +// - if t is NULL will always return s even if there is no file name + +char *__get_redir_fname( char *s, char *t ) +{ + if ( !t ) return s; // if t is NULL then s + if ( *s != '\0' ) return s; // not at the end of the string then s + return t; // otherwise t +} + +// Called at exit to close any files that are targets of redirection +// - registered via atexit() +// - the check is deliberately fhandle < FH_STDIN ) fclose( stdin ); + if ( stdout->fhandle < FH_STDIN ) fclose( stdout ); + if ( stderr->fhandle < FH_STDIN ) fclose( stderr ); +} diff --git a/src/libc/time.c b/src/libc/time.c new file mode 100644 index 0000000..ca6a0d5 --- /dev/null +++ b/src/libc/time.c @@ -0,0 +1,42 @@ +/* time_t time(time_t *t) + ---------------------- + +Description +time() returns the current time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). +If t is non-NULL, the return value is also stored in the memory pointed to by t. + +Return Value +On success, the value of time in seconds since the Epoch is returned. On error, ((time_t) -1) is +returned, and errno is set appropriately. +*/ + +#include +#include +#include + +time_t time(time_t *timer) +{ + volatile RTC_DATA *rtc = getsysvar_rtc(); + + static char rtc_buffer[33]; + mos_getrtc( rtc_buffer ); // Seems that need to call mos_getrtc() to update sysvar_rtc + + struct tm tm2; + time_t res; + + tm2.tm_sec = rtc->second; + tm2.tm_min = rtc->minute; + tm2.tm_hour = rtc->hour; + tm2.tm_mday = rtc->day; + tm2.tm_mon = rtc->month; + tm2.tm_year = (unsigned int)rtc->year + 1980 - 1900; + + res = mktime(&tm2); + + if (timer != NULL) + { + *timer = res; + } + + return res; +} diff --git a/src/libc/time.c.src b/src/libc/time.c.src deleted file mode 100644 index b226975..0000000 --- a/src/libc/time.c.src +++ /dev/null @@ -1,65 +0,0 @@ - section .text,"ax",@progbits - assume adl = 1 - section .text,"ax",@progbits - public _time -_time: - ld hl, -30 - call __frameset - call _getsysvar_rtc - ld (ix - 30), hl - ld hl, _time.rtc_buffer - push hl - call _mos_getrtc - pop hl - ld iy, (ix - 30) - ld a, (iy + 7) - or a, a - sbc hl, hl - ld l, a - ld (ix - 27), hl - ld l, (iy + 6) - ld (ix - 24), hl - ld l, (iy + 5) - ld (ix - 21), hl - ld l, (iy + 2) - ld (ix - 18), hl - ld l, (iy + 1) - ld (ix - 15), hl - ld a, (iy) - ld l, a - ld de, 80 - add hl, de - ld (ix - 12), hl - pea ix - 27 - call _mktime - ld iy, (ix + 6) - push hl - pop bc - pop hl - lea hl, iy - add hl, bc - or a, a - sbc hl, bc - jr z, BB0_2 - ld (iy), bc - ld (iy + 3), e -BB0_2: - push bc - pop hl - ld sp, ix - pop ix - ret - section .text,"ax",@progbits - - section .bss,"aw",@nobits - private _time.rtc_buffer -_time.rtc_buffer: - rb 33 - - ident "clang version 15.0.0 (https://github.com/jacobly0/llvm-project 6c61664110f888c0285ae4c48b150c9a7a4361bb)" - extern __Unwind_SjLj_Register - extern __Unwind_SjLj_Unregister - extern __frameset - extern _mktime - extern _mos_getrtc - extern _getsysvar_rtc diff --git a/src/libc/ungetc.c b/src/libc/ungetc.c new file mode 100644 index 0000000..0649aed --- /dev/null +++ b/src/libc/ungetc.c @@ -0,0 +1,29 @@ +/* ungetc + ------ + +The C library function int ungetc(int char, FILE *stream) pushes the character char (an unsigned +char) onto the specified stream so that the this is available for the next read operation. + +Declaration: Following is the declaration for ungetc() function. + int ungetc(int char, FILE *stream) + +Parameters + char − This is the character to be put back. This is passed as its int promotion. + stream − This is the pointer to a FILE object that identifies the stream where the character + is to be written. + +Return Value + If successful, it returns the character that was pushed back + otherwise, EOF is returned and the stream remains unchanged. +*/ + +#include + +int ungetc(int c, FILE *stream) +{ + if (stream == NULL || stream == stdout || stream == stderr) return EOF; + if (stream->unget_char) return EOF; + + stream->unget_char = c; + return c; +} diff --git a/src/libc/uscan.c b/src/libc/uscan.c new file mode 100644 index 0000000..1dbbafe --- /dev/null +++ b/src/libc/uscan.c @@ -0,0 +1,530 @@ +/************************************************* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + *************************************************/ + +/************************************************************************* + * We now assume that the maximum number of fields processed in a format + * string is 255. Then, we can fit the field count into a char, for a + * slight saving in space and time. + *************************************************************************/ + +// This version is a simplified version with the multi-threading stripped out + +// Updates by Paul Cawte +// 25/06/2023 - minor changes to port to LLVM toolchain +// 24/07/2023 - updated to handle backspace key during input and Ctrl-C + +#include +#include +#include +#include +#include +#include "format.h" +#include +#include +#include + +/* Sizes allowed for various data */ +/* For small model, we must restrict the allowed input */ +#if (defined(__MODEL__) && (__MODEL__ == 0)) && !defined(__ACCLAIM__) +#define FLT_CHARS (2*FLT_DIG+7) // Only need FLT_DIG+7, but allow for extra data +#define PTR_CHARS 11 +#define INT_CHARS 9 +#else +#define FLT_CHARS 127 +#define PTR_CHARS 127 +#define INT_CHARS 127 +#endif + +#define BS_KEY '\x7f' + +static const char _PTR_ bptr; // LLVM port - added const +FILE _PTR_ fp_fscanf; +static va_list argp; +static int len; +static unsigned char fields; +static struct fmt_type fmt_str; +static int prev_ch; +static char isunget; + +/****************************************/ +/* */ +/* get a character */ +/* */ +/****************************************/ + +static int get(void) +{ + ++len; + if (bptr) // If reading from a string (i.e. sscanf) + return(*(bptr++)); + else if (isunget==1) { + isunget = 0; + return prev_ch; + } + if ( fp_fscanf ) + return ( prev_ch = fgetc( fp_fscanf ) ); + prev_ch = getchar(); + if ( prev_ch == '\x03' ) exit( EXIT_FAILURE ); // Exit if control C is pressed + else if ( prev_ch == '\b') { // Change cursor left to BS + prev_ch = BS_KEY; + putchar( ' ' ); // Erase the character printed on the screen + putchar( BS_KEY ); + } + return prev_ch; +} + +/****************************************/ +/* */ +/* unget a character */ +/* */ +/****************************************/ + +static void unget(void) +{ + --len; + isunget = 1; + if (bptr) + --bptr; +} + +/****************************************/ +/* */ +/* Handle pointer conversions */ +/* */ +/****************************************/ + +static unsigned char pointer(void) +{ + unsigned char i; + char ch; + char buffer[PTR_CHARS]; + char _PTR_ bp = buffer; + unsigned int addr; + + if (fmt_str.field_width == 0 || fmt_str.field_width > sizeof(buffer)-1) + fmt_str.field_width = sizeof(buffer)-1; + if ((ch = get()) == EOF) + return false; + for (i=0;isxdigit(ch);) { + *(bp++) = ch; + i++; + if (i >= fmt_str.field_width) + break; + if ((ch = get()) == EOF) + return false; + } + if (bp == buffer) + return false; + if (i < fmt_str.field_width) + unget(); + *bp = '\0'; + addr = strtoul(buffer,(void *)NULL,16); + + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) + { + *(va_arg(argp,int _PTR_ _PTR_)) = (int _PTR_)addr; + ++fields; + } + + return true; +} + +/****************************************/ +/* */ +/* Handle string conversions */ +/* */ +/****************************************/ + +static unsigned char string(void) +{ + unsigned char i; + char ch; + char _PTR_ p = NULL; + + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) + p = va_arg(argp,char _PTR_); + if (fmt_str.field_width == 0) + fmt_str.field_width = 127; + do { // Skip over any leading white space + if ((ch = get()) == EOF) + return false; + } while (isspace(ch)); + unget(); // Put the character back & check for EOF + if ((ch = get()) == EOF) + return false; + for (i=0; !isspace(ch) && ch;) { // Consumer characters until white space + if ( ch == BS_KEY ) { // Deal with backspace + if ( i>0 ) { + i--; + if (p) p--; + } + } else { + if (p) // Store characters if not NULL pointer + *(p++) = ch; + i++; + if (i >= fmt_str.field_width) + break; + } + if ((ch = get()) == EOF) + return false; + } + if (i < fmt_str.field_width) + unget(); + if (p) + { + *p = '\0'; + ++fields; + } + return true; +} + +/****************************************/ +/* */ +/* Handle character conversions */ +/* */ +/****************************************/ + +static unsigned char character(void) +{ + unsigned char i; + char ch; + char _PTR_ p=NULL; + + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) + p = va_arg(argp,char _PTR_); + if (fmt_str.field_width == 0) + fmt_str.field_width = 1; + for (i=0;i0 ) { + i--; + fields--; + if (p) p--; + } + } else { + if (p) + *(p++) = ch; + ++fields; + ++i; + } + } + return true; +} + +/****************************************/ +/* */ +/* Floating point conversions */ +/* */ +/****************************************/ + +static unsigned char fpoint(void) +{ + unsigned char i; + char ch; + char buffer[FLT_CHARS]; + char _PTR_ bp = buffer; + double dval; + unsigned char takeEe = true; + unsigned char takeDot = true; + unsigned char takeSign = true; + + if (fmt_str.field_width == 0 || fmt_str.field_width > sizeof(buffer)-1) + fmt_str.field_width = sizeof(buffer)-1; + do { + if ((ch = get()) == EOF) + return false; + } while (isspace(ch)); + + for (i=0; i < fmt_str.field_width; ) + { + if ( ch == BS_KEY ) { // Deal with backspace + if ( i > 0 ) { + ch = *(--bp); + if ( ch == '-' || ch == '+' ) takeSign = true; + else if ( ch == '.' ) takeDot = true; + else if ( ch == 'e' || ch == 'E' ) takeEe = true; + } + } else { + if (takeEe && (ch == 'e' || ch == 'E')) { + takeEe = false; + takeSign = true; + takeDot = false; + } else if (takeDot && ch=='.') { + takeDot = false; + } else if ( (takeSign && (ch == '-' || ch == '+')) || isdigit(ch) ) { + takeSign = false; + } else { + break; + } + *(bp++) = ch; + i++; + } + if ((ch = get()) == EOF) + return false; + } + if (bp == buffer) + return(fields); + if (i < fmt_str.field_width) + unget(); + *bp = '\0'; + dval = strtod(buffer,(void _PTR_)NULL); + + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) { +#if 0 + /* EZ8 Specific */ + /* float, double and long double are indistinguishable 4-byte + floating-point representations. */ + if (fmt_str.size == 'l') + *(va_arg(argp,double _PTR_)) = dval; + else if (fmt_str.size == 'L') + *(va_arg(argp,long double _PTR_)) = dval; + else + *(va_arg(argp,float _PTR_)) = dval; +#else + *(va_arg(argp, float _PTR_)) = dval; +#endif + ++fields; + } + + return true; +} + +/****************************************/ +/* */ +/* Handle scalar conversions */ +/* */ +/****************************************/ + +static unsigned char scalar(int radix) +{ + unsigned char i; + char ch; + char buffer[INT_CHARS]; + char _PTR_ bp = buffer; + long val; + + if (fmt_str.field_width == 0 || fmt_str.field_width > sizeof(buffer)-1) + fmt_str.field_width = sizeof(buffer)-1; + do { + if ((ch = get()) == EOF) + return false; + } while (isspace(ch)); + unget(); + + for ( i = 0; (ch = get()) != EOF; ) { + if ( ch == BS_KEY ) { // Deal with backspace or cursor left + if ( i>0 ) { i--; bp--; } + } + else if ( (radix == 10 && isdigit(ch)) || (radix == 16 && isxdigit(ch)) || + (radix == 8 && ch >= '0' && ch <= '7') || ch == '-' || ch == '+' ) { + *(bp++) = ch; + i++; + if ( i >= fmt_str.field_width ) break; + } + else break; + } + if ( ch == EOF ) return false; + + if (bp == buffer) + return(fields); + if (i < fmt_str.field_width) + unget(); + *bp = '\0'; + if ((fmt_str.type == 'u') || (radix == 8) || (radix == 16)) + val = strtoul(buffer,(void _PTR_)NULL,radix); + else + val = strtol(buffer,(void _PTR_)NULL,radix); + + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) { + if (fmt_str.size == 'h') + *(va_arg(argp,short _PTR_)) = val; + else if (fmt_str.size == 'l' || fmt_str.size == 'L') + *(va_arg(argp,long _PTR_)) = val; + else + *(va_arg(argp,int _PTR_)) = val; + ++fields; + } + + return true; +} + +/****************************************/ +/* */ +/* Handle set conversions */ +/* */ +/****************************************/ + + +static unsigned char set(void) +{ + const char _PTR_ p2; // LLVM port - const + char neg,ch; + char _PTR_ p = 0; + char width; + + /* Use (p == 0) to signal the case that we are skipping this input + string. */ + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) + p = va_arg(argp,char _PTR_); + + if ( (neg = (*fmt_str.set_begin == '^')) ) + fmt_str.set_begin++; + + width = fmt_str.field_width; + if (width == 0) + width = 127; + + while (width--) + { + if ((ch = get()) == EOF) + return false; + + /* Look for a match in the set. */ + for(p2 = fmt_str.set_begin; p2 < fmt_str.set_end; ++p2) + if (*p2 == ch) + break; /* Matched one in the set. */ + + if (p2 < fmt_str.set_end && *p2 == ch) + { + /* We stop scanning if we match a character in the negative set. */ + if (neg) + break; + } + else + { + /* Likewise, we stop scanning if we fail to match a character in + the positive set. */ + if (!neg) + break; + } + + /* Store the valid character. */ + if (p) + *(p++) = ch; + } + + if (width > 0) + unget(); + + if (p) + *p = '\0'; + + return true; +} + +/************************************************* +* +* _u_scan - scan formated string from a file or string +* +* Inputs: +* fp - NULL = from stdin or string, else from file +* src - NULL = input from keyboard, else input from string (this takes precedence) +* fmt - format string +* argp - argument list pointer +* +* Returns: +* Number of characters transmitted, or +* -1 if an error occured. +* +*************************************************/ + +int _u_scan(FILE _PTR_ fp, const char _PTR_ src, const char _PTR_ fmt,va_list ap) +{ +// int i; + int ch; + unsigned char ok=true; + + argp = ap; + fields = 0; + len = 0; + prev_ch = 0; + isunget = 0; + + fp_fscanf = fp; + bptr = src; +/* + bptr = (void _PTR_)NULL; + + if (src) + bptr = src; +*/ + while ( ok && prev_ch!=EOF && *fmt) { + fmt = _u_sscan(fmt,&fmt_str); + if (fmt_str.status == FMT_ERR) + return(fields); + else if (fmt_str.status == FMT_PASS_THRU) { + if (isspace(fmt_str.chr)) + { + do ch=get(); + while(isspace(ch)); + unget(); + } else + { + ch = get(); + if (ch && ch != fmt_str.chr) + break; + } + } + else if (fmt_str.flags & FMT_FLAG_SET) { + ok = set(); + } + else { + switch (fmt_str.type) { + register int radix; + case 'd': + case 'i': + case 'u': + radix=10; + goto _sclr; + case 'x': + case 'X': + radix=16; + goto _sclr; + case 'o': + radix=8; + _sclr: + ok = scalar(radix); + break; +#if __FPLIB__ || 1 + case 'A': + case 'E': + case 'F': + case 'G': + case 'a': + case 'e': + case 'f': + case 'g': + ok = fpoint(); + break; +#endif + case 'c': + ok = character(); + break; + case 's': + ok = string(); + break; + case 'p': + ok = pointer(); + break; + case 'n': + if (!(fmt_str.flags & FMT_FLAG_IGNORE)) { + *(va_arg(argp,int _PTR_)) = len; + ++fields; + } + break; + } + } + } + // ISO Spec: Return EOF if an input error occurs before any conversion. + // Otherwise return the number of input items assigned. + // A sucessfull passthrough counts as a conversion, so we look at len, + // which will be 1 for a unsucessfull call to get on the first try. + if (prev_ch == EOF && len<=1) + return EOF; + return fields; +} diff --git a/src/libc/uscan.c.src b/src/libc/uscan.c.src deleted file mode 100644 index 1dc82bd..0000000 --- a/src/libc/uscan.c.src +++ /dev/null @@ -1,2037 +0,0 @@ - section .text,"ax",@progbits - assume adl = 1 - section .text,"ax",@progbits - public __u_scan -__u_scan: - ld hl, -161 - call __frameset - ld hl, (ix + 12) - ld bc, -136 - lea iy, ix - add iy, bc - ld (iy), hl - xor a, a - ld de, 0 - ld bc, -133 - lea iy, ix - add iy, bc - ld bc, -142 - lea hl, ix - add hl, bc - ld (hl), iy - ld (ix - 3), de - ld de, -133 - lea iy, ix - add iy, de - lea bc, iy - push ix - ld de, -139 - add ix, de - ld (ix), bc - pop ix - ld de, -133 - lea hl, ix - add hl, de - ld bc, (ix + 15) - ld (_argp), bc - ld (_fields), a - ld de, (ix - 3) - ld (_len), de - ld (_prev_ch), de - ld (_isunget), a - ld bc, (ix + 6) - ld (_fp_fscanf), bc - ld bc, (ix + 9) - ld (_bptr), bc - ld iyl, 1 -BB0_1: - ld a, iyl - or a, a - jp z, BB0_173 - push ix - ld bc, -145 - add ix, bc - ld (ix), hl - pop ix - push de - pop hl - ld bc, -1 - or a, a - sbc hl, bc - jp z, BB0_174 - ld (ix - 3), bc - ld bc, -136 - lea hl, ix - add hl, bc - ld hl, (hl) - ld a, (hl) - or a, a - ld bc, (ix - 3) - jp z, BB0_174 - push ix - ld bc, -148 - add ix, bc - push af - ld a, iyl - ld (ix), a - pop af - pop ix - ld de, _fmt_str - push de - push hl - call __u_sscan - pop de - pop de - ld a, (_fmt_str) - cp a, 1 - jp z, BB0_176 - cp a, 2 - ld bc, -136 - lea iy, ix - push af - add iy, bc - pop af - ld (iy), hl - jr nz, BB0_9 - ld a, (_fmt_str+3) - ld l, a - rlc l - sbc hl, hl - ld l, a - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jp nz, BB0_47 - call _get - push hl - pop de - add hl, bc - or a, a - sbc hl, bc - jp z, BB0_49 - ld a, (_fmt_str+3) - ld l, a - rlc l - sbc hl, hl - push hl - pop bc - ld c, a - ex de, hl - or a, a - sbc hl, bc - ld de, -145 - lea hl, ix - push af - add hl, de - pop af - ld bc, (hl) - jp nz, BB0_172 - jp BB0_103 -BB0_9: - ld a, (_fmt_str+1) - ld e, a - bit 7, e - jp nz, BB0_50 - ld a, (_fmt_str+4) - ld l, a - rlc l - sbc hl, hl - push hl - pop iy - ld iyl, a - lea hl, iy - ld bc, 65 - or a, a - sbc hl, bc - jr z, BB0_12 - lea hl, iy - ld bc, -69 - add hl, bc - ld bc, 3 - or a, a - sbc hl, bc - jp nc, BB0_65 -BB0_12: - ld a, (_fmt_str+5) - add a, -127 - cp a, -126 - jr nc, BB0_14 - ld a, 126 - ld (_fmt_str+5), a -BB0_14: - call _get - push hl - pop iy - ld c, 16 - call __ishl - ld de, -65536 - or a, a - sbc hl, de - jp z, BB0_101 - ld de, -148 - lea hl, ix - add hl, de - ld (hl), iy - lea hl, iy - call __ishl - call __ishrs - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jr nz, BB0_14 - ld b, 0 - ld de, -139 - lea hl, ix - add hl, de - ld iy, (hl) - ld e, 1 - ld l, e - ld d, e -BB0_17: - ld (ix - 3), de - push ix - ld de, -154 - add ix, de - ld (ix), l - pop ix - ld a, (_fmt_str+5) - ld l, a - ld a, b - cp a, l - ld c, 16 - ld de, (ix - 3) - jp nc, BB0_68 - ld (ix - 3), de - ld de, -148 - lea hl, ix - add hl, de - ld hl, (hl) - ld a, l - call __ishl - call __ishrs - ld c, a - cp a, 127 - ld de, (ix - 3) - jr nz, BB0_24 - ld a, b - or a, a - jp nz, BB0_28 - ld bc, -151 - lea hl, ix - add hl, bc - ld (hl), iy - xor a, a - ld bc, -157 - lea iy, ix - add iy, bc - ld (iy), a - push ix - ld bc, -154 - add ix, bc - ld a, (ix) - pop ix - push ix - ld bc, -160 - add ix, bc - ld (ix), a - pop ix -BB0_21: - push ix - ld bc, -161 - add ix, bc - ld (ix), d -BB0_22: - pop ix -BB0_23: - push ix - ld bc, -154 - add ix, bc - ld (ix), e - jp BB0_31 -BB0_24: - ld (ix - 3), bc - push ix - ld bc, -154 - add ix, bc - ld a, (ix) - pop ix - or a, a - ld bc, (ix - 3) - jp nz, BB0_32 -BB0_25: - ld a, d - or a, a - jp z, BB0_34 - ld a, c - cp a, 46 - jp nz, BB0_34 - ld (ix - 3), bc - ld bc, -154 - lea hl, ix - add hl, bc - ld a, (hl) - push ix - ld bc, -160 - add ix, bc - ld (ix), a - pop ix - xor a, a - push ix - dec bc - add ix, bc - ld (ix), a - pop ix - ld a, e - ld bc, (ix - 3) - jp BB0_39 -BB0_28: - ld a, (iy - 1) - dec iy - cp a, 43 - ld (ix - 3), de - ld de, -151 - lea hl, ix - push af - add hl, de - pop af - ld (hl), iy - ld de, -157 - lea iy, ix - push af - add iy, de - pop af - ld (iy), b - ld de, (ix - 3) - jr z, BB0_30 - cp a, 45 - jp nz, BB0_41 -BB0_30: - ld bc, -154 - lea hl, ix - add hl, bc - ld a, (hl) - ld bc, -160 - lea iy, ix - add iy, bc - ld (iy), a - push ix - dec bc - add ix, bc - ld (ix), d - pop ix - ld a, 1 - push ix - ld bc, -154 - add ix, bc - ld (ix), a -BB0_31: - pop ix - jp BB0_40 -BB0_32: - ld a, c - cp a, 69 - ld a, 0 - ld (ix - 3), bc - push ix - ld bc, -160 - push af - add ix, bc - pop af - ld (ix), a - pop ix - push ix - dec bc - push af - add ix, bc - pop af - ld (ix), a - pop ix - ld a, 1 - ld bc, (ix - 3) - jp z, BB0_39 - ld a, c - cp a, 101 - ld a, 0 - ld (ix - 3), bc - push ix - ld bc, -160 - push af - add ix, bc - pop af - ld (ix), a - pop ix - push ix - dec bc - push af - add ix, bc - pop af - ld (ix), a - pop ix - ld a, 1 - ld bc, (ix - 3) - jp nz, BB0_25 - jp BB0_39 -BB0_34: - ld (ix - 3), de - push ix - ld de, -157 - add ix, de - ld (ix), b - pop ix - push ix - ld de, -151 - add ix, de - ld (ix), iy - pop ix - ld de, (ix - 3) - ld a, e - or a, a - jr nz, BB0_36 -BB0_35: - push hl - ld (ix - 3), bc - ld bc, -161 - lea hl, ix - add hl, bc - ld (hl), d - ld bc, (ix - 3) - ld de, -148 - lea iy, ix - add iy, de - ld (iy), c - call _isdigit - ld de, -148 - lea iy, ix - add iy, de - ld c, (iy) - pop de - add hl, bc - or a, a - sbc hl, bc - push ix - ld de, -154 - push af - add ix, de - pop af - ld a, (ix) - pop ix - push ix - ld de, -160 - push af - add ix, de - pop af - ld (ix), a - pop ix - ld a, 0 - push ix - ld de, -151 - push af - add ix, de - pop af - ld iy, (ix) - pop ix - push ix - ld de, -157 - push af - add ix, de - pop af - ld b, (ix) - pop ix - jp z, BB0_68 - jp BB0_39 -BB0_36: - ld a, c - cp a, 43 - jr z, BB0_38 - ld a, c - cp a, 45 - jp nz, BB0_35 -BB0_38: - ld (ix - 3), bc - ld bc, -154 - lea hl, ix - add hl, bc - ld a, (hl) - ld bc, -160 - lea iy, ix - add iy, bc - ld (iy), a - push ix - dec bc - add ix, bc - ld (ix), d - pop ix - xor a, a - push ix - ld de, -151 - add ix, de - ld iy, (ix) - pop ix - ld bc, (ix - 3) - push ix - ld de, -157 - add ix, de - ld b, (ix) - pop ix -BB0_39: - ld de, -154 - lea hl, ix - add hl, de - ld (hl), a - ld (iy), c - inc iy - push ix - ld de, -151 - add ix, de - ld (ix), iy - pop ix - inc b - ld de, -157 - lea iy, ix - add iy, de - ld (iy), b -BB0_40: - call _get - ld de, -148 - lea iy, ix - add iy, de - ld (iy), hl - ld a, l - cp a, d - ld de, -151 - lea hl, ix - push af - add hl, de - pop af - ld iy, (hl) - push ix - ld de, -157 - push af - add ix, de - pop af - ld b, (ix) - pop ix - push ix - ld de, -160 - push af - add ix, de - pop af - ld l, (ix) - pop ix - ld (ix - 3), bc - push ix - ld bc, -161 - push af - add ix, bc - pop af - ld d, (ix) - pop ix - push ix - ld bc, -154 - push af - add ix, bc - pop af - ld e, (ix) - pop ix - ld bc, (ix - 3) - jp z, BB0_101 - jp BB0_17 -BB0_41: - cp a, 46 - jr nz, BB0_43 - ld bc, -154 - lea hl, ix - add hl, bc - ld a, (hl) - ld bc, -160 - lea iy, ix - add iy, bc - ld (iy), a - ld a, 1 - push ix - dec bc - add ix, bc - ld (ix), a - jp BB0_22 -BB0_43: - cp a, 69 - jr z, BB0_45 - cp a, 101 - jr nz, BB0_46 -BB0_45: - ld a, 1 - ld bc, -160 - lea hl, ix - add hl, bc - ld (hl), a - dec bc - lea iy, ix - add iy, bc - ld (iy), d - jp BB0_23 -BB0_46: - ld bc, -154 - lea hl, ix - add hl, bc - ld a, (hl) - ld bc, -160 - lea iy, ix - add iy, bc - ld (iy), a - jp BB0_21 -BB0_47: - call _get - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jr nz, BB0_47 - call _unget -BB0_49: - ld de, -145 - lea hl, ix - add hl, de - ld bc, (hl) - jp BB0_103 -BB0_50: - bit 4, e - ld bc, 0 - jr nz, BB0_52 - ld iy, (_argp) - lea hl, iy + 3 - ld (_argp), hl - ld bc, (iy) -BB0_52: - ld iy, (_fmt_str+7) - ld d, (iy) - ld a, d - cp a, 94 - jr nz, BB0_54 - inc iy - ld (_fmt_str+7), iy -BB0_54: - ld a, (_fmt_str+5) - ld e, a - or a, a - ld a, 127 - jr z, BB0_56 -BB0_55: - ld a, e -BB0_56: - push bc - pop hl - ld e, a - dec e - or a, a - jp z, BB0_71 - ld bc, -154 - lea iy, ix - add iy, bc - ld (iy), e - push ix - ld bc, -148 - add ix, bc - ld (ix), hl - pop ix - ld bc, -151 - lea hl, ix - add hl, bc - ld (hl), d - call _get - push hl - pop de - ld c, 16 - call __ishl - push hl - pop iy - push de - pop hl - call __ishl - call __ishrs - ld (ix - 3), de - push ix - ld de, -157 - add ix, de - ld (ix), hl - pop ix - lea hl, iy - ld bc, -65536 - or a, a - sbc hl, bc - ld de, (ix - 3) - jp z, BB0_101 - ld c, e - ld iy, (_fmt_str+7) - ld de, (_fmt_str+10) -BB0_59: - lea hl, iy - or a, a - sbc hl, de - jr nc, BB0_62 - ld a, (iy) - ld l, a - rlc l - sbc hl, hl - ld (ix - 3), de - push ix - ld de, -160 - add ix, de - ld (ix), c - pop ix - ld de, (ix - 3) - push de - pop bc - push hl - pop de - ld e, a - inc iy - ld (ix - 3), bc - push ix - ld bc, -157 - add ix, bc - ld hl, (ix) - pop ix - or a, a - sbc hl, de - ld bc, (ix - 3) - push bc - pop de - ld (ix - 3), de - ld de, -160 - lea hl, ix - push af - add hl, de - pop af - ld c, (hl) - ld de, (ix - 3) - jr nz, BB0_59 - ld (ix - 3), bc - ld bc, -151 - lea hl, ix - add hl, bc - ld d, (hl) - ld a, d - cp a, 94 - ld bc, -154 - lea iy, ix - push af - add iy, bc - pop af - ld e, (iy) - ld bc, (ix - 3) - jp z, BB0_70 - jr BB0_63 -BB0_62: - ld (ix - 3), bc - ld bc, -151 - lea hl, ix - add hl, bc - ld d, (hl) - ld a, d - cp a, 94 - ld bc, -154 - lea iy, ix - push af - add iy, bc - pop af - ld e, (iy) - ld bc, (ix - 3) - jp nz, BB0_70 -BB0_63: - ld iyl, c - ld bc, -148 - lea hl, ix - add hl, bc - ld hl, (hl) - add hl, bc - or a, a - sbc hl, bc - ld bc, 0 - ld a, e - jp z, BB0_56 - ld a, iyl - ld (hl), a - inc hl - push hl - pop bc - jp BB0_55 -BB0_65: - ld bc, -88 - add iy, bc - lea hl, iy - ld bc, 33 - or a, a - sbc hl, bc - jp nc, BB0_49 - ld hl, JTI0_0 - lea bc, iy - add hl, bc - add hl, bc - add hl, bc - ld hl, (hl) - ld bc, 10 - push bc - pop iy - ld (ix - 3), de - push ix - ld de, -145 - add ix, de - ld bc, (ix) - pop ix - ld de, (ix - 3) - jp (hl) -BB0_67: - ld hl, 16 - jp BB0_107 -BB0_68: - lea hl, iy - ld (ix - 3), bc - push ix - ld bc, -139 - add ix, bc - ld de, (ix) - pop ix - or a, a - sbc hl, de - ld bc, (ix - 3) - jr nz, BB0_74 -BB0_69: - ld a, (_fields) - jp BB0_102 -BB0_70: - ld a, e - cp a, 1 - call pe, __setflag - call p, _unget - ld bc, -148 - lea hl, ix - add hl, bc - ld hl, (hl) -BB0_71: - add hl, bc - or a, a - sbc hl, bc - ld a, 1 - ld de, -148 - lea iy, ix - push af - add iy, de - pop af - ld (iy), a - push ix - ld de, -145 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - jp z, BB0_103 - ld (hl), 0 -BB0_73: - ld a, 1 - ld de, -148 - lea hl, ix - add hl, de - ld (hl), a - jp BB0_103 -BB0_74: - ld de, -151 - lea hl, ix - add hl, de - ld (hl), iy - ld a, (_fmt_str+5) - ld l, a - ld a, b - cp a, l - call c, _unget - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - ld (hl), 0 - ld hl, 0 - push hl - ld bc, -139 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - call _strtod - pop bc - pop bc - ld a, (_fmt_str+1) - bit 4, a - ld a, 1 - jp nz, BB0_102 -BB0_75: - ld iy, (_argp) - lea bc, iy + 3 - ld (_argp), bc - ld iy, (iy) - ld (iy), hl - ld (iy + 3), e -BB0_76: - ld hl, _fields - inc (hl) - ld a, 1 - jp BB0_102 -BB0_77: - bit 4, e - ld hl, 0 - ex de, hl - jr nz, BB0_79 - ld iy, (_argp) - lea hl, iy + 3 - ld (_argp), hl - ld de, (iy) -BB0_79: - ld a, (_fmt_str+5) - ld l, a - or a, a - jr nz, BB0_81 - ld a, 1 - ld (_fmt_str+5), a - ld l, a -BB0_81: - ld h, 0 -BB0_82: - ld a, h - cp a, l - jp nc, BB0_73 - ld bc, -148 - lea iy, ix - add iy, bc - ld (iy), h - ld bc, -151 - lea hl, ix - add hl, bc - ld (hl), de - call _get - push hl - pop iy - ld c, 16 - call __ishl - push hl - pop bc - ld de, -65536 - or a, a - sbc hl, de - jp z, BB0_101 - push bc - pop hl - ld de, 8323072 - or a, a - sbc hl, de - jr nz, BB0_87 - ld bc, -148 - lea hl, ix - add hl, bc - ld a, (hl) - or a, a - jr nz, BB0_90 - ld h, 0 - ld bc, -151 - lea iy, ix - add iy, bc - ld de, (iy) - jr BB0_93 -BB0_87: - ld de, -151 - lea hl, ix - add hl, de - ld hl, (hl) - add hl, bc - or a, a - sbc hl, bc - ld bc, 0 - jr z, BB0_89 - ld a, iyl - ld de, -151 - lea hl, ix - add hl, de - ld hl, (hl) - ld (hl), a - inc hl - push hl - pop bc -BB0_89: - ld hl, _fields - inc (hl) - ld de, -148 - lea hl, ix - add hl, de - ld h, (hl) - inc h - push bc - pop de - jr BB0_93 -BB0_90: - ld bc, -148 - lea hl, ix - add hl, bc - ld a, (hl) - dec a - lea iy, ix - add iy, bc - ld (iy), a - ld hl, _fields - dec (hl) - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - add hl, bc - or a, a - sbc hl, bc - ld hl, 0 - jr z, BB0_92 - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - dec hl -BB0_92: - ex de, hl - ld bc, -148 - lea hl, ix - add hl, bc - ld h, (hl) -BB0_93: - ld a, (_fmt_str+5) - ld l, a - ld (ix - 3), de - ld de, -145 - lea iy, ix - add iy, de - ld bc, (iy) - ld de, (ix - 3) - jp BB0_82 -BB0_94: - ld a, (_fmt_str+5) - add a, -127 - cp a, -126 - jr nc, BB0_96 - ld a, 126 - ld (_fmt_str+5), a -BB0_96: - call _get - push hl - pop de - ld a, e - cp a, -1 - ld a, 0 - jp z, BB0_102 - xor a, a - ld bc, -151 - lea hl, ix - add hl, bc - ld (hl), a - ld bc, -142 - lea iy, ix - add iy, bc - ld hl, (iy) - push ix - ld bc, -148 - add ix, bc - ld (ix), hl - pop ix -BB0_98: - ld bc, -154 - lea hl, ix - add hl, bc - ld (hl), de - ex de, hl - ld c, 16 - call __ishl - call __ishrs - push hl - call _isxdigit - pop de - add hl, bc - or a, a - sbc hl, bc - jp z, BB0_151 - ld de, -154 - lea hl, ix - add hl, de - ld hl, (hl) - ld a, l - ld de, -148 - lea hl, ix - add hl, de - ld hl, (hl) - ld (hl), a - ld de, -151 - lea iy, ix - add iy, de - ld c, (iy) - inc c - ld a, (_fmt_str+5) - ld e, a - ld (ix - 3), de - push ix - ld de, -154 - add ix, de - ld (ix), c - pop ix - ld a, c - ld de, (ix - 3) - cp a, e - jp nc, BB0_152 - inc hl - ld bc, -148 - lea iy, ix - add iy, bc - ld (iy), hl - call _get - push hl - pop de - ld a, e - cp a, -1 - ld bc, -154 - lea iy, ix - push af - add iy, bc - pop af - ld a, (iy) - push ix - ld bc, -151 - push af - add ix, bc - pop af - ld (ix), a - pop ix - jp nz, BB0_98 -BB0_101: - xor a, a -BB0_102: - ld de, -148 - lea hl, ix - add hl, de - ld (hl), a - ld de, -145 - lea iy, ix - add iy, de - ld bc, (iy) -BB0_103: - push bc - pop hl - ld de, (_prev_ch) - ld bc, -148 - lea iy, ix - add iy, bc - push af - ld a, (iy) - ld iyl, a - pop af - jp BB0_1 -BB0_104: - bit 4, e - jr nz, BB0_103 - ld bc, (_len) - ld iy, (_argp) - lea de, iy + 3 - ld (_argp), de - ld hl, (iy) - ld (hl), bc - ld de, -145 - lea hl, ix - add hl, de - ld bc, (hl) - ld hl, _fields - inc (hl) - jr BB0_103 -BB0_106: - ld hl, 8 -BB0_107: - push hl - pop iy -BB0_108: - ld bc, -151 - lea hl, ix - add hl, bc - ld (hl), iy - ld a, (_fmt_str+5) - add a, -127 - cp a, -126 - jr nc, BB0_110 - ld a, 126 - ld (_fmt_str+5), a -BB0_110: - call _get - push hl - pop iy - ld c, 16 - call __ishl - ld de, -65536 - or a, a - sbc hl, de - jp z, BB0_101 - lea hl, iy - call __ishl - call __ishrs - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jr nz, BB0_110 - call _unget - ld e, 0 - ld bc, -145 - lea hl, ix - add hl, bc - ld hl, (hl) -BB0_113: - ld bc, -157 - lea iy, ix - add iy, bc - ld (iy), hl -BB0_114: - ld a, e -BB0_115: - ld bc, -148 - lea hl, ix - add hl, bc - ld (hl), a - call _get - ld de, -154 - lea iy, ix - add iy, de - ld (iy), hl - ld c, 16 - call __ishl - push hl - pop iy - ld de, -65536 - or a, a - sbc hl, de - jp z, BB0_101 - lea hl, iy - ld de, 8323072 - or a, a - sbc hl, de - jr nz, BB0_118 - ld bc, -148 - lea hl, ix - add hl, bc - ld e, (hl) - ld a, e - or a, a - ld a, 0 - jr z, BB0_115 - jp BB0_130 -BB0_118: - ld de, -154 - lea hl, ix - add hl, de - ld hl, (hl) - call __ishl - call __ishrs - ld (ix - 3), bc - push ix - ld bc, -151 - add ix, bc - ld de, (ix) - pop ix - ld a, e - cp a, 8 - push ix - ld bc, -160 - push af - add ix, bc - pop af - ld (ix), iy - pop ix - ld bc, (ix - 3) - jr nz, BB0_122 - lea hl, iy - ld de, -3080193 - add hl, de - ld de, 589823 - or a, a - sbc hl, de - jp c, BB0_129 - lea hl, iy - ld de, 2818048 - or a, a - sbc hl, de - jr z, BB0_129 - lea hl, iy - jr BB0_128 -BB0_122: - ld a, e - cp a, 10 - jr nz, BB0_124 - push hl - call _isdigit - pop de - add hl, bc - or a, a - sbc hl, bc - ld de, -160 - lea iy, ix - push af - add iy, de - pop af - ld bc, (iy) - jr z, BB0_126 - jr BB0_129 -BB0_124: - ld bc, -151 - lea iy, ix - add iy, bc - ld de, (iy) - ld a, e - cp a, 16 - push ix - ld de, -160 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - jr nz, BB0_126 - push hl - call _isxdigit - ld de, -160 - lea iy, ix - add iy, de - ld bc, (iy) - pop de - add hl, bc - or a, a - sbc hl, bc - jr nz, BB0_129 -BB0_126: - push bc - pop hl - ld de, 2818048 - or a, a - sbc hl, de - jr z, BB0_129 - push bc - pop hl -BB0_128: - ld de, 2949120 - or a, a - sbc hl, de - jp nz, BB0_159 -BB0_129: - ld bc, -154 - lea hl, ix - add hl, bc - ld hl, (hl) - ld a, l - ld bc, -157 - lea hl, ix - add hl, bc - ld hl, (hl) - ld (hl), a - inc hl - lea iy, ix - add iy, bc - ld (iy), hl - ld bc, -148 - lea hl, ix - add hl, bc - ld e, (hl) - inc e - ld a, (_fmt_str+5) - ld l, a - ld a, e - cp a, l - ld (ix - 3), de - push ix - ld de, -145 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - ld de, (ix - 3) - jp c, BB0_114 - jp BB0_160 -BB0_130: - dec e - ld bc, -157 - lea hl, ix - add hl, bc - ld hl, (hl) - dec hl - jp BB0_113 -BB0_131: - bit 4, e - ld hl, 0 - jr nz, BB0_133 - ld iy, (_argp) - lea hl, iy + 3 - ld (_argp), hl - ld hl, (iy) -BB0_133: - ld bc, -151 - lea iy, ix - add iy, bc - ld (iy), hl - ld a, (_fmt_str+5) - or a, a - jr nz, BB0_135 - ld a, 127 - ld (_fmt_str+5), a -BB0_135: - call _get - push hl - pop iy - ld c, 16 - call __ishl - ld de, -65536 - or a, a - sbc hl, de - jp z, BB0_101 - lea hl, iy - call __ishl - call __ishrs - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jr nz, BB0_135 - call _unget - call _get - ld de, -154 - lea iy, ix - add iy, de - ld (iy), hl - ld a, l - cp a, d - ld a, 0 - ld de, -148 - lea hl, ix - push af - add hl, de - pop af - ld (hl), a - push ix - ld de, -145 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - jp z, BB0_103 - xor a, a - ld bc, -148 - lea hl, ix - add hl, bc - ld (hl), a -BB0_139: - ld de, -154 - lea hl, ix - add hl, de - ld hl, (hl) - ld c, 16 - call __ishl - call __ishrs - push hl - call _isspace - pop de - add hl, bc - or a, a - sbc hl, bc - jp nz, BB0_156 - ld bc, -154 - lea hl, ix - add hl, bc - ld hl, (hl) - ld e, l - ld a, e - or a, a - jp z, BB0_156 - ld a, e - cp a, 127 - jr nz, BB0_144 - ld bc, -148 - lea hl, ix - add hl, bc - ld a, (hl) - or a, a - jp nz, BB0_147 - xor a, a - ld bc, -148 - lea hl, ix - add hl, bc - ld (hl), a - jp BB0_150 -BB0_144: - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - add hl, bc - or a, a - sbc hl, bc - ld hl, 0 - ld bc, -154 - lea iy, ix - push af - add iy, bc - pop af - ld (iy), hl - jr z, BB0_146 - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - ld (hl), e - inc hl - ld bc, -154 - lea iy, ix - add iy, bc - ld (iy), hl -BB0_146: - ld bc, -148 - lea hl, ix - add hl, bc - ld e, (hl) - inc e - ld a, (_fmt_str+5) - ld l, a - lea iy, ix - add iy, bc - ld (iy), e - ld a, e - cp a, l - push ix - ld bc, -154 - push af - add ix, bc - pop af - ld de, (ix) - pop ix - push ix - ld bc, -151 - push af - add ix, bc - pop af - ld (ix), de - pop ix - jp nc, BB0_157 - jr BB0_150 -BB0_147: - ld bc, -148 - lea hl, ix - add hl, bc - ld a, (hl) - dec a - lea iy, ix - add iy, bc - ld (iy), a - push ix - ld bc, -151 - add ix, bc - ld hl, (ix) - pop ix - add hl, bc - or a, a - sbc hl, bc - ld hl, 0 - jr z, BB0_149 - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - dec hl -BB0_149: - ld bc, -151 - lea iy, ix - add iy, bc - ld (iy), hl -BB0_150: - call _get - ld bc, -154 - lea iy, ix - add iy, bc - ld (iy), hl - ld a, l - cp a, b - jp z, BB0_101 - jp BB0_139 -BB0_151: - ld bc, -148 - lea hl, ix - add hl, bc - ld hl, (hl) - jr BB0_153 -BB0_152: - ld bc, -151 - lea iy, ix - add iy, bc - ld a, (iy) - inc a - push ix - add ix, bc - ld (ix), a - pop ix - inc hl -BB0_153: - ld bc, -148 - lea iy, ix - add iy, bc - ld (iy), hl - push ix - ld bc, -142 - add ix, bc - ld de, (ix) - pop ix - or a, a - sbc hl, de - ld a, 0 - jp z, BB0_102 - ld a, (_fmt_str+5) - ld l, a - ld bc, -151 - lea iy, ix - add iy, bc - ld a, (iy) - cp a, l - call c, _unget - ld bc, -148 - lea hl, ix - add hl, bc - ld hl, (hl) - ld (hl), 0 - ld hl, 16 - push hl - ld hl, 0 - push hl - ld bc, -142 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - call _strtoul - pop de - pop de - pop de - ld a, (_fmt_str+1) - bit 4, a - ld a, 1 - jp nz, BB0_102 -BB0_155: - ld iy, (_argp) - lea de, iy + 3 - ld (_argp), de - ld iy, (iy) - ld (iy), hl - jp BB0_76 -BB0_156: - ld a, (_fmt_str+5) - ld l, a - ld bc, -151 - lea iy, ix - add iy, bc - ld de, (iy) - push ix - ld bc, -154 - add ix, bc - ld (ix), de - pop ix -BB0_157: - ld bc, -148 - lea iy, ix - add iy, bc - ld a, (iy) - cp a, l - call c, _unget - ld de, -154 - lea hl, ix - add hl, de - ld hl, (hl) - add hl, bc - or a, a - sbc hl, bc - ld a, 1 - ld de, -148 - lea iy, ix - push af - add iy, de - pop af - ld (iy), a - push ix - ld de, -145 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - jp z, BB0_103 - ld de, -154 - lea hl, ix - add hl, de - ld hl, (hl) - ld (hl), 0 - ld hl, _fields - inc (hl) - jp BB0_73 -BB0_159: - ld de, -145 - lea hl, ix - add hl, de - ld bc, (hl) - ld (ix - 3), bc - ld bc, -148 - lea iy, ix - add iy, bc - ld e, (iy) - ld bc, (ix - 3) -BB0_160: - ld iyl, e - ld de, -160 - lea hl, ix - add hl, de - ld hl, (hl) - ld de, -65536 - or a, a - sbc hl, de - ld a, d - ld de, -148 - lea hl, ix - push af - add hl, de - pop af - ld (hl), a - jp z, BB0_103 - ld de, -157 - lea hl, ix - add hl, de - ld hl, (hl) - or a, a - sbc hl, bc - jp z, BB0_69 - ld a, (_fmt_str+5) - ld l, a - ld a, iyl - cp a, l - call c, _unget - ld bc, -157 - lea hl, ix - add hl, bc - ld hl, (hl) - ld (hl), 0 - ld a, (_fmt_str+4) - cp a, 117 - jr z, BB0_165 - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - ld a, l - cp a, 8 - jr z, BB0_165 - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - ld a, l - cp a, 16 - jr nz, BB0_170 -BB0_165: - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - ld hl, 0 - push hl - ld bc, -145 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - call _strtoul -BB0_166: - pop bc - pop bc - pop bc - ld a, (_fmt_str+1) - bit 4, a - ld a, 1 - ld bc, -148 - lea iy, ix - push af - add iy, bc - pop af - ld (iy), a - ld (ix - 3), de - push ix - ld de, -145 - push af - add ix, de - pop af - ld bc, (ix) - pop ix - ld de, (ix - 3) - jp nz, BB0_103 - ld a, (_fmt_str+2) - cp a, 76 - jp z, BB0_75 - cp a, 104 - jr nz, BB0_171 - ld iy, (_argp) - lea de, iy + 3 - ld (_argp), de - ld iy, (iy) - ld (iy), l - ld (iy + 1), h - jp BB0_76 -BB0_170: - ld bc, -151 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - ld hl, 0 - push hl - ld bc, -145 - lea hl, ix - add hl, bc - ld hl, (hl) - push hl - call _strtol - jr BB0_166 -BB0_171: - cp a, 108 - jp z, BB0_75 - jp BB0_155 -BB0_172: - ld de, (_prev_ch) -BB0_173: - ld bc, -1 -BB0_174: - ex de, hl - ld de, -1 - or a, a - sbc hl, de - jr nz, BB0_176 - ld hl, (_len) - ld de, 2 - or a, a - sbc hl, de - call pe, __setflag - jp m, BB0_177 -BB0_176: - ld a, (_fields) - ld bc, 0 - ld c, a -BB0_177: - push bc - pop hl - ld sp, ix - pop ix - ret - section .text,"ax",@progbits - section .rodata,"a",@progbits - private JTI0_0 -JTI0_0: - dl BB0_67 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_12 - dl BB0_103 - dl BB0_77 - dl BB0_108 - dl BB0_12 - dl BB0_12 - dl BB0_12 - dl BB0_103 - dl BB0_108 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_103 - dl BB0_104 - dl BB0_106 - dl BB0_94 - dl BB0_103 - dl BB0_103 - dl BB0_131 - dl BB0_103 - dl BB0_108 - dl BB0_103 - dl BB0_103 - dl BB0_67 - - section .text,"ax",@progbits - private _get -_get: - ld hl, (_len) - inc hl - ld (_len), hl - ld hl, (_bptr) - add hl, bc - or a, a - sbc hl, bc - jr nz, BB1_4 - ld a, (_isunget) - bit 0, a - jr z, BB1_6 - xor a, a - ld (_isunget), a -BB1_3: - ld de, (_prev_ch) - jr BB1_5 -BB1_4: - push hl - pop iy - inc iy - ld (_bptr), iy - ld a, (hl) - ld l, a - rlc l - sbc hl, hl - push hl - pop de - ld e, a -BB1_5: - ex de, hl - ret -BB1_6: - ld hl, (_fp_fscanf) - add hl, bc - or a, a - sbc hl, bc - jr nz, BB1_9 - call _getchar - push hl - pop de - ld (_prev_ch), de - ld bc, 3 - or a, a - sbc hl, bc - jr nz, BB1_10 - ld hl, 1 - push hl - call _exit - pop hl -BB1_9: - push hl - call _fgetc - push hl - pop de - pop hl - ld (_prev_ch), de - jr BB1_5 -BB1_10: - ld bc, 8 - push de - pop hl - or a, a - sbc hl, bc - jr nz, BB1_5 - ld de, 127 - ld hl, 32 - ld (_prev_ch), de - push hl - call _putchar - pop hl - ld hl, 127 - push hl - call _putchar - pop hl - jr BB1_3 - section .text,"ax",@progbits - - section .text,"ax",@progbits - private _unget -_unget: - ld a, 1 - ld hl, (_len) - dec hl - ld (_len), hl - ld (_isunget), a - ld hl, (_bptr) - add hl, bc - or a, a - sbc hl, bc - jr z, BB2_2 - dec hl - ld (_bptr), hl -BB2_2: - ret - section .text,"ax",@progbits - - section .bss,"aw",@nobits - private _argp -_argp: - rb 3 - - section .bss,"aw",@nobits - private _fields -_fields: - rb 1 - - section .bss,"aw",@nobits - private _len -_len: - rb 3 - - section .bss,"aw",@nobits - private _prev_ch -_prev_ch: - rb 3 - - section .bss,"aw",@nobits - private _isunget -_isunget: - rb 1 - - section .bss,"aw",@nobits - public _fp_fscanf -_fp_fscanf: - rb 3 - - section .bss,"aw",@nobits - private _bptr -_bptr: - rb 3 - - section .bss,"aw",@nobits - private _fmt_str -_fmt_str: - rb 19 - - ident "clang version 15.0.0 (https://github.com/jacobly0/llvm-project 6c61664110f888c0285ae4c48b150c9a7a4361bb)" - extern __Unwind_SjLj_Register - extern _isxdigit - extern _strtoul - extern __u_sscan - extern __ishl - extern __setflag - extern _exit - extern _putchar - extern __frameset - extern _isspace - extern _fgetc - extern _isdigit - extern __ishrs - extern __Unwind_SjLj_Unregister - extern _strtod - extern _strtol - extern _getchar diff --git a/src/libc/usscan.c b/src/libc/usscan.c new file mode 100644 index 0000000..256fa83 --- /dev/null +++ b/src/libc/usscan.c @@ -0,0 +1,174 @@ +/************************************************* + * Copyright (C) 1999-2008 by Zilog, Inc. + * All Rights Reserved + *************************************************/ + +#include "format.h" +#include +#include + +#ifndef _PTR_ +# define _PTR_ * +#endif + +/* actions */ + +#define ACC -1 +#define ERR -2 + +#define CR 13 +#define LF 10 + +/* +-{0..9} + {sp,tab,nl}{h,l,L}| +-{d,i,o,u,x,e,f,g,s,c,p,n} + | | | | {others} + % | * | | | [ ] | + +-----------------------------------+ */ +static char sscan_fsa[10][9] = { + /* 0 */ { 2, 0, 1, 1, 1, 1, 1, 1, 1}, + /* 1 */ {ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC}, + /* 2 */ { 8,ERR, 3, 5, 4, 9, 6,ERR,ERR}, + /* 3 */ {ERR,ERR,ERR, 5, 4, 9, 6,ERR,ERR}, + /* 4 */ {ERR,ERR,ERR, 5, 4, 9, 6,ERR,ERR}, + /* 5 */ {ERR,ERR,ERR,ERR,ERR, 9, 6,ERR,ERR}, + /* 6 */ { 6, 6, 6, 6, 6, 6, 6, 7, 6}, + /* 7 */ {ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC}, + /* 8 */ {ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC}, + /* 9 */ {ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC,ACC}, + }; + +/************************************************* +* +* _u_sscan - scan a scanf format string +* +* Inputs: +* fmt - pointer to format string +* str - pointer to fmt_type structure +* where the results are put +* +* Returns: +* new pointer to format string +* - with updated location to start scanning next time +* +*************************************************/ +const char _PTR_ _u_sscan( const char _PTR_ fmt,struct fmt_type _PTR_ str ) +{ + int pstate; + int state = 0; + unsigned char class; + char ch; + + str->flags = 0; + str->field_width = 0; + str->precision = 0; + str->size = 0; + str->type = '\0'; + + for (;;) { + ch = *(fmt++); + switch(ch) { + case '%': + class = 0; + break; + /***** Treat these as pass through: + case ' ': + case '\t': + case '\n': + class = 1; + break; + ****/ + case '*': + class = 2; + break; + case 'h': + case 'l': + case 'L': + class = 3; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + class = 4; + break; + case 'A': + case 'E': + case 'F': + case 'G': + case 'X': + case 'a': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'i': + case 'n': + case 'o': + case 'p': + case 's': + case 'u': + case 'x': + class = 5; + break; + case '[': + class = 6; + break; + case ']': + class = 7; + break; + default: + class = 8; + } + + pstate = state; + state = sscan_fsa[state][class]; + + switch (state) { + case ACC: + str->status = FMT_OK; + return(fmt-1); + case ERR: + str->status = FMT_ERR; + return(fmt-1); + case 1: + case 8: + str->status = FMT_PASS_THRU; + str->chr = ch; + return(fmt); + case 3: + str->flags |= FMT_FLAG_IGNORE; + break; + case 4: + str->field_width = str->field_width * 10 + (ch - '0'); + break; + case 5: + str->size = ch; + break; + case 6: + if (pstate != state) { + str->flags |= FMT_FLAG_SET; + str->set_begin = fmt; + // Check for sets that start with [] or [^] + if (*fmt == '^') + fmt++; + if (*fmt == ']') + fmt++; + + } + break; + case 7: + str->set_end = fmt-1; + break; + case 9: + str->type = ch; + break; + } + } +}