blob: a5943a65ddea9561a557ca1ac9f279ddafc6c1c2 [file] [log] [blame]
Jack Jansen024a3871996-07-18 16:07:05 +00001"""checktext - Check that a text file has macintosh-style newlines"""
2
Jack Jansen024a3871996-07-18 16:07:05 +00003import sys
4import EasyDialogs
5import string
6
7def main():
Jack Jansendf976ca2003-01-26 20:35:47 +00008 pathname = EasyDialogs.AskFileForOpen(message='File to check end-of-lines in:')
9 if not pathname:
Jack Jansen024a3871996-07-18 16:07:05 +000010 sys.exit(0)
Jack Jansen024a3871996-07-18 16:07:05 +000011 fp = open(pathname, 'rb')
12 try:
13 data = fp.read()
14 except MemoryError:
15 EasyDialogs.Message('Sorry, file is too big.')
16 sys.exit(0)
17 if len(data) == 0:
18 EasyDialogs.Message('File is empty.')
19 sys.exit(0)
20 number_cr = string.count(data, '\r')
21 number_lf = string.count(data, '\n')
22 if number_cr == number_lf == 0:
23 EasyDialogs.Message('File contains no lines.')
24 if number_cr == 0:
25 EasyDialogs.Message('File has unix-style line endings')
26 elif number_lf == 0:
27 EasyDialogs.Message('File has mac-style line endings')
28 elif number_cr == number_lf:
29 EasyDialogs.Message('File probably has MSDOS-style line endings')
30 else:
31 EasyDialogs.Message('File has no recognizable line endings (binary file?)')
32 sys.exit(0)
33
34if __name__ == '__main__':
35 main()
36
37