📄 astyle_main.cpp
字号:
// $Id: astyle_main.cpp,v 1.2 2005/07/01 18:58:17 mandrav Exp $
// --------------------------------------------------------------------------
//
// Copyright (C) 1998,1999,2000,2001,2002 Tal Davidson.
// Copyright (C) 2004 Martin Baute.
// All rights reserved.
//
// This file is a part of "Artistic Style" - an indentation and reformatting
// tool for C, C++, C# and Java source files - http://astyle.sourceforge.net
//
// --------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// --------------------------------------------------------------------------
#include "astyle.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <sstream>
#include <stdio.h>
using namespace std;
using namespace astyle;
// default options:
ostream *_err = &cerr;
string _suffix = ".orig";
bool shouldBackupFile = true;
ostringstream msg;
const string _version = "1.17.0-dev";
// --------------------------------------------------------------------------
// Helper Functions
// --------------------------------------------------------------------------
bool parseOption(ASFormatter &formatter, const string &arg, const string &errorInfo)
{
TRACE( INFO, "Parsing option '" << arg << "'." );
if ( ( arg == "n" ) || ( arg == "suffix=none" ) )
{
TRACE( INFO, "suffix=none" );
shouldBackupFile = false;
}
else if ( BEGINS_WITH(arg, "suffix=", 7) )
{
string suffixParam = arg.substr(strlen("suffix="));
TRACE( INFO, "suffix=" << suffixParam );
if (suffixParam.size() > 0)
_suffix = suffixParam;
}
else if ( arg == "style=ansi" )
{
TRACE( INFO, "style=ansi" );
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
formatter.bracketFormatMode = BREAK_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = false;
}
else if ( arg == "style=gnu" )
{
TRACE( INFO, "style=gnu" );
formatter.blockIndent = true;
formatter.bracketIndent = false;
formatter.indentLength = 2;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
formatter.bracketFormatMode = BREAK_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = false;
}
else if ( arg == "style=java" )
{
TRACE( INFO, "style=java" );
formatter.sourceStyle = STYLE_JAVA;
formatter.modeSetManually = true;
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
formatter.bracketFormatMode = ATTACH_MODE;
formatter.switchIndent = false;
}
else if ( arg == "style=kr" )
{
//formatter.sourceStyle = STYLE_C;
//formatter.modeSetManually = true;
TRACE( INFO, "style=kr" );
formatter.bracketIndent = false;
formatter.indentLength = 4;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
formatter.bracketFormatMode = ATTACH_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = false;
}
else if ( arg == "style=linux" )
{
TRACE( INFO, "style=linux" );
formatter.bracketIndent = false;
formatter.indentLength = 8;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
formatter.bracketFormatMode = BDAC_MODE;
formatter.classIndent = false;
formatter.switchIndent = false;
formatter.namespaceIndent = false;
}
else if ( (arg == "c") || (arg == "mode=c") )
{
TRACE( INFO, "mode=c" );
formatter.sourceStyle = STYLE_C;
formatter.modeSetManually = true;
}
else if ( (arg == "j") || (arg == "mode=java") )
{
TRACE( INFO, "mode=java" );
formatter.sourceStyle = STYLE_JAVA;
formatter.modeSetManually = true;
}
else if ( arg == "mode=csharp" )
{
TRACE( INFO, "mode=csharp" );
formatter.sourceStyle = STYLE_CSHARP;
formatter.modeSetManually = true;
}
else if ( ( arg == "w" ) || ( arg == "eol=win" ) )
{
TRACE( INFO, "eol=win" );
formatter.eolString = "\r\n"; // not yet implemented!
}
else if ( ( arg == "x" ) || ( arg == "eol=unix" ) )
{
TRACE( INFO, "eol=unix" );
formatter.eolString = "\n"; // not yet implemented!
}
else if ( arg == "eol=mac" )
{
TRACE( INFO, "eol=mac" );
formatter.eolString = "\r"; // not yet implemented!
}
else if ( arg == "indent=tab" )
{
TRACE( INFO, "indent=tab" );
formatter.indentString = "\t";
formatter.indentLength = 4;
formatter.forceTabIndent = false;
if ( formatter.minConditionalIndent == INT_MAX )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
}
else if ( arg == "indent=spaces" )
{
TRACE( INFO, "indent=spaces" );
formatter.indentLength = 4;
formatter.indentString = " ";
if ( formatter.minConditionalIndent == INT_MIN )
{
formatter.minConditionalIndent = formatter.indentLength * 2;
}
}
else if ( (arg == "B") || (arg == "indent-brackets") )
{
TRACE( INFO, "indent-brackets" );
formatter.bracketIndent = true;
}
else if ( (arg == "G") || (arg == "indent-blocks") )
{
TRACE( INFO, "indent-blocks" );
formatter.blockIndent = true;
formatter.bracketIndent = false;
}
else if ( (arg == "N") || (arg == "indent-namespaces") )
{
TRACE( INFO, "indent-namespaces" );
formatter.namespaceIndent = true;
}
else if ( (arg == "C") || (arg == "indent-classes") )
{
TRACE( INFO, "indent-classes" );
formatter.classIndent = true;
}
else if ( (arg == "S") || (arg == "indent-switches") )
{
TRACE( INFO, "indent-switches" );
formatter.switchIndent = true;
}
else if ( (arg == "K") || (arg == "indent-cases") )
{
TRACE( INFO, "indent-cases" );
formatter.caseIndent = true;
}
else if ( (arg == "L") || (arg == "indent-labels") )
{
TRACE( INFO, "indent-labels" );
formatter.labelIndent = true;
}
else if (arg == "indent-preprocessor")
{
TRACE( INFO, "indent-preprocessor" );
formatter.preprocessorIndent = true;
}
else if ( arg == "brackets=break-closing-headers" )
{
TRACE( INFO, "brackets=break-closing-headers" );
formatter.breakClosingHeaderBrackets = true;
}
else if ( (arg == "b") || (arg == "brackets=break") )
{
TRACE( INFO, "brackets=break" );
formatter.bracketFormatMode = BREAK_MODE;
}
else if ( (arg == "a") || (arg == "brackets=attach") )
{
TRACE( INFO, "brackets=attach" );
formatter.bracketFormatMode = ATTACH_MODE;
}
else if ( (arg == "l") || (arg == "brackets=linux") )
{
TRACE( INFO, "brackets=linux" );
formatter.bracketFormatMode = BDAC_MODE;
}
else if ( (arg == "O") || (arg == "one-line=keep-blocks") )
{
TRACE( INFO, "one-line=keep-blocks" );
formatter.breakOneLineBlocks = false;
}
else if ( (arg == "o") || (arg == "one-line=keep-statements") )
{
TRACE( INFO, "one-line=keep-statements" );
formatter.breakOneLineStatements = false;
}
else if ( arg == "pad=paren" )
{
TRACE( INFO, "pad=paren" );
formatter.padParen = true;
}
else if ( (arg == "P") || (arg == "pad=all") )
{
TRACE( INFO, "pad=all" );
formatter.padOperators = true;
formatter.padParen = true;
}
else if ( (arg == "p") || (arg == "pad=oper") )
{
TRACE( INFO, "pad=oper" );
formatter.padOperators = true;
}
else if ( (arg == "E") || (arg == "fill-empty-lines") )
{
TRACE( INFO, "fill-empty-lines" );
formatter.emptyLineIndent = true;
}
else if (arg == "convert-tabs")
{
TRACE( INFO, "convert-tabs" );
formatter.convertTabs2Space = true;
}
else if (arg == "break-blocks=all")
{
TRACE( INFO, "break-blocks=all" );
formatter.breakBlocks = true;
formatter.breakClosingHeaderBlocks = true;
}
else if (arg == "break-blocks")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -