def fixupResultForD978(resultStr, output_d978fa):
  """
  For programs that require the strict output format of dump978 or dump978-fa,
  this routine will edit the result string and return a new string with  
  the desired output.

  All strings contain the message itself. The 'rs=' reed-solomon errors are
  printed only if there are any. Only a single total number is printed. Since 
  FISB-978 stops looking for FISB errors if it doesn't have to process all the
  packets, only the errors actually found are used.

  If this is dump978-fa format, the time and rssi values will always be included.
  For original dump-978, these are always missing.

  Args:
    resultStr (str): Usual FISB-978 result string.
    output_d978fa (bool): True if the output is to be in dump978-fa format.
      Otherwise will be in dump978 format.

  Returns:
    str: Edited result string in proper format.
  """
  parts = resultStr.split(';')

  # Put reed-solomon only if there are any errors.
  # For FIS-B, stop counting for amounts over 90, these are messages parts that
  # don't need to be checked.
  rsStr = parts[1].split('/')[1]
  if ':' in rsStr:
    rsSplit = rsStr.split(':') 
    totalErrs = 0
    for i in rsSplit:
      x = int(i)
      if x > 90:
        break
      totalErrs += x
  else:
    totalErrs = int(rsStr)

  # Start building result string.
  newResultStr = parts[0]
  if totalErrs > 0:
    newResultStr += ';rs=' + str(totalErrs)

  # Add d978-fa only items
  if output_d978fa:
    rssiStr = parts[2].split('/')[1]
    tiStr = parts[3][2:]
    newResultStr += ';rssi=' + rssiStr + ';t=' + tiStr

  # Always add ';' to end
  newResultStr += ';'

  return newResultStr