C++ Beautifier() | C++ Beautifier() |
bcpp - make C++ beautifier
bcpp [-bcl] [-bnl] [-cc <num>]
[-f <num>]
[-fi <input file name>] [-fnc <custom config file>]
[-fo <output file name>] [-h] [-i <num>]
[-lg] [-nc] [-qb] [-s] [-t]
[-tbcl] [-tbnl] [<other options>] [<input file
name>] [<output file name>]
Options beginning with -y or -n enable/disable functions, respectively.
This program enables a user to reformat certain elements of a C, or C++ source code. This helps if one person's code is a little unreadable, or has been indented to a style that you dislike. Using this program will hopefully help in re-styling the code so that it closely meets your style. However, due to the many styles of C(++) that can be coded, there are limits to how well this program will handle the source code, and resulting re-formatted source.
The following are a list of features implemented:
This program will run under Microsoft DOS V3.3 and Unix platforms.
It uses approximately 50 - 70k (or more, dependant upon internal queue size) of memory during execution.
The program code has been written in such a way as to be compatible with existing C++ compilers, however the code is not ANSI standard and may require modification for your environment. The source code has been written with standard ANSI and Posix functions so that least amount of rewriting should be needed if recompiling on another computer platform.
The current sources have been compiled using Turbo C++ V3.0, for MS-DOS, GNU G++ 2.7.2 under Sun SPARCstation running SunOS, Solaris as well as SGI workstations running IRIX.
Operation of the program is via the command line (CLI), and with help from a configuration file you can define your format requirements. Basically each command directive starts with a dash "-" followed my the command name. If another parameter is need for the command, the parameter is added after the command, and separated with a space (i.e. bcpp -fi input.cpp).
N.B: Do not enter bcpp.exe on its own to find its command help, use bcpp -?, or bcpp -h. This is due to the input redirection from the O/S. Keeping to Unix CLI convention, a string that is read from the CLI and does not have a command directive is considered a input file. If there are two such occurrences on the command line, the precedence will be input file first, and output file second (i.e., bcpp infile.cpp outfile.cpp -lg), a third such occurrence will generate a error message.
If no output file is presented, its assumed output is via the standard output. This automatically turns off program output. Parameters entered on the command line will override parameters that have been read from the configuration file.
Example:
bcpp -fi input.cpp -f 2 -qb 5 -na -no -cc 60 > output.cpp
Synopsis
-fi input.cpp Input file = input.cpp
-f 2 Function spacing = 2
-qb 2 Internal Queue Buffer = 5
-na Remove non-ascii chars
-no Suppress program output
-cc 60 Comments that appear on same line as
code will be placed in column 60.
> output.cpp Output of program is redirected to
"output.cpp"
A configuration file can be used to specify most of the non- changing elements in reformatting of code. The configuration file consists of some fairly lengthy words that are used to explain the output style of the code. However setting these parameters is very easy, they basically consist of two types, Boolean, or Integer types. Using your favorite text editor, you can change the following within the configuration file ...
The following parameters will be contained within the configuration file (default is bcpp.cfg). The program will attempt to read the default configuration file at the program source (i.e. which path bcpp was run). Using the -fnc option you can define a custom configuration file name, and path from the CLI.
Integer Type Ranges : 0 - 5000 Boolean Type Ranges : On, Yes, or Off, No
e.g.,
function_spacing = 2
CLI
-f 2
e.g.,
use_tabs = no
CLI
-t (Turn tabs on, default uses spaces)
-s (Use tabs for indenting)
E.G.
indent_spacing = 4
CLI
-i 4
e.g.,
comments_with_code = 50
CLI
-cc 50
e.g.,
comments_with_nocode = 0
CLI
-nc 0
e.g.,
leave_comments_nocode = on
CLI
-nlcnc (Turn off Leave_Comments_NoCode)
-ylcnc (Turn on Leave_Comments_NoCode)
e.g.,
NonAscii_Quotes_to_Octal = no
CLI
-nq (Turn off non-ascii chars in quotes to octal)
-yq (Turn on non-ascii chars in quotes to octal)
E.G.
leave_graphic_chars = yes
CLI
-lg
e.g.,
ascii_chars_only = yes
CLI
-na (Do not remove non-ASCII characters)
-ya (Yes remove non-ASCII characters)
Pascal style C coding:
if (condition)
{
statements;
}
K&R style C coding:
if (condition) {
statements;
}
e.g.,
place_brace_on_new_line = on
CLI
-bnl (on )
-bcl (off)
E.G
program_output = off
CLI
-no (default is generate output if possible, this will
force output off)
-yo (turn on program output if possible)
e.g.,
Queue_Buffer = 2
CLI
-qb 2
e.g.,
backup_file = yes
CLI
-yb (yes, backup input file if possible)
-nb (no, do not backup input file)
Bcpp implements a configuration setting to allow custom file selection from a specific path/file defined by a user.
e.g.,
bcpp input.cpp -yb (read bcpp.cfg configuration file
before processing CLI options)
bcpp -fnc /bin/bcpp.cfg (load configuration file at
said location)
CLI
-fnc (use user defined)
E.G
bcpp -fi input.cpp > output.cpp
CLI
-fi
e.g.,
Has to be like this, (in DOS, at least):
bcpp -fo output.cpp < input.cpp
ClI
-fo
E.G bcpp -h
CLI bcpp -?
bcpp -h
If you enter a command/parameter incorrectly within the configuration file, upon the executable program reading it, the program will generate a error message along with its line number. The following is an explanation of error messages that may occur while reading parameters within the configuration file.
If any errors have occurred after reading the configuration file; the user is prompted with a [y/n] continuation prompt to either fix the configuration error(s) before processing, or continue with current set parameters.
This section highlights certain areas within code where bcpp will fail to reconstruct the output code to the desired style (although it may still be able to compile).
The example shows that the movements of the brace from the new line to the above code line will not take place as it would be out of scope for the program if the internal queue buffer is limited to 2 lines in size.
Example of brace movement scope:
if (a == b)
// Brace will not be re-positioned
{
b = c;
}
if (a == b) // Brace will be re-positioned
{
b = c;
}
End Result
if (a == b)
// Brace will not be re-positioned
{
b = c;
}
if (a == b){ // Brace will be re-positioned
b = c;
}
Example of multiple comments.
/* C Comment */ a = b; // C++ Comment
The above line will generate an error. Remedy this by removing one type of comment, combine them, or place one on a new line.
Written By Steven De Toni December 1995
Updated by Thomas Dickey January 1997-2002
You can contact Steven De Toni via various online networks:
Internet Address
tge@midland.co.nz
steve@alpha.ocbbs.gen.nz
Net Mail Via Fido-Net (Dog Net)
Steven De Toni,
"The Great Escape",
Hamilton,
New Zealand
Demi-Monde New Zealand National Mail Net Work
(see Dog Net)
If all else fails, send snail mail to:
17 Garden Heights Ave,
Melville,
Hamilton,
New Zealand
Thomas Dickey can be reached at
dickey@invisible-island.net
Special thanks goes out to Glyn Webster for proof reading my manual, and testing my program.
Thanks to Justin Slootsky for his input, and changes for this version.
All grammatical errors within this document are there for your enjoyment. ;-)
The authors give no guarantees that this program will function to the specifications given via the configuration, or the program's reconstructed output of source code that have been processed. Any damage that might arise from the use of this program (be it software, or hardware) is the problem of user, and not the authors. Using this software binds you to this disclaimer.=