renamed ll to lastline, hope its now clear what the var is for ..

This commit is contained in:
Daniel Heule 2014-03-26 13:58:29 +01:00
parent bae472eb33
commit 50316902e3

View file

@ -1,5 +1,3 @@
#!/bin/sh
export key="$(cat "$__object/parameter/key" 2>/dev/null \ export key="$(cat "$__object/parameter/key" 2>/dev/null \
|| echo "$__object_id")" || echo "$__object_id")"
export state="$(cat "$__object/parameter/state")" export state="$(cat "$__object/parameter/state")"
@ -32,8 +30,8 @@ BEGIN {
comment=ENVIRON["comment"] comment=ENVIRON["comment"]
exact_delimiter=ENVIRON["exact_delimiter"] exact_delimiter=ENVIRON["exact_delimiter"]
inserted=0 inserted=0
ll="" lastline=""
llpopulated=0 lastlinepopulated=0
line=key delimiter value line=key delimiter value
} }
# enter the main loop # enter the main loop
@ -49,52 +47,52 @@ BEGIN {
if( length(spaces) > 0 ) { if( length(spaces) > 0 ) {
# if there are not only spaces between key and delimiter, # if there are not only spaces between key and delimiter,
# continue since we we are on the wrong line # continue since we we are on the wrong line
if(llpopulated == 1) { if(lastlinepopulated == 1) {
print ll print lastline
} }
ll=$0 lastline=$0
llpopulated=1 lastlinepopulated=1
next next
} }
} }
if(state == "absent") { if(state == "absent") {
if(ll == comment) { if(lastline == comment) {
# if comment is present, clear llpopulated flag # if comment is present, clear lastlinepopulated flag
llpopulated=0 lastlinepopulated=0
} }
# if absent, simple yump over this line # if absent, simple yump over this line
next next
} }
else { else {
# if comment is present and not present in last line # if comment is present and not present in last line
if (llpopulated == 1) { if (lastlinepopulated == 1) {
print ll print lastline
if( comment != "" && ll != comment) { if( comment != "" && lastline != comment) {
print comment print comment
} }
llpopulated=0 lastlinepopulated=0
} }
inserted=1 inserted=1
# state is present, so insert correct line here # state is present, so insert correct line here
print line print line
ll=line lastline=line
next next
} }
} }
else { else {
if(llpopulated == 1) { if(lastlinepopulated == 1) {
print ll print lastline
} }
ll=$0 lastline=$0
llpopulated=1 lastlinepopulated=1
} }
} }
END { END {
if(llpopulated == 1) { if(lastlinepopulated == 1) {
print ll print lastline
} }
if(inserted == 0 && state == "present" ) { if(inserted == 0 && state == "present" ) {
if(comment != "" && ll != comment){ if(comment != "" && lastline != comment){
print comment print comment
} }
print line print line