BOOL PlayMacro(LPCMDLIST lpCmdList, LPTSTR lpFileName, int nRepeat, BOOL fSequenceAll, LPLIST lpMacroList, HWND hParent, int PhotoCDResOverride, LPTSTR lpMacroName) /***********************************************************************/ { LPIMAGE lpImage; LPCMDLIST lpNewList; int nActivates, iCount; ITEMID idCommand; STRING szString, szAppName; BOOL fError; BOOL fSequence, fCmdSequence, fCopyPackets; LIST MacroList; LPCMDPKT lpCmdPkt, lpNextPkt; MACROSETUP Setup; COMMAND_TYPE CommandType; HWND hDlg = NULL; lpAbortProc = NULL; if (!hParent) hParent = PictPubApp.Get_hWndAstral(); // see if we need to copy our packets fCopyPackets = nRepeat > 1; if (!lpMacroList) { // read in the entire macro file for faster processing if (!ReadMacro(lpFileName, &MacroList)) return(FALSE); lpMacroList = &MacroList; } // count the number of activates in the macro file // because it affects sequencing nActivates = CountType(lpMacroList, CT_ACTIVATE); // turn of macro play mode and tell the world MacroMode = MM_PLAY; if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) { if ( AstralStrEx( IDS_MACROPLAY, szString, sizeof(szString) ) ) { lstrcat( szAppName, szString ); SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); } } // reset untitled number so that if a macro is played it // can deal with untitled images the same Control.UntitledNo = 0; // If no command list passed in to work on (Macro Batch Mode) // then get command list for active image if (!lpCmdList) { if (lpImage = GetActiveImage()) lpCmdList = lpImage->lpCmdList; else lpCmdList = NULL; } // See if the macro contains any low res loads and // if so ask to user if he'd like to convert them // to hi res loads and if so do the convert if (FindCommand(lpMacroList, IDS_CMD_LOWRESLOAD)) if (AstralAffirm(IDS_CONVERTLOWRES)) if (!ConvertLowResLoad(lpMacroList)) { DestroyPacketList(lpMacroList); return(FALSE); } // disable all mouse and keyboard input during macro play EnableWindow(hParent, FALSE); // if not in a threading environment and caller wants us // to display a progress dialog, then set it up and do it if (!Control.UseThreading) { iCount = ListGetCount(lpMacroList) - nActivates; iCount *= nRepeat; Setup.iTotal = iCount; Setup.idDialog = IDD_MACRO_STATUS; Setup.lpFileName = NULL; hDlg = AstralDlgParam( YES, PictPubApp.GetResourceHandle(), hParent, IDD_MACRO_STATUS, DlgMacroStatusProc, (LPARAM)(LPVOID)&Setup ); if (hDlg) { if (lpMacroName) { STRING szString; GetWindowText(hDlg, szString, sizeof(szString)); lstrcat(szString, _T(" - ")); lstrcat(szString, lpMacroName); SetWindowText(hDlg, szString); } UpdateWindow(hDlg); } } // Repeat macro nRepeat number of times fError = FALSE; while (--nRepeat >= 0 && !fError) { if (lpAbortProc && (*lpAbortProc)()) break; // back to beginning of macro file lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); // initialize sequencing fSequence = fSequenceAll; while (!fError && lpNextPkt) { if (lpAbortProc && (*lpAbortProc)()) { fError = TRUE; break; } // get the packet to work on if (fCopyPackets) { lpCmdPkt = CopyPacket(lpNextPkt); if (!lpCmdPkt) { fError = TRUE; break; } } else { ListUnlink(lpMacroList, lpNextPkt); lpCmdPkt = lpNextPkt; } // get command id and parms for this command idCommand = lpCmdPkt->idCommand; // Find out whether this command requires sequencing // set it here, so command can change it if needed before // we actually set fSequence fCmdSequence = GetCommandSequence(idCommand); CommandType = GetCommandType(idCommand); // Handle the different types of commands switch (CommandType) { case CT_LOAD: // create new command list for load lpNewList = CreateCommandList(); if (lpNewList) { ListAddTail(&lpNewList->PacketList, lpCmdPkt); // if we already have a command list containing commands, // kick off the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // setup new command list for us to work with lpCmdList = lpNewList; lpCmdList->PhotoCDResOverride = PhotoCDResOverride; // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } } break; case CT_COPY: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); // If there are any activates in this macro make sure a // command that creates an image processes immediately if (nActivates) { PlaybackCommands(lpCmdList); FlushCommands(lpCmdList); fSequence = fSequenceAll; fCmdSequence = NO; // already sequenced } break; case CT_SAVE: case CT_EDIT: case CT_MASK: case CT_MODE: case CT_EDITUNDO: case CT_MASKUNDO: case CT_EDITOBJ: case CT_CLOSE: // Make sure we have a command list to work with if (!lpCmdList) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } if (CommandType == CT_SAVE) { PlaybackCommands(lpCmdList); if (!lpCmdList->ThreadData.lpImage) { Message(IDS_NOIMAGETOWORKON); fError = TRUE; break; } } // Just add this command to the command list ListAddTail(&lpCmdList->PacketList, lpCmdPkt); if (CommandType != CT_CLOSE) break; case CT_ACTIVATE: // Program or commands that affect window activation // are processed here switch (idCommand) { case IDS_CMD_CLOSE: case IDS_CMD_ACTIVATEWINDOW: { // if we already have a command list containing commands, // kick of the execution of those commands before we // switch to the new command list if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); // if some command in the command list affects // sequencing force the whole command list to // be processed if (fSequence) { FlushCommands(lpCmdList); fSequence = fSequenceAll; } } // if this was a close command, then wack the command list pointer if (idCommand == IDS_CMD_CLOSE) lpCmdList = NULL; else { // now process the activate and get a new command list lpNewList = ProgActivateWindow( (LPACTIVATEWINDOW_PARMS)lpCmdPkt->lpParms); // setup the new command list if we got one if (lpNewList) lpCmdList = lpNewList; else { CommandError(idCommand); fError = TRUE; } // activate don't go through command processing // so we have to free it up here FreeUpPacket(lpCmdPkt); } } break; default: break; } break; default: break; } // if command just handled requires sequencing // set sequencing flag if (fCmdSequence) fSequence = YES; if (fCopyPackets) // get next command packet in macro list lpNextPkt = (LPCMDPKT)ListGetNext(lpNextPkt); else // head of list will be next one if we're not copying lpNextPkt = (LPCMDPKT)ListGetHead(lpMacroList); } } // get rid of macro list DestroyPacketList(lpMacroList); // if we already have a command list containing commands, // kick off the execution of those commands if (lpCmdList && !ListIsEmpty(&lpCmdList->PacketList)) { PlaybackCommands(lpCmdList); if (fSequenceAll) FlushCommands(lpCmdList); } // turn off the macro mode EnableWindow(hParent, TRUE); if ( AstralStrEx( IDS_APPNAME, szAppName, sizeof(szAppName) ) ) SetWindowText( PictPubApp.Get_hWndAstral(), szAppName ); // if we have a progress dialog, nuke it if (hDlg) AstralDlgEnd(hDlg, TRUE); // if we are display the macro status for another modal dialog // make sure the main app stuff is still disabled if (hParent != PictPubApp.Get_hWndAstral()) { EnableOverlappedWindow( PictPubApp.Get_hWndAstral(), FALSE ); EnableWindow(PictPubApp.Get_hWndAstral(), FALSE); } MacroMode = MM_NONE; return(TRUE); }
void PlayBatchMacro(LPLIST lpQueueList) /***********************************************************************/ { LPQUEUEITEM lpQueueItem = NULL; LPMACROITEM lpMacroItem; FNAME szFileName; LIST TempList; BOOL fError = TRUE; fPCDNotice = FALSE; while (TRUE) { if (lpQueueItem) lpQueueItem = (LPQUEUEITEM)ListGetNext(lpQueueItem); else lpQueueItem = (LPQUEUEITEM)ListGetHead(lpQueueList); if (!lpQueueItem) { fError = FALSE; break; } ListInit(&lpQueueItem->PacketList); // create a command list for the load command if (!CreateLoadFileParms(0, lpQueueItem->szFileName, TRUE, &lpQueueItem->cmsInfo, &lpQueueItem->PhotoCDResOverride, &lpQueueItem->parms)) continue; lpMacroItem = NULL; while (TRUE) { if (lpMacroItem) lpMacroItem = (LPMACROITEM)ListGetNext(lpMacroItem); else lpMacroItem = (LPMACROITEM)ListGetHead(&lpQueueItem->MacroList); if (!lpMacroItem) break; if ( !LookupExtFile( lpMacroItem->szMacro, szFileName, IDN_MACRO ) ) continue; // read in the entire macro file for faster processing if (!ReadMacro(szFileName, &TempList)) continue; if (MacroAnyLoadCommands(&TempList)) { Message(IDS_BADBATCHMACRO); DestroyPacketList(&TempList); continue; } ListAddTail(&lpQueueItem->PacketList, ListGetHead(&TempList)); } if (!SetupMacro(lpQueueItem)) break; } if (!fError) { if (EnableLogging(TRUE)) { lpQueueItem = NULL; while (!fError) { if (lpQueueItem) lpQueueItem = (LPQUEUEITEM)ListGetNext(lpQueueItem); else lpQueueItem = (LPQUEUEITEM)ListGetHead(lpQueueList); if (!lpQueueItem) break; if (!PlayMacro(NULL, NULL, 1, NO, &lpQueueItem->PacketList, NULL, lpQueueItem->PhotoCDResOverride)) break; } EnableLogging(FALSE); } } lpQueueItem = NULL; while (TRUE) { if (lpQueueItem) lpQueueItem = (LPQUEUEITEM)ListGetNext(lpQueueItem); else lpQueueItem = (LPQUEUEITEM)ListGetHead(lpQueueList); if (!lpQueueItem) break; DestroyPacketList(&lpQueueItem->PacketList); DestroyPtrList(&lpQueueItem->MacroList); } DestroyPtrList(lpQueueList); }
void ReadDefinitions(OBJECT *token, OBJECT encl, unsigned char res_type) { OBJECT t, res, res_target, export_list, import_list, link, y, z; OBJECT curr_encl; BOOLEAN compulsory_par, has_import_encl; t = *token; while( res_type==LOCAL || is_string(t, KW_NAMED) || is_string(t, KW_IMPORT) ) { curr_encl = encl; if( is_string(t, KW_LANGDEF) ) { ReadLangDef(encl); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == PREPEND || type(t) == SYS_PREPEND ) { ReadPrependDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == INCG_REPEATED || type(t) == SINCG_REPEATED ) { ReadIncGRepeatedDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == DATABASE || type(t) == SYS_DATABASE ) { ReadDatabaseDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } if( !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) && !is_string(t, KW_EXTEND) && !is_string(t, KW_EXPORT) ) break; /* get import or extend list and change scope appropriately */ BodyParNotAllowed(); New(import_list, ACAT); has_import_encl = FALSE; if( is_string(t, KW_IMPORT) ) { Dispose(t); t = LexGetToken(); while( type(t) == CLOSURE || (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF) && !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED)) ) { if( type(t) == CLOSURE ) { if( type(actual(t)) == LOCAL ) { /* *** letting this through now if( res_type == NPAR && has_par(actual(t)) ) { Error(5, 46, "named parameter import %s has parameters", WARN, &fpos(t), SymName(actual(t))); } else { *** */ PushScope(actual(t), FALSE, TRUE); if( actual(t) == encl ) has_import_encl = TRUE; Link(import_list, t); /* *** } *** */ } else { Error(5, 26, "import name expected here", WARN, &fpos(t)); Dispose(t); } } else { Error(5, 27, "import %s not in scope", WARN, &fpos(t), string(t)); Dispose(t); } t = LexGetToken(); } } else if( is_string(t, KW_EXTEND) ) { Dispose(t); t = LexGetToken(); while( type(t) == CLOSURE || (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF) && !is_string(t, KW_MACRO)) ) { if( type(t) == CLOSURE ) { if( imports(actual(t)) != nilobj ) { Error(5, 48, "%s has %s clause, so cannot be extended", WARN, &fpos(t), SymName(actual(t)), KW_IMPORT); } else if( type(actual(t)) == LOCAL ) { PushScope(actual(t), FALSE, FALSE); curr_encl = actual(t); debug1(DRD, D, " curr_encl = %s", SymName(curr_encl)); Link(import_list, t); } else { Error(5, 28, "%s symbol name expected here", WARN, &fpos(t), KW_EXTEND); Dispose(t); } } else { Error(5, 29, "extend symbol %s not in scope", WARN,&fpos(t),string(t)); Dispose(t); } t = LexGetToken(); } } /* get export list and store for setting visible flags below */ New(export_list, ACAT); if( is_string(t, KW_EXPORT) ) { Dispose(t); SuppressScope(); t = LexGetToken(); while( is_word(type(t)) && !is_string(t, KW_DEF) && !is_string(t, KW_IMPORT) && !is_string(t, KW_MACRO) && !is_string(t, KW_EXTEND) ) { Link(export_list, t); t = LexGetToken(); } UnSuppressScope(); } if( res_type == LOCAL && !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) ) { Error(5, 30, "keyword %s or %s expected here", WARN, &fpos(t), KW_DEF, KW_MACRO); break; } if( res_type == NPAR && !is_string(t, KW_NAMED) ) { Error(5, 31, "keyword %s expected here", WARN, &fpos(t), KW_NAMED); break; } if( is_string(t, KW_MACRO) ) { if( Down(export_list) != export_list ) Error(5, 32, "ignoring export list of macro", WARN, &fpos(t)); res = ReadMacro(&t, curr_encl, encl); } else { SuppressScope(); Dispose(t); t = LexGetToken(); /* check for compulsory keyword */ if( res_type == NPAR && is_string(t, KW_COMPULSORY) ) { compulsory_par = TRUE; Dispose(t); t = LexGetToken(); } else compulsory_par = FALSE; /* find name of symbol and insert it */ if( !is_word(type(t)) ) { Error(5, 33, "symbol name expected here", WARN, &fpos(t)); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } res = InsertSym(string(t), res_type, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, curr_encl, nilobj); if( curr_encl != encl ) visible(res) = TRUE; if( has_import_encl ) { imports_encl(res) = TRUE; debug1(DCE, D, " setting import_encl(%s) to TRUE", SymName(res)); } if( compulsory_par ) { has_compulsory(encl)++; is_compulsory(res) = TRUE; } Dispose(t); t = LexGetToken(); /* find alternative names for this symbol */ while( is_word(type(t)) && !is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) && !is_string(t, KW_FORCE) && !is_string(t, KW_INTO) && !is_string(t, KW_HORIZ) && !is_string(t, KW_PRECEDENCE) && !is_string(t, KW_ASSOC) && !is_string(t, KW_LEFT) && !is_string(t, KW_RIGHT) && !is_string(t, KW_BODY) && !is_string(t, KW_LBR) && !is_string(t, KW_BEGIN) ) { InsertAlternativeName(string(t), res, &fpos(t)); Dispose(t); t = LexGetToken(); } /* find force, if any */ if( is_string(t, KW_FORCE) ) { force_target(res) = TRUE; Dispose(t); t = LexGetToken(); if( !is_string(t, KW_INTO) && !is_string(t, KW_HORIZ) ) Error(5, 34, "%s expected here", WARN, &fpos(t), KW_INTO); } /* find horizontally, if any */ if( is_string(t, KW_HORIZ) ) { horiz_galley(res) = COLM; Dispose(t); t = LexGetToken(); /* *** want to allow KW_HORIZ with @Target form now if( !is_string(t, KW_INTO) ) Error(5, 35, "%s expected here", WARN, &fpos(t), KW_INTO); *** */ } /* find into clause, if any */ res_target = nilobj; if( is_string(t, KW_INTO) ) { UnSuppressScope(); Dispose(t); t = LexGetToken(); if( type(t) != LBR ) { Error(5, 36, "%s expected here", WARN, &fpos(t), KW_LBR); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } res_target = Parse(&t, curr_encl, FALSE, FALSE); SuppressScope(); if( t == nilobj ) t = LexGetToken(); } /* find precedence clause, if any */ if( is_string(t, KW_PRECEDENCE) ) { int prec = 0; UnSuppressScope(); Dispose(t); t = LexGetToken(); while( type(t) == WORD && decimaldigit(string(t)[0]) ) { prec = prec * 10 + digitchartonum(string(t)[0]); Dispose(t); t = LexGetToken(); } SuppressScope(); if( prec < MIN_PREC ) { Error(5, 37, "precedence is too low (%d substituted)", WARN, &fpos(t), MIN_PREC); prec = MIN_PREC; } else if( prec > MAX_PREC ) { Error(5, 38, "precedence is too high (%d substituted)", WARN, &fpos(t), MAX_PREC); prec = MAX_PREC; } precedence(res) = prec; } /* find associativity clause, if any */ if( is_string(t, KW_ASSOC) ) { UnSuppressScope(); Dispose(t); t = LexGetToken(); if( is_string(t, KW_LEFT) ) right_assoc(res) = FALSE; else if( !is_string(t, KW_RIGHT) ) Error(5, 39, "associativity altered to %s", WARN, &fpos(t), KW_RIGHT); SuppressScope(); Dispose(t); t = LexGetToken(); } /* find left parameter, if any */ if( is_string(t, KW_LEFT) ) { Dispose(t); t = LexGetToken(); if( type(t) != WORD ) { Error(5, 40, "cannot find %s parameter name", WARN, &fpos(t), KW_LEFT); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } InsertSym(string(t), LPAR, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, res, nilobj); Dispose(t); t = LexGetToken(); } /* find named parameters, if any */ UnSuppressScope(); ReadDefinitions(&t, res, NPAR); /* find right or body parameter, if any */ if( is_string(t, KW_RIGHT) || is_string(t, KW_BODY) ) { has_body(res) = is_string(t, KW_BODY); SuppressScope(); Dispose(t); t = LexGetToken(); if( type(t) != WORD ) { Error(5, 41, "cannot find %s parameter name", WARN,&fpos(t),KW_RIGHT); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } InsertSym(string(t), RPAR, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, res, nilobj); UnSuppressScope(); Dispose(t); t = LexGetToken(); } /* read local definitions and body */ if( res_target != nilobj ) InsertSym(KW_TARGET, LOCAL, &fpos(res_target), DEFAULT_PREC, FALSE, FALSE, 0, res, res_target); if( type(t) == WORD && StringEqual(string(t), KW_LBR) ) { z = NewToken(LBR, &fpos(t), 0, 0, LBR_PREC, StartSym); Dispose(t); t = z; } else if( type(t) == WORD && StringEqual(string(t), KW_BEGIN) ) { z = NewToken(BEGIN, &fpos(t), 0, 0, BEGIN_PREC, StartSym); Dispose(t); t = z; } else if( type(t) != LBR && type(t) != BEGIN ) Error(5, 42, "opening left brace or @Begin of %s expected", FATAL, &fpos(t), SymName(res)); if( type(t) == BEGIN ) actual(t) = res; PushScope(res, FALSE, FALSE); BodyParAllowed(); sym_body(res) = Parse(&t, res, TRUE, FALSE); /* set visible flag of the exported symbols */ for( link=Down(export_list); link != export_list; link=NextDown(link) ) { Child(y, link); z = SearchSym(string(y), StringLength(string(y))); if( z == nilobj || enclosing(z) != res ) Error(5, 43, "exported symbol %s is not defined in %s", WARN, &fpos(y), string(y), SymName(res)); else if( has_body(res) && type(z) == RPAR ) Error(5, 44, "body parameter %s may not be exported", WARN, &fpos(y), string(y)); else if( visible(z) ) Error(5, 45, "symbol %s exported twice", WARN, &fpos(y), string(y)); else visible(z) = TRUE; } DisposeObject(export_list); /* pop scope of res */ PopScope(); } /* pop import scopes and store imports in sym tab */ for( link=Down(import_list); link != import_list; link=NextDown(link) ) { PopScope(); } if( Down(import_list) == import_list || curr_encl != encl ) { DisposeObject(import_list); import_list = nilobj; } else { imports(res) = import_list; } BodyParAllowed(); if( t == nilobj ) t = LexGetToken(); } /* end while */ *token = t; return; } /* end ReadDefinitions */