Server IP : 195.201.23.43 / Your IP : 18.217.163.75 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/groff/html/ |
Upload File : |
<!-- Creator : groff version 1.22.4 --> <!-- CreationDate: Sat Mar 21 12:27:30 2020 --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta name="generator" content="groff -Thtml, see www.gnu.org"> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <meta name="Content-Style" content="text/css"> <style type="text/css"> p { margin-top: 0; margin-bottom: 0; vertical-align: top } pre { margin-top: 0; margin-bottom: 0; vertical-align: top } table { margin-top: 0; margin-bottom: 0; vertical-align: top } h1 { text-align: center } </style> <title>pic-14.html</title> </head> <hr> [ <a href="pic-13.html">prev</a> | <a href="pic-15.html">next</a> | <a href="pic.html">top</a> ] <hr> <h2>14. Macros <a name="14. Macros"></a> </h2> <p style="margin-top: 1em"><font color="#000000">You can define macros in <b>pic</b>, with up to 32 arguments (up to 16 on EBCDIC platforms). This is useful for diagrams with repetitive parts. In conjunction with the scope rules for block composites, it effectively gives you the ability to write functions.</font></p> <p style="margin-top: 1em"><font color="#000000">The syntax is</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><b>define</b> <i>name</i> <b>{</b> <i>replacement text</i> <b>}</b></font></p> <p style="margin-top: 1em"><font color="#000000">This defines <i>name</i> as a macro to be replaced by the replacement text (not including the braces). The macro may be called as</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><i>name</i><b>(</b><i>arg1, arg2, ... argn</i><b>)</b></font></p> <p style="margin-top: 1em"><font color="#000000">The arguments (if any) are substituted for tokens <b>$1</b>, <b>$2</b> ... <b>$n</b> appearing in the replacement text.</font></p> <p style="margin-top: 1em"><font color="#000000">As an example of macro use, consider this:</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small>.PS <br> # Plot a single jumper in a box, $1 is the on-off state. <br> define jumper { [ <br> shrinkfactor = 0.8; <br> Outer: box invis wid 0.45 ht 1;</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small># Count on end ] to reset these <br> boxwid = Outer.wid * shrinkfactor / 2; <br> boxht = Outer.ht * shrinkfactor / 2;</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small>box fill (!$1) with .s at center of Outer; <br> box fill ($1) with .n at center of Outer; <br> ] }</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small># Plot a block of six jumpers. <br> define jumperblock { <br> jumper($1); <br> jumper($2); <br> jumper($3); <br> jumper($4); <br> jumper($5); <br> jumper($6);</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small>jwidth = last [].Outer.wid; <br> jheight = last [].Outer.ht;</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small>box with .nw at 6th last [].nw wid 6*jwidth ht jheight;</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small># Use {} to avoid changing position from last box draw. <br> # This is necessary so move in any direction works as expected <br> {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0,-0.2);} <br> }</small></font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000"><small># Sample macro invocations. <br> jumperblock(1,1,0,0,1,0); <br> move; <br> jumperblock(1,0,1,0,1,1); <br> .PE</small></font></p> <p style="margin-top: 1em"><font color="#000000">It yields the following:</font></p> <p align="center" style="margin-top: 1em"><font color="#000000"><img src="img/pic44.png" alt="Image img/pic44.png"></font></p> <p align="center" style="margin-top: 1em"><font color="#000000">Figure 14-1: Sample use of a macro</font></p> <p style="margin-top: 1em"><font color="#000000">This macro example illustrates how you can combine [], brace grouping, and variable assignment to write true functions.</font></p> <p style="margin-top: 1em"><font color="#000000">One detail the example above does not illustrate is the fact that macro argument parsing is not token-oriented. If you call <b>jumper( 1 )</b>, the value of $1 is <b>" 1 "</b>. You could even call <b>jumper(big string)</b> to give $1 the value <b>"big string"</b>.</font></p> <p style="margin-top: 1em"><font color="#000000">If you want to pass in a coordinate pair, you can avoid getting tripped up by the comma by wrapping the pair in parentheses.</font></p> <p style="margin-top: 1em"><font color="#000000">Macros persist through pictures. To undefine a macro, say <b>undef</b> <i>name</i>; for example,</font></p> <p style="margin-left:10%; margin-top: 1em"><font color="#000000">undef jumper <br> undef jumperblock</font></p> <p style="margin-top: 1em"><font color="#000000">would undefine the two macros in the jumper block example.</font></p> <hr> [ <a href="pic-13.html">prev</a> | <a href="pic-15.html">next</a> | <a href="pic.html">top</a> ] <hr>Private