def offsetline(linen,pattern_result):
  """Return the line number offset by the size of a matched pattern.

  This is an internal utility function.

  Given 'linen' (the current line number) and 'pattern_result'
  (a dictionary containing data items returned from one of the
  regular expression functions), this function returns a line
  number which is offset to the start of the regular expression.
  It does this by locating a dictionary key 'nlines', which
  gives the size of the regular expression match."""

  if "nlines" in pattern_result:
    nlines = pattern_result["nlines"]
  else:
    nlines = 0
  new_linen = linen - nlines - 1
  if new_linen < 0:
    return 0
  else:
    return new_linen