summaryrefslogtreecommitdiff
path: root/devtools/devstudio macros/comments.dsm
blob: 6a9ed3ccbd10fb19d7bb59245f038e7839925362 (plain) (blame)
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
259
260
261
262
263
264
265
266
267
268
269
270
'------------------------------------------------------------------------------
'FILE DESCRIPTION: Contains macros which make MSVC commenting more automated
'------------------------------------------------------------------------------

Sub ModuleHeader()
'DESCRIPTION: This macro adds the standard copyright information to the top of a module.

	ActiveDocument.Selection.StartOfDocument

	' Create the standard file prologue
	Header = "//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======" + vbCrLf 
	Header = Header + "//" + vbCrLf 
	Header = Header + "// Purpose: " + vbCrLf
	Header = Header + "//" + vbCrLf 
	Header = Header + "//=============================================================================" + vbCrLf + vbCrLf

	' Add the single inclusion macros for header files
	DotHPos = InStr(ActiveDocument.Name, ".h")

	If DotHPos > 0 Then
		InclusionKey = Left(ActiveDocument.Name, DotHPos - 1)
		InclusionKey = UCase(InclusionKey) + "_H"
		Header = Header + "#ifndef " + InclusionKey + vbCrLf
		Header = Header + "#define " + InclusionKey + vbCrLf
		Header = Header + "#ifdef _WIN32" + vbCrLf
		Header = Header + "#pragma once" + vbCrLf
		Header = Header + "#endif" + vbCrLf + vbCrLf
	End If

	ActiveDocument.Selection.Text = Header

	' Add the "#endif" for header files
	If DotHPos > 0 Then
		ActiveDocument.Selection.EndOfDocument
		Header = vbCrLf + "#endif // " + InclusionKey + vbCrLf
		ActiveDocument.Selection.Text = Header
	End If

	ActiveDocument.Selection.StartOfDocument

End Sub


Sub TypeHeader()
'DESCRIPTION: This macro adds a description block above a type declaration

	' Select the text on the current line and store it for parsing
	ActiveDocument.Selection.SelectLine
	TypeDec = ActiveDocument.Selection.Text
	ActiveDocument.Selection.StartOfLine

	' Check to make sure that this line is a type delcaration
	If InStr(TypeDec, "class") = 0 And InStr(TypeDec, "struct") = 0 And InStr(TypeDec, "interface") = 0 And InStr(TypeDec, "enum") = 0 Then 
		MsgBox("This line does not contain a class, struct, interface, or enum declaration.") 
	Else
		' Construct the type header
		Header = "//-----------------------------------------------------------------------------" + vbCrLf
		Header = Header + "// Purpose: " + vbCrLf
		Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
			
		' Write the header
		ActiveDocument.Selection.Text = Header
	End If

End Sub


Sub FunctionHeader()
'DESCRIPTION: This macro creates a function header for C functions or C++ member functions

	' Select the text on the current line and store it for parsing
	ActiveDocument.Selection.SelectLine
	FunctionImp = ActiveDocument.Selection.Text
 	ActiveDocument.Selection.StartOfLine
	LineNum = ActiveDocument.Selection.CurrentLine

	FunctionName = Left(FunctionImp, InStr(FunctionImp, "("))

	' Check to make sure that this line is a class delcaration
	If len(FunctionName) = 0 Then
		MsgBox("This line does not contain a function implementation.")
	Else
		FuncArray = Split(FunctionName)

		ReturnType = ""

		' Get the return type and function name
		For Each Element In FuncArray
			if InStr(Element, "(") = 0 Then
				ReturnType = ReturnType + Element + " "
			Else
				FunctionName = Left(Element, len(Element) - 1)
			End If
		Next

		ReturnType = Trim(ReturnType)

		if ReturnType = "BOOL" Then
			ReturnType = "Returns TRUE on success, FALSE on failure."
		Elseif ReturnType = "bool" Then
			ReturnType = "Returns true on success, false on failure."
		End If

		' Place the function parameters in its own string
		Params = Right(FunctionImp, len(FunctionImp) - InStr(FunctionImp, "("))
		Do While InStr(Params, ")") = 0
			ActiveDocument.Selection.LineDown
			ActiveDocument.Selection.SelectLine
			Params = Left(Params, InStr(Params, vbCrLf) - 1)
			Params = Params + Trim(ActiveDocument.Selection.Text)
		Loop
		ActiveDocument.Selection.GotoLine LineNum
		Params = Left(Params, InStr(Params, ")") - 1)
		Params = Trim(Params)

		' Remove any /* */ comments from Params
		Pos = InStr( Params, "/*" )
		Do While Pos
			EndComment = InStr( Params, "*/" )
			If EndComment Then
				StartString = Left( Params, InStr( Params, "/*" ) - 1)
				Pos2 = len( Params ) - InStr( Params, "*/" ) + 3
				EndString = Mid( Params, InStr( Params, "*/" ) + 2, Pos2 )

				StartString = Trim( StartString )
				EndString = Trim( EndString )

				Params = StartString + EndString
				Pos = InStr( Params, "/*" )
			Else
				Pos = 0
			End If
		Loop

		' Create an array of individual parameters
		ParamsArray = Split(Params, ",")

		' Construct the parameters section
		ParamSection = ""
		AddNewLine = 0
		For Each Element In ParamsArray
			Element = Trim(Element)
			Element = Right(Element, len(Element) - InstrRev(Element, " "))
			if AddNewLine = 1 Then
				ParamSection = ParamSection + vbCrLf + "//			"
			End If
			ParamSection = ParamSection + Element + " - "
			AddNewLine = 1
		Next

		' Construct the rest of the header
		Header =          "//-----------------------------------------------------------------------------" + vbCrLf
		Header = Header + "// Purpose: " + vbCrLf

		if ParamSection <> "void - " and ParamSection <> "" then
			Header = Header + "// Input  : " + ParamSection + vbCrLf
		end if

		if ReturnType <> "void" and ReturnType <> "" Then
			Header = Header + "// Output : " + ReturnType + vbCrLf
		end if

		Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
			
		' Write the header
		ActiveDocument.Selection.Text = Header

	End If
End Sub


'DESCRIPTION: Comments in or out a line of code, then moves to the next line.
Sub ToggleComment()

	ActiveDocument.Selection.SelectLine
	LineText = ActiveDocument.Selection.Text
 	ActiveDocument.Selection.StartOfLine

	FirstTwoChars = Left(LineText, 2)

	If len(FirstTwoChars) < 2 Then
			ActiveDocument.Selection = ""
	Elseif FirstTwoChars = "//" Then
	 	ActiveDocument.Selection.CharRight dsExtend
	 	ActiveDocument.Selection.CharRight dsExtend
		ActiveDocument.Selection = ""
	Else
		ActiveDocument.Selection = "//"
	End if

	ActiveDocument.Selection.LineDown

End Sub

Sub ScheduleTemplate()
'DESCRIPTION: Adds a schedule template at the current cursor position
	ActiveDocument.Selection = "//==================================================" + vbCrLf + "// SCHED_" + vbCrLf + "//==================================================" + vbCrLf + vbCrLf + "Schedule" + vbCrLf + vbTab + "SCHED_" + vbCrLf + "Tasks" + vbCrLf + vbCrLf + "Interrupts" + vbCrLf + vbCrLf + ActiveDocument.Selection

End Sub

Sub CommentTODO()
'DESCRIPTION: Adds "//TODO:" at the current cursor position
	ActiveDocument.Selection = "//TODO: " + ActiveDocument.Selection

End Sub

Sub CommentFIXME()
'DESCRIPTION: Adds "//FIXME:" at the current cursor position
	ActiveDocument.Selection = "//FIXME: " + ActiveDocument.Selection

End Sub

Sub CommentNOTENOTE()
'DESCRIPTION: Adds "//NOTENOTE:" at the current cursor position
	ActiveDocument.Selection = "//NOTENOTE: " + ActiveDocument.Selection

End Sub

Sub JumpToHeader()
	'////////////////////////////////////////////
	'DESCRIPTION: Switch Between Header and cpp
	'////////////////////////////////////////////
	Dim myDocument
	Dim a
	Dim b
	Dim c
	Dim Flag
	Dim Flag1
	Flag1 = 0
	Flag = 1
	a = ActiveDocument.FullName
	tmp = InStr(a, ".cpp")
	If tmp Then
		b = Left(a, Len(a) - 3) + "h"
		c = Left(a, Len(a) - 3) + "h"
		Flag1 = 1
	Else
		tmp = InStr(a, ".c")
		If tmp Then
			b = Left(a, Len(a) - 1) + "h"
			c = Left(a, Len(a) - 1) + "h"
			Flag1 = 1
		Else
			tmp = InStr(a, ".h")
			If tmp Then
					b = Left(a, Len(a) - 1) + "c"
					c = Left(a, Len(a) - 1) + "cpp"
					Flag1 = 1
			End If
		End If
	End If
	For Each myDocument In Application.Documents
		If myDocument.FullName = b Then
			myDocument.Active = True
			Flag = 0
			Exit For
		End If

		If myDocument.FullName = c Then
			myDocument.Active = True
			Flag = 0
			b = c
			Exit For
		End If

	Next
	If Flag And Flag1 Then
			Documents.Open b, "Text"
	End If
End Sub