Fossil SCM

Adjust the "lndebug()" macro in linenoise so that it works on older compilers that do not support varargs macros.

drh 2015-07-25 14:53 trunk
Commit acab077c4cbcba28f8788d80c9335ce0e403c857
1 file changed +7 -7
+7 -7
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176176
static void refreshLine(struct linenoiseState *l);
177177
178178
/* Debugging macro. */
179179
#if 0
180180
FILE *lndebug_fp = NULL;
181
-#define lndebug(...) \
181
+#define lndebug(fmt, arg1) \
182182
do { \
183183
if (lndebug_fp == NULL) { \
184184
lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185185
fprintf(lndebug_fp, \
186186
"[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187187
(int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188188
(int)l->maxrows,old_rows); \
189189
} \
190
- fprintf(lndebug_fp, ", " __VA_ARGS__); \
190
+ fprintf(lndebug_fp, ", " fmt, arg1); \
191191
fflush(lndebug_fp); \
192192
} while (0)
193193
#else
194
-#define lndebug(fmt, ...)
194
+#define lndebug(fmt, arg1)
195195
#endif
196196
197197
/* ======================= Low level terminal handling ====================== */
198198
199199
/* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526526
abAppend(&ab,seq,strlen(seq));
527527
}
528528
529529
/* Now for every row clear it, go up. */
530530
for (j = 0; j < old_rows-1; j++) {
531
- lndebug("clear+up");
531
+ lndebug("clear+up", 0);
532532
snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533533
abAppend(&ab,seq,strlen(seq));
534534
}
535535
536536
/* Clean the top line. */
537
- lndebug("clear");
537
+ lndebug("clear", 0);
538538
snprintf(seq,64,"\r\x1b[0K");
539539
abAppend(&ab,seq,strlen(seq));
540540
541541
/* Write the prompt and the current buffer content */
542542
abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546546
* emit a newline and move the prompt to the first column. */
547547
if (l->pos &&
548548
l->pos == l->len &&
549549
(l->pos+plen) % l->cols == 0)
550550
{
551
- lndebug("<newline>");
551
+ lndebug("<newline>", 0);
552552
abAppend(&ab,"\n",1);
553553
snprintf(seq,64,"\r");
554554
abAppend(&ab,seq,strlen(seq));
555555
rows++;
556556
if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574574
snprintf(seq,64,"\r\x1b[%dC", col);
575575
else
576576
snprintf(seq,64,"\r");
577577
abAppend(&ab,seq,strlen(seq));
578578
579
- lndebug("\n");
579
+ lndebug("\n", 0);
580580
l->oldpos = l->pos;
581581
582582
if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583583
abFree(&ab);
584584
}
585585
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176 static void refreshLine(struct linenoiseState *l);
177
178 /* Debugging macro. */
179 #if 0
180 FILE *lndebug_fp = NULL;
181 #define lndebug(...) \
182 do { \
183 if (lndebug_fp == NULL) { \
184 lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185 fprintf(lndebug_fp, \
186 "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187 (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188 (int)l->maxrows,old_rows); \
189 } \
190 fprintf(lndebug_fp, ", " __VA_ARGS__); \
191 fflush(lndebug_fp); \
192 } while (0)
193 #else
194 #define lndebug(fmt, ...)
195 #endif
196
197 /* ======================= Low level terminal handling ====================== */
198
199 /* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526 abAppend(&ab,seq,strlen(seq));
527 }
528
529 /* Now for every row clear it, go up. */
530 for (j = 0; j < old_rows-1; j++) {
531 lndebug("clear+up");
532 snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533 abAppend(&ab,seq,strlen(seq));
534 }
535
536 /* Clean the top line. */
537 lndebug("clear");
538 snprintf(seq,64,"\r\x1b[0K");
539 abAppend(&ab,seq,strlen(seq));
540
541 /* Write the prompt and the current buffer content */
542 abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546 * emit a newline and move the prompt to the first column. */
547 if (l->pos &&
548 l->pos == l->len &&
549 (l->pos+plen) % l->cols == 0)
550 {
551 lndebug("<newline>");
552 abAppend(&ab,"\n",1);
553 snprintf(seq,64,"\r");
554 abAppend(&ab,seq,strlen(seq));
555 rows++;
556 if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574 snprintf(seq,64,"\r\x1b[%dC", col);
575 else
576 snprintf(seq,64,"\r");
577 abAppend(&ab,seq,strlen(seq));
578
579 lndebug("\n");
580 l->oldpos = l->pos;
581
582 if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583 abFree(&ab);
584 }
585
--- src/linenoise.c
+++ src/linenoise.c
@@ -176,24 +176,24 @@
176 static void refreshLine(struct linenoiseState *l);
177
178 /* Debugging macro. */
179 #if 0
180 FILE *lndebug_fp = NULL;
181 #define lndebug(fmt, arg1) \
182 do { \
183 if (lndebug_fp == NULL) { \
184 lndebug_fp = fopen("/tmp/lndebug.txt","a"); \
185 fprintf(lndebug_fp, \
186 "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
187 (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
188 (int)l->maxrows,old_rows); \
189 } \
190 fprintf(lndebug_fp, ", " fmt, arg1); \
191 fflush(lndebug_fp); \
192 } while (0)
193 #else
194 #define lndebug(fmt, arg1)
195 #endif
196
197 /* ======================= Low level terminal handling ====================== */
198
199 /* Set if to use or not the multi line mode. */
@@ -526,17 +526,17 @@
526 abAppend(&ab,seq,strlen(seq));
527 }
528
529 /* Now for every row clear it, go up. */
530 for (j = 0; j < old_rows-1; j++) {
531 lndebug("clear+up", 0);
532 snprintf(seq,64,"\r\x1b[0K\x1b[1A");
533 abAppend(&ab,seq,strlen(seq));
534 }
535
536 /* Clean the top line. */
537 lndebug("clear", 0);
538 snprintf(seq,64,"\r\x1b[0K");
539 abAppend(&ab,seq,strlen(seq));
540
541 /* Write the prompt and the current buffer content */
542 abAppend(&ab,l->prompt,strlen(l->prompt));
@@ -546,11 +546,11 @@
546 * emit a newline and move the prompt to the first column. */
547 if (l->pos &&
548 l->pos == l->len &&
549 (l->pos+plen) % l->cols == 0)
550 {
551 lndebug("<newline>", 0);
552 abAppend(&ab,"\n",1);
553 snprintf(seq,64,"\r");
554 abAppend(&ab,seq,strlen(seq));
555 rows++;
556 if (rows > (int)l->maxrows) l->maxrows = rows;
@@ -574,11 +574,11 @@
574 snprintf(seq,64,"\r\x1b[%dC", col);
575 else
576 snprintf(seq,64,"\r");
577 abAppend(&ab,seq,strlen(seq));
578
579 lndebug("\n", 0);
580 l->oldpos = l->pos;
581
582 if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
583 abFree(&ab);
584 }
585

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button