.ig Copyright 2006-2010 Free Software Foundation, Inc. Written by Joachim Walsdorff Enhanced by Werner Lemberg This file is part of hdtbl. hdtbl is distributed with groff, the GNU roff typesetting system. groff is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. groff is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . .. . . .if d t*getarg \ . nx . . .\" ****************************************************************** .\" ** Some macros and default settings needed by hdtbl ** .\" ****************************************************************** . . .\" Utility macro: .getarg ... .\" .\" Get macro argument. This macro searches in the .\" remaining arguments and assigns its value to a string .\" register named . The following syntax forms are .\" recognized. .\" .\" = Assign to string . .\" must not contain spaces. .\" ='' Assign to string . .\" can contain spaces. .\" = Assign '=' to string . .\" Assign 'key' to string . .\" .\" After return, the string 'args' contains the remaining .\" arguments. .\" .\" Example: With the definition of string 'foo' as .\" .\" .ds foo aaa=xxx bbb ccc='yyy zzz' ddd= eee .\" .\" a call to 'getarg' with .\" .\" .getarg ccc \*[foo] .\" .\" sets string 'ccc' to value 'yyy zzz'. The string 'args' .\" now contains 'aaa=xxx bbb ddd= eee'. An additional call .\" like .\" .\" .getarg ddd \*[args] .\" .\" sets string 'ddd' to value '=', and 'args' contains .\" 'aaa=xxx bbb eee'. .de t*getarg . ds \\$1 . ds args . . if (\\n[.$] < 2) \ . return . . ds $1 \\$1\" . shift . . length * \\*[$1] . while \\n[.$] \{\ . ds * "\\$1\" . ds ** "\\$1\" . length ** \\*[**] . shift . if (\\n[*] > \\n[**]) \{\ . as args " "\\*[**]"\" value too short, repeat . continue . \} . substring * 0 (\\n[*] - 1) . \" The surrounding \? escapes emulate string comparison. . ie !"\?\\*[$1]\?"\?\\*[*]\?" \{\ . as args " "\\*[**]"\" key not found, repeat . continue . \} . el \{\ . ie "\?\\*[**]\?"\?\\*[$1]\?" \ . ds \\*[$1] \\*[$1]\" return key as string . el \{\ . ie "\?\\*[**]\?"\?\\*[$1]=\?" \ . ds \\*[$1] =\" return '=' . el \{\ . substring ** (\\n[*] + 1) -1 . ds * \\*[**]\" . substring * 0 0 . . \" check whether value starts with quote . if "\?\\*[*]\?"\?'\?" \{\ . substring ** 1 -1 . ds * \\*[**]\" . substring * -1 -1 . . \" search final quote . ie "\?\\*[*]\?"\?'\?" \ . substring ** 0 -2 . el \{\ . as \\*[$1] \\*[**] \" not found, append argument . . while 1 \{\ . ds ** \\$1\" get next argument . ds * \\$1\" . shift . substring * -1 -1 . . if "\?\\*[*]\?"\?'\?" \{\ . substring ** 0 -2 . break \" break if no final quote . \} . . as \\*[$1] \\*[**] \" otherwise append and repeat . \} . \}\} . . as \\*[$1] \\*[**]\" . \} . . as args " \\$@\" . \}\} . . return . \} .. . . .\" Utility macro: .index .\" .\" Check whether is a substring of and .\" return its position in number register 't*index', starting .\" with 1. If not found, return 0. If is empty, .\" set 't*index' to -999. .de t*index . if "\\$2"" \{\ . nr t*index -999 . return . \} . . length ** \\$1\& . length $2 \\$2 . nr * 0-1 1 . . while (\\n+[*] < \\n[**]) \{\ . ds * \\$1\&\" . substring * \\n[*] (\\n[*]