-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1086 from dictoon/master
Refactorings
- Loading branch information
Showing
162 changed files
with
538 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/python | ||
|
||
# | ||
# This source file is part of appleseed. | ||
# Visit http://appleseedhq.net/ for additional information and resources. | ||
# | ||
# This software is released under the MIT license. | ||
# | ||
# Copyright (c) 2016 Francois Beaune, The appleseedhq Organization | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
|
||
#-------------------------------------------------------------------------------------------------- | ||
# Processing code. | ||
#-------------------------------------------------------------------------------------------------- | ||
|
||
def process_file(filepath): | ||
print("processing {0}...".format(filepath)) | ||
|
||
with open(filepath) as f: | ||
lines = f.readlines() | ||
|
||
section_begin = -1 | ||
|
||
for index in range(len(lines)): | ||
line = lines[index] | ||
|
||
if section_begin == -1 and line.startswith("#include"): | ||
section_begin = index | ||
|
||
if section_begin != -1 and line in ["\n", "\r\n"]: | ||
if all(clause.startswith("#include") for clause in lines[section_begin:index]): | ||
lines[section_begin:index] = sorted(lines[section_begin:index]) | ||
section_begin = -1 | ||
|
||
with open(filepath + ".processed", "wt") as f: | ||
for line in lines: | ||
f.write(line) | ||
|
||
os.remove(filepath) | ||
os.rename(filepath + ".processed", filepath) | ||
|
||
def process_recursively(): | ||
for dirpath, dirnames, filenames in os.walk("."): | ||
for filename in filenames: | ||
ext = os.path.splitext(filename)[1] | ||
if ext == ".h" or ext == ".cpp": | ||
process_file(os.path.join(dirpath, filename)) | ||
|
||
|
||
#-------------------------------------------------------------------------------------------------- | ||
# Entry point. | ||
#-------------------------------------------------------------------------------------------------- | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="sort #include clauses in c++ source code.") | ||
parser.add_argument("-r", "--recursive", action='store_true', dest='recursive', | ||
help="process all files in the specified directory and all its subdirectories") | ||
parser.add_argument("filepath", nargs="?", help="file to process") | ||
args = parser.parse_args() | ||
|
||
if args.filepath: | ||
if args.recursive: | ||
print("cannot simultaneously specify a file path and use the --recursive flag.") | ||
sys.exit(1) | ||
print(args.filepath) | ||
else: | ||
if not args.recursive: | ||
print("either a file path or the --recursive flag must be specified.") | ||
sys.exit(1) | ||
process_recursively() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
// | ||
// This source file is part of appleseed. | ||
// Visit http://appleseedhq.net/ for additional information and resources. | ||
// | ||
// This software is released under the MIT license. | ||
// | ||
// Copyright (c) 2016 Francois Beaune, The appleseedhq Organization | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
// Interface header. | ||
#include "apistring.h" | ||
|
||
namespace foundation | ||
{ | ||
|
||
APIString::APIString(const char* s) | ||
: m_s(duplicate_string(s)) | ||
{ | ||
} | ||
|
||
APIString::APIString(const APIString& rhs) | ||
: m_s(duplicate_string(rhs.m_s)) | ||
{ | ||
} | ||
|
||
APIString::~APIString() | ||
{ | ||
free_string(m_s); | ||
} | ||
|
||
const char* APIString::c_str() const | ||
{ | ||
return m_s; | ||
} | ||
|
||
} // namespace foundation |
Oops, something went wrong.