1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/env python
import cgi, sys, sqlite3
import cgitb; cgitb.enable()
theform=cgi.FieldStorage()
if not theform.has_key('cmd'):
thecmd = ''
else:
thecmd = theform['cmd'].value
pkgs=('pstricks','pst-plot','pst-node','pstricks-add','pst-nodeExtras','pst-3dplot','pst-tree','multido','pst-eps','pst-bspline','pst-grapha','pst-coil','pst-text')
tab=u'\x09'
bdelim=("{","(","[","")
edelim=("}",")","]","")
bgon='<span class="opt">'
bgoff='</span>'
print "Content-type: text/html\r\n"
pagehead='''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO8859-I" />
<link type="css/text" rel="stylesheet" href="../../psthelp.css" />
<title>PSTricks Help Page</title></head>
<body>
<h1>PSTricks Command Help</h1>
<form action="../../cgi-bin/parsehelp.py" method="get">
<p id="ask">Command: <input type="text" value="**thecmd**" name="cmd" /><input type="submit" /></p>
</form>
'''
def cnv(s):
# convert < and > characters to html
ss=s.replace('<-','←')
ss=ss.replace('<','<')
ss=ss.replace('|','| ')
return ss.replace('>','>')
pagetail='</body></html>\n'
pagebody=''
if thecmd[0:1]<>'\\':
thecmd='\\'+thecmd
print pagehead.replace('**thecmd**',thecmd)
if thecmd:
conn = sqlite3.connect('/Library/Webserver/Documents/pstCommands.db')
c=conn.cursor()
t=(thecmd,)
c.execute('select cmdid, cmdname from Commands where cmdname=?',t)
x=c.fetchone()
cmdnum=0
while not (x is None):
if x[1]==thecmd:
cmdnum=int(x[0])
x=c.fetchone()
if cmdnum==0:
print "<p><b>Command not found</b></p> "
c.execute("select cmdname from Commands where cmdname LIKE '"+thecmd+"%' order by cmdname")
x=c.fetchone()
print '<p>Similar commands:</p><p>'
while not (x is None):
print ' <a href="../../cgi-bin/parsehelp.py?cmd=%5C'+x[0][1:]+'">',x[0],'</a> '
x=c.fetchone()
print '</p>'
else:
t=(cmdnum,)
c.execute('select * from Commands where cmdID=?',t)
x=c.fetchone()
#print x---there should be only one
cmdcat=int(x[1])
desc=x[6].split(tab)
isOpt=x[8]
ti=[]
ti.append(thecmd)
if x[2]==1:
ti.append(bgon+"*"+bgoff)
if x[9]==1:
ti.append(bgon+"[<kwds>]"+bgoff)
L=len(x[7]) # delimiters
delim=x[7]
for i in range(0,L):
k=int(delim[i])
s=bdelim[k]+desc[i].replace('<-','←')+edelim[k]
s=cnv(s)
if isOpt[i]=='1':
s=bgon+s+bgoff
ti.append(s)
if x[10]==1:
ti.append("(<coords>)"+bgon+"..."+bgoff)
#ti.append("% "+x[5]+' ['+pkgs[x[11]]+']')
#print ""
print '<p id="syntax"><b>Syntax:</b>',''.join(ti),'</p>'
print '(Gray background indicates optional argument, "←" shows default value, if omitted.)'
print '<p><strong>Synopsis:</strong> ['+pkgs[x[11]]+']',cnv(x[5])
if x[9]==1:
ss="select parName,parPat,parDefault,parDescription from Parameters where (parLimTo="+str(cmdnum)+") or ((parLimTo=0) and (parCat=0 or parCat="+str(x[1])+")) group by parName,parPat,parDefault,parDescription order by parname"
c.execute(ss)
print '<table>'
print '<caption><strong>Keywords for %s</strong></caption>'% thecmd
print '<tr><th>Keyword</th><th>Kind</th><th>Default</th><th>Description</th></tr>'
alt=0
for x in c:
if alt:
print '<tr class="cellcolor">'
else:
print '<tr>'
print '<td>'+x[0]+'</td><td>'+cnv(x[1])+'</td><td class="center">'+x[2]+'</td><td>'+cnv(x[3])+'</td></tr>'
alt=1-alt
print '</table></p>'
t=(cmdcat,cmdnum)
if (cmdcat>0) and (cmdcat<>26):
c.execute('select cmdID, cmdname from Commands where cmdCat=? and cmdID<>?',t)
x=c.fetchone()
if not (x is None):
print '<p>Similar commands: '
while not(x is None):
print ' <a href="../../cgi-bin/parsehelp.py?cmd=%5C'+x[1][1:]+'">',x[1],'</a> '
x=c.fetchone()
print '</p>'
print pagetail
|