diff options
author | Guido van Rossum <guido@python.org> | 1994-08-19 10:51:31 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-08-19 10:51:31 (GMT) |
commit | d4d77284408316a68cdc2ab9e8e1d4a06e534938 (patch) | |
tree | f25369ac9cc34663abcfd3be4b08035d8fe72c62 /Mac/scripts | |
parent | e89bc75048d0142859379b2b92e77d984fdbef6e (diff) | |
download | cpython-d4d77284408316a68cdc2ab9e8e1d4a06e534938.zip cpython-d4d77284408316a68cdc2ab9e8e1d4a06e534938.tar.gz cpython-d4d77284408316a68cdc2ab9e8e1d4a06e534938.tar.bz2 |
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Diffstat (limited to 'Mac/scripts')
-rwxr-xr-x | Mac/scripts/crlf.py | 8 | ||||
-rw-r--r-- | Mac/scripts/unshar.py | 71 |
2 files changed, 77 insertions, 2 deletions
diff --git a/Mac/scripts/crlf.py b/Mac/scripts/crlf.py index f52867a..6506cdc 100755 --- a/Mac/scripts/crlf.py +++ b/Mac/scripts/crlf.py @@ -1,5 +1,9 @@ #! /usr/local/bin/python +# Replace \r by \n -- useful after transferring files from the Mac... +# Run this on UNIX. +# Usage: crlf.py file ... + import sys import os import string @@ -7,8 +11,8 @@ import string def main(): args = sys.argv[1:] if not args: - print 'no files' - sys.exit(1) + print 'usage:', sys.argv[0], 'file ...' + sys.exit(2) for file in args: print file, '...' data = open(file, 'r').read() diff --git a/Mac/scripts/unshar.py b/Mac/scripts/unshar.py new file mode 100644 index 0000000..fa60e5a --- /dev/null +++ b/Mac/scripts/unshar.py @@ -0,0 +1,71 @@ +# Extract files from a SHAR archive. +# Run this on the Mac. +# Usage: +# >>> import unshar +# >>> f = open('SHAR') +# >>> unshar.unshar(f) + +import string + +def unshar(fp, verbose=0, overwrite=0): + ofp = None + file = None + while 1: + line = fp.readline() + if verbose > 3: print 'Got:', `line` + if line[:1] == 'X': + # Most common case first + if ofp: ofp.write(line[1:]) + continue + if not line: + if verbose: print 'EOF' + if ofp: + print 'Unterminated file -- closing' + ofp.close() + ofp = None + break + if line[0] == '#': + if verbose: print line, + continue + if line[:14] == 'sed "s/^X//" >': + if verbose: print "!!!", `line` + i = string.find(line, "'") + j = string.find(line, "'", i+1) + if i >= 0 and j > i: + file = line[i+1:j] + if '/' in file: + words = string.splitfields(file, '/') + for funny in '', '.': + while funny in words: words.remove(funny) + for i in range(len(words)): + if words[i] == '..': words[i] = '' + words.insert(0, '') + file = string.joinfields(words, ':') + try: + ofp = open(file, 'r') + ofp.close() + ofp = None + over = 1 + except IOError: + over = 0 + if over and not overwrite: + print 'Skipping', file, '(already exists) ...' + continue + ofp = open(file, 'w') + if over: + print 'Overwriting', file, '...' + else: + print 'Writing', file, '...' + continue + if line == 'END_OF_FILE\n': + if not file: + print 'Unexpected END_OF_FILE marker' + if ofp: + print 'done' + ofp.close() + ofp = None + else: + print 'done skipping' + file = None + continue + if verbose: print "...", `line` |