🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text
Article #7016

Re: Need groff equivalent to C's strlen()

#7016
From: Fred Dalrymple
Date: Fri, 22 May 1992 14:46
35 lines
2055 bytes
In article <honce.706382992@spso> honce@spso.gsfc.nasa.gov (Jhon Honce) writes:
>I'm writing a set of special macros to handle a small data dictionary.
>One of the fields is the number of characters in a keyword.  I thought
>it would be nice to make the computer count this instead of the person
>filling in the form.
>
>This has turned out to be much more painful than I thought and I would
>like some new ideas.  Assuming someone has some to give away.  ;-)
>
>Using the \w function I can get a number that is the numerical width of
>the string in basic units, eg.
>
>	.nr keywrdlen (+\\w'\\$1')


you've got a start on the problem, but now you've got to translate
the widths of a string into a normalized set of units, then divide
the string's width by the width of a single (normalized) character.
Normalized, in this case, can mean "constant width".  So:

.de x
.nr y \\w"\f(CW\\$1\fR"            \" length of string in units
.nr z \\w"\f(CWx\fR"               \" length of a character in units
.nr x \\ny/\\nz                    \" turn into number of characters
.tm the length of "\\$1" is \\nx
..

is a macro that will tell you the character length of its first argument,
so:

.x "this is the beginning of the end"
the length of "this is the beginning of the end" is 32


Fred
Technical Details
Message-ID: <1992May22.144627.10588@osf.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!bu.edu!ai-lab!ai.mit.edu!gnulists
References: <honce.706382992@spso>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 101a3e,76aa88559285e04f
X-Google-Attributes: gid101a3e,public
X-Google-Thread: 10bba1,76aa88559285e04f
X-Google-Attributes: gid10bba1,public
X-Google-ArrivalTime: 1992-05-22 12:48:32 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!bu.edu!ai-lab!ai.mit.edu!gnulists
From: fred@osf.org (Fred Dalrymple)
Newsgroups: comp.text,gnu.groff.bug
Subject: Re: Need groff equivalent to C's strlen()
Keywords: troff
Message-ID: <1992May22.144627.10588@osf.org>
Date: 22 May 92 14:46:27 GMT
References: <honce.706382992@spso>
Followup-To: comp.text,gnu.groff.bug
Organization: Open Software Foundation
Lines: 35
Approved: info-gnu@prep.ai.mit.edu
Apparently-To: gnu-groff-bug@uunet.uu.net