Notifications
Clear all

[Closed] How to reliably get all macroscript headers from an .mcr file

hey guys, for my setup script i need a way to reliably get all macro headers from a macroscript file

i need macroname, category, icons, tooltip, buttontext

it also needs to check if macroscripts may be commented out using // or –…

i started on this already, but i don’t have any experience with the filestream functions, though i’m sure there are a bunch of gurus on this topic around here… anyone?

7 Replies

deleted nonsense

 PEN

Well this shouldn’t be that hard I don’t think. You have known headings that you can search for then look at what comes after them.

Since I need to do the same let me see if I can get you started with some code. I have written XML readers in the past so I just need to dig that up.

 PEN

This will return the line and position on that line where the word MacroScript is found.


 msFileName="\\PEN_MirrorObjects.mcr"
 mS=(getDir #ui)+"\\macroScripts"+msfileName
 
 openedFile=openfile ms mode:"r"
 lineNum=0
 while not (eof openedFile) do
 (
 	line=readLine openedFile
 	lineNum+=1
 	index=findString line "macroScript"
 	if index!=undefined then 
 	(
 		format "On Line: % \"macroScript\" was found at position: %
" lineNum index
 	)
 )
 
 PEN

Here is the hasle with reading macros. You can have the full definition of a macro on one line or several. This means that once you have found the parameter name like buttonText you will have to read the rest of the line until you have either reached the end of the line or reached the next parameter. No big deal really. What I am currently working on will store each found macroScript definition in a struct and store that in an array. I’ll store which file and the information about the macro so that you can then just loop through the array of structs to do what youneed to do.

Beware tough that since you’re searching for text in a script, the word “macroScript” can also be used in strings or comments

 PEN

Ya I have thought about that but not sure what to do about it. This is part of why I’m not sure this idea is really the best. There can be many problems associated with it. I guess that if macroscript is found you can then test if any other parameters are found and if so then store it. Still isn’t full proof really.

PEN, i have written some code to check if the macroscript is inside comments (“/**/” and “–”)

it’s pretty basic but the code looks very much like a hack… i’ll try to clean it up and post it when i find the time

i also had another idea that i think would be much safer, but i’ve run into wall with it… still maybe one could find a way to use it:

you could iterate over the mcr file using “readExpr”, so just execute all the code in there. i tried this with “macro_layers.mcr”. the beautiful thing with this is that once a macroscript is executed, the value returned from the readExpr function will be the macro’s id

this would actually be all you need to make this method foolproof, if there was a proper way to get info about a macro by it’s id. but the way i see it there’s only macros.list() which will dump macro information to the listener. (it contains the name, source file, category, tooltip… all you need)

you could get the info from within the listener… but that would, again, be just a hack.

is there maybe a way to redirect listener output to a stringstream or file?