1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Align

Discussion in 'Plugins' started by Joe Caverly, Jul 14, 2011.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    730
    Likes Received:
    8
    From http://sites.google.com/site/jlcprogrammingstuff/home/tcc/align

    Code:
    :: ALIGN.BTM
    ::
    :: Demonstrate the use of the Variable Functions of the
    ::   ALIGN Plugin, available from;
    ::
    ::  https://sites.google.com/site/jlcprogrammingstuff/home/tcc/align
    ::
    ::  Written by Joe Caverly
    ::  Tested with Windows XP SP3, TCC 11.00.52
    ::
    ::
    @echo off
    @setlocal
    if not plugin align plugin /l align
    echo %@LALIGN[Left-Aligned,20]%@CALIGN[Centre-Aligned,20]%@RALIGN[Right-Aligned,20]
    do kount = 1 to 25
      echo %@LALIGN[Line %kount,20]%@CALIGN[Line %kount,20]%@RALIGN[Line %kount,20]
    enddo
    if plugin align plugin /u align
    @endlocal
    
    @LALIGN left-aligns text into a string of x characters
    @CALIGN centre-aligns text into a string of x characters
    @RALIGN right-aligns text into a string of x characters

    Joe
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,374
    Likes Received:
    40
    Nifty! Works here, and seems to deal sensibly with (a) strings longer than n characters, and (b) strings with leading/trailing spaces.

    It doesn't like unquoted strings containing commas, though; and if the string is quoted, the quotes remain in the output. All three functions always expect exactly two arguments, right? I'd suggest that if the input string contains more than one comma, then the last one separates the two args -- everything before the last comma is a part of the string arg.
     
  3. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    730
    Likes Received:
    8
    This works;

    Code:
    echo %@calign[%@quote[Hello, It's Me],30]
            Hello, It's Me
    Joe
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,374
    Likes Received:
    40
    ... You're right; the quotes I was seeing were quotes which I put around the function for testing, not the ones I passed in to it. My mistake.

    A couple of other minor quibbles: error messages don't seem to go to stderr (or stdout either?); and in the case of a syntax error, the function ought to return some nonzero value (-1 works for me) so that TCC knows an error occurred and doesn't continue executing the erroneous command.
     

Share This Page