Is there any command line tool which can be used to beautify c++ file on ubuntu? If yes, can you please suggest one?

Thank you.


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))

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

;; EOF ;;

http://www.faqs.org/docs/Linux-HOWTO/C-C++Beautifier-HOWTO.html should cover most topics of your problem:

C++ : BCPP site is at "http://dickey.his.com/bcpp/bcpp.html" or at
      "http://www.clark.net/pub/dickey" . BCPP ftp site is at 

C++ : "http://www.consultix-inc.com/c++b.html"

C : "http://www.chips.navy.mil/oasys/c/" and mirror at Oasys

C++ : "http://www.semdesigns.com/Products/DMS/DMSToolkit.html"

C++, C, Java and Oracle Pro-C Beautifier:

C++, C beautifier "http://users.erols.com/astronaut/vim/ccb-1.07.tar.gz" 
     and site at "http://users.erols.com/astronaut/vim/#vimlinks_src"

C++, C, Java, Perl beautifier CBP "http://www.prismtk.de/docs/cbp"

GC! GreatCode! is a powerful C/C++ source code beautifier Windows 
     95/98/NT/2000 "http://perso.club-internet.fr/cbeaudet"

CbVan for C, C++ and Java at "http://www.geocities.com/~starkville/main.html"

Artistic Style beautifier for C, C++, Java at 
     "http://sourceforge.net/projects/astyle" "http://astyle.sourceforge.net".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.