script() function that sets Script

Posted By: AndrewAMD

script() function that sets Script - 07/19/19 18:55

jcl,

It would be handy if there was a function script() that sets Script, much like algo() sets Algo.

I have an application where I am producing a lot of log files in a batch-heavy setup, with many unique command line options. It would be useful if I can supply strf() as an input.

Thanks,
Andrew

EDIT: In retrospect, it looks like Script has no effect on the name of log files, but only LogNumber does. Nonetheless, I do need to change Script when I have multiple live zorros running the same script.
Posted By: Spirit

Re: script() function that sets Script - 07/19/19 21:44

Why not script(string s) { Script = s; } ?
Posted By: AndrewAMD

Re: script() function that sets Script - 07/20/19 02:12

Wouldn’t that cause undefined behavior?

For example, strf outputs a temporary pointer.
Posted By: Spirit

Re: script() function that sets Script - 07/20/19 05:47

Youre right, but what about this

void script(string s) { static char S[50]; strcpy(S,s); Script = S; }
Posted By: AndrewAMD

Re: script() function that sets Script - 07/20/19 14:18

This works, thanks.

I think the newbies might appreciate a permanent implementation of this. (Rookie mistake: Script = strf(....))
Posted By: jcl

Re: script() function that sets Script - 07/22/19 05:50

We would then need such functions for all the predefined strings. But I'll put a remark in the manual for this case.
Posted By: AndrewAMD

Re: script() function that sets Script - 07/22/19 13:28

Makes sense, thanks.
© 2024 lite-C Forums