Skip to content

Instantly share code, notes, and snippets.

@joshbooks
Last active May 18, 2019 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbooks/d75c167d0254db06d3057d9fcf6dbe31 to your computer and use it in GitHub Desktop.
Save joshbooks/d75c167d0254db06d3057d9fcf6dbe31 to your computer and use it in GitHub Desktop.
push down automaton wrapped in some crazy bash magic
serviceDefinition=`sed -f "remccoms3.sed" "$file" | sed '/^[[:space:]]$/d' | uniq | awk '/service[[:space:]]*'"$service"'/ {beginLine=NR} beginLine > 0 && NR >= beginLine {depth += gsub("{",""); depth -= gsub("}","")} depth > 0 && beginLine < NR {print} beginLine > 0 && depth == 0 {exit}'`
#! /bin/sed -nf
# Remove C and C++ comments, by Brian Hiles (brian_hiles@rocketmail.com)
# Sped up (and bugfixed to some extent) by Paolo Bonzini (bonzini@gnu.org)
# Works its way through the line, copying to hold space the text up to the
# first special character (/, ", '). The original version went exactly a
# character at a time, hence the greater speed of this one. But the concept
# and especially the trick of building the line in hold space are entirely
# merit of Brian.
:loop
# This line is sufficient to remove C++ comments!
/^\/\// s,.*,,
/^$/{
x
p
n
b loop
}
/^"/{
:double
/^$/{
x
p
n
/^"/b break
b double
}
H
x
s,\n\(.[^\"]*\).*,\1,
x
s,.[^\"]*,,
/^"/b break
/^\\/{
H
x
s,\n\(.\).*,\1,
x
s/.//
}
b double
}
/^'/{
:single
/^$/{
x
p
n
/^'/b break
b single
}
H
x
s,\n\(.[^\']*\).*,\1,
x
s,.[^\']*,,
/^'/b break
/^\\/{
H
x
s,\n\(.\).*,\1,
x
s/.//
}
}
b single
}
/^\/\*/{
s/.//
:ccom
s,^.[^*]*,,
/^$/ n
/^\*\//{
s/..//
b loop
}
b ccom
}
:break
H
x
s,\n\(.[^"'/]*\).*,\1,
x
s/.[^"'/]*//
b loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment