Skip to content

Commit 8d3e132

Browse files
committed
FIX: improved output of the ?? parse command (limited and flattened)
1 parent def430a commit 8d3e132

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/core/a-lib.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ extern int Do_Callback(REBSER *obj, u32 name, RXIARG *args, RXIARG *result);
416416
{
417417
va_list args;
418418
va_start(args, fmt);
419-
Debug_Buf(fmt, args); // Limits line size
419+
Debug_Buf(NO_LIMIT, fmt, args); // Limits line size
420420
va_end(args);
421421
}
422422

src/core/d-print.c

+27-9
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static REBREQ *Req_SIO;
412412
Debug_Space(1);
413413
if (n > 0 && VAL_TYPE(value) <= REB_NONE) Debug_Chars('.', 1);
414414
else {
415-
out = Mold_Print_Value(value, limit, TRUE); // shared mold buffer
415+
out = Mold_Print_Value(value, limit, TRUE, TRUE); // shared mold buffer
416416
for (i1 = i2 = 0; i1 < out->tail; i1++) {
417417
uc = GET_ANY_CHAR(out, i1);
418418
if (uc < ' ') uc = ' ';
@@ -429,7 +429,7 @@ static REBREQ *Req_SIO;
429429

430430
/***********************************************************************
431431
**
432-
*/ void Debug_Buf(const REBYTE *fmt, va_list args)
432+
*/ void Debug_Buf(REBCNT limit, const REBYTE *fmt, va_list args)
433433
/*
434434
** Lower level formatted print for debugging purposes.
435435
**
@@ -457,8 +457,12 @@ static REBREQ *Req_SIO;
457457

458458
RESET_SERIES(buf);
459459

460+
if (limit > SERIES_REST(buf) - 1) {
461+
limit = SERIES_REST(buf) - 1;
462+
}
463+
460464
// Limits output to size of buffer, will not expand it:
461-
bp = Form_Var_Args(STR_HEAD(buf), SERIES_REST(buf)-1, fmt, args);
465+
bp = Form_Var_Args(STR_HEAD(buf), limit, fmt, args);
462466
tail = bp - STR_HEAD(buf);
463467

464468
for (n = 0; n < tail; n += len) {
@@ -473,18 +477,18 @@ static REBREQ *Req_SIO;
473477
**
474478
*/ void Debug_Fmt_(const REBYTE *fmt, ...)
475479
/*
476-
** Print using a format string and variable number
480+
** Print using a formatted string and variable number
477481
** of arguments. All args must be long word aligned
478482
** (no short or char sized values unless recast to long).
479-
** Output will be held in series print buffer and
483+
** Output will be held in a series print buffer and
480484
** will not exceed its max size. No line termination
481485
** is supplied after the print.
482486
**
483487
***********************************************************************/
484488
{
485489
va_list args;
486490
va_start(args, fmt);
487-
Debug_Buf(fmt, args);
491+
Debug_Buf(NO_LIMIT, fmt, args);
488492
va_end(args);
489493
}
490494

@@ -504,7 +508,21 @@ static REBREQ *Req_SIO;
504508
{
505509
va_list args;
506510
va_start(args, fmt);
507-
Debug_Buf(fmt, args);
511+
Debug_Buf(NO_LIMIT, fmt, args);
512+
Debug_Line();
513+
va_end(args);
514+
}
515+
/***********************************************************************
516+
**
517+
*/ void Debug_Fmt_Limited(REBCNT limit, const REBYTE *fmt, ...)
518+
/*
519+
** Same like Debug_Fmt, but limits length of the output.
520+
**
521+
***********************************************************************/
522+
{
523+
va_list args;
524+
va_start(args, fmt);
525+
Debug_Buf(limit, fmt, args);
508526
Debug_Line();
509527
va_end(args);
510528
}
@@ -749,7 +767,7 @@ static REBREQ *Req_SIO;
749767
vp = va_arg(args, REBVAL *);
750768
mold_value:
751769
// Form the REBOL value into a reused buffer:
752-
ser = Mold_Print_Value(vp, 0, desc != 'v');
770+
ser = Mold_Print_Value(vp, max, desc != 'v', TRUE);
753771

754772
l = Length_As_UTF8(UNI_HEAD(ser), SERIES_TAIL(ser), TRUE, OS_CRLF);
755773
if (pad != 1 && l > pad) l = pad;
@@ -809,7 +827,7 @@ static REBREQ *Req_SIO;
809827
**
810828
***********************************************************************/
811829
{
812-
REBSER *out = Mold_Print_Value(value, limit, mold);
830+
REBSER *out = Mold_Print_Value(value, limit, mold, FALSE);
813831
Prin_OS_String(out->data, out->tail, TRUE, err);
814832
}
815833

src/core/s-mold.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
15431543

15441544
/***********************************************************************
15451545
**
1546-
*/ REBSER *Mold_Print_Value(REBVAL *value, REBCNT limit, REBFLG mold)
1546+
*/ REBSER *Mold_Print_Value(REBVAL *value, REBCNT limit, REBFLG mold, REBOOL flat)
15471547
/*
15481548
** Basis function for print. Can do a form or a mold based
15491549
** on the mold flag setting. Can limit string output to a
@@ -1554,6 +1554,7 @@ STOID Mold_Error(REBVAL *value, REB_MOLD *mold, REBFLG molded)
15541554
REB_MOLD mo = {0};
15551555

15561556
Reset_Mold(&mo);
1557+
if(flat) SET_FLAG(mo.opts, MOPT_INDENT);
15571558
mo.limit = limit;
15581559

15591560
Mold_Value(&mo, value, mold);

src/core/u-parse.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct reb_parse {
4848
REBCNT type;
4949
REBCNT flags;
5050
REBINT result;
51-
REBVAL *retval;
51+
// REBVAL *retval;
5252
REB_PARSE_COLLECT *collect;
5353
} REBPARSE;
5454

@@ -87,7 +87,8 @@ void Print_Parse_Index(REBCNT type, REBVAL *rules, REBSER *series, REBCNT index)
8787
REBVAL val;
8888
Set_Series(type, &val, series);
8989
VAL_INDEX(&val) = index;
90-
Debug_Fmt(cb_cast("%r: %r"), rules, &val);
90+
//TODO: use console line width?
91+
Debug_Fmt_Limited(76, cb_cast("%r: %r"), rules, &val);
9192
}
9293

9394

0 commit comments

Comments
 (0)