Check-in by ben on 2025-11-12 15:55:27

Merge info_wrap() and print_wrap() into a single function wrap()

 INSERTED    DELETED
       44         57 coprolit.awk
       44         57 TOTAL over 1 changed file

Index: coprolit.awk
==================================================================
--- coprolit.awk
+++ coprolit.awk
@@ -177,11 +177,11 @@
            file = sprintf("%s/patch/%s.txt", _work, commit)
            printf "%s\n\n", type >file
            if (length(comment) < 66) {
                println(file, comment)
            } else {
-                print_wrap(file, comment, 65)
+                wrap("print", file, comment, 65)
            }
            printf "\n" >>file
            close(file)

            cmd = sprintf("fossil diff -v --checkin %s --numstat -R %s >>%s",
@@ -207,11 +207,11 @@
    info(out, "")
    if (length(comment) < 66) {
        info(out, sprintf("Comment:     %s", comment))
    } else {
        info(out, "Comment:")
-        info_wrap(out, comment, 65)
+        wrap("info", out, comment, 65)
    }
    if (is_checkin && has_downloads) {
        info(out, "")
        info(out, "Downloads:")
        slug = sprintf("%s/tarball/%s/%s-%s.tar.gz",
@@ -447,11 +447,11 @@
    printf "Ticket Hash: %s\n", uuid >>out
    if (length(title) < 66) {
        printf "Title:       %s\n", title >>out
    } else {
        printf "Title:\n" >>out
-        print_wrap(out, title, 65)
+        wrap("print", out, title, 65)
    }
    printf "Status:      %s\n", status >>out
    printf "Type:        %s\n", type >>out
    printf "Severity:    %s\n", severity >>out
    printf "Priority:    %s\n", priority >>out
@@ -529,11 +529,11 @@
             info(out, "Status: " $field["status"])
             if (length($field["title"]) < 61) {
                 info(out, "Title:  " $field["title"])
             } else {
                 info(out, "Title:")
-                 info_wrap(out, $field["title"], 65)
+                 wrap("info", out, $field["title"], 65)
             }
             info(out, "")
             generate_ticket(ticket,
                 $field["ctime"],
                 $field["foundin"],
@@ -742,36 +742,10 @@
        printf "i%s\tErr\t%s\t%s\r\n", str, _server, _port >>out
    }
    return
}

-# info_wrap() will break long lines into line continuations
-
-function info_wrap(out, str, len) {
-    line = 1
-    buf = str
-    while (length(buf) > len) {
-        chunk = substr(buf, 1, len)
-        if (match(chunk, / [^ ]*$/)) {
-            before = substr(buf, 1, RSTART-1)
-            after = substr(buf, RSTART+1)
-            info(out, "  " before)
-            buf = after
-        } else if (match(chunk, /-[^-]*$/)) {
-            before = substr(buf, 1, RSTART)
-            after = substr(buf, RSTART+1)
-            info(out, "  " before)
-            buf = after
-        } else {
-            break
-        }
-        line++
-    }
-    info(out, "  " buf)
-    return
-}
-
function item(out, type, label, sel, host, port,     line) {
    line = item_str(type, label, sel, host, port)
    if (length(out) == 0) {
        printf "%s\r\n", line
    } else {
@@ -901,36 +875,10 @@
        print str >>out
    }
    return
}

-# print_wrap() will break long lines into line continuations
-
-function print_wrap(out, str, len) {
-    line = 1
-    buf = str
-    while (length(buf) > len) {
-        chunk = substr(buf, 1, len)
-        if (match(chunk, / [^ ]*$/)) {
-            before = substr(buf, 1, RSTART-1)
-            after = substr(buf, RSTART+1)
-            println(out, "  " before)
-            buf = after
-        } else if (match(chunk, /-[^-]*$/)) {
-            before = substr(buf, 1, RSTART)
-            after = substr(buf, RSTART+1)
-            println(out, "  " before)
-            buf = after
-        } else {
-            break
-        }
-        line++
-    }
-    println(out, "  " buf)
-    return
-}
-
function quit_if_uptodate(workdir,     cmd, path) {
    cmd = "fossil timeline -n 1 --oneline -R " _repo
    if ((cmd | getline) > 0) {
        path = workdir "/info/" $1
        if (exists(path "/gophermap") || exists(path "/index.gph")) {
@@ -946,11 +894,11 @@
    info(out, "")
    info(out, "# Reference")
    info(out, "")
    for (i = 1; i <= refs["count"]; i++) {
        if (length(refs[i]) > 65) {
-            info_wrap(out, refs[i], 65)
+            wrap("info", out, refs[i], 65)
        } else {
            info(out, refs[i])
        }
    }
    return
@@ -986,9 +934,48 @@
    print "--timeline (default: 100)"
    print "  limit number of items in timeline, 0 = unlimited"
    print ""
    return
}
+
+# wrap() will break long lines into line continuations
+
+function wrap(which, out, str, len) {
+    line = 1
+    buf = str
+    while (length(buf) > len) {
+        chunk = substr(buf, 1, len)
+        if (match(chunk, / [^ ]*$/)) {
+            before = substr(buf, 1, RSTART-1)
+            after = substr(buf, RSTART+1)
+            if (which == "info") {
+                info(out, "  " before)
+            } else {
+                println(out, "  " before)
+            }
+            buf = after
+        } else if (match(chunk, /-[^-]*$/)) {
+            before = substr(buf, 1, RSTART)
+            after = substr(buf, RSTART+1)
+            if (which == "info") {
+                info(out, "  " before)
+            } else {
+                println(out, "  " before)
+            }
+            buf = after
+        } else {
+            break
+        }
+        line++
+    }
+    if (which == "info") {
+        info(out, "  " buf)
+    } else {
+        println(out, "  " buf)
+    }
+    return
+}
+

BEGIN {
    main()
}