[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 | delete ARGV[1] ; delete ARGV[3] |
---|
| 28 | nbarg-- |
---|
| 29 | } else { |
---|
| 30 | debug=0 |
---|
| 31 | file=ARGV[1] |
---|
| 32 | section=ARGV[2] |
---|
| 33 | delete ARGV[2] |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | # When exit statement, 'END' rule is always executed, so defined a exit_value to manage this |
---|
| 37 | exit_value=0 |
---|
| 38 | if (nbarg != 3) { |
---|
[7] | 39 | print "Usage: IGCM_card_PrintSection [-d] file section" |
---|
[2] | 40 | print |
---|
| 41 | print "Args:" |
---|
| 42 | print " file = file at CARD format" |
---|
| 43 | print " section = section to find" |
---|
| 44 | print |
---|
| 45 | print "Options:" |
---|
| 46 | print " -d = debug mode" |
---|
| 47 | print |
---|
| 48 | exit_value=1 |
---|
| 49 | exit |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | section_found=0 |
---|
| 53 | option_list="null" |
---|
| 54 | |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | #========================== |
---|
| 58 | { |
---|
| 59 | |
---|
| 60 | myprint($0) |
---|
| 61 | |
---|
| 62 | # Do not consider commented lines (#...) |
---|
| 63 | if (! match($0,/^#/)) { |
---|
| 64 | |
---|
| 65 | # Find section with delimiters '[' and ']' |
---|
| 66 | if (match($0, "\\[" section "\\]")) { |
---|
| 67 | |
---|
| 68 | myprint("---->section found") |
---|
| 69 | section_found=1 |
---|
| 70 | |
---|
| 71 | } else if (section_found == 1 && (match($0, "[.]*="))) { |
---|
| 72 | |
---|
| 73 | myprint("---->option found") |
---|
| 74 | |
---|
| 75 | # Extract string after '=' |
---|
| 76 | option_value=substr($0, 1, index($0, "=")-1) |
---|
| 77 | |
---|
| 78 | # Remove space before '=' |
---|
| 79 | gsub(/[ ]*/, "", option_value) |
---|
| 80 | |
---|
| 81 | # Add options |
---|
| 82 | # If 1st option |
---|
| 83 | if (match(option_list,"null")) { |
---|
| 84 | option_list=option_value |
---|
| 85 | } else { |
---|
| 86 | option_list=option_list " " option_value |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | } else if (section_found == 1 && match($0, /^[\[*\]]/)) { |
---|
| 90 | |
---|
| 91 | myprint("---->end section") |
---|
| 92 | exit |
---|
| 93 | |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | #========================== |
---|
| 101 | END { |
---|
| 102 | |
---|
| 103 | if (! exit_value ) { |
---|
| 104 | |
---|
| 105 | myprint("###############################") |
---|
| 106 | myprint("section ====> " section) |
---|
| 107 | |
---|
| 108 | if (section_found == 0) { |
---|
| 109 | print "Error: Section not found" |
---|
| 110 | } else if (match(option_list,"null")) { |
---|
[475] | 111 | print "Error: Option not found" |
---|
[2] | 112 | } else { |
---|
| 113 | print option_list |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | #========================== |
---|