e_print plus arrays
[nedit-bw.git] / print_array.patch
blobddab0cef6d3592cbe2a6d33410a0127ae7d288a6
1 ---
3 source/macro.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
4 1 file changed, 51 insertions(+), 2 deletions(-)
6 diff --quilt old/source/macro.c new/source/macro.c
7 --- old/source/macro.c
8 +++ new/source/macro.c
9 @@ -2644,6 +2644,48 @@ static int beepMS(WindowInfo *window, Da
10 return True;
13 +static int printDataValue(FILE *stream, DataValue value, int *len, char **errMsg)
15 +#define cond_fprintf(stream, ...) \
16 + if (stream) *len += fprintf(stream, __VA_ARGS__)
18 + switch (value.tag) {
19 + case INT_TAG:
20 + cond_fprintf(stream, "%d", value.val.n);
21 + break;
22 + case STRING_TAG:
23 + cond_fprintf(stream, "%s", value.val.str.rep);
24 + break;
25 + case ARRAY_TAG: {
26 + SparseArrayEntry *iter = arrayIterateFirst(&value);
27 + const char *sep = "";
28 + cond_fprintf(stream, "{ ");
29 + while (iter) {
30 + int num;
31 + if (StringToNum(iter->key, &num)) {
32 + cond_fprintf(stream, "%s[%d] = ", sep, num);
33 + } else {
34 + cond_fprintf(stream, "%s[\"%s\"] = ", sep, iter->key);
35 + }
36 + if (!printDataValue(stream, iter->value, len, errMsg)) {
37 + return False;
38 + }
39 + iter = arrayIterateNext(iter);
40 + sep = ", ";
41 + }
42 + cond_fprintf(stream, " }");
43 + }
44 + break;
45 + default:
46 + *errMsg = "can't print non-scalar/non-array argument";
47 + return False;
48 + }
50 + return True;
52 +#undef cond_fprintf
55 static int printOut(FILE *stream, WindowInfo *window, DataValue *argList,
56 int nArgs, DataValue *result, char **errMsg)
58 @@ -2654,11 +2696,18 @@ static int printOut(FILE *stream, Window
59 if (nArgs == 0) {
60 return tooFewArgsErr(errMsg);
63 + /* check arguments */
64 for (i = 0; i < nArgs; i++) {
65 - if (!readStringArg(argList[i], &string, stringStorage, errMsg)) {
66 + if (!printDataValue(NULL, argList[i], NULL, errMsg)) {
67 return False;
69 - len += fprintf(stream, "%s%s", sep, string);
70 + }
72 + /* print arguments */
73 + for (i = 0; i < nArgs; i++) {
74 + len += fprintf(stream, "%s", sep);
75 + printDataValue(stream, argList[i], &len, errMsg);
76 sep = " ";
78 fflush(stream);