groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] Is it possible to split macro arguments?


From: Ted Harding
Subject: Re: [Groff] Is it possible to split macro arguments?
Date: Sat, 02 Jul 2011 15:40:31 +0100 (BST)

On 02-Jul-11 13:55:10, erich hoffmann wrote:
> Hello.
> I googled and tried a lot for this question, found nothing,
> I think that what I want is not possible - so I'm asking here
> to make sure that I am not missing something. - For a special
> text, a sort of notation of chords for the accordion, I want
> a macro roughly like this:
> 
> .de ch
> \\$1\d\s-8\\$2\s0\r\\$3\u\s-8\v´+2´\\$4\s0
> ..
> 
> So that I can write
> 
> .ch A 4 a7 2
> 
> to get the result, and this works perfectly.
> 
> Is it possible to split arguments into single characters so that I
> could
> write
> 
> .ch A4a72
> 
> and get the same result, like with the split() function in perl or awk?
> 
> TIA,
> Erich

There is the request .substring which you could use to perform
such operations, provided you write the macro in terms of known
lengths/positions of substrings:

- Request: .substring str n1 [n2]
  Replace the string named STR with the substring defined by the
  indices N1 and N2.  The first character in the string has index 0.
  If N2 is omitted, it is taken to be equal to the string's length.
  If the index value N1 or N2 is negative, it is counted from the
  end of the string, going backwards: The last character has
  index -1, the character before the last character has index -2,
  etc.

    .ds xxx abcdefgh
    .substring xxx 1 -4
    \*[xxx]
    => bcde

So, applied to A4a72,

.ds res1 A4a72
.substring res1 0 0
.ds res2 A4a72
.substring res2 1 1
.ds res3 A4a72
.substring res3 2 3
.ds res4 A4a72
.substring res4 4 4

would give res1 = A, res2 = 4, res3 = a7, res4 = 2.

Does this help?

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 02-Jul-11                                       Time: 15:40:28
------------------------------ XFMail ------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]