The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Redefine macro by appending new line

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 09/23/2005 : 10:04:20 AM
Origin Version (Select Help-->About Origin): 7.5SR5
Operating System: Win2000

Hi,

I'd like to be able to modify an existing macro by appending a new line at 'run time' eg

change
def Pete {
lines 1...n
}
to
def Pete {
lines 1..n
new line
}

simply doing something like
def pete {
type pete;
}

def pete {
pete;
type pete;
}

does horrible things like comand error or instant shutdown...

The issue here is that the macro is of the same name but could differ depending on the application but I will want to add the same line.

This would be really a useful way to add new functionality to old origin project files so any help would be appreciated.

Thanks,

Cheers,

pete

4   L A T E S T    R E P L I E S    (Newest First)
peter.cook Posted - 10/05/2005 : 09:08:47 AM
Hi,

Managed to use the file editing as described below. Does the job.


void show_file(string strfile = "htdr2001macros.cnf") // old macro file
{
string LTString;
string striFilename = GetAppPath() + strfile;
string stroFilename = GetAppPath() + "ftemp.cnf";
if(!DeleteFile(stroFilename)) {};
stdioFile ffo(stroFilename,file::modeCreate | file::modeReadWrite);

stdioFile ff;
bool bRet = ff.Open(striFilename, file::modeRead);
if(!bRet)
{
out_str("file not found!");
return;
}

string strTemp;
int CopyThis=0;
int CopyLine;
while(ff.ReadString(strTemp))
{
if((strTemp.Left(4).CompareNoCase("def ")==0)&&(CopyLine>1)) CopyThis=0;
if(strTemp.CompareNoCase("def displaygraphall {")==0) {
CopyThis=1;
}
if(CopyThis==1) {
//out_str(strTemp);
CopyLine++;
if(CopyLine!=1) {
ffo.WriteString(strTemp);
} else {
ffo.WriteString("def TempMacro {");
}
}
}

ff.Close();
ffo.WriteString("");
ffo.WriteString("def DisplayGraphall {");
ffo.WriteString("TempMacro;");
ffo.WriteString("run.section(Smilesjpg.ogs,\"AddImagesToGraph\");");
ffo.WriteString("};");
LTString="run ftemp.cnf";
out_str(LTString);
LT_execute(LTString);
//if(!DeleteFile(stroFilename)) {};
}


adds the line run.section(Smilesjpg.ogs,AddImagesToGraph); to the end of the displaygraphall macro and then reloads/redefines this macro.

Cheers,

pete

Mike Buess Posted - 09/25/2005 : 3:54:03 PM
Hi Pete,

"Placeholder" is my own ad hoc terminology for a function or object that might take on a number of forms or might even be absent. There's probably a more acceptable word for it. You can print a macro definition to the script window with 'def macroName' but I'm not aware of a way to redirect the definition to anything useful (like a string, file or even notes window). Of course if your macro runs a script file... def pete {run.file(pete.cnf)} ...you could edit that file with OriginC or FUM. However, that would probably require modifications to your old projects as well.

Mike Buess
Origin WebRing Member
peter.cook Posted - 09/25/2005 : 1:29:16 PM
Hi Mike,

Thanks for your reply! This method is useful and will help in a number of cases ie new apps and old apps where the code is unattached. (I wasn't aware of the use of a placeholder - maybe I spread a few around the code (eg post data input, post curve fit, post graph display, post results creation etc..) allowing for general modifications at a later date - I like this idea a lot. Something to think about thanks.

One case would still remain - old ops where the code is attached ie I can't insert a placeholder in these old saved opj files (attached files of). Any ideas or do you reckon I'm stuck here?

Q. Is there a way to list the code (eg as string) of a defined macro?

Maybe I need to consider an app to edit the attached code of old opj files. I can then (for cnf files) just rerun the whole file. This works manually (just tried) and I can save the new code. I just need a to find a way to do it via code.

Thanks again,

Cheers,

pete



Mike Buess Posted - 09/25/2005 : 09:16:06 AM
Hi Pete,

I'm not surprised that your attempt to redefine a macro by calling itself has such dire consequences. Much safer to add a placeholder command in the original macro like this...

def pete {
type pete;
{pete2};
};

def pete2 {
type pete2;
};

The brackets around the pete2 call merely suppress the command error that would result if the pete2 macro was undefined.

Mike Buess
Origin WebRing Member

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000