(defun fix-tree ()
  "Fix all process lines in the KSOS calling tree."
  (interactive "*")
  (make-local-variable 'mk)
  (make-local-variable 'name)
  (make-local-variable 'line)
  (make-local-variable 'old-fold)
  (setq old-fold case-fold-search)
  (setq case-fold-search nil)
  (goto-char (point-max))
  (if (search-backward "PSDrelease " nil t)
      (progn
	(forward-word 1)
	(kill-word 3)
	(insert-string " [external")
	)
    (message "PSDrelease not found")
    )
  (while (progn (goto-char (point-min)) (search-forward "P_" nil t))
    (delete-backward-char 2)
    (setq name (buffer-substring (point) (progn (end-of-line) (point))))
    (insert-string " [process]")
    (beginning-of-line)
    (re-search-forward "[0-9]")
    (backward-char)
    (setq mk (point))
    (search-forward " ")
    (backward-char)
    (setq line (buffer-substring mk (point)))
    (end-of-line)
    (while (search-forward (concat " " name " [external") nil t)
      (kill-word -1)
      (insert-string (concat "see line " line))
      )
    )
  (while (progn (goto-char (point-min)) (search-forward "<<< " nil t))
    (setq name (buffer-substring (point) (progn (end-of-line) (point))))
    (beginning-of-line)
    (search-backward (concat " " name "\n"))
    (beginning-of-line)
    (re-search-forward "[0-9]")
    (backward-char)
    (setq mk (point))
    (search-forward " ")
    (backward-char)
    (setq line (buffer-substring mk (point)))
    (search-forward "<<< ")
    (delete-char -4)
    (end-of-line)
    (insert-string (concat " [recursive call to line " line "]"))
    )
  (if (search-forward "init [external]" nil t)
      (progn
	(backward-char)
	(kill-word -2)
	(insert-string "[all module initializations"))
    (message "init [external]" not found)
    )
  (setq case-fold-search old-fold)
  )
