Showing the changes to aa.c (1 of 3 files). Show all
Unified · Split
| @@ -589,7 +589,7 @@ aa_set(aaContext *ctx, aaObject *sym, aaObject *v) · 588 unmodified lines | ||
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | static aaObject * |
| 592 | −read_(aaContext *ctx, aaReadFn fn, void *udata) | |
| 592 | +read_(aaContext *ctx, Biobuf *fp) | |
| 593 | 593 | { |
| 594 | 594 | const char *delimiter = " \n\t\r();"; |
| 595 | 595 | aaObject *v, *res, **tail; |
| @@ -598,21 +598,21 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 2 unmodified lines | ||
| 598 | 598 | char buf[64], *p; |
| 599 | 599 | |
| 600 | 600 | /* get next character */ |
| 601 | − chr = ctx->nextchr ? ctx->nextchr : fn(ctx, udata); | |
| 601 | + chr = ctx->nextchr ? ctx->nextchr : Bgetc(fp); | |
| 602 | 602 | ctx->nextchr = '\0'; |
| 603 | 603 | |
| 604 | 604 | /* skip whitespace */ |
| 605 | − while(chr && strchr(" \n\t\r", chr)) | |
| 606 | − chr = fn(ctx, udata); | |
| 605 | + while(chr > 0 && strchr(" \n\t\r", chr)) | |
| 606 | + chr = Bgetc(fp); | |
| 607 | 607 | |
| 608 | − switch(chr){ | |
| 609 | − case 0: | |
| 608 | + if(chr <= 0) | |
| 610 | 609 | return nil; |
| 611 | 610 | |
| 611 | + switch(chr){ | |
| 612 | 612 | case ';': |
| 613 | − while(chr && chr != '\n') | |
| 614 | − chr = fn(ctx, udata); | |
| 615 | − return read_(ctx, fn, udata); | |
| 613 | + while(chr > 0 && chr != '\n') | |
| 614 | + chr = Bgetc(fp); | |
| 615 | + return read_(ctx, fp); | |
| 616 | 616 | |
| 617 | 617 | case ')': |
| 618 | 618 | return &rparen; |
| @@ -622,12 +622,12 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 3 unmodified lines | ||
| 622 | 622 | tail = &res; |
| 623 | 623 | gc = aa_savegc(ctx); |
| 624 | 624 | aa_pushgc(ctx, res); /* to cause error on too-deep nesting */ |
| 625 | − while((v = read_(ctx, fn, udata)) != &rparen){ | |
| 625 | + while((v = read_(ctx, fp)) != &rparen){ | |
| 626 | 626 | if(v == nil) |
| 627 | 627 | aa_error(ctx, "unclosed list"); |
| 628 | 628 | if(TYPE(v) == AA_TSYMBOL && streq(CAR(CDR(v)), ".")){ |
| 629 | 629 | /* dotted pair */ |
| 630 | − *tail = aa_read(ctx, fn, udata); | |
| 630 | + *tail = aa_read(ctx, fp); | |
| 631 | 631 | }else{ |
| 632 | 632 | /* proper pair */ |
| 633 | 633 | *tail = aa_cons(ctx, v, &Null); |
| @@ -639,7 +639,7 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 5 unmodified lines | ||
| 639 | 639 | return res; |
| 640 | 640 | |
| 641 | 641 | case '\'': |
| 642 | − v = aa_read(ctx, fn, udata); | |
| 642 | + v = aa_read(ctx, fp); | |
| 643 | 643 | if(!v) |
| 644 | 644 | aa_error(ctx, "stray '''"); |
| 645 | 645 | return aa_cons(ctx, aa_symbol(ctx, "quote"), aa_cons(ctx, v, &Null)); |
| @@ -647,11 +647,11 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 1 unmodified line | ||
| 647 | 647 | case '"': |
| 648 | 648 | res = buildstring(ctx, nil, '\0'); |
| 649 | 649 | v = res; |
| 650 | − for(chr = fn(ctx, udata); chr != '"'; chr = fn(ctx, udata)){ | |
| 651 | − if(chr == 0) | |
| 650 | + for(chr = Bgetc(fp); chr != '"'; chr = Bgetc(fp)){ | |
| 651 | + if(chr <= 0) | |
| 652 | 652 | aa_error(ctx, "unclosed string"); |
| 653 | 653 | if(chr == '\\'){ |
| 654 | − chr = fn(ctx, udata); | |
| 654 | + chr = Bgetc(fp); | |
| 655 | 655 | if(strchr("nrt", chr)) |
| 656 | 656 | chr = strchr("n\nr\rt\t", chr)[1]; |
| 657 | 657 | } |
| @@ -665,8 +665,8 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 7 unmodified lines | ||
| 665 | 665 | if(p == buf + sizeof(buf) - 1) |
| 666 | 666 | aa_error(ctx, "symbol too long"); |
| 667 | 667 | *p++ = chr; |
| 668 | − chr = fn(ctx, udata); | |
| 669 | − }while(chr && !strchr(delimiter, chr)); | |
| 668 | + chr = Bgetc(fp); | |
| 669 | + }while(chr > 0 && !strchr(delimiter, chr)); | |
| 670 | 670 | *p = '\0'; |
| 671 | 671 | ctx->nextchr = chr; |
| 672 | 672 | n.r = strtod(buf, &p); /* try to read as number */ |
| @@ -677,9 +677,9 @@ read_(aaContext *ctx, aaReadFn fn, void *udata) · 4 unmodified lines | ||
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | aaObject * |
| 680 | −aa_read(aaContext *ctx, aaReadFn fn, void *udata) | |
| 680 | +aa_read(aaContext *ctx, Biobuf *fp) | |
| 681 | 681 | { |
| 682 | − aaObject *obj = read_(ctx, fn, udata); | |
| 682 | + aaObject *obj = read_(ctx, fp); | |
| 683 | 683 | |
| 684 | 684 | if(obj == &rparen) |
| 685 | 685 | aa_error(ctx, "stray ')'"); |
| @@ -687,22 +687,6 @@ aa_read(aaContext *ctx, aaReadFn fn, void *udata) · 1 unmodified line | ||
| 687 | 687 | return obj; |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | −static char | |
| 691 | −readbio(aaContext *ctx, void *udata) | |
| 692 | −{ | |
| 693 | − int chr; | |
| 694 | − | |
| 695 | − USED(ctx); | |
| 696 | − | |
| 697 | − return (chr = Bgetc(udata)) < 0 ? 0 : chr; | |
| 698 | −} | |
| 699 | − | |
| 700 | −aaObject * | |
| 701 | −aa_readfp(aaContext *ctx, Biobuf *fp) | |
| 702 | −{ | |
| 703 | − return aa_read(ctx, readbio, fp); | |
| 704 | −} | |
| 705 | − | |
| 706 | 690 | static aaObject * |
| 707 | 691 | evallist(aaContext *ctx, aaObject *lst, aaObject *env) |
| 708 | 692 | { |
| @@ -1069,7 +1053,7 @@ aa_open(void *ptr, int size, int flags) · 360 unmodified lines | ||
| 1069 | 1053 | Binits(&b, -1, OREAD, (uchar*)prelude, i); |
| 1070 | 1054 | b.icount = -i; |
| 1071 | 1055 | Biofn(&b, eof); |
| 1072 | − while((v = aa_readfp(ctx, &b)) != nil){ | |
| 1056 | + while((v = aa_read(ctx, &b)) != nil){ | |
| 1073 | 1057 | aa_eval(ctx, v); |
| 1074 | 1058 | aa_restoregc(ctx, save); |
| 1075 | 1059 | } |