; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: Several data definition/manipulation macros.
;
;  Target OS: Any
;
;  Dependencies:
;
;  Notes:
;_________________________________________________________________________________________

macro getfile lblname*, filename* {
  if used lblname
    lblname file filename
    .size = $ - lblname
  end if
}

macro StringTable [string] {
  forward
    local ..lbl
    dd  ..lbl
  common
    dd  0
  forward
..lbl db string, 0
}


macro IndexedStrings [lparam, string] {
  forward
    local ..lbl
    dd  ..lbl, lparam
  common
    dd  0
  forward
..lbl db string, 0
}


macro Sequence [seqname*, initvalue*] {
forward
  seqname#.current = initvalue
  macro seqname [name] \{
    name = seqname#.current
    seqname#.current = seqname#.current + 1
    if defined seqname#.display & seqname#.display
      disp iconInfo, `seqname, ' value: ', \`#name, ' = $', <name, 16>, $0d
    end if
  \}
}





struc StripText source_file, syntax {
local ..lbl, source, string, len, rawlen, char, pchar, j, flag, quot

  label . byte
  ..lbl:
        rb len
  .length = len
        dd 0

  virtual at 0
    source::
    string file source_file
           rawlen = $
  end virtual

  if rawlen = 0
    err
  end if

  j = 0
  pchar = ' '
  flag = 1
  quot = 0

  repeat rawlen
    load char byte from source:(%-1)

    if ~quot & (syntax eq SQL)
      if flag
        if (char = '*' & pchar = "/") | (char = "-" & pchar = "-")
          flag = 0
          char = ' '
          pchar = ' '
          j = j - 1
        end if
      else
        if (char = "/" & pchar = "*" ) | char = 13 | char = 10
          flag = 1
          char = ' '
          pchar = ' '
        end if
      end if
    end if

    if flag & (char = "'" | char = '"' | char = "`") & (syntax eq SQL)
      if ~quot
        quot = char
      else
         if quot = char
           quot = 0
         end if
      end if
    end if

    if ~quot & ( char < ' ' )
      char = ' '
    end if

    if quot | (flag & ( char > ' ' | (char = ' ' & pchar<>' ')))
      if j < len
        store byte char at ..lbl + j
      end if
      j = j + 1
    end if

    pchar = char

  end repeat

  len = j

}