Posted on 2009-11-20 22:40
S.l.e!ep.¢% 阅读(912)
评论(0) 编辑 收藏 引用 所属分类:
VC
Sub FILECOMMENT()
'
DESCRIPTION: COMMENT For file version
ActiveDocument.Selection
=
"
/**
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Name:
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Copyright:
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Author:
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Date:
"
ActiveDocument.Selection
=
DATE
+
TIME
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Description:
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* Modification:
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
**/
"
End Sub
Sub AddFunctionDescription ( )
'
DESCRIPTION: Creates a comment block for the currently selected C/C++ function prototype
'
Throughout this file, ActiveDocument.Selection is used in place
'
of ActiveDocument.Selection.Text. The two are equivalent, and can
'
be used interchangeably. The reason for the equivalence is that
'
Text is regarded as the default property to use. All uses of
'
ActiveDocument.Selection without any other property default to the Text
'
property.
if
ActiveDocument.Language
=
dsCPP Then
Header
=
StripTabs(Trim(ActiveDocument.Selection))
'
Get the function return type.
if
Header
<>
""
then
Reti
=
InStr(Header,
"
"
)
Loc
=
InStr(Header,
"
(
"
)
if
Reti
<
Loc Then
RetTp
=
Left(Header, Reti)
Header
=
Right(Header, Len(Header)
-
Reti)
End If
'
Get the function name.
Loc
=
InStr(Header,
"
(
"
)
-
1
Loc2
=
InStr(Header,
"
)
"
)
if
Loc
>
0
And Loc2
>
0
then
'
make sure there is a
'
(
'
and a
'
)
'
fcName
=
Left(Header, Loc)
Header
=
Right(Header, Len(Header)
-
Len(fcName))
'
Do we have storage type on the return type?
Trim (fcName)
If InStr(fcName,
"
"
)
<>
0
Then
retTp
=
retTp
+
Left(fcName,InStr (fcName,
"
"
))
fcName
=
Right(fcName, Len(fcName)
-
InStr(fcName,
"
"
))
End If
'
Get the function parameters.
iPrm
=
0
iPrmA
=
0
prms
=
Header
'
Count the number of parameters.
Do While InStr(prms,
"
,
"
)
<>
0
iPrm
=
iPrm
+
1
prms
=
Right(prms, Len(prms)
-
InStr(prms,
"
,
"
))
Loop
'
Store the parameter list in the array.
If iPrm
>
0
Then
'
If multiple params.
iPrm
=
iPrm
+
1
iPrmA
=
iPrm
Redim ParamArr(iPrm)
Do While InStr(header,
"
,
"
)
<>
0
ParamArr(iPrm)
=
Left(Header, InStr (Header,
"
,
"
)
-
1
)
'
Remove brace from first parameter.
If InStr(ParamArr(iPrm),
"
(
"
)
<>
0
Then
ParamArr(iPrm)
=
Right(ParamArr(iPrm), _
Len(ParamArr(iPrm))
-
InStr(ParamArr(iPrm),
"
(
"
))
Trim(ParamArr(iPrm))
End If
Header
=
Right(Header, Len(Header)
-
InStr(Header,
"
,
"
))
iPrm
=
iPrm
-
1
Loop
ParamArr(iPrm)
=
Header
'
Remove trailing brace from last parameter.
If InStr(ParamArr(iPrm),
"
)
"
)
<>
0
Then
ParamArr(iPrm)
=
Left(ParamArr(iPrm), _
InStr(ParamArr(iPrm),
"
)
"
)
-
1
)
Trim(ParamArr(iPrm))
End If
Else
'
Possibly one param.
Redim ParamArr(
1
)
Header
=
Right(Header, Len(Header)
-
1
)
'
Strip the first brace.
Trim(Header)
ParamArr(
1
)
=
StripTabs(Header)
If InStr(ParamArr(
1
),
"
)
"
)
<>
1
Then
ParamArr(
1
)
=
Left(ParamArr(
1
), InStr(ParamArr(
1
),
"
)
"
)
-
1
)
Trim(ParamArr(
1
))
iPrmA
=
1
End If
End If
'
Position the cursor one line above the selected text.
ActiveDocument.Selection.LineUp
ActiveDocument.Selection.LineDown
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection.NewLine
Descr
=
""
ActiveDocument.Selection
=
"
/**
"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* @Function name:
"
+
fcName
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
* @Description :
"
ActiveDocument.Selection.NewLine
'
Print the parameter list.
Last
=
iPrmA
Do While iPrmA
<>
0
'
Remove a line feed from any of the arguments.
If InStr(ParamArr(iPrmA), vbLf)
<>
0
Then
ParamArr(iPrmA)
=
Right(ParamArr(iPrmA), _
(Len(ParamArr(iPrmA))
-
_
InStr(ParamArr(iPrmA), vbLf)))
Trim(ParamArr(iPrmA))
End If
ParamArr(iPrmA)
=
StripTabs(ParamArr(iPrmA))
'
If there are 2+ parameters, the first parameter will
'
have a
'
(
'
prepended to it, remove it here:
if
iPrmA
=
Last AND Last
<>
1
then
ParamArr(iPrmA)
=
Right(ParamArr(iPrmA), _
Len(ParamArr(iPrmA))
-
1
)
End If
ActiveDocument.Selection
=
"
* @Argument :
"
+
_
ParamArr(iPrmA)
ActiveDocument.Selection.NewLine
iPrmA
=
iPrmA
-
1
Loop
ActiveDocument.Selection
=
"
* @Return type :
"
+
RetTp
ActiveDocument.Selection.NewLine
ActiveDocument.Selection
=
"
*/
"
ActiveDocument.Selection.NewLine
'
ActiveDocument.Selection = Descr
Else
MsgBox(
"
It is possible that the function you are trying to
"
+
_
"
work with has a syntax error.
"
)
End
if
End If
Else
MsgBox(
"
You need to have an active C/C++ document open
"
+
_
vbLF
+
"
with the function prototype selected.
"
)
End If
End Sub