parent
ff8da9d246
commit
c07e4a8c01
333 changed files with 0 additions and 95037 deletions
|
@ -1,70 +0,0 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
"""M4-quote text, for use as a literal in configure.ac.
|
||||
|
||||
Produces M4 "code" which evaluates to the input text.
|
||||
|
||||
It's not easy to read plain text from an input file in M4, without having it
|
||||
expanded as M4. Sometimes all we want is literal text!
|
||||
"""
|
||||
from __future__ import (
|
||||
absolute_import,
|
||||
print_function,
|
||||
unicode_literals,
|
||||
)
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from sys import (
|
||||
stdin,
|
||||
stdout,
|
||||
)
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
'--open', '-a', default='[[', help="Current open-quote symbol.")
|
||||
parser.add_argument(
|
||||
'--close', '-b', default=']]', help="Current close-quote symbol.")
|
||||
parser.add_argument(
|
||||
'--input', '-i', default='-', help="Input file, or '-' for stdin.")
|
||||
parser.add_argument(
|
||||
'--output', '-o', default='-', help="Output file, or '-' for stdout.")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def open_input(in_file):
|
||||
if in_file == '-':
|
||||
return stdin
|
||||
else:
|
||||
return open(in_file)
|
||||
|
||||
|
||||
def open_output(out_file):
|
||||
if out_file == '-':
|
||||
return stdout
|
||||
else:
|
||||
return open(out_file, 'w')
|
||||
|
||||
|
||||
def escape(line):
|
||||
return (
|
||||
line
|
||||
.replace('[', '@<:@')
|
||||
.replace(']', '@:>@')
|
||||
.replace('#', '@%:@')
|
||||
.replace('$', '@S|@')
|
||||
)
|
||||
|
||||
|
||||
def main(args):
|
||||
with open_input(args.input) as istr, open_output(args.output) as ostr:
|
||||
ostr.write(args.open)
|
||||
for line in istr:
|
||||
ostr.write(escape(line))
|
||||
ostr.write('\n')
|
||||
ostr.write(args.close)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(parse_args())
|
Loading…
Add table
Add a link
Reference in a new issue