(defun fix-SSD ()
  "Do some more translating of the SSD source from Modula to Modula-2."
  (interactive "*")
  (make-local-variable 'old-fold)
  (setq old-fold case-fold-search)
  (setq case-fold-search nil)
  (goto-char (point-min))
  (replace-string "KerrNum" "exceptionType")
  (goto-char (point-min))
  (replace-string "openModes" "setOfOpenModes")
  (goto-char (point-min))
  (replace-string "SYSTEM" "System")
  (goto-char (point-min))
  (replace-string "ipcBlock" "ipcReturn")
  (goto-char (point-min))
  (teco-fs "MODULE ssd;" "MODULE SSD;")
  (teco-fs "END ssd." "END SSD.")
  (goto-char (point-min))
  (search-forward "Nlib;")
  (insert "\n")
  (search-forward "ticksToTimeBlk")
  (teco-fs "SIZE" "size")
  (teco-fs "SIZE" "size")
  (teco-fs "SIZE" "size")
  (teco-fs "SIZE" "size")
  (setq case-fold-search old-fold)
  )

(defun fix-import-list (module symbols)
  (interactive "*sModule name: \nsSymbols to add: ")
  (re-search-forward (concat "MODULE[ \t]*" module))
  (search-forward "IMPORT")
  (re-search-forward "[,;]")
  (forward-word -1)
  (setq col (current-column))
  (search-backward "IMPORT")
  (forward-word 1)
  (if (equal (following-char) 10)
      (forward-char 1)
    (insert "\n")
    )
  (indent-to col 0)
  (insert (format "%s\n" symbols))
  )

(defun kill-lines-containing (string before after)
  (interactive "*sString: \nnLines before: \nnLines after: \n")
  (search-forward string)
  (kill-line (- before))
  (kill-line after)
  )

(defun teco-fs (from-string to-string &optional arg)
  "Perform the TECO \"fs\" (find and substitute) command.
Replaces one occurrence of FROM-STRING with TO-STRING -- the ARGth
occurrence, to be precise.  Negative ARG means search backward.

When calling from a program, nil means \"no arg\",
a number counts as a prefix arg."
  (interactive "*sFind: \nsFind \"%s\" and substitute with: \nP")
  (if (or (equal arg nil) (equal arg 0))
      (setq arg 1))
  (if (< arg 0)
      (search-backward from-string nil nil (- arg))
    (search-forward from-string nil nil arg)
    )
  (replace-match to-string t t)
  )
