bool PageInformation::ApplyStyle(PageInformation* pOther) { APPLY2(m_iWidth); APPLY2(m_iHeight); APPLY2(m_iMarginLeft); APPLY2(m_iMarginRight); APPLY2(m_iMarginTop); APPLY2(m_iMarginBottom); APPLY2(m_iGutter); APPLY2(m_iHeaderY); APPLY2(m_iFooterY); // APPLY(m_iFirstPageNumber); // APPLY(m_iPageNumberXOffset); // APPLY(m_iPageNumberYOffset); APPLY(m_iTextFlow); m_bSwitchMarginDefs=pOther->m_bSwitchMarginDefs; m_bLandscape=pOther->m_bLandscape; m_titlePage = pOther->m_titlePage; m_bLeftToRightCols=pOther->m_bLeftToRightCols; m_bFacingPages = pOther->m_bFacingPages; m_Format=pOther->m_Format; m_HeadingAndPageSeparator=pOther->m_HeadingAndPageSeparator; m_Alignment=pOther->m_Alignment; m_iSectLinePitch = pOther->m_iSectLinePitch; return true; }
Move calcmove(Board *board,int player){ if(board->b[0]==0&&board->b[1]==0){ Move mv={player==ORDER?N*(N/2)+N/2:1,XX}; return mv; } int score,best,bestp=-1,beststone=-1; for(int p=0;p<N*N;p++){ if(!ISEMPTY(board->b[0]|board->b[1],p))continue; for(int stone=0;stone<2;stone++){ score=0; Board b2=*board; APPLY(b2.b[stone],p); for(int i=0;i<MC_PLAYTHROUGHS;i++){ score+=playthrough(b2,!player); } if(bestp==-1||(player==ORDER?score>best:score<best)){ best=score; bestp=p; beststone=stone; } } } Move mv={bestp,beststone}; return mv; }
/* * Dump STUN message to a printable string output. */ PJ_DEF(char*) pj_stun_msg_dump(const pj_stun_msg *msg, char *buffer, unsigned length, unsigned *printed_len) { char *p, *end; int len; unsigned i; PJ_ASSERT_RETURN(msg && buffer && length, NULL); PJ_CHECK_STACK(); p = buffer; end = buffer + length; len = pj_ansi_snprintf(p, end-p, "STUN %s %s\n", pj_stun_get_method_name(msg->hdr.type), pj_stun_get_class_name(msg->hdr.type)); APPLY(); len = pj_ansi_snprintf(p, end-p, " Hdr: length=%d, magic=%08x, tsx_id=%08x%08x%08x\n" " Attributes:\n", msg->hdr.length, msg->hdr.magic, *(pj_uint32_t*)&msg->hdr.tsx_id[0], *(pj_uint32_t*)&msg->hdr.tsx_id[4], *(pj_uint32_t*)&msg->hdr.tsx_id[8]); APPLY(); for (i=0; i<msg->attr_count; ++i) { len = print_attr(p, (unsigned)(end-p), msg->attr[i]); APPLY(); } on_return: *p = '\0'; if (printed_len) *printed_len = (unsigned)(p-buffer); return buffer; #undef APPLY }
void foo() { F(1.0, 3); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments. // CHECK-FIXES: F(3, 1.0) #define M(x, y) x##y() double b = 1.0; F(b, M(Some, Function)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments. // CHECK-FIXES: F(M(Some, Function), b); #define N F(b, SomeFunction()) N; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments. // In macro, don't emit fixits. // CHECK-FIXES: #define N F(b, SomeFunction()) G(b, 3); G(3, 1.0); G(0, 0); F(1.0, 1.0); // no-warning F(3, 1.0); // no-warning F(true, false); // no-warning F(0, 'c'); // no-warning #define APPLY(f, x, y) f(x, y) APPLY(F, 1.0, 3); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments. // CHECK-FIXES: APPLY(F, 3, 1.0); #define PARAMS 1.0, 3 #define CALL(P) F(P) CALL(PARAMS); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'int' to 'double' followed by argument converted from 'double' to 'int', potentially swapped arguments. // In macro, don't emit fixits. }
static int playthrough(Board board,int player){ (void)player; int win; Move poss[2*N*N]; int nposs; while(true){ win=checkwin(&board); if(win!=-1)return 1-2*win; nposs=0; for(int p=0;p<N*N;p++){ for(int stone=0;stone<2;stone++){ if(!ISEMPTY(board.b[0]|board.b[1],p))continue; poss[nposs].pos=p; poss[nposs++].stone=stone; } } assert(nposs>0); //else Chaos would've won int i=random()%nposs; APPLY(board.b[poss[i].stone],poss[i].pos); } }
malValuePtr EVAL(malValuePtr ast, malEnvPtr env) { while (1) { const malList* list = DYNAMIC_CAST(malList, ast); if (!list || (list->count() == 0)) { return ast->eval(env); } // From here on down we are evaluating a non-empty list. // First handle the special forms. if (const malSymbol* symbol = DYNAMIC_CAST(malSymbol, list->item(0))) { String special = symbol->value(); int argCount = list->count() - 1; if (special == "def!") { checkArgsIs("def!", 2, argCount); const malSymbol* id = VALUE_CAST(malSymbol, list->item(1)); return env->set(id->value(), EVAL(list->item(2), env)); } if (special == "do") { checkArgsAtLeast("do", 1, argCount); for (int i = 1; i < argCount; i++) { EVAL(list->item(i), env); } ast = list->item(argCount); continue; // TCO } if (special == "fn*") { checkArgsIs("fn*", 2, argCount); const malSequence* bindings = VALUE_CAST(malSequence, list->item(1)); StringVec params; for (int i = 0; i < bindings->count(); i++) { const malSymbol* sym = VALUE_CAST(malSymbol, bindings->item(i)); params.push_back(sym->value()); } return mal::lambda(params, list->item(2), env); } if (special == "if") { checkArgsBetween("if", 2, 3, argCount); bool isTrue = EVAL(list->item(1), env)->isTrue(); if (!isTrue && (argCount == 2)) { return mal::nilValue(); } ast = list->item(isTrue ? 2 : 3); continue; // TCO } if (special == "let*") { checkArgsIs("let*", 2, argCount); const malSequence* bindings = VALUE_CAST(malSequence, list->item(1)); int count = checkArgsEven("let*", bindings->count()); malEnvPtr inner(new malEnv(env)); for (int i = 0; i < count; i += 2) { const malSymbol* var = VALUE_CAST(malSymbol, bindings->item(i)); inner->set(var->value(), EVAL(bindings->item(i+1), inner)); } ast = list->item(2); env = inner; continue; // TCO } if (special == "quasiquote") { checkArgsIs("quasiquote", 1, argCount); ast = quasiquote(list->item(1)); continue; // TCO } if (special == "quote") { checkArgsIs("quote", 1, argCount); return list->item(1); } } // Now we're left with the case of a regular list to be evaluated. std::unique_ptr<malValueVec> items(list->evalItems(env)); malValuePtr op = items->at(0); if (const malLambda* lambda = DYNAMIC_CAST(malLambda, op)) { ast = lambda->getBody(); env = lambda->makeEnv(items->begin()+1, items->end()); continue; // TCO } else { return APPLY(op, items->begin()+1, items->end(), env); } } }
void applymove(Board *board,Move mv){ APPLY(board->b[mv.stone],mv.pos); }
malValuePtr EVAL(malValuePtr ast, malEnvPtr env) { if (!env) { env = replEnv; } while (1) { const malList* list = DYNAMIC_CAST(malList, ast); if (!list || (list->count() == 0)) { return ast->eval(env); } ast = macroExpand(ast, env); list = DYNAMIC_CAST(malList, ast); if (!list || (list->count() == 0)) { return ast->eval(env); } // From here on down we are evaluating a non-empty list. // First handle the special forms. if (const malSymbol* symbol = DYNAMIC_CAST(malSymbol, list->item(0))) { String special = symbol->value(); int argCount = list->count() - 1; if (special == "def!") { checkArgsIs("def!", 2, argCount); const malSymbol* id = VALUE_CAST(malSymbol, list->item(1)); return env->set(id->value(), EVAL(list->item(2), env)); } if (special == "defmacro!") { checkArgsIs("defmacro!", 2, argCount); const malSymbol* id = VALUE_CAST(malSymbol, list->item(1)); malValuePtr body = EVAL(list->item(2), env); const malLambda* lambda = VALUE_CAST(malLambda, body); return env->set(id->value(), mal::macro(*lambda)); } if (special == "do") { checkArgsAtLeast("do", 1, argCount); for (int i = 1; i < argCount; i++) { EVAL(list->item(i), env); } ast = list->item(argCount); continue; // TCO } if (special == "fn*") { checkArgsIs("fn*", 2, argCount); const malSequence* bindings = VALUE_CAST(malSequence, list->item(1)); StringVec params; for (int i = 0; i < bindings->count(); i++) { const malSymbol* sym = VALUE_CAST(malSymbol, bindings->item(i)); params.push_back(sym->value()); } return mal::lambda(params, list->item(2), env); } if (special == "if") { checkArgsBetween("if", 2, 3, argCount); bool isTrue = EVAL(list->item(1), env)->isTrue(); if (!isTrue && (argCount == 2)) { return mal::nilValue(); } ast = list->item(isTrue ? 2 : 3); continue; // TCO } if (special == "let*") { checkArgsIs("let*", 2, argCount); const malSequence* bindings = VALUE_CAST(malSequence, list->item(1)); int count = checkArgsEven("let*", bindings->count()); malEnvPtr inner(new malEnv(env)); for (int i = 0; i < count; i += 2) { const malSymbol* var = VALUE_CAST(malSymbol, bindings->item(i)); inner->set(var->value(), EVAL(bindings->item(i+1), inner)); } ast = list->item(2); env = inner; continue; // TCO } if (special == "macroexpand") { checkArgsIs("macroexpand", 1, argCount); return macroExpand(list->item(1), env); } if (special == "quasiquote") { checkArgsIs("quasiquote", 1, argCount); ast = quasiquote(list->item(1)); continue; // TCO } if (special == "quote") { checkArgsIs("quote", 1, argCount); return list->item(1); } if (special == "try*") { checkArgsIs("try*", 2, argCount); malValuePtr tryBody = list->item(1); const malList* catchBlock = VALUE_CAST(malList, list->item(2)); checkArgsIs("catch*", 2, catchBlock->count() - 1); MAL_CHECK(VALUE_CAST(malSymbol, catchBlock->item(0))->value() == "catch*", "catch block must begin with catch*"); // We don't need excSym at this scope, but we want to check // that the catch block is valid always, not just in case of // an exception. const malSymbol* excSym = VALUE_CAST(malSymbol, catchBlock->item(1)); malValuePtr excVal; try { ast = EVAL(tryBody, env); } catch(String& s) { excVal = mal::string(s); } catch (malEmptyInputException&) { // Not an error, continue as if we got nil ast = mal::nilValue(); } catch(malValuePtr& o) { excVal = o; }; if (excVal) { // we got some exception env = malEnvPtr(new malEnv(env)); env->set(excSym->value(), excVal); ast = catchBlock->item(2); } continue; // TCO } } // Now we're left with the case of a regular list to be evaluated. std::unique_ptr<malValueVec> items(list->evalItems(env)); malValuePtr op = items->at(0); if (const malLambda* lambda = DYNAMIC_CAST(malLambda, op)) { ast = lambda->getBody(); env = lambda->makeEnv(items->begin()+1, items->end()); continue; // TCO } else { return APPLY(op, items->begin()+1, items->end()); } } }
void __fastcall TFormMain::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { TRect R = RectNormalize(&Selection); unsigned tx = MAX(ListView->ItemIndex,0); //ShowMessage(Key); switch (Key) { case 221: {APPLY(cell->bot += 64) Key = 1; break;} case 219: {APPLY(cell->bot -= 64) Key = 1; break;} //case 36: {APPLY(cell->mid += 64) Key = 1; break;} //case 35: {APPLY(cell->mid -= 64) Key = 1; break;} case 'P': {APPLY(cell->top += 64) Key = 1; break;} case 'O': {APPLY(cell->top -= 64) Key = 1; break;} case 'L': {APPLY(cell->swi ^= CELL_SWI_LIGHT) Key = 1; break;} case 45: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->btx=tx);Key=1;break;} case 46: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->btx=tx);Key=1;break;} case 36: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->wtx=tx);Key=1;break;} case 35: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->wtx=tx);Key=1;break;} case 33: {if(tc)tx=(tx-1)%YETI_TEXTURE_MAX;APPLY(cell->ttx=tx);Key=1;break;} case 34: {if(tc)tx=(tx+1)%YETI_TEXTURE_MAX;APPLY(cell->ttx=tx);Key=1;break;} case 'F': {APPLY(cell_block(cell, true )); Key = 1; break;} case 'G': {APPLY(cell_block(cell, false)); Key = 1; break;} case 'E': { String Value = yeti->cells[R.top][R.left].ent; if (InputQuery("", "Enter Entity ID (0..255):", Value)) { int ent = Value.ToIntDef(0); APPLY(cell->ent = ent); Key = 1; } break; } case VK_LEFT : {yeti->keyboard.left = true; Key = 0; break;} case VK_UP : {yeti->keyboard.up = true; Key = 0; break;} case VK_RIGHT : {yeti->keyboard.right = true; Key = 0; break;} case VK_DOWN : {yeti->keyboard.down = true; Key = 0; break;} case VK_CONTROL : {yeti->keyboard.a = true; Key = 0; break;} case ' ' : {yeti->keyboard.b = true; Key = 0; break;} case 'A' : {yeti->keyboard.l = true; Key = 0; break;} case 'Z' : {yeti->keyboard.r = true; Key = 0; break;} default: { //ShowMessage(Key); } } if (Key == 1) { Key = 0; yeti_default_lighting(yeti); PaintBoxPaint(PaintBox); FormPreview->TimerTimer(FormPreview->Timer); Modified = true; ListView->ItemIndex = tx; ListView->Selected->MakeVisible(False); tc = true; } }
static int print_attr(char *buffer, unsigned length, const pj_stun_attr_hdr *ahdr) { char *p = buffer, *end = buffer + length; const char *attr_name = pj_stun_get_attr_name(ahdr->type); char attr_buf[32]; int len; if (*attr_name == '?') { pj_ansi_snprintf(attr_buf, sizeof(attr_buf), "Attr 0x%x", ahdr->type); attr_name = attr_buf; } len = pj_ansi_snprintf(p, end-p, " %s: length=%d", attr_name, (int)ahdr->length); APPLY(); switch (ahdr->type) { case PJ_STUN_ATTR_MAPPED_ADDR: case PJ_STUN_ATTR_RESPONSE_ADDR: case PJ_STUN_ATTR_SOURCE_ADDR: case PJ_STUN_ATTR_CHANGED_ADDR: case PJ_STUN_ATTR_REFLECTED_FROM: case PJ_STUN_ATTR_XOR_PEER_ADDR: case PJ_STUN_ATTR_XOR_RELAYED_ADDR: case PJ_STUN_ATTR_XOR_MAPPED_ADDR: case PJ_STUN_ATTR_XOR_REFLECTED_FROM: case PJ_STUN_ATTR_ALTERNATE_SERVER: { const pj_stun_sockaddr_attr *attr; attr = (const pj_stun_sockaddr_attr*)ahdr; if (attr->sockaddr.addr.sa_family == pj_AF_INET()) { len = pj_ansi_snprintf(p, end-p, ", IPv4 addr=%s:%d\n", pj_inet_ntoa(attr->sockaddr.ipv4.sin_addr), pj_ntohs(attr->sockaddr.ipv4.sin_port)); } else if (attr->sockaddr.addr.sa_family == pj_AF_INET6()) { len = pj_ansi_snprintf(p, end-p, ", IPv6 addr present\n"); } else { len = pj_ansi_snprintf(p, end-p, ", INVALID ADDRESS FAMILY!\n"); } APPLY(); } break; case PJ_STUN_ATTR_CHANNEL_NUMBER: { const pj_stun_uint_attr *attr; attr = (const pj_stun_uint_attr*)ahdr; len = pj_ansi_snprintf(p, end-p, ", chnum=%u (0x%x)\n", (int)PJ_STUN_GET_CH_NB(attr->value), (int)PJ_STUN_GET_CH_NB(attr->value)); APPLY(); } break; case PJ_STUN_ATTR_CHANGE_REQUEST: case PJ_STUN_ATTR_LIFETIME: case PJ_STUN_ATTR_BANDWIDTH: case PJ_STUN_ATTR_REQ_ADDR_TYPE: case PJ_STUN_ATTR_EVEN_PORT: case PJ_STUN_ATTR_REQ_TRANSPORT: case PJ_STUN_ATTR_TIMER_VAL: case PJ_STUN_ATTR_PRIORITY: case PJ_STUN_ATTR_FINGERPRINT: case PJ_STUN_ATTR_REFRESH_INTERVAL: case PJ_STUN_ATTR_ICMP: { const pj_stun_uint_attr *attr; attr = (const pj_stun_uint_attr*)ahdr; len = pj_ansi_snprintf(p, end-p, ", value=%u (0x%x)\n", (pj_uint32_t)attr->value, (pj_uint32_t)attr->value); APPLY(); } break; case PJ_STUN_ATTR_USERNAME: case PJ_STUN_ATTR_PASSWORD: case PJ_STUN_ATTR_REALM: case PJ_STUN_ATTR_NONCE: case PJ_STUN_ATTR_SOFTWARE: { const pj_stun_string_attr *attr; attr = (pj_stun_string_attr*)ahdr; len = pj_ansi_snprintf(p, end-p, ", value=\"%.*s\"\n", (int)attr->value.slen, attr->value.ptr); APPLY(); } break; case PJ_STUN_ATTR_ERROR_CODE: { const pj_stun_errcode_attr *attr; attr = (const pj_stun_errcode_attr*) ahdr; len = pj_ansi_snprintf(p, end-p, ", err_code=%d, reason=\"%.*s\"\n", attr->err_code, (int)attr->reason.slen, attr->reason.ptr); APPLY(); } break; case PJ_STUN_ATTR_UNKNOWN_ATTRIBUTES: { const pj_stun_unknown_attr *attr; unsigned j; attr = (const pj_stun_unknown_attr*) ahdr; len = pj_ansi_snprintf(p, end-p, ", unknown list:"); APPLY(); for (j=0; j<attr->attr_count; ++j) { len = pj_ansi_snprintf(p, end-p, " %d", (int)attr->attrs[j]); APPLY(); } } break; case PJ_STUN_ATTR_MESSAGE_INTEGRITY: { const pj_stun_msgint_attr *attr; attr = (const pj_stun_msgint_attr*) ahdr; len = print_binary(p, (unsigned)(end-p), attr->hmac, 20); APPLY(); } break; case PJ_STUN_ATTR_DATA: { const pj_stun_binary_attr *attr; attr = (const pj_stun_binary_attr*) ahdr; len = print_binary(p, (unsigned)(end-p), attr->data, attr->length); APPLY(); } break; case PJ_STUN_ATTR_ICE_CONTROLLED: case PJ_STUN_ATTR_ICE_CONTROLLING: case PJ_STUN_ATTR_RESERVATION_TOKEN: { const pj_stun_uint64_attr *attr; pj_uint8_t data[8]; int i; attr = (const pj_stun_uint64_attr*) ahdr; for (i=0; i<8; ++i) data[i] = ((const pj_uint8_t*)&attr->value)[7-i]; len = print_binary(p, (unsigned)(end-p), data, 8); APPLY(); } break; case PJ_STUN_ATTR_USE_CANDIDATE: case PJ_STUN_ATTR_DONT_FRAGMENT: default: len = pj_ansi_snprintf(p, end-p, "\n"); APPLY(); break; } return (int)(p-buffer); on_return: return len; }
void ROWStageEquation<ELLIPTIC_EQ,GRAMIAN>::setup_rhs (unsigned int i, const double tolerance, const double t_n, const double h, const InfiniteVector<double,Index>& D_un, const std::list<InfiniteVector<double,Index> >& Dalpha_uj, const int jmax) { typedef InfiniteVector<double,Index> V; V help, w; const unsigned int stages = row_method_->A.row_dimension(); // for readability // start with zero rhs y.clear(); // first summand DD^{-1}<A Psi,Psi>^T D^{-1}w, where // w = Du^{(n)} + DD_alpha^{-1}sum_{j=1}^{i-1} a_{i,j}D_alpha u_j if (i > 0) { typename std::list<V>::const_iterator it = Dalpha_uj.begin(); for (unsigned int j = 0; j < i; j++, ++it) { w.add(row_method_->A(i,j), *it); } w.scale(this, -1); // w *= D_alpha^{-1} w.scale(elliptic_, 1); // w *= D } w.add(D_un); APPLY(*elliptic_, w, tolerance, help, jmax, St04a); // yields -D^{-1}<A Psi,Psi>D^{-1}w help.scale(elliptic_, 1); // help *= D help.scale(-1.0); // result = -D(-D^{-1}<A Psi,Psi>^T D^{-1}w) y = help; // cout << "ROWStageEquation::setup_rhs() done, y1=" << endl << y << endl; // second summand <f(t_n+alpha_i*h),Psi>^T if (f_ != 0) { f_->set_time(t_n+h*row_method_->alpha_vector[i]); w.clear(); expand(f_, elliptic_->basis(), true, jmax, w); // expand in the dual (!) basis // cout << "ROWStageEquation::setup_rhs() done, y2=" << endl << w << endl; y.add(w); } // third summand <Psi,Psi>^T D_alpha^{-1}sum_{j=1}^{i-1}(c_{i,j}/h)D_alpha u_j if (i > 0) { w.clear(); typename std::list<V>::const_iterator it = Dalpha_uj.begin(); for (unsigned int j = 0; j < i; j++, ++it) { w.add(row_method_->C(i,j)/h, *it); } w.scale(this, -1); // w *= D_alpha^{-1} APPLY(*gramian_, w, tolerance/(4*stages), help, jmax, St04a); // yields <Psi,Psi>^T D_alpha^{-1}sum(...) // cout << "ROWStageEquation::setup_rhs() done, y3=" << endl << help << endl; y.add(help); } // fourth summand h*gamma_i*<f'(t_n),Psi>^T if (ft_ != 0) { ft_->set_time(t_n); w.clear(); expand(ft_, elliptic_->basis(), true, jmax, w); // expand in the dual (!) basis // cout << "ROWStageEquation::setup_rhs() done, y4=" << endl << w << endl; y.add(h*row_method_->gamma_vector[i], w); } // cout << "ROWStageEquation::setup_rhs() done, y=" << endl << y << endl; }
void FormSetup::ApplyB() { APPLY(); Save.zapiszopcje(); }