Skip to content

Commit fa01492

Browse files
committed
Add AUTHORS, COPYING, README
1 parent 3a96f53 commit fa01492

File tree

8 files changed

+721
-14
lines changed

8 files changed

+721
-14
lines changed

AUTHORS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Developers
2+
----------
3+
4+
5+
Contributors
6+
------------
7+
8+
Authors of External source
9+
--------------------------

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README

Whitespace-only changes.

cppman/cppman

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ def main():
9292
cm.man(args[0])
9393

9494
if __name__ == '__main__':
95-
main()
95+
try:
96+
main()
97+
except Exception, e:
98+
print e

cppman/cppman.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,36 @@ def cache_man_page(self, url):
110110
f.close()
111111

112112
def clear_cache(self):
113+
'''
114+
Clear all cache in man3
115+
'''
113116
shutil.rmtree(environ.man_dir)
114117

115118
def man(self, pattern):
116119
'''
117120
Call viewer.sh to view man page
118121
'''
122+
try:
123+
os.mkdir(environ.man_dir)
124+
except: pass
125+
119126
avail = subprocess.Popen('ls %s' % environ.man_dir, shell=True,
120127
stdout=subprocess.PIPE).stdout.read()
121128
conn = sqlite3.connect(environ.index_db)
122129
cursor = conn.cursor()
123-
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN WHERE'
124-
' name LIKE "%%%s%%"' % pattern).fetchone()
125-
conn.close()
130+
try:
131+
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN WHERE'
132+
' name LIKE "%%%s%%"' % pattern).fetchone()
133+
except TypeError:
134+
raise RuntimeError('No manual entry for ' + pattern)
135+
finally:
136+
conn.close()
126137

127138
if page_name + '.3.gz' not in avail:
128139
self.cache_man_page(url)
129140

130-
os.execl('./viewer.sh', 'dummy', environ.man_dir + page_name + '.3.gz')
141+
os.execl(environ.viewer, 'dummy', str(formatter.get_width()),
142+
environ.man_dir + page_name + '.3.gz')
131143

132144
def find(self, pattern):
133145
pass

cppman/environ.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
home = os.path.expanduser('~')
2828
#man_dir = home + '/.local/share/man/man3/'
2929
#index_db = home + '/.config/cppman/index.db'
30+
viewer = './viewer.sh'
3031

3132
man_dir = 'man3/'
3233
index_db = 'index.db'
3334

35+

cppman/formatter.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ def groff2man(data):
141141
'''
142142
Read groff-formated text and output man pages.
143143
'''
144-
145-
# Get terminal size
146-
ws = struct.pack("HHHH", 0, 0, 0, 0)
147-
ws = fcntl.ioctl(0, termios.TIOCGWINSZ, ws)
148-
lines, columns, x, y = struct.unpack("HHHH", ws)
149-
width = columns * 39 / 40
150-
if width >= columns -2: width = columns -2
144+
width = get_width()
151145

152146
cmd = 'groff -t -Tascii -m man -rLL=%dn -rLT=%dn' % (width, width)
153147
handle = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
@@ -164,14 +158,26 @@ def cplusplus2man(data):
164158
man_text = groff2man(groff_text)
165159
return man_text
166160

161+
def get_width():
162+
'''
163+
Calculate appropriate width for groff
164+
'''
165+
# Get terminal size
166+
ws = struct.pack("HHHH", 0, 0, 0, 0)
167+
ws = fcntl.ioctl(0, termios.TIOCGWINSZ, ws)
168+
lines, columns, x, y = struct.unpack("HHHH", ws)
169+
width = columns * 39 / 40
170+
if width >= columns -2: width = columns -2
171+
return width
172+
167173
def test():
168174
'''
169175
Simple Text
170176
'''
171177
#name = raw_input('What manual page do you want?')
172178
name = 'list'
173179
ifs = urllib.urlopen('http://www.cplusplus.com/' + name)
174-
print cplusplus2groff(ifs.read()),
180+
print cplusplus2man(ifs.read()),
175181

176182
if __name__ == '__main__':
177183
test()

cppman/viewer.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2-
cat "$1" | gunzip | groff -t -m man -Tascii | col -b -x | vim -R -c 'set ft=man | map q :q<CR>' -
2+
3+
cat "$2" | gunzip | groff -t -m man -Tascii -rLL=$1n -rLT=$1n | col -b -x | vim -R -c 'set ft=man | map q :q<CR>' -

0 commit comments

Comments
 (0)