30 lines
548 B
Python
Executable file
30 lines
548 B
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
DEFAULT_N_SPACES = 4
|
|
TAB, SPACE = ' ', ' '
|
|
|
|
try:
|
|
n_spaces = int(sys.argv[1])
|
|
except:
|
|
n_spaces = DEFAULT_N_SPACES
|
|
|
|
if n_spaces < 1:
|
|
n_spaces = DEFAULT_N_SPACES
|
|
|
|
for line in sys.stdin:
|
|
line = line.rstrip()
|
|
n_leading_spaces = 0
|
|
|
|
for ch in line:
|
|
if ch != SPACE:
|
|
break
|
|
n_leading_spaces += 1
|
|
|
|
if 0 < n_leading_spaces < n_spaces:
|
|
n_tabs = 1
|
|
else:
|
|
n_tabs = n_leading_spaces // n_spaces
|
|
|
|
print(TAB * n_tabs, line[n_leading_spaces:], sep='')
|