3 source/macro.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
4 1 file changed, 86 insertions(+), 2 deletions(-)
6 diff --quilt old/source/macro.c new/source/macro.c
9 @@ -2644,6 +2644,83 @@ static int beepMS(WindowInfo *window, Da
13 +static void printArrayKey(FILE *stream, const char *key, int *len)
15 + size_t seplen = strlen(ARRAY_DIM_SEP);
16 + const char *keyend = key + strlen(key);
17 + const char *pos = key;
18 + const char *next = key;
19 + const char *sep = "";
27 + next = strstr(pos, ARRAY_DIM_SEP);
32 + if (StringToNumEnd(pos, next, &num)) {
33 + *len += fprintf(stream, "%s%d", sep, num);
35 + *len += fprintf(stream, "%s\"%.*s\"", sep, (int)(next - pos), pos);
39 + pos = next + seplen;
40 + } while (pos < keyend);
44 +static int printDataValue(FILE *stream, DataValue value, int *len,
45 + int first, char **errMsg)
47 +#define cond_fprintf(stream, ...) \
48 + if (stream) *len += fprintf(stream, __VA_ARGS__)
50 + switch (value.tag) {
52 + cond_fprintf(stream, "%d", value.val.n);
56 + /* top level strings should be without "", but strings in array do */
57 + cond_fprintf(stream, "%s", value.val.str.rep);
60 + cond_fprintf(stream, "\"%s\"", value.val.str.rep);
64 + SparseArrayEntry *iter = arrayIterateFirst(&value);
65 + const char *sep = "";
66 + cond_fprintf(stream, "{");
68 + cond_fprintf(stream, "%s[", sep);
69 + printArrayKey(stream, iter->key, len);
70 + cond_fprintf(stream, "]=");
71 + if (!printDataValue(stream, iter->value, len, False, errMsg)) {
74 + iter = arrayIterateNext(iter);
77 + cond_fprintf(stream, "}");
81 + *errMsg = "can't print non-scalar/non-array argument";
90 static int printOut(FILE *stream, WindowInfo *window, DataValue *argList,
91 int nArgs, DataValue *result, char **errMsg)
93 @@ -2654,11 +2731,18 @@ static int printOut(FILE *stream, Window
95 return tooFewArgsErr(errMsg);
98 + /* check arguments */
99 for (i = 0; i < nArgs; i++) {
100 - if (!readStringArg(argList[i], &string, stringStorage, errMsg)) {
101 + if (!printDataValue(NULL, argList[i], NULL, True, errMsg)) {
104 - len += fprintf(stream, "%s%s", sep, string);
107 + /* print arguments */
108 + for (i = 0; i < nArgs; i++) {
109 + len += fprintf(stream, "%s", sep);
110 + printDataValue(stream, argList[i], &len, True, errMsg);