macros.pic 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. .PS
  2. # 02Mar97: Cleaned up this file. Removed a bunch of the tcpipiv2-only
  3. # macros, and deleted those that were never used.
  4. #
  5. # This file defines the handy macros used in the document.
  6. #
  7. arrowwid = 0.0625 # This divisible by 2 (0.03125) has to be a "perfect"
  8. # size for ditroff. This value is OK for TranScript on
  9. # on the LaserWriter (576 units/inch).
  10. #arrowht = 0.125
  11. arrowht = 0.09375
  12. #arrowht = 0.0625
  13. dash_off = 0.2 # default
  14. gap_down = 0.12 # default downward distance in timeline gap
  15. gap_side = 0.04 # default sidewards distance in timeline gap
  16. basef = .375
  17. maxwid = 5.416666
  18. unusedfill = .1 # unused portions of structures
  19. cbase = .256
  20. cindent = .275
  21. v6_hash = 0.06
  22. # Just remove "invis" to see the boxes
  23. define ibox { box invis }
  24. # Client double arrow (left to right on top, right to left below)
  25. define Carrow {
  26. arrow -> right 0.15 from $1 + (-0.15/2, 0.04) wid 0.03 ht 0.05
  27. arrow <- right 0.15 from $1 + (-0.15/2, -0.04) wid 0.03 ht 0.05
  28. }
  29. # Server double arrow (right to left on top, left to right below)
  30. define Sarrow {
  31. arrow <- right 0.15 from $1 + (-0.15/2, 0.04) wid 0.03 ht 0.05
  32. arrow -> right 0.15 from $1 + (-0.15/2, -0.04) wid 0.03 ht 0.05
  33. }
  34. # Right arrow
  35. define Rarrow {
  36. arrow -> right 0.15 from $1 + (-0.15/2, 0.00) wid 0.03 ht 0.05
  37. }
  38. # Left arrow
  39. define Larrow {
  40. arrow <- right 0.15 from $1 + (-0.15/2, 0.00) wid 0.03 ht 0.05
  41. }
  42. #
  43. # flowdef( <scale> )
  44. # set up default for data flow pictures
  45. define flowdef X
  46. boxht = 0.2*$1
  47. boxwid = 0.8*$1
  48. ellipsewid = boxwid
  49. ellipseht = boxht*1.5
  50. .ps 8
  51. .vs 10
  52. X
  53. #
  54. # memdef( <maxbytes>, <x-scale>, <y-scale>)
  55. # set up default for memory layout pictures
  56. define memdef X
  57. boxht = .3*$3
  58. boxwid = (.95*maxwid)/$1*$2
  59. boff = boxwid/(2*$1)
  60. poff = boxht*.25
  61. arrowht = .09375*.8
  62. arrowwid = 0.0625*.8
  63. labelspace=.4 # used in by field2_a functions
  64. .ps 8
  65. .vs 10
  66. X
  67. #
  68. # dsdef
  69. # setup defaults for data structure pictures
  70. define dsdef X
  71. boxht = 0.15
  72. boxwid = boxht*6
  73. myboxrad = boxht/4
  74. ellipsewid = boxwid
  75. ellipseht = boxht*1.5
  76. arrowwid = 0.0625*.75
  77. arrowht = 0.09375*.75
  78. poff = .5*boxht
  79. # ellipse offset
  80. eoff = .5*poff
  81. .ps 8
  82. .vs 9
  83. X
  84. #
  85. # text_span ( <left-corner>, <right-corner>, <text>, <text-wid>,
  86. # <height-of-text-above-corners> )
  87. #
  88. # For normal text, <height...> should be 0.15.
  89. #
  90. define text_span X
  91. Lab001: $3 at 1/2 <$1, $2> + (0, $5)
  92. arrow from Lab001.c + (- $4/2, 0) to $1 + (0, $5)
  93. arrow from Lab001.c + ( $4/2, 0) to $2 + (0, $5)
  94. X
  95. #
  96. # solid_box ( <sw-posn>, <ne-posn> )
  97. #
  98. # Draw a solid box, given 2 opposite corner positions.
  99. # Note - unlike the dash_box macro below, we draw the box exactly from
  100. # from the points specified - we don't offset the box by 0.2i from
  101. # the given coordinates.
  102. # The box is drawn in the order of the arguments, so that the command
  103. # "... at last line.c below" will be positioned at the line from the
  104. # se-posn to the sw-posn.
  105. #
  106. define solid_box X
  107. S0001: $1
  108. S0002: $2
  109. line from S0001 to (S0001.x, S0002.y)
  110. line from last line.end to S0002
  111. line from last line.end to (S0002.x, S0001.y)
  112. line from last line.end to S0001
  113. X
  114. #
  115. # dash_box ( <sw-posn>, <ne-posn> [ , <optional-dash-length> ] )
  116. #
  117. # Draw a dashed box, given the 2 opposite corner positions.
  118. # The box is drawn in the order of the arguments, so that the command
  119. # "... at last line.c below" will be positioned at the line from the
  120. # se-posn to the sw-posn.
  121. #
  122. # Caller can set "dash_off = <value>" to change the default of 0.2 inches
  123. # from all sides. This has to be done before each call to the macro,
  124. # as we reset it after each call.
  125. #
  126. # The <optional-dash-length> specifies the length of each dash and the
  127. # length of the space between each dash. The default is 0.05.
  128. # Note this feature uses pic's substitution of the null string for any
  129. # missing arguments in a macro call.
  130. #
  131. define dash_box X
  132. S001: $1
  133. S002: $2
  134. line dashed $3 from S001 + (-dash_off, -dash_off) to \
  135. (S001.x, S002.y) + (-dash_off, dash_off)
  136. line dashed $3 from last line.end to \
  137. S002 + (dash_off, dash_off)
  138. line dashed $3 from last line.end to \
  139. (S002.x, S001.y) + (dash_off, -dash_off)
  140. line dashed $3 from last line.end to \
  141. S001 + (-dash_off, -dash_off)
  142. dash_off = 0.2 # reset default
  143. X
  144. #
  145. # left_brace ( <top>, <bottom> )
  146. #
  147. define left_brace X
  148. LB1: $1
  149. LB2: $2
  150. arc from LB1 + (-0.09375, 0.00) to LB1 + (-0.15625, -0.0625) rad 0.0625
  151. line down (((LB1.y - LB2.y) - 0.125) / 2) - 0.03125
  152. line down 0.03125 left 0.03125
  153. Bracept:line right 0.03125 down 0.03125
  154. line to LB2 + (-0.15625, 0.0625)
  155. arc from last line.end to LB2 + (-0.09375, 0.00) rad 0.0625
  156. X
  157. #
  158. # right_brace ( <top>, <bottom> )
  159. #
  160. define right_brace X
  161. RB1: $1
  162. RB2: $2
  163. arc cw from RB1 + (0.09375, 0.00) to RB1 + (0.15625, -0.0625) rad 0.0625
  164. line down (((RB1.y - RB2.y) - 0.125) / 2) - 0.03125
  165. line down 0.03125 right 0.03125
  166. Bracept:line left 0.03125 down 0.03125
  167. line to RB2 + (0.15625, 0.0625)
  168. arc cw from last line.end to RB2 + (0.09375, 0.00) rad 0.0625
  169. X
  170. #
  171. # bottom_brace ( <left>, <right> )
  172. #
  173. define bottom_brace X
  174. BB1: $1
  175. BB2: $2
  176. arc from BB1 + (0.00, -0.09375) to BB1 + (0.0625, - 0.15625) rad 0.0625
  177. line right (((BB2.x - BB1.x) - 0.125) / 2) - 0.03125
  178. line right 0.03125 down 0.03125
  179. Bracept:line up 0.03125 right 0.03125
  180. line to BB2 + (-0.0625, -0.15625)
  181. arc from last line.end to BB2 + (0, -0.09375) rad 0.0625
  182. X
  183. #
  184. # top_brace ( <left>, <right> )
  185. #
  186. define top_brace X
  187. TB1: $1
  188. TB2: $2
  189. arc cw from TB1 + (0.00, 0.09375) to TB1 + (0.0625, 0.15625) rad 0.0625
  190. line right (((TB2.x - TB1.x) - 0.125) / 2) - 0.03125
  191. line right 0.03125 up 0.03125
  192. Bracept:line down 0.03125 right 0.03125
  193. line to TB2 + (-0.0625, 0.15625)
  194. arc cw from last line.end to TB2 + (0, 0.09375) rad 0.0625
  195. X
  196. #
  197. # line_gap_down ( <top>, <bottom> )
  198. #
  199. define line_gap_down X
  200. Start: $1
  201. End: $2
  202. line down ((Start.y - End.y) - gap_down)/2 from Start
  203. line right gap_side
  204. line left gap_side*2 down gap_down
  205. line right gap_side
  206. line to End
  207. gap_down = 0.12 # reset default
  208. gap_side = 0.04 # reset default
  209. X
  210. #
  211. # line_gap_right ( <left>, <right> )
  212. #
  213. define line_gap_right X
  214. Start: $1
  215. End: $2
  216. line right ((End.x - Start.x) - gap_down)/2 from Start
  217. line up gap_side
  218. line down gap_side*2 right gap_down
  219. line up gap_side
  220. line to End
  221. gap_down = 0.12 # reset default
  222. gap_side = 0.04 # reset default
  223. X
  224. #
  225. # label_above( <sw-posn>, <se-posn>, <arrow-length>, <text> )
  226. #
  227. define label_above X
  228. P001: $1 + (0, 0.1)
  229. P002: $2 + (0, 0.1)
  230. line up 0.2 from P001
  231. line up 0.2 from P002
  232. arrow <- right $3 from P001 + (0, 0.1)
  233. arrow <- left $3 from P002 + (0, 0.1)
  234. $4 at 1/2 <2nd last arrow.start, last arrow.start>
  235. X
  236. #
  237. # label_below( <sw-posn>, <se-posn>, <arrow-length>, <text> )
  238. #
  239. define label_below X
  240. P001: $1 + (0, -0.1)
  241. P002: $2 + (0, -0.1)
  242. line down 0.2 from P001
  243. line down 0.2 from P002
  244. arrow <- right $3 from P001 + (0, -0.1)
  245. arrow <- left $3 from P002 + (0, -0.1)
  246. $4 at 1/2 <2nd last arrow.start, last arrow.start>
  247. X
  248. #
  249. # text_spanv ( <left-corner>, <right-corner>, <text>, <text-wid>,
  250. # <height-of-text-above-corners> )
  251. # end points are in line with text
  252. #
  253. define text_spanv X
  254. Lab001: $3 at 1/2 <$1, $2>
  255. arrow from Lab001.c + (0, - $4/2) to $1
  256. arrow from Lab001.c + (0, $4/2) to $2
  257. X
  258. #
  259. # text_spanc ( <left-corner>, <right-corner>, <text>, <text-wid>,
  260. # <height-of-text-above-corners> )
  261. # end points are in line with text
  262. #
  263. define text_spanc X
  264. Lab001: $3 at 1/2 <$1, $2>
  265. arrow from Lab001.c + (- $4/2, 0) to $1
  266. arrow from Lab001.c + ( $4/2, 0) to $2
  267. X
  268. #
  269. # measureb ( sw-corner, se-corner, text, <text-wid>, <height>)
  270. # Show the measurement below the object
  271. define measureb X
  272. Mleft: line from $1 + (0, -0.05) to $1 + (0, -($5 * 1.5) )
  273. Mright: line from $2 + (0, -0.05) to $2 + (0, -($5 * 1.5) )
  274. text_spanc( Mleft.c, Mright.c, $3, $4, $5)
  275. X
  276. #
  277. # measurea ( sw-corner, se-corner, text, <text-wid>, <height>)
  278. # Show the measurement above the object
  279. define measurea X
  280. Mleft: line from $1 + (0, 0.05) to $1 + (0, ($5 * 1.5) )
  281. Mright: line from $2 + (0, 0.05) to $2 + (0, ($5 * 1.5) )
  282. text_spanc( Mleft.c, Mright.c, $3, $4, $5)
  283. X
  284. #
  285. # measurel ( nw-corner, sw-corner, text, <text-wid>, <height>)
  286. # Show the measurement above the object
  287. define measurel X
  288. Mtop: line from $1 - (0.05, 0) to $1 - (($5 * 1.5),0 )
  289. Mbot: line from $2 - (0.05, 0) to $2 - (($5 * 1.5),0 )
  290. text_spanv( Mtop.c, Mbot.c, $3, $4, $5)
  291. X
  292. #
  293. # measurer ( nw-corner, sw-corner, text, <text-wid>, <height>)
  294. # Show the measurement above the object
  295. define measurer X
  296. Mtop: line from $1 + (0.05, 0) to $1 + (($5 * 1.5),0 )
  297. Mbot: line from $2 + (0.05, 0) to $2 + (($5 * 1.5),0 )
  298. text_spanv( Mtop.c, Mbot.c, $3, $4, $5)
  299. X
  300. #
  301. # queue ( <start> )
  302. #
  303. define queue X
  304. $2: $1 - (.1,0)
  305. $2exit: $1 + (0,.1)
  306. box wid 0.20 ht 0.05 with .nw at $2
  307. box wid 0.20 ht 0.05 with .nw at last box.sw
  308. box wid 0.20 ht 0.05 with .nw at last box.sw
  309. box wid 0.20 ht 0.05 with .nw at last box.sw
  310. line from last box.sw down 0.20
  311. line from last box.se down 0.20
  312. $2entry: last box.s - 0,0.1
  313. move to $2
  314. X
  315. #
  316. # pointer (from, to, sx, sy)
  317. #
  318. define pointer X
  319. # We want a 10% curve
  320. Start: $1
  321. End: $2
  322. dx = End.x - Start.x
  323. dy = End.y - Start.y
  324. incx = dx * $3; incy = dy * $4
  325. spline -> from $1 \
  326. to $1 + ( -incx, incy ) \
  327. to $2 + ( incx, -incy ) \
  328. to $2
  329. X
  330. #
  331. # field_a( text, bytes, label, other)
  332. # draw a box but label it above the field
  333. # leave room for other labels that may be there
  334. define field_a X
  335. $3: box wid (boxwid*$2)
  336. sprintf("%.0f", $2) below at last box.s
  337. spline <- from $3.n up (2+$4)*.4*boxht then right .1
  338. $1 at last spline.end ljust
  339. move to $3.e
  340. X
  341. #
  342. # field_s(text, bytes, label)
  343. # Draw a field with a slanted label
  344. # leave room for other labels that may be there
  345. define field_s X
  346. $3: box wid (boxwid*$2)
  347. sprintf("%.0f", $2) below at last box.s
  348. line invis $1 ljust above aligned \
  349. from $3.ne + (-.75*boxwid,-.5*boxht) up boxht right boxwid
  350. move to $3.e
  351. X
  352. #
  353. # field2_ai( opts, text, sizetext, bytes, label, other)
  354. # draw an box with options but label it above the field
  355. # leave room for other labels that may be there
  356. # any text for the bottom is provided by sizetext
  357. # additional box options can be provided in opts
  358. define field2_ai X
  359. $5: box $1 wid (boxwid*$4)
  360. spline <- from $5.n up (1.25+$6)*labelspace*boxht then right .1
  361. $2 at last spline.end ljust
  362. $3 below at $5.s
  363. move to $5.e
  364. X
  365. #
  366. # field2_al( text, sizetext, bytes, label, other)
  367. # draw a box but label it above the field but to the left
  368. # leave room for other labels that may be there
  369. # any text for the bottom is provided by sizetext
  370. define field2_al X
  371. $4: box wid (boxwid*$3)
  372. spline <- from $4.n up (1.25+$5)*labelspace*boxht then left .1
  373. right
  374. $1 at last spline.end rjust
  375. $2 below at $4.s
  376. move to $4.e
  377. X
  378. #
  379. # field2_a( text, sizetext, bytes, label, other)
  380. # draw a box but label it above the field
  381. # leave room for other labels that may be there
  382. # any text for the bottom is provided by sizetext
  383. define field2_a X
  384. $4: box wid (boxwid*$3)
  385. spline <- from $4.n up (1.25+$5)*labelspace*boxht then right .1
  386. $1 at last spline.end ljust
  387. $2 below at $4.s
  388. move to $4.e
  389. X
  390. # draw a box and label it as a field within a packet
  391. # field( boxtext, units, label )
  392. define field X
  393. $3: box $1 wid (boxwid*$2)
  394. move to $3.e
  395. X
  396. # draw a box and label it as a field within a packet
  397. # the size in bytes appears below the box
  398. # field2( boxtext, sizetext, units, boxlabel)
  399. define field2 X
  400. $4: box $1 wid (boxwid*$3)
  401. $2 below at last box.s
  402. move to $4.e
  403. X
  404. # Show field with internal tick marks
  405. # fieldt( scale, text, units, label )
  406. define fieldt X
  407. fw = basef * $1
  408. fh = basef
  409. $4: box $2 wid (fw*$3) ht fh
  410. for t = fw to fw * ($3 - 1) by fw do {
  411. line from $4.nw + (t,0) to $4.sw + (t,0) dotted
  412. }
  413. move to $4.e
  414. # [ "$3" at $4.s below ]
  415. X
  416. define inetsw X
  417. Inetsw: box "-" with .c at $1; "0 " rjust at last box.w
  418. "\fCinetsw[]\fP" above at last box.n
  419. Iudp: box "UDP" with .n at last box.s; "1 " rjust at last box.w
  420. Itcp: box "TCP" with .n at last box.s; "2 " rjust at last box.w
  421. Iicmp: box "ICMP" with .n at last box.s; "3 " rjust at last box.w
  422. Irip: box "raw IP" with .n at last box.s; "4 " rjust at last box.w
  423. box "raw IP" with .n at last box.s; "5 " rjust at last box.w
  424. X
  425. #
  426. # array( count, text, center0)
  427. define array X
  428. A0: box with .nw at $3 ; $2 above at last box.n
  429. for i = 2 to $1 do {
  430. Al: box with .n at last box.s;
  431. }
  432. X
  433. #
  434. # lnullp( start )
  435. # draw the grounding end of a null pointer but on the left
  436. define lnullp X
  437. spline from $1+(poff,0) left 2*poff+boxht/2 then down boxht
  438. Mid: Here
  439. line from Mid - (boxht/2, 0) right boxht
  440. line from Mid - (boxht/4,.02) right boxht/2
  441. line from Mid - (boxht/8,.04) right boxht/4
  442. line from Mid - (boxht/16,.06) right boxht/8
  443. #pstart($1 + (poff,0))
  444. X
  445. #
  446. # dnullp(start)
  447. # draw the grounding end of a null pointer
  448. define dnullp X
  449. line from $1 down boxht
  450. Mid: Here
  451. line from Mid - (boxht/2, 0) right boxht
  452. line from Mid - (boxht/4,.02) right boxht/2
  453. line from Mid - (boxht/8,.04) right boxht/4
  454. line from Mid - (boxht/16,.06) right boxht/8
  455. X
  456. #
  457. # nullp( start, horiz )
  458. # draw the grounding end of a null pointer
  459. define nullp X
  460. if ($2 == 0) then {horiz=boxht/2} else { horiz=$2 }
  461. #horiz=$2
  462. spline from $1-(poff,0) right 2*poff+horiz then down boxht
  463. Mid: Here
  464. line from Mid - (boxht/2, 0) right boxht
  465. line from Mid - (boxht/4,.02) right boxht/2
  466. line from Mid - (boxht/8,.04) right boxht/4
  467. line from Mid - (boxht/16,.06) right boxht/8
  468. #pstart($1-(poff,0))
  469. X
  470. #
  471. # vv_spline(top, bottom, offset, gap, arrow )
  472. # Draw a V shaped spline from top to bottom.
  473. define vv_spline X
  474. initspline($1, $2, .5, .5, .25)
  475. line from Spline1 right $3
  476. spline from Spline1 then right $4 then to Spline2 $5
  477. X
  478. #
  479. # vu_spline(top, bottom, off, off, gap, arrow, text)
  480. # Connect top and bottom on the left
  481. define vu_spline X
  482. initspline($1, $2+($5,0), .5, .5, .25)
  483. # then up yrad then up dy-2*yrad then up yrad
  484. spline from Spline1 then right dx-xrad then right xrad \
  485. then up dy \
  486. then left xrad then left dx-xrad $6
  487. if ($3 != 0 ) then {
  488. line from Spline1 right $3
  489. #circle fill 1 rad .015 with .c at last line.end
  490. }
  491. if ($4 != 0 ) then {
  492. line from Spline2 right $4
  493. #circle fill 1 rad .015 with .c at last line.end
  494. }
  495. line invis from $1 + ($5,0) then up dy $7
  496. X
  497. #
  498. # hu_spline(left, right, off, off, gap, arrow, text)
  499. # Connect left and right horizontally
  500. define hu_spline X
  501. Spline1: $1
  502. Spline2: $2
  503. dx = Spline2.x - Spline1.x
  504. spline from Spline1 then up $5 then right dx/2 \
  505. then to Spline2 + (0,$5) then to Spline2 $6
  506. if ($3 != 0 ) then { line from Spline1 up $3 }
  507. if ($4 != 0 ) then { line from Spline2 up $4 }
  508. line invis from $1 + (0,$5) then right dx $7
  509. X
  510. #
  511. # initspline(p1, p2, scalex, scaley, scale_radius)
  512. define initspline X
  513. Spline1: $1
  514. Spline2: $2
  515. dx = Spline2.x - Spline1.x
  516. dy = Spline2.y - Spline1.y
  517. if (dx < 0 ) then { adx = -dx} else { adx = dx}
  518. if (dy < 0 ) then { ady = -dy} else { ady = dy }
  519. srad = max(min(adx*$3, ady*$4), boxht*$5)
  520. #srad = boxht/4
  521. xrad = srad
  522. yrad = srad
  523. #xrad = adx*$3
  524. #yrad = ady*$4
  525. #sprintf("dx %f dy %f srad %fxrad %f yrad %f", dx, dy, srad, xrad, yrad) \
  526. # above at Spline1
  527. if (dx < 0 ) then { xrad = -srad }
  528. if (dy < 0 ) then { yrad = -srad }
  529. #if (dx < 0 ) then { xrad = -xrad }
  530. #if (dy < 0 ) then { yrad = -yrad }
  531. X
  532. #
  533. # lr_spline(start, end, off, off, arrow, text, rad)
  534. # Connect start and end in an l shape
  535. define lr_spline X
  536. initspline($1, $2, .2, .2, $7)
  537. spline from Spline1 \
  538. then up dy-yrad \
  539. then up yrad \
  540. then right xrad \
  541. then right dx-xrad $5
  542. if ($3 != 0 ) then { line from Spline1 up $3 }
  543. if ($4 != 0 ) then { line from Spline2 right $4 }
  544. line invis from $1 + (0,dy) then right dx $6
  545. X
  546. #
  547. # l_spline(start, end, off, off, arrow, text)
  548. # Connect start and end in an l shape
  549. define l_spline X
  550. initspline($1, $2, .2, .2, 1.25)
  551. spline from Spline1 \
  552. then up dy-yrad \
  553. then up yrad \
  554. then right xrad \
  555. then right dx-xrad $5
  556. if ($3 != 0 ) then { line from Spline1 up $3 }
  557. if ($4 != 0 ) then { line from Spline2 right $4 }
  558. line invis from $1 + (0,dy) then right dx $6
  559. X
  560. #
  561. # vertical spline
  562. # v_spline(p1, p2, off1, off2, arrow, turn)
  563. #
  564. define v_spline X
  565. vz_spline($1, $2, $3, $4, $5, $6, .05)
  566. # initspline($1, $2, .2, .2)
  567. # spline from Spline1 \
  568. # then up (dy*$6)-yrad then up yrad \
  569. # then right dx then up yrad \
  570. # then up (dy*(1-$6))-yrad $5
  571. # if ($3 != 0 ) then { line from Spline1 down $3 }
  572. # if ($4 != 0 ) then { line from Spline2 up $4 }
  573. X
  574. #
  575. # vertical Z spline
  576. # vz2_spline(p1, p2, off1, off2, arrow, turn, overrun)
  577. # same as hz_spline but with absolute measurement for turn
  578. # instead of a percentage
  579. #
  580. define vz2_spline X
  581. initspline($1, $2, .2, .2, .25)
  582. d1=$6
  583. d2=dy-$6
  584. overrun=$7
  585. span=min(min(.9*max(d1, -d1), .9*max(d2, -d2)), max($7, -$7))
  586. sign=dy/(max(dy,-dy))
  587. if (overrun < 0 ) then {
  588. overrun = -.5*span
  589. }
  590. spline from Spline1 \
  591. then up $6 - span*sign \
  592. then up span*sign + overrun*sign \
  593. then right dx up 2*overrun*sign \
  594. then up overrun*sign + span*sign \
  595. then to Spline2 $5
  596. if ($3 != 0 ) then { line from Spline1 down $3 }
  597. if ($4 != 0 ) then { line from Spline2 up $4 }
  598. X
  599. #
  600. # vertical Z spline
  601. # vz_spline(p1, p2, off1, off2, arrow, turn, overrun)
  602. #
  603. define vz_spline X
  604. overrun=$7
  605. if (overrun == 0 ) then { overrun = .2 }
  606. initspline($1, $2, .2, .05, .25)
  607. spline from Spline1 \
  608. then up yrad then (dy*$6)+dy*overrun-yrad \
  609. then right dx down 2*dy*overrun \
  610. then up (dy*(1-$6))+dy*overrun-yrad then up yrad $5
  611. if ($3 != 0 ) then { line from Spline1 down $3 }
  612. if ($4 != 0 ) then { line from Spline2 up $4 }
  613. X
  614. #
  615. # horizontal Z spline
  616. # hz_spline(p1, p2, off1, off2, arrow, turn, overrun)
  617. #
  618. define hz_spline X
  619. overrun=$7
  620. if (overrun == 0 ) then { overrun = .2 }
  621. initspline($1, $2, .2, .2, .25)
  622. spline from Spline1 \
  623. then right (dx*$6)+dx*overrun \
  624. then up dy left 2*dx*overrun \
  625. then right dx*(1-$6)+dx*overrun $5
  626. if ($3 != 0 ) then { line from Spline1 left $3 }
  627. if ($4 != 0 ) then { line from Spline2 right $4 }
  628. X
  629. #
  630. # erase(center, fill, rad)
  631. #
  632. define erase X
  633. if ( $3 == 0 ) then { erad = boxht/8 } else { erad = $3 }
  634. circle invis rad erad fill $2 with .c at $1
  635. X
  636. #
  637. # target(center)
  638. #
  639. define target X
  640. circle rad boxht/2 with .c at $1
  641. X
  642. # spline down and on the left
  643. define spline_dl {
  644. Start: $1
  645. Dest: $2
  646. line from Start to Start + ($3, 0)
  647. spline $5 from Start \
  648. then left $4 \
  649. then down $4 \
  650. then to Dest + (-$4, $4) \
  651. then to Dest + (-$4, 0) \
  652. then to Dest
  653. }
  654. # spline down and on the right
  655. define spline_dr {
  656. Start: $1
  657. Dest: $2
  658. line from Start to Start + ($3, 0)
  659. spline $5 from Start \
  660. then right $4 \
  661. then down $4 \
  662. then to Dest + ( $4, $4) \
  663. then to Dest + ( $4, 0) \
  664. then to Dest
  665. }
  666. # spline up and on the left
  667. define spline_ul {
  668. Start: $1
  669. Dest: $2
  670. line from Start to Start + ($3, 0)
  671. spline $5 from Start \
  672. then left $4 \
  673. then up $4 \
  674. then to Dest + (-$4, -$4) \
  675. then to Dest + (-$4, 0) \
  676. then to Dest
  677. }
  678. # spline up and on the right
  679. define spline_ur {
  680. Start: $1
  681. Dest: $2
  682. line from Start to Start + ($3, 0)
  683. spline $5 from Start \
  684. then right $4 \
  685. then up $4 \
  686. then to Dest + ( $4, -$4) \
  687. then to Dest + ( $4, 0) \
  688. then to Dest
  689. }
  690. # Spline right/up/right
  691. define spline_rur {
  692. Start: $1
  693. End: $2
  694. if ($4 == 0) then { dx = (End.x - Start.x) / 2 } else { dx = $4 }
  695. if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  696. if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  697. Turn1: (Start.x + dx, Start.y)
  698. Turn2: (Start.x + dx, End.y)
  699. line from Start to Start + ($3, 0)
  700. spline $5 from Start \
  701. to Turn1 + (-turn1rad, 0) \
  702. to Turn1 \
  703. to Turn1 + (0, turn1rad) \
  704. to Turn2 + (0, -turn2rad) \
  705. to Turn2 \
  706. to Turn2 + ( turn2rad, 0) \
  707. to End
  708. }
  709. # Spline right/down/right
  710. define spline_rdr {
  711. Start: $1
  712. End: $2
  713. if ($4 == 0) then { dx = (End.x - Start.x) / 2 } else { dx = $4 }
  714. if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  715. if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  716. Turn1: (Start.x + dx, Start.y)
  717. Turn2: (Start.x + dx, End.y)
  718. line from Start to Start + ($3, 0)
  719. spline $5 from Start \
  720. to Turn1 + (-turn1rad, 0) \
  721. to Turn1 \
  722. to Turn1 + (0, -turn1rad) \
  723. to Turn2 + (0, turn2rad) \
  724. to Turn2 \
  725. to Turn2 + ( turn2rad, 0) \
  726. to End
  727. }
  728. # Spline left/up/left
  729. define spline_lul {
  730. Start: $1
  731. End: $2
  732. if ($4 == 0) then { dx = (Start.x - End.x) / 2 } else { dx = $4 }
  733. if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  734. if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  735. Turn1: (Start.x - dx, Start.y)
  736. Turn2: (Start.x - dx, End.y)
  737. line from Start to Start + ($3, 0)
  738. spline $5 from Start \
  739. to Turn1 + ( turn1rad, 0) \
  740. to Turn1 \
  741. to Turn1 + (0, turn1rad) \
  742. to Turn2 + (0, -turn2rad) \
  743. to Turn2 \
  744. to Turn2 + (-turn2rad, 0) \
  745. to End $5
  746. }
  747. # Spline left/down/left
  748. define spline_ldl {
  749. Start: $1
  750. End: $2
  751. if ($4 == 0) then { dx = (Start.x - End.x) / 2 } else { dx = $4 }
  752. if ("$6" != "") then { turn1rad = $6 } else { turn1rad = 0.2 }
  753. if ("$7" != "") then { turn2rad = $7 } else { turn2rad = 0.2 }
  754. Turn1: (Start.x - dx, Start.y)
  755. Turn2: (Start.x - dx, End.y)
  756. line from Start to Start + ($3, 0)
  757. spline $5 from Start \
  758. to Turn1 + ( turn1rad, 0) \
  759. to Turn1 \
  760. to Turn1 + (0, -turn1rad) \
  761. to Turn2 + (0, turn2rad) \
  762. to Turn2 \
  763. to Turn2 + (-turn2rad, 0) \
  764. to End $5
  765. }
  766. # Place hash marks at the 32-bit boundaries of an IPv6 16-byte address.
  767. define ipv6_hash {
  768. NW: $1.nw
  769. SE: $1.se
  770. mywid = SE.x - NW.x
  771. myht = NW.y - SE.y
  772. line right v6_hash from NW + (0, -1*myht/4)
  773. line right v6_hash from NW + (0, -2*myht/4)
  774. line right v6_hash from NW + (0, -3*myht/4)
  775. line left v6_hash from SE + (0, 1*myht/4)
  776. line left v6_hash from SE + (0, 2*myht/4)
  777. line left v6_hash from SE + (0, 3*myht/4)
  778. v6_hash = 0.06 # reset default
  779. }
  780. # Draw routers with rounded corners.
  781. # Problem with boxes with rounded corners: .ne, .ne, .se, .sw now refer to
  782. # the rounded portion, which screws things up. Make invisible box without
  783. # rounded corners for compass positions.
  784. define router {
  785. box invis $1 $2
  786. box rad 0.1 with .n at last box.n
  787. }
  788. # small15_text2(box_name, top_string, bottom_string)
  789. #
  790. # Text within a box is often "too big". For example: box "top" "bottom"
  791. # can have the string "top" too high in the box (with ascenders
  792. # touching the top of the box) and the string "bottom" can be too low
  793. # (with descenders touching the bottom of the box.
  794. # But placing .ps and .vs commands within a picture is asking for trouble.
  795. # The "right" way to do this is to make the string smaller with an inline
  796. # \s-1 or \s-2, with a vertical motion before and after, then \s0.
  797. #
  798. # The "15" means the vertical motion is 0.15m and the "2" means two arguments.
  799. #
  800. # Note that when invoking this macro, do *not* put the arguments
  801. # top_string and bottom_string in double quotes. These two arguments
  802. # may contain spaces (but not commas).
  803. define small15_text2 {
  804. box invis ht $1.ht wid $1.wid with .n at $1.n \
  805. "\v'0.15m'\s-1$2\s0\v'-0.15m'" "\v'-0.15m'\s-1$3\s0\v'0.15m'"
  806. }
  807. # Add invisible space to the right, normally to center picture.
  808. define right_space {
  809. box invis wid $2 with .w at $1
  810. }
  811. # Add invisible space to the right, normally to center picture.
  812. define left_space {
  813. box invis wid $2 with .e at $1
  814. }
  815. .PE