diff options
-rw-r--r-- | apl9.h | 2 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | quadnames.c | 60 |
3 files changed, 66 insertions, 0 deletions
@@ -400,6 +400,7 @@ Array *opReduceFirst(Datum *, Array *, Array *); Array *opScanFirst(Datum *, Array *, Array *); /* Global variables */ +extern Biobuf *stdin; /* main.c */ extern int traceeval; /* eval.c */ extern int debugmem; /* memory.c */ extern int datasizes[]; /* array.c */ @@ -418,3 +419,4 @@ extern QuadnameDef quadnames[]; /* quadnames.c */ extern int printprecision; /* print.c */ extern ErrorHandler globalerror; /* error.c */ extern Rune *errorstrs[]; /* error.c */ +extern int needsnewline; /* quadnames.c */
\ No newline at end of file @@ -44,6 +44,10 @@ restart: while(!off){ checkmem("main loop"); + if(needsnewline){ + print("\n"); + needsnewline = 0; + } print("\t"); Datum *result = evalline(nil, stdin, 1); if(result == nil) diff --git a/quadnames.c b/quadnames.c index 266cc02..88fe087 100644 --- a/quadnames.c +++ b/quadnames.c @@ -4,6 +4,8 @@ #include "apl9.h" +Datum *getquotequad(void); +void setquotequad(Datum); Datum *getquad(void); void setquad(Datum); Datum *getio(void); @@ -21,7 +23,11 @@ Array *quadthrow2(Array *, Array *); Array *quadinfo(Array *); Array *quadproto(Array *); +int needsnewline = 0; +static Rune *quadquotebuf = nil; + QuadnameDef quadnames[] = { + {L"⍞", NameTag, getquotequad, setquotequad, nil, nil}, {L"⎕", NameTag, getquad, setquad, nil, nil}, {L"⎕IO", NameTag, getio, setio, nil, nil}, {L"⎕PP", NameTag, getpp, setpp, nil, nil}, @@ -76,6 +82,59 @@ quadnamedatum(QuadnameDef q) return d; } +/* ⍞ */ +Datum * +getquotequad(void) +{ + int sizemax = 512; + int size; + Rune *input; + if(needsnewline && quadquotebuf != nil){ + input = quadquotebuf; + size = runestrlen(input); + sizemax = size+1; + quadquotebuf = nil; + }else{ + input = malloc(sizeof(Rune) * sizemax); + size = 0; + } + do{ + if(size == sizemax-1){ + sizemax += 512; + input = realloc(input, sizeof(Rune) * sizemax); + } + input[size] = Bgetrune(stdin); + size++; + }while(input[size-1] != '\n'); + input[size-1] = 0; + + Datum *result = mallocz(sizeof(Datum), 1); + result->tag = ArrayTag; + result->array = mkrunearray(input); + free(input); + return result; +} + +void +setquotequad(Datum new) +{ + Rune *str = ppdatum(new); + if(needsnewline && quadquotebuf != nil){ + if(quadquotebuf){ + Rune *tmp = quadquotebuf; + quadquotebuf = runesmprint("%S%S", tmp, str); + free(tmp); + } + }else{ + free(quadquotebuf); + quadquotebuf = runestrdup(str); + } + + needsnewline = 1; + print("%S", str); + free(str); +} + /* ⎕ */ Datum * getquad(void) @@ -89,6 +148,7 @@ getquad(void) void setquad(Datum new) { + needsnewline = 0; print("%S\n", ppdatum(new)); } |