@@ -53,9 +53,11 @@ static strConstant cstrTypes = "Variable|String|WAVE|NVAR|SVAR|DFREF|FUNCREF|STR
5353// Loosely based on the WM procedure from the documentation
5454// Returns a human readable string for the given parameter/return type.
5555// See the documentation for FunctionInfo for the exact values.
56- Function /S interpretParamType ( ptype, paramOrReturn)
56+ Function /S interpretParamType ( ptype, paramOrReturn, funcInfo )
5757 variable ptype, paramOrReturn
58+ string funcInfo
5859
60+ string typeName
5961 string typeStr = ""
6062
6163 if ( paramOrReturn != 0 && paramOrReturn != 1 )
@@ -117,7 +119,11 @@ Function/S interpretParamType(ptype, paramOrReturn)
117119 elseif ( ptype & 0x100 )
118120 typeStr += "dfref"
119121 elseif ( ptype & 0x200 )
120- typeStr += "struct"
122+ if ( GetStructureArgument ( funcInfo, typeName))
123+ typeStr += typeName
124+ else
125+ typeStr += "struct"
126+ endif
121127 elseif ( ptype & 0x400 )
122128 typeStr += "funcref"
123129 endif
@@ -191,7 +197,7 @@ Function/S interpretParameters(funcInfo)
191197
192198 for ( i = 0; i < numParams; i += 1 )
193199 sprintf key, "PARAM_%d_TYPE" , i
194- paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1 )
200+ paramType = interpretParamType ( NumberByKey ( key, funcInfo) , 1, funcInfo )
195201
196202 if ( i == numParams - numOptParams)
197203 str += "["
@@ -211,6 +217,34 @@ Function/S interpretParameters(funcInfo)
211217 return str
212218End
213219
220+ // check if Function has as a structure as first parameter
221+ //
222+ // the structure definition has to be in the first line after the function definition
223+ //
224+ // @param[in] funcInfo output of FunctionInfo for the function in question
225+ // @param[out] structureName matched name of the structure as string.
226+ // Not changed if 0 is returned.
227+ //
228+ // @returns 1 if function has such a parameter, 0 otherwise
229+ Function GetStructureArgument ( funcInfo, structureName)
230+ string funcInfo
231+ string & structureName
232+
233+ string declaration, re, str0
234+
235+ if ( NumberByKey ( "PARAM_0_TYPE" , funcInfo) & ( 0x200 | 0x1000 )) // struct | pass-by-reference
236+ declaration = getFunctionLine ( 1, funcInfo)
237+ re = "(?i)^\s *struct\s +(\w +)\s +"
238+ SplitString / E= ( re) declaration, str0
239+ if ( V_flag == 1 )
240+ structureName = str0
241+ return 1
242+ endif
243+ endif
244+
245+ return 0
246+ End
247+
214248// Returns a cmd for the given fill *and* stroke color
215249Function /S getColorDef ( color)
216250 string color
@@ -313,7 +347,7 @@ Function addDecoratedFunctions(module, procedure, declWave, lineWave)
313347 if ( isEmpty ( fi))
314348 debugPrint ( "macro or other error for " + module + "#" + func)
315349 endif
316- returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) ,0 )
350+ returnType = interpretParamType ( NumberByKey ( "RETURNTYPE" , fi) , 0, fi )
317351 threadsafeTag = interpretThreadsafeTag ( StringByKey ( "THREADSAFE" , fi))
318352 specialTag = interpretSpecialTag ( StringByKey ( "SPECIAL" , fi))
319353 subtypeTag = interpretSubtypeTag ( StringByKey ( "SUBTYPE" , fi))
@@ -339,7 +373,7 @@ Function addDecoratedConstants(module, procedureWithoutModule, declWave, lineWav
339373 String procText, re, def, name
340374
341375 // get procedure code
342- procText = getProcedureText ( module, procedureWithoutModule)
376+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
343377 numLines = ItemsInList ( procText, "\r " )
344378
345379 // search code and return wavLineNumber
@@ -382,7 +416,7 @@ Function addDecoratedMacros(module, procedureWithoutModule, declWave, lineWave)
382416 String procText, re, def, name, arguments, type
383417
384418 // get procedure code
385- procText = getProcedureText ( module, procedureWithoutModule)
419+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
386420 numLines = ItemsInList ( procText, "\r " )
387421
388422 // search code and return wavLineNumber
@@ -428,7 +462,7 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
428462 string procText, reStart, reEnd, name, StaticKeyword
429463
430464 // get procedure code
431- procText = getProcedureText ( module, procedureWithoutModule)
465+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
432466 numLines = ItemsInList ( procText, "\r " )
433467 if ( numLines == 0 )
434468 debugPrint ( "no Content in Procedure " + procedureWithoutModule)
@@ -498,7 +532,7 @@ Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
498532 String currentMenu = ""
499533
500534 // get procedure code
501- procText = getProcedureText ( module, procedureWithoutModule)
535+ procText = getProcedureText ( "" , 0, module, procedureWithoutModule)
502536 numLines = ItemsInList ( procText, "\r " )
503537
504538 // search code and return wavLineNumber
@@ -878,18 +912,57 @@ Function/S nicifyProcedureList(list)
878912 return niceList
879913End
880914
881- // returns code of procedure in module
915+ // Get the specified line of code from a function
882916//
883- // @param module independent module
884- // @param procedure procedure without module definition
885- Function /S getProcedureText ( module, procedure)
886- string module, procedure
917+ // @see getProcedureText
918+ //
919+ // @param funcInfo output of FunctionInfo for the function in question
920+ // @param lineNo line number relative to the function definition
921+ // set to -1 to return lines before the procedure that are not part of the preceding macro or function
922+ // see `DisplayHelpTopic ( "ProcedureText" ) `
923+ //
924+ // @returns lines of code from a function inside a procedure file
925+ Function /S getFunctionLine ( lineNo, funcInfo)
926+ variable lineNo
927+ string funcInfo
928+
929+ string funcName, module, procedure, context
930+ variable linesOfContext
931+
932+ funcName = StringByKey ( "NAME" , funcInfo)
933+ module = StringByKey ( "INDEPENDENTMODULE" , funcInfo)
934+ procedure = StringByKey ( "PROCWIN" , funcInfo)
935+
936+ linesOfContext = lineNo < 0 ? lineNo : 0
937+ context = getProcedureText ( funcName, linesOfContext, module, procedure)
938+
939+ if ( lineNo < 0 )
940+ return context
941+ endif
942+
943+ return StringFromList ( lineNo, context, "\r " )
944+ End
945+
946+ // get code of procedure in module
947+ //
948+ // see `DisplayHelpTopic ( "ProcedureText" ) `
949+ //
950+ // @param funcName Name of Function. Leave blank to get full procedure text
951+ // @param linesOfContext line numbers in addition to the function definition. Set to 0 to return only the function.
952+ // set to -1 to return lines before the procedure that are not part of the preceding macro or function
953+ // @param module independent module
954+ // @param procedure procedure without module definition
955+ // @return multi-line string with function definition
956+ Function /S getProcedureText ( funcName, linesOfContext, module, procedure)
957+ string funcName, module, procedure
958+ variable linesOfContext
887959
888960 if ( ! isProcGlobal ( module))
961+ debugPrint ( procedure + " is not in ProcGlobal" )
889962 procedure = procedure + " [" + module + "]"
890963 endif
891964
892- return ProcedureText ( "" , 0 , procedure)
965+ return ProcedureText ( funcName , linesOfContext , procedure)
893966End
894967
895968// Returns 1 if the procedure file has content which we can show, 0 otherwise
@@ -1152,7 +1225,7 @@ static Function setCheckSum(procedure)
11521225
11531226 timer = timerStart ()
11541227
1155- procText = getProcedureText ( procedure. module, procedure. name)
1228+ procText = getProcedureText ( "" , 0, procedure. module, procedure. name)
11561229 returnValue = setGlobalStr ( "parsingChecksum" , Hash ( procText, 1 ))
11571230
11581231 setCheckSumTime ( timerStop ( timer))
0 commit comments