summaryrefslogtreecommitdiff
path: root/quadnames.c
diff options
context:
space:
mode:
Diffstat (limited to 'quadnames.c')
-rw-r--r--quadnames.c60
1 files changed, 60 insertions, 0 deletions
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));
}