diff -ur v1/inc_ut.py v2/inc_ut.py --- v1/inc_ut.py 2020-09-13 22:47:44.000000000 +0900 +++ v2/inc_ut.py 2020-09-15 04:10:46.000000000 +0900 @@ -28,23 +28,35 @@ def new( lst=[] ): lst += [ - r'^# *include +(.*)$', - r'^@ *include +(.*)$', - r'^@ *inc +(.*)$', - r'^@(.*)$', + r'^# *include +(\S*)', + r'^@ *include +(\S*)', + r'^@ *inc +(\S*)', + r'^@(\S*)', ] pat_lst = list( map( re.compile, lst ) ) def match_path(s): for p in pat_lst: - if p.match( s ): - return cut_quote( p.sub( r'\1', s ) ) - return None + m = p.match( s ) + if m and m.groups(): + path = cut_quote( m.group( 1 ) ) + opts = p.sub( '', s ).split() + return ( path, opts ) + return ( None, '' ) paths = [ '-' ] + def cvt_opts(r, opts): + for opt in opts: + delim = '=' + if delim in opt: + i = opt.index( delim ) + (k, v) = ( opt[ : i ], opt[ i + len( delim ) : ] ) + r = r.replace( k, v ) + return r + def inc_text(s): - path = match_path( s ) + (path, opts) = match_path( s ) if path == None: return None @@ -60,6 +72,7 @@ if r == False: return False paths.append( path ) + r = cvt_opts( r, opts ) return cut_tail_nl( r ) return False @@ -83,11 +96,10 @@ inc = new() b = nkf.get_stdin() - opt = nkf.guess( b ) - s = nkf.dec( nkf.cvt( b, '-u' ) ) + (s, opt) = nkf.to_str( b ) s = inc.exp( s ) - b = nkf.cvt( nkf.enc( s ), opt ) + b = nkf.str_to( s, opt ) nkf.put_stdout( b ) # EOF