Loading ...
Sorry, an error occurred while loading the content.

Re: Temporary Arrays in Includ Files

Expand Messages
  • Mike
    ... You kmow, I tried that, but it didn t print the title in bold, so I thought that I was doing something wrong. ... The title is printed in bold. ... The
    Message 1 of 9 , Aug 1, 2007
    • 0 Attachment
      --- In cw@yahoogroups.com, Support <bkvam@...> wrote:
      >
      > I would recommend turning off output once at the start, and back on at
      > the end. Then use @output commands for all output. It's extremely easy
      > to have a mystery blank line, and although you can probably track it
      > down, it will probably be easier to just bite the bullet and do all
      > output with @output. The added advantage is that everything has the
      > correct indentation and the code is easier to read.
      >
      > So, instead of having
      >
      > @if sizeof(arr) > 0
      > @output on
      > @need 3ln
      > @bold
      >
      > %title%
      > @plain
      > @output off
      > ...
      >
      > you would have
      >
      > @if sizeof(arr) > 0
      > @need 3ln
      > @bold
      > @output
      > @output %title%
      > @plain
      > ...
      >


      You kmow, I tried that, but it didn't print the title in bold, so I
      thought that I was doing something wrong.

      If I use:
      > @output on
      > @need 3ln
      > @bold
      >
      > %title%
      > @plain
      > @output off

      The title is printed in bold.

      If I use:
      > @need 3ln
      > @bold
      > @output
      > @output %title%
      > @plain

      The title is printed in plain




      Not sure why yahoo stripped all my tabs from my last post, let me try
      again:

      $$macro dispOtherEquipment(boxwidth)
      {{
      @output off

      @sub display(title, arr)
      @var i, n, tmp
      @if sizeof(arr) > 0
      @need 3ln
      @output on
      @bold

      %title%
      @plain
      @n = sortElements(arr, 1)
      @for i = 1; i <= sizeof(arr); i = i + 1
      @assign @tmp=split(arr[i], " ", "_name", "_cost", "_weight",
      "_notes", "_options")
      @output %_name% ?_cost?%_cost%?? ?_weight=0?--?%_weight%?
      @if ConfigParam('PrintOptions')
      @if strlen(_notes)>0
      $$splitNotesLinesByLength(_notes, $(boxwidth))
      @endif
      @plain
      @if strlen(_options)>0
      @var arryOpts[0]
      @var tmp2, j, tmpopts
      @assign @tmp2=split(_options, ";", arryOpts)
      @for j=1; j<=sizeof(arryOpts); j=j+1
      @assign @tmpopts=split(arryOpts[j], ":", "_optname", "_optcost")
      @output \ %_optname%?_optcost?: %_optcost%??
      @endfor
      @endif
      @endif
      @endfor
      @endif
      @endsub

      @var worn[0]
      @var carried[0]
      @var carriednotes[0]
      @var transport[0]
      @var home[0]
      @var mobile[0]
      @var other[0]

      @foreach(Equipment)
      @assign _n=split(@`Location`, ", ", "_location", "_locnum")
      @assign _equip=concat(@item," ",@notes)
      @assign _equipopts = ""
      @if @options > 0
      @options
      @assign _equipopts = concat(_equipopts,";",@option)
      @endoptions
      @endif
      @assign _equip=concat(_equip," ",_equipopts)
      @if(_locnum="1")
      @n = addElement(worn,_equip)
      @elseif(_locnum="2")
      @n = addElement(carried,_equip)
      @elseif(_locnum="3")
      @n = addElement(transport,_equip)
      @elseif(_locnum="4")
      @n = addElement(home,_equip)
      @elseif(_locnum="5")
      @n = addElement(mobile,_equip)
      @else
      @n = addElement(other,_equip)
      @endif
      @endforeach

      @display('Equip. Worn/Carried', worn)
      @display('Equip. In Backpacks (Non-Combat Gear)', carried)
      @display('Equip. On Transport (Horse/Wagon/etc)', transport)
      @display('Equip. At Home/Somewhere Else', home)
      @display('Self-Mobile Equip. (Horse/Car/etc)', mobile)
      @display('Equip. at Some Other Location', other)

      @output on
      }}



      $$macro splitNotesLinesByLength(main, limit)
      {{
      @output off

      @var _fulltext, _linetext, _linenum
      @var _spacetext, _spacepos, _linelen, _ptrpos, _charlook
      @assign _fulltext=$(main)
      @assign _fulltext=concat(" ", _fulltext)
      @assign _linenum=0

      @while(_fulltext <> "")
      @assign _ptrpos=0
      @assign _spacepos=0
      @assign _linelen=0
      @while ((_linelen <= $(limit)) and (_ptrpos < strlen(_fulltext)))
      @assign _ptrpos=_ptrpos+1
      @assign _charlook=substr(_fulltext, _ptrpos, 1)
      $$CharSize(_charlook)
      @assign _linelen=_linelen+_charwidth
      @if (_charlook=" ")
      @if ((_linelen < $(limit)) and (_ptrpos>2))
      @assign _spacepos=_ptrpos
      @endif
      @endif
      @endwhile
      @if (_ptrpos >= strlen(_fulltext))
      @assign _linetext=_fulltext
      @assign _fulltext=""
      @else
      @if (_spacepos > 0)
      @assign _linetext=substr(_fulltext, 1, _spacepos-1)
      @assign _fulltext=concat(" ", substr(_fulltext, _spacepos+1,
      strlen(_fulltext)))
      @else
      @assign _linetext=substr(_fulltext, 1, _ptrpos)
      @assign _fulltext=concat(" -", substr(_fulltext, _ptrpos+1,
      strlen(_fulltext)))
      @endif
      @endif
      @output %_linetext%
      @endwhile

      @output on
      }}
    • brucekvam
      You may have an extra line in splitNotesByLineLength, or you may need to put a backslash after that macro invocation to keep things on the same line. You may
      Message 2 of 9 , Aug 4, 2007
      • 0 Attachment
        You may have an extra line in splitNotesByLineLength, or you may need
        to put a backslash after that macro invocation to keep things on the
        same line. You may also need a backslash on the opening {{ in that macro.
      • Mike
        ... macro. ... Yep, adding a backslash to the line calling the macro worked. @if strlen(_notes) 0 $$splitNotesLinesByLength(_notes, $(boxwidth)) @endif My
        Message 3 of 9 , Aug 5, 2007
        • 0 Attachment
          --- In cw@yahoogroups.com, "brucekvam" <bkvam@...> wrote:
          >
          > You may have an extra line in splitNotesByLineLength, or you may need
          > to put a backslash after that macro invocation to keep things on the
          > same line. You may also need a backslash on the opening {{ in that
          macro.
          >


          Yep, adding a backslash to the line calling the macro worked.

          @if strlen(_notes)>0
          $$splitNotesLinesByLength(_notes, $(boxwidth)) \
          @endif


          My understanding was that the \ character indicated a continuation of
          the preceding line, just wrapped onto the next line below it - to make
          things more human readable.

          So, it did work, and I'm using it, but not real happy about not being
          able to figure out _why_ it worked.
        • brucekvam
          ... That s what it does. When you have a macro invocation the text of the macro from the $$ to the final ) are replaced by what the macro emits. You had a new
          Message 4 of 9 , Aug 6, 2007
          • 0 Attachment
            > My understanding was that the \ character indicated a continuation of
            > the preceding line, just wrapped onto the next line below it - to make
            > things more human readable.

            That's what it does. When you have a macro invocation the text of the
            macro from the $$ to the final ) are replaced by what the macro emits.
            You had a "new line" after the macro invocation so the output has one
            as well. You could probably eliminate the new line in the body of the
            macro to achieve the same effect.

            The macro calls are therefore not quite the same as subroutine calls
            in filters. The filter subroutine capability was added much later than
            macro invocations, so older filters may use macros where subroutines
            might be more intuitive and convenient.
          Your message has been successfully submitted and would be delivered to recipients shortly.