File indexing completed on 2024-11-24 03:56:08
0001 #!/bin/bash 0002 # 0003 # SPDX-FileCopyrightText: 2013-2023 Mattia Basaglia 0004 # SPDX-License-Identifier: LGPL-3.0-or-later 0005 # 0006 # This program is free software: you can redistribute it and/or modify 0007 # it under the terms of the GNU Lesser General Public License as published by 0008 # the Free Software Foundation, either version 3 of the License, or 0009 # (at your option) any later version. 0010 # 0011 # This program is distributed in the hope that it will be useful, 0012 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 # GNU Lesser General Public License for more details. 0015 # 0016 # You should have received a copy of the GNU Lesser General Public License 0017 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 0019 ################################################################################ 0020 # This script is to refactor the old class names to the new ones # 0021 # eg: occurrences of Color_Dialog become color_widgets::ColorDialog # 0022 # This script does very simple text replacements and overwrites existing files # 0023 # Use with care # 0024 # Usage: # 0025 # ./refactor.sh /path/to/sources # 0026 # # 0027 ################################################################################ 0028 0029 old_classes=( 0030 Color_Delegate 0031 Color_Dialog 0032 Color_List_Widget 0033 Color_Preview 0034 Color_Selector 0035 Color_Wheel 0036 Gradient_Slider 0037 Hue_Slider 0038 ) 0039 old_enums=( 0040 Button_Mode 0041 Display_Mode 0042 Update_Mode 0043 Display_Enum 0044 Display_Flags 0045 ) 0046 file_extensions=( 0047 ui 0048 cpp 0049 hpp 0050 C 0051 H 0052 h 0053 cxx 0054 hxx 0055 ) 0056 0057 0058 function new_class_name() 0059 { 0060 echo "$1" | sed -e 's/_//g' -r -e 's/^/color_widgets::/' 0061 } 0062 0063 0064 function new_enum_name() 0065 { 0066 echo "$1" | sed -e 's/_//g' 0067 } 0068 0069 directory="$1" 0070 0071 if [ -z "$directory" ] 0072 then 0073 echo "Usage: $0 (directory)" 0074 exit 1 0075 fi 0076 0077 find_extensions="" 0078 for ext in ${file_extensions[@]} 0079 do 0080 find_extensions="$find_extensions -o -name '*.$ext'" 0081 done 0082 find_extensions="$(echo "$find_extensions" | sed -r 's/ -o //')" 0083 find_command="find \""$directory"\" -type f -a \( $find_extensions \) -print" 0084 0085 files="$(bash -c "$find_command")" 0086 0087 replacements="" 0088 for class in ${old_classes[@]} 0089 do 0090 replacements="$replacements $class $(new_class_name $class)" 0091 done 0092 for enum in ${old_enums[@]} 0093 do 0094 replacements="$replacements $enum $(new_enum_name $enum)" 0095 done 0096 0097 for file in $files 0098 do 0099 replace $replacements -- "$file" 0100 done