void WHILEStatNode::PrintNode(void) { std::cout << "(WHILE "; PrintNum(0); std::cout << std::endl; PrintNum(1); std::cout << ")\n"; }
void FuncArgsNode::PrintNode(void) { PrintNum(1); if (node_[0] != NULL) { PrintNum(0); std::cout << " "; } }
void FuncCallNode::PrintNode(void) { std::cout << "(FCALL "; PrintNum(0); std::cout << " "; PrintNum(1); std::cout << ")"; }
int main() { Num num,square; int n,i; FILE *fp = fopen("palsquare.in","r"); #ifdef DEBUG FILE *debug = fopen("palsquare.tmp","w"); #endif fscanf(fp,"%d",&n); fclose(fp); fp = fopen("palsquare.out","w"); for(i = 0;i < LENGTH;i++) { num.num[i] = '0'; square.num[i] = '0'; } for(i = 1;i <= M;i++) { add1(&num,n); square = Square(num,n); #ifdef DEBUG PrintNum(debug,num,square); #endif if(IsPalindrom(square)) PrintNum(fp,num,square); } #ifdef DEBUG #endif fclose(fp); return 0; }
void ComStatNode::PrintNode(void) { std::cout << "{" << std::endl; // declartion PrintNum(0); // statement PrintNum(1); std::cout << "\n}"; }
void FuncNode::PrintNode(void) { std::cout << "( "; PrintNum(0); std::cout << " "; PrintNum(1); std::cout << ") ("; PrintNum(2); std::cout << ")\n"; PrintNum(3); }
void IFStatNode::PrintNode(void) { std::cout << "(IF "; PrintNum(0); std::cout << std::endl; PrintNum(1); if (node_[2] != NULL) { std::cout << " ELSE "; node_[2]->PrintNode(); std::cout << ")\n"; } }
void AssignExprNode::PrintNode(void) { if (node_[0] != NULL) { std::cout << "(= "; node_[0]->PrintNode(); std::cout << " "; PrintNum(1); std::cout << ")"; } else { PrintNum(1); } }
/* ** PrintNode() just looks at the type of a node and then calls the ** appropriate print function. */ void PrintNode(node *n) { switch (n->type) { case TNUM: { PrintNum(n->cont.n); break; } case TGEN: { PrintGen(n->cont.g); break; } case TMULT: { PrintMult(n->cont.op.l, n->cont.op.r); break; } case TPOW: { PrintPow(n->cont.op.l, n->cont.op.r); break; } case TCONJ: { PrintConj(n->cont.op.l, n->cont.op.r); break; } case TCOMM: { PrintComm(n->cont.op.l, n->cont.op.r, 1); break; } case TREL: { PrintRel(n->cont.op.l, n->cont.op.r); break; } case TDRELL: { PrintDRelL(n->cont.op.l, n->cont.op.r); break; } case TDRELR: { PrintDRelR(n->cont.op.l, n->cont.op.r); break; } case TENGEL: { PrintEngel(n->cont.op.l, n->cont.op.r, n->cont.op.e); break; } default: { fprintf(OutFp, "\nunknown node type\n"); exit(5); } } }
int main() { // store a free function std::function<void(int)> f_display = print_num; f_display(-9); // store a lambda std::function<void()> f_display_42 = []() { print_num(42); }; f_display_42(); // store the result of a call to std::bind std::function<void()> f_display_31337 = std::bind(print_num, 31337); f_display_31337(); // store a call to a member function //std::function<void(const IFoo&, int)> f_add_display = &Foo::print_add; Foo foo; std::function<void(int)> f_add_display = std::bind(&Foo::print_add, &foo, std::placeholders::_1); f_add_display(1); f_add_display = nullptr; if (f_add_display) { std::cout << "Should not write thuis." << '\n'; } // store a call to a function object std::function<void(int)> f_display_obj = PrintNum(); f_display_obj(18); }
int main(){ int lock5; lock5 = CreateLock("lock5", sizeof("lock5")); PrintNum(lock5); return 0; }
int customersAreAllDone() { int boolCount = 0, i, temp, appMon, likeMon, certMon, doneMon; for(i = 0; i < customerCount + senatorCount; ++i) { temp = GetMonitor(isDone, i); boolCount += temp; } prevTotalBoolCount = currentTotalBoolCount; currentTotalBoolCount = 0; for(i = 0; i < customerCount; ++i) { appMon = GetMonitor(applicationIsFiled, i); likeMon = GetMonitor(likesPicture, i); certMon = GetMonitor(hasCertification, i); doneMon = GetMonitor(isDone, i); /* currentTotalBoolCount = currentTotalBoolCount + appMon + likeMon + certMon + doneMon;*/ currentTotalBoolCount = currentTotalBoolCount + doneMon; } PrintString("Manager is counting finished customers ", 39); PrintNum(currentTotalBoolCount); PrintNl(); if(prevTotalBoolCount == currentTotalBoolCount) { wakeUpClerks(); } if(boolCount == customerCount + senatorCount) { return true; } return false; }
void ExpressionList::PrintNode(void) { PrintNum(1); if (node_[0] != NULL) { std::cout << "("; node_[0]->PrintNode(); std::cout << ")"; } }
void ApplicationClerk() { int myLine = -1; int i, numYields; char personName[50]; int isCustomer = 1, custNumber; Acquire(serverClerkLock); for(i = 0; i < clerkArray[0]; ++i) { if (GetMonitor(clerkOwner, i) == 1 ){ /*ApplicationClerk index*/ myLine = i; SetMonitor(clerkOwner, i, 0); break; } } Release(serverClerkLock); while(GetMonitor(allCustomersAreDone, 0) == 0) { custNumber = chooseCustomerFromLine(myLine, "ApplicationClerk_", 17); if(custNumber >= customerCount) { isCustomer = 0; } else { isCustomer = 1; } SetMonitor(clerkStates, myLine, BUSY); hasSignaledString(isCustomer, "ApplicationClerk_", 17, myLine, custNumber); Yield(); givenSSNString(isCustomer, custNumber, "ApplicationClerk_", 17, myLine); Yield(); recievedSSNString(isCustomer, "ApplicationClerk_", 17, myLine, custNumber); /* CL: random time for applicationclerk to process data */ numYields = Rand(80, 20); for(i = 0; i < numYields; ++i) { Yield(); } SetMonitor(applicationIsFiled, custNumber, 1); PrintString("ApplicationClerk_", 17); PrintNum(myLine); PrintString(" has recorded a completed application for ", 42); PrintCust(isCustomer); PrintNum(custNumber); PrintNl(); /*TODO: delete next line*/ PrintNum(GetMonitor(applicationIsFiled, custNumber)); PrintString("test11", 6); PrintNl(); clerkSignalsNextCustomer(myLine); } }
void DeclNode::PrintNode(const int op) { switch(op){ case(OP::INT): std::cout << "(int "; } PrintNum(0); std::cout << ") "; }
void UnaryNode::PrintNode(void) { switch(op_) { case(OP::MINUS): std::cout << "(- "; break; } PrintNum(0); std::cout << ")"; }
void ExprNode::PrintNode(void) { switch(op_) { case(OP::OR): std::cout << "(|| "; break; case(OP::AND): std::cout << "(&& "; break; case(OP::GREATEREQUAL): std::cout << "(>= "; break; case(OP::LESSEQUAL): std::cout << "(<= "; break; case(OP::EQUAL): std::cout << "(== "; break; case(OP::NOTEQUAL): std::cout << "(!= "; break; case(OP::LESS): std::cout << "(< "; break; case(OP::GREATER): std::cout << "(> "; break; case(OP::ADD): std::cout << "(+ "; break; case(OP::SUB): std::cout << "(- "; break; case(OP::MUL): std::cout << "(* "; break; case(OP::DIV): std::cout << "(/ "; break; } PrintNum(0); std::cout << " "; PrintNum(1); std::cout << ")"; }
/*This function wakes up ALL clerks, so they check their lines, if noone is in their line, they'll go back on break*/ void wakeUpClerks() { int i; for(i = 0; i < clerkCount; ++i) { if(GetMonitor(clerkStates, i) == ONBREAK) { PrintString("Manager has woken up a ", 23); PrintString(clerkTypes[i], clerkTypesLengths[i]); PrintString("_", 1); PrintNum(i); PrintNl(); Acquire(breakLock[i]); Signal(breakLock[i],breakCV[i]); Release(breakLock[i]); PrintString(clerkTypes[i], clerkTypesLengths[i]); PrintString("_", 1); PrintNum(i); PrintString(" is coming off break\n", 21); } } }
/*Function to print money owned by clerks*/ void printMoney() { int totalMoney = 0; int applicationMoney = 0; int pictureMoney = 0; int passportMoney = 0; int cashierMoney = 0; int i, tempMon; for(i = 0; i < clerkCount; ++i) { tempMon = GetMonitor(clerkMoney, i); if (i < clerkArray[0]) { /*ApplicationClerk index*/ applicationMoney += tempMon; } else if (i < clerkArray[0] + clerkArray[1]) { /*PictureClerk index*/ pictureMoney += tempMon; } else if (i < clerkArray[0] + clerkArray[1] + clerkArray[2]) { /*PassportClerk index*/ passportMoney += tempMon; } else if (i < clerkArray[0] + clerkArray[1] + clerkArray[2] + clerkArray[3]) { /*Cashier index*/ cashierMoney += tempMon; } totalMoney += tempMon; } applicationMoney = applicationMoney * 100; pictureMoney = pictureMoney * 100; passportMoney = passportMoney * 100; cashierMoney = cashierMoney * 100; totalMoney = totalMoney * 100; PrintString("Manager has counted a total of ", 31); PrintNum(applicationMoney); PrintString(" for ApplicationClerks\n", 23); PrintString("Manager has counted a total of ", 31); PrintNum(pictureMoney); PrintString(" for PictureClerks\n", 19); PrintString("Manager has counted a total of ", 31); PrintNum(passportMoney); PrintString(" for PassportClerks\n", 20); PrintString("Manager has counted a total of ", 31); PrintNum(cashierMoney); PrintString(" for Cashiers\n", 14); PrintString("Manager has counted a total of ", 31); PrintNum(totalMoney); PrintString(" for passport office\n", 21); }
void ClearScr() { // Clear display(weird logic I used to make this work) SendByte(0x01, FALSE); PrintNum(50); SetCursorPos(0,0); PrintStr(" "); SetCursorPos(0,0); }
void t2(){ Write("t2 acquiring lock1\n", 19, ConsoleOutput); Acquire(lock1); PrintString("t2 output should be 50 or 60 to show that there is no race condition in for loop\n", 81); for ( i = 0; i < 10; ++i) ++check; PrintNum(check); PrintNl(); Write("t2 releasing lock1\n", 19, ConsoleOutput); Release(lock1); Acquire(lock2); Release(lock2); Exit(0); }
/* 递归设置从index位往右的各位数字,并打印出来 */ void RecursionPrint1ToN(char *num,int len,int index) { if(index == len-1) { PrintNum(num); return; } int i; for(i=0;i<10;i++) { num[index+1] = i + '0'; RecursionPrint1ToN(num,len,index+1); } }
void getCustomer(int index){ while(true){ int myLine = index; PrintNum(myLine); Write("That was me; pass clerk\n", sizeof("That was me; pass clerk\n"), ConsoleOutput); if (GetMV(passport_clerks[myLine].bribeLineCount)>0){ /*if someone on bribe line */ Write(" Someone is in Bribe line\n", sizeof(" Someone is in Bribe line\n"), ConsoleOutput); Acquire(PassClerkBribeLineLock[myLine]); Signal(PassClerkBribeLineLock[myLine], PassClerkBribeLineCV[myLine]); /*wake them up, call to register*/ SetMV(passport_clerks[myLine].state, 0); /*make myself busy */ passport_clerks[myLine].money = passport_clerks[myLine].money + 500; SetMV(manager.passClerkMoney, GetMV(manager.passClerkMoney)+500); Write("-PassClerk-Received bribe from customer\n", sizeof("-PassClerk-Received bribe from customer\n"), ConsoleOutput); Release(PassClerkBribeLineLock[myLine]); } else if(GetMV(passport_clerks[myLine].lineCount)>0){ /* if someone on regular line */ Write(" Someone is in Regular Line, no one in Bribe line\n", sizeof(" Someone is in Regular Line, no one in Bribe line\n"), ConsoleOutput); Acquire(PassClerkLineLock[myLine]); Signal(PassClerkLineLock[myLine], PassClerkLineCV[myLine]); /* wake up waiting customer*/ SetMV(passport_clerks[myLine].state, 0); /*state is busy now*/ Release(PassClerkLineLock[myLine]); } else{ SetMV(passport_clerks[myLine].state, 1); /*app clerk is available*/ } Acquire(PassClerkLock[myLine]); /*acquire interaction lock*/ Write("-PassClerk-Acquired Lock\n", sizeof("-PassClerk-Acquired Lock\n"), ConsoleOutput); Wait(PassClerkLock[myLine], PassClerkCV[myLine]); /*wait for customer to give SSN*/ Write("--Got ssn and app from customer- verified \n", sizeof("--Got ssn and app from customer- verified \n"), ConsoleOutput); SetMV(customer_data[customer_counter].verified, 1); Signal(PassClerkLock[myLine], PassClerkCV[myLine]); /*if (passport_clerks[myLine].bribe == true){ passport_clerks[myLine].money = passport_clerks[myLine].money + 500; Write("-PassClerk-Received bribe from customer\n", sizeof("-PassClerk-Received bribe from customer\n"), ConsoleOutput); passport_clerks[myLine].bribe = false; }*/ SetMV(passport_clerks[myLine].state, 1); /*Wait(PassClerkLock[myLine], PassClerkCV[myLine]); Signal(PassClerkLock[myLine], PassClerkCV[myLine]); /*signal the customer that record is completed*/ Release(PassClerkLock[myLine]); /*release the lock*/ /*break;*/ } }
void PrintWeather(Weather weather, string city) { cls(); Center(21 + city.size()); cout << "Weather at " << weather.date << " in " << city << "\n"; Center(15); PrintNum(static_cast<int>(weather.temp)); cout << endl; Center(26); cout << "Max temp: " << weather.tempMax << " Min temp: " << weather.tempMin << "\n\n\n"; Center(19); cout << "Weather: " << weather.main << endl; Center(19); cout << "Cloudiness: " << weather.cloudiness << "%" << endl; Center(19); cout << "Wind speed: " << weather.windSpeed << " m/s" << endl; SetConsoleTextAttribute(ConsoleH, 240); Center(4, 4); cout << "Back"; SetConsoleTextAttribute(ConsoleH, 15); while (_getch() != 13); }
void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer while(1) { InitializeLcm(); _delay_cycles(1000); PrintStr("Hello World"); SetCursorPos(1,0); //Go to second line start _delay_cycles(100000); PrintNum(42); _delay_cycles(1000000); ClearScr(); } }
void t1(){ Write("t1 releasing lock1 before acquiring\n", 36, ConsoleOutput); Release(lock1); Write("t1 acquiring lock1, should be successful\n", 41, ConsoleOutput); Acquire(lock1); for (i = 0; i < 50; ++i) ++check; Write("t1 output should be 50 or 60 to show that there is no race condition in for loop 1-50\n", 86, ConsoleOutput); PrintNum(check);PrintNl(); Write("t1 releasing lock1\n", 19, ConsoleOutput); Release(lock1); Write("t1 acquiring lock2 and not releasing\n", 19, ConsoleOutput); Acquire(lock2); Release(lock2); /* Write("t1 destroying lock1\n", 19, ConsoleOutput); DestroyLock(lock1); Write("t1 destroying lock1\n", 19, ConsoleOutput); DestroyLock(lock1);*/ Exit(0); }
/* -*- * A low level printf() function. */ void lp_Print(void (*output)(void *, char *, int), void * arg, char *fmt, va_list ap) { #define OUTPUT(arg, s, l) \ { if (((l) < 0) || ((l) > LP_MAX_BUF)) { \ (*output)(arg, (char*)theFatalMsg, sizeof(theFatalMsg)-1); for(;;); \ } else { \ (*output)(arg, s, l); \ } \ } char buf[LP_MAX_BUF]; char c; char *s; long int num; int longFlag; int negFlag; int width; int prec; int ladjust; char padc; int length; for(;;) { { /* scan for the next '%' */ /*get the address of fmtStart*/ char *fmtStart = fmt; /*get the end of address of fmtStart*/ while((*fmt!='%')&&(*fmt!='\0')){ fmt++; } /* flush the string found so far */ OUTPUT(arg,fmtStart,fmt-fmtStart); /* are we hitting the end? */ if(*fmt=='\0') break; } /* we found a '%' */ fmt++; //go to next character /* check for long */ if(*fmt=='l'){ longFlag = 1; //the string is long } else{ longFlag = 0; } /* check for other prefixes */ //Initialization width = 0; prec = -1; ladjust = 0; padc = ' '; //according prefixes change the sign of string if(*fmt =='-'){ ladjust = 1; fmt++; } if(*fmt=='0'){ padc = '0'; fmt++; } if(IsDigit(*fmt)){ while(IsDigit(*fmt)){ width = 10*width+Ctod(*fmt++); } } if(*fmt == ' '){ fmt++; if(IsDigit(*fmt)){ prec = 0; while(IsDigit(*fmt)){ prec= prec*10+Ctod(*fmt++); } } } /* check format flag */ negFlag = 0; switch (*fmt) { case 'b': if (longFlag) { num = va_arg(ap, long int); } else { num = va_arg(ap, int); } length = PrintNum(buf, num, 2, 0, width, ladjust, padc, 0); OUTPUT(arg, buf, length); break; case 'd': case 'D': if (longFlag) { num = va_arg(ap, long int); } else { num = va_arg(ap, int); } if (num < 0) { num = - num; negFlag = 1; } length = PrintNum(buf, num, 10, negFlag, width, ladjust, padc, 0); OUTPUT(arg, buf, length); break; case 'o': case 'O': if (longFlag) { num = va_arg(ap, long int); } else {
void StatNode::PrintNode(void) { PrintNum(0); std::cout << std::endl; }
void StatList::PrintNode(void) { PrintNum(1); PrintNum(0); }
void RETURNStatNode::PrintNode(void) { std::cout << "(RETURN "; PrintNum(0); std::cout << " )"; }