void clear() { checkHasGraph(); checkNotRecording(); clearStack( Stack_Undo ); clearStack( Stack_Redo ); }
void Document::parse(const char *inXMLDocument) { ZS_THROW_INVALID_ARGUMENT_IF(!inXMLDocument) mSOF = inXMLDocument; ParserPos pos(*this); clearStack(); clearWarnings(); while (*pos) { if (Parser::parseAnyExceptElement(pos, mThis.lock())) continue; // check if this is an element if (Parser::isLegalName(*(pos+1), true)) { // this is an element ElementPtr element = XML::Element::create(); adoptAsLastChild(element); element->parse(pos); continue; } Parser::skipMismatchedEndTag(pos); } clearStack(); }
//Função para verificar na pilha o estado int VerificacaoPilha(Stack* Pilha,char* x) { int i,resposta; char ValorRemovido; char Valor_top; int n = strlen(x); i = 0; while(i < n) { if(x[i] == ')') { peek(Pilha,&Valor_top); if (sizeStack(Pilha) != 0 && Valor_top == '(') pop(Pilha,&ValorRemovido); else { clearStack(Pilha); return 0; } } else if(x[i] == ']') { peek(Pilha,&Valor_top); if (sizeStack(Pilha) != 0 && Valor_top == '[') pop(Pilha,&ValorRemovido); else { clearStack(Pilha); return 0; } } else if(x[i] == '}') { peek(Pilha,&Valor_top); if (sizeStack(Pilha) != 0 && Valor_top == '{') pop(Pilha,&ValorRemovido); else { clearStack(Pilha); return 0; } } else if (x[i] == '(' || x[i] == '[' || x[i] == '{') push(Pilha,x[i]); i++; } if (sizeStack(Pilha) == 0) resposta = 1; else resposta = 0; clearStack(Pilha); return resposta; }
// Structure of this code influenced by naev void Console::processCommand(const char *cmdline) { #ifndef BF_NO_CONSOLE if(consoleCommand == "" && strcmp(cmdline, "") == 0) return; setEnvironment(); // If we are not on the first line of our command, we need to append the command to our existing line if(consoleCommand == "") consoleCommand = cmdline; else consoleCommand += "\n" + string(cmdline); S32 status = luaL_loadbuffer(L, consoleCommand.c_str(), consoleCommand.length(), "ConsoleInput"); if(status == LUA_ERRSYNTAX) // cmd is not a complete Lua statement yet -- need to add more input { std::size_t lmsg; const char *msg = lua_tolstring(L, -1, &lmsg); const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1); if(strstr(msg, LUA_QL("<eof>")) == tp) lua_pop(L, 1); else { // Error -- print to console output("%s\n", lua_tostring(L, -1)); consoleCommand = ""; // Reset command } } // Success -- print results to console else if(status == 0) { if(lua_pcall(L, 0, LUA_MULTRET, 0)) { output("%s\n", lua_tostring(L, -1)); lua_pop(L, 1); } if(lua_gettop(L) > 0) { lua_getglobal(L, "print"); lua_insert(L, 1); if(lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) output("Error printing results."); } consoleCommand = ""; // Reset command } clearStack(L); // Don't call LuaObject::eraseAllPotentiallyUntrackedObjects() here; we might create an object // in one command and want to use it in another... better to wait until we close the console. #endif }
int main() { Node* cur = NULL; int buf = 0; FILE* f = fopen("test.txt", "r"); while (!feof(f)) { char symbol = fgetc(f); if (symbol != '(' && symbol != ' ') { if (isSign(symbol)) cur = addChar(cur, symbol); if (symbol == ')') cur = cur->parent; if (isDigit(symbol)) { ungetc(symbol, f); fscanf(f, "%d", &buf); cur = addValue(cur, buf); } } } while(cur->parent != NULL) cur = cur->parent; List *top = new List(); Stack *stack = new Stack(); stack->top = top; postorderPrint(cur, stack); printf("\n"); printf("result = %d\n", stack->top->next->value); clearStack(stack); }
// onShipEnteredZone, onShipLeftZone void EventManager::fireEvent(EventType eventType, Ship *ship, Zone *zone) { if(suppressEvents(eventType)) return; lua_State *L = LuaScriptRunner::getL(); TNLAssert(lua_gettop(L) == 0 || dumpStack(L), "Stack dirty!"); for(S32 i = 0; i < subscriptions[eventType].size(); i++) { try { // Passing ship, zone, zoneType, zoneId ship->push(L); // -- ship zone->push(L); // -- ship, zone lua_pushinteger(L, zone->getObjectTypeNumber()); // -- ship, zone, zone->objTypeNumber lua_pushinteger(L, zone->getUserAssignedId()); // -- ship, zone, zone->objTypeNumber, zone->id fire(L, subscriptions[eventType][i].subscriber, eventDefs[eventType].function, subscriptions[eventType][i].context); } catch(LuaException &e) { handleEventFiringError(L, subscriptions[eventType][i], eventType, e.what()); clearStack(L); return; } } }
PretexSettingsTab::PretexSettingsTab() : BAbstractSettingsTab() { QVBoxLayout *vlt = new QVBoxLayout(this); QGroupBox *gbox = new QGroupBox(tr("General", "gbox title")); QFormLayout *flts = new QFormLayout(gbox); QHBoxLayout *hlt = new QHBoxLayout; cboxSaveStack = new QCheckBox; cboxSaveStack->setChecked(PretexEditorModulePlugin::saveExecutionStack()); hlt->addWidget(cboxSaveStack); QPushButton *btn = new QPushButton(tr("Clear stack", "btn text")); connect(btn, SIGNAL(clicked()), this, SLOT(clearStack())); hlt->addWidget(btn); flts->addRow(tr("Save stack:", "lbl text"), hlt); vlt->addWidget(gbox); gbox = new QGroupBox(tr("External tools", "gbox title")); flt = new QFormLayout(gbox); vlt->addWidget(gbox); vlt->addStretch(); hlt = new QHBoxLayout; hlt->addStretch(); btn = new QPushButton(tr("Add line", "btn text")); connect(btn, SIGNAL(clicked()), this, SLOT(addRow())); hlt->addWidget(btn); vlt->addLayout(hlt); // BProperties map = PretexEditorModulePlugin::externalTools(); foreach (const QString &k, map.keys()) addRow(k, map.value(k)); addRow(); }
static void findOcamlTags (void) { vString *name = vStringNew (); lexingState st; ocaToken tok; initStack (); computeModuleName (); tempIdent = vStringNew (); lastModule = vStringNew (); lastClass = vStringNew (); voidName = vStringNew (); vStringCopyS (voidName, "_"); st.name = vStringNew (); st.cp = fileReadLine (); toDoNext = &globalScope; tok = lex (&st); while (tok != Tok_EOF) { (*toDoNext) (st.name, tok); tok = lex (&st); } vStringDelete (st.name); vStringDelete (name); vStringDelete (voidName); vStringDelete (tempIdent); vStringDelete (lastModule); vStringDelete (lastClass); clearStack (); }
/** * DCI handler init */ void drDcihInit( const addr_t dciBuffer, const uint32_t dciBufferLen ){ /* Ensure thread stack is clean */ clearStack( drDcihStack ); /* DCI message buffer */ message = (dciMessage_t*) dciBuffer; /** * Update DCI handler thread so that notifications will be delivered * to DCI handler thread */ if (DRAPI_OK != drUtilsUpdateNotificationThread( DRIVER_THREAD_NO_DCIH )) { drDbgPrintLnf("[Driver DrTemplate] drDcihInit(): Updating notification thread failed"); } /** * Start DCI handler thread. EXH thread becomes local * exception handler of DCIH thread */ if (DRAPI_OK != drApiStartThread( DRIVER_THREAD_NO_DCIH, FUNC_PTR(drDcih), getStackTop(drDcihStack), DCIH_PRIORITY, DRIVER_THREAD_NO_EXCH)) { drDbgPrintLnf("[Driver DrTemplate] drDcihInit(): drApiStartThread failed"); } }
/*---------------------------------------------------------------------------------------------------------------------- | Sets the data members `num_patterns', `num_rates' and `num_states', which determine the dimensions of all | CondLikelihood objects stored. If the `cl_stack' is not currently empty and if the new conditional likelihood array | length is greater than the current length, all existing objects in `cl_stack' are deleted so that CLAs supplied to | the tree in the future will be at least the minimum length needed. Because it is critical that CLAs already checked | out to a tree be removed if the new length is longer than the old length (otherwise, CLAs that are too short will | be used in the future), this function also checks to make sure there are no CLAs currently checked out. If there are | checked out CLAs, an XLikelihood exception is thrown. This function has no effect unless the supplied arguments | imply that newly-created CLAs will be longer than the existing ones. It is somewhat wastefull to leave in CLAs that | are longer than they need to be, but perhaps more wasteful to continually recall and delete all existing CLAs just | to ensure that their length is exactly correct. */ void CondLikelihoodStorage::setCondLikeDimensions(const uint_vect_t & np, const uint_vect_t & nr, const uint_vect_t & ns) { unsigned sz = (unsigned)np.size(); PHYCAS_ASSERT(nr.size() == sz); PHYCAS_ASSERT(ns.size() == sz); bool no_old = (num_patterns.size() == 0) || (num_rates.size() == 0) || (num_states.size() == 0); bool old = !no_old; unsigned newlen = 0; unsigned oldlen = 0; for (unsigned i = 0; i < sz; ++i) { PHYCAS_ASSERT(np[i] > 0); PHYCAS_ASSERT(nr[i] > 0); PHYCAS_ASSERT(ns[i] > 0); newlen += np[i]*nr[i]*ns[i]; if (old) oldlen += num_patterns[i]*num_rates[i]*num_states[i]; } if (newlen > oldlen) { clearStack(); num_patterns.resize(sz); num_rates.resize(sz); num_states.resize(sz); std::copy(np.begin(), np.end(), num_patterns.begin()); std::copy(nr.begin(), nr.end(), num_rates.begin()); std::copy(ns.begin(), ns.end(), num_states.begin()); } }
/* * When you add a value to the stack, you should ensure that * there is space left. It should only be used for global * stack frames, because the others are allocated in the * runtime stack. */ void freeStack(MalStkPtr stk) { if (!stk) { return; } clearStack(stk); GDKfree(stk); }
//============================================================================= // METHOD : SPELLcallstack::reset //============================================================================= void SPELLcallstack::reset() { m_stack = ""; m_stageId = ""; m_stageTitle = ""; m_codeName = ""; m_markExecuted = false; clearStack(); DEBUG("[CSTACK] SPELLcallstack reset") }
void CalculatorTestApp::keyClear() { if (strlen(topText)) { topText[0]=0; } else if (top()) { pop(); push(0.0); } else { clearStack(); } }
/** replaceStack: replace the stack with our copy stack */ void replaceStack() { clearStack(); stackPointer = copyStackPointer; int i = 0; for (; i < stackPointer; i++) { char* copy = malloc(sizeof(char)* INT_100); strcpy(copy, copyPathStack[i]); pathStack[i] = copy; } }
void endChange() { if( _nestingLevel < 1 ) throw co::IllegalStateException( "not currently recording a changeset" ); if( --_nestingLevel > 0 ) return; // nested calls are ignored recordChanges( Stack_Undo ); clearStack( Stack_Redo ); }
PerlStack PerlInterface::sub(const char* functionName, const PerlStack& param){ if(!param.isValid(perlManager)){ throw CrossInterpreterOperation(); } PERL_SET_CONTEXT(my_perl); clearStack(); innerList = param.getSVList(); numberOfElements = innerList.size(); return sub(functionName); }
QgsEffectStack &QgsEffectStack::operator=( const QgsEffectStack & rhs ) { if ( &rhs == this ) return *this; //deep copy clearStack(); for ( int i = 0; i < rhs.count(); ++i ) { appendEffect( rhs.effect( i )->clone() ); } mEnabled = rhs.enabled(); return *this; }
void EventManager::handleEventFiringError(lua_State *L, const Subscription &subscriber, EventType eventType, const char *errorMsg) { if(subscriber.context == RobotContext) { subscriber.subscriber->logError("Error handling event %s: %s. Shutting bot down.", eventDefs[eventType].name, errorMsg); delete subscriber.subscriber; } else { // It was a levelgen logprintf(LogConsumer::LogError, "Error firing event %s: %s", eventDefs[eventType].name, errorMsg); } clearStack(L); }
//============================================================================= // METHOD : SPELLcallstack::reset //============================================================================= void SPELLcallstack::reset() { m_stack = ""; m_recoveryMode = false; m_fullStack.clear(); m_fullStackString = ""; m_stageId = ""; m_stageTitle = ""; m_codeName = ""; m_markExecuted = false; m_notify = true; m_errorState = false; m_currentLine = 0; clearStack(); DEBUG("[CSTACK] SPELLcallstack reset"); }
void clearLCD(){ /* clear the stack */ clearStack(); /* reset any error string */ resetError(); /* clear the entry buffer */ cancelEditor(); /* re-initialize (and clear) the undo system */ initUndoSystem(); /* redraw the window */ calcStackLCD(); drawStackLCD(); }
int main(){ SqStack s; // 初始化栈 initStack(&s); // 入栈 for (int i=0; i<10; i++) { push(&s, i); } // 遍历栈 stackTraverse(s); // 弹出栈 int ele; pop(&s, &ele); printf("弹出的是%d\n", ele); printf("现在的栈:"); stackTraverse(s); clearStack(&s); }
int main(void) { QUEUE_t myQueue; STACK_t myStack; stack_init(&myStack); queue_init(&myQueue); for(int i = 0; i < 10; i++) { insertQueue(&myQueue,(void*) (rand() % 100)); push(&myStack, (void*) (rand() % 50)); } itemS_t* holdS = pop(&myStack); printf("Item popped: %d\n", holdS->keyValue); free(holdS); printf("Pushing 99...\n"); push(&myStack, (void*) 99); holdS = pop(&myStack); printf("Item popped: %d", holdS->keyValue); free(holdS); printQueue(&myQueue); printStack(&myStack); itemQ_t* holdQ = removeQueue(&myQueue); printf("Item removed from queue: %d.\n", holdQ->keyValue); free(holdQ); printQueue(&myQueue); printStack(&myStack); clearQueue(&myQueue); clearStack(&myStack); return 0; }
int main() { Stack s; s.top = -1; int choice, number; printf("You have a stack of size 10. You can push pop show and clear the stack.\n" "The choices are 1, 2, 3 and 4 respectively. 5 to exit."); scanf("%d" ,&choice); while(choice != 5) { switch(choice) { case 1: printf("Enter the number you want to push to the stack:"); scanf("%d", &number); push(&s, number); break; case 2: number = pop(&s); printf("The popped value is:%d", number); break; case 3: display(&s); break; case 4: clearStack(&s); break; case 5: break; } fflush(stdin); printf("You have a stack of size 10. You can push pop show and clear the stack.\n" "The choices are 1, 2, 3 and 4 respectively. 5 to exit."); scanf("%d" ,&choice); } return 0; }
bool QgsEffectStack::readProperties( const QDomElement &element ) { if ( element.isNull() ) { return false; } mEnabled = ( element.attribute( "enabled", "0" ) != "0" ); clearStack(); //restore all child effects QDomNodeList childNodes = element.childNodes(); for ( int i = 0; i < childNodes.size(); ++i ) { QDomElement childElement = childNodes.at( i ).toElement(); QgsPaintEffect* effect = QgsPaintEffectRegistry::instance()->createEffect( childElement ); if ( effect ) mEffectList << effect; } return true; }
/*! \brief Initialise the system. * * Initialisation of the following: * \li Watchdog (off), * \li Stack, * \li BDM interface, * \li USB interface. */ void init(void) { /* disable part reset on USB reset, enable STOP instruction & disable COP */ CONFIG = CONFIG_URSTD_MASK | CONFIG_STOP_MASK | CONFIG_COPD_MASK; // Turn off important things VPP_OFF(); VDD_OFF(); FLASH12V_OFF(); clearStack(); // Make unused pins 'safe' (not floating) // These settings may be overridden later POCR = POCR_PAP_MASK|POCR_PCP_MASK|POCR_PTE20P_MASK; /* acknowledge IRQ interrupt and disable it */ ISCR = ISCR_ACK_MASK | ISCR_IMASK_MASK; (void)bdm_init(); // Do early as possible usb_init(); EnableInterrupts; }
/* stackCommands: executes variuos commands on the stack*/ void stackCommands(int type) { switch (type) { case 'P': printStack(); break; case 'T': printTopElements(1); break; case 'D': duplicate(); break; case 'S': swapTopTwo(); break; case 'C': clearStack(); break; default: break; } underCommand = 1; }
int main(void) { int type; double op2; char s[MAXOP]; int flag = TRUE; while((type = Getop(s)) != EOF) { switch(type) { case NUMBER: push(atof(s)); break; case IDENTIFIER: dealWithName(s); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop()- op2); break; case '/': op2 = pop(); if(op2) push(pop() / op2); else printf("\nError: division by zero!"); break; case '%': op2 = pop(); if(op2) push(fmod(pop(), op2)); else printf("\nError: division by zero!"); break; case '?': showTop(); break; case '#': duplicate(); break; case '~': swapItems(); break; case '!': clearStack(); case '\n': printf("\n\t%.8g\n", pop()); break; default: printf("\nError: unknown command %s.\n", s); break; } } return EXIT_SUCCESS; }
//============================================================================= // DESTRUCTOR : SPELLcallstack::~SPELLcallstack //============================================================================= SPELLcallstack::~SPELLcallstack() { clearStack(); DEBUG("[CSTACK] SPELLcallstack destroyed"); }
/*---------------------------------------------------------------------------------------------------------------------- | Destructor calls clearStack to destroy all CondLikelihoodShPtr objects currently stored. */ CondLikelihoodStorage::~CondLikelihoodStorage() { clearStack(); }
//Destroy the stack int destroyStack(struct Stack *s) { clearStack(s); s = NULL; return 0; }