###
# backslash_newline_subst
#
# Given a string, change
#
# \<newline>whiteSpace into a single space.
# Copyright (c) 2002-2003 by William J. Coleda

.sub __backslash_newline_subst

  .param string buffer

  .include "lib/macros/is_space.imc"
  
  .local string bs_nl
  .local int marker
  .local int pos
  .local int retval
  .local int buffer_length
  .local int diff
  .local string a_char
  .local int a_byte
 
  bs_nl = ""
  chr a_char, 92
  concat bs_nl, a_char
  chr a_char, 10
  concat bs_nl, a_char
  marker=0

loop_outer:
  length buffer_length, buffer
  if marker > buffer_length goto my_end
  index pos, buffer, bs_nl, marker
  if pos == -1 goto my_end

  marker = pos

  # skip one byte of the two byte marker, 
  # the second is skipped in the loop, and
  # we then use that inc as the loop increment as well.
  inc pos

loop_inner:
  inc pos 

  ord a_byte, buffer, pos

  .is_space(a_byte,retval)
 
  if retval == 1 goto loop_inner

  # delete the items from marker to pos

  diff = pos - marker
  substr buffer,marker,diff,""
  goto loop_outer

my_end:

  .return buffer
  ret

.end
