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