fix motifless build, keep original LIBS variable
[nedit-bw.git] / print-array.patch
blob1e2b99167da27c313981c43a044ec9b44c7b1a02
1 ---
3 source/macro.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
4 1 file changed, 86 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,83 @@ static int beepMS(WindowInfo *window, Da
10 return True;
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 = "";
20 + int num;
22 + if (!stream) {
23 + return;
24 + }
26 + do {
27 + next = strstr(pos, ARRAY_DIM_SEP);
28 + if (!next) {
29 + next = keyend;
30 + }
32 + if (StringToNumEnd(pos, next, &num)) {
33 + *len += fprintf(stream, "%s%d", sep, num);
34 + } else {
35 + *len += fprintf(stream, "%s\"%.*s\"", sep, (int)(next - pos), pos);
36 + }
38 + sep = ",";
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) {
51 + case INT_TAG:
52 + cond_fprintf(stream, "%d", value.val.n);
53 + break;
54 + case STRING_TAG:
55 + if (first) {
56 + /* top level strings should be without "", but strings in array do */
57 + cond_fprintf(stream, "%s", value.val.str.rep);
58 + }
59 + else {
60 + cond_fprintf(stream, "\"%s\"", value.val.str.rep);
61 + }
62 + break;
63 + case ARRAY_TAG: {
64 + SparseArrayEntry *iter = arrayIterateFirst(&value);
65 + const char *sep = "";
66 + cond_fprintf(stream, "{");
67 + while (iter) {
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)) {
72 + return False;
73 + }
74 + iter = arrayIterateNext(iter);
75 + sep = ",";
76 + }
77 + cond_fprintf(stream, "}");
78 + }
79 + break;
80 + default:
81 + *errMsg = "can't print non-scalar/non-array argument";
82 + return False;
83 + }
85 + return True;
87 +#undef cond_fprintf
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
94 if (nArgs == 0) {
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)) {
102 return False;
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);
111 sep = " ";
113 fflush(stream);