Command line tool to format c++ code on ubuntu

Have you tried GNU indent?


"astyle" is quite good - and in my experience does a much better job than "indent" for C++.

If you are familiar with Emacs you can also use that for automatic indention from the command line. A simple Emacs script would look like this:

#!/usr/bin/emacs --script

(require 'cc-mode)

(setq require-final-newline 'visit)
(setq c-default-style "gnu")

(defun indent-files (files)
  (dolist (file files)
    (find-file file)
    (indent-region (point-min) (point-max))
    (untabify (point-min) (point-max))
    (save-buffer)
    (kill-buffer)))

(indent-files command-line-args-left)

;; EOF ;;

Tags:

Ubuntu