Changeset 6023
- Timestamp:
- Jan 13, 2026, 2:43:17 PM (4 days ago)
- File:
-
- 1 edited
-
LMDZ6/trunk/tools/format_code.sh (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/trunk/tools/format_code.sh
r6010 r6023 4 4 # a common and unified format 5 5 # it works in 1 or 2 steps: 6 # 1/an optional preprocessing step with findent 6 # 1/an optional preprocessing step with findent (if_findent) 7 7 # (more robust for code structuration) 8 8 # 2/a formatting step with fprettify using a .fprettify format file … … 10 10 # if findent or fprettify displays an error or warning message, 11 11 # the file is not processed 12 # how to use: 13 # ./format_code.sh "file1 file2 file3" 12 14 # v1: November 2025 13 15 #----------------------------------------------------------------- … … 16 18 # List of files to process 17 19 #------------------------------------------------------------------ 18 files_to_process=( $(find ../libf/*/* -maxdepth 0 -type f ! -xtype l \( -name "*.f90" -o -name "*.F90" \)) ) 20 #files_to_process=( $(find ../libf/*/*blowing* -maxdepth 0 -type f ! -xtype l \( -name "*.f90" -o -name "*.F90" \)) ) 21 22 files_to_process="$1" 19 23 20 24 # Check installation of findent and fprettify … … 45 49 echo "the file $FILENAME already exists" 46 50 else 51 echo "I create the file $FILENAME " 52 47 53 # create the file 48 54 cat << 'EOF' > "$FILENAME" 49 # --- Indentation --- 50 indent = 4 # 4-space indentation (standard practice) 51 indent_cont = 6 # continuation lines more indented for clarity 52 tabindent = false # always use spaces, never tabs 55 # ========================= 56 # fprettify configuration 57 # ========================= 53 58 54 # --- Line formatting --- 55 max_line_length = 200 # good default for modern screens 56 whitespace = true # trim trailing whitespace 57 whitespace_statements = true 58 whitespace_operators = true # enforce spaces around operators 59 compact = false # do not compact everything (more readable) 59 # Indentation (number of spaces) 60 indent = 3 60 61 61 # --- Keywords --- 62 case_keywords = lower # lowercase keywords (if, do, end, module) 63 case_intrinsics = lower # lowercase intrinsics (sin, cos, abs) 64 case_types = preserve # preserve user-defined type casing 62 # Maximum line length 63 line-length = 200 65 64 66 # --- Logical formatting --- 67 split_multiline_statements = true # break long statements 68 align_assignments = true # align "=" signs vertically 69 align_continuation = true 65 # Indent internal blocks (do, if, select case…) 66 indent-blocks = true 70 67 71 # --- Operators --- 72 space_in_percents = false # Fortran % operator (component), no spaces 73 space_in_power = false # no spaces around exponent (**) 74 space_in_colons = false # array slices remain compact (i:j) 75 space_in_parentheses = false 68 # Add whitespace around operators (=, +, -, *, /, etc.) 69 whitespace = true 76 70 77 # --- Comments --- 78 keep_comments = true 79 align_comments = true # align trailing comments 80 comment_indent = 2 71 # Keyword normalization (lowercase or uppercase) 72 case = [2,2,2,2] 81 73 82 # --- Preprocessing --- 83 cpp_keywords = true # format #ifdef / #define blocks 84 preserve_cpp_indentation = true 74 # Reformat declarations (type :: variable) 75 reformat-declarations = true 85 76 86 # --- Safety --- 87 strict_indent = true # fail on inconsistent indentation 88 ignore_old_style = false # do not preserve ugly fixed-format legacy stuff 77 # Align variable declarations 78 align-declarations = true 89 79 80 # Align consecutive assignments 81 align-assignments = true 82 83 # Align arguments in multi-line calls 84 align-arguments = true 85 86 # Preserve comments as-is 87 preserve-comments = true 88 89 # Do not modify string literals 90 preserve-strings = true 91 92 # Reformat line continuations (&) 93 reformat-continuations = true 94 95 # Reformat USE statements 96 reformat-use-statements = true 97 98 # Allow inline formatting control 99 # (via ! fprettify: off / on) 100 enable-inline-control = true 90 101 EOF 91 102 fi … … 104 115 tmp=$(mktemp) || return 1 105 116 106 local patterns=" warning|error|failed|deprecated"117 local patterns="error" 107 118 local err 108 119 local ret … … 110 121 cp "$f" "$tmp" 111 122 112 # # Step 1: findent 113 # rm "$tmp" 114 # err=$(findent < "$f" 2>&1) 115 # ret=$? 116 # if [ $ret -ne 0 ] || echo "$err" | grep -Eqi "$patterns"; then 117 # echo "findent detected WARNING/ERROR in $f" 118 # rm -f "$tmp" 119 # return 1 120 # fi 121 # findent < "$f" > "$tmp" 2>/dev/null 123 # Step 1: findent 124 if_findent=0 125 if [ "$if_findent" -eq 1 ]; then 126 rm "$tmp" 127 err=$(findent < "$f" 2>&1) 128 ret=$? 129 if [ $ret -ne 0 ] || echo "$err" | grep -Eqi "$patterns"; then 130 echo "findent detected ERROR in $f" 131 echo $err 132 #rm -f "$tmp" 133 return 1 134 fi 135 findent < "$f" > "$tmp" 2>/dev/null 136 fi 122 137 123 124 # Step 2: fprettify 125 err=$(fprettify "$tmp" 2>&1) 138 # Step 2: fprettify 139 err=$(fprettify "$tmp" 2>&1) 126 140 ret=$? 127 141 if [ $ret -ne 0 ] || echo "$err" | grep -Eqi "$patterns"; then 128 echo "fprettify detected WARNING/ERROR in $f" 129 rm -f "$tmp" 142 echo "fprettify detected ERROR in $f" 143 echo "$err" 144 #rm -f "$tmp" 130 145 return 1 131 146 fi
Note: See TracChangeset
for help on using the changeset viewer.
