~nickpapior/siesta/trunk-buds-format0.92

« back to all changes in this revision

Viewing changes to Src/buds/tools/update_file_settings.bash

  • Committer: Nick Papior
  • Date: 2017-04-07 12:42:28 UTC
  • Revision ID: nickpapior@gmail.com-20170407124228-u5t08yr2p4fhzfeo
Initial commit of buds merged into siesta

Currently I have only enabled buds compilation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
# Requirements:
 
4
#  GNU sed compilance (q-specifier)
 
5
 
 
6
# Author: Nick R. Papior, 2016
 
7
 
 
8
# This small script ensures a custom setting of
 
9
# variables for consistent editing of files across
 
10
# platforms and user-boxes.
 
11
#
 
12
# Essentially the script sets the design choices
 
13
# regarding the indentation and other settings.
 
14
 
 
15
# Each file has the settings at the end of the file
 
16
# The settings MUST be the last lines in each file.
 
17
 
 
18
_LINE_END="buds -- local file settings"
 
19
 
 
20
# Here are the fortran local variables
 
21
declare -A fv
 
22
for v in do if structure continuation associate \
 
23
                         critical program type
 
24
do
 
25
    fv["f90-$v-indent"]=2
 
26
done
 
27
 
 
28
function update_setting() {
 
29
    # Set settings in this file:
 
30
    local f=$1
 
31
    shift
 
32
    local ftype=fortran
 
33
 
 
34
    function clean_tmp() {
 
35
        rm -f .tmp_file
 
36
    }
 
37
 
 
38
    # We use this fixed file-name...
 
39
    # I hardly think anybody would like to
 
40
    # seriously create a file named this
 
41
    sed -e "/$_LINE_END/Q" $f > .tmp_file
 
42
 
 
43
    {
 
44
    case $ftype in
 
45
        fortran)
 
46
            echo "! project-$_LINE_END"
 
47
            echo "!     Anything below this line may be overwritten by scripts"
 
48
            echo "!     Below are non-editable settings"
 
49
            ;;
 
50
    esac
 
51
    # Empty line
 
52
    echo ""
 
53
    case $ftype in
 
54
        fortran)
 
55
            echo "! Local Variables:"
 
56
            # Note that if users override the f90
 
57
            # format name, we cannot do anything about it...
 
58
            echo "!  mode: f90"
 
59
            for key in ${!fv[@]}
 
60
            do
 
61
                echo "!  $key: ${fv[$key]}"
 
62
            done
 
63
            echo "! End:"
 
64
            ;;
 
65
        *)
 
66
            echo "Error, could not figure out file type"
 
67
            clean_tmp
 
68
            exit 0
 
69
            ;;
 
70
    esac
 
71
    echo ""
 
72
    } >> .tmp_file
 
73
    mv .tmp_file $f
 
74
}
 
75
 
 
76
 
 
77
for d in $@
 
78
do
 
79
    while read f
 
80
    do
 
81
        f=${f// /}
 
82
        [ -z "${f}" ] && continue
 
83
        update_setting $d/$f
 
84
    done < $d/files.fortran
 
85
done