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