source: tags/libIGCM_v1/libIGCM_card/IGCM_card_PrintOption.awk @ 484

Last change on this file since 484 was 2, checked in by mmaipsl, 16 years ago

MM: import first trunk version of libIGCM.

File size: 2.7 KB
Line 
1#!/usr/bin/awk -f
2
3#**************************************************************
4# Author: Patrick Brockmann
5# Contact: Patrick.Brockmann@cea.fr
6# $Date: 2006/12/22 15:26:28 $
7# $Name: libIGCM_v1 $
8# $Revision: 1.3 $
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#==========================
17function myprint(str) {
18        if (debug) {
19                print str
20        }
21}
22
23#==========================
24BEGIN {
25
26nbarg=ARGC
27if (match(ARGV[1],"-d")) {
28        debug=1
29        file=ARGV[2]
30        section=ARGV[3]
31        option=ARGV[4]
32        delete ARGV[1] ; delete ARGV[3] ; delete ARGV[4]
33        nbarg--
34} else {
35        debug=0
36        file=ARGV[1]
37        section=ARGV[2]
38        option=ARGV[3]
39        delete ARGV[2] ; delete ARGV[3]
40}
41
42# When exit statement, 'END' rule is always executed, so defined a exit_value to manage this
43exit_value=0
44if (nbarg != 4) {
45        print "Usage: IGCM_card_PrintOption [-d] file section option" 
46        print 
47        print "Args:"
48        print "      file = file at CARD format" 
49        print "      section = section to find" 
50        print "      option = option to find" 
51        print 
52        print "Options:" 
53        print "       -d = debug mode" 
54        print 
55        exit_value=1
56        exit
57}
58
59section_found=0
60option_found=0
61
62}
63
64#==========================
65{
66
67myprint($0) 
68
69# Do not consider commented lines (#...)
70if (! match($0,/^#/)) {
71
72# Find section with delimiters '[' and ']'
73if (match($0, "\\[" section "\\]")) {
74
75        myprint("---->section found")
76        section_found=1
77
78} else if (section_found == 1 && (match($0, option "[ ]*="))) {
79
80        myprint("---->option found")
81        option_found=1
82       
83        # Extract string after '='
84        option_value=substr($0, index($0, "=")+1)
85
86        # Remove space after '='
87        gsub(/^[ ]*/, "", option_value)
88
89        # If continuation character '\' get next lines
90        if (match($0,/\\$/)) {
91                tmp=$0
92                tmp=substr(tmp, 1, length(tmp)-1)
93                gsub(/[ \t]*/, "", tmp)
94                option_value=tmp
95                getline tmp
96                while (match(tmp,/\\$/)) {
97                        tmp=substr(tmp, 1, length(tmp)-1)
98                        gsub(/[ \t]*/, "", tmp)
99                        option_value=option_value " " tmp
100                        getline tmp 
101                        }
102                gsub(/[ \t]*/, "", tmp)
103                option_value=option_value " " tmp
104        }
105
106        exit
107
108} else if (section_found == 1 && match($0, /^[\[*\]]/)) {
109
110        myprint("---->end section")
111        exit
112
113}
114
115}
116
117}
118
119#==========================
120END {
121
122if (! exit_value ) {
123
124myprint("###############################")
125myprint("section      ====> " section)
126myprint("option       ====> " option)
127myprint("value        ====> " option_value)
128
129if (section_found == 0) {
130        print "Error: Section not found"
131} else if (option_found == 0) {
132        print "Error: Option not found"
133} else {
134        print option_value
135}
136
137}
138
139}
140 
141#==========================
Note: See TracBrowser for help on using the repository browser.