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