Smartcode (sc) is a source code formatting and pretty-printing tool for C/C++ developed with the goal of improving code readability and maintainability. It was forked from GC Greatcode by Christophe Beaudet, with enhancements specifically for modern C++ codebases.
Smartcode reads C/C++ source files and reformats them according to configurable style rules. The tool focuses on:
- Consistent indentation and spacing
- Comment formatting and alignment
- Preprocessor directive handling
- Configurable brace styles
- Flexible code organization options
The original project (GC Greatcode) provided a solid foundation, and Smartcode builds upon it with additional formatting options, better C++11+ support, and improved configurability.
- Source Code Formatting - Indents C/C++ code based on language rules
- Configurable Style Rules - Over 100 command-line options for fine-grained control
- Comment Handling - Formats both
//and/* */comments with alignment options - Preprocessor Support - Handles
#include,#define, and other directives intelligently - Cross-platform - Compiles on Windows (MSVC), Linux, and macOS
- Configurable brace styles (attachment, end of line, next line)
- Space insertion rules for various contexts (if, for, function calls, etc.)
- Comment formatting with configurable alignment and splitting
- Preprocessor directive handling with special alignment options
- Support for template specializations and modern C++ constructs
- Optional tag file generation for code navigation
This project uses Jam as its build system. To build:
# Clone the repository
git clone https://github.com/dreamraster/smartcode.git
cd smartcode
# Build with Jam
jam
# Or for debug build
jam -sCONFIG=debugThe executable sc.exe (or sc) will be created in the project directory.
Note: On Windows, you may need to copy
msvc.installtoJamfile.jamfirst and run Jam with the Visual Studio environment.
# Show help
sc -help
sc -h
# Format a single file (overwrites in place)
sc myfile.cpp
# Format with specific config
sc -c myconfig.cfg myfile.cpp
# Verbose mode to see what's happening
sc -v *.cpp| Option | Description |
|---|---|
-h, -help, /? |
Display help message |
-v, -verbose |
Enable verbose output |
-bak |
Create backup files (.orig extension) |
-c <file> |
Specify configuration file (default: sc.cfg) |
-d |
Generate dependency information |
-da |
Include system headers in dependencies |
0: Success<128: Non-fatal errors (files processed, some may have failed)>=128: Fatal errors or invalid arguments
Smartcode reads settings from sc.cfg in the current directory or parent directories. The configuration file uses a simple format:
-option1-value
-option2-
option3-123
See the Configuration Guide for all available options.
# Tab and indentation
-tab_size-4 # Number of spaces per tab
-out_tab # Use tabs in output (0=spaces, 1=tab, 2=tab/indent)
# Brace styles
-brace_style-0 # GNU style (brace with statement)
-brace_style-1 # K&R style (brace on same line as function)
# Spacing
-space_if-1 # Add space after if/while/for/catch
-space_return-2 # Add space between return and expression
# Comment formatting
-cmt_cpp2c_keep_eol-0 # Convert C++ comments to C at EOL
-cmt_first_space_cpp-1 # Space after C++ comment marker
.
├── main.c # Entry point, CLI parsing
├── config.c/.h # Configuration handling
├── tools.c/.h # Utility functions
├── error.c # Error reporting
├── debug.c # Debug utilities
├── in.c # File input handling
├── out.c # Output generation
├── lexi.c # Lexical analysis (tokenization)
├── grammar.c # Grammar analysis
├── grammar_pp.c # Preprocessor directives handling
├── grammar_decl.c # Declaration parsing
├── indent.c # Indentation logic
├── indent_*.c # Specialized formatters (comments, C++, etc.)
├── os.h # OS-specific definitions
└── Jamfile.jam # Jam build system file
Smartcode is a fork of GC Greatcode by Christophe Beaudet, with the first version released in 2012. The Smartcode branch was started by dreamraster to add modern C++ support and additional formatting options beyond the original project's capabilities.
Current version: 1.403
Based on GC Greatcode by Christophe Beaudet et al.
Contributions are welcome! Please feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
- Original GC Greatcode by Christophe Beaudet - The foundation upon which Smartcode was built
- Contributors - All who helped test, report issues, and improve Smartcode
This README was generated automatically from the project source on 2026-03-08