flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > [fasmg] ? macro strips spaces

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 473
Location: Belarus
[fasmg] ? macro strips spaces
I thought of creating the ability to define multiline text with the ? macro

Code:

macro text?! nameterminator
  local lines
  lines = 0
  name equ
  macro ?! line&
    if `line = `terminator
      purge ?
    else
      if lines > 0
        name equ name1310, `line
      else
        name equ `line
      end if
      lines = lines + 1
    end if
  end macro
end macro



Unfortunately, it strips whitespaces, so all text indentation is lost.
Is it possible to preserve line as is with leading spaces?
Post 21 Feb 2017, 23:02
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6386
Location: Kraków, Poland
Like fasm's preprocessor, fasmg's macro operate on a pre-tokenized text that loses some of the properties of the original - the excess whitespace is stripped, it is not remembered which kind of quotes were used to enclose a quoted string and comments starting with a semicolon are not tokenized at all.

If you need to operate on the raw text, the only option might be to load it with FILE. You could load original text of current source with "file __file__" and count lines to find one with "__line__" number - a bit clunky but might work:

Code:
macro find_me?
        virtual at 0
                file __file__
                counter = 0
                repeat $
                        load a:byte from %-1
                        if a = 10 | % = %%
                                counter = counter + 1
                                if counter = __line__
                                        load line_data : %-line_start from line_start
                                        display line_data
                                        break
                                end if
                                line_start = %
                        end if
                end repeat
        end virtual
end macro

        find_me ; here


Post 22 Feb 2017, 07:54
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 473
Location: Belarus
Thanks for the hint.
Here's what I got:

Code:

macro text?! nameterminator
  local linesstart_linestart_indxend_indx
  lines = 0
  start_line = 1
  macro ?! line&
    if `line = `terminator
      virtual at 0
        file __file__
        ln = 1
        start_indx = 0
        end_indx = 0
        repeat $
          load a:byte from % - 1
          if a = 10 | % = %%
            ln = ln + 1
            if ln = start_line
              start_indx = %
            else if ln = start_line + lines
              end_indx = % - 1
              break
            end if
          end if
        end repeat
        load name:end_indx - start_indx from start_indx
      end virtual
      purge ?
    else
      if lines = 0
        start_line = __line__
      end if
      lines = lines + 1
    end if
  end macro
end macro

text myfileEOF
    line1
  line 2
line3
EOF


Post 23 Feb 2017, 22:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.