@@ -2135,19 +2135,32 @@ Parse_stat MCSave::parse(MCScriptPoint &sp)
21352135 (PE_SAVE_BADEXP, sp);
21362136 return PS_ERROR;
21372137 }
2138- if (sp. next (type) != PS_NORMAL)
2139- return PS_NORMAL;
2140- if (sp.lookup (SP_FACTOR, te) != PS_NORMAL || te-> which != PT_AS )
2138+
2139+ /* Parse optional "as _" clause */
2140+ if (sp.skip_token (SP_FACTOR, TT_PREP, PT_AS) == PS_NORMAL )
21412141 {
2142- sp.backup ();
2143- return PS_NORMAL;
2142+ if (sp.parseexp (False, True, &filename) != PS_NORMAL)
2143+ {
2144+ MCperror->add (PE_SAVE_BADFILEEXP, sp);
2145+ return PS_ERROR;
2146+ }
21442147 }
2145- if (sp.parseexp (False, True, &filename) != PS_NORMAL)
2148+
2149+ /* Parse optional "with format _" clause */
2150+ if (sp.skip_token (SP_REPEAT, TT_UNDEFINED, RF_WITH) == PS_NORMAL)
21462151 {
2147- MCperror->add
2148- (PE_SAVE_BADFILEEXP, sp);
2149- return PS_ERROR;
2152+ if (sp.skip_token (SP_FACTOR, TT_FUNCTION, F_FORMAT) != PS_NORMAL)
2153+ {
2154+ MCperror->add (PE_SAVE_BADFORMATEXP, sp);
2155+ return PS_ERROR;
2156+ }
2157+ if (sp.parseexp (False, True, &format) != PS_NORMAL)
2158+ {
2159+ MCperror->add (PE_SAVE_BADFORMATEXP, sp);
2160+ return PS_ERROR;
2161+ }
21502162 }
2163+
21512164 return PS_NORMAL;
21522165}
21532166
@@ -2205,16 +2218,45 @@ void MCSave::exec_ctxt(MCExecContext &ctxt)
22052218 ctxt . LegacyThrow (EE_SAVE_NOTASTACK);
22062219 return ;
22072220 }
2221+
2222+ MCStack *t_stack = static_cast <MCStack *>(optr);
2223+
2224+ MCAutoStringRef t_filename;
22082225 if (filename != NULL )
22092226 {
2210- MCAutoStringRef t_filename;
22112227 if (!ctxt . EvalExprAsStringRef (filename, EE_SAVE_BADNOFILEEXP, &t_filename))
22122228 return ;
2229+ }
22132230
2214- MCInterfaceExecSaveStackAs (ctxt, (MCStack *)optr, *t_filename);
2231+ MCAutoStringRef t_format;
2232+ if (format != NULL )
2233+ {
2234+ if (!ctxt.EvalExprAsStringRef (format, EE_SAVE_BADNOFORMATEXP, &t_format))
2235+ return ;
2236+ }
2237+
2238+ if (NULL != filename)
2239+ {
2240+ if (NULL != format)
2241+ {
2242+ MCInterfaceExecSaveStackAsWithVersion (ctxt, t_stack, *t_filename, *t_format);
2243+ }
2244+ else
2245+ {
2246+ MCInterfaceExecSaveStackAs (ctxt, t_stack, *t_filename);
2247+ }
22152248 }
22162249 else
2217- MCInterfaceExecSaveStack (ctxt, (MCStack*) optr);
2250+ {
2251+ if (NULL != format)
2252+ {
2253+ MCInterfaceExecSaveStackWithVersion (ctxt, t_stack, *t_format);
2254+ }
2255+ else
2256+ {
2257+ MCInterfaceExecSaveStack (ctxt, t_stack);
2258+ }
2259+ }
22182260}
22192261
22202262void MCSave::compile (MCSyntaxFactoryRef ctxt)
0 commit comments