[master] b93a741f8 vcc: Better format TOSTRANDS() C code

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Dec 3 15:01:07 UTC 2021


commit b93a741f872fc5b2f622233984d494d810c8e431
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Nov 30 11:26:52 2021 +0100

    vcc: Better format TOSTRANDS() C code

diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index dcc0c07c9..bc9864d29 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -148,6 +148,19 @@ vcc_delete_expr(struct expr *e)
  * XXX: check line lengths in edit, should pass indent in for this
  */
 
+static void
+vcc_strands_edit(struct expr *e1, struct expr *e2)
+{
+
+	if (e2->nstr == 1) {
+		VSB_printf(e1->vsb, "TOSTRAND(%s)", VSB_data(e2->vsb));
+		return;
+	}
+
+	VSB_printf(e1->vsb, "TOSTRANDS(%d,\v+\n%s\v-)",
+	    e2->nstr, VSB_data(e2->vsb));
+}
+
 static struct expr *
 vcc_expr_edit(struct vcc *tl, vcc_type_t fmt, const char *p, struct expr *e1,
     struct expr *e2)
@@ -179,9 +192,7 @@ vcc_expr_edit(struct vcc *tl, vcc_type_t fmt, const char *p, struct expr *e1,
 			if (e3->nstr > 1) {
 				VSB_cat(e->vsb,
 				    "\nVRT_STRANDS_string(ctx,\v+\n");
-				VSB_printf(e->vsb,
-				    "TOSTRANDS(%d,%s)",
-				    e3->nstr, VSB_data(e3->vsb));
+				vcc_strands_edit(e, e3);
 				VSB_cat(e->vsb,
 				    "\v-\n)\n");
 			} else {
@@ -192,8 +203,7 @@ vcc_expr_edit(struct vcc *tl, vcc_type_t fmt, const char *p, struct expr *e1,
 		case 't':
 			e3 = (*p == 'T' ? e1 : e2);
 			AN(e3);
-			VSB_printf(e->vsb, "TOSTRANDS(%d,%s)",
-			    e3->nstr, VSB_data(e3->vsb));
+			vcc_strands_edit(e, e3);
 			break;
 		case '1':
 			VSB_cat(e->vsb, VSB_data(e1->vsb));


More information about the varnish-commit mailing list