File: SHFacer.py

package info (click to toggle)
mysql-admin 1.2.5rc-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80,944 kB
  • ctags: 43,103
  • sloc: sql: 295,916; pascal: 256,535; cpp: 74,487; ansic: 68,881; objc: 26,417; sh: 16,867; yacc: 10,755; java: 9,917; xml: 8,453; php: 2,806; python: 2,068; makefile: 1,252; perl: 3
file content (258 lines) | stat: -rw-r--r-- 7,506 bytes parent folder | download | duplicates (4)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# PasFacer.py - Updates pascal units used to create an object pascal scintilla wrapper.

import string
import sys
import os
import SHFace

def Contains(s,sub):
	return string.find(s, sub) != -1

def pType(s):
	if s == "bool":
		return "bool"
	elif s == "position":
		return "long"
	elif s == "colour":
		return "COLORREF"
	elif s == "string":
		return "const char*"
	elif s == "stringresult":
		return "char*"
	elif s == "cells":
		return "char*"
	elif s == "textrange":
		return "TextRange*"
	elif s == "findtext":
		return "TextToFind*"
	elif s == "keymod":
		return "DWORD"
	elif s == "formatrange":
		return "long"
	elif s == "int":
		return "int"
	return ""

def fixConstant(c):
	#r = string.replace(c, "|", "or")
	#r = string.replace(r, "0x", "$")
	return c

def printDefines(f, out):
	for name in f.order:
		v = f.features[name]
		if v["Category"] != "Deprecated":
			if v["FeatureType"] in ["fun", "get", "set"]:
				featureDefineName = "SCI_" + string.upper(name)
				out.write("#define " + featureDefineName + " " + fixConstant(v["Value"]) + ";\n")
			elif v["FeatureType"] in ["evt"]:
				featureDefineName = "SCN_" + string.upper(name)
				out.write("#define " + featureDefineName + " " + fixConstant(v["Value"]) + ";\n")
			elif v["FeatureType"] in ["val"]:
				featureDefineName = string.upper(name)
				out.write("#define " + featureDefineName + " " + fixConstant(v["Value"]) + ";\n")

def genfuncPrototype(name, fun):
	retval = name
	retval = retval + "("
	bp1 = 0
	if fun["Param1Type"] != "" and fun["Param1Type"] != " ":
		retval = retval + pType(fun["Param1Type"]) + " " + fun["Param1Name"]
		bp1 = 1
	if fun["Param2Type"] != "" and fun["Param2Type"] != " ":
		if bp1 == 1:
			retval = retval + ", "
		retval = retval + pType(fun["Param2Type"]) + " " + fun["Param2Name"] 
	retval = retval + ")"
	return retval

def getfuncHeader(name, fun, extra):
	retval = genfuncPrototype(name, fun)
	line = ""
	if pType(fun["ReturnType"]) == "":
		line = line + "void " + extra + retval
	else:
		line = line + pType(fun["ReturnType"]) + " " + extra + retval
	return line

def printFunctionDefs(f, out):
	for name in f.order:
		v = f.features[name]
		if v["Category"] != "Deprecated":
			if v["FeatureType"] in ["fun", "set", "get"]:
				line = ""
				if not v["Comment"] in ["", " "]:
					line = line + "		/**\n";
					
					for cline in v["Comment"]:
						line = line + "		 * " + cline + "\n";
					line = line + "		 */\n		";
				else:
					line = "		";
				line = line + getfuncHeader(name, v, "") + ";\n"
				out.write(line)

def isFunction(v):
	if pType(v["ReturnType"]) == "":
		ret = 0
	else:
		ret = 1
	return ret

def printFunctionImpl(f, out):
	for name in f.order:
		v = f.features[name]
		if v["Category"] != "Deprecated":
			if v["FeatureType"] in ["fun", "set", "get"]:
				header = getfuncHeader(name, v, "CScintilla::") + "\n"
				out.write(header)
				out.write("{\n")
				line = "	"
				endline = ""
				if not isFunction(v):
					line = line + "SPerform("
				else:
					line = line + "return "
					if pType(v["ReturnType"]) != "long":
						if pType(v["ReturnType"]) != "bool":
							line = line + "(" + pType(v["ReturnType"]) + ")"
						else:
							endline = " != 0"
					line = line + "SPerform("
				line = line + "SCI_" + string.upper(name) + ", "
				if not (v["Param1Type"] in ["", " "]):
					add = ""
					if pType(v["Param1Type"]) != "long":
						line = line + "(long)"
					line= line + v["Param1Name"] + add + ", "
				else:
					line = line + "0, "
				if not (v["Param2Type"] in ["", " "]):
					add = ""
					if pType(v["Param2Type"]) != "long":
						line = line + "(long)"
					line = line + v["Param2Name"] + add + ")"
				else:
					line = line + "0)"
				line = line + endline + ";"
				out.write(line + "\n}\n\n")

def printInlineFunctionImpl(f, out):
	for name in f.order:
		v = f.features[name]
		if v["Category"] != "Deprecated":
			if v["FeatureType"] in ["fun", "set", "get"]:
			
				line = ""
				indent = "\t\t"
				indent2 = "\t\t\t"
			
				if not v["Comment"] in ["", " "]:
					line = indent + "/**\n";
					
					for cline in v["Comment"]:
						line = line + indent + " * " + cline + "\n";
					line = line + indent + " */\n";
				
				out.write(line)
			
				header = getfuncHeader(name, v, "") + "\n"
				out.write(indent + header)
				out.write(indent + "{\n")
				
				line = ""
				endline = ""
				if not isFunction(v):
					line = line + "SPerform("
				else:
					line = line + "return "
					if pType(v["ReturnType"]) != "long":
						if pType(v["ReturnType"]) != "bool":
							line = line + "(" + pType(v["ReturnType"]) + ")"
						else:
							endline = " != 0"
					line = line + "SPerform("
				line = line + "SCI_" + string.upper(name) + ", "
				if not (v["Param1Type"] in ["", " "]):
					add = ""
					if pType(v["Param1Type"]) != "long":
						line = line + "(long)"
					line= line + v["Param1Name"] + add + ", "
				else:
					line = line + "0, "
				if not (v["Param2Type"] in ["", " "]):
					add = ""
					if pType(v["Param2Type"]) != "long":
						line = line + "(long)"
					line = line + v["Param2Name"] + add + ")"
				else:
					line = line + "0)"
				line = line + endline + ";"
				out.write(indent2 + line + "\n" + indent + "}\n\n")

def genMainControl(input, output, definition):
	copying = 1
	for line in input.readlines():
		if copying:
			output.write(line)
		#if Contains(line, "//++Autogenerated"):
		#	copying = 0
		#	genfn(definition, output)
		if Contains(line, "//++EventTypes"):
			copying = 0
			printEventDefs(definition, output)
		if Contains(line,"//++EventPrivates"):
			copying = 0
			printEventPrivates(definition, output)
		if Contains(line, "//++EventProperties"):
			copying = 0
			printEventProperties(definition, output)
		if Contains(line,"//++FuncDef"):
			copying = 0
			printFunctionDefs(definition, output)
		if Contains(line,"//++Const"):
			copying = 0
			printDefines(definition, output)
		if Contains(line,"//++FuncImp"):
			copying = 0
			printFunctionImpl(definition, output)
		if Contains(line,"//++InlineFuncImp"):
			copying = 0
			printInlineFunctionImpl(definition, output)
		if Contains(line,"//++EventImpl"):
			copying = 0
			printEventImpl(definition, output)
		if Contains(line,"//--"):
			copying = 1
			output.write(line)

def genConsts(input, output, definition):
	copying = 1
	for line in input.readlines():
		if copying:
			output.write(line)
		if Contains(line,"//++Const"):
			copying = 0
			printDefines(definition, output)
		if Contains(line,"//--") and copying == 0:
			copying = 1
			output.write(line)

def Regenerate(filename, outputfilename, definition, fn):
	tempname = "CPPFacer.tmp"
	out = open(tempname,"w")
	hfile = open(filename)
	#CopyWithInsertion(hfile, out, definition)
	fn(hfile, out, definition)
	out.close()
	hfile.close()
	if(os.access(outputfilename, os.F_OK)):
		os.unlink(outputfilename)
	os.rename(tempname, outputfilename)

# Program Start
f = SHFace.Face()
f.ReadFromFile("..\\include\\Scintilla.iface")
Regenerate("..\\originals\\scintillaif.cpp", "..\\cpp\\scintillaif.cpp", f, genMainControl)
Regenerate("..\\originals\\scintillaif.h", "..\\cpp\\scintillaif.h", f, genMainControl)
Regenerate("..\\originals\\atlscintilla.h", "..\\cpp\\atlscintilla.h", f, genMainControl)