From: op Date: Fri, 21 Apr 2023 14:14:13 +0000 (+0000) Subject: mg: fix space_to_tabstop X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e86ce36f439bb0682f7641cad7ef753088587eb1;p=openbsd mg: fix space_to_tabstop Since the import of mg in the tree, space_to_tabstop used curbp->w_doto (the byte offset in the current line) as mean to deduce the current column for indentation. This is wrong because it doesn't account for tab, control characters and octets > 127 (which are all rendered with more than one column.) Use instead getcolpos(). ok tb@ --- diff --git a/usr.bin/mg/util.c b/usr.bin/mg/util.c index 6168f51144b..acb3714b28d 100644 --- a/usr.bin/mg/util.c +++ b/usr.bin/mg/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.48 2023/04/21 13:39:37 op Exp $ */ +/* $OpenBSD: util.c,v 1.49 2023/04/21 14:14:13 op Exp $ */ /* This file is in the public domain. */ @@ -482,17 +482,17 @@ backdel(int f, int n) int space_to_tabstop(int f, int n) { - int c; + int col, target; if (n < 0) return (FALSE); if (n == 0) return (TRUE); - c = curwp->w_doto; + col = target = getcolpos(curwp); while (n-- > 0) - c = ntabstop(c, curbp->b_tabw); - return (linsert(c - curwp->w_doto, ' ')); + target = ntabstop(target, curbp->b_tabw); + return (linsert(target - col, ' ')); } /*