<s> import sys <EOL> import getopt <EOL> defs = [ ] <EOL> undefs = [ ] <EOL> def main ( ) : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> for o , a in opts : <EOL> if o == '<STR_LIT>' : <EOL> defs . append ( a ) <EOL> if o == '<STR_LIT>' : <EOL> undefs . append ( a ) <EOL> if not args : <EOL> args = [ '<STR_LIT:->' ] <EOL> for filename in args : <EOL> if filename == '<STR_LIT:->' : <EOL> process ( sys . stdin , sys . stdout ) <EOL> else : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> process ( f , sys . stdout ) <EOL> f . close ( ) <EOL> def process ( fpi , fpo ) : <EOL> keywords = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ok = <NUM_LIT:1> <EOL> stack = [ ] <EOL> while <NUM_LIT:1> : <EOL> line = fpi . readline ( ) <EOL> if not line : break <EOL> while line [ - <NUM_LIT:2> : ] == '<STR_LIT>' : <EOL> nextline = fpi . readline ( ) <EOL> if not nextline : break <EOL> line = line + nextline <EOL> tmp = line . strip ( ) <EOL> if tmp [ : <NUM_LIT:1> ] != '<STR_LIT:#>' : <EOL> if ok : fpo . write ( line ) <EOL> continue <EOL> tmp = tmp [ <NUM_LIT:1> : ] . strip ( ) <EOL> words = tmp . split ( ) <EOL> keyword = words [ <NUM_LIT:0> ] <EOL> if keyword not in keywords : <EOL> if ok : fpo . write ( line ) <EOL> continue <EOL> if keyword in ( '<STR_LIT>' , '<STR_LIT>' ) and len ( words ) == <NUM_LIT:2> : <EOL> if keyword == '<STR_LIT>' : <EOL> ko = <NUM_LIT:1> <EOL> else : <EOL> ko = <NUM_LIT:0> <EOL> word = words [ <NUM_LIT:1> ] <EOL> if word in defs : <EOL> stack . append ( ( ok , ko , word ) ) <EOL> if not ko : ok = <NUM_LIT:0> <EOL> elif word in undefs : <EOL> stack . append ( ( ok , not ko , word ) ) <EOL> if ko : ok = <NUM_LIT:0> <EOL> else : <EOL> stack . append ( ( ok , - <NUM_LIT:1> , word ) ) <EOL> if ok : fpo . write ( line ) <EOL> elif keyword == '<STR_LIT>' : <EOL> stack . append ( ( ok , - <NUM_LIT:1> , '<STR_LIT>' ) ) <EOL> if ok : fpo . write ( line ) <EOL> elif keyword == '<STR_LIT>' and stack : <EOL> s_ok , s_ko , s_word = stack [ - <NUM_LIT:1> ] <EOL> if s_ko < <NUM_LIT:0> : <EOL> if ok : fpo . write ( line ) <EOL> else : <EOL> s_ko = not s_ko <EOL> ok = s_ok <EOL> if not s_ko : ok = <NUM_LIT:0> <EOL> stack [ - <NUM_LIT:1> ] = s_ok , s_ko , s_word <EOL> elif keyword == '<STR_LIT>' and stack : <EOL> s_ok , s_ko , s_word = stack [ - <NUM_LIT:1> ] <EOL> if s_ko < <NUM_LIT:0> : <EOL> if ok : fpo . write ( line ) <EOL> del stack [ - <NUM_LIT:1> ] <EOL> ok = s_ok <EOL> else : <EOL> sys . stderr . write ( '<STR_LIT>' % keyword ) <EOL> if stack : <EOL> sys . stderr . write ( '<STR_LIT>' % stack ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
