DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦1c6814429⟧ TextFile

    Length: 13184 (0x3380)
    Types: TextFile
    Names: »SCANF.C«

Derivation

└─⟦4dd5d59b6⟧ Bits:30003303 Mix C version 2.1 og debugger til RC703
    └─ ⟦this⟧ »SCANF.C« 
└─⟦b6190e06c⟧ Bits:30003304 Mix C version 2.1 til RC703
└─⟦b6190e06c⟧ Bits:30005327 Mix C version 2.1 til RC703
    └─ ⟦this⟧ »SCANF.C« 

TextFile

#include "stdio"

scanf(fs)                           /* standard routine */
char     *fs;
æ
    int    getc();
    int    ungetc();
    return _input(stdin, &fs, getc, ungetc);
å

fscanf(fp, fs)                      /* standard routine */
char     *fp, *fs;
æ
    int    getc();
    int    ungetc();
    return _input(fp, &fs, getc, ungetc);
å

sscanf(s,fs)                        /* standard routine */
char    *s, *fs;
æ
    int     _mread();
    int     _mungetc();
    return _input(&s, &fs, _mread, _mungetc);
å

_input(fp, parms, read, ungetc)     /* input routine for */
                                    /* scanf, sscanf, fscanf */
char    *fp;                        /* pointer to input */
char    **parms;                    /* pointer to addr of parameters */
int     (*read)();                  /* character read function */
int     (*ungetc)();                /* character unget function */
æ
    union æ                         /* buffer for numeric & string storage */
      int   integer;
      char  stringÆ81Å;
    å buffer;
    char    *format;                /* format string pointer */
    char    c;                      /* format string character */
    char    **ptr;                  /* pointer to pointer */
    int     base;                   /* number base */
    int     value;                  /* binary value of digit */
    int     pflag;                  /* real precision flag */
    int     asflag;                 /* assignment supression flag */
    int     sflag;                  /* sign flag */
    int     ch;                     /* input character */
    int     temp;                   /* temporary storage */
    int     i;                      /* loop counter */
    int     count;                  /* character count */
    int     width;                  /* maximum field width */
    int     status;                 /* status returned from the read */
    int     valid;                  /* valid real number format */
    int     (*acc)();               /* pointer to accumulate function */
    int     (*neg)();               /* pointer to negate function */
    int     (*asn)();               /* pointer to assign function */
    int     _digit();               /* decode digit function */
    int     _dint();                /* decode integer function */
    int     _dlong();               /* decode long function */
    int     _negint();              /* negate integer function */
    int     _neglong();             /* negate long function */
    int     _aint();                /* assign integer function */
    int     _along();               /* assign long function */
    int     _atoi();                /* convert string to integer */
    int     isspace();              /* whitespace function */
    int     isdigit();              /* digit function */
    STRING  *stods();               /* convert string to dynamic string */

    format = *parms--;              /* format points to format string */
    count = 0;                      /* number of parameters read */
    while (c = *format++) æ
        if (isspace(c)) continue;   /* skip white space */
        if (c != '%') æ
            while (isspace(ch = (*read)(fp)));
            if (ch == c) continue;
            else return (ch == EOF) ? EOF : count;
        å
        pflag = sflag = asflag = 0;
        if ((*format) == '*') æ     /* check for assignment suppression */
            ++asflag;
            ++format;
        å
        acc = _dint;
        neg = _negint;
        asn = _aint;
        width = isdigit(*format) ? _atoi(&format) : -1;
        if (toupper(*format) == 'L') æ  /* check for double precision */
            ++pflag;
            ++format;
            acc = _dlong;
            neg = _neglong;
            asn = _along;
        å
        c = *format++;
        switch (toupper(c)) æ

            case 'H':                   /* signed decimal */
                    pflag++;
            case 'D':
            case 'U':
                    base = 10;
                    goto decode;

            case 'O':                   /* unsigned octal */
                    base = 8;
                    goto decode;

            case 'X':                   /* unsigned hexadecimal */
                    base = 16;
            decode:
                    for (i=0; i<5; ++i) buffer.stringÆiÅ = 'Ø0';
                    while ((ch=(*read)(fp))==' ' øø ch == 'Øt'
                            øø ch == 'Øn');
                    if (ch == EOF) return EOF;
                    if (width && (ch == '+' øø ch == '-')) æ
                       if (ch == '-') ++sflag;
                       ch = (*read)(fp);
                       --width;
                    å
                    if (width && base == 16 && ch == '0') æ
                       temp = (*read)(fp);
                       --width;
                       if (toupper(temp) == 'X' && width) æ
                          ch = (*read)(fp);
                          --width;
                       å
                       else æ
                          (*ungetc)(temp, fp);
                          ++width;
                       å
                    å
                    if ((value = _digit(ch, base)) == -1) return count;
                    while (width && (value != -1)) æ
                       (*acc)(&buffer.integer, value, base);
                       ch = (*read)(fp);
                       --width;
                       value = _digit(ch,base);
                    å
                    (*ungetc)(ch, fp);
                    if (sflag) (*neg)(&buffer.integer);
                    if (!asflag) æ
                       (*asn)(&buffer.integer, *parms, pflag);
                       ++count;
                       --parms;
                    å
                    break;

            case 'S':                   /* string */
                    while ((ch=(*read)(fp))==' ' øø ch == 'Øt'
                            øø ch == 'Øn');
                    if (ch == EOF) return EOF;
                    while (width && ch != ' ' && ch != 'Øt'
                           && ch != 'Øn' && ch != EOF) æ
                       if (!asflag) *(*parms)++ = ch;
                       ch = (*read)(fp);
                       --width;
                       å
                    (*ungetc)(ch, fp);
                    if (!asflag) æ
                       *(*parms) = 'Ø0';
                       ++count;
                       --parms;
                    å
                    break;

            case 'C':                   /* character */
                    if ((ch = (*read)(fp)) == EOF) return EOF;
                    else
                       if (!asflag) æ
                          *(*parms) = ch;
                          ++count;
                          --parms;
                        å
                    break;

            case 'E':
            case 'F':                   /* floating point */
                    while ((ch=(*read)(fp))==' ' øø ch == 'Øt'
                            øø ch == 'Øn');
                    if (ch == EOF) return EOF;
                    i = 0;
                    valid = 0;
                    if (width && (ch == '+' øø ch == '-')) æ
                        buffer.stringÆi++Å = ch;
                        ch = (*read)(fp);
                        --width;
                    å
                    while (width && ch >= '0' && ch <= '9') æ
                        buffer.stringÆi++Å = ch;
                        ch = (*read)(fp);
                        --width;
                        ++valid;
                    å
                    if (width && ch == '.') æ
                       buffer.stringÆi++Å = ch;
                       ch = (*read)(fp);
                       --width;
                       while (width && ch >= '0' && ch <= '9') æ
                          buffer.stringÆi++Å = ch;
                          ch = (*read)(fp);
                          --width;
                          ++valid;
                       å
                    å
                    if (width && (ch == 'E' øø ch == 'e' øø ch == 'D')) æ
                       if (!valid) return count;
                       valid = 0;
                       buffer.stringÆi++Å = 'E';
                       ch = (*read)(fp);
                       --width;
                       if (width && (ch == '+' øø ch == '-')) æ
                          buffer.stringÆi++Å = ch;
                          ch = (*read)(fp);
                          --width;
                       å
                       while (width && isdigit(ch)) æ
                          buffer.stringÆi++Å = ch;
                          ch = (*read)(fp);
                          --width;
                          ++valid;
                       å
                    å
                    (*ungetc)(ch, fp);
                    if (!valid) return count;
                    buffer.stringÆiÅ = 'Ø0';
                    if (!asflag) æ
                        _dreal(buffer.string, *parms, pflag);
                        ++count;
                        --parms;
                    å
                    break;

            case 'Y':               /* dynamic string */
                    while ((ch=(*read)(fp))==' ' øø ch == 'Øt'
                            øø ch == 'Øn');
                    if (ch == EOF) return EOF;
                    i = 0;
                    while (width && ch != ' ' && ch != 'Øt'
                           && ch != 'Øn' && ch != EOF) æ
                       if (i < 80) buffer.stringÆi++Å = ch;
                       ch = (*read)(fp);
                       --width;
                       å
                    buffer.stringÆiÅ = 'Ø0';
                    (*ungetc)(ch,fp);
                    if (!asflag) æ
                       ptr = *parms;
                       *ptr = stods(buffer.string);
                       ++count;
                       --parms;
                    å
                    break;

            default :
                    return count;
        å
    å
    return count;
å

_negint(iptr)                       /* negate integer */
int         *iptr;                  /* pointer to integer */
æ
    *iptr = -*iptr;
å

_aint(iptr1, iptr2, pflag)         /* assign integer */
int     *iptr1;                    /* pointer to fp */
int     *iptr2;                    /* pointer to destination */
int     pflag;                     /* short integer flag */
æ
    short *sptr;
    if (pflag) æ
        sptr = iptr2;
        *sptr = *iptr1;
    å
    else *iptr2 = *iptr1;
å

_neglong(lptr)                      /* negate long */
long        *lptr;                  /* pointer to long integer */
æ
    *lptr = -*lptr;
å

_along(lptr1, lptr2)               /* assign long */
long    *lptr1;                    /* pointer to fp */
long    *lptr2;                    /* pointer to destination */
æ
    *lptr2 = *lptr1;
å

_digit(ch, base)                   /* decode ch to binary */
int     ch;                        /* character to decode */
int     base;                      /* number base */
æ
    if (ch >= '0' && ch <= '9') ch -= 48;
    else
       if  (isalpha(ch = toupper(ch))) ch -= 55;
       else
          return -1;
    if (ch < base) return ch;
    else return -1;
å

_dint(iptr, digit, base)                    /* decode an integer */
int      *iptr;                             /* pointer to integer */
int      digit;                             /* digit to add to integer */
int      base;                              /* number base */
æ
    *iptr = *iptr * base + digit;
å

_dlong(lptr, digit, base)           /* decode a long */
long    *lptr;                      /* pointer to long */
int     digit;                      /* digit to add to long */
int     base;                       /* number base */
æ
    *lptr = *lptr * base + digit;
å

_dreal(s, fptr, pflag)              /* decode a real */
char    *s;                         /* pointer to decode string */
float   *fptr;                      /* pointer to float */
int     pflag;                      /* precision flag */
æ
    double  atof();                 /* string to double function */
    double  *dptr;                  /* pointer to double */
    if (pflag) æ
       dptr = fptr;
       *dptr = atof(s);
    å
    else
        *fptr = (float) atof(s);
å

_mread(s)                           /* read character from string */
char    **s;                        /* pointer to string */
æ
    if (*(*s) != 'Ø0') return *(*s)++;
    else return EOF;
å

_mungetc(c,s)                       /* unget character to string */
int     c;                          /* dumy parameter */
char    **s;                        /* pointer to string pointer */
æ
    --(*s);
    return c;
å

«eof»