Macros attached.

On Wed, 23 Jun 2021 21:26:23 +0100
"Denis M. Wilson" <d...@oxytropis.plus.com> wrote:

> I have macros corresponding to Cs strchr and strrchr functions.
> Do you want me to pass them on?
> 
> Denis
> 
> On Wed, 23 Jun 2021 21:48:48 +0200
> Wim Stockman <wim.stock...@gmail.com> wrote:
> 
> > Is there a function in groff to find the position of a char in a
> > string. So I can split a string into more than one.
> > I found the substring function that can cut based on length. If I
> > could my marker in the string I could cut it there.
> > 
> > Kind regards,
> > Wim Stockman  
> 
> 


-- 
\# .----------------------------.
\# |                            |
\# |  strchr reg string char    |
\# |  ------ --- ------ ----    |
\# |                            |
\# |  strrchr reg string char   |
\# |  ------- --- ------ ----   |
\# |                            |
\# `----------------------------'
.
\# Position of characters in strings
.
\# .strchr reg string char
\# defines the number register to be the first position in
\# string of the character CW char, or \-1 if the character
\# does not occur in the string.
\#Strings are indexed from 0.
.
\# .strrchr reg string char
\# defines the number register to be the last position in
\# string of the character char, or \-1 if the character
\# does not occur in the string.
.
.eo
.de strchr
.nr \$[1] 0-1
.length str-len \$[2]
.nr str-i 0-1 1
.while \n+[str-i]<\n[str-len] \{\
.       ds str-tmp \$[2]
.       substring str-tmp \n[str-i] \n[str-i]
.       if \[str]\*[str-tmp]\[str]\$[3]\[str] \{\
.               nr \$[1] \n[str-i]
.               break
.       \}
.\}
..
.
.de strrchr
.nr \$[1] 0-1
.length str-len \$[2]
.nr str-i \n[str-len] -1
.while \n+[str-i]>=0 \{\
.       ds str-tmp \$[2]
.       substring str-tmp \n[str-i] \n[str-i]
.       if \[str]\*[str-tmp]\[str]\$[3]\[str] \{\
.               nr \$[1] \n[str-i]
.               break
.       \}
.\}
..
.ec

Reply via email to