acme/bin/t2s

27 lines
433 B
Text
Raw Normal View History

2017-08-17 01:04:01 +03:00
#!/usr/bin/env python3
2017-01-26 19:29:57 +03:00
2017-08-17 01:04:01 +03:00
import sys
2017-01-26 19:29:57 +03:00
2017-08-17 01:04:01 +03:00
DEFAULT_N_SPACES = 4
TAB, SPACE = ' ', ' '
2017-01-26 19:29:57 +03:00
2017-08-17 01:04:01 +03:00
try:
n_spaces = int(sys.argv[1])
except:
n_spaces = DEFAULT_N_SPACES
2017-01-26 19:29:57 +03:00
2017-08-17 01:04:01 +03:00
if n_spaces < 1:
n_spaces = DEFAULT_N_SPACES
2017-01-26 19:29:57 +03:00
2017-08-17 01:04:01 +03:00
for line in sys.stdin:
line = line.rstrip()
n_tabs = 0
2017-08-17 01:04:01 +03:00
for ch in line:
if ch != TAB:
break
n_tabs += 1
2017-08-17 01:04:01 +03:00
spaces = SPACE * n_spaces * n_tabs
print(spaces, line[n_tabs:], sep='')