[2] | 1 | #************************************************************** |
---|
| 2 | # Author: Patrick Brockmann |
---|
| 3 | # Contact: Patrick.Brockmann@cea.fr |
---|
[4] | 4 | # $Date$ |
---|
[5] | 5 | # $Author$ |
---|
| 6 | # $Revision$ |
---|
[2] | 7 | # IPSL (2006) |
---|
| 8 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 9 | # History: |
---|
| 10 | # Modification: |
---|
| 11 | # |
---|
| 12 | #************************************************************** |
---|
| 13 | |
---|
| 14 | #========================== |
---|
| 15 | function myprint(str) { |
---|
| 16 | if (debug) { |
---|
| 17 | print str |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | #========================== |
---|
| 22 | BEGIN { |
---|
| 23 | |
---|
| 24 | nbarg=ARGC |
---|
| 25 | if (match(ARGV[1],"-d")) { |
---|
| 26 | debug=1 |
---|
| 27 | file=ARGV[2] |
---|
| 28 | section=ARGV[3] |
---|
| 29 | option=ARGV[4] |
---|
| 30 | value=ARGV[5] |
---|
| 31 | delete ARGV[1] ; delete ARGV[3] ; delete ARGV[4] ; delete ARGV[5] |
---|
| 32 | nbarg-- |
---|
| 33 | } else { |
---|
| 34 | debug=0 |
---|
| 35 | file=ARGV[1] |
---|
| 36 | section=ARGV[2] |
---|
| 37 | option=ARGV[3] |
---|
| 38 | value=ARGV[4] |
---|
| 39 | delete ARGV[2] ; delete ARGV[3] ; delete ARGV[4] |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | # When exit statement, 'END' rule is always executed, so defined a exit_value to manage this |
---|
| 44 | exit_value=0 |
---|
| 45 | if (nbarg != 5) { |
---|
| 46 | print "Usage: IGCM_card_WriteOption [-d] file section option value" |
---|
| 47 | print |
---|
| 48 | print "Args:" |
---|
| 49 | print " file = file at CARD format" |
---|
| 50 | print " section = section to find" |
---|
| 51 | print " option = option to find" |
---|
| 52 | print " value = value option to write" |
---|
| 53 | print |
---|
| 54 | print "Options:" |
---|
| 55 | print " -d = debug mode" |
---|
| 56 | print |
---|
| 57 | exit_value=1 |
---|
| 58 | exit |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | section_found=0 |
---|
| 62 | section_inside=0 |
---|
| 63 | option_found=0 |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | #========================== |
---|
| 67 | { |
---|
| 68 | |
---|
| 69 | myprint($0) |
---|
| 70 | |
---|
| 71 | # Find section with delimiters '[' and ']' |
---|
| 72 | if (match($0, "\\[" section "\\]")) { |
---|
| 73 | |
---|
| 74 | myprint("---->section found") |
---|
| 75 | section_found=1 |
---|
| 76 | section_inside=1 |
---|
| 77 | print $0 |
---|
| 78 | |
---|
| 79 | } else if (section_inside == 1 && (match($0, "^[ ]*" option "[ ]*="))) { |
---|
| 80 | |
---|
| 81 | myprint("---->option found") |
---|
| 82 | option_found=1 |
---|
| 83 | |
---|
| 84 | print option "= " value |
---|
| 85 | myprint("---->new value ") |
---|
| 86 | |
---|
| 87 | } else if (section_inside == 1 && match($0, /^[\[*\]]/)) { |
---|
| 88 | |
---|
| 89 | myprint("---->end section") |
---|
| 90 | section_inside=0 |
---|
| 91 | print $0 |
---|
| 92 | |
---|
| 93 | } else { |
---|
| 94 | print $0 |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | #========================== |
---|
| 100 | END { |
---|
| 101 | |
---|
[23] | 102 | if (! exit_value ) { |
---|
[2] | 103 | |
---|
[23] | 104 | myprint("###############################") |
---|
| 105 | myprint("section ====> " section) |
---|
| 106 | myprint("option ====> " option) |
---|
| 107 | myprint("value ====> " value) |
---|
| 108 | |
---|
| 109 | if (section_found == 0) { |
---|
| 110 | print "Error: Section not found", section, option |
---|
| 111 | } else if (option_found == 0) { |
---|
| 112 | print "Error: Option not found", section, option |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | } else { |
---|
[2] | 116 | |
---|
[23] | 117 | print "Error in with IGCM_WriteOption : ", section, option |
---|
[2] | 118 | |
---|
[23] | 119 | } |
---|
[2] | 120 | |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | #========================== |
---|