Skip to content

Commit

Permalink
Add AUTHORS, COPYING, README
Browse files Browse the repository at this point in the history
  • Loading branch information
aitjcize committed Jul 3, 2010
1 parent 3a96f53 commit fa01492
Show file tree
Hide file tree
Showing 8 changed files with 721 additions and 14 deletions.
9 changes: 9 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Developers
----------
AZ Huang <[email protected]>

Contributors
------------

Authors of External source
--------------------------
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

Empty file added README
Empty file.
5 changes: 4 additions & 1 deletion cppman/cppman
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ def main():
cm.man(args[0])

if __name__ == '__main__':
main()
try:
main()
except Exception, e:
print e
20 changes: 16 additions & 4 deletions cppman/cppman.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,36 @@ def cache_man_page(self, url):
f.close()

def clear_cache(self):
'''
Clear all cache in man3
'''
shutil.rmtree(environ.man_dir)

def man(self, pattern):
'''
Call viewer.sh to view man page
'''
try:
os.mkdir(environ.man_dir)
except: pass

avail = subprocess.Popen('ls %s' % environ.man_dir, shell=True,
stdout=subprocess.PIPE).stdout.read()
conn = sqlite3.connect(environ.index_db)
cursor = conn.cursor()
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN WHERE'
' name LIKE "%%%s%%"' % pattern).fetchone()
conn.close()
try:
page_name, url = cursor.execute('SELECT name,url FROM CPPMAN WHERE'
' name LIKE "%%%s%%"' % pattern).fetchone()
except TypeError:
raise RuntimeError('No manual entry for ' + pattern)
finally:
conn.close()

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

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

def find(self, pattern):
pass
2 changes: 2 additions & 0 deletions cppman/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
home = os.path.expanduser('~')
#man_dir = home + '/.local/share/man/man3/'
#index_db = home + '/.config/cppman/index.db'
viewer = './viewer.sh'

man_dir = 'man3/'
index_db = 'index.db'


22 changes: 14 additions & 8 deletions cppman/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,7 @@ def groff2man(data):
'''
Read groff-formated text and output man pages.
'''

# Get terminal size
ws = struct.pack("HHHH", 0, 0, 0, 0)
ws = fcntl.ioctl(0, termios.TIOCGWINSZ, ws)
lines, columns, x, y = struct.unpack("HHHH", ws)
width = columns * 39 / 40
if width >= columns -2: width = columns -2
width = get_width()

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

def get_width():
'''
Calculate appropriate width for groff
'''
# Get terminal size
ws = struct.pack("HHHH", 0, 0, 0, 0)
ws = fcntl.ioctl(0, termios.TIOCGWINSZ, ws)
lines, columns, x, y = struct.unpack("HHHH", ws)
width = columns * 39 / 40
if width >= columns -2: width = columns -2
return width

def test():
'''
Simple Text
'''
#name = raw_input('What manual page do you want?')
name = 'list'
ifs = urllib.urlopen('http://www.cplusplus.com/' + name)
print cplusplus2groff(ifs.read()),
print cplusplus2man(ifs.read()),

if __name__ == '__main__':
test()
3 changes: 2 additions & 1 deletion cppman/viewer.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
cat "$1" | gunzip | groff -t -m man -Tascii | col -b -x | vim -R -c 'set ft=man | map q :q<CR>' -

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 comments on commit fa01492

Please sign in to comment.