Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
7.9 KiB

  1. '------------------------------------------------------------------------------
  2. 'FILE DESCRIPTION: Contains macros which make MSVC commenting more automated
  3. '------------------------------------------------------------------------------
  4. Sub ModuleHeader()
  5. 'DESCRIPTION: This macro adds the standard copyright information to the top of a module.
  6. ActiveDocument.Selection.StartOfDocument
  7. ' Create the standard file prologue
  8. Header = "//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======" + vbCrLf
  9. Header = Header + "//" + vbCrLf
  10. Header = Header + "// Purpose: " + vbCrLf
  11. Header = Header + "//" + vbCrLf
  12. Header = Header + "//=============================================================================" + vbCrLf + vbCrLf
  13. ' Add the single inclusion macros for header files
  14. DotHPos = InStr(ActiveDocument.Name, ".h")
  15. If DotHPos > 0 Then
  16. InclusionKey = Left(ActiveDocument.Name, DotHPos - 1)
  17. InclusionKey = UCase(InclusionKey) + "_H"
  18. Header = Header + "#ifndef " + InclusionKey + vbCrLf
  19. Header = Header + "#define " + InclusionKey + vbCrLf
  20. Header = Header + "#ifdef _WIN32" + vbCrLf
  21. Header = Header + "#pragma once" + vbCrLf
  22. Header = Header + "#endif" + vbCrLf + vbCrLf
  23. End If
  24. ActiveDocument.Selection.Text = Header
  25. ' Add the "#endif" for header files
  26. If DotHPos > 0 Then
  27. ActiveDocument.Selection.EndOfDocument
  28. Header = vbCrLf + "#endif // " + InclusionKey + vbCrLf
  29. ActiveDocument.Selection.Text = Header
  30. End If
  31. ActiveDocument.Selection.StartOfDocument
  32. End Sub
  33. Sub TypeHeader()
  34. 'DESCRIPTION: This macro adds a description block above a type declaration
  35. ' Select the text on the current line and store it for parsing
  36. ActiveDocument.Selection.SelectLine
  37. TypeDec = ActiveDocument.Selection.Text
  38. ActiveDocument.Selection.StartOfLine
  39. ' Check to make sure that this line is a type delcaration
  40. If InStr(TypeDec, "class") = 0 And InStr(TypeDec, "struct") = 0 And InStr(TypeDec, "interface") = 0 And InStr(TypeDec, "enum") = 0 Then
  41. MsgBox("This line does not contain a class, struct, interface, or enum declaration.")
  42. Else
  43. ' Construct the type header
  44. Header = "//-----------------------------------------------------------------------------" + vbCrLf
  45. Header = Header + "// Purpose: " + vbCrLf
  46. Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
  47. ' Write the header
  48. ActiveDocument.Selection.Text = Header
  49. End If
  50. End Sub
  51. Sub FunctionHeader()
  52. 'DESCRIPTION: This macro creates a function header for C functions or C++ member functions
  53. ' Select the text on the current line and store it for parsing
  54. ActiveDocument.Selection.SelectLine
  55. FunctionImp = ActiveDocument.Selection.Text
  56. ActiveDocument.Selection.StartOfLine
  57. LineNum = ActiveDocument.Selection.CurrentLine
  58. FunctionName = Left(FunctionImp, InStr(FunctionImp, "("))
  59. ' Check to make sure that this line is a class delcaration
  60. If len(FunctionName) = 0 Then
  61. MsgBox("This line does not contain a function implementation.")
  62. Else
  63. FuncArray = Split(FunctionName)
  64. ReturnType = ""
  65. ' Get the return type and function name
  66. For Each Element In FuncArray
  67. if InStr(Element, "(") = 0 Then
  68. ReturnType = ReturnType + Element + " "
  69. Else
  70. FunctionName = Left(Element, len(Element) - 1)
  71. End If
  72. Next
  73. ReturnType = Trim(ReturnType)
  74. if ReturnType = "BOOL" Then
  75. ReturnType = "Returns TRUE on success, FALSE on failure."
  76. Elseif ReturnType = "bool" Then
  77. ReturnType = "Returns true on success, false on failure."
  78. End If
  79. ' Place the function parameters in its own string
  80. Params = Right(FunctionImp, len(FunctionImp) - InStr(FunctionImp, "("))
  81. Do While InStr(Params, ")") = 0
  82. ActiveDocument.Selection.LineDown
  83. ActiveDocument.Selection.SelectLine
  84. Params = Left(Params, InStr(Params, vbCrLf) - 1)
  85. Params = Params + Trim(ActiveDocument.Selection.Text)
  86. Loop
  87. ActiveDocument.Selection.GotoLine LineNum
  88. Params = Left(Params, InStr(Params, ")") - 1)
  89. Params = Trim(Params)
  90. ' Remove any /* */ comments from Params
  91. Pos = InStr( Params, "/*" )
  92. Do While Pos
  93. EndComment = InStr( Params, "*/" )
  94. If EndComment Then
  95. StartString = Left( Params, InStr( Params, "/*" ) - 1)
  96. Pos2 = len( Params ) - InStr( Params, "*/" ) + 3
  97. EndString = Mid( Params, InStr( Params, "*/" ) + 2, Pos2 )
  98. StartString = Trim( StartString )
  99. EndString = Trim( EndString )
  100. Params = StartString + EndString
  101. Pos = InStr( Params, "/*" )
  102. Else
  103. Pos = 0
  104. End If
  105. Loop
  106. ' Create an array of individual parameters
  107. ParamsArray = Split(Params, ",")
  108. ' Construct the parameters section
  109. ParamSection = ""
  110. AddNewLine = 0
  111. For Each Element In ParamsArray
  112. Element = Trim(Element)
  113. Element = Right(Element, len(Element) - InstrRev(Element, " "))
  114. if AddNewLine = 1 Then
  115. ParamSection = ParamSection + vbCrLf + "// "
  116. End If
  117. ParamSection = ParamSection + Element + " - "
  118. AddNewLine = 1
  119. Next
  120. ' Construct the rest of the header
  121. Header = "//-----------------------------------------------------------------------------" + vbCrLf
  122. Header = Header + "// Purpose: " + vbCrLf
  123. if ParamSection <> "void - " and ParamSection <> "" then
  124. Header = Header + "// Input : " + ParamSection + vbCrLf
  125. end if
  126. if ReturnType <> "void" and ReturnType <> "" Then
  127. Header = Header + "// Output : " + ReturnType + vbCrLf
  128. end if
  129. Header = Header + "//-----------------------------------------------------------------------------" + vbCrLf
  130. ' Write the header
  131. ActiveDocument.Selection.Text = Header
  132. End If
  133. End Sub
  134. 'DESCRIPTION: Comments in or out a line of code, then moves to the next line.
  135. Sub ToggleComment()
  136. ActiveDocument.Selection.SelectLine
  137. LineText = ActiveDocument.Selection.Text
  138. ActiveDocument.Selection.StartOfLine
  139. FirstTwoChars = Left(LineText, 2)
  140. If len(FirstTwoChars) < 2 Then
  141. ActiveDocument.Selection = ""
  142. Elseif FirstTwoChars = "//" Then
  143. ActiveDocument.Selection.CharRight dsExtend
  144. ActiveDocument.Selection.CharRight dsExtend
  145. ActiveDocument.Selection = ""
  146. Else
  147. ActiveDocument.Selection = "//"
  148. End if
  149. ActiveDocument.Selection.LineDown
  150. End Sub
  151. Sub ScheduleTemplate()
  152. 'DESCRIPTION: Adds a schedule template at the current cursor position
  153. ActiveDocument.Selection = "//==================================================" + vbCrLf + "// SCHED_" + vbCrLf + "//==================================================" + vbCrLf + vbCrLf + "Schedule" + vbCrLf + vbTab + "SCHED_" + vbCrLf + "Tasks" + vbCrLf + vbCrLf + "Interrupts" + vbCrLf + vbCrLf + ActiveDocument.Selection
  154. End Sub
  155. Sub CommentTODO()
  156. 'DESCRIPTION: Adds "//TODO:" at the current cursor position
  157. ActiveDocument.Selection = "//TODO: " + ActiveDocument.Selection
  158. End Sub
  159. Sub CommentFIXME()
  160. 'DESCRIPTION: Adds "//FIXME:" at the current cursor position
  161. ActiveDocument.Selection = "//FIXME: " + ActiveDocument.Selection
  162. End Sub
  163. Sub CommentNOTENOTE()
  164. 'DESCRIPTION: Adds "//NOTENOTE:" at the current cursor position
  165. ActiveDocument.Selection = "//NOTENOTE: " + ActiveDocument.Selection
  166. End Sub
  167. Sub JumpToHeader()
  168. '////////////////////////////////////////////
  169. 'DESCRIPTION: Switch Between Header and cpp
  170. '////////////////////////////////////////////
  171. Dim myDocument
  172. Dim a
  173. Dim b
  174. Dim c
  175. Dim Flag
  176. Dim Flag1
  177. Flag1 = 0
  178. Flag = 1
  179. a = ActiveDocument.FullName
  180. tmp = InStr(a, ".cpp")
  181. If tmp Then
  182. b = Left(a, Len(a) - 3) + "h"
  183. c = Left(a, Len(a) - 3) + "h"
  184. Flag1 = 1
  185. Else
  186. tmp = InStr(a, ".c")
  187. If tmp Then
  188. b = Left(a, Len(a) - 1) + "h"
  189. c = Left(a, Len(a) - 1) + "h"
  190. Flag1 = 1
  191. Else
  192. tmp = InStr(a, ".h")
  193. If tmp Then
  194. b = Left(a, Len(a) - 1) + "c"
  195. c = Left(a, Len(a) - 1) + "cpp"
  196. Flag1 = 1
  197. End If
  198. End If
  199. End If
  200. For Each myDocument In Application.Documents
  201. If myDocument.FullName = b Then
  202. myDocument.Active = True
  203. Flag = 0
  204. Exit For
  205. End If
  206. If myDocument.FullName = c Then
  207. myDocument.Active = True
  208. Flag = 0
  209. b = c
  210. Exit For
  211. End If
  212. Next
  213. If Flag And Flag1 Then
  214. Documents.Open b, "Text"
  215. End If
  216. End Sub